@leafer-in/editor 2.1.11 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { Event, isArray, defineKey, isNull, isUndefined, isObject, MatrixHelper, BoundsHelper, LeafBoundsHelper, getMatrixData, getBoundsData, surfaceType, UI, ColorConvert, isString, Paint, Group, Rect, Bounds, LeafList, Direction9, AroundHelper, MathHelper, PointHelper, isNumber, Box, DataHelper, ResizeEvent, getPointData, Text, Matrix, Debug, LeafHelper, PropertyEvent, Plugin, RenderEvent, LeaferEvent, Creator, dataType } from "@leafer-ui/draw";
1
+ import { Event, isArray, Group, Matrix, defineKey, isNull, isUndefined, isObject, DataHelper, MatrixHelper, BoundsHelper, LeafBoundsHelper, getMatrixData, getBoundsData, surfaceType, UI, ColorConvert, isString, Paint, Rect, Bounds, LeafList, Direction9, AroundHelper, MathHelper, PointHelper, isNumber, Box, Debug, ResizeEvent, getPointData, Text, LeafHelper, PropertyEvent, Plugin, RenderEvent, LeaferEvent, Creator, dataType } from "@leafer-ui/draw";
2
2
 
3
3
  import { PointerEvent, DragEvent, MoveEvent, ZoomEvent, DragBoundsHelper, KeyEvent, RotateEvent, useModule } from "@leafer-ui/core";
4
4
 
@@ -42,6 +42,69 @@ EditorEvent.BEFORE_HOVER = "editor.before_hover";
42
42
 
43
43
  EditorEvent.HOVER = "editor.hover";
44
44
 
45
+ const order = (a, b) => a.parent.children.indexOf(a) - b.parent.children.indexOf(b);
46
+
47
+ const reverseOrder = (a, b) => b.parent.children.indexOf(b) - a.parent.children.indexOf(a);
48
+
49
+ const EditorHelper = {
50
+ group(list, element, userGroup) {
51
+ list.sort(reverseOrder);
52
+ const {app: app, parent: parent} = list[0];
53
+ let group;
54
+ if (userGroup && userGroup.add) {
55
+ group = userGroup;
56
+ } else {
57
+ group = new Group(userGroup);
58
+ }
59
+ parent.addAt(group, parent.children.indexOf(list[0]));
60
+ list.sort(order);
61
+ const matrx = new Matrix(element.worldTransform);
62
+ matrx.divideParent(parent.scrollWorldTransform);
63
+ group.setTransform(matrx);
64
+ group.editable = true;
65
+ group.hitChildren = false;
66
+ app.lockLayout();
67
+ list.forEach(child => child.dropTo(group));
68
+ app.unlockLayout();
69
+ return group;
70
+ },
71
+ ungroup(list) {
72
+ const {app: app} = list[0];
73
+ const ungroupList = [];
74
+ app.lockLayout();
75
+ list.forEach(leaf => {
76
+ if (leaf.isBranch) {
77
+ const {parent: parent, children: children} = leaf;
78
+ while (children.length) {
79
+ ungroupList.push(children[0]);
80
+ children[0].dropTo(parent, parent.children.indexOf(leaf));
81
+ }
82
+ if (leaf.isBranchLeaf) ungroupList.push(leaf); else leaf.remove();
83
+ } else {
84
+ ungroupList.push(leaf);
85
+ }
86
+ });
87
+ app.unlockLayout();
88
+ return ungroupList;
89
+ },
90
+ toTop(list) {
91
+ list.sort(order);
92
+ list.forEach(leaf => {
93
+ if (leaf.parent) leaf.parent.add(leaf);
94
+ });
95
+ },
96
+ toBottom(list) {
97
+ list.sort(reverseOrder);
98
+ list.forEach(leaf => {
99
+ if (leaf.parent) leaf.parent.addAt(leaf, 0);
100
+ });
101
+ },
102
+ mergeMaskConfig(_mergeConfig, _editor) {},
103
+ getSiblingMaskElements(_editor) {
104
+ return undefined;
105
+ }
106
+ };
107
+
45
108
  function targetAttr(fn) {
46
109
  return (target, key) => {
47
110
  const privateKey = "_" + key;
@@ -90,6 +153,7 @@ function mergeConfigAttr() {
90
153
  get() {
91
154
  const {config: config, element: element, dragPoint: dragPoint, editBox: editBox, editTool: editTool, innerEditor: innerEditor, app: app} = this, mergeConfig = Object.assign({}, config);
92
155
  if (innerEditor) innerEditor.editConfig && Object.assign(mergeConfig, innerEditor.editConfig); else if (editTool) editTool.editConfig && Object.assign(mergeConfig, editTool.editConfig);
156
+ if (element && element.mask) EditorHelper.mergeMaskConfig(mergeConfig, this);
93
157
  if (element && element.editConfig) {
94
158
  let {editConfig: editConfig} = element;
95
159
  if (editConfig.hover || editConfig.hoverStyle || editConfig.hoverPathType) {
@@ -116,7 +180,28 @@ function mergeConfigAttr() {
116
180
  };
117
181
  }
118
182
 
119
- const {abs: abs$1} = Math;
183
+ function editToolMergeConfigAttr() {
184
+ return (target, key) => {
185
+ defineKey(target, key, {
186
+ get() {
187
+ const t = this;
188
+ const {config: config, userConfig: userConfig, configKeepKeys: configKeepKeys} = t, mergedConfig = config ? DataHelper.clone(config) : {};
189
+ if (configKeepKeys) {
190
+ for (let key in userConfig) {
191
+ if (!configKeepKeys.includes(key)) mergedConfig[key] = userConfig[key];
192
+ }
193
+ }
194
+ if (t.preMergedConfig) t.preMergedConfig(mergedConfig);
195
+ if (configKeepKeys) configKeepKeys.forEach(key => {
196
+ userConfig[key] && Object.assign(mergedConfig[key], userConfig[key]);
197
+ });
198
+ return t.mergedConfig = mergedConfig;
199
+ }
200
+ });
201
+ };
202
+ }
203
+
204
+ const {abs: abs$2} = Math;
120
205
 
121
206
  const {copy: copy$1} = MatrixHelper;
122
207
 
@@ -159,7 +244,7 @@ class Stroker extends UI {
159
244
  leaf = list[i];
160
245
  const {worldTransform: worldTransform, worldRenderBounds: worldRenderBounds} = leaf;
161
246
  if (worldRenderBounds.width && worldRenderBounds.height && (!bounds || bounds.hit(worldRenderBounds, options.matrix))) {
162
- const aScaleX = abs$1(worldTransform.scaleX), aScaleY = abs$1(worldTransform.scaleY);
247
+ const aScaleX = abs$2(worldTransform.scaleX), aScaleY = abs$2(worldTransform.scaleY);
163
248
  copy$1(matrix, worldTransform);
164
249
  matrix.half = strokeWidth % 2;
165
250
  canvas.setWorld(matrix, options.matrix);
@@ -314,7 +399,11 @@ class EditSelect extends Group {
314
399
  }
315
400
  onSelect() {
316
401
  if (this.running) {
317
- this.targetStroker.setTarget(this.editor.list);
402
+ const {editor: editor} = this;
403
+ let {list: list} = editor;
404
+ const maskList = EditorHelper.getSiblingMaskElements(editor);
405
+ if (maskList) list = maskList.concat(list);
406
+ this.targetStroker.setTarget(list);
318
407
  this.hoverStroker.target = null;
319
408
  }
320
409
  }
@@ -486,13 +575,13 @@ class EditSelect extends Group {
486
575
 
487
576
  const {topLeft: topLeft, top: top, topRight: topRight, right: right$1, bottomRight: bottomRight, bottom: bottom, bottomLeft: bottomLeft, left: left$1} = Direction9;
488
577
 
489
- const {toPoint: toPoint} = AroundHelper, {within: within, sign: sign} = MathHelper, {abs: abs} = Math;
578
+ const {toPoint: toPoint} = AroundHelper, {within: within, sign: sign} = MathHelper, {abs: abs$1} = Math;
490
579
 
491
580
  const EditDataHelper = {
492
581
  getScaleData(target, startBounds, direction, totalMoveOrScale, lockRatio, around, flipable, scaleMode) {
493
582
  let align, origin = {}, scaleX = 1, scaleY = 1, lockScale;
494
583
  const {widthRange: widthRange, heightRange: heightRange, dragBounds: dragBounds, worldTransform: worldTransform, boxBounds: boxBounds} = target;
495
- const {width: width, height: height} = startBounds, worldScaleX = abs(worldTransform.scaleX), worldScaleY = abs(worldTransform.scaleY);
584
+ const {width: width, height: height} = startBounds, worldScaleX = abs$1(worldTransform.scaleX), worldScaleY = abs$1(worldTransform.scaleY);
496
585
  const originChangedScaleX = target.scaleX / startBounds.scaleX;
497
586
  const originChangedScaleY = target.scaleY / startBounds.scaleY;
498
587
  const signX = sign(originChangedScaleX);
@@ -572,7 +661,7 @@ const EditDataHelper = {
572
661
  break;
573
662
 
574
663
  default:
575
- lockScale = Math.sqrt(abs(scaleX * scaleY));
664
+ lockScale = Math.sqrt(abs$1(scaleX * scaleY));
576
665
  scaleX = sign(scaleX) * lockScale;
577
666
  scaleY = sign(scaleY) * lockScale;
578
667
  }
@@ -606,10 +695,10 @@ const EditDataHelper = {
606
695
  }
607
696
  const minWidth = 1, minHeight = 1;
608
697
  const worldWidth = worldScaleX * boxBounds.width, worldHeight = worldScaleY * boxBounds.height;
609
- if (useScaleX && abs(scaleX * worldWidth) < minWidth) scaleX = sign(scaleX) * minWidth / worldWidth;
610
- if (useScaleY && abs(scaleY * worldHeight) < minHeight) scaleY = sign(scaleY) * minHeight / worldHeight;
698
+ if (useScaleX && abs$1(scaleX * worldWidth) < minWidth) scaleX = sign(scaleX) * minWidth / worldWidth;
699
+ if (useScaleY && abs$1(scaleY * worldHeight) < minHeight) scaleY = sign(scaleY) * minHeight / worldHeight;
611
700
  if (lockRatio && scaleX !== scaleY) {
612
- lockScale = Math.min(abs(scaleX), abs(scaleY));
701
+ lockScale = Math.min(abs$1(scaleX), abs$1(scaleY));
613
702
  scaleX = sign(scaleX) * lockScale;
614
703
  scaleY = sign(scaleY) * lockScale;
615
704
  }
@@ -831,6 +920,8 @@ class EditPoint extends Box {
831
920
 
832
921
  const fourDirection = [ "top", "right", "bottom", "left" ], editConfig = undefined;
833
922
 
923
+ const debug$1 = Debug.get("EditBox");
924
+
834
925
  class EditBox extends Group {
835
926
  get mergeConfig() {
836
927
  const {config: config} = this, {mergeConfig: mergeConfig, editBox: editBox} = this.editor;
@@ -901,10 +992,12 @@ class EditBox extends Group {
901
992
  this.resizeLines = [];
902
993
  this.dragStartData = {};
903
994
  this.__eventIds = [];
995
+ this.widgets = [];
904
996
  this.editor = editor;
905
997
  this.visible = false;
906
998
  this.create();
907
999
  this.__listenEvents();
1000
+ this.createWidgets();
908
1001
  }
909
1002
  create() {
910
1003
  let rotatePoint, resizeLine, resizePoint;
@@ -940,7 +1033,7 @@ class EditBox extends Group {
940
1033
  }
941
1034
  this.listenPointEvents(circle, "rotate", 2);
942
1035
  this.listenPointEvents(rect, "move", 8);
943
- view.addMany(...rotatePoints, rect, circle, buttons, ...resizeLines, ...resizePoints);
1036
+ view.add([ ...rotatePoints, rect, circle, buttons, ...resizeLines, ...resizePoints ]);
944
1037
  this.add(view);
945
1038
  }
946
1039
  load() {
@@ -953,6 +1046,7 @@ class EditBox extends Group {
953
1046
  let resizeP;
954
1047
  for (let i = 0; i < 8; i++) {
955
1048
  resizeP = resizePoints[i];
1049
+ if (resizeP.children.length) resizeP.clear();
956
1050
  resizeP.set(this.getPointStyle(i % 2 ? middlePointsStyle[(i - 1) / 2 % middlePointsStyle.length] : pointsStyle[i / 2 % pointsStyle.length]));
957
1051
  resizeP.rotation = (i - (i % 2 ? 1 : 0)) / 2 * 90;
958
1052
  if (i % 2) resizeLines[(i - 1) / 2].set(Object.assign({
@@ -978,6 +1072,7 @@ class EditBox extends Group {
978
1072
  }
979
1073
  if (single) DataHelper.stintSet(target.__world, "ignorePixelSnap", ignorePixelSnap);
980
1074
  updateMoveCursor(this);
1075
+ this.loadWidgets();
981
1076
  }
982
1077
  update() {
983
1078
  const {editor: editor} = this;
@@ -998,8 +1093,10 @@ class EditBox extends Group {
998
1093
  width: width,
999
1094
  height: height
1000
1095
  });
1096
+ this.updateWidgets();
1001
1097
  }
1002
1098
  unload() {
1099
+ this.unloadWidgets();
1003
1100
  this.visible = false;
1004
1101
  if (this.app) this.rect.syncEventer = this.app.interaction.bottomList = null;
1005
1102
  }
@@ -1012,6 +1109,7 @@ class EditBox extends Group {
1012
1109
  strokeBoxSpread && BoundsHelper.spread(bounds, [ strokeBoxSpread * Math.abs(scaleY), strokeBoxSpread * Math.abs(scaleX) ]);
1013
1110
  }
1014
1111
  if (spread) BoundsHelper.spread(bounds, spread);
1112
+ this.rectBounds = bounds;
1015
1113
  editMask.visible = mask ? true : 0;
1016
1114
  if (!isUndefined(dimOthers) || !isUndefined(bright)) {
1017
1115
  editor.setDimOthers(dimOthers);
@@ -1023,7 +1121,7 @@ class EditBox extends Group {
1023
1121
  if (this.view.worldOpacity) {
1024
1122
  const {width: width, height: height} = bounds;
1025
1123
  const smallSize = isNumber(hideOnSmall) ? hideOnSmall : 10;
1026
- const showPoints = editBox && !(hideOnSmall && width < smallSize && height < smallSize);
1124
+ const showPoints = this.showPoints = editBox && !(hideOnSmall && width < smallSize && height < smallSize);
1027
1125
  let point = {}, rotateP, resizeP, resizeL;
1028
1126
  for (let i = 0; i < 8; i++) {
1029
1127
  AroundHelper.toPoint(AroundHelper.directionData[i], bounds, point);
@@ -1317,13 +1415,38 @@ class EditBox extends Group {
1317
1415
  __removeListenEvents() {
1318
1416
  this.off_(this.__eventIds);
1319
1417
  }
1418
+ static registerWidget(Widget) {
1419
+ const {tag: tag} = Widget.prototype;
1420
+ EditBox.WidgetList[tag] && debug$1.repeat(tag);
1421
+ EditBox.WidgetList[tag] = Widget;
1422
+ }
1423
+ createWidgets() {
1424
+ Object.values(EditBox.WidgetList).forEach(item => {
1425
+ this.widgets.push(new item(this));
1426
+ });
1427
+ }
1428
+ loadWidgets() {
1429
+ this.widgets.forEach(item => item.onLoad());
1430
+ }
1431
+ updateWidgets() {
1432
+ this.widgets.forEach(item => item.onUpdate());
1433
+ }
1434
+ unloadWidgets() {
1435
+ this.widgets.forEach(item => item.onUnload());
1436
+ }
1437
+ destroyWidgets() {
1438
+ this.widgets.forEach(item => item.onDestroy());
1439
+ }
1320
1440
  destroy() {
1321
1441
  this.editor = null;
1322
1442
  this.__removeListenEvents();
1443
+ this.destroyWidgets();
1323
1444
  super.destroy();
1324
1445
  }
1325
1446
  }
1326
1447
 
1448
+ EditBox.WidgetList = {};
1449
+
1327
1450
  const bigBounds = {
1328
1451
  x: 0,
1329
1452
  y: 0,
@@ -1470,65 +1593,6 @@ function onHover(editor, oldValue) {
1470
1593
  }));
1471
1594
  }
1472
1595
 
1473
- const order = (a, b) => a.parent.children.indexOf(a) - b.parent.children.indexOf(b);
1474
-
1475
- const reverseOrder = (a, b) => b.parent.children.indexOf(b) - a.parent.children.indexOf(a);
1476
-
1477
- const EditorHelper = {
1478
- group(list, element, userGroup) {
1479
- list.sort(reverseOrder);
1480
- const {app: app, parent: parent} = list[0];
1481
- let group;
1482
- if (userGroup && userGroup.add) {
1483
- group = userGroup;
1484
- } else {
1485
- group = new Group(userGroup);
1486
- }
1487
- parent.addAt(group, parent.children.indexOf(list[0]));
1488
- list.sort(order);
1489
- const matrx = new Matrix(element.worldTransform);
1490
- matrx.divideParent(parent.scrollWorldTransform);
1491
- group.setTransform(matrx);
1492
- group.editable = true;
1493
- group.hitChildren = false;
1494
- app.lockLayout();
1495
- list.forEach(child => child.dropTo(group));
1496
- app.unlockLayout();
1497
- return group;
1498
- },
1499
- ungroup(list) {
1500
- const {app: app} = list[0];
1501
- const ungroupList = [];
1502
- app.lockLayout();
1503
- list.forEach(leaf => {
1504
- if (leaf.isBranch) {
1505
- const {parent: parent, children: children} = leaf;
1506
- while (children.length) {
1507
- ungroupList.push(children[0]);
1508
- children[0].dropTo(parent, parent.children.indexOf(leaf));
1509
- }
1510
- if (leaf.isBranchLeaf) ungroupList.push(leaf); else leaf.remove();
1511
- } else {
1512
- ungroupList.push(leaf);
1513
- }
1514
- });
1515
- app.unlockLayout();
1516
- return ungroupList;
1517
- },
1518
- toTop(list) {
1519
- list.sort(order);
1520
- list.forEach(leaf => {
1521
- if (leaf.parent) leaf.parent.add(leaf);
1522
- });
1523
- },
1524
- toBottom(list) {
1525
- list.sort(reverseOrder);
1526
- list.forEach(leaf => {
1527
- if (leaf.parent) leaf.parent.addAt(leaf, 0);
1528
- });
1529
- }
1530
- };
1531
-
1532
1596
  const debug = Debug.get("EditToolCreator");
1533
1597
 
1534
1598
  function registerEditTool() {
@@ -2304,6 +2368,8 @@ __decorate([ targetAttr(onHover) ], Editor.prototype, "hoverTarget", void 0);
2304
2368
 
2305
2369
  Editor = __decorate([ useModule(TransformTool, [ "editBox", "editTool", "emitEvent" ]) ], Editor);
2306
2370
 
2371
+ const {abs: abs} = Math, {scale: scale} = PointHelper;
2372
+
2307
2373
  class InnerEditor {
2308
2374
  static registerInnerEditor() {
2309
2375
  EditToolCreator.register(this);
@@ -2314,6 +2380,9 @@ class InnerEditor {
2314
2380
  get mode() {
2315
2381
  return "focus";
2316
2382
  }
2383
+ get userConfig() {
2384
+ return this.editBox.mergeConfig[this.tag] || {};
2385
+ }
2317
2386
  get editBox() {
2318
2387
  return this._editBox || this.editor.editBox;
2319
2388
  }
@@ -2325,6 +2394,22 @@ class InnerEditor {
2325
2394
  this.editor = editor;
2326
2395
  this.create();
2327
2396
  }
2397
+ getEditBoxPoint(editTargetPoint, change) {
2398
+ const point = change ? editTargetPoint : {
2399
+ x: editTargetPoint.x,
2400
+ y: editTargetPoint.y
2401
+ }, {scaleX: scaleX, scaleY: scaleY} = this.editTarget.worldTransform;
2402
+ scale(point, abs(scaleX), abs(scaleY));
2403
+ return point;
2404
+ }
2405
+ getEditTargetPoint(editBoxPoint, change) {
2406
+ const point = change ? editBoxPoint : {
2407
+ x: editBoxPoint.x,
2408
+ y: editBoxPoint.y
2409
+ }, {scaleX: scaleX, scaleY: scaleY} = this.editTarget.worldTransform;
2410
+ scale(point, Math.abs(1 / scaleX), abs(1 / scaleY));
2411
+ return point;
2412
+ }
2328
2413
  onCreate() {}
2329
2414
  create() {
2330
2415
  this.view = new Group;
@@ -2576,4 +2661,4 @@ UI.setEditInner = function(editorName) {
2576
2661
  this.changeAttr("editInner", editorName);
2577
2662
  };
2578
2663
 
2579
- export { EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorGroupEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, InnerEditor, InnerEditorEvent, LineEditTool, SelectArea, Stroker, TransformTool, registerEditTool, registerInnerEditor };
2664
+ export { EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorGroupEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, InnerEditor, InnerEditorEvent, LineEditTool, SelectArea, Stroker, TransformTool, editToolMergeConfigAttr, registerEditTool, registerInnerEditor };
@@ -1,2 +1,2 @@
1
- import{Event as t,isArray as e,defineKey as i,isNull as s,isUndefined as o,isObject as r,MatrixHelper as n,BoundsHelper as a,LeafBoundsHelper as h,getMatrixData as l,getBoundsData as d,surfaceType as c,UI as g,ColorConvert as u,isString as f,Paint as p,Group as m,Rect as E,Bounds as v,LeafList as b,Direction9 as w,AroundHelper as y,MathHelper as k,PointHelper as L,isNumber as T,Box as O,DataHelper as x,ResizeEvent as S,getPointData as _,Text as B,Matrix as C,Debug as M,LeafHelper as R,PropertyEvent as P,Plugin as V,RenderEvent as H,LeaferEvent as D,Creator as A,dataType as I}from"@leafer-ui/draw";import{PointerEvent as z,DragEvent as F,MoveEvent as W,ZoomEvent as Z,DragBoundsHelper as G,KeyEvent as X,RotateEvent as Y,useModule as U}from"@leafer-ui/core";import"@leafer-in/resize";function K(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n}function j(t){return t?e(t)?t:[t]:[]}"function"==typeof SuppressedError&&SuppressedError;class N extends t{get list(){return j(this.value)}get oldList(){return j(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}function $(t){return(s,o)=>{const n="_"+o;i(s,o,{get(){return this[n]},set(i){const s=this[n];if(s!==i){const a=this;if(a.config){const t="target"===o;if(t){const{beforeSelect:t}=a.config;if(t){const e=t({target:i});if(r(e))i=e;else if(!1===e)return}a.hasDimOthers&&a.cancelDimOthers(),e(i)&&i.length>1&&i[0].locked&&i.splice(0,1),a.single&&(delete a.element.syncEventer,delete a.element.__world.ignorePixelSnap)}const n=t?N.BEFORE_SELECT:N.BEFORE_HOVER;this.hasEvent(n)&&this.emitEvent(new N(n,{editor:a,value:i,oldValue:s}))}this[n]=i,t(this,s)}}})}}N.BEFORE_SELECT="editor.before_select",N.SELECT="editor.select",N.AFTER_SELECT="editor.after_select",N.BEFORE_HOVER="editor.before_hover",N.HOVER="editor.hover";const{abs:q}=Math,{copy:J}=n,{setListWithFn:Q}=a,{worldBounds:tt}=h,et=l(),it=d();class st extends g{constructor(){super(),this.list=[],this.visible=0,this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){e&&this.set(e),this.target=t,this.update()}update(t){const{list:e}=this;e.length?(Q(it,e,tt),t&&this.set(t),this.set(it),this.visible=!0):this.visible=0}__draw(t,e){const{list:i}=this;if(i.length){let s;const o=this.__,{stroke:r,strokeWidth:n,fill:a}=o,{bounds:h}=e;for(let l=0;l<i.length;l++){s=i[l];const{worldTransform:d,worldRenderBounds:c}=s;if(c.width&&c.height&&(!h||h.hit(c,e.matrix))){const i=q(d.scaleX),h=q(d.scaleY);switch(J(et,d),et.half=n%2,t.setWorld(et,e.matrix),t.beginPath(),this.strokePathType){case"box":const{boxBounds:e}=s.__layout;t.rect(e.x,e.y,e.width,e.height);break;case"stroke":const{strokeBounds:i}=s.__layout;t.rect(i.x,i.y,i.width,i.height);break;case"path":s.__drawPath(t);break;default:s.__.__useArrow?s.__drawPath(t):s.__.__pathForRender?s.__drawRenderPath(t):s.__drawPathByBox(t)}if(o.strokeWidth=n/Math.max(i,h),o.shadow){const e=o.shadow[0],{scaleX:i,scaleY:s}=this.getRenderScaleData(!0,e.scaleFixed);t.save(),t.setWorldShadow(e.x*i,e.y*s,e.blur*i,u.string(e.color))}r&&(f(r)?p.stroke(r,this,t,e):p.strokes(r,this,t,e)),a&&(f(a)?p.fill(a,this,t,e):p.fills(a,this,t,e)),o.shadow&&t.restore()}}o.strokeWidth=n}}destroy(){this.target=null,super.destroy()}}K([$(function(t){const i=t.target;t.list=i?e(i)?i:[i]:[]})],st.prototype,"target",void 0),K([c("render-path")],st.prototype,"strokePathType",void 0);class ot extends m{constructor(t){super(t),this.strokeArea=new E({strokeAlign:"center"}),this.fillArea=new E,this.visible=0,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 rt={findOne:t=>t.list.find(t=>t.editable),findByBounds(t,e){const i=[];return nt([t],i,e),i}};function nt(t,e,i){let s,o;for(let r=0,n=t.length;r<n;r++)if(s=t[r],o=s.__,o.hittable&&o.visible&&!o.locked&&i.hit(s.__world)){if(o.editable){if(s.isBranch&&!o.hitChildren){o.hitSelf&&e.push(s);continue}if(s.isFrame){if(i.includes(s.__layout.boxBounds,s.__world)){e.push(s);continue}}else i.hit(s.__layout.boxBounds,s.__world)&&o.hitSelf&&e.push(s)}s.isBranch&&nt(s.children,e,i)}}const{findOne:at,findByBounds:ht}=rt;class lt extends m{get dragging(){return!!this.originList}get running(){const{editor:t,app:e}=this;return this.hittable&&t.visible&&t.hittable&&t.mergeConfig.selector&&e&&"normal"===e.mode}get isMoveMode(){const{app:t}=this;return t&&t.interaction.moveMode}constructor(t){super(),this.hoverStroker=new st,this.targetStroker=new st,this.bounds=new v,this.selectArea=new ot,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{hoverTarget:e,mergeConfig:i}=t,s=Object.assign({},i);e&&e.editConfig&&Object.assign(s,e.editConfig);const{stroke:o,strokeWidth:r,hover:n,hoverStyle:a,hoverPathType:h}=s;this.hoverStroker.setTarget(n?e:null,Object.assign({stroke:o,strokeWidth:r,strokePathType:h},a||{}))}}onSelect(){this.running&&(this.targetStroker.setTarget(this.editor.list),this.hoverStroker.target=null)}update(){this.hoverStroker.update();const{stroke:t,strokeWidth:e,selectedPathType:i,selectedStyle:s}=this.editor.mergedConfig;this.targetStroker.update(Object.assign({stroke:t,strokeWidth:e&&Math.max(1,e/2),strokePathType:i},s||{}))}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,selectKeep:s}=e.mergeConfig;"tap"===i?this.checkAndSelect(t):this.waitSelect&&this.waitSelect(),this.needRemoveItem?e.removeItem(this.needRemoveItem):this.isMoveMode&&(s||(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,t.path.needUpdate=!0):this.allow(t.target)&&(this.isHoldMultipleSelectKey(t)||this.editor.mergedConfig.selectKeep||(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:r}=t.getInnerPoint(this);this.bounds.set(o,r),this.selectArea.setStyle({visible:!0,stroke:i,x:o,y:r},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 b(ht(e.app,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=0)}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){const{boxSelect:e,multipleSelect:i}=this.editor.mergeConfig;return!(!(this.running&&i&&e)||t.target.draggable)&&(!this.editor.editing&&this.allow(t.target)||this.isHoldMultipleSelectKey(t)&&!at(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new b(this.editor.editBox.rect)};return at(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):at(t.path)}isMultipleSelect(t){const{multipleSelect:e,continuousSelect:i}=this.editor.mergeConfig;return e&&(this.isHoldMultipleSelectKey(t)||i)}isHoldMultipleSelectKey(t){const{multipleSelectKey:e}=this.editor.mergedConfig;return e?t.isHoldKeys(e):t.shiftKey}__listenEvents(){const{editor:t}=this;t.waitLeafer(()=>{const{app:e}=t;e.selector.proxy=t,this.__eventIds=[t.on_([[N.HOVER,this.onHover,this],[N.SELECT,this.onSelect,this]]),e.on_([[z.MOVE,this.onPointerMove,this],[z.BEFORE_DOWN,this.onBeforeDown,this],[z.TAP,this.onTap,this],[F.START,this.onDragStart,this,!0],[F.DRAG,this.onDrag,this],[F.END,this.onDragEnd,this],[W.MOVE,this.onAutoMove,this],[[Z.ZOOM,W.MOVE],()=>{this.editor.hoverTarget=null}]])]})}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=this.originList=this.needRemoveItem=null,this.__removeListenEvents(),super.destroy()}}const{topLeft:dt,top:ct,topRight:gt,right:ut,bottomRight:ft,bottom:pt,bottomLeft:mt,left:Et}=w,{toPoint:vt}=y,{within:bt,sign:wt}=k,{abs:yt}=Math,kt={getScaleData(t,e,i,s,o,r,n,a){let h,l,d={},c=1,g=1;const{widthRange:u,heightRange:f,dragBounds:p,worldTransform:m,boxBounds:E}=t,{width:v,height:b}=e,w=yt(m.scaleX),y=yt(m.scaleY),k=t.scaleX/e.scaleX,L=t.scaleY/e.scaleY,O=wt(k),x=wt(L),S=a?k:O*E.width/v,_=a?L:x*E.height/b;if(T(s))c=g=Math.sqrt(s);else{r&&(s.x*=2,s.y*=2),s.x*=a?k:O,s.y*=a?L:x;const t=(-s.y+b)/b,e=(s.x+v)/v,n=(s.y+b)/b,d=(-s.x+v)/v;switch(i){case ct:g=t,h="bottom";break;case ut:c=e,h="left";break;case pt:g=n,h="top";break;case Et:c=d,h="right";break;case dt:g=t,c=d,h="bottom-right";break;case gt:g=t,c=e,h="bottom-left";break;case ft:g=n,c=e,h="top-left";break;case mt:g=n,c=d,h="top-right"}if(o)if("corner"===o&&i%2)o=!1;else switch(i){case ct:case pt:c=g;break;case Et:case ut:g=c;break;default:l=Math.sqrt(yt(c*g)),c=wt(c)*l,g=wt(g)*l}}const B=1!==c,C=1!==g;if(B&&(c/=S),C&&(g/=_),n||(c<0&&(c=1/E.width/w),g<0&&(g=1/E.height/y)),vt(r||h,E,d,!0),p){const e={x:c,y:g};G.limitScaleOf(t,d,e,o),c=e.x,g=e.y}if(B&&u){const e=E.width*t.scaleX;c=bt(e*c,u)/e}if(C&&f){const e=E.height*t.scaleY;g=bt(e*g,f)/e}const M=w*E.width,R=y*E.height;return B&&yt(c*M)<1&&(c=1*wt(c)/M),C&&yt(g*R)<1&&(g=1*wt(g)/R),o&&c!==g&&(l=Math.min(yt(c),yt(g)),c=wt(c)*l,g=wt(g)*l),isFinite(c)||(c=1),isFinite(g)||(g=1),{origin:d,scaleX:c,scaleY:g,direction:i,lockRatio:o,around:r}},getRotateData(t,e,i,s,o){let r,n={};switch(e){case dt:r="bottom-right";break;case gt:r="bottom-left";break;case ft:r="top-left";break;case mt:r="top-right";break;default:r="center"}return vt(o||r,t.boxBounds,n,!0),{origin:n,rotation:L.getRotation(s,t.getWorldPointByBox(n),i)}},getSkewData(t,e,i,s){let o,r,n={},a=0,h=0;switch(e){case ct:case dt:r={x:.5,y:0},o="bottom",a=1;break;case pt:case ft:r={x:.5,y:1},o="top",a=1;break;case Et:case mt:r={x:0,y:.5},o="right",h=1;break;case ut:case gt:r={x:1,y:.5},o="left",h=1}const{boxBounds:l}=t,{width:d,height:c}=l;r.x=r.x*d,r.y=r.y*c,vt(s||o,l,n,!0);const g=L.getRotation(r,n,{x:r.x+(a?i.x:0),y:r.y+(h?i.y:0)});return a?a=-g:h=g,{origin:n,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 Et:t=ut;break;case dt:t=gt;break;case mt:t=ft;break;case ut:t=Et;break;case gt:t=dt;break;case ft:t=mt}if(i)switch(t){case ct:t=pt;break;case dt:t=mt;break;case gt:t=ft;break;case pt:t=ct;break;case mt:t=dt;break;case ft:t=gt}return t}},Lt={};function Tt(t,e){const{enterPoint:i,dragging:s,skewing:o,resizing:r,flippedX:n,flippedY:a}=t;if(!i||!t.editor.editing||!t.canUse)return;if("rect"===i.name)return Ot(t);if("circle"===i.name)return;let{rotation:h}=t;const{pointType:l}=i,{moveCursor:d,resizeCursor:c,rotateCursor:g,skewCursor:u,moveable:f,resizeable:p,rotateable:m,skewable:E}=t.mergeConfig;if("move"===l)return i.cursor=d,void(f||(i.visible=!1));if("button"===l)return void(i.cursor||(i.cursor="pointer"));let v=l.includes("resize");v&&m&&(t.isHoldRotateKey(e)||!p)&&(v=!1);const b=E&&!v&&("resize-line"===i.name||"skew"===l),w=s?o?u:r?c:g:b?u:v?c:g;h+=45*(kt.getFlipDirection(i.direction,n,a)+1),h=2*Math.round(k.formatRotation(h,!0)/2);const{url:y,x:L,y:T}=w,O=y+h;Lt[O]?i.cursor=Lt[O]:Lt[O]=i.cursor={url:xt(y,h),x:L,y:T}}function Ot(t){const{moveCursor:e,moveable:i}=t.mergeConfig;t.canUse&&(t.rect.cursor=i?e:void 0)}function xt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class St extends O{constructor(t){super(t),this.useFastShadow=!0}}const _t=["top","right","bottom","left"],Bt=void 0;class Ct extends m{get mergeConfig(){const{config:t}=this,{mergeConfig:e,editBox:i}=this.editor;return this.mergedConfig=t&&i!==this?Object.assign(Object.assign({},e),t):e}get target(){return this._target||this.editor.element}set target(t){this._target=t}get single(){return!!this._target||this.editor.single}get transformTool(){return this._transformTool||this.editor}set transformTool(t){this._transformTool=t}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}get canUse(){return this.app&&this.editor.editing}get canGesture(){if(!this.canUse)return!1;const{moveable:t,resizeable:e,rotateable:i}=this.mergeConfig;return f(t)||f(e)||f(i)}get canDragLimitAnimate(){return this.moving&&this.mergeConfig.dragLimitAnimate&&this.target.dragBounds}constructor(t){super(),this.view=new m,this.rect=new St({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new St({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new m({around:"center",hitSelf:!1,visible:0}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.dragStartData={},this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.__listenEvents()}create(){let t,e,i;const{view:s,resizePoints:o,rotatePoints:r,resizeLines:n,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 St({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),r.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new St({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),n.push(e),this.listenPointEvents(e,"resize",s)),i=new St({name:"resize-point",hitRadius:5}),o.push(i),this.listenPointEvents(i,"resize",s);this.listenPointEvents(h,"rotate",2),this.listenPointEvents(a,"move",8),s.addMany(...r,a,h,l,...n,...o),this.add(s)}load(){const{target:t,mergeConfig:e,single:i,rect:o,circle:r,resizePoints:n,resizeLines:a}=this,{stroke:h,strokeWidth:l,ignorePixelSnap:d}=e,c=this.getPointsStyle(),g=this.getMiddlePointsStyle(),u=this.getResizeLinesStyle();let f;this.visible=!t.locked;for(let t=0;t<8;t++)f=n[t],f.set(this.getPointStyle(t%2?g[(t-1)/2%g.length]:c[t/2%c.length])),f.rotation=(t-(t%2?1:0))/2*90,t%2&&a[(t-1)/2].set(Object.assign({pointType:"resize",rotation:(t-1)/2*90},u[(t-1)/2%u.length]||{}));r.set(this.getPointStyle(e.circle||e.rotatePoint||c[0])),o.set(Object.assign({stroke:h,strokeWidth:l,opacity:1,editConfig:Bt},e.rect||{}));const p=s(e.rectThrough)?i:e.rectThrough;o.hittable=!p,p&&(t.syncEventer=o,this.app.interaction.bottomList=[{target:o,proxy:t}]),i&&x.stintSet(t.__world,"ignorePixelSnap",d),Ot(this)}update(){const{editor:t}=this,{x:e,y:i,scaleX:s,scaleY:o,rotation:r,skewX:n,skewY:a,width:h,height:l}=this.target.getLayoutBounds("box",t,!0);this.visible=!this.target.locked,this.set({x:e,y:i,scaleX:s,scaleY:o,rotation:r,skewX:n,skewY:a}),this.updateBounds({x:0,y:0,width:h,height:l})}unload(){this.visible=!1,this.app&&(this.rect.syncEventer=this.app.interaction.bottomList=null)}updateBounds(t){const{editor:e,target:i,mergeConfig:s,single:r,rect:n,circle:h,buttons:l,resizePoints:d,rotatePoints:c,resizeLines:g}=this,{editMask:u}=e,{middlePoint:f,resizeable:p,rotateable:m,hideOnSmall:E,editBox:v,editBoxType:b,mask:w,dimOthers:k,bright:L,spread:O,hideRotatePoints:x,hideResizeLines:S}=s;if("stroke"===b){const{scaleX:e,scaleY:s}=i.worldTransform,{strokeBoxSpread:o}=i.__layout;o&&a.spread(t,[o*Math.abs(s),o*Math.abs(e)])}if(O&&a.spread(t,O),u.visible=!!w||0,o(k)&&o(L)?e.hasDimOthers&&e.cancelDimOthers():(e.setDimOthers(k),e.setBright(!!k||L),e.hasDimOthers=!0),this.view.worldOpacity){const{width:e,height:i}=t,o=T(E)?E:10,a=v&&!(E&&e<o&&i<o);let u,b,w,k={};for(let s=0;s<8;s++)y.toPoint(y.directionData[s],t,k),b=d[s],u=c[s],b.set(k),u.set(k),b.visible=a&&!(!p&&!m),u.visible=a&&m&&p&&!x,s%2&&(w=g[(s-1)/2],w.set(k),w.visible=b.visible&&!S,b.visible&&(b.visible=!!f),u.visible&&(u.visible=!!f),(s+1)/2%2?(w.width=e+w.height,E&&2*b.width>e&&(b.visible=!1)):(w.width=i+w.height,E&&2*b.width>i&&(b.visible=!1)));h.visible=a&&m&&!(!s.circle&&!s.rotatePoint),h.visible&&this.layoutCircle(),n.path&&(n.path=null),n.set(Object.assign(Object.assign({},t),{visible:!r||v})),l.visible=a&&l.children.length>0||0,l.visible&&this.layoutButtons()}else n.set(t)}layoutCircle(){const{circleDirection:t,circleMargin:e,buttonsMargin:i,buttonsDirection:s,middlePoint:o}=this.mergedConfig,r=_t.indexOf(t||(this.buttons.children.length&&"bottom"===s?"top":"bottom"));this.setButtonPosition(this.circle,r,e||i,!!o)}layoutButtons(){const{buttons:t}=this,{buttonsDirection:e,buttonsFixed:i,buttonsMargin:s,middlePoint:o}=this.mergedConfig,{flippedX:r,flippedY:n}=this;let a=_t.indexOf(e);(a%2&&r||(a+1)%2&&n)&&i&&(a=(a+2)%4);const h=i?kt.getRotateDirection(a,this.flippedOne?this.rotation:-this.rotation,4):a;this.setButtonPosition(t,h,s,!!o),i&&(t.rotation=90*(h-a)),t.scaleX=r?-1:1,t.scaleY=n?-1:1}setButtonPosition(t,e,i,s){const o=this.resizePoints[2*e+1],r=e%2,n=e&&3!==e?1:-1,a=(i+(e%2?(s?o.width:0)+t.boxBounds.width:(s?o.height:0)+t.boxBounds.height)/2)*n;r?(t.x=o.x+a,t.y=o.y):(t.x=o.x,t.y=o.y+a)}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:s,pointSize:o,pointRadius:r}=this.mergedConfig,n={fill:s,stroke:e,strokeWidth:i,around:"center",strokeAlign:"center",opacity:1,width:o,height:o,cornerRadius:r,offsetX:0,offsetY:0,editConfig:Bt};return t?Object.assign(n,t):n}getPointsStyle(){const{point:t}=this.mergedConfig;return e(t)?t:[t]}getMiddlePointsStyle(){const{middlePoint:t}=this.mergedConfig;return e(t)?t:t?[t]:this.getPointsStyle()}getResizeLinesStyle(){const{resizeLine:t}=this.mergedConfig;return e(t)?t:[t]}onDragStart(t){this.dragging=!0;const e=this.dragPoint=t.current,{pointType:i}=e,{moveable:s,resizeable:o,rotateable:r,skewable:n,onCopy:a}=this.mergeConfig;"move"===i?(t.altKey&&a&&a()&&this.editor.single&&this.app.interaction.replaceDownTarget(this.target),s&&(this.moving=!0)):(i.includes("rotate")||this.isHoldRotateKey(t)||!o?(r&&(this.rotating=!0),"resize-rotate"===i?o&&(this.resizing=!0):"resize-line"===e.name&&(n&&(this.skewing=!0),this.rotating=!1)):"resize"===i&&o&&(this.resizing=!0),"skew"===i&&n&&(this.skewing=!0)),this.onTransformStart(t)}onDrag(t){const{transformTool:e,moving:i,resizing:s,rotating:o,skewing:r}=this;if(i)e.onMove(t);else if(s||o||r){const i=t.current;i.pointType&&(this.enterPoint=i),o&&e.onRotate(t),s&&e.onScale(t),r&&e.onSkew(t)}Tt(this,t)}onDragEnd(t){this.onTransformEnd(t),this.dragPoint=null}onTransformStart(t){const{hideOnMove:e}=this.mergedConfig;(this.moving||this.gesturing)&&(this.editor.opacity=e?0:1),this.resizing&&(S.resizingKeys=this.editor.leafList.keys);const{dragStartData:i,target:s}=this;i.x=t.x,i.y=t.y,i.totalOffset=_(),i.point={x:s.x,y:s.y},i.bounds=Object.assign({},s.getLayoutBounds("box","local")),i.rotation=s.rotation}onTransformEnd(t){this.canDragLimitAnimate&&(t instanceof F||t instanceof W)&&this.transformTool.onMove(t),this.resizing&&(S.resizingKeys=null),this.dragging=this.gesturing=this.moving=this.resizing=this.rotating=this.skewing=!1,this.editor.opacity=1,this.editor.update()}onMove(t){if(this.canGesture&&"drag"!==t.moveType&&(t.stop(),f(this.mergedConfig.moveable)))switch(this.gesturing=this.moving=!0,t.type){case W.START:this.onTransformStart(t);break;case W.END:this.onTransformEnd(t);break;default:this.transformTool.onMove(t)}}onScale(t){if(this.canGesture&&(t.stop(),f(this.mergedConfig.resizeable)))switch(this.gesturing=this.resizing=!0,t.type){case Z.START:this.onTransformStart(t);break;case Z.END:this.onTransformEnd(t);break;default:this.transformTool.onScale(t)}}onRotate(t){if(this.canGesture&&(t.stop(),f(this.mergedConfig.rotateable)))switch(this.gesturing=this.rotating=!0,t.type){case Z.START:this.onTransformStart(t);break;case Z.END:this.onTransformEnd(t);break;default:this.transformTool.onRotate(t)}}isHoldRotateKey(t){const{rotateKey:e}=this.mergedConfig;return e?t.isHoldKeys(e):t.metaKey||t.ctrlKey}onKey(t){Tt(this,t)}onArrow(t){if(this.canUse){let e=0,i=0;switch(t.code){case"ArrowDown":i=1;break;case"ArrowUp":i=-1;break;case"ArrowLeft":e=-1;break;case"ArrowRight":e=1}if(e||i){const{keyEvent:s,arrowStep:o,arrowFastStep:r}=this.mergeConfig;if(s){const s=t.shiftKey?r:o;this.transformTool.move(e*s,i*s)}}}}onDoubleTap(t){const{openInner:e,preventEditInner:i}=this.mergeConfig;"double"!==e||i||this.openInner(t)}onLongPress(t){const{openInner:e,preventEditInner:i}=this.mergeConfig;"long"===e&&i&&this.openInner(t)}openInner(t){const{editor:e,target:i}=this;if(this.single){if(i.locked)return;if(i.isBranch&&!i.editInner){if(i.textBox){const{children:t}=i,s=t.find(t=>t.editable&&t instanceof B)||t.find(t=>t instanceof B);if(s)return e.openInnerEditor(s)}e.openGroup(i),e.target=e.selector.findDeepOne(t)}else e.openInnerEditor()}}listenPointEvents(t,e,i){t.direction=i,t.pointType=e,this.__eventIds.push(t.on_([[F.START,this.onDragStart,this],[F.DRAG,this.onDrag,this],[F.END,this.onDragEnd,this],[z.ENTER,e=>{this.enterPoint=t,Tt(this,e)}],[z.LEAVE,()=>{this.enterPoint=null}]]))}__listenEvents(){const{rect:t,editor:e,__eventIds:i}=this;i.push(t.on_([[z.DOUBLE_TAP,this.onDoubleTap,this],[z.LONG_PRESS,this.onLongPress,this]])),this.waitLeafer(()=>{i.push(e.app.on_([[[X.HOLD,X.UP],this.onKey,this],[X.DOWN,this.onArrow,this],[[W.START,W.BEFORE_MOVE,W.END],this.onMove,this,!0],[[Z.START,Z.BEFORE_ZOOM,Z.END],this.onScale,this,!0],[[Y.START,Y.BEFORE_ROTATE,Y.END],this.onRotate,this,!0]]))})}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const Mt={x:0,y:0,width:1e5,height:1e5};class Rt extends g{constructor(t){super(),this.editor=t,this.hittable=!1,this.visible=0}__updateWorldBounds(){Object.assign(this.__local,Mt),Object.assign(this.__world,Mt)}__draw(t,e){const{editor:i}=this,{mask:s}=i.mergedConfig;if(s&&i.editing){if(t.fillWorld(t.bounds,!0===s?"rgba(0,0,0,0.8)":s),e.bounds&&!e.bounds.hit(i.editBox.rect.__world,e.matrix))return;t.saveBlendMode("destination-out"),e=Object.assign(Object.assign({},e),{shape:!0}),i.list.forEach(i=>{i.__render(t,e);const{parent:s}=i;s&&s.textBox&&s.__renderShape(t,e)}),t.restoreBlendMode()}}destroy(){this.editor=null,super.destroy()}}const Pt='\n<feOffset dy="1"/>\n<feGaussianBlur stdDeviation="1.5"/>\n<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2 0"/>\n<feBlend mode="normal" in="SourceGraphic" result="shape"/>',Vt={editSize:"size",keyEvent:!0,stroke:"#836DFF",strokeWidth:2,pointFill:"#FFFFFF",pointSize:10,pointRadius:16,rotateGap:45,arrowStep:1,arrowFastStep:10,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${Pt}\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${Pt}\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${Pt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,editBox:!0,editBoxType:"box",hover:!0,select:"press",openInner:"double",multipleSelect:!0,boxSelect:!0,moveable:!0,resizeable:!0,flipable:!0,rotateable:!0,skewable:!0},Ht=new v;function Dt(t){const{simulateTarget:e,list:i}=t,{zoomLayer:s}=i[0].leafer;e.safeChange(()=>{Ht.setListWithFn(i,t=>t.getBounds("box","page")),0===Ht.width&&(Ht.width=.1),0===Ht.height&&(Ht.height=.1),e.reset(Ht.get())}),s.add(e)}const At=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),It=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),zt={group(t,e,i){t.sort(It);const{app:s,parent:o}=t[0];let r;r=i&&i.add?i:new m(i),o.addAt(r,o.children.indexOf(t[0])),t.sort(At);const n=new C(e.worldTransform);return n.divideParent(o.scrollWorldTransform),r.setTransform(n),r.editable=!0,r.hitChildren=!1,s.lockLayout(),t.forEach(t=>t.dropTo(r)),s.unlockLayout(),r},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach(t=>{if(t.isBranch){const{parent:e,children:s}=t;for(;s.length;)i.push(s[0]),s[0].dropTo(e,e.children.indexOf(t));t.isBranchLeaf?i.push(t):t.remove()}else i.push(t)}),e.unlockLayout(),i},toTop(t){t.sort(At),t.forEach(t=>{t.parent&&t.parent.add(t)})},toBottom(t){t.sort(It),t.forEach(t=>{t.parent&&t.parent.addAt(t,0)})}},Ft=M.get("EditToolCreator");function Wt(){return t=>{Gt.register(t)}}const Zt=Wt,Gt={EditTool:"EditTool",LineEditTool:"LineEditTool",PointsEditTool:"PointsEditTool",list:{},register(t,e){const{tag:i}=t.prototype;e||(e=i),Xt[e]&&Ft.repeat(e),Xt[e]=t},get:(t,e)=>new Xt[t](e)},{list:Xt}=Gt;class Yt extends N{constructor(t,e){super(t,e)}}Yt.BEFORE_OPEN="innerEditor.before_open",Yt.OPEN="innerEditor.open",Yt.BEFORE_CLOSE="innerEditor.before_close",Yt.CLOSE="innerEditor.close";class Ut extends N{constructor(t,e){super(t,e)}}Ut.BEFORE_GROUP="editor.before_group",Ut.GROUP="editor.group",Ut.BEFORE_UNGROUP="editor.before_ungroup",Ut.UNGROUP="editor.ungroup",Ut.BEFORE_OPEN="editor.before_open_group",Ut.OPEN="editor.open_group",Ut.BEFORE_CLOSE="editor.before_close_group",Ut.CLOSE="editor.close_group";const{updateMatrix:Kt}=R,jt={x:1,y:1,scaleX:1,scaleY:1,rotation:1,skewX:1,skewY:1},Nt="top-left";class $t extends E{get __tag(){return"SimulateElement"}constructor(t){super(),this.checkChange=!0,this.canChange=!0,this.visible=this.hittable=!1,this.skipJSON=!0,this.on(P.CHANGE,e=>{if(this.checkChange&&jt[e.attrName]){const{attrName:i,newValue:s,oldValue:o}=e,r="s"===i[0]?(s||1)/(o||1):(s||0)-(o||0);this.canChange=!1;const n=this.__;n[i]=o,Kt(this.parent),Kt(this);const a=new C(this.__world);switch(n[i]=s,this.__layout.rotationChange(),Kt(this),this.changedTransform=new C(this.__world).divide(a),i){case"x":t.move(r,0);break;case"y":t.move(0,r);break;case"rotation":t.rotateOf(Nt,r);break;case"scaleX":t.scaleOf(Nt,r,1);break;case"scaleY":t.scaleOf(Nt,1,r);break;case"skewX":t.skewOf(Nt,r,0);break;case"skewY":t.skewOf(Nt,0,r)}this.canChange=!0}})}safeChange(t){this.canChange&&(this.checkChange=!1,t(),this.checkChange=!0)}}class qt extends N{constructor(t,e){super(t,e)}}qt.BEFORE_MOVE="editor.before_move",qt.MOVE="editor.move";class Jt extends N{constructor(t,e){super(t,e)}}Jt.BEFORE_SCALE="editor.before_scale",Jt.SCALE="editor.scale";class Qt extends N{constructor(t,e){super(t,e)}}Qt.BEFORE_ROTATE="editor.before_rotate",Qt.ROTATE="editor.rotate";class te extends N{constructor(t,e){super(t,e)}}te.BEFORE_SKEW="editor.before_skew",te.SKEW="editor.skew";class ee{onMove(t){const{target:e,mergeConfig:i,dragStartData:s}=this.editBox;let o,{dragLimitAnimate:r}=i;const n=t.type===W.END||t.type===F.END,a=f(e.draggable),h=!r||n||a,l={x:t.totalX,y:t.totalY};t instanceof W&&L.move(l,e.getWorldPointByLocal(s.totalOffset,null,!0)),t.shiftKey&&(Math.abs(l.x)>Math.abs(l.y)?l.y=0:l.x=0),o=F.getValidMove(e,s.point,l,h),(o.x||o.y)&&(r&&!a&&n?R.animateMove(this,o,T(r)?r:.3):this.move(o))}onScale(t){const{target:e,mergeConfig:i,single:s,dragStartData:o}=this.editBox;let r,{around:n,lockRatio:a,flipable:h,editSize:l}=i;t instanceof Z?(n||(n=e.getBoxPoint(t)),r=t.totalScale):r=t.getInnerTotal(e);const{direction:d}=t.current;(t.shiftKey||e.lockRatio)&&(a=!0);const c=kt.getScaleData(e,o.bounds,d,r,a,kt.getAround(n,t.altKey),h,!s||"scale"===l),g=e.x,u=e.y;t instanceof F&&this.editTool&&this.editTool.onScaleWithDrag?(c.drag=t,this.scaleWithDrag(c)):this.scaleOf(c.origin,c.scaleX,c.scaleY),L.move(o.totalOffset,e.x-g,e.y-u)}onRotate(t){const{target:e,mergeConfig:i,dragStartData:s}=this.editBox,{around:o,rotateAround:r,rotateGap:n,diagonalRotateKey:a}=i,{direction:h}=t.current;let l,d;if(t instanceof Y)d=t.rotation,l=r?y.getPoint(r,e.boxBounds):e.getBoxPoint(t);else{const i=a?t.isHoldKeys(a):t.shiftKey,n=kt.getRotateData(e,h,t,s,i?null:r||e.around||e.origin||o||"center");d=s.rotation+n.rotation-e.rotation,l=n.origin}if(d=k.float(k.getGapRotation(d,n,e.rotation),2),!d)return;const c=e.x,g=e.y;this.rotateOf(l,d),L.move(s.totalOffset,e.x-c,e.y-g)}onSkew(t){const{target:e,mergeConfig:i}=this.editBox,{around:s}=i,{origin:o,skewX:r,skewY:n}=kt.getSkewData(e,t.current.direction,t.getInnerMove(e),kt.getAround(s,t.altKey));(r||n)&&this.skewOf(o,r,n)}move(t,e=0){if(!this.checkTransform("moveable"))return;r(t)&&(e=t.y,t=t.x);const{target:i,mergeConfig:s,single:o,editor:n}=this.editBox,{beforeMove:a}=s;if(a){const s=a({target:i,x:t,y:e});if(r(s))t=s.x,e=s.y;else if(!1===s)return}const h=i.getWorldPointByLocal({x:t,y:e},null,!0);o||i.safeChange(()=>i.move(t,e));const l={target:i,editor:n,moveX:h.x,moveY:h.y};this.emitEvent(new qt(qt.BEFORE_MOVE,l));const d=new qt(qt.MOVE,l);this.doMove(d),this.emitEvent(d)}scaleWithDrag(t){if(!this.checkTransform("resizeable"))return;const{target:e,mergeConfig:i,editor:s}=this.editBox,{beforeScale:o}=i;if(o){const{origin:i,scaleX:s,scaleY:r,drag:n}=t;if(!1===o({target:e,drag:n,origin:i,scaleX:s,scaleY:r}))return}t=Object.assign(Object.assign({},t),{target:e,editor:s,worldOrigin:e.getWorldPoint(t.origin)}),this.emitEvent(new Jt(Jt.BEFORE_SCALE,t));const r=new Jt(Jt.SCALE,t);this.editTool.onScaleWithDrag(r),this.emitEvent(r)}scaleOf(t,e,i=e,s){if(!this.checkTransform("resizeable"))return;const{target:o,mergeConfig:n,single:a,editor:h}=this.editBox,{beforeScale:l}=n;if(l){const s=l({target:o,origin:t,scaleX:e,scaleY:i});if(r(s))e=s.scaleX,i=s.scaleY;else if(!1===s)return}const d=this.getWorldOrigin(t),c=!a&&this.getChangedTransform(()=>o.safeChange(()=>o.scaleOf(t,e,i))),g={target:o,editor:h,worldOrigin:d,scaleX:e,scaleY:i,transform:c};this.emitEvent(new Jt(Jt.BEFORE_SCALE,g));const u=new Jt(Jt.SCALE,g);this.doScale(u),this.emitEvent(u)}flip(t){if(!this.checkTransform("resizeable"))return;const{target:e,single:i,editor:s}=this.editBox,o=this.getWorldOrigin("center"),r=i?new C(R.getFlipTransform(e,t)):this.getChangedTransform(()=>e.safeChange(()=>e.flip(t))),n={target:e,editor:s,worldOrigin:o,scaleX:"x"===t?-1:1,scaleY:"y"===t?-1:1,transform:r};this.emitEvent(new Jt(Jt.BEFORE_SCALE,n));const a=new Jt(Jt.SCALE,n);this.doScale(a),this.emitEvent(a)}rotateOf(t,e){if(!this.checkTransform("rotateable"))return;const{target:i,mergeConfig:s,single:o,editor:r}=this.editBox,{beforeRotate:n}=s;if(n){const s=n({target:i,origin:t,rotation:e});if(T(s))e=s;else if(!1===s)return}const a=this.getWorldOrigin(t),h=!o&&this.getChangedTransform(()=>i.safeChange(()=>i.rotateOf(t,e))),l={target:i,editor:r,worldOrigin:a,rotation:e,transform:h};this.emitEvent(new Qt(Qt.BEFORE_ROTATE,l));const d=new Qt(Qt.ROTATE,l);this.doRotate(d),this.emitEvent(d)}skewOf(t,e,i=0,s){if(!this.checkTransform("skewable"))return;const{target:o,mergeConfig:n,single:a,editor:h}=this.editBox,{beforeSkew:l}=n;if(l){const s=l({target:o,origin:t,skewX:e,skewY:i});if(r(s))e=s.skewX,i=s.skewY;else if(!1===s)return}const d=this.getWorldOrigin(t),c=!a&&this.getChangedTransform(()=>o.safeChange(()=>o.skewOf(t,e,i))),g={target:o,editor:h,worldOrigin:d,skewX:e,skewY:i,transform:c};this.emitEvent(new te(te.BEFORE_SKEW,g));const u=new te(te.SKEW,g);this.doSkew(u),this.emitEvent(u)}doMove(t){this.editTool.onMove(t)}doScale(t){this.editTool.onScale(t)}doRotate(t){this.editTool.onRotate(t)}doSkew(t){this.editTool.onSkew(t)}checkTransform(t){const{target:e,mergeConfig:i}=this.editBox;return e&&!e.locked&&i[t]}getWorldOrigin(t){const{target:e}=this.editBox;return e.getWorldPoint(R.getInnerOrigin(e,t))}getChangedTransform(t){const{target:e,single:i}=this.editBox;if(!i&&!e.canChange)return e.changedTransform;const s=new C(e.worldTransform);return t(),new C(e.worldTransform).divide(s)}emitEvent(t,e){this.editBox.editor.emitEvent(t,e)}}let ie=class extends m{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 dragPoint(){return this.editBox.dragPoint}get dragging(){return this.editBox.dragging}get gesturing(){return this.editBox.gesturing}get moving(){return this.editBox.moving}get resizing(){return this.editBox.resizing}get rotating(){return this.editBox.rotating}get skewing(){return this.editBox.skewing}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}get targetLeafer(){const t=this.list[0];return t&&t.leafer}constructor(t,e){super(e),this.leafList=new b,this.openedGroupList=new b,this.simulateTarget=new $t(this),this.editBox=new Ct(this),this.editToolList={},this.selector=new lt(this),this.editMask=new Rt(this),this.targetEventIds=[];let i=x.clone(Vt);t&&(i=x.default(t,i)),this.mergedConfig=this.config=i,this.addMany(this.editMask,this.selector,this.editBox),V.has("resize")||(this.config.editSize="scale")}select(t){this.target=t}cancel(){this.target=null}hasItem(t){return this.leafList.has(t)}getItem(t){return this.list[t||0]}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)}setDimOthers(t,i="dim",s){if(!s){const{dimTarget:t,targetLeafer:i}=this;s=t?e(t)?t:[t]:[i]}s[0]&&s[0][i]!==(t||!1)&&s.forEach(e=>x.stintSet(e,i,t))}setBright(t){this.setDimOthers(t,"bright",this.list)}cancelDimOthers(){this.setDimOthers(!1),this.setBright(!1),this.hasDimOthers=void 0}update(){if(this.editing){if(!this.element.parent)return this.cancel();this.innerEditing&&this.innerEditor.update(),this.editTool.update(),this.selector.update()}}updateEditBox(){this.multiple&&Dt(this),this.update()}getEditTool(t){return this.editToolList[t]=this.editToolList[t]||Gt.get(t,this)}updateEditTool(){if(this.unloadEditTool(),this.editing){const t=this.element;let e=t.editOuter||"EditTool";const{beforeEditOuter:i}=this.mergeConfig;if(i){const s=i({target:t,name:e});if(f(s))e=s;else if(!1===s)return}if(Gt.list[e]){const i=this.editTool=this.getEditTool(e);this.editBox.load(),i.editTarget=t,i.load(),this.update()}}}unloadEditTool(t){let e=this.editTool;e&&(t||this.editBox.unload(),e.unload(),t||(this.editTool=null),e.editTarget=null)}getEditSize(t){return this.mergeConfig.editSize}onMove(t){}onScale(t){}onRotate(t){}onSkew(t){}move(t,e=0){}scaleWithDrag(t){}scaleOf(t,e,i=e,s){}flip(t){}rotateOf(t,e){}skewOf(t,e,i=0,s){}checkTransform(t){}getWorldOrigin(t){}getChangedTransform(t){}group(t){return this.multiple&&(this.emitGroupEvent(Ut.BEFORE_GROUP),this.target=zt.group(this.list,this.element,t),this.emitGroupEvent(Ut.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach(t=>t.isBranch&&this.emitGroupEvent(Ut.BEFORE_UNGROUP,t)),this.target=zt.ungroup(t),t.forEach(t=>t.isBranch&&this.emitGroupEvent(Ut.UNGROUP,t))),this.list}openGroup(t){this.emitGroupEvent(Ut.BEFORE_OPEN,t),this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(Ut.OPEN,t)}closeGroup(t){this.emitGroupEvent(Ut.BEFORE_CLOSE,t),this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(Ut.CLOSE,t)}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:e}=t;this.editing&&(e=[],t.forEach(t=>this.list.every(e=>!R.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 Ut(t,{editTarget:e});this.emitEvent(i),e&&e.emitEvent(i)}getInnerEditor(t){return this.editToolList[t]=this.editToolList[t]||Gt.get(t,this)}openInnerEditor(t,e,i){let s;if(f(e)?s=e:i||(i=e),t&&i&&(this.target=t),this.single){t||(t=this.element),s||(s=t.editInner);const{beforeEditInner:e}=this.mergeConfig;if(e){const i=e({target:t,name:s});if(f(i))s=i;else if(!1===i)return}Gt.list[s]&&(this.unloadEditTool(!0),this.innerEditing=!0,this.innerEditor=this.getInnerEditor(s),this.innerEditor.editTarget=t,this.emitInnerEvent(Yt.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(Yt.OPEN))}}closeInnerEditor(t){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(Yt.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(Yt.CLOSE),t||this.updateEditTool(),this.innerEditor=this.innerEditor.editTarget=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,s=new Yt(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&&(zt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(zt.toBottom(this.list),this.leafList.update())}onAppRenderStart(t){(this.targetChanged=t.children.some(t=>t!==this.leafer&&t.renderer.changed))&&this.editBox.forceRender()}onRenderStart(){this.targetChanged&&this.update()}onChildScroll(){this.multiple&&this.updateEditBox()}listenTargetEvents(){if(!this.targetEventIds.length){const{app:t,leafer:e,targetLeafer:i,editMask:s}=this;this.targetEventIds=[e.on_(H.START,this.onRenderStart,this),i&&i.on_(P.SCROLL,this.onChildScroll,this),t.on_(H.CHILD_START,this.onAppRenderStart,this),t.on_(D.UPDATE_MODE,t=>{t.mode&&"normal"!==t.mode&&this.cancel()})],s.visible&&s.forceRender()}}removeTargetEvents(){const{targetEventIds:t,editMask:e}=this;t.length&&(this.off_(t),e.visible&&e.forceRender())}destroy(){this.destroyed||(this.target=this.hoverTarget=null,Object.values(this.editToolList).forEach(t=>t.destroy()),this.simulateTarget.destroy(),this.editToolList={},this.simulateTarget=this.editTool=this.innerEditor=null,super.destroy())}};K([(t,e)=>{i(t,e,{get(){const{config:t,element:e,dragPoint:i,editBox:r,editTool:n,innerEditor:a,app:h}=this,l=Object.assign({},t);if(a?a.editConfig&&Object.assign(l,a.editConfig):n&&n.editConfig&&Object.assign(l,n.editConfig),e&&e.editConfig){let{editConfig:t}=e;(t.hover||t.hoverStyle||t.hoverPathType)&&(t=Object.assign({},t),delete t.hover,delete t.hoverStyle,delete t.hoverPathType),Object.assign(l,t)}return r.config&&Object.assign(l,r.config),i&&(i.editConfig&&Object.assign(l,i.editConfig),"font-size"===l.editSize&&(l.lockRatio=!0),"resize-rotate"===i.pointType&&(l.around||(l.around="center"),s(l.lockRatio)&&(l.lockRatio=!0))),o(l.dragLimitAnimate)&&(l.dragLimitAnimate=h&&h.config.pointer.dragLimitAnimate),this.mergedConfig=l}})}],ie.prototype,"mergeConfig",void 0),K([$(function(t,e){const{target:i}=t;i?(t.leafList=i instanceof b?i:new b(i),t.multiple&&Dt(t)):(t.simulateTarget.remove(),t.leafList.reset()),t.closeInnerEditor(!0),t.unloadEditTool();const s={editor:t,value:i,oldValue:e};t.emitEvent(new N(N.SELECT,s)),t.checkOpenedGroups(),t.editing?t.waitLeafer(()=>{t.updateEditTool(),t.listenTargetEvents()}):(t.updateEditTool(),t.removeTargetEvents()),t.emitEvent(new N(N.AFTER_SELECT,s))})],ie.prototype,"target",void 0),K([$(function(t,e){t.emitEvent(new N(N.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))})],ie.prototype,"hoverTarget",void 0),ie=K([U(ee,["editBox","editTool","emitEvent"])],ie);class se{static registerInnerEditor(){Gt.register(this)}get tag(){return"InnerEditor"}get mode(){return"focus"}get editBox(){return this._editBox||this.editor.editBox}set editBox(t){this._editBox=t}constructor(t){this.eventIds=[],this.editor=t,this.create()}onCreate(){}create(){this.view=new m,this.onCreate()}onLoad(){}load(){const{editor:t}=this;t&&(t.app&&"focus"===this.mode&&(t.selector.hittable=t.app.tree.hitChildren=!1),this.onLoad())}onUpdate(){}update(){this.onUpdate()}onUnload(){}unload(){const{editor:t}=this;t&&(t.app&&"focus"===this.mode&&(t.selector.hittable=t.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 oe=class extends se{static registerEditTool(t,e){Gt.register(this,t),e&&i(this.prototype,"tag",{get:()=>t})}get tag(){return"EditTool"}onMove(t){const{moveX:e,moveY:i,editor:s}=t,{app:o,list:r}=s;o.lockLayout(),r.forEach(t=>{t.moveWorld(e,i)}),o.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:s,worldOrigin:o,editor:r}=t,{app:n,list:a}=r;n.lockLayout(),a.forEach(t=>{const n="scale"!==r.getEditSize(t);s?t.transformWorld(s,n,!1):t.scaleOfWorld(o,e,i,n,!1)}),n.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:s,editor:o}=t,{app:r,list:n}=o;r.lockLayout(),n.forEach(t=>{const r="scale"!==o.getEditSize(t);i?t.transformWorld(i,r,!1):t.rotateOfWorld(s,e)}),r.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:s,worldOrigin:o,editor:r}=t,{app:n,list:a}=r;n.lockLayout(),a.forEach(t=>{const n="scale"!==r.getEditSize(t);s?t.transformWorld(s,n,!1):t.skewOfWorld(o,e,i,n)}),n.unlockLayout()}load(){this.editBox.view.visible=!0,this.onLoad()}update(){this.editBox.update(),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}};oe=K([Wt()],oe);const{left:re,right:ne}=w,{move:ae,copy:he,toNumberPoints:le}=L;let de=class extends oe{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(t){const{drag:e,direction:i,lockRatio:s,around:o}=t,r=t.target,n=i===re;if(r.pathInputed){const{path:t}=r.__,{from:i,to:a}=this.getFromToByPath(t);this.dragPoint(i,a,n,o,this.getInnerMove(r,e,s)),t[1]=i.x,t[2]=i.y,t[4]=a.x,t[5]=a.y,r.path=t}else if(r.points){const{points:t}=r,{from:i,to:a}=this.getFromToByPoints(t);this.dragPoint(i,a,n,o,this.getInnerMove(r,e,s)),t[0]=i.x,t[1]=i.y,t[2]=a.x,t[3]=a.y,r.points=t}else{const t=_(),{toPoint:i}=r;r.rotation=0,this.dragPoint(t,i,n,o,this.getInnerMove(r,e,s)),r.getLocalPointByInner(t,null,null,!0),r.getLocalPointByInner(i,null,null,!0),r.x=t.x,r.y=t.y,r.getInnerPointByLocal(i,null,null,!0),r.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){const e=le(t);return{from:{x:e[0],y:e[1]},to:{x:e[2],y:e[3]}}}dragPoint(t,e,i,s,o){const{x:r,y:n}=o;i?(ae(t,r,n),s&&ae(e,-r,-n)):(s&&ae(t,-r,-n),ae(e,r,n))}onSkew(t){}onUpdate(){const{editBox:t}=this,{rotatePoints:e,resizeLines:i,resizePoints:s,rect:o}=t,r=t.target;let n,a;if(r.pathInputed?n=this.getFromToByPath(r.__.path):r.points&&(n=this.getFromToByPoints(r.__.points)),n){const{from:i,to:a}=n;r.innerToWorld(i,i,!1,t),r.innerToWorld(a,a,!1,t),o.pen.clearPath().moveTo(i.x,i.y).lineTo(a.x,a.y),he(s[7],i),he(e[7],i),he(s[3],a),he(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===re||t===ne,s[t].visible=a,e[t].visible=!n&&a}};de=K([Wt()],de),V.add("editor","resize"),A.editor=function(t,e){const i=new ie(t);return e&&e.sky.add(e.editor=i),i},O.addAttr("textBox",!1,I),g.addAttr("editConfig",void 0,I),g.addAttr("editOuter",t=>{t.updateLayout();const{EditTool:e,LineEditTool:i,PointsEditTool:s}=Gt,o=t.pathInputed||t.isPointsMode?s:t.tag+"EditTool",r=Gt.list[o];return!t.__.__isLinePath||o==s&&r?r?o:e:i},I),g.addAttr("editInner","PathEditor",I),m.addAttr("editInner","",I),B.addAttr("editInner","TextEditor",I),g.setEditConfig=function(t){this.changeAttr("editConfig",t)},g.setEditOuter=function(t){this.changeAttr("editOuter",t)},g.setEditInner=function(t){this.changeAttr("editInner",t)};export{Ct as EditBox,kt as EditDataHelper,St as EditPoint,lt as EditSelect,rt as EditSelectHelper,oe as EditTool,Gt as EditToolCreator,ie as Editor,N as EditorEvent,Ut as EditorGroupEvent,zt as EditorHelper,qt as EditorMoveEvent,Qt as EditorRotateEvent,Jt as EditorScaleEvent,te as EditorSkewEvent,se as InnerEditor,Yt as InnerEditorEvent,de as LineEditTool,ot as SelectArea,st as Stroker,ee as TransformTool,Wt as registerEditTool,Zt as registerInnerEditor};
1
+ import{Event as t,isArray as e,Group as i,Matrix as s,defineKey as o,isNull as r,isUndefined as n,isObject as a,DataHelper as h,MatrixHelper as l,BoundsHelper as d,LeafBoundsHelper as c,getMatrixData as g,getBoundsData as u,surfaceType as f,UI as p,ColorConvert as m,isString as E,Paint as v,Rect as b,Bounds as w,LeafList as y,Direction9 as k,AroundHelper as L,MathHelper as T,PointHelper as x,isNumber as O,Box as S,Debug as _,ResizeEvent as B,getPointData as C,Text as M,LeafHelper as R,PropertyEvent as P,Plugin as V,RenderEvent as H,LeaferEvent as D,Creator as A,dataType as I}from"@leafer-ui/draw";import{PointerEvent as W,DragEvent as z,MoveEvent as F,ZoomEvent as Z,DragBoundsHelper as X,KeyEvent as Y,RotateEvent as G,useModule as U}from"@leafer-ui/core";import"@leafer-in/resize";function K(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n}function j(t){return t?e(t)?t:[t]:[]}"function"==typeof SuppressedError&&SuppressedError;class N extends t{get list(){return j(this.value)}get oldList(){return j(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}N.BEFORE_SELECT="editor.before_select",N.SELECT="editor.select",N.AFTER_SELECT="editor.after_select",N.BEFORE_HOVER="editor.before_hover",N.HOVER="editor.hover";const $=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),q=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),J={group(t,e,o){t.sort(q);const{app:r,parent:n}=t[0];let a;a=o&&o.add?o:new i(o),n.addAt(a,n.children.indexOf(t[0])),t.sort($);const h=new s(e.worldTransform);return h.divideParent(n.scrollWorldTransform),a.setTransform(h),a.editable=!0,a.hitChildren=!1,r.lockLayout(),t.forEach(t=>t.dropTo(a)),r.unlockLayout(),a},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.isBranchLeaf?i.push(t):t.remove()}else i.push(t)}),e.unlockLayout(),i},toTop(t){t.sort($),t.forEach(t=>{t.parent&&t.parent.add(t)})},toBottom(t){t.sort(q),t.forEach(t=>{t.parent&&t.parent.addAt(t,0)})},mergeMaskConfig(t,e){},getSiblingMaskElements(t){}};function Q(t){return(i,s)=>{const r="_"+s;o(i,s,{get(){return this[r]},set(i){const o=this[r];if(o!==i){const n=this;if(n.config){const t="target"===s;if(t){const{beforeSelect:t}=n.config;if(t){const e=t({target:i});if(a(e))i=e;else if(!1===e)return}n.hasDimOthers&&n.cancelDimOthers(),e(i)&&i.length>1&&i[0].locked&&i.splice(0,1),n.single&&(delete n.element.syncEventer,delete n.element.__world.ignorePixelSnap)}const r=t?N.BEFORE_SELECT:N.BEFORE_HOVER;this.hasEvent(r)&&this.emitEvent(new N(r,{editor:n,value:i,oldValue:o}))}this[r]=i,t(this,o)}}})}}function tt(){return(t,e)=>{o(t,e,{get(){const t=this,{config:e,userConfig:i,configKeepKeys:s}=t,o=e?h.clone(e):{};if(s)for(let t in i)s.includes(t)||(o[t]=i[t]);return t.preMergedConfig&&t.preMergedConfig(o),s&&s.forEach(t=>{i[t]&&Object.assign(o[t],i[t])}),t.mergedConfig=o}})}}const{abs:et}=Math,{copy:it}=l,{setListWithFn:st}=d,{worldBounds:ot}=c,rt=g(),nt=u();class at extends p{constructor(){super(),this.list=[],this.visible=0,this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){e&&this.set(e),this.target=t,this.update()}update(t){const{list:e}=this;e.length?(st(nt,e,ot),t&&this.set(t),this.set(nt),this.visible=!0):this.visible=0}__draw(t,e){const{list:i}=this;if(i.length){let s;const o=this.__,{stroke:r,strokeWidth:n,fill:a}=o,{bounds:h}=e;for(let l=0;l<i.length;l++){s=i[l];const{worldTransform:d,worldRenderBounds:c}=s;if(c.width&&c.height&&(!h||h.hit(c,e.matrix))){const i=et(d.scaleX),h=et(d.scaleY);switch(it(rt,d),rt.half=n%2,t.setWorld(rt,e.matrix),t.beginPath(),this.strokePathType){case"box":const{boxBounds:e}=s.__layout;t.rect(e.x,e.y,e.width,e.height);break;case"stroke":const{strokeBounds:i}=s.__layout;t.rect(i.x,i.y,i.width,i.height);break;case"path":s.__drawPath(t);break;default:s.__.__useArrow?s.__drawPath(t):s.__.__pathForRender?s.__drawRenderPath(t):s.__drawPathByBox(t)}if(o.strokeWidth=n/Math.max(i,h),o.shadow){const e=o.shadow[0],{scaleX:i,scaleY:s}=this.getRenderScaleData(!0,e.scaleFixed);t.save(),t.setWorldShadow(e.x*i,e.y*s,e.blur*i,m.string(e.color))}r&&(E(r)?v.stroke(r,this,t,e):v.strokes(r,this,t,e)),a&&(E(a)?v.fill(a,this,t,e):v.fills(a,this,t,e)),o.shadow&&t.restore()}}o.strokeWidth=n}}destroy(){this.target=null,super.destroy()}}K([Q(function(t){const i=t.target;t.list=i?e(i)?i:[i]:[]})],at.prototype,"target",void 0),K([f("render-path")],at.prototype,"strokePathType",void 0);class ht extends i{constructor(t){super(t),this.strokeArea=new b({strokeAlign:"center"}),this.fillArea=new b,this.visible=0,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 lt={findOne:t=>t.list.find(t=>t.editable),findByBounds(t,e){const i=[];return dt([t],i,e),i}};function dt(t,e,i){let s,o;for(let r=0,n=t.length;r<n;r++)if(s=t[r],o=s.__,o.hittable&&o.visible&&!o.locked&&i.hit(s.__world)){if(o.editable){if(s.isBranch&&!o.hitChildren){o.hitSelf&&e.push(s);continue}if(s.isFrame){if(i.includes(s.__layout.boxBounds,s.__world)){e.push(s);continue}}else i.hit(s.__layout.boxBounds,s.__world)&&o.hitSelf&&e.push(s)}s.isBranch&&dt(s.children,e,i)}}const{findOne:ct,findByBounds:gt}=lt;class ut extends i{get dragging(){return!!this.originList}get running(){const{editor:t,app:e}=this;return this.hittable&&t.visible&&t.hittable&&t.mergeConfig.selector&&e&&"normal"===e.mode}get isMoveMode(){const{app:t}=this;return t&&t.interaction.moveMode}constructor(t){super(),this.hoverStroker=new at,this.targetStroker=new at,this.bounds=new w,this.selectArea=new ht,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{hoverTarget:e,mergeConfig:i}=t,s=Object.assign({},i);e&&e.editConfig&&Object.assign(s,e.editConfig);const{stroke:o,strokeWidth:r,hover:n,hoverStyle:a,hoverPathType:h}=s;this.hoverStroker.setTarget(n?e:null,Object.assign({stroke:o,strokeWidth:r,strokePathType:h},a||{}))}}onSelect(){if(this.running){const{editor:t}=this;let{list:e}=t;const i=J.getSiblingMaskElements(t);i&&(e=i.concat(e)),this.targetStroker.setTarget(e),this.hoverStroker.target=null}}update(){this.hoverStroker.update();const{stroke:t,strokeWidth:e,selectedPathType:i,selectedStyle:s}=this.editor.mergedConfig;this.targetStroker.update(Object.assign({stroke:t,strokeWidth:e&&Math.max(1,e/2),strokePathType:i},s||{}))}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,selectKeep:s}=e.mergeConfig;"tap"===i?this.checkAndSelect(t):this.waitSelect&&this.waitSelect(),this.needRemoveItem?e.removeItem(this.needRemoveItem):this.isMoveMode&&(s||(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,t.path.needUpdate=!0):this.allow(t.target)&&(this.isHoldMultipleSelectKey(t)||this.editor.mergedConfig.selectKeep||(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:r}=t.getInnerPoint(this);this.bounds.set(o,r),this.selectArea.setStyle({visible:!0,stroke:i,x:o,y:r},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 y(gt(e.app,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=0)}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){const{boxSelect:e,multipleSelect:i}=this.editor.mergeConfig;return!(!(this.running&&i&&e)||t.target.draggable)&&(!this.editor.editing&&this.allow(t.target)||this.isHoldMultipleSelectKey(t)&&!ct(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new y(this.editor.editBox.rect)};return ct(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):ct(t.path)}isMultipleSelect(t){const{multipleSelect:e,continuousSelect:i}=this.editor.mergeConfig;return e&&(this.isHoldMultipleSelectKey(t)||i)}isHoldMultipleSelectKey(t){const{multipleSelectKey:e}=this.editor.mergedConfig;return e?t.isHoldKeys(e):t.shiftKey}__listenEvents(){const{editor:t}=this;t.waitLeafer(()=>{const{app:e}=t;e.selector.proxy=t,this.__eventIds=[t.on_([[N.HOVER,this.onHover,this],[N.SELECT,this.onSelect,this]]),e.on_([[W.MOVE,this.onPointerMove,this],[W.BEFORE_DOWN,this.onBeforeDown,this],[W.TAP,this.onTap,this],[z.START,this.onDragStart,this,!0],[z.DRAG,this.onDrag,this],[z.END,this.onDragEnd,this],[F.MOVE,this.onAutoMove,this],[[Z.ZOOM,F.MOVE],()=>{this.editor.hoverTarget=null}]])]})}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=this.originList=this.needRemoveItem=null,this.__removeListenEvents(),super.destroy()}}const{topLeft:ft,top:pt,topRight:mt,right:Et,bottomRight:vt,bottom:bt,bottomLeft:wt,left:yt}=k,{toPoint:kt}=L,{within:Lt,sign:Tt}=T,{abs:xt}=Math,Ot={getScaleData(t,e,i,s,o,r,n,a){let h,l,d={},c=1,g=1;const{widthRange:u,heightRange:f,dragBounds:p,worldTransform:m,boxBounds:E}=t,{width:v,height:b}=e,w=xt(m.scaleX),y=xt(m.scaleY),k=t.scaleX/e.scaleX,L=t.scaleY/e.scaleY,T=Tt(k),x=Tt(L),S=a?k:T*E.width/v,_=a?L:x*E.height/b;if(O(s))c=g=Math.sqrt(s);else{r&&(s.x*=2,s.y*=2),s.x*=a?k:T,s.y*=a?L:x;const t=(-s.y+b)/b,e=(s.x+v)/v,n=(s.y+b)/b,d=(-s.x+v)/v;switch(i){case pt:g=t,h="bottom";break;case Et:c=e,h="left";break;case bt:g=n,h="top";break;case yt:c=d,h="right";break;case ft:g=t,c=d,h="bottom-right";break;case mt:g=t,c=e,h="bottom-left";break;case vt:g=n,c=e,h="top-left";break;case wt:g=n,c=d,h="top-right"}if(o)if("corner"===o&&i%2)o=!1;else switch(i){case pt:case bt:c=g;break;case yt:case Et:g=c;break;default:l=Math.sqrt(xt(c*g)),c=Tt(c)*l,g=Tt(g)*l}}const B=1!==c,C=1!==g;if(B&&(c/=S),C&&(g/=_),n||(c<0&&(c=1/E.width/w),g<0&&(g=1/E.height/y)),kt(r||h,E,d,!0),p){const e={x:c,y:g};X.limitScaleOf(t,d,e,o),c=e.x,g=e.y}if(B&&u){const e=E.width*t.scaleX;c=Lt(e*c,u)/e}if(C&&f){const e=E.height*t.scaleY;g=Lt(e*g,f)/e}const M=w*E.width,R=y*E.height;return B&&xt(c*M)<1&&(c=1*Tt(c)/M),C&&xt(g*R)<1&&(g=1*Tt(g)/R),o&&c!==g&&(l=Math.min(xt(c),xt(g)),c=Tt(c)*l,g=Tt(g)*l),isFinite(c)||(c=1),isFinite(g)||(g=1),{origin:d,scaleX:c,scaleY:g,direction:i,lockRatio:o,around:r}},getRotateData(t,e,i,s,o){let r,n={};switch(e){case ft:r="bottom-right";break;case mt:r="bottom-left";break;case vt:r="top-left";break;case wt:r="top-right";break;default:r="center"}return kt(o||r,t.boxBounds,n,!0),{origin:n,rotation:x.getRotation(s,t.getWorldPointByBox(n),i)}},getSkewData(t,e,i,s){let o,r,n={},a=0,h=0;switch(e){case pt:case ft:r={x:.5,y:0},o="bottom",a=1;break;case bt:case vt:r={x:.5,y:1},o="top",a=1;break;case yt:case wt:r={x:0,y:.5},o="right",h=1;break;case Et:case mt:r={x:1,y:.5},o="left",h=1}const{boxBounds:l}=t,{width:d,height:c}=l;r.x=r.x*d,r.y=r.y*c,kt(s||o,l,n,!0);const g=x.getRotation(r,n,{x:r.x+(a?i.x:0),y:r.y+(h?i.y:0)});return a?a=-g:h=g,{origin:n,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 yt:t=Et;break;case ft:t=mt;break;case wt:t=vt;break;case Et:t=yt;break;case mt:t=ft;break;case vt:t=wt}if(i)switch(t){case pt:t=bt;break;case ft:t=wt;break;case mt:t=vt;break;case bt:t=pt;break;case wt:t=ft;break;case vt:t=mt}return t}},St={};function _t(t,e){const{enterPoint:i,dragging:s,skewing:o,resizing:r,flippedX:n,flippedY:a}=t;if(!i||!t.editor.editing||!t.canUse)return;if("rect"===i.name)return Bt(t);if("circle"===i.name)return;let{rotation:h}=t;const{pointType:l}=i,{moveCursor:d,resizeCursor:c,rotateCursor:g,skewCursor:u,moveable:f,resizeable:p,rotateable:m,skewable:E}=t.mergeConfig;if("move"===l)return i.cursor=d,void(f||(i.visible=!1));if("button"===l)return void(i.cursor||(i.cursor="pointer"));let v=l.includes("resize");v&&m&&(t.isHoldRotateKey(e)||!p)&&(v=!1);const b=E&&!v&&("resize-line"===i.name||"skew"===l),w=s?o?u:r?c:g:b?u:v?c:g;h+=45*(Ot.getFlipDirection(i.direction,n,a)+1),h=2*Math.round(T.formatRotation(h,!0)/2);const{url:y,x:k,y:L}=w,x=y+h;St[x]?i.cursor=St[x]:St[x]=i.cursor={url:Ct(y,h),x:k,y:L}}function Bt(t){const{moveCursor:e,moveable:i}=t.mergeConfig;t.canUse&&(t.rect.cursor=i?e:void 0)}function Ct(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class Mt extends S{constructor(t){super(t),this.useFastShadow=!0}}const Rt=["top","right","bottom","left"],Pt=void 0,Vt=_.get("EditBox");class Ht extends i{get mergeConfig(){const{config:t}=this,{mergeConfig:e,editBox:i}=this.editor;return this.mergedConfig=t&&i!==this?Object.assign(Object.assign({},e),t):e}get target(){return this._target||this.editor.element}set target(t){this._target=t}get single(){return!!this._target||this.editor.single}get transformTool(){return this._transformTool||this.editor}set transformTool(t){this._transformTool=t}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}get canUse(){return this.app&&this.editor.editing}get canGesture(){if(!this.canUse)return!1;const{moveable:t,resizeable:e,rotateable:i}=this.mergeConfig;return E(t)||E(e)||E(i)}get canDragLimitAnimate(){return this.moving&&this.mergeConfig.dragLimitAnimate&&this.target.dragBounds}constructor(t){super(),this.view=new i,this.rect=new Mt({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new Mt({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new i({around:"center",hitSelf:!1,visible:0}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.dragStartData={},this.__eventIds=[],this.widgets=[],this.editor=t,this.visible=!1,this.create(),this.__listenEvents(),this.createWidgets()}create(){let t,e,i;const{view:s,resizePoints:o,rotatePoints:r,resizeLines:n,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 Mt({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),r.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new Mt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),n.push(e),this.listenPointEvents(e,"resize",s)),i=new Mt({name:"resize-point",hitRadius:5}),o.push(i),this.listenPointEvents(i,"resize",s);this.listenPointEvents(h,"rotate",2),this.listenPointEvents(a,"move",8),s.add([...r,a,h,l,...n,...o]),this.add(s)}load(){const{target:t,mergeConfig:e,single:i,rect:s,circle:o,resizePoints:n,resizeLines:a}=this,{stroke:l,strokeWidth:d,ignorePixelSnap:c}=e,g=this.getPointsStyle(),u=this.getMiddlePointsStyle(),f=this.getResizeLinesStyle();let p;this.visible=!t.locked;for(let t=0;t<8;t++)p=n[t],p.children.length&&p.clear(),p.set(this.getPointStyle(t%2?u[(t-1)/2%u.length]:g[t/2%g.length])),p.rotation=(t-(t%2?1:0))/2*90,t%2&&a[(t-1)/2].set(Object.assign({pointType:"resize",rotation:(t-1)/2*90},f[(t-1)/2%f.length]||{}));o.set(this.getPointStyle(e.circle||e.rotatePoint||g[0])),s.set(Object.assign({stroke:l,strokeWidth:d,opacity:1,editConfig:Pt},e.rect||{}));const m=r(e.rectThrough)?i:e.rectThrough;s.hittable=!m,m&&(t.syncEventer=s,this.app.interaction.bottomList=[{target:s,proxy:t}]),i&&h.stintSet(t.__world,"ignorePixelSnap",c),Bt(this),this.loadWidgets()}update(){const{editor:t}=this,{x:e,y:i,scaleX:s,scaleY:o,rotation:r,skewX:n,skewY:a,width:h,height:l}=this.target.getLayoutBounds("box",t,!0);this.visible=!this.target.locked,this.set({x:e,y:i,scaleX:s,scaleY:o,rotation:r,skewX:n,skewY:a}),this.updateBounds({x:0,y:0,width:h,height:l}),this.updateWidgets()}unload(){this.unloadWidgets(),this.visible=!1,this.app&&(this.rect.syncEventer=this.app.interaction.bottomList=null)}updateBounds(t){const{editor:e,target:i,mergeConfig:s,single:o,rect:r,circle:a,buttons:h,resizePoints:l,rotatePoints:c,resizeLines:g}=this,{editMask:u}=e,{middlePoint:f,resizeable:p,rotateable:m,hideOnSmall:E,editBox:v,editBoxType:b,mask:w,dimOthers:y,bright:k,spread:T,hideRotatePoints:x,hideResizeLines:S}=s;if("stroke"===b){const{scaleX:e,scaleY:s}=i.worldTransform,{strokeBoxSpread:o}=i.__layout;o&&d.spread(t,[o*Math.abs(s),o*Math.abs(e)])}if(T&&d.spread(t,T),this.rectBounds=t,u.visible=!!w||0,n(y)&&n(k)?e.hasDimOthers&&e.cancelDimOthers():(e.setDimOthers(y),e.setBright(!!y||k),e.hasDimOthers=!0),this.view.worldOpacity){const{width:e,height:i}=t,n=O(E)?E:10,d=this.showPoints=v&&!(E&&e<n&&i<n);let u,b,w,y={};for(let s=0;s<8;s++)L.toPoint(L.directionData[s],t,y),b=l[s],u=c[s],b.set(y),u.set(y),b.visible=d&&!(!p&&!m),u.visible=d&&m&&p&&!x,s%2&&(w=g[(s-1)/2],w.set(y),w.visible=b.visible&&!S,b.visible&&(b.visible=!!f),u.visible&&(u.visible=!!f),(s+1)/2%2?(w.width=e+w.height,E&&2*b.width>e&&(b.visible=!1)):(w.width=i+w.height,E&&2*b.width>i&&(b.visible=!1)));a.visible=d&&m&&!(!s.circle&&!s.rotatePoint),a.visible&&this.layoutCircle(),r.path&&(r.path=null),r.set(Object.assign(Object.assign({},t),{visible:!o||v})),h.visible=d&&h.children.length>0||0,h.visible&&this.layoutButtons()}else r.set(t)}layoutCircle(){const{circleDirection:t,circleMargin:e,buttonsMargin:i,buttonsDirection:s,middlePoint:o}=this.mergedConfig,r=Rt.indexOf(t||(this.buttons.children.length&&"bottom"===s?"top":"bottom"));this.setButtonPosition(this.circle,r,e||i,!!o)}layoutButtons(){const{buttons:t}=this,{buttonsDirection:e,buttonsFixed:i,buttonsMargin:s,middlePoint:o}=this.mergedConfig,{flippedX:r,flippedY:n}=this;let a=Rt.indexOf(e);(a%2&&r||(a+1)%2&&n)&&i&&(a=(a+2)%4);const h=i?Ot.getRotateDirection(a,this.flippedOne?this.rotation:-this.rotation,4):a;this.setButtonPosition(t,h,s,!!o),i&&(t.rotation=90*(h-a)),t.scaleX=r?-1:1,t.scaleY=n?-1:1}setButtonPosition(t,e,i,s){const o=this.resizePoints[2*e+1],r=e%2,n=e&&3!==e?1:-1,a=(i+(e%2?(s?o.width:0)+t.boxBounds.width:(s?o.height:0)+t.boxBounds.height)/2)*n;r?(t.x=o.x+a,t.y=o.y):(t.x=o.x,t.y=o.y+a)}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:s,pointSize:o,pointRadius:r}=this.mergedConfig,n={fill:s,stroke:e,strokeWidth:i,around:"center",strokeAlign:"center",opacity:1,width:o,height:o,cornerRadius:r,offsetX:0,offsetY:0,editConfig:Pt};return t?Object.assign(n,t):n}getPointsStyle(){const{point:t}=this.mergedConfig;return e(t)?t:[t]}getMiddlePointsStyle(){const{middlePoint:t}=this.mergedConfig;return e(t)?t:t?[t]:this.getPointsStyle()}getResizeLinesStyle(){const{resizeLine:t}=this.mergedConfig;return e(t)?t:[t]}onDragStart(t){this.dragging=!0;const e=this.dragPoint=t.current,{pointType:i}=e,{moveable:s,resizeable:o,rotateable:r,skewable:n,onCopy:a}=this.mergeConfig;"move"===i?(t.altKey&&a&&a()&&this.editor.single&&this.app.interaction.replaceDownTarget(this.target),s&&(this.moving=!0)):(i.includes("rotate")||this.isHoldRotateKey(t)||!o?(r&&(this.rotating=!0),"resize-rotate"===i?o&&(this.resizing=!0):"resize-line"===e.name&&(n&&(this.skewing=!0),this.rotating=!1)):"resize"===i&&o&&(this.resizing=!0),"skew"===i&&n&&(this.skewing=!0)),this.onTransformStart(t)}onDrag(t){const{transformTool:e,moving:i,resizing:s,rotating:o,skewing:r}=this;if(i)e.onMove(t);else if(s||o||r){const i=t.current;i.pointType&&(this.enterPoint=i),o&&e.onRotate(t),s&&e.onScale(t),r&&e.onSkew(t)}_t(this,t)}onDragEnd(t){this.onTransformEnd(t),this.dragPoint=null}onTransformStart(t){const{hideOnMove:e}=this.mergedConfig;(this.moving||this.gesturing)&&(this.editor.opacity=e?0:1),this.resizing&&(B.resizingKeys=this.editor.leafList.keys);const{dragStartData:i,target:s}=this;i.x=t.x,i.y=t.y,i.totalOffset=C(),i.point={x:s.x,y:s.y},i.bounds=Object.assign({},s.getLayoutBounds("box","local")),i.rotation=s.rotation}onTransformEnd(t){this.canDragLimitAnimate&&(t instanceof z||t instanceof F)&&this.transformTool.onMove(t),this.resizing&&(B.resizingKeys=null),this.dragging=this.gesturing=this.moving=this.resizing=this.rotating=this.skewing=!1,this.editor.opacity=1,this.editor.update()}onMove(t){if(this.canGesture&&"drag"!==t.moveType&&(t.stop(),E(this.mergedConfig.moveable)))switch(this.gesturing=this.moving=!0,t.type){case F.START:this.onTransformStart(t);break;case F.END:this.onTransformEnd(t);break;default:this.transformTool.onMove(t)}}onScale(t){if(this.canGesture&&(t.stop(),E(this.mergedConfig.resizeable)))switch(this.gesturing=this.resizing=!0,t.type){case Z.START:this.onTransformStart(t);break;case Z.END:this.onTransformEnd(t);break;default:this.transformTool.onScale(t)}}onRotate(t){if(this.canGesture&&(t.stop(),E(this.mergedConfig.rotateable)))switch(this.gesturing=this.rotating=!0,t.type){case Z.START:this.onTransformStart(t);break;case Z.END:this.onTransformEnd(t);break;default:this.transformTool.onRotate(t)}}isHoldRotateKey(t){const{rotateKey:e}=this.mergedConfig;return e?t.isHoldKeys(e):t.metaKey||t.ctrlKey}onKey(t){_t(this,t)}onArrow(t){if(this.canUse){let e=0,i=0;switch(t.code){case"ArrowDown":i=1;break;case"ArrowUp":i=-1;break;case"ArrowLeft":e=-1;break;case"ArrowRight":e=1}if(e||i){const{keyEvent:s,arrowStep:o,arrowFastStep:r}=this.mergeConfig;if(s){const s=t.shiftKey?r:o;this.transformTool.move(e*s,i*s)}}}}onDoubleTap(t){const{openInner:e,preventEditInner:i}=this.mergeConfig;"double"!==e||i||this.openInner(t)}onLongPress(t){const{openInner:e,preventEditInner:i}=this.mergeConfig;"long"===e&&i&&this.openInner(t)}openInner(t){const{editor:e,target:i}=this;if(this.single){if(i.locked)return;if(i.isBranch&&!i.editInner){if(i.textBox){const{children:t}=i,s=t.find(t=>t.editable&&t instanceof M)||t.find(t=>t instanceof M);if(s)return e.openInnerEditor(s)}e.openGroup(i),e.target=e.selector.findDeepOne(t)}else e.openInnerEditor()}}listenPointEvents(t,e,i){t.direction=i,t.pointType=e,this.__eventIds.push(t.on_([[z.START,this.onDragStart,this],[z.DRAG,this.onDrag,this],[z.END,this.onDragEnd,this],[W.ENTER,e=>{this.enterPoint=t,_t(this,e)}],[W.LEAVE,()=>{this.enterPoint=null}]]))}__listenEvents(){const{rect:t,editor:e,__eventIds:i}=this;i.push(t.on_([[W.DOUBLE_TAP,this.onDoubleTap,this],[W.LONG_PRESS,this.onLongPress,this]])),this.waitLeafer(()=>{i.push(e.app.on_([[[Y.HOLD,Y.UP],this.onKey,this],[Y.DOWN,this.onArrow,this],[[F.START,F.BEFORE_MOVE,F.END],this.onMove,this,!0],[[Z.START,Z.BEFORE_ZOOM,Z.END],this.onScale,this,!0],[[G.START,G.BEFORE_ROTATE,G.END],this.onRotate,this,!0]]))})}__removeListenEvents(){this.off_(this.__eventIds)}static registerWidget(t){const{tag:e}=t.prototype;Ht.WidgetList[e]&&Vt.repeat(e),Ht.WidgetList[e]=t}createWidgets(){Object.values(Ht.WidgetList).forEach(t=>{this.widgets.push(new t(this))})}loadWidgets(){this.widgets.forEach(t=>t.onLoad())}updateWidgets(){this.widgets.forEach(t=>t.onUpdate())}unloadWidgets(){this.widgets.forEach(t=>t.onUnload())}destroyWidgets(){this.widgets.forEach(t=>t.onDestroy())}destroy(){this.editor=null,this.__removeListenEvents(),this.destroyWidgets(),super.destroy()}}Ht.WidgetList={};const Dt={x:0,y:0,width:1e5,height:1e5};class At extends p{constructor(t){super(),this.editor=t,this.hittable=!1,this.visible=0}__updateWorldBounds(){Object.assign(this.__local,Dt),Object.assign(this.__world,Dt)}__draw(t,e){const{editor:i}=this,{mask:s}=i.mergedConfig;if(s&&i.editing){if(t.fillWorld(t.bounds,!0===s?"rgba(0,0,0,0.8)":s),e.bounds&&!e.bounds.hit(i.editBox.rect.__world,e.matrix))return;t.saveBlendMode("destination-out"),e=Object.assign(Object.assign({},e),{shape:!0}),i.list.forEach(i=>{i.__render(t,e);const{parent:s}=i;s&&s.textBox&&s.__renderShape(t,e)}),t.restoreBlendMode()}}destroy(){this.editor=null,super.destroy()}}const It='\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"/>',Wt={editSize:"size",keyEvent:!0,stroke:"#836DFF",strokeWidth:2,pointFill:"#FFFFFF",pointSize:10,pointRadius:16,rotateGap:45,arrowStep:1,arrowFastStep:10,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${It}\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${It}\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${It}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,editBox:!0,editBoxType:"box",hover:!0,select:"press",openInner:"double",multipleSelect:!0,boxSelect:!0,moveable:!0,resizeable:!0,flipable:!0,rotateable:!0,skewable:!0},zt=new w;function Ft(t){const{simulateTarget:e,list:i}=t,{zoomLayer:s}=i[0].leafer;e.safeChange(()=>{zt.setListWithFn(i,t=>t.getBounds("box","page")),0===zt.width&&(zt.width=.1),0===zt.height&&(zt.height=.1),e.reset(zt.get())}),s.add(e)}const Zt=_.get("EditToolCreator");function Xt(){return t=>{Gt.register(t)}}const Yt=Xt,Gt={EditTool:"EditTool",LineEditTool:"LineEditTool",PointsEditTool:"PointsEditTool",list:{},register(t,e){const{tag:i}=t.prototype;e||(e=i),Ut[e]&&Zt.repeat(e),Ut[e]=t},get:(t,e)=>new Ut[t](e)},{list:Ut}=Gt;class Kt extends N{constructor(t,e){super(t,e)}}Kt.BEFORE_OPEN="innerEditor.before_open",Kt.OPEN="innerEditor.open",Kt.BEFORE_CLOSE="innerEditor.before_close",Kt.CLOSE="innerEditor.close";class jt extends N{constructor(t,e){super(t,e)}}jt.BEFORE_GROUP="editor.before_group",jt.GROUP="editor.group",jt.BEFORE_UNGROUP="editor.before_ungroup",jt.UNGROUP="editor.ungroup",jt.BEFORE_OPEN="editor.before_open_group",jt.OPEN="editor.open_group",jt.BEFORE_CLOSE="editor.before_close_group",jt.CLOSE="editor.close_group";const{updateMatrix:Nt}=R,$t={x:1,y:1,scaleX:1,scaleY:1,rotation:1,skewX:1,skewY:1},qt="top-left";class Jt extends b{get __tag(){return"SimulateElement"}constructor(t){super(),this.checkChange=!0,this.canChange=!0,this.visible=this.hittable=!1,this.skipJSON=!0,this.on(P.CHANGE,e=>{if(this.checkChange&&$t[e.attrName]){const{attrName:i,newValue:o,oldValue:r}=e,n="s"===i[0]?(o||1)/(r||1):(o||0)-(r||0);this.canChange=!1;const a=this.__;a[i]=r,Nt(this.parent),Nt(this);const h=new s(this.__world);switch(a[i]=o,this.__layout.rotationChange(),Nt(this),this.changedTransform=new s(this.__world).divide(h),i){case"x":t.move(n,0);break;case"y":t.move(0,n);break;case"rotation":t.rotateOf(qt,n);break;case"scaleX":t.scaleOf(qt,n,1);break;case"scaleY":t.scaleOf(qt,1,n);break;case"skewX":t.skewOf(qt,n,0);break;case"skewY":t.skewOf(qt,0,n)}this.canChange=!0}})}safeChange(t){this.canChange&&(this.checkChange=!1,t(),this.checkChange=!0)}}class Qt extends N{constructor(t,e){super(t,e)}}Qt.BEFORE_MOVE="editor.before_move",Qt.MOVE="editor.move";class te extends N{constructor(t,e){super(t,e)}}te.BEFORE_SCALE="editor.before_scale",te.SCALE="editor.scale";class ee extends N{constructor(t,e){super(t,e)}}ee.BEFORE_ROTATE="editor.before_rotate",ee.ROTATE="editor.rotate";class ie extends N{constructor(t,e){super(t,e)}}ie.BEFORE_SKEW="editor.before_skew",ie.SKEW="editor.skew";class se{onMove(t){const{target:e,mergeConfig:i,dragStartData:s}=this.editBox;let o,{dragLimitAnimate:r}=i;const n=t.type===F.END||t.type===z.END,a=E(e.draggable),h=!r||n||a,l={x:t.totalX,y:t.totalY};t instanceof F&&x.move(l,e.getWorldPointByLocal(s.totalOffset,null,!0)),t.shiftKey&&(Math.abs(l.x)>Math.abs(l.y)?l.y=0:l.x=0),o=z.getValidMove(e,s.point,l,h),(o.x||o.y)&&(r&&!a&&n?R.animateMove(this,o,O(r)?r:.3):this.move(o))}onScale(t){const{target:e,mergeConfig:i,single:s,dragStartData:o}=this.editBox;let r,{around:n,lockRatio:a,flipable:h,editSize:l}=i;t instanceof Z?(n||(n=e.getBoxPoint(t)),r=t.totalScale):r=t.getInnerTotal(e);const{direction:d}=t.current;(t.shiftKey||e.lockRatio)&&(a=!0);const c=Ot.getScaleData(e,o.bounds,d,r,a,Ot.getAround(n,t.altKey),h,!s||"scale"===l),g=e.x,u=e.y;t instanceof z&&this.editTool&&this.editTool.onScaleWithDrag?(c.drag=t,this.scaleWithDrag(c)):this.scaleOf(c.origin,c.scaleX,c.scaleY),x.move(o.totalOffset,e.x-g,e.y-u)}onRotate(t){const{target:e,mergeConfig:i,dragStartData:s}=this.editBox,{around:o,rotateAround:r,rotateGap:n,diagonalRotateKey:a}=i,{direction:h}=t.current;let l,d;if(t instanceof G)d=t.rotation,l=r?L.getPoint(r,e.boxBounds):e.getBoxPoint(t);else{const i=a?t.isHoldKeys(a):t.shiftKey,n=Ot.getRotateData(e,h,t,s,i?null:r||e.around||e.origin||o||"center");d=s.rotation+n.rotation-e.rotation,l=n.origin}if(d=T.float(T.getGapRotation(d,n,e.rotation),2),!d)return;const c=e.x,g=e.y;this.rotateOf(l,d),x.move(s.totalOffset,e.x-c,e.y-g)}onSkew(t){const{target:e,mergeConfig:i}=this.editBox,{around:s}=i,{origin:o,skewX:r,skewY:n}=Ot.getSkewData(e,t.current.direction,t.getInnerMove(e),Ot.getAround(s,t.altKey));(r||n)&&this.skewOf(o,r,n)}move(t,e=0){if(!this.checkTransform("moveable"))return;a(t)&&(e=t.y,t=t.x);const{target:i,mergeConfig:s,single:o,editor:r}=this.editBox,{beforeMove:n}=s;if(n){const s=n({target:i,x:t,y:e});if(a(s))t=s.x,e=s.y;else if(!1===s)return}const h=i.getWorldPointByLocal({x:t,y:e},null,!0);o||i.safeChange(()=>i.move(t,e));const l={target:i,editor:r,moveX:h.x,moveY:h.y};this.emitEvent(new Qt(Qt.BEFORE_MOVE,l));const d=new Qt(Qt.MOVE,l);this.doMove(d),this.emitEvent(d)}scaleWithDrag(t){if(!this.checkTransform("resizeable"))return;const{target:e,mergeConfig:i,editor:s}=this.editBox,{beforeScale:o}=i;if(o){const{origin:i,scaleX:s,scaleY:r,drag:n}=t;if(!1===o({target:e,drag:n,origin:i,scaleX:s,scaleY:r}))return}t=Object.assign(Object.assign({},t),{target:e,editor:s,worldOrigin:e.getWorldPoint(t.origin)}),this.emitEvent(new te(te.BEFORE_SCALE,t));const r=new te(te.SCALE,t);this.editTool.onScaleWithDrag(r),this.emitEvent(r)}scaleOf(t,e,i=e,s){if(!this.checkTransform("resizeable"))return;const{target:o,mergeConfig:r,single:n,editor:h}=this.editBox,{beforeScale:l}=r;if(l){const s=l({target:o,origin:t,scaleX:e,scaleY:i});if(a(s))e=s.scaleX,i=s.scaleY;else if(!1===s)return}const d=this.getWorldOrigin(t),c=!n&&this.getChangedTransform(()=>o.safeChange(()=>o.scaleOf(t,e,i))),g={target:o,editor:h,worldOrigin:d,scaleX:e,scaleY:i,transform:c};this.emitEvent(new te(te.BEFORE_SCALE,g));const u=new te(te.SCALE,g);this.doScale(u),this.emitEvent(u)}flip(t){if(!this.checkTransform("resizeable"))return;const{target:e,single:i,editor:o}=this.editBox,r=this.getWorldOrigin("center"),n=i?new s(R.getFlipTransform(e,t)):this.getChangedTransform(()=>e.safeChange(()=>e.flip(t))),a={target:e,editor:o,worldOrigin:r,scaleX:"x"===t?-1:1,scaleY:"y"===t?-1:1,transform:n};this.emitEvent(new te(te.BEFORE_SCALE,a));const h=new te(te.SCALE,a);this.doScale(h),this.emitEvent(h)}rotateOf(t,e){if(!this.checkTransform("rotateable"))return;const{target:i,mergeConfig:s,single:o,editor:r}=this.editBox,{beforeRotate:n}=s;if(n){const s=n({target:i,origin:t,rotation:e});if(O(s))e=s;else if(!1===s)return}const a=this.getWorldOrigin(t),h=!o&&this.getChangedTransform(()=>i.safeChange(()=>i.rotateOf(t,e))),l={target:i,editor:r,worldOrigin:a,rotation:e,transform:h};this.emitEvent(new ee(ee.BEFORE_ROTATE,l));const d=new ee(ee.ROTATE,l);this.doRotate(d),this.emitEvent(d)}skewOf(t,e,i=0,s){if(!this.checkTransform("skewable"))return;const{target:o,mergeConfig:r,single:n,editor:h}=this.editBox,{beforeSkew:l}=r;if(l){const s=l({target:o,origin:t,skewX:e,skewY:i});if(a(s))e=s.skewX,i=s.skewY;else if(!1===s)return}const d=this.getWorldOrigin(t),c=!n&&this.getChangedTransform(()=>o.safeChange(()=>o.skewOf(t,e,i))),g={target:o,editor:h,worldOrigin:d,skewX:e,skewY:i,transform:c};this.emitEvent(new ie(ie.BEFORE_SKEW,g));const u=new ie(ie.SKEW,g);this.doSkew(u),this.emitEvent(u)}doMove(t){this.editTool.onMove(t)}doScale(t){this.editTool.onScale(t)}doRotate(t){this.editTool.onRotate(t)}doSkew(t){this.editTool.onSkew(t)}checkTransform(t){const{target:e,mergeConfig:i}=this.editBox;return e&&!e.locked&&i[t]}getWorldOrigin(t){const{target:e}=this.editBox;return e.getWorldPoint(R.getInnerOrigin(e,t))}getChangedTransform(t){const{target:e,single:i}=this.editBox;if(!i&&!e.canChange)return e.changedTransform;const o=new s(e.worldTransform);return t(),new s(e.worldTransform).divide(o)}emitEvent(t,e){this.editBox.editor.emitEvent(t,e)}}let oe=class extends i{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 dragPoint(){return this.editBox.dragPoint}get dragging(){return this.editBox.dragging}get gesturing(){return this.editBox.gesturing}get moving(){return this.editBox.moving}get resizing(){return this.editBox.resizing}get rotating(){return this.editBox.rotating}get skewing(){return this.editBox.skewing}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}get targetLeafer(){const t=this.list[0];return t&&t.leafer}constructor(t,e){super(e),this.leafList=new y,this.openedGroupList=new y,this.simulateTarget=new Jt(this),this.editBox=new Ht(this),this.editToolList={},this.selector=new ut(this),this.editMask=new At(this),this.targetEventIds=[];let i=h.clone(Wt);t&&(i=h.default(t,i)),this.mergedConfig=this.config=i,this.addMany(this.editMask,this.selector,this.editBox),V.has("resize")||(this.config.editSize="scale")}select(t){this.target=t}cancel(){this.target=null}hasItem(t){return this.leafList.has(t)}getItem(t){return this.list[t||0]}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)}setDimOthers(t,i="dim",s){if(!s){const{dimTarget:t,targetLeafer:i}=this;s=t?e(t)?t:[t]:[i]}s[0]&&s[0][i]!==(t||!1)&&s.forEach(e=>h.stintSet(e,i,t))}setBright(t){this.setDimOthers(t,"bright",this.list)}cancelDimOthers(){this.setDimOthers(!1),this.setBright(!1),this.hasDimOthers=void 0}update(){if(this.editing){if(!this.element.parent)return this.cancel();this.innerEditing&&this.innerEditor.update(),this.editTool.update(),this.selector.update()}}updateEditBox(){this.multiple&&Ft(this),this.update()}getEditTool(t){return this.editToolList[t]=this.editToolList[t]||Gt.get(t,this)}updateEditTool(){if(this.unloadEditTool(),this.editing){const t=this.element;let e=t.editOuter||"EditTool";const{beforeEditOuter:i}=this.mergeConfig;if(i){const s=i({target:t,name:e});if(E(s))e=s;else if(!1===s)return}if(Gt.list[e]){const i=this.editTool=this.getEditTool(e);this.editBox.load(),i.editTarget=t,i.load(),this.update()}}}unloadEditTool(t){let e=this.editTool;e&&(t||this.editBox.unload(),e.unload(),t||(this.editTool=null),e.editTarget=null)}getEditSize(t){return this.mergeConfig.editSize}onMove(t){}onScale(t){}onRotate(t){}onSkew(t){}move(t,e=0){}scaleWithDrag(t){}scaleOf(t,e,i=e,s){}flip(t){}rotateOf(t,e){}skewOf(t,e,i=0,s){}checkTransform(t){}getWorldOrigin(t){}getChangedTransform(t){}group(t){return this.multiple&&(this.emitGroupEvent(jt.BEFORE_GROUP),this.target=J.group(this.list,this.element,t),this.emitGroupEvent(jt.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach(t=>t.isBranch&&this.emitGroupEvent(jt.BEFORE_UNGROUP,t)),this.target=J.ungroup(t),t.forEach(t=>t.isBranch&&this.emitGroupEvent(jt.UNGROUP,t))),this.list}openGroup(t){this.emitGroupEvent(jt.BEFORE_OPEN,t),this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(jt.OPEN,t)}closeGroup(t){this.emitGroupEvent(jt.BEFORE_CLOSE,t),this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(jt.CLOSE,t)}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:e}=t;this.editing&&(e=[],t.forEach(t=>this.list.every(e=>!R.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 jt(t,{editTarget:e});this.emitEvent(i),e&&e.emitEvent(i)}getInnerEditor(t){return this.editToolList[t]=this.editToolList[t]||Gt.get(t,this)}openInnerEditor(t,e,i){let s;if(E(e)?s=e:i||(i=e),t&&i&&(this.target=t),this.single){t||(t=this.element),s||(s=t.editInner);const{beforeEditInner:e}=this.mergeConfig;if(e){const i=e({target:t,name:s});if(E(i))s=i;else if(!1===i)return}Gt.list[s]&&(this.unloadEditTool(!0),this.innerEditing=!0,this.innerEditor=this.getInnerEditor(s),this.innerEditor.editTarget=t,this.emitInnerEvent(Kt.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(Kt.OPEN))}}closeInnerEditor(t){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(Kt.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(Kt.CLOSE),t||this.updateEditTool(),this.innerEditor=this.innerEditor.editTarget=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,s=new Kt(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&&(J.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(J.toBottom(this.list),this.leafList.update())}onAppRenderStart(t){(this.targetChanged=t.children.some(t=>t!==this.leafer&&t.renderer.changed))&&this.editBox.forceRender()}onRenderStart(){this.targetChanged&&this.update()}onChildScroll(){this.multiple&&this.updateEditBox()}listenTargetEvents(){if(!this.targetEventIds.length){const{app:t,leafer:e,targetLeafer:i,editMask:s}=this;this.targetEventIds=[e.on_(H.START,this.onRenderStart,this),i&&i.on_(P.SCROLL,this.onChildScroll,this),t.on_(H.CHILD_START,this.onAppRenderStart,this),t.on_(D.UPDATE_MODE,t=>{t.mode&&"normal"!==t.mode&&this.cancel()})],s.visible&&s.forceRender()}}removeTargetEvents(){const{targetEventIds:t,editMask:e}=this;t.length&&(this.off_(t),e.visible&&e.forceRender())}destroy(){this.destroyed||(this.target=this.hoverTarget=null,Object.values(this.editToolList).forEach(t=>t.destroy()),this.simulateTarget.destroy(),this.editToolList={},this.simulateTarget=this.editTool=this.innerEditor=null,super.destroy())}};K([(t,e)=>{o(t,e,{get(){const{config:t,element:e,dragPoint:i,editBox:s,editTool:o,innerEditor:a,app:h}=this,l=Object.assign({},t);if(a?a.editConfig&&Object.assign(l,a.editConfig):o&&o.editConfig&&Object.assign(l,o.editConfig),e&&e.mask&&J.mergeMaskConfig(l,this),e&&e.editConfig){let{editConfig:t}=e;(t.hover||t.hoverStyle||t.hoverPathType)&&(t=Object.assign({},t),delete t.hover,delete t.hoverStyle,delete t.hoverPathType),Object.assign(l,t)}return s.config&&Object.assign(l,s.config),i&&(i.editConfig&&Object.assign(l,i.editConfig),"font-size"===l.editSize&&(l.lockRatio=!0),"resize-rotate"===i.pointType&&(l.around||(l.around="center"),r(l.lockRatio)&&(l.lockRatio=!0))),n(l.dragLimitAnimate)&&(l.dragLimitAnimate=h&&h.config.pointer.dragLimitAnimate),this.mergedConfig=l}})}],oe.prototype,"mergeConfig",void 0),K([Q(function(t,e){const{target:i}=t;i?(t.leafList=i instanceof y?i:new y(i),t.multiple&&Ft(t)):(t.simulateTarget.remove(),t.leafList.reset()),t.closeInnerEditor(!0),t.unloadEditTool();const s={editor:t,value:i,oldValue:e};t.emitEvent(new N(N.SELECT,s)),t.checkOpenedGroups(),t.editing?t.waitLeafer(()=>{t.updateEditTool(),t.listenTargetEvents()}):(t.updateEditTool(),t.removeTargetEvents()),t.emitEvent(new N(N.AFTER_SELECT,s))})],oe.prototype,"target",void 0),K([Q(function(t,e){t.emitEvent(new N(N.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))})],oe.prototype,"hoverTarget",void 0),oe=K([U(se,["editBox","editTool","emitEvent"])],oe);const{abs:re}=Math,{scale:ne}=x;class ae{static registerInnerEditor(){Gt.register(this)}get tag(){return"InnerEditor"}get mode(){return"focus"}get userConfig(){return this.editBox.mergeConfig[this.tag]||{}}get editBox(){return this._editBox||this.editor.editBox}set editBox(t){this._editBox=t}constructor(t){this.eventIds=[],this.editor=t,this.create()}getEditBoxPoint(t,e){const i=e?t:{x:t.x,y:t.y},{scaleX:s,scaleY:o}=this.editTarget.worldTransform;return ne(i,re(s),re(o)),i}getEditTargetPoint(t,e){const i=e?t:{x:t.x,y:t.y},{scaleX:s,scaleY:o}=this.editTarget.worldTransform;return ne(i,Math.abs(1/s),re(1/o)),i}onCreate(){}create(){this.view=new i,this.onCreate()}onLoad(){}load(){const{editor:t}=this;t&&(t.app&&"focus"===this.mode&&(t.selector.hittable=t.app.tree.hitChildren=!1),this.onLoad())}onUpdate(){}update(){this.onUpdate()}onUnload(){}unload(){const{editor:t}=this;t&&(t.app&&"focus"===this.mode&&(t.selector.hittable=t.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 he=class extends ae{static registerEditTool(t,e){Gt.register(this,t),e&&o(this.prototype,"tag",{get:()=>t})}get tag(){return"EditTool"}onMove(t){const{moveX:e,moveY:i,editor:s}=t,{app:o,list:r}=s;o.lockLayout(),r.forEach(t=>{t.moveWorld(e,i)}),o.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:s,worldOrigin:o,editor:r}=t,{app:n,list:a}=r;n.lockLayout(),a.forEach(t=>{const n="scale"!==r.getEditSize(t);s?t.transformWorld(s,n,!1):t.scaleOfWorld(o,e,i,n,!1)}),n.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:s,editor:o}=t,{app:r,list:n}=o;r.lockLayout(),n.forEach(t=>{const r="scale"!==o.getEditSize(t);i?t.transformWorld(i,r,!1):t.rotateOfWorld(s,e)}),r.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:s,worldOrigin:o,editor:r}=t,{app:n,list:a}=r;n.lockLayout(),a.forEach(t=>{const n="scale"!==r.getEditSize(t);s?t.transformWorld(s,n,!1):t.skewOfWorld(o,e,i,n)}),n.unlockLayout()}load(){this.editBox.view.visible=!0,this.onLoad()}update(){this.editBox.update(),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}};he=K([Xt()],he);const{left:le,right:de}=k,{move:ce,copy:ge,toNumberPoints:ue}=x;let fe=class extends he{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(t){const{drag:e,direction:i,lockRatio:s,around:o}=t,r=t.target,n=i===le;if(r.pathInputed){const{path:t}=r.__,{from:i,to:a}=this.getFromToByPath(t);this.dragPoint(i,a,n,o,this.getInnerMove(r,e,s)),t[1]=i.x,t[2]=i.y,t[4]=a.x,t[5]=a.y,r.path=t}else if(r.points){const{points:t}=r,{from:i,to:a}=this.getFromToByPoints(t);this.dragPoint(i,a,n,o,this.getInnerMove(r,e,s)),t[0]=i.x,t[1]=i.y,t[2]=a.x,t[3]=a.y,r.points=t}else{const t=C(),{toPoint:i}=r;r.rotation=0,this.dragPoint(t,i,n,o,this.getInnerMove(r,e,s)),r.getLocalPointByInner(t,null,null,!0),r.getLocalPointByInner(i,null,null,!0),r.x=t.x,r.y=t.y,r.getInnerPointByLocal(i,null,null,!0),r.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){const e=ue(t);return{from:{x:e[0],y:e[1]},to:{x:e[2],y:e[3]}}}dragPoint(t,e,i,s,o){const{x:r,y:n}=o;i?(ce(t,r,n),s&&ce(e,-r,-n)):(s&&ce(t,-r,-n),ce(e,r,n))}onSkew(t){}onUpdate(){const{editBox:t}=this,{rotatePoints:e,resizeLines:i,resizePoints:s,rect:o}=t,r=t.target;let n,a;if(r.pathInputed?n=this.getFromToByPath(r.__.path):r.points&&(n=this.getFromToByPoints(r.__.points)),n){const{from:i,to:a}=n;r.innerToWorld(i,i,!1,t),r.innerToWorld(a,a,!1,t),o.pen.clearPath().moveTo(i.x,i.y).lineTo(a.x,a.y),ge(s[7],i),ge(e[7],i),ge(s[3],a),ge(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===le||t===de,s[t].visible=a,e[t].visible=!n&&a}};fe=K([Xt()],fe),V.add("editor","resize"),A.editor=function(t,e){const i=new oe(t);return e&&e.sky.add(e.editor=i),i},S.addAttr("textBox",!1,I),p.addAttr("editConfig",void 0,I),p.addAttr("editOuter",t=>{t.updateLayout();const{EditTool:e,LineEditTool:i,PointsEditTool:s}=Gt,o=t.pathInputed||t.isPointsMode?s:t.tag+"EditTool",r=Gt.list[o];return!t.__.__isLinePath||o==s&&r?r?o:e:i},I),p.addAttr("editInner","PathEditor",I),i.addAttr("editInner","",I),M.addAttr("editInner","TextEditor",I),p.setEditConfig=function(t){this.changeAttr("editConfig",t)},p.setEditOuter=function(t){this.changeAttr("editOuter",t)},p.setEditInner=function(t){this.changeAttr("editInner",t)};export{Ht as EditBox,Ot as EditDataHelper,Mt as EditPoint,ut as EditSelect,lt as EditSelectHelper,he as EditTool,Gt as EditToolCreator,oe as Editor,N as EditorEvent,jt as EditorGroupEvent,J as EditorHelper,Qt as EditorMoveEvent,ee as EditorRotateEvent,te as EditorScaleEvent,ie as EditorSkewEvent,ae as InnerEditor,Kt as InnerEditorEvent,fe as LineEditTool,ht as SelectArea,at as Stroker,se as TransformTool,tt as editToolMergeConfigAttr,Xt as registerEditTool,Yt as registerInnerEditor};
2
2
  //# sourceMappingURL=editor.esm.min.js.map