@idraw/util 0.4.0-beta.3 → 0.4.0-beta.31

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.
Files changed (48) hide show
  1. package/dist/esm/index.d.ts +14 -8
  2. package/dist/esm/index.js +14 -8
  3. package/dist/esm/lib/canvas.d.ts +6 -1
  4. package/dist/esm/lib/canvas.js +42 -19
  5. package/dist/esm/lib/config.d.ts +5 -10
  6. package/dist/esm/lib/config.js +9 -9
  7. package/dist/esm/lib/context2d.d.ts +2 -0
  8. package/dist/esm/lib/context2d.js +14 -0
  9. package/dist/esm/lib/controller.d.ts +5 -1
  10. package/dist/esm/lib/controller.js +142 -0
  11. package/dist/esm/lib/data.d.ts +6 -2
  12. package/dist/esm/lib/data.js +95 -2
  13. package/dist/esm/lib/element.d.ts +1 -0
  14. package/dist/esm/lib/element.js +19 -0
  15. package/dist/esm/lib/event.d.ts +4 -2
  16. package/dist/esm/lib/event.js +31 -11
  17. package/dist/esm/lib/file.d.ts +7 -2
  18. package/dist/esm/lib/file.js +26 -7
  19. package/dist/esm/lib/flat.d.ts +2 -0
  20. package/dist/esm/lib/flat.js +132 -0
  21. package/dist/esm/lib/handle-element.d.ts +6 -1
  22. package/dist/esm/lib/handle-element.js +108 -43
  23. package/dist/esm/lib/html.d.ts +1 -1
  24. package/dist/esm/lib/istype.d.ts +1 -0
  25. package/dist/esm/lib/istype.js +3 -0
  26. package/dist/esm/lib/modify-recorder.d.ts +15 -0
  27. package/dist/esm/lib/modify-recorder.js +177 -0
  28. package/dist/esm/lib/modify.d.ts +6 -0
  29. package/dist/esm/lib/modify.js +99 -0
  30. package/dist/esm/lib/rect.js +9 -9
  31. package/dist/esm/lib/resize-element.d.ts +2 -0
  32. package/dist/esm/lib/resize-element.js +101 -0
  33. package/dist/esm/lib/store.d.ts +6 -5
  34. package/dist/esm/lib/store.js +30 -9
  35. package/dist/esm/lib/text.d.ts +1 -0
  36. package/dist/esm/lib/text.js +4 -0
  37. package/dist/esm/lib/time.d.ts +1 -0
  38. package/dist/esm/lib/time.js +13 -1
  39. package/dist/esm/lib/view-box.js +4 -3
  40. package/dist/esm/lib/view-calc.d.ts +20 -3
  41. package/dist/esm/lib/view-calc.js +171 -3
  42. package/dist/esm/lib/view-content.d.ts +14 -0
  43. package/dist/esm/lib/view-content.js +88 -0
  44. package/dist/esm/lib/view-visible.d.ts +21 -0
  45. package/dist/esm/lib/view-visible.js +93 -0
  46. package/dist/index.global.js +1272 -176
  47. package/dist/index.global.min.js +1 -1
  48. package/package.json +1 -1
@@ -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, viewSizeInfo } = opts;
91
+ const { context2d: ctx, element: elem, viewScaleInfo } = opts;
90
92
  const { angle = 0 } = elem;
91
- const { x, y, w, h } = calcViewElementSize(elem, { viewScaleInfo, viewSizeInfo });
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, viewSizeInfo });
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,150 @@ 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
+ }
311
+ export function calcElementViewRectInfoMap(elemSize, opts) {
312
+ const { groupQueue, viewScaleInfo } = opts;
313
+ const originRectInfo = calcElementOriginRectInfo(elemSize, { groupQueue });
314
+ const { center, top, bottom, left, right, topLeft, topRight, bottomLeft, bottomRight } = originRectInfo;
315
+ const viewRectInfo = {
316
+ center: calcViewPointSize(center, { viewScaleInfo }),
317
+ topLeft: calcViewPointSize(topLeft, { viewScaleInfo }),
318
+ topRight: calcViewPointSize(topRight, { viewScaleInfo }),
319
+ bottomLeft: calcViewPointSize(bottomLeft, { viewScaleInfo }),
320
+ bottomRight: calcViewPointSize(bottomRight, { viewScaleInfo }),
321
+ top: calcViewPointSize(top, { viewScaleInfo }),
322
+ right: calcViewPointSize(right, { viewScaleInfo }),
323
+ left: calcViewPointSize(left, { viewScaleInfo }),
324
+ bottom: calcViewPointSize(bottom, { viewScaleInfo })
325
+ };
326
+ const viewMaxX = Math.max(viewRectInfo.topLeft.x, viewRectInfo.topRight.x, viewRectInfo.bottomRight.x, viewRectInfo.bottomLeft.x);
327
+ const viewMaxY = Math.max(viewRectInfo.topLeft.y, viewRectInfo.topRight.y, viewRectInfo.bottomRight.y, viewRectInfo.bottomLeft.y);
328
+ const viewMinX = Math.min(viewRectInfo.topLeft.x, viewRectInfo.topRight.x, viewRectInfo.bottomRight.x, viewRectInfo.bottomLeft.x);
329
+ const viewMinY = Math.min(viewRectInfo.topLeft.y, viewRectInfo.topRight.y, viewRectInfo.bottomRight.y, viewRectInfo.bottomLeft.y);
330
+ const rangeCenter = { x: viewRectInfo.center.x, y: viewRectInfo.center.y };
331
+ const rangeTopLeft = { x: viewMinX, y: viewMinY };
332
+ const rangeTopRight = { x: viewMaxX, y: viewMinY };
333
+ const rangeBottomRight = { x: viewMaxX, y: viewMaxY };
334
+ const rangeBottomLeft = { x: viewMinX, y: viewMaxY };
335
+ const rangeTop = getCenterFromTwoPoints(rangeTopLeft, rangeTopRight);
336
+ const rangeBottom = getCenterFromTwoPoints(rangeBottomLeft, rangeBottomRight);
337
+ const rangeLeft = getCenterFromTwoPoints(rangeTopLeft, rangeBottomLeft);
338
+ const rangeRight = getCenterFromTwoPoints(rangeTopRight, rangeBottomRight);
339
+ const rangeRectInfo = {
340
+ center: rangeCenter,
341
+ topLeft: rangeTopLeft,
342
+ topRight: rangeTopRight,
343
+ bottomLeft: rangeBottomLeft,
344
+ bottomRight: rangeBottomRight,
345
+ top: rangeTop,
346
+ right: rangeRight,
347
+ left: rangeLeft,
348
+ bottom: rangeBottom
349
+ };
350
+ return {
351
+ originRectInfo,
352
+ rangeRectInfo
353
+ };
354
+ }
@@ -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
+ }
@@ -0,0 +1,21 @@
1
+ import { Elements, ViewScaleInfo, ViewSizeInfo, ViewRectInfo, ViewVisibleInfoMap } from '@idraw/types';
2
+ export declare function sortElementsViewVisiableInfoMap(elements: Elements, opts: {
3
+ viewScaleInfo: ViewScaleInfo;
4
+ viewSizeInfo: ViewSizeInfo;
5
+ }): {
6
+ viewVisibleInfoMap: ViewVisibleInfoMap;
7
+ visibleCount: number;
8
+ invisibleCount: number;
9
+ };
10
+ export declare function updateViewVisibleInfoMapStatus(viewVisibleInfoMap: ViewVisibleInfoMap, opts: {
11
+ viewScaleInfo: ViewScaleInfo;
12
+ viewSizeInfo: ViewSizeInfo;
13
+ }): {
14
+ viewVisibleInfoMap: ViewVisibleInfoMap;
15
+ visibleCount: number;
16
+ invisibleCount: number;
17
+ };
18
+ export declare function calcVisibleOriginCanvasRectInfo(opts: {
19
+ viewScaleInfo: ViewScaleInfo;
20
+ viewSizeInfo: ViewSizeInfo;
21
+ }): ViewRectInfo;
@@ -0,0 +1,93 @@
1
+ import { calcElementOriginRectInfo, originRectInfoToRangeRectInfo } from './view-calc';
2
+ import { getGroupQueueByElementPosition } from './element';
3
+ import { calcElementCenter } from './rotate';
4
+ import { is } from './is';
5
+ export function sortElementsViewVisiableInfoMap(elements, opts) {
6
+ const visibleInfoMap = {};
7
+ const currentPosition = [];
8
+ const _walk = (elem) => {
9
+ const baseInfo = {
10
+ isVisibleInView: true,
11
+ isGroup: elem.type === 'group',
12
+ position: [...currentPosition]
13
+ };
14
+ let originRectInfo = null;
15
+ const groupQueue = getGroupQueueByElementPosition(elements, currentPosition);
16
+ originRectInfo = calcElementOriginRectInfo(elem, {
17
+ groupQueue: groupQueue || []
18
+ });
19
+ visibleInfoMap[elem.uuid] = Object.assign(Object.assign({}, baseInfo), {
20
+ originRectInfo: originRectInfo,
21
+ rangeRectInfo: is.angle(elem.angle) ? originRectInfoToRangeRectInfo(originRectInfo) : originRectInfo
22
+ });
23
+ if (elem.type === 'group') {
24
+ elem.detail.children.forEach((ele, i) => {
25
+ currentPosition.push(i);
26
+ _walk(ele);
27
+ currentPosition.pop();
28
+ });
29
+ }
30
+ };
31
+ elements.forEach((elem, index) => {
32
+ currentPosition.push(index);
33
+ _walk(elem);
34
+ currentPosition.pop();
35
+ });
36
+ return updateViewVisibleInfoMapStatus(visibleInfoMap, opts);
37
+ }
38
+ function isRangeRectInfoCollide(info1, info2) {
39
+ const rect1MinX = Math.min(info1.topLeft.x, info1.topRight.x, info1.bottomLeft.x, info1.bottomRight.x);
40
+ const rect1MaxX = Math.max(info1.topLeft.x, info1.topRight.x, info1.bottomLeft.x, info1.bottomRight.x);
41
+ const rect1MinY = Math.min(info1.topLeft.y, info1.topRight.y, info1.bottomLeft.y, info1.bottomRight.y);
42
+ const rect1MaxY = Math.max(info1.topLeft.y, info1.topRight.y, info1.bottomLeft.y, info1.bottomRight.y);
43
+ const rect2MinX = Math.min(info2.topLeft.x, info2.topRight.x, info2.bottomLeft.x, info2.bottomRight.x);
44
+ const rect2MaxX = Math.max(info2.topLeft.x, info2.topRight.x, info2.bottomLeft.x, info2.bottomRight.x);
45
+ const rect2MinY = Math.min(info2.topLeft.y, info2.topRight.y, info2.bottomLeft.y, info2.bottomRight.y);
46
+ const rect2MaxY = Math.max(info2.topLeft.y, info2.topRight.y, info2.bottomLeft.y, info2.bottomRight.y);
47
+ if ((rect1MinX <= rect2MaxX && rect1MaxX >= rect2MinX && rect1MinY <= rect2MaxY && rect1MaxY >= rect2MinY) ||
48
+ (rect2MaxX <= rect1MaxY && rect2MaxX >= rect1MaxY && rect2MaxX <= rect1MaxY && rect2MaxX >= rect1MaxY)) {
49
+ return true;
50
+ }
51
+ return false;
52
+ }
53
+ export function updateViewVisibleInfoMapStatus(viewVisibleInfoMap, opts) {
54
+ const canvasRectInfo = calcVisibleOriginCanvasRectInfo(opts);
55
+ let visibleCount = 0;
56
+ let invisibleCount = 0;
57
+ Object.keys(viewVisibleInfoMap).forEach((uuid) => {
58
+ const info = viewVisibleInfoMap[uuid];
59
+ info.isVisibleInView = isRangeRectInfoCollide(info.rangeRectInfo, canvasRectInfo);
60
+ info.isVisibleInView ? visibleCount++ : invisibleCount++;
61
+ });
62
+ return { viewVisibleInfoMap, visibleCount, invisibleCount };
63
+ }
64
+ export function calcVisibleOriginCanvasRectInfo(opts) {
65
+ const { viewScaleInfo, viewSizeInfo } = opts;
66
+ const { scale, offsetTop, offsetLeft } = viewScaleInfo;
67
+ const { width, height } = viewSizeInfo;
68
+ const x = 0 - offsetLeft / scale;
69
+ const y = 0 - offsetTop / scale;
70
+ const w = width / scale;
71
+ const h = height / scale;
72
+ const center = calcElementCenter({ x, y, w, h });
73
+ const topLeft = { x, y };
74
+ const topRight = { x: x + w, y };
75
+ const bottomLeft = { x, y: y + h };
76
+ const bottomRight = { x: x + w, y: y + h };
77
+ const left = { x, y: center.y };
78
+ const top = { x: center.x, y };
79
+ const right = { x: x + w, y: center.y };
80
+ const bottom = { x: center.x, y: y + h };
81
+ const rectInfo = {
82
+ center,
83
+ topLeft,
84
+ topRight,
85
+ bottomLeft,
86
+ bottomRight,
87
+ left,
88
+ top,
89
+ right,
90
+ bottom
91
+ };
92
+ return rectInfo;
93
+ }