@idraw/util 0.4.0-beta.9 → 0.4.0

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 (105) hide show
  1. package/dist/esm/index.d.ts +46 -31
  2. package/dist/esm/index.js +46 -31
  3. package/dist/esm/{lib → tool}/color.js +9 -6
  4. package/dist/esm/{lib → tool}/event.d.ts +1 -0
  5. package/dist/esm/{lib → tool}/event.js +3 -0
  6. package/dist/esm/tool/flat-object.d.ts +6 -0
  7. package/dist/esm/tool/flat-object.js +28 -0
  8. package/dist/esm/tool/get-set-del.d.ts +4 -0
  9. package/dist/esm/tool/get-set-del.js +65 -0
  10. package/dist/esm/{lib → tool}/html.d.ts +1 -1
  11. package/dist/esm/{lib → tool}/html.js +6 -2
  12. package/dist/esm/{lib → tool}/istype.d.ts +1 -0
  13. package/dist/esm/{lib → tool}/istype.js +3 -0
  14. package/dist/esm/tool/merge.d.ts +1 -0
  15. package/dist/esm/tool/merge.js +17 -0
  16. package/dist/esm/tool/omit.d.ts +1 -0
  17. package/dist/esm/tool/omit.js +7 -0
  18. package/dist/esm/tool/store.d.ts +16 -0
  19. package/dist/esm/{lib → tool}/store.js +17 -5
  20. package/dist/esm/tool/unflat-object.d.ts +3 -0
  21. package/dist/esm/tool/unflat-object.js +91 -0
  22. package/dist/esm/{lib → tool}/uuid.d.ts +1 -1
  23. package/dist/esm/tool/uuid.js +39 -0
  24. package/dist/esm/view/box.d.ts +2 -0
  25. package/dist/esm/view/box.js +173 -0
  26. package/dist/esm/{lib → view}/canvas.d.ts +0 -1
  27. package/dist/esm/view/canvas.js +57 -0
  28. package/dist/esm/{lib → view}/check.js +14 -14
  29. package/dist/esm/{lib → view}/config.js +2 -2
  30. package/dist/esm/{lib → view}/context2d.d.ts +4 -0
  31. package/dist/esm/{lib → view}/context2d.js +20 -0
  32. package/dist/esm/view/controller.d.ts +12 -0
  33. package/dist/esm/view/controller.js +321 -0
  34. package/dist/esm/{lib → view}/data.d.ts +1 -0
  35. package/dist/esm/{lib → view}/data.js +43 -22
  36. package/dist/esm/{lib → view}/element.d.ts +5 -0
  37. package/dist/esm/{lib → view}/element.js +66 -5
  38. package/dist/esm/view/flat.d.ts +2 -0
  39. package/dist/esm/view/flat.js +133 -0
  40. package/dist/esm/view/group.d.ts +3 -0
  41. package/dist/esm/view/group.js +81 -0
  42. package/dist/esm/{lib → view}/handle-element.d.ts +11 -1
  43. package/dist/esm/{lib → view}/handle-element.js +102 -51
  44. package/dist/esm/view/handle-global.d.ts +4 -0
  45. package/dist/esm/view/handle-global.js +28 -0
  46. package/dist/esm/view/handle-layout.d.ts +4 -0
  47. package/dist/esm/view/handle-layout.js +28 -0
  48. package/dist/esm/{lib → view}/is.d.ts +3 -1
  49. package/dist/esm/{lib → view}/is.js +22 -6
  50. package/dist/esm/view/modify-record.d.ts +4 -0
  51. package/dist/esm/view/modify-record.js +10 -0
  52. package/dist/esm/view/point-move-element.d.ts +5 -0
  53. package/dist/esm/view/point-move-element.js +26 -0
  54. package/dist/esm/view/position.d.ts +15 -0
  55. package/dist/esm/view/position.js +79 -0
  56. package/dist/esm/view/rect.js +11 -0
  57. package/dist/esm/view/resize-element.d.ts +4 -0
  58. package/dist/esm/view/resize-element.js +255 -0
  59. package/dist/esm/{lib → view}/rotate.js +8 -13
  60. package/dist/esm/view/text.d.ts +1 -0
  61. package/dist/esm/view/text.js +4 -0
  62. package/dist/esm/{lib → view}/view-box.js +3 -1
  63. package/dist/esm/{lib → view}/view-calc.d.ts +16 -3
  64. package/dist/esm/{lib → view}/view-calc.js +127 -3
  65. package/dist/esm/view/view-content.d.ts +14 -0
  66. package/dist/esm/view/view-content.js +88 -0
  67. package/dist/index.global.js +1938 -346
  68. package/dist/index.global.min.js +1 -1
  69. package/package.json +2 -2
  70. package/dist/esm/lib/canvas.js +0 -81
  71. package/dist/esm/lib/controller.d.ts +0 -6
  72. package/dist/esm/lib/controller.js +0 -103
  73. package/dist/esm/lib/rect.js +0 -11
  74. package/dist/esm/lib/resize-element.d.ts +0 -2
  75. package/dist/esm/lib/resize-element.js +0 -101
  76. package/dist/esm/lib/store.d.ts +0 -11
  77. package/dist/esm/lib/uuid.js +0 -31
  78. /package/dist/esm/{lib → tool}/color.d.ts +0 -0
  79. /package/dist/esm/{lib → tool}/file.d.ts +0 -0
  80. /package/dist/esm/{lib → tool}/file.js +0 -0
  81. /package/dist/esm/{lib → tool}/image.d.ts +0 -0
  82. /package/dist/esm/{lib → tool}/image.js +0 -0
  83. /package/dist/esm/{lib → tool}/number.d.ts +0 -0
  84. /package/dist/esm/{lib → tool}/number.js +0 -0
  85. /package/dist/esm/{lib → tool}/time.d.ts +0 -0
  86. /package/dist/esm/{lib → tool}/time.js +0 -0
  87. /package/dist/esm/{lib → view}/check.d.ts +0 -0
  88. /package/dist/esm/{lib → view}/config.d.ts +0 -0
  89. /package/dist/esm/{lib → view}/load.d.ts +0 -0
  90. /package/dist/esm/{lib → view}/load.js +0 -0
  91. /package/dist/esm/{lib → view}/matrix.d.ts +0 -0
  92. /package/dist/esm/{lib → view}/matrix.js +0 -0
  93. /package/dist/esm/{lib → view}/middleware.d.ts +0 -0
  94. /package/dist/esm/{lib → view}/middleware.js +0 -0
  95. /package/dist/esm/{lib → view}/parser.d.ts +0 -0
  96. /package/dist/esm/{lib → view}/parser.js +0 -0
  97. /package/dist/esm/{lib → view}/point.d.ts +0 -0
  98. /package/dist/esm/{lib → view}/point.js +0 -0
  99. /package/dist/esm/{lib → view}/rect.d.ts +0 -0
  100. /package/dist/esm/{lib → view}/rotate.d.ts +0 -0
  101. /package/dist/esm/{lib → view}/svg-path.d.ts +0 -0
  102. /package/dist/esm/{lib → view}/svg-path.js +0 -0
  103. /package/dist/esm/{lib → view}/vertex.d.ts +0 -0
  104. /package/dist/esm/{lib → view}/vertex.js +0 -0
  105. /package/dist/esm/{lib → view}/view-box.d.ts +0 -0
@@ -1,28 +1,14 @@
1
1
  var iDrawUtil = function(exports) {
2
- "use strict";var __accessCheck = (obj, member, msg) => {
3
- if (!member.has(obj))
4
- throw TypeError("Cannot " + msg);
5
- };
6
- var __privateGet = (obj, member, getter) => {
7
- __accessCheck(obj, member, "read from private field");
8
- return getter ? getter.call(obj) : member.get(obj);
9
- };
10
- var __privateAdd = (obj, member, value) => {
11
- if (member.has(obj))
12
- throw TypeError("Cannot add the same private member more than once");
13
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
14
- };
15
- var __privateSet = (obj, member, value, setter) => {
16
- __accessCheck(obj, member, "write to private field");
17
- setter ? setter.call(obj, value) : member.set(obj, value);
18
- return value;
19
- };
20
- var __privateMethod = (obj, member, method) => {
21
- __accessCheck(obj, member, "access private method");
22
- return method;
2
+ "use strict";var __typeError = (msg) => {
3
+ throw TypeError(msg);
23
4
  };
5
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
6
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
7
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
8
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
9
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
24
10
 
25
- var _ctx, _opts, _listeners, _temp, _backUpDefaultStorage, _createTempStorage, createTempStorage_fn;
11
+ var _ctx, _opts, _listeners, _temp, _backUpDefaultStorage, _static, _Store_instances, createTempStorage_fn;
26
12
  function compose(middleware) {
27
13
  return function(context, next) {
28
14
  return dispatch(0);
@@ -31,8 +17,7 @@ var __privateMethod = (obj, member, method) => {
31
17
  if (i === middleware.length && next) {
32
18
  fn = next;
33
19
  }
34
- if (!fn)
35
- return Promise.resolve();
20
+ if (!fn) return Promise.resolve();
36
21
  try {
37
22
  return Promise.resolve(fn(context, dispatch.bind(null, i + 1)));
38
23
  } catch (err) {
@@ -158,13 +143,13 @@ var __privateMethod = (obj, member, method) => {
158
143
  downloadLink = null;
159
144
  }
160
145
  function toColorHexNum(color2) {
161
- return parseInt(color2.replace(/^\#/, "0x"));
146
+ return parseInt(color2.replace(/^#/, "0x"));
162
147
  }
163
148
  function toColorHexStr(color2) {
164
149
  return "#" + color2.toString(16);
165
150
  }
166
151
  function isColorStr(color2) {
167
- return typeof color2 === "string" && (/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(color2) || /^[a-z]{1,}$/i.test(color2));
152
+ return typeof color2 === "string" && (/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(color2) || /^[a-z]{1,}$/i.test(color2));
168
153
  }
169
154
  const colorNameMap = {
170
155
  aliceblue: "#f0f8ff",
@@ -321,6 +306,8 @@ var __privateMethod = (obj, member, method) => {
321
306
  let css = "transparent";
322
307
  if (typeof color2 === "string") {
323
308
  css = color2;
309
+ } else if ((color2 == null ? void 0 : color2.stops.length) === 1) {
310
+ css = color2.stops[0].color;
324
311
  } else if ((color2 == null ? void 0 : color2.type) === "linear-gradient") {
325
312
  const items = [];
326
313
  if (typeof color2.angle === "number") {
@@ -368,13 +355,13 @@ var __privateMethod = (obj, member, method) => {
368
355
  return hex;
369
356
  }
370
357
  let hexAlpha = 1;
371
- const regHex1 = /^\#[0-9a-f]{6,6}$/i;
372
- const regHex2 = /^\#[0-9a-f]{8,8}$/i;
358
+ const regHex1 = /^#[0-9a-f]{6,6}$/i;
359
+ const regHex2 = /^#[0-9a-f]{8,8}$/i;
373
360
  let result = hex;
374
361
  if (regHex1.test(hex)) {
375
- hexAlpha = parseInt(hex.substring(5, 7).replace(/^\#/, "0x"));
362
+ hexAlpha = parseInt(hex.substring(5, 7).replace(/^#/, "0x"));
376
363
  } else if (regHex2.test(hex)) {
377
- hexAlpha = parseInt(hex.substring(7, 9).replace(/^\#/, "0x"));
364
+ hexAlpha = parseInt(hex.substring(7, 9).replace(/^#/, "0x"));
378
365
  result = hex.substring(0, 7);
379
366
  }
380
367
  hexAlpha = hexAlpha * alpha;
@@ -390,30 +377,38 @@ var __privateMethod = (obj, member, method) => {
390
377
  }
391
378
  return `${_createStr()}${_createStr()}-${_createStr()}-${_createStr()}-${_createStr()}-${_createStr()}${_createStr()}${_createStr()}`;
392
379
  }
393
- function limitHexStr(str) {
380
+ function limitHexStr(str, seed) {
394
381
  let count = 0;
395
382
  for (let i = 0; i < str.length; i++) {
396
- count += str.charCodeAt(i) * str.charCodeAt(i) * i * i;
383
+ count += str.charCodeAt(i);
397
384
  }
398
- return count.toString(16).substring(0, 4);
385
+ return (count + seed).toString(16).substring(0, 4);
399
386
  }
400
- function createAssetId(assetStr) {
387
+ function sumCharCodes(str) {
388
+ let sum = 0;
389
+ for (let i = 0; i < str.length; i++) {
390
+ sum += str.charCodeAt(i);
391
+ }
392
+ return sum;
393
+ }
394
+ function createAssetId(assetStr, elemUUID) {
401
395
  const len = assetStr.length;
396
+ const seed = sumCharCodes(elemUUID);
402
397
  const mid = Math.floor(len / 2);
403
- const start4 = assetStr.substring(0, 4).padEnd(4, "0");
404
- const end4 = assetStr.substring(0, 4).padEnd(4, "0");
405
- const str1 = limitHexStr(len.toString(16).padEnd(4, start4));
406
- const str2 = limitHexStr(assetStr.substring(mid - 4, mid).padEnd(4, start4)).padEnd(4, "f");
407
- const str3 = limitHexStr(assetStr.substring(mid - 8, mid - 4).padEnd(4, start4)).padEnd(4, "f");
408
- const str4 = limitHexStr(assetStr.substring(mid - 12, mid - 8).padEnd(4, start4)).padEnd(4, "f");
409
- const str5 = limitHexStr(assetStr.substring(mid - 16, mid - 12).padEnd(4, end4)).padEnd(4, "f");
410
- const str6 = limitHexStr(assetStr.substring(mid, mid + 4).padEnd(4, end4)).padEnd(4, "f");
411
- const str7 = limitHexStr(assetStr.substring(mid + 4, mid + 8).padEnd(4, end4)).padEnd(4, "f");
412
- const str8 = limitHexStr(end4.padEnd(4, start4).padEnd(4, end4));
398
+ const start4 = assetStr.substring(0, 4).padStart(4, "0");
399
+ const end4 = assetStr.substring(0, 4).padStart(4, "0");
400
+ const str1 = limitHexStr(len.toString(16).padStart(4, start4), seed).padStart(4, "0");
401
+ const str2 = limitHexStr(assetStr.substring(mid - 4, mid).padStart(4, start4), seed).padStart(4, "0");
402
+ const str3 = limitHexStr(assetStr.substring(mid - 8, mid - 4).padStart(4, start4), seed).padStart(4, "0");
403
+ const str4 = limitHexStr(assetStr.substring(mid - 12, mid - 8).padStart(4, start4), seed).padStart(4, "0");
404
+ const str5 = limitHexStr(assetStr.substring(mid - 16, mid - 12).padStart(4, end4), seed).padStart(4, "0");
405
+ const str6 = limitHexStr(assetStr.substring(mid, mid + 4).padStart(4, end4), seed).padStart(4, "0");
406
+ const str7 = limitHexStr(assetStr.substring(mid + 4, mid + 8).padStart(4, end4), seed).padStart(4, "0");
407
+ const str8 = limitHexStr(end4.padStart(4, start4).padStart(4, end4), seed);
413
408
  return `@assets/${str1}${str2}-${str3}-${str4}-${str5}-${str6}${str7}${str8}`;
414
409
  }
415
410
  function isAssetId(id) {
416
- return /^@assets\/[0-9a-z]{8,8}\-[0-9a-z]{4,4}\-[0-9a-z]{4,4}\-[0-9a-z]{4,4}\-[0-9a-z]{12,12}$/.test(`${id}`);
411
+ return /^@assets\/[0-9a-z-]{0,}$/.test(`${id}`);
417
412
  }
418
413
  function deepClone(target) {
419
414
  function _clone(t) {
@@ -454,6 +449,15 @@ var __privateMethod = (obj, member, method) => {
454
449
  _resetUUID(elem);
455
450
  return elem;
456
451
  }
452
+ function deepCloneData(data) {
453
+ const { elements, ...restData } = data;
454
+ return {
455
+ ...deepClone(restData),
456
+ ...{
457
+ elements: elements.map((elem) => deepCloneElement(elem))
458
+ }
459
+ };
460
+ }
457
461
  function is$1(target) {
458
462
  return Object.prototype.toString.call(target).replace(/[\]|\[]{1,1}/gi, "").split(" ")[1];
459
463
  }
@@ -467,7 +471,7 @@ var __privateMethod = (obj, member, method) => {
467
471
  elems.forEach((elem) => {
468
472
  if (elem.type === "image" && elem.detail.src) {
469
473
  const src = elem.detail.src;
470
- const assetUUID = createAssetId(src);
474
+ const assetUUID = createAssetId(src, elem.uuid);
471
475
  if (!assets[assetUUID]) {
472
476
  assets[assetUUID] = {
473
477
  type: "image",
@@ -477,7 +481,7 @@ var __privateMethod = (obj, member, method) => {
477
481
  elem.detail.src = assetUUID;
478
482
  } else if (elem.type === "svg") {
479
483
  const svg2 = elem.detail.svg;
480
- const assetUUID = createAssetId(svg2);
484
+ const assetUUID = createAssetId(svg2, elem.uuid);
481
485
  if (!assets[assetUUID]) {
482
486
  assets[assetUUID] = {
483
487
  type: "svg",
@@ -487,7 +491,7 @@ var __privateMethod = (obj, member, method) => {
487
491
  elem.detail.svg = assetUUID;
488
492
  } else if (elem.type === "html") {
489
493
  const html2 = elem.detail.html;
490
- const assetUUID = createAssetId(html2);
494
+ const assetUUID = createAssetId(html2, elem.uuid);
491
495
  if (!assets[assetUUID]) {
492
496
  assets[assetUUID] = {
493
497
  type: "html",
@@ -525,8 +529,8 @@ var __privateMethod = (obj, member, method) => {
525
529
  type: "image",
526
530
  value: loadItemMap[src].source
527
531
  };
528
- } else {
529
- const assetUUID = createAssetId(src);
532
+ } else if (!assets[src]) {
533
+ const assetUUID = createAssetId(src, elem.uuid);
530
534
  if (!assets[assetUUID]) {
531
535
  assets[assetUUID] = {
532
536
  type: "image",
@@ -537,34 +541,38 @@ var __privateMethod = (obj, member, method) => {
537
541
  }
538
542
  } else if (elem.type === "svg") {
539
543
  const svg2 = elem.detail.svg;
540
- const assetUUID = createAssetId(svg2);
541
544
  if (isAssetId(svg2) && !assets[svg2] && loadItemMap[svg2] && typeof ((_b = loadItemMap[svg2]) == null ? void 0 : _b.source) === "string") {
542
545
  assets[svg2] = {
543
546
  type: "svg",
544
547
  value: loadItemMap[svg2].source
545
548
  };
546
- } else if (!assets[assetUUID]) {
547
- assets[assetUUID] = {
548
- type: "svg",
549
- value: svg2
550
- };
549
+ } else if (!assets[svg2]) {
550
+ const assetUUID = createAssetId(svg2, elem.uuid);
551
+ if (!assets[assetUUID]) {
552
+ assets[assetUUID] = {
553
+ type: "svg",
554
+ value: svg2
555
+ };
556
+ }
557
+ elem.detail.svg = assetUUID;
551
558
  }
552
- elem.detail.svg = assetUUID;
553
559
  } else if (elem.type === "html") {
554
560
  const html2 = elem.detail.html;
555
- const assetUUID = createAssetId(html2);
556
561
  if (isAssetId(html2) && !assets[html2] && loadItemMap[html2] && typeof ((_c = loadItemMap[html2]) == null ? void 0 : _c.source) === "string") {
557
562
  assets[html2] = {
558
563
  type: "html",
559
564
  value: loadItemMap[html2].source
560
565
  };
561
- } else if (!assets[assetUUID]) {
562
- assets[assetUUID] = {
563
- type: "html",
564
- value: html2
565
- };
566
+ } else if (!assets[html2]) {
567
+ const assetUUID = createAssetId(html2, elem.uuid);
568
+ if (!assets[assetUUID]) {
569
+ assets[assetUUID] = {
570
+ type: "html",
571
+ value: html2
572
+ };
573
+ }
574
+ elem.detail.html = assetUUID;
566
575
  }
567
- elem.detail.html = assetUUID;
568
576
  } else if (elem.type === "group" && Array.isArray(elem.detail.children)) {
569
577
  const groupAssets = elem.detail.assets || {};
570
578
  Object.keys(groupAssets).forEach((assetId) => {
@@ -603,6 +611,9 @@ var __privateMethod = (obj, member, method) => {
603
611
  asyncFunction(data) {
604
612
  return parsePrototype(data) === "AsyncFunction";
605
613
  },
614
+ boolean(data) {
615
+ return parsePrototype(data) === "Boolean";
616
+ },
606
617
  string(data) {
607
618
  return parsePrototype(data) === "String";
608
619
  },
@@ -696,6 +707,9 @@ var __privateMethod = (obj, member, method) => {
696
707
  const image = await loadImage(dataURL);
697
708
  return image;
698
709
  }
710
+ function positiveNum(value) {
711
+ return typeof value === "number" && value >= 0;
712
+ }
699
713
  function number(value) {
700
714
  return typeof value === "number" && (value > 0 || value <= 0);
701
715
  }
@@ -706,19 +720,19 @@ var __privateMethod = (obj, member, method) => {
706
720
  return number(value);
707
721
  }
708
722
  function w(value) {
709
- return typeof value === "number" && value >= 0;
723
+ return positiveNum(value);
710
724
  }
711
725
  function h(value) {
712
- return typeof value === "number" && value >= 0;
726
+ return positiveNum(value);
713
727
  }
714
728
  function angle(value) {
715
729
  return typeof value === "number" && value >= -360 && value <= 360;
716
730
  }
717
731
  function borderWidth(value) {
718
- return w(value);
732
+ return positiveNum(value) || Array.isArray(value) && positiveNum(value[0]) && positiveNum(value[1]) && positiveNum(value[2]) && positiveNum(value[3]);
719
733
  }
720
734
  function borderRadius(value) {
721
- return number(value) && value >= 0;
735
+ return positiveNum(value) || Array.isArray(value) && positiveNum(value[0]) && positiveNum(value[1]) && positiveNum(value[2]) && positiveNum(value[3]);
722
736
  }
723
737
  function color(value) {
724
738
  return isColorStr(value);
@@ -772,6 +786,7 @@ var __privateMethod = (obj, member, method) => {
772
786
  return /^(-?\d+(?:\.\d+)?)$/.test(`${value}`);
773
787
  }
774
788
  const is = {
789
+ positiveNum,
775
790
  x,
776
791
  y,
777
792
  w,
@@ -807,20 +822,20 @@ var __privateMethod = (obj, member, method) => {
807
822
  }
808
823
  function box(detail = {}) {
809
824
  const { borderColor, borderRadius: borderRadius2, borderWidth: borderWidth2 } = detail;
810
- if (detail.hasOwnProperty("borderColor") && !is.color(borderColor)) {
825
+ if (Object.prototype.hasOwnProperty.call(detail, "borderColor") && !is.color(borderColor)) {
811
826
  return false;
812
827
  }
813
- if (detail.hasOwnProperty("borderRadius") && !is.number(borderRadius2)) {
828
+ if (Object.prototype.hasOwnProperty.call(detail, "borderRadius") && !is.number(borderRadius2)) {
814
829
  return false;
815
830
  }
816
- if (detail.hasOwnProperty("borderWidth") && !is.number(borderWidth2)) {
831
+ if (Object.prototype.hasOwnProperty.call(detail, "borderWidth") && !is.number(borderWidth2)) {
817
832
  return false;
818
833
  }
819
834
  return true;
820
835
  }
821
836
  function rectDesc(detail) {
822
837
  const { background } = detail;
823
- if (detail.hasOwnProperty("background") && !is.color(background)) {
838
+ if (Object.prototype.hasOwnProperty.call(detail, "background") && !is.color(background)) {
824
839
  return false;
825
840
  }
826
841
  if (!box(detail)) {
@@ -830,13 +845,13 @@ var __privateMethod = (obj, member, method) => {
830
845
  }
831
846
  function circleDesc(detail) {
832
847
  const { background, borderColor, borderWidth: borderWidth2 } = detail;
833
- if (detail.hasOwnProperty("background") && !is.color(background)) {
848
+ if (Object.prototype.hasOwnProperty.call(detail, "background") && !is.color(background)) {
834
849
  return false;
835
850
  }
836
- if (detail.hasOwnProperty("borderColor") && !is.color(borderColor)) {
851
+ if (Object.prototype.hasOwnProperty.call(detail, "borderColor") && !is.color(borderColor)) {
837
852
  return false;
838
853
  }
839
- if (detail.hasOwnProperty("borderWidth") && !is.number(borderWidth2)) {
854
+ if (Object.prototype.hasOwnProperty.call(detail, "borderWidth") && !is.number(borderWidth2)) {
840
855
  return false;
841
856
  }
842
857
  return true;
@@ -873,25 +888,25 @@ var __privateMethod = (obj, member, method) => {
873
888
  if (!is.fontSize(fontSize2)) {
874
889
  return false;
875
890
  }
876
- if (detail.hasOwnProperty("background") && !is.color(background)) {
891
+ if (Object.prototype.hasOwnProperty.call(detail, "background") && !is.color(background)) {
877
892
  return false;
878
893
  }
879
- if (detail.hasOwnProperty("fontWeight") && !is.fontWeight(fontWeight2)) {
894
+ if (Object.prototype.hasOwnProperty.call(detail, "fontWeight") && !is.fontWeight(fontWeight2)) {
880
895
  return false;
881
896
  }
882
- if (detail.hasOwnProperty("lineHeight") && !is.lineHeight(lineHeight2)) {
897
+ if (Object.prototype.hasOwnProperty.call(detail, "lineHeight") && !is.lineHeight(lineHeight2)) {
883
898
  return false;
884
899
  }
885
- if (detail.hasOwnProperty("fontFamily") && !is.fontFamily(fontFamily2)) {
900
+ if (Object.prototype.hasOwnProperty.call(detail, "fontFamily") && !is.fontFamily(fontFamily2)) {
886
901
  return false;
887
902
  }
888
- if (detail.hasOwnProperty("textAlign") && !is.textAlign(textAlign2)) {
903
+ if (Object.prototype.hasOwnProperty.call(detail, "textAlign") && !is.textAlign(textAlign2)) {
889
904
  return false;
890
905
  }
891
- if (detail.hasOwnProperty("strokeWidth") && !is.strokeWidth(strokeWidth2)) {
906
+ if (Object.prototype.hasOwnProperty.call(detail, "strokeWidth") && !is.strokeWidth(strokeWidth2)) {
892
907
  return false;
893
908
  }
894
- if (detail.hasOwnProperty("strokeColor") && !is.color(strokeColor)) {
909
+ if (Object.prototype.hasOwnProperty.call(detail, "strokeColor") && !is.color(strokeColor)) {
895
910
  return false;
896
911
  }
897
912
  if (!box(detail)) {
@@ -908,14 +923,18 @@ var __privateMethod = (obj, member, method) => {
908
923
  svgDesc,
909
924
  htmlDesc
910
925
  };
926
+ const defaultFontSize = 12;
927
+ const defaultFontWeight = "400";
928
+ const defaultFontFamily = `-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'`;
911
929
  class Context2D {
912
930
  // private _width: number = 0;
913
931
  // private _height: number = 0;
914
932
  constructor(ctx, opts) {
915
- __privateAdd(this, _ctx, void 0);
916
- __privateAdd(this, _opts, void 0);
933
+ __privateAdd(this, _ctx);
934
+ __privateAdd(this, _opts);
917
935
  __privateSet(this, _ctx, ctx);
918
936
  __privateSet(this, _opts, { ...{ devicePixelRatio: 1, offscreenCanvas: null }, ...opts });
937
+ this.$resetFont();
919
938
  }
920
939
  $undoPixelRatio(num) {
921
940
  return num / __privateGet(this, _opts).devicePixelRatio;
@@ -926,6 +945,9 @@ var __privateMethod = (obj, member, method) => {
926
945
  $getContext() {
927
946
  return __privateGet(this, _ctx);
928
947
  }
948
+ $setContext(ctx) {
949
+ __privateSet(this, _ctx, ctx);
950
+ }
929
951
  $setFont(opts) {
930
952
  const strList = [];
931
953
  if (opts.fontWeight) {
@@ -935,6 +957,13 @@ var __privateMethod = (obj, member, method) => {
935
957
  strList.push(`${opts.fontFamily || "sans-serif"}`);
936
958
  __privateGet(this, _ctx).font = `${strList.join(" ")}`;
937
959
  }
960
+ $resetFont() {
961
+ this.$setFont({
962
+ fontSize: defaultFontSize,
963
+ fontFamily: defaultFontFamily,
964
+ fontWeight: defaultFontWeight
965
+ });
966
+ }
938
967
  $getOffscreenCanvas() {
939
968
  return __privateGet(this, _opts).offscreenCanvas;
940
969
  }
@@ -1042,16 +1071,33 @@ var __privateMethod = (obj, member, method) => {
1042
1071
  return __privateGet(this, _ctx).fill(...args);
1043
1072
  }
1044
1073
  arc(x2, y2, radius, startAngle, endAngle, anticlockwise) {
1045
- return __privateGet(this, _ctx).arc(this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(radius), startAngle, endAngle, anticlockwise);
1074
+ return __privateGet(this, _ctx).arc(
1075
+ this.$doPixelRatio(x2),
1076
+ this.$doPixelRatio(y2),
1077
+ this.$doPixelRatio(radius),
1078
+ startAngle,
1079
+ endAngle,
1080
+ anticlockwise
1081
+ );
1046
1082
  }
1047
1083
  rect(x2, y2, w2, h2) {
1048
1084
  return __privateGet(this, _ctx).rect(this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(w2), this.$doPixelRatio(h2));
1049
1085
  }
1050
1086
  fillRect(x2, y2, w2, h2) {
1051
- return __privateGet(this, _ctx).fillRect(this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(w2), this.$doPixelRatio(h2));
1087
+ return __privateGet(this, _ctx).fillRect(
1088
+ this.$doPixelRatio(x2),
1089
+ this.$doPixelRatio(y2),
1090
+ this.$doPixelRatio(w2),
1091
+ this.$doPixelRatio(h2)
1092
+ );
1052
1093
  }
1053
1094
  clearRect(x2, y2, w2, h2) {
1054
- return __privateGet(this, _ctx).clearRect(this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(w2), this.$doPixelRatio(h2));
1095
+ return __privateGet(this, _ctx).clearRect(
1096
+ this.$doPixelRatio(x2),
1097
+ this.$doPixelRatio(y2),
1098
+ this.$doPixelRatio(w2),
1099
+ this.$doPixelRatio(h2)
1100
+ );
1055
1101
  }
1056
1102
  beginPath() {
1057
1103
  return __privateGet(this, _ctx).beginPath();
@@ -1066,7 +1112,31 @@ var __privateMethod = (obj, member, method) => {
1066
1112
  return __privateGet(this, _ctx).moveTo(this.$doPixelRatio(x2), this.$doPixelRatio(y2));
1067
1113
  }
1068
1114
  arcTo(x1, y1, x2, y2, radius) {
1069
- return __privateGet(this, _ctx).arcTo(this.$doPixelRatio(x1), this.$doPixelRatio(y1), this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(radius));
1115
+ return __privateGet(this, _ctx).arcTo(
1116
+ this.$doPixelRatio(x1),
1117
+ this.$doPixelRatio(y1),
1118
+ this.$doPixelRatio(x2),
1119
+ this.$doPixelRatio(y2),
1120
+ this.$doPixelRatio(radius)
1121
+ );
1122
+ }
1123
+ bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x2, y2) {
1124
+ return __privateGet(this, _ctx).bezierCurveTo(
1125
+ this.$doPixelRatio(cp1x),
1126
+ this.$doPixelRatio(cp1y),
1127
+ this.$doPixelRatio(cp2x),
1128
+ this.$doPixelRatio(cp2y),
1129
+ this.$doPixelRatio(x2),
1130
+ this.$doPixelRatio(y2)
1131
+ );
1132
+ }
1133
+ quadraticCurveTo(cpx, cpy, x2, y2) {
1134
+ return __privateGet(this, _ctx).quadraticCurveTo(
1135
+ this.$doPixelRatio(cpx),
1136
+ this.$doPixelRatio(cpy),
1137
+ this.$doPixelRatio(x2),
1138
+ this.$doPixelRatio(y2)
1139
+ );
1070
1140
  }
1071
1141
  getLineDash() {
1072
1142
  return __privateGet(this, _ctx).getLineDash();
@@ -1107,7 +1177,13 @@ var __privateMethod = (obj, member, method) => {
1107
1177
  this.$doPixelRatio(dh)
1108
1178
  );
1109
1179
  } else {
1110
- return __privateGet(this, _ctx).drawImage(image, this.$doPixelRatio(dx), this.$doPixelRatio(dy), this.$doPixelRatio(dw), this.$doPixelRatio(dh));
1180
+ return __privateGet(this, _ctx).drawImage(
1181
+ image,
1182
+ this.$doPixelRatio(dx),
1183
+ this.$doPixelRatio(dy),
1184
+ this.$doPixelRatio(dw),
1185
+ this.$doPixelRatio(dh)
1186
+ );
1111
1187
  }
1112
1188
  }
1113
1189
  createPattern(image, repetition) {
@@ -1167,7 +1243,12 @@ var __privateMethod = (obj, member, method) => {
1167
1243
  return __privateGet(this, _ctx).getTransform();
1168
1244
  }
1169
1245
  createLinearGradient(x0, y0, x1, y1) {
1170
- return __privateGet(this, _ctx).createLinearGradient(this.$doPixelRatio(x0), this.$doPixelRatio(y0), this.$doPixelRatio(x1), this.$doPixelRatio(y1));
1246
+ return __privateGet(this, _ctx).createLinearGradient(
1247
+ this.$doPixelRatio(x0),
1248
+ this.$doPixelRatio(y0),
1249
+ this.$doPixelRatio(x1),
1250
+ this.$doPixelRatio(y1)
1251
+ );
1171
1252
  }
1172
1253
  createRadialGradient(x0, y0, r0, x1, y1, r1) {
1173
1254
  return __privateGet(this, _ctx).createRadialGradient(
@@ -1209,64 +1290,41 @@ var __privateMethod = (obj, member, method) => {
1209
1290
  return context2d;
1210
1291
  }
1211
1292
  function createBoardContent(canvas, opts) {
1212
- const { width, height, devicePixelRatio, offscreen } = opts;
1293
+ const { width, height, devicePixelRatio } = opts;
1213
1294
  const ctxOpts = {
1214
1295
  width,
1215
1296
  height,
1216
1297
  devicePixelRatio
1217
1298
  };
1218
- if (offscreen === true) {
1219
- const ctx = canvas.getContext("2d");
1220
- const viewContext = createOffscreenContext2D(ctxOpts);
1221
- const helperContext = createOffscreenContext2D(ctxOpts);
1222
- const underContext = createOffscreenContext2D(ctxOpts);
1223
- const boardContext = createContext2D({ ctx, ...ctxOpts });
1224
- const drawView = () => {
1225
- const { width: w2, height: h2 } = viewContext.$getSize();
1226
- boardContext.clearRect(0, 0, w2, h2);
1227
- boardContext.drawImage(underContext.canvas, 0, 0, w2, h2);
1228
- boardContext.drawImage(viewContext.canvas, 0, 0, w2, h2);
1229
- boardContext.drawImage(helperContext.canvas, 0, 0, w2, h2);
1230
- underContext.clearRect(0, 0, w2, h2);
1231
- viewContext.clearRect(0, 0, w2, h2);
1232
- helperContext.clearRect(0, 0, w2, h2);
1233
- };
1234
- const content = {
1235
- underContext,
1236
- viewContext,
1237
- helperContext,
1238
- boardContext,
1239
- drawView
1240
- };
1241
- return content;
1242
- } else {
1243
- const ctx = canvas.getContext("2d");
1244
- const viewContext = createContext2D(ctxOpts);
1245
- const helperContext = createContext2D(ctxOpts);
1246
- const underContext = createContext2D(ctxOpts);
1247
- const boardContext = createContext2D({ ctx, ...ctxOpts });
1248
- const drawView = () => {
1249
- boardContext.clearRect(0, 0, width, height);
1250
- boardContext.drawImage(underContext.canvas, 0, 0, width, height);
1251
- boardContext.drawImage(viewContext.canvas, 0, 0, width, height);
1252
- boardContext.drawImage(helperContext.canvas, 0, 0, width, height);
1253
- underContext.clearRect(0, 0, width, height);
1254
- viewContext.clearRect(0, 0, width, height);
1255
- helperContext.clearRect(0, 0, width, height);
1256
- };
1257
- const content = {
1258
- underContext,
1259
- viewContext,
1260
- helperContext,
1261
- boardContext,
1262
- drawView
1263
- };
1264
- return content;
1265
- }
1299
+ const ctx = canvas.getContext("2d");
1300
+ const viewContext = createOffscreenContext2D(ctxOpts);
1301
+ const overlayContext = createOffscreenContext2D(ctxOpts);
1302
+ const underlayContext = createOffscreenContext2D(ctxOpts);
1303
+ const boardContext = createContext2D({ ctx, ...ctxOpts });
1304
+ const tempContext = createOffscreenContext2D(ctxOpts);
1305
+ const drawView = () => {
1306
+ const { width: w2, height: h2 } = viewContext.$getSize();
1307
+ boardContext.clearRect(0, 0, w2, h2);
1308
+ boardContext.drawImage(underlayContext.canvas, 0, 0, w2, h2);
1309
+ boardContext.drawImage(viewContext.canvas, 0, 0, w2, h2);
1310
+ boardContext.drawImage(overlayContext.canvas, 0, 0, w2, h2);
1311
+ underlayContext.clearRect(0, 0, w2, h2);
1312
+ viewContext.clearRect(0, 0, w2, h2);
1313
+ overlayContext.clearRect(0, 0, w2, h2);
1314
+ };
1315
+ const content = {
1316
+ underlayContext,
1317
+ viewContext,
1318
+ overlayContext,
1319
+ boardContext,
1320
+ tempContext,
1321
+ drawView
1322
+ };
1323
+ return content;
1266
1324
  }
1267
1325
  class EventEmitter {
1268
1326
  constructor() {
1269
- __privateAdd(this, _listeners, void 0);
1327
+ __privateAdd(this, _listeners);
1270
1328
  __privateSet(this, _listeners, /* @__PURE__ */ new Map());
1271
1329
  }
1272
1330
  on(eventKey, callback) {
@@ -1313,6 +1371,9 @@ var __privateMethod = (obj, member, method) => {
1313
1371
  return false;
1314
1372
  }
1315
1373
  destroy() {
1374
+ this.clear();
1375
+ }
1376
+ clear() {
1316
1377
  __privateGet(this, _listeners).clear();
1317
1378
  }
1318
1379
  }
@@ -1349,11 +1410,13 @@ var __privateMethod = (obj, member, method) => {
1349
1410
  }
1350
1411
  class Store {
1351
1412
  constructor(opts) {
1352
- __privateAdd(this, _createTempStorage);
1353
- __privateAdd(this, _temp, void 0);
1354
- __privateAdd(this, _backUpDefaultStorage, void 0);
1413
+ __privateAdd(this, _Store_instances);
1414
+ __privateAdd(this, _temp);
1415
+ __privateAdd(this, _backUpDefaultStorage);
1416
+ __privateAdd(this, _static);
1355
1417
  __privateSet(this, _backUpDefaultStorage, deepClone(opts.defaultStorage));
1356
- __privateSet(this, _temp, __privateMethod(this, _createTempStorage, createTempStorage_fn).call(this));
1418
+ __privateSet(this, _temp, __privateMethod(this, _Store_instances, createTempStorage_fn).call(this));
1419
+ __privateSet(this, _static, opts.defaultStatic || {});
1357
1420
  }
1358
1421
  set(name, value) {
1359
1422
  __privateGet(this, _temp)[name] = value;
@@ -1361,19 +1424,30 @@ var __privateMethod = (obj, member, method) => {
1361
1424
  get(name) {
1362
1425
  return __privateGet(this, _temp)[name];
1363
1426
  }
1364
- getSnapshot() {
1365
- return deepClone(__privateGet(this, _temp));
1427
+ setStatic(name, value) {
1428
+ __privateGet(this, _static)[name] = value;
1429
+ }
1430
+ getStatic(name) {
1431
+ return __privateGet(this, _static)[name];
1432
+ }
1433
+ getSnapshot(opts) {
1434
+ if ((opts == null ? void 0 : opts.deepClone) === true) {
1435
+ return deepClone(__privateGet(this, _temp));
1436
+ }
1437
+ return { ...__privateGet(this, _temp) };
1366
1438
  }
1367
1439
  clear() {
1368
- __privateSet(this, _temp, __privateMethod(this, _createTempStorage, createTempStorage_fn).call(this));
1440
+ __privateSet(this, _temp, __privateMethod(this, _Store_instances, createTempStorage_fn).call(this));
1369
1441
  }
1370
1442
  destroy() {
1371
1443
  __privateSet(this, _temp, null);
1444
+ __privateSet(this, _static, null);
1372
1445
  }
1373
1446
  }
1374
1447
  _temp = new WeakMap();
1375
1448
  _backUpDefaultStorage = new WeakMap();
1376
- _createTempStorage = new WeakSet();
1449
+ _static = new WeakMap();
1450
+ _Store_instances = new WeakSet();
1377
1451
  createTempStorage_fn = function() {
1378
1452
  return deepClone(__privateGet(this, _backUpDefaultStorage));
1379
1453
  };
@@ -1445,6 +1519,15 @@ var __privateMethod = (obj, member, method) => {
1445
1519
  };
1446
1520
  return calcElementCenter(elemSize);
1447
1521
  }
1522
+ function calcRadian(center, start, end) {
1523
+ const startRadian = calcLineRadian(center, start);
1524
+ const endRadian = calcLineRadian(center, end);
1525
+ if (endRadian !== null && startRadian !== null) {
1526
+ return endRadian - startRadian;
1527
+ } else {
1528
+ return 0;
1529
+ }
1530
+ }
1448
1531
  function calcLineRadian(center, p) {
1449
1532
  const x2 = p.x - center.x;
1450
1533
  const y2 = p.y - center.y;
@@ -1525,7 +1608,7 @@ var __privateMethod = (obj, member, method) => {
1525
1608
  let resultY = point.y;
1526
1609
  groupQueue.forEach((group) => {
1527
1610
  const { x: x2, y: y2, w: w2, h: h2, angle: angle2 = 0 } = group;
1528
- const center = calcElementCenter({ x: x2, y: y2, w: w2, h: h2, angle: angle2 });
1611
+ const center = calcElementCenter({ x: x2, y: y2, w: w2, h: h2 });
1529
1612
  const temp = rotatePoint(center, { x: resultX, y: resultY }, parseAngleToRadian(angle2));
1530
1613
  resultX = temp.x;
1531
1614
  resultY = temp.y;
@@ -1566,12 +1649,14 @@ var __privateMethod = (obj, member, method) => {
1566
1649
  ];
1567
1650
  }
1568
1651
  function limitAngle(angle2) {
1569
- if (!(angle2 > 0 || angle2 < 0) || angle2 === 0) {
1652
+ if (!(angle2 > 0 || angle2 < 0) || angle2 === 0 || angle2 === 360) {
1570
1653
  return 0;
1571
1654
  }
1572
1655
  let num = angle2 % 360;
1573
1656
  if (num < 0) {
1574
1657
  num += 360;
1658
+ } else if (angle2 === 360) {
1659
+ num = 0;
1575
1660
  }
1576
1661
  return num;
1577
1662
  }
@@ -1738,7 +1823,11 @@ var __privateMethod = (obj, member, method) => {
1738
1823
  return ctxSize;
1739
1824
  }
1740
1825
  function calcElementsViewInfo(elements, prevViewSize, options) {
1741
- const contextSize = calcElementsContextSize(elements, { viewWidth: prevViewSize.width, viewHeight: prevViewSize.height, extend: options == null ? void 0 : options.extend });
1826
+ const contextSize = calcElementsContextSize(elements, {
1827
+ viewWidth: prevViewSize.width,
1828
+ viewHeight: prevViewSize.height,
1829
+ extend: options == null ? void 0 : options.extend
1830
+ });
1742
1831
  if ((options == null ? void 0 : options.extend) === true) {
1743
1832
  contextSize.contextWidth = Math.max(contextSize.contextWidth, prevViewSize.contextWidth);
1744
1833
  contextSize.contextHeight = Math.max(contextSize.contextHeight, prevViewSize.contextHeight);
@@ -1824,6 +1913,24 @@ var __privateMethod = (obj, member, method) => {
1824
1913
  _scan(uuid, elements);
1825
1914
  return groupQueue;
1826
1915
  }
1916
+ function getGroupQueueByElementPosition(elements, position) {
1917
+ var _a;
1918
+ const groupQueue = [];
1919
+ let currentElements = elements;
1920
+ if (position.length > 1) {
1921
+ for (let i = 0; i < position.length - 1; i++) {
1922
+ const index = position[i];
1923
+ const group = currentElements[index];
1924
+ if ((group == null ? void 0 : group.type) === "group" && Array.isArray((_a = group == null ? void 0 : group.detail) == null ? void 0 : _a.children)) {
1925
+ groupQueue.push(group);
1926
+ currentElements = group.detail.children;
1927
+ } else {
1928
+ return null;
1929
+ }
1930
+ }
1931
+ }
1932
+ return groupQueue;
1933
+ }
1827
1934
  function getElementSize(elem) {
1828
1935
  const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = elem;
1829
1936
  const size = { x: x2, y: y2, w: w2, h: h2, angle: angle2 };
@@ -1866,7 +1973,7 @@ var __privateMethod = (obj, member, method) => {
1866
1973
  resource = element.detail.html;
1867
1974
  }
1868
1975
  if (typeof resource === "string" && !isAssetId(resource)) {
1869
- assetId = createAssetId(resource);
1976
+ assetId = createAssetId(resource, element.uuid);
1870
1977
  assetItem = {
1871
1978
  type: element.type,
1872
1979
  value: resource
@@ -1904,7 +2011,7 @@ var __privateMethod = (obj, member, method) => {
1904
2011
  for (let i = 0; i < position.length; i++) {
1905
2012
  const pos = position[i];
1906
2013
  const item = tempList[pos];
1907
- if (i < position.length - 1 && item.type === "group") {
2014
+ if (i < position.length - 1 && (item == null ? void 0 : item.type) === "group") {
1908
2015
  tempList = item.detail.children;
1909
2016
  } else if (i === position.length - 1) {
1910
2017
  result = item;
@@ -1959,16 +2066,120 @@ var __privateMethod = (obj, member, method) => {
1959
2066
  _loop(elements);
1960
2067
  return result;
1961
2068
  }
2069
+ function getElementPositionMapFromList(uuids, elements) {
2070
+ const currentPosition = [];
2071
+ const positionMap = {};
2072
+ let over = false;
2073
+ const _loop = (list) => {
2074
+ var _a;
2075
+ for (let i = 0; i < list.length; i++) {
2076
+ if (over === true) {
2077
+ break;
2078
+ }
2079
+ currentPosition.push(i);
2080
+ const elem = list[i];
2081
+ if (uuids.includes(elem.uuid)) {
2082
+ positionMap[elem.uuid] = [...currentPosition];
2083
+ if (Object.keys(positionMap).length === uuids.length) {
2084
+ over = true;
2085
+ break;
2086
+ }
2087
+ } else if (elem.type === "group") {
2088
+ _loop(((_a = elem == null ? void 0 : elem.detail) == null ? void 0 : _a.children) || []);
2089
+ }
2090
+ if (over) {
2091
+ break;
2092
+ }
2093
+ currentPosition.pop();
2094
+ }
2095
+ };
2096
+ _loop(elements);
2097
+ return positionMap;
2098
+ }
2099
+ function isSameElementSize(elem1, elem2) {
2100
+ return elem1.x === elem2.x && elem1.y === elem2.y && elem1.h === elem2.h && elem1.w === elem2.w && limitAngle(elem1.angle || 0) === limitAngle(elem2.angle || 0);
2101
+ }
1962
2102
  function checkRectIntersect(rect1, rect2) {
1963
- const react1MinX = rect1.x;
1964
- const react1MinY = rect1.y;
1965
- const react1MaxX = rect1.x + rect1.w;
1966
- const react1MaxY = rect1.y + rect1.h;
1967
- const react2MinX = rect2.x;
1968
- const react2MinY = rect2.y;
1969
- const react2MaxX = rect2.x + rect2.w;
1970
- const react2MaxY = rect2.y + rect2.h;
1971
- return react1MinX <= react2MaxX && react1MaxX >= react2MinX && react1MinY <= react2MaxY && react1MaxY >= react2MinY;
2103
+ const rect1MinX = rect1.x;
2104
+ const rect1MinY = rect1.y;
2105
+ const rect1MaxX = rect1.x + rect1.w;
2106
+ const rect1MaxY = rect1.y + rect1.h;
2107
+ const rect2MinX = rect2.x;
2108
+ const rect2MinY = rect2.y;
2109
+ const rect2MaxX = rect2.x + rect2.w;
2110
+ const rect2MaxY = rect2.y + rect2.h;
2111
+ return rect1MinX <= rect2MaxX && rect1MaxX >= rect2MinX && rect1MinY <= rect2MaxY && rect1MaxY >= rect2MinY;
2112
+ }
2113
+ function getElementVertexes(elemSize) {
2114
+ const { x: x2, y: y2, h: h2, w: w2 } = elemSize;
2115
+ return [
2116
+ { x: x2, y: y2 },
2117
+ { x: x2 + w2, y: y2 },
2118
+ { x: x2 + w2, y: y2 + h2 },
2119
+ { x: x2, y: y2 + h2 }
2120
+ ];
2121
+ }
2122
+ function calcElementVertexes(elemSize) {
2123
+ const { x: x2, y: y2, w: w2, h: h2, angle: angle2 = 0 } = elemSize;
2124
+ if (angle2 === 0) {
2125
+ return getElementVertexes(elemSize);
2126
+ }
2127
+ return getElementRotateVertexes(elemSize, calcElementCenter({ x: x2, y: y2, w: w2, h: h2 }), angle2);
2128
+ }
2129
+ function calcElementQueueVertexesQueueInGroup(groupQueue) {
2130
+ const vesList = [];
2131
+ let totalX = 0;
2132
+ let totalY = 0;
2133
+ const rotateActionList = [];
2134
+ const elemQueue = [...groupQueue];
2135
+ for (let i = 0; i < elemQueue.length; i++) {
2136
+ const { x: x2, y: y2, w: w2, h: h2, angle: angle2 = 0 } = elemQueue[i];
2137
+ totalX += x2;
2138
+ totalY += y2;
2139
+ let ves;
2140
+ if (i === 0) {
2141
+ const elemSize = { x: totalX, y: totalY, w: w2, h: h2 };
2142
+ ves = calcElementVertexes({ x: x2, y: y2, w: w2, h: h2, angle: angle2 });
2143
+ rotateActionList.push({
2144
+ center: calcElementCenter(elemSize),
2145
+ angle: angle2,
2146
+ radian: parseAngleToRadian(angle2)
2147
+ });
2148
+ } else {
2149
+ const elemSize = { x: totalX, y: totalY, w: w2, h: h2 };
2150
+ ves = getElementVertexes(elemSize);
2151
+ for (let aIdx = 0; aIdx < rotateActionList.length; aIdx++) {
2152
+ const { center, radian } = rotateActionList[aIdx];
2153
+ ves = rotateVertexes(center, ves, radian);
2154
+ }
2155
+ const vesCenter = calcElementCenterFromVertexes(ves);
2156
+ if (angle2 > 0 || angle2 < 0) {
2157
+ const radian = parseAngleToRadian(angle2);
2158
+ ves = rotateVertexes(vesCenter, ves, radian);
2159
+ }
2160
+ rotateActionList.push({
2161
+ center: vesCenter,
2162
+ angle: angle2,
2163
+ radian: parseAngleToRadian(angle2)
2164
+ });
2165
+ }
2166
+ vesList.push(ves);
2167
+ }
2168
+ return vesList;
2169
+ }
2170
+ function calcElementVertexesQueueInGroup(targetElem, opts) {
2171
+ const { groupQueue } = opts;
2172
+ if (!(groupQueue.length > 0)) {
2173
+ return [calcElementVertexes(targetElem)];
2174
+ }
2175
+ const elemQueue = [...groupQueue, ...[targetElem]];
2176
+ const vesList = calcElementQueueVertexesQueueInGroup(elemQueue);
2177
+ return vesList;
2178
+ }
2179
+ function calcElementVertexesInGroup(targetElem, opts) {
2180
+ const vesList = calcElementVertexesQueueInGroup(targetElem, opts);
2181
+ const ves = vesList.pop();
2182
+ return ves || null;
1972
2183
  }
1973
2184
  function calcViewScaleInfo(info, opts) {
1974
2185
  const { scale, offsetX, offsetY } = info;
@@ -2056,9 +2267,9 @@ var __privateMethod = (obj, member, method) => {
2056
2267
  ];
2057
2268
  }
2058
2269
  function isViewPointInElement(p, opts) {
2059
- const { context2d: ctx, element: elem, viewScaleInfo, viewSizeInfo } = opts;
2270
+ const { context2d: ctx, element: elem, viewScaleInfo } = opts;
2060
2271
  const { angle: angle2 = 0 } = elem;
2061
- const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(elem, { viewScaleInfo, viewSizeInfo });
2272
+ const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(elem, { viewScaleInfo });
2062
2273
  const vertexes = rotateElementVertexes({ x: x2, y: y2, w: w2, h: h2, angle: angle2 });
2063
2274
  if (vertexes.length >= 2) {
2064
2275
  ctx.beginPath();
@@ -2073,6 +2284,25 @@ var __privateMethod = (obj, member, method) => {
2073
2284
  }
2074
2285
  return false;
2075
2286
  }
2287
+ function isViewPointInElementSize(p, elemSize, opts) {
2288
+ const vertexes = calcElementVertexes(elemSize);
2289
+ return isViewPointInVertexes(p, vertexes, opts);
2290
+ }
2291
+ function isViewPointInVertexes(p, vertexes, opts) {
2292
+ const xList = [vertexes[0].x, vertexes[1].x, vertexes[2].x, vertexes[3].x];
2293
+ const yList = [vertexes[0].y, vertexes[1].y, vertexes[2].y, vertexes[3].y];
2294
+ const mixX = Math.min(...xList);
2295
+ const maxX = Math.max(...xList);
2296
+ const mixY = Math.min(...yList);
2297
+ const maxY = Math.max(...yList);
2298
+ if (p.x > mixX && p.x < maxX && p.y > mixY && p.y < maxY) {
2299
+ return true;
2300
+ }
2301
+ if ((opts == null ? void 0 : opts.includeBorder) === true && (p.x === mixX || p.x === maxX || p.y === mixY || p.y === maxY)) {
2302
+ return true;
2303
+ }
2304
+ return false;
2305
+ }
2076
2306
  function getViewPointAtElement(p, opts) {
2077
2307
  var _a, _b, _c;
2078
2308
  const { context2d: ctx, data, viewScaleInfo, viewSizeInfo, groupQueue } = opts;
@@ -2106,7 +2336,7 @@ var __privateMethod = (obj, member, method) => {
2106
2336
  h: child.h,
2107
2337
  angle: totalAngle + (child.angle || 0)
2108
2338
  };
2109
- if (isViewPointInElement(p, { context2d: ctx, element: elemSize, viewScaleInfo, viewSizeInfo })) {
2339
+ if (isViewPointInElement(p, { context2d: ctx, element: elemSize, viewScaleInfo })) {
2110
2340
  result.element = child;
2111
2341
  if (gIdx < groupQueue.length - 1 || child.type !== "group") {
2112
2342
  result.groupQueueIndex = gIdx;
@@ -2131,7 +2361,7 @@ var __privateMethod = (obj, member, method) => {
2131
2361
  if (((_c = elem == null ? void 0 : elem.operations) == null ? void 0 : _c.invisible) === true) {
2132
2362
  continue;
2133
2363
  }
2134
- if (isViewPointInElement(p, { context2d: ctx, element: elem, viewScaleInfo, viewSizeInfo })) {
2364
+ if (isViewPointInElement(p, { context2d: ctx, element: elem, viewScaleInfo })) {
2135
2365
  result.index = i;
2136
2366
  result.element = elem;
2137
2367
  break;
@@ -2143,7 +2373,7 @@ var __privateMethod = (obj, member, method) => {
2143
2373
  const { viewSizeInfo, viewScaleInfo } = opts;
2144
2374
  const { width, height } = viewSizeInfo;
2145
2375
  const { angle: angle2 } = elem;
2146
- const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(elem, { viewScaleInfo, viewSizeInfo });
2376
+ const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(elem, { viewScaleInfo });
2147
2377
  const ves = rotateElementVertexes({ x: x2, y: y2, w: w2, h: h2, angle: angle2 });
2148
2378
  const viewSize = { x: 0, y: 0, w: width, h: height };
2149
2379
  const elemStartX = Math.min(ves[0].x, ves[1].x, ves[2].x, ves[3].x);
@@ -2153,76 +2383,148 @@ var __privateMethod = (obj, member, method) => {
2153
2383
  const elemSize = { x: elemStartX, y: elemStartY, w: elemEndX - elemStartX, h: elemEndY - elemStartY };
2154
2384
  return checkRectIntersect(viewSize, elemSize);
2155
2385
  }
2156
- function getElementVertexes(elemSize) {
2157
- const { x: x2, y: y2, h: h2, w: w2 } = elemSize;
2158
- return [
2159
- { x: x2, y: y2 },
2160
- { x: x2 + w2, y: y2 },
2161
- { x: x2 + w2, y: y2 + h2 },
2162
- { x: x2, y: y2 + h2 }
2163
- ];
2164
- }
2165
- function calcElementVertexes(elemSize) {
2166
- const { x: x2, y: y2, w: w2, h: h2, angle: angle2 = 0 } = elemSize;
2167
- if (angle2 === 0) {
2168
- return getElementVertexes(elemSize);
2386
+ function calcElementOriginRectInfo(elemSize, opts) {
2387
+ const { groupQueue } = opts;
2388
+ const vertexes = calcElementVertexesInGroup(elemSize, { groupQueue });
2389
+ const top = getCenterFromTwoPoints(vertexes[0], vertexes[1]);
2390
+ const right = getCenterFromTwoPoints(vertexes[1], vertexes[2]);
2391
+ const bottom = getCenterFromTwoPoints(vertexes[2], vertexes[3]);
2392
+ const left = getCenterFromTwoPoints(vertexes[3], vertexes[0]);
2393
+ const topLeft = vertexes[0];
2394
+ const topRight = vertexes[1];
2395
+ const bottomRight = vertexes[2];
2396
+ const bottomLeft = vertexes[3];
2397
+ const maxX = Math.max(topLeft.x, topRight.x, bottomRight.x, bottomLeft.x);
2398
+ const maxY = Math.max(topLeft.y, topRight.y, bottomRight.y, bottomLeft.y);
2399
+ const minX = Math.min(topLeft.x, topRight.x, bottomRight.x, bottomLeft.x);
2400
+ const minY = Math.min(topLeft.y, topRight.y, bottomRight.y, bottomLeft.y);
2401
+ const center = {
2402
+ x: (maxX + minX) / 2,
2403
+ y: (maxY + minY) / 2
2404
+ };
2405
+ const rectInfo = {
2406
+ center,
2407
+ topLeft,
2408
+ topRight,
2409
+ bottomLeft,
2410
+ bottomRight,
2411
+ top,
2412
+ right,
2413
+ left,
2414
+ bottom
2415
+ };
2416
+ return rectInfo;
2417
+ }
2418
+ function originRectInfoToRangeRectInfo(originRectInfo) {
2419
+ const rangeMaxX = Math.max(
2420
+ originRectInfo.topLeft.x,
2421
+ originRectInfo.topRight.x,
2422
+ originRectInfo.bottomRight.x,
2423
+ originRectInfo.bottomLeft.x
2424
+ );
2425
+ const rangeMaxY = Math.max(
2426
+ originRectInfo.topLeft.y,
2427
+ originRectInfo.topRight.y,
2428
+ originRectInfo.bottomRight.y,
2429
+ originRectInfo.bottomLeft.y
2430
+ );
2431
+ const rangeMinX = Math.min(
2432
+ originRectInfo.topLeft.x,
2433
+ originRectInfo.topRight.x,
2434
+ originRectInfo.bottomRight.x,
2435
+ originRectInfo.bottomLeft.x
2436
+ );
2437
+ const rangeMinY = Math.min(
2438
+ originRectInfo.topLeft.y,
2439
+ originRectInfo.topRight.y,
2440
+ originRectInfo.bottomRight.y,
2441
+ originRectInfo.bottomLeft.y
2442
+ );
2443
+ const rangeCenter = { x: originRectInfo.center.x, y: originRectInfo.center.y };
2444
+ const rangeTopLeft = { x: rangeMinX, y: rangeMinY };
2445
+ const rangeTopRight = { x: rangeMaxX, y: rangeMinY };
2446
+ const rangeBottomRight = { x: rangeMaxX, y: rangeMaxY };
2447
+ const rangeBottomLeft = { x: rangeMinX, y: rangeMaxY };
2448
+ const rangeTop = getCenterFromTwoPoints(rangeTopLeft, rangeTopRight);
2449
+ const rangeBottom = getCenterFromTwoPoints(rangeBottomLeft, rangeBottomRight);
2450
+ const rangeLeft = getCenterFromTwoPoints(rangeTopLeft, rangeBottomLeft);
2451
+ const rangeRight = getCenterFromTwoPoints(rangeTopRight, rangeBottomRight);
2452
+ const rangeRectInfo = {
2453
+ center: rangeCenter,
2454
+ topLeft: rangeTopLeft,
2455
+ topRight: rangeTopRight,
2456
+ bottomLeft: rangeBottomLeft,
2457
+ bottomRight: rangeBottomRight,
2458
+ top: rangeTop,
2459
+ right: rangeRight,
2460
+ left: rangeLeft,
2461
+ bottom: rangeBottom
2462
+ };
2463
+ return rangeRectInfo;
2464
+ }
2465
+ function calcElementViewRectInfo(elemSize, opts) {
2466
+ const { groupQueue, viewScaleInfo, range } = opts;
2467
+ const originRectInfo = calcElementOriginRectInfo(elemSize, { groupQueue });
2468
+ const { center, top, bottom, left, right, topLeft, topRight, bottomLeft, bottomRight } = originRectInfo;
2469
+ const viewRectInfo = {
2470
+ center: calcViewPointSize(center, { viewScaleInfo }),
2471
+ topLeft: calcViewPointSize(topLeft, { viewScaleInfo }),
2472
+ topRight: calcViewPointSize(topRight, { viewScaleInfo }),
2473
+ bottomLeft: calcViewPointSize(bottomLeft, { viewScaleInfo }),
2474
+ bottomRight: calcViewPointSize(bottomRight, { viewScaleInfo }),
2475
+ top: calcViewPointSize(top, { viewScaleInfo }),
2476
+ right: calcViewPointSize(right, { viewScaleInfo }),
2477
+ left: calcViewPointSize(left, { viewScaleInfo }),
2478
+ bottom: calcViewPointSize(bottom, { viewScaleInfo })
2479
+ };
2480
+ if (range === true) {
2481
+ const viewMaxX = Math.max(
2482
+ viewRectInfo.topLeft.x,
2483
+ viewRectInfo.topRight.x,
2484
+ viewRectInfo.bottomRight.x,
2485
+ viewRectInfo.bottomLeft.x
2486
+ );
2487
+ const viewMaxY = Math.max(
2488
+ viewRectInfo.topLeft.y,
2489
+ viewRectInfo.topRight.y,
2490
+ viewRectInfo.bottomRight.y,
2491
+ viewRectInfo.bottomLeft.y
2492
+ );
2493
+ const viewMinX = Math.min(
2494
+ viewRectInfo.topLeft.x,
2495
+ viewRectInfo.topRight.x,
2496
+ viewRectInfo.bottomRight.x,
2497
+ viewRectInfo.bottomLeft.x
2498
+ );
2499
+ const viewMinY = Math.min(
2500
+ viewRectInfo.topLeft.y,
2501
+ viewRectInfo.topRight.y,
2502
+ viewRectInfo.bottomRight.y,
2503
+ viewRectInfo.bottomLeft.y
2504
+ );
2505
+ const rangeCenter = { x: viewRectInfo.center.x, y: viewRectInfo.center.y };
2506
+ const rangeTopLeft = { x: viewMinX, y: viewMinY };
2507
+ const rangeTopRight = { x: viewMaxX, y: viewMinY };
2508
+ const rangeBottomRight = { x: viewMaxX, y: viewMaxY };
2509
+ const rangeBottomLeft = { x: viewMinX, y: viewMaxY };
2510
+ const rangeTop = getCenterFromTwoPoints(rangeTopLeft, rangeTopRight);
2511
+ const rangeBottom = getCenterFromTwoPoints(rangeBottomLeft, rangeBottomRight);
2512
+ const rangeLeft = getCenterFromTwoPoints(rangeTopLeft, rangeBottomLeft);
2513
+ const rangeRight = getCenterFromTwoPoints(rangeTopRight, rangeBottomRight);
2514
+ const rangeRectInfo = {
2515
+ center: rangeCenter,
2516
+ topLeft: rangeTopLeft,
2517
+ topRight: rangeTopRight,
2518
+ bottomLeft: rangeBottomLeft,
2519
+ bottomRight: rangeBottomRight,
2520
+ top: rangeTop,
2521
+ right: rangeRight,
2522
+ left: rangeLeft,
2523
+ bottom: rangeBottom
2524
+ };
2525
+ return rangeRectInfo;
2169
2526
  }
2170
- return getElementRotateVertexes(elemSize, calcElementCenter({ x: x2, y: y2, w: w2, h: h2, angle: angle2 }), angle2);
2171
- }
2172
- function calcElementQueueVertexesQueueInGroup(groupQueue) {
2173
- const vesList = [];
2174
- let totalX = 0;
2175
- let totalY = 0;
2176
- const rotateActionList = [];
2177
- const elemQueue = [...groupQueue];
2178
- for (let i = 0; i < elemQueue.length; i++) {
2179
- const { x: x2, y: y2, w: w2, h: h2, angle: angle2 = 0 } = elemQueue[i];
2180
- totalX += x2;
2181
- totalY += y2;
2182
- let ves;
2183
- if (i === 0) {
2184
- const elemSize = { x: totalX, y: totalY, w: w2, h: h2, angle: angle2 };
2185
- ves = calcElementVertexes({ x: x2, y: y2, w: w2, h: h2, angle: angle2 });
2186
- rotateActionList.push({
2187
- center: calcElementCenter(elemSize),
2188
- angle: angle2,
2189
- radian: parseAngleToRadian(angle2)
2190
- });
2191
- } else {
2192
- const elemSize = { x: totalX, y: totalY, w: w2, h: h2, angle: angle2 };
2193
- ves = getElementVertexes(elemSize);
2194
- for (let aIdx = 0; aIdx < rotateActionList.length; aIdx++) {
2195
- const { center, radian } = rotateActionList[aIdx];
2196
- ves = rotateVertexes(center, ves, radian);
2197
- }
2198
- const vesCenter = calcElementCenterFromVertexes(ves);
2199
- if (angle2 > 0 || angle2 < 0) {
2200
- const radian = parseAngleToRadian(angle2);
2201
- ves = rotateVertexes(vesCenter, ves, radian);
2202
- }
2203
- rotateActionList.push({
2204
- center: vesCenter,
2205
- angle: angle2,
2206
- radian: parseAngleToRadian(angle2)
2207
- });
2208
- }
2209
- vesList.push(ves);
2210
- }
2211
- return vesList;
2212
- }
2213
- function calcElementVertexesQueueInGroup(targetElem, opts) {
2214
- const { groupQueue } = opts;
2215
- if (!(groupQueue.length > 0)) {
2216
- return [calcElementVertexes(targetElem)];
2217
- }
2218
- const elemQueue = [...groupQueue, ...[targetElem]];
2219
- const vesList = calcElementQueueVertexesQueueInGroup(elemQueue);
2220
- return vesList;
2221
- }
2222
- function calcElementVertexesInGroup(targetElem, opts) {
2223
- const vesList = calcElementVertexesQueueInGroup(targetElem, opts);
2224
- const ves = vesList.pop();
2225
- return ves || null;
2527
+ return viewRectInfo;
2226
2528
  }
2227
2529
  function createControllerElementSizeFromCenter(center, opts) {
2228
2530
  const { x: x2, y: y2 } = center;
@@ -2236,9 +2538,11 @@ var __privateMethod = (obj, member, method) => {
2236
2538
  };
2237
2539
  }
2238
2540
  function calcElementSizeController(elemSize, opts) {
2239
- const { groupQueue, controllerSize, viewScaleInfo } = opts;
2541
+ const { groupQueue, controllerSize, viewScaleInfo, rotateControllerSize, rotateControllerPosition } = opts;
2240
2542
  const ctrlSize = (controllerSize && controllerSize > 0 ? controllerSize : 8) / viewScaleInfo.scale;
2241
2543
  const { x: x2, y: y2, w: w2, h: h2, angle: angle2 = 0 } = elemSize;
2544
+ const rotateCtrlSize = rotateControllerSize;
2545
+ const rotateCtrlPos = rotateControllerPosition;
2242
2546
  const ctrlGroupQueue = [
2243
2547
  ...[
2244
2548
  {
@@ -2259,6 +2563,16 @@ var __privateMethod = (obj, member, method) => {
2259
2563
  totalAngle += angle22;
2260
2564
  });
2261
2565
  const vertexes = calcElementVertexesInGroup(elemSize, { groupQueue });
2566
+ const rotateElemVertexes = calcElementVertexesInGroup(
2567
+ {
2568
+ x: x2,
2569
+ y: y2 - (rotateCtrlPos + rotateCtrlSize / 2) / viewScaleInfo.scale,
2570
+ h: h2 + (rotateCtrlPos * 2 + rotateCtrlSize) / viewScaleInfo.scale,
2571
+ w: w2,
2572
+ angle: angle2
2573
+ },
2574
+ { groupQueue: [...groupQueue] }
2575
+ );
2262
2576
  const topCenter = getCenterFromTwoPoints(vertexes[0], vertexes[1]);
2263
2577
  const rightCenter = getCenterFromTwoPoints(vertexes[1], vertexes[2]);
2264
2578
  const bottomCenter = getCenterFromTwoPoints(vertexes[2], vertexes[3]);
@@ -2267,59 +2581,266 @@ var __privateMethod = (obj, member, method) => {
2267
2581
  const topRightCenter = vertexes[1];
2268
2582
  const bottomRightCenter = vertexes[2];
2269
2583
  const bottomLeftCenter = vertexes[3];
2584
+ const topMiddleSize = createControllerElementSizeFromCenter(topCenter, { size: ctrlSize, angle: totalAngle });
2585
+ const rightMiddleSize = createControllerElementSizeFromCenter(rightCenter, { size: ctrlSize, angle: totalAngle });
2586
+ const bottomMiddleSize = createControllerElementSizeFromCenter(bottomCenter, { size: ctrlSize, angle: totalAngle });
2587
+ const leftMiddleSize = createControllerElementSizeFromCenter(leftCenter, { size: ctrlSize, angle: totalAngle });
2270
2588
  const topLeftSize = createControllerElementSizeFromCenter(topLeftCenter, { size: ctrlSize, angle: totalAngle });
2271
2589
  const topRightSize = createControllerElementSizeFromCenter(topRightCenter, { size: ctrlSize, angle: totalAngle });
2272
2590
  const bottomLeftSize = createControllerElementSizeFromCenter(bottomLeftCenter, { size: ctrlSize, angle: totalAngle });
2273
- const bottomRightSize = createControllerElementSizeFromCenter(bottomRightCenter, { size: ctrlSize, angle: totalAngle });
2591
+ const bottomRightSize = createControllerElementSizeFromCenter(bottomRightCenter, {
2592
+ size: ctrlSize,
2593
+ angle: totalAngle
2594
+ });
2274
2595
  const topLeftVertexes = calcElementVertexes(topLeftSize);
2275
2596
  const topRightVertexes = calcElementVertexes(topRightSize);
2276
2597
  const bottomLeftVertexes = calcElementVertexes(bottomLeftSize);
2277
2598
  const bottomRightVertexes = calcElementVertexes(bottomRightSize);
2278
- const topVertexes = [topLeftVertexes[1], topRightVertexes[0], topRightVertexes[3], topLeftVertexes[2]];
2279
- const rightVertexes = [topRightVertexes[3], topRightVertexes[2], bottomRightVertexes[1], bottomRightVertexes[0]];
2280
- const bottomVertexes = [bottomLeftVertexes[1], bottomRightVertexes[0], bottomRightVertexes[3], bottomLeftVertexes[2]];
2281
- const leftVertexes = [topLeftVertexes[3], topLeftVertexes[2], bottomLeftVertexes[1], bottomLeftVertexes[0]];
2599
+ const topVertexes = [
2600
+ topLeftVertexes[1],
2601
+ topRightVertexes[0],
2602
+ topRightVertexes[3],
2603
+ topLeftVertexes[2]
2604
+ ];
2605
+ const rightVertexes = [
2606
+ topRightVertexes[3],
2607
+ topRightVertexes[2],
2608
+ bottomRightVertexes[1],
2609
+ bottomRightVertexes[0]
2610
+ ];
2611
+ const bottomVertexes = [
2612
+ bottomLeftVertexes[1],
2613
+ bottomRightVertexes[0],
2614
+ bottomRightVertexes[3],
2615
+ bottomLeftVertexes[2]
2616
+ ];
2617
+ const leftVertexes = [
2618
+ topLeftVertexes[3],
2619
+ topLeftVertexes[2],
2620
+ bottomLeftVertexes[1],
2621
+ bottomLeftVertexes[0]
2622
+ ];
2623
+ const topMiddleVertexes = calcElementVertexes(topMiddleSize);
2624
+ const rightMiddleVertexes = calcElementVertexes(rightMiddleSize);
2625
+ const bottomMiddleVertexes = calcElementVertexes(bottomMiddleSize);
2626
+ const leftMiddleVertexes = calcElementVertexes(leftMiddleSize);
2627
+ const rotateCenter = getCenterFromTwoPoints(rotateElemVertexes[0], rotateElemVertexes[1]);
2628
+ const tempRotateSizeRepairRatio = 1.1;
2629
+ const rotateSize = createControllerElementSizeFromCenter(rotateCenter, {
2630
+ size: rotateControllerSize * tempRotateSizeRepairRatio / viewScaleInfo.scale,
2631
+ angle: totalAngle
2632
+ });
2633
+ const rotateVertexes2 = calcElementVertexes(rotateSize);
2282
2634
  const sizeController = {
2635
+ originalElementCenter: calcElementCenter(elemSize),
2636
+ originalElementSize: { ...elemSize },
2283
2637
  elementWrapper: vertexes,
2284
2638
  left: {
2285
2639
  type: "left",
2286
2640
  vertexes: leftVertexes,
2287
- center: leftCenter
2641
+ center: leftCenter,
2642
+ size: ctrlSize
2288
2643
  },
2289
2644
  right: {
2290
2645
  type: "right",
2291
2646
  vertexes: rightVertexes,
2292
- center: rightCenter
2647
+ center: rightCenter,
2648
+ size: ctrlSize
2293
2649
  },
2294
2650
  top: {
2295
2651
  type: "top",
2296
2652
  vertexes: topVertexes,
2297
- center: topCenter
2653
+ center: topCenter,
2654
+ size: ctrlSize
2298
2655
  },
2299
2656
  bottom: {
2300
2657
  type: "bottom",
2301
2658
  vertexes: bottomVertexes,
2302
- center: bottomCenter
2659
+ center: bottomCenter,
2660
+ size: ctrlSize
2303
2661
  },
2304
2662
  topLeft: {
2305
2663
  type: "top-left",
2306
2664
  vertexes: topLeftVertexes,
2307
- center: topLeftCenter
2665
+ center: topLeftCenter,
2666
+ size: ctrlSize
2308
2667
  },
2309
2668
  topRight: {
2310
2669
  type: "top-right",
2311
2670
  vertexes: topRightVertexes,
2312
- center: topRightCenter
2671
+ center: topRightCenter,
2672
+ size: ctrlSize
2313
2673
  },
2314
2674
  bottomLeft: {
2315
2675
  type: "bottom-left",
2316
2676
  vertexes: bottomLeftVertexes,
2317
- center: bottomLeftCenter
2677
+ center: bottomLeftCenter,
2678
+ size: ctrlSize
2318
2679
  },
2319
2680
  bottomRight: {
2320
2681
  type: "bottom-right",
2321
2682
  vertexes: bottomRightVertexes,
2322
- center: bottomRightCenter
2683
+ center: bottomRightCenter,
2684
+ size: ctrlSize
2685
+ },
2686
+ leftMiddle: {
2687
+ type: "left-middle",
2688
+ vertexes: leftMiddleVertexes,
2689
+ center: leftCenter,
2690
+ size: ctrlSize
2691
+ },
2692
+ rightMiddle: {
2693
+ type: "right-middle",
2694
+ vertexes: rightMiddleVertexes,
2695
+ center: rightCenter,
2696
+ size: ctrlSize
2697
+ },
2698
+ topMiddle: {
2699
+ type: "top-middle",
2700
+ vertexes: topMiddleVertexes,
2701
+ center: topCenter,
2702
+ size: ctrlSize
2703
+ },
2704
+ bottomMiddle: {
2705
+ type: "bottom-middle",
2706
+ vertexes: bottomMiddleVertexes,
2707
+ center: bottomCenter,
2708
+ size: ctrlSize
2709
+ },
2710
+ rotate: {
2711
+ type: "rotate",
2712
+ vertexes: rotateVertexes2,
2713
+ center: rotateCenter,
2714
+ size: rotateControllerSize
2715
+ }
2716
+ };
2717
+ return sizeController;
2718
+ }
2719
+ function calcLayoutSizeController(layoutSize, opts) {
2720
+ const { controllerSize, viewScaleInfo } = opts;
2721
+ const ctrlSize = controllerSize && controllerSize > 0 ? controllerSize : 8;
2722
+ const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(layoutSize, { viewScaleInfo });
2723
+ const center = calcElementCenter({ x: x2, y: y2, w: w2, h: h2 });
2724
+ const topCenter = { x: center.x, y: y2 };
2725
+ const rightCenter = { x: x2 + w2, y: center.y };
2726
+ const bottomCenter = { x: center.x, y: y2 + h2 };
2727
+ const leftCenter = { x: x2, y: center.y };
2728
+ const topLeftCenter = { x: x2, y: y2 };
2729
+ const topRightCenter = { x: x2 + w2, y: y2 };
2730
+ const bottomRightCenter = { x: x2 + w2, y: y2 + h2 };
2731
+ const bottomLeftCenter = { x: x2, y: y2 + h2 };
2732
+ const topMiddleSize = createControllerElementSizeFromCenter(topCenter, { size: ctrlSize, angle: 0 });
2733
+ const rightMiddleSize = createControllerElementSizeFromCenter(rightCenter, { size: ctrlSize, angle: 0 });
2734
+ const bottomMiddleSize = createControllerElementSizeFromCenter(bottomCenter, { size: ctrlSize, angle: 0 });
2735
+ const leftMiddleSize = createControllerElementSizeFromCenter(leftCenter, { size: ctrlSize, angle: 0 });
2736
+ const topLeftSize = createControllerElementSizeFromCenter(topLeftCenter, { size: ctrlSize, angle: 0 });
2737
+ const topRightSize = createControllerElementSizeFromCenter(topRightCenter, { size: ctrlSize, angle: 0 });
2738
+ const bottomLeftSize = createControllerElementSizeFromCenter(bottomLeftCenter, { size: ctrlSize, angle: 0 });
2739
+ const bottomRightSize = createControllerElementSizeFromCenter(bottomRightCenter, { size: ctrlSize, angle: 0 });
2740
+ const topLeftVertexes = calcElementVertexes(topLeftSize);
2741
+ const topRightVertexes = calcElementVertexes(topRightSize);
2742
+ const bottomLeftVertexes = calcElementVertexes(bottomLeftSize);
2743
+ const bottomRightVertexes = calcElementVertexes(bottomRightSize);
2744
+ const topVertexes = [
2745
+ topLeftVertexes[1],
2746
+ topRightVertexes[0],
2747
+ topRightVertexes[3],
2748
+ topLeftVertexes[2]
2749
+ ];
2750
+ const rightVertexes = [
2751
+ topRightVertexes[3],
2752
+ topRightVertexes[2],
2753
+ bottomRightVertexes[1],
2754
+ bottomRightVertexes[0]
2755
+ ];
2756
+ const bottomVertexes = [
2757
+ bottomLeftVertexes[1],
2758
+ bottomRightVertexes[0],
2759
+ bottomRightVertexes[3],
2760
+ bottomLeftVertexes[2]
2761
+ ];
2762
+ const leftVertexes = [
2763
+ topLeftVertexes[3],
2764
+ topLeftVertexes[2],
2765
+ bottomLeftVertexes[1],
2766
+ bottomLeftVertexes[0]
2767
+ ];
2768
+ const topMiddleVertexes = calcElementVertexes(topMiddleSize);
2769
+ const rightMiddleVertexes = calcElementVertexes(rightMiddleSize);
2770
+ const bottomMiddleVertexes = calcElementVertexes(bottomMiddleSize);
2771
+ const leftMiddleVertexes = calcElementVertexes(leftMiddleSize);
2772
+ const sizeController = {
2773
+ left: {
2774
+ type: "left",
2775
+ vertexes: leftVertexes,
2776
+ center: leftCenter,
2777
+ size: ctrlSize
2778
+ },
2779
+ right: {
2780
+ type: "right",
2781
+ vertexes: rightVertexes,
2782
+ center: rightCenter,
2783
+ size: ctrlSize
2784
+ },
2785
+ top: {
2786
+ type: "top",
2787
+ vertexes: topVertexes,
2788
+ center: topCenter,
2789
+ size: ctrlSize
2790
+ },
2791
+ bottom: {
2792
+ type: "bottom",
2793
+ vertexes: bottomVertexes,
2794
+ center: bottomCenter,
2795
+ size: ctrlSize
2796
+ },
2797
+ topLeft: {
2798
+ type: "top-left",
2799
+ vertexes: topLeftVertexes,
2800
+ center: topLeftCenter,
2801
+ size: ctrlSize
2802
+ },
2803
+ topRight: {
2804
+ type: "top-right",
2805
+ vertexes: topRightVertexes,
2806
+ center: topRightCenter,
2807
+ size: ctrlSize
2808
+ },
2809
+ bottomLeft: {
2810
+ type: "bottom-left",
2811
+ vertexes: bottomLeftVertexes,
2812
+ center: bottomLeftCenter,
2813
+ size: ctrlSize
2814
+ },
2815
+ bottomRight: {
2816
+ type: "bottom-right",
2817
+ vertexes: bottomRightVertexes,
2818
+ center: bottomRightCenter,
2819
+ size: ctrlSize
2820
+ },
2821
+ leftMiddle: {
2822
+ type: "left-middle",
2823
+ vertexes: leftMiddleVertexes,
2824
+ center: leftCenter,
2825
+ size: ctrlSize
2826
+ },
2827
+ rightMiddle: {
2828
+ type: "right-middle",
2829
+ vertexes: rightMiddleVertexes,
2830
+ center: rightCenter,
2831
+ size: ctrlSize
2832
+ },
2833
+ topMiddle: {
2834
+ type: "top-middle",
2835
+ vertexes: topMiddleVertexes,
2836
+ center: topCenter,
2837
+ size: ctrlSize
2838
+ },
2839
+ bottomMiddle: {
2840
+ type: "bottom-middle",
2841
+ vertexes: bottomMiddleVertexes,
2842
+ center: bottomCenter,
2843
+ size: ctrlSize
2323
2844
  }
2324
2845
  };
2325
2846
  return sizeController;
@@ -2406,7 +2927,6 @@ var __privateMethod = (obj, member, method) => {
2406
2927
  const arr = [];
2407
2928
  let current;
2408
2929
  let level = -1;
2409
- let inComponent = false;
2410
2930
  html2.replace(elemRegExp, (element, index) => {
2411
2931
  const isOpen = element.charAt(1) !== "/";
2412
2932
  const isComment = element.startsWith("<!--");
@@ -2426,7 +2946,7 @@ var __privateMethod = (obj, member, method) => {
2426
2946
  if (isOpen) {
2427
2947
  level++;
2428
2948
  current = parseElement(element);
2429
- if (!current.isVoid && !inComponent && nextChar && nextChar !== "<") {
2949
+ if (!current.isVoid && true && nextChar && nextChar !== "<") {
2430
2950
  const content = html2.slice(start, html2.indexOf("<", start));
2431
2951
  if (content.trim()) {
2432
2952
  current.children.push({
@@ -2480,7 +3000,7 @@ var __privateMethod = (obj, member, method) => {
2480
3000
  }
2481
3001
  function attrString(attrs2) {
2482
3002
  const buff = [];
2483
- for (let key in attrs2) {
3003
+ for (const key in attrs2) {
2484
3004
  buff.push(key + '="' + attrs2[key] + '"');
2485
3005
  }
2486
3006
  if (!buff.length) {
@@ -2574,9 +3094,11 @@ var __privateMethod = (obj, member, method) => {
2574
3094
  textAlign: "left",
2575
3095
  verticalAlign: "top",
2576
3096
  fontSize: 16,
2577
- lineHeight: 20,
3097
+ // lineHeight: 20,
2578
3098
  fontFamily: "sans-serif",
2579
3099
  fontWeight: 400,
3100
+ minInlineSize: "auto",
3101
+ wordBreak: "break-all",
2580
3102
  overflow: "hidden"
2581
3103
  };
2582
3104
  return config;
@@ -2601,7 +3123,7 @@ var __privateMethod = (obj, member, method) => {
2601
3123
  color: detailConfig.color,
2602
3124
  fontFamily: detailConfig.fontFamily,
2603
3125
  fontWeight: detailConfig.fontWeight,
2604
- lineHeight: elementSize.w / defaultText.length,
3126
+ // lineHeight: elementSize.w / defaultText.length,
2605
3127
  fontSize: elementSize.w / defaultText.length,
2606
3128
  textAlign: "center",
2607
3129
  verticalAlign: "middle"
@@ -2633,6 +3155,8 @@ var __privateMethod = (obj, member, method) => {
2633
3155
  const { viewScaleInfo } = opts;
2634
3156
  const { scale } = viewScaleInfo;
2635
3157
  let { borderRadius: borderRadius2 } = viewElem.detail;
3158
+ const { borderDash } = viewElem.detail;
3159
+ const hasBorderDash = Array.isArray(borderDash) && borderDash.length > 0;
2636
3160
  const { boxSizing = defaultElemConfig.boxSizing, borderWidth: borderWidth2 } = viewElem.detail;
2637
3161
  if (Array.isArray(borderWidth2)) {
2638
3162
  borderRadius2 = 0;
@@ -2649,7 +3173,7 @@ var __privateMethod = (obj, member, method) => {
2649
3173
  if (typeof borderWidth2 === "number") {
2650
3174
  bw = (borderWidth2 || 0) * scale;
2651
3175
  }
2652
- if (boxSizing === "border-box") {
3176
+ if (boxSizing === "border-box" && !hasBorderDash) {
2653
3177
  x2 = viewElem.x + bw / 2;
2654
3178
  y2 = viewElem.y + bw / 2;
2655
3179
  w2 = viewElem.w - bw;
@@ -2678,102 +3202,355 @@ var __privateMethod = (obj, member, method) => {
2678
3202
  radiusList
2679
3203
  };
2680
3204
  }
3205
+ function flattenObject(obj, parentKey = "", result = {}, opts) {
3206
+ Object.keys(obj).forEach((key) => {
3207
+ var _a;
3208
+ const currentKey = parentKey ? `${parentKey}${isArrayIndex$1(key) ? `[${key}]` : `.${key}`}` : key;
3209
+ if (!((_a = opts == null ? void 0 : opts.ignorePaths) == null ? void 0 : _a.includes(currentKey))) {
3210
+ const value = obj[key];
3211
+ if (isFlattenable(value)) {
3212
+ flattenObject(value, Array.isArray(value) ? currentKey : currentKey, result, opts);
3213
+ } else {
3214
+ result[currentKey] = value;
3215
+ }
3216
+ }
3217
+ });
3218
+ return result;
3219
+ }
3220
+ function isFlattenable(value) {
3221
+ return typeof value === "object" && value !== null && !(value instanceof Date) || Array.isArray(value);
3222
+ }
3223
+ function isArrayIndex$1(key) {
3224
+ return /^\d+$/.test(key) && !isNaN(Number(key));
3225
+ }
3226
+ function flatObject(obj, opts) {
3227
+ if (typeof obj !== "object" || obj === null) {
3228
+ return { "": obj };
3229
+ }
3230
+ return flattenObject(obj, "", {}, opts);
3231
+ }
3232
+ function toFlattenElement(elem) {
3233
+ return flatObject(elem, { ignorePaths: ["detail.children"] });
3234
+ }
3235
+ function toFlattenLayout(layout) {
3236
+ return flatObject(layout);
3237
+ }
3238
+ function toFlattenGlobal(global) {
3239
+ return flatObject(global);
3240
+ }
3241
+ function toPath(path) {
3242
+ if (Array.isArray(path)) return [...path];
3243
+ return path.split(/\.|\[|\]/).filter((key) => key !== "");
3244
+ }
3245
+ function get(obj, path, defaultValue) {
3246
+ if (!path) {
3247
+ return void 0;
3248
+ }
3249
+ const pathArray = toPath(path);
3250
+ let current = obj;
3251
+ for (const key of pathArray) {
3252
+ if (current === null || current === void 0) {
3253
+ return defaultValue;
3254
+ }
3255
+ current = current[key];
3256
+ }
3257
+ return current !== void 0 ? current : defaultValue;
3258
+ }
3259
+ function set(obj, path, value) {
3260
+ const pathArray = toPath(path);
3261
+ if (pathArray.length === 0) {
3262
+ return obj;
3263
+ }
3264
+ let current = obj;
3265
+ if (current) {
3266
+ for (let i = 0; i < pathArray.length; i++) {
3267
+ const key = pathArray[i];
3268
+ if (i === pathArray.length - 1) {
3269
+ current[key] = value;
3270
+ break;
3271
+ }
3272
+ if (current && ((current == null ? void 0 : current[key]) === void 0 || typeof (current == null ? void 0 : current[key]) !== "object" || (current == null ? void 0 : current[key]) === null)) {
3273
+ const nextKey = pathArray[i + 1];
3274
+ const isNextNumeric = /^\d+$/.test(nextKey);
3275
+ current[key] = isNextNumeric ? [] : {};
3276
+ }
3277
+ current = current == null ? void 0 : current[key];
3278
+ }
3279
+ }
3280
+ return obj;
3281
+ }
3282
+ function del(obj, path) {
3283
+ const pathArray = toPath(path);
3284
+ if (pathArray.length === 0) {
3285
+ return obj;
3286
+ }
3287
+ let current = obj;
3288
+ if (current) {
3289
+ for (let i = 0; i < pathArray.length; i++) {
3290
+ const key = pathArray[i];
3291
+ if (i === pathArray.length - 1) {
3292
+ delete current[key];
3293
+ break;
3294
+ }
3295
+ if (current && ((current == null ? void 0 : current[key]) === void 0 || typeof (current == null ? void 0 : current[key]) !== "object" || (current == null ? void 0 : current[key]) === null)) {
3296
+ const nextKey = pathArray[i + 1];
3297
+ const isNextNumeric = /^\d+$/.test(nextKey);
3298
+ current[key] = isNextNumeric ? [] : {};
3299
+ }
3300
+ current = current == null ? void 0 : current[key];
3301
+ }
3302
+ }
3303
+ return obj;
3304
+ }
2681
3305
  const doNum = (n) => {
2682
3306
  return formatNumber(n, { decimalPlaces: 4 });
2683
3307
  };
2684
- function resizeElementBaseDetail(elem, opts) {
3308
+ function resizeElementBaseDetailByRatio(elem, opts) {
3309
+ const beforeElem = { detail: {} };
3310
+ const afterElem = { detail: {} };
3311
+ const record = {
3312
+ type: "modifyElement",
3313
+ time: Date.now(),
3314
+ content: {
3315
+ method: "modifyElement",
3316
+ uuid: elem.uuid,
3317
+ before: null,
3318
+ after: null
3319
+ }
3320
+ };
2685
3321
  const { detail } = elem;
2686
3322
  const { xRatio, yRatio, maxRatio } = opts;
2687
3323
  const middleRatio = (xRatio + yRatio) / 2;
2688
3324
  const { borderWidth: borderWidth2, borderRadius: borderRadius2, borderDash, shadowOffsetX, shadowOffsetY, shadowBlur } = detail;
2689
3325
  if (typeof borderWidth2 === "number") {
2690
3326
  detail.borderWidth = doNum(borderWidth2 * middleRatio);
3327
+ beforeElem.detail.borderWidth = borderWidth2;
3328
+ afterElem.detail.borderWidth = detail.borderWidth;
2691
3329
  } else if (Array.isArray(detail.borderWidth)) {
2692
3330
  const bw = borderWidth2;
2693
3331
  detail.borderWidth = [doNum(bw[0] * yRatio), doNum(bw[1] * xRatio), doNum(bw[2] * yRatio), doNum(bw[3] * xRatio)];
3332
+ beforeElem.detail.borderWidth = [...bw];
3333
+ afterElem.detail.borderWidth = [...detail.borderWidth];
2694
3334
  }
2695
3335
  if (typeof borderRadius2 === "number") {
2696
3336
  detail.borderRadius = doNum(borderRadius2 * middleRatio);
3337
+ beforeElem.detail.borderRadius = borderRadius2;
3338
+ afterElem.detail.borderRadius = detail.borderRadius;
2697
3339
  } else if (Array.isArray(detail.borderRadius)) {
2698
3340
  const br = borderRadius2;
2699
3341
  detail.borderRadius = [br[0] * xRatio, br[1] * xRatio, br[2] * yRatio, br[3] * yRatio];
3342
+ beforeElem.detail.borderRadius = [...br];
3343
+ afterElem.detail.borderRadius = [...detail.borderRadius];
2700
3344
  }
2701
3345
  if (Array.isArray(borderDash)) {
2702
3346
  borderDash.forEach((dash, i) => {
2703
3347
  detail.borderDash[i] = doNum(dash * maxRatio);
2704
3348
  });
3349
+ beforeElem.detail.borderDash = [...borderDash];
3350
+ afterElem.detail.borderDash = [...detail.borderDash];
2705
3351
  }
2706
3352
  if (typeof shadowOffsetX === "number") {
2707
3353
  detail.shadowOffsetX = doNum(shadowOffsetX * maxRatio);
3354
+ beforeElem.detail.shadowOffsetX = shadowOffsetX;
3355
+ afterElem.detail.shadowOffsetX = detail.shadowOffsetX;
2708
3356
  }
2709
3357
  if (typeof shadowOffsetY === "number") {
2710
- detail.shadowOffsetX = doNum(shadowOffsetY * maxRatio);
3358
+ detail.shadowOffsetY = doNum(shadowOffsetY * maxRatio);
3359
+ beforeElem.detail.shadowOffsetY = shadowOffsetY;
3360
+ afterElem.detail.shadowOffsetY = detail.shadowOffsetY;
2711
3361
  }
2712
3362
  if (typeof shadowBlur === "number") {
2713
- detail.shadowOffsetX = doNum(shadowBlur * maxRatio);
3363
+ detail.shadowBlur = doNum(shadowBlur * maxRatio);
3364
+ beforeElem.detail.shadowBlur = shadowBlur;
3365
+ afterElem.detail.shadowBlur = detail.shadowBlur;
2714
3366
  }
3367
+ record.content.before = toFlattenElement(beforeElem);
3368
+ record.content.after = toFlattenElement(afterElem);
3369
+ return record;
2715
3370
  }
2716
- function resizeElementBase(elem, opts) {
3371
+ function resizeElementBaseByRatio(elem, opts) {
2717
3372
  const { xRatio, yRatio } = opts;
2718
- const { x: x2, y: y2, w: w2, h: h2 } = elem;
3373
+ const { uuid, x: x2, y: y2, w: w2, h: h2 } = elem;
2719
3374
  elem.x = doNum(x2 * xRatio);
2720
3375
  elem.y = doNum(y2 * yRatio);
2721
3376
  elem.w = doNum(w2 * xRatio);
2722
3377
  elem.h = doNum(h2 * yRatio);
2723
- resizeElementBaseDetail(elem, opts);
3378
+ const record = {
3379
+ type: "modifyElement",
3380
+ time: Date.now(),
3381
+ content: {
3382
+ method: "modifyElement",
3383
+ uuid,
3384
+ before: { x: x2, y: y2, w: w2, h: h2 },
3385
+ after: { x: elem.x, y: elem.y, w: elem.w, h: elem.h }
3386
+ }
3387
+ };
3388
+ const detailRecord = resizeElementBaseDetailByRatio(elem, opts);
3389
+ record.content.before = {
3390
+ ...record.content.before,
3391
+ ...detailRecord.content.before
3392
+ };
3393
+ record.content.after = {
3394
+ ...record.content.after,
3395
+ ...detailRecord.content.after
3396
+ };
3397
+ return record;
2724
3398
  }
2725
- function resizeTextElementDetail(elem, opts) {
3399
+ function resizeTextElementDetailByRatio(elem, opts) {
2726
3400
  const { minRatio, maxRatio } = opts;
2727
3401
  const { fontSize: fontSize2, lineHeight: lineHeight2 } = elem.detail;
2728
3402
  const ratio = (minRatio + maxRatio) / 2;
3403
+ const beforeFlattenElem = {};
3404
+ const afterFlattenElem = {};
2729
3405
  if (fontSize2 && fontSize2 > 0) {
2730
3406
  elem.detail.fontSize = doNum(fontSize2 * ratio);
3407
+ beforeFlattenElem["detail.fontSize"] = fontSize2;
3408
+ afterFlattenElem["detail.fontSize"] = elem.detail.fontSize;
2731
3409
  }
2732
3410
  if (lineHeight2 && lineHeight2 > 0) {
2733
3411
  elem.detail.lineHeight = doNum(lineHeight2 * ratio);
2734
- }
2735
- }
2736
- function resizeElement(elem, opts) {
2737
- const { type } = elem;
2738
- resizeElementBase(elem, opts);
2739
- if (type === "circle")
2740
- ;
3412
+ beforeFlattenElem["detail.lineHeight"] = lineHeight2;
3413
+ afterFlattenElem["detail.lineHeight"] = elem.detail.lineHeight;
3414
+ }
3415
+ const record = {
3416
+ type: "modifyElement",
3417
+ time: Date.now(),
3418
+ content: {
3419
+ method: "modifyElement",
3420
+ uuid: elem.uuid,
3421
+ before: beforeFlattenElem,
3422
+ after: afterFlattenElem
3423
+ }
3424
+ };
3425
+ return record;
3426
+ }
3427
+ function deepResizeElementByRatio(elem, opts, record) {
3428
+ const { type, uuid } = elem;
3429
+ const rootRecord = resizeElementBaseByRatio(elem, opts);
3430
+ const rootRecordBefore = { ...rootRecord.content.before, uuid };
3431
+ const rootRecordAfter = { ...rootRecord.content.after, uuid };
3432
+ record == null ? void 0 : record.content.before.push(rootRecordBefore);
3433
+ record == null ? void 0 : record.content.after.push(rootRecordAfter);
3434
+ if (type === "circle") ;
2741
3435
  else if (type === "text") {
2742
- resizeTextElementDetail(elem, opts);
2743
- } else if (type === "image")
2744
- ;
2745
- else if (type === "svg")
2746
- ;
2747
- else if (type === "html")
2748
- ;
2749
- else if (type === "path")
2750
- ;
3436
+ const textRecord = resizeTextElementDetailByRatio(elem, opts);
3437
+ Object.keys(textRecord.content.before || {}).forEach((key) => {
3438
+ var _a;
3439
+ rootRecordBefore[key] = (_a = textRecord.content.before) == null ? void 0 : _a[key];
3440
+ });
3441
+ Object.keys(textRecord.content.after || {}).forEach((key) => {
3442
+ var _a;
3443
+ rootRecordAfter[key] = (_a = textRecord.content.after) == null ? void 0 : _a[key];
3444
+ });
3445
+ } else if (type === "image") ;
3446
+ else if (type === "svg") ;
3447
+ else if (type === "html") ;
3448
+ else if (type === "path") ;
2751
3449
  else if (type === "group" && Array.isArray(elem.detail.children)) {
2752
3450
  elem.detail.children.forEach((child) => {
2753
- resizeElement(child, opts);
3451
+ deepResizeElementByRatio(child, opts, record);
2754
3452
  });
2755
3453
  }
2756
3454
  }
2757
- function deepResizeGroupElement(elem, size) {
2758
- const resizeW = size.w && size.w > 0 ? size.w : elem.w;
2759
- const resizeH = size.h && size.h > 0 ? size.h : elem.h;
2760
- const xRatio = resizeW / elem.w;
2761
- const yRatio = resizeH / elem.h;
2762
- if (xRatio === yRatio && xRatio === 1) {
2763
- return elem;
3455
+ function fixedResizeGroupElementChildren(elem, opts, record) {
3456
+ if (!(elem.type === "group" && Array.isArray(elem.detail.children))) {
3457
+ return;
3458
+ }
3459
+ const { moveX, moveY, moveH, moveW } = opts;
3460
+ let childChangedX = 0;
3461
+ let childChangedY = 0;
3462
+ let needReszieChildren = false;
3463
+ if ((moveX !== 0 || moveY !== 0) && (moveH !== 0 || moveW !== 0)) {
3464
+ needReszieChildren = true;
3465
+ childChangedX = -moveX;
3466
+ childChangedY = -moveY;
3467
+ }
3468
+ if (needReszieChildren !== true) {
3469
+ return;
3470
+ }
3471
+ elem.detail.children.forEach((child) => {
3472
+ const { uuid, x: x2, y: y2 } = child;
3473
+ const afterX = x2 + childChangedX;
3474
+ const afterY = y2 + childChangedY;
3475
+ const before = { uuid, x: x2, y: y2 };
3476
+ const after = { uuid, x: afterX, y: afterY };
3477
+ child.x = afterX;
3478
+ child.y = afterY;
3479
+ record == null ? void 0 : record.content.before.push(before);
3480
+ record == null ? void 0 : record.content.after.push(after);
3481
+ });
3482
+ }
3483
+ function resizeEffectGroupElement(elem, size, opts) {
3484
+ const record = {
3485
+ type: "resizeElements",
3486
+ time: Date.now(),
3487
+ content: {
3488
+ method: "modifyElements",
3489
+ before: [],
3490
+ after: []
3491
+ }
3492
+ };
3493
+ const uuid = elem.uuid;
3494
+ const originX = elem.x;
3495
+ const originY = elem.y;
3496
+ const originW = elem.w;
3497
+ const originH = elem.h;
3498
+ const resizeX = istype.number(size.x) ? size.x : elem.x;
3499
+ const resizeY = istype.number(size.y) ? size.y : elem.y;
3500
+ const resizeW = (size.w && size.w > 0 ? size.w : elem.w) || 0;
3501
+ const resizeH = (size.h && size.h > 0 ? size.h : elem.h) || 0;
3502
+ const beforeGroupElem = { uuid, x: originX, y: originY, w: originW, h: originH };
3503
+ const afterGroupElem = { uuid, x: resizeX, y: resizeY, w: resizeW, h: resizeH };
3504
+ if ((opts == null ? void 0 : opts.resizeEffect) === "deepResize") {
3505
+ record.content.before.push(beforeGroupElem);
3506
+ record.content.after.push(afterGroupElem);
3507
+ const xRatio = resizeW / elem.w;
3508
+ const yRatio = resizeH / elem.h;
3509
+ if (xRatio === yRatio && xRatio === 1) {
3510
+ return record;
3511
+ }
3512
+ const minRatio = Math.min(xRatio, yRatio);
3513
+ const maxRatio = Math.max(xRatio, yRatio);
3514
+ elem.w = resizeW;
3515
+ elem.h = resizeH;
3516
+ const resizeRadioOpts = { xRatio, yRatio, minRatio, maxRatio };
3517
+ if (elem.type === "group" && Array.isArray(elem.detail.children)) {
3518
+ elem.detail.children.forEach((child) => {
3519
+ deepResizeElementByRatio(child, resizeRadioOpts, record);
3520
+ });
3521
+ }
3522
+ const groupDetailRecord = resizeElementBaseDetailByRatio(elem, resizeRadioOpts);
3523
+ Object.keys(groupDetailRecord.content.before || {}).forEach((key) => {
3524
+ var _a;
3525
+ beforeGroupElem[key] = (_a = groupDetailRecord.content.before) == null ? void 0 : _a[key];
3526
+ });
3527
+ Object.keys(groupDetailRecord.content.after || {}).forEach((key) => {
3528
+ var _a;
3529
+ afterGroupElem[key] = (_a = groupDetailRecord.content.after) == null ? void 0 : _a[key];
3530
+ });
3531
+ return record;
3532
+ }
3533
+ if ((opts == null ? void 0 : opts.resizeEffect) === "fixed") {
3534
+ record.content.before.push(beforeGroupElem);
3535
+ record.content.after.push(afterGroupElem);
3536
+ const moveX = resizeX - elem.x;
3537
+ const moveY = resizeY - elem.y;
3538
+ const moveW = resizeW - elem.w;
3539
+ const moveH = resizeH - elem.h;
3540
+ fixedResizeGroupElementChildren(elem, { moveX, moveY, moveH, moveW }, record);
3541
+ elem.w = resizeW;
3542
+ elem.h = resizeH;
3543
+ elem.x = resizeX;
3544
+ elem.y = resizeY;
3545
+ return record;
2764
3546
  }
2765
- const minRatio = Math.min(xRatio, yRatio);
2766
- const maxRatio = Math.max(xRatio, yRatio);
2767
3547
  elem.w = resizeW;
2768
3548
  elem.h = resizeH;
2769
- const opts = { xRatio, yRatio, minRatio, maxRatio };
2770
- if (elem.type === "group" && Array.isArray(elem.detail.children)) {
2771
- elem.detail.children.forEach((child) => {
2772
- resizeElement(child, opts);
2773
- });
2774
- }
2775
- resizeElementBaseDetail(elem, opts);
2776
- return elem;
3549
+ elem.x = resizeX;
3550
+ elem.y = resizeY;
3551
+ record.content.before.push(beforeGroupElem);
3552
+ record.content.after.push(afterGroupElem);
3553
+ return record;
2777
3554
  }
2778
3555
  const defaultViewWidth = 200;
2779
3556
  const defaultViewHeight = 200;
@@ -2832,9 +3609,9 @@ var __privateMethod = (obj, member, method) => {
2832
3609
  detail = getDefaultElementGroupDetail();
2833
3610
  }
2834
3611
  const elem = {
3612
+ uuid: createUUID(),
2835
3613
  ...elementSize,
2836
3614
  ...baseElem,
2837
- uuid: createUUID(),
2838
3615
  type,
2839
3616
  detail: {
2840
3617
  ...detail,
@@ -2896,15 +3673,16 @@ var __privateMethod = (obj, member, method) => {
2896
3673
  return deleteElementInListByPosition(position, list);
2897
3674
  }
2898
3675
  function moveElementPosition(elements, opts) {
2899
- const { from, to } = opts;
3676
+ const from = [...opts.from];
3677
+ const to = [...opts.to];
2900
3678
  if (from.length === 0 || to.length === 0) {
2901
- return elements;
3679
+ return { elements, from, to };
2902
3680
  }
2903
3681
  if (from.length <= to.length) {
2904
3682
  for (let i = 0; i < from.length; i++) {
2905
3683
  if (to[i] === from[i]) {
2906
3684
  if (i === from.length - 1) {
2907
- return elements;
3685
+ return { elements, from, to };
2908
3686
  }
2909
3687
  continue;
2910
3688
  }
@@ -2914,18 +3692,59 @@ var __privateMethod = (obj, member, method) => {
2914
3692
  if (target) {
2915
3693
  const insterResult = insertElementToListByPosition(target, to, elements);
2916
3694
  if (!insterResult) {
2917
- return elements;
3695
+ return { elements, from, to };
2918
3696
  }
2919
3697
  let trimDeletePosIndex = -1;
2920
- for (let i = 0; i < from.length; i++) {
2921
- if (!(to[i] >= 0)) {
2922
- break;
3698
+ let isEffectToIndex = false;
3699
+ if (from.length >= 1 && to.length >= 1) {
3700
+ if (from.length <= to.length) {
3701
+ if (from.length === 1) {
3702
+ if (from[0] < to[0]) {
3703
+ isEffectToIndex = true;
3704
+ }
3705
+ } else {
3706
+ for (let i = 0; i < from.length; i++) {
3707
+ if (from[i] === to[i]) {
3708
+ if (from.length === from.length - 1) {
3709
+ isEffectToIndex = true;
3710
+ break;
3711
+ }
3712
+ } else {
3713
+ break;
3714
+ }
3715
+ }
3716
+ }
2923
3717
  }
2924
- if (to[i] === from[i]) {
2925
- continue;
3718
+ if (from.length >= to.length) {
3719
+ if (to.length === 1) {
3720
+ if (to[0] < from[0]) {
3721
+ isEffectToIndex = true;
3722
+ }
3723
+ } else {
3724
+ for (let i = 0; i < to.length; i++) {
3725
+ if (i === to.length - 1 && to[i] < from[i]) {
3726
+ isEffectToIndex = true;
3727
+ }
3728
+ if (from[i] === to[i]) {
3729
+ continue;
3730
+ } else {
3731
+ break;
3732
+ }
3733
+ }
3734
+ }
2926
3735
  }
2927
- if (to[i] < from[i] && i == to.length - 1) {
2928
- trimDeletePosIndex = i;
3736
+ }
3737
+ if (isEffectToIndex === true) {
3738
+ for (let i = 0; i < from.length; i++) {
3739
+ if (!(to[i] >= 0)) {
3740
+ break;
3741
+ }
3742
+ if (to[i] === from[i]) {
3743
+ continue;
3744
+ }
3745
+ if (to[i] < from[i] && i == to.length - 1) {
3746
+ trimDeletePosIndex = i;
3747
+ }
2929
3748
  }
2930
3749
  }
2931
3750
  if (trimDeletePosIndex >= 0) {
@@ -2935,61 +3754,799 @@ var __privateMethod = (obj, member, method) => {
2935
3754
  }
2936
3755
  deleteElementInListByPosition(from, elements);
2937
3756
  }
2938
- return elements;
2939
- }
2940
- function mergeElement(originElem, updateContent) {
2941
- var _a;
2942
- const commonKeys = Object.keys(updateContent);
2943
- for (let i = 0; i < commonKeys.length; i++) {
2944
- const commonKey = commonKeys[i];
2945
- if (["x", "y", "w", "h", "angle", "name"].includes(commonKey)) {
2946
- originElem[commonKey] = updateContent[commonKey];
2947
- } else if (["detail", "operations"].includes(commonKey)) {
2948
- if (istype.json(updateContent[commonKey])) {
2949
- if (!(originElem == null ? void 0 : originElem.hasOwnProperty(commonKey))) {
2950
- originElem[commonKey] = {};
2951
- }
2952
- if (istype.json(originElem[commonKey])) {
2953
- originElem[commonKey] = { ...originElem[commonKey], ...updateContent[commonKey] };
2954
- }
2955
- } else if (istype.array(updateContent[commonKey])) {
2956
- if (!(originElem == null ? void 0 : originElem.hasOwnProperty(commonKey))) {
2957
- originElem[commonKey] = [];
2958
- }
2959
- if (istype.array(originElem[commonKey])) {
2960
- (_a = updateContent == null ? void 0 : updateContent[commonKey]) == null ? void 0 : _a.forEach((item, i2) => {
2961
- originElem[commonKey][i2] = item;
2962
- });
2963
- originElem[commonKey] = [...originElem[commonKey], ...updateContent[commonKey]];
2964
- }
3757
+ return { elements, from, to };
3758
+ }
3759
+ function mergeElement(originElem, updateContent, opts) {
3760
+ const updatedFlatten = toFlattenElement(updateContent);
3761
+ const ignoreKeys = ["uuid", "type"];
3762
+ const updatedKeys = Object.keys(updatedFlatten);
3763
+ updatedKeys.forEach((key) => {
3764
+ if (!ignoreKeys.includes(key)) {
3765
+ const value = updatedFlatten[key];
3766
+ del(originElem, key);
3767
+ if (value !== void 0) {
3768
+ set(originElem, key, value);
2965
3769
  }
2966
3770
  }
3771
+ });
3772
+ if ((opts == null ? void 0 : opts.strict) === true) {
3773
+ const originFlatten = toFlattenElement(originElem);
3774
+ const originKeys = Object.keys(originFlatten);
3775
+ originKeys.forEach((key) => {
3776
+ if (!ignoreKeys.includes(key)) {
3777
+ if (!updatedKeys.includes(key)) {
3778
+ del(originElem, key);
3779
+ }
3780
+ }
3781
+ });
2967
3782
  }
2968
3783
  return originElem;
2969
3784
  }
2970
3785
  function updateElementInList(uuid, updateContent, elements) {
2971
- var _a, _b;
3786
+ var _a, _b, _c;
2972
3787
  let targetElement = null;
2973
3788
  for (let i = 0; i < elements.length; i++) {
2974
3789
  const elem = elements[i];
2975
3790
  if (elem.uuid === uuid) {
2976
- if (elem.type === "group" && ((_a = elem.operations) == null ? void 0 : _a.deepResize) === true) {
2977
- if (updateContent.w && updateContent.w > 0 || updateContent.h && updateContent.h > 0) {
2978
- deepResizeGroupElement(elem, {
2979
- w: updateContent.w,
2980
- h: updateContent.h
2981
- });
2982
- }
3791
+ if (elem.type === "group" && ((_a = elem.operations) == null ? void 0 : _a.resizeEffect)) {
3792
+ resizeEffectGroupElement(
3793
+ elem,
3794
+ {
3795
+ ...updateContent
3796
+ },
3797
+ {
3798
+ resizeEffect: (_b = elem.operations) == null ? void 0 : _b.resizeEffect
3799
+ }
3800
+ );
2983
3801
  }
2984
3802
  mergeElement(elem, updateContent);
2985
3803
  targetElement = elem;
2986
3804
  break;
2987
3805
  } else if (elem.type === "group") {
2988
- targetElement = updateElementInList(uuid, updateContent, ((_b = elem == null ? void 0 : elem.detail) == null ? void 0 : _b.children) || []);
3806
+ targetElement = updateElementInList(uuid, updateContent, ((_c = elem == null ? void 0 : elem.detail) == null ? void 0 : _c.children) || []);
2989
3807
  }
2990
3808
  }
2991
3809
  return targetElement;
2992
3810
  }
3811
+ function updateElementInListByPosition(position, updateContent, elements, opts) {
3812
+ var _a, _b;
3813
+ const elem = findElementFromListByPosition(position, elements);
3814
+ if (elem) {
3815
+ if (elem.type === "group" && ((_a = elem.operations) == null ? void 0 : _a.resizeEffect)) {
3816
+ resizeEffectGroupElement(
3817
+ elem,
3818
+ {
3819
+ ...updateContent
3820
+ },
3821
+ {
3822
+ resizeEffect: (_b = elem.operations) == null ? void 0 : _b.resizeEffect
3823
+ }
3824
+ );
3825
+ }
3826
+ mergeElement(elem, updateContent, opts);
3827
+ }
3828
+ return elem;
3829
+ }
3830
+ function calcViewCenterContent(data, opts) {
3831
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
3832
+ let offsetX = 0;
3833
+ let offsetY = 0;
3834
+ let scale = 1;
3835
+ let contentX = ((_b = (_a = data == null ? void 0 : data.elements) == null ? void 0 : _a[0]) == null ? void 0 : _b.x) || 0;
3836
+ let contentY = ((_d = (_c = data == null ? void 0 : data.elements) == null ? void 0 : _c[0]) == null ? void 0 : _d.y) || 0;
3837
+ let contentW = ((_f = (_e = data == null ? void 0 : data.elements) == null ? void 0 : _e[0]) == null ? void 0 : _f.w) || 0;
3838
+ let contentH = ((_h = (_g = data == null ? void 0 : data.elements) == null ? void 0 : _g[0]) == null ? void 0 : _h.h) || 0;
3839
+ const { width, height } = opts.viewSizeInfo;
3840
+ if (data.layout && ((_j = (_i = data.layout) == null ? void 0 : _i.detail) == null ? void 0 : _j.overflow) === "hidden") {
3841
+ contentX = 0;
3842
+ contentY = 0;
3843
+ contentW = data.layout.w || 0;
3844
+ contentH = data.layout.h || 0;
3845
+ } else {
3846
+ data.elements.forEach((elem) => {
3847
+ const elemSize = {
3848
+ x: elem.x,
3849
+ y: elem.y,
3850
+ w: elem.w,
3851
+ h: elem.h,
3852
+ angle: elem.angle
3853
+ };
3854
+ if (elemSize.angle && (elemSize.angle > 0 || elemSize.angle < 0)) {
3855
+ const ves = rotateElementVertexes(elemSize);
3856
+ if (ves.length === 4) {
3857
+ const xList = [ves[0].x, ves[1].x, ves[2].x, ves[3].x];
3858
+ const yList = [ves[0].y, ves[1].y, ves[2].y, ves[3].y];
3859
+ elemSize.x = Math.min(...xList);
3860
+ elemSize.y = Math.min(...yList);
3861
+ elemSize.w = Math.abs(Math.max(...xList) - Math.min(...xList));
3862
+ elemSize.h = Math.abs(Math.max(...yList) - Math.min(...yList));
3863
+ }
3864
+ }
3865
+ const areaStartX = Math.min(elemSize.x, contentX);
3866
+ const areaStartY = Math.min(elemSize.y, contentY);
3867
+ const areaEndX = Math.max(elemSize.x + elemSize.w, contentX + contentW);
3868
+ const areaEndY = Math.max(elemSize.y + elemSize.h, contentY + contentH);
3869
+ contentX = areaStartX;
3870
+ contentY = areaStartY;
3871
+ contentW = Math.abs(areaEndX - areaStartX);
3872
+ contentH = Math.abs(areaEndY - areaStartY);
3873
+ });
3874
+ }
3875
+ if (data.layout) {
3876
+ const { x: x2, y: y2, w: w2, h: h2 } = data.layout;
3877
+ if (is.x(x2) && is.y(y2) && is.w(w2) && is.h(h2)) {
3878
+ contentX = Math.min(contentX, x2);
3879
+ contentY = Math.min(contentY, y2);
3880
+ contentW = Math.max(contentW, w2);
3881
+ contentH = Math.max(contentH, h2);
3882
+ }
3883
+ }
3884
+ if (contentW > 0 && contentH > 0) {
3885
+ const scaleW = formatNumber(width / contentW, { decimalPlaces: 4 });
3886
+ const scaleH = formatNumber(height / contentH, { decimalPlaces: 4 });
3887
+ scale = Math.min(scaleW, scaleH, 1);
3888
+ offsetX = (contentW * scale - width) / 2 / scale + contentX;
3889
+ offsetY = (contentH * scale - height) / 2 / scale + contentY;
3890
+ }
3891
+ const result = {
3892
+ offsetX: formatNumber(offsetX, { decimalPlaces: 0 }),
3893
+ offsetY: formatNumber(offsetY, { decimalPlaces: 0 }),
3894
+ scale
3895
+ };
3896
+ return result;
3897
+ }
3898
+ function calcViewCenter(opts) {
3899
+ let x2 = 0;
3900
+ let y2 = 0;
3901
+ if (opts) {
3902
+ const { viewScaleInfo, viewSizeInfo } = opts;
3903
+ const { offsetLeft, offsetTop, scale } = viewScaleInfo;
3904
+ const { width, height } = viewSizeInfo;
3905
+ x2 = 0 - offsetLeft + width / scale / 2;
3906
+ y2 = 0 - offsetTop + height / scale / 2;
3907
+ }
3908
+ const p = {
3909
+ x: x2,
3910
+ y: y2
3911
+ };
3912
+ return p;
3913
+ }
3914
+ const baseFontFamilyList = ["-apple-system", '"system-ui"', ' "Segoe UI"', " Roboto", '"Helvetica Neue"', "Arial", '"Noto Sans"', " sans-serif"];
3915
+ function enhanceFontFamliy(fontFamily2) {
3916
+ return [fontFamily2, ...baseFontFamilyList].join(", ");
3917
+ }
3918
+ function flatElementSize(elemSize, opts) {
3919
+ const { groupQueue } = opts;
3920
+ let { x: x2, y: y2 } = elemSize;
3921
+ const { w: w2, h: h2, angle: angle2 = 0 } = elemSize;
3922
+ let totalAngle = 0;
3923
+ groupQueue.forEach((group) => {
3924
+ x2 += group.x;
3925
+ y2 += group.y;
3926
+ totalAngle += group.angle || 0;
3927
+ });
3928
+ totalAngle = limitAngle(totalAngle);
3929
+ if (totalAngle === 0) {
3930
+ return {
3931
+ x: x2,
3932
+ y: y2,
3933
+ w: w2,
3934
+ h: h2,
3935
+ angle: angle2
3936
+ };
3937
+ }
3938
+ totalAngle += elemSize.angle || 0;
3939
+ totalAngle = limitAngle(totalAngle);
3940
+ const vertexes = calcElementVertexesInGroup(elemSize, { groupQueue });
3941
+ const center = calcElementCenterFromVertexes(vertexes);
3942
+ const start = rotatePoint(center, vertexes[0], parseAngleToRadian(0 - totalAngle));
3943
+ x2 = start.x;
3944
+ y2 = start.y;
3945
+ return {
3946
+ x: x2,
3947
+ y: y2,
3948
+ w: w2,
3949
+ h: h2,
3950
+ angle: totalAngle
3951
+ };
3952
+ }
3953
+ function isValidElement(elem) {
3954
+ var _a;
3955
+ if (["rect", "circle"].includes(elem.type)) {
3956
+ const detail = elem.detail;
3957
+ if (!detail.background && !detail.borderWidth) {
3958
+ return false;
3959
+ }
3960
+ if (detail.background === "transparent" && !detail.borderWidth) {
3961
+ return false;
3962
+ }
3963
+ }
3964
+ if (["group"].includes(elem.type)) {
3965
+ const detail = elem.detail || {};
3966
+ const { children } = detail;
3967
+ if (!(children.length > 0) && !detail.background && !detail.borderWidth) {
3968
+ return false;
3969
+ }
3970
+ if (!(children.length > 0) && detail.background === "transparent" && !detail.borderWidth) {
3971
+ return false;
3972
+ }
3973
+ }
3974
+ if (elem.type === "text") {
3975
+ if (!elem.detail.text) {
3976
+ return false;
3977
+ }
3978
+ }
3979
+ if (elem.type === "image") {
3980
+ if (!elem.detail.src) {
3981
+ return false;
3982
+ }
3983
+ }
3984
+ if (elem.type === "html") {
3985
+ if (!elem.detail.html) {
3986
+ return false;
3987
+ }
3988
+ }
3989
+ if (elem.type === "svg") {
3990
+ if (!elem.detail.svg) {
3991
+ return false;
3992
+ }
3993
+ }
3994
+ if (elem.type === "path") {
3995
+ const detail = elem.detail;
3996
+ if (!(((_a = detail == null ? void 0 : detail.commands) == null ? void 0 : _a.length) > 0)) {
3997
+ return false;
3998
+ }
3999
+ }
4000
+ return true;
4001
+ }
4002
+ function flatElementList(list) {
4003
+ const elemeList = [];
4004
+ const currentGroupQueue = [];
4005
+ const _resetElemSize = (elem) => {
4006
+ if (!isValidElement(elem)) {
4007
+ return;
4008
+ }
4009
+ const newSize = flatElementSize(elem, { groupQueue: currentGroupQueue });
4010
+ const resizeElem = {
4011
+ ...elem,
4012
+ ...newSize
4013
+ };
4014
+ elemeList.push(resizeElem);
4015
+ };
4016
+ const _walk = (elem) => {
4017
+ var _a;
4018
+ if (((_a = elem == null ? void 0 : elem.operations) == null ? void 0 : _a.invisible) === true) {
4019
+ return;
4020
+ }
4021
+ if (elem.type === "group") {
4022
+ const { detail } = elem;
4023
+ const { children, ...restDetail } = detail;
4024
+ _resetElemSize({ ...elem, ...{ detail: { ...restDetail, children: [] } } });
4025
+ currentGroupQueue.push(elem);
4026
+ children.forEach((child) => {
4027
+ _walk(child);
4028
+ });
4029
+ currentGroupQueue.pop();
4030
+ } else {
4031
+ _resetElemSize(elem);
4032
+ }
4033
+ };
4034
+ for (let i = 0; i < list.length; i++) {
4035
+ const elem = list[i];
4036
+ _walk(elem);
4037
+ }
4038
+ return elemeList;
4039
+ }
4040
+ function groupElementsByPosition(list, positions) {
4041
+ if (positions.length > 1) {
4042
+ let isValidPositions = true;
4043
+ let lastIndexs = [];
4044
+ for (let i = 1; i < positions.length; i++) {
4045
+ const prevPosition = positions[i - 1];
4046
+ const position = positions[i];
4047
+ if (!(prevPosition.length > 0 && position.length > 0)) {
4048
+ isValidPositions = false;
4049
+ break;
4050
+ }
4051
+ if (prevPosition.length !== position.length) {
4052
+ isValidPositions = false;
4053
+ break;
4054
+ }
4055
+ const temp1 = [...prevPosition];
4056
+ const temp2 = [...position];
4057
+ const lastIndex1 = temp1.pop();
4058
+ const lastIndex2 = temp2.pop();
4059
+ if (i === 1 && typeof lastIndex1 === "number" && lastIndex1 >= 0) {
4060
+ lastIndexs.push(lastIndex1);
4061
+ }
4062
+ if (typeof lastIndex2 === "number" && lastIndex2 >= 0) {
4063
+ lastIndexs.push(lastIndex2);
4064
+ }
4065
+ }
4066
+ if (isValidPositions !== true) {
4067
+ console.error("[idraw]: The grouped elements are not siblings!");
4068
+ return list;
4069
+ }
4070
+ lastIndexs.sort((a, b) => a - b);
4071
+ const groupParentPosition = [...positions[0]].splice(0, positions[0].length - 1);
4072
+ const groupChildren = [];
4073
+ const groupPosition = [...groupParentPosition, lastIndexs[0]];
4074
+ for (let i = 0; i < lastIndexs.length; i++) {
4075
+ const position = [...groupParentPosition, lastIndexs[i]];
4076
+ const elem = findElementFromListByPosition(position, list);
4077
+ if (elem) {
4078
+ groupChildren.push(elem);
4079
+ }
4080
+ }
4081
+ const groupSize = calcElementListSize(groupChildren);
4082
+ for (let i = 0; i < groupChildren.length; i++) {
4083
+ const elem = groupChildren[i];
4084
+ if (elem) {
4085
+ elem.x -= groupSize.x;
4086
+ elem.y -= groupSize.y;
4087
+ }
4088
+ }
4089
+ for (let i = lastIndexs.length - 1; i >= 0; i--) {
4090
+ const position = [...groupParentPosition, lastIndexs[i]];
4091
+ deleteElementInListByPosition(position, list);
4092
+ }
4093
+ const group = {
4094
+ name: "Group",
4095
+ uuid: createUUID(),
4096
+ type: "group",
4097
+ ...groupSize,
4098
+ detail: {
4099
+ children: groupChildren
4100
+ }
4101
+ };
4102
+ insertElementToListByPosition(group, groupPosition, list);
4103
+ }
4104
+ return list;
4105
+ }
4106
+ function ungroupElementsByPosition(list, position) {
4107
+ var _a;
4108
+ const elem = findElementFromListByPosition(position, list);
4109
+ if (!(elem && (elem == null ? void 0 : elem.type) === "group" && Array.isArray((_a = elem == null ? void 0 : elem.detail) == null ? void 0 : _a.children))) {
4110
+ console.error("[idraw]: The ungrouped element is not a group element!");
4111
+ }
4112
+ const groupParentPosition = [...position].splice(0, position.length - 1);
4113
+ const groupLastIndex = position[position.length - 1];
4114
+ const { x: x2, y: y2 } = elem;
4115
+ deleteElementInListByPosition(position, list);
4116
+ elem.detail.children.forEach((child, i) => {
4117
+ child.x += x2;
4118
+ child.y += y2;
4119
+ const elemPosition = [...groupParentPosition, groupLastIndex + i];
4120
+ insertElementToListByPosition(child, elemPosition, list);
4121
+ });
4122
+ return list;
4123
+ }
4124
+ function calcPointMoveElementInGroup(start, end, groupQueue) {
4125
+ let moveX = end.x - start.x;
4126
+ let moveY = end.y - start.y;
4127
+ const pointGroupQueue = [];
4128
+ groupQueue.forEach((group) => {
4129
+ const { x: x2, y: y2, w: w2, h: h2, angle: angle2 = 0 } = group;
4130
+ pointGroupQueue.push({
4131
+ x: x2,
4132
+ y: y2,
4133
+ w: w2,
4134
+ h: h2,
4135
+ angle: 0 - angle2
4136
+ });
4137
+ });
4138
+ if ((groupQueue == null ? void 0 : groupQueue.length) > 0) {
4139
+ const startInGroup = rotatePointInGroup(start, pointGroupQueue);
4140
+ const endInGroup = rotatePointInGroup(end, pointGroupQueue);
4141
+ moveX = endInGroup.x - startInGroup.x;
4142
+ moveY = endInGroup.y - startInGroup.y;
4143
+ }
4144
+ return {
4145
+ moveX,
4146
+ moveY
4147
+ };
4148
+ }
4149
+ function mergeLayout(originLayout, updateContent, opts) {
4150
+ const updatedFlatten = toFlattenLayout(updateContent);
4151
+ const ignoreKeys = [];
4152
+ const updatedKeys = Object.keys(updatedFlatten);
4153
+ updatedKeys.forEach((key) => {
4154
+ if (!ignoreKeys.includes(key)) {
4155
+ const value = updatedFlatten[key];
4156
+ del(originLayout, key);
4157
+ if (value !== void 0) {
4158
+ set(originLayout, key, value);
4159
+ }
4160
+ }
4161
+ });
4162
+ if ((opts == null ? void 0 : opts.strict) === true) {
4163
+ const originFlatten = toFlattenLayout(originLayout);
4164
+ const originKeys = Object.keys(originFlatten);
4165
+ originKeys.forEach((key) => {
4166
+ if (!ignoreKeys.includes(key)) {
4167
+ if (!updatedKeys.includes(key)) {
4168
+ del(originLayout, key);
4169
+ }
4170
+ }
4171
+ });
4172
+ }
4173
+ return originLayout;
4174
+ }
4175
+ function mergeGlobal(originGlobal, updateContent, opts) {
4176
+ const updatedFlatten = toFlattenGlobal(updateContent);
4177
+ const ignoreKeys = [];
4178
+ const updatedKeys = Object.keys(updatedFlatten);
4179
+ updatedKeys.forEach((key) => {
4180
+ if (!ignoreKeys.includes(key)) {
4181
+ const value = updatedFlatten[key];
4182
+ del(originGlobal, key);
4183
+ if (value !== void 0) {
4184
+ set(originGlobal, key, value);
4185
+ }
4186
+ }
4187
+ });
4188
+ if ((opts == null ? void 0 : opts.strict) === true) {
4189
+ const originFlatten = toFlattenGlobal(originGlobal);
4190
+ const originKeys = Object.keys(originFlatten);
4191
+ originKeys.forEach((key) => {
4192
+ if (!ignoreKeys.includes(key)) {
4193
+ if (!updatedKeys.includes(key)) {
4194
+ del(originGlobal, key);
4195
+ }
4196
+ }
4197
+ });
4198
+ }
4199
+ return originGlobal;
4200
+ }
4201
+ function calcResultMovePosition(opts) {
4202
+ const from = [...opts.from];
4203
+ const to = [...opts.to];
4204
+ if (from.length === 0 || to.length === 0) {
4205
+ return null;
4206
+ }
4207
+ if (from.length <= to.length) {
4208
+ for (let i = 0; i < from.length; i++) {
4209
+ if (to[i] === from[i]) {
4210
+ if (i === from.length - 1) {
4211
+ return null;
4212
+ }
4213
+ continue;
4214
+ }
4215
+ }
4216
+ }
4217
+ let moveDirection = null;
4218
+ if (from.length >= 1 && to.length >= 1) {
4219
+ if (from.length <= to.length) {
4220
+ if (from.length === 1) {
4221
+ if (from[0] < to[0]) {
4222
+ moveDirection = "up-down";
4223
+ }
4224
+ } else {
4225
+ for (let i = 0; i < from.length; i++) {
4226
+ if (from[i] === to[i]) {
4227
+ if (from.length === from.length - 1) {
4228
+ moveDirection = "up-down";
4229
+ break;
4230
+ }
4231
+ } else {
4232
+ break;
4233
+ }
4234
+ }
4235
+ }
4236
+ }
4237
+ if (from.length >= to.length) {
4238
+ if (to.length === 1) {
4239
+ if (to[0] < from[0]) {
4240
+ moveDirection = "down-up";
4241
+ }
4242
+ } else {
4243
+ for (let i = 0; i < to.length; i++) {
4244
+ if (i === to.length - 1 && to[i] < from[i]) {
4245
+ moveDirection = "down-up";
4246
+ }
4247
+ if (from[i] === to[i]) {
4248
+ continue;
4249
+ } else {
4250
+ break;
4251
+ }
4252
+ }
4253
+ }
4254
+ }
4255
+ }
4256
+ const startEffectIndex = from.length - 1;
4257
+ const endEffectIndex = to.length - 1;
4258
+ if (moveDirection === "up-down" && startEffectIndex >= 0) {
4259
+ to[startEffectIndex] -= 1;
4260
+ } else if (moveDirection === "down-up" && endEffectIndex >= 0) {
4261
+ from[endEffectIndex] += 1;
4262
+ }
4263
+ return { from, to };
4264
+ }
4265
+ function calcRevertMovePosition(opts) {
4266
+ const result = calcResultMovePosition(opts);
4267
+ if (!result) {
4268
+ return result;
4269
+ }
4270
+ return {
4271
+ from: [...result.to],
4272
+ to: [...result.from]
4273
+ };
4274
+ }
4275
+ function merge(target, source) {
4276
+ const result = target;
4277
+ for (const key in source) {
4278
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
4279
+ if (typeof source[key] === "object" && source[key] !== null && typeof result[key] === "object" && result[key] !== null) {
4280
+ result[key] = merge(result[key], source[key]);
4281
+ } else {
4282
+ result[key] = source[key];
4283
+ }
4284
+ }
4285
+ }
4286
+ return target;
4287
+ }
4288
+ function omit(obj, keys) {
4289
+ const result = { ...obj };
4290
+ for (const key of keys) {
4291
+ delete result[key];
4292
+ }
4293
+ return result;
4294
+ }
4295
+ function elementToBoxInfo(elem) {
4296
+ const { x: x2, y: y2, w: w2, h: h2, detail } = elem;
4297
+ const { borderWidth: borderWidth2, borderRadius: borderRadius2, boxSizing } = detail;
4298
+ let btw = 0;
4299
+ let brw = 0;
4300
+ let bbw = 0;
4301
+ let blw = 0;
4302
+ let btlr = 0;
4303
+ let btrr = 0;
4304
+ let bblr = 0;
4305
+ let bbrr = 0;
4306
+ if (typeof borderWidth2 === "number" && borderWidth2 > 0) {
4307
+ btw = borderWidth2;
4308
+ brw = borderWidth2;
4309
+ bbw = borderWidth2;
4310
+ blw = borderWidth2;
4311
+ } else if (Array.isArray(borderWidth2)) {
4312
+ btw = is.positiveNum(borderWidth2[0]) ? borderWidth2[0] : 0;
4313
+ brw = is.positiveNum(borderWidth2[1]) ? borderWidth2[0] : 0;
4314
+ bbw = is.positiveNum(borderWidth2[2]) ? borderWidth2[0] : 0;
4315
+ blw = is.positiveNum(borderWidth2[3]) ? borderWidth2[0] : 0;
4316
+ }
4317
+ if (typeof borderRadius2 === "number" && borderRadius2 > 0) {
4318
+ btlr = borderRadius2;
4319
+ btrr = borderRadius2;
4320
+ bblr = borderRadius2;
4321
+ bbrr = borderRadius2;
4322
+ } else if (Array.isArray(borderRadius2)) {
4323
+ btlr = is.positiveNum(borderRadius2[0]) ? borderRadius2[0] : 0;
4324
+ btrr = is.positiveNum(borderRadius2[0]) ? borderRadius2[0] : 0;
4325
+ bblr = is.positiveNum(borderRadius2[0]) ? borderRadius2[0] : 0;
4326
+ bbrr = is.positiveNum(borderRadius2[0]) ? borderRadius2[0] : 0;
4327
+ }
4328
+ const p0 = { x: x2, y: y2 };
4329
+ const p1 = { x: x2 + w2, y: y2 };
4330
+ const p2 = { x: x2 + w2, y: y2 + h2 };
4331
+ const p3 = { x: x2, y: y2 + h2 };
4332
+ const p0s = { x: x2, y: y2 + btlr };
4333
+ const p0e = { x: x2 + btlr, y: y2 };
4334
+ const p1s = { x: x2 + w2 - btrr, y: y2 };
4335
+ const p1e = { x: x2 + w2, y: y2 + btrr };
4336
+ const p2s = { x: x2 + w2, y: y2 + h2 - bbrr };
4337
+ const p2e = { x: x2 + w2 - bbrr, y: y2 + h2 };
4338
+ const p3s = { x: x2 + bblr, y: y2 + h2 };
4339
+ const p3e = { x: x2, y: y2 + h2 - bblr };
4340
+ let op0 = { ...p0 };
4341
+ let op1 = { ...p1 };
4342
+ let op2 = { ...p2 };
4343
+ let op3 = { ...p3 };
4344
+ let op0s = { ...p0s };
4345
+ let op0e = { ...p0e };
4346
+ let op1s = { ...p1s };
4347
+ let op1e = { ...p1e };
4348
+ let op2s = { ...p2s };
4349
+ let op2e = { ...p2e };
4350
+ let op3s = { ...p3s };
4351
+ let op3e = { ...p3e };
4352
+ let ip0 = { ...p0 };
4353
+ let ip1 = { ...p1 };
4354
+ let ip2 = { ...p2 };
4355
+ let ip3 = { ...p3 };
4356
+ let ip0s = { ...p0s };
4357
+ let ip0e = { ...p0e };
4358
+ let ip1s = { ...p1s };
4359
+ let ip1e = { ...p1e };
4360
+ let ip2s = { ...p2s };
4361
+ let ip2e = { ...p2e };
4362
+ let ip3s = { ...p3s };
4363
+ let ip3e = { ...p3e };
4364
+ if (boxSizing === "border-box") {
4365
+ ip0 = { x: ip0.x + blw, y: ip0.y + btw };
4366
+ ip1 = { x: ip1.x - brw, y: ip1.y + btw };
4367
+ ip2 = { x: ip2.x - brw, y: ip2.y - bbw };
4368
+ ip3 = { x: ip3.x + blw, y: ip3.y - bbw };
4369
+ ip0s = { x: ip0s.x + blw, y: ip0s.y + btw };
4370
+ ip0e = { x: ip0e.x + blw, y: ip0e.y + btw };
4371
+ ip1s = { x: ip1s.x - brw, y: ip1s.y + btw };
4372
+ ip1e = { x: ip1e.x - brw, y: ip1e.y + btw };
4373
+ ip2s = { x: ip2s.x - brw, y: ip2s.y - bbw };
4374
+ ip2e = { x: ip2e.x - brw, y: ip2e.y - bbw };
4375
+ ip3s = { x: ip3s.x + blw, y: ip3s.y - bbw };
4376
+ ip3e = { x: ip3e.x + blw, y: ip3e.y - bbw };
4377
+ } else if (boxSizing === "content-box") {
4378
+ op0 = { x: op0.x - blw, y: op0.y - btw };
4379
+ op1 = { x: op1.x + brw, y: op1.y - btw };
4380
+ op2 = { x: op2.x + brw, y: op2.y + bbw };
4381
+ op3 = { x: op3.x - blw, y: op3.y + bbw };
4382
+ op0s = { x: op0s.x - blw, y: op0s.y - btw };
4383
+ op0e = { x: op0e.x - blw, y: op0e.y - btw };
4384
+ op1s = { x: op1s.x + brw, y: op1s.y - btw };
4385
+ op1e = { x: op1e.x + brw, y: op1e.y - btw };
4386
+ op2s = { x: op2s.x + brw, y: op2s.y + bbw };
4387
+ op2e = { x: op2e.x + brw, y: op2e.y + bbw };
4388
+ op3s = { x: op3s.x - blw, y: op3s.y + bbw };
4389
+ op3e = { x: op3e.x - blw, y: op3e.y + bbw };
4390
+ } else {
4391
+ ip0 = { x: ip0.x + blw / 2, y: ip0.y + btw / 2 };
4392
+ ip1 = { x: ip1.x - brw / 2, y: ip1.y + btw / 2 };
4393
+ ip2 = { x: ip2.x - brw / 2, y: ip2.y - bbw / 2 };
4394
+ ip3 = { x: ip3.x + blw / 2, y: ip3.y - bbw / 2 };
4395
+ ip0s = { x: ip0s.x + blw / 2, y: ip0s.y + btw / 2 };
4396
+ ip0e = { x: ip0e.x + blw / 2, y: ip0e.y + btw / 2 };
4397
+ ip1s = { x: ip1s.x - brw / 2, y: ip1s.y + btw / 2 };
4398
+ ip1e = { x: ip1e.x - brw / 2, y: ip1e.y + btw / 2 };
4399
+ ip2s = { x: ip2s.x - brw / 2, y: ip2s.y - bbw / 2 };
4400
+ ip2e = { x: ip2e.x - brw / 2, y: ip2e.y - bbw / 2 };
4401
+ ip3s = { x: ip3s.x + blw / 2, y: ip3s.y - bbw / 2 };
4402
+ ip3e = { x: ip3e.x + blw / 2, y: ip3e.y - bbw / 2 };
4403
+ op0 = { x: op0.x - blw / 2, y: op0.y - btw / 2 };
4404
+ op1 = { x: op1.x + brw / 2, y: op1.y - btw / 2 };
4405
+ op2 = { x: op2.x + brw / 2, y: op2.y + bbw / 2 };
4406
+ op3 = { x: op3.x - blw / 2, y: op3.y + bbw / 2 };
4407
+ op0s = { x: op0s.x - blw / 2, y: op0s.y - btw / 2 };
4408
+ op0e = { x: op0e.x - blw / 2, y: op0e.y - btw / 2 };
4409
+ op1s = { x: op1s.x + brw / 2, y: op1s.y - btw / 2 };
4410
+ op1e = { x: op1e.x + brw / 2, y: op1e.y - btw / 2 };
4411
+ op2s = { x: op2s.x + brw / 2, y: op2s.y + bbw / 2 };
4412
+ op2e = { x: op2e.x + brw / 2, y: op2e.y + bbw / 2 };
4413
+ op3s = { x: op3s.x - blw / 2, y: op3s.y + bbw / 2 };
4414
+ op3e = { x: op3e.x - blw / 2, y: op3e.y + bbw / 2 };
4415
+ }
4416
+ return {
4417
+ btw,
4418
+ brw,
4419
+ bbw,
4420
+ blw,
4421
+ btlr,
4422
+ btrr,
4423
+ bblr,
4424
+ bbrr,
4425
+ p0,
4426
+ p1,
4427
+ p2,
4428
+ p3,
4429
+ p0s,
4430
+ p0e,
4431
+ p1s,
4432
+ p1e,
4433
+ p2s,
4434
+ p2e,
4435
+ p3s,
4436
+ p3e,
4437
+ op0,
4438
+ op1,
4439
+ op2,
4440
+ op3,
4441
+ op0s,
4442
+ op0e,
4443
+ op1s,
4444
+ op1e,
4445
+ op2s,
4446
+ op2e,
4447
+ op3s,
4448
+ op3e,
4449
+ ip0,
4450
+ ip1,
4451
+ ip2,
4452
+ ip3,
4453
+ ip0s,
4454
+ ip0e,
4455
+ ip1s,
4456
+ ip1e,
4457
+ ip2s,
4458
+ ip2e,
4459
+ ip3s,
4460
+ ip3e
4461
+ };
4462
+ }
4463
+ function unflatObject(flatObj) {
4464
+ const result = {};
4465
+ for (const [flatKey, value] of Object.entries(flatObj)) {
4466
+ const pathParts = parseKeyToPath(flatKey);
4467
+ buildNestedStructure(result, pathParts, value);
4468
+ }
4469
+ return result;
4470
+ }
4471
+ function parseKeyToPath(flatKey) {
4472
+ const regex = /([\w-]+)|\[(\d+)\]/g;
4473
+ const pathParts = [];
4474
+ let match;
4475
+ while ((match = regex.exec(flatKey)) !== null) {
4476
+ const prop = match[1] || match[2];
4477
+ if (prop) {
4478
+ pathParts.push(prop);
4479
+ }
4480
+ }
4481
+ return pathParts;
4482
+ }
4483
+ function buildNestedStructure(currentObj, pathParts, value) {
4484
+ let currentLevel = currentObj;
4485
+ for (let i = 0; i < pathParts.length; i++) {
4486
+ const part = pathParts[i];
4487
+ const isArrayPart = isArrayIndex(part);
4488
+ const isLast = i === pathParts.length - 1;
4489
+ try {
4490
+ if (isArrayPart) {
4491
+ validateArrayPath(currentLevel, part);
4492
+ } else {
4493
+ validateObjectPath(currentLevel, part);
4494
+ }
4495
+ } catch (e) {
4496
+ throw new Error(`Structure conflict at path '${pathParts.slice(0, i + 1).join(".")}': ${e.message}`);
4497
+ }
4498
+ if (isLast) {
4499
+ assignValue(currentLevel, part, value);
4500
+ } else {
4501
+ currentLevel = prepareNextLevel(currentLevel, part, pathParts[i + 1]);
4502
+ }
4503
+ }
4504
+ }
4505
+ function isArrayIndex(key) {
4506
+ return /^\d+$/.test(key);
4507
+ }
4508
+ function validateArrayPath(obj, index) {
4509
+ if (!Array.isArray(obj)) {
4510
+ throw new Error(`Expected array but found ${typeof obj}`);
4511
+ }
4512
+ const idx = Number(index);
4513
+ if (idx > obj.length) {
4514
+ obj.length = idx + 1;
4515
+ }
4516
+ }
4517
+ function validateObjectPath(obj, key) {
4518
+ if (Array.isArray(obj)) {
4519
+ throw new Error(`Cannot create object property '${key}' on array`);
4520
+ }
4521
+ if (typeof obj !== "object" || obj === null) {
4522
+ throw new Error(`Invalid structure for property '${key}'`);
4523
+ }
4524
+ }
4525
+ function prepareNextLevel(current, part, nextPart) {
4526
+ const isNextArray = nextPart ? isArrayIndex(nextPart) : false;
4527
+ if (Array.isArray(current)) {
4528
+ const index = Number(part);
4529
+ if (!current[index]) {
4530
+ current[index] = isNextArray ? [] : {};
4531
+ }
4532
+ return current[index];
4533
+ }
4534
+ if (!current[part]) {
4535
+ current[part] = isNextArray ? [] : {};
4536
+ }
4537
+ return current[part];
4538
+ }
4539
+ function assignValue(target, key, value) {
4540
+ if (Array.isArray(target)) {
4541
+ const index = Number(key);
4542
+ if (index >= target.length) {
4543
+ target.length = index + 1;
4544
+ }
4545
+ target[index] = value;
4546
+ } else {
4547
+ target[key] = value;
4548
+ }
4549
+ }
2993
4550
  exports.Context2D = Context2D;
2994
4551
  exports.EventEmitter = EventEmitter;
2995
4552
  exports.Store = Store;
@@ -2997,14 +4554,23 @@ var __privateMethod = (obj, member, method) => {
2997
4554
  exports.calcElementCenter = calcElementCenter;
2998
4555
  exports.calcElementCenterFromVertexes = calcElementCenterFromVertexes;
2999
4556
  exports.calcElementListSize = calcElementListSize;
4557
+ exports.calcElementOriginRectInfo = calcElementOriginRectInfo;
3000
4558
  exports.calcElementQueueVertexesQueueInGroup = calcElementQueueVertexesQueueInGroup;
3001
4559
  exports.calcElementSizeController = calcElementSizeController;
3002
4560
  exports.calcElementVertexesInGroup = calcElementVertexesInGroup;
3003
4561
  exports.calcElementVertexesQueueInGroup = calcElementVertexesQueueInGroup;
4562
+ exports.calcElementViewRectInfo = calcElementViewRectInfo;
3004
4563
  exports.calcElementsContextSize = calcElementsContextSize;
3005
4564
  exports.calcElementsViewInfo = calcElementsViewInfo;
4565
+ exports.calcLayoutSizeController = calcLayoutSizeController;
4566
+ exports.calcPointMoveElementInGroup = calcPointMoveElementInGroup;
4567
+ exports.calcRadian = calcRadian;
4568
+ exports.calcResultMovePosition = calcResultMovePosition;
4569
+ exports.calcRevertMovePosition = calcRevertMovePosition;
3006
4570
  exports.calcSpeed = calcSpeed;
3007
4571
  exports.calcViewBoxSize = calcViewBoxSize;
4572
+ exports.calcViewCenter = calcViewCenter;
4573
+ exports.calcViewCenterContent = calcViewCenterContent;
3008
4574
  exports.calcViewElementSize = calcViewElementSize;
3009
4575
  exports.calcViewPointSize = calcViewPointSize;
3010
4576
  exports.calcViewScaleInfo = calcViewScaleInfo;
@@ -3024,13 +4590,15 @@ var __privateMethod = (obj, member, method) => {
3024
4590
  exports.createUUID = createUUID;
3025
4591
  exports.debounce = debounce;
3026
4592
  exports.deepClone = deepClone;
4593
+ exports.deepCloneData = deepCloneData;
3027
4594
  exports.deepCloneElement = deepCloneElement;
3028
- exports.deepResizeGroupElement = deepResizeGroupElement;
3029
4595
  exports.delay = delay;
3030
4596
  exports.deleteElementInList = deleteElementInList;
3031
4597
  exports.deleteElementInListByPosition = deleteElementInListByPosition;
3032
4598
  exports.downloadFileFromText = downloadFileFromText;
3033
4599
  exports.downloadImageFromCanvas = downloadImageFromCanvas;
4600
+ exports.elementToBoxInfo = elementToBoxInfo;
4601
+ exports.enhanceFontFamliy = enhanceFontFamliy;
3034
4602
  exports.equalPoint = equalPoint;
3035
4603
  exports.equalTouchPoint = equalTouchPoint;
3036
4604
  exports.filterCompactData = filterCompactData;
@@ -3040,29 +4608,38 @@ var __privateMethod = (obj, member, method) => {
3040
4608
  exports.findElementQueueFromListByPosition = findElementQueueFromListByPosition;
3041
4609
  exports.findElementsFromList = findElementsFromList;
3042
4610
  exports.findElementsFromListByPositions = findElementsFromListByPositions;
4611
+ exports.flatElementList = flatElementList;
4612
+ exports.flatObject = flatObject;
3043
4613
  exports.formatNumber = formatNumber;
3044
4614
  exports.generateHTML = generateHTML;
3045
4615
  exports.generateSVGPath = generateSVGPath;
4616
+ exports.get = get;
3046
4617
  exports.getCenterFromTwoPoints = getCenterFromTwoPoints;
3047
4618
  exports.getDefaultElementDetailConfig = getDefaultElementDetailConfig;
3048
4619
  exports.getDefaultElementRectDetail = getDefaultElementRectDetail;
3049
4620
  exports.getElemenetsAssetIds = getElemenetsAssetIds;
3050
4621
  exports.getElementPositionFromList = getElementPositionFromList;
4622
+ exports.getElementPositionMapFromList = getElementPositionMapFromList;
3051
4623
  exports.getElementRotateVertexes = getElementRotateVertexes;
3052
4624
  exports.getElementSize = getElementSize;
3053
4625
  exports.getElementVertexes = getElementVertexes;
4626
+ exports.getGroupQueueByElementPosition = getGroupQueueByElementPosition;
3054
4627
  exports.getGroupQueueFromList = getGroupQueueFromList;
3055
4628
  exports.getSelectedElementUUIDs = getSelectedElementUUIDs;
3056
4629
  exports.getViewPointAtElement = getViewPointAtElement;
3057
4630
  exports.getViewScaleInfoFromSnapshot = getViewScaleInfoFromSnapshot;
3058
4631
  exports.getViewSizeInfoFromSnapshot = getViewSizeInfoFromSnapshot;
4632
+ exports.groupElementsByPosition = groupElementsByPosition;
3059
4633
  exports.insertElementToListByPosition = insertElementToListByPosition;
3060
4634
  exports.is = is;
3061
4635
  exports.isAssetId = isAssetId;
3062
4636
  exports.isColorStr = isColorStr;
3063
4637
  exports.isElementInView = isElementInView;
3064
4638
  exports.isResourceElement = isResourceElement;
4639
+ exports.isSameElementSize = isSameElementSize;
3065
4640
  exports.isViewPointInElement = isViewPointInElement;
4641
+ exports.isViewPointInElementSize = isViewPointInElementSize;
4642
+ exports.isViewPointInVertexes = isViewPointInVertexes;
3066
4643
  exports.istype = istype;
3067
4644
  exports.limitAngle = limitAngle;
3068
4645
  exports.loadHTML = loadHTML;
@@ -3070,9 +4647,15 @@ var __privateMethod = (obj, member, method) => {
3070
4647
  exports.loadSVG = loadSVG;
3071
4648
  exports.matrixToAngle = matrixToAngle;
3072
4649
  exports.matrixToRadian = matrixToRadian;
4650
+ exports.merge = merge;
4651
+ exports.mergeElement = mergeElement;
3073
4652
  exports.mergeElementAsset = mergeElementAsset;
4653
+ exports.mergeGlobal = mergeGlobal;
3074
4654
  exports.mergeHexColorAlpha = mergeHexColorAlpha;
4655
+ exports.mergeLayout = mergeLayout;
3075
4656
  exports.moveElementPosition = moveElementPosition;
4657
+ exports.omit = omit;
4658
+ exports.originRectInfoToRangeRectInfo = originRectInfoToRangeRectInfo;
3076
4659
  exports.parseAngleToRadian = parseAngleToRadian;
3077
4660
  exports.parseFileToBase64 = parseFileToBase64;
3078
4661
  exports.parseFileToText = parseFileToText;
@@ -3080,17 +4663,26 @@ var __privateMethod = (obj, member, method) => {
3080
4663
  exports.parseRadianToAngle = parseRadianToAngle;
3081
4664
  exports.parseSVGPath = parseSVGPath;
3082
4665
  exports.pickFile = pickFile;
4666
+ exports.resizeEffectGroupElement = resizeEffectGroupElement;
3083
4667
  exports.rotateByCenter = rotateByCenter;
3084
4668
  exports.rotateElement = rotateElement;
3085
4669
  exports.rotateElementVertexes = rotateElementVertexes;
3086
4670
  exports.rotatePoint = rotatePoint;
3087
4671
  exports.rotatePointInGroup = rotatePointInGroup;
3088
4672
  exports.rotateVertexes = rotateVertexes;
4673
+ exports.set = set;
3089
4674
  exports.sortDataAsserts = sortDataAsserts;
3090
4675
  exports.throttle = throttle;
3091
4676
  exports.toColorHexNum = toColorHexNum;
3092
4677
  exports.toColorHexStr = toColorHexStr;
4678
+ exports.toFlattenElement = toFlattenElement;
4679
+ exports.toFlattenGlobal = toFlattenGlobal;
4680
+ exports.toFlattenLayout = toFlattenLayout;
4681
+ exports.toPath = toPath;
4682
+ exports.unflatObject = unflatObject;
4683
+ exports.ungroupElementsByPosition = ungroupElementsByPosition;
3093
4684
  exports.updateElementInList = updateElementInList;
4685
+ exports.updateElementInListByPosition = updateElementInListByPosition;
3094
4686
  exports.vaildPoint = vaildPoint;
3095
4687
  exports.vaildTouchPoint = vaildTouchPoint;
3096
4688
  exports.validateElements = validateElements;