@leafer-in/editor 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/editor.js CHANGED
@@ -128,8 +128,9 @@ this.LeaferIN.editor = (function (exports, draw, core) {
128
128
  leaf.path = leaf.__.path;
129
129
  }
130
130
  function scaleResizePoints(leaf, scaleX, scaleY) {
131
- PathScaler.scalePoints(leaf.__.points, scaleX, scaleY);
132
- leaf.points = leaf.__.points;
131
+ const { points } = leaf;
132
+ typeof points[0] === 'object' ? points.forEach(p => { p.x *= scaleX, p.y *= scaleY; }) : PathScaler.scalePoints(points, scaleX, scaleY);
133
+ leaf.points = points;
133
134
  }
134
135
  function scaleResizeGroup(group, scaleX, scaleY) {
135
136
  const { children } = group;
@@ -317,31 +318,29 @@ this.LeaferIN.editor = (function (exports, draw, core) {
317
318
  const { list } = this;
318
319
  if (list.length) {
319
320
  let leaf;
320
- const { stroke, strokeWidth, fill } = this.__;
321
- const { bounds } = options;
321
+ const data = this.__, { stroke, strokeWidth, fill } = data, { bounds } = options;
322
322
  for (let i = 0; i < list.length; i++) {
323
323
  leaf = list[i];
324
- if (bounds && bounds.hit(leaf.__world, options.matrix)) {
325
- const aScaleX = abs(leaf.__world.scaleX), aScaleY = abs(leaf.__world.scaleY);
324
+ const { worldTransform, worldRenderBounds } = leaf;
325
+ if (bounds && bounds.hit(worldRenderBounds, options.matrix)) {
326
+ const aScaleX = abs(worldTransform.scaleX), aScaleY = abs(worldTransform.scaleY);
326
327
  if (aScaleX !== aScaleY) {
327
- copy$1(matrix, leaf.__world);
328
+ copy$1(matrix, worldTransform);
328
329
  scale(matrix, 1 / aScaleX, 1 / aScaleY);
329
330
  canvas.setWorld(matrix, options.matrix);
330
331
  canvas.beginPath();
331
- this.__.strokeWidth = strokeWidth;
332
+ data.strokeWidth = strokeWidth;
332
333
  const { x, y, width, height } = leaf.__layout.boxBounds;
333
334
  canvas.rect(x * aScaleX, y * aScaleY, width * aScaleX, height * aScaleY);
334
335
  }
335
336
  else {
336
- canvas.setWorld(leaf.__world, options.matrix);
337
+ canvas.setWorld(worldTransform, options.matrix);
337
338
  canvas.beginPath();
338
- if (leaf.__.__useArrow) {
339
+ if (leaf.__.__useArrow)
339
340
  leaf.__drawPath(canvas);
340
- }
341
- else {
341
+ else
342
342
  leaf.__.__pathForRender ? leaf.__drawRenderPath(canvas) : leaf.__drawPathByBox(canvas);
343
- }
344
- this.__.strokeWidth = strokeWidth / abs(leaf.__world.scaleX);
343
+ data.strokeWidth = strokeWidth / abs(worldTransform.scaleX);
345
344
  }
346
345
  if (stroke)
347
346
  typeof stroke === 'string' ? draw.Paint.stroke(stroke, this, canvas) : draw.Paint.strokes(stroke, this, canvas);
@@ -349,7 +348,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
349
348
  typeof fill === 'string' ? draw.Paint.fill(fill, this, canvas) : draw.Paint.fills(fill, this, canvas);
350
349
  }
351
350
  }
352
- this.__.strokeWidth = strokeWidth;
351
+ data.strokeWidth = strokeWidth;
353
352
  }
354
353
  }
355
354
  destroy() {
@@ -900,7 +899,6 @@ this.LeaferIN.editor = (function (exports, draw, core) {
900
899
  this.editor = editor;
901
900
  this.visible = false;
902
901
  this.create();
903
- this.rect.syncEventer = editor;
904
902
  this.__listenEvents();
905
903
  }
906
904
  create() {
@@ -940,8 +938,11 @@ this.LeaferIN.editor = (function (exports, draw, core) {
940
938
  circle.set(this.getPointStyle(mergeConfig.circle || mergeConfig.rotatePoint || pointsStyle[0]));
941
939
  rect.set(Object.assign({ stroke, strokeWidth }, (mergeConfig.rect || {})));
942
940
  rect.hittable = !single && !!moveable;
943
- element.syncEventer = (single && moveable) ? rect : null;
944
- this.app.interaction.bottomList = (single && moveable) ? [{ target: rect, proxy: element }] : null;
941
+ rect.syncEventer = single && this.editor;
942
+ if (single && moveable) {
943
+ element.syncEventer = rect;
944
+ this.app.interaction.bottomList = [{ target: rect, proxy: element }];
945
+ }
945
946
  }
946
947
  update(bounds) {
947
948
  this.visible = !this.editor.element.locked;
@@ -1113,6 +1114,11 @@ this.LeaferIN.editor = (function (exports, draw, core) {
1113
1114
  if (editor.single) {
1114
1115
  const { element } = editor;
1115
1116
  if (element.isBranch) {
1117
+ if (element.textBox) {
1118
+ const find = element.children.find(item => item.editable && item instanceof draw.Text);
1119
+ if (find)
1120
+ return editor.openInnerEditor(find);
1121
+ }
1116
1122
  editor.openGroup(element);
1117
1123
  editor.target = editor.selector.findDeepOne(e);
1118
1124
  }
@@ -1258,12 +1264,12 @@ ${filterStyle}
1258
1264
  skewable: true
1259
1265
  };
1260
1266
 
1267
+ const bounds = new draw.Bounds();
1261
1268
  function simulate(editor) {
1262
- const { simulateTarget, leafList: targetList } = editor;
1263
- const { x, y, width, height } = new draw.Bounds().setListWithFn(targetList.list, (leaf) => leaf.worldBoxBounds);
1264
- const parent = simulateTarget.parent = targetList.list[0].leafer.zoomLayer;
1265
- const { scaleX, scaleY, e: worldX, f: worldY } = parent.__world;
1266
- simulateTarget.reset({ x: (x - worldX) / scaleX, y: (y - worldY) / scaleY, width: width / scaleX, height: height / scaleY });
1269
+ const { simulateTarget, list } = editor;
1270
+ const { zoomLayer } = list[0].leafer.zoomLayer;
1271
+ simulateTarget.safeChange(() => simulateTarget.reset(bounds.setListWithFn(list, (leaf) => leaf.getBounds('box', 'page')).get()));
1272
+ zoomLayer.add(simulateTarget);
1267
1273
  }
1268
1274
 
1269
1275
  function onTarget(editor, oldValue) {
@@ -1272,6 +1278,7 @@ ${filterStyle}
1272
1278
  editor.leafList = target instanceof draw.LeafList ? target : new draw.LeafList(target instanceof Array ? target : target);
1273
1279
  }
1274
1280
  else {
1281
+ editor.simulateTarget.remove();
1275
1282
  editor.leafList.reset();
1276
1283
  editor.closeInnerEditor();
1277
1284
  }
@@ -1326,7 +1333,7 @@ ${filterStyle}
1326
1333
  const ungroupList = [];
1327
1334
  app.lockLayout();
1328
1335
  list.forEach(leaf => {
1329
- if (leaf.isBranch) {
1336
+ if (leaf.isBranch && !leaf.isBranchLeaf) {
1330
1337
  const { parent, children } = leaf;
1331
1338
  while (children.length) {
1332
1339
  ungroupList.push(children[0]);
@@ -1397,17 +1404,77 @@ ${filterStyle}
1397
1404
  EditorGroupEvent.OPEN = 'editor.open_group';
1398
1405
  EditorGroupEvent.CLOSE = 'editor.close_group';
1399
1406
 
1407
+ const { updateMatrix } = draw.LeafHelper;
1408
+ const checkMap = { x: 1, y: 1, scaleX: 1, scaleY: 1, rotation: 1, skewX: 1, skewY: 1 }, origin = 'top-left';
1409
+ class SimulateElement extends draw.Rect {
1410
+ get __tag() { return 'SimulateElement'; }
1411
+ constructor(editor) {
1412
+ super();
1413
+ this.checkChange = true;
1414
+ this.canChange = true;
1415
+ this.visible = this.hittable = false;
1416
+ this.on(draw.PropertyEvent.CHANGE, (event) => {
1417
+ if (this.checkChange && checkMap[event.attrName]) {
1418
+ const { attrName, newValue, oldValue } = event;
1419
+ const addValue = attrName[0] === 's' ? (newValue || 1) / (oldValue || 1) : (newValue || 0) - (oldValue || 0);
1420
+ this.canChange = false;
1421
+ const data = this.__;
1422
+ data[attrName] = oldValue;
1423
+ updateMatrix(this.parent);
1424
+ updateMatrix(this);
1425
+ const oldMatrix = new draw.Matrix(this.__world);
1426
+ data[attrName] = newValue;
1427
+ this.__layout.rotationChange();
1428
+ updateMatrix(this);
1429
+ this.changedTransform = new draw.Matrix(this.__world).divide(oldMatrix);
1430
+ switch (attrName) {
1431
+ case 'x':
1432
+ editor.move(addValue, 0);
1433
+ break;
1434
+ case 'y':
1435
+ editor.move(0, addValue);
1436
+ break;
1437
+ case 'rotation':
1438
+ editor.rotateOf(origin, addValue);
1439
+ break;
1440
+ case 'scaleX':
1441
+ editor.scaleOf(origin, addValue, 1);
1442
+ break;
1443
+ case 'scaleY':
1444
+ editor.scaleOf(origin, 1, addValue);
1445
+ break;
1446
+ case 'skewX':
1447
+ editor.skewOf(origin, addValue, 0);
1448
+ break;
1449
+ case 'skewY':
1450
+ editor.skewOf(origin, 0, addValue);
1451
+ }
1452
+ this.canChange = true;
1453
+ }
1454
+ });
1455
+ }
1456
+ safeChange(changeFn) {
1457
+ if (this.canChange) {
1458
+ this.checkChange = false;
1459
+ changeFn();
1460
+ this.checkChange = true;
1461
+ }
1462
+ }
1463
+ }
1464
+
1400
1465
  class Editor extends draw.Group {
1401
1466
  get mergeConfig() {
1402
1467
  const { element, config } = this;
1403
1468
  return this.single && element.editConfig ? Object.assign(Object.assign({}, config), element.editConfig) : config;
1404
1469
  }
1405
1470
  get list() { return this.leafList.list; }
1471
+ get dragHoverExclude() { return [this.editBox.rect]; }
1406
1472
  get editing() { return !!this.list.length; }
1407
1473
  get groupOpening() { return !!this.openedGroupList.length; }
1408
1474
  get multiple() { return this.list.length > 1; }
1409
1475
  get single() { return this.list.length === 1; }
1410
1476
  get dragging() { return this.editBox.dragging; }
1477
+ get moving() { return this.editBox.moving; }
1411
1478
  get element() { return this.multiple ? this.simulateTarget : this.list[0]; }
1412
1479
  get buttons() { return this.editBox.buttons; }
1413
1480
  constructor(userConfig, data) {
@@ -1415,7 +1482,7 @@ ${filterStyle}
1415
1482
  this.config = draw.DataHelper.clone(config);
1416
1483
  this.leafList = new draw.LeafList();
1417
1484
  this.openedGroupList = new draw.LeafList();
1418
- this.simulateTarget = new draw.Rect({ visible: false });
1485
+ this.simulateTarget = new SimulateElement(this);
1419
1486
  this.editBox = new EditBox(this);
1420
1487
  this.editToolList = {};
1421
1488
  this.selector = new EditSelect(this);
@@ -1553,18 +1620,18 @@ ${filterStyle}
1553
1620
  this.skewOf(origin, skewX, skewY);
1554
1621
  }
1555
1622
  move(x, y = 0) {
1556
- if (!this.mergeConfig.moveable || this.element.locked)
1623
+ if (!this.checkTransform('moveable'))
1557
1624
  return;
1558
1625
  const { element } = this;
1559
1626
  const world = element.getWorldPointByLocal(typeof x === 'object' ? Object.assign({}, x) : { x, y }, null, true);
1627
+ if (this.multiple)
1628
+ element.safeChange(() => element.move(x, y));
1560
1629
  const event = new EditorMoveEvent(EditorMoveEvent.MOVE, { target: element, editor: this, moveX: world.x, moveY: world.y });
1561
1630
  this.editTool.onMove(event);
1562
1631
  this.emitEvent(event);
1563
- if (this.multiple)
1564
- element.move(x, y);
1565
1632
  }
1566
1633
  scaleWithDrag(data) {
1567
- if (!this.mergeConfig.resizeable || this.element.locked)
1634
+ if (!this.checkTransform('resizeable'))
1568
1635
  return;
1569
1636
  const { element } = this;
1570
1637
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, Object.assign(Object.assign({}, data), { target: element, editor: this, worldOrigin: element.getWorldPoint(data.origin) }));
@@ -1572,50 +1639,53 @@ ${filterStyle}
1572
1639
  this.emitEvent(event);
1573
1640
  }
1574
1641
  scaleOf(origin, scaleX, scaleY = scaleX, _resize) {
1575
- if (!this.mergeConfig.resizeable || this.element.locked)
1642
+ if (!this.checkTransform('resizeable'))
1576
1643
  return;
1577
1644
  const { element } = this;
1578
1645
  const worldOrigin = this.getWorldOrigin(origin);
1579
- const transform = this.multiple && this.getChangedTransform(() => element.scaleOf(origin, scaleX, scaleY));
1646
+ const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.scaleOf(origin, scaleX, scaleY)));
1580
1647
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, { target: element, editor: this, worldOrigin, scaleX, scaleY, transform });
1581
1648
  this.editTool.onScale(event);
1582
1649
  this.emitEvent(event);
1583
1650
  }
1584
1651
  flip(axis) {
1585
- if (this.element.locked)
1652
+ if (!this.checkTransform('resizeable'))
1586
1653
  return;
1587
1654
  const { element } = this;
1588
1655
  const worldOrigin = this.getWorldOrigin('center');
1589
- const transform = this.multiple ? this.getChangedTransform(() => element.flip(axis)) : new draw.Matrix(draw.LeafHelper.getFlipTransform(element, axis));
1656
+ const transform = this.multiple ? this.getChangedTransform(() => element.safeChange(() => element.flip(axis))) : new draw.Matrix(draw.LeafHelper.getFlipTransform(element, axis));
1590
1657
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, { target: element, editor: this, worldOrigin, scaleX: axis === 'x' ? -1 : 1, scaleY: axis === 'y' ? -1 : 1, transform });
1591
1658
  this.editTool.onScale(event);
1592
1659
  this.emitEvent(event);
1593
1660
  }
1594
1661
  rotateOf(origin, rotation) {
1595
- if (!this.mergeConfig.rotateable || this.element.locked)
1662
+ if (!this.checkTransform('rotateable'))
1596
1663
  return;
1597
1664
  const { element } = this;
1598
1665
  const worldOrigin = this.getWorldOrigin(origin);
1599
- const transform = this.multiple && this.getChangedTransform(() => element.rotateOf(origin, rotation));
1666
+ const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.rotateOf(origin, rotation)));
1600
1667
  const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, { target: element, editor: this, worldOrigin, rotation, transform });
1601
1668
  this.editTool.onRotate(event);
1602
1669
  this.emitEvent(event);
1603
1670
  }
1604
1671
  skewOf(origin, skewX, skewY = 0, _resize) {
1605
- if (!this.mergeConfig.skewable || this.element.locked)
1672
+ if (!this.checkTransform('skewable'))
1606
1673
  return;
1607
1674
  const { element } = this;
1608
1675
  const worldOrigin = this.getWorldOrigin(origin);
1609
- const transform = this.multiple && this.getChangedTransform(() => element.skewOf(origin, skewX, skewY));
1676
+ const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.skewOf(origin, skewX, skewY)));
1610
1677
  const event = new EditorSkewEvent(EditorSkewEvent.SKEW, { target: element, editor: this, worldOrigin, skewX, skewY, transform });
1611
1678
  this.editTool.onSkew(event);
1612
1679
  this.emitEvent(event);
1613
1680
  }
1681
+ checkTransform(type) { return this.element && !this.element.locked && this.mergeConfig[type]; }
1614
1682
  getWorldOrigin(origin) {
1615
1683
  return this.element.getWorldPoint(draw.LeafHelper.getInnerOrigin(this.element, origin));
1616
1684
  }
1617
1685
  getChangedTransform(func) {
1618
1686
  const { element } = this;
1687
+ if (this.multiple && !element.canChange)
1688
+ return element.changedTransform;
1619
1689
  const oldMatrix = new draw.Matrix(element.worldTransform);
1620
1690
  func();
1621
1691
  return new draw.Matrix(element.worldTransform).divide(oldMatrix);
@@ -1672,11 +1742,11 @@ ${filterStyle}
1672
1742
  this.emitEvent(event);
1673
1743
  group.emitEvent(event);
1674
1744
  }
1675
- openInnerEditor(target) {
1676
- if (target)
1745
+ openInnerEditor(target, select) {
1746
+ if (target && select)
1677
1747
  this.target = target;
1678
1748
  if (this.single) {
1679
- const editTarget = this.element;
1749
+ const editTarget = target || this.element;
1680
1750
  const tag = editTarget.editInner;
1681
1751
  if (tag && EditToolCreator.list[tag]) {
1682
1752
  this.editTool.unload();
@@ -1728,14 +1798,15 @@ ${filterStyle}
1728
1798
  }
1729
1799
  listenTargetEvents() {
1730
1800
  if (!this.targetEventIds.length) {
1731
- const { leafer } = this.list[0];
1801
+ const { app, leafer } = this;
1732
1802
  this.targetEventIds = [
1733
- this.app.on_(core.MoveEvent.BEFORE_MOVE, this.onMove, this, true),
1734
- this.app.on_(core.ZoomEvent.BEFORE_ZOOM, this.onScale, this, true),
1735
- this.app.on_(core.RotateEvent.BEFORE_ROTATE, this.onRotate, this, true),
1736
1803
  leafer.on_(draw.RenderEvent.START, this.update, this),
1737
- leafer.on_([core.KeyEvent.HOLD, core.KeyEvent.UP], (e) => { updateCursor(this, e); }),
1738
- leafer.on_(core.KeyEvent.DOWN, this.editBox.onArrow, this.editBox)
1804
+ app.on_(draw.RenderEvent.CHILD_START, this.forceRender, this),
1805
+ app.on_(core.MoveEvent.BEFORE_MOVE, this.onMove, this, true),
1806
+ app.on_(core.ZoomEvent.BEFORE_ZOOM, this.onScale, this, true),
1807
+ app.on_(core.RotateEvent.BEFORE_ROTATE, this.onRotate, this, true),
1808
+ app.on_([core.KeyEvent.HOLD, core.KeyEvent.UP], (e) => { updateCursor(this, e); }),
1809
+ app.on_(core.KeyEvent.DOWN, this.editBox.onArrow, this.editBox)
1739
1810
  ];
1740
1811
  }
1741
1812
  }
@@ -1751,7 +1822,8 @@ ${filterStyle}
1751
1822
  this.simulateTarget.destroy();
1752
1823
  Object.values(this.editToolList).forEach(item => item.destroy());
1753
1824
  this.editToolList = {};
1754
- this.target = this.hoverTarget = this.simulateTarget = this.editTool = this.innerEditor = null;
1825
+ this.target = this.hoverTarget = null;
1826
+ this.simulateTarget = this.editTool = this.innerEditor = null;
1755
1827
  super.destroy();
1756
1828
  }
1757
1829
  }
@@ -1868,10 +1940,7 @@ ${filterStyle}
1868
1940
  }
1869
1941
  update() {
1870
1942
  const { editor, editBox } = this;
1871
- const { simulateTarget, element } = editor;
1872
- if (editor.multiple)
1873
- simulateTarget.parent.updateLayout();
1874
- const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = element.getLayoutBounds('box', editor, true);
1943
+ const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = editor.element.getLayoutBounds('box', editor, true);
1875
1944
  editBox.set({ x, y, scaleX, scaleY, rotation, skewX, skewY });
1876
1945
  editBox.update({ x: 0, y: 0, width, height });
1877
1946
  this.onUpdate();
@@ -1886,7 +1955,7 @@ ${filterStyle}
1886
1955
  ], exports.EditTool);
1887
1956
 
1888
1957
  const { left, right } = draw.Direction9;
1889
- const { move, copy } = draw.PointHelper;
1958
+ const { move, copy, toNumberPoints } = draw.PointHelper;
1890
1959
  exports.LineEditTool = class LineEditTool extends exports.EditTool {
1891
1960
  constructor() {
1892
1961
  super(...arguments);
@@ -1928,14 +1997,8 @@ ${filterStyle}
1928
1997
  }
1929
1998
  getInnerMove(ui, event, lockRatio) {
1930
1999
  const movePoint = event.getInnerMove(ui);
1931
- if (lockRatio) {
1932
- if (Math.abs(movePoint.x) > Math.abs(movePoint.y)) {
1933
- movePoint.y = 0;
1934
- }
1935
- else {
1936
- movePoint.x = 0;
1937
- }
1938
- }
2000
+ if (lockRatio)
2001
+ Math.abs(movePoint.x) > Math.abs(movePoint.y) ? movePoint.y = 0 : movePoint.x = 0;
1939
2002
  return movePoint;
1940
2003
  }
1941
2004
  getFromToByPath(path) {
@@ -1944,7 +2007,8 @@ ${filterStyle}
1944
2007
  to: { x: path[4], y: path[5] }
1945
2008
  };
1946
2009
  }
1947
- getFromToByPoints(points) {
2010
+ getFromToByPoints(originPoints) {
2011
+ const points = toNumberPoints(originPoints);
1948
2012
  return {
1949
2013
  from: { x: points[0], y: points[1] },
1950
2014
  to: { x: points[2], y: points[3] }
@@ -1997,6 +2061,15 @@ ${filterStyle}
1997
2061
  ], exports.LineEditTool);
1998
2062
 
1999
2063
  draw.Creator.editor = function (options) { return new Editor(options); };
2064
+ draw.defineKey(draw.UI.prototype, 'editOuter', {
2065
+ get() { return this.__.__isLinePath ? 'LineEditTool' : 'EditTool'; }
2066
+ });
2067
+ draw.defineKey(draw.UI.prototype, 'editInner', {
2068
+ get() { return 'PathEditor'; }
2069
+ });
2070
+ draw.defineKey(draw.Text.prototype, 'editInner', {
2071
+ get() { return 'TextEditor'; }
2072
+ });
2000
2073
  draw.UI.setEditConfig = function (config) {
2001
2074
  draw.defineKey(this.prototype, 'editConfig', {
2002
2075
  get() { return typeof config === 'function' ? config(this) : config; }
@@ -1 +1 @@
1
- "use strict";var t=require("@leafer-ui/draw"),e=require("@leafer-ui/core");const{M:i,L:o,C:s,Q:n,Z:r,N:a,D:l,X:h,G:d,F:c,O:g,P:u,U:p}=t.PathCommandMap,f={scale(t,e,f){if(!t)return;let v,E=0,b=t.length;for(;E<b;)switch(v=t[E],v){case i:case o:m(t,e,f,E,1),E+=3;break;case s:m(t,e,f,E,3),E+=7;break;case n:m(t,e,f,E,2),E+=5;break;case r:E+=1;break;case a:m(t,e,f,E,2),E+=5;break;case l:m(t,e,f,E,2),E+=9;break;case h:m(t,e,f,E,2),E+=6;break;case d:m(t,e,f,E,2),E+=9;break;case c:m(t,e,f,E,2),E+=5;break;case g:t[E]=d,t.splice(E+4,0,t[E+3],0),m(t,e,f,E,2),E+=9,b+=2;break;case u:t[E]=c,t.splice(E+4,0,t[E+3]),m(t,e,f,E,2),E+=5,b+=1;break;case p:m(t,e,f,E,2),E+=6}},scalePoints(t,e,i,o,s){for(let n=s?o+1:0,r=s?n+2*s:t.length;n<r;n+=2)t[n]*=e,t[n+1]*=i}},{scalePoints:m}=f,v=t.MatrixHelper.get(),{topLeft:E,top:b,topRight:y,right:_,bottom:L,left:w}=t.Direction9;function x(t,e,i){t.pathInputed?M(t,e,i):(1!==e&&(t.width*=e),1!==i&&(t.height*=i))}function k(t,e,i){const{app:o}=t,s=o&&o.editor;let n=e;if(s.editing){const o=t.__layout;let{width:r,height:a}=o.boxBounds;switch(r*=i-e,a*=e-i,s.resizeDirection){case b:case L:n=i,o.affectScaleOrRotation?t.moveInner(-r/2,0):t.x-=r/2;break;case w:case _:o.affectScaleOrRotation?t.moveInner(0,-a/2):t.y-=a/2;break;case E:case y:o.affectScaleOrRotation?t.moveInner(0,-a):t.y-=a}}t.fontSize*=n;const r=t.__;r.__autoWidth||(t.width*=n),r.__autoHeight||(t.height*=n)}function M(t,e,i){f.scale(t.__.path,e,i),t.path=t.__.path}function S(t,e,i){f.scalePoints(t.__.points,e,i),t.points=t.__.points}function T(t,e,i){const{children:o}=t;for(let t=0;t<o.length;t++)v.a=e,v.d=i,o[t].transform(v,!0)}const O=t.Leaf.prototype;function P(t,e,i,o){var s,n=arguments.length,r=n<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,o);else for(var a=t.length-1;a>=0;a--)(s=t[a])&&(r=(n<3?s(r):n>3?s(e,i,r):s(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}function H(t){return t?t instanceof Array?t:[t]:[]}O.scaleResize=function(t,e=t,i){const o=this;i||o.editConfig&&"scale"===o.editConfig.editSize?(o.scaleX*=t,o.scaleY*=e):(t<0&&(o.scaleX*=-1,t=-t),e<0&&(o.scaleY*=-1,e=-e),this.__scaleResize(t,e))},O.__scaleResize=function(t,e){x(this,t,e)},O.resizeWidth=function(t){const e=t/this.getBounds("box","local").width;this.scaleOf(this.__layout.boxBounds,e,this.__.lockRatio?e:1,!0)},O.resizeHeight=function(t){const e=t/this.getBounds("box","local").height;this.scaleOf(this.__layout.boxBounds,this.__.lockRatio?e:1,e,!0)},t.Text.prototype.__scaleResize=function(t,e){this.__.resizeFontSize||this.editConfig&&"font-size"===this.editConfig.editSize?k(this,t,e):x(this,t,e)},t.Path.prototype.__scaleResize=function(t,e){M(this,t,e)},t.Line.prototype.__scaleResize=function(t,e){this.pathInputed?M(this,t,e):this.points?S(this,t,e):this.width*=t},t.Polygon.prototype.__scaleResize=function(t,e){this.pathInputed?M(this,t,e):this.points?S(this,t,e):x(this,t,e)},t.Group.prototype.__scaleResize=function(t,e){T(this,t,e)},t.Box.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?T(this,t,e):(x(this,t,e),this.__.resizeChildren&&T(this,t,e))},"function"==typeof SuppressedError&&SuppressedError;class R extends t.Event{get list(){return H(this.value)}get oldList(){return H(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}R.SELECT="editor.select",R.HOVER="editor.hover";class B extends R{constructor(t,e){super(t,e)}}B.MOVE="editor.move";class C extends R{constructor(t,e){super(t,e)}}C.SCALE="editor.scale";class V extends R{constructor(t,e){super(t,e)}}V.ROTATE="editor.rotate";class I extends R{constructor(t,e){super(t,e)}}function D(e){return(i,o)=>{const s="_"+o;t.defineKey(i,o,{get(){return this[s]},set(t){const i=this[s];i!==t&&(this[s]=t,e(this,i))}})}}I.SKEW="editor.skew";const z=t.MatrixHelper.get(),{abs:A}=Math,{copy:Z,scale:W}=t.MatrixHelper;class G extends t.UI{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){this.set(e),this.target=t}__draw(e,i){const{list:o}=this;if(o.length){let s;const{stroke:n,strokeWidth:r,fill:a}=this.__,{bounds:l}=i;for(let h=0;h<o.length;h++)if(s=o[h],l&&l.hit(s.__world,i.matrix)){const o=A(s.__world.scaleX),l=A(s.__world.scaleY);if(o!==l){Z(z,s.__world),W(z,1/o,1/l),e.setWorld(z,i.matrix),e.beginPath(),this.__.strokeWidth=r;const{x:t,y:n,width:a,height:h}=s.__layout.boxBounds;e.rect(t*o,n*l,a*o,h*l)}else e.setWorld(s.__world,i.matrix),e.beginPath(),s.__.__useArrow?s.__drawPath(e):s.__.__pathForRender?s.__drawRenderPath(e):s.__drawPathByBox(e),this.__.strokeWidth=r/A(s.__world.scaleX);n&&("string"==typeof n?t.Paint.stroke(n,this,e):t.Paint.strokes(n,this,e)),a&&("string"==typeof a?t.Paint.fill(a,this,e):t.Paint.fills(a,this,e))}this.__.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}P([D((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],G.prototype,"target",void 0);class F extends t.Group{constructor(e){super(e),this.strokeArea=new t.Rect({strokeAlign:"center"}),this.fillArea=new t.Rect,this.visible=this.hittable=!1,this.addMany(this.fillArea,this.strokeArea)}setStyle(t,e){const{visible:i,stroke:o,strokeWidth:s}=t;this.visible=i,this.strokeArea.reset(Object.assign({stroke:o,strokeWidth:s},e||{})),this.fillArea.reset({visible:!e,fill:o,opacity:.2})}setBounds(t){this.strokeArea.set(t),this.fillArea.set(t)}}const{No:U,Yes:X,NoAndSkip:Y,YesAndSkip:K}=t.Answer,N={findOne:t=>t.list.find((t=>t.editable)),findBounds(t,e){if(t.__.hittable&&t.__.visible&&!t.__.locked&&e.hit(t.__world)){if(t.__.editable){if(t.isBranch&&!t.__.hitChildren)return t.__.hitSelf?K:Y;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?K:U;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return X}return U}return t.isBranch?Y:U}},{findOne:j}=N;class q extends t.Group{get dragging(){return!!this.originList}get running(){const{editor:t}=this;return this.hittable&&t.visible&&t.hittable&&t.mergeConfig.selector}get isMoveMode(){return this.app&&this.app.interaction.moveMode}constructor(e){super(),this.hoverStroker=new G,this.targetStroker=new G,this.bounds=new t.Bounds,this.selectArea=new F,this.__eventIds=[],this.editor=e,this.addMany(this.targetStroker,this.hoverStroker,this.selectArea),this.__listenEvents()}onHover(){const{editor:t}=this;if(!this.running||this.dragging||t.dragging)this.hoverStroker.target=null;else{const{stroke:e,strokeWidth:i,hover:o,hoverStyle:s}=t.mergeConfig;this.hoverStroker.setTarget(o?this.editor.hoverTarget:null,Object.assign({stroke:e,strokeWidth:i},s||{}))}}onSelect(){if(this.running){const{mergeConfig:t,list:e}=this.editor,{stroke:i,strokeWidth:o}=t;this.targetStroker.setTarget(e,{stroke:i,strokeWidth:Math.max(1,o/2)}),this.hoverStroker.target=null}}update(){this.targetStroker.target&&this.targetStroker.forceUpdate()}onPointerMove(t){const{app:e,editor:i}=this;if(this.running&&!this.isMoveMode&&e.interaction.canHover&&!e.interaction.dragging){const e=this.findUI(t);i.hoverTarget=i.hasItem(e)?null:e}this.isMoveMode&&(i.hoverTarget=null)}onBeforeDown(t){if(t.multiTouch)return;const{select:e}=this.editor.mergeConfig;"press"===e&&(this.app.config.mobile?this.waitSelect=()=>this.checkAndSelect(t):this.checkAndSelect(t))}onTap(t){if(t.multiTouch)return;const{editor:e}=this,{select:i}=e.mergeConfig;"tap"===i?this.checkAndSelect(t):this.waitSelect&&this.waitSelect(),this.needRemoveItem?e.removeItem(this.needRemoveItem):this.isMoveMode&&(e.target=null)}checkAndSelect(t){if(this.needRemoveItem=null,this.allowSelect(t)){const{editor:e}=this,i=this.findUI(t);i?this.isMultipleSelect(t)?e.hasItem(i)?this.needRemoveItem=i:e.addItem(i):e.target=i:this.allow(t.target)&&(t.shiftKey||(e.target=null))}}onDragStart(t){if(!t.multiTouch&&(this.waitSelect&&this.waitSelect(),this.allowDrag(t))){const{editor:e}=this,{stroke:i,area:o}=e.mergeConfig,{x:s,y:n}=t.getInnerPoint(this);this.bounds.set(s,n),this.selectArea.setStyle({visible:!0,stroke:i,x:s,y:n},o),this.selectArea.setBounds(this.bounds.get()),this.originList=e.leafList.clone()}}onDrag(e){if(!e.multiTouch){if(this.editor.dragging)return this.onDragEnd(e);if(this.dragging){const{editor:i}=this,o=e.getInnerTotal(this),s=this.bounds.clone().unsign(),n=new t.LeafList(i.app.find(N.findBounds,s));if(this.bounds.width=o.x,this.bounds.height=o.y,this.selectArea.setBounds(s.get()),n.length){const t=[];this.originList.forEach((e=>{n.has(e)||t.push(e)})),n.forEach((e=>{this.originList.has(e)||t.push(e)})),(t.length!==i.list.length||i.list.some(((e,i)=>e!==t[i])))&&(i.target=t)}else i.target=this.originList.list}}}onDragEnd(t){t.multiTouch||this.dragging&&(this.originList=null,this.selectArea.visible=!1)}onAutoMove(t){if(this.dragging){const{x:e,y:i}=t.getLocalMove(this);this.bounds.x+=e,this.bounds.y+=i}}allow(t){return t.leafer!==this.editor.leafer}allowDrag(t){return!(!this.running||!this.editor.mergeConfig.boxSelect||t.target.draggable)&&(!this.editor.editing&&this.allow(t.target)||t.shiftKey&&!j(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(e){const i={exclude:new t.LeafList(this.editor.editBox.rect)};return j(e.target.leafer.interaction.findPath(e,i))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):j(t.path)}isMultipleSelect(t){return t.shiftKey||this.editor.mergeConfig.continuousSelect}__listenEvents(){const{editor:t}=this;t.waitLeafer((()=>{const{app:i}=t;i.selector.proxy=t,this.__eventIds=[t.on_(R.HOVER,this.onHover,this),t.on_(R.SELECT,this.onSelect,this),i.on_(e.PointerEvent.MOVE,this.onPointerMove,this),i.on_(e.PointerEvent.BEFORE_DOWN,this.onBeforeDown,this),i.on_(e.PointerEvent.TAP,this.onTap,this),i.on_(e.DragEvent.START,this.onDragStart,this,!0),i.on_(e.DragEvent.DRAG,this.onDrag,this),i.on_(e.DragEvent.END,this.onDragEnd,this),i.on_(e.MoveEvent.MOVE,this.onAutoMove,this),i.on_([e.ZoomEvent.ZOOM,e.MoveEvent.MOVE],(()=>{this.editor.hoverTarget=null}))]}))}__removeListenEvents(){this.__eventIds&&(this.off_(this.__eventIds),this.__eventIds.length=0)}destroy(){this.editor=this.originList=this.needRemoveItem=null,this.__removeListenEvents(),super.destroy()}}const{topLeft:$,top:Q,topRight:J,right:tt,bottomRight:et,bottom:it,bottomLeft:ot,left:st}=t.Direction9,{toPoint:nt}=t.AroundHelper,{within:rt}=t.MathHelper,at={getScaleData(t,e,i,o,s,n,r,a){let l,h={},d=1,c=1;const{boxBounds:g,widthRange:u,heightRange:p}=t,{width:f,height:m}=e;n&&(o.x*=2,o.y*=2);const v=t.scaleX/e.scaleX,E=t.scaleY/e.scaleY,b=v<0?-1:1,y=E<0?-1:1,_=a?v:b*g.width/f,L=a?E:y*g.height/m;o.x*=a?v:b,o.y*=a?E:y,Math.abs(o.x)===f&&(o.x+=.1),Math.abs(o.y)===m&&(o.y+=.1);const w=(-o.y+m)/m,x=(o.x+f)/f,k=(o.y+m)/m,M=(-o.x+f)/f;switch(i){case Q:c=w,l="bottom";break;case tt:d=x,l="left";break;case it:c=k,l="top";break;case st:d=M,l="right";break;case $:c=w,d=M,l="bottom-right";break;case J:c=w,d=x,l="bottom-left";break;case et:c=k,d=x,l="top-left";break;case ot:c=k,d=M,l="top-right"}if(s){if(!("corner"===s&&i%2)){let t;switch(i){case Q:case it:t=c;break;case st:case tt:t=d;break;default:t=Math.sqrt(Math.abs(d*c))}d=d<0?-t:t,c=c<0?-t:t}}if(d/=_,c/=L,!r){const{worldTransform:e}=t;d<0&&(d=1/g.width/e.scaleX),c<0&&(c=1/g.height/e.scaleY)}if(u){const e=g.width*t.scaleX;d=rt(e*d,u)/e}if(p){const e=g.height*t.scaleY;c=rt(e*c,p)/e}return nt(n||l,g,h,!0),{origin:h,scaleX:d,scaleY:c,direction:i,lockRatio:s,around:n}},getRotateData(e,i,o,s,n){let r,a={};switch(i){case $:r="bottom-right";break;case J:r="bottom-left";break;case et:r="top-left";break;case ot:r="top-right";break;default:r="center"}return nt(n||r,e,a,!0),{origin:a,rotation:t.PointHelper.getRotation(s,a,o)}},getSkewData(e,i,o,s){let n,r,a={},l=0,h=0;switch(i){case Q:r={x:.5,y:0},n="bottom",l=1;break;case it:r={x:.5,y:1},n="top",l=1;break;case st:r={x:0,y:.5},n="right",h=1;break;case tt:r={x:1,y:.5},n="left",h=1}const{width:d,height:c}=e;r.x=r.x*d,r.y=r.y*c,nt(s||n,e,a,!0);const g=t.PointHelper.getRotation(r,a,{x:r.x+(l?o.x:0),y:r.y+(h?o.y:0)});return l?l=-g:h=g,{origin:a,skewX:l,skewY:h}},getAround:(t,e)=>e&&!t?"center":t,getRotateDirection:(t,e,i=8)=>((t=(t+Math.round(e/(360/i)))%i)<0&&(t+=i),t),getFlipDirection(t,e,i){if(e)switch(t){case st:t=tt;break;case $:t=J;break;case ot:t=et;break;case tt:t=st;break;case J:t=$;break;case et:t=ot}if(i)switch(t){case Q:t=it;break;case $:t=ot;break;case J:t=et;break;case it:t=Q;break;case ot:t=$;break;case et:t=J}return t}},lt={};function ht(e,i){const{editBox:o}=e,s=o.enterPoint;if(!s||!e.editing||!o.visible)return;if("circle"===s.name)return;if("button"===s.pointType)return void(s.cursor||(s.cursor="pointer"));let{rotation:n}=o;const{resizeCursor:r,rotateCursor:a,skewCursor:l,resizeable:h,rotateable:d,skewable:c}=e.mergeConfig,{pointType:g}=s,{flippedX:u,flippedY:p}=o;let f="resize"===g;f&&d&&(i.metaKey||i.ctrlKey||!h)&&(f=!1);const m=c&&!f&&"resize-line"===s.name?l:f?r:a;n+=45*(at.getFlipDirection(s.direction,u,p)+1),n=2*Math.round(t.MathHelper.formatRotation(n,!0)/2);const{url:v,x:E,y:b}=m,y=v+n;lt[y]?s.cursor=lt[y]:lt[y]=s.cursor={url:ct(v,n),x:E,y:b}}function dt(t){t.editBox.rect.cursor=t.mergeConfig.moveCursor}function ct(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class gt extends t.Box{}const ut=["top","right","bottom","left"];class pt extends t.Group{get flipped(){return this.flippedX||this.flippedY}get flippedX(){return this.scaleX<0}get flippedY(){return this.scaleY<0}get flippedOne(){return this.scaleX*this.scaleY<0}constructor(e){super(),this.view=new t.Group,this.rect=new t.Box({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new gt({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new t.Group({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.__eventIds=[],this.editor=e,this.visible=!1,this.create(),this.rect.syncEventer=e,this.__listenEvents()}create(){let t,e,i;const{view:o,resizePoints:s,rotatePoints:n,resizeLines:r,rect:a,circle:l,buttons:h}=this,d=["bottom-right","bottom","bottom-left","left","top-left","top","top-right","right"];for(let o=0;o<8;o++)t=new gt({name:"rotate-point",around:d[o],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",o),o%2&&(e=new gt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",o)),i=new gt({name:"resize-point",hitRadius:5}),s.push(i),this.listenPointEvents(i,"resize",o);this.listenPointEvents(l,"rotate",2),o.addMany(...n,a,l,h,...r,...s),this.add(o)}load(){const{mergeConfig:t,element:e,single:i}=this.editor,{rect:o,circle:s,resizePoints:n}=this,{stroke:r,strokeWidth:a,moveable:l}=t,h=this.getPointsStyle(),d=this.getMiddlePointsStyle();let c;for(let t=0;t<8;t++)c=n[t],c.set(this.getPointStyle(t%2?d[(t-1)/2%d.length]:h[t/2%h.length])),t%2||(c.rotation=t/2*90);s.set(this.getPointStyle(t.circle||t.rotatePoint||h[0])),o.set(Object.assign({stroke:r,strokeWidth:a},t.rect||{})),o.hittable=!i&&!!l,e.syncEventer=i&&l?o:null,this.app.interaction.bottomList=i&&l?[{target:o,proxy:e}]:null}update(e){if(this.visible=!this.editor.element.locked,this.view.worldOpacity){const{mergeConfig:i}=this.editor,{width:o,height:s}=e,{rect:n,circle:r,buttons:a,resizePoints:l,rotatePoints:h,resizeLines:d}=this,{middlePoint:c,resizeable:g,rotateable:u,hideOnSmall:p}=i,f="number"==typeof p?p:10,m=!(p&&o<f&&s<f);let v,E,b,y={};for(let n=0;n<8;n++)t.AroundHelper.toPoint(t.AroundHelper.directionData[n],e,y),E=l[n],v=h[n],b=d[Math.floor(n/2)],E.set(y),v.set(y),b.set(y),E.visible=b.visible=m&&!(!g&&!u),v.visible=m&&u&&g&&!i.rotatePoint,n%2&&(E.visible=v.visible=m&&!!c,(n+1)/2%2?(b.width=o,E.width>o-30&&(E.visible=!1)):(b.height=s,E.rotation=90,E.width>s-30&&(E.visible=!1)));r.visible=m&&u&&!(!i.circle&&!i.rotatePoint),r.visible&&this.layoutCircle(i),n.path&&(n.path=null),n.set(Object.assign(Object.assign({},e),{visible:!0})),a.visible=m&&a.children.length>0,a.visible&&this.layoutButtons(i)}}layoutCircle(t){const{circleDirection:e,circleMargin:i,buttonsMargin:o,buttonsDirection:s,middlePoint:n}=t,r=ut.indexOf(e||(this.buttons.children.length&&"bottom"===s?"top":"bottom"));this.setButtonPosition(this.circle,r,i||o,!!n)}layoutButtons(t){const{buttons:e}=this,{buttonsDirection:i,buttonsFixed:o,buttonsMargin:s,middlePoint:n}=t,{flippedX:r,flippedY:a}=this;let l=ut.indexOf(i);(l%2&&r||(l+1)%2&&a)&&o&&(l=(l+2)%4);const h=o?at.getRotateDirection(l,this.flippedOne?this.rotation:-this.rotation,4):l;this.setButtonPosition(e,h,s,!!n),o&&(e.rotation=90*(h-l)),e.scaleX=r?-1:1,e.scaleY=a?-1:1}setButtonPosition(t,e,i,o){const s=this.resizePoints[2*e+1],n=e%2,r=e&&3!==e?1:-1,a=(i+(e%2?(o?s.width:0)+t.boxBounds.width:(o?s.height:0)+t.boxBounds.height)/2)*r;n?(t.x=s.x+a,t.y=s.y):(t.x=s.x,t.y=s.y+a)}unload(){this.visible=!1}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:o,pointSize:s,pointRadius:n}=this.editor.mergeConfig,r={fill:o,stroke:e,strokeWidth:i,around:"center",strokeAlign:"center",width:s,height:s,cornerRadius:n};return t?Object.assign(r,t):r}getPointsStyle(){const{point:t}=this.editor.mergeConfig;return t instanceof Array?t:[t]}getMiddlePointsStyle(){const{middlePoint:t}=this.editor.mergeConfig;return t instanceof Array?t:t?[t]:this.getPointsStyle()}onSelect(t){1===t.oldList.length&&(t.oldList[0].syncEventer=null,this.app&&(this.app.interaction.bottomList=null))}onDragStart(t){this.dragging=!0;const{editor:e}=this;"rect"===t.current.name?(this.moving=!0,e.dragStartPoint={x:e.element.x,y:e.element.y},e.opacity=e.mergeConfig.hideOnMove?0:1):"resize"===t.current.pointType&&(e.dragStartBounds=Object.assign({},e.element.getLayoutBounds("box","local")),e.resizeDirection=t.current.direction)}onDragEnd(t){this.dragging=!1,this.moving=!1,"rect"===t.current.name&&(this.editor.opacity=1),this.editor.resizeDirection=void 0}onDrag(t){const{editor:e}=this,i=this.enterPoint=t.current;"rotate"===i.pointType||t.metaKey||t.ctrlKey||!e.mergeConfig.resizeable?e.mergeConfig.rotateable&&e.onRotate(t):"resize"===i.pointType&&e.onScale(t),ht(e,t)}onArrow(t){if(this.editor.editing&&this.editor.mergeConfig.keyEvent){const e={x:0,y:0},i=t.shiftKey?10:1;switch(t.code){case"ArrowDown":e.y=i;break;case"ArrowUp":e.y=-i;break;case"ArrowLeft":e.x=-i;break;case"ArrowRight":e.x=i}this.editor.move(e)}}onDoubleTap(t){"double"===this.editor.mergeConfig.openInner&&this.openInner(t)}onLongPress(t){"long"===this.editor.mergeConfig.openInner&&this.openInner(t)}openInner(t){const{editor:e}=this;if(e.single){const{element:i}=e;i.isBranch?(e.openGroup(i),e.target=e.selector.findDeepOne(t)):e.openInnerEditor()}}listenPointEvents(t,i,o){const{editor:s}=this;t.direction=o,t.pointType=i,t.on_(e.DragEvent.START,this.onDragStart,this),t.on_(e.DragEvent.DRAG,this.onDrag,this),t.on_(e.DragEvent.END,this.onDragEnd,this),t.on_(e.PointerEvent.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(e.PointerEvent.ENTER,(e=>{this.enterPoint=t,ht(s,e)}))}__listenEvents(){const{rect:t,editor:i}=this;this.__eventIds=[i.on_(R.SELECT,this.onSelect,this),t.on_(e.DragEvent.START,this.onDragStart,this),t.on_(e.DragEvent.DRAG,i.onMove,i),t.on_(e.DragEvent.END,this.onDragEnd,this),t.on_(e.PointerEvent.ENTER,(()=>dt(i))),t.on_(e.PointerEvent.DOUBLE_TAP,this.onDoubleTap,this),t.on_(e.PointerEvent.LONG_PRESS,this.onLongPress,this)]}__removeListenEvents(){this.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}class ft extends t.UI{constructor(t){super(),this.editor=t,this.hittable=!1}__draw(t,e){const{editor:i}=this,{mask:o}=i.mergeConfig;if(o&&i.list.length){const{rect:s}=i.editBox,{width:n,height:r}=s.__;t.resetTransform(),t.fillWorld(t.bounds,!0===o?"rgba(0,0,0,0.8)":o),t.setWorld(s.__world,e.matrix),t.clearRect(0,0,n,r)}}destroy(){this.editor=null,super.destroy()}}const mt='\n<feOffset dy="1"/>\n<feGaussianBlur stdDeviation="1.5"/>\n<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2 0"/>\n<feBlend mode="normal" in="SourceGraphic" result="shape"/>',vt={editSize:"size",keyEvent:!0,stroke:"#836DFF",strokeWidth:2,pointFill:"#FFFFFF",pointSize:10,pointRadius:16,rotateGap:45,buttonsDirection:"bottom",buttonsMargin:12,hideOnSmall:!0,moveCursor:"move",resizeCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate({{rotation}},12,12)">\n<path d="M7.5 8.0H8.5V5.9L6.8 7.2L7.5 8.0ZM3 11.4L2.3 10.6L1.3 11.4L2.3 12.2L3 11.4ZM7.5 10.4H6.5V11.4H7.5V10.4ZM16.5 10.4V11.4H17.5V10.4H16.5ZM16.5 8.0L17.1 7.2L15.5 5.9V8.0H16.5ZM21 11.4L21.6 12.2L22.6 11.4L21.6 10.6L21 11.4ZM16.5 14.9H15.5V16.9L17.1 15.7L16.5 14.9ZM16.5 12.4H17.5V11.4H16.5V12.4ZM7.5 12.4V11.4H6.5V12.4H7.5ZM7.5 14.9L6.8 15.7L8.5 16.9V14.9H7.5ZM6.8 7.2L2.3 10.6L3.6 12.2L8.1 8.7L6.8 7.2ZM8.5 10.4V8.0H6.5V10.4H8.5ZM16.5 9.4H7.5V11.4H16.5V9.4ZM17.5 10.4V8.0H15.5V10.4H17.5ZM15.8 8.7L20.3 12.2L21.6 10.6L17.1 7.2L15.8 8.7ZM20.3 10.6L15.8 14.1L17.1 15.7L21.6 12.2L20.3 10.6ZM17.5 14.9V12.4H15.5V14.9H17.5ZM7.5 13.4H16.5V11.4H7.5V13.4ZM8.5 14.9V12.4H6.5V14.9H8.5ZM2.3 12.2L6.8 15.7L8.1 14.1L3.6 10.6L2.3 12.2Z" fill="white"/>\n<path fill-rule="evenodd" d="M3 11.4L7.5 8.0V10.4H16.5V8.0L21 11.4L16.5 14.9V12.4H7.5V14.9L3 11.4Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="3.9" width="27.2" height="16.9" filterUnits="userSpaceOnUse">\n${mt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},rotateCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate(135,12,12),rotate({{rotation}},12,12)">\n<path d="M20.4 8H21.4L20.8 7.1L17.3 2.6L17 2.1L16.6 2.6L13.1 7.1L12.5 8H13.5H15.4C14.9 11.8 11.8 14.9 8 15.4V13.5V12.5L7.1 13.1L2.6 16.6L2.1 17L2.6 17.3L7.1 20.8L8 21.4V20.4V18.4C13.5 17.9 17.9 13.5 18.4 8H20.4Z" stroke="white"/>\n<path fill-rule="evenodd" d="M17 3L20.4 7.5H17.9C17.7 13.1 13.1 17.7 7.5 17.9V20.4L3 17L7.5 13.5V15.9C12.0 15.7 15.7 12.0 15.9 7.5H13.5L17 3Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="-0.6" width="27.1" height="27.1" filterUnits="userSpaceOnUse">\n${mt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},skewCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate(90,12,12),rotate({{rotation}},12,12)">\n<path d="M21 10.4L21 11.4L23.8 11.4L21.6 9.6L21 10.4ZM17 10.4V11.4L17 11.4L17 10.4ZM15.5 6L16.1 5.2L14.5 3.9V6H15.5ZM15.5 8.4V9.4H16.5V8.4H15.5ZM6 8.4V7.4H5V8.4H6ZM6 10.4H5V11.4H6V10.4ZM7 14.4V13.4L7 13.4L7 14.4ZM3 14.4L3 13.4L0.1 13.4L2.3 15.2L3 14.4ZM8.5 18.9L7.8 19.7L9.5 21.0V18.9H8.5ZM8.5 16.4V15.4H7.5V16.4H8.5ZM19 16.4V17.4H20V16.4H19ZM19 14.4H20V13.4H19V14.4ZM21 9.4L17 9.4L17 11.4L21 11.4L21 9.4ZM14.8 6.7L20.3 11.2L21.6 9.6L16.1 5.2L14.8 6.7ZM16.5 8.4V6H14.5V8.4H16.5ZM6 9.4H15.5V7.4H6V9.4ZM7 10.4V8.4H5V10.4H7ZM15.5 9.4H6V11.4H15.5V9.4ZM17 9.4H15.5V11.4H17V9.4ZM7 15.4H8.5V13.4H7V15.4ZM3 15.4L7 15.4L7 13.4L3 13.4L3 15.4ZM9.1 18.1L3.6 13.6L2.3 15.2L7.8 19.7L9.1 18.1ZM7.5 16.4V18.9H9.5V16.4H7.5ZM19 15.4H8.5V17.4H19V15.4ZM18 14.4V16.4H20V14.4H18ZM8.5 15.4H19V13.4H8.5V15.4Z" fill="white"/>\n<path fill-rule="evenodd" d="M17 10.4L21 10.4L15.5 6V8.4H6V10.4H15.5H17ZM8.5 14.4H7L3 14.4L8.5 18.9V16.4H19V14.4H8.5Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter x="-2.8" y="1.9" width="29.6" height="23.1" filterUnits="userSpaceOnUse" >\n${mt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,hover:!0,select:"press",openInner:"double",boxSelect:!0,moveable:!0,resizeable:!0,flipable:!0,rotateable:!0,skewable:!0};function Et(e){const{simulateTarget:i,leafList:o}=e,{x:s,y:n,width:r,height:a}=(new t.Bounds).setListWithFn(o.list,(t=>t.worldBoxBounds)),l=i.parent=o.list[0].leafer.zoomLayer,{scaleX:h,scaleY:d,e:c,f:g}=l.__world;i.reset({x:(s-c)/h,y:(n-g)/d,width:r/h,height:a/d})}const bt=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),yt=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),_t={group(e,i,o){e.sort(yt);const{app:s,parent:n}=e[0];let r;r=o&&o.add?o:new t.Group(o),n.addAt(r,n.children.indexOf(e[0])),e.sort(bt);const a=new t.Matrix(i.worldTransform);return a.divideParent(n.worldTransform),r.setTransform(a),r.editable=!0,r.hitChildren=!1,s.lockLayout(),e.forEach((t=>t.dropTo(r))),s.unlockLayout(),r},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach((t=>{if(t.isBranch){const{parent:e,children:o}=t;for(;o.length;)i.push(o[0]),o[0].dropTo(e,e.children.indexOf(t));t.remove()}else i.push(t)})),e.unlockLayout(),i},toTop(t){t.sort(bt),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(yt),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},Lt=t.Debug.get("EditToolCreator");function wt(){return t=>{kt.register(t)}}const xt=wt,kt={list:{},register(t){const{tag:e}=t.prototype;Mt[e]?Lt.repeat(e):Mt[e]=t},get:(t,e)=>new Mt[t](e)},{list:Mt}=kt;class St extends R{constructor(t,e){super(t,e)}}St.BEFORE_OPEN="innerEditor.before_open",St.OPEN="innerEditor.open",St.BEFORE_CLOSE="innerEditor.before_close",St.CLOSE="innerEditor.close";class Tt extends R{constructor(t,e){super(t,e)}}Tt.GROUP="editor.group",Tt.BEFORE_UNGROUP="editor.before_ungroup",Tt.UNGROUP="editor.ungroup",Tt.OPEN="editor.open_group",Tt.CLOSE="editor.close_group";class Ot extends t.Group{get mergeConfig(){const{element:t,config:e}=this;return this.single&&t.editConfig?Object.assign(Object.assign({},e),t.editConfig):e}get list(){return this.leafList.list}get editing(){return!!this.list.length}get groupOpening(){return!!this.openedGroupList.length}get multiple(){return this.list.length>1}get single(){return 1===this.list.length}get dragging(){return this.editBox.dragging}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}constructor(e,i){super(i),this.config=t.DataHelper.clone(vt),this.leafList=new t.LeafList,this.openedGroupList=new t.LeafList,this.simulateTarget=new t.Rect({visible:!1}),this.editBox=new pt(this),this.editToolList={},this.selector=new q(this),this.editMask=new ft(this),this.targetEventIds=[],e&&(this.config=t.DataHelper.default(e,this.config)),this.addMany(this.editMask,this.selector,this.editBox)}select(t){this.target=t}cancel(){this.target=null}hasItem(t){return this.leafList.has(t)}addItem(t){this.hasItem(t)||t.locked||(this.leafList.add(t),this.target=this.leafList.list)}removeItem(t){this.hasItem(t)&&(this.leafList.remove(t),this.target=this.leafList.list)}shiftItem(t){this.hasItem(t)?this.removeItem(t):this.addItem(t)}update(){this.editing&&(this.innerEditing&&this.innerEditor.update(),this.editTool.update(),this.selector.update())}updateEditBox(){this.multiple&&Et(this),this.update()}updateEditTool(){const t=this.editTool;if(t&&(this.editBox.unload(),t.unload(),this.editTool=null),this.editing){const t=this.single?this.list[0].editOuter:"EditTool";this.editTool=this.editToolList[t]=this.editToolList[t]||kt.get(t,this),this.editBox.load(),this.editTool.load()}}getEditSize(t){return this.mergeConfig.editSize}onMove(t){if(t instanceof e.MoveEvent){if("drag"!==t.moveType){const{moveable:e,resizeable:i}=this.mergeConfig,o=t.getLocalMove(this.element);"move"===e?(t.stop(),this.move(o.x,o.y)):"zoom"===i&&t.stop()}}else{const i={x:t.totalX,y:t.totalY};t.shiftKey&&(Math.abs(i.x)>Math.abs(i.y)?i.y=0:i.x=0),this.move(e.DragEvent.getValidMove(this.element,this.dragStartPoint,i))}}onScale(t){const{element:i}=this;let{around:o,lockRatio:s,resizeable:n,flipable:r,editSize:a}=this.mergeConfig;if(t instanceof e.ZoomEvent)"zoom"===n&&(t.stop(),this.scaleOf(i.getBoxPoint(t),t.scale,t.scale));else{const{direction:e}=t.current;(t.shiftKey||i.lockRatio)&&(s=!0);const n=at.getScaleData(i,this.dragStartBounds,e,t.getInnerTotal(i),s,at.getAround(o,t.altKey),r,this.multiple||"scale"===a);this.editTool.onScaleWithDrag?(n.drag=t,this.scaleWithDrag(n)):this.scaleOf(n.origin,n.scaleX,n.scaleY)}}onRotate(i){const{skewable:o,rotateable:s,around:n,rotateGap:r}=this.mergeConfig,{direction:a,name:l}=i.current;if(o&&"resize-line"===l)return this.onSkew(i);const{element:h}=this;let d,c;if(i instanceof e.RotateEvent){if("rotate"!==s)return;i.stop(),c=i.rotation,d=h.getBoxPoint(i)}else{const t={x:i.x-i.moveX,y:i.y-i.moveY},e=at.getRotateData(h.boxBounds,a,i.getBoxPoint(h),h.getBoxPoint(t),i.shiftKey?null:h.around||h.origin||n||"center");c=e.rotation,d=e.origin}c=t.MathHelper.getGapRotation(c,r,h.rotation),c&&(h.scaleX*h.scaleY<0&&(c=-c),this.rotateOf(d,t.MathHelper.float(c,2)))}onSkew(t){const{element:e}=this,{around:i}=this.mergeConfig,{origin:o,skewX:s,skewY:n}=at.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),at.getAround(i,t.altKey));(s||n)&&this.skewOf(o,s,n)}move(t,e=0){if(!this.mergeConfig.moveable||this.element.locked)return;const{element:i}=this,o=i.getWorldPointByLocal("object"==typeof t?Object.assign({},t):{x:t,y:e},null,!0),s=new B(B.MOVE,{target:i,editor:this,moveX:o.x,moveY:o.y});this.editTool.onMove(s),this.emitEvent(s),this.multiple&&i.move(t,e)}scaleWithDrag(t){if(!this.mergeConfig.resizeable||this.element.locked)return;const{element:e}=this,i=new C(C.SCALE,Object.assign(Object.assign({},t),{target:e,editor:this,worldOrigin:e.getWorldPoint(t.origin)}));this.editTool.onScaleWithDrag(i),this.emitEvent(i)}scaleOf(t,e,i=e,o){if(!this.mergeConfig.resizeable||this.element.locked)return;const{element:s}=this,n=this.getWorldOrigin(t),r=this.multiple&&this.getChangedTransform((()=>s.scaleOf(t,e,i))),a=new C(C.SCALE,{target:s,editor:this,worldOrigin:n,scaleX:e,scaleY:i,transform:r});this.editTool.onScale(a),this.emitEvent(a)}flip(e){if(this.element.locked)return;const{element:i}=this,o=this.getWorldOrigin("center"),s=this.multiple?this.getChangedTransform((()=>i.flip(e))):new t.Matrix(t.LeafHelper.getFlipTransform(i,e)),n=new C(C.SCALE,{target:i,editor:this,worldOrigin:o,scaleX:"x"===e?-1:1,scaleY:"y"===e?-1:1,transform:s});this.editTool.onScale(n),this.emitEvent(n)}rotateOf(t,e){if(!this.mergeConfig.rotateable||this.element.locked)return;const{element:i}=this,o=this.getWorldOrigin(t),s=this.multiple&&this.getChangedTransform((()=>i.rotateOf(t,e))),n=new V(V.ROTATE,{target:i,editor:this,worldOrigin:o,rotation:e,transform:s});this.editTool.onRotate(n),this.emitEvent(n)}skewOf(t,e,i=0,o){if(!this.mergeConfig.skewable||this.element.locked)return;const{element:s}=this,n=this.getWorldOrigin(t),r=this.multiple&&this.getChangedTransform((()=>s.skewOf(t,e,i))),a=new I(I.SKEW,{target:s,editor:this,worldOrigin:n,skewX:e,skewY:i,transform:r});this.editTool.onSkew(a),this.emitEvent(a)}getWorldOrigin(e){return this.element.getWorldPoint(t.LeafHelper.getInnerOrigin(this.element,e))}getChangedTransform(e){const{element:i}=this,o=new t.Matrix(i.worldTransform);return e(),new t.Matrix(i.worldTransform).divide(o)}group(t){return this.multiple&&(this.target=_t.group(this.list,this.element,t),this.emitGroupEvent(Tt.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach((t=>t.isBranch&&this.emitGroupEvent(Tt.BEFORE_UNGROUP,t))),this.target=_t.ungroup(t),t.forEach((t=>t.isBranch&&this.emitGroupEvent(Tt.UNGROUP,t)))),this.list}openGroup(t){this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(Tt.OPEN,t)}closeGroup(t){this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(Tt.CLOSE,t)}checkOpenedGroups(){const e=this.openedGroupList;if(e.length){let{list:i}=e;this.editing&&(i=[],e.forEach((e=>this.list.every((i=>!t.LeafHelper.hasParent(i,e)))&&i.push(e)))),i.forEach((t=>this.closeGroup(t)))}this.editing&&!this.selector.dragging&&this.checkDeepSelect()}checkDeepSelect(){let t,{list:e}=this;for(let i=0;i<e.length;i++)for(t=e[i].parent;t&&!t.hitChildren;)this.openGroup(t),t=t.parent}emitGroupEvent(t,e){const i=new Tt(t,{editTarget:e});this.emitEvent(i),e.emitEvent(i)}openInnerEditor(t){if(t&&(this.target=t),this.single){const t=this.element,e=t.editInner;e&&kt.list[e]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[e]||kt.get(e,this),this.innerEditor.editTarget=t,this.emitInnerEvent(St.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(St.OPEN))}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(St.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(St.CLOSE),this.editTool.load(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,o=new St(t,{editTarget:i,innerEditor:e});this.emitEvent(o),i.emitEvent(o)}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(_t.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(_t.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{leafer:i}=this.list[0];this.targetEventIds=[this.app.on_(e.MoveEvent.BEFORE_MOVE,this.onMove,this,!0),this.app.on_(e.ZoomEvent.BEFORE_ZOOM,this.onScale,this,!0),this.app.on_(e.RotateEvent.BEFORE_ROTATE,this.onRotate,this,!0),i.on_(t.RenderEvent.START,this.update,this),i.on_([e.KeyEvent.HOLD,e.KeyEvent.UP],(t=>{ht(this,t)})),i.on_(e.KeyEvent.DOWN,this.editBox.onArrow,this.editBox)]}}removeTargetEvents(){const{targetEventIds:t}=this;t.length&&(this.off_(t),t.length=0)}destroy(){this.destroyed||(this.simulateTarget.destroy(),Object.values(this.editToolList).forEach((t=>t.destroy())),this.editToolList={},this.target=this.hoverTarget=this.simulateTarget=this.editTool=this.innerEditor=null,super.destroy())}}P([D((function(t,e){t.emitEvent(new R(R.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],Ot.prototype,"hoverTarget",void 0),P([D((function(e,i){const{target:o}=e;o?e.leafList=o instanceof t.LeafList?o:new t.LeafList(o):(e.leafList.reset(),e.closeInnerEditor()),e.emitEvent(new R(R.SELECT,{editor:e,value:o,oldValue:i})),e.checkOpenedGroups(),e.editing?e.waitLeafer((()=>{e.multiple&&Et(e),dt(e),e.updateEditTool(),e.update(),e.listenTargetEvents()})):(e.updateEditTool(),e.removeTargetEvents())}))],Ot.prototype,"target",void 0);class Pt{static registerInnerEditor(){kt.register(this)}get tag(){return"InnerEditor"}get editBox(){return this.editor.editBox}constructor(t){this.editor=t,this.create()}onCreate(){}create(){this.view=new t.Group,this.onCreate()}onLoad(){}load(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!1,this.onLoad()}onUpdate(){}update(){this.onUpdate()}onUnload(){}unload(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!0,this.onUnload()}onDestroy(){}destroy(){this.onDestroy(),this.editor&&(this.view&&this.view.destroy(),this.eventIds&&this.editor.off_(this.eventIds),this.editor=this.view=this.eventIds=null)}}exports.EditTool=class extends Pt{static registerEditTool(){kt.register(this)}get tag(){return"EditTool"}onMove(t){const{moveX:e,moveY:i,editor:o}=t,{app:s,list:n}=o;s.lockLayout(),n.forEach((t=>{t.moveWorld(e,i)})),s.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:o,worldOrigin:s,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="scale"!==n.getEditSize(t);o?t.transformWorld(o,r):t.scaleOfWorld(s,e,i,r)})),r.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:o,editor:s}=t,{app:n,list:r}=s;n.lockLayout(),r.forEach((t=>{const n="scale"!==s.getEditSize(t);i?t.transformWorld(i,n):t.rotateOfWorld(o,e)})),n.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:o,worldOrigin:s,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="scale"!==n.getEditSize(t);o?t.transformWorld(o,r):t.skewOfWorld(s,e,i,r)})),r.unlockLayout()}load(){this.editBox.view.visible=!0,this.onLoad()}update(){const{editor:t,editBox:e}=this,{simulateTarget:i,element:o}=t;t.multiple&&i.parent.updateLayout();const{x:s,y:n,scaleX:r,scaleY:a,rotation:l,skewX:h,skewY:d,width:c,height:g}=o.getLayoutBounds("box",t,!0);e.set({x:s,y:n,scaleX:r,scaleY:a,rotation:l,skewX:h,skewY:d}),e.update({x:0,y:0,width:c,height:g}),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}},exports.EditTool=P([wt()],exports.EditTool);const{left:Ht,right:Rt}=t.Direction9,{move:Bt,copy:Ct}=t.PointHelper;exports.LineEditTool=class extends exports.EditTool{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(e){const{drag:i,direction:o,lockRatio:s,around:n}=e,r=e.target,a=o===Ht;if(r.pathInputed){const{path:t}=r.__,{from:e,to:o}=this.getFromToByPath(t);this.dragPoint(e,o,a,n,this.getInnerMove(r,i,s)),t[1]=e.x,t[2]=e.y,t[4]=o.x,t[5]=o.y,r.path=t}else if(r.points){const{points:t}=r,{from:e,to:o}=this.getFromToByPoints(t);this.dragPoint(e,o,a,n,this.getInnerMove(r,i,s)),t[0]=e.x,t[1]=e.y,t[2]=o.x,t[3]=o.y,r.points=t}else{const e=t.getPointData(),{toPoint:o}=r;r.rotation=0,this.dragPoint(e,o,a,n,this.getInnerMove(r,i,s)),r.getLocalPointByInner(e,null,null,!0),r.getLocalPointByInner(o,null,null,!0),r.x=e.x,r.y=e.y,r.getInnerPointByLocal(o,null,null,!0),r.toPoint=o}}getInnerMove(t,e,i){const o=e.getInnerMove(t);return i&&(Math.abs(o.x)>Math.abs(o.y)?o.y=0:o.x=0),o}getFromToByPath(t){return{from:{x:t[1],y:t[2]},to:{x:t[4],y:t[5]}}}getFromToByPoints(t){return{from:{x:t[0],y:t[1]},to:{x:t[2],y:t[3]}}}dragPoint(t,e,i,o,s){const{x:n,y:r}=s;i?(Bt(t,n,r),o&&Bt(e,-n,-r)):(o&&Bt(t,-n,-r),Bt(e,n,r))}onSkew(t){}onUpdate(){const{editBox:t}=this,{rotatePoints:e,resizeLines:i,resizePoints:o,rect:s}=t,n=this.editor.element;let r,a;if(n.pathInputed?r=this.getFromToByPath(n.__.path):n.points&&(r=this.getFromToByPoints(n.__.points)),r){const{from:i,to:a}=r;n.innerToWorld(i,i,!1,t),n.innerToWorld(a,a,!1,t),s.pen.clearPath().moveTo(i.x,i.y).lineTo(a.x,a.y),Ct(o[7],i),Ct(e[7],i),Ct(o[3],a),Ct(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===Ht||t===Rt,o[t].visible=a,e[t].visible=!r&&a}},exports.LineEditTool=P([wt()],exports.LineEditTool),t.Creator.editor=function(t){return new Ot(t)},t.UI.setEditConfig=function(e){t.defineKey(this.prototype,"editConfig",{get(){return"function"==typeof e?e(this):e}})},t.UI.setEditOuter=function(e){t.defineKey(this.prototype,"editOuter",{get(){return"string"==typeof e?e:e(this)}})},t.UI.setEditInner=function(e){t.defineKey(this.prototype,"editInner",{get(){return"string"==typeof e?e:e(this)}})},exports.EditBox=pt,exports.EditDataHelper=at,exports.EditPoint=gt,exports.EditSelect=q,exports.EditSelectHelper=N,exports.EditToolCreator=kt,exports.Editor=Ot,exports.EditorEvent=R,exports.EditorGroupEvent=Tt,exports.EditorHelper=_t,exports.EditorMoveEvent=B,exports.EditorRotateEvent=V,exports.EditorScaleEvent=C,exports.EditorSkewEvent=I,exports.InnerEditor=Pt,exports.InnerEditorEvent=St,exports.PathScaler=f,exports.SelectArea=F,exports.Stroker=G,exports.registerEditTool=wt,exports.registerInnerEditor=xt,exports.scaleResize=x,exports.scaleResizeFontSize=k,exports.scaleResizeGroup=T,exports.scaleResizePath=M,exports.scaleResizePoints=S;
1
+ "use strict";var t=require("@leafer-ui/draw"),e=require("@leafer-ui/core");const{M:i,L:o,C:s,Q:n,Z:r,N:a,D:h,X:l,G:c,F:d,O:g,P:u,U:p}=t.PathCommandMap,f={scale(t,e,f){if(!t)return;let v,E=0,b=t.length;for(;E<b;)switch(v=t[E],v){case i:case o:m(t,e,f,E,1),E+=3;break;case s:m(t,e,f,E,3),E+=7;break;case n:m(t,e,f,E,2),E+=5;break;case r:E+=1;break;case a:m(t,e,f,E,2),E+=5;break;case h:m(t,e,f,E,2),E+=9;break;case l:m(t,e,f,E,2),E+=6;break;case c:m(t,e,f,E,2),E+=9;break;case d:m(t,e,f,E,2),E+=5;break;case g:t[E]=c,t.splice(E+4,0,t[E+3],0),m(t,e,f,E,2),E+=9,b+=2;break;case u:t[E]=d,t.splice(E+4,0,t[E+3]),m(t,e,f,E,2),E+=5,b+=1;break;case p:m(t,e,f,E,2),E+=6}},scalePoints(t,e,i,o,s){for(let n=s?o+1:0,r=s?n+2*s:t.length;n<r;n+=2)t[n]*=e,t[n+1]*=i}},{scalePoints:m}=f,v=t.MatrixHelper.get(),{topLeft:E,top:b,topRight:y,right:L,bottom:x,left:w}=t.Direction9;function _(t,e,i){t.pathInputed?T(t,e,i):(1!==e&&(t.width*=e),1!==i&&(t.height*=i))}function k(t,e,i){const{app:o}=t,s=o&&o.editor;let n=e;if(s.editing){const o=t.__layout;let{width:r,height:a}=o.boxBounds;switch(r*=i-e,a*=e-i,s.resizeDirection){case b:case x:n=i,o.affectScaleOrRotation?t.moveInner(-r/2,0):t.x-=r/2;break;case w:case L:o.affectScaleOrRotation?t.moveInner(0,-a/2):t.y-=a/2;break;case E:case y:o.affectScaleOrRotation?t.moveInner(0,-a):t.y-=a}}t.fontSize*=n;const r=t.__;r.__autoWidth||(t.width*=n),r.__autoHeight||(t.height*=n)}function T(t,e,i){f.scale(t.__.path,e,i),t.path=t.__.path}function M(t,e,i){const{points:o}=t;"object"==typeof o[0]?o.forEach((t=>{t.x*=e,t.y*=i})):f.scalePoints(o,e,i),t.points=o}function O(t,e,i){const{children:o}=t;for(let t=0;t<o.length;t++)v.a=e,v.d=i,o[t].transform(v,!0)}const S=t.Leaf.prototype;function P(t,e,i,o){var s,n=arguments.length,r=n<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,o);else for(var a=t.length-1;a>=0;a--)(s=t[a])&&(r=(n<3?s(r):n>3?s(e,i,r):s(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}function C(t){return t?t instanceof Array?t:[t]:[]}S.scaleResize=function(t,e=t,i){const o=this;i||o.editConfig&&"scale"===o.editConfig.editSize?(o.scaleX*=t,o.scaleY*=e):(t<0&&(o.scaleX*=-1,t=-t),e<0&&(o.scaleY*=-1,e=-e),this.__scaleResize(t,e))},S.__scaleResize=function(t,e){_(this,t,e)},S.resizeWidth=function(t){const e=t/this.getBounds("box","local").width;this.scaleOf(this.__layout.boxBounds,e,this.__.lockRatio?e:1,!0)},S.resizeHeight=function(t){const e=t/this.getBounds("box","local").height;this.scaleOf(this.__layout.boxBounds,this.__.lockRatio?e:1,e,!0)},t.Text.prototype.__scaleResize=function(t,e){this.__.resizeFontSize||this.editConfig&&"font-size"===this.editConfig.editSize?k(this,t,e):_(this,t,e)},t.Path.prototype.__scaleResize=function(t,e){T(this,t,e)},t.Line.prototype.__scaleResize=function(t,e){this.pathInputed?T(this,t,e):this.points?M(this,t,e):this.width*=t},t.Polygon.prototype.__scaleResize=function(t,e){this.pathInputed?T(this,t,e):this.points?M(this,t,e):_(this,t,e)},t.Group.prototype.__scaleResize=function(t,e){O(this,t,e)},t.Box.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?O(this,t,e):(_(this,t,e),this.__.resizeChildren&&O(this,t,e))},"function"==typeof SuppressedError&&SuppressedError;class H extends t.Event{get list(){return C(this.value)}get oldList(){return C(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}H.SELECT="editor.select",H.HOVER="editor.hover";class R extends H{constructor(t,e){super(t,e)}}R.MOVE="editor.move";class B extends H{constructor(t,e){super(t,e)}}B.SCALE="editor.scale";class I extends H{constructor(t,e){super(t,e)}}I.ROTATE="editor.rotate";class V extends H{constructor(t,e){super(t,e)}}function D(e){return(i,o)=>{const s="_"+o;t.defineKey(i,o,{get(){return this[s]},set(t){const i=this[s];i!==t&&(this[s]=t,e(this,i))}})}}V.SKEW="editor.skew";const z=t.MatrixHelper.get(),{abs:A}=Math,{copy:Z,scale:W}=t.MatrixHelper;class G extends t.UI{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){this.set(e),this.target=t}__draw(e,i){const{list:o}=this;if(o.length){let s;const n=this.__,{stroke:r,strokeWidth:a,fill:h}=n,{bounds:l}=i;for(let c=0;c<o.length;c++){s=o[c];const{worldTransform:d,worldRenderBounds:g}=s;if(l&&l.hit(g,i.matrix)){const o=A(d.scaleX),l=A(d.scaleY);if(o!==l){Z(z,d),W(z,1/o,1/l),e.setWorld(z,i.matrix),e.beginPath(),n.strokeWidth=a;const{x:t,y:r,width:h,height:c}=s.__layout.boxBounds;e.rect(t*o,r*l,h*o,c*l)}else e.setWorld(d,i.matrix),e.beginPath(),s.__.__useArrow?s.__drawPath(e):s.__.__pathForRender?s.__drawRenderPath(e):s.__drawPathByBox(e),n.strokeWidth=a/A(d.scaleX);r&&("string"==typeof r?t.Paint.stroke(r,this,e):t.Paint.strokes(r,this,e)),h&&("string"==typeof h?t.Paint.fill(h,this,e):t.Paint.fills(h,this,e))}}n.strokeWidth=a}}destroy(){this.target=null,super.destroy()}}P([D((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],G.prototype,"target",void 0);class U extends t.Group{constructor(e){super(e),this.strokeArea=new t.Rect({strokeAlign:"center"}),this.fillArea=new t.Rect,this.visible=this.hittable=!1,this.addMany(this.fillArea,this.strokeArea)}setStyle(t,e){const{visible:i,stroke:o,strokeWidth:s}=t;this.visible=i,this.strokeArea.reset(Object.assign({stroke:o,strokeWidth:s},e||{})),this.fillArea.reset({visible:!e,fill:o,opacity:.2})}setBounds(t){this.strokeArea.set(t),this.fillArea.set(t)}}const{No:F,Yes:X,NoAndSkip:Y,YesAndSkip:K}=t.Answer,N={findOne:t=>t.list.find((t=>t.editable)),findBounds(t,e){if(t.__.hittable&&t.__.visible&&!t.__.locked&&e.hit(t.__world)){if(t.__.editable){if(t.isBranch&&!t.__.hitChildren)return t.__.hitSelf?K:Y;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?K:F;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return X}return F}return t.isBranch?Y:F}},{findOne:j}=N;class q extends t.Group{get dragging(){return!!this.originList}get running(){const{editor:t}=this;return this.hittable&&t.visible&&t.hittable&&t.mergeConfig.selector}get isMoveMode(){return this.app&&this.app.interaction.moveMode}constructor(e){super(),this.hoverStroker=new G,this.targetStroker=new G,this.bounds=new t.Bounds,this.selectArea=new U,this.__eventIds=[],this.editor=e,this.addMany(this.targetStroker,this.hoverStroker,this.selectArea),this.__listenEvents()}onHover(){const{editor:t}=this;if(!this.running||this.dragging||t.dragging)this.hoverStroker.target=null;else{const{stroke:e,strokeWidth:i,hover:o,hoverStyle:s}=t.mergeConfig;this.hoverStroker.setTarget(o?this.editor.hoverTarget:null,Object.assign({stroke:e,strokeWidth:i},s||{}))}}onSelect(){if(this.running){const{mergeConfig:t,list:e}=this.editor,{stroke:i,strokeWidth:o}=t;this.targetStroker.setTarget(e,{stroke:i,strokeWidth:Math.max(1,o/2)}),this.hoverStroker.target=null}}update(){this.targetStroker.target&&this.targetStroker.forceUpdate()}onPointerMove(t){const{app:e,editor:i}=this;if(this.running&&!this.isMoveMode&&e.interaction.canHover&&!e.interaction.dragging){const e=this.findUI(t);i.hoverTarget=i.hasItem(e)?null:e}this.isMoveMode&&(i.hoverTarget=null)}onBeforeDown(t){if(t.multiTouch)return;const{select:e}=this.editor.mergeConfig;"press"===e&&(this.app.config.mobile?this.waitSelect=()=>this.checkAndSelect(t):this.checkAndSelect(t))}onTap(t){if(t.multiTouch)return;const{editor:e}=this,{select:i}=e.mergeConfig;"tap"===i?this.checkAndSelect(t):this.waitSelect&&this.waitSelect(),this.needRemoveItem?e.removeItem(this.needRemoveItem):this.isMoveMode&&(e.target=null)}checkAndSelect(t){if(this.needRemoveItem=null,this.allowSelect(t)){const{editor:e}=this,i=this.findUI(t);i?this.isMultipleSelect(t)?e.hasItem(i)?this.needRemoveItem=i:e.addItem(i):e.target=i:this.allow(t.target)&&(t.shiftKey||(e.target=null))}}onDragStart(t){if(!t.multiTouch&&(this.waitSelect&&this.waitSelect(),this.allowDrag(t))){const{editor:e}=this,{stroke:i,area:o}=e.mergeConfig,{x:s,y:n}=t.getInnerPoint(this);this.bounds.set(s,n),this.selectArea.setStyle({visible:!0,stroke:i,x:s,y:n},o),this.selectArea.setBounds(this.bounds.get()),this.originList=e.leafList.clone()}}onDrag(e){if(!e.multiTouch){if(this.editor.dragging)return this.onDragEnd(e);if(this.dragging){const{editor:i}=this,o=e.getInnerTotal(this),s=this.bounds.clone().unsign(),n=new t.LeafList(i.app.find(N.findBounds,s));if(this.bounds.width=o.x,this.bounds.height=o.y,this.selectArea.setBounds(s.get()),n.length){const t=[];this.originList.forEach((e=>{n.has(e)||t.push(e)})),n.forEach((e=>{this.originList.has(e)||t.push(e)})),(t.length!==i.list.length||i.list.some(((e,i)=>e!==t[i])))&&(i.target=t)}else i.target=this.originList.list}}}onDragEnd(t){t.multiTouch||this.dragging&&(this.originList=null,this.selectArea.visible=!1)}onAutoMove(t){if(this.dragging){const{x:e,y:i}=t.getLocalMove(this);this.bounds.x+=e,this.bounds.y+=i}}allow(t){return t.leafer!==this.editor.leafer}allowDrag(t){return!(!this.running||!this.editor.mergeConfig.boxSelect||t.target.draggable)&&(!this.editor.editing&&this.allow(t.target)||t.shiftKey&&!j(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(e){const i={exclude:new t.LeafList(this.editor.editBox.rect)};return j(e.target.leafer.interaction.findPath(e,i))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):j(t.path)}isMultipleSelect(t){return t.shiftKey||this.editor.mergeConfig.continuousSelect}__listenEvents(){const{editor:t}=this;t.waitLeafer((()=>{const{app:i}=t;i.selector.proxy=t,this.__eventIds=[t.on_(H.HOVER,this.onHover,this),t.on_(H.SELECT,this.onSelect,this),i.on_(e.PointerEvent.MOVE,this.onPointerMove,this),i.on_(e.PointerEvent.BEFORE_DOWN,this.onBeforeDown,this),i.on_(e.PointerEvent.TAP,this.onTap,this),i.on_(e.DragEvent.START,this.onDragStart,this,!0),i.on_(e.DragEvent.DRAG,this.onDrag,this),i.on_(e.DragEvent.END,this.onDragEnd,this),i.on_(e.MoveEvent.MOVE,this.onAutoMove,this),i.on_([e.ZoomEvent.ZOOM,e.MoveEvent.MOVE],(()=>{this.editor.hoverTarget=null}))]}))}__removeListenEvents(){this.__eventIds&&(this.off_(this.__eventIds),this.__eventIds.length=0)}destroy(){this.editor=this.originList=this.needRemoveItem=null,this.__removeListenEvents(),super.destroy()}}const{topLeft:$,top:Q,topRight:J,right:tt,bottomRight:et,bottom:it,bottomLeft:ot,left:st}=t.Direction9,{toPoint:nt}=t.AroundHelper,{within:rt}=t.MathHelper,at={getScaleData(t,e,i,o,s,n,r,a){let h,l={},c=1,d=1;const{boxBounds:g,widthRange:u,heightRange:p}=t,{width:f,height:m}=e;n&&(o.x*=2,o.y*=2);const v=t.scaleX/e.scaleX,E=t.scaleY/e.scaleY,b=v<0?-1:1,y=E<0?-1:1,L=a?v:b*g.width/f,x=a?E:y*g.height/m;o.x*=a?v:b,o.y*=a?E:y,Math.abs(o.x)===f&&(o.x+=.1),Math.abs(o.y)===m&&(o.y+=.1);const w=(-o.y+m)/m,_=(o.x+f)/f,k=(o.y+m)/m,T=(-o.x+f)/f;switch(i){case Q:d=w,h="bottom";break;case tt:c=_,h="left";break;case it:d=k,h="top";break;case st:c=T,h="right";break;case $:d=w,c=T,h="bottom-right";break;case J:d=w,c=_,h="bottom-left";break;case et:d=k,c=_,h="top-left";break;case ot:d=k,c=T,h="top-right"}if(s){if(!("corner"===s&&i%2)){let t;switch(i){case Q:case it:t=d;break;case st:case tt:t=c;break;default:t=Math.sqrt(Math.abs(c*d))}c=c<0?-t:t,d=d<0?-t:t}}if(c/=L,d/=x,!r){const{worldTransform:e}=t;c<0&&(c=1/g.width/e.scaleX),d<0&&(d=1/g.height/e.scaleY)}if(u){const e=g.width*t.scaleX;c=rt(e*c,u)/e}if(p){const e=g.height*t.scaleY;d=rt(e*d,p)/e}return nt(n||h,g,l,!0),{origin:l,scaleX:c,scaleY:d,direction:i,lockRatio:s,around:n}},getRotateData(e,i,o,s,n){let r,a={};switch(i){case $:r="bottom-right";break;case J:r="bottom-left";break;case et:r="top-left";break;case ot:r="top-right";break;default:r="center"}return nt(n||r,e,a,!0),{origin:a,rotation:t.PointHelper.getRotation(s,a,o)}},getSkewData(e,i,o,s){let n,r,a={},h=0,l=0;switch(i){case Q:r={x:.5,y:0},n="bottom",h=1;break;case it:r={x:.5,y:1},n="top",h=1;break;case st:r={x:0,y:.5},n="right",l=1;break;case tt:r={x:1,y:.5},n="left",l=1}const{width:c,height:d}=e;r.x=r.x*c,r.y=r.y*d,nt(s||n,e,a,!0);const g=t.PointHelper.getRotation(r,a,{x:r.x+(h?o.x:0),y:r.y+(l?o.y:0)});return h?h=-g:l=g,{origin:a,skewX:h,skewY:l}},getAround:(t,e)=>e&&!t?"center":t,getRotateDirection:(t,e,i=8)=>((t=(t+Math.round(e/(360/i)))%i)<0&&(t+=i),t),getFlipDirection(t,e,i){if(e)switch(t){case st:t=tt;break;case $:t=J;break;case ot:t=et;break;case tt:t=st;break;case J:t=$;break;case et:t=ot}if(i)switch(t){case Q:t=it;break;case $:t=ot;break;case J:t=et;break;case it:t=Q;break;case ot:t=$;break;case et:t=J}return t}},ht={};function lt(e,i){const{editBox:o}=e,s=o.enterPoint;if(!s||!e.editing||!o.visible)return;if("circle"===s.name)return;if("button"===s.pointType)return void(s.cursor||(s.cursor="pointer"));let{rotation:n}=o;const{resizeCursor:r,rotateCursor:a,skewCursor:h,resizeable:l,rotateable:c,skewable:d}=e.mergeConfig,{pointType:g}=s,{flippedX:u,flippedY:p}=o;let f="resize"===g;f&&c&&(i.metaKey||i.ctrlKey||!l)&&(f=!1);const m=d&&!f&&"resize-line"===s.name?h:f?r:a;n+=45*(at.getFlipDirection(s.direction,u,p)+1),n=2*Math.round(t.MathHelper.formatRotation(n,!0)/2);const{url:v,x:E,y:b}=m,y=v+n;ht[y]?s.cursor=ht[y]:ht[y]=s.cursor={url:dt(v,n),x:E,y:b}}function ct(t){t.editBox.rect.cursor=t.mergeConfig.moveCursor}function dt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class gt extends t.Box{}const ut=["top","right","bottom","left"];class pt extends t.Group{get flipped(){return this.flippedX||this.flippedY}get flippedX(){return this.scaleX<0}get flippedY(){return this.scaleY<0}get flippedOne(){return this.scaleX*this.scaleY<0}constructor(e){super(),this.view=new t.Group,this.rect=new t.Box({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new gt({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new t.Group({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.__eventIds=[],this.editor=e,this.visible=!1,this.create(),this.__listenEvents()}create(){let t,e,i;const{view:o,resizePoints:s,rotatePoints:n,resizeLines:r,rect:a,circle:h,buttons:l}=this,c=["bottom-right","bottom","bottom-left","left","top-left","top","top-right","right"];for(let o=0;o<8;o++)t=new gt({name:"rotate-point",around:c[o],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",o),o%2&&(e=new gt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",o)),i=new gt({name:"resize-point",hitRadius:5}),s.push(i),this.listenPointEvents(i,"resize",o);this.listenPointEvents(h,"rotate",2),o.addMany(...n,a,h,l,...r,...s),this.add(o)}load(){const{mergeConfig:t,element:e,single:i}=this.editor,{rect:o,circle:s,resizePoints:n}=this,{stroke:r,strokeWidth:a,moveable:h}=t,l=this.getPointsStyle(),c=this.getMiddlePointsStyle();let d;for(let t=0;t<8;t++)d=n[t],d.set(this.getPointStyle(t%2?c[(t-1)/2%c.length]:l[t/2%l.length])),t%2||(d.rotation=t/2*90);s.set(this.getPointStyle(t.circle||t.rotatePoint||l[0])),o.set(Object.assign({stroke:r,strokeWidth:a},t.rect||{})),o.hittable=!i&&!!h,o.syncEventer=i&&this.editor,i&&h&&(e.syncEventer=o,this.app.interaction.bottomList=[{target:o,proxy:e}])}update(e){if(this.visible=!this.editor.element.locked,this.view.worldOpacity){const{mergeConfig:i}=this.editor,{width:o,height:s}=e,{rect:n,circle:r,buttons:a,resizePoints:h,rotatePoints:l,resizeLines:c}=this,{middlePoint:d,resizeable:g,rotateable:u,hideOnSmall:p}=i,f="number"==typeof p?p:10,m=!(p&&o<f&&s<f);let v,E,b,y={};for(let n=0;n<8;n++)t.AroundHelper.toPoint(t.AroundHelper.directionData[n],e,y),E=h[n],v=l[n],b=c[Math.floor(n/2)],E.set(y),v.set(y),b.set(y),E.visible=b.visible=m&&!(!g&&!u),v.visible=m&&u&&g&&!i.rotatePoint,n%2&&(E.visible=v.visible=m&&!!d,(n+1)/2%2?(b.width=o,E.width>o-30&&(E.visible=!1)):(b.height=s,E.rotation=90,E.width>s-30&&(E.visible=!1)));r.visible=m&&u&&!(!i.circle&&!i.rotatePoint),r.visible&&this.layoutCircle(i),n.path&&(n.path=null),n.set(Object.assign(Object.assign({},e),{visible:!0})),a.visible=m&&a.children.length>0,a.visible&&this.layoutButtons(i)}}layoutCircle(t){const{circleDirection:e,circleMargin:i,buttonsMargin:o,buttonsDirection:s,middlePoint:n}=t,r=ut.indexOf(e||(this.buttons.children.length&&"bottom"===s?"top":"bottom"));this.setButtonPosition(this.circle,r,i||o,!!n)}layoutButtons(t){const{buttons:e}=this,{buttonsDirection:i,buttonsFixed:o,buttonsMargin:s,middlePoint:n}=t,{flippedX:r,flippedY:a}=this;let h=ut.indexOf(i);(h%2&&r||(h+1)%2&&a)&&o&&(h=(h+2)%4);const l=o?at.getRotateDirection(h,this.flippedOne?this.rotation:-this.rotation,4):h;this.setButtonPosition(e,l,s,!!n),o&&(e.rotation=90*(l-h)),e.scaleX=r?-1:1,e.scaleY=a?-1:1}setButtonPosition(t,e,i,o){const s=this.resizePoints[2*e+1],n=e%2,r=e&&3!==e?1:-1,a=(i+(e%2?(o?s.width:0)+t.boxBounds.width:(o?s.height:0)+t.boxBounds.height)/2)*r;n?(t.x=s.x+a,t.y=s.y):(t.x=s.x,t.y=s.y+a)}unload(){this.visible=!1}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:o,pointSize:s,pointRadius:n}=this.editor.mergeConfig,r={fill:o,stroke:e,strokeWidth:i,around:"center",strokeAlign:"center",width:s,height:s,cornerRadius:n};return t?Object.assign(r,t):r}getPointsStyle(){const{point:t}=this.editor.mergeConfig;return t instanceof Array?t:[t]}getMiddlePointsStyle(){const{middlePoint:t}=this.editor.mergeConfig;return t instanceof Array?t:t?[t]:this.getPointsStyle()}onSelect(t){1===t.oldList.length&&(t.oldList[0].syncEventer=null,this.app&&(this.app.interaction.bottomList=null))}onDragStart(t){this.dragging=!0;const{editor:e}=this;"rect"===t.current.name?(this.moving=!0,e.dragStartPoint={x:e.element.x,y:e.element.y},e.opacity=e.mergeConfig.hideOnMove?0:1):"resize"===t.current.pointType&&(e.dragStartBounds=Object.assign({},e.element.getLayoutBounds("box","local")),e.resizeDirection=t.current.direction)}onDragEnd(t){this.dragging=!1,this.moving=!1,"rect"===t.current.name&&(this.editor.opacity=1),this.editor.resizeDirection=void 0}onDrag(t){const{editor:e}=this,i=this.enterPoint=t.current;"rotate"===i.pointType||t.metaKey||t.ctrlKey||!e.mergeConfig.resizeable?e.mergeConfig.rotateable&&e.onRotate(t):"resize"===i.pointType&&e.onScale(t),lt(e,t)}onArrow(t){if(this.editor.editing&&this.editor.mergeConfig.keyEvent){const e={x:0,y:0},i=t.shiftKey?10:1;switch(t.code){case"ArrowDown":e.y=i;break;case"ArrowUp":e.y=-i;break;case"ArrowLeft":e.x=-i;break;case"ArrowRight":e.x=i}this.editor.move(e)}}onDoubleTap(t){"double"===this.editor.mergeConfig.openInner&&this.openInner(t)}onLongPress(t){"long"===this.editor.mergeConfig.openInner&&this.openInner(t)}openInner(e){const{editor:i}=this;if(i.single){const{element:o}=i;if(o.isBranch){if(o.textBox){const e=o.children.find((e=>e.editable&&e instanceof t.Text));if(e)return i.openInnerEditor(e)}i.openGroup(o),i.target=i.selector.findDeepOne(e)}else i.openInnerEditor()}}listenPointEvents(t,i,o){const{editor:s}=this;t.direction=o,t.pointType=i,t.on_(e.DragEvent.START,this.onDragStart,this),t.on_(e.DragEvent.DRAG,this.onDrag,this),t.on_(e.DragEvent.END,this.onDragEnd,this),t.on_(e.PointerEvent.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(e.PointerEvent.ENTER,(e=>{this.enterPoint=t,lt(s,e)}))}__listenEvents(){const{rect:t,editor:i}=this;this.__eventIds=[i.on_(H.SELECT,this.onSelect,this),t.on_(e.DragEvent.START,this.onDragStart,this),t.on_(e.DragEvent.DRAG,i.onMove,i),t.on_(e.DragEvent.END,this.onDragEnd,this),t.on_(e.PointerEvent.ENTER,(()=>ct(i))),t.on_(e.PointerEvent.DOUBLE_TAP,this.onDoubleTap,this),t.on_(e.PointerEvent.LONG_PRESS,this.onLongPress,this)]}__removeListenEvents(){this.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}class ft extends t.UI{constructor(t){super(),this.editor=t,this.hittable=!1}__draw(t,e){const{editor:i}=this,{mask:o}=i.mergeConfig;if(o&&i.list.length){const{rect:s}=i.editBox,{width:n,height:r}=s.__;t.resetTransform(),t.fillWorld(t.bounds,!0===o?"rgba(0,0,0,0.8)":o),t.setWorld(s.__world,e.matrix),t.clearRect(0,0,n,r)}}destroy(){this.editor=null,super.destroy()}}const mt='\n<feOffset dy="1"/>\n<feGaussianBlur stdDeviation="1.5"/>\n<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2 0"/>\n<feBlend mode="normal" in="SourceGraphic" result="shape"/>',vt={editSize:"size",keyEvent:!0,stroke:"#836DFF",strokeWidth:2,pointFill:"#FFFFFF",pointSize:10,pointRadius:16,rotateGap:45,buttonsDirection:"bottom",buttonsMargin:12,hideOnSmall:!0,moveCursor:"move",resizeCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate({{rotation}},12,12)">\n<path d="M7.5 8.0H8.5V5.9L6.8 7.2L7.5 8.0ZM3 11.4L2.3 10.6L1.3 11.4L2.3 12.2L3 11.4ZM7.5 10.4H6.5V11.4H7.5V10.4ZM16.5 10.4V11.4H17.5V10.4H16.5ZM16.5 8.0L17.1 7.2L15.5 5.9V8.0H16.5ZM21 11.4L21.6 12.2L22.6 11.4L21.6 10.6L21 11.4ZM16.5 14.9H15.5V16.9L17.1 15.7L16.5 14.9ZM16.5 12.4H17.5V11.4H16.5V12.4ZM7.5 12.4V11.4H6.5V12.4H7.5ZM7.5 14.9L6.8 15.7L8.5 16.9V14.9H7.5ZM6.8 7.2L2.3 10.6L3.6 12.2L8.1 8.7L6.8 7.2ZM8.5 10.4V8.0H6.5V10.4H8.5ZM16.5 9.4H7.5V11.4H16.5V9.4ZM17.5 10.4V8.0H15.5V10.4H17.5ZM15.8 8.7L20.3 12.2L21.6 10.6L17.1 7.2L15.8 8.7ZM20.3 10.6L15.8 14.1L17.1 15.7L21.6 12.2L20.3 10.6ZM17.5 14.9V12.4H15.5V14.9H17.5ZM7.5 13.4H16.5V11.4H7.5V13.4ZM8.5 14.9V12.4H6.5V14.9H8.5ZM2.3 12.2L6.8 15.7L8.1 14.1L3.6 10.6L2.3 12.2Z" fill="white"/>\n<path fill-rule="evenodd" d="M3 11.4L7.5 8.0V10.4H16.5V8.0L21 11.4L16.5 14.9V12.4H7.5V14.9L3 11.4Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="3.9" width="27.2" height="16.9" filterUnits="userSpaceOnUse">\n${mt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},rotateCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate(135,12,12),rotate({{rotation}},12,12)">\n<path d="M20.4 8H21.4L20.8 7.1L17.3 2.6L17 2.1L16.6 2.6L13.1 7.1L12.5 8H13.5H15.4C14.9 11.8 11.8 14.9 8 15.4V13.5V12.5L7.1 13.1L2.6 16.6L2.1 17L2.6 17.3L7.1 20.8L8 21.4V20.4V18.4C13.5 17.9 17.9 13.5 18.4 8H20.4Z" stroke="white"/>\n<path fill-rule="evenodd" d="M17 3L20.4 7.5H17.9C17.7 13.1 13.1 17.7 7.5 17.9V20.4L3 17L7.5 13.5V15.9C12.0 15.7 15.7 12.0 15.9 7.5H13.5L17 3Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="-0.6" width="27.1" height="27.1" filterUnits="userSpaceOnUse">\n${mt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},skewCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate(90,12,12),rotate({{rotation}},12,12)">\n<path d="M21 10.4L21 11.4L23.8 11.4L21.6 9.6L21 10.4ZM17 10.4V11.4L17 11.4L17 10.4ZM15.5 6L16.1 5.2L14.5 3.9V6H15.5ZM15.5 8.4V9.4H16.5V8.4H15.5ZM6 8.4V7.4H5V8.4H6ZM6 10.4H5V11.4H6V10.4ZM7 14.4V13.4L7 13.4L7 14.4ZM3 14.4L3 13.4L0.1 13.4L2.3 15.2L3 14.4ZM8.5 18.9L7.8 19.7L9.5 21.0V18.9H8.5ZM8.5 16.4V15.4H7.5V16.4H8.5ZM19 16.4V17.4H20V16.4H19ZM19 14.4H20V13.4H19V14.4ZM21 9.4L17 9.4L17 11.4L21 11.4L21 9.4ZM14.8 6.7L20.3 11.2L21.6 9.6L16.1 5.2L14.8 6.7ZM16.5 8.4V6H14.5V8.4H16.5ZM6 9.4H15.5V7.4H6V9.4ZM7 10.4V8.4H5V10.4H7ZM15.5 9.4H6V11.4H15.5V9.4ZM17 9.4H15.5V11.4H17V9.4ZM7 15.4H8.5V13.4H7V15.4ZM3 15.4L7 15.4L7 13.4L3 13.4L3 15.4ZM9.1 18.1L3.6 13.6L2.3 15.2L7.8 19.7L9.1 18.1ZM7.5 16.4V18.9H9.5V16.4H7.5ZM19 15.4H8.5V17.4H19V15.4ZM18 14.4V16.4H20V14.4H18ZM8.5 15.4H19V13.4H8.5V15.4Z" fill="white"/>\n<path fill-rule="evenodd" d="M17 10.4L21 10.4L15.5 6V8.4H6V10.4H15.5H17ZM8.5 14.4H7L3 14.4L8.5 18.9V16.4H19V14.4H8.5Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter x="-2.8" y="1.9" width="29.6" height="23.1" filterUnits="userSpaceOnUse" >\n${mt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,hover:!0,select:"press",openInner:"double",boxSelect:!0,moveable:!0,resizeable:!0,flipable:!0,rotateable:!0,skewable:!0},Et=new t.Bounds;function bt(t){const{simulateTarget:e,list:i}=t,{zoomLayer:o}=i[0].leafer.zoomLayer;e.safeChange((()=>e.reset(Et.setListWithFn(i,(t=>t.getBounds("box","page"))).get()))),o.add(e)}const yt=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),Lt=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),xt={group(e,i,o){e.sort(Lt);const{app:s,parent:n}=e[0];let r;r=o&&o.add?o:new t.Group(o),n.addAt(r,n.children.indexOf(e[0])),e.sort(yt);const a=new t.Matrix(i.worldTransform);return a.divideParent(n.worldTransform),r.setTransform(a),r.editable=!0,r.hitChildren=!1,s.lockLayout(),e.forEach((t=>t.dropTo(r))),s.unlockLayout(),r},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach((t=>{if(t.isBranch&&!t.isBranchLeaf){const{parent:e,children:o}=t;for(;o.length;)i.push(o[0]),o[0].dropTo(e,e.children.indexOf(t));t.remove()}else i.push(t)})),e.unlockLayout(),i},toTop(t){t.sort(yt),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(Lt),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},wt=t.Debug.get("EditToolCreator");function _t(){return t=>{Tt.register(t)}}const kt=_t,Tt={list:{},register(t){const{tag:e}=t.prototype;Mt[e]?wt.repeat(e):Mt[e]=t},get:(t,e)=>new Mt[t](e)},{list:Mt}=Tt;class Ot extends H{constructor(t,e){super(t,e)}}Ot.BEFORE_OPEN="innerEditor.before_open",Ot.OPEN="innerEditor.open",Ot.BEFORE_CLOSE="innerEditor.before_close",Ot.CLOSE="innerEditor.close";class St extends H{constructor(t,e){super(t,e)}}St.GROUP="editor.group",St.BEFORE_UNGROUP="editor.before_ungroup",St.UNGROUP="editor.ungroup",St.OPEN="editor.open_group",St.CLOSE="editor.close_group";const{updateMatrix:Pt}=t.LeafHelper,Ct={x:1,y:1,scaleX:1,scaleY:1,rotation:1,skewX:1,skewY:1},Ht="top-left";class Rt extends t.Rect{get __tag(){return"SimulateElement"}constructor(e){super(),this.checkChange=!0,this.canChange=!0,this.visible=this.hittable=!1,this.on(t.PropertyEvent.CHANGE,(i=>{if(this.checkChange&&Ct[i.attrName]){const{attrName:o,newValue:s,oldValue:n}=i,r="s"===o[0]?(s||1)/(n||1):(s||0)-(n||0);this.canChange=!1;const a=this.__;a[o]=n,Pt(this.parent),Pt(this);const h=new t.Matrix(this.__world);switch(a[o]=s,this.__layout.rotationChange(),Pt(this),this.changedTransform=new t.Matrix(this.__world).divide(h),o){case"x":e.move(r,0);break;case"y":e.move(0,r);break;case"rotation":e.rotateOf(Ht,r);break;case"scaleX":e.scaleOf(Ht,r,1);break;case"scaleY":e.scaleOf(Ht,1,r);break;case"skewX":e.skewOf(Ht,r,0);break;case"skewY":e.skewOf(Ht,0,r)}this.canChange=!0}}))}safeChange(t){this.canChange&&(this.checkChange=!1,t(),this.checkChange=!0)}}class Bt extends t.Group{get mergeConfig(){const{element:t,config:e}=this;return this.single&&t.editConfig?Object.assign(Object.assign({},e),t.editConfig):e}get list(){return this.leafList.list}get dragHoverExclude(){return[this.editBox.rect]}get editing(){return!!this.list.length}get groupOpening(){return!!this.openedGroupList.length}get multiple(){return this.list.length>1}get single(){return 1===this.list.length}get dragging(){return this.editBox.dragging}get moving(){return this.editBox.moving}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}constructor(e,i){super(i),this.config=t.DataHelper.clone(vt),this.leafList=new t.LeafList,this.openedGroupList=new t.LeafList,this.simulateTarget=new Rt(this),this.editBox=new pt(this),this.editToolList={},this.selector=new q(this),this.editMask=new ft(this),this.targetEventIds=[],e&&(this.config=t.DataHelper.default(e,this.config)),this.addMany(this.editMask,this.selector,this.editBox)}select(t){this.target=t}cancel(){this.target=null}hasItem(t){return this.leafList.has(t)}addItem(t){this.hasItem(t)||t.locked||(this.leafList.add(t),this.target=this.leafList.list)}removeItem(t){this.hasItem(t)&&(this.leafList.remove(t),this.target=this.leafList.list)}shiftItem(t){this.hasItem(t)?this.removeItem(t):this.addItem(t)}update(){this.editing&&(this.innerEditing&&this.innerEditor.update(),this.editTool.update(),this.selector.update())}updateEditBox(){this.multiple&&bt(this),this.update()}updateEditTool(){const t=this.editTool;if(t&&(this.editBox.unload(),t.unload(),this.editTool=null),this.editing){const t=this.single?this.list[0].editOuter:"EditTool";this.editTool=this.editToolList[t]=this.editToolList[t]||Tt.get(t,this),this.editBox.load(),this.editTool.load()}}getEditSize(t){return this.mergeConfig.editSize}onMove(t){if(t instanceof e.MoveEvent){if("drag"!==t.moveType){const{moveable:e,resizeable:i}=this.mergeConfig,o=t.getLocalMove(this.element);"move"===e?(t.stop(),this.move(o.x,o.y)):"zoom"===i&&t.stop()}}else{const i={x:t.totalX,y:t.totalY};t.shiftKey&&(Math.abs(i.x)>Math.abs(i.y)?i.y=0:i.x=0),this.move(e.DragEvent.getValidMove(this.element,this.dragStartPoint,i))}}onScale(t){const{element:i}=this;let{around:o,lockRatio:s,resizeable:n,flipable:r,editSize:a}=this.mergeConfig;if(t instanceof e.ZoomEvent)"zoom"===n&&(t.stop(),this.scaleOf(i.getBoxPoint(t),t.scale,t.scale));else{const{direction:e}=t.current;(t.shiftKey||i.lockRatio)&&(s=!0);const n=at.getScaleData(i,this.dragStartBounds,e,t.getInnerTotal(i),s,at.getAround(o,t.altKey),r,this.multiple||"scale"===a);this.editTool.onScaleWithDrag?(n.drag=t,this.scaleWithDrag(n)):this.scaleOf(n.origin,n.scaleX,n.scaleY)}}onRotate(i){const{skewable:o,rotateable:s,around:n,rotateGap:r}=this.mergeConfig,{direction:a,name:h}=i.current;if(o&&"resize-line"===h)return this.onSkew(i);const{element:l}=this;let c,d;if(i instanceof e.RotateEvent){if("rotate"!==s)return;i.stop(),d=i.rotation,c=l.getBoxPoint(i)}else{const t={x:i.x-i.moveX,y:i.y-i.moveY},e=at.getRotateData(l.boxBounds,a,i.getBoxPoint(l),l.getBoxPoint(t),i.shiftKey?null:l.around||l.origin||n||"center");d=e.rotation,c=e.origin}d=t.MathHelper.getGapRotation(d,r,l.rotation),d&&(l.scaleX*l.scaleY<0&&(d=-d),this.rotateOf(c,t.MathHelper.float(d,2)))}onSkew(t){const{element:e}=this,{around:i}=this.mergeConfig,{origin:o,skewX:s,skewY:n}=at.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),at.getAround(i,t.altKey));(s||n)&&this.skewOf(o,s,n)}move(t,e=0){if(!this.checkTransform("moveable"))return;const{element:i}=this,o=i.getWorldPointByLocal("object"==typeof t?Object.assign({},t):{x:t,y:e},null,!0);this.multiple&&i.safeChange((()=>i.move(t,e)));const s=new R(R.MOVE,{target:i,editor:this,moveX:o.x,moveY:o.y});this.editTool.onMove(s),this.emitEvent(s)}scaleWithDrag(t){if(!this.checkTransform("resizeable"))return;const{element:e}=this,i=new B(B.SCALE,Object.assign(Object.assign({},t),{target:e,editor:this,worldOrigin:e.getWorldPoint(t.origin)}));this.editTool.onScaleWithDrag(i),this.emitEvent(i)}scaleOf(t,e,i=e,o){if(!this.checkTransform("resizeable"))return;const{element:s}=this,n=this.getWorldOrigin(t),r=this.multiple&&this.getChangedTransform((()=>s.safeChange((()=>s.scaleOf(t,e,i))))),a=new B(B.SCALE,{target:s,editor:this,worldOrigin:n,scaleX:e,scaleY:i,transform:r});this.editTool.onScale(a),this.emitEvent(a)}flip(e){if(!this.checkTransform("resizeable"))return;const{element:i}=this,o=this.getWorldOrigin("center"),s=this.multiple?this.getChangedTransform((()=>i.safeChange((()=>i.flip(e))))):new t.Matrix(t.LeafHelper.getFlipTransform(i,e)),n=new B(B.SCALE,{target:i,editor:this,worldOrigin:o,scaleX:"x"===e?-1:1,scaleY:"y"===e?-1:1,transform:s});this.editTool.onScale(n),this.emitEvent(n)}rotateOf(t,e){if(!this.checkTransform("rotateable"))return;const{element:i}=this,o=this.getWorldOrigin(t),s=this.multiple&&this.getChangedTransform((()=>i.safeChange((()=>i.rotateOf(t,e))))),n=new I(I.ROTATE,{target:i,editor:this,worldOrigin:o,rotation:e,transform:s});this.editTool.onRotate(n),this.emitEvent(n)}skewOf(t,e,i=0,o){if(!this.checkTransform("skewable"))return;const{element:s}=this,n=this.getWorldOrigin(t),r=this.multiple&&this.getChangedTransform((()=>s.safeChange((()=>s.skewOf(t,e,i))))),a=new V(V.SKEW,{target:s,editor:this,worldOrigin:n,skewX:e,skewY:i,transform:r});this.editTool.onSkew(a),this.emitEvent(a)}checkTransform(t){return this.element&&!this.element.locked&&this.mergeConfig[t]}getWorldOrigin(e){return this.element.getWorldPoint(t.LeafHelper.getInnerOrigin(this.element,e))}getChangedTransform(e){const{element:i}=this;if(this.multiple&&!i.canChange)return i.changedTransform;const o=new t.Matrix(i.worldTransform);return e(),new t.Matrix(i.worldTransform).divide(o)}group(t){return this.multiple&&(this.target=xt.group(this.list,this.element,t),this.emitGroupEvent(St.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach((t=>t.isBranch&&this.emitGroupEvent(St.BEFORE_UNGROUP,t))),this.target=xt.ungroup(t),t.forEach((t=>t.isBranch&&this.emitGroupEvent(St.UNGROUP,t)))),this.list}openGroup(t){this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(St.OPEN,t)}closeGroup(t){this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(St.CLOSE,t)}checkOpenedGroups(){const e=this.openedGroupList;if(e.length){let{list:i}=e;this.editing&&(i=[],e.forEach((e=>this.list.every((i=>!t.LeafHelper.hasParent(i,e)))&&i.push(e)))),i.forEach((t=>this.closeGroup(t)))}this.editing&&!this.selector.dragging&&this.checkDeepSelect()}checkDeepSelect(){let t,{list:e}=this;for(let i=0;i<e.length;i++)for(t=e[i].parent;t&&!t.hitChildren;)this.openGroup(t),t=t.parent}emitGroupEvent(t,e){const i=new St(t,{editTarget:e});this.emitEvent(i),e.emitEvent(i)}openInnerEditor(t,e){if(t&&e&&(this.target=t),this.single){const e=t||this.element,i=e.editInner;i&&Tt.list[i]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[i]||Tt.get(i,this),this.innerEditor.editTarget=e,this.emitInnerEvent(Ot.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(Ot.OPEN))}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(Ot.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(Ot.CLOSE),this.editTool.load(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,o=new Ot(t,{editTarget:i,innerEditor:e});this.emitEvent(o),i.emitEvent(o)}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(xt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(xt.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{app:i,leafer:o}=this;this.targetEventIds=[o.on_(t.RenderEvent.START,this.update,this),i.on_(t.RenderEvent.CHILD_START,this.forceRender,this),i.on_(e.MoveEvent.BEFORE_MOVE,this.onMove,this,!0),i.on_(e.ZoomEvent.BEFORE_ZOOM,this.onScale,this,!0),i.on_(e.RotateEvent.BEFORE_ROTATE,this.onRotate,this,!0),i.on_([e.KeyEvent.HOLD,e.KeyEvent.UP],(t=>{lt(this,t)})),i.on_(e.KeyEvent.DOWN,this.editBox.onArrow,this.editBox)]}}removeTargetEvents(){const{targetEventIds:t}=this;t.length&&(this.off_(t),t.length=0)}destroy(){this.destroyed||(this.simulateTarget.destroy(),Object.values(this.editToolList).forEach((t=>t.destroy())),this.editToolList={},this.target=this.hoverTarget=null,this.simulateTarget=this.editTool=this.innerEditor=null,super.destroy())}}P([D((function(t,e){t.emitEvent(new H(H.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],Bt.prototype,"hoverTarget",void 0),P([D((function(e,i){const{target:o}=e;o?e.leafList=o instanceof t.LeafList?o:new t.LeafList(o):(e.simulateTarget.remove(),e.leafList.reset(),e.closeInnerEditor()),e.emitEvent(new H(H.SELECT,{editor:e,value:o,oldValue:i})),e.checkOpenedGroups(),e.editing?e.waitLeafer((()=>{e.multiple&&bt(e),ct(e),e.updateEditTool(),e.update(),e.listenTargetEvents()})):(e.updateEditTool(),e.removeTargetEvents())}))],Bt.prototype,"target",void 0);class It{static registerInnerEditor(){Tt.register(this)}get tag(){return"InnerEditor"}get editBox(){return this.editor.editBox}constructor(t){this.editor=t,this.create()}onCreate(){}create(){this.view=new t.Group,this.onCreate()}onLoad(){}load(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!1,this.onLoad()}onUpdate(){}update(){this.onUpdate()}onUnload(){}unload(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!0,this.onUnload()}onDestroy(){}destroy(){this.onDestroy(),this.editor&&(this.view&&this.view.destroy(),this.eventIds&&this.editor.off_(this.eventIds),this.editor=this.view=this.eventIds=null)}}exports.EditTool=class extends It{static registerEditTool(){Tt.register(this)}get tag(){return"EditTool"}onMove(t){const{moveX:e,moveY:i,editor:o}=t,{app:s,list:n}=o;s.lockLayout(),n.forEach((t=>{t.moveWorld(e,i)})),s.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:o,worldOrigin:s,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="scale"!==n.getEditSize(t);o?t.transformWorld(o,r):t.scaleOfWorld(s,e,i,r)})),r.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:o,editor:s}=t,{app:n,list:r}=s;n.lockLayout(),r.forEach((t=>{const n="scale"!==s.getEditSize(t);i?t.transformWorld(i,n):t.rotateOfWorld(o,e)})),n.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:o,worldOrigin:s,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="scale"!==n.getEditSize(t);o?t.transformWorld(o,r):t.skewOfWorld(s,e,i,r)})),r.unlockLayout()}load(){this.editBox.view.visible=!0,this.onLoad()}update(){const{editor:t,editBox:e}=this,{x:i,y:o,scaleX:s,scaleY:n,rotation:r,skewX:a,skewY:h,width:l,height:c}=t.element.getLayoutBounds("box",t,!0);e.set({x:i,y:o,scaleX:s,scaleY:n,rotation:r,skewX:a,skewY:h}),e.update({x:0,y:0,width:l,height:c}),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}},exports.EditTool=P([_t()],exports.EditTool);const{left:Vt,right:Dt}=t.Direction9,{move:zt,copy:At,toNumberPoints:Zt}=t.PointHelper;exports.LineEditTool=class extends exports.EditTool{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(e){const{drag:i,direction:o,lockRatio:s,around:n}=e,r=e.target,a=o===Vt;if(r.pathInputed){const{path:t}=r.__,{from:e,to:o}=this.getFromToByPath(t);this.dragPoint(e,o,a,n,this.getInnerMove(r,i,s)),t[1]=e.x,t[2]=e.y,t[4]=o.x,t[5]=o.y,r.path=t}else if(r.points){const{points:t}=r,{from:e,to:o}=this.getFromToByPoints(t);this.dragPoint(e,o,a,n,this.getInnerMove(r,i,s)),t[0]=e.x,t[1]=e.y,t[2]=o.x,t[3]=o.y,r.points=t}else{const e=t.getPointData(),{toPoint:o}=r;r.rotation=0,this.dragPoint(e,o,a,n,this.getInnerMove(r,i,s)),r.getLocalPointByInner(e,null,null,!0),r.getLocalPointByInner(o,null,null,!0),r.x=e.x,r.y=e.y,r.getInnerPointByLocal(o,null,null,!0),r.toPoint=o}}getInnerMove(t,e,i){const o=e.getInnerMove(t);return i&&(Math.abs(o.x)>Math.abs(o.y)?o.y=0:o.x=0),o}getFromToByPath(t){return{from:{x:t[1],y:t[2]},to:{x:t[4],y:t[5]}}}getFromToByPoints(t){const e=Zt(t);return{from:{x:e[0],y:e[1]},to:{x:e[2],y:e[3]}}}dragPoint(t,e,i,o,s){const{x:n,y:r}=s;i?(zt(t,n,r),o&&zt(e,-n,-r)):(o&&zt(t,-n,-r),zt(e,n,r))}onSkew(t){}onUpdate(){const{editBox:t}=this,{rotatePoints:e,resizeLines:i,resizePoints:o,rect:s}=t,n=this.editor.element;let r,a;if(n.pathInputed?r=this.getFromToByPath(n.__.path):n.points&&(r=this.getFromToByPoints(n.__.points)),r){const{from:i,to:a}=r;n.innerToWorld(i,i,!1,t),n.innerToWorld(a,a,!1,t),s.pen.clearPath().moveTo(i.x,i.y).lineTo(a.x,a.y),At(o[7],i),At(e[7],i),At(o[3],a),At(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===Vt||t===Dt,o[t].visible=a,e[t].visible=!r&&a}},exports.LineEditTool=P([_t()],exports.LineEditTool),t.Creator.editor=function(t){return new Bt(t)},t.defineKey(t.UI.prototype,"editOuter",{get(){return this.__.__isLinePath?"LineEditTool":"EditTool"}}),t.defineKey(t.UI.prototype,"editInner",{get:()=>"PathEditor"}),t.defineKey(t.Text.prototype,"editInner",{get:()=>"TextEditor"}),t.UI.setEditConfig=function(e){t.defineKey(this.prototype,"editConfig",{get(){return"function"==typeof e?e(this):e}})},t.UI.setEditOuter=function(e){t.defineKey(this.prototype,"editOuter",{get(){return"string"==typeof e?e:e(this)}})},t.UI.setEditInner=function(e){t.defineKey(this.prototype,"editInner",{get(){return"string"==typeof e?e:e(this)}})},exports.EditBox=pt,exports.EditDataHelper=at,exports.EditPoint=gt,exports.EditSelect=q,exports.EditSelectHelper=N,exports.EditToolCreator=Tt,exports.Editor=Bt,exports.EditorEvent=H,exports.EditorGroupEvent=St,exports.EditorHelper=xt,exports.EditorMoveEvent=R,exports.EditorRotateEvent=I,exports.EditorScaleEvent=B,exports.EditorSkewEvent=V,exports.InnerEditor=It,exports.InnerEditorEvent=Ot,exports.PathScaler=f,exports.SelectArea=U,exports.Stroker=G,exports.registerEditTool=_t,exports.registerInnerEditor=kt,exports.scaleResize=_,exports.scaleResizeFontSize=k,exports.scaleResizeGroup=O,exports.scaleResizePath=T,exports.scaleResizePoints=M;