UNPKG

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