@idraw/util 0.4.0-beta.4 → 0.4.0-beta.41

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 (111) hide show
  1. package/dist/esm/index.d.ts +46 -30
  2. package/dist/esm/index.js +46 -30
  3. package/dist/esm/{lib → tool}/color.js +9 -6
  4. package/dist/esm/{lib → tool}/event.d.ts +4 -2
  5. package/dist/esm/tool/event.js +70 -0
  6. package/dist/esm/{lib → tool}/file.d.ts +2 -1
  7. package/dist/esm/{lib → tool}/file.js +4 -1
  8. package/dist/esm/tool/flat-object.d.ts +6 -0
  9. package/dist/esm/tool/flat-object.js +28 -0
  10. package/dist/esm/tool/get-set-del.d.ts +4 -0
  11. package/dist/esm/tool/get-set-del.js +65 -0
  12. package/dist/esm/tool/hash.d.ts +1 -0
  13. package/dist/esm/tool/hash.js +33 -0
  14. package/dist/esm/{lib → tool}/html.d.ts +1 -1
  15. package/dist/esm/{lib → tool}/html.js +6 -2
  16. package/dist/esm/{lib → tool}/istype.d.ts +1 -0
  17. package/dist/esm/{lib → tool}/istype.js +3 -0
  18. package/dist/esm/tool/merge.d.ts +1 -0
  19. package/dist/esm/tool/merge.js +17 -0
  20. package/dist/esm/tool/omit.d.ts +1 -0
  21. package/dist/esm/tool/omit.js +7 -0
  22. package/dist/esm/tool/store.d.ts +16 -0
  23. package/dist/esm/tool/store.js +52 -0
  24. package/dist/esm/{lib → tool}/time.d.ts +1 -0
  25. package/dist/esm/{lib → tool}/time.js +13 -1
  26. package/dist/esm/tool/unflat-object.d.ts +3 -0
  27. package/dist/esm/tool/unflat-object.js +91 -0
  28. package/dist/esm/tool/uuid.js +13 -0
  29. package/dist/esm/view/box.d.ts +2 -0
  30. package/dist/esm/view/box.js +173 -0
  31. package/dist/esm/{lib → view}/canvas.d.ts +0 -1
  32. package/dist/esm/view/canvas.js +57 -0
  33. package/dist/esm/{lib → view}/check.js +14 -14
  34. package/dist/esm/view/config.d.ts +9 -0
  35. package/dist/esm/{lib → view}/config.js +9 -9
  36. package/dist/esm/{lib → view}/context2d.d.ts +4 -0
  37. package/dist/esm/{lib → view}/context2d.js +20 -0
  38. package/dist/esm/view/controller.d.ts +12 -0
  39. package/dist/esm/view/controller.js +321 -0
  40. package/dist/esm/view/data.d.ts +10 -0
  41. package/dist/esm/view/data.js +202 -0
  42. package/dist/esm/{lib → view}/element.d.ts +5 -0
  43. package/dist/esm/{lib → view}/element.js +65 -4
  44. package/dist/esm/view/flat.d.ts +2 -0
  45. package/dist/esm/view/flat.js +133 -0
  46. package/dist/esm/view/group.d.ts +3 -0
  47. package/dist/esm/view/group.js +81 -0
  48. package/dist/esm/{lib → view}/handle-element.d.ts +11 -1
  49. package/dist/esm/view/handle-element.js +286 -0
  50. package/dist/esm/view/handle-global.d.ts +4 -0
  51. package/dist/esm/view/handle-global.js +28 -0
  52. package/dist/esm/view/handle-layout.d.ts +4 -0
  53. package/dist/esm/view/handle-layout.js +28 -0
  54. package/dist/esm/{lib → view}/is.d.ts +3 -1
  55. package/dist/esm/{lib → view}/is.js +22 -6
  56. package/dist/esm/view/modify-record.d.ts +4 -0
  57. package/dist/esm/view/modify-record.js +10 -0
  58. package/dist/esm/view/point-move-element.d.ts +5 -0
  59. package/dist/esm/view/point-move-element.js +26 -0
  60. package/dist/esm/view/position.d.ts +15 -0
  61. package/dist/esm/view/position.js +79 -0
  62. package/dist/esm/view/rect.js +11 -0
  63. package/dist/esm/view/resize-element.d.ts +2 -0
  64. package/dist/esm/view/resize-element.js +101 -0
  65. package/dist/esm/{lib → view}/rotate.js +8 -13
  66. package/dist/esm/view/text.d.ts +1 -0
  67. package/dist/esm/view/text.js +4 -0
  68. package/dist/esm/{lib → view}/view-box.js +4 -2
  69. package/dist/esm/{lib → view}/view-calc.d.ts +16 -3
  70. package/dist/esm/{lib → view}/view-calc.js +127 -3
  71. package/dist/esm/view/view-content.d.ts +14 -0
  72. package/dist/esm/view/view-content.js +88 -0
  73. package/dist/index.global.js +1977 -326
  74. package/dist/index.global.min.js +1 -1
  75. package/package.json +2 -2
  76. package/dist/esm/lib/canvas.js +0 -81
  77. package/dist/esm/lib/config.d.ts +0 -14
  78. package/dist/esm/lib/controller.d.ts +0 -6
  79. package/dist/esm/lib/controller.js +0 -103
  80. package/dist/esm/lib/data.d.ts +0 -5
  81. package/dist/esm/lib/data.js +0 -92
  82. package/dist/esm/lib/event.js +0 -50
  83. package/dist/esm/lib/handle-element.js +0 -226
  84. package/dist/esm/lib/rect.js +0 -11
  85. package/dist/esm/lib/store.d.ts +0 -12
  86. package/dist/esm/lib/store.js +0 -22
  87. package/dist/esm/lib/uuid.js +0 -31
  88. /package/dist/esm/{lib → tool}/color.d.ts +0 -0
  89. /package/dist/esm/{lib → tool}/image.d.ts +0 -0
  90. /package/dist/esm/{lib → tool}/image.js +0 -0
  91. /package/dist/esm/{lib → tool}/number.d.ts +0 -0
  92. /package/dist/esm/{lib → tool}/number.js +0 -0
  93. /package/dist/esm/{lib → tool}/uuid.d.ts +0 -0
  94. /package/dist/esm/{lib → view}/check.d.ts +0 -0
  95. /package/dist/esm/{lib → view}/load.d.ts +0 -0
  96. /package/dist/esm/{lib → view}/load.js +0 -0
  97. /package/dist/esm/{lib → view}/matrix.d.ts +0 -0
  98. /package/dist/esm/{lib → view}/matrix.js +0 -0
  99. /package/dist/esm/{lib → view}/middleware.d.ts +0 -0
  100. /package/dist/esm/{lib → view}/middleware.js +0 -0
  101. /package/dist/esm/{lib → view}/parser.d.ts +0 -0
  102. /package/dist/esm/{lib → view}/parser.js +0 -0
  103. /package/dist/esm/{lib → view}/point.d.ts +0 -0
  104. /package/dist/esm/{lib → view}/point.js +0 -0
  105. /package/dist/esm/{lib → view}/rect.d.ts +0 -0
  106. /package/dist/esm/{lib → view}/rotate.d.ts +0 -0
  107. /package/dist/esm/{lib → view}/svg-path.d.ts +0 -0
  108. /package/dist/esm/{lib → view}/svg-path.js +0 -0
  109. /package/dist/esm/{lib → view}/vertex.d.ts +0 -0
  110. /package/dist/esm/{lib → view}/vertex.js +0 -0
  111. /package/dist/esm/{lib → view}/view-box.d.ts +0 -0
@@ -1,24 +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;
2
+ "use strict";var __typeError = (msg) => {
3
+ throw TypeError(msg);
19
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);
20
10
 
21
- var _ctx, _opts;
11
+ var _ctx, _opts, _listeners, _temp, _backUpDefaultStorage, _static, _Store_instances, createTempStorage_fn;
22
12
  function compose(middleware) {
23
13
  return function(context, next) {
24
14
  return dispatch(0);
@@ -27,8 +17,7 @@ var __privateSet = (obj, member, value, setter) => {
27
17
  if (i === middleware.length && next) {
28
18
  fn = next;
29
19
  }
30
- if (!fn)
31
- return Promise.resolve();
20
+ if (!fn) return Promise.resolve();
32
21
  try {
33
22
  return Promise.resolve(fn(context, dispatch.bind(null, i + 1)));
34
23
  } catch (err) {
@@ -47,7 +36,7 @@ var __privateSet = (obj, member, value, setter) => {
47
36
  function throttle(fn, timeout) {
48
37
  let timer = -1;
49
38
  return function(...args) {
50
- if (timer > 0) {
39
+ if (timer >= 0) {
51
40
  return;
52
41
  }
53
42
  timer = setTimeout(() => {
@@ -56,6 +45,18 @@ var __privateSet = (obj, member, value, setter) => {
56
45
  }, timeout);
57
46
  };
58
47
  }
48
+ function debounce(fn, timeout) {
49
+ let timer = -1;
50
+ return function(...args) {
51
+ if (timer >= 0) {
52
+ window.clearTimeout(timer);
53
+ }
54
+ timer = setTimeout(() => {
55
+ fn(...args);
56
+ timer = -1;
57
+ }, timeout);
58
+ };
59
+ }
59
60
  function downloadImageFromCanvas(canvas, opts) {
60
61
  const { fileName, type = "image/jpeg" } = opts;
61
62
  const stream = canvas.toDataURL(type);
@@ -66,9 +67,12 @@ var __privateSet = (obj, member, value, setter) => {
66
67
  downloadLink = null;
67
68
  }
68
69
  function pickFile(opts) {
69
- const { success, error } = opts;
70
+ const { accept, success, error } = opts;
70
71
  let input = document.createElement("input");
71
72
  input.type = "file";
73
+ if (accept) {
74
+ input.accept = accept;
75
+ }
72
76
  input.addEventListener("change", function() {
73
77
  var _a;
74
78
  const file = (_a = input.files) == null ? void 0 : _a[0];
@@ -139,13 +143,13 @@ var __privateSet = (obj, member, value, setter) => {
139
143
  downloadLink = null;
140
144
  }
141
145
  function toColorHexNum(color2) {
142
- return parseInt(color2.replace(/^\#/, "0x"));
146
+ return parseInt(color2.replace(/^#/, "0x"));
143
147
  }
144
148
  function toColorHexStr(color2) {
145
149
  return "#" + color2.toString(16);
146
150
  }
147
151
  function isColorStr(color2) {
148
- 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));
149
153
  }
150
154
  const colorNameMap = {
151
155
  aliceblue: "#f0f8ff",
@@ -302,6 +306,8 @@ var __privateSet = (obj, member, value, setter) => {
302
306
  let css = "transparent";
303
307
  if (typeof color2 === "string") {
304
308
  css = color2;
309
+ } else if ((color2 == null ? void 0 : color2.stops.length) === 1) {
310
+ css = color2.stops[0].color;
305
311
  } else if ((color2 == null ? void 0 : color2.type) === "linear-gradient") {
306
312
  const items = [];
307
313
  if (typeof color2.angle === "number") {
@@ -349,13 +355,13 @@ var __privateSet = (obj, member, value, setter) => {
349
355
  return hex;
350
356
  }
351
357
  let hexAlpha = 1;
352
- const regHex1 = /^\#[0-9a-f]{6,6}$/i;
353
- 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;
354
360
  let result = hex;
355
361
  if (regHex1.test(hex)) {
356
- hexAlpha = parseInt(hex.substring(5, 7).replace(/^\#/, "0x"));
362
+ hexAlpha = parseInt(hex.substring(5, 7).replace(/^#/, "0x"));
357
363
  } else if (regHex2.test(hex)) {
358
- hexAlpha = parseInt(hex.substring(7, 9).replace(/^\#/, "0x"));
364
+ hexAlpha = parseInt(hex.substring(7, 9).replace(/^#/, "0x"));
359
365
  result = hex.substring(0, 7);
360
366
  }
361
367
  hexAlpha = hexAlpha * alpha;
@@ -365,36 +371,49 @@ var __privateSet = (obj, member, value, setter) => {
365
371
  }
366
372
  return result;
367
373
  }
374
+ function generate32Base36Hash(str) {
375
+ const hash256 = generate256BitHash(str);
376
+ return bigIntToBase36(hash256).padStart(32, "0").slice(0, 32);
377
+ }
378
+ function generate256BitHash(str) {
379
+ let h1 = 0xcbf29ce484222325n, h2 = 0x84222325cbf29ce4n;
380
+ let h3 = 0x1b3n * h1, h4 = 0x1000000n * h2;
381
+ const prime = 0x100000001b3n;
382
+ const chunkSize = 4096;
383
+ for (let i = 0; i < str.length; i += chunkSize) {
384
+ const chunk = str.slice(i, i + chunkSize);
385
+ for (let j = 0; j < chunk.length; j++) {
386
+ const code = BigInt(chunk.charCodeAt(j) + i + j);
387
+ h1 = (h1 ^ code) * prime;
388
+ h2 = (h2 ^ h1) * prime ^ h3;
389
+ h3 = (h3 ^ h2) * prime + h4;
390
+ h4 = (h4 ^ h3) * prime | 0x1234567890abcdefn;
391
+ }
392
+ }
393
+ return h1 << 192n | h2 << 128n | h3 << 64n | h4;
394
+ }
395
+ function bigIntToBase36(num) {
396
+ const chars = "0123456789abcdefghijklmnopqrstuvwxyz";
397
+ if (num === 0n) return "0";
398
+ let result = "";
399
+ while (num > 0n) {
400
+ const rem = num % 36n;
401
+ result = chars[Number(rem)] + result;
402
+ num = num / 36n;
403
+ }
404
+ return result;
405
+ }
368
406
  function createUUID() {
369
407
  function _createStr() {
370
408
  return ((1 + Math.random()) * 65536 | 0).toString(16).substring(1);
371
409
  }
372
410
  return `${_createStr()}${_createStr()}-${_createStr()}-${_createStr()}-${_createStr()}-${_createStr()}${_createStr()}${_createStr()}`;
373
411
  }
374
- function limitHexStr(str) {
375
- let count = 0;
376
- for (let i = 0; i < str.length; i++) {
377
- count += str.charCodeAt(i) * str.charCodeAt(i) * i * i;
378
- }
379
- return count.toString(16).substring(0, 4);
380
- }
381
412
  function createAssetId(assetStr) {
382
- const len = assetStr.length;
383
- const mid = Math.floor(len / 2);
384
- const start4 = assetStr.substring(0, 4).padEnd(4, "0");
385
- const end4 = assetStr.substring(0, 4).padEnd(4, "0");
386
- const str1 = limitHexStr(len.toString(16).padEnd(4, start4));
387
- const str2 = limitHexStr(assetStr.substring(mid - 4, mid).padEnd(4, start4)).padEnd(4, "f");
388
- const str3 = limitHexStr(assetStr.substring(mid - 8, mid - 4).padEnd(4, start4)).padEnd(4, "f");
389
- const str4 = limitHexStr(assetStr.substring(mid - 12, mid - 8).padEnd(4, start4)).padEnd(4, "f");
390
- const str5 = limitHexStr(assetStr.substring(mid - 16, mid - 12).padEnd(4, end4)).padEnd(4, "f");
391
- const str6 = limitHexStr(assetStr.substring(mid, mid + 4).padEnd(4, end4)).padEnd(4, "f");
392
- const str7 = limitHexStr(assetStr.substring(mid + 4, mid + 8).padEnd(4, end4)).padEnd(4, "f");
393
- const str8 = limitHexStr(end4.padEnd(4, start4).padEnd(4, end4));
394
- return `@assets/${str1}${str2}-${str3}-${str4}-${str5}-${str6}${str7}${str8}`;
413
+ return `@assets/${generate32Base36Hash(assetStr)}`;
395
414
  }
396
415
  function isAssetId(id) {
397
- 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}`);
416
+ return /^@assets\/[0-9a-z-]{0,}$/.test(`${id}`);
398
417
  }
399
418
  function deepClone(target) {
400
419
  function _clone(t) {
@@ -422,6 +441,28 @@ var __privateSet = (obj, member, value, setter) => {
422
441
  }
423
442
  return _clone(target);
424
443
  }
444
+ function deepCloneElement(element) {
445
+ const elem = deepClone(element);
446
+ const _resetUUID = (e) => {
447
+ e.uuid = createUUID();
448
+ if (e.type === "group" && e.detail.children) {
449
+ e.detail.children.forEach((child) => {
450
+ _resetUUID(child);
451
+ });
452
+ }
453
+ };
454
+ _resetUUID(elem);
455
+ return elem;
456
+ }
457
+ function deepCloneData(data) {
458
+ const { elements, ...restData } = data;
459
+ return {
460
+ ...deepClone(restData),
461
+ ...{
462
+ elements: elements.map((elem) => deepCloneElement(elem))
463
+ }
464
+ };
465
+ }
425
466
  function is$1(target) {
426
467
  return Object.prototype.toString.call(target).replace(/[\]|\[]{1,1}/gi, "").split(" ")[1];
427
468
  }
@@ -458,7 +499,7 @@ var __privateSet = (obj, member, value, setter) => {
458
499
  const assetUUID = createAssetId(html2);
459
500
  if (!assets[assetUUID]) {
460
501
  assets[assetUUID] = {
461
- type: "svg",
502
+ type: "html",
462
503
  value: html2
463
504
  };
464
505
  }
@@ -479,6 +520,80 @@ var __privateSet = (obj, member, value, setter) => {
479
520
  sortedData.assets = assets;
480
521
  return sortedData;
481
522
  }
523
+ function filterCompactData(data, opts) {
524
+ const assets = data.assets || {};
525
+ const sortedData = deepClone(data);
526
+ const loadItemMap = (opts == null ? void 0 : opts.loadItemMap) || {};
527
+ const _scanElements = (elems) => {
528
+ elems.forEach((elem) => {
529
+ var _a, _b, _c;
530
+ if (elem.type === "image" && elem.detail.src) {
531
+ const src = elem.detail.src;
532
+ if (isAssetId(src) && !assets[src] && loadItemMap[src] && typeof ((_a = loadItemMap[src]) == null ? void 0 : _a.source) === "string") {
533
+ assets[src] = {
534
+ type: "image",
535
+ value: loadItemMap[src].source
536
+ };
537
+ } else if (!assets[src]) {
538
+ const assetUUID = createAssetId(src);
539
+ if (!assets[assetUUID]) {
540
+ assets[assetUUID] = {
541
+ type: "image",
542
+ value: src
543
+ };
544
+ }
545
+ elem.detail.src = assetUUID;
546
+ }
547
+ } else if (elem.type === "svg") {
548
+ const svg2 = elem.detail.svg;
549
+ if (isAssetId(svg2) && !assets[svg2] && loadItemMap[svg2] && typeof ((_b = loadItemMap[svg2]) == null ? void 0 : _b.source) === "string") {
550
+ assets[svg2] = {
551
+ type: "svg",
552
+ value: loadItemMap[svg2].source
553
+ };
554
+ } else if (!assets[svg2]) {
555
+ const assetUUID = createAssetId(svg2);
556
+ if (!assets[assetUUID]) {
557
+ assets[assetUUID] = {
558
+ type: "svg",
559
+ value: svg2
560
+ };
561
+ }
562
+ elem.detail.svg = assetUUID;
563
+ }
564
+ } else if (elem.type === "html") {
565
+ const html2 = elem.detail.html;
566
+ if (isAssetId(html2) && !assets[html2] && loadItemMap[html2] && typeof ((_c = loadItemMap[html2]) == null ? void 0 : _c.source) === "string") {
567
+ assets[html2] = {
568
+ type: "html",
569
+ value: loadItemMap[html2].source
570
+ };
571
+ } else if (!assets[html2]) {
572
+ const assetUUID = createAssetId(html2);
573
+ if (!assets[assetUUID]) {
574
+ assets[assetUUID] = {
575
+ type: "html",
576
+ value: html2
577
+ };
578
+ }
579
+ elem.detail.html = assetUUID;
580
+ }
581
+ } else if (elem.type === "group" && Array.isArray(elem.detail.children)) {
582
+ const groupAssets = elem.detail.assets || {};
583
+ Object.keys(groupAssets).forEach((assetId) => {
584
+ if (!assets[assetId]) {
585
+ assets[assetId] = groupAssets[assetId];
586
+ }
587
+ });
588
+ delete elem.detail.assets;
589
+ _scanElements(elem.detail.children);
590
+ }
591
+ });
592
+ };
593
+ _scanElements(sortedData.elements);
594
+ sortedData.assets = assets;
595
+ return sortedData;
596
+ }
482
597
  function parsePrototype(data) {
483
598
  const typeStr = Object.prototype.toString.call(data) || "";
484
599
  const result = typeStr.replace(/(\[object|\])/gi, "").trim();
@@ -501,6 +616,9 @@ var __privateSet = (obj, member, value, setter) => {
501
616
  asyncFunction(data) {
502
617
  return parsePrototype(data) === "AsyncFunction";
503
618
  },
619
+ boolean(data) {
620
+ return parsePrototype(data) === "Boolean";
621
+ },
504
622
  string(data) {
505
623
  return parsePrototype(data) === "String";
506
624
  },
@@ -594,6 +712,9 @@ var __privateSet = (obj, member, value, setter) => {
594
712
  const image = await loadImage(dataURL);
595
713
  return image;
596
714
  }
715
+ function positiveNum(value) {
716
+ return typeof value === "number" && value >= 0;
717
+ }
597
718
  function number(value) {
598
719
  return typeof value === "number" && (value > 0 || value <= 0);
599
720
  }
@@ -604,19 +725,19 @@ var __privateSet = (obj, member, value, setter) => {
604
725
  return number(value);
605
726
  }
606
727
  function w(value) {
607
- return typeof value === "number" && value >= 0;
728
+ return positiveNum(value);
608
729
  }
609
730
  function h(value) {
610
- return typeof value === "number" && value >= 0;
731
+ return positiveNum(value);
611
732
  }
612
733
  function angle(value) {
613
734
  return typeof value === "number" && value >= -360 && value <= 360;
614
735
  }
615
736
  function borderWidth(value) {
616
- return w(value);
737
+ return positiveNum(value) || Array.isArray(value) && positiveNum(value[0]) && positiveNum(value[1]) && positiveNum(value[2]) && positiveNum(value[3]);
617
738
  }
618
739
  function borderRadius(value) {
619
- return number(value) && value >= 0;
740
+ return positiveNum(value) || Array.isArray(value) && positiveNum(value[0]) && positiveNum(value[1]) && positiveNum(value[2]) && positiveNum(value[3]);
620
741
  }
621
742
  function color(value) {
622
743
  return isColorStr(value);
@@ -670,6 +791,7 @@ var __privateSet = (obj, member, value, setter) => {
670
791
  return /^(-?\d+(?:\.\d+)?)$/.test(`${value}`);
671
792
  }
672
793
  const is = {
794
+ positiveNum,
673
795
  x,
674
796
  y,
675
797
  w,
@@ -705,20 +827,20 @@ var __privateSet = (obj, member, value, setter) => {
705
827
  }
706
828
  function box(detail = {}) {
707
829
  const { borderColor, borderRadius: borderRadius2, borderWidth: borderWidth2 } = detail;
708
- if (detail.hasOwnProperty("borderColor") && !is.color(borderColor)) {
830
+ if (Object.prototype.hasOwnProperty.call(detail, "borderColor") && !is.color(borderColor)) {
709
831
  return false;
710
832
  }
711
- if (detail.hasOwnProperty("borderRadius") && !is.number(borderRadius2)) {
833
+ if (Object.prototype.hasOwnProperty.call(detail, "borderRadius") && !is.number(borderRadius2)) {
712
834
  return false;
713
835
  }
714
- if (detail.hasOwnProperty("borderWidth") && !is.number(borderWidth2)) {
836
+ if (Object.prototype.hasOwnProperty.call(detail, "borderWidth") && !is.number(borderWidth2)) {
715
837
  return false;
716
838
  }
717
839
  return true;
718
840
  }
719
841
  function rectDesc(detail) {
720
842
  const { background } = detail;
721
- if (detail.hasOwnProperty("background") && !is.color(background)) {
843
+ if (Object.prototype.hasOwnProperty.call(detail, "background") && !is.color(background)) {
722
844
  return false;
723
845
  }
724
846
  if (!box(detail)) {
@@ -728,13 +850,13 @@ var __privateSet = (obj, member, value, setter) => {
728
850
  }
729
851
  function circleDesc(detail) {
730
852
  const { background, borderColor, borderWidth: borderWidth2 } = detail;
731
- if (detail.hasOwnProperty("background") && !is.color(background)) {
853
+ if (Object.prototype.hasOwnProperty.call(detail, "background") && !is.color(background)) {
732
854
  return false;
733
855
  }
734
- if (detail.hasOwnProperty("borderColor") && !is.color(borderColor)) {
856
+ if (Object.prototype.hasOwnProperty.call(detail, "borderColor") && !is.color(borderColor)) {
735
857
  return false;
736
858
  }
737
- if (detail.hasOwnProperty("borderWidth") && !is.number(borderWidth2)) {
859
+ if (Object.prototype.hasOwnProperty.call(detail, "borderWidth") && !is.number(borderWidth2)) {
738
860
  return false;
739
861
  }
740
862
  return true;
@@ -771,25 +893,25 @@ var __privateSet = (obj, member, value, setter) => {
771
893
  if (!is.fontSize(fontSize2)) {
772
894
  return false;
773
895
  }
774
- if (detail.hasOwnProperty("background") && !is.color(background)) {
896
+ if (Object.prototype.hasOwnProperty.call(detail, "background") && !is.color(background)) {
775
897
  return false;
776
898
  }
777
- if (detail.hasOwnProperty("fontWeight") && !is.fontWeight(fontWeight2)) {
899
+ if (Object.prototype.hasOwnProperty.call(detail, "fontWeight") && !is.fontWeight(fontWeight2)) {
778
900
  return false;
779
901
  }
780
- if (detail.hasOwnProperty("lineHeight") && !is.lineHeight(lineHeight2)) {
902
+ if (Object.prototype.hasOwnProperty.call(detail, "lineHeight") && !is.lineHeight(lineHeight2)) {
781
903
  return false;
782
904
  }
783
- if (detail.hasOwnProperty("fontFamily") && !is.fontFamily(fontFamily2)) {
905
+ if (Object.prototype.hasOwnProperty.call(detail, "fontFamily") && !is.fontFamily(fontFamily2)) {
784
906
  return false;
785
907
  }
786
- if (detail.hasOwnProperty("textAlign") && !is.textAlign(textAlign2)) {
908
+ if (Object.prototype.hasOwnProperty.call(detail, "textAlign") && !is.textAlign(textAlign2)) {
787
909
  return false;
788
910
  }
789
- if (detail.hasOwnProperty("strokeWidth") && !is.strokeWidth(strokeWidth2)) {
911
+ if (Object.prototype.hasOwnProperty.call(detail, "strokeWidth") && !is.strokeWidth(strokeWidth2)) {
790
912
  return false;
791
913
  }
792
- if (detail.hasOwnProperty("strokeColor") && !is.color(strokeColor)) {
914
+ if (Object.prototype.hasOwnProperty.call(detail, "strokeColor") && !is.color(strokeColor)) {
793
915
  return false;
794
916
  }
795
917
  if (!box(detail)) {
@@ -806,14 +928,18 @@ var __privateSet = (obj, member, value, setter) => {
806
928
  svgDesc,
807
929
  htmlDesc
808
930
  };
931
+ const defaultFontSize = 12;
932
+ const defaultFontWeight = "400";
933
+ 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'`;
809
934
  class Context2D {
810
935
  // private _width: number = 0;
811
936
  // private _height: number = 0;
812
937
  constructor(ctx, opts) {
813
- __privateAdd(this, _ctx, void 0);
814
- __privateAdd(this, _opts, void 0);
938
+ __privateAdd(this, _ctx);
939
+ __privateAdd(this, _opts);
815
940
  __privateSet(this, _ctx, ctx);
816
941
  __privateSet(this, _opts, { ...{ devicePixelRatio: 1, offscreenCanvas: null }, ...opts });
942
+ this.$resetFont();
817
943
  }
818
944
  $undoPixelRatio(num) {
819
945
  return num / __privateGet(this, _opts).devicePixelRatio;
@@ -824,6 +950,9 @@ var __privateSet = (obj, member, value, setter) => {
824
950
  $getContext() {
825
951
  return __privateGet(this, _ctx);
826
952
  }
953
+ $setContext(ctx) {
954
+ __privateSet(this, _ctx, ctx);
955
+ }
827
956
  $setFont(opts) {
828
957
  const strList = [];
829
958
  if (opts.fontWeight) {
@@ -833,6 +962,13 @@ var __privateSet = (obj, member, value, setter) => {
833
962
  strList.push(`${opts.fontFamily || "sans-serif"}`);
834
963
  __privateGet(this, _ctx).font = `${strList.join(" ")}`;
835
964
  }
965
+ $resetFont() {
966
+ this.$setFont({
967
+ fontSize: defaultFontSize,
968
+ fontFamily: defaultFontFamily,
969
+ fontWeight: defaultFontWeight
970
+ });
971
+ }
836
972
  $getOffscreenCanvas() {
837
973
  return __privateGet(this, _opts).offscreenCanvas;
838
974
  }
@@ -940,16 +1076,33 @@ var __privateSet = (obj, member, value, setter) => {
940
1076
  return __privateGet(this, _ctx).fill(...args);
941
1077
  }
942
1078
  arc(x2, y2, radius, startAngle, endAngle, anticlockwise) {
943
- return __privateGet(this, _ctx).arc(this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(radius), startAngle, endAngle, anticlockwise);
1079
+ return __privateGet(this, _ctx).arc(
1080
+ this.$doPixelRatio(x2),
1081
+ this.$doPixelRatio(y2),
1082
+ this.$doPixelRatio(radius),
1083
+ startAngle,
1084
+ endAngle,
1085
+ anticlockwise
1086
+ );
944
1087
  }
945
1088
  rect(x2, y2, w2, h2) {
946
1089
  return __privateGet(this, _ctx).rect(this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(w2), this.$doPixelRatio(h2));
947
1090
  }
948
1091
  fillRect(x2, y2, w2, h2) {
949
- return __privateGet(this, _ctx).fillRect(this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(w2), this.$doPixelRatio(h2));
1092
+ return __privateGet(this, _ctx).fillRect(
1093
+ this.$doPixelRatio(x2),
1094
+ this.$doPixelRatio(y2),
1095
+ this.$doPixelRatio(w2),
1096
+ this.$doPixelRatio(h2)
1097
+ );
950
1098
  }
951
1099
  clearRect(x2, y2, w2, h2) {
952
- return __privateGet(this, _ctx).clearRect(this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(w2), this.$doPixelRatio(h2));
1100
+ return __privateGet(this, _ctx).clearRect(
1101
+ this.$doPixelRatio(x2),
1102
+ this.$doPixelRatio(y2),
1103
+ this.$doPixelRatio(w2),
1104
+ this.$doPixelRatio(h2)
1105
+ );
953
1106
  }
954
1107
  beginPath() {
955
1108
  return __privateGet(this, _ctx).beginPath();
@@ -964,7 +1117,31 @@ var __privateSet = (obj, member, value, setter) => {
964
1117
  return __privateGet(this, _ctx).moveTo(this.$doPixelRatio(x2), this.$doPixelRatio(y2));
965
1118
  }
966
1119
  arcTo(x1, y1, x2, y2, radius) {
967
- return __privateGet(this, _ctx).arcTo(this.$doPixelRatio(x1), this.$doPixelRatio(y1), this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(radius));
1120
+ return __privateGet(this, _ctx).arcTo(
1121
+ this.$doPixelRatio(x1),
1122
+ this.$doPixelRatio(y1),
1123
+ this.$doPixelRatio(x2),
1124
+ this.$doPixelRatio(y2),
1125
+ this.$doPixelRatio(radius)
1126
+ );
1127
+ }
1128
+ bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x2, y2) {
1129
+ return __privateGet(this, _ctx).bezierCurveTo(
1130
+ this.$doPixelRatio(cp1x),
1131
+ this.$doPixelRatio(cp1y),
1132
+ this.$doPixelRatio(cp2x),
1133
+ this.$doPixelRatio(cp2y),
1134
+ this.$doPixelRatio(x2),
1135
+ this.$doPixelRatio(y2)
1136
+ );
1137
+ }
1138
+ quadraticCurveTo(cpx, cpy, x2, y2) {
1139
+ return __privateGet(this, _ctx).quadraticCurveTo(
1140
+ this.$doPixelRatio(cpx),
1141
+ this.$doPixelRatio(cpy),
1142
+ this.$doPixelRatio(x2),
1143
+ this.$doPixelRatio(y2)
1144
+ );
968
1145
  }
969
1146
  getLineDash() {
970
1147
  return __privateGet(this, _ctx).getLineDash();
@@ -1005,7 +1182,13 @@ var __privateSet = (obj, member, value, setter) => {
1005
1182
  this.$doPixelRatio(dh)
1006
1183
  );
1007
1184
  } else {
1008
- return __privateGet(this, _ctx).drawImage(image, this.$doPixelRatio(dx), this.$doPixelRatio(dy), this.$doPixelRatio(dw), this.$doPixelRatio(dh));
1185
+ return __privateGet(this, _ctx).drawImage(
1186
+ image,
1187
+ this.$doPixelRatio(dx),
1188
+ this.$doPixelRatio(dy),
1189
+ this.$doPixelRatio(dw),
1190
+ this.$doPixelRatio(dh)
1191
+ );
1009
1192
  }
1010
1193
  }
1011
1194
  createPattern(image, repetition) {
@@ -1065,7 +1248,12 @@ var __privateSet = (obj, member, value, setter) => {
1065
1248
  return __privateGet(this, _ctx).getTransform();
1066
1249
  }
1067
1250
  createLinearGradient(x0, y0, x1, y1) {
1068
- return __privateGet(this, _ctx).createLinearGradient(this.$doPixelRatio(x0), this.$doPixelRatio(y0), this.$doPixelRatio(x1), this.$doPixelRatio(y1));
1251
+ return __privateGet(this, _ctx).createLinearGradient(
1252
+ this.$doPixelRatio(x0),
1253
+ this.$doPixelRatio(y0),
1254
+ this.$doPixelRatio(x1),
1255
+ this.$doPixelRatio(y1)
1256
+ );
1069
1257
  }
1070
1258
  createRadialGradient(x0, y0, r0, x1, y1, r1) {
1071
1259
  return __privateGet(this, _ctx).createRadialGradient(
@@ -1107,77 +1295,55 @@ var __privateSet = (obj, member, value, setter) => {
1107
1295
  return context2d;
1108
1296
  }
1109
1297
  function createBoardContent(canvas, opts) {
1110
- const { width, height, devicePixelRatio, offscreen } = opts;
1298
+ const { width, height, devicePixelRatio } = opts;
1111
1299
  const ctxOpts = {
1112
1300
  width,
1113
1301
  height,
1114
1302
  devicePixelRatio
1115
1303
  };
1116
- if (offscreen === true) {
1117
- const ctx = canvas.getContext("2d");
1118
- const viewContext = createOffscreenContext2D(ctxOpts);
1119
- const helperContext = createOffscreenContext2D(ctxOpts);
1120
- const underContext = createOffscreenContext2D(ctxOpts);
1121
- const boardContext = createContext2D({ ctx, ...ctxOpts });
1122
- const drawView = () => {
1123
- const { width: w2, height: h2 } = viewContext.$getSize();
1124
- boardContext.clearRect(0, 0, w2, h2);
1125
- boardContext.drawImage(underContext.canvas, 0, 0, w2, h2);
1126
- boardContext.drawImage(viewContext.canvas, 0, 0, w2, h2);
1127
- boardContext.drawImage(helperContext.canvas, 0, 0, w2, h2);
1128
- underContext.clearRect(0, 0, w2, h2);
1129
- viewContext.clearRect(0, 0, w2, h2);
1130
- helperContext.clearRect(0, 0, w2, h2);
1131
- };
1132
- const content = {
1133
- underContext,
1134
- viewContext,
1135
- helperContext,
1136
- boardContext,
1137
- drawView
1138
- };
1139
- return content;
1140
- } else {
1141
- const ctx = canvas.getContext("2d");
1142
- const viewContext = createContext2D(ctxOpts);
1143
- const helperContext = createContext2D(ctxOpts);
1144
- const underContext = createContext2D(ctxOpts);
1145
- const boardContext = createContext2D({ ctx, ...ctxOpts });
1146
- const drawView = () => {
1147
- boardContext.clearRect(0, 0, width, height);
1148
- boardContext.drawImage(underContext.canvas, 0, 0, width, height);
1149
- boardContext.drawImage(viewContext.canvas, 0, 0, width, height);
1150
- boardContext.drawImage(helperContext.canvas, 0, 0, width, height);
1151
- underContext.clearRect(0, 0, width, height);
1152
- viewContext.clearRect(0, 0, width, height);
1153
- helperContext.clearRect(0, 0, width, height);
1154
- };
1155
- const content = {
1156
- underContext,
1157
- viewContext,
1158
- helperContext,
1159
- boardContext,
1160
- drawView
1161
- };
1162
- return content;
1163
- }
1304
+ const ctx = canvas.getContext("2d");
1305
+ const viewContext = createOffscreenContext2D(ctxOpts);
1306
+ const overlayContext = createOffscreenContext2D(ctxOpts);
1307
+ const underlayContext = createOffscreenContext2D(ctxOpts);
1308
+ const boardContext = createContext2D({ ctx, ...ctxOpts });
1309
+ const tempContext = createOffscreenContext2D(ctxOpts);
1310
+ const drawView = () => {
1311
+ const { width: w2, height: h2 } = viewContext.$getSize();
1312
+ boardContext.clearRect(0, 0, w2, h2);
1313
+ boardContext.drawImage(underlayContext.canvas, 0, 0, w2, h2);
1314
+ boardContext.drawImage(viewContext.canvas, 0, 0, w2, h2);
1315
+ boardContext.drawImage(overlayContext.canvas, 0, 0, w2, h2);
1316
+ underlayContext.clearRect(0, 0, w2, h2);
1317
+ viewContext.clearRect(0, 0, w2, h2);
1318
+ overlayContext.clearRect(0, 0, w2, h2);
1319
+ };
1320
+ const content = {
1321
+ underlayContext,
1322
+ viewContext,
1323
+ overlayContext,
1324
+ boardContext,
1325
+ tempContext,
1326
+ drawView
1327
+ };
1328
+ return content;
1164
1329
  }
1165
1330
  class EventEmitter {
1166
1331
  constructor() {
1167
- this._listeners = /* @__PURE__ */ new Map();
1332
+ __privateAdd(this, _listeners);
1333
+ __privateSet(this, _listeners, /* @__PURE__ */ new Map());
1168
1334
  }
1169
1335
  on(eventKey, callback) {
1170
- if (this._listeners.has(eventKey)) {
1171
- const callbacks = this._listeners.get(eventKey) || [];
1336
+ if (__privateGet(this, _listeners).has(eventKey)) {
1337
+ const callbacks = __privateGet(this, _listeners).get(eventKey) || [];
1172
1338
  callbacks == null ? void 0 : callbacks.push(callback);
1173
- this._listeners.set(eventKey, callbacks);
1339
+ __privateGet(this, _listeners).set(eventKey, callbacks);
1174
1340
  } else {
1175
- this._listeners.set(eventKey, [callback]);
1341
+ __privateGet(this, _listeners).set(eventKey, [callback]);
1176
1342
  }
1177
1343
  }
1178
1344
  off(eventKey, callback) {
1179
- if (this._listeners.has(eventKey)) {
1180
- const callbacks = this._listeners.get(eventKey);
1345
+ if (__privateGet(this, _listeners).has(eventKey)) {
1346
+ const callbacks = __privateGet(this, _listeners).get(eventKey);
1181
1347
  if (Array.isArray(callbacks)) {
1182
1348
  for (let i = 0; i < (callbacks == null ? void 0 : callbacks.length); i++) {
1183
1349
  if (callbacks[i] === callback) {
@@ -1186,11 +1352,11 @@ var __privateSet = (obj, member, value, setter) => {
1186
1352
  }
1187
1353
  }
1188
1354
  }
1189
- this._listeners.set(eventKey, callbacks || []);
1355
+ __privateGet(this, _listeners).set(eventKey, callbacks || []);
1190
1356
  }
1191
1357
  }
1192
1358
  trigger(eventKey, e) {
1193
- const callbacks = this._listeners.get(eventKey);
1359
+ const callbacks = __privateGet(this, _listeners).get(eventKey);
1194
1360
  if (Array.isArray(callbacks)) {
1195
1361
  callbacks.forEach((cb) => {
1196
1362
  cb(e);
@@ -1201,15 +1367,22 @@ var __privateSet = (obj, member, value, setter) => {
1201
1367
  }
1202
1368
  }
1203
1369
  has(name) {
1204
- if (this._listeners.has(name)) {
1205
- const list = this._listeners.get(name);
1370
+ if (__privateGet(this, _listeners).has(name)) {
1371
+ const list = __privateGet(this, _listeners).get(name);
1206
1372
  if (Array.isArray(list) && list.length > 0) {
1207
1373
  return true;
1208
1374
  }
1209
1375
  }
1210
1376
  return false;
1211
1377
  }
1378
+ destroy() {
1379
+ this.clear();
1380
+ }
1381
+ clear() {
1382
+ __privateGet(this, _listeners).clear();
1383
+ }
1212
1384
  }
1385
+ _listeners = new WeakMap();
1213
1386
  function calcDistance(start, end) {
1214
1387
  const distance = (start.x - end.x) * (start.x - end.x) + (start.y - end.y) * (start.y - end.y);
1215
1388
  return distance === 0 ? distance : Math.sqrt(distance);
@@ -1242,25 +1415,47 @@ var __privateSet = (obj, member, value, setter) => {
1242
1415
  }
1243
1416
  class Store {
1244
1417
  constructor(opts) {
1245
- this._backUpDefaultStorage = deepClone(opts.defaultStorage);
1246
- this._temp = this._createTempStorage();
1418
+ __privateAdd(this, _Store_instances);
1419
+ __privateAdd(this, _temp);
1420
+ __privateAdd(this, _backUpDefaultStorage);
1421
+ __privateAdd(this, _static);
1422
+ __privateSet(this, _backUpDefaultStorage, deepClone(opts.defaultStorage));
1423
+ __privateSet(this, _temp, __privateMethod(this, _Store_instances, createTempStorage_fn).call(this));
1424
+ __privateSet(this, _static, opts.defaultStatic || {});
1247
1425
  }
1248
1426
  set(name, value) {
1249
- this._temp[name] = value;
1427
+ __privateGet(this, _temp)[name] = value;
1250
1428
  }
1251
1429
  get(name) {
1252
- return this._temp[name];
1430
+ return __privateGet(this, _temp)[name];
1253
1431
  }
1254
- getSnapshot() {
1255
- return deepClone(this._temp);
1432
+ setStatic(name, value) {
1433
+ __privateGet(this, _static)[name] = value;
1434
+ }
1435
+ getStatic(name) {
1436
+ return __privateGet(this, _static)[name];
1437
+ }
1438
+ getSnapshot(opts) {
1439
+ if ((opts == null ? void 0 : opts.deepClone) === true) {
1440
+ return deepClone(__privateGet(this, _temp));
1441
+ }
1442
+ return { ...__privateGet(this, _temp) };
1256
1443
  }
1257
1444
  clear() {
1258
- this._temp = this._createTempStorage();
1445
+ __privateSet(this, _temp, __privateMethod(this, _Store_instances, createTempStorage_fn).call(this));
1259
1446
  }
1260
- _createTempStorage() {
1261
- return deepClone(this._backUpDefaultStorage);
1447
+ destroy() {
1448
+ __privateSet(this, _temp, null);
1449
+ __privateSet(this, _static, null);
1262
1450
  }
1263
1451
  }
1452
+ _temp = new WeakMap();
1453
+ _backUpDefaultStorage = new WeakMap();
1454
+ _static = new WeakMap();
1455
+ _Store_instances = new WeakSet();
1456
+ createTempStorage_fn = function() {
1457
+ return deepClone(__privateGet(this, _backUpDefaultStorage));
1458
+ };
1264
1459
  function getViewScaleInfoFromSnapshot(snapshot) {
1265
1460
  const { activeStore } = snapshot;
1266
1461
  const sacelInfo = {
@@ -1329,6 +1524,15 @@ var __privateSet = (obj, member, value, setter) => {
1329
1524
  };
1330
1525
  return calcElementCenter(elemSize);
1331
1526
  }
1527
+ function calcRadian(center, start, end) {
1528
+ const startRadian = calcLineRadian(center, start);
1529
+ const endRadian = calcLineRadian(center, end);
1530
+ if (endRadian !== null && startRadian !== null) {
1531
+ return endRadian - startRadian;
1532
+ } else {
1533
+ return 0;
1534
+ }
1535
+ }
1332
1536
  function calcLineRadian(center, p) {
1333
1537
  const x2 = p.x - center.x;
1334
1538
  const y2 = p.y - center.y;
@@ -1409,7 +1613,7 @@ var __privateSet = (obj, member, value, setter) => {
1409
1613
  let resultY = point.y;
1410
1614
  groupQueue.forEach((group) => {
1411
1615
  const { x: x2, y: y2, w: w2, h: h2, angle: angle2 = 0 } = group;
1412
- const center = calcElementCenter({ x: x2, y: y2, w: w2, h: h2, angle: angle2 });
1616
+ const center = calcElementCenter({ x: x2, y: y2, w: w2, h: h2 });
1413
1617
  const temp = rotatePoint(center, { x: resultX, y: resultY }, parseAngleToRadian(angle2));
1414
1618
  resultX = temp.x;
1415
1619
  resultY = temp.y;
@@ -1450,12 +1654,14 @@ var __privateSet = (obj, member, value, setter) => {
1450
1654
  ];
1451
1655
  }
1452
1656
  function limitAngle(angle2) {
1453
- if (!(angle2 > 0 || angle2 < 0) || angle2 === 0) {
1657
+ if (!(angle2 > 0 || angle2 < 0) || angle2 === 0 || angle2 === 360) {
1454
1658
  return 0;
1455
1659
  }
1456
1660
  let num = angle2 % 360;
1457
1661
  if (num < 0) {
1458
1662
  num += 360;
1663
+ } else if (angle2 === 360) {
1664
+ num = 0;
1459
1665
  }
1460
1666
  return num;
1461
1667
  }
@@ -1622,7 +1828,11 @@ var __privateSet = (obj, member, value, setter) => {
1622
1828
  return ctxSize;
1623
1829
  }
1624
1830
  function calcElementsViewInfo(elements, prevViewSize, options) {
1625
- const contextSize = calcElementsContextSize(elements, { viewWidth: prevViewSize.width, viewHeight: prevViewSize.height, extend: options == null ? void 0 : options.extend });
1831
+ const contextSize = calcElementsContextSize(elements, {
1832
+ viewWidth: prevViewSize.width,
1833
+ viewHeight: prevViewSize.height,
1834
+ extend: options == null ? void 0 : options.extend
1835
+ });
1626
1836
  if ((options == null ? void 0 : options.extend) === true) {
1627
1837
  contextSize.contextWidth = Math.max(contextSize.contextWidth, prevViewSize.contextWidth);
1628
1838
  contextSize.contextHeight = Math.max(contextSize.contextHeight, prevViewSize.contextHeight);
@@ -1708,6 +1918,24 @@ var __privateSet = (obj, member, value, setter) => {
1708
1918
  _scan(uuid, elements);
1709
1919
  return groupQueue;
1710
1920
  }
1921
+ function getGroupQueueByElementPosition(elements, position) {
1922
+ var _a;
1923
+ const groupQueue = [];
1924
+ let currentElements = elements;
1925
+ if (position.length > 1) {
1926
+ for (let i = 0; i < position.length - 1; i++) {
1927
+ const index = position[i];
1928
+ const group = currentElements[index];
1929
+ if ((group == null ? void 0 : group.type) === "group" && Array.isArray((_a = group == null ? void 0 : group.detail) == null ? void 0 : _a.children)) {
1930
+ groupQueue.push(group);
1931
+ currentElements = group.detail.children;
1932
+ } else {
1933
+ return null;
1934
+ }
1935
+ }
1936
+ }
1937
+ return groupQueue;
1938
+ }
1711
1939
  function getElementSize(elem) {
1712
1940
  const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = elem;
1713
1941
  const size = { x: x2, y: y2, w: w2, h: h2, angle: angle2 };
@@ -1788,7 +2016,7 @@ var __privateSet = (obj, member, value, setter) => {
1788
2016
  for (let i = 0; i < position.length; i++) {
1789
2017
  const pos = position[i];
1790
2018
  const item = tempList[pos];
1791
- if (i < position.length - 1 && item.type === "group") {
2019
+ if (i < position.length - 1 && (item == null ? void 0 : item.type) === "group") {
1792
2020
  tempList = item.detail.children;
1793
2021
  } else if (i === position.length - 1) {
1794
2022
  result = item;
@@ -1843,16 +2071,120 @@ var __privateSet = (obj, member, value, setter) => {
1843
2071
  _loop(elements);
1844
2072
  return result;
1845
2073
  }
2074
+ function getElementPositionMapFromList(uuids, elements) {
2075
+ const currentPosition = [];
2076
+ const positionMap = {};
2077
+ let over = false;
2078
+ const _loop = (list) => {
2079
+ var _a;
2080
+ for (let i = 0; i < list.length; i++) {
2081
+ if (over === true) {
2082
+ break;
2083
+ }
2084
+ currentPosition.push(i);
2085
+ const elem = list[i];
2086
+ if (uuids.includes(elem.uuid)) {
2087
+ positionMap[elem.uuid] = [...currentPosition];
2088
+ if (Object.keys(positionMap).length === uuids.length) {
2089
+ over = true;
2090
+ break;
2091
+ }
2092
+ } else if (elem.type === "group") {
2093
+ _loop(((_a = elem == null ? void 0 : elem.detail) == null ? void 0 : _a.children) || []);
2094
+ }
2095
+ if (over) {
2096
+ break;
2097
+ }
2098
+ currentPosition.pop();
2099
+ }
2100
+ };
2101
+ _loop(elements);
2102
+ return positionMap;
2103
+ }
2104
+ function isSameElementSize(elem1, elem2) {
2105
+ 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);
2106
+ }
1846
2107
  function checkRectIntersect(rect1, rect2) {
1847
- const react1MinX = rect1.x;
1848
- const react1MinY = rect1.y;
1849
- const react1MaxX = rect1.x + rect1.w;
1850
- const react1MaxY = rect1.y + rect1.h;
1851
- const react2MinX = rect2.x;
1852
- const react2MinY = rect2.y;
1853
- const react2MaxX = rect2.x + rect2.w;
1854
- const react2MaxY = rect2.y + rect2.h;
1855
- return react1MinX <= react2MaxX && react1MaxX >= react2MinX && react1MinY <= react2MaxY && react1MaxY >= react2MinY;
2108
+ const rect1MinX = rect1.x;
2109
+ const rect1MinY = rect1.y;
2110
+ const rect1MaxX = rect1.x + rect1.w;
2111
+ const rect1MaxY = rect1.y + rect1.h;
2112
+ const rect2MinX = rect2.x;
2113
+ const rect2MinY = rect2.y;
2114
+ const rect2MaxX = rect2.x + rect2.w;
2115
+ const rect2MaxY = rect2.y + rect2.h;
2116
+ return rect1MinX <= rect2MaxX && rect1MaxX >= rect2MinX && rect1MinY <= rect2MaxY && rect1MaxY >= rect2MinY;
2117
+ }
2118
+ function getElementVertexes(elemSize) {
2119
+ const { x: x2, y: y2, h: h2, w: w2 } = elemSize;
2120
+ return [
2121
+ { x: x2, y: y2 },
2122
+ { x: x2 + w2, y: y2 },
2123
+ { x: x2 + w2, y: y2 + h2 },
2124
+ { x: x2, y: y2 + h2 }
2125
+ ];
2126
+ }
2127
+ function calcElementVertexes(elemSize) {
2128
+ const { x: x2, y: y2, w: w2, h: h2, angle: angle2 = 0 } = elemSize;
2129
+ if (angle2 === 0) {
2130
+ return getElementVertexes(elemSize);
2131
+ }
2132
+ return getElementRotateVertexes(elemSize, calcElementCenter({ x: x2, y: y2, w: w2, h: h2 }), angle2);
2133
+ }
2134
+ function calcElementQueueVertexesQueueInGroup(groupQueue) {
2135
+ const vesList = [];
2136
+ let totalX = 0;
2137
+ let totalY = 0;
2138
+ const rotateActionList = [];
2139
+ const elemQueue = [...groupQueue];
2140
+ for (let i = 0; i < elemQueue.length; i++) {
2141
+ const { x: x2, y: y2, w: w2, h: h2, angle: angle2 = 0 } = elemQueue[i];
2142
+ totalX += x2;
2143
+ totalY += y2;
2144
+ let ves;
2145
+ if (i === 0) {
2146
+ const elemSize = { x: totalX, y: totalY, w: w2, h: h2 };
2147
+ ves = calcElementVertexes({ x: x2, y: y2, w: w2, h: h2, angle: angle2 });
2148
+ rotateActionList.push({
2149
+ center: calcElementCenter(elemSize),
2150
+ angle: angle2,
2151
+ radian: parseAngleToRadian(angle2)
2152
+ });
2153
+ } else {
2154
+ const elemSize = { x: totalX, y: totalY, w: w2, h: h2 };
2155
+ ves = getElementVertexes(elemSize);
2156
+ for (let aIdx = 0; aIdx < rotateActionList.length; aIdx++) {
2157
+ const { center, radian } = rotateActionList[aIdx];
2158
+ ves = rotateVertexes(center, ves, radian);
2159
+ }
2160
+ const vesCenter = calcElementCenterFromVertexes(ves);
2161
+ if (angle2 > 0 || angle2 < 0) {
2162
+ const radian = parseAngleToRadian(angle2);
2163
+ ves = rotateVertexes(vesCenter, ves, radian);
2164
+ }
2165
+ rotateActionList.push({
2166
+ center: vesCenter,
2167
+ angle: angle2,
2168
+ radian: parseAngleToRadian(angle2)
2169
+ });
2170
+ }
2171
+ vesList.push(ves);
2172
+ }
2173
+ return vesList;
2174
+ }
2175
+ function calcElementVertexesQueueInGroup(targetElem, opts) {
2176
+ const { groupQueue } = opts;
2177
+ if (!(groupQueue.length > 0)) {
2178
+ return [calcElementVertexes(targetElem)];
2179
+ }
2180
+ const elemQueue = [...groupQueue, ...[targetElem]];
2181
+ const vesList = calcElementQueueVertexesQueueInGroup(elemQueue);
2182
+ return vesList;
2183
+ }
2184
+ function calcElementVertexesInGroup(targetElem, opts) {
2185
+ const vesList = calcElementVertexesQueueInGroup(targetElem, opts);
2186
+ const ves = vesList.pop();
2187
+ return ves || null;
1856
2188
  }
1857
2189
  function calcViewScaleInfo(info, opts) {
1858
2190
  const { scale, offsetX, offsetY } = info;
@@ -1940,9 +2272,9 @@ var __privateSet = (obj, member, value, setter) => {
1940
2272
  ];
1941
2273
  }
1942
2274
  function isViewPointInElement(p, opts) {
1943
- const { context2d: ctx, element: elem, viewScaleInfo, viewSizeInfo } = opts;
2275
+ const { context2d: ctx, element: elem, viewScaleInfo } = opts;
1944
2276
  const { angle: angle2 = 0 } = elem;
1945
- const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(elem, { viewScaleInfo, viewSizeInfo });
2277
+ const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(elem, { viewScaleInfo });
1946
2278
  const vertexes = rotateElementVertexes({ x: x2, y: y2, w: w2, h: h2, angle: angle2 });
1947
2279
  if (vertexes.length >= 2) {
1948
2280
  ctx.beginPath();
@@ -1957,6 +2289,25 @@ var __privateSet = (obj, member, value, setter) => {
1957
2289
  }
1958
2290
  return false;
1959
2291
  }
2292
+ function isViewPointInElementSize(p, elemSize, opts) {
2293
+ const vertexes = calcElementVertexes(elemSize);
2294
+ return isViewPointInVertexes(p, vertexes, opts);
2295
+ }
2296
+ function isViewPointInVertexes(p, vertexes, opts) {
2297
+ const xList = [vertexes[0].x, vertexes[1].x, vertexes[2].x, vertexes[3].x];
2298
+ const yList = [vertexes[0].y, vertexes[1].y, vertexes[2].y, vertexes[3].y];
2299
+ const mixX = Math.min(...xList);
2300
+ const maxX = Math.max(...xList);
2301
+ const mixY = Math.min(...yList);
2302
+ const maxY = Math.max(...yList);
2303
+ if (p.x > mixX && p.x < maxX && p.y > mixY && p.y < maxY) {
2304
+ return true;
2305
+ }
2306
+ if ((opts == null ? void 0 : opts.includeBorder) === true && (p.x === mixX || p.x === maxX || p.y === mixY || p.y === maxY)) {
2307
+ return true;
2308
+ }
2309
+ return false;
2310
+ }
1960
2311
  function getViewPointAtElement(p, opts) {
1961
2312
  var _a, _b, _c;
1962
2313
  const { context2d: ctx, data, viewScaleInfo, viewSizeInfo, groupQueue } = opts;
@@ -1990,7 +2341,7 @@ var __privateSet = (obj, member, value, setter) => {
1990
2341
  h: child.h,
1991
2342
  angle: totalAngle + (child.angle || 0)
1992
2343
  };
1993
- if (isViewPointInElement(p, { context2d: ctx, element: elemSize, viewScaleInfo, viewSizeInfo })) {
2344
+ if (isViewPointInElement(p, { context2d: ctx, element: elemSize, viewScaleInfo })) {
1994
2345
  result.element = child;
1995
2346
  if (gIdx < groupQueue.length - 1 || child.type !== "group") {
1996
2347
  result.groupQueueIndex = gIdx;
@@ -2015,7 +2366,7 @@ var __privateSet = (obj, member, value, setter) => {
2015
2366
  if (((_c = elem == null ? void 0 : elem.operations) == null ? void 0 : _c.invisible) === true) {
2016
2367
  continue;
2017
2368
  }
2018
- if (isViewPointInElement(p, { context2d: ctx, element: elem, viewScaleInfo, viewSizeInfo })) {
2369
+ if (isViewPointInElement(p, { context2d: ctx, element: elem, viewScaleInfo })) {
2019
2370
  result.index = i;
2020
2371
  result.element = elem;
2021
2372
  break;
@@ -2027,7 +2378,7 @@ var __privateSet = (obj, member, value, setter) => {
2027
2378
  const { viewSizeInfo, viewScaleInfo } = opts;
2028
2379
  const { width, height } = viewSizeInfo;
2029
2380
  const { angle: angle2 } = elem;
2030
- const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(elem, { viewScaleInfo, viewSizeInfo });
2381
+ const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(elem, { viewScaleInfo });
2031
2382
  const ves = rotateElementVertexes({ x: x2, y: y2, w: w2, h: h2, angle: angle2 });
2032
2383
  const viewSize = { x: 0, y: 0, w: width, h: height };
2033
2384
  const elemStartX = Math.min(ves[0].x, ves[1].x, ves[2].x, ves[3].x);
@@ -2037,76 +2388,148 @@ var __privateSet = (obj, member, value, setter) => {
2037
2388
  const elemSize = { x: elemStartX, y: elemStartY, w: elemEndX - elemStartX, h: elemEndY - elemStartY };
2038
2389
  return checkRectIntersect(viewSize, elemSize);
2039
2390
  }
2040
- function getElementVertexes(elemSize) {
2041
- const { x: x2, y: y2, h: h2, w: w2 } = elemSize;
2042
- return [
2043
- { x: x2, y: y2 },
2044
- { x: x2 + w2, y: y2 },
2045
- { x: x2 + w2, y: y2 + h2 },
2046
- { x: x2, y: y2 + h2 }
2047
- ];
2048
- }
2049
- function calcElementVertexes(elemSize) {
2050
- const { x: x2, y: y2, w: w2, h: h2, angle: angle2 = 0 } = elemSize;
2051
- if (angle2 === 0) {
2052
- return getElementVertexes(elemSize);
2053
- }
2054
- return getElementRotateVertexes(elemSize, calcElementCenter({ x: x2, y: y2, w: w2, h: h2, angle: angle2 }), angle2);
2055
- }
2056
- function calcElementQueueVertexesQueueInGroup(groupQueue) {
2057
- const vesList = [];
2058
- let totalX = 0;
2059
- let totalY = 0;
2060
- const rotateActionList = [];
2061
- const elemQueue = [...groupQueue];
2062
- for (let i = 0; i < elemQueue.length; i++) {
2063
- const { x: x2, y: y2, w: w2, h: h2, angle: angle2 = 0 } = elemQueue[i];
2064
- totalX += x2;
2065
- totalY += y2;
2066
- let ves;
2067
- if (i === 0) {
2068
- const elemSize = { x: totalX, y: totalY, w: w2, h: h2, angle: angle2 };
2069
- ves = calcElementVertexes({ x: x2, y: y2, w: w2, h: h2, angle: angle2 });
2070
- rotateActionList.push({
2071
- center: calcElementCenter(elemSize),
2072
- angle: angle2,
2073
- radian: parseAngleToRadian(angle2)
2074
- });
2075
- } else {
2076
- const elemSize = { x: totalX, y: totalY, w: w2, h: h2, angle: angle2 };
2077
- ves = getElementVertexes(elemSize);
2078
- for (let aIdx = 0; aIdx < rotateActionList.length; aIdx++) {
2079
- const { center, radian } = rotateActionList[aIdx];
2080
- ves = rotateVertexes(center, ves, radian);
2081
- }
2082
- const vesCenter = calcElementCenterFromVertexes(ves);
2083
- if (angle2 > 0 || angle2 < 0) {
2084
- const radian = parseAngleToRadian(angle2);
2085
- ves = rotateVertexes(vesCenter, ves, radian);
2086
- }
2087
- rotateActionList.push({
2088
- center: vesCenter,
2089
- angle: angle2,
2090
- radian: parseAngleToRadian(angle2)
2091
- });
2092
- }
2093
- vesList.push(ves);
2094
- }
2095
- return vesList;
2096
- }
2097
- function calcElementVertexesQueueInGroup(targetElem, opts) {
2391
+ function calcElementOriginRectInfo(elemSize, opts) {
2098
2392
  const { groupQueue } = opts;
2099
- if (!(groupQueue.length > 0)) {
2100
- return [calcElementVertexes(targetElem)];
2393
+ const vertexes = calcElementVertexesInGroup(elemSize, { groupQueue });
2394
+ const top = getCenterFromTwoPoints(vertexes[0], vertexes[1]);
2395
+ const right = getCenterFromTwoPoints(vertexes[1], vertexes[2]);
2396
+ const bottom = getCenterFromTwoPoints(vertexes[2], vertexes[3]);
2397
+ const left = getCenterFromTwoPoints(vertexes[3], vertexes[0]);
2398
+ const topLeft = vertexes[0];
2399
+ const topRight = vertexes[1];
2400
+ const bottomRight = vertexes[2];
2401
+ const bottomLeft = vertexes[3];
2402
+ const maxX = Math.max(topLeft.x, topRight.x, bottomRight.x, bottomLeft.x);
2403
+ const maxY = Math.max(topLeft.y, topRight.y, bottomRight.y, bottomLeft.y);
2404
+ const minX = Math.min(topLeft.x, topRight.x, bottomRight.x, bottomLeft.x);
2405
+ const minY = Math.min(topLeft.y, topRight.y, bottomRight.y, bottomLeft.y);
2406
+ const center = {
2407
+ x: (maxX + minX) / 2,
2408
+ y: (maxY + minY) / 2
2409
+ };
2410
+ const rectInfo = {
2411
+ center,
2412
+ topLeft,
2413
+ topRight,
2414
+ bottomLeft,
2415
+ bottomRight,
2416
+ top,
2417
+ right,
2418
+ left,
2419
+ bottom
2420
+ };
2421
+ return rectInfo;
2422
+ }
2423
+ function originRectInfoToRangeRectInfo(originRectInfo) {
2424
+ const rangeMaxX = Math.max(
2425
+ originRectInfo.topLeft.x,
2426
+ originRectInfo.topRight.x,
2427
+ originRectInfo.bottomRight.x,
2428
+ originRectInfo.bottomLeft.x
2429
+ );
2430
+ const rangeMaxY = Math.max(
2431
+ originRectInfo.topLeft.y,
2432
+ originRectInfo.topRight.y,
2433
+ originRectInfo.bottomRight.y,
2434
+ originRectInfo.bottomLeft.y
2435
+ );
2436
+ const rangeMinX = Math.min(
2437
+ originRectInfo.topLeft.x,
2438
+ originRectInfo.topRight.x,
2439
+ originRectInfo.bottomRight.x,
2440
+ originRectInfo.bottomLeft.x
2441
+ );
2442
+ const rangeMinY = Math.min(
2443
+ originRectInfo.topLeft.y,
2444
+ originRectInfo.topRight.y,
2445
+ originRectInfo.bottomRight.y,
2446
+ originRectInfo.bottomLeft.y
2447
+ );
2448
+ const rangeCenter = { x: originRectInfo.center.x, y: originRectInfo.center.y };
2449
+ const rangeTopLeft = { x: rangeMinX, y: rangeMinY };
2450
+ const rangeTopRight = { x: rangeMaxX, y: rangeMinY };
2451
+ const rangeBottomRight = { x: rangeMaxX, y: rangeMaxY };
2452
+ const rangeBottomLeft = { x: rangeMinX, y: rangeMaxY };
2453
+ const rangeTop = getCenterFromTwoPoints(rangeTopLeft, rangeTopRight);
2454
+ const rangeBottom = getCenterFromTwoPoints(rangeBottomLeft, rangeBottomRight);
2455
+ const rangeLeft = getCenterFromTwoPoints(rangeTopLeft, rangeBottomLeft);
2456
+ const rangeRight = getCenterFromTwoPoints(rangeTopRight, rangeBottomRight);
2457
+ const rangeRectInfo = {
2458
+ center: rangeCenter,
2459
+ topLeft: rangeTopLeft,
2460
+ topRight: rangeTopRight,
2461
+ bottomLeft: rangeBottomLeft,
2462
+ bottomRight: rangeBottomRight,
2463
+ top: rangeTop,
2464
+ right: rangeRight,
2465
+ left: rangeLeft,
2466
+ bottom: rangeBottom
2467
+ };
2468
+ return rangeRectInfo;
2469
+ }
2470
+ function calcElementViewRectInfo(elemSize, opts) {
2471
+ const { groupQueue, viewScaleInfo, range } = opts;
2472
+ const originRectInfo = calcElementOriginRectInfo(elemSize, { groupQueue });
2473
+ const { center, top, bottom, left, right, topLeft, topRight, bottomLeft, bottomRight } = originRectInfo;
2474
+ const viewRectInfo = {
2475
+ center: calcViewPointSize(center, { viewScaleInfo }),
2476
+ topLeft: calcViewPointSize(topLeft, { viewScaleInfo }),
2477
+ topRight: calcViewPointSize(topRight, { viewScaleInfo }),
2478
+ bottomLeft: calcViewPointSize(bottomLeft, { viewScaleInfo }),
2479
+ bottomRight: calcViewPointSize(bottomRight, { viewScaleInfo }),
2480
+ top: calcViewPointSize(top, { viewScaleInfo }),
2481
+ right: calcViewPointSize(right, { viewScaleInfo }),
2482
+ left: calcViewPointSize(left, { viewScaleInfo }),
2483
+ bottom: calcViewPointSize(bottom, { viewScaleInfo })
2484
+ };
2485
+ if (range === true) {
2486
+ const viewMaxX = Math.max(
2487
+ viewRectInfo.topLeft.x,
2488
+ viewRectInfo.topRight.x,
2489
+ viewRectInfo.bottomRight.x,
2490
+ viewRectInfo.bottomLeft.x
2491
+ );
2492
+ const viewMaxY = Math.max(
2493
+ viewRectInfo.topLeft.y,
2494
+ viewRectInfo.topRight.y,
2495
+ viewRectInfo.bottomRight.y,
2496
+ viewRectInfo.bottomLeft.y
2497
+ );
2498
+ const viewMinX = Math.min(
2499
+ viewRectInfo.topLeft.x,
2500
+ viewRectInfo.topRight.x,
2501
+ viewRectInfo.bottomRight.x,
2502
+ viewRectInfo.bottomLeft.x
2503
+ );
2504
+ const viewMinY = Math.min(
2505
+ viewRectInfo.topLeft.y,
2506
+ viewRectInfo.topRight.y,
2507
+ viewRectInfo.bottomRight.y,
2508
+ viewRectInfo.bottomLeft.y
2509
+ );
2510
+ const rangeCenter = { x: viewRectInfo.center.x, y: viewRectInfo.center.y };
2511
+ const rangeTopLeft = { x: viewMinX, y: viewMinY };
2512
+ const rangeTopRight = { x: viewMaxX, y: viewMinY };
2513
+ const rangeBottomRight = { x: viewMaxX, y: viewMaxY };
2514
+ const rangeBottomLeft = { x: viewMinX, y: viewMaxY };
2515
+ const rangeTop = getCenterFromTwoPoints(rangeTopLeft, rangeTopRight);
2516
+ const rangeBottom = getCenterFromTwoPoints(rangeBottomLeft, rangeBottomRight);
2517
+ const rangeLeft = getCenterFromTwoPoints(rangeTopLeft, rangeBottomLeft);
2518
+ const rangeRight = getCenterFromTwoPoints(rangeTopRight, rangeBottomRight);
2519
+ const rangeRectInfo = {
2520
+ center: rangeCenter,
2521
+ topLeft: rangeTopLeft,
2522
+ topRight: rangeTopRight,
2523
+ bottomLeft: rangeBottomLeft,
2524
+ bottomRight: rangeBottomRight,
2525
+ top: rangeTop,
2526
+ right: rangeRight,
2527
+ left: rangeLeft,
2528
+ bottom: rangeBottom
2529
+ };
2530
+ return rangeRectInfo;
2101
2531
  }
2102
- const elemQueue = [...groupQueue, ...[targetElem]];
2103
- const vesList = calcElementQueueVertexesQueueInGroup(elemQueue);
2104
- return vesList;
2105
- }
2106
- function calcElementVertexesInGroup(targetElem, opts) {
2107
- const vesList = calcElementVertexesQueueInGroup(targetElem, opts);
2108
- const ves = vesList.pop();
2109
- return ves || null;
2532
+ return viewRectInfo;
2110
2533
  }
2111
2534
  function createControllerElementSizeFromCenter(center, opts) {
2112
2535
  const { x: x2, y: y2 } = center;
@@ -2120,9 +2543,11 @@ var __privateSet = (obj, member, value, setter) => {
2120
2543
  };
2121
2544
  }
2122
2545
  function calcElementSizeController(elemSize, opts) {
2123
- const { groupQueue, controllerSize, viewScaleInfo } = opts;
2546
+ const { groupQueue, controllerSize, viewScaleInfo, rotateControllerSize, rotateControllerPosition } = opts;
2124
2547
  const ctrlSize = (controllerSize && controllerSize > 0 ? controllerSize : 8) / viewScaleInfo.scale;
2125
2548
  const { x: x2, y: y2, w: w2, h: h2, angle: angle2 = 0 } = elemSize;
2549
+ const rotateCtrlSize = rotateControllerSize;
2550
+ const rotateCtrlPos = rotateControllerPosition;
2126
2551
  const ctrlGroupQueue = [
2127
2552
  ...[
2128
2553
  {
@@ -2143,6 +2568,16 @@ var __privateSet = (obj, member, value, setter) => {
2143
2568
  totalAngle += angle22;
2144
2569
  });
2145
2570
  const vertexes = calcElementVertexesInGroup(elemSize, { groupQueue });
2571
+ const rotateElemVertexes = calcElementVertexesInGroup(
2572
+ {
2573
+ x: x2,
2574
+ y: y2 - (rotateCtrlPos + rotateCtrlSize / 2) / viewScaleInfo.scale,
2575
+ h: h2 + (rotateCtrlPos * 2 + rotateCtrlSize) / viewScaleInfo.scale,
2576
+ w: w2,
2577
+ angle: angle2
2578
+ },
2579
+ { groupQueue: [...groupQueue] }
2580
+ );
2146
2581
  const topCenter = getCenterFromTwoPoints(vertexes[0], vertexes[1]);
2147
2582
  const rightCenter = getCenterFromTwoPoints(vertexes[1], vertexes[2]);
2148
2583
  const bottomCenter = getCenterFromTwoPoints(vertexes[2], vertexes[3]);
@@ -2151,59 +2586,266 @@ var __privateSet = (obj, member, value, setter) => {
2151
2586
  const topRightCenter = vertexes[1];
2152
2587
  const bottomRightCenter = vertexes[2];
2153
2588
  const bottomLeftCenter = vertexes[3];
2589
+ const topMiddleSize = createControllerElementSizeFromCenter(topCenter, { size: ctrlSize, angle: totalAngle });
2590
+ const rightMiddleSize = createControllerElementSizeFromCenter(rightCenter, { size: ctrlSize, angle: totalAngle });
2591
+ const bottomMiddleSize = createControllerElementSizeFromCenter(bottomCenter, { size: ctrlSize, angle: totalAngle });
2592
+ const leftMiddleSize = createControllerElementSizeFromCenter(leftCenter, { size: ctrlSize, angle: totalAngle });
2154
2593
  const topLeftSize = createControllerElementSizeFromCenter(topLeftCenter, { size: ctrlSize, angle: totalAngle });
2155
2594
  const topRightSize = createControllerElementSizeFromCenter(topRightCenter, { size: ctrlSize, angle: totalAngle });
2156
2595
  const bottomLeftSize = createControllerElementSizeFromCenter(bottomLeftCenter, { size: ctrlSize, angle: totalAngle });
2157
- const bottomRightSize = createControllerElementSizeFromCenter(bottomRightCenter, { size: ctrlSize, angle: totalAngle });
2596
+ const bottomRightSize = createControllerElementSizeFromCenter(bottomRightCenter, {
2597
+ size: ctrlSize,
2598
+ angle: totalAngle
2599
+ });
2158
2600
  const topLeftVertexes = calcElementVertexes(topLeftSize);
2159
2601
  const topRightVertexes = calcElementVertexes(topRightSize);
2160
2602
  const bottomLeftVertexes = calcElementVertexes(bottomLeftSize);
2161
2603
  const bottomRightVertexes = calcElementVertexes(bottomRightSize);
2162
- const topVertexes = [topLeftVertexes[1], topRightVertexes[0], topRightVertexes[3], topLeftVertexes[2]];
2163
- const rightVertexes = [topRightVertexes[3], topRightVertexes[2], bottomRightVertexes[1], bottomRightVertexes[0]];
2164
- const bottomVertexes = [bottomLeftVertexes[1], bottomRightVertexes[0], bottomRightVertexes[3], bottomLeftVertexes[2]];
2165
- const leftVertexes = [topLeftVertexes[3], topLeftVertexes[2], bottomLeftVertexes[1], bottomLeftVertexes[0]];
2604
+ const topVertexes = [
2605
+ topLeftVertexes[1],
2606
+ topRightVertexes[0],
2607
+ topRightVertexes[3],
2608
+ topLeftVertexes[2]
2609
+ ];
2610
+ const rightVertexes = [
2611
+ topRightVertexes[3],
2612
+ topRightVertexes[2],
2613
+ bottomRightVertexes[1],
2614
+ bottomRightVertexes[0]
2615
+ ];
2616
+ const bottomVertexes = [
2617
+ bottomLeftVertexes[1],
2618
+ bottomRightVertexes[0],
2619
+ bottomRightVertexes[3],
2620
+ bottomLeftVertexes[2]
2621
+ ];
2622
+ const leftVertexes = [
2623
+ topLeftVertexes[3],
2624
+ topLeftVertexes[2],
2625
+ bottomLeftVertexes[1],
2626
+ bottomLeftVertexes[0]
2627
+ ];
2628
+ const topMiddleVertexes = calcElementVertexes(topMiddleSize);
2629
+ const rightMiddleVertexes = calcElementVertexes(rightMiddleSize);
2630
+ const bottomMiddleVertexes = calcElementVertexes(bottomMiddleSize);
2631
+ const leftMiddleVertexes = calcElementVertexes(leftMiddleSize);
2632
+ const rotateCenter = getCenterFromTwoPoints(rotateElemVertexes[0], rotateElemVertexes[1]);
2633
+ const tempRotateSizeRepairRatio = 1.1;
2634
+ const rotateSize = createControllerElementSizeFromCenter(rotateCenter, {
2635
+ size: rotateControllerSize * tempRotateSizeRepairRatio / viewScaleInfo.scale,
2636
+ angle: totalAngle
2637
+ });
2638
+ const rotateVertexes2 = calcElementVertexes(rotateSize);
2166
2639
  const sizeController = {
2640
+ originalElementCenter: calcElementCenter(elemSize),
2641
+ originalElementSize: { ...elemSize },
2167
2642
  elementWrapper: vertexes,
2168
2643
  left: {
2169
2644
  type: "left",
2170
2645
  vertexes: leftVertexes,
2171
- center: leftCenter
2646
+ center: leftCenter,
2647
+ size: ctrlSize
2172
2648
  },
2173
2649
  right: {
2174
2650
  type: "right",
2175
2651
  vertexes: rightVertexes,
2176
- center: rightCenter
2652
+ center: rightCenter,
2653
+ size: ctrlSize
2177
2654
  },
2178
2655
  top: {
2179
2656
  type: "top",
2180
2657
  vertexes: topVertexes,
2181
- center: topCenter
2658
+ center: topCenter,
2659
+ size: ctrlSize
2182
2660
  },
2183
2661
  bottom: {
2184
2662
  type: "bottom",
2185
2663
  vertexes: bottomVertexes,
2186
- center: bottomCenter
2664
+ center: bottomCenter,
2665
+ size: ctrlSize
2187
2666
  },
2188
2667
  topLeft: {
2189
2668
  type: "top-left",
2190
2669
  vertexes: topLeftVertexes,
2191
- center: topLeftCenter
2670
+ center: topLeftCenter,
2671
+ size: ctrlSize
2192
2672
  },
2193
2673
  topRight: {
2194
2674
  type: "top-right",
2195
2675
  vertexes: topRightVertexes,
2196
- center: topRightCenter
2676
+ center: topRightCenter,
2677
+ size: ctrlSize
2197
2678
  },
2198
2679
  bottomLeft: {
2199
2680
  type: "bottom-left",
2200
2681
  vertexes: bottomLeftVertexes,
2201
- center: bottomLeftCenter
2682
+ center: bottomLeftCenter,
2683
+ size: ctrlSize
2202
2684
  },
2203
2685
  bottomRight: {
2204
2686
  type: "bottom-right",
2205
2687
  vertexes: bottomRightVertexes,
2206
- center: bottomRightCenter
2688
+ center: bottomRightCenter,
2689
+ size: ctrlSize
2690
+ },
2691
+ leftMiddle: {
2692
+ type: "left-middle",
2693
+ vertexes: leftMiddleVertexes,
2694
+ center: leftCenter,
2695
+ size: ctrlSize
2696
+ },
2697
+ rightMiddle: {
2698
+ type: "right-middle",
2699
+ vertexes: rightMiddleVertexes,
2700
+ center: rightCenter,
2701
+ size: ctrlSize
2702
+ },
2703
+ topMiddle: {
2704
+ type: "top-middle",
2705
+ vertexes: topMiddleVertexes,
2706
+ center: topCenter,
2707
+ size: ctrlSize
2708
+ },
2709
+ bottomMiddle: {
2710
+ type: "bottom-middle",
2711
+ vertexes: bottomMiddleVertexes,
2712
+ center: bottomCenter,
2713
+ size: ctrlSize
2714
+ },
2715
+ rotate: {
2716
+ type: "rotate",
2717
+ vertexes: rotateVertexes2,
2718
+ center: rotateCenter,
2719
+ size: rotateControllerSize
2720
+ }
2721
+ };
2722
+ return sizeController;
2723
+ }
2724
+ function calcLayoutSizeController(layoutSize, opts) {
2725
+ const { controllerSize, viewScaleInfo } = opts;
2726
+ const ctrlSize = controllerSize && controllerSize > 0 ? controllerSize : 8;
2727
+ const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(layoutSize, { viewScaleInfo });
2728
+ const center = calcElementCenter({ x: x2, y: y2, w: w2, h: h2 });
2729
+ const topCenter = { x: center.x, y: y2 };
2730
+ const rightCenter = { x: x2 + w2, y: center.y };
2731
+ const bottomCenter = { x: center.x, y: y2 + h2 };
2732
+ const leftCenter = { x: x2, y: center.y };
2733
+ const topLeftCenter = { x: x2, y: y2 };
2734
+ const topRightCenter = { x: x2 + w2, y: y2 };
2735
+ const bottomRightCenter = { x: x2 + w2, y: y2 + h2 };
2736
+ const bottomLeftCenter = { x: x2, y: y2 + h2 };
2737
+ const topMiddleSize = createControllerElementSizeFromCenter(topCenter, { size: ctrlSize, angle: 0 });
2738
+ const rightMiddleSize = createControllerElementSizeFromCenter(rightCenter, { size: ctrlSize, angle: 0 });
2739
+ const bottomMiddleSize = createControllerElementSizeFromCenter(bottomCenter, { size: ctrlSize, angle: 0 });
2740
+ const leftMiddleSize = createControllerElementSizeFromCenter(leftCenter, { size: ctrlSize, angle: 0 });
2741
+ const topLeftSize = createControllerElementSizeFromCenter(topLeftCenter, { size: ctrlSize, angle: 0 });
2742
+ const topRightSize = createControllerElementSizeFromCenter(topRightCenter, { size: ctrlSize, angle: 0 });
2743
+ const bottomLeftSize = createControllerElementSizeFromCenter(bottomLeftCenter, { size: ctrlSize, angle: 0 });
2744
+ const bottomRightSize = createControllerElementSizeFromCenter(bottomRightCenter, { size: ctrlSize, angle: 0 });
2745
+ const topLeftVertexes = calcElementVertexes(topLeftSize);
2746
+ const topRightVertexes = calcElementVertexes(topRightSize);
2747
+ const bottomLeftVertexes = calcElementVertexes(bottomLeftSize);
2748
+ const bottomRightVertexes = calcElementVertexes(bottomRightSize);
2749
+ const topVertexes = [
2750
+ topLeftVertexes[1],
2751
+ topRightVertexes[0],
2752
+ topRightVertexes[3],
2753
+ topLeftVertexes[2]
2754
+ ];
2755
+ const rightVertexes = [
2756
+ topRightVertexes[3],
2757
+ topRightVertexes[2],
2758
+ bottomRightVertexes[1],
2759
+ bottomRightVertexes[0]
2760
+ ];
2761
+ const bottomVertexes = [
2762
+ bottomLeftVertexes[1],
2763
+ bottomRightVertexes[0],
2764
+ bottomRightVertexes[3],
2765
+ bottomLeftVertexes[2]
2766
+ ];
2767
+ const leftVertexes = [
2768
+ topLeftVertexes[3],
2769
+ topLeftVertexes[2],
2770
+ bottomLeftVertexes[1],
2771
+ bottomLeftVertexes[0]
2772
+ ];
2773
+ const topMiddleVertexes = calcElementVertexes(topMiddleSize);
2774
+ const rightMiddleVertexes = calcElementVertexes(rightMiddleSize);
2775
+ const bottomMiddleVertexes = calcElementVertexes(bottomMiddleSize);
2776
+ const leftMiddleVertexes = calcElementVertexes(leftMiddleSize);
2777
+ const sizeController = {
2778
+ left: {
2779
+ type: "left",
2780
+ vertexes: leftVertexes,
2781
+ center: leftCenter,
2782
+ size: ctrlSize
2783
+ },
2784
+ right: {
2785
+ type: "right",
2786
+ vertexes: rightVertexes,
2787
+ center: rightCenter,
2788
+ size: ctrlSize
2789
+ },
2790
+ top: {
2791
+ type: "top",
2792
+ vertexes: topVertexes,
2793
+ center: topCenter,
2794
+ size: ctrlSize
2795
+ },
2796
+ bottom: {
2797
+ type: "bottom",
2798
+ vertexes: bottomVertexes,
2799
+ center: bottomCenter,
2800
+ size: ctrlSize
2801
+ },
2802
+ topLeft: {
2803
+ type: "top-left",
2804
+ vertexes: topLeftVertexes,
2805
+ center: topLeftCenter,
2806
+ size: ctrlSize
2807
+ },
2808
+ topRight: {
2809
+ type: "top-right",
2810
+ vertexes: topRightVertexes,
2811
+ center: topRightCenter,
2812
+ size: ctrlSize
2813
+ },
2814
+ bottomLeft: {
2815
+ type: "bottom-left",
2816
+ vertexes: bottomLeftVertexes,
2817
+ center: bottomLeftCenter,
2818
+ size: ctrlSize
2819
+ },
2820
+ bottomRight: {
2821
+ type: "bottom-right",
2822
+ vertexes: bottomRightVertexes,
2823
+ center: bottomRightCenter,
2824
+ size: ctrlSize
2825
+ },
2826
+ leftMiddle: {
2827
+ type: "left-middle",
2828
+ vertexes: leftMiddleVertexes,
2829
+ center: leftCenter,
2830
+ size: ctrlSize
2831
+ },
2832
+ rightMiddle: {
2833
+ type: "right-middle",
2834
+ vertexes: rightMiddleVertexes,
2835
+ center: rightCenter,
2836
+ size: ctrlSize
2837
+ },
2838
+ topMiddle: {
2839
+ type: "top-middle",
2840
+ vertexes: topMiddleVertexes,
2841
+ center: topCenter,
2842
+ size: ctrlSize
2843
+ },
2844
+ bottomMiddle: {
2845
+ type: "bottom-middle",
2846
+ vertexes: bottomMiddleVertexes,
2847
+ center: bottomCenter,
2848
+ size: ctrlSize
2207
2849
  }
2208
2850
  };
2209
2851
  return sizeController;
@@ -2290,7 +2932,6 @@ var __privateSet = (obj, member, value, setter) => {
2290
2932
  const arr = [];
2291
2933
  let current;
2292
2934
  let level = -1;
2293
- let inComponent = false;
2294
2935
  html2.replace(elemRegExp, (element, index) => {
2295
2936
  const isOpen = element.charAt(1) !== "/";
2296
2937
  const isComment = element.startsWith("<!--");
@@ -2310,7 +2951,7 @@ var __privateSet = (obj, member, value, setter) => {
2310
2951
  if (isOpen) {
2311
2952
  level++;
2312
2953
  current = parseElement(element);
2313
- if (!current.isVoid && !inComponent && nextChar && nextChar !== "<") {
2954
+ if (!current.isVoid && true && nextChar && nextChar !== "<") {
2314
2955
  const content = html2.slice(start, html2.indexOf("<", start));
2315
2956
  if (content.trim()) {
2316
2957
  current.children.push({
@@ -2364,7 +3005,7 @@ var __privateSet = (obj, member, value, setter) => {
2364
3005
  }
2365
3006
  function attrString(attrs2) {
2366
3007
  const buff = [];
2367
- for (let key in attrs2) {
3008
+ for (const key in attrs2) {
2368
3009
  buff.push(key + '="' + attrs2[key] + '"');
2369
3010
  }
2370
3011
  if (!buff.length) {
@@ -2441,6 +3082,7 @@ var __privateSet = (obj, member, value, setter) => {
2441
3082
  }
2442
3083
  return radian;
2443
3084
  }
3085
+ const defaultText = "Text Element";
2444
3086
  function getDefaultElementDetailConfig() {
2445
3087
  const config = {
2446
3088
  boxSizing: "border-box",
@@ -2457,9 +3099,11 @@ var __privateSet = (obj, member, value, setter) => {
2457
3099
  textAlign: "left",
2458
3100
  verticalAlign: "top",
2459
3101
  fontSize: 16,
2460
- lineHeight: 20,
3102
+ // lineHeight: 20,
2461
3103
  fontFamily: "sans-serif",
2462
3104
  fontWeight: 400,
3105
+ minInlineSize: "auto",
3106
+ wordBreak: "break-all",
2463
3107
  overflow: "hidden"
2464
3108
  };
2465
3109
  return config;
@@ -2470,24 +3114,22 @@ var __privateSet = (obj, member, value, setter) => {
2470
3114
  };
2471
3115
  return detail;
2472
3116
  }
2473
- function getDefaultElementCircleDetail(opts) {
3117
+ function getDefaultElementCircleDetail() {
2474
3118
  const detail = {
2475
3119
  background: "#D9D9D9",
2476
3120
  radius: 0
2477
3121
  };
2478
3122
  return detail;
2479
3123
  }
2480
- function getDefaultElementTextDetail(opts) {
2481
- var _a;
3124
+ function getDefaultElementTextDetail(elementSize) {
2482
3125
  const detailConfig = getDefaultElementDetailConfig();
2483
- const scale = ((_a = opts == null ? void 0 : opts.viewScaleInfo) == null ? void 0 : _a.scale) || 1;
2484
3126
  const detail = {
2485
- text: "Text Element",
3127
+ text: defaultText,
2486
3128
  color: detailConfig.color,
2487
3129
  fontFamily: detailConfig.fontFamily,
2488
3130
  fontWeight: detailConfig.fontWeight,
2489
- lineHeight: detailConfig.fontSize * scale,
2490
- fontSize: detailConfig.fontSize * scale,
3131
+ lineHeight: elementSize.w / defaultText.length,
3132
+ fontSize: elementSize.w / defaultText.length,
2491
3133
  textAlign: "center",
2492
3134
  verticalAlign: "middle"
2493
3135
  };
@@ -2505,7 +3147,7 @@ var __privateSet = (obj, member, value, setter) => {
2505
3147
  };
2506
3148
  return detail;
2507
3149
  }
2508
- function getDefaultElementGroupDetail(opts) {
3150
+ function getDefaultElementGroupDetail() {
2509
3151
  const detail = {
2510
3152
  children: [],
2511
3153
  background: "#D9D9D9",
@@ -2518,8 +3160,10 @@ var __privateSet = (obj, member, value, setter) => {
2518
3160
  const { viewScaleInfo } = opts;
2519
3161
  const { scale } = viewScaleInfo;
2520
3162
  let { borderRadius: borderRadius2 } = viewElem.detail;
3163
+ const { borderDash } = viewElem.detail;
3164
+ const hasBorderDash = Array.isArray(borderDash) && borderDash.length > 0;
2521
3165
  const { boxSizing = defaultElemConfig.boxSizing, borderWidth: borderWidth2 } = viewElem.detail;
2522
- if (typeof borderWidth2 !== "number") {
3166
+ if (Array.isArray(borderWidth2)) {
2523
3167
  borderRadius2 = 0;
2524
3168
  }
2525
3169
  let { x: x2, y: y2, w: w2, h: h2 } = viewElem;
@@ -2534,7 +3178,7 @@ var __privateSet = (obj, member, value, setter) => {
2534
3178
  if (typeof borderWidth2 === "number") {
2535
3179
  bw = (borderWidth2 || 0) * scale;
2536
3180
  }
2537
- if (boxSizing === "border-box") {
3181
+ if (boxSizing === "border-box" && !hasBorderDash) {
2538
3182
  x2 = viewElem.x + bw / 2;
2539
3183
  y2 = viewElem.y + bw / 2;
2540
3184
  w2 = viewElem.w - bw;
@@ -2563,9 +3207,200 @@ var __privateSet = (obj, member, value, setter) => {
2563
3207
  radiusList
2564
3208
  };
2565
3209
  }
3210
+ function flattenObject(obj, parentKey = "", result = {}, opts) {
3211
+ Object.keys(obj).forEach((key) => {
3212
+ var _a;
3213
+ const currentKey = parentKey ? `${parentKey}${isArrayIndex$1(key) ? `[${key}]` : `.${key}`}` : key;
3214
+ if (!((_a = opts == null ? void 0 : opts.ignorePaths) == null ? void 0 : _a.includes(currentKey))) {
3215
+ const value = obj[key];
3216
+ if (isFlattenable(value)) {
3217
+ flattenObject(value, Array.isArray(value) ? currentKey : currentKey, result, opts);
3218
+ } else {
3219
+ result[currentKey] = value;
3220
+ }
3221
+ }
3222
+ });
3223
+ return result;
3224
+ }
3225
+ function isFlattenable(value) {
3226
+ return typeof value === "object" && value !== null && !(value instanceof Date) || Array.isArray(value);
3227
+ }
3228
+ function isArrayIndex$1(key) {
3229
+ return /^\d+$/.test(key) && !isNaN(Number(key));
3230
+ }
3231
+ function flatObject(obj, opts) {
3232
+ if (typeof obj !== "object" || obj === null) {
3233
+ return { "": obj };
3234
+ }
3235
+ return flattenObject(obj, "", {}, opts);
3236
+ }
3237
+ function toFlattenElement(elem) {
3238
+ return flatObject(elem, { ignorePaths: ["detail.children"] });
3239
+ }
3240
+ function toFlattenLayout(layout) {
3241
+ return flatObject(layout);
3242
+ }
3243
+ function toFlattenGlobal(global) {
3244
+ return flatObject(global);
3245
+ }
3246
+ function toPath(path) {
3247
+ if (Array.isArray(path)) return [...path];
3248
+ return path.split(/\.|\[|\]/).filter((key) => key !== "");
3249
+ }
3250
+ function get(obj, path, defaultValue) {
3251
+ if (!path) {
3252
+ return void 0;
3253
+ }
3254
+ const pathArray = toPath(path);
3255
+ let current = obj;
3256
+ for (const key of pathArray) {
3257
+ if (current === null || current === void 0) {
3258
+ return defaultValue;
3259
+ }
3260
+ current = current[key];
3261
+ }
3262
+ return current !== void 0 ? current : defaultValue;
3263
+ }
3264
+ function set(obj, path, value) {
3265
+ const pathArray = toPath(path);
3266
+ if (pathArray.length === 0) {
3267
+ return obj;
3268
+ }
3269
+ let current = obj;
3270
+ if (current) {
3271
+ for (let i = 0; i < pathArray.length; i++) {
3272
+ const key = pathArray[i];
3273
+ if (i === pathArray.length - 1) {
3274
+ current[key] = value;
3275
+ break;
3276
+ }
3277
+ 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)) {
3278
+ const nextKey = pathArray[i + 1];
3279
+ const isNextNumeric = /^\d+$/.test(nextKey);
3280
+ current[key] = isNextNumeric ? [] : {};
3281
+ }
3282
+ current = current == null ? void 0 : current[key];
3283
+ }
3284
+ }
3285
+ return obj;
3286
+ }
3287
+ function del(obj, path) {
3288
+ const pathArray = toPath(path);
3289
+ if (pathArray.length === 0) {
3290
+ return obj;
3291
+ }
3292
+ let current = obj;
3293
+ if (current) {
3294
+ for (let i = 0; i < pathArray.length; i++) {
3295
+ const key = pathArray[i];
3296
+ if (i === pathArray.length - 1) {
3297
+ delete current[key];
3298
+ break;
3299
+ }
3300
+ 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)) {
3301
+ const nextKey = pathArray[i + 1];
3302
+ const isNextNumeric = /^\d+$/.test(nextKey);
3303
+ current[key] = isNextNumeric ? [] : {};
3304
+ }
3305
+ current = current == null ? void 0 : current[key];
3306
+ }
3307
+ }
3308
+ return obj;
3309
+ }
3310
+ const doNum = (n) => {
3311
+ return formatNumber(n, { decimalPlaces: 4 });
3312
+ };
3313
+ function resizeElementBaseDetail(elem, opts) {
3314
+ const { detail } = elem;
3315
+ const { xRatio, yRatio, maxRatio } = opts;
3316
+ const middleRatio = (xRatio + yRatio) / 2;
3317
+ const { borderWidth: borderWidth2, borderRadius: borderRadius2, borderDash, shadowOffsetX, shadowOffsetY, shadowBlur } = detail;
3318
+ if (typeof borderWidth2 === "number") {
3319
+ detail.borderWidth = doNum(borderWidth2 * middleRatio);
3320
+ } else if (Array.isArray(detail.borderWidth)) {
3321
+ const bw = borderWidth2;
3322
+ detail.borderWidth = [doNum(bw[0] * yRatio), doNum(bw[1] * xRatio), doNum(bw[2] * yRatio), doNum(bw[3] * xRatio)];
3323
+ }
3324
+ if (typeof borderRadius2 === "number") {
3325
+ detail.borderRadius = doNum(borderRadius2 * middleRatio);
3326
+ } else if (Array.isArray(detail.borderRadius)) {
3327
+ const br = borderRadius2;
3328
+ detail.borderRadius = [br[0] * xRatio, br[1] * xRatio, br[2] * yRatio, br[3] * yRatio];
3329
+ }
3330
+ if (Array.isArray(borderDash)) {
3331
+ borderDash.forEach((dash, i) => {
3332
+ detail.borderDash[i] = doNum(dash * maxRatio);
3333
+ });
3334
+ }
3335
+ if (typeof shadowOffsetX === "number") {
3336
+ detail.shadowOffsetX = doNum(shadowOffsetX * maxRatio);
3337
+ }
3338
+ if (typeof shadowOffsetY === "number") {
3339
+ detail.shadowOffsetX = doNum(shadowOffsetY * maxRatio);
3340
+ }
3341
+ if (typeof shadowBlur === "number") {
3342
+ detail.shadowOffsetX = doNum(shadowBlur * maxRatio);
3343
+ }
3344
+ }
3345
+ function resizeElementBase(elem, opts) {
3346
+ const { xRatio, yRatio } = opts;
3347
+ const { x: x2, y: y2, w: w2, h: h2 } = elem;
3348
+ elem.x = doNum(x2 * xRatio);
3349
+ elem.y = doNum(y2 * yRatio);
3350
+ elem.w = doNum(w2 * xRatio);
3351
+ elem.h = doNum(h2 * yRatio);
3352
+ resizeElementBaseDetail(elem, opts);
3353
+ }
3354
+ function resizeTextElementDetail(elem, opts) {
3355
+ const { minRatio, maxRatio } = opts;
3356
+ const { fontSize: fontSize2, lineHeight: lineHeight2 } = elem.detail;
3357
+ const ratio = (minRatio + maxRatio) / 2;
3358
+ if (fontSize2 && fontSize2 > 0) {
3359
+ elem.detail.fontSize = doNum(fontSize2 * ratio);
3360
+ }
3361
+ if (lineHeight2 && lineHeight2 > 0) {
3362
+ elem.detail.lineHeight = doNum(lineHeight2 * ratio);
3363
+ }
3364
+ }
3365
+ function resizeElement(elem, opts) {
3366
+ const { type } = elem;
3367
+ resizeElementBase(elem, opts);
3368
+ if (type === "circle") ;
3369
+ else if (type === "text") {
3370
+ resizeTextElementDetail(elem, opts);
3371
+ } else if (type === "image") ;
3372
+ else if (type === "svg") ;
3373
+ else if (type === "html") ;
3374
+ else if (type === "path") ;
3375
+ else if (type === "group" && Array.isArray(elem.detail.children)) {
3376
+ elem.detail.children.forEach((child) => {
3377
+ resizeElement(child, opts);
3378
+ });
3379
+ }
3380
+ }
3381
+ function deepResizeGroupElement(elem, size) {
3382
+ const resizeW = size.w && size.w > 0 ? size.w : elem.w;
3383
+ const resizeH = size.h && size.h > 0 ? size.h : elem.h;
3384
+ const xRatio = resizeW / elem.w;
3385
+ const yRatio = resizeH / elem.h;
3386
+ if (xRatio === yRatio && xRatio === 1) {
3387
+ return elem;
3388
+ }
3389
+ const minRatio = Math.min(xRatio, yRatio);
3390
+ const maxRatio = Math.max(xRatio, yRatio);
3391
+ elem.w = resizeW;
3392
+ elem.h = resizeH;
3393
+ const opts = { xRatio, yRatio, minRatio, maxRatio };
3394
+ if (elem.type === "group" && Array.isArray(elem.detail.children)) {
3395
+ elem.detail.children.forEach((child) => {
3396
+ resizeElement(child, opts);
3397
+ });
3398
+ }
3399
+ resizeElementBaseDetail(elem, opts);
3400
+ return elem;
3401
+ }
2566
3402
  const defaultViewWidth = 200;
2567
3403
  const defaultViewHeight = 200;
2568
- const defaultDetail = getDefaultElementDetailConfig();
2569
3404
  function createElementSize(type, opts) {
2570
3405
  let x2 = 0;
2571
3406
  let y2 = 0;
@@ -2575,26 +3410,23 @@ var __privateSet = (obj, member, value, setter) => {
2575
3410
  const { viewScaleInfo, viewSizeInfo } = opts;
2576
3411
  const { scale, offsetLeft, offsetTop } = viewScaleInfo;
2577
3412
  const { width, height } = viewSizeInfo;
2578
- if (type === "text") {
2579
- const textDetail = getDefaultElementTextDetail();
2580
- w2 = defaultDetail.fontSize * scale * textDetail.text.length;
2581
- h2 = defaultDetail.fontSize * scale * 2;
3413
+ const limitViewWidth = width / 4;
3414
+ const limitViewHeight = height / 4;
3415
+ if (defaultViewWidth >= limitViewWidth) {
3416
+ w2 = limitViewWidth / scale;
2582
3417
  } else {
2583
- const limitViewWidth = width / 4;
2584
- const limitViewHeight = height / 4;
2585
- if (defaultViewWidth >= limitViewWidth) {
2586
- w2 = limitViewWidth / scale;
2587
- } else {
2588
- w2 = defaultViewWidth / scale;
2589
- }
2590
- if (defaultViewHeight >= limitViewHeight) {
2591
- h2 = limitViewHeight / scale;
2592
- } else {
2593
- h2 = defaultViewHeight / scale;
2594
- }
2595
- if (["circle", "svg", "image"].includes(type)) {
2596
- w2 = h2 = Math.max(w2, h2);
2597
- }
3418
+ w2 = defaultViewWidth / scale;
3419
+ }
3420
+ if (defaultViewHeight >= limitViewHeight) {
3421
+ h2 = limitViewHeight / scale;
3422
+ } else {
3423
+ h2 = defaultViewHeight / scale;
3424
+ }
3425
+ if (["circle", "svg", "image"].includes(type)) {
3426
+ w2 = h2 = Math.max(w2, h2);
3427
+ } else if (type === "text") {
3428
+ const fontSize2 = w2 / defaultText.length;
3429
+ h2 = fontSize2 * 2;
2598
3430
  }
2599
3431
  x2 = (0 - offsetLeft + width / 2 - w2 * scale / 2) / scale;
2600
3432
  y2 = (0 - offsetTop + height / 2 - h2 * scale / 2) / scale;
@@ -2608,16 +3440,14 @@ var __privateSet = (obj, member, value, setter) => {
2608
3440
  return elemSize;
2609
3441
  }
2610
3442
  function createElement(type, baseElem, opts) {
2611
- const elemSize = createElementSize(type, opts);
3443
+ const elementSize = createElementSize(type, opts);
2612
3444
  let detail = {};
2613
3445
  if (type === "rect") {
2614
3446
  detail = getDefaultElementRectDetail();
2615
3447
  } else if (type === "circle") {
2616
- detail = getDefaultElementCircleDetail({
2617
- radius: elemSize.w
2618
- });
3448
+ detail = getDefaultElementCircleDetail();
2619
3449
  } else if (type === "text") {
2620
- detail = getDefaultElementTextDetail(opts);
3450
+ detail = getDefaultElementTextDetail(elementSize);
2621
3451
  } else if (type === "svg") {
2622
3452
  detail = getDefaultElementSVGDetail();
2623
3453
  } else if (type === "image") {
@@ -2626,9 +3456,9 @@ var __privateSet = (obj, member, value, setter) => {
2626
3456
  detail = getDefaultElementGroupDetail();
2627
3457
  }
2628
3458
  const elem = {
2629
- ...elemSize,
2630
- ...baseElem,
2631
3459
  uuid: createUUID(),
3460
+ ...elementSize,
3461
+ ...baseElem,
2632
3462
  type,
2633
3463
  detail: {
2634
3464
  ...detail,
@@ -2690,15 +3520,16 @@ var __privateSet = (obj, member, value, setter) => {
2690
3520
  return deleteElementInListByPosition(position, list);
2691
3521
  }
2692
3522
  function moveElementPosition(elements, opts) {
2693
- const { from, to } = opts;
3523
+ const from = [...opts.from];
3524
+ const to = [...opts.to];
2694
3525
  if (from.length === 0 || to.length === 0) {
2695
- return elements;
3526
+ return { elements, from, to };
2696
3527
  }
2697
3528
  if (from.length <= to.length) {
2698
3529
  for (let i = 0; i < from.length; i++) {
2699
3530
  if (to[i] === from[i]) {
2700
3531
  if (i === from.length - 1) {
2701
- return elements;
3532
+ return { elements, from, to };
2702
3533
  }
2703
3534
  continue;
2704
3535
  }
@@ -2708,18 +3539,59 @@ var __privateSet = (obj, member, value, setter) => {
2708
3539
  if (target) {
2709
3540
  const insterResult = insertElementToListByPosition(target, to, elements);
2710
3541
  if (!insterResult) {
2711
- return elements;
3542
+ return { elements, from, to };
2712
3543
  }
2713
3544
  let trimDeletePosIndex = -1;
2714
- for (let i = 0; i < from.length; i++) {
2715
- if (!(to[i] >= 0)) {
2716
- break;
3545
+ let isEffectToIndex = false;
3546
+ if (from.length >= 1 && to.length >= 1) {
3547
+ if (from.length <= to.length) {
3548
+ if (from.length === 1) {
3549
+ if (from[0] < to[0]) {
3550
+ isEffectToIndex = true;
3551
+ }
3552
+ } else {
3553
+ for (let i = 0; i < from.length; i++) {
3554
+ if (from[i] === to[i]) {
3555
+ if (from.length === from.length - 1) {
3556
+ isEffectToIndex = true;
3557
+ break;
3558
+ }
3559
+ } else {
3560
+ break;
3561
+ }
3562
+ }
3563
+ }
2717
3564
  }
2718
- if (to[i] === from[i]) {
2719
- continue;
3565
+ if (from.length >= to.length) {
3566
+ if (to.length === 1) {
3567
+ if (to[0] < from[0]) {
3568
+ isEffectToIndex = true;
3569
+ }
3570
+ } else {
3571
+ for (let i = 0; i < to.length; i++) {
3572
+ if (i === to.length - 1 && to[i] < from[i]) {
3573
+ isEffectToIndex = true;
3574
+ }
3575
+ if (from[i] === to[i]) {
3576
+ continue;
3577
+ } else {
3578
+ break;
3579
+ }
3580
+ }
3581
+ }
2720
3582
  }
2721
- if (to[i] < from[i] && i == to.length - 1) {
2722
- trimDeletePosIndex = i;
3583
+ }
3584
+ if (isEffectToIndex === true) {
3585
+ for (let i = 0; i < from.length; i++) {
3586
+ if (!(to[i] >= 0)) {
3587
+ break;
3588
+ }
3589
+ if (to[i] === from[i]) {
3590
+ continue;
3591
+ }
3592
+ if (to[i] < from[i] && i == to.length - 1) {
3593
+ trimDeletePosIndex = i;
3594
+ }
2723
3595
  }
2724
3596
  }
2725
3597
  if (trimDeletePosIndex >= 0) {
@@ -2729,53 +3601,793 @@ var __privateSet = (obj, member, value, setter) => {
2729
3601
  }
2730
3602
  deleteElementInListByPosition(from, elements);
2731
3603
  }
2732
- return elements;
2733
- }
2734
- function mergeElement(originElem, updateContent) {
2735
- var _a;
2736
- const commonKeys = Object.keys(updateContent);
2737
- for (let i = 0; i < commonKeys.length; i++) {
2738
- const commonKey = commonKeys[i];
2739
- if (["x", "y", "w", "h", "angle", "name"].includes(commonKey)) {
2740
- originElem[commonKey] = updateContent[commonKey];
2741
- } else if (["detail", "operations"].includes(commonKey)) {
2742
- if (istype.json(updateContent[commonKey])) {
2743
- if (!(originElem == null ? void 0 : originElem.hasOwnProperty(commonKey))) {
2744
- originElem[commonKey] = {};
2745
- }
2746
- if (istype.json(originElem[commonKey])) {
2747
- originElem[commonKey] = { ...originElem[commonKey], ...updateContent[commonKey] };
2748
- }
2749
- } else if (istype.array(updateContent[commonKey])) {
2750
- if (!(originElem == null ? void 0 : originElem.hasOwnProperty(commonKey))) {
2751
- originElem[commonKey] = [];
2752
- }
2753
- if (istype.array(originElem[commonKey])) {
2754
- (_a = updateContent == null ? void 0 : updateContent[commonKey]) == null ? void 0 : _a.forEach((item, i2) => {
2755
- originElem[commonKey][i2] = item;
2756
- });
2757
- originElem[commonKey] = [...originElem[commonKey], ...updateContent[commonKey]];
2758
- }
3604
+ return { elements, from, to };
3605
+ }
3606
+ function mergeElement(originElem, updateContent, opts) {
3607
+ const updatedFlatten = toFlattenElement(updateContent);
3608
+ const ignoreKeys = ["uuid", "type"];
3609
+ const updatedKeys = Object.keys(updatedFlatten);
3610
+ updatedKeys.forEach((key) => {
3611
+ if (!ignoreKeys.includes(key)) {
3612
+ const value = updatedFlatten[key];
3613
+ del(originElem, key);
3614
+ if (value !== void 0) {
3615
+ set(originElem, key, value);
2759
3616
  }
2760
3617
  }
3618
+ });
3619
+ if ((opts == null ? void 0 : opts.strict) === true) {
3620
+ const originFlatten = toFlattenElement(originElem);
3621
+ const originKeys = Object.keys(originFlatten);
3622
+ originKeys.forEach((key) => {
3623
+ if (!ignoreKeys.includes(key)) {
3624
+ if (!updatedKeys.includes(key)) {
3625
+ del(originElem, key);
3626
+ }
3627
+ }
3628
+ });
2761
3629
  }
2762
3630
  return originElem;
2763
3631
  }
2764
3632
  function updateElementInList(uuid, updateContent, elements) {
2765
- var _a;
3633
+ var _a, _b;
2766
3634
  let targetElement = null;
2767
3635
  for (let i = 0; i < elements.length; i++) {
2768
3636
  const elem = elements[i];
2769
3637
  if (elem.uuid === uuid) {
3638
+ if (elem.type === "group" && ((_a = elem.operations) == null ? void 0 : _a.deepResize) === true) {
3639
+ if (updateContent.w && updateContent.w > 0 || updateContent.h && updateContent.h > 0) {
3640
+ deepResizeGroupElement(elem, {
3641
+ w: updateContent.w,
3642
+ h: updateContent.h
3643
+ });
3644
+ }
3645
+ }
2770
3646
  mergeElement(elem, updateContent);
2771
3647
  targetElement = elem;
2772
3648
  break;
2773
3649
  } else if (elem.type === "group") {
2774
- targetElement = updateElementInList(uuid, updateContent, ((_a = elem == null ? void 0 : elem.detail) == null ? void 0 : _a.children) || []);
3650
+ targetElement = updateElementInList(uuid, updateContent, ((_b = elem == null ? void 0 : elem.detail) == null ? void 0 : _b.children) || []);
2775
3651
  }
2776
3652
  }
2777
3653
  return targetElement;
2778
3654
  }
3655
+ function updateElementInListByPosition(position, updateContent, elements, opts) {
3656
+ var _a;
3657
+ const elem = findElementFromListByPosition(position, elements);
3658
+ if (elem) {
3659
+ if (elem.type === "group" && ((_a = elem.operations) == null ? void 0 : _a.deepResize) === true) {
3660
+ if (updateContent.w && updateContent.w > 0 || updateContent.h && updateContent.h > 0) {
3661
+ deepResizeGroupElement(elem, {
3662
+ w: updateContent.w,
3663
+ h: updateContent.h
3664
+ });
3665
+ }
3666
+ }
3667
+ mergeElement(elem, updateContent, opts);
3668
+ }
3669
+ return elem;
3670
+ }
3671
+ function calcViewCenterContent(data, opts) {
3672
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
3673
+ let offsetX = 0;
3674
+ let offsetY = 0;
3675
+ let scale = 1;
3676
+ let contentX = ((_b = (_a = data == null ? void 0 : data.elements) == null ? void 0 : _a[0]) == null ? void 0 : _b.x) || 0;
3677
+ let contentY = ((_d = (_c = data == null ? void 0 : data.elements) == null ? void 0 : _c[0]) == null ? void 0 : _d.y) || 0;
3678
+ let contentW = ((_f = (_e = data == null ? void 0 : data.elements) == null ? void 0 : _e[0]) == null ? void 0 : _f.w) || 0;
3679
+ let contentH = ((_h = (_g = data == null ? void 0 : data.elements) == null ? void 0 : _g[0]) == null ? void 0 : _h.h) || 0;
3680
+ const { width, height } = opts.viewSizeInfo;
3681
+ if (data.layout && ((_j = (_i = data.layout) == null ? void 0 : _i.detail) == null ? void 0 : _j.overflow) === "hidden") {
3682
+ contentX = 0;
3683
+ contentY = 0;
3684
+ contentW = data.layout.w || 0;
3685
+ contentH = data.layout.h || 0;
3686
+ } else {
3687
+ data.elements.forEach((elem) => {
3688
+ const elemSize = {
3689
+ x: elem.x,
3690
+ y: elem.y,
3691
+ w: elem.w,
3692
+ h: elem.h,
3693
+ angle: elem.angle
3694
+ };
3695
+ if (elemSize.angle && (elemSize.angle > 0 || elemSize.angle < 0)) {
3696
+ const ves = rotateElementVertexes(elemSize);
3697
+ if (ves.length === 4) {
3698
+ const xList = [ves[0].x, ves[1].x, ves[2].x, ves[3].x];
3699
+ const yList = [ves[0].y, ves[1].y, ves[2].y, ves[3].y];
3700
+ elemSize.x = Math.min(...xList);
3701
+ elemSize.y = Math.min(...yList);
3702
+ elemSize.w = Math.abs(Math.max(...xList) - Math.min(...xList));
3703
+ elemSize.h = Math.abs(Math.max(...yList) - Math.min(...yList));
3704
+ }
3705
+ }
3706
+ const areaStartX = Math.min(elemSize.x, contentX);
3707
+ const areaStartY = Math.min(elemSize.y, contentY);
3708
+ const areaEndX = Math.max(elemSize.x + elemSize.w, contentX + contentW);
3709
+ const areaEndY = Math.max(elemSize.y + elemSize.h, contentY + contentH);
3710
+ contentX = areaStartX;
3711
+ contentY = areaStartY;
3712
+ contentW = Math.abs(areaEndX - areaStartX);
3713
+ contentH = Math.abs(areaEndY - areaStartY);
3714
+ });
3715
+ }
3716
+ if (data.layout) {
3717
+ const { x: x2, y: y2, w: w2, h: h2 } = data.layout;
3718
+ if (is.x(x2) && is.y(y2) && is.w(w2) && is.h(h2)) {
3719
+ contentX = Math.min(contentX, x2);
3720
+ contentY = Math.min(contentY, y2);
3721
+ contentW = Math.max(contentW, w2);
3722
+ contentH = Math.max(contentH, h2);
3723
+ }
3724
+ }
3725
+ if (contentW > 0 && contentH > 0) {
3726
+ const scaleW = formatNumber(width / contentW, { decimalPlaces: 4 });
3727
+ const scaleH = formatNumber(height / contentH, { decimalPlaces: 4 });
3728
+ scale = Math.min(scaleW, scaleH, 1);
3729
+ offsetX = (contentW * scale - width) / 2 / scale + contentX;
3730
+ offsetY = (contentH * scale - height) / 2 / scale + contentY;
3731
+ }
3732
+ const result = {
3733
+ offsetX: formatNumber(offsetX, { decimalPlaces: 0 }),
3734
+ offsetY: formatNumber(offsetY, { decimalPlaces: 0 }),
3735
+ scale
3736
+ };
3737
+ return result;
3738
+ }
3739
+ function calcViewCenter(opts) {
3740
+ let x2 = 0;
3741
+ let y2 = 0;
3742
+ if (opts) {
3743
+ const { viewScaleInfo, viewSizeInfo } = opts;
3744
+ const { offsetLeft, offsetTop, scale } = viewScaleInfo;
3745
+ const { width, height } = viewSizeInfo;
3746
+ x2 = 0 - offsetLeft + width / scale / 2;
3747
+ y2 = 0 - offsetTop + height / scale / 2;
3748
+ }
3749
+ const p = {
3750
+ x: x2,
3751
+ y: y2
3752
+ };
3753
+ return p;
3754
+ }
3755
+ const baseFontFamilyList = ["-apple-system", '"system-ui"', ' "Segoe UI"', " Roboto", '"Helvetica Neue"', "Arial", '"Noto Sans"', " sans-serif"];
3756
+ function enhanceFontFamliy(fontFamily2) {
3757
+ return [fontFamily2, ...baseFontFamilyList].join(", ");
3758
+ }
3759
+ function flatElementSize(elemSize, opts) {
3760
+ const { groupQueue } = opts;
3761
+ let { x: x2, y: y2 } = elemSize;
3762
+ const { w: w2, h: h2, angle: angle2 = 0 } = elemSize;
3763
+ let totalAngle = 0;
3764
+ groupQueue.forEach((group) => {
3765
+ x2 += group.x;
3766
+ y2 += group.y;
3767
+ totalAngle += group.angle || 0;
3768
+ });
3769
+ totalAngle = limitAngle(totalAngle);
3770
+ if (totalAngle === 0) {
3771
+ return {
3772
+ x: x2,
3773
+ y: y2,
3774
+ w: w2,
3775
+ h: h2,
3776
+ angle: angle2
3777
+ };
3778
+ }
3779
+ totalAngle += elemSize.angle || 0;
3780
+ totalAngle = limitAngle(totalAngle);
3781
+ const vertexes = calcElementVertexesInGroup(elemSize, { groupQueue });
3782
+ const center = calcElementCenterFromVertexes(vertexes);
3783
+ const start = rotatePoint(center, vertexes[0], parseAngleToRadian(0 - totalAngle));
3784
+ x2 = start.x;
3785
+ y2 = start.y;
3786
+ return {
3787
+ x: x2,
3788
+ y: y2,
3789
+ w: w2,
3790
+ h: h2,
3791
+ angle: totalAngle
3792
+ };
3793
+ }
3794
+ function isValidElement(elem) {
3795
+ var _a;
3796
+ if (["rect", "circle"].includes(elem.type)) {
3797
+ const detail = elem.detail;
3798
+ if (!detail.background && !detail.borderWidth) {
3799
+ return false;
3800
+ }
3801
+ if (detail.background === "transparent" && !detail.borderWidth) {
3802
+ return false;
3803
+ }
3804
+ }
3805
+ if (["group"].includes(elem.type)) {
3806
+ const detail = elem.detail || {};
3807
+ const { children } = detail;
3808
+ if (!(children.length > 0) && !detail.background && !detail.borderWidth) {
3809
+ return false;
3810
+ }
3811
+ if (!(children.length > 0) && detail.background === "transparent" && !detail.borderWidth) {
3812
+ return false;
3813
+ }
3814
+ }
3815
+ if (elem.type === "text") {
3816
+ if (!elem.detail.text) {
3817
+ return false;
3818
+ }
3819
+ }
3820
+ if (elem.type === "image") {
3821
+ if (!elem.detail.src) {
3822
+ return false;
3823
+ }
3824
+ }
3825
+ if (elem.type === "html") {
3826
+ if (!elem.detail.html) {
3827
+ return false;
3828
+ }
3829
+ }
3830
+ if (elem.type === "svg") {
3831
+ if (!elem.detail.svg) {
3832
+ return false;
3833
+ }
3834
+ }
3835
+ if (elem.type === "path") {
3836
+ const detail = elem.detail;
3837
+ if (!(((_a = detail == null ? void 0 : detail.commands) == null ? void 0 : _a.length) > 0)) {
3838
+ return false;
3839
+ }
3840
+ }
3841
+ return true;
3842
+ }
3843
+ function flatElementList(list) {
3844
+ const elemeList = [];
3845
+ const currentGroupQueue = [];
3846
+ const _resetElemSize = (elem) => {
3847
+ if (!isValidElement(elem)) {
3848
+ return;
3849
+ }
3850
+ const newSize = flatElementSize(elem, { groupQueue: currentGroupQueue });
3851
+ const resizeElem = {
3852
+ ...elem,
3853
+ ...newSize
3854
+ };
3855
+ elemeList.push(resizeElem);
3856
+ };
3857
+ const _walk = (elem) => {
3858
+ var _a;
3859
+ if (((_a = elem == null ? void 0 : elem.operations) == null ? void 0 : _a.invisible) === true) {
3860
+ return;
3861
+ }
3862
+ if (elem.type === "group") {
3863
+ const { detail } = elem;
3864
+ const { children, ...restDetail } = detail;
3865
+ _resetElemSize({ ...elem, ...{ detail: { ...restDetail, children: [] } } });
3866
+ currentGroupQueue.push(elem);
3867
+ children.forEach((child) => {
3868
+ _walk(child);
3869
+ });
3870
+ currentGroupQueue.pop();
3871
+ } else {
3872
+ _resetElemSize(elem);
3873
+ }
3874
+ };
3875
+ for (let i = 0; i < list.length; i++) {
3876
+ const elem = list[i];
3877
+ _walk(elem);
3878
+ }
3879
+ return elemeList;
3880
+ }
3881
+ function groupElementsByPosition(list, positions) {
3882
+ if (positions.length > 1) {
3883
+ let isValidPositions = true;
3884
+ let lastIndexs = [];
3885
+ for (let i = 1; i < positions.length; i++) {
3886
+ const prevPosition = positions[i - 1];
3887
+ const position = positions[i];
3888
+ if (!(prevPosition.length > 0 && position.length > 0)) {
3889
+ isValidPositions = false;
3890
+ break;
3891
+ }
3892
+ if (prevPosition.length !== position.length) {
3893
+ isValidPositions = false;
3894
+ break;
3895
+ }
3896
+ const temp1 = [...prevPosition];
3897
+ const temp2 = [...position];
3898
+ const lastIndex1 = temp1.pop();
3899
+ const lastIndex2 = temp2.pop();
3900
+ if (i === 1 && typeof lastIndex1 === "number" && lastIndex1 >= 0) {
3901
+ lastIndexs.push(lastIndex1);
3902
+ }
3903
+ if (typeof lastIndex2 === "number" && lastIndex2 >= 0) {
3904
+ lastIndexs.push(lastIndex2);
3905
+ }
3906
+ }
3907
+ if (isValidPositions !== true) {
3908
+ console.error("[idraw]: The grouped elements are not siblings!");
3909
+ return list;
3910
+ }
3911
+ lastIndexs.sort((a, b) => a - b);
3912
+ const groupParentPosition = [...positions[0]].splice(0, positions[0].length - 1);
3913
+ const groupChildren = [];
3914
+ const groupPosition = [...groupParentPosition, lastIndexs[0]];
3915
+ for (let i = 0; i < lastIndexs.length; i++) {
3916
+ const position = [...groupParentPosition, lastIndexs[i]];
3917
+ const elem = findElementFromListByPosition(position, list);
3918
+ if (elem) {
3919
+ groupChildren.push(elem);
3920
+ }
3921
+ }
3922
+ const groupSize = calcElementListSize(groupChildren);
3923
+ for (let i = 0; i < groupChildren.length; i++) {
3924
+ const elem = groupChildren[i];
3925
+ if (elem) {
3926
+ elem.x -= groupSize.x;
3927
+ elem.y -= groupSize.y;
3928
+ }
3929
+ }
3930
+ for (let i = lastIndexs.length - 1; i >= 0; i--) {
3931
+ const position = [...groupParentPosition, lastIndexs[i]];
3932
+ deleteElementInListByPosition(position, list);
3933
+ }
3934
+ const group = {
3935
+ name: "Group",
3936
+ uuid: createUUID(),
3937
+ type: "group",
3938
+ ...groupSize,
3939
+ detail: {
3940
+ children: groupChildren
3941
+ }
3942
+ };
3943
+ insertElementToListByPosition(group, groupPosition, list);
3944
+ }
3945
+ return list;
3946
+ }
3947
+ function ungroupElementsByPosition(list, position) {
3948
+ var _a;
3949
+ const elem = findElementFromListByPosition(position, list);
3950
+ if (!(elem && (elem == null ? void 0 : elem.type) === "group" && Array.isArray((_a = elem == null ? void 0 : elem.detail) == null ? void 0 : _a.children))) {
3951
+ console.error("[idraw]: The ungrouped element is not a group element!");
3952
+ }
3953
+ const groupParentPosition = [...position].splice(0, position.length - 1);
3954
+ const groupLastIndex = position[position.length - 1];
3955
+ const { x: x2, y: y2 } = elem;
3956
+ deleteElementInListByPosition(position, list);
3957
+ elem.detail.children.forEach((child, i) => {
3958
+ child.x += x2;
3959
+ child.y += y2;
3960
+ const elemPosition = [...groupParentPosition, groupLastIndex + i];
3961
+ insertElementToListByPosition(child, elemPosition, list);
3962
+ });
3963
+ return list;
3964
+ }
3965
+ function calcPointMoveElementInGroup(start, end, groupQueue) {
3966
+ let moveX = end.x - start.x;
3967
+ let moveY = end.y - start.y;
3968
+ const pointGroupQueue = [];
3969
+ groupQueue.forEach((group) => {
3970
+ const { x: x2, y: y2, w: w2, h: h2, angle: angle2 = 0 } = group;
3971
+ pointGroupQueue.push({
3972
+ x: x2,
3973
+ y: y2,
3974
+ w: w2,
3975
+ h: h2,
3976
+ angle: 0 - angle2
3977
+ });
3978
+ });
3979
+ if ((groupQueue == null ? void 0 : groupQueue.length) > 0) {
3980
+ const startInGroup = rotatePointInGroup(start, pointGroupQueue);
3981
+ const endInGroup = rotatePointInGroup(end, pointGroupQueue);
3982
+ moveX = endInGroup.x - startInGroup.x;
3983
+ moveY = endInGroup.y - startInGroup.y;
3984
+ }
3985
+ return {
3986
+ moveX,
3987
+ moveY
3988
+ };
3989
+ }
3990
+ function mergeLayout(originLayout, updateContent, opts) {
3991
+ const updatedFlatten = toFlattenLayout(updateContent);
3992
+ const ignoreKeys = [];
3993
+ const updatedKeys = Object.keys(updatedFlatten);
3994
+ updatedKeys.forEach((key) => {
3995
+ if (!ignoreKeys.includes(key)) {
3996
+ const value = updatedFlatten[key];
3997
+ del(originLayout, key);
3998
+ if (value !== void 0) {
3999
+ set(originLayout, key, value);
4000
+ }
4001
+ }
4002
+ });
4003
+ if ((opts == null ? void 0 : opts.strict) === true) {
4004
+ const originFlatten = toFlattenLayout(originLayout);
4005
+ const originKeys = Object.keys(originFlatten);
4006
+ originKeys.forEach((key) => {
4007
+ if (!ignoreKeys.includes(key)) {
4008
+ if (!updatedKeys.includes(key)) {
4009
+ del(originLayout, key);
4010
+ }
4011
+ }
4012
+ });
4013
+ }
4014
+ return originLayout;
4015
+ }
4016
+ function mergeGlobal(originGlobal, updateContent, opts) {
4017
+ const updatedFlatten = toFlattenGlobal(updateContent);
4018
+ const ignoreKeys = [];
4019
+ const updatedKeys = Object.keys(updatedFlatten);
4020
+ updatedKeys.forEach((key) => {
4021
+ if (!ignoreKeys.includes(key)) {
4022
+ const value = updatedFlatten[key];
4023
+ del(originGlobal, key);
4024
+ if (value !== void 0) {
4025
+ set(originGlobal, key, value);
4026
+ }
4027
+ }
4028
+ });
4029
+ if ((opts == null ? void 0 : opts.strict) === true) {
4030
+ const originFlatten = toFlattenGlobal(originGlobal);
4031
+ const originKeys = Object.keys(originFlatten);
4032
+ originKeys.forEach((key) => {
4033
+ if (!ignoreKeys.includes(key)) {
4034
+ if (!updatedKeys.includes(key)) {
4035
+ del(originGlobal, key);
4036
+ }
4037
+ }
4038
+ });
4039
+ }
4040
+ return originGlobal;
4041
+ }
4042
+ function calcResultMovePosition(opts) {
4043
+ const from = [...opts.from];
4044
+ const to = [...opts.to];
4045
+ if (from.length === 0 || to.length === 0) {
4046
+ return null;
4047
+ }
4048
+ if (from.length <= to.length) {
4049
+ for (let i = 0; i < from.length; i++) {
4050
+ if (to[i] === from[i]) {
4051
+ if (i === from.length - 1) {
4052
+ return null;
4053
+ }
4054
+ continue;
4055
+ }
4056
+ }
4057
+ }
4058
+ let moveDirection = null;
4059
+ if (from.length >= 1 && to.length >= 1) {
4060
+ if (from.length <= to.length) {
4061
+ if (from.length === 1) {
4062
+ if (from[0] < to[0]) {
4063
+ moveDirection = "up-down";
4064
+ }
4065
+ } else {
4066
+ for (let i = 0; i < from.length; i++) {
4067
+ if (from[i] === to[i]) {
4068
+ if (from.length === from.length - 1) {
4069
+ moveDirection = "up-down";
4070
+ break;
4071
+ }
4072
+ } else {
4073
+ break;
4074
+ }
4075
+ }
4076
+ }
4077
+ }
4078
+ if (from.length >= to.length) {
4079
+ if (to.length === 1) {
4080
+ if (to[0] < from[0]) {
4081
+ moveDirection = "down-up";
4082
+ }
4083
+ } else {
4084
+ for (let i = 0; i < to.length; i++) {
4085
+ if (i === to.length - 1 && to[i] < from[i]) {
4086
+ moveDirection = "down-up";
4087
+ }
4088
+ if (from[i] === to[i]) {
4089
+ continue;
4090
+ } else {
4091
+ break;
4092
+ }
4093
+ }
4094
+ }
4095
+ }
4096
+ }
4097
+ const startEffectIndex = from.length - 1;
4098
+ const endEffectIndex = to.length - 1;
4099
+ if (moveDirection === "up-down" && startEffectIndex >= 0) {
4100
+ to[startEffectIndex] -= 1;
4101
+ } else if (moveDirection === "down-up" && endEffectIndex >= 0) {
4102
+ from[endEffectIndex] += 1;
4103
+ }
4104
+ return { from, to };
4105
+ }
4106
+ function calcRevertMovePosition(opts) {
4107
+ const result = calcResultMovePosition(opts);
4108
+ if (!result) {
4109
+ return result;
4110
+ }
4111
+ return {
4112
+ from: [...result.to],
4113
+ to: [...result.from]
4114
+ };
4115
+ }
4116
+ function merge(target, source) {
4117
+ const result = target;
4118
+ for (const key in source) {
4119
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
4120
+ if (typeof source[key] === "object" && source[key] !== null && typeof result[key] === "object" && result[key] !== null) {
4121
+ result[key] = merge(result[key], source[key]);
4122
+ } else {
4123
+ result[key] = source[key];
4124
+ }
4125
+ }
4126
+ }
4127
+ return target;
4128
+ }
4129
+ function omit(obj, keys) {
4130
+ const result = { ...obj };
4131
+ for (const key of keys) {
4132
+ delete result[key];
4133
+ }
4134
+ return result;
4135
+ }
4136
+ function elementToBoxInfo(elem) {
4137
+ const { x: x2, y: y2, w: w2, h: h2, detail } = elem;
4138
+ const { borderWidth: borderWidth2, borderRadius: borderRadius2, boxSizing } = detail;
4139
+ let btw = 0;
4140
+ let brw = 0;
4141
+ let bbw = 0;
4142
+ let blw = 0;
4143
+ let btlr = 0;
4144
+ let btrr = 0;
4145
+ let bblr = 0;
4146
+ let bbrr = 0;
4147
+ if (typeof borderWidth2 === "number" && borderWidth2 > 0) {
4148
+ btw = borderWidth2;
4149
+ brw = borderWidth2;
4150
+ bbw = borderWidth2;
4151
+ blw = borderWidth2;
4152
+ } else if (Array.isArray(borderWidth2)) {
4153
+ btw = is.positiveNum(borderWidth2[0]) ? borderWidth2[0] : 0;
4154
+ brw = is.positiveNum(borderWidth2[1]) ? borderWidth2[0] : 0;
4155
+ bbw = is.positiveNum(borderWidth2[2]) ? borderWidth2[0] : 0;
4156
+ blw = is.positiveNum(borderWidth2[3]) ? borderWidth2[0] : 0;
4157
+ }
4158
+ if (typeof borderRadius2 === "number" && borderRadius2 > 0) {
4159
+ btlr = borderRadius2;
4160
+ btrr = borderRadius2;
4161
+ bblr = borderRadius2;
4162
+ bbrr = borderRadius2;
4163
+ } else if (Array.isArray(borderRadius2)) {
4164
+ btlr = is.positiveNum(borderRadius2[0]) ? borderRadius2[0] : 0;
4165
+ btrr = is.positiveNum(borderRadius2[0]) ? borderRadius2[0] : 0;
4166
+ bblr = is.positiveNum(borderRadius2[0]) ? borderRadius2[0] : 0;
4167
+ bbrr = is.positiveNum(borderRadius2[0]) ? borderRadius2[0] : 0;
4168
+ }
4169
+ const p0 = { x: x2, y: y2 };
4170
+ const p1 = { x: x2 + w2, y: y2 };
4171
+ const p2 = { x: x2 + w2, y: y2 + h2 };
4172
+ const p3 = { x: x2, y: y2 + h2 };
4173
+ const p0s = { x: x2, y: y2 + btlr };
4174
+ const p0e = { x: x2 + btlr, y: y2 };
4175
+ const p1s = { x: x2 + w2 - btrr, y: y2 };
4176
+ const p1e = { x: x2 + w2, y: y2 + btrr };
4177
+ const p2s = { x: x2 + w2, y: y2 + h2 - bbrr };
4178
+ const p2e = { x: x2 + w2 - bbrr, y: y2 + h2 };
4179
+ const p3s = { x: x2 + bblr, y: y2 + h2 };
4180
+ const p3e = { x: x2, y: y2 + h2 - bblr };
4181
+ let op0 = { ...p0 };
4182
+ let op1 = { ...p1 };
4183
+ let op2 = { ...p2 };
4184
+ let op3 = { ...p3 };
4185
+ let op0s = { ...p0s };
4186
+ let op0e = { ...p0e };
4187
+ let op1s = { ...p1s };
4188
+ let op1e = { ...p1e };
4189
+ let op2s = { ...p2s };
4190
+ let op2e = { ...p2e };
4191
+ let op3s = { ...p3s };
4192
+ let op3e = { ...p3e };
4193
+ let ip0 = { ...p0 };
4194
+ let ip1 = { ...p1 };
4195
+ let ip2 = { ...p2 };
4196
+ let ip3 = { ...p3 };
4197
+ let ip0s = { ...p0s };
4198
+ let ip0e = { ...p0e };
4199
+ let ip1s = { ...p1s };
4200
+ let ip1e = { ...p1e };
4201
+ let ip2s = { ...p2s };
4202
+ let ip2e = { ...p2e };
4203
+ let ip3s = { ...p3s };
4204
+ let ip3e = { ...p3e };
4205
+ if (boxSizing === "border-box") {
4206
+ ip0 = { x: ip0.x + blw, y: ip0.y + btw };
4207
+ ip1 = { x: ip1.x - brw, y: ip1.y + btw };
4208
+ ip2 = { x: ip2.x - brw, y: ip2.y - bbw };
4209
+ ip3 = { x: ip3.x + blw, y: ip3.y - bbw };
4210
+ ip0s = { x: ip0s.x + blw, y: ip0s.y + btw };
4211
+ ip0e = { x: ip0e.x + blw, y: ip0e.y + btw };
4212
+ ip1s = { x: ip1s.x - brw, y: ip1s.y + btw };
4213
+ ip1e = { x: ip1e.x - brw, y: ip1e.y + btw };
4214
+ ip2s = { x: ip2s.x - brw, y: ip2s.y - bbw };
4215
+ ip2e = { x: ip2e.x - brw, y: ip2e.y - bbw };
4216
+ ip3s = { x: ip3s.x + blw, y: ip3s.y - bbw };
4217
+ ip3e = { x: ip3e.x + blw, y: ip3e.y - bbw };
4218
+ } else if (boxSizing === "content-box") {
4219
+ op0 = { x: op0.x - blw, y: op0.y - btw };
4220
+ op1 = { x: op1.x + brw, y: op1.y - btw };
4221
+ op2 = { x: op2.x + brw, y: op2.y + bbw };
4222
+ op3 = { x: op3.x - blw, y: op3.y + bbw };
4223
+ op0s = { x: op0s.x - blw, y: op0s.y - btw };
4224
+ op0e = { x: op0e.x - blw, y: op0e.y - btw };
4225
+ op1s = { x: op1s.x + brw, y: op1s.y - btw };
4226
+ op1e = { x: op1e.x + brw, y: op1e.y - btw };
4227
+ op2s = { x: op2s.x + brw, y: op2s.y + bbw };
4228
+ op2e = { x: op2e.x + brw, y: op2e.y + bbw };
4229
+ op3s = { x: op3s.x - blw, y: op3s.y + bbw };
4230
+ op3e = { x: op3e.x - blw, y: op3e.y + bbw };
4231
+ } else {
4232
+ ip0 = { x: ip0.x + blw / 2, y: ip0.y + btw / 2 };
4233
+ ip1 = { x: ip1.x - brw / 2, y: ip1.y + btw / 2 };
4234
+ ip2 = { x: ip2.x - brw / 2, y: ip2.y - bbw / 2 };
4235
+ ip3 = { x: ip3.x + blw / 2, y: ip3.y - bbw / 2 };
4236
+ ip0s = { x: ip0s.x + blw / 2, y: ip0s.y + btw / 2 };
4237
+ ip0e = { x: ip0e.x + blw / 2, y: ip0e.y + btw / 2 };
4238
+ ip1s = { x: ip1s.x - brw / 2, y: ip1s.y + btw / 2 };
4239
+ ip1e = { x: ip1e.x - brw / 2, y: ip1e.y + btw / 2 };
4240
+ ip2s = { x: ip2s.x - brw / 2, y: ip2s.y - bbw / 2 };
4241
+ ip2e = { x: ip2e.x - brw / 2, y: ip2e.y - bbw / 2 };
4242
+ ip3s = { x: ip3s.x + blw / 2, y: ip3s.y - bbw / 2 };
4243
+ ip3e = { x: ip3e.x + blw / 2, y: ip3e.y - bbw / 2 };
4244
+ op0 = { x: op0.x - blw / 2, y: op0.y - btw / 2 };
4245
+ op1 = { x: op1.x + brw / 2, y: op1.y - btw / 2 };
4246
+ op2 = { x: op2.x + brw / 2, y: op2.y + bbw / 2 };
4247
+ op3 = { x: op3.x - blw / 2, y: op3.y + bbw / 2 };
4248
+ op0s = { x: op0s.x - blw / 2, y: op0s.y - btw / 2 };
4249
+ op0e = { x: op0e.x - blw / 2, y: op0e.y - btw / 2 };
4250
+ op1s = { x: op1s.x + brw / 2, y: op1s.y - btw / 2 };
4251
+ op1e = { x: op1e.x + brw / 2, y: op1e.y - btw / 2 };
4252
+ op2s = { x: op2s.x + brw / 2, y: op2s.y + bbw / 2 };
4253
+ op2e = { x: op2e.x + brw / 2, y: op2e.y + bbw / 2 };
4254
+ op3s = { x: op3s.x - blw / 2, y: op3s.y + bbw / 2 };
4255
+ op3e = { x: op3e.x - blw / 2, y: op3e.y + bbw / 2 };
4256
+ }
4257
+ return {
4258
+ btw,
4259
+ brw,
4260
+ bbw,
4261
+ blw,
4262
+ btlr,
4263
+ btrr,
4264
+ bblr,
4265
+ bbrr,
4266
+ p0,
4267
+ p1,
4268
+ p2,
4269
+ p3,
4270
+ p0s,
4271
+ p0e,
4272
+ p1s,
4273
+ p1e,
4274
+ p2s,
4275
+ p2e,
4276
+ p3s,
4277
+ p3e,
4278
+ op0,
4279
+ op1,
4280
+ op2,
4281
+ op3,
4282
+ op0s,
4283
+ op0e,
4284
+ op1s,
4285
+ op1e,
4286
+ op2s,
4287
+ op2e,
4288
+ op3s,
4289
+ op3e,
4290
+ ip0,
4291
+ ip1,
4292
+ ip2,
4293
+ ip3,
4294
+ ip0s,
4295
+ ip0e,
4296
+ ip1s,
4297
+ ip1e,
4298
+ ip2s,
4299
+ ip2e,
4300
+ ip3s,
4301
+ ip3e
4302
+ };
4303
+ }
4304
+ function unflatObject(flatObj) {
4305
+ const result = {};
4306
+ for (const [flatKey, value] of Object.entries(flatObj)) {
4307
+ const pathParts = parseKeyToPath(flatKey);
4308
+ buildNestedStructure(result, pathParts, value);
4309
+ }
4310
+ return result;
4311
+ }
4312
+ function parseKeyToPath(flatKey) {
4313
+ const regex = /([\w-]+)|\[(\d+)\]/g;
4314
+ const pathParts = [];
4315
+ let match;
4316
+ while ((match = regex.exec(flatKey)) !== null) {
4317
+ const prop = match[1] || match[2];
4318
+ if (prop) {
4319
+ pathParts.push(prop);
4320
+ }
4321
+ }
4322
+ return pathParts;
4323
+ }
4324
+ function buildNestedStructure(currentObj, pathParts, value) {
4325
+ let currentLevel = currentObj;
4326
+ for (let i = 0; i < pathParts.length; i++) {
4327
+ const part = pathParts[i];
4328
+ const isArrayPart = isArrayIndex(part);
4329
+ const isLast = i === pathParts.length - 1;
4330
+ try {
4331
+ if (isArrayPart) {
4332
+ validateArrayPath(currentLevel, part);
4333
+ } else {
4334
+ validateObjectPath(currentLevel, part);
4335
+ }
4336
+ } catch (e) {
4337
+ throw new Error(`Structure conflict at path '${pathParts.slice(0, i + 1).join(".")}': ${e.message}`);
4338
+ }
4339
+ if (isLast) {
4340
+ assignValue(currentLevel, part, value);
4341
+ } else {
4342
+ currentLevel = prepareNextLevel(currentLevel, part, pathParts[i + 1]);
4343
+ }
4344
+ }
4345
+ }
4346
+ function isArrayIndex(key) {
4347
+ return /^\d+$/.test(key);
4348
+ }
4349
+ function validateArrayPath(obj, index) {
4350
+ if (!Array.isArray(obj)) {
4351
+ throw new Error(`Expected array but found ${typeof obj}`);
4352
+ }
4353
+ const idx = Number(index);
4354
+ if (idx > obj.length) {
4355
+ obj.length = idx + 1;
4356
+ }
4357
+ }
4358
+ function validateObjectPath(obj, key) {
4359
+ if (Array.isArray(obj)) {
4360
+ throw new Error(`Cannot create object property '${key}' on array`);
4361
+ }
4362
+ if (typeof obj !== "object" || obj === null) {
4363
+ throw new Error(`Invalid structure for property '${key}'`);
4364
+ }
4365
+ }
4366
+ function prepareNextLevel(current, part, nextPart) {
4367
+ const isNextArray = nextPart ? isArrayIndex(nextPart) : false;
4368
+ if (Array.isArray(current)) {
4369
+ const index = Number(part);
4370
+ if (!current[index]) {
4371
+ current[index] = isNextArray ? [] : {};
4372
+ }
4373
+ return current[index];
4374
+ }
4375
+ if (!current[part]) {
4376
+ current[part] = isNextArray ? [] : {};
4377
+ }
4378
+ return current[part];
4379
+ }
4380
+ function assignValue(target, key, value) {
4381
+ if (Array.isArray(target)) {
4382
+ const index = Number(key);
4383
+ if (index >= target.length) {
4384
+ target.length = index + 1;
4385
+ }
4386
+ target[index] = value;
4387
+ } else {
4388
+ target[key] = value;
4389
+ }
4390
+ }
2779
4391
  exports.Context2D = Context2D;
2780
4392
  exports.EventEmitter = EventEmitter;
2781
4393
  exports.Store = Store;
@@ -2783,14 +4395,23 @@ var __privateSet = (obj, member, value, setter) => {
2783
4395
  exports.calcElementCenter = calcElementCenter;
2784
4396
  exports.calcElementCenterFromVertexes = calcElementCenterFromVertexes;
2785
4397
  exports.calcElementListSize = calcElementListSize;
4398
+ exports.calcElementOriginRectInfo = calcElementOriginRectInfo;
2786
4399
  exports.calcElementQueueVertexesQueueInGroup = calcElementQueueVertexesQueueInGroup;
2787
4400
  exports.calcElementSizeController = calcElementSizeController;
2788
4401
  exports.calcElementVertexesInGroup = calcElementVertexesInGroup;
2789
4402
  exports.calcElementVertexesQueueInGroup = calcElementVertexesQueueInGroup;
4403
+ exports.calcElementViewRectInfo = calcElementViewRectInfo;
2790
4404
  exports.calcElementsContextSize = calcElementsContextSize;
2791
4405
  exports.calcElementsViewInfo = calcElementsViewInfo;
4406
+ exports.calcLayoutSizeController = calcLayoutSizeController;
4407
+ exports.calcPointMoveElementInGroup = calcPointMoveElementInGroup;
4408
+ exports.calcRadian = calcRadian;
4409
+ exports.calcResultMovePosition = calcResultMovePosition;
4410
+ exports.calcRevertMovePosition = calcRevertMovePosition;
2792
4411
  exports.calcSpeed = calcSpeed;
2793
4412
  exports.calcViewBoxSize = calcViewBoxSize;
4413
+ exports.calcViewCenter = calcViewCenter;
4414
+ exports.calcViewCenterContent = calcViewCenterContent;
2794
4415
  exports.calcViewElementSize = calcViewElementSize;
2795
4416
  exports.calcViewPointSize = calcViewPointSize;
2796
4417
  exports.calcViewScaleInfo = calcViewScaleInfo;
@@ -2808,43 +4429,59 @@ var __privateSet = (obj, member, value, setter) => {
2808
4429
  exports.createElement = createElement;
2809
4430
  exports.createOffscreenContext2D = createOffscreenContext2D;
2810
4431
  exports.createUUID = createUUID;
4432
+ exports.debounce = debounce;
2811
4433
  exports.deepClone = deepClone;
4434
+ exports.deepCloneData = deepCloneData;
4435
+ exports.deepCloneElement = deepCloneElement;
4436
+ exports.deepResizeGroupElement = deepResizeGroupElement;
2812
4437
  exports.delay = delay;
2813
4438
  exports.deleteElementInList = deleteElementInList;
2814
4439
  exports.deleteElementInListByPosition = deleteElementInListByPosition;
2815
4440
  exports.downloadFileFromText = downloadFileFromText;
2816
4441
  exports.downloadImageFromCanvas = downloadImageFromCanvas;
4442
+ exports.elementToBoxInfo = elementToBoxInfo;
4443
+ exports.enhanceFontFamliy = enhanceFontFamliy;
2817
4444
  exports.equalPoint = equalPoint;
2818
4445
  exports.equalTouchPoint = equalTouchPoint;
4446
+ exports.filterCompactData = filterCompactData;
2819
4447
  exports.filterElementAsset = filterElementAsset;
2820
4448
  exports.findElementFromList = findElementFromList;
2821
4449
  exports.findElementFromListByPosition = findElementFromListByPosition;
2822
4450
  exports.findElementQueueFromListByPosition = findElementQueueFromListByPosition;
2823
4451
  exports.findElementsFromList = findElementsFromList;
2824
4452
  exports.findElementsFromListByPositions = findElementsFromListByPositions;
4453
+ exports.flatElementList = flatElementList;
4454
+ exports.flatObject = flatObject;
2825
4455
  exports.formatNumber = formatNumber;
2826
4456
  exports.generateHTML = generateHTML;
2827
4457
  exports.generateSVGPath = generateSVGPath;
4458
+ exports.get = get;
2828
4459
  exports.getCenterFromTwoPoints = getCenterFromTwoPoints;
2829
4460
  exports.getDefaultElementDetailConfig = getDefaultElementDetailConfig;
2830
4461
  exports.getDefaultElementRectDetail = getDefaultElementRectDetail;
2831
4462
  exports.getElemenetsAssetIds = getElemenetsAssetIds;
2832
4463
  exports.getElementPositionFromList = getElementPositionFromList;
4464
+ exports.getElementPositionMapFromList = getElementPositionMapFromList;
2833
4465
  exports.getElementRotateVertexes = getElementRotateVertexes;
2834
4466
  exports.getElementSize = getElementSize;
2835
4467
  exports.getElementVertexes = getElementVertexes;
4468
+ exports.getGroupQueueByElementPosition = getGroupQueueByElementPosition;
2836
4469
  exports.getGroupQueueFromList = getGroupQueueFromList;
2837
4470
  exports.getSelectedElementUUIDs = getSelectedElementUUIDs;
2838
4471
  exports.getViewPointAtElement = getViewPointAtElement;
2839
4472
  exports.getViewScaleInfoFromSnapshot = getViewScaleInfoFromSnapshot;
2840
4473
  exports.getViewSizeInfoFromSnapshot = getViewSizeInfoFromSnapshot;
4474
+ exports.groupElementsByPosition = groupElementsByPosition;
2841
4475
  exports.insertElementToListByPosition = insertElementToListByPosition;
2842
4476
  exports.is = is;
2843
4477
  exports.isAssetId = isAssetId;
2844
4478
  exports.isColorStr = isColorStr;
2845
4479
  exports.isElementInView = isElementInView;
2846
4480
  exports.isResourceElement = isResourceElement;
4481
+ exports.isSameElementSize = isSameElementSize;
2847
4482
  exports.isViewPointInElement = isViewPointInElement;
4483
+ exports.isViewPointInElementSize = isViewPointInElementSize;
4484
+ exports.isViewPointInVertexes = isViewPointInVertexes;
2848
4485
  exports.istype = istype;
2849
4486
  exports.limitAngle = limitAngle;
2850
4487
  exports.loadHTML = loadHTML;
@@ -2852,9 +4489,15 @@ var __privateSet = (obj, member, value, setter) => {
2852
4489
  exports.loadSVG = loadSVG;
2853
4490
  exports.matrixToAngle = matrixToAngle;
2854
4491
  exports.matrixToRadian = matrixToRadian;
4492
+ exports.merge = merge;
4493
+ exports.mergeElement = mergeElement;
2855
4494
  exports.mergeElementAsset = mergeElementAsset;
4495
+ exports.mergeGlobal = mergeGlobal;
2856
4496
  exports.mergeHexColorAlpha = mergeHexColorAlpha;
4497
+ exports.mergeLayout = mergeLayout;
2857
4498
  exports.moveElementPosition = moveElementPosition;
4499
+ exports.omit = omit;
4500
+ exports.originRectInfoToRangeRectInfo = originRectInfoToRangeRectInfo;
2858
4501
  exports.parseAngleToRadian = parseAngleToRadian;
2859
4502
  exports.parseFileToBase64 = parseFileToBase64;
2860
4503
  exports.parseFileToText = parseFileToText;
@@ -2868,11 +4511,19 @@ var __privateSet = (obj, member, value, setter) => {
2868
4511
  exports.rotatePoint = rotatePoint;
2869
4512
  exports.rotatePointInGroup = rotatePointInGroup;
2870
4513
  exports.rotateVertexes = rotateVertexes;
4514
+ exports.set = set;
2871
4515
  exports.sortDataAsserts = sortDataAsserts;
2872
4516
  exports.throttle = throttle;
2873
4517
  exports.toColorHexNum = toColorHexNum;
2874
4518
  exports.toColorHexStr = toColorHexStr;
4519
+ exports.toFlattenElement = toFlattenElement;
4520
+ exports.toFlattenGlobal = toFlattenGlobal;
4521
+ exports.toFlattenLayout = toFlattenLayout;
4522
+ exports.toPath = toPath;
4523
+ exports.unflatObject = unflatObject;
4524
+ exports.ungroupElementsByPosition = ungroupElementsByPosition;
2875
4525
  exports.updateElementInList = updateElementInList;
4526
+ exports.updateElementInListByPosition = updateElementInListByPosition;
2876
4527
  exports.vaildPoint = vaildPoint;
2877
4528
  exports.vaildTouchPoint = vaildTouchPoint;
2878
4529
  exports.validateElements = validateElements;