@idraw/util 0.4.2 → 1.0.0-alpha.1

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 (96) hide show
  1. package/dist/esm/converter/data-svg.d.ts +2 -0
  2. package/dist/esm/converter/data-svg.js +19 -0
  3. package/dist/esm/converter/material-svg.d.ts +2 -0
  4. package/dist/esm/converter/material-svg.js +63 -0
  5. package/dist/esm/converter/svg-material.d.ts +2 -0
  6. package/dist/esm/converter/svg-material.js +188 -0
  7. package/dist/esm/index.d.ts +32 -21
  8. package/dist/esm/index.js +32 -21
  9. package/dist/esm/static.d.ts +1 -0
  10. package/dist/esm/static.js +1 -0
  11. package/dist/esm/tool/file.js +2 -2
  12. package/dist/esm/tool/html.js +27 -27
  13. package/dist/esm/tool/id.d.ts +1 -0
  14. package/dist/esm/tool/id.js +4 -0
  15. package/dist/esm/tool/image.js +6 -6
  16. package/dist/esm/tool/path-to-box.d.ts +3 -0
  17. package/dist/esm/tool/path-to-box.js +353 -0
  18. package/dist/esm/tool/path-to-command.d.ts +4 -0
  19. package/dist/esm/tool/path-to-command.js +392 -0
  20. package/dist/esm/tool/path.d.ts +18 -0
  21. package/dist/esm/tool/path.js +421 -0
  22. package/dist/esm/tool/svg-path.d.ts +3 -0
  23. package/dist/esm/{view → tool}/svg-path.js +4 -16
  24. package/dist/esm/tool/time.d.ts +2 -2
  25. package/dist/esm/tool/time.js +4 -4
  26. package/dist/esm/tool/uuid.d.ts +1 -1
  27. package/dist/esm/tool/uuid.js +6 -6
  28. package/dist/esm/view/box.d.ts +0 -2
  29. package/dist/esm/view/box.js +1 -173
  30. package/dist/esm/view/canvas.js +3 -3
  31. package/dist/esm/view/check.d.ts +8 -7
  32. package/dist/esm/view/check.js +34 -34
  33. package/dist/esm/view/config.d.ts +0 -9
  34. package/dist/esm/view/config.js +1 -71
  35. package/dist/esm/view/context2d.d.ts +10 -3
  36. package/dist/esm/view/context2d.js +39 -18
  37. package/dist/esm/view/controller.d.ts +5 -5
  38. package/dist/esm/view/controller.js +105 -102
  39. package/dist/esm/view/data.d.ts +2 -2
  40. package/dist/esm/view/data.js +65 -65
  41. package/dist/esm/view/dom.d.ts +23 -0
  42. package/dist/esm/view/dom.js +190 -0
  43. package/dist/esm/view/flat.d.ts +2 -2
  44. package/dist/esm/view/flat.js +53 -53
  45. package/dist/esm/view/group.d.ts +3 -3
  46. package/dist/esm/view/group.js +25 -28
  47. package/dist/esm/view/handle-material.d.ts +24 -0
  48. package/dist/esm/view/{handle-element.js → handle-material.js} +98 -75
  49. package/dist/esm/view/is.d.ts +10 -12
  50. package/dist/esm/view/is.js +15 -19
  51. package/dist/esm/view/load.d.ts +2 -2
  52. package/dist/esm/view/load.js +7 -7
  53. package/dist/esm/view/material.d.ts +40 -0
  54. package/dist/esm/view/material.js +476 -0
  55. package/dist/esm/view/middleware.d.ts +1 -0
  56. package/dist/esm/view/middleware.js +14 -2
  57. package/dist/esm/view/modify-record.d.ts +4 -4
  58. package/dist/esm/view/modify-record.js +2 -2
  59. package/dist/esm/view/parser.d.ts +2 -2
  60. package/dist/esm/view/parser.js +3 -3
  61. package/dist/esm/view/path.d.ts +2 -0
  62. package/dist/esm/view/path.js +30 -0
  63. package/dist/esm/view/point-move-material.d.ts +5 -0
  64. package/dist/esm/view/{point-move-element.js → point-move-material.js} +6 -6
  65. package/dist/esm/view/point.d.ts +3 -8
  66. package/dist/esm/view/point.js +1 -21
  67. package/dist/esm/view/position.d.ts +9 -9
  68. package/dist/esm/view/position.js +1 -1
  69. package/dist/esm/view/rect.d.ts +2 -2
  70. package/dist/esm/view/rect.js +4 -4
  71. package/dist/esm/view/resize-material.d.ts +4 -0
  72. package/dist/esm/view/resize-material.js +266 -0
  73. package/dist/esm/view/rotate.d.ts +11 -11
  74. package/dist/esm/view/rotate.js +24 -24
  75. package/dist/esm/view/static.d.ts +13 -0
  76. package/dist/esm/view/static.js +89 -0
  77. package/dist/esm/view/styles.d.ts +11 -0
  78. package/dist/esm/view/styles.js +78 -0
  79. package/dist/esm/view/vertex.d.ts +8 -8
  80. package/dist/esm/view/vertex.js +28 -28
  81. package/dist/esm/view/view-box.d.ts +2 -6
  82. package/dist/esm/view/view-box.js +8 -64
  83. package/dist/esm/view/view-calc.d.ts +23 -20
  84. package/dist/esm/view/view-calc.js +104 -93
  85. package/dist/esm/view/view-content.d.ts +2 -2
  86. package/dist/esm/view/view-content.js +34 -34
  87. package/dist/index.global.js +3144 -1548
  88. package/dist/index.global.min.js +1 -1
  89. package/package.json +1 -1
  90. package/dist/esm/view/element.d.ts +0 -35
  91. package/dist/esm/view/element.js +0 -471
  92. package/dist/esm/view/handle-element.d.ts +0 -24
  93. package/dist/esm/view/point-move-element.d.ts +0 -5
  94. package/dist/esm/view/resize-element.d.ts +0 -4
  95. package/dist/esm/view/resize-element.js +0 -255
  96. package/dist/esm/view/svg-path.d.ts +0 -10
@@ -1,10 +1,10 @@
1
- import { Element, ElementSize, ViewRectVertexes } from '@idraw/types';
2
- export declare function getElementVertexes(elemSize: ElementSize): ViewRectVertexes;
3
- export declare function calcElementVertexes(elemSize: ElementSize): ViewRectVertexes;
4
- export declare function calcElementQueueVertexesQueueInGroup(groupQueue: ElementSize[]): ViewRectVertexes[];
5
- export declare function calcElementVertexesQueueInGroup(targetElem: ElementSize, opts: {
6
- groupQueue: Element<'group'>[];
1
+ import { StrictMaterial, MaterialSize, ViewRectVertexes } from '@idraw/types';
2
+ export declare function getMaterialVertexes(mtrlSize: MaterialSize): ViewRectVertexes;
3
+ export declare function calcMaterialVertexes(mtrlSize: MaterialSize): ViewRectVertexes;
4
+ export declare function calcMaterialQueueVertexesQueueInGroup(groupQueue: MaterialSize[]): ViewRectVertexes[];
5
+ export declare function calcMaterialVertexesQueueInGroup(targetMtrl: MaterialSize, opts: {
6
+ groupQueue: StrictMaterial<'group'>[];
7
7
  }): ViewRectVertexes[];
8
- export declare function calcElementVertexesInGroup(targetElem: ElementSize, opts: {
9
- groupQueue: Element<'group'>[];
8
+ export declare function calcMaterialVertexesInGroup(targetMtrl: MaterialSize, opts: {
9
+ groupQueue: StrictMaterial<'group'>[];
10
10
  }): ViewRectVertexes | null;
@@ -1,48 +1,48 @@
1
- import { getElementRotateVertexes, calcElementCenter, parseAngleToRadian, rotateVertexes, calcElementCenterFromVertexes } from './rotate';
2
- export function getElementVertexes(elemSize) {
3
- const { x, y, h, w } = elemSize;
1
+ import { getMaterialRotateVertexes, calcMaterialCenter, parseAngleToRadian, rotateVertexes, calcMaterialCenterFromVertexes, } from './rotate';
2
+ export function getMaterialVertexes(mtrlSize) {
3
+ const { x, y, height, width } = mtrlSize;
4
4
  return [
5
5
  { x, y },
6
- { x: x + w, y },
7
- { x: x + w, y: y + h },
8
- { x, y: y + h }
6
+ { x: x + width, y },
7
+ { x: x + width, y: y + height },
8
+ { x, y: y + height },
9
9
  ];
10
10
  }
11
- export function calcElementVertexes(elemSize) {
12
- const { x, y, w, h, angle = 0 } = elemSize;
11
+ export function calcMaterialVertexes(mtrlSize) {
12
+ const { x, y, width, height, angle = 0 } = mtrlSize;
13
13
  if (angle === 0) {
14
- return getElementVertexes(elemSize);
14
+ return getMaterialVertexes(mtrlSize);
15
15
  }
16
- return getElementRotateVertexes(elemSize, calcElementCenter({ x, y, w, h, angle }), angle);
16
+ return getMaterialRotateVertexes(mtrlSize, calcMaterialCenter({ x, y, width, height, angle }), angle);
17
17
  }
18
- export function calcElementQueueVertexesQueueInGroup(groupQueue) {
18
+ export function calcMaterialQueueVertexesQueueInGroup(groupQueue) {
19
19
  const vesList = [];
20
20
  let totalX = 0;
21
21
  let totalY = 0;
22
22
  const rotateActionList = [];
23
- const elemQueue = [...groupQueue];
24
- for (let i = 0; i < elemQueue.length; i++) {
25
- const { x, y, w, h, angle = 0 } = elemQueue[i];
23
+ const mtrlQueue = [...groupQueue];
24
+ for (let i = 0; i < mtrlQueue.length; i++) {
25
+ const { x, y, width, height, angle = 0 } = mtrlQueue[i];
26
26
  totalX += x;
27
27
  totalY += y;
28
28
  let ves;
29
29
  if (i === 0) {
30
- const elemSize = { x: totalX, y: totalY, w, h, angle };
31
- ves = calcElementVertexes({ x, y, w, h, angle });
30
+ const mtrlSize = { x: totalX, y: totalY, width, height, angle };
31
+ ves = calcMaterialVertexes({ x, y, width, height, angle });
32
32
  rotateActionList.push({
33
- center: calcElementCenter(elemSize),
33
+ center: calcMaterialCenter(mtrlSize),
34
34
  angle,
35
- radian: parseAngleToRadian(angle)
35
+ radian: parseAngleToRadian(angle),
36
36
  });
37
37
  }
38
38
  else {
39
- const elemSize = { x: totalX, y: totalY, w, h, angle };
40
- ves = getElementVertexes(elemSize);
39
+ const mtrlSize = { x: totalX, y: totalY, width, height, angle };
40
+ ves = getMaterialVertexes(mtrlSize);
41
41
  for (let aIdx = 0; aIdx < rotateActionList.length; aIdx++) {
42
42
  const { center, radian } = rotateActionList[aIdx];
43
43
  ves = rotateVertexes(center, ves, radian);
44
44
  }
45
- const vesCenter = calcElementCenterFromVertexes(ves);
45
+ const vesCenter = calcMaterialCenterFromVertexes(ves);
46
46
  if (angle > 0 || angle < 0) {
47
47
  const radian = parseAngleToRadian(angle);
48
48
  ves = rotateVertexes(vesCenter, ves, radian);
@@ -50,24 +50,24 @@ export function calcElementQueueVertexesQueueInGroup(groupQueue) {
50
50
  rotateActionList.push({
51
51
  center: vesCenter,
52
52
  angle,
53
- radian: parseAngleToRadian(angle)
53
+ radian: parseAngleToRadian(angle),
54
54
  });
55
55
  }
56
56
  vesList.push(ves);
57
57
  }
58
58
  return vesList;
59
59
  }
60
- export function calcElementVertexesQueueInGroup(targetElem, opts) {
60
+ export function calcMaterialVertexesQueueInGroup(targetMtrl, opts) {
61
61
  const { groupQueue } = opts;
62
62
  if (!(groupQueue.length > 0)) {
63
- return [calcElementVertexes(targetElem)];
63
+ return [calcMaterialVertexes(targetMtrl)];
64
64
  }
65
- const elemQueue = [...groupQueue, ...[targetElem]];
66
- const vesList = calcElementQueueVertexesQueueInGroup(elemQueue);
65
+ const mtrlQueue = [...groupQueue, ...[targetMtrl]];
66
+ const vesList = calcMaterialQueueVertexesQueueInGroup(mtrlQueue);
67
67
  return vesList;
68
68
  }
69
- export function calcElementVertexesInGroup(targetElem, opts) {
70
- const vesList = calcElementVertexesQueueInGroup(targetElem, opts);
69
+ export function calcMaterialVertexesInGroup(targetMtrl, opts) {
70
+ const vesList = calcMaterialVertexesQueueInGroup(targetMtrl, opts);
71
71
  const ves = vesList.pop();
72
72
  return ves || null;
73
73
  }
@@ -1,6 +1,2 @@
1
- import type { Data, Element, ElementSize, ViewScaleInfo, ViewSizeInfo, ViewBoxSize } from '@idraw/types';
2
- export declare function calcViewBoxSize(viewElem: Element, opts: {
3
- viewScaleInfo: ViewScaleInfo;
4
- viewSizeInfo: ViewSizeInfo;
5
- }): ViewBoxSize;
6
- export declare function calcVisiableViewSize(data: Data): Omit<ElementSize, 'angle'>;
1
+ import type { Data, MaterialSize } from '@idraw/types';
2
+ export declare function calcVisiableViewSize(data: Data): Omit<MaterialSize, 'angle'>;
@@ -1,75 +1,19 @@
1
- import { getDefaultElementDetailConfig } from './config';
2
- import { calcElementListSize } from './element';
3
- const defaultElemConfig = getDefaultElementDetailConfig();
4
- export function calcViewBoxSize(viewElem, opts) {
5
- const { viewScaleInfo } = opts;
6
- const { scale } = viewScaleInfo;
7
- let { borderRadius } = viewElem.detail;
8
- const { borderDash } = viewElem.detail;
9
- const hasBorderDash = Array.isArray(borderDash) && borderDash.length > 0;
10
- const { boxSizing = defaultElemConfig.boxSizing, borderWidth } = viewElem.detail;
11
- if (Array.isArray(borderWidth)) {
12
- borderRadius = 0;
13
- }
14
- let { x, y, w, h } = viewElem;
15
- let radiusList = [0, 0, 0, 0];
16
- if (typeof borderRadius === 'number') {
17
- const br = borderRadius * scale;
18
- radiusList = [br, br, br, br];
19
- }
20
- else if (Array.isArray(borderRadius) && (borderRadius === null || borderRadius === void 0 ? void 0 : borderRadius.length) === 4) {
21
- radiusList = [borderRadius[0] * scale, borderRadius[1] * scale, borderRadius[2] * scale, borderRadius[3] * scale];
22
- }
23
- let bw = 0;
24
- if (typeof borderWidth === 'number') {
25
- bw = (borderWidth || 0) * scale;
26
- }
27
- if (boxSizing === 'border-box' && !hasBorderDash) {
28
- x = viewElem.x + bw / 2;
29
- y = viewElem.y + bw / 2;
30
- w = viewElem.w - bw;
31
- h = viewElem.h - bw;
32
- }
33
- else if (boxSizing === 'content-box') {
34
- x = viewElem.x - bw / 2;
35
- y = viewElem.y - bw / 2;
36
- w = viewElem.w + bw;
37
- h = viewElem.h + bw;
38
- }
39
- else {
40
- x = viewElem.x;
41
- y = viewElem.y;
42
- w = viewElem.w;
43
- h = viewElem.h;
44
- }
45
- w = Math.max(w, 1);
46
- h = Math.max(h, 1);
47
- radiusList = radiusList.map((r) => {
48
- return Math.min(r, w / 2, h / 2);
49
- });
50
- return {
51
- x,
52
- y,
53
- w,
54
- h,
55
- radiusList
56
- };
57
- }
1
+ import { calcMaterialListSize } from './material';
58
2
  export function calcVisiableViewSize(data) {
59
- var _a, _b;
60
- const outputSize = calcElementListSize(data.elements);
3
+ var _a;
4
+ const outputSize = calcMaterialListSize(data.materials);
61
5
  if (data.layout) {
62
- if (((_b = (_a = data.layout) === null || _a === void 0 ? void 0 : _a.detail) === null || _b === void 0 ? void 0 : _b.overflow) === 'hidden') {
6
+ if (((_a = data.layout) === null || _a === void 0 ? void 0 : _a.overflow) === 'hidden') {
63
7
  outputSize.x = data.layout.x;
64
8
  outputSize.y = data.layout.y;
65
- outputSize.w = data.layout.w;
66
- outputSize.h = data.layout.h;
9
+ outputSize.width = data.layout.width;
10
+ outputSize.height = data.layout.height;
67
11
  }
68
12
  else {
69
13
  outputSize.x = Math.min(outputSize.x, data.layout.x);
70
14
  outputSize.y = Math.min(outputSize.y, data.layout.y);
71
- outputSize.w = Math.max(outputSize.w, data.layout.w);
72
- outputSize.h = Math.max(outputSize.h, data.layout.h);
15
+ outputSize.width = Math.max(outputSize.width, data.layout.width);
16
+ outputSize.height = Math.max(outputSize.height, data.layout.height);
73
17
  }
74
18
  }
75
19
  return outputSize;
@@ -1,4 +1,4 @@
1
- import { Point, PointSize, Data, ViewScaleInfo, ViewSizeInfo, Element, ElementType, ElementSize, ViewContext2D, ViewRectVertexes, ViewRectInfo } from '@idraw/types';
1
+ import { Point, Data, ViewScaleInfo, ViewSizeInfo, StrictMaterial, MaterialType, MaterialSize, ViewContext2D, ViewRectVertexes, BoundingInfo } from '@idraw/types';
2
2
  export declare function calcViewScaleInfo(info: {
3
3
  scale: number;
4
4
  offsetX: number;
@@ -8,7 +8,7 @@ export declare function calcViewScaleInfo(info: {
8
8
  }): ViewScaleInfo;
9
9
  export declare function viewScale(opts: {
10
10
  scale: number;
11
- point: PointSize;
11
+ point: Point;
12
12
  viewScaleInfo: ViewScaleInfo;
13
13
  viewSizeInfo: ViewSizeInfo;
14
14
  }): {
@@ -21,49 +21,52 @@ export declare function viewScroll(opts: {
21
21
  viewScaleInfo: ViewScaleInfo;
22
22
  viewSizeInfo: ViewSizeInfo;
23
23
  }): ViewScaleInfo;
24
- export declare function calcViewElementSize(size: ElementSize, opts: {
24
+ export declare function calcViewMaterialSize(size: MaterialSize, opts: {
25
+ viewScaleInfo: Partial<ViewScaleInfo>;
26
+ }): MaterialSize;
27
+ export declare function calcViewPoint(size: Point, opts: {
25
28
  viewScaleInfo: ViewScaleInfo;
26
- }): ElementSize;
27
- export declare function calcViewPointSize(size: PointSize, opts: {
29
+ }): Point;
30
+ export declare function calcPointFromView(viewPoint: Point, opts: {
28
31
  viewScaleInfo: ViewScaleInfo;
29
- }): PointSize;
32
+ }): Point;
30
33
  export declare function calcViewVertexes(vertexes: ViewRectVertexes, opts: {
31
34
  viewScaleInfo: ViewScaleInfo;
32
35
  viewSizeInfo: ViewSizeInfo;
33
36
  }): ViewRectVertexes;
34
- export declare function isViewPointInElement(p: Point, opts: {
37
+ export declare function isViewPointInMaterial(p: Point, opts: {
35
38
  context2d: ViewContext2D;
36
- element: ElementSize;
39
+ material: MaterialSize;
37
40
  viewScaleInfo: ViewScaleInfo;
38
41
  viewSizeInfo: ViewSizeInfo;
39
42
  }): boolean;
40
- export declare function isViewPointInElementSize(p: Point, elemSize: ElementSize, opts?: {
43
+ export declare function isViewPointInMaterialSize(p: Point, mtrlSize: MaterialSize, opts?: {
41
44
  includeBorder?: boolean;
42
45
  }): boolean;
43
46
  export declare function isViewPointInVertexes(p: Point, vertexes: ViewRectVertexes, opts?: {
44
47
  includeBorder?: boolean;
45
48
  }): boolean;
46
- export declare function getViewPointAtElement(p: Point, opts: {
49
+ export declare function getViewPointAtMaterial(p: Point, opts: {
47
50
  context2d: ViewContext2D;
48
51
  data: Data;
49
52
  viewScaleInfo: ViewScaleInfo;
50
53
  viewSizeInfo: ViewSizeInfo;
51
- groupQueue?: Element<'group'>[];
54
+ groupQueue?: StrictMaterial<'group'>[];
52
55
  }): {
53
56
  index: number;
54
- element: null | Element<ElementType>;
57
+ material: null | StrictMaterial<MaterialType>;
55
58
  groupQueueIndex: number;
56
59
  };
57
- export declare function isElementInView(elem: ElementSize, opts: {
60
+ export declare function isMaterialInView(mtrl: MaterialSize, opts: {
58
61
  viewScaleInfo: ViewScaleInfo;
59
62
  viewSizeInfo: ViewSizeInfo;
60
63
  }): 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'>[];
64
+ export declare function calcMaterialBoundingInfo(mtrlSize: MaterialSize, opts: {
65
+ groupQueue: StrictMaterial<'group'>[];
66
+ }): BoundingInfo;
67
+ export declare function boundingInfoToRangeBoundingInfo(boundingInfo: BoundingInfo): BoundingInfo;
68
+ export declare function calcMaterialViewBoundingInfo(mtrlSize: MaterialSize, opts: {
69
+ groupQueue: StrictMaterial<'group'>[];
67
70
  viewScaleInfo: ViewScaleInfo;
68
71
  range?: boolean;
69
- }): ViewRectInfo;
72
+ }): BoundingInfo;
@@ -1,6 +1,6 @@
1
- import { rotateElementVertexes } from './rotate';
1
+ import { rotateMaterialVertexes } from './rotate';
2
2
  import { checkRectIntersect } from './rect';
3
- import { calcElementVertexesInGroup, calcElementVertexes } from './vertex';
3
+ import { calcMaterialVertexesInGroup, calcMaterialVertexes } from './vertex';
4
4
  import { getCenterFromTwoPoints } from './point';
5
5
  export function calcViewScaleInfo(info, opts) {
6
6
  const { scale, offsetX, offsetY } = info;
@@ -17,7 +17,7 @@ export function calcViewScaleInfo(info, opts) {
17
17
  offsetLeft,
18
18
  offsetTop,
19
19
  offsetRight,
20
- offsetBottom
20
+ offsetBottom,
21
21
  };
22
22
  return newScaleInfo;
23
23
  }
@@ -31,7 +31,7 @@ export function viewScale(opts) {
31
31
  const moveY = y0 - y0 * scaleDiff + (offsetTop * scaleDiff - offsetTop);
32
32
  return {
33
33
  moveX,
34
- moveY
34
+ moveY,
35
35
  };
36
36
  }
37
37
  export function viewScroll(opts) {
@@ -53,45 +53,56 @@ export function viewScroll(opts) {
53
53
  offsetTop,
54
54
  offsetLeft,
55
55
  offsetRight,
56
- offsetBottom
56
+ offsetBottom,
57
57
  };
58
58
  }
59
- export function calcViewElementSize(size, opts) {
59
+ export function calcViewMaterialSize(size, opts) {
60
60
  const { viewScaleInfo } = opts;
61
- const { x, y, w, h, angle } = size;
62
- const { scale, offsetTop, offsetLeft } = viewScaleInfo;
61
+ const { id, x, y, width, height, angle } = size;
62
+ const { scale = 1, offsetTop = 0, offsetLeft = 0 } = viewScaleInfo;
63
63
  const newSize = {
64
+ id,
64
65
  x: x * scale + offsetLeft,
65
66
  y: y * scale + offsetTop,
66
- w: w * scale,
67
- h: h * scale,
68
- angle
67
+ width: width * scale,
68
+ height: height * scale,
69
+ angle,
69
70
  };
70
71
  return newSize;
71
72
  }
72
- export function calcViewPointSize(size, opts) {
73
+ export function calcViewPoint(size, opts) {
73
74
  const { viewScaleInfo } = opts;
74
75
  const { x, y } = size;
75
76
  const { scale, offsetTop, offsetLeft } = viewScaleInfo;
76
77
  const newSize = {
77
78
  x: x * scale + offsetLeft,
78
- y: y * scale + offsetTop
79
+ y: y * scale + offsetTop,
80
+ };
81
+ return newSize;
82
+ }
83
+ export function calcPointFromView(viewPoint, opts) {
84
+ const { viewScaleInfo } = opts;
85
+ const { x, y } = viewPoint;
86
+ const { scale, offsetTop, offsetLeft } = viewScaleInfo;
87
+ const newSize = {
88
+ x: (x - offsetLeft) / scale,
89
+ y: (y - offsetTop) / scale,
79
90
  };
80
91
  return newSize;
81
92
  }
82
93
  export function calcViewVertexes(vertexes, opts) {
83
94
  return [
84
- calcViewPointSize(vertexes[0], opts),
85
- calcViewPointSize(vertexes[1], opts),
86
- calcViewPointSize(vertexes[2], opts),
87
- calcViewPointSize(vertexes[3], opts)
95
+ calcViewPoint(vertexes[0], opts),
96
+ calcViewPoint(vertexes[1], opts),
97
+ calcViewPoint(vertexes[2], opts),
98
+ calcViewPoint(vertexes[3], opts),
88
99
  ];
89
100
  }
90
- export function isViewPointInElement(p, opts) {
91
- const { context2d: ctx, element: elem, viewScaleInfo } = opts;
92
- const { angle = 0 } = elem;
93
- const { x, y, w, h } = calcViewElementSize(elem, { viewScaleInfo });
94
- const vertexes = rotateElementVertexes({ x, y, w, h, angle });
101
+ export function isViewPointInMaterial(p, opts) {
102
+ const { context2d: ctx, material: mtrl, viewScaleInfo } = opts;
103
+ const { angle = 0 } = mtrl;
104
+ const { x, y, width, height } = calcViewMaterialSize(mtrl, { viewScaleInfo });
105
+ const vertexes = rotateMaterialVertexes({ x, y, width, height, angle });
95
106
  if (vertexes.length >= 2) {
96
107
  ctx.beginPath();
97
108
  ctx.moveTo(vertexes[0].x, vertexes[0].y);
@@ -105,8 +116,8 @@ export function isViewPointInElement(p, opts) {
105
116
  }
106
117
  return false;
107
118
  }
108
- export function isViewPointInElementSize(p, elemSize, opts) {
109
- const vertexes = calcElementVertexes(elemSize);
119
+ export function isViewPointInMaterialSize(p, mtrlSize, opts) {
120
+ const vertexes = calcMaterialVertexes(mtrlSize);
110
121
  return isViewPointInVertexes(p, vertexes, opts);
111
122
  }
112
123
  export function isViewPointInVertexes(p, vertexes, opts) {
@@ -124,13 +135,13 @@ export function isViewPointInVertexes(p, vertexes, opts) {
124
135
  }
125
136
  return false;
126
137
  }
127
- export function getViewPointAtElement(p, opts) {
128
- var _a, _b, _c;
138
+ export function getViewPointAtMaterial(p, opts) {
139
+ var _a, _b;
129
140
  const { context2d: ctx, data, viewScaleInfo, viewSizeInfo, groupQueue } = opts;
130
141
  const result = {
131
142
  index: -1,
132
- element: null,
133
- groupQueueIndex: -1
143
+ material: null,
144
+ groupQueueIndex: -1,
134
145
  };
135
146
  if (groupQueue && Array.isArray(groupQueue) && (groupQueue === null || groupQueue === void 0 ? void 0 : groupQueue.length) > 0) {
136
147
  for (let gIdx = groupQueue.length - 1; gIdx >= 0; gIdx--) {
@@ -143,22 +154,22 @@ export function getViewPointAtElement(p, opts) {
143
154
  totalAngle += groupQueue[i].angle || 0;
144
155
  }
145
156
  const lastGroup = groupQueue[gIdx];
146
- if (lastGroup && lastGroup.type === 'group' && Array.isArray((_a = lastGroup.detail) === null || _a === void 0 ? void 0 : _a.children)) {
147
- for (let i = 0; i < lastGroup.detail.children.length; i++) {
148
- const child = lastGroup.detail.children[i];
149
- if (((_b = child === null || child === void 0 ? void 0 : child.operations) === null || _b === void 0 ? void 0 : _b.invisible) === true) {
157
+ if (lastGroup && lastGroup.type === 'group' && Array.isArray(lastGroup === null || lastGroup === void 0 ? void 0 : lastGroup.children)) {
158
+ for (let i = 0; i < lastGroup.children.length; i++) {
159
+ const child = lastGroup.children[i];
160
+ if (((_a = child === null || child === void 0 ? void 0 : child.operations) === null || _a === void 0 ? void 0 : _a.invisible) === true) {
150
161
  continue;
151
162
  }
152
163
  if (child) {
153
- const elemSize = {
164
+ const mtrlSize = {
154
165
  x: totalX + child.x,
155
166
  y: totalY + child.y,
156
- w: child.w,
157
- h: child.h,
158
- angle: totalAngle + (child.angle || 0)
167
+ width: child.width,
168
+ height: child.height,
169
+ angle: totalAngle + (child.angle || 0),
159
170
  };
160
- if (isViewPointInElement(p, { context2d: ctx, element: elemSize, viewScaleInfo, viewSizeInfo })) {
161
- result.element = child;
171
+ if (isViewPointInMaterial(p, { context2d: ctx, material: mtrlSize, viewScaleInfo, viewSizeInfo })) {
172
+ result.material = child;
162
173
  if (gIdx < groupQueue.length - 1 || child.type !== 'group') {
163
174
  result.groupQueueIndex = gIdx;
164
175
  }
@@ -170,44 +181,44 @@ export function getViewPointAtElement(p, opts) {
170
181
  }
171
182
  }
172
183
  }
173
- if (result.element) {
184
+ if (result.material) {
174
185
  break;
175
186
  }
176
187
  }
177
188
  }
178
- if (result.element) {
189
+ if (result.material) {
179
190
  return result;
180
191
  }
181
- for (let i = data.elements.length - 1; i >= 0; i--) {
182
- const elem = data.elements[i];
183
- if (((_c = elem === null || elem === void 0 ? void 0 : elem.operations) === null || _c === void 0 ? void 0 : _c.invisible) === true) {
192
+ for (let i = data.materials.length - 1; i >= 0; i--) {
193
+ const mtrl = data.materials[i];
194
+ if (((_b = mtrl === null || mtrl === void 0 ? void 0 : mtrl.operations) === null || _b === void 0 ? void 0 : _b.invisible) === true) {
184
195
  continue;
185
196
  }
186
- if (isViewPointInElement(p, { context2d: ctx, element: elem, viewScaleInfo, viewSizeInfo })) {
197
+ if (isViewPointInMaterial(p, { context2d: ctx, material: mtrl, viewScaleInfo, viewSizeInfo })) {
187
198
  result.index = i;
188
- result.element = elem;
199
+ result.material = mtrl;
189
200
  break;
190
201
  }
191
202
  }
192
203
  return result;
193
204
  }
194
- export function isElementInView(elem, opts) {
205
+ export function isMaterialInView(mtrl, opts) {
195
206
  const { viewSizeInfo, viewScaleInfo } = opts;
196
207
  const { width, height } = viewSizeInfo;
197
- const { angle } = elem;
198
- const { x, y, w, h } = calcViewElementSize(elem, { viewScaleInfo });
199
- const ves = rotateElementVertexes({ x, y, w, h, angle });
200
- const viewSize = { x: 0, y: 0, w: width, h: height };
201
- const elemStartX = Math.min(ves[0].x, ves[1].x, ves[2].x, ves[3].x);
202
- const elemStartY = Math.min(ves[0].y, ves[1].y, ves[2].y, ves[3].y);
203
- const elemEndX = Math.max(ves[0].x, ves[1].x, ves[2].x, ves[3].x);
204
- const elemEndY = Math.max(ves[0].y, ves[1].y, ves[2].y, ves[3].y);
205
- const elemSize = { x: elemStartX, y: elemStartY, w: elemEndX - elemStartX, h: elemEndY - elemStartY };
206
- return checkRectIntersect(viewSize, elemSize);
208
+ const { angle } = mtrl;
209
+ const { x, y, width: w, height: h } = calcViewMaterialSize(mtrl, { viewScaleInfo });
210
+ const ves = rotateMaterialVertexes({ x, y, width: w, height: h, angle });
211
+ const viewSize = { x: 0, y: 0, width, height };
212
+ const mtrlStartX = Math.min(ves[0].x, ves[1].x, ves[2].x, ves[3].x);
213
+ const mtrlStartY = Math.min(ves[0].y, ves[1].y, ves[2].y, ves[3].y);
214
+ const mtrlEndX = Math.max(ves[0].x, ves[1].x, ves[2].x, ves[3].x);
215
+ const mtrlEndY = Math.max(ves[0].y, ves[1].y, ves[2].y, ves[3].y);
216
+ const mtrlSize = { x: mtrlStartX, y: mtrlStartY, width: mtrlEndX - mtrlStartX, height: mtrlEndY - mtrlStartY };
217
+ return checkRectIntersect(viewSize, mtrlSize);
207
218
  }
208
- export function calcElementOriginRectInfo(elemSize, opts) {
219
+ export function calcMaterialBoundingInfo(mtrlSize, opts) {
209
220
  const { groupQueue } = opts;
210
- const vertexes = calcElementVertexesInGroup(elemSize, { groupQueue });
221
+ const vertexes = calcMaterialVertexesInGroup(mtrlSize, { groupQueue });
211
222
  const top = getCenterFromTwoPoints(vertexes[0], vertexes[1]);
212
223
  const right = getCenterFromTwoPoints(vertexes[1], vertexes[2]);
213
224
  const bottom = getCenterFromTwoPoints(vertexes[2], vertexes[3]);
@@ -222,9 +233,9 @@ export function calcElementOriginRectInfo(elemSize, opts) {
222
233
  const minY = Math.min(topLeft.y, topRight.y, bottomRight.y, bottomLeft.y);
223
234
  const center = {
224
235
  x: (maxX + minX) / 2,
225
- y: (maxY + minY) / 2
236
+ y: (maxY + minY) / 2,
226
237
  };
227
- const rectInfo = {
238
+ const boundingBox = {
228
239
  center,
229
240
  topLeft,
230
241
  topRight,
@@ -233,16 +244,16 @@ export function calcElementOriginRectInfo(elemSize, opts) {
233
244
  top,
234
245
  right,
235
246
  left,
236
- bottom
247
+ bottom,
237
248
  };
238
- return rectInfo;
249
+ return boundingBox;
239
250
  }
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 };
251
+ export function boundingInfoToRangeBoundingInfo(boundingInfo) {
252
+ const rangeMaxX = Math.max(boundingInfo.topLeft.x, boundingInfo.topRight.x, boundingInfo.bottomRight.x, boundingInfo.bottomLeft.x);
253
+ const rangeMaxY = Math.max(boundingInfo.topLeft.y, boundingInfo.topRight.y, boundingInfo.bottomRight.y, boundingInfo.bottomLeft.y);
254
+ const rangeMinX = Math.min(boundingInfo.topLeft.x, boundingInfo.topRight.x, boundingInfo.bottomRight.x, boundingInfo.bottomLeft.x);
255
+ const rangeMinY = Math.min(boundingInfo.topLeft.y, boundingInfo.topRight.y, boundingInfo.bottomRight.y, boundingInfo.bottomLeft.y);
256
+ const rangeCenter = { x: boundingInfo.center.x, y: boundingInfo.center.y };
246
257
  const rangeTopLeft = { x: rangeMinX, y: rangeMinY };
247
258
  const rangeTopRight = { x: rangeMaxX, y: rangeMinY };
248
259
  const rangeBottomRight = { x: rangeMaxX, y: rangeMaxY };
@@ -251,7 +262,7 @@ export function originRectInfoToRangeRectInfo(originRectInfo) {
251
262
  const rangeBottom = getCenterFromTwoPoints(rangeBottomLeft, rangeBottomRight);
252
263
  const rangeLeft = getCenterFromTwoPoints(rangeTopLeft, rangeBottomLeft);
253
264
  const rangeRight = getCenterFromTwoPoints(rangeTopRight, rangeBottomRight);
254
- const rangeRectInfo = {
265
+ const rangeBoundingInfo = {
255
266
  center: rangeCenter,
256
267
  topLeft: rangeTopLeft,
257
268
  topRight: rangeTopRight,
@@ -260,31 +271,31 @@ export function originRectInfoToRangeRectInfo(originRectInfo) {
260
271
  top: rangeTop,
261
272
  right: rangeRight,
262
273
  left: rangeLeft,
263
- bottom: rangeBottom
274
+ bottom: rangeBottom,
264
275
  };
265
- return rangeRectInfo;
276
+ return rangeBoundingInfo;
266
277
  }
267
- export function calcElementViewRectInfo(elemSize, opts) {
278
+ export function calcMaterialViewBoundingInfo(mtrlSize, opts) {
268
279
  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 })
280
+ const boundingInfo = calcMaterialBoundingInfo(mtrlSize, { groupQueue });
281
+ const { center, top, bottom, left, right, topLeft, topRight, bottomLeft, bottomRight } = boundingInfo;
282
+ const viewBoundingInfo = {
283
+ center: calcViewPoint(center, { viewScaleInfo }),
284
+ topLeft: calcViewPoint(topLeft, { viewScaleInfo }),
285
+ topRight: calcViewPoint(topRight, { viewScaleInfo }),
286
+ bottomLeft: calcViewPoint(bottomLeft, { viewScaleInfo }),
287
+ bottomRight: calcViewPoint(bottomRight, { viewScaleInfo }),
288
+ top: calcViewPoint(top, { viewScaleInfo }),
289
+ right: calcViewPoint(right, { viewScaleInfo }),
290
+ left: calcViewPoint(left, { viewScaleInfo }),
291
+ bottom: calcViewPoint(bottom, { viewScaleInfo }),
281
292
  };
282
293
  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 };
294
+ const viewMaxX = Math.max(viewBoundingInfo.topLeft.x, viewBoundingInfo.topRight.x, viewBoundingInfo.bottomRight.x, viewBoundingInfo.bottomLeft.x);
295
+ const viewMaxY = Math.max(viewBoundingInfo.topLeft.y, viewBoundingInfo.topRight.y, viewBoundingInfo.bottomRight.y, viewBoundingInfo.bottomLeft.y);
296
+ const viewMinX = Math.min(viewBoundingInfo.topLeft.x, viewBoundingInfo.topRight.x, viewBoundingInfo.bottomRight.x, viewBoundingInfo.bottomLeft.x);
297
+ const viewMinY = Math.min(viewBoundingInfo.topLeft.y, viewBoundingInfo.topRight.y, viewBoundingInfo.bottomRight.y, viewBoundingInfo.bottomLeft.y);
298
+ const rangeCenter = { x: viewBoundingInfo.center.x, y: viewBoundingInfo.center.y };
288
299
  const rangeTopLeft = { x: viewMinX, y: viewMinY };
289
300
  const rangeTopRight = { x: viewMaxX, y: viewMinY };
290
301
  const rangeBottomRight = { x: viewMaxX, y: viewMaxY };
@@ -293,7 +304,7 @@ export function calcElementViewRectInfo(elemSize, opts) {
293
304
  const rangeBottom = getCenterFromTwoPoints(rangeBottomLeft, rangeBottomRight);
294
305
  const rangeLeft = getCenterFromTwoPoints(rangeTopLeft, rangeBottomLeft);
295
306
  const rangeRight = getCenterFromTwoPoints(rangeTopRight, rangeBottomRight);
296
- const rangeRectInfo = {
307
+ const rangeBoundingInfo = {
297
308
  center: rangeCenter,
298
309
  topLeft: rangeTopLeft,
299
310
  topRight: rangeTopRight,
@@ -302,9 +313,9 @@ export function calcElementViewRectInfo(elemSize, opts) {
302
313
  top: rangeTop,
303
314
  right: rangeRight,
304
315
  left: rangeLeft,
305
- bottom: rangeBottom
316
+ bottom: rangeBottom,
306
317
  };
307
- return rangeRectInfo;
318
+ return rangeBoundingInfo;
308
319
  }
309
- return viewRectInfo;
320
+ return viewBoundingInfo;
310
321
  }