@leafer-in/editor 1.0.0-rc.25 → 1.0.0-rc.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,183 +1,7 @@
1
- import { PathCommandMap, MatrixHelper, Leaf, Text, Path, Line, Polygon, Group, Box, Event, defineKey, UI, Paint, Rect, Answer, Bounds, LeafList, PointHelper, AroundHelper, Direction9, MathHelper, Matrix, Debug, DataHelper, LeafHelper, RenderEvent, getPointData, Creator } from '@leafer-ui/draw';
1
+ export * from '@leafer-in/resize';
2
+ import { Event, defineKey, MatrixHelper, UI, Paint, Group, Rect, Answer, Bounds, LeafList, PointHelper, AroundHelper, Direction9, MathHelper, Box, Matrix, Debug, DataHelper, LeafHelper, RenderEvent, getPointData, Creator } from '@leafer-ui/draw';
2
3
  import { PointerEvent, DragEvent, MoveEvent, ZoomEvent, RotateEvent, KeyEvent } from '@leafer-ui/core';
3
4
 
4
- const { M, L, C, Q, Z, N, D, X, G, F, O, P, U } = PathCommandMap;
5
- const PathScaler = {
6
- scale(data, scaleX, scaleY) {
7
- if (!data)
8
- return;
9
- let command;
10
- let i = 0, len = data.length;
11
- while (i < len) {
12
- command = data[i];
13
- switch (command) {
14
- case M:
15
- scalePoints(data, scaleX, scaleY, i, 1);
16
- i += 3;
17
- break;
18
- case L:
19
- scalePoints(data, scaleX, scaleY, i, 1);
20
- i += 3;
21
- break;
22
- case C:
23
- scalePoints(data, scaleX, scaleY, i, 3);
24
- i += 7;
25
- break;
26
- case Q:
27
- scalePoints(data, scaleX, scaleY, i, 2);
28
- i += 5;
29
- break;
30
- case Z:
31
- i += 1;
32
- break;
33
- case N:
34
- scalePoints(data, scaleX, scaleY, i, 2);
35
- i += 5;
36
- break;
37
- case D:
38
- scalePoints(data, scaleX, scaleY, i, 2);
39
- i += 9;
40
- break;
41
- case X:
42
- scalePoints(data, scaleX, scaleY, i, 2);
43
- i += 6;
44
- break;
45
- case G:
46
- scalePoints(data, scaleX, scaleY, i, 2);
47
- i += 9;
48
- break;
49
- case F:
50
- scalePoints(data, scaleX, scaleY, i, 2);
51
- i += 5;
52
- break;
53
- case O:
54
- data[i] = G;
55
- data.splice(i + 4, 0, data[i + 3], 0);
56
- scalePoints(data, scaleX, scaleY, i, 2);
57
- i += 7 + 2;
58
- len += 2;
59
- break;
60
- case P:
61
- data[i] = F;
62
- data.splice(i + 4, 0, data[i + 3]);
63
- scalePoints(data, scaleX, scaleY, i, 2);
64
- i += 4 + 1;
65
- len += 1;
66
- break;
67
- case U:
68
- scalePoints(data, scaleX, scaleY, i, 2);
69
- i += 6;
70
- break;
71
- }
72
- }
73
- },
74
- scalePoints(data, scaleX, scaleY, start, pointCount) {
75
- for (let i = pointCount ? start + 1 : 0, end = pointCount ? i + pointCount * 2 : data.length; i < end; i += 2) {
76
- data[i] *= scaleX;
77
- data[i + 1] *= scaleY;
78
- }
79
- }
80
- };
81
- const { scalePoints } = PathScaler;
82
-
83
- const matrix$1 = MatrixHelper.get();
84
- function scaleResize(leaf, scaleX, scaleY) {
85
- if (leaf.pathInputed) {
86
- scaleResizePath(leaf, scaleX, scaleY);
87
- }
88
- else {
89
- leaf.width *= scaleX;
90
- leaf.height *= scaleY;
91
- }
92
- }
93
- function scaleResizeFont(leaf, scaleX, scaleY) {
94
- if (scaleX !== 1)
95
- leaf.fontSize *= scaleX;
96
- else if (scaleY !== 1)
97
- leaf.fontSize *= scaleY;
98
- }
99
- function scaleResizePath(leaf, scaleX, scaleY) {
100
- PathScaler.scale(leaf.__.path, scaleX, scaleY);
101
- leaf.path = leaf.__.path;
102
- }
103
- function scaleResizePoints(leaf, scaleX, scaleY) {
104
- PathScaler.scalePoints(leaf.__.points, scaleX, scaleY);
105
- leaf.points = leaf.__.points;
106
- }
107
- function scaleResizeGroup(group, scaleX, scaleY) {
108
- const { children } = group;
109
- for (let i = 0; i < children.length; i++) {
110
- matrix$1.a = scaleX;
111
- matrix$1.d = scaleY;
112
- children[i].transform(matrix$1, true);
113
- }
114
- }
115
-
116
- Leaf.prototype.scaleResize = function (scaleX, scaleY = scaleX, noResize) {
117
- const data = this;
118
- if (noResize) {
119
- data.scaleX *= scaleX;
120
- data.scaleY *= scaleY;
121
- }
122
- else {
123
- if (scaleX < 0)
124
- data.scaleX *= -1, scaleX = -scaleX;
125
- if (scaleY < 0)
126
- data.scaleY *= -1, scaleY = -scaleY;
127
- this.__scaleResize(scaleX, scaleY);
128
- }
129
- };
130
- Leaf.prototype.__scaleResize = function (scaleX, scaleY) {
131
- scaleResize(this, scaleX, scaleY);
132
- };
133
- Text.prototype.__scaleResize = function (scaleX, scaleY) {
134
- if (this.editConfig && this.editConfig.editSize === 'font-size') {
135
- scaleResizeFont(this, scaleX, scaleY);
136
- }
137
- else {
138
- scaleResize(this, scaleX, scaleY);
139
- }
140
- };
141
- Path.prototype.__scaleResize = function (scaleX, scaleY) {
142
- scaleResizePath(this, scaleX, scaleY);
143
- };
144
- Line.prototype.__scaleResize = function (scaleX, scaleY) {
145
- if (this.pathInputed) {
146
- scaleResizePath(this, scaleX, scaleY);
147
- }
148
- else if (this.points) {
149
- scaleResizePoints(this, scaleX, scaleY);
150
- }
151
- else {
152
- const point = this.toPoint;
153
- point.x *= scaleX;
154
- point.y *= scaleY;
155
- this.toPoint = point;
156
- }
157
- };
158
- Polygon.prototype.__scaleResize = function (scaleX, scaleY) {
159
- if (this.pathInputed) {
160
- scaleResizePath(this, scaleX, scaleY);
161
- }
162
- else if (this.points) {
163
- scaleResizePoints(this, scaleX, scaleY);
164
- }
165
- else {
166
- scaleResize(this, scaleX, scaleY);
167
- }
168
- };
169
- Group.prototype.__scaleResize = function (scaleX, scaleY) {
170
- scaleResizeGroup(this, scaleX, scaleY);
171
- };
172
- Box.prototype.__scaleResize = function (scaleX, scaleY) {
173
- if (this.__.__autoSize && this.children.length) {
174
- scaleResizeGroup(this, scaleX, scaleY);
175
- }
176
- else {
177
- scaleResize(this, scaleX, scaleY);
178
- }
179
- };
180
-
181
5
  /******************************************************************************
182
6
  Copyright (c) Microsoft Corporation.
183
7
 
@@ -803,6 +627,7 @@ class EditBox extends Group {
803
627
  this.editor = editor;
804
628
  this.visible = false;
805
629
  this.create();
630
+ this.rect.syncEventer = editor;
806
631
  this.__listenEvents();
807
632
  }
808
633
  create() {
@@ -845,9 +670,9 @@ class EditBox extends Group {
845
670
  rect.hittable = !single && moveable;
846
671
  element.syncEventer = (single && moveable) ? rect : null;
847
672
  this.app.interaction.bottomList = (single && moveable) ? [{ target: rect, proxy: element }] : null;
848
- this.visible = !element.locked;
849
673
  }
850
674
  update(bounds) {
675
+ this.visible = !this.editor.element.locked;
851
676
  if (this.view.worldOpacity) {
852
677
  const { mergeConfig } = this.editor;
853
678
  const { width, height } = bounds;
@@ -864,7 +689,7 @@ class EditBox extends Group {
864
689
  resizeP.set(point);
865
690
  rotateP.set(point);
866
691
  resizeL.set(point);
867
- resizeP.visible = resizeL.visible = showPoints && (resizeable || rotateable);
692
+ resizeP.visible = resizeL.visible = showPoints && !!(resizeable || rotateable);
868
693
  rotateP.visible = showPoints && rotateable && resizeable && !mergeConfig.rotatePoint;
869
694
  if (i % 2) {
870
695
  resizeP.visible = rotateP.visible = showPoints && !!middlePoint;
@@ -1026,6 +851,8 @@ class EditBox extends Group {
1026
851
  rect.on_(DragEvent.START, this.onDragStart, this),
1027
852
  rect.on_(DragEvent.DRAG, editor.onMove, editor),
1028
853
  rect.on_(DragEvent.END, this.onDragEnd, this),
854
+ rect.on_(ZoomEvent.BEFORE_ZOOM, editor.onScale, editor, true),
855
+ rect.on_(RotateEvent.BEFORE_ROTATE, editor.onRotate, editor, true),
1029
856
  rect.on_(PointerEvent.ENTER, () => updateMoveCursor(editor)),
1030
857
  rect.on_(PointerEvent.DOUBLE_TAP, this.onDoubleTap, this),
1031
858
  rect.on_(PointerEvent.LONG_PRESS, this.onLongPress, this)
@@ -1237,6 +1064,27 @@ const EditToolCreator = {
1237
1064
  };
1238
1065
  const { list } = EditToolCreator;
1239
1066
 
1067
+ class InnerEditorEvent extends EditorEvent {
1068
+ constructor(type, data) {
1069
+ super(type, data);
1070
+ }
1071
+ }
1072
+ InnerEditorEvent.BEFORE_OPEN = 'innerEditor.before_open';
1073
+ InnerEditorEvent.OPEN = 'innerEditor.open';
1074
+ InnerEditorEvent.BEFORE_CLOSE = 'innerEditor.before_close';
1075
+ InnerEditorEvent.CLOSE = 'innerEditor.close';
1076
+
1077
+ class EditorGroupEvent extends EditorEvent {
1078
+ constructor(type, data) {
1079
+ super(type, data);
1080
+ }
1081
+ }
1082
+ EditorGroupEvent.GROUP = 'editor.group';
1083
+ EditorGroupEvent.BEFORE_UNGROUP = 'editor.before_ungroup';
1084
+ EditorGroupEvent.UNGROUP = 'editor.ungroup';
1085
+ EditorGroupEvent.OPEN = 'editor.open_group';
1086
+ EditorGroupEvent.CLOSE = 'editor.close_group';
1087
+
1240
1088
  class Editor extends Group {
1241
1089
  get list() { return this.leafList.list; }
1242
1090
  get editing() { return !!this.list.length; }
@@ -1320,17 +1168,25 @@ class Editor extends Group {
1320
1168
  }
1321
1169
  onScale(e) {
1322
1170
  const { element } = this;
1323
- const { direction } = e.current;
1324
- let { around, lockRatio } = this.mergeConfig;
1325
- if (e.shiftKey)
1326
- lockRatio = true;
1327
- const data = EditDataHelper.getScaleData(element.boxBounds, direction, e.getInnerMove(element), lockRatio, EditDataHelper.getAround(around, e.altKey));
1328
- if (this.editTool.onScaleWithDrag) {
1329
- data.drag = e;
1330
- this.scaleWithDrag(data);
1171
+ if (e instanceof ZoomEvent) {
1172
+ if (this.mergeConfig.resizeable === 'zoom') {
1173
+ e.stop();
1174
+ this.scaleOf(element.getInnerPoint(e), e.scale, e.scale);
1175
+ }
1331
1176
  }
1332
1177
  else {
1333
- this.scaleOf(data.origin, data.scaleX, data.scaleY);
1178
+ const { direction } = e.current;
1179
+ let { around, lockRatio } = this.mergeConfig;
1180
+ if (e.shiftKey || element.lockRatio)
1181
+ lockRatio = true;
1182
+ const data = EditDataHelper.getScaleData(element.boxBounds, direction, e.getInnerMove(element), lockRatio, EditDataHelper.getAround(around, e.altKey));
1183
+ if (this.editTool.onScaleWithDrag) {
1184
+ data.drag = e;
1185
+ this.scaleWithDrag(data);
1186
+ }
1187
+ else {
1188
+ this.scaleOf(data.origin, data.scaleX, data.scaleY);
1189
+ }
1334
1190
  }
1335
1191
  }
1336
1192
  onRotate(e) {
@@ -1341,7 +1197,12 @@ class Editor extends Group {
1341
1197
  const { element } = this;
1342
1198
  let origin, rotation;
1343
1199
  if (e instanceof RotateEvent) {
1344
- rotation = e.rotation, origin = element.getInnerPoint(e);
1200
+ if (this.mergeConfig.rotateable === 'rotate') {
1201
+ e.stop();
1202
+ rotation = e.rotation, origin = element.getInnerPoint(e);
1203
+ }
1204
+ else
1205
+ return;
1345
1206
  }
1346
1207
  else {
1347
1208
  const last = { x: e.x - e.moveX, y: e.y - e.moveY };
@@ -1376,6 +1237,8 @@ class Editor extends Group {
1376
1237
  element.move(x, y);
1377
1238
  }
1378
1239
  scaleWithDrag(data) {
1240
+ if (!this.mergeConfig.resizeable || this.element.locked)
1241
+ return;
1379
1242
  const { element } = this;
1380
1243
  const worldOrigin = element.getWorldPoint(data.origin);
1381
1244
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, Object.assign(Object.assign({}, data), { target: element, editor: this, worldOrigin }));
@@ -1383,8 +1246,10 @@ class Editor extends Group {
1383
1246
  this.emitEvent(event);
1384
1247
  }
1385
1248
  scaleOf(origin, scaleX, scaleY = scaleX, _resize) {
1249
+ if (!this.mergeConfig.resizeable || this.element.locked)
1250
+ return;
1386
1251
  const { element } = this;
1387
- const worldOrigin = element.getWorldPoint(origin);
1252
+ const worldOrigin = element.getWorldPoint(LeafHelper.getInnerOrigin(element, origin));
1388
1253
  let transform;
1389
1254
  if (this.multiple) {
1390
1255
  const oldMatrix = new Matrix(element.worldTransform);
@@ -1396,8 +1261,10 @@ class Editor extends Group {
1396
1261
  this.emitEvent(event);
1397
1262
  }
1398
1263
  rotateOf(origin, rotation) {
1264
+ if (!this.mergeConfig.rotateable || this.element.locked)
1265
+ return;
1399
1266
  const { element } = this;
1400
- const worldOrigin = element.getWorldPoint(origin);
1267
+ const worldOrigin = element.getWorldPoint(LeafHelper.getInnerOrigin(element, origin));
1401
1268
  let transform;
1402
1269
  if (this.multiple) {
1403
1270
  const oldMatrix = new Matrix(element.worldTransform);
@@ -1409,8 +1276,10 @@ class Editor extends Group {
1409
1276
  this.emitEvent(event);
1410
1277
  }
1411
1278
  skewOf(origin, skewX, skewY = 0, _resize) {
1279
+ if (!this.mergeConfig.skewable || this.element.locked)
1280
+ return;
1412
1281
  const { element } = this;
1413
- const worldOrigin = element.getWorldPoint(origin);
1282
+ const worldOrigin = element.getWorldPoint(LeafHelper.getInnerOrigin(element, origin));
1414
1283
  let transform;
1415
1284
  if (this.multiple) {
1416
1285
  const oldMatrix = new Matrix(element.worldTransform);
@@ -1424,22 +1293,30 @@ class Editor extends Group {
1424
1293
  this.emitEvent(event);
1425
1294
  }
1426
1295
  group(userGroup) {
1427
- if (this.multiple)
1296
+ if (this.multiple) {
1428
1297
  this.target = EditorHelper.group(this.list, this.element, userGroup);
1298
+ this.emitGroupEvent(EditorGroupEvent.GROUP, this.target);
1299
+ }
1429
1300
  return this.target;
1430
1301
  }
1431
1302
  ungroup() {
1432
- if (this.list.length)
1433
- this.target = EditorHelper.ungroup(this.list);
1303
+ const { list } = this;
1304
+ if (list.length) {
1305
+ list.forEach(item => item.isBranch && this.emitGroupEvent(EditorGroupEvent.BEFORE_UNGROUP, item));
1306
+ this.target = EditorHelper.ungroup(list);
1307
+ list.forEach(item => item.isBranch && this.emitGroupEvent(EditorGroupEvent.UNGROUP, item));
1308
+ }
1434
1309
  return this.list;
1435
1310
  }
1436
1311
  openGroup(group) {
1437
1312
  this.openedGroupList.add(group);
1438
1313
  group.hitChildren = true;
1314
+ this.emitGroupEvent(EditorGroupEvent.OPEN, group);
1439
1315
  }
1440
1316
  closeGroup(group) {
1441
1317
  this.openedGroupList.remove(group);
1442
1318
  group.hitChildren = false;
1319
+ this.emitGroupEvent(EditorGroupEvent.CLOSE, group);
1443
1320
  }
1444
1321
  checkOpenedGroups() {
1445
1322
  const opened = this.openedGroupList;
@@ -1449,28 +1326,58 @@ class Editor extends Group {
1449
1326
  list = [], opened.forEach(item => this.list.every(leaf => !LeafHelper.hasParent(leaf, item)) && list.push(item));
1450
1327
  list.forEach(item => this.closeGroup(item));
1451
1328
  }
1329
+ if (this.editing && !this.selector.dragging)
1330
+ this.checkDeepSelect();
1331
+ }
1332
+ checkDeepSelect() {
1333
+ let parent, { list } = this;
1334
+ for (let i = 0; i < list.length; i++) {
1335
+ parent = list[i].parent;
1336
+ while (parent && !parent.hitChildren) {
1337
+ this.openGroup(parent);
1338
+ parent = parent.parent;
1339
+ }
1340
+ }
1452
1341
  }
1453
- openInnerEditor() {
1342
+ emitGroupEvent(type, group) {
1343
+ const event = new EditorGroupEvent(type, { editTarget: group });
1344
+ this.emitEvent(event);
1345
+ group.emitEvent(event);
1346
+ }
1347
+ openInnerEditor(target) {
1348
+ if (target)
1349
+ this.target = target;
1454
1350
  if (this.single) {
1455
- const tag = this.element.editInner;
1456
- if (tag) {
1457
- if (EditToolCreator.list[tag]) {
1458
- this.editTool.unload();
1459
- this.innerEditing = true;
1460
- this.innerEditor = this.editToolList[tag] || EditToolCreator.get(tag, this);
1461
- this.innerEditor.load();
1462
- }
1351
+ const editTarget = this.element;
1352
+ const tag = editTarget.editInner;
1353
+ if (tag && EditToolCreator.list[tag]) {
1354
+ this.editTool.unload();
1355
+ this.innerEditing = true;
1356
+ this.innerEditor = this.editToolList[tag] || EditToolCreator.get(tag, this);
1357
+ this.innerEditor.editTarget = editTarget;
1358
+ this.emitInnerEvent(InnerEditorEvent.BEFORE_OPEN);
1359
+ this.innerEditor.load();
1360
+ this.emitInnerEvent(InnerEditorEvent.OPEN);
1463
1361
  }
1464
1362
  }
1465
1363
  }
1466
1364
  closeInnerEditor() {
1467
1365
  if (this.innerEditing) {
1468
1366
  this.innerEditing = false;
1367
+ this.emitInnerEvent(InnerEditorEvent.BEFORE_CLOSE);
1469
1368
  this.innerEditor.unload();
1369
+ this.emitInnerEvent(InnerEditorEvent.CLOSE);
1470
1370
  this.editTool.load();
1471
1371
  this.innerEditor = null;
1472
1372
  }
1473
1373
  }
1374
+ emitInnerEvent(type) {
1375
+ const { innerEditor } = this;
1376
+ const { editTarget } = innerEditor;
1377
+ const event = new InnerEditorEvent(type, { editTarget, innerEditor });
1378
+ this.emitEvent(event);
1379
+ editTarget.emitEvent(event);
1380
+ }
1474
1381
  lock() {
1475
1382
  this.list.forEach(leaf => leaf.locked = true);
1476
1383
  this.update();
@@ -1775,4 +1682,4 @@ UI.setEditInner = function (editorName) {
1775
1682
  });
1776
1683
  };
1777
1684
 
1778
- export { EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, InnerEditor, LineEditTool, PathScaler, SelectArea, Stroker, registerEditTool, registerInnerEditor, scaleResize, scaleResizeFont, scaleResizeGroup, scaleResizePath, scaleResizePoints };
1685
+ export { EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, InnerEditor, InnerEditorEvent, LineEditTool, SelectArea, Stroker, registerEditTool, registerInnerEditor };
@@ -1 +1 @@
1
- import{PathCommandMap as t,MatrixHelper as e,Leaf as i,Text as s,Path as o,Line as n,Polygon as r,Group as a,Box as h,Event as l,defineKey as d,UI as c,Paint as g,Rect as u,Answer as f,Bounds as p,LeafList as m,PointHelper as v,AroundHelper as y,Direction9 as b,MathHelper as w,Matrix as L,Debug as _,DataHelper as k,LeafHelper as x,RenderEvent as E,getPointData as M,Creator as S}from"@leafer-ui/draw";import{PointerEvent as T,DragEvent as V,MoveEvent as P,ZoomEvent as O,RotateEvent as H,KeyEvent as I}from"@leafer-ui/core";const{M:C,L:B,C:R,Q:D,Z:A,N:Z,D:z,X:W,G:X,F:Y,O:F,P:U,U:G}=t,j={scale(t,e,i){if(!t)return;let s,o=0,n=t.length;for(;o<n;)switch(s=t[o],s){case C:case B:K(t,e,i,o,1),o+=3;break;case R:K(t,e,i,o,3),o+=7;break;case D:K(t,e,i,o,2),o+=5;break;case A:o+=1;break;case Z:K(t,e,i,o,2),o+=5;break;case z:K(t,e,i,o,2),o+=9;break;case W:K(t,e,i,o,2),o+=6;break;case X:K(t,e,i,o,2),o+=9;break;case Y:K(t,e,i,o,2),o+=5;break;case F:t[o]=X,t.splice(o+4,0,t[o+3],0),K(t,e,i,o,2),o+=9,n+=2;break;case U:t[o]=Y,t.splice(o+4,0,t[o+3]),K(t,e,i,o,2),o+=5,n+=1;break;case G:K(t,e,i,o,2),o+=6}},scalePoints(t,e,i,s,o){for(let n=o?s+1:0,r=o?n+2*o:t.length;n<r;n+=2)t[n]*=e,t[n+1]*=i}},{scalePoints:K}=j,N=e.get();function $(t,e,i){t.pathInputed?Q(t,e,i):(t.width*=e,t.height*=i)}function q(t,e,i){1!==e?t.fontSize*=e:1!==i&&(t.fontSize*=i)}function Q(t,e,i){j.scale(t.__.path,e,i),t.path=t.__.path}function J(t,e,i){j.scalePoints(t.__.points,e,i),t.points=t.__.points}function tt(t,e,i){const{children:s}=t;for(let t=0;t<s.length;t++)N.a=e,N.d=i,s[t].transform(N,!0)}function et(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(n<3?o(r):n>3?o(e,i,r):o(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}function it(t){return t?t instanceof Array?t:[t]:[]}i.prototype.scaleResize=function(t,e=t,i){const s=this;i?(s.scaleX*=t,s.scaleY*=e):(t<0&&(s.scaleX*=-1,t=-t),e<0&&(s.scaleY*=-1,e=-e),this.__scaleResize(t,e))},i.prototype.__scaleResize=function(t,e){$(this,t,e)},s.prototype.__scaleResize=function(t,e){this.editConfig&&"font-size"===this.editConfig.editSize?q(this,t,e):$(this,t,e)},o.prototype.__scaleResize=function(t,e){Q(this,t,e)},n.prototype.__scaleResize=function(t,e){if(this.pathInputed)Q(this,t,e);else if(this.points)J(this,t,e);else{const i=this.toPoint;i.x*=t,i.y*=e,this.toPoint=i}},r.prototype.__scaleResize=function(t,e){this.pathInputed?Q(this,t,e):this.points?J(this,t,e):$(this,t,e)},a.prototype.__scaleResize=function(t,e){tt(this,t,e)},h.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?tt(this,t,e):$(this,t,e)},"function"==typeof SuppressedError&&SuppressedError;class st extends l{get list(){return it(this.value)}get oldList(){return it(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}st.SELECT="editor.select",st.HOVER="editor.hover";class ot extends st{constructor(t,e){super(t,e)}}ot.MOVE="editor.move";class nt extends st{constructor(t,e){super(t,e)}}nt.SCALE="editor.scale";class rt extends st{constructor(t,e){super(t,e)}}rt.ROTATE="editor.rotate";class at extends st{constructor(t,e){super(t,e)}}function ht(t){return(e,i)=>{const s="_"+i;d(e,i,{get(){return this[s]},set(e){const i=this[s];i!==e&&(this[s]=e,t(this,i))}})}}at.SKEW="editor.skew";const lt=e.get(),{abs:dt}=Math,{copy:ct,scale:gt}=e;class ut extends c{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){this.set(e),this.target=t}__draw(t,e){const{list:i}=this;if(i.length){let s;const{stroke:o,strokeWidth:n,fill:r}=this.__,{bounds:a}=e;for(let h=0;h<i.length;h++)if(s=i[h],a&&a.hit(s.__world,e.matrix)){const i=dt(s.__world.scaleX),a=dt(s.__world.scaleY);if(i!==a){ct(lt,s.__world),gt(lt,1/i,1/a),t.setWorld(lt,e.matrix),t.beginPath(),this.__.strokeWidth=n;const{x:o,y:r,width:h,height:l}=s.__layout.boxBounds;t.rect(o*i,r*a,h*i,l*a)}else t.setWorld(s.__world,e.matrix),t.beginPath(),s.__.__useArrow?s.__drawPath(t):s.__.__pathForRender?s.__drawRenderPath(t):s.__drawPathByBox(t),this.__.strokeWidth=n/dt(s.__world.scaleX);o&&("string"==typeof o?g.stroke(o,this,t):g.strokes(o,this,t)),r&&("string"==typeof r?g.fill(r,this,t):g.fills(r,this,t))}this.__.strokeWidth=n}}destroy(){this.target=null,super.destroy()}}et([ht((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],ut.prototype,"target",void 0);class ft extends a{constructor(t){super(t),this.strokeArea=new u({strokeAlign:"center"}),this.fillArea=new u,this.visible=this.hittable=!1,this.addMany(this.fillArea,this.strokeArea)}setStyle(t,e){const{visible:i,stroke:s,strokeWidth:o}=t;this.visible=i,this.strokeArea.reset(Object.assign({stroke:s,strokeWidth:o},e||{})),this.fillArea.reset({visible:!e,fill:s,opacity:.2})}setBounds(t){this.strokeArea.set(t),this.fillArea.set(t)}}const{No:pt,Yes:mt,NoAndSkip:vt,YesAndSkip:yt}=f,bt={findOne:t=>t.list.find((t=>t.editable)),findBounds(t,e){if(t.__.hittable&&t.__.visible&&!t.__.locked&&e.hit(t.__world)){if(t.__.editable){if(t.isBranch&&!t.__.hitChildren)return t.__.hitSelf?yt:vt;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?yt:pt;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return mt}return pt}return t.isBranch?vt:pt}},{findOne:wt}=bt;class Lt extends a{get dragging(){return!!this.originList}get running(){const{editor:t}=this;return this.hittable&&t.visible&&t.hittable&&t.mergeConfig.selector}get isMoveMode(){return this.app&&this.app.interaction.moveMode}constructor(t){super(),this.hoverStroker=new ut,this.targetStroker=new ut,this.bounds=new p,this.selectArea=new ft,this.__eventIds=[],this.editor=t,this.addMany(this.targetStroker,this.hoverStroker,this.selectArea),this.__listenEvents()}onHover(){const{editor:t}=this;if(!this.running||this.dragging||t.dragging)this.hoverStroker.target=null;else{const{stroke:e,strokeWidth:i,hover:s,hoverStyle:o}=t.mergeConfig;this.hoverStroker.setTarget(s?this.editor.hoverTarget:null,Object.assign({stroke:e,strokeWidth:i},o||{}))}}onSelect(){if(this.running){const{mergeConfig:t,list:e}=this.editor,{stroke:i,strokeWidth:s}=t;this.targetStroker.setTarget(e,{stroke:i,strokeWidth:Math.max(1,s/2)}),this.hoverStroker.target=null}}update(){this.targetStroker.target&&this.targetStroker.forceUpdate()}onPointerMove(t){const{app:e,editor:i}=this;if(this.running&&!this.isMoveMode&&e.config.pointer.hover&&!e.interaction.dragging){const e=this.findUI(t);i.hoverTarget=i.hasItem(e)?null:e}this.isMoveMode&&(i.hoverTarget=null)}onBeforeDown(t){const{select:e}=this.editor.mergeConfig;"press"===e&&this.checkAndSelect(t)}onTap(t){const{editor:e}=this,{select:i}=e.mergeConfig;"tap"===i&&this.checkAndSelect(t),this.needRemoveItem?e.removeItem(this.needRemoveItem):this.isMoveMode&&(e.target=null)}checkAndSelect(t){if(this.needRemoveItem=null,this.allowSelect(t)){const{editor:e}=this,i=this.findUI(t);i?this.isMultipleSelect(t)?e.hasItem(i)?this.needRemoveItem=i:e.addItem(i):e.target=i:this.allow(t.target)&&(t.shiftKey||(e.target=null))}}onDragStart(t){if(this.allowDrag(t)){const{editor:e}=this,{stroke:i,area:s}=e.mergeConfig,{x:o,y:n}=t.getInner(this);this.bounds.set(o,n),this.selectArea.setStyle({visible:!0,stroke:i,x:o,y:n},s),this.selectArea.setBounds(this.bounds.get()),this.originList=e.leafList.clone()}}onDrag(t){if(this.editor.dragging)this.onDragEnd();else if(this.dragging){const{editor:e}=this,i=t.getInnerTotal(this),s=this.bounds.clone().unsign(),o=new m(e.app.find(bt.findBounds,s));if(this.bounds.width=i.x,this.bounds.height=i.y,this.selectArea.setBounds(s.get()),o.length){const t=[];this.originList.forEach((e=>{o.has(e)||t.push(e)})),o.forEach((e=>{this.originList.has(e)||t.push(e)})),(t.length!==e.list.length||e.list.some(((e,i)=>e!==t[i])))&&(e.target=t)}else e.target=this.originList.list}}onDragEnd(){this.dragging&&(this.originList=null,this.selectArea.visible=!1)}onAutoMove(t){if(this.dragging){const{x:e,y:i}=t.getLocalMove(this);this.bounds.x+=e,this.bounds.y+=i}}allow(t){return t.leafer!==this.editor.leafer}allowDrag(t){return!(!this.running||!this.editor.mergeConfig.boxSelect||t.target.draggable)&&(!this.editor.editing&&this.allow(t.target)||t.shiftKey&&!wt(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new m(this.editor.editBox.rect)};return wt(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):wt(t.path)}isMultipleSelect(t){return t.shiftKey||this.editor.mergeConfig.continuousSelect}__listenEvents(){const{editor:t}=this;t.waitLeafer((()=>{const{app:e}=t;e.selector.proxy=t,this.__eventIds=[t.on_(st.HOVER,this.onHover,this),t.on_(st.SELECT,this.onSelect,this),e.on_(T.MOVE,this.onPointerMove,this),e.on_(T.BEFORE_DOWN,this.onBeforeDown,this),e.on_(T.TAP,this.onTap,this),e.on_(V.START,this.onDragStart,this),e.on_(V.DRAG,this.onDrag,this),e.on_(V.END,this.onDragEnd,this),e.on_(P.MOVE,this.onAutoMove,this),e.on_([O.ZOOM,P.MOVE],(()=>{this.editor.hoverTarget=null}))]}))}__removeListenEvents(){this.__eventIds&&(this.off_(this.__eventIds),this.__eventIds.length=0)}destroy(){this.editor=this.originList=this.needRemoveItem=null,this.__removeListenEvents(),super.destroy()}}const{topLeft:_t,top:kt,topRight:xt,right:Et,bottomRight:Mt,bottom:St,bottomLeft:Tt,left:Vt}=b,{toPoint:Pt}=y,Ot={getScaleData(t,e,i,s,o){let n,r={},a=1,h=1;const{width:l,height:d}=t;o&&(i.x*=2,i.y*=2),Math.abs(i.x)===l&&(i.x+=.1),Math.abs(i.y)===d&&(i.y+=.1);const c=(-i.y+d)/d,g=(i.x+l)/l,u=(i.y+d)/d,f=(-i.x+l)/l;switch(e){case kt:h=c,n="bottom";break;case Et:a=g,n="left";break;case St:h=u,n="top";break;case Vt:a=f,n="right";break;case _t:h=c,a=f,n="bottom-right";break;case xt:h=c,a=g,n="bottom-left";break;case Mt:h=u,a=g,n="top-left";break;case Tt:h=u,a=f,n="top-right"}if(s){if(!("corner"===s&&e%2)){const t=Math.sqrt(Math.abs(a*h));a=a<0?-t:t,h=h<0?-t:t}}return Pt(o||n,t,r),{origin:r,scaleX:a,scaleY:h,direction:e,lockRatio:s,around:o}},getRotateData(t,e,i,s,o){let n,r={};switch(e){case _t:n="bottom-right";break;case xt:n="bottom-left";break;case Mt:n="top-left";break;case Tt:n="top-right";break;default:n="center"}return Pt(o||n,t,r),{origin:r,rotation:v.getRotation(s,r,i)}},getSkewData(t,e,i,s){let o,n,r={},a=0,h=0;switch(e){case kt:n={x:.5,y:0},o="bottom",a=1;break;case St:n={x:.5,y:1},o="top",a=1;break;case Vt:n={x:0,y:.5},o="right",h=1;break;case Et:n={x:1,y:.5},o="left",h=1}const{x:l,y:d,width:c,height:g}=t;n.x=l+n.x*c,n.y=d+n.y*g,Pt(s||o,t,r);const u=v.getRotation(n,r,{x:n.x+(a?i.x:0),y:n.y+(h?i.y:0)});return a?a=-u:h=u,{origin:r,skewX:a,skewY:h}},getAround:(t,e)=>e&&!t?"center":t,getRotateDirection:(t,e,i=8)=>((t=(t+Math.round(e/(360/i)))%i)<0&&(t+=i),t),getFlipDirection(t,e,i){if(e)switch(t){case Vt:t=Et;break;case _t:t=xt;break;case Tt:t=Mt;break;case Et:t=Vt;break;case xt:t=_t;break;case Mt:t=Tt}if(i)switch(t){case kt:t=St;break;case _t:t=Tt;break;case xt:t=Mt;break;case St:t=kt;break;case Tt:t=_t;break;case Mt:t=xt}return t}},Ht={};function It(t,e){const{editBox:i}=t,s=i.enterPoint;if(!s||!t.editing||!i.visible)return;if("circle"===s.name)return;let{rotation:o}=i;const{resizeCursor:n,rotateCursor:r,skewCursor:a,resizeable:h,rotateable:l,skewable:d}=t.mergeConfig,{pointType:c}=s,{flippedX:g,flippedY:u}=i;let f="resize"===c;f&&l&&(e.metaKey||e.ctrlKey||!h)&&(f=!1);const p=d&&!f&&"resize-line"===s.name?a:f?n:r;o+=45*(Ot.getFlipDirection(s.direction,g,u)+1),o=2*Math.round(w.formatRotation(o,!0)/2);const{url:m,x:v,y:y}=p,b=m+o;Ht[b]?s.cursor=Ht[b]:Ht[b]=s.cursor={url:Bt(m,o),x:v,y:y}}function Ct(t){t.editBox.rect.cursor=t.mergeConfig.moveCursor}function Bt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class Rt extends h{}const Dt=["top","right","bottom","left"];class At extends a{get flipped(){return this.flippedX||this.flippedY}get flippedX(){return this.scaleX<0}get flippedY(){return this.scaleY<0}get flippedOne(){return this.scaleX*this.scaleY<0}constructor(t){super(),this.view=new a,this.rect=new h({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new Rt({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new a({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.__listenEvents()}create(){let t,e,i;const{view:s,resizePoints:o,rotatePoints:n,resizeLines:r,rect:a,circle:h,buttons:l}=this,d=["bottom-right","bottom","bottom-left","left","top-left","top","top-right","right"];for(let s=0;s<8;s++)t=new Rt({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new Rt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",s)),i=new Rt({name:"resize-point",hitRadius:5}),o.push(i),this.listenPointEvents(i,"resize",s);l.add(h),this.listenPointEvents(h,"rotate",2),s.addMany(...n,a,l,...r,...o),this.add(s)}load(){const{mergeConfig:t,element:e,single:i}=this.editor,{rect:s,circle:o,resizePoints:n}=this,{stroke:r,strokeWidth:a,moveable:h}=t,l=this.getPointsStyle(),d=this.getMiddlePointsStyle();let c;for(let t=0;t<8;t++)c=n[t],c.set(this.getPointStyle(t%2?d[(t-1)/2%d.length]:l[t/2%l.length])),t%2||(c.rotation=t/2*90);o.set(this.getPointStyle(t.rotatePoint||l[0])),s.set(Object.assign({stroke:r,strokeWidth:a},t.rect||{})),s.hittable=!i&&h,e.syncEventer=i&&h?s:null,this.app.interaction.bottomList=i&&h?[{target:s,proxy:e}]:null,this.visible=!e.locked}update(t){if(this.view.worldOpacity){const{mergeConfig:e}=this.editor,{width:i,height:s}=t,{rect:o,circle:n,resizePoints:r,rotatePoints:a,resizeLines:h}=this,{middlePoint:l,resizeable:d,rotateable:c,hideOnSmall:g}=e,u="number"==typeof g?g:10,f=!(g&&i<u&&s<u);let p,m,v,b={};for(let o=0;o<8;o++)y.toPoint(y.directionData[o],t,b),m=r[o],p=a[o],v=h[Math.floor(o/2)],m.set(b),p.set(b),v.set(b),m.visible=v.visible=f&&(d||c),p.visible=f&&c&&d&&!e.rotatePoint,o%2&&(m.visible=p.visible=f&&!!l,(o+1)/2%2?(v.width=i,m.width>i-30&&(m.visible=!1)):(v.height=s,m.rotation=90,m.width>s-30&&(m.visible=!1)));n.visible=f&&c&&!!e.rotatePoint,o.path&&(o.path=null),o.set(Object.assign(Object.assign({},t),{visible:!0}));const w=f&&(n.visible||this.buttons.children.length>1);this.buttons.visible=w,w&&this.layoutButtons()}}layoutButtons(){const{buttons:t,resizePoints:e}=this,{buttonsDirection:i,buttonsFixed:s,buttonsMargin:o,middlePoint:n}=this.editor.mergeConfig,{flippedX:r,flippedY:a}=this;let h=Dt.indexOf(i);(h%2&&r||(h+1)%2&&a)&&s&&(h=(h+2)%4);const l=s?Ot.getRotateDirection(h,this.flippedOne?this.rotation:-this.rotation,4):h,d=e[2*l+1],c=l%2,g=l&&3!==l?1:-1,u=(o+(h%2?(n?d.width:0)+t.boxBounds.width:(n?d.height:0)+t.boxBounds.height)/2)*g;c?(t.x=d.x+u,t.y=d.y):(t.x=d.x,t.y=d.y+u),s&&(t.rotation=90*(l-h),t.scaleX=r?-1:1,t.scaleY=a?-1:1)}unload(){this.visible=!1}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:s,pointSize:o,pointRadius:n}=this.editor.mergeConfig,r={fill:s,stroke:e,strokeWidth:i,around:"center",strokeAlign:"center",width:o,height:o,cornerRadius:n};return t?Object.assign(r,t):r}getPointsStyle(){const{point:t}=this.editor.mergeConfig;return t instanceof Array?t:[t]}getMiddlePointsStyle(){const{middlePoint:t}=this.editor.mergeConfig;return t instanceof Array?t:t?[t]:this.getPointsStyle()}onSelect(t){1===t.oldList.length&&(t.oldList[0].syncEventer=this.app.interaction.bottomList=null)}onDragStart(t){if(this.dragging=!0,"rect"===t.current.name){const{editor:t}=this;this.moving=!0,t.dragStartPoint={x:t.element.x,y:t.element.y},t.opacity=t.mergeConfig.hideOnMove?0:1}}onDragEnd(t){this.dragging=!1,this.moving=!1,"rect"===t.current.name&&(this.editor.opacity=1)}onDrag(t){const{editor:e}=this;"rotate"===(this.enterPoint=t.current).pointType||t.metaKey||t.ctrlKey||!e.mergeConfig.resizeable?e.mergeConfig.rotateable&&e.onRotate(t):e.onScale(t),It(e,t)}onArrow(t){if(this.editor.editing&&this.editor.mergeConfig.keyEvent){const e={x:0,y:0},i=t.shiftKey?10:1;switch(t.code){case"ArrowDown":e.y=i;break;case"ArrowUp":e.y=-i;break;case"ArrowLeft":e.x=-i;break;case"ArrowRight":e.x=i}this.editor.move(e)}}onDoubleTap(t){"double"===this.editor.mergeConfig.openInner&&this.openInner(t)}onLongPress(t){"long"===this.editor.mergeConfig.openInner&&this.openInner(t)}openInner(t){const{editor:e}=this;if(e.single){const{element:i}=e;i.isBranch?(e.openGroup(i),e.target=e.selector.findDeepOne(t)):e.openInnerEditor()}}listenPointEvents(t,e,i){const{editor:s}=this;t.direction=i,t.pointType=e,t.on_(V.START,this.onDragStart,this),t.on_(V.DRAG,this.onDrag,this),t.on_(V.END,this.onDragEnd,this),t.on_(T.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(T.ENTER,(e=>{this.enterPoint=t,It(s,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(st.SELECT,this.onSelect,this),t.on_(V.START,this.onDragStart,this),t.on_(V.DRAG,e.onMove,e),t.on_(V.END,this.onDragEnd,this),t.on_(T.ENTER,(()=>Ct(e))),t.on_(T.DOUBLE_TAP,this.onDoubleTap,this),t.on_(T.LONG_PRESS,this.onLongPress,this)]}__removeListenEvents(){this.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const Zt='\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"/>',zt={editSize:"size",keyEvent:!0,stroke:"#836DFF",strokeWidth:2,pointFill:"#FFFFFF",pointSize:10,pointRadius:16,rotateGap:45,buttonsDirection:"bottom",buttonsMargin:12,hideOnSmall:!0,moveCursor:"move",resizeCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate({{rotation}},12,12)">\n<path d="M7.5 8.0H8.5V5.9L6.8 7.2L7.5 8.0ZM3 11.4L2.3 10.6L1.3 11.4L2.3 12.2L3 11.4ZM7.5 10.4H6.5V11.4H7.5V10.4ZM16.5 10.4V11.4H17.5V10.4H16.5ZM16.5 8.0L17.1 7.2L15.5 5.9V8.0H16.5ZM21 11.4L21.6 12.2L22.6 11.4L21.6 10.6L21 11.4ZM16.5 14.9H15.5V16.9L17.1 15.7L16.5 14.9ZM16.5 12.4H17.5V11.4H16.5V12.4ZM7.5 12.4V11.4H6.5V12.4H7.5ZM7.5 14.9L6.8 15.7L8.5 16.9V14.9H7.5ZM6.8 7.2L2.3 10.6L3.6 12.2L8.1 8.7L6.8 7.2ZM8.5 10.4V8.0H6.5V10.4H8.5ZM16.5 9.4H7.5V11.4H16.5V9.4ZM17.5 10.4V8.0H15.5V10.4H17.5ZM15.8 8.7L20.3 12.2L21.6 10.6L17.1 7.2L15.8 8.7ZM20.3 10.6L15.8 14.1L17.1 15.7L21.6 12.2L20.3 10.6ZM17.5 14.9V12.4H15.5V14.9H17.5ZM7.5 13.4H16.5V11.4H7.5V13.4ZM8.5 14.9V12.4H6.5V14.9H8.5ZM2.3 12.2L6.8 15.7L8.1 14.1L3.6 10.6L2.3 12.2Z" fill="white"/>\n<path fill-rule="evenodd" d="M3 11.4L7.5 8.0V10.4H16.5V8.0L21 11.4L16.5 14.9V12.4H7.5V14.9L3 11.4Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="3.9" width="27.2" height="16.9" filterUnits="userSpaceOnUse">\n${Zt}\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${Zt}\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${Zt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,hover:!0,select:"press",openInner:"double",boxSelect:!0,moveable:!0,resizeable:!0,rotateable:!0,skewable:!0};const Wt=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),Xt=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),Yt={group(t,e,i){t.sort(Xt);const{app:s,parent:o}=t[0];let n;n=i&&i.add?i:new a(i),o.addAt(n,o.children.indexOf(t[0])),t.sort(Wt);const r=new L(e.worldTransform);return r.divideParent(o.worldTransform),n.setTransform(r),n.editable=!0,n.hitChildren=!1,s.lockLayout(),t.forEach((t=>t.dropTo(n))),s.unlockLayout(),n},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach((t=>{if(t.isBranch){const{parent:e,children:s}=t;for(;s.length;)i.push(s[0]),s[0].dropTo(e,e.children.indexOf(t));t.remove()}else i.push(t)})),e.unlockLayout(),i},toTop(t){t.sort(Wt),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(Xt),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},Ft=_.get("EditToolCreator");function Ut(){return t=>{jt.register(t)}}const Gt=Ut,jt={list:{},register(t){const{tag:e}=t.prototype;Kt[e]?Ft.repeat(e):Kt[e]=t},get:(t,e)=>new Kt[t](e)},{list:Kt}=jt;class Nt extends a{get list(){return this.leafList.list}get editing(){return!!this.list.length}get groupOpening(){return!!this.openedGroupList.length}get multiple(){return this.list.length>1}get single(){return 1===this.list.length}get dragging(){return this.editBox.dragging}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}constructor(t,e){super(e),this.config=zt,this.mergeConfig=zt,this.leafList=new m,this.openedGroupList=new m,this.simulateTarget=new u({visible:!1}),this.editBox=new At(this),this.editToolList={},this.selector=new Lt(this),this.targetEventIds=[],t&&(this.config=k.default(t,this.config)),this.addMany(this.selector,this.editBox)}select(t){this.target=t}cancel(){this.target=null}hasItem(t){return this.leafList.has(t)}addItem(t){this.hasItem(t)||t.locked||(this.leafList.add(t),this.target=this.leafList.list)}removeItem(t){this.hasItem(t)&&(this.leafList.remove(t),this.target=this.leafList.list)}shiftItem(t){this.hasItem(t)?this.removeItem(t):this.addItem(t)}update(){this.editing&&(this.innerEditing&&this.innerEditor.update(),this.editTool.update(),this.selector.update())}updateEditTool(){const t=this.editTool;if(t&&(this.editBox.unload(),t.unload(),this.editTool=null),this.editing){const t=this.single?this.list[0].editOuter:"EditTool";this.editTool=this.editToolList[t]=this.editToolList[t]||jt.get(t,this);const{editConfig:e}=this.element;this.mergeConfig=this.single&&e?Object.assign(Object.assign({},this.mergeConfig),e):this.config,this.editBox.load(),this.editTool.load()}}getEditSize(t){return this.mergeConfig.editSize}onMove(t){const e={x:t.totalX,y:t.totalY};t.shiftKey&&(Math.abs(e.x)>Math.abs(e.y)?e.y=0:e.x=0),this.move(V.getValidMove(this.element,this.dragStartPoint,e))}onScale(t){const{element:e}=this,{direction:i}=t.current;let{around:s,lockRatio:o}=this.mergeConfig;t.shiftKey&&(o=!0);const n=Ot.getScaleData(e.boxBounds,i,t.getInnerMove(e),o,Ot.getAround(s,t.altKey));this.editTool.onScaleWithDrag?(n.drag=t,this.scaleWithDrag(n)):this.scaleOf(n.origin,n.scaleX,n.scaleY)}onRotate(t){const{skewable:e,around:i,rotateGap:s}=this.mergeConfig,{direction:o,name:n}=t.current;if(e&&"resize-line"===n)return this.onSkew(t);const{element:r}=this;let a,h;if(t instanceof H)h=t.rotation,a=r.getInnerPoint(t);else{const e={x:t.x-t.moveX,y:t.y-t.moveY},s=Ot.getRotateData(r.boxBounds,o,t.getInner(r),r.getInnerPoint(e),t.shiftKey?null:i||"center");h=s.rotation,a=s.origin}h=w.getGapRotation(h,s,r.rotation),h&&(r.scaleX*r.scaleY<0&&(h=-h),this.rotateOf(a,w.float(h,2)))}onSkew(t){const{element:e}=this,{around:i}=this.mergeConfig,{origin:s,skewX:o,skewY:n}=Ot.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),Ot.getAround(i,t.altKey));(o||n)&&this.skewOf(s,o,n)}move(t,e=0){if(!this.mergeConfig.moveable||this.element.locked)return;const{element:i}=this,s=i.getWorldPointByLocal("object"==typeof t?Object.assign({},t):{x:t,y:e},null,!0),o=new ot(ot.MOVE,{target:i,editor:this,moveX:s.x,moveY:s.y});this.editTool.onMove(o),this.emitEvent(o),this.multiple&&i.move(t,e)}scaleWithDrag(t){const{element:e}=this,i=e.getWorldPoint(t.origin),s=new nt(nt.SCALE,Object.assign(Object.assign({},t),{target:e,editor:this,worldOrigin:i}));this.editTool.onScaleWithDrag(s),this.emitEvent(s)}scaleOf(t,e,i=e,s){const{element:o}=this,n=o.getWorldPoint(t);let r;if(this.multiple){const s=new L(o.worldTransform);o.scaleOf(t,e,i),r=new L(o.worldTransform).divide(s)}const a=new nt(nt.SCALE,{target:o,editor:this,worldOrigin:n,scaleX:e,scaleY:i,transform:r});this.editTool.onScale(a),this.emitEvent(a)}rotateOf(t,e){const{element:i}=this,s=i.getWorldPoint(t);let o;if(this.multiple){const s=new L(i.worldTransform);i.rotateOf(t,e),o=new L(i.worldTransform).divide(s)}const n=new rt(rt.ROTATE,{target:i,editor:this,worldOrigin:s,rotation:e,transform:o});this.editTool.onRotate(n),this.emitEvent(n)}skewOf(t,e,i=0,s){const{element:o}=this,n=o.getWorldPoint(t);let r;if(this.multiple){const s=new L(o.worldTransform);o.skewOf(t,e,i),r=new L(o.worldTransform).divide(s)}const a=new at(at.SKEW,{target:o,editor:this,skewX:e,skewY:i,transform:r,worldOrigin:n});this.editTool.onSkew(a),this.emitEvent(a)}group(t){return this.multiple&&(this.target=Yt.group(this.list,this.element,t)),this.target}ungroup(){return this.list.length&&(this.target=Yt.ungroup(this.list)),this.list}openGroup(t){this.openedGroupList.add(t),t.hitChildren=!0}closeGroup(t){this.openedGroupList.remove(t),t.hitChildren=!1}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:e}=t;this.editing&&(e=[],t.forEach((t=>this.list.every((e=>!x.hasParent(e,t)))&&e.push(t)))),e.forEach((t=>this.closeGroup(t)))}}openInnerEditor(){if(this.single){const t=this.element.editInner;t&&jt.list[t]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[t]||jt.get(t,this),this.innerEditor.load())}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.innerEditor.unload(),this.editTool.load(),this.innerEditor=null)}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(Yt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(Yt.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{leafer:t}=this.list[0];this.targetEventIds=[t.on_(E.START,this.update,this),t.on_([I.HOLD,I.UP],(t=>{It(this,t)})),t.on_(I.DOWN,this.editBox.onArrow,this.editBox)]}}removeTargetEvents(){const{targetEventIds:t}=this;t.length&&(this.off_(t),t.length=0)}destroy(){this.destroyed||(this.simulateTarget.destroy(),Object.values(this.editToolList).forEach((t=>t.destroy())),this.editToolList={},this.target=this.hoverTarget=this.simulateTarget=this.editTool=this.innerEditor=null,super.destroy())}}et([ht((function(t,e){t.emitEvent(new st(st.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],Nt.prototype,"hoverTarget",void 0),et([ht((function(t,e){const{target:i}=t;i?t.leafList=i instanceof m?i:new m(i):t.leafList.reset(),t.emitEvent(new st(st.SELECT,{editor:t,value:i,oldValue:e})),t.checkOpenedGroups(),t.editing?t.waitLeafer((()=>{t.multiple&&function(t){const{simulateTarget:e,leafList:i}=t,{x:s,y:o,width:n,height:r}=(new p).setListWithFn(i.list,(t=>t.worldBoxBounds)),a=e.parent=i.list[0].leafer.zoomLayer,{scaleX:h,scaleY:l,e:d,f:c}=a.__world;e.reset({x:(s-d)/h,y:(o-c)/l,width:n/h,height:r/l})}(t),Ct(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):(t.updateEditTool(),t.removeTargetEvents())}))],Nt.prototype,"target",void 0);class $t{static registerInnerEditor(){jt.register(this)}get tag(){return"InnerEditor"}get editBox(){return this.editor.editBox}constructor(t){this.editor=t,this.create()}onCreate(){}create(){this.view=new a,this.onCreate()}onLoad(){}load(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!1,this.onLoad()}onUpdate(){}update(){this.onUpdate()}onUnload(){}unload(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!0,this.onUnload()}onDestroy(){}destroy(){this.onDestroy(),this.editor&&(this.view&&this.view.destroy(),this.eventIds&&this.editor.off_(this.eventIds),this.editor=this.view=this.eventIds=null)}}let qt=class extends $t{static registerEditTool(){jt.register(this)}get tag(){return"EditTool"}onMove(t){const{moveX:e,moveY:i,editor:s}=t,{app:o,list:n}=s;o.lockLayout(),n.forEach((t=>{t.moveWorld(e,i)})),o.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="scale"!==n.getEditSize(t);s?t.transformWorld(s,r):t.scaleOfWorld(o,e,i,r)})),r.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:s,editor:o}=t,{app:n,list:r}=o;n.lockLayout(),r.forEach((t=>{const n="scale"!==o.getEditSize(t);i?t.transformWorld(i,n):t.rotateOfWorld(s,e)})),n.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="scale"!==n.getEditSize(t);s?t.transformWorld(s,r):t.skewOfWorld(o,e,i,r)})),r.unlockLayout()}load(){this.editBox.view.visible=!0,this.onLoad()}update(){const{editor:t,editBox:e}=this,{simulateTarget:i,element:s}=t;t.multiple&&i.parent.updateLayout();const{x:o,y:n,scaleX:r,scaleY:a,rotation:h,skewX:l,skewY:d,width:c,height:g}=s.getLayoutBounds("box",t,!0);e.set({x:o,y:n,scaleX:r,scaleY:a,rotation:h,skewX:l,skewY:d}),e.update({x:0,y:0,width:c,height:g}),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}};qt=et([Ut()],qt);const{left:Qt,right:Jt}=b,{move:te,copy:ee}=v;let ie=class extends qt{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(t){const{drag:e,direction:i,lockRatio:s,around:o}=t,n=t.target,r=i===Qt;if(n.pathInputed){const{path:t}=n.__,{from:i,to:a}=this.getFromToByPath(t);this.dragPoint(i,a,r,o,this.getInnerMove(n,e,s)),t[1]=i.x,t[2]=i.y,t[4]=a.x,t[5]=a.y,n.path=t}else if(n.points){const{points:t}=n,{from:i,to:a}=this.getFromToByPoints(t);this.dragPoint(i,a,r,o,this.getInnerMove(n,e,s)),t[0]=i.x,t[1]=i.y,t[2]=a.x,t[3]=a.y,n.points=t}else{const t=M(),{toPoint:i}=n;n.rotation=0,this.dragPoint(t,i,r,o,this.getInnerMove(n,e,s)),n.getLocalPointByInner(t,null,null,!0),n.getLocalPointByInner(i,null,null,!0),n.x=t.x,n.y=t.y,n.getInnerPointByLocal(i,null,null,!0),n.toPoint=i}}getInnerMove(t,e,i){const s=e.getInnerMove(t);return i&&(Math.abs(s.x)>Math.abs(s.y)?s.y=0:s.x=0),s}getFromToByPath(t){return{from:{x:t[1],y:t[2]},to:{x:t[4],y:t[5]}}}getFromToByPoints(t){return{from:{x:t[0],y:t[1]},to:{x:t[2],y:t[3]}}}dragPoint(t,e,i,s,o){const{x:n,y:r}=o;i?(te(t,n,r),s&&te(e,-n,-r)):(s&&te(t,-n,-r),te(e,n,r))}onSkew(t){}onUpdate(){const{editBox:t}=this,{rotatePoints:e,resizeLines:i,resizePoints:s,rect:o}=t,n=this.editor.element;let r,a;if(n.pathInputed?r=this.getFromToByPath(n.__.path):n.points&&(r=this.getFromToByPoints(n.__.points)),r){const{from:i,to:a}=r;n.innerToWorld(i,i,!1,t),n.innerToWorld(a,a,!1,t),o.pen.clearPath().moveTo(i.x,i.y).lineTo(a.x,a.y),ee(s[7],i),ee(e[7],i),ee(s[3],a),ee(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===Qt||t===Jt,s[t].visible=a,e[t].visible=!r&&a}};ie=et([Ut()],ie),S.editor=function(t){return new Nt(t)},c.setEditConfig=function(t){d(this.prototype,"editConfig",{get(){return"function"==typeof t?t(this):t}})},c.setEditOuter=function(t){d(this.prototype,"editOuter",{get(){return"string"==typeof t?t:t(this)}})},c.setEditInner=function(t){d(this.prototype,"editInner",{get(){return"string"==typeof t?t:t(this)}})};export{At as EditBox,Ot as EditDataHelper,Rt as EditPoint,Lt as EditSelect,bt as EditSelectHelper,qt as EditTool,jt as EditToolCreator,Nt as Editor,st as EditorEvent,Yt as EditorHelper,ot as EditorMoveEvent,rt as EditorRotateEvent,nt as EditorScaleEvent,at as EditorSkewEvent,$t as InnerEditor,ie as LineEditTool,j as PathScaler,ft as SelectArea,ut as Stroker,Ut as registerEditTool,Gt as registerInnerEditor,$ as scaleResize,q as scaleResizeFont,tt as scaleResizeGroup,Q as scaleResizePath,J as scaleResizePoints};
1
+ export*from"@leafer-in/resize";import{Event as t,defineKey as e,MatrixHelper as i,UI as o,Paint as s,Group as n,Rect as r,Answer as h,Bounds as a,LeafList as l,PointHelper as d,AroundHelper as c,Direction9 as g,MathHelper as u,Box as f,Matrix as p,Debug as m,DataHelper as v,LeafHelper as y,RenderEvent as L,getPointData as w,Creator as E}from"@leafer-ui/draw";import{PointerEvent as b,DragEvent as _,MoveEvent as k,ZoomEvent as x,RotateEvent as O,KeyEvent as M}from"@leafer-ui/core";function S(t,e,i,o){var s,n=arguments.length,r=n<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,o);else for(var h=t.length-1;h>=0;h--)(s=t[h])&&(r=(n<3?s(r):n>3?s(e,i,r):s(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}function T(t){return t?t instanceof Array?t:[t]:[]}"function"==typeof SuppressedError&&SuppressedError;class P extends t{get list(){return T(this.value)}get oldList(){return T(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}P.SELECT="editor.select",P.HOVER="editor.hover";class V extends P{constructor(t,e){super(t,e)}}V.MOVE="editor.move";class H extends P{constructor(t,e){super(t,e)}}H.SCALE="editor.scale";class I extends P{constructor(t,e){super(t,e)}}I.ROTATE="editor.rotate";class C extends P{constructor(t,e){super(t,e)}}function B(t){return(i,o)=>{const s="_"+o;e(i,o,{get(){return this[s]},set(e){const i=this[s];i!==e&&(this[s]=e,t(this,i))}})}}C.SKEW="editor.skew";const R=i.get(),{abs:D}=Math,{copy:A,scale:Z}=i;class W extends o{constructor(){super(),this.list=[],this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){this.set(e),this.target=t}__draw(t,e){const{list:i}=this;if(i.length){let o;const{stroke:n,strokeWidth:r,fill:h}=this.__,{bounds:a}=e;for(let l=0;l<i.length;l++)if(o=i[l],a&&a.hit(o.__world,e.matrix)){const i=D(o.__world.scaleX),a=D(o.__world.scaleY);if(i!==a){A(R,o.__world),Z(R,1/i,1/a),t.setWorld(R,e.matrix),t.beginPath(),this.__.strokeWidth=r;const{x:s,y:n,width:h,height:l}=o.__layout.boxBounds;t.rect(s*i,n*a,h*i,l*a)}else t.setWorld(o.__world,e.matrix),t.beginPath(),o.__.__useArrow?o.__drawPath(t):o.__.__pathForRender?o.__drawRenderPath(t):o.__drawPathByBox(t),this.__.strokeWidth=r/D(o.__world.scaleX);n&&("string"==typeof n?s.stroke(n,this,t):s.strokes(n,this,t)),h&&("string"==typeof h?s.fill(h,this,t):s.fills(h,this,t))}this.__.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}S([B((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],W.prototype,"target",void 0);class z extends n{constructor(t){super(t),this.strokeArea=new r({strokeAlign:"center"}),this.fillArea=new r,this.visible=this.hittable=!1,this.addMany(this.fillArea,this.strokeArea)}setStyle(t,e){const{visible:i,stroke:o,strokeWidth:s}=t;this.visible=i,this.strokeArea.reset(Object.assign({stroke:o,strokeWidth:s},e||{})),this.fillArea.reset({visible:!e,fill:o,opacity:.2})}setBounds(t){this.strokeArea.set(t),this.fillArea.set(t)}}const{No:F,Yes:G,NoAndSkip:U,YesAndSkip:Y}=h,X={findOne:t=>t.list.find((t=>t.editable)),findBounds(t,e){if(t.__.hittable&&t.__.visible&&!t.__.locked&&e.hit(t.__world)){if(t.__.editable){if(t.isBranch&&!t.__.hitChildren)return t.__.hitSelf?Y:U;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?Y:F;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return G}return F}return t.isBranch?U:F}},{findOne:N}=X;class j extends n{get dragging(){return!!this.originList}get running(){const{editor:t}=this;return this.hittable&&t.visible&&t.hittable&&t.mergeConfig.selector}get isMoveMode(){return this.app&&this.app.interaction.moveMode}constructor(t){super(),this.hoverStroker=new W,this.targetStroker=new W,this.bounds=new a,this.selectArea=new z,this.__eventIds=[],this.editor=t,this.addMany(this.targetStroker,this.hoverStroker,this.selectArea),this.__listenEvents()}onHover(){const{editor:t}=this;if(!this.running||this.dragging||t.dragging)this.hoverStroker.target=null;else{const{stroke:e,strokeWidth:i,hover:o,hoverStyle:s}=t.mergeConfig;this.hoverStroker.setTarget(o?this.editor.hoverTarget:null,Object.assign({stroke:e,strokeWidth:i},s||{}))}}onSelect(){if(this.running){const{mergeConfig:t,list:e}=this.editor,{stroke:i,strokeWidth:o}=t;this.targetStroker.setTarget(e,{stroke:i,strokeWidth:Math.max(1,o/2)}),this.hoverStroker.target=null}}update(){this.targetStroker.target&&this.targetStroker.forceUpdate()}onPointerMove(t){const{app:e,editor:i}=this;if(this.running&&!this.isMoveMode&&e.config.pointer.hover&&!e.interaction.dragging){const e=this.findUI(t);i.hoverTarget=i.hasItem(e)?null:e}this.isMoveMode&&(i.hoverTarget=null)}onBeforeDown(t){const{select:e}=this.editor.mergeConfig;"press"===e&&this.checkAndSelect(t)}onTap(t){const{editor:e}=this,{select:i}=e.mergeConfig;"tap"===i&&this.checkAndSelect(t),this.needRemoveItem?e.removeItem(this.needRemoveItem):this.isMoveMode&&(e.target=null)}checkAndSelect(t){if(this.needRemoveItem=null,this.allowSelect(t)){const{editor:e}=this,i=this.findUI(t);i?this.isMultipleSelect(t)?e.hasItem(i)?this.needRemoveItem=i:e.addItem(i):e.target=i:this.allow(t.target)&&(t.shiftKey||(e.target=null))}}onDragStart(t){if(this.allowDrag(t)){const{editor:e}=this,{stroke:i,area:o}=e.mergeConfig,{x:s,y:n}=t.getInner(this);this.bounds.set(s,n),this.selectArea.setStyle({visible:!0,stroke:i,x:s,y:n},o),this.selectArea.setBounds(this.bounds.get()),this.originList=e.leafList.clone()}}onDrag(t){if(this.editor.dragging)this.onDragEnd();else if(this.dragging){const{editor:e}=this,i=t.getInnerTotal(this),o=this.bounds.clone().unsign(),s=new l(e.app.find(X.findBounds,o));if(this.bounds.width=i.x,this.bounds.height=i.y,this.selectArea.setBounds(o.get()),s.length){const t=[];this.originList.forEach((e=>{s.has(e)||t.push(e)})),s.forEach((e=>{this.originList.has(e)||t.push(e)})),(t.length!==e.list.length||e.list.some(((e,i)=>e!==t[i])))&&(e.target=t)}else e.target=this.originList.list}}onDragEnd(){this.dragging&&(this.originList=null,this.selectArea.visible=!1)}onAutoMove(t){if(this.dragging){const{x:e,y:i}=t.getLocalMove(this);this.bounds.x+=e,this.bounds.y+=i}}allow(t){return t.leafer!==this.editor.leafer}allowDrag(t){return!(!this.running||!this.editor.mergeConfig.boxSelect||t.target.draggable)&&(!this.editor.editing&&this.allow(t.target)||t.shiftKey&&!N(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new l(this.editor.editBox.rect)};return N(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):N(t.path)}isMultipleSelect(t){return t.shiftKey||this.editor.mergeConfig.continuousSelect}__listenEvents(){const{editor:t}=this;t.waitLeafer((()=>{const{app:e}=t;e.selector.proxy=t,this.__eventIds=[t.on_(P.HOVER,this.onHover,this),t.on_(P.SELECT,this.onSelect,this),e.on_(b.MOVE,this.onPointerMove,this),e.on_(b.BEFORE_DOWN,this.onBeforeDown,this),e.on_(b.TAP,this.onTap,this),e.on_(_.START,this.onDragStart,this),e.on_(_.DRAG,this.onDrag,this),e.on_(_.END,this.onDragEnd,this),e.on_(k.MOVE,this.onAutoMove,this),e.on_([x.ZOOM,k.MOVE],(()=>{this.editor.hoverTarget=null}))]}))}__removeListenEvents(){this.__eventIds&&(this.off_(this.__eventIds),this.__eventIds.length=0)}destroy(){this.editor=this.originList=this.needRemoveItem=null,this.__removeListenEvents(),super.destroy()}}const{topLeft:K,top:$,topRight:q,right:J,bottomRight:Q,bottom:tt,bottomLeft:et,left:it}=g,{toPoint:ot}=c,st={getScaleData(t,e,i,o,s){let n,r={},h=1,a=1;const{width:l,height:d}=t;s&&(i.x*=2,i.y*=2),Math.abs(i.x)===l&&(i.x+=.1),Math.abs(i.y)===d&&(i.y+=.1);const c=(-i.y+d)/d,g=(i.x+l)/l,u=(i.y+d)/d,f=(-i.x+l)/l;switch(e){case $:a=c,n="bottom";break;case J:h=g,n="left";break;case tt:a=u,n="top";break;case it:h=f,n="right";break;case K:a=c,h=f,n="bottom-right";break;case q:a=c,h=g,n="bottom-left";break;case Q:a=u,h=g,n="top-left";break;case et:a=u,h=f,n="top-right"}if(o){if(!("corner"===o&&e%2)){const t=Math.sqrt(Math.abs(h*a));h=h<0?-t:t,a=a<0?-t:t}}return ot(s||n,t,r),{origin:r,scaleX:h,scaleY:a,direction:e,lockRatio:o,around:s}},getRotateData(t,e,i,o,s){let n,r={};switch(e){case K:n="bottom-right";break;case q:n="bottom-left";break;case Q:n="top-left";break;case et:n="top-right";break;default:n="center"}return ot(s||n,t,r),{origin:r,rotation:d.getRotation(o,r,i)}},getSkewData(t,e,i,o){let s,n,r={},h=0,a=0;switch(e){case $:n={x:.5,y:0},s="bottom",h=1;break;case tt:n={x:.5,y:1},s="top",h=1;break;case it:n={x:0,y:.5},s="right",a=1;break;case J:n={x:1,y:.5},s="left",a=1}const{x:l,y:c,width:g,height:u}=t;n.x=l+n.x*g,n.y=c+n.y*u,ot(o||s,t,r);const f=d.getRotation(n,r,{x:n.x+(h?i.x:0),y:n.y+(a?i.y:0)});return h?h=-f:a=f,{origin:r,skewX:h,skewY:a}},getAround:(t,e)=>e&&!t?"center":t,getRotateDirection:(t,e,i=8)=>((t=(t+Math.round(e/(360/i)))%i)<0&&(t+=i),t),getFlipDirection(t,e,i){if(e)switch(t){case it:t=J;break;case K:t=q;break;case et:t=Q;break;case J:t=it;break;case q:t=K;break;case Q:t=et}if(i)switch(t){case $:t=tt;break;case K:t=et;break;case q:t=Q;break;case tt:t=$;break;case et:t=K;break;case Q:t=q}return t}},nt={};function rt(t,e){const{editBox:i}=t,o=i.enterPoint;if(!o||!t.editing||!i.visible)return;if("circle"===o.name)return;let{rotation:s}=i;const{resizeCursor:n,rotateCursor:r,skewCursor:h,resizeable:a,rotateable:l,skewable:d}=t.mergeConfig,{pointType:c}=o,{flippedX:g,flippedY:f}=i;let p="resize"===c;p&&l&&(e.metaKey||e.ctrlKey||!a)&&(p=!1);const m=d&&!p&&"resize-line"===o.name?h:p?n:r;s+=45*(st.getFlipDirection(o.direction,g,f)+1),s=2*Math.round(u.formatRotation(s,!0)/2);const{url:v,x:y,y:L}=m,w=v+s;nt[w]?o.cursor=nt[w]:nt[w]=o.cursor={url:at(v,s),x:y,y:L}}function ht(t){t.editBox.rect.cursor=t.mergeConfig.moveCursor}function at(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class lt extends f{}const dt=["top","right","bottom","left"];class ct extends n{get flipped(){return this.flippedX||this.flippedY}get flippedX(){return this.scaleX<0}get flippedY(){return this.scaleY<0}get flippedOne(){return this.scaleX*this.scaleY<0}constructor(t){super(),this.view=new n,this.rect=new f({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new lt({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new n({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.rect.syncEventer=t,this.__listenEvents()}create(){let t,e,i;const{view:o,resizePoints:s,rotatePoints:n,resizeLines:r,rect:h,circle:a,buttons:l}=this,d=["bottom-right","bottom","bottom-left","left","top-left","top","top-right","right"];for(let o=0;o<8;o++)t=new lt({name:"rotate-point",around:d[o],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",o),o%2&&(e=new lt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",o)),i=new lt({name:"resize-point",hitRadius:5}),s.push(i),this.listenPointEvents(i,"resize",o);l.add(a),this.listenPointEvents(a,"rotate",2),o.addMany(...n,h,l,...r,...s),this.add(o)}load(){const{mergeConfig:t,element:e,single:i}=this.editor,{rect:o,circle:s,resizePoints:n}=this,{stroke:r,strokeWidth:h,moveable:a}=t,l=this.getPointsStyle(),d=this.getMiddlePointsStyle();let c;for(let t=0;t<8;t++)c=n[t],c.set(this.getPointStyle(t%2?d[(t-1)/2%d.length]:l[t/2%l.length])),t%2||(c.rotation=t/2*90);s.set(this.getPointStyle(t.rotatePoint||l[0])),o.set(Object.assign({stroke:r,strokeWidth:h},t.rect||{})),o.hittable=!i&&a,e.syncEventer=i&&a?o:null,this.app.interaction.bottomList=i&&a?[{target:o,proxy:e}]:null}update(t){if(this.visible=!this.editor.element.locked,this.view.worldOpacity){const{mergeConfig:e}=this.editor,{width:i,height:o}=t,{rect:s,circle:n,resizePoints:r,rotatePoints:h,resizeLines:a}=this,{middlePoint:l,resizeable:d,rotateable:g,hideOnSmall:u}=e,f="number"==typeof u?u:10,p=!(u&&i<f&&o<f);let m,v,y,L={};for(let s=0;s<8;s++)c.toPoint(c.directionData[s],t,L),v=r[s],m=h[s],y=a[Math.floor(s/2)],v.set(L),m.set(L),y.set(L),v.visible=y.visible=p&&!(!d&&!g),m.visible=p&&g&&d&&!e.rotatePoint,s%2&&(v.visible=m.visible=p&&!!l,(s+1)/2%2?(y.width=i,v.width>i-30&&(v.visible=!1)):(y.height=o,v.rotation=90,v.width>o-30&&(v.visible=!1)));n.visible=p&&g&&!!e.rotatePoint,s.path&&(s.path=null),s.set(Object.assign(Object.assign({},t),{visible:!0}));const w=p&&(n.visible||this.buttons.children.length>1);this.buttons.visible=w,w&&this.layoutButtons()}}layoutButtons(){const{buttons:t,resizePoints:e}=this,{buttonsDirection:i,buttonsFixed:o,buttonsMargin:s,middlePoint:n}=this.editor.mergeConfig,{flippedX:r,flippedY:h}=this;let a=dt.indexOf(i);(a%2&&r||(a+1)%2&&h)&&o&&(a=(a+2)%4);const l=o?st.getRotateDirection(a,this.flippedOne?this.rotation:-this.rotation,4):a,d=e[2*l+1],c=l%2,g=l&&3!==l?1:-1,u=(s+(a%2?(n?d.width:0)+t.boxBounds.width:(n?d.height:0)+t.boxBounds.height)/2)*g;c?(t.x=d.x+u,t.y=d.y):(t.x=d.x,t.y=d.y+u),o&&(t.rotation=90*(l-a),t.scaleX=r?-1:1,t.scaleY=h?-1:1)}unload(){this.visible=!1}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:o,pointSize:s,pointRadius:n}=this.editor.mergeConfig,r={fill:o,stroke:e,strokeWidth:i,around:"center",strokeAlign:"center",width:s,height:s,cornerRadius:n};return t?Object.assign(r,t):r}getPointsStyle(){const{point:t}=this.editor.mergeConfig;return t instanceof Array?t:[t]}getMiddlePointsStyle(){const{middlePoint:t}=this.editor.mergeConfig;return t instanceof Array?t:t?[t]:this.getPointsStyle()}onSelect(t){1===t.oldList.length&&(t.oldList[0].syncEventer=this.app.interaction.bottomList=null)}onDragStart(t){if(this.dragging=!0,"rect"===t.current.name){const{editor:t}=this;this.moving=!0,t.dragStartPoint={x:t.element.x,y:t.element.y},t.opacity=t.mergeConfig.hideOnMove?0:1}}onDragEnd(t){this.dragging=!1,this.moving=!1,"rect"===t.current.name&&(this.editor.opacity=1)}onDrag(t){const{editor:e}=this;"rotate"===(this.enterPoint=t.current).pointType||t.metaKey||t.ctrlKey||!e.mergeConfig.resizeable?e.mergeConfig.rotateable&&e.onRotate(t):e.onScale(t),rt(e,t)}onArrow(t){if(this.editor.editing&&this.editor.mergeConfig.keyEvent){const e={x:0,y:0},i=t.shiftKey?10:1;switch(t.code){case"ArrowDown":e.y=i;break;case"ArrowUp":e.y=-i;break;case"ArrowLeft":e.x=-i;break;case"ArrowRight":e.x=i}this.editor.move(e)}}onDoubleTap(t){"double"===this.editor.mergeConfig.openInner&&this.openInner(t)}onLongPress(t){"long"===this.editor.mergeConfig.openInner&&this.openInner(t)}openInner(t){const{editor:e}=this;if(e.single){const{element:i}=e;i.isBranch?(e.openGroup(i),e.target=e.selector.findDeepOne(t)):e.openInnerEditor()}}listenPointEvents(t,e,i){const{editor:o}=this;t.direction=i,t.pointType=e,t.on_(_.START,this.onDragStart,this),t.on_(_.DRAG,this.onDrag,this),t.on_(_.END,this.onDragEnd,this),t.on_(b.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(b.ENTER,(e=>{this.enterPoint=t,rt(o,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(P.SELECT,this.onSelect,this),t.on_(_.START,this.onDragStart,this),t.on_(_.DRAG,e.onMove,e),t.on_(_.END,this.onDragEnd,this),t.on_(x.BEFORE_ZOOM,e.onScale,e,!0),t.on_(O.BEFORE_ROTATE,e.onRotate,e,!0),t.on_(b.ENTER,(()=>ht(e))),t.on_(b.DOUBLE_TAP,this.onDoubleTap,this),t.on_(b.LONG_PRESS,this.onLongPress,this)]}__removeListenEvents(){this.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const gt='\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"/>',ut={editSize:"size",keyEvent:!0,stroke:"#836DFF",strokeWidth:2,pointFill:"#FFFFFF",pointSize:10,pointRadius:16,rotateGap:45,buttonsDirection:"bottom",buttonsMargin:12,hideOnSmall:!0,moveCursor:"move",resizeCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate({{rotation}},12,12)">\n<path d="M7.5 8.0H8.5V5.9L6.8 7.2L7.5 8.0ZM3 11.4L2.3 10.6L1.3 11.4L2.3 12.2L3 11.4ZM7.5 10.4H6.5V11.4H7.5V10.4ZM16.5 10.4V11.4H17.5V10.4H16.5ZM16.5 8.0L17.1 7.2L15.5 5.9V8.0H16.5ZM21 11.4L21.6 12.2L22.6 11.4L21.6 10.6L21 11.4ZM16.5 14.9H15.5V16.9L17.1 15.7L16.5 14.9ZM16.5 12.4H17.5V11.4H16.5V12.4ZM7.5 12.4V11.4H6.5V12.4H7.5ZM7.5 14.9L6.8 15.7L8.5 16.9V14.9H7.5ZM6.8 7.2L2.3 10.6L3.6 12.2L8.1 8.7L6.8 7.2ZM8.5 10.4V8.0H6.5V10.4H8.5ZM16.5 9.4H7.5V11.4H16.5V9.4ZM17.5 10.4V8.0H15.5V10.4H17.5ZM15.8 8.7L20.3 12.2L21.6 10.6L17.1 7.2L15.8 8.7ZM20.3 10.6L15.8 14.1L17.1 15.7L21.6 12.2L20.3 10.6ZM17.5 14.9V12.4H15.5V14.9H17.5ZM7.5 13.4H16.5V11.4H7.5V13.4ZM8.5 14.9V12.4H6.5V14.9H8.5ZM2.3 12.2L6.8 15.7L8.1 14.1L3.6 10.6L2.3 12.2Z" fill="white"/>\n<path fill-rule="evenodd" d="M3 11.4L7.5 8.0V10.4H16.5V8.0L21 11.4L16.5 14.9V12.4H7.5V14.9L3 11.4Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="3.9" width="27.2" height="16.9" filterUnits="userSpaceOnUse">\n${gt}\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${gt}\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${gt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,hover:!0,select:"press",openInner:"double",boxSelect:!0,moveable:!0,resizeable:!0,rotateable:!0,skewable:!0};const ft=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),pt=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),mt={group(t,e,i){t.sort(pt);const{app:o,parent:s}=t[0];let r;r=i&&i.add?i:new n(i),s.addAt(r,s.children.indexOf(t[0])),t.sort(ft);const h=new p(e.worldTransform);return h.divideParent(s.worldTransform),r.setTransform(h),r.editable=!0,r.hitChildren=!1,o.lockLayout(),t.forEach((t=>t.dropTo(r))),o.unlockLayout(),r},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach((t=>{if(t.isBranch){const{parent:e,children:o}=t;for(;o.length;)i.push(o[0]),o[0].dropTo(e,e.children.indexOf(t));t.remove()}else i.push(t)})),e.unlockLayout(),i},toTop(t){t.sort(ft),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(pt),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},vt=m.get("EditToolCreator");function yt(){return t=>{wt.register(t)}}const Lt=yt,wt={list:{},register(t){const{tag:e}=t.prototype;Et[e]?vt.repeat(e):Et[e]=t},get:(t,e)=>new Et[t](e)},{list:Et}=wt;class bt extends P{constructor(t,e){super(t,e)}}bt.BEFORE_OPEN="innerEditor.before_open",bt.OPEN="innerEditor.open",bt.BEFORE_CLOSE="innerEditor.before_close",bt.CLOSE="innerEditor.close";class _t extends P{constructor(t,e){super(t,e)}}_t.GROUP="editor.group",_t.BEFORE_UNGROUP="editor.before_ungroup",_t.UNGROUP="editor.ungroup",_t.OPEN="editor.open_group",_t.CLOSE="editor.close_group";class kt extends n{get list(){return this.leafList.list}get editing(){return!!this.list.length}get groupOpening(){return!!this.openedGroupList.length}get multiple(){return this.list.length>1}get single(){return 1===this.list.length}get dragging(){return this.editBox.dragging}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}constructor(t,e){super(e),this.config=ut,this.mergeConfig=ut,this.leafList=new l,this.openedGroupList=new l,this.simulateTarget=new r({visible:!1}),this.editBox=new ct(this),this.editToolList={},this.selector=new j(this),this.targetEventIds=[],t&&(this.config=v.default(t,this.config)),this.addMany(this.selector,this.editBox)}select(t){this.target=t}cancel(){this.target=null}hasItem(t){return this.leafList.has(t)}addItem(t){this.hasItem(t)||t.locked||(this.leafList.add(t),this.target=this.leafList.list)}removeItem(t){this.hasItem(t)&&(this.leafList.remove(t),this.target=this.leafList.list)}shiftItem(t){this.hasItem(t)?this.removeItem(t):this.addItem(t)}update(){this.editing&&(this.innerEditing&&this.innerEditor.update(),this.editTool.update(),this.selector.update())}updateEditTool(){const t=this.editTool;if(t&&(this.editBox.unload(),t.unload(),this.editTool=null),this.editing){const t=this.single?this.list[0].editOuter:"EditTool";this.editTool=this.editToolList[t]=this.editToolList[t]||wt.get(t,this);const{editConfig:e}=this.element;this.mergeConfig=this.single&&e?Object.assign(Object.assign({},this.mergeConfig),e):this.config,this.editBox.load(),this.editTool.load()}}getEditSize(t){return this.mergeConfig.editSize}onMove(t){const e={x:t.totalX,y:t.totalY};t.shiftKey&&(Math.abs(e.x)>Math.abs(e.y)?e.y=0:e.x=0),this.move(_.getValidMove(this.element,this.dragStartPoint,e))}onScale(t){const{element:e}=this;if(t instanceof x)"zoom"===this.mergeConfig.resizeable&&(t.stop(),this.scaleOf(e.getInnerPoint(t),t.scale,t.scale));else{const{direction:i}=t.current;let{around:o,lockRatio:s}=this.mergeConfig;(t.shiftKey||e.lockRatio)&&(s=!0);const n=st.getScaleData(e.boxBounds,i,t.getInnerMove(e),s,st.getAround(o,t.altKey));this.editTool.onScaleWithDrag?(n.drag=t,this.scaleWithDrag(n)):this.scaleOf(n.origin,n.scaleX,n.scaleY)}}onRotate(t){const{skewable:e,around:i,rotateGap:o}=this.mergeConfig,{direction:s,name:n}=t.current;if(e&&"resize-line"===n)return this.onSkew(t);const{element:r}=this;let h,a;if(t instanceof O){if("rotate"!==this.mergeConfig.rotateable)return;t.stop(),a=t.rotation,h=r.getInnerPoint(t)}else{const e={x:t.x-t.moveX,y:t.y-t.moveY},o=st.getRotateData(r.boxBounds,s,t.getInner(r),r.getInnerPoint(e),t.shiftKey?null:i||"center");a=o.rotation,h=o.origin}a=u.getGapRotation(a,o,r.rotation),a&&(r.scaleX*r.scaleY<0&&(a=-a),this.rotateOf(h,u.float(a,2)))}onSkew(t){const{element:e}=this,{around:i}=this.mergeConfig,{origin:o,skewX:s,skewY:n}=st.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),st.getAround(i,t.altKey));(s||n)&&this.skewOf(o,s,n)}move(t,e=0){if(!this.mergeConfig.moveable||this.element.locked)return;const{element:i}=this,o=i.getWorldPointByLocal("object"==typeof t?Object.assign({},t):{x:t,y:e},null,!0),s=new V(V.MOVE,{target:i,editor:this,moveX:o.x,moveY:o.y});this.editTool.onMove(s),this.emitEvent(s),this.multiple&&i.move(t,e)}scaleWithDrag(t){if(!this.mergeConfig.resizeable||this.element.locked)return;const{element:e}=this,i=e.getWorldPoint(t.origin),o=new H(H.SCALE,Object.assign(Object.assign({},t),{target:e,editor:this,worldOrigin:i}));this.editTool.onScaleWithDrag(o),this.emitEvent(o)}scaleOf(t,e,i=e,o){if(!this.mergeConfig.resizeable||this.element.locked)return;const{element:s}=this,n=s.getWorldPoint(y.getInnerOrigin(s,t));let r;if(this.multiple){const o=new p(s.worldTransform);s.scaleOf(t,e,i),r=new p(s.worldTransform).divide(o)}const h=new H(H.SCALE,{target:s,editor:this,worldOrigin:n,scaleX:e,scaleY:i,transform:r});this.editTool.onScale(h),this.emitEvent(h)}rotateOf(t,e){if(!this.mergeConfig.rotateable||this.element.locked)return;const{element:i}=this,o=i.getWorldPoint(y.getInnerOrigin(i,t));let s;if(this.multiple){const o=new p(i.worldTransform);i.rotateOf(t,e),s=new p(i.worldTransform).divide(o)}const n=new I(I.ROTATE,{target:i,editor:this,worldOrigin:o,rotation:e,transform:s});this.editTool.onRotate(n),this.emitEvent(n)}skewOf(t,e,i=0,o){if(!this.mergeConfig.skewable||this.element.locked)return;const{element:s}=this,n=s.getWorldPoint(y.getInnerOrigin(s,t));let r;if(this.multiple){const o=new p(s.worldTransform);s.skewOf(t,e,i),r=new p(s.worldTransform).divide(o)}const h=new C(C.SKEW,{target:s,editor:this,skewX:e,skewY:i,transform:r,worldOrigin:n});this.editTool.onSkew(h),this.emitEvent(h)}group(t){return this.multiple&&(this.target=mt.group(this.list,this.element,t),this.emitGroupEvent(_t.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach((t=>t.isBranch&&this.emitGroupEvent(_t.BEFORE_UNGROUP,t))),this.target=mt.ungroup(t),t.forEach((t=>t.isBranch&&this.emitGroupEvent(_t.UNGROUP,t)))),this.list}openGroup(t){this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(_t.OPEN,t)}closeGroup(t){this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(_t.CLOSE,t)}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:e}=t;this.editing&&(e=[],t.forEach((t=>this.list.every((e=>!y.hasParent(e,t)))&&e.push(t)))),e.forEach((t=>this.closeGroup(t)))}this.editing&&!this.selector.dragging&&this.checkDeepSelect()}checkDeepSelect(){let t,{list:e}=this;for(let i=0;i<e.length;i++)for(t=e[i].parent;t&&!t.hitChildren;)this.openGroup(t),t=t.parent}emitGroupEvent(t,e){const i=new _t(t,{editTarget:e});this.emitEvent(i),e.emitEvent(i)}openInnerEditor(t){if(t&&(this.target=t),this.single){const t=this.element,e=t.editInner;e&&wt.list[e]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[e]||wt.get(e,this),this.innerEditor.editTarget=t,this.emitInnerEvent(bt.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(bt.OPEN))}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(bt.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(bt.CLOSE),this.editTool.load(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,o=new bt(t,{editTarget:i,innerEditor:e});this.emitEvent(o),i.emitEvent(o)}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(mt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(mt.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{leafer:t}=this.list[0];this.targetEventIds=[t.on_(L.START,this.update,this),t.on_([M.HOLD,M.UP],(t=>{rt(this,t)})),t.on_(M.DOWN,this.editBox.onArrow,this.editBox)]}}removeTargetEvents(){const{targetEventIds:t}=this;t.length&&(this.off_(t),t.length=0)}destroy(){this.destroyed||(this.simulateTarget.destroy(),Object.values(this.editToolList).forEach((t=>t.destroy())),this.editToolList={},this.target=this.hoverTarget=this.simulateTarget=this.editTool=this.innerEditor=null,super.destroy())}}S([B((function(t,e){t.emitEvent(new P(P.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],kt.prototype,"hoverTarget",void 0),S([B((function(t,e){const{target:i}=t;i?t.leafList=i instanceof l?i:new l(i):t.leafList.reset(),t.emitEvent(new P(P.SELECT,{editor:t,value:i,oldValue:e})),t.checkOpenedGroups(),t.editing?t.waitLeafer((()=>{t.multiple&&function(t){const{simulateTarget:e,leafList:i}=t,{x:o,y:s,width:n,height:r}=(new a).setListWithFn(i.list,(t=>t.worldBoxBounds)),h=e.parent=i.list[0].leafer.zoomLayer,{scaleX:l,scaleY:d,e:c,f:g}=h.__world;e.reset({x:(o-c)/l,y:(s-g)/d,width:n/l,height:r/d})}(t),ht(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):(t.updateEditTool(),t.removeTargetEvents())}))],kt.prototype,"target",void 0);class xt{static registerInnerEditor(){wt.register(this)}get tag(){return"InnerEditor"}get editBox(){return this.editor.editBox}constructor(t){this.editor=t,this.create()}onCreate(){}create(){this.view=new n,this.onCreate()}onLoad(){}load(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!1,this.onLoad()}onUpdate(){}update(){this.onUpdate()}onUnload(){}unload(){this.editor.selector.hittable=this.editor.app.tree.hitChildren=!0,this.onUnload()}onDestroy(){}destroy(){this.onDestroy(),this.editor&&(this.view&&this.view.destroy(),this.eventIds&&this.editor.off_(this.eventIds),this.editor=this.view=this.eventIds=null)}}let Ot=class extends xt{static registerEditTool(){wt.register(this)}get tag(){return"EditTool"}onMove(t){const{moveX:e,moveY:i,editor:o}=t,{app:s,list:n}=o;s.lockLayout(),n.forEach((t=>{t.moveWorld(e,i)})),s.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:o,worldOrigin:s,editor:n}=t,{app:r,list:h}=n;r.lockLayout(),h.forEach((t=>{const r="scale"!==n.getEditSize(t);o?t.transformWorld(o,r):t.scaleOfWorld(s,e,i,r)})),r.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:o,editor:s}=t,{app:n,list:r}=s;n.lockLayout(),r.forEach((t=>{const n="scale"!==s.getEditSize(t);i?t.transformWorld(i,n):t.rotateOfWorld(o,e)})),n.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:o,worldOrigin:s,editor:n}=t,{app:r,list:h}=n;r.lockLayout(),h.forEach((t=>{const r="scale"!==n.getEditSize(t);o?t.transformWorld(o,r):t.skewOfWorld(s,e,i,r)})),r.unlockLayout()}load(){this.editBox.view.visible=!0,this.onLoad()}update(){const{editor:t,editBox:e}=this,{simulateTarget:i,element:o}=t;t.multiple&&i.parent.updateLayout();const{x:s,y:n,scaleX:r,scaleY:h,rotation:a,skewX:l,skewY:d,width:c,height:g}=o.getLayoutBounds("box",t,!0);e.set({x:s,y:n,scaleX:r,scaleY:h,rotation:a,skewX:l,skewY:d}),e.update({x:0,y:0,width:c,height:g}),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}};Ot=S([yt()],Ot);const{left:Mt,right:St}=g,{move:Tt,copy:Pt}=d;let Vt=class extends Ot{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(t){const{drag:e,direction:i,lockRatio:o,around:s}=t,n=t.target,r=i===Mt;if(n.pathInputed){const{path:t}=n.__,{from:i,to:h}=this.getFromToByPath(t);this.dragPoint(i,h,r,s,this.getInnerMove(n,e,o)),t[1]=i.x,t[2]=i.y,t[4]=h.x,t[5]=h.y,n.path=t}else if(n.points){const{points:t}=n,{from:i,to:h}=this.getFromToByPoints(t);this.dragPoint(i,h,r,s,this.getInnerMove(n,e,o)),t[0]=i.x,t[1]=i.y,t[2]=h.x,t[3]=h.y,n.points=t}else{const t=w(),{toPoint:i}=n;n.rotation=0,this.dragPoint(t,i,r,s,this.getInnerMove(n,e,o)),n.getLocalPointByInner(t,null,null,!0),n.getLocalPointByInner(i,null,null,!0),n.x=t.x,n.y=t.y,n.getInnerPointByLocal(i,null,null,!0),n.toPoint=i}}getInnerMove(t,e,i){const o=e.getInnerMove(t);return i&&(Math.abs(o.x)>Math.abs(o.y)?o.y=0:o.x=0),o}getFromToByPath(t){return{from:{x:t[1],y:t[2]},to:{x:t[4],y:t[5]}}}getFromToByPoints(t){return{from:{x:t[0],y:t[1]},to:{x:t[2],y:t[3]}}}dragPoint(t,e,i,o,s){const{x:n,y:r}=s;i?(Tt(t,n,r),o&&Tt(e,-n,-r)):(o&&Tt(t,-n,-r),Tt(e,n,r))}onSkew(t){}onUpdate(){const{editBox:t}=this,{rotatePoints:e,resizeLines:i,resizePoints:o,rect:s}=t,n=this.editor.element;let r,h;if(n.pathInputed?r=this.getFromToByPath(n.__.path):n.points&&(r=this.getFromToByPoints(n.__.points)),r){const{from:i,to:h}=r;n.innerToWorld(i,i,!1,t),n.innerToWorld(h,h,!1,t),s.pen.clearPath().moveTo(i.x,i.y).lineTo(h.x,h.y),Pt(o[7],i),Pt(e[7],i),Pt(o[3],h),Pt(e[3],h)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),h=t===Mt||t===St,o[t].visible=h,e[t].visible=!r&&h}};Vt=S([yt()],Vt),E.editor=function(t){return new kt(t)},o.setEditConfig=function(t){e(this.prototype,"editConfig",{get(){return"function"==typeof t?t(this):t}})},o.setEditOuter=function(t){e(this.prototype,"editOuter",{get(){return"string"==typeof t?t:t(this)}})},o.setEditInner=function(t){e(this.prototype,"editInner",{get(){return"string"==typeof t?t:t(this)}})};export{ct as EditBox,st as EditDataHelper,lt as EditPoint,j as EditSelect,X as EditSelectHelper,Ot as EditTool,wt as EditToolCreator,kt as Editor,P as EditorEvent,mt as EditorHelper,V as EditorMoveEvent,I as EditorRotateEvent,H as EditorScaleEvent,C as EditorSkewEvent,xt as InnerEditor,bt as InnerEditorEvent,Vt as LineEditTool,z as SelectArea,W as Stroker,yt as registerEditTool,Lt as registerInnerEditor};