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