getFixScaleEleTransPosition.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
  3. import { getClientSize } from "rc-util/es/Dom/css";
  4. function fixPoint(key, start, width, clientWidth) {
  5. var startAddWidth = start + width;
  6. var offsetStart = (width - clientWidth) / 2;
  7. if (width > clientWidth) {
  8. if (start > 0) {
  9. return _defineProperty({}, key, offsetStart);
  10. }
  11. if (start < 0 && startAddWidth < clientWidth) {
  12. return _defineProperty({}, key, -offsetStart);
  13. }
  14. } else if (start < 0 || startAddWidth > clientWidth) {
  15. return _defineProperty({}, key, start < 0 ? offsetStart : -offsetStart);
  16. }
  17. return {};
  18. }
  19. /**
  20. * Fix positon x,y point when
  21. *
  22. * Ele width && height < client
  23. * - Back origin
  24. *
  25. * - Ele width | height > clientWidth | clientHeight
  26. * - left | top > 0 -> Back 0
  27. * - left | top + width | height < clientWidth | clientHeight -> Back left | top + width | height === clientWidth | clientHeight
  28. *
  29. * Regardless of other
  30. */
  31. export default function getFixScaleEleTransPosition(width, height, left, top) {
  32. var _getClientSize = getClientSize(),
  33. clientWidth = _getClientSize.width,
  34. clientHeight = _getClientSize.height;
  35. var fixPos = null;
  36. if (width <= clientWidth && height <= clientHeight) {
  37. fixPos = {
  38. x: 0,
  39. y: 0
  40. };
  41. } else if (width > clientWidth || height > clientHeight) {
  42. fixPos = _objectSpread(_objectSpread({}, fixPoint('x', left, width, clientWidth)), fixPoint('y', top, height, clientHeight));
  43. }
  44. return fixPos;
  45. }