@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.
package/dist/editor.js CHANGED
@@ -31,6 +31,66 @@ this.LeaferIN.editor = function(exports, draw, core) {
31
31
  EditorEvent.AFTER_SELECT = "editor.after_select";
32
32
  EditorEvent.BEFORE_HOVER = "editor.before_hover";
33
33
  EditorEvent.HOVER = "editor.hover";
34
+ const order = (a, b) => a.parent.children.indexOf(a) - b.parent.children.indexOf(b);
35
+ const reverseOrder = (a, b) => b.parent.children.indexOf(b) - a.parent.children.indexOf(a);
36
+ const EditorHelper = {
37
+ group(list, element, userGroup) {
38
+ list.sort(reverseOrder);
39
+ const {app: app, parent: parent} = list[0];
40
+ let group;
41
+ if (userGroup && userGroup.add) {
42
+ group = userGroup;
43
+ } else {
44
+ group = new draw.Group(userGroup);
45
+ }
46
+ parent.addAt(group, parent.children.indexOf(list[0]));
47
+ list.sort(order);
48
+ const matrx = new draw.Matrix(element.worldTransform);
49
+ matrx.divideParent(parent.scrollWorldTransform);
50
+ group.setTransform(matrx);
51
+ group.editable = true;
52
+ group.hitChildren = false;
53
+ app.lockLayout();
54
+ list.forEach(child => child.dropTo(group));
55
+ app.unlockLayout();
56
+ return group;
57
+ },
58
+ ungroup(list) {
59
+ const {app: app} = list[0];
60
+ const ungroupList = [];
61
+ app.lockLayout();
62
+ list.forEach(leaf => {
63
+ if (leaf.isBranch) {
64
+ const {parent: parent, children: children} = leaf;
65
+ while (children.length) {
66
+ ungroupList.push(children[0]);
67
+ children[0].dropTo(parent, parent.children.indexOf(leaf));
68
+ }
69
+ if (leaf.isBranchLeaf) ungroupList.push(leaf); else leaf.remove();
70
+ } else {
71
+ ungroupList.push(leaf);
72
+ }
73
+ });
74
+ app.unlockLayout();
75
+ return ungroupList;
76
+ },
77
+ toTop(list) {
78
+ list.sort(order);
79
+ list.forEach(leaf => {
80
+ if (leaf.parent) leaf.parent.add(leaf);
81
+ });
82
+ },
83
+ toBottom(list) {
84
+ list.sort(reverseOrder);
85
+ list.forEach(leaf => {
86
+ if (leaf.parent) leaf.parent.addAt(leaf, 0);
87
+ });
88
+ },
89
+ mergeMaskConfig(_mergeConfig, _editor) {},
90
+ getSiblingMaskElements(_editor) {
91
+ return undefined;
92
+ }
93
+ };
34
94
  function targetAttr(fn) {
35
95
  return (target, key) => {
36
96
  const privateKey = "_" + key;
@@ -78,6 +138,7 @@ this.LeaferIN.editor = function(exports, draw, core) {
78
138
  get() {
79
139
  const {config: config, element: element, dragPoint: dragPoint, editBox: editBox, editTool: editTool, innerEditor: innerEditor, app: app} = this, mergeConfig = Object.assign({}, config);
80
140
  if (innerEditor) innerEditor.editConfig && Object.assign(mergeConfig, innerEditor.editConfig); else if (editTool) editTool.editConfig && Object.assign(mergeConfig, editTool.editConfig);
141
+ if (element && element.mask) EditorHelper.mergeMaskConfig(mergeConfig, this);
81
142
  if (element && element.editConfig) {
82
143
  let {editConfig: editConfig} = element;
83
144
  if (editConfig.hover || editConfig.hoverStyle || editConfig.hoverPathType) {
@@ -103,7 +164,27 @@ this.LeaferIN.editor = function(exports, draw, core) {
103
164
  });
104
165
  };
105
166
  }
106
- const {abs: abs$1} = Math;
167
+ function editToolMergeConfigAttr() {
168
+ return (target, key) => {
169
+ draw.defineKey(target, key, {
170
+ get() {
171
+ const t = this;
172
+ const {config: config, userConfig: userConfig, configKeepKeys: configKeepKeys} = t, mergedConfig = config ? draw.DataHelper.clone(config) : {};
173
+ if (configKeepKeys) {
174
+ for (let key in userConfig) {
175
+ if (!configKeepKeys.includes(key)) mergedConfig[key] = userConfig[key];
176
+ }
177
+ }
178
+ if (t.preMergedConfig) t.preMergedConfig(mergedConfig);
179
+ if (configKeepKeys) configKeepKeys.forEach(key => {
180
+ userConfig[key] && Object.assign(mergedConfig[key], userConfig[key]);
181
+ });
182
+ return t.mergedConfig = mergedConfig;
183
+ }
184
+ });
185
+ };
186
+ }
187
+ const {abs: abs$2} = Math;
107
188
  const {copy: copy$1} = draw.MatrixHelper;
108
189
  const {setListWithFn: setListWithFn} = draw.BoundsHelper;
109
190
  const {worldBounds: worldBounds} = draw.LeafBoundsHelper;
@@ -140,7 +221,7 @@ this.LeaferIN.editor = function(exports, draw, core) {
140
221
  leaf = list[i];
141
222
  const {worldTransform: worldTransform, worldRenderBounds: worldRenderBounds} = leaf;
142
223
  if (worldRenderBounds.width && worldRenderBounds.height && (!bounds || bounds.hit(worldRenderBounds, options.matrix))) {
143
- const aScaleX = abs$1(worldTransform.scaleX), aScaleY = abs$1(worldTransform.scaleY);
224
+ const aScaleX = abs$2(worldTransform.scaleX), aScaleY = abs$2(worldTransform.scaleY);
144
225
  copy$1(matrix, worldTransform);
145
226
  matrix.half = strokeWidth % 2;
146
227
  canvas.setWorld(matrix, options.matrix);
@@ -287,7 +368,11 @@ this.LeaferIN.editor = function(exports, draw, core) {
287
368
  }
288
369
  onSelect() {
289
370
  if (this.running) {
290
- this.targetStroker.setTarget(this.editor.list);
371
+ const {editor: editor} = this;
372
+ let {list: list} = editor;
373
+ const maskList = EditorHelper.getSiblingMaskElements(editor);
374
+ if (maskList) list = maskList.concat(list);
375
+ this.targetStroker.setTarget(list);
291
376
  this.hoverStroker.target = null;
292
377
  }
293
378
  }
@@ -457,12 +542,12 @@ this.LeaferIN.editor = function(exports, draw, core) {
457
542
  }
458
543
  }
459
544
  const {topLeft: topLeft, top: top, topRight: topRight, right: right$1, bottomRight: bottomRight, bottom: bottom, bottomLeft: bottomLeft, left: left$1} = draw.Direction9;
460
- const {toPoint: toPoint} = draw.AroundHelper, {within: within, sign: sign} = draw.MathHelper, {abs: abs} = Math;
545
+ const {toPoint: toPoint} = draw.AroundHelper, {within: within, sign: sign} = draw.MathHelper, {abs: abs$1} = Math;
461
546
  const EditDataHelper = {
462
547
  getScaleData(target, startBounds, direction, totalMoveOrScale, lockRatio, around, flipable, scaleMode) {
463
548
  let align, origin = {}, scaleX = 1, scaleY = 1, lockScale;
464
549
  const {widthRange: widthRange, heightRange: heightRange, dragBounds: dragBounds, worldTransform: worldTransform, boxBounds: boxBounds} = target;
465
- const {width: width, height: height} = startBounds, worldScaleX = abs(worldTransform.scaleX), worldScaleY = abs(worldTransform.scaleY);
550
+ const {width: width, height: height} = startBounds, worldScaleX = abs$1(worldTransform.scaleX), worldScaleY = abs$1(worldTransform.scaleY);
466
551
  const originChangedScaleX = target.scaleX / startBounds.scaleX;
467
552
  const originChangedScaleY = target.scaleY / startBounds.scaleY;
468
553
  const signX = sign(originChangedScaleX);
@@ -542,7 +627,7 @@ this.LeaferIN.editor = function(exports, draw, core) {
542
627
  break;
543
628
 
544
629
  default:
545
- lockScale = Math.sqrt(abs(scaleX * scaleY));
630
+ lockScale = Math.sqrt(abs$1(scaleX * scaleY));
546
631
  scaleX = sign(scaleX) * lockScale;
547
632
  scaleY = sign(scaleY) * lockScale;
548
633
  }
@@ -576,10 +661,10 @@ this.LeaferIN.editor = function(exports, draw, core) {
576
661
  }
577
662
  const minWidth = 1, minHeight = 1;
578
663
  const worldWidth = worldScaleX * boxBounds.width, worldHeight = worldScaleY * boxBounds.height;
579
- if (useScaleX && abs(scaleX * worldWidth) < minWidth) scaleX = sign(scaleX) * minWidth / worldWidth;
580
- if (useScaleY && abs(scaleY * worldHeight) < minHeight) scaleY = sign(scaleY) * minHeight / worldHeight;
664
+ if (useScaleX && abs$1(scaleX * worldWidth) < minWidth) scaleX = sign(scaleX) * minWidth / worldWidth;
665
+ if (useScaleY && abs$1(scaleY * worldHeight) < minHeight) scaleY = sign(scaleY) * minHeight / worldHeight;
581
666
  if (lockRatio && scaleX !== scaleY) {
582
- lockScale = Math.min(abs(scaleX), abs(scaleY));
667
+ lockScale = Math.min(abs$1(scaleX), abs$1(scaleY));
583
668
  scaleX = sign(scaleX) * lockScale;
584
669
  scaleY = sign(scaleY) * lockScale;
585
670
  }
@@ -794,6 +879,7 @@ this.LeaferIN.editor = function(exports, draw, core) {
794
879
  }
795
880
  }
796
881
  const fourDirection = [ "top", "right", "bottom", "left" ], editConfig = undefined;
882
+ const debug$1 = draw.Debug.get("EditBox");
797
883
  class EditBox extends draw.Group {
798
884
  get mergeConfig() {
799
885
  const {config: config} = this, {mergeConfig: mergeConfig, editBox: editBox} = this.editor;
@@ -864,10 +950,12 @@ this.LeaferIN.editor = function(exports, draw, core) {
864
950
  this.resizeLines = [];
865
951
  this.dragStartData = {};
866
952
  this.__eventIds = [];
953
+ this.widgets = [];
867
954
  this.editor = editor;
868
955
  this.visible = false;
869
956
  this.create();
870
957
  this.__listenEvents();
958
+ this.createWidgets();
871
959
  }
872
960
  create() {
873
961
  let rotatePoint, resizeLine, resizePoint;
@@ -903,7 +991,7 @@ this.LeaferIN.editor = function(exports, draw, core) {
903
991
  }
904
992
  this.listenPointEvents(circle, "rotate", 2);
905
993
  this.listenPointEvents(rect, "move", 8);
906
- view.addMany(...rotatePoints, rect, circle, buttons, ...resizeLines, ...resizePoints);
994
+ view.add([ ...rotatePoints, rect, circle, buttons, ...resizeLines, ...resizePoints ]);
907
995
  this.add(view);
908
996
  }
909
997
  load() {
@@ -916,6 +1004,7 @@ this.LeaferIN.editor = function(exports, draw, core) {
916
1004
  let resizeP;
917
1005
  for (let i = 0; i < 8; i++) {
918
1006
  resizeP = resizePoints[i];
1007
+ if (resizeP.children.length) resizeP.clear();
919
1008
  resizeP.set(this.getPointStyle(i % 2 ? middlePointsStyle[(i - 1) / 2 % middlePointsStyle.length] : pointsStyle[i / 2 % pointsStyle.length]));
920
1009
  resizeP.rotation = (i - (i % 2 ? 1 : 0)) / 2 * 90;
921
1010
  if (i % 2) resizeLines[(i - 1) / 2].set(Object.assign({
@@ -941,6 +1030,7 @@ this.LeaferIN.editor = function(exports, draw, core) {
941
1030
  }
942
1031
  if (single) draw.DataHelper.stintSet(target.__world, "ignorePixelSnap", ignorePixelSnap);
943
1032
  updateMoveCursor(this);
1033
+ this.loadWidgets();
944
1034
  }
945
1035
  update() {
946
1036
  const {editor: editor} = this;
@@ -961,8 +1051,10 @@ this.LeaferIN.editor = function(exports, draw, core) {
961
1051
  width: width,
962
1052
  height: height
963
1053
  });
1054
+ this.updateWidgets();
964
1055
  }
965
1056
  unload() {
1057
+ this.unloadWidgets();
966
1058
  this.visible = false;
967
1059
  if (this.app) this.rect.syncEventer = this.app.interaction.bottomList = null;
968
1060
  }
@@ -975,6 +1067,7 @@ this.LeaferIN.editor = function(exports, draw, core) {
975
1067
  strokeBoxSpread && draw.BoundsHelper.spread(bounds, [ strokeBoxSpread * Math.abs(scaleY), strokeBoxSpread * Math.abs(scaleX) ]);
976
1068
  }
977
1069
  if (spread) draw.BoundsHelper.spread(bounds, spread);
1070
+ this.rectBounds = bounds;
978
1071
  editMask.visible = mask ? true : 0;
979
1072
  if (!draw.isUndefined(dimOthers) || !draw.isUndefined(bright)) {
980
1073
  editor.setDimOthers(dimOthers);
@@ -986,7 +1079,7 @@ this.LeaferIN.editor = function(exports, draw, core) {
986
1079
  if (this.view.worldOpacity) {
987
1080
  const {width: width, height: height} = bounds;
988
1081
  const smallSize = draw.isNumber(hideOnSmall) ? hideOnSmall : 10;
989
- const showPoints = editBox && !(hideOnSmall && width < smallSize && height < smallSize);
1082
+ const showPoints = this.showPoints = editBox && !(hideOnSmall && width < smallSize && height < smallSize);
990
1083
  let point = {}, rotateP, resizeP, resizeL;
991
1084
  for (let i = 0; i < 8; i++) {
992
1085
  draw.AroundHelper.toPoint(draw.AroundHelper.directionData[i], bounds, point);
@@ -1280,12 +1373,36 @@ this.LeaferIN.editor = function(exports, draw, core) {
1280
1373
  __removeListenEvents() {
1281
1374
  this.off_(this.__eventIds);
1282
1375
  }
1376
+ static registerWidget(Widget) {
1377
+ const {tag: tag} = Widget.prototype;
1378
+ EditBox.WidgetList[tag] && debug$1.repeat(tag);
1379
+ EditBox.WidgetList[tag] = Widget;
1380
+ }
1381
+ createWidgets() {
1382
+ Object.values(EditBox.WidgetList).forEach(item => {
1383
+ this.widgets.push(new item(this));
1384
+ });
1385
+ }
1386
+ loadWidgets() {
1387
+ this.widgets.forEach(item => item.onLoad());
1388
+ }
1389
+ updateWidgets() {
1390
+ this.widgets.forEach(item => item.onUpdate());
1391
+ }
1392
+ unloadWidgets() {
1393
+ this.widgets.forEach(item => item.onUnload());
1394
+ }
1395
+ destroyWidgets() {
1396
+ this.widgets.forEach(item => item.onDestroy());
1397
+ }
1283
1398
  destroy() {
1284
1399
  this.editor = null;
1285
1400
  this.__removeListenEvents();
1401
+ this.destroyWidgets();
1286
1402
  super.destroy();
1287
1403
  }
1288
1404
  }
1405
+ EditBox.WidgetList = {};
1289
1406
  const bigBounds = {
1290
1407
  x: 0,
1291
1408
  y: 0,
@@ -1421,62 +1538,6 @@ this.LeaferIN.editor = function(exports, draw, core) {
1421
1538
  oldValue: oldValue
1422
1539
  }));
1423
1540
  }
1424
- const order = (a, b) => a.parent.children.indexOf(a) - b.parent.children.indexOf(b);
1425
- const reverseOrder = (a, b) => b.parent.children.indexOf(b) - a.parent.children.indexOf(a);
1426
- const EditorHelper = {
1427
- group(list, element, userGroup) {
1428
- list.sort(reverseOrder);
1429
- const {app: app, parent: parent} = list[0];
1430
- let group;
1431
- if (userGroup && userGroup.add) {
1432
- group = userGroup;
1433
- } else {
1434
- group = new draw.Group(userGroup);
1435
- }
1436
- parent.addAt(group, parent.children.indexOf(list[0]));
1437
- list.sort(order);
1438
- const matrx = new draw.Matrix(element.worldTransform);
1439
- matrx.divideParent(parent.scrollWorldTransform);
1440
- group.setTransform(matrx);
1441
- group.editable = true;
1442
- group.hitChildren = false;
1443
- app.lockLayout();
1444
- list.forEach(child => child.dropTo(group));
1445
- app.unlockLayout();
1446
- return group;
1447
- },
1448
- ungroup(list) {
1449
- const {app: app} = list[0];
1450
- const ungroupList = [];
1451
- app.lockLayout();
1452
- list.forEach(leaf => {
1453
- if (leaf.isBranch) {
1454
- const {parent: parent, children: children} = leaf;
1455
- while (children.length) {
1456
- ungroupList.push(children[0]);
1457
- children[0].dropTo(parent, parent.children.indexOf(leaf));
1458
- }
1459
- if (leaf.isBranchLeaf) ungroupList.push(leaf); else leaf.remove();
1460
- } else {
1461
- ungroupList.push(leaf);
1462
- }
1463
- });
1464
- app.unlockLayout();
1465
- return ungroupList;
1466
- },
1467
- toTop(list) {
1468
- list.sort(order);
1469
- list.forEach(leaf => {
1470
- if (leaf.parent) leaf.parent.add(leaf);
1471
- });
1472
- },
1473
- toBottom(list) {
1474
- list.sort(reverseOrder);
1475
- list.forEach(leaf => {
1476
- if (leaf.parent) leaf.parent.addAt(leaf, 0);
1477
- });
1478
- }
1479
- };
1480
1541
  const debug = draw.Debug.get("EditToolCreator");
1481
1542
  function registerEditTool() {
1482
1543
  return target => {
@@ -2212,6 +2273,7 @@ this.LeaferIN.editor = function(exports, draw, core) {
2212
2273
  __decorate([ targetAttr(onTarget) ], exports.Editor.prototype, "target", void 0);
2213
2274
  __decorate([ targetAttr(onHover) ], exports.Editor.prototype, "hoverTarget", void 0);
2214
2275
  exports.Editor = __decorate([ core.useModule(TransformTool, [ "editBox", "editTool", "emitEvent" ]) ], exports.Editor);
2276
+ const {abs: abs} = Math, {scale: scale} = draw.PointHelper;
2215
2277
  class InnerEditor {
2216
2278
  static registerInnerEditor() {
2217
2279
  EditToolCreator.register(this);
@@ -2222,6 +2284,9 @@ this.LeaferIN.editor = function(exports, draw, core) {
2222
2284
  get mode() {
2223
2285
  return "focus";
2224
2286
  }
2287
+ get userConfig() {
2288
+ return this.editBox.mergeConfig[this.tag] || {};
2289
+ }
2225
2290
  get editBox() {
2226
2291
  return this._editBox || this.editor.editBox;
2227
2292
  }
@@ -2233,6 +2298,22 @@ this.LeaferIN.editor = function(exports, draw, core) {
2233
2298
  this.editor = editor;
2234
2299
  this.create();
2235
2300
  }
2301
+ getEditBoxPoint(editTargetPoint, change) {
2302
+ const point = change ? editTargetPoint : {
2303
+ x: editTargetPoint.x,
2304
+ y: editTargetPoint.y
2305
+ }, {scaleX: scaleX, scaleY: scaleY} = this.editTarget.worldTransform;
2306
+ scale(point, abs(scaleX), abs(scaleY));
2307
+ return point;
2308
+ }
2309
+ getEditTargetPoint(editBoxPoint, change) {
2310
+ const point = change ? editBoxPoint : {
2311
+ x: editBoxPoint.x,
2312
+ y: editBoxPoint.y
2313
+ }, {scaleX: scaleX, scaleY: scaleY} = this.editTarget.worldTransform;
2314
+ scale(point, Math.abs(1 / scaleX), abs(1 / scaleY));
2315
+ return point;
2316
+ }
2236
2317
  onCreate() {}
2237
2318
  create() {
2238
2319
  this.view = new draw.Group;
@@ -2484,6 +2565,7 @@ this.LeaferIN.editor = function(exports, draw, core) {
2484
2565
  exports.SelectArea = SelectArea;
2485
2566
  exports.Stroker = Stroker;
2486
2567
  exports.TransformTool = TransformTool;
2568
+ exports.editToolMergeConfigAttr = editToolMergeConfigAttr;
2487
2569
  exports.registerEditTool = registerEditTool;
2488
2570
  exports.registerInnerEditor = registerInnerEditor;
2489
2571
  return exports;
@@ -1,2 +1,2 @@
1
- "use strict";var t=require("@leafer-ui/draw"),e=require("@leafer-ui/core");function i(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 s(e){return e?t.isArray(e)?e:[e]:[]}require("@leafer-in/resize"),"function"==typeof SuppressedError&&SuppressedError;class o extends t.Event{get list(){return s(this.value)}get oldList(){return s(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}function r(e){return(i,s)=>{const r="_"+s;t.defineKey(i,s,{get(){return this[r]},set(i){const n=this[r];if(n!==i){const a=this;if(a.config){const e="target"===s;if(e){const{beforeSelect:e}=a.config;if(e){const s=e({target:i});if(t.isObject(s))i=s;else if(!1===s)return}a.hasDimOthers&&a.cancelDimOthers(),t.isArray(i)&&i.length>1&&i[0].locked&&i.splice(0,1),a.single&&(delete a.element.syncEventer,delete a.element.__world.ignorePixelSnap)}const r=e?o.BEFORE_SELECT:o.BEFORE_HOVER;this.hasEvent(r)&&this.emitEvent(new o(r,{editor:a,value:i,oldValue:n}))}this[r]=i,e(this,n)}}})}}o.BEFORE_SELECT="editor.before_select",o.SELECT="editor.select",o.AFTER_SELECT="editor.after_select",o.BEFORE_HOVER="editor.before_hover",o.HOVER="editor.hover";const{abs:n}=Math,{copy:a}=t.MatrixHelper,{setListWithFn:h}=t.BoundsHelper,{worldBounds:l}=t.LeafBoundsHelper,d=t.getMatrixData(),c=t.getBoundsData();class g extends t.UI{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?(h(c,e,l),t&&this.set(t),this.set(c),this.visible=!0):this.visible=0}__draw(e,i){const{list:s}=this;if(s.length){let o;const r=this.__,{stroke:h,strokeWidth:l,fill:c}=r,{bounds:g}=i;for(let u=0;u<s.length;u++){o=s[u];const{worldTransform:f,worldRenderBounds:p}=o;if(p.width&&p.height&&(!g||g.hit(p,i.matrix))){const s=n(f.scaleX),g=n(f.scaleY);switch(a(d,f),d.half=l%2,e.setWorld(d,i.matrix),e.beginPath(),this.strokePathType){case"box":const{boxBounds:t}=o.__layout;e.rect(t.x,t.y,t.width,t.height);break;case"stroke":const{strokeBounds:i}=o.__layout;e.rect(i.x,i.y,i.width,i.height);break;case"path":o.__drawPath(e);break;default:o.__.__useArrow?o.__drawPath(e):o.__.__pathForRender?o.__drawRenderPath(e):o.__drawPathByBox(e)}if(r.strokeWidth=l/Math.max(s,g),r.shadow){const i=r.shadow[0],{scaleX:s,scaleY:o}=this.getRenderScaleData(!0,i.scaleFixed);e.save(),e.setWorldShadow(i.x*s,i.y*o,i.blur*s,t.ColorConvert.string(i.color))}h&&(t.isString(h)?t.Paint.stroke(h,this,e,i):t.Paint.strokes(h,this,e,i)),c&&(t.isString(c)?t.Paint.fill(c,this,e,i):t.Paint.fills(c,this,e,i)),r.shadow&&e.restore()}}r.strokeWidth=l}}destroy(){this.target=null,super.destroy()}}i([r(function(e){const i=e.target;e.list=i?t.isArray(i)?i:[i]:[]})],g.prototype,"target",void 0),i([t.surfaceType("render-path")],g.prototype,"strokePathType",void 0);class u extends t.Group{constructor(e){super(e),this.strokeArea=new t.Rect({strokeAlign:"center"}),this.fillArea=new t.Rect,this.visible=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 f={findOne:t=>t.list.find(t=>t.editable),findByBounds(t,e){const i=[];return p([t],i,e),i}};function p(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&&p(s.children,e,i)}}const{findOne:E,findByBounds:m}=f;class v extends t.Group{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(e){super(),this.hoverStroker=new g,this.targetStroker=new g,this.bounds=new t.Bounds,this.selectArea=new u,this.__eventIds=[],this.editor=e,this.addMany(this.targetStroker,this.hoverStroker,this.selectArea),this.__listenEvents()}onHover(){const{editor:t}=this;if(!this.running||this.dragging||t.dragging)this.hoverStroker.target=null;else{const{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(e){if(!e.multiTouch){if(this.editor.dragging)return this.onDragEnd(e);if(this.dragging){const{editor:i}=this,s=e.getInnerTotal(this),o=this.bounds.clone().unsign(),r=new t.LeafList(m(i.app,o));if(this.bounds.width=s.x,this.bounds.height=s.y,this.selectArea.setBounds(o.get()),r.length){const t=[];this.originList.forEach(e=>{r.has(e)||t.push(e)}),r.forEach(e=>{this.originList.has(e)||t.push(e)}),(t.length!==i.list.length||i.list.some((e,i)=>e!==t[i]))&&(i.target=t)}else i.target=this.originList.list}}}onDragEnd(t){t.multiTouch||this.dragging&&(this.originList=null,this.selectArea.visible=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)&&!E(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(e){const i={exclude:new t.LeafList(this.editor.editBox.rect)};return E(e.target.leafer.interaction.findPath(e,i))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):E(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:i}=t;i.selector.proxy=t,this.__eventIds=[t.on_([[o.HOVER,this.onHover,this],[o.SELECT,this.onSelect,this]]),i.on_([[e.PointerEvent.MOVE,this.onPointerMove,this],[e.PointerEvent.BEFORE_DOWN,this.onBeforeDown,this],[e.PointerEvent.TAP,this.onTap,this],[e.DragEvent.START,this.onDragStart,this,!0],[e.DragEvent.DRAG,this.onDrag,this],[e.DragEvent.END,this.onDragEnd,this],[e.MoveEvent.MOVE,this.onAutoMove,this],[[e.ZoomEvent.ZOOM,e.MoveEvent.MOVE],()=>{this.editor.hoverTarget=null}]])]})}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=this.originList=this.needRemoveItem=null,this.__removeListenEvents(),super.destroy()}}const{topLeft:b,top:y,topRight:w,right:x,bottomRight:L,bottom:T,bottomLeft:k,left:S}=t.Direction9,{toPoint:O}=t.AroundHelper,{within:_,sign:M}=t.MathHelper,{abs:B}=Math,C={getScaleData(i,s,o,r,n,a,h,l){let d,c,g={},u=1,f=1;const{widthRange:p,heightRange:E,dragBounds:m,worldTransform:v,boxBounds:C}=i,{width:P,height:R}=s,H=B(v.scaleX),D=B(v.scaleY),A=i.scaleX/s.scaleX,I=i.scaleY/s.scaleY,V=M(A),z=M(I),F=l?A:V*C.width/P,Z=l?I:z*C.height/R;if(t.isNumber(r))u=f=Math.sqrt(r);else{a&&(r.x*=2,r.y*=2),r.x*=l?A:V,r.y*=l?I:z;const t=(-r.y+R)/R,e=(r.x+P)/P,i=(r.y+R)/R,s=(-r.x+P)/P;switch(o){case y:f=t,d="bottom";break;case x:u=e,d="left";break;case T:f=i,d="top";break;case S:u=s,d="right";break;case b:f=t,u=s,d="bottom-right";break;case w:f=t,u=e,d="bottom-left";break;case L:f=i,u=e,d="top-left";break;case k:f=i,u=s,d="top-right"}if(n)if("corner"===n&&o%2)n=!1;else switch(o){case y:case T:u=f;break;case S:case x:f=u;break;default:c=Math.sqrt(B(u*f)),u=M(u)*c,f=M(f)*c}}const W=1!==u,G=1!==f;if(W&&(u/=F),G&&(f/=Z),h||(u<0&&(u=1/C.width/H),f<0&&(f=1/C.height/D)),O(a||d,C,g,!0),m){const t={x:u,y:f};e.DragBoundsHelper.limitScaleOf(i,g,t,n),u=t.x,f=t.y}if(W&&p){const t=C.width*i.scaleX;u=_(t*u,p)/t}if(G&&E){const t=C.height*i.scaleY;f=_(t*f,E)/t}const U=H*C.width,X=D*C.height;return W&&B(u*U)<1&&(u=1*M(u)/U),G&&B(f*X)<1&&(f=1*M(f)/X),n&&u!==f&&(c=Math.min(B(u),B(f)),u=M(u)*c,f=M(f)*c),isFinite(u)||(u=1),isFinite(f)||(f=1),{origin:g,scaleX:u,scaleY:f,direction:o,lockRatio:n,around:a}},getRotateData(e,i,s,o,r){let n,a={};switch(i){case b:n="bottom-right";break;case w:n="bottom-left";break;case L:n="top-left";break;case k:n="top-right";break;default:n="center"}return O(r||n,e.boxBounds,a,!0),{origin:a,rotation:t.PointHelper.getRotation(o,e.getWorldPointByBox(a),s)}},getSkewData(e,i,s,o){let r,n,a={},h=0,l=0;switch(i){case y:case b:n={x:.5,y:0},r="bottom",h=1;break;case T:case L:n={x:.5,y:1},r="top",h=1;break;case S:case k:n={x:0,y:.5},r="right",l=1;break;case x:case w:n={x:1,y:.5},r="left",l=1}const{boxBounds:d}=e,{width:c,height:g}=d;n.x=n.x*c,n.y=n.y*g,O(o||r,d,a,!0);const u=t.PointHelper.getRotation(n,a,{x:n.x+(h?s.x:0),y:n.y+(l?s.y:0)});return h?h=-u:l=u,{origin:a,skewX:h,skewY:l}},getAround:(t,e)=>e&&!t?"center":t,getRotateDirection:(t,e,i=8)=>((t=(t+Math.round(e/(360/i)))%i)<0&&(t+=i),t),getFlipDirection(t,e,i){if(e)switch(t){case S:t=x;break;case b:t=w;break;case k:t=L;break;case x:t=S;break;case w:t=b;break;case L:t=k}if(i)switch(t){case y:t=T;break;case b:t=k;break;case w:t=L;break;case T:t=y;break;case k:t=b;break;case L:t=w}return t}},P={};function R(e,i){const{enterPoint:s,dragging:o,skewing:r,resizing:n,flippedX:a,flippedY:h}=e;if(!s||!e.editor.editing||!e.canUse)return;if("rect"===s.name)return H(e);if("circle"===s.name)return;let{rotation:l}=e;const{pointType:d}=s,{moveCursor:c,resizeCursor:g,rotateCursor:u,skewCursor:f,moveable:p,resizeable:E,rotateable:m,skewable:v}=e.mergeConfig;if("move"===d)return s.cursor=c,void(p||(s.visible=!1));if("button"===d)return void(s.cursor||(s.cursor="pointer"));let b=d.includes("resize");b&&m&&(e.isHoldRotateKey(i)||!E)&&(b=!1);const y=v&&!b&&("resize-line"===s.name||"skew"===d),w=o?r?f:n?g:u:y?f:b?g:u;l+=45*(C.getFlipDirection(s.direction,a,h)+1),l=2*Math.round(t.MathHelper.formatRotation(l,!0)/2);const{url:x,x:L,y:T}=w,k=x+l;P[k]?s.cursor=P[k]:P[k]=s.cursor={url:D(x,l),x:L,y:T}}function H(t){const{moveCursor:e,moveable:i}=t.mergeConfig;t.canUse&&(t.rect.cursor=i?e:void 0)}function D(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class A extends t.Box{constructor(t){super(t),this.useFastShadow=!0}}const I=["top","right","bottom","left"],V=void 0;class z extends t.Group{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:e,resizeable:i,rotateable:s}=this.mergeConfig;return t.isString(e)||t.isString(i)||t.isString(s)}get canDragLimitAnimate(){return this.moving&&this.mergeConfig.dragLimitAnimate&&this.target.dragBounds}constructor(e){super(),this.view=new t.Group,this.rect=new A({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new A({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new t.Group({around:"center",hitSelf:!1,visible:0}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.dragStartData={},this.__eventIds=[],this.editor=e,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 A({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),r.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new A({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),n.push(e),this.listenPointEvents(e,"resize",s)),i=new A({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:e,mergeConfig:i,single:s,rect:o,circle:r,resizePoints:n,resizeLines:a}=this,{stroke:h,strokeWidth:l,ignorePixelSnap:d}=i,c=this.getPointsStyle(),g=this.getMiddlePointsStyle(),u=this.getResizeLinesStyle();let f;this.visible=!e.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(i.circle||i.rotatePoint||c[0])),o.set(Object.assign({stroke:h,strokeWidth:l,opacity:1,editConfig:V},i.rect||{}));const p=t.isNull(i.rectThrough)?s:i.rectThrough;o.hittable=!p,p&&(e.syncEventer=o,this.app.interaction.bottomList=[{target:o,proxy:e}]),s&&t.DataHelper.stintSet(e.__world,"ignorePixelSnap",d),H(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(e){const{editor:i,target:s,mergeConfig:o,single:r,rect:n,circle:a,buttons:h,resizePoints:l,rotatePoints:d,resizeLines:c}=this,{editMask:g}=i,{middlePoint:u,resizeable:f,rotateable:p,hideOnSmall:E,editBox:m,editBoxType:v,mask:b,dimOthers:y,bright:w,spread:x,hideRotatePoints:L,hideResizeLines:T}=o;if("stroke"===v){const{scaleX:i,scaleY:o}=s.worldTransform,{strokeBoxSpread:r}=s.__layout;r&&t.BoundsHelper.spread(e,[r*Math.abs(o),r*Math.abs(i)])}if(x&&t.BoundsHelper.spread(e,x),g.visible=!!b||0,t.isUndefined(y)&&t.isUndefined(w)?i.hasDimOthers&&i.cancelDimOthers():(i.setDimOthers(y),i.setBright(!!y||w),i.hasDimOthers=!0),this.view.worldOpacity){const{width:i,height:s}=e,g=t.isNumber(E)?E:10,v=m&&!(E&&i<g&&s<g);let b,y,w,x={};for(let o=0;o<8;o++)t.AroundHelper.toPoint(t.AroundHelper.directionData[o],e,x),y=l[o],b=d[o],y.set(x),b.set(x),y.visible=v&&!(!f&&!p),b.visible=v&&p&&f&&!L,o%2&&(w=c[(o-1)/2],w.set(x),w.visible=y.visible&&!T,y.visible&&(y.visible=!!u),b.visible&&(b.visible=!!u),(o+1)/2%2?(w.width=i+w.height,E&&2*y.width>i&&(y.visible=!1)):(w.width=s+w.height,E&&2*y.width>s&&(y.visible=!1)));a.visible=v&&p&&!(!o.circle&&!o.rotatePoint),a.visible&&this.layoutCircle(),n.path&&(n.path=null),n.set(Object.assign(Object.assign({},e),{visible:!r||m})),h.visible=v&&h.children.length>0||0,h.visible&&this.layoutButtons()}else n.set(e)}layoutCircle(){const{circleDirection:t,circleMargin:e,buttonsMargin:i,buttonsDirection:s,middlePoint:o}=this.mergedConfig,r=I.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=I.indexOf(e);(a%2&&r||(a+1)%2&&n)&&i&&(a=(a+2)%4);const h=i?C.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:V};return t?Object.assign(n,t):n}getPointsStyle(){const{point:e}=this.mergedConfig;return t.isArray(e)?e:[e]}getMiddlePointsStyle(){const{middlePoint:e}=this.mergedConfig;return t.isArray(e)?e:e?[e]:this.getPointsStyle()}getResizeLinesStyle(){const{resizeLine:e}=this.mergedConfig;return t.isArray(e)?e:[e]}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)}R(this,t)}onDragEnd(t){this.onTransformEnd(t),this.dragPoint=null}onTransformStart(e){const{hideOnMove:i}=this.mergedConfig;(this.moving||this.gesturing)&&(this.editor.opacity=i?0:1),this.resizing&&(t.ResizeEvent.resizingKeys=this.editor.leafList.keys);const{dragStartData:s,target:o}=this;s.x=e.x,s.y=e.y,s.totalOffset=t.getPointData(),s.point={x:o.x,y:o.y},s.bounds=Object.assign({},o.getLayoutBounds("box","local")),s.rotation=o.rotation}onTransformEnd(i){this.canDragLimitAnimate&&(i instanceof e.DragEvent||i instanceof e.MoveEvent)&&this.transformTool.onMove(i),this.resizing&&(t.ResizeEvent.resizingKeys=null),this.dragging=this.gesturing=this.moving=this.resizing=this.rotating=this.skewing=!1,this.editor.opacity=1,this.editor.update()}onMove(i){if(this.canGesture&&"drag"!==i.moveType&&(i.stop(),t.isString(this.mergedConfig.moveable)))switch(this.gesturing=this.moving=!0,i.type){case e.MoveEvent.START:this.onTransformStart(i);break;case e.MoveEvent.END:this.onTransformEnd(i);break;default:this.transformTool.onMove(i)}}onScale(i){if(this.canGesture&&(i.stop(),t.isString(this.mergedConfig.resizeable)))switch(this.gesturing=this.resizing=!0,i.type){case e.ZoomEvent.START:this.onTransformStart(i);break;case e.ZoomEvent.END:this.onTransformEnd(i);break;default:this.transformTool.onScale(i)}}onRotate(i){if(this.canGesture&&(i.stop(),t.isString(this.mergedConfig.rotateable)))switch(this.gesturing=this.rotating=!0,i.type){case e.ZoomEvent.START:this.onTransformStart(i);break;case e.ZoomEvent.END:this.onTransformEnd(i);break;default:this.transformTool.onRotate(i)}}isHoldRotateKey(t){const{rotateKey:e}=this.mergedConfig;return e?t.isHoldKeys(e):t.metaKey||t.ctrlKey}onKey(t){R(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(e){const{editor:i,target:s}=this;if(this.single){if(s.locked)return;if(s.isBranch&&!s.editInner){if(s.textBox){const{children:e}=s,o=e.find(e=>e.editable&&e instanceof t.Text)||e.find(e=>e instanceof t.Text);if(o)return i.openInnerEditor(o)}i.openGroup(s),i.target=i.selector.findDeepOne(e)}else i.openInnerEditor()}}listenPointEvents(t,i,s){t.direction=s,t.pointType=i,this.__eventIds.push(t.on_([[e.DragEvent.START,this.onDragStart,this],[e.DragEvent.DRAG,this.onDrag,this],[e.DragEvent.END,this.onDragEnd,this],[e.PointerEvent.ENTER,e=>{this.enterPoint=t,R(this,e)}],[e.PointerEvent.LEAVE,()=>{this.enterPoint=null}]]))}__listenEvents(){const{rect:t,editor:i,__eventIds:s}=this;s.push(t.on_([[e.PointerEvent.DOUBLE_TAP,this.onDoubleTap,this],[e.PointerEvent.LONG_PRESS,this.onLongPress,this]])),this.waitLeafer(()=>{s.push(i.app.on_([[[e.KeyEvent.HOLD,e.KeyEvent.UP],this.onKey,this],[e.KeyEvent.DOWN,this.onArrow,this],[[e.MoveEvent.START,e.MoveEvent.BEFORE_MOVE,e.MoveEvent.END],this.onMove,this,!0],[[e.ZoomEvent.START,e.ZoomEvent.BEFORE_ZOOM,e.ZoomEvent.END],this.onScale,this,!0],[[e.RotateEvent.START,e.RotateEvent.BEFORE_ROTATE,e.RotateEvent.END],this.onRotate,this,!0]]))})}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const F={x:0,y:0,width:1e5,height:1e5};class Z extends t.UI{constructor(t){super(),this.editor=t,this.hittable=!1,this.visible=0}__updateWorldBounds(){Object.assign(this.__local,F),Object.assign(this.__world,F)}__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 W='\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"/>',G={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${W}\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${W}\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${W}\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},U=new t.Bounds;function X(t){const{simulateTarget:e,list:i}=t,{zoomLayer:s}=i[0].leafer;e.safeChange(()=>{U.setListWithFn(i,t=>t.getBounds("box","page")),0===U.width&&(U.width=.1),0===U.height&&(U.height=.1),e.reset(U.get())}),s.add(e)}const Y=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),K=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),N={group(e,i,s){e.sort(K);const{app:o,parent:r}=e[0];let n;n=s&&s.add?s:new t.Group(s),r.addAt(n,r.children.indexOf(e[0])),e.sort(Y);const a=new t.Matrix(i.worldTransform);return a.divideParent(r.scrollWorldTransform),n.setTransform(a),n.editable=!0,n.hitChildren=!1,o.lockLayout(),e.forEach(t=>t.dropTo(n)),o.unlockLayout(),n},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach(t=>{if(t.isBranch){const{parent:e,children:s}=t;for(;s.length;)i.push(s[0]),s[0].dropTo(e,e.children.indexOf(t));t.isBranchLeaf?i.push(t):t.remove()}else i.push(t)}),e.unlockLayout(),i},toTop(t){t.sort(Y),t.forEach(t=>{t.parent&&t.parent.add(t)})},toBottom(t){t.sort(K),t.forEach(t=>{t.parent&&t.parent.addAt(t,0)})}},j=t.Debug.get("EditToolCreator");function q(){return t=>{J.register(t)}}const $=q,J={EditTool:"EditTool",LineEditTool:"LineEditTool",PointsEditTool:"PointsEditTool",list:{},register(t,e){const{tag:i}=t.prototype;e||(e=i),Q[e]&&j.repeat(e),Q[e]=t},get:(t,e)=>new Q[t](e)},{list:Q}=J;class tt extends o{constructor(t,e){super(t,e)}}tt.BEFORE_OPEN="innerEditor.before_open",tt.OPEN="innerEditor.open",tt.BEFORE_CLOSE="innerEditor.before_close",tt.CLOSE="innerEditor.close";class et extends o{constructor(t,e){super(t,e)}}et.BEFORE_GROUP="editor.before_group",et.GROUP="editor.group",et.BEFORE_UNGROUP="editor.before_ungroup",et.UNGROUP="editor.ungroup",et.BEFORE_OPEN="editor.before_open_group",et.OPEN="editor.open_group",et.BEFORE_CLOSE="editor.before_close_group",et.CLOSE="editor.close_group";const{updateMatrix:it}=t.LeafHelper,st={x:1,y:1,scaleX:1,scaleY:1,rotation:1,skewX:1,skewY:1},ot="top-left";class rt extends t.Rect{get __tag(){return"SimulateElement"}constructor(e){super(),this.checkChange=!0,this.canChange=!0,this.visible=this.hittable=!1,this.skipJSON=!0,this.on(t.PropertyEvent.CHANGE,i=>{if(this.checkChange&&st[i.attrName]){const{attrName:s,newValue:o,oldValue:r}=i,n="s"===s[0]?(o||1)/(r||1):(o||0)-(r||0);this.canChange=!1;const a=this.__;a[s]=r,it(this.parent),it(this);const h=new t.Matrix(this.__world);switch(a[s]=o,this.__layout.rotationChange(),it(this),this.changedTransform=new t.Matrix(this.__world).divide(h),s){case"x":e.move(n,0);break;case"y":e.move(0,n);break;case"rotation":e.rotateOf(ot,n);break;case"scaleX":e.scaleOf(ot,n,1);break;case"scaleY":e.scaleOf(ot,1,n);break;case"skewX":e.skewOf(ot,n,0);break;case"skewY":e.skewOf(ot,0,n)}this.canChange=!0}})}safeChange(t){this.canChange&&(this.checkChange=!1,t(),this.checkChange=!0)}}class nt extends o{constructor(t,e){super(t,e)}}nt.BEFORE_MOVE="editor.before_move",nt.MOVE="editor.move";class at extends o{constructor(t,e){super(t,e)}}at.BEFORE_SCALE="editor.before_scale",at.SCALE="editor.scale";class ht extends o{constructor(t,e){super(t,e)}}ht.BEFORE_ROTATE="editor.before_rotate",ht.ROTATE="editor.rotate";class lt extends o{constructor(t,e){super(t,e)}}lt.BEFORE_SKEW="editor.before_skew",lt.SKEW="editor.skew";class dt{onMove(i){const{target:s,mergeConfig:o,dragStartData:r}=this.editBox;let n,{dragLimitAnimate:a}=o;const h=i.type===e.MoveEvent.END||i.type===e.DragEvent.END,l=t.isString(s.draggable),d=!a||h||l,c={x:i.totalX,y:i.totalY};i instanceof e.MoveEvent&&t.PointHelper.move(c,s.getWorldPointByLocal(r.totalOffset,null,!0)),i.shiftKey&&(Math.abs(c.x)>Math.abs(c.y)?c.y=0:c.x=0),n=e.DragEvent.getValidMove(s,r.point,c,d),(n.x||n.y)&&(a&&!l&&h?t.LeafHelper.animateMove(this,n,t.isNumber(a)?a:.3):this.move(n))}onScale(i){const{target:s,mergeConfig:o,single:r,dragStartData:n}=this.editBox;let a,{around:h,lockRatio:l,flipable:d,editSize:c}=o;i instanceof e.ZoomEvent?(h||(h=s.getBoxPoint(i)),a=i.totalScale):a=i.getInnerTotal(s);const{direction:g}=i.current;(i.shiftKey||s.lockRatio)&&(l=!0);const u=C.getScaleData(s,n.bounds,g,a,l,C.getAround(h,i.altKey),d,!r||"scale"===c),f=s.x,p=s.y;i instanceof e.DragEvent&&this.editTool&&this.editTool.onScaleWithDrag?(u.drag=i,this.scaleWithDrag(u)):this.scaleOf(u.origin,u.scaleX,u.scaleY),t.PointHelper.move(n.totalOffset,s.x-f,s.y-p)}onRotate(i){const{target:s,mergeConfig:o,dragStartData:r}=this.editBox,{around:n,rotateAround:a,rotateGap:h,diagonalRotateKey:l}=o,{direction:d}=i.current;let c,g;if(i instanceof e.RotateEvent)g=i.rotation,c=a?t.AroundHelper.getPoint(a,s.boxBounds):s.getBoxPoint(i);else{const t=l?i.isHoldKeys(l):i.shiftKey,e=C.getRotateData(s,d,i,r,t?null:a||s.around||s.origin||n||"center");g=r.rotation+e.rotation-s.rotation,c=e.origin}if(g=t.MathHelper.float(t.MathHelper.getGapRotation(g,h,s.rotation),2),!g)return;const u=s.x,f=s.y;this.rotateOf(c,g),t.PointHelper.move(r.totalOffset,s.x-u,s.y-f)}onSkew(t){const{target:e,mergeConfig:i}=this.editBox,{around:s}=i,{origin:o,skewX:r,skewY:n}=C.getSkewData(e,t.current.direction,t.getInnerMove(e),C.getAround(s,t.altKey));(r||n)&&this.skewOf(o,r,n)}move(e,i=0){if(!this.checkTransform("moveable"))return;t.isObject(e)&&(i=e.y,e=e.x);const{target:s,mergeConfig:o,single:r,editor:n}=this.editBox,{beforeMove:a}=o;if(a){const o=a({target:s,x:e,y:i});if(t.isObject(o))e=o.x,i=o.y;else if(!1===o)return}const h=s.getWorldPointByLocal({x:e,y:i},null,!0);r||s.safeChange(()=>s.move(e,i));const l={target:s,editor:n,moveX:h.x,moveY:h.y};this.emitEvent(new nt(nt.BEFORE_MOVE,l));const d=new nt(nt.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 at(at.BEFORE_SCALE,t));const r=new at(at.SCALE,t);this.editTool.onScaleWithDrag(r),this.emitEvent(r)}scaleOf(e,i,s=i,o){if(!this.checkTransform("resizeable"))return;const{target:r,mergeConfig:n,single:a,editor:h}=this.editBox,{beforeScale:l}=n;if(l){const o=l({target:r,origin:e,scaleX:i,scaleY:s});if(t.isObject(o))i=o.scaleX,s=o.scaleY;else if(!1===o)return}const d=this.getWorldOrigin(e),c=!a&&this.getChangedTransform(()=>r.safeChange(()=>r.scaleOf(e,i,s))),g={target:r,editor:h,worldOrigin:d,scaleX:i,scaleY:s,transform:c};this.emitEvent(new at(at.BEFORE_SCALE,g));const u=new at(at.SCALE,g);this.doScale(u),this.emitEvent(u)}flip(e){if(!this.checkTransform("resizeable"))return;const{target:i,single:s,editor:o}=this.editBox,r=this.getWorldOrigin("center"),n=s?new t.Matrix(t.LeafHelper.getFlipTransform(i,e)):this.getChangedTransform(()=>i.safeChange(()=>i.flip(e))),a={target:i,editor:o,worldOrigin:r,scaleX:"x"===e?-1:1,scaleY:"y"===e?-1:1,transform:n};this.emitEvent(new at(at.BEFORE_SCALE,a));const h=new at(at.SCALE,a);this.doScale(h),this.emitEvent(h)}rotateOf(e,i){if(!this.checkTransform("rotateable"))return;const{target:s,mergeConfig:o,single:r,editor:n}=this.editBox,{beforeRotate:a}=o;if(a){const o=a({target:s,origin:e,rotation:i});if(t.isNumber(o))i=o;else if(!1===o)return}const h=this.getWorldOrigin(e),l=!r&&this.getChangedTransform(()=>s.safeChange(()=>s.rotateOf(e,i))),d={target:s,editor:n,worldOrigin:h,rotation:i,transform:l};this.emitEvent(new ht(ht.BEFORE_ROTATE,d));const c=new ht(ht.ROTATE,d);this.doRotate(c),this.emitEvent(c)}skewOf(e,i,s=0,o){if(!this.checkTransform("skewable"))return;const{target:r,mergeConfig:n,single:a,editor:h}=this.editBox,{beforeSkew:l}=n;if(l){const o=l({target:r,origin:e,skewX:i,skewY:s});if(t.isObject(o))i=o.skewX,s=o.skewY;else if(!1===o)return}const d=this.getWorldOrigin(e),c=!a&&this.getChangedTransform(()=>r.safeChange(()=>r.skewOf(e,i,s))),g={target:r,editor:h,worldOrigin:d,skewX:i,skewY:s,transform:c};this.emitEvent(new lt(lt.BEFORE_SKEW,g));const u=new lt(lt.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(e){const{target:i}=this.editBox;return i.getWorldPoint(t.LeafHelper.getInnerOrigin(i,e))}getChangedTransform(e){const{target:i,single:s}=this.editBox;if(!s&&!i.canChange)return i.changedTransform;const o=new t.Matrix(i.worldTransform);return e(),new t.Matrix(i.worldTransform).divide(o)}emitEvent(t,e){this.editBox.editor.emitEvent(t,e)}}exports.Editor=class extends t.Group{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(e,i){super(i),this.leafList=new t.LeafList,this.openedGroupList=new t.LeafList,this.simulateTarget=new rt(this),this.editBox=new z(this),this.editToolList={},this.selector=new v(this),this.editMask=new Z(this),this.targetEventIds=[];let s=t.DataHelper.clone(G);e&&(s=t.DataHelper.default(e,s)),this.mergedConfig=this.config=s,this.addMany(this.editMask,this.selector,this.editBox),t.Plugin.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(e,i="dim",s){if(!s){const{dimTarget:e,targetLeafer:i}=this;s=e?t.isArray(e)?e:[e]:[i]}s[0]&&s[0][i]!==(e||!1)&&s.forEach(s=>t.DataHelper.stintSet(s,i,e))}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&&X(this),this.update()}getEditTool(t){return this.editToolList[t]=this.editToolList[t]||J.get(t,this)}updateEditTool(){if(this.unloadEditTool(),this.editing){const e=this.element;let i=e.editOuter||"EditTool";const{beforeEditOuter:s}=this.mergeConfig;if(s){const o=s({target:e,name:i});if(t.isString(o))i=o;else if(!1===o)return}if(J.list[i]){const t=this.editTool=this.getEditTool(i);this.editBox.load(),t.editTarget=e,t.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(et.BEFORE_GROUP),this.target=N.group(this.list,this.element,t),this.emitGroupEvent(et.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach(t=>t.isBranch&&this.emitGroupEvent(et.BEFORE_UNGROUP,t)),this.target=N.ungroup(t),t.forEach(t=>t.isBranch&&this.emitGroupEvent(et.UNGROUP,t))),this.list}openGroup(t){this.emitGroupEvent(et.BEFORE_OPEN,t),this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(et.OPEN,t)}closeGroup(t){this.emitGroupEvent(et.BEFORE_CLOSE,t),this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(et.CLOSE,t)}checkOpenedGroups(){const e=this.openedGroupList;if(e.length){let{list:i}=e;this.editing&&(i=[],e.forEach(e=>this.list.every(i=>!t.LeafHelper.hasParent(i,e))&&i.push(e))),i.forEach(t=>this.closeGroup(t))}this.editing&&!this.selector.dragging&&this.checkDeepSelect()}checkDeepSelect(){let t,{list:e}=this;for(let i=0;i<e.length;i++)for(t=e[i].parent;t&&!t.hitChildren;)this.openGroup(t),t=t.parent}emitGroupEvent(t,e){const i=new et(t,{editTarget:e});this.emitEvent(i),e&&e.emitEvent(i)}getInnerEditor(t){return this.editToolList[t]=this.editToolList[t]||J.get(t,this)}openInnerEditor(e,i,s){let o;if(t.isString(i)?o=i:s||(s=i),e&&s&&(this.target=e),this.single){e||(e=this.element),o||(o=e.editInner);const{beforeEditInner:i}=this.mergeConfig;if(i){const s=i({target:e,name:o});if(t.isString(s))o=s;else if(!1===s)return}J.list[o]&&(this.unloadEditTool(!0),this.innerEditing=!0,this.innerEditor=this.getInnerEditor(o),this.innerEditor.editTarget=e,this.emitInnerEvent(tt.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(tt.OPEN))}}closeInnerEditor(t){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(tt.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(tt.CLOSE),t||this.updateEditTool(),this.innerEditor=this.innerEditor.editTarget=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,s=new tt(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&&(N.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(N.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:e,leafer:i,targetLeafer:s,editMask:o}=this;this.targetEventIds=[i.on_(t.RenderEvent.START,this.onRenderStart,this),s&&s.on_(t.PropertyEvent.SCROLL,this.onChildScroll,this),e.on_(t.RenderEvent.CHILD_START,this.onAppRenderStart,this),e.on_(t.LeaferEvent.UPDATE_MODE,t=>{t.mode&&"normal"!==t.mode&&this.cancel()})],o.visible&&o.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())}},i([(e,i)=>{t.defineKey(e,i,{get(){const{config:e,element:i,dragPoint:s,editBox:o,editTool:r,innerEditor:n,app:a}=this,h=Object.assign({},e);if(n?n.editConfig&&Object.assign(h,n.editConfig):r&&r.editConfig&&Object.assign(h,r.editConfig),i&&i.editConfig){let{editConfig:t}=i;(t.hover||t.hoverStyle||t.hoverPathType)&&(t=Object.assign({},t),delete t.hover,delete t.hoverStyle,delete t.hoverPathType),Object.assign(h,t)}return o.config&&Object.assign(h,o.config),s&&(s.editConfig&&Object.assign(h,s.editConfig),"font-size"===h.editSize&&(h.lockRatio=!0),"resize-rotate"===s.pointType&&(h.around||(h.around="center"),t.isNull(h.lockRatio)&&(h.lockRatio=!0))),t.isUndefined(h.dragLimitAnimate)&&(h.dragLimitAnimate=a&&a.config.pointer.dragLimitAnimate),this.mergedConfig=h}})}],exports.Editor.prototype,"mergeConfig",void 0),i([r(function(e,i){const{target:s}=e;s?(e.leafList=s instanceof t.LeafList?s:new t.LeafList(s),e.multiple&&X(e)):(e.simulateTarget.remove(),e.leafList.reset()),e.closeInnerEditor(!0),e.unloadEditTool();const r={editor:e,value:s,oldValue:i};e.emitEvent(new o(o.SELECT,r)),e.checkOpenedGroups(),e.editing?e.waitLeafer(()=>{e.updateEditTool(),e.listenTargetEvents()}):(e.updateEditTool(),e.removeTargetEvents()),e.emitEvent(new o(o.AFTER_SELECT,r))})],exports.Editor.prototype,"target",void 0),i([r(function(t,e){t.emitEvent(new o(o.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))})],exports.Editor.prototype,"hoverTarget",void 0),exports.Editor=i([e.useModule(dt,["editBox","editTool","emitEvent"])],exports.Editor);class ct{static registerInnerEditor(){J.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 t.Group,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)}}exports.EditTool=class extends ct{static registerEditTool(e,i){J.register(this,e),i&&t.defineKey(this.prototype,"tag",{get:()=>e})}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()}},exports.EditTool=i([q()],exports.EditTool);const{left:gt,right:ut}=t.Direction9,{move:ft,copy:pt,toNumberPoints:Et}=t.PointHelper;exports.LineEditTool=class extends exports.EditTool{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(e){const{drag:i,direction:s,lockRatio:o,around:r}=e,n=e.target,a=s===gt;if(n.pathInputed){const{path:t}=n.__,{from:e,to:s}=this.getFromToByPath(t);this.dragPoint(e,s,a,r,this.getInnerMove(n,i,o)),t[1]=e.x,t[2]=e.y,t[4]=s.x,t[5]=s.y,n.path=t}else if(n.points){const{points:t}=n,{from:e,to:s}=this.getFromToByPoints(t);this.dragPoint(e,s,a,r,this.getInnerMove(n,i,o)),t[0]=e.x,t[1]=e.y,t[2]=s.x,t[3]=s.y,n.points=t}else{const e=t.getPointData(),{toPoint:s}=n;n.rotation=0,this.dragPoint(e,s,a,r,this.getInnerMove(n,i,o)),n.getLocalPointByInner(e,null,null,!0),n.getLocalPointByInner(s,null,null,!0),n.x=e.x,n.y=e.y,n.getInnerPointByLocal(s,null,null,!0),n.toPoint=s}}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=Et(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?(ft(t,r,n),s&&ft(e,-r,-n)):(s&&ft(t,-r,-n),ft(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),pt(s[7],i),pt(e[7],i),pt(s[3],a),pt(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===gt||t===ut,s[t].visible=a,e[t].visible=!n&&a}},exports.LineEditTool=i([q()],exports.LineEditTool),t.Plugin.add("editor","resize"),t.Creator.editor=function(t,e){const i=new exports.Editor(t);return e&&e.sky.add(e.editor=i),i},t.Box.addAttr("textBox",!1,t.dataType),t.UI.addAttr("editConfig",void 0,t.dataType),t.UI.addAttr("editOuter",t=>{t.updateLayout();const{EditTool:e,LineEditTool:i,PointsEditTool:s}=J,o=t.pathInputed||t.isPointsMode?s:t.tag+"EditTool",r=J.list[o];return!t.__.__isLinePath||o==s&&r?r?o:e:i},t.dataType),t.UI.addAttr("editInner","PathEditor",t.dataType),t.Group.addAttr("editInner","",t.dataType),t.Text.addAttr("editInner","TextEditor",t.dataType),t.UI.setEditConfig=function(t){this.changeAttr("editConfig",t)},t.UI.setEditOuter=function(t){this.changeAttr("editOuter",t)},t.UI.setEditInner=function(t){this.changeAttr("editInner",t)},exports.EditBox=z,exports.EditDataHelper=C,exports.EditPoint=A,exports.EditSelect=v,exports.EditSelectHelper=f,exports.EditToolCreator=J,exports.EditorEvent=o,exports.EditorGroupEvent=et,exports.EditorHelper=N,exports.EditorMoveEvent=nt,exports.EditorRotateEvent=ht,exports.EditorScaleEvent=at,exports.EditorSkewEvent=lt,exports.InnerEditor=ct,exports.InnerEditorEvent=tt,exports.SelectArea=u,exports.Stroker=g,exports.TransformTool=dt,exports.registerEditTool=q,exports.registerInnerEditor=$;
1
+ "use strict";var t=require("@leafer-ui/draw"),e=require("@leafer-ui/core");function i(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 s(e){return e?t.isArray(e)?e:[e]:[]}require("@leafer-in/resize"),"function"==typeof SuppressedError&&SuppressedError;class o extends t.Event{get list(){return s(this.value)}get oldList(){return s(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}o.BEFORE_SELECT="editor.before_select",o.SELECT="editor.select",o.AFTER_SELECT="editor.after_select",o.BEFORE_HOVER="editor.before_hover",o.HOVER="editor.hover";const r=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),n=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),a={group(e,i,s){e.sort(n);const{app:o,parent:a}=e[0];let h;h=s&&s.add?s:new t.Group(s),a.addAt(h,a.children.indexOf(e[0])),e.sort(r);const l=new t.Matrix(i.worldTransform);return l.divideParent(a.scrollWorldTransform),h.setTransform(l),h.editable=!0,h.hitChildren=!1,o.lockLayout(),e.forEach(t=>t.dropTo(h)),o.unlockLayout(),h},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(r),t.forEach(t=>{t.parent&&t.parent.add(t)})},toBottom(t){t.sort(n),t.forEach(t=>{t.parent&&t.parent.addAt(t,0)})},mergeMaskConfig(t,e){},getSiblingMaskElements(t){}};function h(e){return(i,s)=>{const r="_"+s;t.defineKey(i,s,{get(){return this[r]},set(i){const n=this[r];if(n!==i){const a=this;if(a.config){const e="target"===s;if(e){const{beforeSelect:e}=a.config;if(e){const s=e({target:i});if(t.isObject(s))i=s;else if(!1===s)return}a.hasDimOthers&&a.cancelDimOthers(),t.isArray(i)&&i.length>1&&i[0].locked&&i.splice(0,1),a.single&&(delete a.element.syncEventer,delete a.element.__world.ignorePixelSnap)}const r=e?o.BEFORE_SELECT:o.BEFORE_HOVER;this.hasEvent(r)&&this.emitEvent(new o(r,{editor:a,value:i,oldValue:n}))}this[r]=i,e(this,n)}}})}}const{abs:l}=Math,{copy:d}=t.MatrixHelper,{setListWithFn:g}=t.BoundsHelper,{worldBounds:c}=t.LeafBoundsHelper,u=t.getMatrixData(),f=t.getBoundsData();class p extends t.UI{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?(g(f,e,c),t&&this.set(t),this.set(f),this.visible=!0):this.visible=0}__draw(e,i){const{list:s}=this;if(s.length){let o;const r=this.__,{stroke:n,strokeWidth:a,fill:h}=r,{bounds:g}=i;for(let c=0;c<s.length;c++){o=s[c];const{worldTransform:f,worldRenderBounds:p}=o;if(p.width&&p.height&&(!g||g.hit(p,i.matrix))){const s=l(f.scaleX),g=l(f.scaleY);switch(d(u,f),u.half=a%2,e.setWorld(u,i.matrix),e.beginPath(),this.strokePathType){case"box":const{boxBounds:t}=o.__layout;e.rect(t.x,t.y,t.width,t.height);break;case"stroke":const{strokeBounds:i}=o.__layout;e.rect(i.x,i.y,i.width,i.height);break;case"path":o.__drawPath(e);break;default:o.__.__useArrow?o.__drawPath(e):o.__.__pathForRender?o.__drawRenderPath(e):o.__drawPathByBox(e)}if(r.strokeWidth=a/Math.max(s,g),r.shadow){const i=r.shadow[0],{scaleX:s,scaleY:o}=this.getRenderScaleData(!0,i.scaleFixed);e.save(),e.setWorldShadow(i.x*s,i.y*o,i.blur*s,t.ColorConvert.string(i.color))}n&&(t.isString(n)?t.Paint.stroke(n,this,e,i):t.Paint.strokes(n,this,e,i)),h&&(t.isString(h)?t.Paint.fill(h,this,e,i):t.Paint.fills(h,this,e,i)),r.shadow&&e.restore()}}r.strokeWidth=a}}destroy(){this.target=null,super.destroy()}}i([h(function(e){const i=e.target;e.list=i?t.isArray(i)?i:[i]:[]})],p.prototype,"target",void 0),i([t.surfaceType("render-path")],p.prototype,"strokePathType",void 0);class E extends t.Group{constructor(e){super(e),this.strokeArea=new t.Rect({strokeAlign:"center"}),this.fillArea=new t.Rect,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 m={findOne:t=>t.list.find(t=>t.editable),findByBounds(t,e){const i=[];return v([t],i,e),i}};function v(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&&v(s.children,e,i)}}const{findOne:b,findByBounds:y}=m;class w extends t.Group{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(e){super(),this.hoverStroker=new p,this.targetStroker=new p,this.bounds=new t.Bounds,this.selectArea=new E,this.__eventIds=[],this.editor=e,this.addMany(this.targetStroker,this.hoverStroker,this.selectArea),this.__listenEvents()}onHover(){const{editor:t}=this;if(!this.running||this.dragging||t.dragging)this.hoverStroker.target=null;else{const{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=a.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(e){if(!e.multiTouch){if(this.editor.dragging)return this.onDragEnd(e);if(this.dragging){const{editor:i}=this,s=e.getInnerTotal(this),o=this.bounds.clone().unsign(),r=new t.LeafList(y(i.app,o));if(this.bounds.width=s.x,this.bounds.height=s.y,this.selectArea.setBounds(o.get()),r.length){const t=[];this.originList.forEach(e=>{r.has(e)||t.push(e)}),r.forEach(e=>{this.originList.has(e)||t.push(e)}),(t.length!==i.list.length||i.list.some((e,i)=>e!==t[i]))&&(i.target=t)}else i.target=this.originList.list}}}onDragEnd(t){t.multiTouch||this.dragging&&(this.originList=null,this.selectArea.visible=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)&&!b(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(e){const i={exclude:new t.LeafList(this.editor.editBox.rect)};return b(e.target.leafer.interaction.findPath(e,i))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):b(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:i}=t;i.selector.proxy=t,this.__eventIds=[t.on_([[o.HOVER,this.onHover,this],[o.SELECT,this.onSelect,this]]),i.on_([[e.PointerEvent.MOVE,this.onPointerMove,this],[e.PointerEvent.BEFORE_DOWN,this.onBeforeDown,this],[e.PointerEvent.TAP,this.onTap,this],[e.DragEvent.START,this.onDragStart,this,!0],[e.DragEvent.DRAG,this.onDrag,this],[e.DragEvent.END,this.onDragEnd,this],[e.MoveEvent.MOVE,this.onAutoMove,this],[[e.ZoomEvent.ZOOM,e.MoveEvent.MOVE],()=>{this.editor.hoverTarget=null}]])]})}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=this.originList=this.needRemoveItem=null,this.__removeListenEvents(),super.destroy()}}const{topLeft:x,top:L,topRight:T,right:k,bottomRight:S,bottom:O,bottomLeft:_,left:M}=t.Direction9,{toPoint:B}=t.AroundHelper,{within:C,sign:P}=t.MathHelper,{abs:R}=Math,H={getScaleData(i,s,o,r,n,a,h,l){let d,g,c={},u=1,f=1;const{widthRange:p,heightRange:E,dragBounds:m,worldTransform:v,boxBounds:b}=i,{width:y,height:w}=s,H=R(v.scaleX),D=R(v.scaleY),A=i.scaleX/s.scaleX,I=i.scaleY/s.scaleY,V=P(A),z=P(I),W=l?A:V*b.width/y,F=l?I:z*b.height/w;if(t.isNumber(r))u=f=Math.sqrt(r);else{a&&(r.x*=2,r.y*=2),r.x*=l?A:V,r.y*=l?I:z;const t=(-r.y+w)/w,e=(r.x+y)/y,i=(r.y+w)/w,s=(-r.x+y)/y;switch(o){case L:f=t,d="bottom";break;case k:u=e,d="left";break;case O:f=i,d="top";break;case M:u=s,d="right";break;case x:f=t,u=s,d="bottom-right";break;case T:f=t,u=e,d="bottom-left";break;case S:f=i,u=e,d="top-left";break;case _:f=i,u=s,d="top-right"}if(n)if("corner"===n&&o%2)n=!1;else switch(o){case L:case O:u=f;break;case M:case k:f=u;break;default:g=Math.sqrt(R(u*f)),u=P(u)*g,f=P(f)*g}}const Z=1!==u,G=1!==f;if(Z&&(u/=W),G&&(f/=F),h||(u<0&&(u=1/b.width/H),f<0&&(f=1/b.height/D)),B(a||d,b,c,!0),m){const t={x:u,y:f};e.DragBoundsHelper.limitScaleOf(i,c,t,n),u=t.x,f=t.y}if(Z&&p){const t=b.width*i.scaleX;u=C(t*u,p)/t}if(G&&E){const t=b.height*i.scaleY;f=C(t*f,E)/t}const U=H*b.width,X=D*b.height;return Z&&R(u*U)<1&&(u=1*P(u)/U),G&&R(f*X)<1&&(f=1*P(f)/X),n&&u!==f&&(g=Math.min(R(u),R(f)),u=P(u)*g,f=P(f)*g),isFinite(u)||(u=1),isFinite(f)||(f=1),{origin:c,scaleX:u,scaleY:f,direction:o,lockRatio:n,around:a}},getRotateData(e,i,s,o,r){let n,a={};switch(i){case x:n="bottom-right";break;case T:n="bottom-left";break;case S:n="top-left";break;case _:n="top-right";break;default:n="center"}return B(r||n,e.boxBounds,a,!0),{origin:a,rotation:t.PointHelper.getRotation(o,e.getWorldPointByBox(a),s)}},getSkewData(e,i,s,o){let r,n,a={},h=0,l=0;switch(i){case L:case x:n={x:.5,y:0},r="bottom",h=1;break;case O:case S:n={x:.5,y:1},r="top",h=1;break;case M:case _:n={x:0,y:.5},r="right",l=1;break;case k:case T:n={x:1,y:.5},r="left",l=1}const{boxBounds:d}=e,{width:g,height:c}=d;n.x=n.x*g,n.y=n.y*c,B(o||r,d,a,!0);const u=t.PointHelper.getRotation(n,a,{x:n.x+(h?s.x:0),y:n.y+(l?s.y:0)});return h?h=-u:l=u,{origin:a,skewX:h,skewY:l}},getAround:(t,e)=>e&&!t?"center":t,getRotateDirection:(t,e,i=8)=>((t=(t+Math.round(e/(360/i)))%i)<0&&(t+=i),t),getFlipDirection(t,e,i){if(e)switch(t){case M:t=k;break;case x:t=T;break;case _:t=S;break;case k:t=M;break;case T:t=x;break;case S:t=_}if(i)switch(t){case L:t=O;break;case x:t=_;break;case T:t=S;break;case O:t=L;break;case _:t=x;break;case S:t=T}return t}},D={};function A(e,i){const{enterPoint:s,dragging:o,skewing:r,resizing:n,flippedX:a,flippedY:h}=e;if(!s||!e.editor.editing||!e.canUse)return;if("rect"===s.name)return I(e);if("circle"===s.name)return;let{rotation:l}=e;const{pointType:d}=s,{moveCursor:g,resizeCursor:c,rotateCursor:u,skewCursor:f,moveable:p,resizeable:E,rotateable:m,skewable:v}=e.mergeConfig;if("move"===d)return s.cursor=g,void(p||(s.visible=!1));if("button"===d)return void(s.cursor||(s.cursor="pointer"));let b=d.includes("resize");b&&m&&(e.isHoldRotateKey(i)||!E)&&(b=!1);const y=v&&!b&&("resize-line"===s.name||"skew"===d),w=o?r?f:n?c:u:y?f:b?c:u;l+=45*(H.getFlipDirection(s.direction,a,h)+1),l=2*Math.round(t.MathHelper.formatRotation(l,!0)/2);const{url:x,x:L,y:T}=w,k=x+l;D[k]?s.cursor=D[k]:D[k]=s.cursor={url:V(x,l),x:L,y:T}}function I(t){const{moveCursor:e,moveable:i}=t.mergeConfig;t.canUse&&(t.rect.cursor=i?e:void 0)}function V(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class z extends t.Box{constructor(t){super(t),this.useFastShadow=!0}}const W=["top","right","bottom","left"],F=void 0,Z=t.Debug.get("EditBox");class G extends t.Group{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:e,resizeable:i,rotateable:s}=this.mergeConfig;return t.isString(e)||t.isString(i)||t.isString(s)}get canDragLimitAnimate(){return this.moving&&this.mergeConfig.dragLimitAnimate&&this.target.dragBounds}constructor(e){super(),this.view=new t.Group,this.rect=new z({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new z({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new t.Group({around:"center",hitSelf:!1,visible:0}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.dragStartData={},this.__eventIds=[],this.widgets=[],this.editor=e,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 z({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),r.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new z({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),n.push(e),this.listenPointEvents(e,"resize",s)),i=new z({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:e,mergeConfig:i,single:s,rect:o,circle:r,resizePoints:n,resizeLines:a}=this,{stroke:h,strokeWidth:l,ignorePixelSnap:d}=i,g=this.getPointsStyle(),c=this.getMiddlePointsStyle(),u=this.getResizeLinesStyle();let f;this.visible=!e.locked;for(let t=0;t<8;t++)f=n[t],f.children.length&&f.clear(),f.set(this.getPointStyle(t%2?c[(t-1)/2%c.length]:g[t/2%g.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(i.circle||i.rotatePoint||g[0])),o.set(Object.assign({stroke:h,strokeWidth:l,opacity:1,editConfig:F},i.rect||{}));const p=t.isNull(i.rectThrough)?s:i.rectThrough;o.hittable=!p,p&&(e.syncEventer=o,this.app.interaction.bottomList=[{target:o,proxy:e}]),s&&t.DataHelper.stintSet(e.__world,"ignorePixelSnap",d),I(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(e){const{editor:i,target:s,mergeConfig:o,single:r,rect:n,circle:a,buttons:h,resizePoints:l,rotatePoints:d,resizeLines:g}=this,{editMask:c}=i,{middlePoint:u,resizeable:f,rotateable:p,hideOnSmall:E,editBox:m,editBoxType:v,mask:b,dimOthers:y,bright:w,spread:x,hideRotatePoints:L,hideResizeLines:T}=o;if("stroke"===v){const{scaleX:i,scaleY:o}=s.worldTransform,{strokeBoxSpread:r}=s.__layout;r&&t.BoundsHelper.spread(e,[r*Math.abs(o),r*Math.abs(i)])}if(x&&t.BoundsHelper.spread(e,x),this.rectBounds=e,c.visible=!!b||0,t.isUndefined(y)&&t.isUndefined(w)?i.hasDimOthers&&i.cancelDimOthers():(i.setDimOthers(y),i.setBright(!!y||w),i.hasDimOthers=!0),this.view.worldOpacity){const{width:i,height:s}=e,c=t.isNumber(E)?E:10,v=this.showPoints=m&&!(E&&i<c&&s<c);let b,y,w,x={};for(let o=0;o<8;o++)t.AroundHelper.toPoint(t.AroundHelper.directionData[o],e,x),y=l[o],b=d[o],y.set(x),b.set(x),y.visible=v&&!(!f&&!p),b.visible=v&&p&&f&&!L,o%2&&(w=g[(o-1)/2],w.set(x),w.visible=y.visible&&!T,y.visible&&(y.visible=!!u),b.visible&&(b.visible=!!u),(o+1)/2%2?(w.width=i+w.height,E&&2*y.width>i&&(y.visible=!1)):(w.width=s+w.height,E&&2*y.width>s&&(y.visible=!1)));a.visible=v&&p&&!(!o.circle&&!o.rotatePoint),a.visible&&this.layoutCircle(),n.path&&(n.path=null),n.set(Object.assign(Object.assign({},e),{visible:!r||m})),h.visible=v&&h.children.length>0||0,h.visible&&this.layoutButtons()}else n.set(e)}layoutCircle(){const{circleDirection:t,circleMargin:e,buttonsMargin:i,buttonsDirection:s,middlePoint:o}=this.mergedConfig,r=W.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=W.indexOf(e);(a%2&&r||(a+1)%2&&n)&&i&&(a=(a+2)%4);const h=i?H.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:F};return t?Object.assign(n,t):n}getPointsStyle(){const{point:e}=this.mergedConfig;return t.isArray(e)?e:[e]}getMiddlePointsStyle(){const{middlePoint:e}=this.mergedConfig;return t.isArray(e)?e:e?[e]:this.getPointsStyle()}getResizeLinesStyle(){const{resizeLine:e}=this.mergedConfig;return t.isArray(e)?e:[e]}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)}A(this,t)}onDragEnd(t){this.onTransformEnd(t),this.dragPoint=null}onTransformStart(e){const{hideOnMove:i}=this.mergedConfig;(this.moving||this.gesturing)&&(this.editor.opacity=i?0:1),this.resizing&&(t.ResizeEvent.resizingKeys=this.editor.leafList.keys);const{dragStartData:s,target:o}=this;s.x=e.x,s.y=e.y,s.totalOffset=t.getPointData(),s.point={x:o.x,y:o.y},s.bounds=Object.assign({},o.getLayoutBounds("box","local")),s.rotation=o.rotation}onTransformEnd(i){this.canDragLimitAnimate&&(i instanceof e.DragEvent||i instanceof e.MoveEvent)&&this.transformTool.onMove(i),this.resizing&&(t.ResizeEvent.resizingKeys=null),this.dragging=this.gesturing=this.moving=this.resizing=this.rotating=this.skewing=!1,this.editor.opacity=1,this.editor.update()}onMove(i){if(this.canGesture&&"drag"!==i.moveType&&(i.stop(),t.isString(this.mergedConfig.moveable)))switch(this.gesturing=this.moving=!0,i.type){case e.MoveEvent.START:this.onTransformStart(i);break;case e.MoveEvent.END:this.onTransformEnd(i);break;default:this.transformTool.onMove(i)}}onScale(i){if(this.canGesture&&(i.stop(),t.isString(this.mergedConfig.resizeable)))switch(this.gesturing=this.resizing=!0,i.type){case e.ZoomEvent.START:this.onTransformStart(i);break;case e.ZoomEvent.END:this.onTransformEnd(i);break;default:this.transformTool.onScale(i)}}onRotate(i){if(this.canGesture&&(i.stop(),t.isString(this.mergedConfig.rotateable)))switch(this.gesturing=this.rotating=!0,i.type){case e.ZoomEvent.START:this.onTransformStart(i);break;case e.ZoomEvent.END:this.onTransformEnd(i);break;default:this.transformTool.onRotate(i)}}isHoldRotateKey(t){const{rotateKey:e}=this.mergedConfig;return e?t.isHoldKeys(e):t.metaKey||t.ctrlKey}onKey(t){A(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(e){const{editor:i,target:s}=this;if(this.single){if(s.locked)return;if(s.isBranch&&!s.editInner){if(s.textBox){const{children:e}=s,o=e.find(e=>e.editable&&e instanceof t.Text)||e.find(e=>e instanceof t.Text);if(o)return i.openInnerEditor(o)}i.openGroup(s),i.target=i.selector.findDeepOne(e)}else i.openInnerEditor()}}listenPointEvents(t,i,s){t.direction=s,t.pointType=i,this.__eventIds.push(t.on_([[e.DragEvent.START,this.onDragStart,this],[e.DragEvent.DRAG,this.onDrag,this],[e.DragEvent.END,this.onDragEnd,this],[e.PointerEvent.ENTER,e=>{this.enterPoint=t,A(this,e)}],[e.PointerEvent.LEAVE,()=>{this.enterPoint=null}]]))}__listenEvents(){const{rect:t,editor:i,__eventIds:s}=this;s.push(t.on_([[e.PointerEvent.DOUBLE_TAP,this.onDoubleTap,this],[e.PointerEvent.LONG_PRESS,this.onLongPress,this]])),this.waitLeafer(()=>{s.push(i.app.on_([[[e.KeyEvent.HOLD,e.KeyEvent.UP],this.onKey,this],[e.KeyEvent.DOWN,this.onArrow,this],[[e.MoveEvent.START,e.MoveEvent.BEFORE_MOVE,e.MoveEvent.END],this.onMove,this,!0],[[e.ZoomEvent.START,e.ZoomEvent.BEFORE_ZOOM,e.ZoomEvent.END],this.onScale,this,!0],[[e.RotateEvent.START,e.RotateEvent.BEFORE_ROTATE,e.RotateEvent.END],this.onRotate,this,!0]]))})}__removeListenEvents(){this.off_(this.__eventIds)}static registerWidget(t){const{tag:e}=t.prototype;G.WidgetList[e]&&Z.repeat(e),G.WidgetList[e]=t}createWidgets(){Object.values(G.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()}}G.WidgetList={};const U={x:0,y:0,width:1e5,height:1e5};class X extends t.UI{constructor(t){super(),this.editor=t,this.hittable=!1,this.visible=0}__updateWorldBounds(){Object.assign(this.__local,U),Object.assign(this.__world,U)}__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 Y='\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"/>',K={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${Y}\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${Y}\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${Y}\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},j=new t.Bounds;function N(t){const{simulateTarget:e,list:i}=t,{zoomLayer:s}=i[0].leafer;e.safeChange(()=>{j.setListWithFn(i,t=>t.getBounds("box","page")),0===j.width&&(j.width=.1),0===j.height&&(j.height=.1),e.reset(j.get())}),s.add(e)}const q=t.Debug.get("EditToolCreator");function $(){return t=>{Q.register(t)}}const J=$,Q={EditTool:"EditTool",LineEditTool:"LineEditTool",PointsEditTool:"PointsEditTool",list:{},register(t,e){const{tag:i}=t.prototype;e||(e=i),tt[e]&&q.repeat(e),tt[e]=t},get:(t,e)=>new tt[t](e)},{list:tt}=Q;class et extends o{constructor(t,e){super(t,e)}}et.BEFORE_OPEN="innerEditor.before_open",et.OPEN="innerEditor.open",et.BEFORE_CLOSE="innerEditor.before_close",et.CLOSE="innerEditor.close";class it extends o{constructor(t,e){super(t,e)}}it.BEFORE_GROUP="editor.before_group",it.GROUP="editor.group",it.BEFORE_UNGROUP="editor.before_ungroup",it.UNGROUP="editor.ungroup",it.BEFORE_OPEN="editor.before_open_group",it.OPEN="editor.open_group",it.BEFORE_CLOSE="editor.before_close_group",it.CLOSE="editor.close_group";const{updateMatrix:st}=t.LeafHelper,ot={x:1,y:1,scaleX:1,scaleY:1,rotation:1,skewX:1,skewY:1},rt="top-left";class nt extends t.Rect{get __tag(){return"SimulateElement"}constructor(e){super(),this.checkChange=!0,this.canChange=!0,this.visible=this.hittable=!1,this.skipJSON=!0,this.on(t.PropertyEvent.CHANGE,i=>{if(this.checkChange&&ot[i.attrName]){const{attrName:s,newValue:o,oldValue:r}=i,n="s"===s[0]?(o||1)/(r||1):(o||0)-(r||0);this.canChange=!1;const a=this.__;a[s]=r,st(this.parent),st(this);const h=new t.Matrix(this.__world);switch(a[s]=o,this.__layout.rotationChange(),st(this),this.changedTransform=new t.Matrix(this.__world).divide(h),s){case"x":e.move(n,0);break;case"y":e.move(0,n);break;case"rotation":e.rotateOf(rt,n);break;case"scaleX":e.scaleOf(rt,n,1);break;case"scaleY":e.scaleOf(rt,1,n);break;case"skewX":e.skewOf(rt,n,0);break;case"skewY":e.skewOf(rt,0,n)}this.canChange=!0}})}safeChange(t){this.canChange&&(this.checkChange=!1,t(),this.checkChange=!0)}}class at extends o{constructor(t,e){super(t,e)}}at.BEFORE_MOVE="editor.before_move",at.MOVE="editor.move";class ht extends o{constructor(t,e){super(t,e)}}ht.BEFORE_SCALE="editor.before_scale",ht.SCALE="editor.scale";class lt extends o{constructor(t,e){super(t,e)}}lt.BEFORE_ROTATE="editor.before_rotate",lt.ROTATE="editor.rotate";class dt extends o{constructor(t,e){super(t,e)}}dt.BEFORE_SKEW="editor.before_skew",dt.SKEW="editor.skew";class gt{onMove(i){const{target:s,mergeConfig:o,dragStartData:r}=this.editBox;let n,{dragLimitAnimate:a}=o;const h=i.type===e.MoveEvent.END||i.type===e.DragEvent.END,l=t.isString(s.draggable),d=!a||h||l,g={x:i.totalX,y:i.totalY};i instanceof e.MoveEvent&&t.PointHelper.move(g,s.getWorldPointByLocal(r.totalOffset,null,!0)),i.shiftKey&&(Math.abs(g.x)>Math.abs(g.y)?g.y=0:g.x=0),n=e.DragEvent.getValidMove(s,r.point,g,d),(n.x||n.y)&&(a&&!l&&h?t.LeafHelper.animateMove(this,n,t.isNumber(a)?a:.3):this.move(n))}onScale(i){const{target:s,mergeConfig:o,single:r,dragStartData:n}=this.editBox;let a,{around:h,lockRatio:l,flipable:d,editSize:g}=o;i instanceof e.ZoomEvent?(h||(h=s.getBoxPoint(i)),a=i.totalScale):a=i.getInnerTotal(s);const{direction:c}=i.current;(i.shiftKey||s.lockRatio)&&(l=!0);const u=H.getScaleData(s,n.bounds,c,a,l,H.getAround(h,i.altKey),d,!r||"scale"===g),f=s.x,p=s.y;i instanceof e.DragEvent&&this.editTool&&this.editTool.onScaleWithDrag?(u.drag=i,this.scaleWithDrag(u)):this.scaleOf(u.origin,u.scaleX,u.scaleY),t.PointHelper.move(n.totalOffset,s.x-f,s.y-p)}onRotate(i){const{target:s,mergeConfig:o,dragStartData:r}=this.editBox,{around:n,rotateAround:a,rotateGap:h,diagonalRotateKey:l}=o,{direction:d}=i.current;let g,c;if(i instanceof e.RotateEvent)c=i.rotation,g=a?t.AroundHelper.getPoint(a,s.boxBounds):s.getBoxPoint(i);else{const t=l?i.isHoldKeys(l):i.shiftKey,e=H.getRotateData(s,d,i,r,t?null:a||s.around||s.origin||n||"center");c=r.rotation+e.rotation-s.rotation,g=e.origin}if(c=t.MathHelper.float(t.MathHelper.getGapRotation(c,h,s.rotation),2),!c)return;const u=s.x,f=s.y;this.rotateOf(g,c),t.PointHelper.move(r.totalOffset,s.x-u,s.y-f)}onSkew(t){const{target:e,mergeConfig:i}=this.editBox,{around:s}=i,{origin:o,skewX:r,skewY:n}=H.getSkewData(e,t.current.direction,t.getInnerMove(e),H.getAround(s,t.altKey));(r||n)&&this.skewOf(o,r,n)}move(e,i=0){if(!this.checkTransform("moveable"))return;t.isObject(e)&&(i=e.y,e=e.x);const{target:s,mergeConfig:o,single:r,editor:n}=this.editBox,{beforeMove:a}=o;if(a){const o=a({target:s,x:e,y:i});if(t.isObject(o))e=o.x,i=o.y;else if(!1===o)return}const h=s.getWorldPointByLocal({x:e,y:i},null,!0);r||s.safeChange(()=>s.move(e,i));const l={target:s,editor:n,moveX:h.x,moveY:h.y};this.emitEvent(new at(at.BEFORE_MOVE,l));const d=new at(at.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 ht(ht.BEFORE_SCALE,t));const r=new ht(ht.SCALE,t);this.editTool.onScaleWithDrag(r),this.emitEvent(r)}scaleOf(e,i,s=i,o){if(!this.checkTransform("resizeable"))return;const{target:r,mergeConfig:n,single:a,editor:h}=this.editBox,{beforeScale:l}=n;if(l){const o=l({target:r,origin:e,scaleX:i,scaleY:s});if(t.isObject(o))i=o.scaleX,s=o.scaleY;else if(!1===o)return}const d=this.getWorldOrigin(e),g=!a&&this.getChangedTransform(()=>r.safeChange(()=>r.scaleOf(e,i,s))),c={target:r,editor:h,worldOrigin:d,scaleX:i,scaleY:s,transform:g};this.emitEvent(new ht(ht.BEFORE_SCALE,c));const u=new ht(ht.SCALE,c);this.doScale(u),this.emitEvent(u)}flip(e){if(!this.checkTransform("resizeable"))return;const{target:i,single:s,editor:o}=this.editBox,r=this.getWorldOrigin("center"),n=s?new t.Matrix(t.LeafHelper.getFlipTransform(i,e)):this.getChangedTransform(()=>i.safeChange(()=>i.flip(e))),a={target:i,editor:o,worldOrigin:r,scaleX:"x"===e?-1:1,scaleY:"y"===e?-1:1,transform:n};this.emitEvent(new ht(ht.BEFORE_SCALE,a));const h=new ht(ht.SCALE,a);this.doScale(h),this.emitEvent(h)}rotateOf(e,i){if(!this.checkTransform("rotateable"))return;const{target:s,mergeConfig:o,single:r,editor:n}=this.editBox,{beforeRotate:a}=o;if(a){const o=a({target:s,origin:e,rotation:i});if(t.isNumber(o))i=o;else if(!1===o)return}const h=this.getWorldOrigin(e),l=!r&&this.getChangedTransform(()=>s.safeChange(()=>s.rotateOf(e,i))),d={target:s,editor:n,worldOrigin:h,rotation:i,transform:l};this.emitEvent(new lt(lt.BEFORE_ROTATE,d));const g=new lt(lt.ROTATE,d);this.doRotate(g),this.emitEvent(g)}skewOf(e,i,s=0,o){if(!this.checkTransform("skewable"))return;const{target:r,mergeConfig:n,single:a,editor:h}=this.editBox,{beforeSkew:l}=n;if(l){const o=l({target:r,origin:e,skewX:i,skewY:s});if(t.isObject(o))i=o.skewX,s=o.skewY;else if(!1===o)return}const d=this.getWorldOrigin(e),g=!a&&this.getChangedTransform(()=>r.safeChange(()=>r.skewOf(e,i,s))),c={target:r,editor:h,worldOrigin:d,skewX:i,skewY:s,transform:g};this.emitEvent(new dt(dt.BEFORE_SKEW,c));const u=new dt(dt.SKEW,c);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(e){const{target:i}=this.editBox;return i.getWorldPoint(t.LeafHelper.getInnerOrigin(i,e))}getChangedTransform(e){const{target:i,single:s}=this.editBox;if(!s&&!i.canChange)return i.changedTransform;const o=new t.Matrix(i.worldTransform);return e(),new t.Matrix(i.worldTransform).divide(o)}emitEvent(t,e){this.editBox.editor.emitEvent(t,e)}}exports.Editor=class extends t.Group{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(e,i){super(i),this.leafList=new t.LeafList,this.openedGroupList=new t.LeafList,this.simulateTarget=new nt(this),this.editBox=new G(this),this.editToolList={},this.selector=new w(this),this.editMask=new X(this),this.targetEventIds=[];let s=t.DataHelper.clone(K);e&&(s=t.DataHelper.default(e,s)),this.mergedConfig=this.config=s,this.addMany(this.editMask,this.selector,this.editBox),t.Plugin.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(e,i="dim",s){if(!s){const{dimTarget:e,targetLeafer:i}=this;s=e?t.isArray(e)?e:[e]:[i]}s[0]&&s[0][i]!==(e||!1)&&s.forEach(s=>t.DataHelper.stintSet(s,i,e))}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&&N(this),this.update()}getEditTool(t){return this.editToolList[t]=this.editToolList[t]||Q.get(t,this)}updateEditTool(){if(this.unloadEditTool(),this.editing){const e=this.element;let i=e.editOuter||"EditTool";const{beforeEditOuter:s}=this.mergeConfig;if(s){const o=s({target:e,name:i});if(t.isString(o))i=o;else if(!1===o)return}if(Q.list[i]){const t=this.editTool=this.getEditTool(i);this.editBox.load(),t.editTarget=e,t.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(it.BEFORE_GROUP),this.target=a.group(this.list,this.element,t),this.emitGroupEvent(it.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach(t=>t.isBranch&&this.emitGroupEvent(it.BEFORE_UNGROUP,t)),this.target=a.ungroup(t),t.forEach(t=>t.isBranch&&this.emitGroupEvent(it.UNGROUP,t))),this.list}openGroup(t){this.emitGroupEvent(it.BEFORE_OPEN,t),this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(it.OPEN,t)}closeGroup(t){this.emitGroupEvent(it.BEFORE_CLOSE,t),this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(it.CLOSE,t)}checkOpenedGroups(){const e=this.openedGroupList;if(e.length){let{list:i}=e;this.editing&&(i=[],e.forEach(e=>this.list.every(i=>!t.LeafHelper.hasParent(i,e))&&i.push(e))),i.forEach(t=>this.closeGroup(t))}this.editing&&!this.selector.dragging&&this.checkDeepSelect()}checkDeepSelect(){let t,{list:e}=this;for(let i=0;i<e.length;i++)for(t=e[i].parent;t&&!t.hitChildren;)this.openGroup(t),t=t.parent}emitGroupEvent(t,e){const i=new it(t,{editTarget:e});this.emitEvent(i),e&&e.emitEvent(i)}getInnerEditor(t){return this.editToolList[t]=this.editToolList[t]||Q.get(t,this)}openInnerEditor(e,i,s){let o;if(t.isString(i)?o=i:s||(s=i),e&&s&&(this.target=e),this.single){e||(e=this.element),o||(o=e.editInner);const{beforeEditInner:i}=this.mergeConfig;if(i){const s=i({target:e,name:o});if(t.isString(s))o=s;else if(!1===s)return}Q.list[o]&&(this.unloadEditTool(!0),this.innerEditing=!0,this.innerEditor=this.getInnerEditor(o),this.innerEditor.editTarget=e,this.emitInnerEvent(et.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(et.OPEN))}}closeInnerEditor(t){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(et.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(et.CLOSE),t||this.updateEditTool(),this.innerEditor=this.innerEditor.editTarget=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,s=new et(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&&(a.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(a.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:e,leafer:i,targetLeafer:s,editMask:o}=this;this.targetEventIds=[i.on_(t.RenderEvent.START,this.onRenderStart,this),s&&s.on_(t.PropertyEvent.SCROLL,this.onChildScroll,this),e.on_(t.RenderEvent.CHILD_START,this.onAppRenderStart,this),e.on_(t.LeaferEvent.UPDATE_MODE,t=>{t.mode&&"normal"!==t.mode&&this.cancel()})],o.visible&&o.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())}},i([(e,i)=>{t.defineKey(e,i,{get(){const{config:e,element:i,dragPoint:s,editBox:o,editTool:r,innerEditor:n,app:h}=this,l=Object.assign({},e);if(n?n.editConfig&&Object.assign(l,n.editConfig):r&&r.editConfig&&Object.assign(l,r.editConfig),i&&i.mask&&a.mergeMaskConfig(l,this),i&&i.editConfig){let{editConfig:t}=i;(t.hover||t.hoverStyle||t.hoverPathType)&&(t=Object.assign({},t),delete t.hover,delete t.hoverStyle,delete t.hoverPathType),Object.assign(l,t)}return o.config&&Object.assign(l,o.config),s&&(s.editConfig&&Object.assign(l,s.editConfig),"font-size"===l.editSize&&(l.lockRatio=!0),"resize-rotate"===s.pointType&&(l.around||(l.around="center"),t.isNull(l.lockRatio)&&(l.lockRatio=!0))),t.isUndefined(l.dragLimitAnimate)&&(l.dragLimitAnimate=h&&h.config.pointer.dragLimitAnimate),this.mergedConfig=l}})}],exports.Editor.prototype,"mergeConfig",void 0),i([h(function(e,i){const{target:s}=e;s?(e.leafList=s instanceof t.LeafList?s:new t.LeafList(s),e.multiple&&N(e)):(e.simulateTarget.remove(),e.leafList.reset()),e.closeInnerEditor(!0),e.unloadEditTool();const r={editor:e,value:s,oldValue:i};e.emitEvent(new o(o.SELECT,r)),e.checkOpenedGroups(),e.editing?e.waitLeafer(()=>{e.updateEditTool(),e.listenTargetEvents()}):(e.updateEditTool(),e.removeTargetEvents()),e.emitEvent(new o(o.AFTER_SELECT,r))})],exports.Editor.prototype,"target",void 0),i([h(function(t,e){t.emitEvent(new o(o.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))})],exports.Editor.prototype,"hoverTarget",void 0),exports.Editor=i([e.useModule(gt,["editBox","editTool","emitEvent"])],exports.Editor);const{abs:ct}=Math,{scale:ut}=t.PointHelper;class ft{static registerInnerEditor(){Q.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 ut(i,ct(s),ct(o)),i}getEditTargetPoint(t,e){const i=e?t:{x:t.x,y:t.y},{scaleX:s,scaleY:o}=this.editTarget.worldTransform;return ut(i,Math.abs(1/s),ct(1/o)),i}onCreate(){}create(){this.view=new t.Group,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)}}exports.EditTool=class extends ft{static registerEditTool(e,i){Q.register(this,e),i&&t.defineKey(this.prototype,"tag",{get:()=>e})}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()}},exports.EditTool=i([$()],exports.EditTool);const{left:pt,right:Et}=t.Direction9,{move:mt,copy:vt,toNumberPoints:bt}=t.PointHelper;exports.LineEditTool=class extends exports.EditTool{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(e){const{drag:i,direction:s,lockRatio:o,around:r}=e,n=e.target,a=s===pt;if(n.pathInputed){const{path:t}=n.__,{from:e,to:s}=this.getFromToByPath(t);this.dragPoint(e,s,a,r,this.getInnerMove(n,i,o)),t[1]=e.x,t[2]=e.y,t[4]=s.x,t[5]=s.y,n.path=t}else if(n.points){const{points:t}=n,{from:e,to:s}=this.getFromToByPoints(t);this.dragPoint(e,s,a,r,this.getInnerMove(n,i,o)),t[0]=e.x,t[1]=e.y,t[2]=s.x,t[3]=s.y,n.points=t}else{const e=t.getPointData(),{toPoint:s}=n;n.rotation=0,this.dragPoint(e,s,a,r,this.getInnerMove(n,i,o)),n.getLocalPointByInner(e,null,null,!0),n.getLocalPointByInner(s,null,null,!0),n.x=e.x,n.y=e.y,n.getInnerPointByLocal(s,null,null,!0),n.toPoint=s}}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=bt(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?(mt(t,r,n),s&&mt(e,-r,-n)):(s&&mt(t,-r,-n),mt(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),vt(s[7],i),vt(e[7],i),vt(s[3],a),vt(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===pt||t===Et,s[t].visible=a,e[t].visible=!n&&a}},exports.LineEditTool=i([$()],exports.LineEditTool),t.Plugin.add("editor","resize"),t.Creator.editor=function(t,e){const i=new exports.Editor(t);return e&&e.sky.add(e.editor=i),i},t.Box.addAttr("textBox",!1,t.dataType),t.UI.addAttr("editConfig",void 0,t.dataType),t.UI.addAttr("editOuter",t=>{t.updateLayout();const{EditTool:e,LineEditTool:i,PointsEditTool:s}=Q,o=t.pathInputed||t.isPointsMode?s:t.tag+"EditTool",r=Q.list[o];return!t.__.__isLinePath||o==s&&r?r?o:e:i},t.dataType),t.UI.addAttr("editInner","PathEditor",t.dataType),t.Group.addAttr("editInner","",t.dataType),t.Text.addAttr("editInner","TextEditor",t.dataType),t.UI.setEditConfig=function(t){this.changeAttr("editConfig",t)},t.UI.setEditOuter=function(t){this.changeAttr("editOuter",t)},t.UI.setEditInner=function(t){this.changeAttr("editInner",t)},exports.EditBox=G,exports.EditDataHelper=H,exports.EditPoint=z,exports.EditSelect=w,exports.EditSelectHelper=m,exports.EditToolCreator=Q,exports.EditorEvent=o,exports.EditorGroupEvent=it,exports.EditorHelper=a,exports.EditorMoveEvent=at,exports.EditorRotateEvent=lt,exports.EditorScaleEvent=ht,exports.EditorSkewEvent=dt,exports.InnerEditor=ft,exports.InnerEditorEvent=et,exports.SelectArea=E,exports.Stroker=p,exports.TransformTool=gt,exports.editToolMergeConfigAttr=function(){return(e,i)=>{t.defineKey(e,i,{get(){const e=this,{config:i,userConfig:s,configKeepKeys:o}=e,r=i?t.DataHelper.clone(i):{};if(o)for(let t in s)o.includes(t)||(r[t]=s[t]);return e.preMergedConfig&&e.preMergedConfig(r),o&&o.forEach(t=>{s[t]&&Object.assign(r[t],s[t])}),e.mergedConfig=r}})}},exports.registerEditTool=$,exports.registerInnerEditor=J;
2
2
  //# sourceMappingURL=editor.min.cjs.map