@leafer-in/editor 1.0.4 → 1.0.5

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.
@@ -1,4 +1,4 @@
1
- import { PathCommandMap, MatrixHelper, Direction9, Leaf, Text, Path, Line, Polygon, Group, Box, Event, defineKey, UI, Paint, Rect, Answer, Bounds, LeafList, PointHelper, AroundHelper, MathHelper, Matrix, Debug, DataHelper, LeafHelper, RenderEvent, getPointData, Creator } from '@leafer-ui/draw';
1
+ import { PathCommandMap, MatrixHelper, Direction9, Leaf, Text, Path, Line, Polygon, Group, Box, Event, defineKey, UI, Paint, Rect, Answer, Bounds, LeafList, PointHelper, AroundHelper, MathHelper, Matrix, Debug, PropertyEvent, LeafHelper, DataHelper, RenderEvent, getPointData, Creator } from '@leafer-ui/draw';
2
2
  import { PointerEvent, DragEvent, MoveEvent, ZoomEvent, RotateEvent, KeyEvent } from '@leafer-ui/core';
3
3
 
4
4
  const { M, L, C, Q, Z, N, D, X, G, F, O, P, U } = PathCommandMap;
@@ -316,31 +316,29 @@ class Stroker extends UI {
316
316
  const { list } = this;
317
317
  if (list.length) {
318
318
  let leaf;
319
- const { stroke, strokeWidth, fill } = this.__;
320
- const { bounds } = options;
319
+ const data = this.__, { stroke, strokeWidth, fill } = data, { bounds } = options;
321
320
  for (let i = 0; i < list.length; i++) {
322
321
  leaf = list[i];
323
- if (bounds && bounds.hit(leaf.__world, options.matrix)) {
324
- const aScaleX = abs(leaf.__world.scaleX), aScaleY = abs(leaf.__world.scaleY);
322
+ const { worldTransform, worldRenderBounds } = leaf;
323
+ if (bounds && bounds.hit(worldRenderBounds, options.matrix)) {
324
+ const aScaleX = abs(worldTransform.scaleX), aScaleY = abs(worldTransform.scaleY);
325
325
  if (aScaleX !== aScaleY) {
326
- copy$1(matrix, leaf.__world);
326
+ copy$1(matrix, worldTransform);
327
327
  scale(matrix, 1 / aScaleX, 1 / aScaleY);
328
328
  canvas.setWorld(matrix, options.matrix);
329
329
  canvas.beginPath();
330
- this.__.strokeWidth = strokeWidth;
330
+ data.strokeWidth = strokeWidth;
331
331
  const { x, y, width, height } = leaf.__layout.boxBounds;
332
332
  canvas.rect(x * aScaleX, y * aScaleY, width * aScaleX, height * aScaleY);
333
333
  }
334
334
  else {
335
- canvas.setWorld(leaf.__world, options.matrix);
335
+ canvas.setWorld(worldTransform, options.matrix);
336
336
  canvas.beginPath();
337
- if (leaf.__.__useArrow) {
337
+ if (leaf.__.__useArrow)
338
338
  leaf.__drawPath(canvas);
339
- }
340
- else {
339
+ else
341
340
  leaf.__.__pathForRender ? leaf.__drawRenderPath(canvas) : leaf.__drawPathByBox(canvas);
342
- }
343
- this.__.strokeWidth = strokeWidth / abs(leaf.__world.scaleX);
341
+ data.strokeWidth = strokeWidth / abs(worldTransform.scaleX);
344
342
  }
345
343
  if (stroke)
346
344
  typeof stroke === 'string' ? Paint.stroke(stroke, this, canvas) : Paint.strokes(stroke, this, canvas);
@@ -348,7 +346,7 @@ class Stroker extends UI {
348
346
  typeof fill === 'string' ? Paint.fill(fill, this, canvas) : Paint.fills(fill, this, canvas);
349
347
  }
350
348
  }
351
- this.__.strokeWidth = strokeWidth;
349
+ data.strokeWidth = strokeWidth;
352
350
  }
353
351
  }
354
352
  destroy() {
@@ -899,7 +897,6 @@ class EditBox extends Group {
899
897
  this.editor = editor;
900
898
  this.visible = false;
901
899
  this.create();
902
- this.rect.syncEventer = editor;
903
900
  this.__listenEvents();
904
901
  }
905
902
  create() {
@@ -939,8 +936,11 @@ class EditBox extends Group {
939
936
  circle.set(this.getPointStyle(mergeConfig.circle || mergeConfig.rotatePoint || pointsStyle[0]));
940
937
  rect.set(Object.assign({ stroke, strokeWidth }, (mergeConfig.rect || {})));
941
938
  rect.hittable = !single && !!moveable;
942
- element.syncEventer = (single && moveable) ? rect : null;
943
- this.app.interaction.bottomList = (single && moveable) ? [{ target: rect, proxy: element }] : null;
939
+ rect.syncEventer = single && this.editor;
940
+ if (single && moveable) {
941
+ element.syncEventer = rect;
942
+ this.app.interaction.bottomList = [{ target: rect, proxy: element }];
943
+ }
944
944
  }
945
945
  update(bounds) {
946
946
  this.visible = !this.editor.element.locked;
@@ -1112,6 +1112,11 @@ class EditBox extends Group {
1112
1112
  if (editor.single) {
1113
1113
  const { element } = editor;
1114
1114
  if (element.isBranch) {
1115
+ if (element.textBox) {
1116
+ const find = element.children.find(item => item.editable && item instanceof Text);
1117
+ if (find)
1118
+ return editor.openInnerEditor(find);
1119
+ }
1115
1120
  editor.openGroup(element);
1116
1121
  editor.target = editor.selector.findDeepOne(e);
1117
1122
  }
@@ -1257,12 +1262,12 @@ const config = {
1257
1262
  skewable: true
1258
1263
  };
1259
1264
 
1265
+ const bounds = new Bounds();
1260
1266
  function simulate(editor) {
1261
- const { simulateTarget, leafList: targetList } = editor;
1262
- const { x, y, width, height } = new Bounds().setListWithFn(targetList.list, (leaf) => leaf.worldBoxBounds);
1263
- const parent = simulateTarget.parent = targetList.list[0].leafer.zoomLayer;
1264
- const { scaleX, scaleY, e: worldX, f: worldY } = parent.__world;
1265
- simulateTarget.reset({ x: (x - worldX) / scaleX, y: (y - worldY) / scaleY, width: width / scaleX, height: height / scaleY });
1267
+ const { simulateTarget, list } = editor;
1268
+ const { zoomLayer } = list[0].leafer.zoomLayer;
1269
+ simulateTarget.safeChange(() => simulateTarget.reset(bounds.setListWithFn(list, (leaf) => leaf.getBounds('box', 'page')).get()));
1270
+ zoomLayer.add(simulateTarget);
1266
1271
  }
1267
1272
 
1268
1273
  function onTarget(editor, oldValue) {
@@ -1271,6 +1276,7 @@ function onTarget(editor, oldValue) {
1271
1276
  editor.leafList = target instanceof LeafList ? target : new LeafList(target instanceof Array ? target : target);
1272
1277
  }
1273
1278
  else {
1279
+ editor.simulateTarget.remove();
1274
1280
  editor.leafList.reset();
1275
1281
  editor.closeInnerEditor();
1276
1282
  }
@@ -1325,7 +1331,7 @@ const EditorHelper = {
1325
1331
  const ungroupList = [];
1326
1332
  app.lockLayout();
1327
1333
  list.forEach(leaf => {
1328
- if (leaf.isBranch) {
1334
+ if (leaf.isBranch && !leaf.isBranchLeaf) {
1329
1335
  const { parent, children } = leaf;
1330
1336
  while (children.length) {
1331
1337
  ungroupList.push(children[0]);
@@ -1396,17 +1402,77 @@ EditorGroupEvent.UNGROUP = 'editor.ungroup';
1396
1402
  EditorGroupEvent.OPEN = 'editor.open_group';
1397
1403
  EditorGroupEvent.CLOSE = 'editor.close_group';
1398
1404
 
1405
+ const { updateMatrix } = LeafHelper;
1406
+ const checkMap = { x: 1, y: 1, scaleX: 1, scaleY: 1, rotation: 1, skewX: 1, skewY: 1 }, origin = 'top-left';
1407
+ class SimulateElement extends Rect {
1408
+ get __tag() { return 'SimulateElement'; }
1409
+ constructor(editor) {
1410
+ super();
1411
+ this.checkChange = true;
1412
+ this.canChange = true;
1413
+ this.visible = this.hittable = false;
1414
+ this.on(PropertyEvent.CHANGE, (event) => {
1415
+ if (this.checkChange && checkMap[event.attrName]) {
1416
+ const { attrName, newValue, oldValue } = event;
1417
+ const addValue = attrName[0] === 's' ? (newValue || 1) / (oldValue || 1) : (newValue || 0) - (oldValue || 0);
1418
+ this.canChange = false;
1419
+ const data = this.__;
1420
+ data[attrName] = oldValue;
1421
+ updateMatrix(this.parent);
1422
+ updateMatrix(this);
1423
+ const oldMatrix = new Matrix(this.__world);
1424
+ data[attrName] = newValue;
1425
+ this.__layout.rotationChange();
1426
+ updateMatrix(this);
1427
+ this.changedTransform = new Matrix(this.__world).divide(oldMatrix);
1428
+ switch (attrName) {
1429
+ case 'x':
1430
+ editor.move(addValue, 0);
1431
+ break;
1432
+ case 'y':
1433
+ editor.move(0, addValue);
1434
+ break;
1435
+ case 'rotation':
1436
+ editor.rotateOf(origin, addValue);
1437
+ break;
1438
+ case 'scaleX':
1439
+ editor.scaleOf(origin, addValue, 1);
1440
+ break;
1441
+ case 'scaleY':
1442
+ editor.scaleOf(origin, 1, addValue);
1443
+ break;
1444
+ case 'skewX':
1445
+ editor.skewOf(origin, addValue, 0);
1446
+ break;
1447
+ case 'skewY':
1448
+ editor.skewOf(origin, 0, addValue);
1449
+ }
1450
+ this.canChange = true;
1451
+ }
1452
+ });
1453
+ }
1454
+ safeChange(changeFn) {
1455
+ if (this.canChange) {
1456
+ this.checkChange = false;
1457
+ changeFn();
1458
+ this.checkChange = true;
1459
+ }
1460
+ }
1461
+ }
1462
+
1399
1463
  class Editor extends Group {
1400
1464
  get mergeConfig() {
1401
1465
  const { element, config } = this;
1402
1466
  return this.single && element.editConfig ? Object.assign(Object.assign({}, config), element.editConfig) : config;
1403
1467
  }
1404
1468
  get list() { return this.leafList.list; }
1469
+ get dragHoverExclude() { return [this.editBox.rect]; }
1405
1470
  get editing() { return !!this.list.length; }
1406
1471
  get groupOpening() { return !!this.openedGroupList.length; }
1407
1472
  get multiple() { return this.list.length > 1; }
1408
1473
  get single() { return this.list.length === 1; }
1409
1474
  get dragging() { return this.editBox.dragging; }
1475
+ get moving() { return this.editBox.moving; }
1410
1476
  get element() { return this.multiple ? this.simulateTarget : this.list[0]; }
1411
1477
  get buttons() { return this.editBox.buttons; }
1412
1478
  constructor(userConfig, data) {
@@ -1414,7 +1480,7 @@ class Editor extends Group {
1414
1480
  this.config = DataHelper.clone(config);
1415
1481
  this.leafList = new LeafList();
1416
1482
  this.openedGroupList = new LeafList();
1417
- this.simulateTarget = new Rect({ visible: false });
1483
+ this.simulateTarget = new SimulateElement(this);
1418
1484
  this.editBox = new EditBox(this);
1419
1485
  this.editToolList = {};
1420
1486
  this.selector = new EditSelect(this);
@@ -1552,18 +1618,18 @@ class Editor extends Group {
1552
1618
  this.skewOf(origin, skewX, skewY);
1553
1619
  }
1554
1620
  move(x, y = 0) {
1555
- if (!this.mergeConfig.moveable || this.element.locked)
1621
+ if (!this.checkTransform('moveable'))
1556
1622
  return;
1557
1623
  const { element } = this;
1558
1624
  const world = element.getWorldPointByLocal(typeof x === 'object' ? Object.assign({}, x) : { x, y }, null, true);
1625
+ if (this.multiple)
1626
+ element.safeChange(() => element.move(x, y));
1559
1627
  const event = new EditorMoveEvent(EditorMoveEvent.MOVE, { target: element, editor: this, moveX: world.x, moveY: world.y });
1560
1628
  this.editTool.onMove(event);
1561
1629
  this.emitEvent(event);
1562
- if (this.multiple)
1563
- element.move(x, y);
1564
1630
  }
1565
1631
  scaleWithDrag(data) {
1566
- if (!this.mergeConfig.resizeable || this.element.locked)
1632
+ if (!this.checkTransform('resizeable'))
1567
1633
  return;
1568
1634
  const { element } = this;
1569
1635
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, Object.assign(Object.assign({}, data), { target: element, editor: this, worldOrigin: element.getWorldPoint(data.origin) }));
@@ -1571,50 +1637,53 @@ class Editor extends Group {
1571
1637
  this.emitEvent(event);
1572
1638
  }
1573
1639
  scaleOf(origin, scaleX, scaleY = scaleX, _resize) {
1574
- if (!this.mergeConfig.resizeable || this.element.locked)
1640
+ if (!this.checkTransform('resizeable'))
1575
1641
  return;
1576
1642
  const { element } = this;
1577
1643
  const worldOrigin = this.getWorldOrigin(origin);
1578
- const transform = this.multiple && this.getChangedTransform(() => element.scaleOf(origin, scaleX, scaleY));
1644
+ const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.scaleOf(origin, scaleX, scaleY)));
1579
1645
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, { target: element, editor: this, worldOrigin, scaleX, scaleY, transform });
1580
1646
  this.editTool.onScale(event);
1581
1647
  this.emitEvent(event);
1582
1648
  }
1583
1649
  flip(axis) {
1584
- if (this.element.locked)
1650
+ if (!this.checkTransform('resizeable'))
1585
1651
  return;
1586
1652
  const { element } = this;
1587
1653
  const worldOrigin = this.getWorldOrigin('center');
1588
- const transform = this.multiple ? this.getChangedTransform(() => element.flip(axis)) : new Matrix(LeafHelper.getFlipTransform(element, axis));
1654
+ const transform = this.multiple ? this.getChangedTransform(() => element.safeChange(() => element.flip(axis))) : new Matrix(LeafHelper.getFlipTransform(element, axis));
1589
1655
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, { target: element, editor: this, worldOrigin, scaleX: axis === 'x' ? -1 : 1, scaleY: axis === 'y' ? -1 : 1, transform });
1590
1656
  this.editTool.onScale(event);
1591
1657
  this.emitEvent(event);
1592
1658
  }
1593
1659
  rotateOf(origin, rotation) {
1594
- if (!this.mergeConfig.rotateable || this.element.locked)
1660
+ if (!this.checkTransform('rotateable'))
1595
1661
  return;
1596
1662
  const { element } = this;
1597
1663
  const worldOrigin = this.getWorldOrigin(origin);
1598
- const transform = this.multiple && this.getChangedTransform(() => element.rotateOf(origin, rotation));
1664
+ const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.rotateOf(origin, rotation)));
1599
1665
  const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, { target: element, editor: this, worldOrigin, rotation, transform });
1600
1666
  this.editTool.onRotate(event);
1601
1667
  this.emitEvent(event);
1602
1668
  }
1603
1669
  skewOf(origin, skewX, skewY = 0, _resize) {
1604
- if (!this.mergeConfig.skewable || this.element.locked)
1670
+ if (!this.checkTransform('skewable'))
1605
1671
  return;
1606
1672
  const { element } = this;
1607
1673
  const worldOrigin = this.getWorldOrigin(origin);
1608
- const transform = this.multiple && this.getChangedTransform(() => element.skewOf(origin, skewX, skewY));
1674
+ const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.skewOf(origin, skewX, skewY)));
1609
1675
  const event = new EditorSkewEvent(EditorSkewEvent.SKEW, { target: element, editor: this, worldOrigin, skewX, skewY, transform });
1610
1676
  this.editTool.onSkew(event);
1611
1677
  this.emitEvent(event);
1612
1678
  }
1679
+ checkTransform(type) { return this.element && !this.element.locked && this.mergeConfig[type]; }
1613
1680
  getWorldOrigin(origin) {
1614
1681
  return this.element.getWorldPoint(LeafHelper.getInnerOrigin(this.element, origin));
1615
1682
  }
1616
1683
  getChangedTransform(func) {
1617
1684
  const { element } = this;
1685
+ if (this.multiple && !element.canChange)
1686
+ return element.changedTransform;
1618
1687
  const oldMatrix = new Matrix(element.worldTransform);
1619
1688
  func();
1620
1689
  return new Matrix(element.worldTransform).divide(oldMatrix);
@@ -1671,11 +1740,11 @@ class Editor extends Group {
1671
1740
  this.emitEvent(event);
1672
1741
  group.emitEvent(event);
1673
1742
  }
1674
- openInnerEditor(target) {
1675
- if (target)
1743
+ openInnerEditor(target, select) {
1744
+ if (target && select)
1676
1745
  this.target = target;
1677
1746
  if (this.single) {
1678
- const editTarget = this.element;
1747
+ const editTarget = target || this.element;
1679
1748
  const tag = editTarget.editInner;
1680
1749
  if (tag && EditToolCreator.list[tag]) {
1681
1750
  this.editTool.unload();
@@ -1727,14 +1796,15 @@ class Editor extends Group {
1727
1796
  }
1728
1797
  listenTargetEvents() {
1729
1798
  if (!this.targetEventIds.length) {
1730
- const { leafer } = this.list[0];
1799
+ const { app, leafer } = this;
1731
1800
  this.targetEventIds = [
1732
- this.app.on_(MoveEvent.BEFORE_MOVE, this.onMove, this, true),
1733
- this.app.on_(ZoomEvent.BEFORE_ZOOM, this.onScale, this, true),
1734
- this.app.on_(RotateEvent.BEFORE_ROTATE, this.onRotate, this, true),
1735
1801
  leafer.on_(RenderEvent.START, this.update, this),
1736
- leafer.on_([KeyEvent.HOLD, KeyEvent.UP], (e) => { updateCursor(this, e); }),
1737
- leafer.on_(KeyEvent.DOWN, this.editBox.onArrow, this.editBox)
1802
+ app.on_(RenderEvent.CHILD_START, this.forceRender, this),
1803
+ app.on_(MoveEvent.BEFORE_MOVE, this.onMove, this, true),
1804
+ app.on_(ZoomEvent.BEFORE_ZOOM, this.onScale, this, true),
1805
+ app.on_(RotateEvent.BEFORE_ROTATE, this.onRotate, this, true),
1806
+ app.on_([KeyEvent.HOLD, KeyEvent.UP], (e) => { updateCursor(this, e); }),
1807
+ app.on_(KeyEvent.DOWN, this.editBox.onArrow, this.editBox)
1738
1808
  ];
1739
1809
  }
1740
1810
  }
@@ -1867,10 +1937,7 @@ let EditTool = class EditTool extends InnerEditor {
1867
1937
  }
1868
1938
  update() {
1869
1939
  const { editor, editBox } = this;
1870
- const { simulateTarget, element } = editor;
1871
- if (editor.multiple)
1872
- simulateTarget.parent.updateLayout();
1873
- const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = element.getLayoutBounds('box', editor, true);
1940
+ const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = editor.element.getLayoutBounds('box', editor, true);
1874
1941
  editBox.set({ x, y, scaleX, scaleY, rotation, skewX, skewY });
1875
1942
  editBox.update({ x: 0, y: 0, width, height });
1876
1943
  this.onUpdate();
@@ -1 +1 @@
1
- import{PathCommandMap as t,MatrixHelper as e,Direction9 as i,Leaf as s,Text as o,Path as n,Line as r,Polygon as a,Group as h,Box as l,Event as d,defineKey as c,UI as g,Paint as u,Rect as f,Answer as p,Bounds as m,LeafList as v,PointHelper as b,AroundHelper as _,MathHelper as y,Matrix as w,Debug as L,DataHelper as E,LeafHelper as k,RenderEvent as x,getPointData as O,Creator as S}from"@leafer-ui/draw";import{PointerEvent as T,DragEvent as M,MoveEvent as P,ZoomEvent as B,RotateEvent as C,KeyEvent as V}from"@leafer-ui/core";const{M:R,L:H,C:I,Q:D,Z:z,N:A,D:Z,X:W,G:F,F:X,O:Y,P:G,U:U}=t,N={scale(t,e,i){if(!t)return;let s,o=0,n=t.length;for(;o<n;)switch(s=t[o],s){case R:case H:j(t,e,i,o,1),o+=3;break;case I:j(t,e,i,o,3),o+=7;break;case D:j(t,e,i,o,2),o+=5;break;case z:o+=1;break;case A:j(t,e,i,o,2),o+=5;break;case Z:j(t,e,i,o,2),o+=9;break;case W:j(t,e,i,o,2),o+=6;break;case F:j(t,e,i,o,2),o+=9;break;case X:j(t,e,i,o,2),o+=5;break;case Y:t[o]=F,t.splice(o+4,0,t[o+3],0),j(t,e,i,o,2),o+=9,n+=2;break;case G:t[o]=X,t.splice(o+4,0,t[o+3]),j(t,e,i,o,2),o+=5,n+=1;break;case U:j(t,e,i,o,2),o+=6}},scalePoints(t,e,i,s,o){for(let n=o?s+1:0,r=o?n+2*o:t.length;n<r;n+=2)t[n]*=e,t[n+1]*=i}},{scalePoints:j}=N,K=e.get(),{topLeft:$,top:q,topRight:Q,right:J,bottom:tt,left:et}=i;function it(t,e,i){t.pathInputed?ot(t,e,i):(1!==e&&(t.width*=e),1!==i&&(t.height*=i))}function st(t,e,i){const{app:s}=t,o=s&&s.editor;let n=e;if(o.editing){const s=t.__layout;let{width:r,height:a}=s.boxBounds;switch(r*=i-e,a*=e-i,o.resizeDirection){case q:case tt:n=i,s.affectScaleOrRotation?t.moveInner(-r/2,0):t.x-=r/2;break;case et:case J:s.affectScaleOrRotation?t.moveInner(0,-a/2):t.y-=a/2;break;case $:case Q:s.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 ot(t,e,i){N.scale(t.__.path,e,i),t.path=t.__.path}function nt(t,e,i){N.scalePoints(t.__.points,e,i),t.points=t.__.points}function rt(t,e,i){const{children:s}=t;for(let t=0;t<s.length;t++)K.a=e,K.d=i,s[t].transform(K,!0)}const at=s.prototype;function ht(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(n<3?o(r):n>3?o(e,i,r):o(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}function lt(t){return t?t instanceof Array?t:[t]:[]}at.scaleResize=function(t,e=t,i){const s=this;i||s.editConfig&&"scale"===s.editConfig.editSize?(s.scaleX*=t,s.scaleY*=e):(t<0&&(s.scaleX*=-1,t=-t),e<0&&(s.scaleY*=-1,e=-e),this.__scaleResize(t,e))},at.__scaleResize=function(t,e){it(this,t,e)},at.resizeWidth=function(t){const e=t/this.getBounds("box","local").width;this.scaleOf(this.__layout.boxBounds,e,this.__.lockRatio?e:1,!0)},at.resizeHeight=function(t){const e=t/this.getBounds("box","local").height;this.scaleOf(this.__layout.boxBounds,this.__.lockRatio?e:1,e,!0)},o.prototype.__scaleResize=function(t,e){this.__.resizeFontSize||this.editConfig&&"font-size"===this.editConfig.editSize?st(this,t,e):it(this,t,e)},n.prototype.__scaleResize=function(t,e){ot(this,t,e)},r.prototype.__scaleResize=function(t,e){this.pathInputed?ot(this,t,e):this.points?nt(this,t,e):this.width*=t},a.prototype.__scaleResize=function(t,e){this.pathInputed?ot(this,t,e):this.points?nt(this,t,e):it(this,t,e)},h.prototype.__scaleResize=function(t,e){rt(this,t,e)},l.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?rt(this,t,e):(it(this,t,e),this.__.resizeChildren&&rt(this,t,e))},"function"==typeof SuppressedError&&SuppressedError;class dt extends d{get list(){return lt(this.value)}get oldList(){return lt(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}dt.SELECT="editor.select",dt.HOVER="editor.hover";class ct extends dt{constructor(t,e){super(t,e)}}ct.MOVE="editor.move";class gt extends dt{constructor(t,e){super(t,e)}}gt.SCALE="editor.scale";class ut extends dt{constructor(t,e){super(t,e)}}ut.ROTATE="editor.rotate";class ft extends dt{constructor(t,e){super(t,e)}}function pt(t){return(e,i)=>{const s="_"+i;c(e,i,{get(){return this[s]},set(e){const i=this[s];i!==e&&(this[s]=e,t(this,i))}})}}ft.SKEW="editor.skew";const mt=e.get(),{abs:vt}=Math,{copy:bt,scale:_t}=e;class yt extends g{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){this.set(e),this.target=t}__draw(t,e){const{list:i}=this;if(i.length){let s;const{stroke:o,strokeWidth:n,fill:r}=this.__,{bounds:a}=e;for(let h=0;h<i.length;h++)if(s=i[h],a&&a.hit(s.__world,e.matrix)){const i=vt(s.__world.scaleX),a=vt(s.__world.scaleY);if(i!==a){bt(mt,s.__world),_t(mt,1/i,1/a),t.setWorld(mt,e.matrix),t.beginPath(),this.__.strokeWidth=n;const{x:o,y:r,width:h,height:l}=s.__layout.boxBounds;t.rect(o*i,r*a,h*i,l*a)}else t.setWorld(s.__world,e.matrix),t.beginPath(),s.__.__useArrow?s.__drawPath(t):s.__.__pathForRender?s.__drawRenderPath(t):s.__drawPathByBox(t),this.__.strokeWidth=n/vt(s.__world.scaleX);o&&("string"==typeof o?u.stroke(o,this,t):u.strokes(o,this,t)),r&&("string"==typeof r?u.fill(r,this,t):u.fills(r,this,t))}this.__.strokeWidth=n}}destroy(){this.target=null,super.destroy()}}ht([pt((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],yt.prototype,"target",void 0);class wt extends h{constructor(t){super(t),this.strokeArea=new f({strokeAlign:"center"}),this.fillArea=new f,this.visible=this.hittable=!1,this.addMany(this.fillArea,this.strokeArea)}setStyle(t,e){const{visible:i,stroke:s,strokeWidth:o}=t;this.visible=i,this.strokeArea.reset(Object.assign({stroke:s,strokeWidth:o},e||{})),this.fillArea.reset({visible:!e,fill:s,opacity:.2})}setBounds(t){this.strokeArea.set(t),this.fillArea.set(t)}}const{No:Lt,Yes:Et,NoAndSkip:kt,YesAndSkip:xt}=p,Ot={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?xt:kt;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?xt:Lt;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return Et}return Lt}return t.isBranch?kt:Lt}},{findOne:St}=Ot;class Tt extends h{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(t){super(),this.hoverStroker=new yt,this.targetStroker=new yt,this.bounds=new m,this.selectArea=new wt,this.__eventIds=[],this.editor=t,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:s,hoverStyle:o}=t.mergeConfig;this.hoverStroker.setTarget(s?this.editor.hoverTarget:null,Object.assign({stroke:e,strokeWidth:i},o||{}))}}onSelect(){if(this.running){const{mergeConfig:t,list:e}=this.editor,{stroke:i,strokeWidth:s}=t;this.targetStroker.setTarget(e,{stroke:i,strokeWidth:Math.max(1,s/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:s}=e.mergeConfig,{x:o,y:n}=t.getInnerPoint(this);this.bounds.set(o,n),this.selectArea.setStyle({visible:!0,stroke:i,x:o,y:n},s),this.selectArea.setBounds(this.bounds.get()),this.originList=e.leafList.clone()}}onDrag(t){if(!t.multiTouch){if(this.editor.dragging)return this.onDragEnd(t);if(this.dragging){const{editor:e}=this,i=t.getInnerTotal(this),s=this.bounds.clone().unsign(),o=new v(e.app.find(Ot.findBounds,s));if(this.bounds.width=i.x,this.bounds.height=i.y,this.selectArea.setBounds(s.get()),o.length){const t=[];this.originList.forEach((e=>{o.has(e)||t.push(e)})),o.forEach((e=>{this.originList.has(e)||t.push(e)})),(t.length!==e.list.length||e.list.some(((e,i)=>e!==t[i])))&&(e.target=t)}else e.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&&!St(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new v(this.editor.editBox.rect)};return St(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):St(t.path)}isMultipleSelect(t){return t.shiftKey||this.editor.mergeConfig.continuousSelect}__listenEvents(){const{editor:t}=this;t.waitLeafer((()=>{const{app:e}=t;e.selector.proxy=t,this.__eventIds=[t.on_(dt.HOVER,this.onHover,this),t.on_(dt.SELECT,this.onSelect,this),e.on_(T.MOVE,this.onPointerMove,this),e.on_(T.BEFORE_DOWN,this.onBeforeDown,this),e.on_(T.TAP,this.onTap,this),e.on_(M.START,this.onDragStart,this,!0),e.on_(M.DRAG,this.onDrag,this),e.on_(M.END,this.onDragEnd,this),e.on_(P.MOVE,this.onAutoMove,this),e.on_([B.ZOOM,P.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:Mt,top:Pt,topRight:Bt,right:Ct,bottomRight:Vt,bottom:Rt,bottomLeft:Ht,left:It}=i,{toPoint:Dt}=_,{within:zt}=y,At={getScaleData(t,e,i,s,o,n,r,a){let h,l={},d=1,c=1;const{boxBounds:g,widthRange:u,heightRange:f}=t,{width:p,height:m}=e;n&&(s.x*=2,s.y*=2);const v=t.scaleX/e.scaleX,b=t.scaleY/e.scaleY,_=v<0?-1:1,y=b<0?-1:1,w=a?v:_*g.width/p,L=a?b:y*g.height/m;s.x*=a?v:_,s.y*=a?b:y,Math.abs(s.x)===p&&(s.x+=.1),Math.abs(s.y)===m&&(s.y+=.1);const E=(-s.y+m)/m,k=(s.x+p)/p,x=(s.y+m)/m,O=(-s.x+p)/p;switch(i){case Pt:c=E,h="bottom";break;case Ct:d=k,h="left";break;case Rt:c=x,h="top";break;case It:d=O,h="right";break;case Mt:c=E,d=O,h="bottom-right";break;case Bt:c=E,d=k,h="bottom-left";break;case Vt:c=x,d=k,h="top-left";break;case Ht:c=x,d=O,h="top-right"}if(o){if(!("corner"===o&&i%2)){let t;switch(i){case Pt:case Rt:t=c;break;case It:case Ct:t=d;break;default:t=Math.sqrt(Math.abs(d*c))}d=d<0?-t:t,c=c<0?-t:t}}if(d/=w,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=zt(e*d,u)/e}if(f){const e=g.height*t.scaleY;c=zt(e*c,f)/e}return Dt(n||h,g,l,!0),{origin:l,scaleX:d,scaleY:c,direction:i,lockRatio:o,around:n}},getRotateData(t,e,i,s,o){let n,r={};switch(e){case Mt:n="bottom-right";break;case Bt:n="bottom-left";break;case Vt:n="top-left";break;case Ht:n="top-right";break;default:n="center"}return Dt(o||n,t,r,!0),{origin:r,rotation:b.getRotation(s,r,i)}},getSkewData(t,e,i,s){let o,n,r={},a=0,h=0;switch(e){case Pt:n={x:.5,y:0},o="bottom",a=1;break;case Rt:n={x:.5,y:1},o="top",a=1;break;case It:n={x:0,y:.5},o="right",h=1;break;case Ct:n={x:1,y:.5},o="left",h=1}const{width:l,height:d}=t;n.x=n.x*l,n.y=n.y*d,Dt(s||o,t,r,!0);const c=b.getRotation(n,r,{x:n.x+(a?i.x:0),y:n.y+(h?i.y:0)});return a?a=-c:h=c,{origin:r,skewX:a,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 It:t=Ct;break;case Mt:t=Bt;break;case Ht:t=Vt;break;case Ct:t=It;break;case Bt:t=Mt;break;case Vt:t=Ht}if(i)switch(t){case Pt:t=Rt;break;case Mt:t=Ht;break;case Bt:t=Vt;break;case Rt:t=Pt;break;case Ht:t=Mt;break;case Vt:t=Bt}return t}},Zt={};function Wt(t,e){const{editBox:i}=t,s=i.enterPoint;if(!s||!t.editing||!i.visible)return;if("circle"===s.name)return;if("button"===s.pointType)return void(s.cursor||(s.cursor="pointer"));let{rotation:o}=i;const{resizeCursor:n,rotateCursor:r,skewCursor:a,resizeable:h,rotateable:l,skewable:d}=t.mergeConfig,{pointType:c}=s,{flippedX:g,flippedY:u}=i;let f="resize"===c;f&&l&&(e.metaKey||e.ctrlKey||!h)&&(f=!1);const p=d&&!f&&"resize-line"===s.name?a:f?n:r;o+=45*(At.getFlipDirection(s.direction,g,u)+1),o=2*Math.round(y.formatRotation(o,!0)/2);const{url:m,x:v,y:b}=p,_=m+o;Zt[_]?s.cursor=Zt[_]:Zt[_]=s.cursor={url:Xt(m,o),x:v,y:b}}function Ft(t){t.editBox.rect.cursor=t.mergeConfig.moveCursor}function Xt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class Yt extends l{}const Gt=["top","right","bottom","left"];class Ut extends h{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(t){super(),this.view=new h,this.rect=new l({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new Yt({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new h({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.rect.syncEventer=t,this.__listenEvents()}create(){let t,e,i;const{view:s,resizePoints:o,rotatePoints:n,resizeLines:r,rect:a,circle:h,buttons:l}=this,d=["bottom-right","bottom","bottom-left","left","top-left","top","top-right","right"];for(let s=0;s<8;s++)t=new Yt({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new Yt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",s)),i=new Yt({name:"resize-point",hitRadius:5}),o.push(i),this.listenPointEvents(i,"resize",s);this.listenPointEvents(h,"rotate",2),s.addMany(...n,a,h,l,...r,...o),this.add(s)}load(){const{mergeConfig:t,element:e,single:i}=this.editor,{rect:s,circle:o,resizePoints:n}=this,{stroke:r,strokeWidth:a,moveable:h}=t,l=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]:l[t/2%l.length])),t%2||(c.rotation=t/2*90);o.set(this.getPointStyle(t.circle||t.rotatePoint||l[0])),s.set(Object.assign({stroke:r,strokeWidth:a},t.rect||{})),s.hittable=!i&&!!h,e.syncEventer=i&&h?s:null,this.app.interaction.bottomList=i&&h?[{target:s,proxy:e}]:null}update(t){if(this.visible=!this.editor.element.locked,this.view.worldOpacity){const{mergeConfig:e}=this.editor,{width:i,height:s}=t,{rect:o,circle:n,buttons:r,resizePoints:a,rotatePoints:h,resizeLines:l}=this,{middlePoint:d,resizeable:c,rotateable:g,hideOnSmall:u}=e,f="number"==typeof u?u:10,p=!(u&&i<f&&s<f);let m,v,b,y={};for(let o=0;o<8;o++)_.toPoint(_.directionData[o],t,y),v=a[o],m=h[o],b=l[Math.floor(o/2)],v.set(y),m.set(y),b.set(y),v.visible=b.visible=p&&!(!c&&!g),m.visible=p&&g&&c&&!e.rotatePoint,o%2&&(v.visible=m.visible=p&&!!d,(o+1)/2%2?(b.width=i,v.width>i-30&&(v.visible=!1)):(b.height=s,v.rotation=90,v.width>s-30&&(v.visible=!1)));n.visible=p&&g&&!(!e.circle&&!e.rotatePoint),n.visible&&this.layoutCircle(e),o.path&&(o.path=null),o.set(Object.assign(Object.assign({},t),{visible:!0})),r.visible=p&&r.children.length>0,r.visible&&this.layoutButtons(e)}}layoutCircle(t){const{circleDirection:e,circleMargin:i,buttonsMargin:s,buttonsDirection:o,middlePoint:n}=t,r=Gt.indexOf(e||(this.buttons.children.length&&"bottom"===o?"top":"bottom"));this.setButtonPosition(this.circle,r,i||s,!!n)}layoutButtons(t){const{buttons:e}=this,{buttonsDirection:i,buttonsFixed:s,buttonsMargin:o,middlePoint:n}=t,{flippedX:r,flippedY:a}=this;let h=Gt.indexOf(i);(h%2&&r||(h+1)%2&&a)&&s&&(h=(h+2)%4);const l=s?At.getRotateDirection(h,this.flippedOne?this.rotation:-this.rotation,4):h;this.setButtonPosition(e,l,o,!!n),s&&(e.rotation=90*(l-h)),e.scaleX=r?-1:1,e.scaleY=a?-1:1}setButtonPosition(t,e,i,s){const o=this.resizePoints[2*e+1],n=e%2,r=e&&3!==e?1:-1,a=(i+(e%2?(s?o.width:0)+t.boxBounds.width:(s?o.height:0)+t.boxBounds.height)/2)*r;n?(t.x=o.x+a,t.y=o.y):(t.x=o.x,t.y=o.y+a)}unload(){this.visible=!1}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:s,pointSize:o,pointRadius:n}=this.editor.mergeConfig,r={fill:s,stroke:e,strokeWidth:i,around:"center",strokeAlign:"center",width:o,height:o,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),Wt(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,e,i){const{editor:s}=this;t.direction=i,t.pointType=e,t.on_(M.START,this.onDragStart,this),t.on_(M.DRAG,this.onDrag,this),t.on_(M.END,this.onDragEnd,this),t.on_(T.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(T.ENTER,(e=>{this.enterPoint=t,Wt(s,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(dt.SELECT,this.onSelect,this),t.on_(M.START,this.onDragStart,this),t.on_(M.DRAG,e.onMove,e),t.on_(M.END,this.onDragEnd,this),t.on_(T.ENTER,(()=>Ft(e))),t.on_(T.DOUBLE_TAP,this.onDoubleTap,this),t.on_(T.LONG_PRESS,this.onLongPress,this)]}__removeListenEvents(){this.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}class Nt extends g{constructor(t){super(),this.editor=t,this.hittable=!1}__draw(t,e){const{editor:i}=this,{mask:s}=i.mergeConfig;if(s&&i.list.length){const{rect:o}=i.editBox,{width:n,height:r}=o.__;t.resetTransform(),t.fillWorld(t.bounds,!0===s?"rgba(0,0,0,0.8)":s),t.setWorld(o.__world,e.matrix),t.clearRect(0,0,n,r)}}destroy(){this.editor=null,super.destroy()}}const jt='\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"/>',Kt={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${jt}\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${jt}\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${jt}\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 $t(t){const{simulateTarget:e,leafList:i}=t,{x:s,y:o,width:n,height:r}=(new m).setListWithFn(i.list,(t=>t.worldBoxBounds)),a=e.parent=i.list[0].leafer.zoomLayer,{scaleX:h,scaleY:l,e:d,f:c}=a.__world;e.reset({x:(s-d)/h,y:(o-c)/l,width:n/h,height:r/l})}const qt=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),Qt=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),Jt={group(t,e,i){t.sort(Qt);const{app:s,parent:o}=t[0];let n;n=i&&i.add?i:new h(i),o.addAt(n,o.children.indexOf(t[0])),t.sort(qt);const r=new w(e.worldTransform);return r.divideParent(o.worldTransform),n.setTransform(r),n.editable=!0,n.hitChildren=!1,s.lockLayout(),t.forEach((t=>t.dropTo(n))),s.unlockLayout(),n},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach((t=>{if(t.isBranch){const{parent:e,children:s}=t;for(;s.length;)i.push(s[0]),s[0].dropTo(e,e.children.indexOf(t));t.remove()}else i.push(t)})),e.unlockLayout(),i},toTop(t){t.sort(qt),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(Qt),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},te=L.get("EditToolCreator");function ee(){return t=>{se.register(t)}}const ie=ee,se={list:{},register(t){const{tag:e}=t.prototype;oe[e]?te.repeat(e):oe[e]=t},get:(t,e)=>new oe[t](e)},{list:oe}=se;class ne extends dt{constructor(t,e){super(t,e)}}ne.BEFORE_OPEN="innerEditor.before_open",ne.OPEN="innerEditor.open",ne.BEFORE_CLOSE="innerEditor.before_close",ne.CLOSE="innerEditor.close";class re extends dt{constructor(t,e){super(t,e)}}re.GROUP="editor.group",re.BEFORE_UNGROUP="editor.before_ungroup",re.UNGROUP="editor.ungroup",re.OPEN="editor.open_group",re.CLOSE="editor.close_group";class ae extends h{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(t,e){super(e),this.config=E.clone(Kt),this.leafList=new v,this.openedGroupList=new v,this.simulateTarget=new f({visible:!1}),this.editBox=new Ut(this),this.editToolList={},this.selector=new Tt(this),this.editMask=new Nt(this),this.targetEventIds=[],t&&(this.config=E.default(t,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&&$t(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]||se.get(t,this),this.editBox.load(),this.editTool.load()}}getEditSize(t){return this.mergeConfig.editSize}onMove(t){if(t instanceof P){if("drag"!==t.moveType){const{moveable:e,resizeable:i}=this.mergeConfig,s=t.getLocalMove(this.element);"move"===e?(t.stop(),this.move(s.x,s.y)):"zoom"===i&&t.stop()}}else{const e={x:t.totalX,y:t.totalY};t.shiftKey&&(Math.abs(e.x)>Math.abs(e.y)?e.y=0:e.x=0),this.move(M.getValidMove(this.element,this.dragStartPoint,e))}}onScale(t){const{element:e}=this;let{around:i,lockRatio:s,resizeable:o,flipable:n,editSize:r}=this.mergeConfig;if(t instanceof B)"zoom"===o&&(t.stop(),this.scaleOf(e.getBoxPoint(t),t.scale,t.scale));else{const{direction:o}=t.current;(t.shiftKey||e.lockRatio)&&(s=!0);const a=At.getScaleData(e,this.dragStartBounds,o,t.getInnerTotal(e),s,At.getAround(i,t.altKey),n,this.multiple||"scale"===r);this.editTool.onScaleWithDrag?(a.drag=t,this.scaleWithDrag(a)):this.scaleOf(a.origin,a.scaleX,a.scaleY)}}onRotate(t){const{skewable:e,rotateable:i,around:s,rotateGap:o}=this.mergeConfig,{direction:n,name:r}=t.current;if(e&&"resize-line"===r)return this.onSkew(t);const{element:a}=this;let h,l;if(t instanceof C){if("rotate"!==i)return;t.stop(),l=t.rotation,h=a.getBoxPoint(t)}else{const e={x:t.x-t.moveX,y:t.y-t.moveY},i=At.getRotateData(a.boxBounds,n,t.getBoxPoint(a),a.getBoxPoint(e),t.shiftKey?null:a.around||a.origin||s||"center");l=i.rotation,h=i.origin}l=y.getGapRotation(l,o,a.rotation),l&&(a.scaleX*a.scaleY<0&&(l=-l),this.rotateOf(h,y.float(l,2)))}onSkew(t){const{element:e}=this,{around:i}=this.mergeConfig,{origin:s,skewX:o,skewY:n}=At.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),At.getAround(i,t.altKey));(o||n)&&this.skewOf(s,o,n)}move(t,e=0){if(!this.mergeConfig.moveable||this.element.locked)return;const{element:i}=this,s=i.getWorldPointByLocal("object"==typeof t?Object.assign({},t):{x:t,y:e},null,!0),o=new ct(ct.MOVE,{target:i,editor:this,moveX:s.x,moveY:s.y});this.editTool.onMove(o),this.emitEvent(o),this.multiple&&i.move(t,e)}scaleWithDrag(t){if(!this.mergeConfig.resizeable||this.element.locked)return;const{element:e}=this,i=new gt(gt.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,s){if(!this.mergeConfig.resizeable||this.element.locked)return;const{element:o}=this,n=this.getWorldOrigin(t),r=this.multiple&&this.getChangedTransform((()=>o.scaleOf(t,e,i))),a=new gt(gt.SCALE,{target:o,editor:this,worldOrigin:n,scaleX:e,scaleY:i,transform:r});this.editTool.onScale(a),this.emitEvent(a)}flip(t){if(this.element.locked)return;const{element:e}=this,i=this.getWorldOrigin("center"),s=this.multiple?this.getChangedTransform((()=>e.flip(t))):new w(k.getFlipTransform(e,t)),o=new gt(gt.SCALE,{target:e,editor:this,worldOrigin:i,scaleX:"x"===t?-1:1,scaleY:"y"===t?-1:1,transform:s});this.editTool.onScale(o),this.emitEvent(o)}rotateOf(t,e){if(!this.mergeConfig.rotateable||this.element.locked)return;const{element:i}=this,s=this.getWorldOrigin(t),o=this.multiple&&this.getChangedTransform((()=>i.rotateOf(t,e))),n=new ut(ut.ROTATE,{target:i,editor:this,worldOrigin:s,rotation:e,transform:o});this.editTool.onRotate(n),this.emitEvent(n)}skewOf(t,e,i=0,s){if(!this.mergeConfig.skewable||this.element.locked)return;const{element:o}=this,n=this.getWorldOrigin(t),r=this.multiple&&this.getChangedTransform((()=>o.skewOf(t,e,i))),a=new ft(ft.SKEW,{target:o,editor:this,worldOrigin:n,skewX:e,skewY:i,transform:r});this.editTool.onSkew(a),this.emitEvent(a)}getWorldOrigin(t){return this.element.getWorldPoint(k.getInnerOrigin(this.element,t))}getChangedTransform(t){const{element:e}=this,i=new w(e.worldTransform);return t(),new w(e.worldTransform).divide(i)}group(t){return this.multiple&&(this.target=Jt.group(this.list,this.element,t),this.emitGroupEvent(re.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach((t=>t.isBranch&&this.emitGroupEvent(re.BEFORE_UNGROUP,t))),this.target=Jt.ungroup(t),t.forEach((t=>t.isBranch&&this.emitGroupEvent(re.UNGROUP,t)))),this.list}openGroup(t){this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(re.OPEN,t)}closeGroup(t){this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(re.CLOSE,t)}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:e}=t;this.editing&&(e=[],t.forEach((t=>this.list.every((e=>!k.hasParent(e,t)))&&e.push(t)))),e.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 re(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&&se.list[e]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[e]||se.get(e,this),this.innerEditor.editTarget=t,this.emitInnerEvent(ne.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(ne.OPEN))}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(ne.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(ne.CLOSE),this.editTool.load(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,s=new ne(t,{editTarget:i,innerEditor:e});this.emitEvent(s),i.emitEvent(s)}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(Jt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(Jt.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{leafer:t}=this.list[0];this.targetEventIds=[this.app.on_(P.BEFORE_MOVE,this.onMove,this,!0),this.app.on_(B.BEFORE_ZOOM,this.onScale,this,!0),this.app.on_(C.BEFORE_ROTATE,this.onRotate,this,!0),t.on_(x.START,this.update,this),t.on_([V.HOLD,V.UP],(t=>{Wt(this,t)})),t.on_(V.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())}}ht([pt((function(t,e){t.emitEvent(new dt(dt.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],ae.prototype,"hoverTarget",void 0),ht([pt((function(t,e){const{target:i}=t;i?t.leafList=i instanceof v?i:new v(i):(t.leafList.reset(),t.closeInnerEditor()),t.emitEvent(new dt(dt.SELECT,{editor:t,value:i,oldValue:e})),t.checkOpenedGroups(),t.editing?t.waitLeafer((()=>{t.multiple&&$t(t),Ft(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):(t.updateEditTool(),t.removeTargetEvents())}))],ae.prototype,"target",void 0);class he{static registerInnerEditor(){se.register(this)}get tag(){return"InnerEditor"}get editBox(){return this.editor.editBox}constructor(t){this.editor=t,this.create()}onCreate(){}create(){this.view=new h,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)}}let le=class extends he{static registerEditTool(){se.register(this)}get tag(){return"EditTool"}onMove(t){const{moveX:e,moveY:i,editor:s}=t,{app:o,list:n}=s;o.lockLayout(),n.forEach((t=>{t.moveWorld(e,i)})),o.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="scale"!==n.getEditSize(t);s?t.transformWorld(s,r):t.scaleOfWorld(o,e,i,r)})),r.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:s,editor:o}=t,{app:n,list:r}=o;n.lockLayout(),r.forEach((t=>{const n="scale"!==o.getEditSize(t);i?t.transformWorld(i,n):t.rotateOfWorld(s,e)})),n.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="scale"!==n.getEditSize(t);s?t.transformWorld(s,r):t.skewOfWorld(o,e,i,r)})),r.unlockLayout()}load(){this.editBox.view.visible=!0,this.onLoad()}update(){const{editor:t,editBox:e}=this,{simulateTarget:i,element:s}=t;t.multiple&&i.parent.updateLayout();const{x:o,y:n,scaleX:r,scaleY:a,rotation:h,skewX:l,skewY:d,width:c,height:g}=s.getLayoutBounds("box",t,!0);e.set({x:o,y:n,scaleX:r,scaleY:a,rotation:h,skewX:l,skewY:d}),e.update({x:0,y:0,width:c,height:g}),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}};le=ht([ee()],le);const{left:de,right:ce}=i,{move:ge,copy:ue}=b;let fe=class extends le{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(t){const{drag:e,direction:i,lockRatio:s,around:o}=t,n=t.target,r=i===de;if(n.pathInputed){const{path:t}=n.__,{from:i,to:a}=this.getFromToByPath(t);this.dragPoint(i,a,r,o,this.getInnerMove(n,e,s)),t[1]=i.x,t[2]=i.y,t[4]=a.x,t[5]=a.y,n.path=t}else if(n.points){const{points:t}=n,{from:i,to:a}=this.getFromToByPoints(t);this.dragPoint(i,a,r,o,this.getInnerMove(n,e,s)),t[0]=i.x,t[1]=i.y,t[2]=a.x,t[3]=a.y,n.points=t}else{const t=O(),{toPoint:i}=n;n.rotation=0,this.dragPoint(t,i,r,o,this.getInnerMove(n,e,s)),n.getLocalPointByInner(t,null,null,!0),n.getLocalPointByInner(i,null,null,!0),n.x=t.x,n.y=t.y,n.getInnerPointByLocal(i,null,null,!0),n.toPoint=i}}getInnerMove(t,e,i){const s=e.getInnerMove(t);return i&&(Math.abs(s.x)>Math.abs(s.y)?s.y=0:s.x=0),s}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,s,o){const{x:n,y:r}=o;i?(ge(t,n,r),s&&ge(e,-n,-r)):(s&&ge(t,-n,-r),ge(e,n,r))}onSkew(t){}onUpdate(){const{editBox:t}=this,{rotatePoints:e,resizeLines:i,resizePoints:s,rect:o}=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),o.pen.clearPath().moveTo(i.x,i.y).lineTo(a.x,a.y),ue(s[7],i),ue(e[7],i),ue(s[3],a),ue(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===de||t===ce,s[t].visible=a,e[t].visible=!r&&a}};fe=ht([ee()],fe),S.editor=function(t){return new ae(t)},g.setEditConfig=function(t){c(this.prototype,"editConfig",{get(){return"function"==typeof t?t(this):t}})},g.setEditOuter=function(t){c(this.prototype,"editOuter",{get(){return"string"==typeof t?t:t(this)}})},g.setEditInner=function(t){c(this.prototype,"editInner",{get(){return"string"==typeof t?t:t(this)}})};export{Ut as EditBox,At as EditDataHelper,Yt as EditPoint,Tt as EditSelect,Ot as EditSelectHelper,le as EditTool,se as EditToolCreator,ae as Editor,dt as EditorEvent,re as EditorGroupEvent,Jt as EditorHelper,ct as EditorMoveEvent,ut as EditorRotateEvent,gt as EditorScaleEvent,ft as EditorSkewEvent,he as InnerEditor,ne as InnerEditorEvent,fe as LineEditTool,N as PathScaler,wt as SelectArea,yt as Stroker,ee as registerEditTool,ie as registerInnerEditor,it as scaleResize,st as scaleResizeFontSize,rt as scaleResizeGroup,ot as scaleResizePath,nt as scaleResizePoints};
1
+ import{PathCommandMap as t,MatrixHelper as e,Direction9 as i,Leaf as s,Text as o,Path as n,Line as r,Polygon as a,Group as h,Box as l,Event as c,defineKey as d,UI as g,Paint as u,Rect as f,Answer as p,Bounds as m,LeafList as v,PointHelper as b,AroundHelper as y,MathHelper as _,Matrix as w,Debug as k,PropertyEvent as E,LeafHelper as L,DataHelper as x,RenderEvent as O,getPointData as T,Creator as S}from"@leafer-ui/draw";import{PointerEvent as M,DragEvent as C,MoveEvent as P,ZoomEvent as B,RotateEvent as R,KeyEvent as V}from"@leafer-ui/core";const{M:H,L:I,C:D,Q:z,Z:A,N:Z,D:W,X:F,G:X,F:Y,O:G,P:U,U:N}=t,j={scale(t,e,i){if(!t)return;let s,o=0,n=t.length;for(;o<n;)switch(s=t[o],s){case H:case I:K(t,e,i,o,1),o+=3;break;case D:K(t,e,i,o,3),o+=7;break;case z:K(t,e,i,o,2),o+=5;break;case A:o+=1;break;case Z:K(t,e,i,o,2),o+=5;break;case W:K(t,e,i,o,2),o+=9;break;case F:K(t,e,i,o,2),o+=6;break;case X:K(t,e,i,o,2),o+=9;break;case Y:K(t,e,i,o,2),o+=5;break;case G:t[o]=X,t.splice(o+4,0,t[o+3],0),K(t,e,i,o,2),o+=9,n+=2;break;case U:t[o]=Y,t.splice(o+4,0,t[o+3]),K(t,e,i,o,2),o+=5,n+=1;break;case N:K(t,e,i,o,2),o+=6}},scalePoints(t,e,i,s,o){for(let n=o?s+1:0,r=o?n+2*o:t.length;n<r;n+=2)t[n]*=e,t[n+1]*=i}},{scalePoints:K}=j,$=e.get(),{topLeft:q,top:Q,topRight:J,right:tt,bottom:et,left:it}=i;function st(t,e,i){t.pathInputed?nt(t,e,i):(1!==e&&(t.width*=e),1!==i&&(t.height*=i))}function ot(t,e,i){const{app:s}=t,o=s&&s.editor;let n=e;if(o.editing){const s=t.__layout;let{width:r,height:a}=s.boxBounds;switch(r*=i-e,a*=e-i,o.resizeDirection){case Q:case et:n=i,s.affectScaleOrRotation?t.moveInner(-r/2,0):t.x-=r/2;break;case it:case tt:s.affectScaleOrRotation?t.moveInner(0,-a/2):t.y-=a/2;break;case q:case J:s.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 nt(t,e,i){j.scale(t.__.path,e,i),t.path=t.__.path}function rt(t,e,i){j.scalePoints(t.__.points,e,i),t.points=t.__.points}function at(t,e,i){const{children:s}=t;for(let t=0;t<s.length;t++)$.a=e,$.d=i,s[t].transform($,!0)}const ht=s.prototype;function lt(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(n<3?o(r):n>3?o(e,i,r):o(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}function ct(t){return t?t instanceof Array?t:[t]:[]}ht.scaleResize=function(t,e=t,i){const s=this;i||s.editConfig&&"scale"===s.editConfig.editSize?(s.scaleX*=t,s.scaleY*=e):(t<0&&(s.scaleX*=-1,t=-t),e<0&&(s.scaleY*=-1,e=-e),this.__scaleResize(t,e))},ht.__scaleResize=function(t,e){st(this,t,e)},ht.resizeWidth=function(t){const e=t/this.getBounds("box","local").width;this.scaleOf(this.__layout.boxBounds,e,this.__.lockRatio?e:1,!0)},ht.resizeHeight=function(t){const e=t/this.getBounds("box","local").height;this.scaleOf(this.__layout.boxBounds,this.__.lockRatio?e:1,e,!0)},o.prototype.__scaleResize=function(t,e){this.__.resizeFontSize||this.editConfig&&"font-size"===this.editConfig.editSize?ot(this,t,e):st(this,t,e)},n.prototype.__scaleResize=function(t,e){nt(this,t,e)},r.prototype.__scaleResize=function(t,e){this.pathInputed?nt(this,t,e):this.points?rt(this,t,e):this.width*=t},a.prototype.__scaleResize=function(t,e){this.pathInputed?nt(this,t,e):this.points?rt(this,t,e):st(this,t,e)},h.prototype.__scaleResize=function(t,e){at(this,t,e)},l.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?at(this,t,e):(st(this,t,e),this.__.resizeChildren&&at(this,t,e))},"function"==typeof SuppressedError&&SuppressedError;class dt extends c{get list(){return ct(this.value)}get oldList(){return ct(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}dt.SELECT="editor.select",dt.HOVER="editor.hover";class gt extends dt{constructor(t,e){super(t,e)}}gt.MOVE="editor.move";class ut extends dt{constructor(t,e){super(t,e)}}ut.SCALE="editor.scale";class ft extends dt{constructor(t,e){super(t,e)}}ft.ROTATE="editor.rotate";class pt extends dt{constructor(t,e){super(t,e)}}function mt(t){return(e,i)=>{const s="_"+i;d(e,i,{get(){return this[s]},set(e){const i=this[s];i!==e&&(this[s]=e,t(this,i))}})}}pt.SKEW="editor.skew";const vt=e.get(),{abs:bt}=Math,{copy:yt,scale:_t}=e;class wt extends g{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){this.set(e),this.target=t}__draw(t,e){const{list:i}=this;if(i.length){let s;const o=this.__,{stroke:n,strokeWidth:r,fill:a}=o,{bounds:h}=e;for(let l=0;l<i.length;l++){s=i[l];const{worldTransform:c,worldRenderBounds:d}=s;if(h&&h.hit(d,e.matrix)){const i=bt(c.scaleX),h=bt(c.scaleY);if(i!==h){yt(vt,c),_t(vt,1/i,1/h),t.setWorld(vt,e.matrix),t.beginPath(),o.strokeWidth=r;const{x:n,y:a,width:l,height:d}=s.__layout.boxBounds;t.rect(n*i,a*h,l*i,d*h)}else t.setWorld(c,e.matrix),t.beginPath(),s.__.__useArrow?s.__drawPath(t):s.__.__pathForRender?s.__drawRenderPath(t):s.__drawPathByBox(t),o.strokeWidth=r/bt(c.scaleX);n&&("string"==typeof n?u.stroke(n,this,t):u.strokes(n,this,t)),a&&("string"==typeof a?u.fill(a,this,t):u.fills(a,this,t))}}o.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}lt([mt((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],wt.prototype,"target",void 0);class kt extends h{constructor(t){super(t),this.strokeArea=new f({strokeAlign:"center"}),this.fillArea=new f,this.visible=this.hittable=!1,this.addMany(this.fillArea,this.strokeArea)}setStyle(t,e){const{visible:i,stroke:s,strokeWidth:o}=t;this.visible=i,this.strokeArea.reset(Object.assign({stroke:s,strokeWidth:o},e||{})),this.fillArea.reset({visible:!e,fill:s,opacity:.2})}setBounds(t){this.strokeArea.set(t),this.fillArea.set(t)}}const{No:Et,Yes:Lt,NoAndSkip:xt,YesAndSkip:Ot}=p,Tt={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?Ot:xt;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?Ot:Et;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return Lt}return Et}return t.isBranch?xt:Et}},{findOne:St}=Tt;class Mt extends h{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(t){super(),this.hoverStroker=new wt,this.targetStroker=new wt,this.bounds=new m,this.selectArea=new kt,this.__eventIds=[],this.editor=t,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:s,hoverStyle:o}=t.mergeConfig;this.hoverStroker.setTarget(s?this.editor.hoverTarget:null,Object.assign({stroke:e,strokeWidth:i},o||{}))}}onSelect(){if(this.running){const{mergeConfig:t,list:e}=this.editor,{stroke:i,strokeWidth:s}=t;this.targetStroker.setTarget(e,{stroke:i,strokeWidth:Math.max(1,s/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:s}=e.mergeConfig,{x:o,y:n}=t.getInnerPoint(this);this.bounds.set(o,n),this.selectArea.setStyle({visible:!0,stroke:i,x:o,y:n},s),this.selectArea.setBounds(this.bounds.get()),this.originList=e.leafList.clone()}}onDrag(t){if(!t.multiTouch){if(this.editor.dragging)return this.onDragEnd(t);if(this.dragging){const{editor:e}=this,i=t.getInnerTotal(this),s=this.bounds.clone().unsign(),o=new v(e.app.find(Tt.findBounds,s));if(this.bounds.width=i.x,this.bounds.height=i.y,this.selectArea.setBounds(s.get()),o.length){const t=[];this.originList.forEach((e=>{o.has(e)||t.push(e)})),o.forEach((e=>{this.originList.has(e)||t.push(e)})),(t.length!==e.list.length||e.list.some(((e,i)=>e!==t[i])))&&(e.target=t)}else e.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&&!St(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new v(this.editor.editBox.rect)};return St(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):St(t.path)}isMultipleSelect(t){return t.shiftKey||this.editor.mergeConfig.continuousSelect}__listenEvents(){const{editor:t}=this;t.waitLeafer((()=>{const{app:e}=t;e.selector.proxy=t,this.__eventIds=[t.on_(dt.HOVER,this.onHover,this),t.on_(dt.SELECT,this.onSelect,this),e.on_(M.MOVE,this.onPointerMove,this),e.on_(M.BEFORE_DOWN,this.onBeforeDown,this),e.on_(M.TAP,this.onTap,this),e.on_(C.START,this.onDragStart,this,!0),e.on_(C.DRAG,this.onDrag,this),e.on_(C.END,this.onDragEnd,this),e.on_(P.MOVE,this.onAutoMove,this),e.on_([B.ZOOM,P.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:Ct,top:Pt,topRight:Bt,right:Rt,bottomRight:Vt,bottom:Ht,bottomLeft:It,left:Dt}=i,{toPoint:zt}=y,{within:At}=_,Zt={getScaleData(t,e,i,s,o,n,r,a){let h,l={},c=1,d=1;const{boxBounds:g,widthRange:u,heightRange:f}=t,{width:p,height:m}=e;n&&(s.x*=2,s.y*=2);const v=t.scaleX/e.scaleX,b=t.scaleY/e.scaleY,y=v<0?-1:1,_=b<0?-1:1,w=a?v:y*g.width/p,k=a?b:_*g.height/m;s.x*=a?v:y,s.y*=a?b:_,Math.abs(s.x)===p&&(s.x+=.1),Math.abs(s.y)===m&&(s.y+=.1);const E=(-s.y+m)/m,L=(s.x+p)/p,x=(s.y+m)/m,O=(-s.x+p)/p;switch(i){case Pt:d=E,h="bottom";break;case Rt:c=L,h="left";break;case Ht:d=x,h="top";break;case Dt:c=O,h="right";break;case Ct:d=E,c=O,h="bottom-right";break;case Bt:d=E,c=L,h="bottom-left";break;case Vt:d=x,c=L,h="top-left";break;case It:d=x,c=O,h="top-right"}if(o){if(!("corner"===o&&i%2)){let t;switch(i){case Pt:case Ht:t=d;break;case Dt:case Rt:t=c;break;default:t=Math.sqrt(Math.abs(c*d))}c=c<0?-t:t,d=d<0?-t:t}}if(c/=w,d/=k,!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=At(e*c,u)/e}if(f){const e=g.height*t.scaleY;d=At(e*d,f)/e}return zt(n||h,g,l,!0),{origin:l,scaleX:c,scaleY:d,direction:i,lockRatio:o,around:n}},getRotateData(t,e,i,s,o){let n,r={};switch(e){case Ct:n="bottom-right";break;case Bt:n="bottom-left";break;case Vt:n="top-left";break;case It:n="top-right";break;default:n="center"}return zt(o||n,t,r,!0),{origin:r,rotation:b.getRotation(s,r,i)}},getSkewData(t,e,i,s){let o,n,r={},a=0,h=0;switch(e){case Pt:n={x:.5,y:0},o="bottom",a=1;break;case Ht:n={x:.5,y:1},o="top",a=1;break;case Dt:n={x:0,y:.5},o="right",h=1;break;case Rt:n={x:1,y:.5},o="left",h=1}const{width:l,height:c}=t;n.x=n.x*l,n.y=n.y*c,zt(s||o,t,r,!0);const d=b.getRotation(n,r,{x:n.x+(a?i.x:0),y:n.y+(h?i.y:0)});return a?a=-d:h=d,{origin:r,skewX:a,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 Dt:t=Rt;break;case Ct:t=Bt;break;case It:t=Vt;break;case Rt:t=Dt;break;case Bt:t=Ct;break;case Vt:t=It}if(i)switch(t){case Pt:t=Ht;break;case Ct:t=It;break;case Bt:t=Vt;break;case Ht:t=Pt;break;case It:t=Ct;break;case Vt:t=Bt}return t}},Wt={};function Ft(t,e){const{editBox:i}=t,s=i.enterPoint;if(!s||!t.editing||!i.visible)return;if("circle"===s.name)return;if("button"===s.pointType)return void(s.cursor||(s.cursor="pointer"));let{rotation:o}=i;const{resizeCursor:n,rotateCursor:r,skewCursor:a,resizeable:h,rotateable:l,skewable:c}=t.mergeConfig,{pointType:d}=s,{flippedX:g,flippedY:u}=i;let f="resize"===d;f&&l&&(e.metaKey||e.ctrlKey||!h)&&(f=!1);const p=c&&!f&&"resize-line"===s.name?a:f?n:r;o+=45*(Zt.getFlipDirection(s.direction,g,u)+1),o=2*Math.round(_.formatRotation(o,!0)/2);const{url:m,x:v,y:b}=p,y=m+o;Wt[y]?s.cursor=Wt[y]:Wt[y]=s.cursor={url:Yt(m,o),x:v,y:b}}function Xt(t){t.editBox.rect.cursor=t.mergeConfig.moveCursor}function Yt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class Gt extends l{}const Ut=["top","right","bottom","left"];class Nt extends h{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(t){super(),this.view=new h,this.rect=new l({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 h({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.__listenEvents()}create(){let t,e,i;const{view:s,resizePoints:o,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 s=0;s<8;s++)t=new Gt({name:"rotate-point",around:c[s],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new Gt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",s)),i=new Gt({name:"resize-point",hitRadius:5}),o.push(i),this.listenPointEvents(i,"resize",s);this.listenPointEvents(h,"rotate",2),s.addMany(...n,a,h,l,...r,...o),this.add(s)}load(){const{mergeConfig:t,element:e,single:i}=this.editor,{rect:s,circle:o,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);o.set(this.getPointStyle(t.circle||t.rotatePoint||l[0])),s.set(Object.assign({stroke:r,strokeWidth:a},t.rect||{})),s.hittable=!i&&!!h,s.syncEventer=i&&this.editor,i&&h&&(e.syncEventer=s,this.app.interaction.bottomList=[{target:s,proxy:e}])}update(t){if(this.visible=!this.editor.element.locked,this.view.worldOpacity){const{mergeConfig:e}=this.editor,{width:i,height:s}=t,{rect:o,circle:n,buttons:r,resizePoints:a,rotatePoints:h,resizeLines:l}=this,{middlePoint:c,resizeable:d,rotateable:g,hideOnSmall:u}=e,f="number"==typeof u?u:10,p=!(u&&i<f&&s<f);let m,v,b,_={};for(let o=0;o<8;o++)y.toPoint(y.directionData[o],t,_),v=a[o],m=h[o],b=l[Math.floor(o/2)],v.set(_),m.set(_),b.set(_),v.visible=b.visible=p&&!(!d&&!g),m.visible=p&&g&&d&&!e.rotatePoint,o%2&&(v.visible=m.visible=p&&!!c,(o+1)/2%2?(b.width=i,v.width>i-30&&(v.visible=!1)):(b.height=s,v.rotation=90,v.width>s-30&&(v.visible=!1)));n.visible=p&&g&&!(!e.circle&&!e.rotatePoint),n.visible&&this.layoutCircle(e),o.path&&(o.path=null),o.set(Object.assign(Object.assign({},t),{visible:!0})),r.visible=p&&r.children.length>0,r.visible&&this.layoutButtons(e)}}layoutCircle(t){const{circleDirection:e,circleMargin:i,buttonsMargin:s,buttonsDirection:o,middlePoint:n}=t,r=Ut.indexOf(e||(this.buttons.children.length&&"bottom"===o?"top":"bottom"));this.setButtonPosition(this.circle,r,i||s,!!n)}layoutButtons(t){const{buttons:e}=this,{buttonsDirection:i,buttonsFixed:s,buttonsMargin:o,middlePoint:n}=t,{flippedX:r,flippedY:a}=this;let h=Ut.indexOf(i);(h%2&&r||(h+1)%2&&a)&&s&&(h=(h+2)%4);const l=s?Zt.getRotateDirection(h,this.flippedOne?this.rotation:-this.rotation,4):h;this.setButtonPosition(e,l,o,!!n),s&&(e.rotation=90*(l-h)),e.scaleX=r?-1:1,e.scaleY=a?-1:1}setButtonPosition(t,e,i,s){const o=this.resizePoints[2*e+1],n=e%2,r=e&&3!==e?1:-1,a=(i+(e%2?(s?o.width:0)+t.boxBounds.width:(s?o.height:0)+t.boxBounds.height)/2)*r;n?(t.x=o.x+a,t.y=o.y):(t.x=o.x,t.y=o.y+a)}unload(){this.visible=!1}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:s,pointSize:o,pointRadius:n}=this.editor.mergeConfig,r={fill:s,stroke:e,strokeWidth:i,around:"center",strokeAlign:"center",width:o,height:o,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),Ft(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;if(i.isBranch){if(i.textBox){const t=i.children.find((t=>t.editable&&t instanceof o));if(t)return e.openInnerEditor(t)}e.openGroup(i),e.target=e.selector.findDeepOne(t)}else e.openInnerEditor()}}listenPointEvents(t,e,i){const{editor:s}=this;t.direction=i,t.pointType=e,t.on_(C.START,this.onDragStart,this),t.on_(C.DRAG,this.onDrag,this),t.on_(C.END,this.onDragEnd,this),t.on_(M.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(M.ENTER,(e=>{this.enterPoint=t,Ft(s,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(dt.SELECT,this.onSelect,this),t.on_(C.START,this.onDragStart,this),t.on_(C.DRAG,e.onMove,e),t.on_(C.END,this.onDragEnd,this),t.on_(M.ENTER,(()=>Xt(e))),t.on_(M.DOUBLE_TAP,this.onDoubleTap,this),t.on_(M.LONG_PRESS,this.onLongPress,this)]}__removeListenEvents(){this.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}class jt extends g{constructor(t){super(),this.editor=t,this.hittable=!1}__draw(t,e){const{editor:i}=this,{mask:s}=i.mergeConfig;if(s&&i.list.length){const{rect:o}=i.editBox,{width:n,height:r}=o.__;t.resetTransform(),t.fillWorld(t.bounds,!0===s?"rgba(0,0,0,0.8)":s),t.setWorld(o.__world,e.matrix),t.clearRect(0,0,n,r)}}destroy(){this.editor=null,super.destroy()}}const Kt='\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"/>',$t={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${Kt}\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${Kt}\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${Kt}\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},qt=new m;function Qt(t){const{simulateTarget:e,list:i}=t,{zoomLayer:s}=i[0].leafer.zoomLayer;e.safeChange((()=>e.reset(qt.setListWithFn(i,(t=>t.getBounds("box","page"))).get()))),s.add(e)}const Jt=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),te=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),ee={group(t,e,i){t.sort(te);const{app:s,parent:o}=t[0];let n;n=i&&i.add?i:new h(i),o.addAt(n,o.children.indexOf(t[0])),t.sort(Jt);const r=new w(e.worldTransform);return r.divideParent(o.worldTransform),n.setTransform(r),n.editable=!0,n.hitChildren=!1,s.lockLayout(),t.forEach((t=>t.dropTo(n))),s.unlockLayout(),n},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach((t=>{if(t.isBranch&&!t.isBranchLeaf){const{parent:e,children:s}=t;for(;s.length;)i.push(s[0]),s[0].dropTo(e,e.children.indexOf(t));t.remove()}else i.push(t)})),e.unlockLayout(),i},toTop(t){t.sort(Jt),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(te),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},ie=k.get("EditToolCreator");function se(){return t=>{ne.register(t)}}const oe=se,ne={list:{},register(t){const{tag:e}=t.prototype;re[e]?ie.repeat(e):re[e]=t},get:(t,e)=>new re[t](e)},{list:re}=ne;class ae extends dt{constructor(t,e){super(t,e)}}ae.BEFORE_OPEN="innerEditor.before_open",ae.OPEN="innerEditor.open",ae.BEFORE_CLOSE="innerEditor.before_close",ae.CLOSE="innerEditor.close";class he extends dt{constructor(t,e){super(t,e)}}he.GROUP="editor.group",he.BEFORE_UNGROUP="editor.before_ungroup",he.UNGROUP="editor.ungroup",he.OPEN="editor.open_group",he.CLOSE="editor.close_group";const{updateMatrix:le}=L,ce={x:1,y:1,scaleX:1,scaleY:1,rotation:1,skewX:1,skewY:1},de="top-left";class ge extends f{get __tag(){return"SimulateElement"}constructor(t){super(),this.checkChange=!0,this.canChange=!0,this.visible=this.hittable=!1,this.on(E.CHANGE,(e=>{if(this.checkChange&&ce[e.attrName]){const{attrName:i,newValue:s,oldValue:o}=e,n="s"===i[0]?(s||1)/(o||1):(s||0)-(o||0);this.canChange=!1;const r=this.__;r[i]=o,le(this.parent),le(this);const a=new w(this.__world);switch(r[i]=s,this.__layout.rotationChange(),le(this),this.changedTransform=new w(this.__world).divide(a),i){case"x":t.move(n,0);break;case"y":t.move(0,n);break;case"rotation":t.rotateOf(de,n);break;case"scaleX":t.scaleOf(de,n,1);break;case"scaleY":t.scaleOf(de,1,n);break;case"skewX":t.skewOf(de,n,0);break;case"skewY":t.skewOf(de,0,n)}this.canChange=!0}}))}safeChange(t){this.canChange&&(this.checkChange=!1,t(),this.checkChange=!0)}}class ue extends h{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(t,e){super(e),this.config=x.clone($t),this.leafList=new v,this.openedGroupList=new v,this.simulateTarget=new ge(this),this.editBox=new Nt(this),this.editToolList={},this.selector=new Mt(this),this.editMask=new jt(this),this.targetEventIds=[],t&&(this.config=x.default(t,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&&Qt(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]||ne.get(t,this),this.editBox.load(),this.editTool.load()}}getEditSize(t){return this.mergeConfig.editSize}onMove(t){if(t instanceof P){if("drag"!==t.moveType){const{moveable:e,resizeable:i}=this.mergeConfig,s=t.getLocalMove(this.element);"move"===e?(t.stop(),this.move(s.x,s.y)):"zoom"===i&&t.stop()}}else{const e={x:t.totalX,y:t.totalY};t.shiftKey&&(Math.abs(e.x)>Math.abs(e.y)?e.y=0:e.x=0),this.move(C.getValidMove(this.element,this.dragStartPoint,e))}}onScale(t){const{element:e}=this;let{around:i,lockRatio:s,resizeable:o,flipable:n,editSize:r}=this.mergeConfig;if(t instanceof B)"zoom"===o&&(t.stop(),this.scaleOf(e.getBoxPoint(t),t.scale,t.scale));else{const{direction:o}=t.current;(t.shiftKey||e.lockRatio)&&(s=!0);const a=Zt.getScaleData(e,this.dragStartBounds,o,t.getInnerTotal(e),s,Zt.getAround(i,t.altKey),n,this.multiple||"scale"===r);this.editTool.onScaleWithDrag?(a.drag=t,this.scaleWithDrag(a)):this.scaleOf(a.origin,a.scaleX,a.scaleY)}}onRotate(t){const{skewable:e,rotateable:i,around:s,rotateGap:o}=this.mergeConfig,{direction:n,name:r}=t.current;if(e&&"resize-line"===r)return this.onSkew(t);const{element:a}=this;let h,l;if(t instanceof R){if("rotate"!==i)return;t.stop(),l=t.rotation,h=a.getBoxPoint(t)}else{const e={x:t.x-t.moveX,y:t.y-t.moveY},i=Zt.getRotateData(a.boxBounds,n,t.getBoxPoint(a),a.getBoxPoint(e),t.shiftKey?null:a.around||a.origin||s||"center");l=i.rotation,h=i.origin}l=_.getGapRotation(l,o,a.rotation),l&&(a.scaleX*a.scaleY<0&&(l=-l),this.rotateOf(h,_.float(l,2)))}onSkew(t){const{element:e}=this,{around:i}=this.mergeConfig,{origin:s,skewX:o,skewY:n}=Zt.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),Zt.getAround(i,t.altKey));(o||n)&&this.skewOf(s,o,n)}move(t,e=0){if(!this.checkTransform("moveable"))return;const{element:i}=this,s=i.getWorldPointByLocal("object"==typeof t?Object.assign({},t):{x:t,y:e},null,!0);this.multiple&&i.safeChange((()=>i.move(t,e)));const o=new gt(gt.MOVE,{target:i,editor:this,moveX:s.x,moveY:s.y});this.editTool.onMove(o),this.emitEvent(o)}scaleWithDrag(t){if(!this.checkTransform("resizeable"))return;const{element:e}=this,i=new ut(ut.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,s){if(!this.checkTransform("resizeable"))return;const{element:o}=this,n=this.getWorldOrigin(t),r=this.multiple&&this.getChangedTransform((()=>o.safeChange((()=>o.scaleOf(t,e,i))))),a=new ut(ut.SCALE,{target:o,editor:this,worldOrigin:n,scaleX:e,scaleY:i,transform:r});this.editTool.onScale(a),this.emitEvent(a)}flip(t){if(!this.checkTransform("resizeable"))return;const{element:e}=this,i=this.getWorldOrigin("center"),s=this.multiple?this.getChangedTransform((()=>e.safeChange((()=>e.flip(t))))):new w(L.getFlipTransform(e,t)),o=new ut(ut.SCALE,{target:e,editor:this,worldOrigin:i,scaleX:"x"===t?-1:1,scaleY:"y"===t?-1:1,transform:s});this.editTool.onScale(o),this.emitEvent(o)}rotateOf(t,e){if(!this.checkTransform("rotateable"))return;const{element:i}=this,s=this.getWorldOrigin(t),o=this.multiple&&this.getChangedTransform((()=>i.safeChange((()=>i.rotateOf(t,e))))),n=new ft(ft.ROTATE,{target:i,editor:this,worldOrigin:s,rotation:e,transform:o});this.editTool.onRotate(n),this.emitEvent(n)}skewOf(t,e,i=0,s){if(!this.checkTransform("skewable"))return;const{element:o}=this,n=this.getWorldOrigin(t),r=this.multiple&&this.getChangedTransform((()=>o.safeChange((()=>o.skewOf(t,e,i))))),a=new pt(pt.SKEW,{target:o,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(t){return this.element.getWorldPoint(L.getInnerOrigin(this.element,t))}getChangedTransform(t){const{element:e}=this;if(this.multiple&&!e.canChange)return e.changedTransform;const i=new w(e.worldTransform);return t(),new w(e.worldTransform).divide(i)}group(t){return this.multiple&&(this.target=ee.group(this.list,this.element,t),this.emitGroupEvent(he.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach((t=>t.isBranch&&this.emitGroupEvent(he.BEFORE_UNGROUP,t))),this.target=ee.ungroup(t),t.forEach((t=>t.isBranch&&this.emitGroupEvent(he.UNGROUP,t)))),this.list}openGroup(t){this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(he.OPEN,t)}closeGroup(t){this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(he.CLOSE,t)}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:e}=t;this.editing&&(e=[],t.forEach((t=>this.list.every((e=>!L.hasParent(e,t)))&&e.push(t)))),e.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 he(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&&ne.list[i]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[i]||ne.get(i,this),this.innerEditor.editTarget=e,this.emitInnerEvent(ae.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(ae.OPEN))}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(ae.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(ae.CLOSE),this.editTool.load(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,s=new ae(t,{editTarget:i,innerEditor:e});this.emitEvent(s),i.emitEvent(s)}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(ee.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(ee.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{app:t,leafer:e}=this;this.targetEventIds=[e.on_(O.START,this.update,this),t.on_(O.CHILD_START,this.forceRender,this),t.on_(P.BEFORE_MOVE,this.onMove,this,!0),t.on_(B.BEFORE_ZOOM,this.onScale,this,!0),t.on_(R.BEFORE_ROTATE,this.onRotate,this,!0),t.on_([V.HOLD,V.UP],(t=>{Ft(this,t)})),t.on_(V.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())}}lt([mt((function(t,e){t.emitEvent(new dt(dt.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],ue.prototype,"hoverTarget",void 0),lt([mt((function(t,e){const{target:i}=t;i?t.leafList=i instanceof v?i:new v(i):(t.simulateTarget.remove(),t.leafList.reset(),t.closeInnerEditor()),t.emitEvent(new dt(dt.SELECT,{editor:t,value:i,oldValue:e})),t.checkOpenedGroups(),t.editing?t.waitLeafer((()=>{t.multiple&&Qt(t),Xt(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):(t.updateEditTool(),t.removeTargetEvents())}))],ue.prototype,"target",void 0);class fe{static registerInnerEditor(){ne.register(this)}get tag(){return"InnerEditor"}get editBox(){return this.editor.editBox}constructor(t){this.editor=t,this.create()}onCreate(){}create(){this.view=new h,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)}}let pe=class extends fe{static registerEditTool(){ne.register(this)}get tag(){return"EditTool"}onMove(t){const{moveX:e,moveY:i,editor:s}=t,{app:o,list:n}=s;o.lockLayout(),n.forEach((t=>{t.moveWorld(e,i)})),o.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="scale"!==n.getEditSize(t);s?t.transformWorld(s,r):t.scaleOfWorld(o,e,i,r)})),r.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:s,editor:o}=t,{app:n,list:r}=o;n.lockLayout(),r.forEach((t=>{const n="scale"!==o.getEditSize(t);i?t.transformWorld(i,n):t.rotateOfWorld(s,e)})),n.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="scale"!==n.getEditSize(t);s?t.transformWorld(s,r):t.skewOfWorld(o,e,i,r)})),r.unlockLayout()}load(){this.editBox.view.visible=!0,this.onLoad()}update(){const{editor:t,editBox:e}=this,{x:i,y:s,scaleX:o,scaleY:n,rotation:r,skewX:a,skewY:h,width:l,height:c}=t.element.getLayoutBounds("box",t,!0);e.set({x:i,y:s,scaleX:o,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()}};pe=lt([se()],pe);const{left:me,right:ve}=i,{move:be,copy:ye}=b;let _e=class extends pe{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(t){const{drag:e,direction:i,lockRatio:s,around:o}=t,n=t.target,r=i===me;if(n.pathInputed){const{path:t}=n.__,{from:i,to:a}=this.getFromToByPath(t);this.dragPoint(i,a,r,o,this.getInnerMove(n,e,s)),t[1]=i.x,t[2]=i.y,t[4]=a.x,t[5]=a.y,n.path=t}else if(n.points){const{points:t}=n,{from:i,to:a}=this.getFromToByPoints(t);this.dragPoint(i,a,r,o,this.getInnerMove(n,e,s)),t[0]=i.x,t[1]=i.y,t[2]=a.x,t[3]=a.y,n.points=t}else{const t=T(),{toPoint:i}=n;n.rotation=0,this.dragPoint(t,i,r,o,this.getInnerMove(n,e,s)),n.getLocalPointByInner(t,null,null,!0),n.getLocalPointByInner(i,null,null,!0),n.x=t.x,n.y=t.y,n.getInnerPointByLocal(i,null,null,!0),n.toPoint=i}}getInnerMove(t,e,i){const s=e.getInnerMove(t);return i&&(Math.abs(s.x)>Math.abs(s.y)?s.y=0:s.x=0),s}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,s,o){const{x:n,y:r}=o;i?(be(t,n,r),s&&be(e,-n,-r)):(s&&be(t,-n,-r),be(e,n,r))}onSkew(t){}onUpdate(){const{editBox:t}=this,{rotatePoints:e,resizeLines:i,resizePoints:s,rect:o}=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),o.pen.clearPath().moveTo(i.x,i.y).lineTo(a.x,a.y),ye(s[7],i),ye(e[7],i),ye(s[3],a),ye(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===me||t===ve,s[t].visible=a,e[t].visible=!r&&a}};_e=lt([se()],_e),S.editor=function(t){return new ue(t)},g.setEditConfig=function(t){d(this.prototype,"editConfig",{get(){return"function"==typeof t?t(this):t}})},g.setEditOuter=function(t){d(this.prototype,"editOuter",{get(){return"string"==typeof t?t:t(this)}})},g.setEditInner=function(t){d(this.prototype,"editInner",{get(){return"string"==typeof t?t:t(this)}})};export{Nt as EditBox,Zt as EditDataHelper,Gt as EditPoint,Mt as EditSelect,Tt as EditSelectHelper,pe as EditTool,ne as EditToolCreator,ue as Editor,dt as EditorEvent,he as EditorGroupEvent,ee as EditorHelper,gt as EditorMoveEvent,ft as EditorRotateEvent,ut as EditorScaleEvent,pt as EditorSkewEvent,fe as InnerEditor,ae as InnerEditorEvent,_e as LineEditTool,j as PathScaler,kt as SelectArea,wt as Stroker,se as registerEditTool,oe as registerInnerEditor,st as scaleResize,ot as scaleResizeFontSize,at as scaleResizeGroup,nt as scaleResizePath,rt as scaleResizePoints};