@idraw/util 0.4.0-beta.4 → 0.4.0-beta.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.d.ts +17 -7
- package/dist/esm/index.js +17 -7
- package/dist/esm/lib/box.d.ts +2 -0
- package/dist/esm/lib/box.js +173 -0
- package/dist/esm/lib/canvas.d.ts +0 -1
- package/dist/esm/lib/canvas.js +26 -50
- package/dist/esm/lib/color.js +9 -6
- package/dist/esm/lib/config.d.ts +5 -10
- package/dist/esm/lib/config.js +9 -9
- package/dist/esm/lib/context2d.d.ts +4 -0
- package/dist/esm/lib/context2d.js +20 -0
- package/dist/esm/lib/controller.d.ts +8 -2
- package/dist/esm/lib/controller.js +184 -9
- package/dist/esm/lib/data.d.ts +7 -2
- package/dist/esm/lib/data.js +114 -4
- package/dist/esm/lib/element.d.ts +5 -0
- package/dist/esm/lib/element.js +54 -1
- package/dist/esm/lib/event.d.ts +4 -2
- package/dist/esm/lib/event.js +31 -11
- package/dist/esm/lib/file.d.ts +2 -1
- package/dist/esm/lib/file.js +4 -1
- package/dist/esm/lib/flat.d.ts +2 -0
- package/dist/esm/lib/flat.js +132 -0
- package/dist/esm/lib/group.d.ts +3 -0
- package/dist/esm/lib/group.js +81 -0
- package/dist/esm/lib/handle-element.d.ts +6 -1
- package/dist/esm/lib/handle-element.js +108 -43
- package/dist/esm/lib/html.d.ts +1 -1
- package/dist/esm/lib/is.d.ts +3 -1
- package/dist/esm/lib/is.js +21 -5
- package/dist/esm/lib/istype.d.ts +1 -0
- package/dist/esm/lib/istype.js +3 -0
- package/dist/esm/lib/merge.d.ts +1 -0
- package/dist/esm/lib/merge.js +17 -0
- package/dist/esm/lib/modify-recorder.d.ts +15 -0
- package/dist/esm/lib/modify-recorder.js +177 -0
- package/dist/esm/lib/modify.d.ts +6 -0
- package/dist/esm/lib/modify.js +99 -0
- package/dist/esm/lib/omit.d.ts +1 -0
- package/dist/esm/lib/omit.js +7 -0
- package/dist/esm/lib/point-move-element.d.ts +5 -0
- package/dist/esm/lib/point-move-element.js +26 -0
- package/dist/esm/lib/rect.js +9 -9
- package/dist/esm/lib/resize-element.d.ts +2 -0
- package/dist/esm/lib/resize-element.js +101 -0
- package/dist/esm/lib/rotate.js +8 -13
- package/dist/esm/lib/store.d.ts +9 -5
- package/dist/esm/lib/store.js +39 -9
- package/dist/esm/lib/text.d.ts +1 -0
- package/dist/esm/lib/text.js +4 -0
- package/dist/esm/lib/time.d.ts +1 -0
- package/dist/esm/lib/time.js +13 -1
- package/dist/esm/lib/view-box.js +4 -2
- package/dist/esm/lib/view-calc.d.ts +16 -3
- package/dist/esm/lib/view-calc.js +127 -3
- package/dist/esm/lib/view-content.d.ts +14 -0
- package/dist/esm/lib/view-content.js +88 -0
- package/dist/index.global.js +1614 -257
- package/dist/index.global.min.js +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Point, PointSize, Data, ViewScaleInfo, ViewSizeInfo, Element, ElementType, ElementSize, ViewContext2D, ViewRectVertexes } from '@idraw/types';
|
|
1
|
+
import { Point, PointSize, Data, ViewScaleInfo, ViewSizeInfo, Element, ElementType, ElementSize, ViewContext2D, ViewRectVertexes, ViewRectInfo } from '@idraw/types';
|
|
2
2
|
export declare function calcViewScaleInfo(info: {
|
|
3
3
|
scale: number;
|
|
4
4
|
offsetX: number;
|
|
@@ -23,11 +23,9 @@ export declare function viewScroll(opts: {
|
|
|
23
23
|
}): ViewScaleInfo;
|
|
24
24
|
export declare function calcViewElementSize(size: ElementSize, opts: {
|
|
25
25
|
viewScaleInfo: ViewScaleInfo;
|
|
26
|
-
viewSizeInfo: ViewSizeInfo;
|
|
27
26
|
}): ElementSize;
|
|
28
27
|
export declare function calcViewPointSize(size: PointSize, opts: {
|
|
29
28
|
viewScaleInfo: ViewScaleInfo;
|
|
30
|
-
viewSizeInfo: ViewSizeInfo;
|
|
31
29
|
}): PointSize;
|
|
32
30
|
export declare function calcViewVertexes(vertexes: ViewRectVertexes, opts: {
|
|
33
31
|
viewScaleInfo: ViewScaleInfo;
|
|
@@ -39,6 +37,12 @@ export declare function isViewPointInElement(p: Point, opts: {
|
|
|
39
37
|
viewScaleInfo: ViewScaleInfo;
|
|
40
38
|
viewSizeInfo: ViewSizeInfo;
|
|
41
39
|
}): boolean;
|
|
40
|
+
export declare function isViewPointInElementSize(p: Point, elemSize: ElementSize, opts?: {
|
|
41
|
+
includeBorder?: boolean;
|
|
42
|
+
}): boolean;
|
|
43
|
+
export declare function isViewPointInVertexes(p: Point, vertexes: ViewRectVertexes, opts?: {
|
|
44
|
+
includeBorder?: boolean;
|
|
45
|
+
}): boolean;
|
|
42
46
|
export declare function getViewPointAtElement(p: Point, opts: {
|
|
43
47
|
context2d: ViewContext2D;
|
|
44
48
|
data: Data;
|
|
@@ -54,3 +58,12 @@ export declare function isElementInView(elem: ElementSize, opts: {
|
|
|
54
58
|
viewScaleInfo: ViewScaleInfo;
|
|
55
59
|
viewSizeInfo: ViewSizeInfo;
|
|
56
60
|
}): boolean;
|
|
61
|
+
export declare function calcElementOriginRectInfo(elemSize: ElementSize, opts: {
|
|
62
|
+
groupQueue: Element<'group'>[];
|
|
63
|
+
}): ViewRectInfo;
|
|
64
|
+
export declare function originRectInfoToRangeRectInfo(originRectInfo: ViewRectInfo): ViewRectInfo;
|
|
65
|
+
export declare function calcElementViewRectInfo(elemSize: ElementSize, opts: {
|
|
66
|
+
groupQueue: Element<'group'>[];
|
|
67
|
+
viewScaleInfo: ViewScaleInfo;
|
|
68
|
+
range?: boolean;
|
|
69
|
+
}): ViewRectInfo;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { rotateElementVertexes } from './rotate';
|
|
2
2
|
import { checkRectIntersect } from './rect';
|
|
3
|
+
import { calcElementVertexesInGroup, calcElementVertexes } from './vertex';
|
|
4
|
+
import { getCenterFromTwoPoints } from './point';
|
|
3
5
|
export function calcViewScaleInfo(info, opts) {
|
|
4
6
|
const { scale, offsetX, offsetY } = info;
|
|
5
7
|
const { viewSizeInfo } = opts;
|
|
@@ -86,9 +88,9 @@ export function calcViewVertexes(vertexes, opts) {
|
|
|
86
88
|
];
|
|
87
89
|
}
|
|
88
90
|
export function isViewPointInElement(p, opts) {
|
|
89
|
-
const { context2d: ctx, element: elem, viewScaleInfo
|
|
91
|
+
const { context2d: ctx, element: elem, viewScaleInfo } = opts;
|
|
90
92
|
const { angle = 0 } = elem;
|
|
91
|
-
const { x, y, w, h } = calcViewElementSize(elem, { viewScaleInfo
|
|
93
|
+
const { x, y, w, h } = calcViewElementSize(elem, { viewScaleInfo });
|
|
92
94
|
const vertexes = rotateElementVertexes({ x, y, w, h, angle });
|
|
93
95
|
if (vertexes.length >= 2) {
|
|
94
96
|
ctx.beginPath();
|
|
@@ -103,6 +105,25 @@ export function isViewPointInElement(p, opts) {
|
|
|
103
105
|
}
|
|
104
106
|
return false;
|
|
105
107
|
}
|
|
108
|
+
export function isViewPointInElementSize(p, elemSize, opts) {
|
|
109
|
+
const vertexes = calcElementVertexes(elemSize);
|
|
110
|
+
return isViewPointInVertexes(p, vertexes, opts);
|
|
111
|
+
}
|
|
112
|
+
export function isViewPointInVertexes(p, vertexes, opts) {
|
|
113
|
+
const xList = [vertexes[0].x, vertexes[1].x, vertexes[2].x, vertexes[3].x];
|
|
114
|
+
const yList = [vertexes[0].y, vertexes[1].y, vertexes[2].y, vertexes[3].y];
|
|
115
|
+
const mixX = Math.min(...xList);
|
|
116
|
+
const maxX = Math.max(...xList);
|
|
117
|
+
const mixY = Math.min(...yList);
|
|
118
|
+
const maxY = Math.max(...yList);
|
|
119
|
+
if (p.x > mixX && p.x < maxX && p.y > mixY && p.y < maxY) {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.includeBorder) === true && (p.x === mixX || p.x === maxX || p.y === mixY || p.y === maxY)) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
106
127
|
export function getViewPointAtElement(p, opts) {
|
|
107
128
|
var _a, _b, _c;
|
|
108
129
|
const { context2d: ctx, data, viewScaleInfo, viewSizeInfo, groupQueue } = opts;
|
|
@@ -174,7 +195,7 @@ export function isElementInView(elem, opts) {
|
|
|
174
195
|
const { viewSizeInfo, viewScaleInfo } = opts;
|
|
175
196
|
const { width, height } = viewSizeInfo;
|
|
176
197
|
const { angle } = elem;
|
|
177
|
-
const { x, y, w, h } = calcViewElementSize(elem, { viewScaleInfo
|
|
198
|
+
const { x, y, w, h } = calcViewElementSize(elem, { viewScaleInfo });
|
|
178
199
|
const ves = rotateElementVertexes({ x, y, w, h, angle });
|
|
179
200
|
const viewSize = { x: 0, y: 0, w: width, h: height };
|
|
180
201
|
const elemStartX = Math.min(ves[0].x, ves[1].x, ves[2].x, ves[3].x);
|
|
@@ -184,3 +205,106 @@ export function isElementInView(elem, opts) {
|
|
|
184
205
|
const elemSize = { x: elemStartX, y: elemStartY, w: elemEndX - elemStartX, h: elemEndY - elemStartY };
|
|
185
206
|
return checkRectIntersect(viewSize, elemSize);
|
|
186
207
|
}
|
|
208
|
+
export function calcElementOriginRectInfo(elemSize, opts) {
|
|
209
|
+
const { groupQueue } = opts;
|
|
210
|
+
const vertexes = calcElementVertexesInGroup(elemSize, { groupQueue });
|
|
211
|
+
const top = getCenterFromTwoPoints(vertexes[0], vertexes[1]);
|
|
212
|
+
const right = getCenterFromTwoPoints(vertexes[1], vertexes[2]);
|
|
213
|
+
const bottom = getCenterFromTwoPoints(vertexes[2], vertexes[3]);
|
|
214
|
+
const left = getCenterFromTwoPoints(vertexes[3], vertexes[0]);
|
|
215
|
+
const topLeft = vertexes[0];
|
|
216
|
+
const topRight = vertexes[1];
|
|
217
|
+
const bottomRight = vertexes[2];
|
|
218
|
+
const bottomLeft = vertexes[3];
|
|
219
|
+
const maxX = Math.max(topLeft.x, topRight.x, bottomRight.x, bottomLeft.x);
|
|
220
|
+
const maxY = Math.max(topLeft.y, topRight.y, bottomRight.y, bottomLeft.y);
|
|
221
|
+
const minX = Math.min(topLeft.x, topRight.x, bottomRight.x, bottomLeft.x);
|
|
222
|
+
const minY = Math.min(topLeft.y, topRight.y, bottomRight.y, bottomLeft.y);
|
|
223
|
+
const center = {
|
|
224
|
+
x: (maxX + minX) / 2,
|
|
225
|
+
y: (maxY + minY) / 2
|
|
226
|
+
};
|
|
227
|
+
const rectInfo = {
|
|
228
|
+
center,
|
|
229
|
+
topLeft,
|
|
230
|
+
topRight,
|
|
231
|
+
bottomLeft,
|
|
232
|
+
bottomRight,
|
|
233
|
+
top,
|
|
234
|
+
right,
|
|
235
|
+
left,
|
|
236
|
+
bottom
|
|
237
|
+
};
|
|
238
|
+
return rectInfo;
|
|
239
|
+
}
|
|
240
|
+
export function originRectInfoToRangeRectInfo(originRectInfo) {
|
|
241
|
+
const rangeMaxX = Math.max(originRectInfo.topLeft.x, originRectInfo.topRight.x, originRectInfo.bottomRight.x, originRectInfo.bottomLeft.x);
|
|
242
|
+
const rangeMaxY = Math.max(originRectInfo.topLeft.y, originRectInfo.topRight.y, originRectInfo.bottomRight.y, originRectInfo.bottomLeft.y);
|
|
243
|
+
const rangeMinX = Math.min(originRectInfo.topLeft.x, originRectInfo.topRight.x, originRectInfo.bottomRight.x, originRectInfo.bottomLeft.x);
|
|
244
|
+
const rangeMinY = Math.min(originRectInfo.topLeft.y, originRectInfo.topRight.y, originRectInfo.bottomRight.y, originRectInfo.bottomLeft.y);
|
|
245
|
+
const rangeCenter = { x: originRectInfo.center.x, y: originRectInfo.center.y };
|
|
246
|
+
const rangeTopLeft = { x: rangeMinX, y: rangeMinY };
|
|
247
|
+
const rangeTopRight = { x: rangeMaxX, y: rangeMinY };
|
|
248
|
+
const rangeBottomRight = { x: rangeMaxX, y: rangeMaxY };
|
|
249
|
+
const rangeBottomLeft = { x: rangeMinX, y: rangeMaxY };
|
|
250
|
+
const rangeTop = getCenterFromTwoPoints(rangeTopLeft, rangeTopRight);
|
|
251
|
+
const rangeBottom = getCenterFromTwoPoints(rangeBottomLeft, rangeBottomRight);
|
|
252
|
+
const rangeLeft = getCenterFromTwoPoints(rangeTopLeft, rangeBottomLeft);
|
|
253
|
+
const rangeRight = getCenterFromTwoPoints(rangeTopRight, rangeBottomRight);
|
|
254
|
+
const rangeRectInfo = {
|
|
255
|
+
center: rangeCenter,
|
|
256
|
+
topLeft: rangeTopLeft,
|
|
257
|
+
topRight: rangeTopRight,
|
|
258
|
+
bottomLeft: rangeBottomLeft,
|
|
259
|
+
bottomRight: rangeBottomRight,
|
|
260
|
+
top: rangeTop,
|
|
261
|
+
right: rangeRight,
|
|
262
|
+
left: rangeLeft,
|
|
263
|
+
bottom: rangeBottom
|
|
264
|
+
};
|
|
265
|
+
return rangeRectInfo;
|
|
266
|
+
}
|
|
267
|
+
export function calcElementViewRectInfo(elemSize, opts) {
|
|
268
|
+
const { groupQueue, viewScaleInfo, range } = opts;
|
|
269
|
+
const originRectInfo = calcElementOriginRectInfo(elemSize, { groupQueue });
|
|
270
|
+
const { center, top, bottom, left, right, topLeft, topRight, bottomLeft, bottomRight } = originRectInfo;
|
|
271
|
+
const viewRectInfo = {
|
|
272
|
+
center: calcViewPointSize(center, { viewScaleInfo }),
|
|
273
|
+
topLeft: calcViewPointSize(topLeft, { viewScaleInfo }),
|
|
274
|
+
topRight: calcViewPointSize(topRight, { viewScaleInfo }),
|
|
275
|
+
bottomLeft: calcViewPointSize(bottomLeft, { viewScaleInfo }),
|
|
276
|
+
bottomRight: calcViewPointSize(bottomRight, { viewScaleInfo }),
|
|
277
|
+
top: calcViewPointSize(top, { viewScaleInfo }),
|
|
278
|
+
right: calcViewPointSize(right, { viewScaleInfo }),
|
|
279
|
+
left: calcViewPointSize(left, { viewScaleInfo }),
|
|
280
|
+
bottom: calcViewPointSize(bottom, { viewScaleInfo })
|
|
281
|
+
};
|
|
282
|
+
if (range === true) {
|
|
283
|
+
const viewMaxX = Math.max(viewRectInfo.topLeft.x, viewRectInfo.topRight.x, viewRectInfo.bottomRight.x, viewRectInfo.bottomLeft.x);
|
|
284
|
+
const viewMaxY = Math.max(viewRectInfo.topLeft.y, viewRectInfo.topRight.y, viewRectInfo.bottomRight.y, viewRectInfo.bottomLeft.y);
|
|
285
|
+
const viewMinX = Math.min(viewRectInfo.topLeft.x, viewRectInfo.topRight.x, viewRectInfo.bottomRight.x, viewRectInfo.bottomLeft.x);
|
|
286
|
+
const viewMinY = Math.min(viewRectInfo.topLeft.y, viewRectInfo.topRight.y, viewRectInfo.bottomRight.y, viewRectInfo.bottomLeft.y);
|
|
287
|
+
const rangeCenter = { x: viewRectInfo.center.x, y: viewRectInfo.center.y };
|
|
288
|
+
const rangeTopLeft = { x: viewMinX, y: viewMinY };
|
|
289
|
+
const rangeTopRight = { x: viewMaxX, y: viewMinY };
|
|
290
|
+
const rangeBottomRight = { x: viewMaxX, y: viewMaxY };
|
|
291
|
+
const rangeBottomLeft = { x: viewMinX, y: viewMaxY };
|
|
292
|
+
const rangeTop = getCenterFromTwoPoints(rangeTopLeft, rangeTopRight);
|
|
293
|
+
const rangeBottom = getCenterFromTwoPoints(rangeBottomLeft, rangeBottomRight);
|
|
294
|
+
const rangeLeft = getCenterFromTwoPoints(rangeTopLeft, rangeBottomLeft);
|
|
295
|
+
const rangeRight = getCenterFromTwoPoints(rangeTopRight, rangeBottomRight);
|
|
296
|
+
const rangeRectInfo = {
|
|
297
|
+
center: rangeCenter,
|
|
298
|
+
topLeft: rangeTopLeft,
|
|
299
|
+
topRight: rangeTopRight,
|
|
300
|
+
bottomLeft: rangeBottomLeft,
|
|
301
|
+
bottomRight: rangeBottomRight,
|
|
302
|
+
top: rangeTop,
|
|
303
|
+
right: rangeRight,
|
|
304
|
+
left: rangeLeft,
|
|
305
|
+
bottom: rangeBottom
|
|
306
|
+
};
|
|
307
|
+
return rangeRectInfo;
|
|
308
|
+
}
|
|
309
|
+
return viewRectInfo;
|
|
310
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Data, ViewSizeInfo, ViewScaleInfo, PointSize } from '@idraw/types';
|
|
2
|
+
interface ViewCenterContentResult {
|
|
3
|
+
offsetX: number;
|
|
4
|
+
offsetY: number;
|
|
5
|
+
scale: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function calcViewCenterContent(data: Data, opts: {
|
|
8
|
+
viewSizeInfo: ViewSizeInfo;
|
|
9
|
+
}): ViewCenterContentResult;
|
|
10
|
+
export declare function calcViewCenter(opts?: {
|
|
11
|
+
viewScaleInfo: ViewScaleInfo;
|
|
12
|
+
viewSizeInfo: ViewSizeInfo;
|
|
13
|
+
}): PointSize;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { rotateElementVertexes } from './rotate';
|
|
2
|
+
import { formatNumber } from './number';
|
|
3
|
+
import { is } from './is';
|
|
4
|
+
export function calcViewCenterContent(data, opts) {
|
|
5
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
6
|
+
let offsetX = 0;
|
|
7
|
+
let offsetY = 0;
|
|
8
|
+
let scale = 1;
|
|
9
|
+
let contentX = ((_b = (_a = data === null || data === void 0 ? void 0 : data.elements) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.x) || 0;
|
|
10
|
+
let contentY = ((_d = (_c = data === null || data === void 0 ? void 0 : data.elements) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.y) || 0;
|
|
11
|
+
let contentW = ((_f = (_e = data === null || data === void 0 ? void 0 : data.elements) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.w) || 0;
|
|
12
|
+
let contentH = ((_h = (_g = data === null || data === void 0 ? void 0 : data.elements) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.h) || 0;
|
|
13
|
+
const { width, height } = opts.viewSizeInfo;
|
|
14
|
+
if (data.layout && ((_k = (_j = data.layout) === null || _j === void 0 ? void 0 : _j.detail) === null || _k === void 0 ? void 0 : _k.overflow) === 'hidden') {
|
|
15
|
+
contentX = 0;
|
|
16
|
+
contentY = 0;
|
|
17
|
+
contentW = data.layout.w || 0;
|
|
18
|
+
contentH = data.layout.h || 0;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
data.elements.forEach((elem) => {
|
|
22
|
+
const elemSize = {
|
|
23
|
+
x: elem.x,
|
|
24
|
+
y: elem.y,
|
|
25
|
+
w: elem.w,
|
|
26
|
+
h: elem.h,
|
|
27
|
+
angle: elem.angle
|
|
28
|
+
};
|
|
29
|
+
if (elemSize.angle && (elemSize.angle > 0 || elemSize.angle < 0)) {
|
|
30
|
+
const ves = rotateElementVertexes(elemSize);
|
|
31
|
+
if (ves.length === 4) {
|
|
32
|
+
const xList = [ves[0].x, ves[1].x, ves[2].x, ves[3].x];
|
|
33
|
+
const yList = [ves[0].y, ves[1].y, ves[2].y, ves[3].y];
|
|
34
|
+
elemSize.x = Math.min(...xList);
|
|
35
|
+
elemSize.y = Math.min(...yList);
|
|
36
|
+
elemSize.w = Math.abs(Math.max(...xList) - Math.min(...xList));
|
|
37
|
+
elemSize.h = Math.abs(Math.max(...yList) - Math.min(...yList));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const areaStartX = Math.min(elemSize.x, contentX);
|
|
41
|
+
const areaStartY = Math.min(elemSize.y, contentY);
|
|
42
|
+
const areaEndX = Math.max(elemSize.x + elemSize.w, contentX + contentW);
|
|
43
|
+
const areaEndY = Math.max(elemSize.y + elemSize.h, contentY + contentH);
|
|
44
|
+
contentX = areaStartX;
|
|
45
|
+
contentY = areaStartY;
|
|
46
|
+
contentW = Math.abs(areaEndX - areaStartX);
|
|
47
|
+
contentH = Math.abs(areaEndY - areaStartY);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (data.layout) {
|
|
51
|
+
const { x, y, w, h } = data.layout;
|
|
52
|
+
if (is.x(x) && is.y(y) && is.w(w) && is.h(h)) {
|
|
53
|
+
contentX = Math.min(contentX, x);
|
|
54
|
+
contentY = Math.min(contentY, y);
|
|
55
|
+
contentW = Math.max(contentW, w);
|
|
56
|
+
contentH = Math.max(contentH, h);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (contentW > 0 && contentH > 0) {
|
|
60
|
+
const scaleW = formatNumber(width / contentW, { decimalPlaces: 4 });
|
|
61
|
+
const scaleH = formatNumber(height / contentH, { decimalPlaces: 4 });
|
|
62
|
+
scale = Math.min(scaleW, scaleH, 1);
|
|
63
|
+
offsetX = (contentW * scale - width) / 2 / scale + contentX;
|
|
64
|
+
offsetY = (contentH * scale - height) / 2 / scale + contentY;
|
|
65
|
+
}
|
|
66
|
+
const result = {
|
|
67
|
+
offsetX: formatNumber(offsetX, { decimalPlaces: 0 }),
|
|
68
|
+
offsetY: formatNumber(offsetY, { decimalPlaces: 0 }),
|
|
69
|
+
scale
|
|
70
|
+
};
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
export function calcViewCenter(opts) {
|
|
74
|
+
let x = 0;
|
|
75
|
+
let y = 0;
|
|
76
|
+
if (opts) {
|
|
77
|
+
const { viewScaleInfo, viewSizeInfo } = opts;
|
|
78
|
+
const { offsetLeft, offsetTop, scale } = viewScaleInfo;
|
|
79
|
+
const { width, height } = viewSizeInfo;
|
|
80
|
+
x = 0 - offsetLeft + width / scale / 2;
|
|
81
|
+
y = 0 - offsetTop + height / scale / 2;
|
|
82
|
+
}
|
|
83
|
+
const p = {
|
|
84
|
+
x,
|
|
85
|
+
y
|
|
86
|
+
};
|
|
87
|
+
return p;
|
|
88
|
+
}
|