@leafer-in/editor 1.7.0 → 1.9.0

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,79 +1,76 @@
1
- import { Event, defineKey, isNull, MatrixHelper, BoundsHelper, LeafBoundsHelper, getMatrixData, getBoundsData, UI, Paint, Group, Rect, Bounds, LeafList, Direction9, AroundHelper, MathHelper, PointHelper, Box, ResizeEvent, Text, Matrix, Debug, LeafHelper, PropertyEvent, DataHelper, Plugin, RenderEvent, getPointData, Creator, dataType } from '@leafer-ui/draw';
2
- import { PointerEvent, DragEvent, MoveEvent, ZoomEvent, KeyEvent, RotateEvent, useModule } from '@leafer-ui/core';
3
- import '@leafer-in/resize';
4
-
5
- /******************************************************************************
6
- Copyright (c) Microsoft Corporation.
7
-
8
- Permission to use, copy, modify, and/or distribute this software for any
9
- purpose with or without fee is hereby granted.
10
-
11
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
- PERFORMANCE OF THIS SOFTWARE.
18
- ***************************************************************************** */
19
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
20
-
21
-
22
- function __decorate(decorators, target, key, desc) {
23
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
24
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
25
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
26
- return c > 3 && r && Object.defineProperty(target, key, r), r;
27
- }
28
-
29
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
30
- var e = new Error(message);
31
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1
+ import { Event, isArray, defineKey, isNull, isObject, MatrixHelper, BoundsHelper, LeafBoundsHelper, getMatrixData, getBoundsData, UI, isString, Paint, Group, Rect, Bounds, LeafList, Direction9, AroundHelper, MathHelper, PointHelper, Box, isNumber, ResizeEvent, Text, Matrix, Debug, LeafHelper, PropertyEvent, isUndefined, DataHelper, Plugin, RenderEvent, getPointData, Creator, dataType } from "@leafer-ui/draw";
2
+
3
+ import { PointerEvent, DragEvent, MoveEvent, ZoomEvent, KeyEvent, RotateEvent, useModule } from "@leafer-ui/core";
4
+
5
+ import "@leafer-in/resize";
6
+
7
+ function __decorate(decorators, target, key, desc) {
8
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
10
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
11
+ }
12
+
13
+ typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
14
+ var e = new Error(message);
15
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
32
16
  };
33
17
 
34
18
  function toList(value) {
35
- return value ? (value instanceof Array ? value : [value]) : [];
19
+ return value ? isArray(value) ? value : [ value ] : [];
36
20
  }
21
+
37
22
  class EditorEvent extends Event {
38
- get list() { return toList(this.value); }
39
- get oldList() { return toList(this.oldValue); }
23
+ get list() {
24
+ return toList(this.value);
25
+ }
26
+ get oldList() {
27
+ return toList(this.oldValue);
28
+ }
40
29
  constructor(type, data) {
41
30
  super(type);
42
- if (data)
43
- Object.assign(this, data);
31
+ if (data) Object.assign(this, data);
44
32
  }
45
33
  }
46
- EditorEvent.BEFORE_SELECT = 'editor.before_select';
47
- EditorEvent.SELECT = 'editor.select';
48
- EditorEvent.AFTER_SELECT = 'editor.after_select';
49
- EditorEvent.BEFORE_HOVER = 'editor.before_hover';
50
- EditorEvent.HOVER = 'editor.hover';
34
+
35
+ EditorEvent.BEFORE_SELECT = "editor.before_select";
36
+
37
+ EditorEvent.SELECT = "editor.select";
38
+
39
+ EditorEvent.AFTER_SELECT = "editor.after_select";
40
+
41
+ EditorEvent.BEFORE_HOVER = "editor.before_hover";
42
+
43
+ EditorEvent.HOVER = "editor.hover";
51
44
 
52
45
  function targetAttr(fn) {
53
46
  return (target, key) => {
54
- const privateKey = '_' + key;
47
+ const privateKey = "_" + key;
55
48
  defineKey(target, key, {
56
- get() { return this[privateKey]; },
49
+ get() {
50
+ return this[privateKey];
51
+ },
57
52
  set(value) {
58
53
  const old = this[privateKey];
59
54
  if (old !== value) {
60
55
  if (this.config) {
61
- const isSelect = key === 'target';
56
+ const isSelect = key === "target";
62
57
  if (isSelect) {
63
- if (value instanceof Array && value.length > 1 && value[0].locked)
64
- value.splice(0, 1);
65
- const { beforeSelect } = this.config;
58
+ if (isArray(value) && value.length > 1 && value[0].locked) value.splice(0, 1);
59
+ if (this.single) this.element.syncEventer = null;
60
+ const {beforeSelect: beforeSelect} = this.config;
66
61
  if (beforeSelect) {
67
- const check = beforeSelect({ target: value });
68
- if (typeof check === 'object')
69
- value = check;
70
- else if (check === false)
71
- return;
62
+ const check = beforeSelect({
63
+ target: value
64
+ });
65
+ if (isObject(check)) value = check; else if (check === false) return;
72
66
  }
73
67
  }
74
68
  const type = isSelect ? EditorEvent.BEFORE_SELECT : EditorEvent.BEFORE_HOVER;
75
- if (this.hasEvent(type))
76
- this.emitEvent(new EditorEvent(type, { editor: this, value: value, oldValue: old }));
69
+ if (this.hasEvent(type)) this.emitEvent(new EditorEvent(type, {
70
+ editor: this,
71
+ value: value,
72
+ oldValue: old
73
+ }));
77
74
  }
78
75
  this[privateKey] = value, fn(this, old);
79
76
  }
@@ -81,20 +78,19 @@ function targetAttr(fn) {
81
78
  });
82
79
  };
83
80
  }
81
+
84
82
  function mergeConfigAttr() {
85
83
  return (target, key) => {
86
84
  defineKey(target, key, {
87
85
  get() {
88
- const { config, element, dragPoint } = this, mergeConfig = Object.assign({}, config);
89
- if (element && element.editConfig)
90
- Object.assign(mergeConfig, element.editConfig);
86
+ const {config: config, element: element, dragPoint: dragPoint, editBox: editBox} = this, mergeConfig = Object.assign({}, config);
87
+ if (element && element.editConfig) Object.assign(mergeConfig, element.editConfig);
88
+ if (editBox.config) Object.assign(mergeConfig, editBox.config);
91
89
  if (dragPoint) {
92
- if (dragPoint.editConfig)
93
- Object.assign(mergeConfig, dragPoint.editConfig);
94
- if (mergeConfig.editSize === 'font-size')
95
- mergeConfig.lockRatio = true;
96
- if (dragPoint.pointType === 'resize-rotate') {
97
- mergeConfig.around || (mergeConfig.around = 'center');
90
+ if (dragPoint.editConfig) Object.assign(mergeConfig, dragPoint.editConfig);
91
+ if (mergeConfig.editSize === "font-size") mergeConfig.lockRatio = true;
92
+ if (dragPoint.pointType === "resize-rotate") {
93
+ mergeConfig.around || (mergeConfig.around = "center");
98
94
  isNull(mergeConfig.lockRatio) && (mergeConfig.lockRatio = true);
99
95
  }
100
96
  }
@@ -104,43 +100,48 @@ function mergeConfigAttr() {
104
100
  };
105
101
  }
106
102
 
107
- const { abs } = Math;
108
- const { copy: copy$1, scale } = MatrixHelper;
109
- const { setListWithFn } = BoundsHelper;
110
- const { worldBounds } = LeafBoundsHelper;
103
+ const {abs: abs} = Math;
104
+
105
+ const {copy: copy$1, scale: scale} = MatrixHelper;
106
+
107
+ const {setListWithFn: setListWithFn} = BoundsHelper;
108
+
109
+ const {worldBounds: worldBounds} = LeafBoundsHelper;
110
+
111
111
  const matrix = getMatrixData();
112
+
112
113
  const bounds$1 = getBoundsData();
114
+
113
115
  class Stroker extends UI {
114
116
  constructor() {
115
117
  super();
116
118
  this.list = [];
117
119
  this.visible = 0;
118
120
  this.hittable = false;
119
- this.strokeAlign = 'center';
121
+ this.strokeAlign = "center";
120
122
  }
121
123
  setTarget(target, style) {
122
- this.set(style);
124
+ if (style) this.set(style);
123
125
  this.target = target;
124
126
  this.update();
125
127
  }
126
- update() {
127
- const { list } = this;
128
+ update(style) {
129
+ const {list: list} = this;
128
130
  if (list.length) {
129
131
  setListWithFn(bounds$1, list, worldBounds);
132
+ if (style) this.set(style);
130
133
  this.set(bounds$1);
131
134
  this.visible = true;
132
- }
133
- else
134
- this.visible = 0;
135
+ } else this.visible = 0;
135
136
  }
136
137
  __draw(canvas, options) {
137
- const { list } = this;
138
+ const {list: list} = this;
138
139
  if (list.length) {
139
140
  let leaf;
140
- const data = this.__, { stroke, strokeWidth, fill } = data, { bounds } = options;
141
+ const data = this.__, {stroke: stroke, strokeWidth: strokeWidth, fill: fill} = data, {bounds: bounds} = options;
141
142
  for (let i = 0; i < list.length; i++) {
142
143
  leaf = list[i];
143
- const { worldTransform, worldRenderBounds } = leaf;
144
+ const {worldTransform: worldTransform, worldRenderBounds: worldRenderBounds} = leaf;
144
145
  if (worldRenderBounds.width && worldRenderBounds.height && (!bounds || bounds.hit(worldRenderBounds, options.matrix))) {
145
146
  const aScaleX = abs(worldTransform.scaleX), aScaleY = abs(worldTransform.scaleY);
146
147
  copy$1(matrix, worldTransform);
@@ -150,22 +151,16 @@ class Stroker extends UI {
150
151
  canvas.setWorld(matrix, options.matrix);
151
152
  canvas.beginPath();
152
153
  data.strokeWidth = strokeWidth;
153
- const { x, y, width, height } = leaf.__layout.boxBounds;
154
+ const {x: x, y: y, width: width, height: height} = leaf.__layout.boxBounds;
154
155
  canvas.rect(x * aScaleX, y * aScaleY, width * aScaleX, height * aScaleY);
155
- }
156
- else {
156
+ } else {
157
157
  canvas.setWorld(matrix, options.matrix);
158
158
  canvas.beginPath();
159
- if (leaf.__.__useArrow)
160
- leaf.__drawPath(canvas);
161
- else
162
- leaf.__.__pathForRender ? leaf.__drawRenderPath(canvas) : leaf.__drawPathByBox(canvas);
159
+ if (leaf.__.__useArrow) leaf.__drawPath(canvas); else leaf.__.__pathForRender ? leaf.__drawRenderPath(canvas) : leaf.__drawPathByBox(canvas);
163
160
  data.strokeWidth = strokeWidth / abs(worldTransform.scaleX);
164
161
  }
165
- if (stroke)
166
- typeof stroke === 'string' ? Paint.stroke(stroke, this, canvas) : Paint.strokes(stroke, this, canvas);
167
- if (fill)
168
- typeof fill === 'string' ? Paint.fill(fill, this, canvas) : Paint.fills(fill, this, canvas);
162
+ if (stroke) isString(stroke) ? Paint.stroke(stroke, this, canvas) : Paint.strokes(stroke, this, canvas);
163
+ if (fill) isString(fill) ? Paint.fill(fill, this, canvas) : Paint.fills(fill, this, canvas);
169
164
  }
170
165
  }
171
166
  data.strokeWidth = strokeWidth;
@@ -176,28 +171,37 @@ class Stroker extends UI {
176
171
  super.destroy();
177
172
  }
178
173
  }
179
- __decorate([
180
- targetAttr(onTarget$1)
181
- ], Stroker.prototype, "target", void 0);
174
+
175
+ __decorate([ targetAttr(onTarget$1) ], Stroker.prototype, "target", void 0);
176
+
182
177
  function onTarget$1(stroker) {
183
178
  const value = stroker.target;
184
- stroker.list = value ? (value instanceof Array ? value : [value]) : [];
179
+ stroker.list = value ? isArray(value) ? value : [ value ] : [];
185
180
  }
186
181
 
187
182
  class SelectArea extends Group {
188
183
  constructor(data) {
189
184
  super(data);
190
- this.strokeArea = new Rect({ strokeAlign: 'center' });
191
- this.fillArea = new Rect();
185
+ this.strokeArea = new Rect({
186
+ strokeAlign: "center"
187
+ });
188
+ this.fillArea = new Rect;
192
189
  this.visible = 0;
193
190
  this.hittable = false;
194
191
  this.addMany(this.fillArea, this.strokeArea);
195
192
  }
196
193
  setStyle(style, userStyle) {
197
- const { visible, stroke, strokeWidth } = style;
194
+ const {visible: visible, stroke: stroke, strokeWidth: strokeWidth} = style;
198
195
  this.visible = visible;
199
- this.strokeArea.reset(Object.assign({ stroke, strokeWidth }, (userStyle || {})));
200
- this.fillArea.reset({ visible: userStyle ? false : true, fill: stroke, opacity: 0.2 });
196
+ this.strokeArea.reset(Object.assign({
197
+ stroke: stroke,
198
+ strokeWidth: strokeWidth
199
+ }, userStyle || {}));
200
+ this.fillArea.reset({
201
+ visible: userStyle ? false : true,
202
+ fill: stroke,
203
+ opacity: .2
204
+ });
201
205
  }
202
206
  setBounds(bounds) {
203
207
  this.strokeArea.set(bounds);
@@ -207,14 +211,15 @@ class SelectArea extends Group {
207
211
 
208
212
  const EditSelectHelper = {
209
213
  findOne(path) {
210
- return path.list.find((leaf) => leaf.editable);
214
+ return path.list.find(leaf => leaf.editable);
211
215
  },
212
216
  findByBounds(branch, bounds) {
213
217
  const list = [];
214
- eachFind([branch], list, bounds);
218
+ eachFind([ branch ], list, bounds);
215
219
  return list;
216
220
  }
217
221
  };
222
+
218
223
  function eachFind(children, list, bounds) {
219
224
  let child, data;
220
225
  for (let i = 0, len = children.length; i < len; i++) {
@@ -222,65 +227,72 @@ function eachFind(children, list, bounds) {
222
227
  if (data.hittable && data.visible && !data.locked && bounds.hit(child.__world)) {
223
228
  if (data.editable) {
224
229
  if (child.isBranch && !data.hitChildren) {
225
- if (data.hitSelf)
226
- list.push(child);
230
+ if (data.hitSelf) list.push(child);
227
231
  continue;
228
- }
229
- else if (child.isFrame) {
232
+ } else if (child.isFrame) {
230
233
  if (bounds.includes(child.__layout.boxBounds, child.__world)) {
231
234
  list.push(child);
232
235
  continue;
233
236
  }
234
- }
235
- else if (bounds.hit(child.__layout.boxBounds, child.__world) && data.hitSelf)
236
- list.push(child);
237
+ } else if (bounds.hit(child.__layout.boxBounds, child.__world) && data.hitSelf) list.push(child);
237
238
  }
238
- if (child.isBranch)
239
- eachFind(child.children, list, bounds);
239
+ if (child.isBranch) eachFind(child.children, list, bounds);
240
240
  }
241
241
  }
242
242
  }
243
243
 
244
- const { findOne, findByBounds } = EditSelectHelper;
244
+ const {findOne: findOne, findByBounds: findByBounds} = EditSelectHelper;
245
+
245
246
  class EditSelect extends Group {
246
- get dragging() { return !!this.originList; }
247
- get running() { const { editor } = this; return this.hittable && editor.visible && editor.hittable && editor.mergeConfig.selector; }
248
- get isMoveMode() { return this.app && this.app.interaction.moveMode; }
247
+ get dragging() {
248
+ return !!this.originList;
249
+ }
250
+ get running() {
251
+ const {editor: editor} = this;
252
+ return this.hittable && editor.visible && editor.hittable && editor.mergeConfig.selector;
253
+ }
254
+ get isMoveMode() {
255
+ return this.app && this.app.interaction.moveMode;
256
+ }
249
257
  constructor(editor) {
250
258
  super();
251
- this.hoverStroker = new Stroker();
252
- this.targetStroker = new Stroker();
253
- this.bounds = new Bounds();
254
- this.selectArea = new SelectArea();
259
+ this.hoverStroker = new Stroker;
260
+ this.targetStroker = new Stroker;
261
+ this.bounds = new Bounds;
262
+ this.selectArea = new SelectArea;
255
263
  this.__eventIds = [];
256
264
  this.editor = editor;
257
265
  this.addMany(this.targetStroker, this.hoverStroker, this.selectArea);
258
266
  this.__listenEvents();
259
267
  }
260
268
  onHover() {
261
- const { editor } = this;
269
+ const {editor: editor} = this;
262
270
  if (this.running && !this.dragging && !editor.dragging) {
263
- const { stroke, strokeWidth, hover, hoverStyle } = editor.mergeConfig;
264
- this.hoverStroker.setTarget(hover ? this.editor.hoverTarget : null, Object.assign({ stroke, strokeWidth }, (hoverStyle || {})));
265
- }
266
- else {
271
+ const {stroke: stroke, strokeWidth: strokeWidth, hover: hover, hoverStyle: hoverStyle} = editor.mergeConfig;
272
+ this.hoverStroker.setTarget(hover ? this.editor.hoverTarget : null, Object.assign({
273
+ stroke: stroke,
274
+ strokeWidth: strokeWidth
275
+ }, hoverStyle || {}));
276
+ } else {
267
277
  this.hoverStroker.target = null;
268
278
  }
269
279
  }
270
280
  onSelect() {
271
281
  if (this.running) {
272
- const { mergeConfig, list } = this.editor;
273
- const { stroke, strokeWidth, selectedStyle } = mergeConfig;
274
- this.targetStroker.setTarget(list, Object.assign({ stroke, strokeWidth: Math.max(1, strokeWidth / 2) }, (selectedStyle || {})));
282
+ this.targetStroker.setTarget(this.editor.list);
275
283
  this.hoverStroker.target = null;
276
284
  }
277
285
  }
278
286
  update() {
279
287
  this.hoverStroker.update();
280
- this.targetStroker.update();
288
+ const {stroke: stroke, strokeWidth: strokeWidth, selectedStyle: selectedStyle} = this.editor.mergedConfig;
289
+ this.targetStroker.update(Object.assign({
290
+ stroke: stroke,
291
+ strokeWidth: strokeWidth && Math.max(1, strokeWidth / 2)
292
+ }, selectedStyle || {}));
281
293
  }
282
294
  onPointerMove(e) {
283
- const { app, editor } = this;
295
+ const {app: app, editor: editor} = this;
284
296
  if (this.running && !this.isMoveMode && app.interaction.canHover && !app.interaction.dragging) {
285
297
  const find = this.findUI(e);
286
298
  editor.hoverTarget = editor.hasItem(find) ? null : find;
@@ -290,78 +302,66 @@ class EditSelect extends Group {
290
302
  }
291
303
  }
292
304
  onBeforeDown(e) {
293
- if (e.multiTouch)
294
- return;
295
- const { select } = this.editor.mergeConfig;
296
- if (select === 'press') {
305
+ if (e.multiTouch) return;
306
+ const {select: select} = this.editor.mergeConfig;
307
+ if (select === "press") {
297
308
  if (this.app.config.mobile) {
298
309
  this.waitSelect = () => this.checkAndSelect(e);
299
- }
300
- else {
310
+ } else {
301
311
  this.checkAndSelect(e);
302
312
  }
303
313
  }
304
314
  }
305
315
  onTap(e) {
306
- if (e.multiTouch)
307
- return;
308
- const { editor } = this;
309
- const { select } = editor.mergeConfig;
310
- if (select === 'tap')
311
- this.checkAndSelect(e);
312
- else if (this.waitSelect)
313
- this.waitSelect();
316
+ if (e.multiTouch) return;
317
+ const {editor: editor} = this;
318
+ const {select: select} = editor.mergeConfig;
319
+ if (select === "tap") this.checkAndSelect(e); else if (this.waitSelect) this.waitSelect();
314
320
  if (this.needRemoveItem) {
315
321
  editor.removeItem(this.needRemoveItem);
316
- }
317
- else if (this.isMoveMode) {
322
+ } else if (this.isMoveMode) {
318
323
  editor.target = null;
319
324
  }
320
325
  }
321
326
  checkAndSelect(e) {
322
327
  this.needRemoveItem = null;
323
328
  if (this.allowSelect(e)) {
324
- const { editor } = this;
329
+ const {editor: editor} = this;
325
330
  const find = this.findUI(e);
326
331
  if (find) {
327
332
  if (this.isMultipleSelect(e)) {
328
- if (editor.hasItem(find))
329
- this.needRemoveItem = find;
330
- else
331
- editor.addItem(find);
332
- }
333
- else {
333
+ if (editor.hasItem(find)) this.needRemoveItem = find; else editor.addItem(find);
334
+ } else {
334
335
  editor.target = find;
335
336
  }
336
- }
337
- else if (this.allow(e.target)) {
338
- if (!e.shiftKey)
339
- editor.target = null;
337
+ } else if (this.allow(e.target)) {
338
+ if (!this.isHoldMultipleSelectKey(e)) editor.target = null;
340
339
  }
341
340
  }
342
341
  }
343
342
  onDragStart(e) {
344
- if (e.multiTouch)
345
- return;
346
- if (this.waitSelect)
347
- this.waitSelect();
343
+ if (e.multiTouch) return;
344
+ if (this.waitSelect) this.waitSelect();
348
345
  if (this.allowDrag(e)) {
349
- const { editor } = this;
350
- const { stroke, area } = editor.mergeConfig;
351
- const { x, y } = e.getInnerPoint(this);
346
+ const {editor: editor} = this;
347
+ const {stroke: stroke, area: area} = editor.mergeConfig;
348
+ const {x: x, y: y} = e.getInnerPoint(this);
352
349
  this.bounds.set(x, y);
353
- this.selectArea.setStyle({ visible: true, stroke, x, y }, area);
350
+ this.selectArea.setStyle({
351
+ visible: true,
352
+ stroke: stroke,
353
+ x: x,
354
+ y: y
355
+ }, area);
354
356
  this.selectArea.setBounds(this.bounds.get());
355
357
  this.originList = editor.leafList.clone();
356
358
  }
357
359
  }
358
360
  onDrag(e) {
359
- if (e.multiTouch)
360
- return;
361
- if (this.editor.dragging)
362
- return this.onDragEnd(e);
361
+ if (e.multiTouch) return;
362
+ if (this.editor.dragging) return this.onDragEnd(e);
363
363
  if (this.dragging) {
364
- const { editor } = this;
364
+ const {editor: editor} = this;
365
365
  const total = e.getInnerTotal(this);
366
366
  const dragBounds = this.bounds.clone().unsign();
367
367
  const list = new LeafList(findByBounds(editor.app, dragBounds));
@@ -370,28 +370,27 @@ class EditSelect extends Group {
370
370
  this.selectArea.setBounds(dragBounds.get());
371
371
  if (list.length) {
372
372
  const selectList = [];
373
- this.originList.forEach(item => { if (!list.has(item))
374
- selectList.push(item); });
375
- list.forEach(item => { if (!this.originList.has(item))
376
- selectList.push(item); });
373
+ this.originList.forEach(item => {
374
+ if (!list.has(item)) selectList.push(item);
375
+ });
376
+ list.forEach(item => {
377
+ if (!this.originList.has(item)) selectList.push(item);
378
+ });
377
379
  if (selectList.length !== editor.list.length || editor.list.some((child, index) => child !== selectList[index])) {
378
380
  editor.target = selectList;
379
381
  }
380
- }
381
- else {
382
+ } else {
382
383
  editor.target = this.originList.list;
383
384
  }
384
385
  }
385
386
  }
386
387
  onDragEnd(e) {
387
- if (e.multiTouch)
388
- return;
389
- if (this.dragging)
390
- this.originList = null, this.selectArea.visible = 0;
388
+ if (e.multiTouch) return;
389
+ if (this.dragging) this.originList = null, this.selectArea.visible = 0;
391
390
  }
392
391
  onAutoMove(e) {
393
392
  if (this.dragging) {
394
- const { x, y } = e.getLocalMove(this);
393
+ const {x: x, y: y} = e.getLocalMove(this);
395
394
  this.bounds.x += x;
396
395
  this.bounds.y += y;
397
396
  }
@@ -400,11 +399,10 @@ class EditSelect extends Group {
400
399
  return target.leafer !== this.editor.leafer;
401
400
  }
402
401
  allowDrag(e) {
403
- const { boxSelect, multipleSelect } = this.editor.mergeConfig;
402
+ const {boxSelect: boxSelect, multipleSelect: multipleSelect} = this.editor.mergeConfig;
404
403
  if (this.running && (multipleSelect && boxSelect) && !e.target.draggable) {
405
- return (!this.editor.editing && this.allow(e.target)) || (e.shiftKey && !findOne(e.path));
406
- }
407
- else {
404
+ return !this.editor.editing && this.allow(e.target) || this.isHoldMultipleSelectKey(e) && !findOne(e.path);
405
+ } else {
408
406
  return false;
409
407
  }
410
408
  }
@@ -412,37 +410,31 @@ class EditSelect extends Group {
412
410
  return this.running && !this.isMoveMode && !e.middle;
413
411
  }
414
412
  findDeepOne(e) {
415
- const options = { exclude: new LeafList(this.editor.editBox.rect) };
413
+ const options = {
414
+ exclude: new LeafList(this.editor.editBox.rect)
415
+ };
416
416
  return findOne(e.target.leafer.interaction.findPath(e, options));
417
417
  }
418
418
  findUI(e) {
419
419
  return this.isMultipleSelect(e) ? this.findDeepOne(e) : findOne(e.path);
420
420
  }
421
421
  isMultipleSelect(e) {
422
- const { multipleSelect, continuousSelect } = this.editor.mergeConfig;
423
- return multipleSelect && (e.shiftKey || continuousSelect);
422
+ const {multipleSelect: multipleSelect, continuousSelect: continuousSelect} = this.editor.mergeConfig;
423
+ return multipleSelect && (this.isHoldMultipleSelectKey(e) || continuousSelect);
424
+ }
425
+ isHoldMultipleSelectKey(e) {
426
+ const {multipleSelectKey: multipleSelectKey} = this.editor.mergedConfig;
427
+ if (multipleSelectKey) return e.isHoldKeys(multipleSelectKey);
428
+ return e.shiftKey;
424
429
  }
425
430
  __listenEvents() {
426
- const { editor } = this;
431
+ const {editor: editor} = this;
427
432
  editor.waitLeafer(() => {
428
- const { app } = editor;
433
+ const {app: app} = editor;
429
434
  app.selector.proxy = editor;
430
- this.__eventIds = [
431
- editor.on_([
432
- [EditorEvent.HOVER, this.onHover, this],
433
- [EditorEvent.SELECT, this.onSelect, this]
434
- ]),
435
- app.on_([
436
- [PointerEvent.MOVE, this.onPointerMove, this],
437
- [PointerEvent.BEFORE_DOWN, this.onBeforeDown, this],
438
- [PointerEvent.TAP, this.onTap, this],
439
- [DragEvent.START, this.onDragStart, this, true],
440
- [DragEvent.DRAG, this.onDrag, this],
441
- [DragEvent.END, this.onDragEnd, this],
442
- [MoveEvent.MOVE, this.onAutoMove, this],
443
- [[ZoomEvent.ZOOM, MoveEvent.MOVE], () => { this.editor.hoverTarget = null; }],
444
- ])
445
- ];
435
+ this.__eventIds = [ editor.on_([ [ EditorEvent.HOVER, this.onHover, this ], [ EditorEvent.SELECT, this.onSelect, this ] ]), app.on_([ [ PointerEvent.MOVE, this.onPointerMove, this ], [ PointerEvent.BEFORE_DOWN, this.onBeforeDown, this ], [ PointerEvent.TAP, this.onTap, this ], [ DragEvent.START, this.onDragStart, this, true ], [ DragEvent.DRAG, this.onDrag, this ], [ DragEvent.END, this.onDragEnd, this ], [ MoveEvent.MOVE, this.onAutoMove, this ], [ [ ZoomEvent.ZOOM, MoveEvent.MOVE ], () => {
436
+ this.editor.hoverTarget = null;
437
+ } ] ]) ];
446
438
  });
447
439
  }
448
440
  __removeListenEvents() {
@@ -455,14 +447,17 @@ class EditSelect extends Group {
455
447
  }
456
448
  }
457
449
 
458
- const { topLeft, top, topRight, right: right$1, bottomRight, bottom, bottomLeft, left: left$1 } = Direction9;
459
- const { toPoint } = AroundHelper;
460
- const { within } = MathHelper;
450
+ const {topLeft: topLeft, top: top, topRight: topRight, right: right$1, bottomRight: bottomRight, bottom: bottom, bottomLeft: bottomLeft, left: left$1} = Direction9;
451
+
452
+ const {toPoint: toPoint} = AroundHelper;
453
+
454
+ const {within: within} = MathHelper;
455
+
461
456
  const EditDataHelper = {
462
457
  getScaleData(target, startBounds, direction, totalMove, lockRatio, around, flipable, scaleMode) {
463
458
  let align, origin = {}, scaleX = 1, scaleY = 1;
464
- const { boxBounds, widthRange, heightRange, dragBounds, worldBoxBounds } = target;
465
- const { width, height } = startBounds;
459
+ const {boxBounds: boxBounds, widthRange: widthRange, heightRange: heightRange, dragBounds: dragBounds, worldBoxBounds: worldBoxBounds} = target;
460
+ const {width: width, height: height} = startBounds;
466
461
  if (around) {
467
462
  totalMove.x *= 2;
468
463
  totalMove.y *= 2;
@@ -480,88 +475,92 @@ const EditDataHelper = {
480
475
  const bottomScale = (totalMove.y + height) / height;
481
476
  const leftScale = (-totalMove.x + width) / width;
482
477
  switch (direction) {
483
- case top:
484
- scaleY = topScale;
485
- align = 'bottom';
486
- break;
487
- case right$1:
488
- scaleX = rightScale;
489
- align = 'left';
490
- break;
491
- case bottom:
492
- scaleY = bottomScale;
493
- align = 'top';
494
- break;
495
- case left$1:
496
- scaleX = leftScale;
497
- align = 'right';
498
- break;
499
- case topLeft:
500
- scaleY = topScale;
501
- scaleX = leftScale;
502
- align = 'bottom-right';
503
- break;
504
- case topRight:
505
- scaleY = topScale;
506
- scaleX = rightScale;
507
- align = 'bottom-left';
508
- break;
509
- case bottomRight:
510
- scaleY = bottomScale;
511
- scaleX = rightScale;
512
- align = 'top-left';
513
- break;
514
- case bottomLeft:
515
- scaleY = bottomScale;
516
- scaleX = leftScale;
517
- align = 'top-right';
478
+ case top:
479
+ scaleY = topScale;
480
+ align = "bottom";
481
+ break;
482
+
483
+ case right$1:
484
+ scaleX = rightScale;
485
+ align = "left";
486
+ break;
487
+
488
+ case bottom:
489
+ scaleY = bottomScale;
490
+ align = "top";
491
+ break;
492
+
493
+ case left$1:
494
+ scaleX = leftScale;
495
+ align = "right";
496
+ break;
497
+
498
+ case topLeft:
499
+ scaleY = topScale;
500
+ scaleX = leftScale;
501
+ align = "bottom-right";
502
+ break;
503
+
504
+ case topRight:
505
+ scaleY = topScale;
506
+ scaleX = rightScale;
507
+ align = "bottom-left";
508
+ break;
509
+
510
+ case bottomRight:
511
+ scaleY = bottomScale;
512
+ scaleX = rightScale;
513
+ align = "top-left";
514
+ break;
515
+
516
+ case bottomLeft:
517
+ scaleY = bottomScale;
518
+ scaleX = leftScale;
519
+ align = "top-right";
518
520
  }
519
521
  if (lockRatio) {
520
- if (lockRatio === 'corner' && direction % 2) {
522
+ if (lockRatio === "corner" && direction % 2) {
521
523
  lockRatio = false;
522
- }
523
- else {
524
+ } else {
524
525
  let scale;
525
526
  switch (direction) {
526
- case top:
527
- case bottom:
528
- scale = scaleY;
529
- break;
530
- case left$1:
531
- case right$1:
532
- scale = scaleX;
533
- break;
534
- default:
535
- scale = Math.sqrt(Math.abs(scaleX * scaleY));
527
+ case top:
528
+ case bottom:
529
+ scale = scaleY;
530
+ break;
531
+
532
+ case left$1:
533
+ case right$1:
534
+ scale = scaleX;
535
+ break;
536
+
537
+ default:
538
+ scale = Math.sqrt(Math.abs(scaleX * scaleY));
536
539
  }
537
540
  scaleX = scaleX < 0 ? -scale : scale;
538
541
  scaleY = scaleY < 0 ? -scale : scale;
539
542
  }
540
543
  }
541
544
  const useScaleX = scaleX !== 1, useScaleY = scaleY !== 1;
542
- if (useScaleX)
543
- scaleX /= changedScaleX;
544
- if (useScaleY)
545
- scaleY /= changedScaleY;
545
+ if (useScaleX) scaleX /= changedScaleX;
546
+ if (useScaleY) scaleY /= changedScaleY;
546
547
  if (!flipable) {
547
- const { worldTransform } = target;
548
- if (scaleX < 0)
549
- scaleX = 1 / boxBounds.width / worldTransform.scaleX;
550
- if (scaleY < 0)
551
- scaleY = 1 / boxBounds.height / worldTransform.scaleY;
548
+ const {worldTransform: worldTransform} = target;
549
+ if (scaleX < 0) scaleX = 1 / boxBounds.width / worldTransform.scaleX;
550
+ if (scaleY < 0) scaleY = 1 / boxBounds.height / worldTransform.scaleY;
552
551
  }
553
552
  toPoint(around || align, boxBounds, origin, true);
554
553
  if (dragBounds) {
555
- const allowBounds = dragBounds === 'parent' ? target.parent.boxBounds : dragBounds;
556
- const localBounds = new Bounds(target.__localBoxBounds);
557
- localBounds.scaleOf(target.getLocalPointByInner(origin), scaleX, scaleY);
558
- if (!BoundsHelper.includes(allowBounds, localBounds)) {
559
- const realBounds = localBounds.getIntersect(allowBounds);
560
- const fitScaleX = realBounds.width / localBounds.width, fitScaleY = realBounds.height / localBounds.height;
561
- if (useScaleX)
562
- scaleX *= fitScaleX;
563
- if (useScaleY)
564
- scaleY *= fitScaleY;
554
+ const allowBounds = dragBounds === "parent" ? target.parent.boxBounds : dragBounds;
555
+ const childBounds = new Bounds(target.__localBoxBounds);
556
+ if (BoundsHelper.includes(new Bounds(allowBounds).spread(.1), childBounds)) {
557
+ childBounds.scaleOf(target.getLocalPointByInner(origin), scaleX, scaleY);
558
+ if (!BoundsHelper.includes(allowBounds, childBounds)) {
559
+ const realBounds = childBounds.getIntersect(allowBounds);
560
+ const fitScaleX = realBounds.width / childBounds.width, fitScaleY = realBounds.height / childBounds.height;
561
+ if (useScaleX) scaleX *= fitScaleX;
562
+ if (useScaleY) scaleY *= fitScaleY;
563
+ }
565
564
  }
566
565
  }
567
566
  if (useScaleX && widthRange) {
@@ -572,123 +571,165 @@ const EditDataHelper = {
572
571
  const nowHeight = boxBounds.height * target.scaleY;
573
572
  scaleY = within(nowHeight * scaleY, heightRange) / nowHeight;
574
573
  }
575
- if (useScaleX && Math.abs(scaleX * worldBoxBounds.width) < 1)
576
- scaleX = (scaleX < 0 ? -1 : 1) / worldBoxBounds.width;
577
- if (useScaleY && Math.abs(scaleY * worldBoxBounds.height) < 1)
578
- scaleY = (scaleY < 0 ? -1 : 1) / worldBoxBounds.height;
579
- if (lockRatio && scaleX !== scaleY)
580
- scaleY = scaleX = Math.min(scaleX, scaleY);
581
- return { origin, scaleX, scaleY, direction, lockRatio, around };
574
+ if (useScaleX && Math.abs(scaleX * worldBoxBounds.width) < 1) scaleX = (scaleX < 0 ? -1 : 1) / worldBoxBounds.width;
575
+ if (useScaleY && Math.abs(scaleY * worldBoxBounds.height) < 1) scaleY = (scaleY < 0 ? -1 : 1) / worldBoxBounds.height;
576
+ if (lockRatio && scaleX !== scaleY) scaleY = scaleX = Math.min(scaleX, scaleY);
577
+ return {
578
+ origin: origin,
579
+ scaleX: scaleX,
580
+ scaleY: scaleY,
581
+ direction: direction,
582
+ lockRatio: lockRatio,
583
+ around: around
584
+ };
582
585
  },
583
586
  getRotateData(target, direction, current, last, around) {
584
587
  let align, origin = {};
585
588
  switch (direction) {
586
- case topLeft:
587
- align = 'bottom-right';
588
- break;
589
- case topRight:
590
- align = 'bottom-left';
591
- break;
592
- case bottomRight:
593
- align = 'top-left';
594
- break;
595
- case bottomLeft:
596
- align = 'top-right';
597
- break;
598
- default:
599
- align = 'center';
589
+ case topLeft:
590
+ align = "bottom-right";
591
+ break;
592
+
593
+ case topRight:
594
+ align = "bottom-left";
595
+ break;
596
+
597
+ case bottomRight:
598
+ align = "top-left";
599
+ break;
600
+
601
+ case bottomLeft:
602
+ align = "top-right";
603
+ break;
604
+
605
+ default:
606
+ align = "center";
600
607
  }
601
608
  toPoint(around || align, target.boxBounds, origin, true);
602
- return { origin, rotation: PointHelper.getRotation(last, target.getWorldPointByBox(origin), current) };
609
+ return {
610
+ origin: origin,
611
+ rotation: PointHelper.getRotation(last, target.getWorldPointByBox(origin), current)
612
+ };
603
613
  },
604
614
  getSkewData(bounds, direction, move, around) {
605
615
  let align, origin = {}, skewX = 0, skewY = 0;
606
616
  let last;
607
617
  switch (direction) {
608
- case top:
609
- case topLeft:
610
- last = { x: 0.5, y: 0 };
611
- align = 'bottom';
612
- skewX = 1;
613
- break;
614
- case bottom:
615
- case bottomRight:
616
- last = { x: 0.5, y: 1 };
617
- align = 'top';
618
- skewX = 1;
619
- break;
620
- case left$1:
621
- case bottomLeft:
622
- last = { x: 0, y: 0.5 };
623
- align = 'right';
624
- skewY = 1;
625
- break;
626
- case right$1:
627
- case topRight:
628
- last = { x: 1, y: 0.5 };
629
- align = 'left';
630
- skewY = 1;
631
- }
632
- const { width, height } = bounds;
618
+ case top:
619
+ case topLeft:
620
+ last = {
621
+ x: .5,
622
+ y: 0
623
+ };
624
+ align = "bottom";
625
+ skewX = 1;
626
+ break;
627
+
628
+ case bottom:
629
+ case bottomRight:
630
+ last = {
631
+ x: .5,
632
+ y: 1
633
+ };
634
+ align = "top";
635
+ skewX = 1;
636
+ break;
637
+
638
+ case left$1:
639
+ case bottomLeft:
640
+ last = {
641
+ x: 0,
642
+ y: .5
643
+ };
644
+ align = "right";
645
+ skewY = 1;
646
+ break;
647
+
648
+ case right$1:
649
+ case topRight:
650
+ last = {
651
+ x: 1,
652
+ y: .5
653
+ };
654
+ align = "left";
655
+ skewY = 1;
656
+ }
657
+ const {width: width, height: height} = bounds;
633
658
  last.x = last.x * width;
634
659
  last.y = last.y * height;
635
660
  toPoint(around || align, bounds, origin, true);
636
- const rotation = PointHelper.getRotation(last, origin, { x: last.x + (skewX ? move.x : 0), y: last.y + (skewY ? move.y : 0) });
661
+ const rotation = PointHelper.getRotation(last, origin, {
662
+ x: last.x + (skewX ? move.x : 0),
663
+ y: last.y + (skewY ? move.y : 0)
664
+ });
637
665
  skewX ? skewX = -rotation : skewY = rotation;
638
- return { origin, skewX, skewY };
666
+ return {
667
+ origin: origin,
668
+ skewX: skewX,
669
+ skewY: skewY
670
+ };
639
671
  },
640
672
  getAround(around, altKey) {
641
- return (altKey && !around) ? 'center' : around;
673
+ return altKey && !around ? "center" : around;
642
674
  },
643
675
  getRotateDirection(direction, rotation, totalDirection = 8) {
644
676
  direction = (direction + Math.round(rotation / (360 / totalDirection))) % totalDirection;
645
- if (direction < 0)
646
- direction += totalDirection;
677
+ if (direction < 0) direction += totalDirection;
647
678
  return direction;
648
679
  },
649
680
  getFlipDirection(direction, flipedX, flipedY) {
650
681
  if (flipedX) {
651
682
  switch (direction) {
652
- case left$1:
653
- direction = right$1;
654
- break;
655
- case topLeft:
656
- direction = topRight;
657
- break;
658
- case bottomLeft:
659
- direction = bottomRight;
660
- break;
661
- case right$1:
662
- direction = left$1;
663
- break;
664
- case topRight:
665
- direction = topLeft;
666
- break;
667
- case bottomRight:
668
- direction = bottomLeft;
669
- break;
683
+ case left$1:
684
+ direction = right$1;
685
+ break;
686
+
687
+ case topLeft:
688
+ direction = topRight;
689
+ break;
690
+
691
+ case bottomLeft:
692
+ direction = bottomRight;
693
+ break;
694
+
695
+ case right$1:
696
+ direction = left$1;
697
+ break;
698
+
699
+ case topRight:
700
+ direction = topLeft;
701
+ break;
702
+
703
+ case bottomRight:
704
+ direction = bottomLeft;
705
+ break;
670
706
  }
671
707
  }
672
708
  if (flipedY) {
673
709
  switch (direction) {
674
- case top:
675
- direction = bottom;
676
- break;
677
- case topLeft:
678
- direction = bottomLeft;
679
- break;
680
- case topRight:
681
- direction = bottomRight;
682
- break;
683
- case bottom:
684
- direction = top;
685
- break;
686
- case bottomLeft:
687
- direction = topLeft;
688
- break;
689
- case bottomRight:
690
- direction = topRight;
691
- break;
710
+ case top:
711
+ direction = bottom;
712
+ break;
713
+
714
+ case topLeft:
715
+ direction = bottomLeft;
716
+ break;
717
+
718
+ case topRight:
719
+ direction = bottomRight;
720
+ break;
721
+
722
+ case bottom:
723
+ direction = top;
724
+ break;
725
+
726
+ case bottomLeft:
727
+ direction = topLeft;
728
+ break;
729
+
730
+ case bottomRight:
731
+ direction = topRight;
732
+ break;
692
733
  }
693
734
  }
694
735
  return direction;
@@ -696,41 +737,43 @@ const EditDataHelper = {
696
737
  };
697
738
 
698
739
  const cacheCursors = {};
699
- function updateCursor(editBox, e) {
700
- const { enterPoint: point } = editBox;
701
- if (!point || !editBox.editor.editing || !editBox.visible)
702
- return;
703
- if (point.name === 'circle')
704
- return;
705
- if (point.pointType === 'button') {
706
- if (!point.cursor)
707
- point.cursor = 'pointer';
740
+
741
+ function updatePointCursor(editBox, e) {
742
+ const {enterPoint: point, dragging: dragging, skewing: skewing, resizing: resizing, flippedX: flippedX, flippedY: flippedY} = editBox;
743
+ if (!point || !editBox.editor.editing || !editBox.canUse) return;
744
+ if (point.name === "circle") return;
745
+ if (point.pointType === "button") {
746
+ if (!point.cursor) point.cursor = "pointer";
708
747
  return;
709
748
  }
710
- let { rotation, flippedX, flippedY } = editBox;
711
- const { pointType } = point, { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editBox.mergeConfig;
712
- let showResize = pointType.includes('resize');
713
- if (showResize && rotateable && (e.metaKey || e.ctrlKey || !resizeable))
714
- showResize = false;
715
- const showSkew = skewable && !showResize && (point.name === 'resize-line' || pointType === 'skew');
716
- const cursor = showSkew ? skewCursor : (showResize ? resizeCursor : rotateCursor);
749
+ let {rotation: rotation} = editBox;
750
+ const {pointType: pointType} = point, {resizeCursor: resizeCursor, rotateCursor: rotateCursor, skewCursor: skewCursor, resizeable: resizeable, rotateable: rotateable, skewable: skewable} = editBox.mergeConfig;
751
+ let showResize = pointType.includes("resize");
752
+ if (showResize && rotateable && (editBox.isHoldRotateKey(e) || !resizeable)) showResize = false;
753
+ const showSkew = skewable && !showResize && (point.name === "resize-line" || pointType === "skew");
754
+ const cursor = dragging ? skewing ? skewCursor : resizing ? resizeCursor : rotateCursor : showSkew ? skewCursor : showResize ? resizeCursor : rotateCursor;
717
755
  rotation += (EditDataHelper.getFlipDirection(point.direction, flippedX, flippedY) + 1) * 45;
718
756
  rotation = Math.round(MathHelper.formatRotation(rotation, true) / 2) * 2;
719
- const { url, x, y } = cursor;
757
+ const {url: url, x: x, y: y} = cursor;
720
758
  const key = url + rotation;
721
759
  if (cacheCursors[key]) {
722
760
  point.cursor = cacheCursors[key];
723
- }
724
- else {
725
- cacheCursors[key] = point.cursor = { url: toDataURL(url, rotation), x, y };
761
+ } else {
762
+ cacheCursors[key] = point.cursor = {
763
+ url: toDataURL(url, rotation),
764
+ x: x,
765
+ y: y
766
+ };
726
767
  }
727
768
  }
769
+
728
770
  function updateMoveCursor(editBox) {
729
- const { moveCursor, moveable } = editBox.mergeConfig;
730
- editBox.rect.cursor = moveable ? moveCursor : undefined;
771
+ const {moveCursor: moveCursor, moveable: moveable} = editBox.mergeConfig;
772
+ if (editBox.canUse) editBox.rect.cursor = moveable ? moveCursor : undefined;
731
773
  }
774
+
732
775
  function toDataURL(svg, rotation) {
733
- return '"data:image/svg+xml,' + encodeURIComponent(svg.replace('{{rotation}}', rotation.toString())) + '"';
776
+ return '"data:image/svg+xml,' + encodeURIComponent(svg.replace("{{rotation}}", rotation.toString())) + '"';
734
777
  }
735
778
 
736
779
  class EditPoint extends Box {
@@ -740,27 +783,70 @@ class EditPoint extends Box {
740
783
  }
741
784
  }
742
785
 
743
- const fourDirection = ['top', 'right', 'bottom', 'left'], editConfig = undefined;
786
+ const fourDirection = [ "top", "right", "bottom", "left" ], editConfig = undefined;
787
+
744
788
  class EditBox extends Group {
745
789
  get mergeConfig() {
746
- const { config } = this, { mergeConfig } = this.editor;
747
- return this.mergedConfig = config ? Object.assign(Object.assign({}, mergeConfig), config) : mergeConfig;
748
- }
749
- get target() { return this._target || this.editor.element; }
750
- set target(target) { this._target = target; }
751
- get single() { return !!this._target || this.editor.single; }
752
- get transformTool() { return this._transformTool || this.editor; }
753
- set transformTool(tool) { this._transformTool = tool; }
754
- get flipped() { return this.flippedX || this.flippedY; }
755
- get flippedX() { return this.scaleX < 0; }
756
- get flippedY() { return this.scaleY < 0; }
757
- get flippedOne() { return this.scaleX * this.scaleY < 0; }
790
+ const {config: config} = this, {mergeConfig: mergeConfig, editBox: editBox} = this.editor;
791
+ return this.mergedConfig = config && editBox !== this ? Object.assign(Object.assign({}, mergeConfig), config) : mergeConfig;
792
+ }
793
+ get target() {
794
+ return this._target || this.editor.element;
795
+ }
796
+ set target(target) {
797
+ this._target = target;
798
+ }
799
+ get single() {
800
+ return !!this._target || this.editor.single;
801
+ }
802
+ get transformTool() {
803
+ return this._transformTool || this.editor;
804
+ }
805
+ set transformTool(tool) {
806
+ this._transformTool = tool;
807
+ }
808
+ get flipped() {
809
+ return this.flippedX || this.flippedY;
810
+ }
811
+ get flippedX() {
812
+ return this.scaleX < 0;
813
+ }
814
+ get flippedY() {
815
+ return this.scaleY < 0;
816
+ }
817
+ get flippedOne() {
818
+ return this.scaleX * this.scaleY < 0;
819
+ }
820
+ get canUse() {
821
+ return this.visible && this.view.visible;
822
+ }
823
+ get canGesture() {
824
+ if (!this.canUse) return false;
825
+ const {moveable: moveable, resizeable: resizeable, rotateable: rotateable} = this.mergeConfig;
826
+ return isString(moveable) || isString(resizeable) || isString(rotateable);
827
+ }
758
828
  constructor(editor) {
759
829
  super();
760
- this.view = new Group();
761
- this.rect = new Box({ name: 'rect', hitFill: 'all', hitStroke: 'none', strokeAlign: 'center', hitRadius: 5 });
762
- this.circle = new EditPoint({ name: 'circle', strokeAlign: 'center', around: 'center', cursor: 'crosshair', hitRadius: 5 });
763
- this.buttons = new Group({ around: 'center', hitSelf: false, visible: 0 });
830
+ this.view = new Group;
831
+ this.rect = new Box({
832
+ name: "rect",
833
+ hitFill: "all",
834
+ hitStroke: "none",
835
+ strokeAlign: "center",
836
+ hitRadius: 5
837
+ });
838
+ this.circle = new EditPoint({
839
+ name: "circle",
840
+ strokeAlign: "center",
841
+ around: "center",
842
+ cursor: "crosshair",
843
+ hitRadius: 5
844
+ });
845
+ this.buttons = new Group({
846
+ around: "center",
847
+ hitSelf: false,
848
+ visible: 0
849
+ });
764
850
  this.resizePoints = [];
765
851
  this.rotatePoints = [];
766
852
  this.resizeLines = [];
@@ -773,259 +859,325 @@ class EditBox extends Group {
773
859
  }
774
860
  create() {
775
861
  let rotatePoint, resizeLine, resizePoint;
776
- const { view, resizePoints, rotatePoints, resizeLines, rect, circle, buttons } = this;
777
- const arounds = ['bottom-right', 'bottom', 'bottom-left', 'left', 'top-left', 'top', 'top-right', 'right'];
862
+ const {view: view, resizePoints: resizePoints, rotatePoints: rotatePoints, resizeLines: resizeLines, rect: rect, circle: circle, buttons: buttons} = this;
863
+ const arounds = [ "bottom-right", "bottom", "bottom-left", "left", "top-left", "top", "top-right", "right" ];
778
864
  for (let i = 0; i < 8; i++) {
779
- rotatePoint = new EditPoint({ name: 'rotate-point', around: arounds[i], width: 15, height: 15, hitFill: "all" });
865
+ rotatePoint = new EditPoint({
866
+ name: "rotate-point",
867
+ around: arounds[i],
868
+ width: 15,
869
+ height: 15,
870
+ hitFill: "all"
871
+ });
780
872
  rotatePoints.push(rotatePoint);
781
- this.listenPointEvents(rotatePoint, 'rotate', i);
873
+ this.listenPointEvents(rotatePoint, "rotate", i);
782
874
  if (i % 2) {
783
- resizeLine = new EditPoint({ name: 'resize-line', around: 'center', width: 10, height: 10, hitFill: "all" });
875
+ resizeLine = new EditPoint({
876
+ name: "resize-line",
877
+ around: "center",
878
+ width: 10,
879
+ height: 10,
880
+ hitFill: "all"
881
+ });
784
882
  resizeLines.push(resizeLine);
785
- this.listenPointEvents(resizeLine, 'resize', i);
883
+ this.listenPointEvents(resizeLine, "resize", i);
786
884
  }
787
- resizePoint = new EditPoint({ name: 'resize-point', hitRadius: 5 });
885
+ resizePoint = new EditPoint({
886
+ name: "resize-point",
887
+ hitRadius: 5
888
+ });
788
889
  resizePoints.push(resizePoint);
789
- this.listenPointEvents(resizePoint, 'resize', i);
890
+ this.listenPointEvents(resizePoint, "resize", i);
790
891
  }
791
- this.listenPointEvents(circle, 'rotate', 2);
892
+ this.listenPointEvents(circle, "rotate", 2);
792
893
  view.addMany(...rotatePoints, rect, circle, buttons, ...resizeLines, ...resizePoints);
793
894
  this.add(view);
794
895
  }
795
896
  load() {
796
- const { target, mergeConfig, single, rect, circle, resizePoints } = this;
797
- const { stroke, strokeWidth } = mergeConfig;
897
+ const {target: target, mergeConfig: mergeConfig, single: single, rect: rect, circle: circle, resizePoints: resizePoints} = this;
898
+ const {stroke: stroke, strokeWidth: strokeWidth} = mergeConfig;
798
899
  const pointsStyle = this.getPointsStyle();
799
900
  const middlePointsStyle = this.getMiddlePointsStyle();
901
+ this.visible = !target.locked;
800
902
  let resizeP;
801
903
  for (let i = 0; i < 8; i++) {
802
904
  resizeP = resizePoints[i];
803
- resizeP.set(this.getPointStyle((i % 2) ? middlePointsStyle[((i - 1) / 2) % middlePointsStyle.length] : pointsStyle[(i / 2) % pointsStyle.length]));
804
- if (!(i % 2))
805
- resizeP.rotation = (i / 2) * 90;
905
+ resizeP.set(this.getPointStyle(i % 2 ? middlePointsStyle[(i - 1) / 2 % middlePointsStyle.length] : pointsStyle[i / 2 % pointsStyle.length]));
906
+ resizeP.rotation = (i - (i % 2 ? 1 : 0)) / 2 * 90;
806
907
  }
807
908
  circle.set(this.getPointStyle(mergeConfig.circle || mergeConfig.rotatePoint || pointsStyle[0]));
808
- rect.set(Object.assign({ stroke, strokeWidth, editConfig }, (mergeConfig.rect || {})));
909
+ rect.set(Object.assign({
910
+ stroke: stroke,
911
+ strokeWidth: strokeWidth,
912
+ editConfig: editConfig
913
+ }, mergeConfig.rect || {}));
809
914
  const syncEventer = single && this.transformTool.editTool;
810
915
  rect.hittable = !syncEventer;
811
916
  rect.syncEventer = syncEventer && this.editor;
812
917
  if (syncEventer) {
813
918
  target.syncEventer = rect;
814
- this.app.interaction.bottomList = [{ target: rect, proxy: target }];
919
+ this.app.interaction.bottomList = [ {
920
+ target: rect,
921
+ proxy: target
922
+ } ];
815
923
  }
816
924
  updateMoveCursor(this);
817
925
  }
818
926
  update() {
819
- const { editor } = this;
820
- const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = this.target.getLayoutBounds('box', editor, true);
821
- this.set({ x, y, scaleX, scaleY, rotation, skewX, skewY });
822
- this.updateBounds({ x: 0, y: 0, width, height });
927
+ const {editor: editor} = this;
928
+ const {x: x, y: y, scaleX: scaleX, scaleY: scaleY, rotation: rotation, skewX: skewX, skewY: skewY, width: width, height: height} = this.target.getLayoutBounds("box", editor, true);
929
+ this.visible = !this.target.locked;
930
+ this.set({
931
+ x: x,
932
+ y: y,
933
+ scaleX: scaleX,
934
+ scaleY: scaleY,
935
+ rotation: rotation,
936
+ skewX: skewX,
937
+ skewY: skewY
938
+ });
939
+ this.updateBounds({
940
+ x: 0,
941
+ y: 0,
942
+ width: width,
943
+ height: height
944
+ });
945
+ }
946
+ unload() {
947
+ this.visible = false;
948
+ if (this.app) this.rect.syncEventer = this.app.interaction.bottomList = null;
823
949
  }
824
950
  updateBounds(bounds) {
825
- const { editMask } = this.editor;
826
- const { mergeConfig, single, rect, circle, buttons, resizePoints, rotatePoints, resizeLines } = this;
827
- const { middlePoint, resizeable, rotateable, hideOnSmall, editBox, mask } = mergeConfig;
828
- this.visible = !this.target.locked;
951
+ const {editMask: editMask} = this.editor;
952
+ const {mergeConfig: mergeConfig, single: single, rect: rect, circle: circle, buttons: buttons, resizePoints: resizePoints, rotatePoints: rotatePoints, resizeLines: resizeLines} = this;
953
+ const {middlePoint: middlePoint, resizeable: resizeable, rotateable: rotateable, hideOnSmall: hideOnSmall, editBox: editBox, mask: mask, spread: spread, hideRotatePoints: hideRotatePoints, hideResizeLines: hideResizeLines} = mergeConfig;
829
954
  editMask.visible = mask ? true : 0;
955
+ if (spread) BoundsHelper.spread(bounds, spread);
830
956
  if (this.view.worldOpacity) {
831
- const { width, height } = bounds;
832
- const smallSize = typeof hideOnSmall === 'number' ? hideOnSmall : 10;
957
+ const {width: width, height: height} = bounds;
958
+ const smallSize = isNumber(hideOnSmall) ? hideOnSmall : 10;
833
959
  const showPoints = editBox && !(hideOnSmall && width < smallSize && height < smallSize);
834
960
  let point = {}, rotateP, resizeP, resizeL;
835
961
  for (let i = 0; i < 8; i++) {
836
962
  AroundHelper.toPoint(AroundHelper.directionData[i], bounds, point);
837
963
  resizeP = resizePoints[i];
838
964
  rotateP = rotatePoints[i];
839
- resizeL = resizeLines[Math.floor(i / 2)];
840
965
  resizeP.set(point);
841
966
  rotateP.set(point);
842
- resizeL.set(point);
843
- resizeP.visible = resizeL.visible = showPoints && !!(resizeable || rotateable);
844
- rotateP.visible = showPoints && rotateable && resizeable && !mergeConfig.rotatePoint;
967
+ resizeP.visible = showPoints && !!(resizeable || rotateable);
968
+ rotateP.visible = showPoints && rotateable && resizeable && !hideRotatePoints;
845
969
  if (i % 2) {
970
+ resizeL = resizeLines[(i - 1) / 2];
971
+ resizeL.set(point);
972
+ resizeL.visible = resizeP.visible && !hideResizeLines;
846
973
  resizeP.visible = rotateP.visible = showPoints && !!middlePoint;
847
- if (((i + 1) / 2) % 2) {
974
+ if ((i + 1) / 2 % 2) {
848
975
  resizeL.width = width;
849
- if (hideOnSmall && resizeP.width * 2 > width)
850
- resizeP.visible = false;
851
- }
852
- else {
976
+ if (hideOnSmall && resizeP.width * 2 > width) resizeP.visible = false;
977
+ } else {
853
978
  resizeL.height = height;
854
- resizeP.rotation = 90;
855
- if (hideOnSmall && resizeP.width * 2 > height)
856
- resizeP.visible = false;
979
+ if (hideOnSmall && resizeP.width * 2 > height) resizeP.visible = false;
857
980
  }
858
981
  }
859
982
  }
860
983
  circle.visible = showPoints && rotateable && !!(mergeConfig.circle || mergeConfig.rotatePoint);
861
- if (circle.visible)
862
- this.layoutCircle();
863
- if (rect.path)
864
- rect.path = null;
865
- rect.set(Object.assign(Object.assign({}, bounds), { visible: single ? editBox : true }));
984
+ if (circle.visible) this.layoutCircle();
985
+ if (rect.path) rect.path = null;
986
+ rect.set(Object.assign(Object.assign({}, bounds), {
987
+ visible: single ? editBox : true
988
+ }));
866
989
  buttons.visible = showPoints && buttons.children.length > 0 || 0;
867
- if (buttons.visible)
868
- this.layoutButtons();
869
- }
870
- else
871
- rect.set(bounds);
990
+ if (buttons.visible) this.layoutButtons();
991
+ } else rect.set(bounds);
872
992
  }
873
993
  layoutCircle() {
874
- const { circleDirection, circleMargin, buttonsMargin, buttonsDirection, middlePoint } = this.mergedConfig;
875
- const direction = fourDirection.indexOf(circleDirection || ((this.buttons.children.length && buttonsDirection === 'bottom') ? 'top' : 'bottom'));
994
+ const {circleDirection: circleDirection, circleMargin: circleMargin, buttonsMargin: buttonsMargin, buttonsDirection: buttonsDirection, middlePoint: middlePoint} = this.mergedConfig;
995
+ const direction = fourDirection.indexOf(circleDirection || (this.buttons.children.length && buttonsDirection === "bottom" ? "top" : "bottom"));
876
996
  this.setButtonPosition(this.circle, direction, circleMargin || buttonsMargin, !!middlePoint);
877
997
  }
878
998
  layoutButtons() {
879
- const { buttons } = this;
880
- const { buttonsDirection, buttonsFixed, buttonsMargin, middlePoint } = this.mergedConfig;
881
- const { flippedX, flippedY } = this;
999
+ const {buttons: buttons} = this;
1000
+ const {buttonsDirection: buttonsDirection, buttonsFixed: buttonsFixed, buttonsMargin: buttonsMargin, middlePoint: middlePoint} = this.mergedConfig;
1001
+ const {flippedX: flippedX, flippedY: flippedY} = this;
882
1002
  let index = fourDirection.indexOf(buttonsDirection);
883
- if ((index % 2 && flippedX) || ((index + 1) % 2 && flippedY)) {
884
- if (buttonsFixed)
885
- index = (index + 2) % 4;
1003
+ if (index % 2 && flippedX || (index + 1) % 2 && flippedY) {
1004
+ if (buttonsFixed) index = (index + 2) % 4;
886
1005
  }
887
1006
  const direction = buttonsFixed ? EditDataHelper.getRotateDirection(index, this.flippedOne ? this.rotation : -this.rotation, 4) : index;
888
1007
  this.setButtonPosition(buttons, direction, buttonsMargin, !!middlePoint);
889
- if (buttonsFixed)
890
- buttons.rotation = (direction - index) * 90;
1008
+ if (buttonsFixed) buttons.rotation = (direction - index) * 90;
891
1009
  buttons.scaleX = flippedX ? -1 : 1;
892
1010
  buttons.scaleY = flippedY ? -1 : 1;
893
1011
  }
894
1012
  setButtonPosition(buttons, direction, buttonsMargin, useMiddlePoint) {
895
1013
  const point = this.resizePoints[direction * 2 + 1];
896
1014
  const useX = direction % 2;
897
- const sign = (!direction || direction === 3) ? -1 : 1;
1015
+ const sign = !direction || direction === 3 ? -1 : 1;
898
1016
  const useWidth = direction % 2;
899
- const margin = (buttonsMargin + (useWidth ? ((useMiddlePoint ? point.width : 0) + buttons.boxBounds.width) : ((useMiddlePoint ? point.height : 0) + buttons.boxBounds.height)) / 2) * sign;
1017
+ const margin = (buttonsMargin + (useWidth ? (useMiddlePoint ? point.width : 0) + buttons.boxBounds.width : (useMiddlePoint ? point.height : 0) + buttons.boxBounds.height) / 2) * sign;
900
1018
  if (useX) {
901
1019
  buttons.x = point.x + margin;
902
1020
  buttons.y = point.y;
903
- }
904
- else {
1021
+ } else {
905
1022
  buttons.x = point.x;
906
1023
  buttons.y = point.y + margin;
907
1024
  }
908
1025
  }
909
- unload() {
910
- this.visible = false;
911
- }
912
1026
  getPointStyle(userStyle) {
913
- const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.mergedConfig;
914
- const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', width: pointSize, height: pointSize, cornerRadius: pointRadius, offsetX: 0, offsetY: 0, editConfig };
1027
+ const {stroke: stroke, strokeWidth: strokeWidth, pointFill: pointFill, pointSize: pointSize, pointRadius: pointRadius} = this.mergedConfig;
1028
+ const defaultStyle = {
1029
+ fill: pointFill,
1030
+ stroke: stroke,
1031
+ strokeWidth: strokeWidth,
1032
+ around: "center",
1033
+ strokeAlign: "center",
1034
+ width: pointSize,
1035
+ height: pointSize,
1036
+ cornerRadius: pointRadius,
1037
+ offsetX: 0,
1038
+ offsetY: 0,
1039
+ editConfig: editConfig
1040
+ };
915
1041
  return userStyle ? Object.assign(defaultStyle, userStyle) : defaultStyle;
916
1042
  }
917
1043
  getPointsStyle() {
918
- const { point } = this.mergedConfig;
919
- return point instanceof Array ? point : [point];
1044
+ const {point: point} = this.mergedConfig;
1045
+ return isArray(point) ? point : [ point ];
920
1046
  }
921
1047
  getMiddlePointsStyle() {
922
- const { middlePoint } = this.mergedConfig;
923
- return middlePoint instanceof Array ? middlePoint : (middlePoint ? [middlePoint] : this.getPointsStyle());
924
- }
925
- onSelect(e) {
926
- if (e.oldList.length === 1) {
927
- e.oldList[0].syncEventer = null;
928
- if (this.app)
929
- this.app.interaction.bottomList = null;
930
- }
1048
+ const {middlePoint: middlePoint} = this.mergedConfig;
1049
+ return isArray(middlePoint) ? middlePoint : middlePoint ? [ middlePoint ] : this.getPointsStyle();
931
1050
  }
932
1051
  onDragStart(e) {
933
1052
  this.dragging = true;
934
- const point = this.dragPoint = e.current, { pointType } = point;
935
- const { editor, dragStartData } = this, { target } = this;
936
- if (point.name === 'rect') {
937
- this.moving = true;
938
- editor.opacity = this.mergeConfig.hideOnMove ? 0 : 1;
1053
+ const point = this.dragPoint = e.current, {pointType: pointType} = point;
1054
+ const {editor: editor, dragStartData: dragStartData} = this, {target: target} = this, {moveable: moveable, resizeable: resizeable, rotateable: rotateable, skewable: skewable, hideOnMove: hideOnMove} = this.mergeConfig;
1055
+ if (point.name === "rect") {
1056
+ moveable && (this.moving = true);
1057
+ editor.opacity = hideOnMove ? 0 : 1;
1058
+ } else {
1059
+ if (pointType.includes("rotate") || this.isHoldRotateKey(e) || !resizeable) {
1060
+ rotateable && (this.rotating = true);
1061
+ if (pointType === "resize-rotate") resizeable && (this.resizing = true); else if (point.name === "resize-line") skewable && (this.skewing = true),
1062
+ this.rotating = false;
1063
+ } else if (pointType === "resize") resizeable && (this.resizing = true);
1064
+ if (pointType === "skew") skewable && (this.skewing = true);
939
1065
  }
940
1066
  dragStartData.x = e.x;
941
1067
  dragStartData.y = e.y;
942
- dragStartData.point = { x: target.x, y: target.y };
943
- dragStartData.bounds = Object.assign({}, target.getLayoutBounds('box', 'local'));
1068
+ dragStartData.point = {
1069
+ x: target.x,
1070
+ y: target.y
1071
+ };
1072
+ dragStartData.bounds = Object.assign({}, target.getLayoutBounds("box", "local"));
944
1073
  dragStartData.rotation = target.rotation;
945
- if (pointType && pointType.includes('resize'))
946
- ResizeEvent.resizingKeys = editor.leafList.keys;
1074
+ if (pointType && pointType.includes("resize")) ResizeEvent.resizingKeys = editor.leafList.keys;
947
1075
  }
948
1076
  onDragEnd(e) {
949
- this.dragging = false;
1077
+ if (this.mergeConfig.dragLimitAnimate && this.moving) this.transformTool.onMove(e);
950
1078
  this.dragPoint = null;
951
- this.moving = false;
952
- const { name, pointType } = e.current;
953
- if (name === 'rect')
954
- this.editor.opacity = 1;
955
- if (pointType && pointType.includes('resize'))
956
- ResizeEvent.resizingKeys = null;
1079
+ this.resetDoing();
1080
+ const {name: name, pointType: pointType} = e.current;
1081
+ if (name === "rect") this.editor.opacity = 1;
1082
+ if (pointType && pointType.includes("resize")) ResizeEvent.resizingKeys = null;
957
1083
  }
958
1084
  onDrag(e) {
959
- const { transformTool } = this, point = e.current;
960
- if (point.name === 'rect') {
1085
+ const {transformTool: transformTool, moving: moving, resizing: resizing, rotating: rotating, skewing: skewing} = this;
1086
+ if (moving) {
961
1087
  transformTool.onMove(e);
962
1088
  updateMoveCursor(this);
1089
+ } else if (resizing || rotating || skewing) {
1090
+ const point = e.current;
1091
+ if (point.pointType) this.enterPoint = point;
1092
+ if (rotating) transformTool.onRotate(e);
1093
+ if (resizing) transformTool.onScale(e);
1094
+ if (skewing) transformTool.onSkew(e);
1095
+ updatePointCursor(this, e);
963
1096
  }
964
- else {
965
- const { pointType } = this.enterPoint = point;
966
- if (pointType.includes('rotate') || e.metaKey || e.ctrlKey || !this.mergeConfig.resizeable) {
967
- transformTool.onRotate(e);
968
- if (pointType === 'resize-rotate')
969
- transformTool.onScale(e);
1097
+ }
1098
+ resetDoing() {
1099
+ if (this.canUse) this.dragging = this.gesturing = this.moving = this.resizing = this.rotating = this.skewing = false;
1100
+ }
1101
+ onMove(e) {
1102
+ if (this.canGesture && e.moveType !== "drag") {
1103
+ e.stop();
1104
+ if (isString(this.mergeConfig.moveable)) {
1105
+ this.gesturing = this.moving = true;
1106
+ this.transformTool.onMove(e);
970
1107
  }
971
- else if (pointType === 'resize')
972
- transformTool.onScale(e);
973
- if (pointType === 'skew')
974
- transformTool.onSkew(e);
975
- updateCursor(this, e);
976
1108
  }
977
1109
  }
1110
+ onScale(e) {
1111
+ if (this.canGesture) {
1112
+ e.stop();
1113
+ if (isString(this.mergeConfig.resizeable)) {
1114
+ this.gesturing = this.resizing = true;
1115
+ this.transformTool.onScale(e);
1116
+ }
1117
+ }
1118
+ }
1119
+ onRotate(e) {
1120
+ if (this.canGesture) {
1121
+ e.stop();
1122
+ if (isString(this.mergeConfig.rotateable)) {
1123
+ this.gesturing = this.rotating = true;
1124
+ this.transformTool.onRotate(e);
1125
+ }
1126
+ }
1127
+ }
1128
+ isHoldRotateKey(e) {
1129
+ const {rotateKey: rotateKey} = this.mergedConfig;
1130
+ if (rotateKey) return e.isHoldKeys(rotateKey);
1131
+ return e.metaKey || e.ctrlKey;
1132
+ }
978
1133
  onKey(e) {
979
- updateCursor(this, e);
1134
+ updatePointCursor(this, e);
980
1135
  }
981
1136
  onArrow(e) {
982
- const { editor } = this;
983
- if (editor.editing && this.mergeConfig.keyEvent) {
1137
+ const {editor: editor, transformTool: transformTool} = this;
1138
+ if (this.canUse && editor.editing && this.mergeConfig.keyEvent) {
984
1139
  let x = 0, y = 0;
985
1140
  const distance = e.shiftKey ? 10 : 1;
986
1141
  switch (e.code) {
987
- case 'ArrowDown':
988
- y = distance;
989
- break;
990
- case 'ArrowUp':
991
- y = -distance;
992
- break;
993
- case 'ArrowLeft':
994
- x = -distance;
995
- break;
996
- case 'ArrowRight':
997
- x = distance;
1142
+ case "ArrowDown":
1143
+ y = distance;
1144
+ break;
1145
+
1146
+ case "ArrowUp":
1147
+ y = -distance;
1148
+ break;
1149
+
1150
+ case "ArrowLeft":
1151
+ x = -distance;
1152
+ break;
1153
+
1154
+ case "ArrowRight":
1155
+ x = distance;
998
1156
  }
999
- if (x || y)
1000
- editor.move(x, y);
1157
+ if (x || y) transformTool.move(x, y);
1001
1158
  }
1002
1159
  }
1003
1160
  onDoubleTap(e) {
1004
- const { openInner, preventEditInner } = this.mergeConfig;
1005
- if (openInner === 'double' && !preventEditInner)
1006
- this.openInner(e);
1161
+ const {openInner: openInner, preventEditInner: preventEditInner} = this.mergeConfig;
1162
+ if (openInner === "double" && !preventEditInner) this.openInner(e);
1007
1163
  }
1008
1164
  onLongPress(e) {
1009
- const { openInner, preventEditInner } = this.mergeConfig;
1010
- if (openInner === 'long' && preventEditInner)
1011
- this.openInner(e);
1165
+ const {openInner: openInner, preventEditInner: preventEditInner} = this.mergeConfig;
1166
+ if (openInner === "long" && preventEditInner) this.openInner(e);
1012
1167
  }
1013
1168
  openInner(e) {
1014
- const { editor, target } = this;
1169
+ const {editor: editor, target: target} = this;
1015
1170
  if (this.single) {
1016
- if (target.locked)
1017
- return;
1171
+ if (target.locked) return;
1018
1172
  if (target.isBranch && !target.editInner) {
1019
1173
  if (target.textBox) {
1020
- const { children } = target;
1174
+ const {children: children} = target;
1021
1175
  const find = children.find(item => item.editable && item instanceof Text) || children.find(item => item instanceof Text);
1022
- if (find)
1023
- return editor.openInnerEditor(find);
1176
+ if (find) return editor.openInnerEditor(find);
1024
1177
  }
1025
1178
  editor.openGroup(target);
1026
1179
  editor.target = editor.selector.findDeepOne(e);
1027
- }
1028
- else {
1180
+ } else {
1029
1181
  editor.openInnerEditor();
1030
1182
  }
1031
1183
  }
@@ -1033,31 +1185,19 @@ class EditBox extends Group {
1033
1185
  listenPointEvents(point, type, direction) {
1034
1186
  point.direction = direction;
1035
1187
  point.pointType = type;
1036
- const events = [
1037
- [DragEvent.START, this.onDragStart, this],
1038
- [DragEvent.DRAG, this.onDrag, this],
1039
- [DragEvent.END, this.onDragEnd, this],
1040
- [PointerEvent.LEAVE, () => { this.enterPoint = null; }],
1041
- ];
1042
- if (point.name !== 'circle')
1043
- events.push([PointerEvent.ENTER, (e) => { this.enterPoint = point, updateCursor(this, e); }]);
1188
+ const events = [ [ DragEvent.START, this.onDragStart, this ], [ DragEvent.DRAG, this.onDrag, this ], [ DragEvent.END, this.onDragEnd, this ], [ PointerEvent.LEAVE, () => {
1189
+ this.enterPoint = null;
1190
+ } ] ];
1191
+ if (point.name !== "circle") events.push([ PointerEvent.ENTER, e => {
1192
+ this.enterPoint = point, updatePointCursor(this, e);
1193
+ } ]);
1044
1194
  this.__eventIds.push(point.on_(events));
1045
1195
  }
1046
1196
  __listenEvents() {
1047
- const { rect, editor, __eventIds: events } = this;
1048
- events.push(editor.on_(EditorEvent.SELECT, this.onSelect, this), rect.on_([
1049
- [DragEvent.START, this.onDragStart, this],
1050
- [DragEvent.DRAG, this.onDrag, this],
1051
- [DragEvent.END, this.onDragEnd, this],
1052
- [PointerEvent.ENTER, () => updateMoveCursor(this)],
1053
- [PointerEvent.DOUBLE_TAP, this.onDoubleTap, this],
1054
- [PointerEvent.LONG_PRESS, this.onLongPress, this]
1055
- ]));
1197
+ const {rect: rect, editor: editor, __eventIds: events} = this;
1198
+ events.push(rect.on_([ [ DragEvent.START, this.onDragStart, this ], [ DragEvent.DRAG, this.onDrag, this ], [ DragEvent.END, this.onDragEnd, this ], [ PointerEvent.ENTER, () => updateMoveCursor(this) ], [ PointerEvent.DOUBLE_TAP, this.onDoubleTap, this ], [ PointerEvent.LONG_PRESS, this.onLongPress, this ] ]));
1056
1199
  this.waitLeafer(() => {
1057
- events.push(editor.app.on_([
1058
- [[KeyEvent.HOLD, KeyEvent.UP], this.onKey, this],
1059
- [KeyEvent.DOWN, this.onArrow, this]
1060
- ]));
1200
+ events.push(editor.app.on_([ [ [ KeyEvent.HOLD, KeyEvent.UP ], this.onKey, this ], [ KeyEvent.DOWN, this.onArrow, this ], [ MoveEvent.BEFORE_MOVE, this.onMove, this, true ], [ ZoomEvent.BEFORE_ZOOM, this.onScale, this, true ], [ RotateEvent.BEFORE_ROTATE, this.onRotate, this, true ], [ MoveEvent.END, this.resetDoing, this ], [ ZoomEvent.END, this.resetDoing, this ], [ RotateEvent.END, this.resetDoing, this ] ]));
1061
1201
  });
1062
1202
  }
1063
1203
  __removeListenEvents() {
@@ -1070,7 +1210,13 @@ class EditBox extends Group {
1070
1210
  }
1071
1211
  }
1072
1212
 
1073
- const bigBounds = { x: 0, y: 0, width: 100000, height: 100000 };
1213
+ const bigBounds = {
1214
+ x: 0,
1215
+ y: 0,
1216
+ width: 1e5,
1217
+ height: 1e5
1218
+ };
1219
+
1074
1220
  class EditMask extends UI {
1075
1221
  constructor(editor) {
1076
1222
  super();
@@ -1083,18 +1229,18 @@ class EditMask extends UI {
1083
1229
  Object.assign(this.__world, bigBounds);
1084
1230
  }
1085
1231
  __draw(canvas, options) {
1086
- const { editor } = this, { mask } = editor.mergedConfig;
1232
+ const {editor: editor} = this, {mask: mask} = editor.mergedConfig;
1087
1233
  if (mask && editor.editing) {
1088
- canvas.fillWorld(canvas.bounds, mask === true ? 'rgba(0,0,0,0.8)' : mask);
1089
- if (options.bounds && !options.bounds.hit(editor.editBox.rect.__world, options.matrix))
1090
- return;
1091
- canvas.saveBlendMode('destination-out');
1092
- options = Object.assign(Object.assign({}, options), { shape: true });
1234
+ canvas.fillWorld(canvas.bounds, mask === true ? "rgba(0,0,0,0.8)" : mask);
1235
+ if (options.bounds && !options.bounds.hit(editor.editBox.rect.__world, options.matrix)) return;
1236
+ canvas.saveBlendMode("destination-out");
1237
+ options = Object.assign(Object.assign({}, options), {
1238
+ shape: true
1239
+ });
1093
1240
  editor.list.forEach(item => {
1094
1241
  item.__render(canvas, options);
1095
- const { parent } = item;
1096
- if (parent && parent.textBox)
1097
- parent.__renderShape(canvas, options);
1242
+ const {parent: parent} = item;
1243
+ if (parent && parent.textBox) parent.__renderShape(canvas, options);
1098
1244
  });
1099
1245
  canvas.restoreBlendMode();
1100
1246
  }
@@ -1105,78 +1251,47 @@ class EditMask extends UI {
1105
1251
  }
1106
1252
  }
1107
1253
 
1108
- const filterStyle = `
1109
- <feOffset dy="1"/>
1110
- <feGaussianBlur stdDeviation="1.5"/>
1111
- <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"/>
1112
- <feBlend mode="normal" in="SourceGraphic" result="shape"/>`;
1113
- const resizeSVG = `
1114
- <svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">
1115
- <g filter="url(#f)">
1116
- <g transform="rotate({{rotation}},12,12)">
1117
- <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"/>
1118
- <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"/>
1119
- </g>
1120
- </g>
1121
- <defs>
1122
- <filter id="f" x="-1.6" y="3.9" width="27.2" height="16.9" filterUnits="userSpaceOnUse">
1123
- ${filterStyle}
1124
- </filter>
1125
- </defs>
1126
- </svg>
1127
- `;
1128
- const rotateSVG = `
1129
- <svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">
1130
- <g filter="url(#f)">
1131
- <g transform="rotate(135,12,12),rotate({{rotation}},12,12)">
1132
- <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"/>
1133
- <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"/>
1134
- </g>
1135
- </g>
1136
- <defs>
1137
- <filter id="f" x="-1.6" y="-0.6" width="27.1" height="27.1" filterUnits="userSpaceOnUse">
1138
- ${filterStyle}
1139
- </filter>
1140
- </defs>
1141
- </svg>
1142
- `;
1143
- const skewSVG = `
1144
- <svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">
1145
- <g filter="url(#f)">
1146
- <g transform="rotate(90,12,12),rotate({{rotation}},12,12)">
1147
- <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"/>
1148
- <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"/>
1149
- </g>
1150
- </g>
1151
- <defs>
1152
- <filter x="-2.8" y="1.9" width="29.6" height="23.1" filterUnits="userSpaceOnUse" >
1153
- ${filterStyle}
1154
- </filter>
1155
- </defs>
1156
- </svg>
1157
- `;
1254
+ const filterStyle = `\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"/>`;
1255
+
1256
+ const resizeSVG = `\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${filterStyle}\n</filter>\n</defs>\n</svg>\n`;
1257
+
1258
+ const rotateSVG = `\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${filterStyle}\n</filter>\n</defs>\n</svg>\n`;
1259
+
1260
+ const skewSVG = `\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${filterStyle}\n</filter>\n</defs>\n</svg>\n`;
1158
1261
 
1159
1262
  const config = {
1160
- editSize: 'size',
1263
+ editSize: "size",
1161
1264
  keyEvent: true,
1162
- stroke: '#836DFF',
1265
+ stroke: "#836DFF",
1163
1266
  strokeWidth: 2,
1164
- pointFill: '#FFFFFF',
1267
+ pointFill: "#FFFFFF",
1165
1268
  pointSize: 10,
1166
1269
  pointRadius: 16,
1167
1270
  rotateGap: 45,
1168
- buttonsDirection: 'bottom',
1271
+ buttonsDirection: "bottom",
1169
1272
  buttonsMargin: 12,
1170
1273
  hideOnSmall: true,
1171
- moveCursor: 'move',
1172
- resizeCursor: { url: resizeSVG, x: 12, y: 12 },
1173
- rotateCursor: { url: rotateSVG, x: 12, y: 12 },
1174
- skewCursor: { url: skewSVG, x: 12, y: 12 },
1274
+ moveCursor: "move",
1275
+ resizeCursor: {
1276
+ url: resizeSVG,
1277
+ x: 12,
1278
+ y: 12
1279
+ },
1280
+ rotateCursor: {
1281
+ url: rotateSVG,
1282
+ x: 12,
1283
+ y: 12
1284
+ },
1285
+ skewCursor: {
1286
+ url: skewSVG,
1287
+ x: 12,
1288
+ y: 12
1289
+ },
1175
1290
  selector: true,
1176
1291
  editBox: true,
1177
1292
  hover: true,
1178
- select: 'press',
1179
- openInner: 'double',
1293
+ select: "press",
1294
+ openInner: "double",
1180
1295
  multipleSelect: true,
1181
1296
  boxSelect: true,
1182
1297
  moveable: true,
@@ -1186,34 +1301,36 @@ const config = {
1186
1301
  skewable: true
1187
1302
  };
1188
1303
 
1189
- const bounds = new Bounds();
1304
+ const bounds = new Bounds;
1305
+
1190
1306
  function simulate(editor) {
1191
- const { simulateTarget, list } = editor;
1192
- const { zoomLayer } = list[0].leafer;
1307
+ const {simulateTarget: simulateTarget, list: list} = editor;
1308
+ const {zoomLayer: zoomLayer} = list[0].leafer;
1193
1309
  simulateTarget.safeChange(() => {
1194
- bounds.setListWithFn(list, (leaf) => leaf.getBounds('box', 'page'));
1195
- if (bounds.width === 0)
1196
- bounds.width = 0.1;
1197
- if (bounds.height === 0)
1198
- bounds.height = 0.1;
1310
+ bounds.setListWithFn(list, leaf => leaf.getBounds("box", "page"));
1311
+ if (bounds.width === 0) bounds.width = .1;
1312
+ if (bounds.height === 0) bounds.height = .1;
1199
1313
  simulateTarget.reset(bounds.get());
1200
1314
  });
1201
1315
  zoomLayer.add(simulateTarget);
1202
1316
  }
1203
1317
 
1204
1318
  function onTarget(editor, oldValue) {
1205
- const { target } = editor;
1319
+ const {target: target} = editor;
1206
1320
  if (target) {
1207
1321
  editor.leafList = target instanceof LeafList ? target : new LeafList(target);
1208
- if (editor.multiple)
1209
- simulate(editor);
1210
- }
1211
- else {
1322
+ if (editor.multiple) simulate(editor);
1323
+ } else {
1212
1324
  editor.simulateTarget.remove();
1213
1325
  editor.leafList.reset();
1214
1326
  }
1215
- editor.closeInnerEditor();
1216
- const data = { editor, value: target, oldValue };
1327
+ editor.closeInnerEditor(true);
1328
+ editor.unloadEditTool();
1329
+ const data = {
1330
+ editor: editor,
1331
+ value: target,
1332
+ oldValue: oldValue
1333
+ };
1217
1334
  editor.emitEvent(new EditorEvent(EditorEvent.SELECT, data));
1218
1335
  editor.checkOpenedGroups();
1219
1336
  if (editor.editing) {
@@ -1221,28 +1338,33 @@ function onTarget(editor, oldValue) {
1221
1338
  editor.updateEditTool();
1222
1339
  editor.listenTargetEvents();
1223
1340
  });
1224
- }
1225
- else {
1341
+ } else {
1226
1342
  editor.updateEditTool();
1227
1343
  editor.removeTargetEvents();
1228
1344
  }
1229
1345
  editor.emitEvent(new EditorEvent(EditorEvent.AFTER_SELECT, data));
1230
1346
  }
1347
+
1231
1348
  function onHover(editor, oldValue) {
1232
- editor.emitEvent(new EditorEvent(EditorEvent.HOVER, { editor, value: editor.hoverTarget, oldValue }));
1349
+ editor.emitEvent(new EditorEvent(EditorEvent.HOVER, {
1350
+ editor: editor,
1351
+ value: editor.hoverTarget,
1352
+ oldValue: oldValue
1353
+ }));
1233
1354
  }
1234
1355
 
1235
1356
  const order = (a, b) => a.parent.children.indexOf(a) - b.parent.children.indexOf(b);
1357
+
1236
1358
  const reverseOrder = (a, b) => b.parent.children.indexOf(b) - a.parent.children.indexOf(a);
1359
+
1237
1360
  const EditorHelper = {
1238
1361
  group(list, element, userGroup) {
1239
1362
  list.sort(reverseOrder);
1240
- const { app, parent } = list[0];
1363
+ const {app: app, parent: parent} = list[0];
1241
1364
  let group;
1242
1365
  if (userGroup && userGroup.add) {
1243
1366
  group = userGroup;
1244
- }
1245
- else {
1367
+ } else {
1246
1368
  group = new Group(userGroup);
1247
1369
  }
1248
1370
  parent.addAt(group, parent.children.indexOf(list[0]));
@@ -1258,22 +1380,18 @@ const EditorHelper = {
1258
1380
  return group;
1259
1381
  },
1260
1382
  ungroup(list) {
1261
- const { app } = list[0];
1383
+ const {app: app} = list[0];
1262
1384
  const ungroupList = [];
1263
1385
  app.lockLayout();
1264
1386
  list.forEach(leaf => {
1265
1387
  if (leaf.isBranch) {
1266
- const { parent, children } = leaf;
1388
+ const {parent: parent, children: children} = leaf;
1267
1389
  while (children.length) {
1268
1390
  ungroupList.push(children[0]);
1269
1391
  children[0].dropTo(parent, parent.children.indexOf(leaf));
1270
1392
  }
1271
- if (leaf.isBranchLeaf)
1272
- ungroupList.push(leaf);
1273
- else
1274
- leaf.remove();
1275
- }
1276
- else {
1393
+ if (leaf.isBranchLeaf) ungroupList.push(leaf); else leaf.remove();
1394
+ } else {
1277
1395
  ungroupList.push(leaf);
1278
1396
  }
1279
1397
  });
@@ -1283,30 +1401,31 @@ const EditorHelper = {
1283
1401
  toTop(list) {
1284
1402
  list.sort(order);
1285
1403
  list.forEach(leaf => {
1286
- if (leaf.parent)
1287
- leaf.parent.add(leaf);
1404
+ if (leaf.parent) leaf.parent.add(leaf);
1288
1405
  });
1289
1406
  },
1290
1407
  toBottom(list) {
1291
1408
  list.sort(reverseOrder);
1292
1409
  list.forEach(leaf => {
1293
- if (leaf.parent)
1294
- leaf.parent.addAt(leaf, 0);
1410
+ if (leaf.parent) leaf.parent.addAt(leaf, 0);
1295
1411
  });
1296
1412
  }
1297
1413
  };
1298
1414
 
1299
- const debug = Debug.get('EditToolCreator');
1415
+ const debug = Debug.get("EditToolCreator");
1416
+
1300
1417
  function registerEditTool() {
1301
- return (target) => {
1418
+ return target => {
1302
1419
  EditToolCreator.register(target);
1303
1420
  };
1304
1421
  }
1422
+
1305
1423
  const registerInnerEditor = registerEditTool;
1424
+
1306
1425
  const EditToolCreator = {
1307
1426
  list: {},
1308
1427
  register(EditTool) {
1309
- const { tag } = EditTool.prototype;
1428
+ const {tag: tag} = EditTool.prototype;
1310
1429
  list[tag] && debug.repeat(tag);
1311
1430
  list[tag] = EditTool;
1312
1431
  },
@@ -1314,45 +1433,70 @@ const EditToolCreator = {
1314
1433
  return new list[tag](editor);
1315
1434
  }
1316
1435
  };
1317
- const { list } = EditToolCreator;
1436
+
1437
+ const {list: list} = EditToolCreator;
1318
1438
 
1319
1439
  class InnerEditorEvent extends EditorEvent {
1320
1440
  constructor(type, data) {
1321
1441
  super(type, data);
1322
1442
  }
1323
1443
  }
1324
- InnerEditorEvent.BEFORE_OPEN = 'innerEditor.before_open';
1325
- InnerEditorEvent.OPEN = 'innerEditor.open';
1326
- InnerEditorEvent.BEFORE_CLOSE = 'innerEditor.before_close';
1327
- InnerEditorEvent.CLOSE = 'innerEditor.close';
1444
+
1445
+ InnerEditorEvent.BEFORE_OPEN = "innerEditor.before_open";
1446
+
1447
+ InnerEditorEvent.OPEN = "innerEditor.open";
1448
+
1449
+ InnerEditorEvent.BEFORE_CLOSE = "innerEditor.before_close";
1450
+
1451
+ InnerEditorEvent.CLOSE = "innerEditor.close";
1328
1452
 
1329
1453
  class EditorGroupEvent extends EditorEvent {
1330
1454
  constructor(type, data) {
1331
1455
  super(type, data);
1332
1456
  }
1333
1457
  }
1334
- EditorGroupEvent.BEFORE_GROUP = 'editor.before_group';
1335
- EditorGroupEvent.GROUP = 'editor.group';
1336
- EditorGroupEvent.BEFORE_UNGROUP = 'editor.before_ungroup';
1337
- EditorGroupEvent.UNGROUP = 'editor.ungroup';
1338
- EditorGroupEvent.BEFORE_OPEN = 'editor.before_open_group';
1339
- EditorGroupEvent.OPEN = 'editor.open_group';
1340
- EditorGroupEvent.BEFORE_CLOSE = 'editor.before_close_group';
1341
- EditorGroupEvent.CLOSE = 'editor.close_group';
1342
-
1343
- const { updateMatrix } = LeafHelper;
1344
- const checkMap = { x: 1, y: 1, scaleX: 1, scaleY: 1, rotation: 1, skewX: 1, skewY: 1 }, origin = 'top-left';
1458
+
1459
+ EditorGroupEvent.BEFORE_GROUP = "editor.before_group";
1460
+
1461
+ EditorGroupEvent.GROUP = "editor.group";
1462
+
1463
+ EditorGroupEvent.BEFORE_UNGROUP = "editor.before_ungroup";
1464
+
1465
+ EditorGroupEvent.UNGROUP = "editor.ungroup";
1466
+
1467
+ EditorGroupEvent.BEFORE_OPEN = "editor.before_open_group";
1468
+
1469
+ EditorGroupEvent.OPEN = "editor.open_group";
1470
+
1471
+ EditorGroupEvent.BEFORE_CLOSE = "editor.before_close_group";
1472
+
1473
+ EditorGroupEvent.CLOSE = "editor.close_group";
1474
+
1475
+ const {updateMatrix: updateMatrix} = LeafHelper;
1476
+
1477
+ const checkMap = {
1478
+ x: 1,
1479
+ y: 1,
1480
+ scaleX: 1,
1481
+ scaleY: 1,
1482
+ rotation: 1,
1483
+ skewX: 1,
1484
+ skewY: 1
1485
+ }, origin = "top-left";
1486
+
1345
1487
  class SimulateElement extends Rect {
1346
- get __tag() { return 'SimulateElement'; }
1488
+ get __tag() {
1489
+ return "SimulateElement";
1490
+ }
1347
1491
  constructor(editor) {
1348
1492
  super();
1349
1493
  this.checkChange = true;
1350
1494
  this.canChange = true;
1351
1495
  this.visible = this.hittable = false;
1352
- this.on(PropertyEvent.CHANGE, (event) => {
1496
+ this.on(PropertyEvent.CHANGE, event => {
1353
1497
  if (this.checkChange && checkMap[event.attrName]) {
1354
- const { attrName, newValue, oldValue } = event;
1355
- const addValue = attrName[0] === 's' ? (newValue || 1) / (oldValue || 1) : (newValue || 0) - (oldValue || 0);
1498
+ const {attrName: attrName, newValue: newValue, oldValue: oldValue} = event;
1499
+ const addValue = attrName[0] === "s" ? (newValue || 1) / (oldValue || 1) : (newValue || 0) - (oldValue || 0);
1356
1500
  this.canChange = false;
1357
1501
  const data = this.__;
1358
1502
  data[attrName] = oldValue;
@@ -1364,26 +1508,32 @@ class SimulateElement extends Rect {
1364
1508
  updateMatrix(this);
1365
1509
  this.changedTransform = new Matrix(this.__world).divide(oldMatrix);
1366
1510
  switch (attrName) {
1367
- case 'x':
1368
- editor.move(addValue, 0);
1369
- break;
1370
- case 'y':
1371
- editor.move(0, addValue);
1372
- break;
1373
- case 'rotation':
1374
- editor.rotateOf(origin, addValue);
1375
- break;
1376
- case 'scaleX':
1377
- editor.scaleOf(origin, addValue, 1);
1378
- break;
1379
- case 'scaleY':
1380
- editor.scaleOf(origin, 1, addValue);
1381
- break;
1382
- case 'skewX':
1383
- editor.skewOf(origin, addValue, 0);
1384
- break;
1385
- case 'skewY':
1386
- editor.skewOf(origin, 0, addValue);
1511
+ case "x":
1512
+ editor.move(addValue, 0);
1513
+ break;
1514
+
1515
+ case "y":
1516
+ editor.move(0, addValue);
1517
+ break;
1518
+
1519
+ case "rotation":
1520
+ editor.rotateOf(origin, addValue);
1521
+ break;
1522
+
1523
+ case "scaleX":
1524
+ editor.scaleOf(origin, addValue, 1);
1525
+ break;
1526
+
1527
+ case "scaleY":
1528
+ editor.scaleOf(origin, 1, addValue);
1529
+ break;
1530
+
1531
+ case "skewX":
1532
+ editor.skewOf(origin, addValue, 0);
1533
+ break;
1534
+
1535
+ case "skewY":
1536
+ editor.skewOf(origin, 0, addValue);
1387
1537
  }
1388
1538
  this.canChange = true;
1389
1539
  }
@@ -1403,222 +1553,253 @@ class EditorMoveEvent extends EditorEvent {
1403
1553
  super(type, data);
1404
1554
  }
1405
1555
  }
1406
- EditorMoveEvent.BEFORE_MOVE = 'editor.before_move';
1407
- EditorMoveEvent.MOVE = 'editor.move';
1556
+
1557
+ EditorMoveEvent.BEFORE_MOVE = "editor.before_move";
1558
+
1559
+ EditorMoveEvent.MOVE = "editor.move";
1408
1560
 
1409
1561
  class EditorScaleEvent extends EditorEvent {
1410
1562
  constructor(type, data) {
1411
1563
  super(type, data);
1412
1564
  }
1413
1565
  }
1414
- EditorScaleEvent.BEFORE_SCALE = 'editor.before_scale';
1415
- EditorScaleEvent.SCALE = 'editor.scale';
1566
+
1567
+ EditorScaleEvent.BEFORE_SCALE = "editor.before_scale";
1568
+
1569
+ EditorScaleEvent.SCALE = "editor.scale";
1416
1570
 
1417
1571
  class EditorRotateEvent extends EditorEvent {
1418
1572
  constructor(type, data) {
1419
1573
  super(type, data);
1420
1574
  }
1421
1575
  }
1422
- EditorRotateEvent.BEFORE_ROTATE = 'editor.before_rotate';
1423
- EditorRotateEvent.ROTATE = 'editor.rotate';
1576
+
1577
+ EditorRotateEvent.BEFORE_ROTATE = "editor.before_rotate";
1578
+
1579
+ EditorRotateEvent.ROTATE = "editor.rotate";
1424
1580
 
1425
1581
  class EditorSkewEvent extends EditorEvent {
1426
1582
  constructor(type, data) {
1427
1583
  super(type, data);
1428
1584
  }
1429
1585
  }
1430
- EditorSkewEvent.BEFORE_SKEW = 'editor.before_skew';
1431
- EditorSkewEvent.SKEW = 'editor.skew';
1586
+
1587
+ EditorSkewEvent.BEFORE_SKEW = "editor.before_skew";
1588
+
1589
+ EditorSkewEvent.SKEW = "editor.skew";
1432
1590
 
1433
1591
  class TransformTool {
1434
1592
  onMove(e) {
1435
- const { target, mergeConfig, dragStartData } = this.editBox;
1593
+ const {target: target, mergeConfig: mergeConfig, dragStartData: dragStartData, app: app} = this.editBox;
1594
+ let move, {dragLimitAnimate: dragLimitAnimate} = mergeConfig;
1595
+ if (isUndefined(dragLimitAnimate)) dragLimitAnimate = app && app.config.pointer.dragLimitAnimate;
1596
+ const isMoveEnd = e.type === DragEvent.END || e.type === DragEvent.END;
1597
+ const checkLimitMove = !dragLimitAnimate || isMoveEnd;
1436
1598
  if (e instanceof MoveEvent) {
1437
- if (e.moveType !== 'drag') {
1438
- const { moveable, resizeable } = mergeConfig;
1439
- const move = e.getLocalMove(target);
1440
- if (moveable === 'move')
1441
- e.stop(), this.move(move.x, move.y);
1442
- else if (resizeable === 'zoom')
1443
- e.stop();
1444
- }
1445
- }
1446
- else {
1447
- const total = { x: e.totalX, y: e.totalY };
1599
+ move = e.getLocalMove(target);
1600
+ if (checkLimitMove) DragEvent.limitMove(target, move);
1601
+ } else {
1602
+ const total = {
1603
+ x: e.totalX,
1604
+ y: e.totalY
1605
+ };
1448
1606
  if (e.shiftKey) {
1449
- if (Math.abs(total.x) > Math.abs(total.y))
1450
- total.y = 0;
1451
- else
1452
- total.x = 0;
1607
+ if (Math.abs(total.x) > Math.abs(total.y)) total.y = 0; else total.x = 0;
1453
1608
  }
1454
- this.move(DragEvent.getValidMove(target, dragStartData.point, total));
1609
+ move = DragEvent.getValidMove(target, dragStartData.point, total, checkLimitMove);
1455
1610
  }
1611
+ if (dragLimitAnimate && isMoveEnd) LeafHelper.animateMove(this, move, isNumber(dragLimitAnimate) ? dragLimitAnimate : .3); else this.move(move);
1456
1612
  }
1457
1613
  onScale(e) {
1458
- const { target, mergeConfig, single, dragStartData } = this.editBox;
1459
- let { around, lockRatio, resizeable, flipable, editSize } = mergeConfig;
1614
+ const {target: target, mergeConfig: mergeConfig, single: single, dragStartData: dragStartData} = this.editBox;
1615
+ let {around: around, lockRatio: lockRatio, flipable: flipable, editSize: editSize} = mergeConfig;
1460
1616
  if (e instanceof ZoomEvent) {
1461
- if (resizeable === 'zoom')
1462
- e.stop(), this.scaleOf(target.getBoxPoint(e), e.scale, e.scale);
1463
- }
1464
- else {
1465
- const { direction } = e.current;
1466
- if (e.shiftKey || target.lockRatio)
1467
- lockRatio = true;
1468
- const data = EditDataHelper.getScaleData(target, dragStartData.bounds, direction, e.getInnerTotal(target), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, !single || editSize === 'scale');
1617
+ this.scaleOf(target.getBoxPoint(e), e.scale, e.scale);
1618
+ } else {
1619
+ const {direction: direction} = e.current;
1620
+ if (e.shiftKey || target.lockRatio) lockRatio = true;
1621
+ const data = EditDataHelper.getScaleData(target, dragStartData.bounds, direction, e.getInnerTotal(target), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, !single || editSize === "scale");
1469
1622
  if (this.editTool && this.editTool.onScaleWithDrag) {
1470
1623
  data.drag = e;
1471
1624
  this.scaleWithDrag(data);
1472
- }
1473
- else {
1625
+ } else {
1474
1626
  this.scaleOf(data.origin, data.scaleX, data.scaleY);
1475
1627
  }
1476
1628
  }
1477
1629
  }
1478
1630
  onRotate(e) {
1479
- const { target, mergeConfig, dragStartData } = this.editBox;
1480
- const { skewable, rotateable, around, rotateGap } = mergeConfig;
1481
- const { direction, name } = e.current;
1482
- if (skewable && name === 'resize-line')
1483
- return this.onSkew(e);
1631
+ const {target: target, mergeConfig: mergeConfig, dragStartData: dragStartData} = this.editBox;
1632
+ const {around: around, rotateAround: rotateAround, rotateGap: rotateGap} = mergeConfig;
1633
+ const {direction: direction} = e.current;
1484
1634
  let origin, rotation;
1485
1635
  if (e instanceof RotateEvent) {
1486
- if (rotateable === 'rotate')
1487
- e.stop(), rotation = e.rotation, origin = target.getBoxPoint(e);
1488
- else
1489
- return;
1490
- if (target.scaleX * target.scaleY < 0)
1491
- rotation = -rotation;
1492
- }
1493
- else {
1494
- const data = EditDataHelper.getRotateData(target, direction, e, dragStartData, e.shiftKey ? null : (target.around || target.origin || around || 'center'));
1495
- rotation = data.rotation;
1636
+ rotation = e.rotation;
1637
+ origin = rotateAround ? AroundHelper.getPoint(rotateAround, target.boxBounds) : target.getBoxPoint(e);
1638
+ } else {
1639
+ const data = EditDataHelper.getRotateData(target, direction, e, dragStartData, e.shiftKey ? null : rotateAround || target.around || target.origin || around || "center");
1640
+ rotation = dragStartData.rotation + data.rotation - target.rotation;
1496
1641
  origin = data.origin;
1497
1642
  }
1498
- if (target.scaleX * target.scaleY < 0)
1499
- rotation = -rotation;
1500
- if (e instanceof DragEvent)
1501
- rotation = dragStartData.rotation + rotation - target.rotation;
1502
1643
  rotation = MathHelper.float(MathHelper.getGapRotation(rotation, rotateGap, target.rotation), 2);
1503
- if (!rotation)
1504
- return;
1644
+ if (!rotation) return;
1505
1645
  this.rotateOf(origin, rotation);
1506
1646
  }
1507
1647
  onSkew(e) {
1508
- const { target, mergeConfig } = this.editBox;
1509
- const { around } = mergeConfig;
1510
- const { origin, skewX, skewY } = EditDataHelper.getSkewData(target.boxBounds, e.current.direction, e.getInnerMove(target), EditDataHelper.getAround(around, e.altKey));
1511
- if (!skewX && !skewY)
1512
- return;
1648
+ const {target: target, mergeConfig: mergeConfig} = this.editBox;
1649
+ const {around: around} = mergeConfig;
1650
+ const {origin: origin, skewX: skewX, skewY: skewY} = EditDataHelper.getSkewData(target.boxBounds, e.current.direction, e.getInnerMove(target), EditDataHelper.getAround(around, e.altKey));
1651
+ if (!skewX && !skewY) return;
1513
1652
  this.skewOf(origin, skewX, skewY);
1514
1653
  }
1515
1654
  move(x, y = 0) {
1516
- if (!this.checkTransform('moveable'))
1517
- return;
1518
- if (typeof x === 'object')
1519
- y = x.y, x = x.x;
1520
- const { target, mergeConfig, single, editor } = this.editBox;
1521
- const { beforeMove } = mergeConfig;
1655
+ if (!this.checkTransform("moveable")) return;
1656
+ if (isObject(x)) y = x.y, x = x.x;
1657
+ const {target: target, mergeConfig: mergeConfig, single: single, editor: editor} = this.editBox;
1658
+ const {beforeMove: beforeMove} = mergeConfig;
1522
1659
  if (beforeMove) {
1523
- const check = beforeMove({ target, x, y });
1524
- if (typeof check === 'object')
1525
- x = check.x, y = check.y;
1526
- else if (check === false)
1527
- return;
1528
- }
1529
- const world = target.getWorldPointByLocal({ x, y }, null, true);
1530
- if (!single)
1531
- target.safeChange(() => target.move(x, y));
1532
- const data = { target, editor, moveX: world.x, moveY: world.y };
1660
+ const check = beforeMove({
1661
+ target: target,
1662
+ x: x,
1663
+ y: y
1664
+ });
1665
+ if (isObject(check)) x = check.x, y = check.y; else if (check === false) return;
1666
+ }
1667
+ const world = target.getWorldPointByLocal({
1668
+ x: x,
1669
+ y: y
1670
+ }, null, true);
1671
+ if (!single) target.safeChange(() => target.move(x, y));
1672
+ const data = {
1673
+ target: target,
1674
+ editor: editor,
1675
+ moveX: world.x,
1676
+ moveY: world.y
1677
+ };
1533
1678
  this.emitEvent(new EditorMoveEvent(EditorMoveEvent.BEFORE_MOVE, data));
1534
1679
  const event = new EditorMoveEvent(EditorMoveEvent.MOVE, data);
1535
1680
  this.doMove(event);
1536
1681
  this.emitEvent(event);
1537
1682
  }
1538
1683
  scaleWithDrag(data) {
1539
- if (!this.checkTransform('resizeable'))
1540
- return;
1541
- const { target, mergeConfig, editor } = this.editBox;
1542
- const { beforeScale } = mergeConfig;
1684
+ if (!this.checkTransform("resizeable")) return;
1685
+ const {target: target, mergeConfig: mergeConfig, editor: editor} = this.editBox;
1686
+ const {beforeScale: beforeScale} = mergeConfig;
1543
1687
  if (beforeScale) {
1544
- const { origin, scaleX, scaleY, drag } = data;
1545
- const check = beforeScale({ target, drag, origin, scaleX, scaleY });
1546
- if (check === false)
1547
- return;
1688
+ const {origin: origin, scaleX: scaleX, scaleY: scaleY, drag: drag} = data;
1689
+ const check = beforeScale({
1690
+ target: target,
1691
+ drag: drag,
1692
+ origin: origin,
1693
+ scaleX: scaleX,
1694
+ scaleY: scaleY
1695
+ });
1696
+ if (check === false) return;
1548
1697
  }
1549
- data = Object.assign(Object.assign({}, data), { target, editor, worldOrigin: target.getWorldPoint(data.origin) });
1698
+ data = Object.assign(Object.assign({}, data), {
1699
+ target: target,
1700
+ editor: editor,
1701
+ worldOrigin: target.getWorldPoint(data.origin)
1702
+ });
1550
1703
  this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
1551
1704
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
1552
1705
  this.editTool.onScaleWithDrag(event);
1553
1706
  this.emitEvent(event);
1554
1707
  }
1555
1708
  scaleOf(origin, scaleX, scaleY = scaleX, _resize) {
1556
- if (!this.checkTransform('resizeable'))
1557
- return;
1558
- const { target, mergeConfig, single, editor } = this.editBox;
1559
- const { beforeScale } = mergeConfig;
1709
+ if (!this.checkTransform("resizeable")) return;
1710
+ const {target: target, mergeConfig: mergeConfig, single: single, editor: editor} = this.editBox;
1711
+ const {beforeScale: beforeScale} = mergeConfig;
1560
1712
  if (beforeScale) {
1561
- const check = beforeScale({ target, origin, scaleX, scaleY });
1562
- if (typeof check === 'object')
1563
- scaleX = check.scaleX, scaleY = check.scaleY;
1564
- else if (check === false)
1565
- return;
1713
+ const check = beforeScale({
1714
+ target: target,
1715
+ origin: origin,
1716
+ scaleX: scaleX,
1717
+ scaleY: scaleY
1718
+ });
1719
+ if (isObject(check)) scaleX = check.scaleX, scaleY = check.scaleY; else if (check === false) return;
1566
1720
  }
1567
1721
  const worldOrigin = this.getWorldOrigin(origin);
1568
1722
  const transform = !single && this.getChangedTransform(() => target.safeChange(() => target.scaleOf(origin, scaleX, scaleY)));
1569
- const data = { target, editor, worldOrigin, scaleX, scaleY, transform };
1723
+ const data = {
1724
+ target: target,
1725
+ editor: editor,
1726
+ worldOrigin: worldOrigin,
1727
+ scaleX: scaleX,
1728
+ scaleY: scaleY,
1729
+ transform: transform
1730
+ };
1570
1731
  this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
1571
1732
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
1572
1733
  this.doScale(event);
1573
1734
  this.emitEvent(event);
1574
1735
  }
1575
1736
  flip(axis) {
1576
- if (!this.checkTransform('resizeable'))
1577
- return;
1578
- const { target, single, editor } = this.editBox;
1579
- const worldOrigin = this.getWorldOrigin('center');
1737
+ if (!this.checkTransform("resizeable")) return;
1738
+ const {target: target, single: single, editor: editor} = this.editBox;
1739
+ const worldOrigin = this.getWorldOrigin("center");
1580
1740
  const transform = !single ? this.getChangedTransform(() => target.safeChange(() => target.flip(axis))) : new Matrix(LeafHelper.getFlipTransform(target, axis));
1581
- const data = { target, editor, worldOrigin, scaleX: axis === 'x' ? -1 : 1, scaleY: axis === 'y' ? -1 : 1, transform };
1741
+ const data = {
1742
+ target: target,
1743
+ editor: editor,
1744
+ worldOrigin: worldOrigin,
1745
+ scaleX: axis === "x" ? -1 : 1,
1746
+ scaleY: axis === "y" ? -1 : 1,
1747
+ transform: transform
1748
+ };
1582
1749
  this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
1583
1750
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
1584
1751
  this.doScale(event);
1585
1752
  this.emitEvent(event);
1586
1753
  }
1587
1754
  rotateOf(origin, rotation) {
1588
- if (!this.checkTransform('rotateable'))
1589
- return;
1590
- const { target, mergeConfig, single, editor } = this.editBox;
1591
- const { beforeRotate } = mergeConfig;
1755
+ if (!this.checkTransform("rotateable")) return;
1756
+ const {target: target, mergeConfig: mergeConfig, single: single, editor: editor} = this.editBox;
1757
+ const {beforeRotate: beforeRotate} = mergeConfig;
1592
1758
  if (beforeRotate) {
1593
- const check = beforeRotate({ target, origin, rotation });
1594
- if (typeof check === 'number')
1595
- rotation = check;
1596
- else if (check === false)
1597
- return;
1759
+ const check = beforeRotate({
1760
+ target: target,
1761
+ origin: origin,
1762
+ rotation: rotation
1763
+ });
1764
+ if (isNumber(check)) rotation = check; else if (check === false) return;
1598
1765
  }
1599
1766
  const worldOrigin = this.getWorldOrigin(origin);
1600
1767
  const transform = !single && this.getChangedTransform(() => target.safeChange(() => target.rotateOf(origin, rotation)));
1601
- const data = { target, editor, worldOrigin, rotation, transform };
1768
+ const data = {
1769
+ target: target,
1770
+ editor: editor,
1771
+ worldOrigin: worldOrigin,
1772
+ rotation: rotation,
1773
+ transform: transform
1774
+ };
1602
1775
  this.emitEvent(new EditorRotateEvent(EditorRotateEvent.BEFORE_ROTATE, data));
1603
1776
  const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, data);
1604
1777
  this.doRotate(event);
1605
1778
  this.emitEvent(event);
1606
1779
  }
1607
1780
  skewOf(origin, skewX, skewY = 0, _resize) {
1608
- if (!this.checkTransform('skewable'))
1609
- return;
1610
- const { target, mergeConfig, single, editor } = this.editBox;
1611
- const { beforeSkew } = mergeConfig;
1781
+ if (!this.checkTransform("skewable")) return;
1782
+ const {target: target, mergeConfig: mergeConfig, single: single, editor: editor} = this.editBox;
1783
+ const {beforeSkew: beforeSkew} = mergeConfig;
1612
1784
  if (beforeSkew) {
1613
- const check = beforeSkew({ target, origin, skewX, skewY });
1614
- if (typeof check === 'object')
1615
- skewX = check.skewX, skewY = check.skewY;
1616
- else if (check === false)
1617
- return;
1785
+ const check = beforeSkew({
1786
+ target: target,
1787
+ origin: origin,
1788
+ skewX: skewX,
1789
+ skewY: skewY
1790
+ });
1791
+ if (isObject(check)) skewX = check.skewX, skewY = check.skewY; else if (check === false) return;
1618
1792
  }
1619
1793
  const worldOrigin = this.getWorldOrigin(origin);
1620
1794
  const transform = !single && this.getChangedTransform(() => target.safeChange(() => target.skewOf(origin, skewX, skewY)));
1621
- const data = { target, editor, worldOrigin, skewX, skewY, transform };
1795
+ const data = {
1796
+ target: target,
1797
+ editor: editor,
1798
+ worldOrigin: worldOrigin,
1799
+ skewX: skewX,
1800
+ skewY: skewY,
1801
+ transform: transform
1802
+ };
1622
1803
  this.emitEvent(new EditorSkewEvent(EditorSkewEvent.BEFORE_SKEW, data));
1623
1804
  const event = new EditorSkewEvent(EditorSkewEvent.SKEW, data);
1624
1805
  this.doSkew(event);
@@ -1637,17 +1818,16 @@ class TransformTool {
1637
1818
  this.editTool.onSkew(event);
1638
1819
  }
1639
1820
  checkTransform(type) {
1640
- const { target, mergeConfig } = this.editBox;
1821
+ const {target: target, mergeConfig: mergeConfig} = this.editBox;
1641
1822
  return target && !target.locked && mergeConfig[type];
1642
1823
  }
1643
1824
  getWorldOrigin(origin) {
1644
- const { target } = this.editBox;
1825
+ const {target: target} = this.editBox;
1645
1826
  return target.getWorldPoint(LeafHelper.getInnerOrigin(target, origin));
1646
1827
  }
1647
1828
  getChangedTransform(func) {
1648
- const { target, single } = this.editBox;
1649
- if (!single && !target.canChange)
1650
- return target.changedTransform;
1829
+ const {target: target, single: single} = this.editBox;
1830
+ if (!single && !target.canChange) return target.changedTransform;
1651
1831
  const oldMatrix = new Matrix(target.worldTransform);
1652
1832
  func();
1653
1833
  return new Matrix(target.worldTransform).divide(oldMatrix);
@@ -1658,21 +1838,55 @@ class TransformTool {
1658
1838
  }
1659
1839
 
1660
1840
  let Editor = class Editor extends Group {
1661
- get list() { return this.leafList.list; }
1662
- get dragHoverExclude() { return [this.editBox.rect]; }
1663
- get editing() { return !!this.list.length; }
1664
- get groupOpening() { return !!this.openedGroupList.length; }
1665
- get multiple() { return this.list.length > 1; }
1666
- get single() { return this.list.length === 1; }
1667
- get dragging() { return this.editBox.dragging; }
1668
- get moving() { return this.editBox.moving; }
1669
- get dragPoint() { return this.editBox.dragPoint; }
1670
- get element() { return this.multiple ? this.simulateTarget : this.list[0]; }
1671
- get buttons() { return this.editBox.buttons; }
1841
+ get list() {
1842
+ return this.leafList.list;
1843
+ }
1844
+ get dragHoverExclude() {
1845
+ return [ this.editBox.rect ];
1846
+ }
1847
+ get editing() {
1848
+ return !!this.list.length;
1849
+ }
1850
+ get groupOpening() {
1851
+ return !!this.openedGroupList.length;
1852
+ }
1853
+ get multiple() {
1854
+ return this.list.length > 1;
1855
+ }
1856
+ get single() {
1857
+ return this.list.length === 1;
1858
+ }
1859
+ get dragPoint() {
1860
+ return this.editBox.dragPoint;
1861
+ }
1862
+ get dragging() {
1863
+ return this.editBox.dragging;
1864
+ }
1865
+ get gesturing() {
1866
+ return this.editBox.gesturing;
1867
+ }
1868
+ get moving() {
1869
+ return this.editBox.moving;
1870
+ }
1871
+ get resizing() {
1872
+ return this.editBox.resizing;
1873
+ }
1874
+ get rotating() {
1875
+ return this.editBox.rotating;
1876
+ }
1877
+ get skewing() {
1878
+ return this.editBox.skewing;
1879
+ }
1880
+ get element() {
1881
+ return this.multiple ? this.simulateTarget : this.list[0];
1882
+ }
1883
+ get buttons() {
1884
+ return this.editBox.buttons;
1885
+ }
1672
1886
  constructor(userConfig, data) {
1673
1887
  super(data);
1674
- this.leafList = new LeafList();
1675
- this.openedGroupList = new LeafList();
1888
+ this.leafList = new LeafList;
1889
+ this.openedGroupList = new LeafList;
1676
1890
  this.simulateTarget = new SimulateElement(this);
1677
1891
  this.editBox = new EditBox(this);
1678
1892
  this.editToolList = {};
@@ -1680,12 +1894,10 @@ let Editor = class Editor extends Group {
1680
1894
  this.editMask = new EditMask(this);
1681
1895
  this.targetEventIds = [];
1682
1896
  let mergedConfig = DataHelper.clone(config);
1683
- if (userConfig)
1684
- mergedConfig = DataHelper.default(userConfig, mergedConfig);
1897
+ if (userConfig) mergedConfig = DataHelper.default(userConfig, mergedConfig);
1685
1898
  this.mergedConfig = this.config = mergedConfig;
1686
1899
  this.addMany(this.editMask, this.selector, this.editBox);
1687
- if (!Plugin.has('resize'))
1688
- this.config.editSize = 'scale';
1900
+ if (!Plugin.has("resize")) this.config.editSize = "scale";
1689
1901
  }
1690
1902
  select(target) {
1691
1903
  this.target = target;
@@ -1697,62 +1909,66 @@ let Editor = class Editor extends Group {
1697
1909
  return this.leafList.has(item);
1698
1910
  }
1699
1911
  addItem(item) {
1700
- if (!this.hasItem(item) && !item.locked)
1701
- this.leafList.add(item), this.target = this.leafList.list;
1912
+ if (!this.hasItem(item) && !item.locked) this.leafList.add(item), this.target = this.leafList.list;
1702
1913
  }
1703
1914
  removeItem(item) {
1704
- if (this.hasItem(item))
1705
- this.leafList.remove(item), this.target = this.leafList.list;
1915
+ if (this.hasItem(item)) this.leafList.remove(item), this.target = this.leafList.list;
1706
1916
  }
1707
1917
  shiftItem(item) {
1708
1918
  this.hasItem(item) ? this.removeItem(item) : this.addItem(item);
1709
1919
  }
1710
1920
  update() {
1711
1921
  if (this.editing) {
1712
- if (!this.element.parent)
1713
- return this.cancel();
1714
- if (this.innerEditing)
1715
- this.innerEditor.update();
1922
+ if (!this.element.parent) return this.cancel();
1923
+ if (this.innerEditing) this.innerEditor.update();
1716
1924
  this.editTool.update();
1717
1925
  this.selector.update();
1718
1926
  }
1719
1927
  }
1720
1928
  updateEditBox() {
1721
- if (this.multiple)
1722
- simulate(this);
1929
+ if (this.multiple) simulate(this);
1723
1930
  this.update();
1724
1931
  }
1725
1932
  updateEditTool() {
1933
+ this.unloadEditTool();
1934
+ if (this.editing) {
1935
+ const name = this.element.editOuter || "EditTool";
1936
+ const tool = this.editTool = this.editToolList[name] = this.editToolList[name] || EditToolCreator.get(name, this);
1937
+ this.editBox.load();
1938
+ tool.load();
1939
+ this.update();
1940
+ }
1941
+ }
1942
+ unloadEditTool() {
1726
1943
  let tool = this.editTool;
1727
1944
  if (tool) {
1728
1945
  this.editBox.unload();
1729
1946
  tool.unload();
1730
1947
  this.editTool = null;
1731
1948
  }
1732
- if (this.editing) {
1733
- const tag = this.element.editOuter || 'EditTool';
1734
- tool = this.editTool = this.editToolList[tag] = this.editToolList[tag] || EditToolCreator.get(tag, this);
1735
- this.editBox.load();
1736
- tool.load();
1737
- this.update();
1738
- }
1739
1949
  }
1740
1950
  getEditSize(_ui) {
1741
1951
  return this.mergeConfig.editSize;
1742
1952
  }
1743
- onMove(_e) { }
1744
- onScale(_e) { }
1745
- onRotate(_e) { }
1746
- onSkew(_e) { }
1747
- move(_x, _y = 0) { }
1748
- scaleWithDrag(_data) { }
1749
- scaleOf(_origin, scaleX, _scaleY = scaleX, _resize) { }
1750
- flip(_axis) { }
1751
- rotateOf(_origin, _rotation) { }
1752
- skewOf(_origin, _skewX, _skewY = 0, _resize) { }
1753
- checkTransform(_type) { return undefined; }
1754
- getWorldOrigin(_origin) { return undefined; }
1755
- getChangedTransform(_func) { return undefined; }
1953
+ onMove(_e) {}
1954
+ onScale(_e) {}
1955
+ onRotate(_e) {}
1956
+ onSkew(_e) {}
1957
+ move(_x, _y = 0) {}
1958
+ scaleWithDrag(_data) {}
1959
+ scaleOf(_origin, scaleX, _scaleY = scaleX, _resize) {}
1960
+ flip(_axis) {}
1961
+ rotateOf(_origin, _rotation) {}
1962
+ skewOf(_origin, _skewX, _skewY = 0, _resize) {}
1963
+ checkTransform(_type) {
1964
+ return undefined;
1965
+ }
1966
+ getWorldOrigin(_origin) {
1967
+ return undefined;
1968
+ }
1969
+ getChangedTransform(_func) {
1970
+ return undefined;
1971
+ }
1756
1972
  group(userGroup) {
1757
1973
  if (this.multiple) {
1758
1974
  this.emitGroupEvent(EditorGroupEvent.BEFORE_GROUP);
@@ -1762,7 +1978,7 @@ let Editor = class Editor extends Group {
1762
1978
  return this.target;
1763
1979
  }
1764
1980
  ungroup() {
1765
- const { list } = this;
1981
+ const {list: list} = this;
1766
1982
  if (list.length) {
1767
1983
  list.forEach(item => item.isBranch && this.emitGroupEvent(EditorGroupEvent.BEFORE_UNGROUP, item));
1768
1984
  this.target = EditorHelper.ungroup(list);
@@ -1785,16 +2001,14 @@ let Editor = class Editor extends Group {
1785
2001
  checkOpenedGroups() {
1786
2002
  const opened = this.openedGroupList;
1787
2003
  if (opened.length) {
1788
- let { list } = opened;
1789
- if (this.editing)
1790
- list = [], opened.forEach(item => this.list.every(leaf => !LeafHelper.hasParent(leaf, item)) && list.push(item));
2004
+ let {list: list} = opened;
2005
+ if (this.editing) list = [], opened.forEach(item => this.list.every(leaf => !LeafHelper.hasParent(leaf, item)) && list.push(item));
1791
2006
  list.forEach(item => this.closeGroup(item));
1792
2007
  }
1793
- if (this.editing && !this.selector.dragging)
1794
- this.checkDeepSelect();
2008
+ if (this.editing && !this.selector.dragging) this.checkDeepSelect();
1795
2009
  }
1796
2010
  checkDeepSelect() {
1797
- let parent, { list } = this;
2011
+ let parent, {list: list} = this;
1798
2012
  for (let i = 0; i < list.length; i++) {
1799
2013
  parent = list[i].parent;
1800
2014
  while (parent && !parent.hitChildren) {
@@ -1804,42 +2018,48 @@ let Editor = class Editor extends Group {
1804
2018
  }
1805
2019
  }
1806
2020
  emitGroupEvent(type, group) {
1807
- const event = new EditorGroupEvent(type, { editTarget: group });
1808
- this.emitEvent(event);
1809
- if (group)
1810
- group.emitEvent(event);
2021
+ const event = new EditorGroupEvent(type, {
2022
+ editTarget: group
2023
+ });
2024
+ if (!group || !group.syncEventer) this.emitEvent(event);
2025
+ if (group) group.emitEvent(event);
1811
2026
  }
1812
- openInnerEditor(target, select) {
1813
- if (target && select)
1814
- this.target = target;
2027
+ openInnerEditor(target, nameOrSelect, select) {
2028
+ let name;
2029
+ if (isString(nameOrSelect)) name = nameOrSelect; else if (!select) select = nameOrSelect;
2030
+ if (target && select) this.target = target;
1815
2031
  if (this.single) {
1816
2032
  const editTarget = target || this.element;
1817
- const tag = editTarget.editInner;
1818
- if (tag && EditToolCreator.list[tag]) {
2033
+ name || (name = editTarget.editInner);
2034
+ if (name && EditToolCreator.list[name]) {
1819
2035
  this.editTool.unload();
1820
2036
  this.innerEditing = true;
1821
- this.innerEditor = this.editToolList[tag] || EditToolCreator.get(tag, this);
2037
+ this.innerEditor = this.editToolList[name] = this.editToolList[name] || EditToolCreator.get(name, this);
1822
2038
  this.innerEditor.editTarget = editTarget;
1823
2039
  this.emitInnerEvent(InnerEditorEvent.BEFORE_OPEN);
1824
2040
  this.innerEditor.load();
1825
2041
  this.emitInnerEvent(InnerEditorEvent.OPEN);
2042
+ console.log("hello");
1826
2043
  }
1827
2044
  }
1828
2045
  }
1829
- closeInnerEditor() {
2046
+ closeInnerEditor(onlyInnerEditor) {
1830
2047
  if (this.innerEditing) {
1831
2048
  this.innerEditing = false;
1832
2049
  this.emitInnerEvent(InnerEditorEvent.BEFORE_CLOSE);
1833
2050
  this.innerEditor.unload();
1834
2051
  this.emitInnerEvent(InnerEditorEvent.CLOSE);
1835
- this.editTool.load();
2052
+ if (!onlyInnerEditor) this.updateEditTool();
1836
2053
  this.innerEditor = null;
1837
2054
  }
1838
2055
  }
1839
2056
  emitInnerEvent(type) {
1840
- const { innerEditor } = this, { editTarget } = innerEditor;
1841
- const event = new InnerEditorEvent(type, { editTarget, innerEditor });
1842
- this.emitEvent(event);
2057
+ const {innerEditor: innerEditor} = this, {editTarget: editTarget} = innerEditor;
2058
+ const event = new InnerEditorEvent(type, {
2059
+ editTarget: editTarget,
2060
+ innerEditor: innerEditor
2061
+ });
2062
+ if (!editTarget.syncEventer) this.emitEvent(event);
1843
2063
  editTarget.emitEvent(event);
1844
2064
  }
1845
2065
  lock() {
@@ -1863,35 +2083,23 @@ let Editor = class Editor extends Group {
1863
2083
  }
1864
2084
  }
1865
2085
  onAppRenderStart(app) {
1866
- if (this.targetChanged = app.children.some(leafer => leafer !== this.leafer && leafer.renderer.changed))
1867
- this.editBox.forceRender();
2086
+ if (this.targetChanged = app.children.some(leafer => leafer !== this.leafer && leafer.renderer.changed)) this.editBox.forceRender();
1868
2087
  }
1869
2088
  onRenderStart() {
1870
- if (this.targetChanged)
1871
- this.update();
2089
+ if (this.targetChanged) this.update();
1872
2090
  }
1873
2091
  listenTargetEvents() {
1874
2092
  if (!this.targetEventIds.length) {
1875
- const { app, leafer, editMask } = this;
1876
- this.targetEventIds = [
1877
- leafer.on_(RenderEvent.START, this.onRenderStart, this),
1878
- app.on_([
1879
- [RenderEvent.CHILD_START, this.onAppRenderStart, this],
1880
- [MoveEvent.BEFORE_MOVE, this.onMove, this, true],
1881
- [ZoomEvent.BEFORE_ZOOM, this.onScale, this, true],
1882
- [RotateEvent.BEFORE_ROTATE, this.onRotate, this, true],
1883
- ])
1884
- ];
1885
- if (editMask.visible)
1886
- editMask.forceRender();
2093
+ const {app: app, leafer: leafer, editMask: editMask} = this;
2094
+ this.targetEventIds = [ leafer.on_(RenderEvent.START, this.onRenderStart, this), app.on_(RenderEvent.CHILD_START, this.onAppRenderStart, this) ];
2095
+ if (editMask.visible) editMask.forceRender();
1887
2096
  }
1888
2097
  }
1889
2098
  removeTargetEvents() {
1890
- const { targetEventIds, editMask } = this;
2099
+ const {targetEventIds: targetEventIds, editMask: editMask} = this;
1891
2100
  if (targetEventIds.length) {
1892
2101
  this.off_(targetEventIds);
1893
- if (editMask.visible)
1894
- editMask.forceRender();
2102
+ if (editMask.visible) editMask.forceRender();
1895
2103
  }
1896
2104
  }
1897
2105
  destroy() {
@@ -1905,64 +2113,64 @@ let Editor = class Editor extends Group {
1905
2113
  }
1906
2114
  }
1907
2115
  };
1908
- __decorate([
1909
- mergeConfigAttr()
1910
- ], Editor.prototype, "mergeConfig", void 0);
1911
- __decorate([
1912
- targetAttr(onHover)
1913
- ], Editor.prototype, "hoverTarget", void 0);
1914
- __decorate([
1915
- targetAttr(onTarget)
1916
- ], Editor.prototype, "target", void 0);
1917
- Editor = __decorate([
1918
- useModule(TransformTool, ['editBox', 'editTool', 'emitEvent'])
1919
- ], Editor);
2116
+
2117
+ __decorate([ mergeConfigAttr() ], Editor.prototype, "mergeConfig", void 0);
2118
+
2119
+ __decorate([ targetAttr(onHover) ], Editor.prototype, "hoverTarget", void 0);
2120
+
2121
+ __decorate([ targetAttr(onTarget) ], Editor.prototype, "target", void 0);
2122
+
2123
+ Editor = __decorate([ useModule(TransformTool, [ "editBox", "editTool", "emitEvent" ]) ], Editor);
1920
2124
 
1921
2125
  class InnerEditor {
1922
2126
  static registerInnerEditor() {
1923
2127
  EditToolCreator.register(this);
1924
2128
  }
1925
- get tag() { return 'InnerEditor'; }
1926
- get mode() { return 'focus'; }
1927
- get editBox() { return this.editor.editBox; }
2129
+ get tag() {
2130
+ return "InnerEditor";
2131
+ }
2132
+ get mode() {
2133
+ return "focus";
2134
+ }
2135
+ get editBox() {
2136
+ return this.editor.editBox;
2137
+ }
1928
2138
  constructor(editor) {
1929
2139
  this.eventIds = [];
1930
2140
  this.editor = editor;
1931
2141
  this.create();
1932
2142
  }
1933
- onCreate() { }
2143
+ onCreate() {}
1934
2144
  create() {
1935
- this.view = new Group();
2145
+ this.view = new Group;
1936
2146
  this.onCreate();
1937
2147
  }
1938
- onLoad() { }
2148
+ onLoad() {}
1939
2149
  load() {
1940
- const { editor } = this;
2150
+ const {editor: editor} = this;
1941
2151
  if (editor) {
1942
- if (editor.app && this.mode === 'focus')
1943
- editor.selector.hittable = editor.app.tree.hitChildren = false;
2152
+ if (editor.app && this.mode === "focus") editor.selector.hittable = editor.app.tree.hitChildren = false;
1944
2153
  this.onLoad();
1945
2154
  }
1946
2155
  }
1947
- onUpdate() { }
1948
- update() { this.onUpdate(); }
1949
- onUnload() { }
2156
+ onUpdate() {}
2157
+ update() {
2158
+ this.onUpdate();
2159
+ }
2160
+ onUnload() {}
1950
2161
  unload() {
1951
- const { editor } = this;
2162
+ const {editor: editor} = this;
1952
2163
  if (editor) {
1953
- if (editor.app && this.mode === 'focus')
1954
- editor.selector.hittable = editor.app.tree.hitChildren = true;
2164
+ if (editor.app && this.mode === "focus") editor.selector.hittable = editor.app.tree.hitChildren = true;
1955
2165
  this.onUnload();
1956
2166
  }
1957
2167
  }
1958
- onDestroy() { }
2168
+ onDestroy() {}
1959
2169
  destroy() {
1960
2170
  this.onDestroy();
1961
2171
  if (this.editor) {
1962
- if (this.view)
1963
- this.view.destroy();
1964
- if (this.eventIds)
1965
- this.editor.off_(this.eventIds);
2172
+ if (this.view) this.view.destroy();
2173
+ if (this.eventIds) this.editor.off_(this.eventIds);
1966
2174
  this.editor = this.view = this.eventIds = null;
1967
2175
  }
1968
2176
  }
@@ -1972,50 +2180,45 @@ let EditTool = class EditTool extends InnerEditor {
1972
2180
  static registerEditTool() {
1973
2181
  EditToolCreator.register(this);
1974
2182
  }
1975
- get tag() { return 'EditTool'; }
2183
+ get tag() {
2184
+ return "EditTool";
2185
+ }
1976
2186
  onMove(e) {
1977
- const { moveX, moveY, editor } = e;
1978
- const { app, list } = editor;
2187
+ const {moveX: moveX, moveY: moveY, editor: editor} = e;
2188
+ const {app: app, list: list} = editor;
1979
2189
  app.lockLayout();
1980
- list.forEach(target => { target.moveWorld(moveX, moveY); });
2190
+ list.forEach(target => {
2191
+ target.moveWorld(moveX, moveY);
2192
+ });
1981
2193
  app.unlockLayout();
1982
2194
  }
1983
2195
  onScale(e) {
1984
- const { scaleX, scaleY, transform, worldOrigin, editor } = e;
1985
- const { app, list } = editor;
2196
+ const {scaleX: scaleX, scaleY: scaleY, transform: transform, worldOrigin: worldOrigin, editor: editor} = e;
2197
+ const {app: app, list: list} = editor;
1986
2198
  app.lockLayout();
1987
2199
  list.forEach(target => {
1988
- const resize = editor.getEditSize(target) !== 'scale';
1989
- if (transform)
1990
- target.transformWorld(transform, resize);
1991
- else
1992
- target.scaleOfWorld(worldOrigin, scaleX, scaleY, resize);
2200
+ const resize = editor.getEditSize(target) !== "scale";
2201
+ if (transform) target.transformWorld(transform, resize); else target.scaleOfWorld(worldOrigin, scaleX, scaleY, resize);
1993
2202
  });
1994
2203
  app.unlockLayout();
1995
2204
  }
1996
2205
  onRotate(e) {
1997
- const { rotation, transform, worldOrigin, editor } = e;
1998
- const { app, list } = editor;
2206
+ const {rotation: rotation, transform: transform, worldOrigin: worldOrigin, editor: editor} = e;
2207
+ const {app: app, list: list} = editor;
1999
2208
  app.lockLayout();
2000
2209
  list.forEach(target => {
2001
- const resize = editor.getEditSize(target) !== 'scale';
2002
- if (transform)
2003
- target.transformWorld(transform, resize);
2004
- else
2005
- target.rotateOfWorld(worldOrigin, rotation);
2210
+ const resize = editor.getEditSize(target) !== "scale";
2211
+ if (transform) target.transformWorld(transform, resize); else target.rotateOfWorld(worldOrigin, rotation);
2006
2212
  });
2007
2213
  app.unlockLayout();
2008
2214
  }
2009
2215
  onSkew(e) {
2010
- const { skewX, skewY, transform, worldOrigin, editor } = e;
2011
- const { app, list } = editor;
2216
+ const {skewX: skewX, skewY: skewY, transform: transform, worldOrigin: worldOrigin, editor: editor} = e;
2217
+ const {app: app, list: list} = editor;
2012
2218
  app.lockLayout();
2013
2219
  list.forEach(target => {
2014
- const resize = editor.getEditSize(target) !== 'scale';
2015
- if (transform)
2016
- target.transformWorld(transform, resize);
2017
- else
2018
- target.skewOfWorld(worldOrigin, skewX, skewY, resize);
2220
+ const resize = editor.getEditSize(target) !== "scale";
2221
+ if (transform) target.transformWorld(transform, resize); else target.skewOfWorld(worldOrigin, skewX, skewY, resize);
2019
2222
  });
2020
2223
  app.unlockLayout();
2021
2224
  }
@@ -2032,41 +2235,42 @@ let EditTool = class EditTool extends InnerEditor {
2032
2235
  this.onUnload();
2033
2236
  }
2034
2237
  };
2035
- EditTool = __decorate([
2036
- registerEditTool()
2037
- ], EditTool);
2038
2238
 
2039
- const { left, right } = Direction9;
2040
- const { move, copy, toNumberPoints } = PointHelper;
2239
+ EditTool = __decorate([ registerEditTool() ], EditTool);
2240
+
2241
+ const {left: left, right: right} = Direction9;
2242
+
2243
+ const {move: move, copy: copy, toNumberPoints: toNumberPoints} = PointHelper;
2244
+
2041
2245
  let LineEditTool = class LineEditTool extends EditTool {
2042
2246
  constructor() {
2043
2247
  super(...arguments);
2044
2248
  this.scaleOfEvent = true;
2045
2249
  }
2046
- get tag() { return 'LineEditTool'; }
2250
+ get tag() {
2251
+ return "LineEditTool";
2252
+ }
2047
2253
  onScaleWithDrag(e) {
2048
- const { drag, direction, lockRatio, around } = e;
2254
+ const {drag: drag, direction: direction, lockRatio: lockRatio, around: around} = e;
2049
2255
  const line = e.target;
2050
2256
  const isDragFrom = direction === left;
2051
2257
  if (line.pathInputed) {
2052
- const { path } = line.__;
2053
- const { from, to } = this.getFromToByPath(path);
2258
+ const {path: path} = line.__;
2259
+ const {from: from, to: to} = this.getFromToByPath(path);
2054
2260
  this.dragPoint(from, to, isDragFrom, around, this.getInnerMove(line, drag, lockRatio));
2055
2261
  path[1] = from.x, path[2] = from.y;
2056
2262
  path[4] = to.x, path[5] = to.y;
2057
2263
  line.path = path;
2058
- }
2059
- else if (line.points) {
2060
- const { points } = line;
2061
- const { from, to } = this.getFromToByPoints(points);
2264
+ } else if (line.points) {
2265
+ const {points: points} = line;
2266
+ const {from: from, to: to} = this.getFromToByPoints(points);
2062
2267
  this.dragPoint(from, to, isDragFrom, around, this.getInnerMove(line, drag, lockRatio));
2063
2268
  points[0] = from.x, points[1] = from.y;
2064
2269
  points[2] = to.x, points[3] = to.y;
2065
2270
  line.points = points;
2066
- }
2067
- else {
2271
+ } else {
2068
2272
  const from = getPointData();
2069
- const { toPoint } = line;
2273
+ const {toPoint: toPoint} = line;
2070
2274
  line.rotation = 0;
2071
2275
  this.dragPoint(from, toPoint, isDragFrom, around, this.getInnerMove(line, drag, lockRatio));
2072
2276
  line.getLocalPointByInner(from, null, null, true);
@@ -2079,48 +2283,52 @@ let LineEditTool = class LineEditTool extends EditTool {
2079
2283
  }
2080
2284
  getInnerMove(ui, event, lockRatio) {
2081
2285
  const movePoint = event.getInnerMove(ui);
2082
- if (lockRatio)
2083
- Math.abs(movePoint.x) > Math.abs(movePoint.y) ? movePoint.y = 0 : movePoint.x = 0;
2286
+ if (lockRatio) Math.abs(movePoint.x) > Math.abs(movePoint.y) ? movePoint.y = 0 : movePoint.x = 0;
2084
2287
  return movePoint;
2085
2288
  }
2086
2289
  getFromToByPath(path) {
2087
2290
  return {
2088
- from: { x: path[1], y: path[2] },
2089
- to: { x: path[4], y: path[5] }
2291
+ from: {
2292
+ x: path[1],
2293
+ y: path[2]
2294
+ },
2295
+ to: {
2296
+ x: path[4],
2297
+ y: path[5]
2298
+ }
2090
2299
  };
2091
2300
  }
2092
2301
  getFromToByPoints(originPoints) {
2093
2302
  const points = toNumberPoints(originPoints);
2094
2303
  return {
2095
- from: { x: points[0], y: points[1] },
2096
- to: { x: points[2], y: points[3] }
2304
+ from: {
2305
+ x: points[0],
2306
+ y: points[1]
2307
+ },
2308
+ to: {
2309
+ x: points[2],
2310
+ y: points[3]
2311
+ }
2097
2312
  };
2098
2313
  }
2099
2314
  dragPoint(fromPoint, toPoint, isDragFrom, around, movePoint) {
2100
- const { x, y } = movePoint;
2315
+ const {x: x, y: y} = movePoint;
2101
2316
  if (isDragFrom) {
2102
2317
  move(fromPoint, x, y);
2103
- if (around)
2104
- move(toPoint, -x, -y);
2105
- }
2106
- else {
2107
- if (around)
2108
- move(fromPoint, -x, -y);
2318
+ if (around) move(toPoint, -x, -y);
2319
+ } else {
2320
+ if (around) move(fromPoint, -x, -y);
2109
2321
  move(toPoint, x, y);
2110
2322
  }
2111
2323
  }
2112
- onSkew(_e) {
2113
- }
2324
+ onSkew(_e) {}
2114
2325
  onUpdate() {
2115
- const { editBox } = this, { rotatePoints, resizeLines, resizePoints, rect } = editBox;
2326
+ const {editBox: editBox} = this, {rotatePoints: rotatePoints, resizeLines: resizeLines, resizePoints: resizePoints, rect: rect} = editBox;
2116
2327
  const line = this.editor.element;
2117
2328
  let fromTo, leftOrRight;
2118
- if (line.pathInputed)
2119
- fromTo = this.getFromToByPath(line.__.path);
2120
- else if (line.points)
2121
- fromTo = this.getFromToByPoints(line.__.points);
2329
+ if (line.pathInputed) fromTo = this.getFromToByPath(line.__.path); else if (line.points) fromTo = this.getFromToByPoints(line.__.points);
2122
2330
  if (fromTo) {
2123
- const { from, to } = fromTo;
2331
+ const {from: from, to: to} = fromTo;
2124
2332
  line.innerToWorld(from, from, false, editBox);
2125
2333
  line.innerToWorld(to, to, false, editBox);
2126
2334
  rect.pen.clearPath().moveTo(from.x, from.y).lineTo(to.x, to.y);
@@ -2130,33 +2338,49 @@ let LineEditTool = class LineEditTool extends EditTool {
2130
2338
  copy(rotatePoints[3], to);
2131
2339
  }
2132
2340
  for (let i = 0; i < 8; i++) {
2133
- if (i < 4)
2134
- resizeLines[i].visible = false;
2341
+ if (i < 4) resizeLines[i].visible = false;
2135
2342
  leftOrRight = i === left || i === right;
2136
2343
  resizePoints[i].visible = leftOrRight;
2137
2344
  rotatePoints[i].visible = fromTo ? false : leftOrRight;
2138
2345
  }
2139
2346
  }
2140
2347
  };
2141
- LineEditTool = __decorate([
2142
- registerEditTool()
2143
- ], LineEditTool);
2144
2348
 
2145
- Plugin.add('editor', 'resize');
2146
- Creator.editor = function (options, app) {
2349
+ LineEditTool = __decorate([ registerEditTool() ], LineEditTool);
2350
+
2351
+ Plugin.add("editor", "resize");
2352
+
2353
+ Creator.editor = function(options, app) {
2147
2354
  const editor = new Editor(options);
2148
- if (app)
2149
- app.sky.add(app.editor = editor);
2355
+ if (app) app.sky.add(app.editor = editor);
2150
2356
  return editor;
2151
2357
  };
2152
- Box.addAttr('textBox', false, dataType);
2153
- UI.addAttr('editConfig', undefined, dataType);
2154
- UI.addAttr('editOuter', (ui) => ui.__.__isLinePath ? 'LineEditTool' : 'EditTool', dataType);
2155
- UI.addAttr('editInner', 'PathEditor', dataType);
2156
- Group.addAttr('editInner', '', dataType);
2157
- Text.addAttr('editInner', 'TextEditor', dataType);
2158
- UI.setEditConfig = function (config) { this.changeAttr('editConfig', config); };
2159
- UI.setEditOuter = function (toolName) { this.changeAttr('editOuter', toolName); };
2160
- UI.setEditInner = function (editorName) { this.changeAttr('editInner', editorName); };
2358
+
2359
+ Box.addAttr("textBox", false, dataType);
2360
+
2361
+ UI.addAttr("editConfig", undefined, dataType);
2362
+
2363
+ UI.addAttr("editOuter", ui => {
2364
+ ui.updateLayout();
2365
+ return ui.__.__isLinePath ? "LineEditTool" : "EditTool";
2366
+ }, dataType);
2367
+
2368
+ UI.addAttr("editInner", "PathEditor", dataType);
2369
+
2370
+ Group.addAttr("editInner", "", dataType);
2371
+
2372
+ Text.addAttr("editInner", "TextEditor", dataType);
2373
+
2374
+ UI.setEditConfig = function(config) {
2375
+ this.changeAttr("editConfig", config);
2376
+ };
2377
+
2378
+ UI.setEditOuter = function(toolName) {
2379
+ this.changeAttr("editOuter", toolName);
2380
+ };
2381
+
2382
+ UI.setEditInner = function(editorName) {
2383
+ this.changeAttr("editInner", editorName);
2384
+ };
2161
2385
 
2162
2386
  export { EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorGroupEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, InnerEditor, InnerEditorEvent, LineEditTool, SelectArea, Stroker, TransformTool, registerEditTool, registerInnerEditor };