getFixScaleEleTransPosition.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = getFixScaleEleTransPosition;
  7. var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
  8. var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
  9. var _css = require("rc-util/lib/Dom/css");
  10. function fixPoint(key, start, width, clientWidth) {
  11. var startAddWidth = start + width;
  12. var offsetStart = (width - clientWidth) / 2;
  13. if (width > clientWidth) {
  14. if (start > 0) {
  15. return (0, _defineProperty2.default)({}, key, offsetStart);
  16. }
  17. if (start < 0 && startAddWidth < clientWidth) {
  18. return (0, _defineProperty2.default)({}, key, -offsetStart);
  19. }
  20. } else if (start < 0 || startAddWidth > clientWidth) {
  21. return (0, _defineProperty2.default)({}, key, start < 0 ? offsetStart : -offsetStart);
  22. }
  23. return {};
  24. }
  25. /**
  26. * Fix positon x,y point when
  27. *
  28. * Ele width && height < client
  29. * - Back origin
  30. *
  31. * - Ele width | height > clientWidth | clientHeight
  32. * - left | top > 0 -> Back 0
  33. * - left | top + width | height < clientWidth | clientHeight -> Back left | top + width | height === clientWidth | clientHeight
  34. *
  35. * Regardless of other
  36. */
  37. function getFixScaleEleTransPosition(width, height, left, top) {
  38. var _getClientSize = (0, _css.getClientSize)(),
  39. clientWidth = _getClientSize.width,
  40. clientHeight = _getClientSize.height;
  41. var fixPos = null;
  42. if (width <= clientWidth && height <= clientHeight) {
  43. fixPos = {
  44. x: 0,
  45. y: 0
  46. };
  47. } else if (width > clientWidth || height > clientHeight) {
  48. fixPos = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, fixPoint('x', left, width, clientWidth)), fixPoint('y', top, height, clientHeight));
  49. }
  50. return fixPos;
  51. }