@leafer-in/editor 1.0.0-rc.8 → 1.0.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,7 +1,199 @@
1
1
  this.LeaferIN = this.LeaferIN || {};
2
- this.LeaferIN.editor = (function (exports, core) {
2
+ this.LeaferIN.editor = (function (exports, draw, core) {
3
3
  'use strict';
4
4
 
5
+ const { M, L, C, Q, Z, N, D, X, G, F, O, P, U } = draw.PathCommandMap;
6
+ const PathScaler = {
7
+ scale(data, scaleX, scaleY) {
8
+ if (!data)
9
+ return;
10
+ let command;
11
+ let i = 0, len = data.length;
12
+ while (i < len) {
13
+ command = data[i];
14
+ switch (command) {
15
+ case M:
16
+ scalePoints(data, scaleX, scaleY, i, 1);
17
+ i += 3;
18
+ break;
19
+ case L:
20
+ scalePoints(data, scaleX, scaleY, i, 1);
21
+ i += 3;
22
+ break;
23
+ case C:
24
+ scalePoints(data, scaleX, scaleY, i, 3);
25
+ i += 7;
26
+ break;
27
+ case Q:
28
+ scalePoints(data, scaleX, scaleY, i, 2);
29
+ i += 5;
30
+ break;
31
+ case Z:
32
+ i += 1;
33
+ break;
34
+ case N:
35
+ scalePoints(data, scaleX, scaleY, i, 2);
36
+ i += 5;
37
+ break;
38
+ case D:
39
+ scalePoints(data, scaleX, scaleY, i, 2);
40
+ i += 9;
41
+ break;
42
+ case X:
43
+ scalePoints(data, scaleX, scaleY, i, 2);
44
+ i += 6;
45
+ break;
46
+ case G:
47
+ scalePoints(data, scaleX, scaleY, i, 2);
48
+ i += 9;
49
+ break;
50
+ case F:
51
+ scalePoints(data, scaleX, scaleY, i, 2);
52
+ i += 5;
53
+ break;
54
+ case O:
55
+ data[i] = G;
56
+ data.splice(i + 4, 0, data[i + 3], 0);
57
+ scalePoints(data, scaleX, scaleY, i, 2);
58
+ i += 7 + 2;
59
+ len += 2;
60
+ break;
61
+ case P:
62
+ data[i] = F;
63
+ data.splice(i + 4, 0, data[i + 3]);
64
+ scalePoints(data, scaleX, scaleY, i, 2);
65
+ i += 4 + 1;
66
+ len += 1;
67
+ break;
68
+ case U:
69
+ scalePoints(data, scaleX, scaleY, i, 2);
70
+ i += 6;
71
+ break;
72
+ }
73
+ }
74
+ },
75
+ scalePoints(data, scaleX, scaleY, start, pointCount) {
76
+ for (let i = pointCount ? start + 1 : 0, end = pointCount ? i + pointCount * 2 : data.length; i < end; i += 2) {
77
+ data[i] *= scaleX;
78
+ data[i + 1] *= scaleY;
79
+ }
80
+ }
81
+ };
82
+ const { scalePoints } = PathScaler;
83
+
84
+ const matrix$1 = draw.MatrixHelper.get();
85
+ function scaleResize(leaf, scaleX, scaleY) {
86
+ if (leaf.pathInputed) {
87
+ scaleResizePath(leaf, scaleX, scaleY);
88
+ }
89
+ else {
90
+ if (scaleX !== 1)
91
+ leaf.width *= scaleX;
92
+ if (scaleY !== 1)
93
+ leaf.height *= scaleY;
94
+ }
95
+ }
96
+ function scaleResizeFontSize(leaf, scaleX, scaleY) {
97
+ const { width, height } = leaf.__localBoxBounds;
98
+ if (scaleX !== 1) {
99
+ leaf.fontSize *= scaleX;
100
+ leaf.y -= height * (scaleX - scaleY) / 2;
101
+ }
102
+ else if (scaleY !== 1) {
103
+ leaf.fontSize *= scaleY;
104
+ leaf.x -= width * (scaleY - scaleX) / 2;
105
+ }
106
+ }
107
+ function scaleResizePath(leaf, scaleX, scaleY) {
108
+ PathScaler.scale(leaf.__.path, scaleX, scaleY);
109
+ leaf.path = leaf.__.path;
110
+ }
111
+ function scaleResizePoints(leaf, scaleX, scaleY) {
112
+ PathScaler.scalePoints(leaf.__.points, scaleX, scaleY);
113
+ leaf.points = leaf.__.points;
114
+ }
115
+ function scaleResizeGroup(group, scaleX, scaleY) {
116
+ const { children } = group;
117
+ for (let i = 0; i < children.length; i++) {
118
+ matrix$1.a = scaleX;
119
+ matrix$1.d = scaleY;
120
+ children[i].transform(matrix$1, true);
121
+ }
122
+ }
123
+
124
+ const leaf = draw.Leaf.prototype;
125
+ leaf.scaleResize = function (scaleX, scaleY = scaleX, noResize) {
126
+ const data = this;
127
+ if (noResize || (data.editConfig && data.editConfig.editSize === 'scale')) {
128
+ data.scaleX *= scaleX;
129
+ data.scaleY *= scaleY;
130
+ }
131
+ else {
132
+ if (scaleX < 0)
133
+ data.scaleX *= -1, scaleX = -scaleX;
134
+ if (scaleY < 0)
135
+ data.scaleY *= -1, scaleY = -scaleY;
136
+ this.__scaleResize(scaleX, scaleY);
137
+ }
138
+ };
139
+ leaf.__scaleResize = function (scaleX, scaleY) {
140
+ scaleResize(this, scaleX, scaleY);
141
+ };
142
+ leaf.resizeWidth = function (width) {
143
+ const scale = width / this.getBounds('box', 'local').width;
144
+ this.scaleOf(this.__layout.boxBounds, scale, this.__.lockRatio ? scale : 1, true);
145
+ };
146
+ leaf.resizeHeight = function (height) {
147
+ const scale = height / this.getBounds('box', 'local').height;
148
+ this.scaleOf(this.__layout.boxBounds, this.__.lockRatio ? scale : 1, scale, true);
149
+ };
150
+ draw.Text.prototype.__scaleResize = function (scaleX, scaleY) {
151
+ if (this.__.__autoSize && (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size'))) {
152
+ scaleResizeFontSize(this, scaleX, scaleY);
153
+ }
154
+ else {
155
+ scaleResize(this, scaleX, scaleY);
156
+ }
157
+ };
158
+ draw.Path.prototype.__scaleResize = function (scaleX, scaleY) {
159
+ scaleResizePath(this, scaleX, scaleY);
160
+ };
161
+ draw.Line.prototype.__scaleResize = function (scaleX, scaleY) {
162
+ if (this.pathInputed) {
163
+ scaleResizePath(this, scaleX, scaleY);
164
+ }
165
+ else if (this.points) {
166
+ scaleResizePoints(this, scaleX, scaleY);
167
+ }
168
+ else {
169
+ this.width *= scaleX;
170
+ }
171
+ };
172
+ draw.Polygon.prototype.__scaleResize = function (scaleX, scaleY) {
173
+ if (this.pathInputed) {
174
+ scaleResizePath(this, scaleX, scaleY);
175
+ }
176
+ else if (this.points) {
177
+ scaleResizePoints(this, scaleX, scaleY);
178
+ }
179
+ else {
180
+ scaleResize(this, scaleX, scaleY);
181
+ }
182
+ };
183
+ draw.Group.prototype.__scaleResize = function (scaleX, scaleY) {
184
+ scaleResizeGroup(this, scaleX, scaleY);
185
+ };
186
+ draw.Box.prototype.__scaleResize = function (scaleX, scaleY) {
187
+ if (this.__.__autoSize && this.children.length) {
188
+ scaleResizeGroup(this, scaleX, scaleY);
189
+ }
190
+ else {
191
+ scaleResize(this, scaleX, scaleY);
192
+ if (this.__.resizeChildren)
193
+ scaleResizeGroup(this, scaleX, scaleY);
194
+ }
195
+ };
196
+
5
197
  /******************************************************************************
6
198
  Copyright (c) Microsoft Corporation.
7
199
 
@@ -31,7 +223,12 @@ this.LeaferIN.editor = (function (exports, core) {
31
223
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
32
224
  };
33
225
 
34
- class EditorEvent extends core.Event {
226
+ function toList(value) {
227
+ return value ? (value instanceof Array ? value : [value]) : [];
228
+ }
229
+ class EditorEvent extends draw.Event {
230
+ get list() { return toList(this.value); }
231
+ get oldList() { return toList(this.oldValue); }
35
232
  constructor(type, data) {
36
233
  super(type);
37
234
  if (data)
@@ -72,7 +269,7 @@ this.LeaferIN.editor = (function (exports, core) {
72
269
  function targetAttr(fn) {
73
270
  return (target, key) => {
74
271
  const privateKey = '_' + key;
75
- core.defineKey(target, key, {
272
+ draw.defineKey(target, key, {
76
273
  get() { return this[privateKey]; },
77
274
  set(value) {
78
275
  const old = this[privateKey];
@@ -83,10 +280,10 @@ this.LeaferIN.editor = (function (exports, core) {
83
280
  };
84
281
  }
85
282
 
86
- const matrix = core.MatrixHelper.get();
283
+ const matrix = draw.MatrixHelper.get();
87
284
  const { abs } = Math;
88
- const { copy, scale } = core.MatrixHelper;
89
- class Stroker extends core.UI {
285
+ const { copy: copy$1, scale } = draw.MatrixHelper;
286
+ class Stroker extends draw.UI {
90
287
  constructor() {
91
288
  super();
92
289
  this.list = [];
@@ -94,40 +291,43 @@ this.LeaferIN.editor = (function (exports, core) {
94
291
  this.strokeAlign = 'center';
95
292
  }
96
293
  setTarget(target, style) {
97
- const { stroke, strokeWidth } = style;
98
- this.set({ stroke, strokeWidth });
294
+ this.set(style);
99
295
  this.target = target;
100
296
  }
101
297
  __draw(canvas, options) {
102
298
  const { list } = this;
103
299
  if (list.length) {
104
300
  let leaf;
105
- const { stroke, strokeWidth } = this.__;
301
+ const { stroke, strokeWidth, fill } = this.__;
106
302
  const { bounds } = options;
107
303
  for (let i = 0; i < list.length; i++) {
108
304
  leaf = list[i];
109
305
  if (bounds && bounds.hit(leaf.__world, options.matrix)) {
110
- let drewPath;
111
- if (leaf.__.editSize === 'scale') {
112
- const aScaleX = abs(leaf.__world.scaleX), aScaleY = abs(leaf.__world.scaleY);
113
- if (aScaleX !== aScaleY) {
114
- copy(matrix, leaf.__world);
115
- scale(matrix, 1 / aScaleX, 1 / aScaleY);
116
- canvas.setWorld(matrix, options.matrix);
117
- canvas.beginPath();
118
- this.__.strokeWidth = strokeWidth;
119
- const { x, y, width, height } = leaf.__layout.boxBounds;
120
- canvas.rect(x * aScaleX, y * aScaleY, width * aScaleX, height * aScaleY);
121
- drewPath = true;
122
- }
306
+ const aScaleX = abs(leaf.__world.scaleX), aScaleY = abs(leaf.__world.scaleY);
307
+ if (aScaleX !== aScaleY) {
308
+ copy$1(matrix, leaf.__world);
309
+ scale(matrix, 1 / aScaleX, 1 / aScaleY);
310
+ canvas.setWorld(matrix, options.matrix);
311
+ canvas.beginPath();
312
+ this.__.strokeWidth = strokeWidth;
313
+ const { x, y, width, height } = leaf.__layout.boxBounds;
314
+ canvas.rect(x * aScaleX, y * aScaleY, width * aScaleX, height * aScaleY);
123
315
  }
124
- if (!drewPath) {
316
+ else {
125
317
  canvas.setWorld(leaf.__world, options.matrix);
126
318
  canvas.beginPath();
127
- leaf.__.__pathForRender ? leaf.__drawRenderPath(canvas) : leaf.__drawPathByBox(canvas);
319
+ if (leaf.__.__useArrow) {
320
+ leaf.__drawPath(canvas);
321
+ }
322
+ else {
323
+ leaf.__.__pathForRender ? leaf.__drawRenderPath(canvas) : leaf.__drawPathByBox(canvas);
324
+ }
128
325
  this.__.strokeWidth = strokeWidth / abs(leaf.__world.scaleX);
129
326
  }
130
- typeof stroke === 'string' ? core.Paint.stroke(stroke, this, canvas, options) : core.Paint.strokes(stroke, this, canvas, options);
327
+ if (stroke)
328
+ typeof stroke === 'string' ? draw.Paint.stroke(stroke, this, canvas) : draw.Paint.strokes(stroke, this, canvas);
329
+ if (fill)
330
+ typeof fill === 'string' ? draw.Paint.fill(fill, this, canvas) : draw.Paint.fills(fill, this, canvas);
131
331
  }
132
332
  }
133
333
  this.__.strokeWidth = strokeWidth;
@@ -147,11 +347,11 @@ this.LeaferIN.editor = (function (exports, core) {
147
347
  stroker.forceUpdate();
148
348
  }
149
349
 
150
- class SelectArea extends core.Group {
350
+ class SelectArea extends draw.Group {
151
351
  constructor(data) {
152
352
  super(data);
153
- this.strokeArea = new core.Rect({ strokeAlign: 'center' });
154
- this.fillArea = new core.Rect();
353
+ this.strokeArea = new draw.Rect({ strokeAlign: 'center' });
354
+ this.fillArea = new draw.Rect();
155
355
  this.visible = this.hittable = false;
156
356
  this.addMany(this.fillArea, this.strokeArea);
157
357
  }
@@ -167,21 +367,13 @@ this.LeaferIN.editor = (function (exports, core) {
167
367
  }
168
368
  }
169
369
 
170
- var AnswerType;
171
- (function (AnswerType) {
172
- AnswerType[AnswerType["No"] = 0] = "No";
173
- AnswerType[AnswerType["Yes"] = 1] = "Yes";
174
- AnswerType[AnswerType["NoAndSkip"] = 2] = "NoAndSkip";
175
- AnswerType[AnswerType["YesAndSkip"] = 3] = "YesAndSkip";
176
- })(AnswerType || (AnswerType = {}));
177
-
178
- const { No, Yes, NoAndSkip, YesAndSkip } = AnswerType;
370
+ const { No, Yes, NoAndSkip, YesAndSkip } = draw.Answer;
179
371
  const EditSelectHelper = {
180
372
  findOne(path) {
181
373
  return path.list.find((leaf) => leaf.editable);
182
374
  },
183
375
  findBounds(leaf, bounds) {
184
- if (leaf.__.hittable && !leaf.__.locked && bounds.hit(leaf.__world)) {
376
+ if (leaf.__.hittable && leaf.__.visible && !leaf.__.locked && bounds.hit(leaf.__world)) {
185
377
  if (leaf.__.editable) {
186
378
  if (leaf.isBranch && !leaf.__.hitChildren) {
187
379
  return leaf.__.hitSelf ? YesAndSkip : NoAndSkip;
@@ -203,15 +395,15 @@ this.LeaferIN.editor = (function (exports, core) {
203
395
  };
204
396
 
205
397
  const { findOne } = EditSelectHelper;
206
- class EditSelect extends core.Group {
398
+ class EditSelect extends draw.Group {
207
399
  get dragging() { return !!this.originList; }
208
- get running() { return this.editor.hittable && this.editor.config.selector; }
400
+ get running() { const { editor } = this; return this.hittable && editor.visible && editor.hittable && editor.mergeConfig.selector; }
209
401
  get isMoveMode() { return this.app && this.app.interaction.moveMode; }
210
402
  constructor(editor) {
211
403
  super();
212
404
  this.hoverStroker = new Stroker();
213
405
  this.targetStroker = new Stroker();
214
- this.bounds = new core.Bounds();
406
+ this.bounds = new draw.Bounds();
215
407
  this.selectArea = new SelectArea();
216
408
  this.__eventIds = [];
217
409
  this.editor = editor;
@@ -221,8 +413,8 @@ this.LeaferIN.editor = (function (exports, core) {
221
413
  onHover() {
222
414
  const { editor } = this;
223
415
  if (this.running && !this.dragging && !editor.dragging) {
224
- const { stroke, strokeWidth, hover } = editor.config;
225
- this.hoverStroker.setTarget(hover ? this.editor.hoverTarget : null, { stroke, strokeWidth });
416
+ const { stroke, strokeWidth, hover, hoverStyle } = editor.mergeConfig;
417
+ this.hoverStroker.setTarget(hover ? this.editor.hoverTarget : null, Object.assign({ stroke, strokeWidth }, (hoverStyle || {})));
226
418
  }
227
419
  else {
228
420
  this.hoverStroker.target = null;
@@ -230,62 +422,72 @@ this.LeaferIN.editor = (function (exports, core) {
230
422
  }
231
423
  onSelect() {
232
424
  if (this.running) {
233
- const { config, list } = this.editor;
425
+ const { mergeConfig: config, list } = this.editor;
234
426
  const { stroke, strokeWidth } = config;
235
427
  this.targetStroker.setTarget(list, { stroke, strokeWidth: Math.max(1, strokeWidth / 2) });
236
428
  this.hoverStroker.target = null;
237
429
  }
238
430
  }
239
431
  update() {
240
- if (this.running)
432
+ if (this.targetStroker.target)
241
433
  this.targetStroker.forceUpdate();
242
434
  }
243
435
  onPointerMove(e) {
244
- if (this.running && !this.isMoveMode) {
245
- const find = e.shiftKey ? this.findDeepOne(e) : findOne(e.path);
246
- this.editor.hoverTarget = this.editor.hasItem(find) ? null : find;
436
+ const { app, editor } = this;
437
+ if (this.running && !this.isMoveMode && app.config.pointer.hover && !app.interaction.dragging) {
438
+ const find = this.findUI(e);
439
+ editor.hoverTarget = editor.hasItem(find) ? null : find;
247
440
  }
248
441
  if (this.isMoveMode) {
249
- this.editor.hoverTarget = null;
442
+ editor.hoverTarget = null;
250
443
  }
251
444
  }
252
445
  onBeforeDown(e) {
253
- if (this.running && !this.isMoveMode && !e.middle) {
254
- const find = this.lastDownLeaf = findOne(e.path);
446
+ const { select } = this.editor.mergeConfig;
447
+ if (select === 'press')
448
+ this.checkAndSelect(e);
449
+ }
450
+ onTap(e) {
451
+ const { editor } = this;
452
+ const { select } = editor.mergeConfig;
453
+ if (select === 'tap')
454
+ this.checkAndSelect(e);
455
+ if (this.needRemoveItem) {
456
+ editor.removeItem(this.needRemoveItem);
457
+ }
458
+ else if (this.isMoveMode) {
459
+ editor.target = null;
460
+ }
461
+ }
462
+ checkAndSelect(e) {
463
+ this.needRemoveItem = null;
464
+ if (this.allowSelect(e)) {
465
+ const { editor } = this;
466
+ const find = this.findUI(e);
255
467
  if (find) {
256
- if (e.shiftKey) {
257
- this.editor.shiftItem(find);
468
+ if (this.isMultipleSelect(e)) {
469
+ if (editor.hasItem(find))
470
+ this.needRemoveItem = find;
471
+ else
472
+ editor.addItem(find);
258
473
  }
259
474
  else {
260
- this.editor.target = find;
475
+ editor.target = find;
261
476
  }
262
- this.editor.updateLayout();
263
- find.leafer.interaction.updateDownData();
264
477
  }
265
478
  else if (this.allow(e.target)) {
266
479
  if (!e.shiftKey)
267
- this.editor.target = null;
480
+ editor.target = null;
268
481
  }
269
482
  }
270
483
  }
271
- onTap(e) {
272
- if (this.running && e.shiftKey && !e.middle && !this.lastDownLeaf) {
273
- const find = this.findDeepOne(e);
274
- if (find)
275
- this.editor.shiftItem(find);
276
- }
277
- else if (this.isMoveMode) {
278
- this.editor.target = null;
279
- }
280
- this.lastDownLeaf = null;
281
- }
282
484
  onDragStart(e) {
283
- if (this.running && this.allowDrag(e)) {
485
+ if (this.allowDrag(e)) {
284
486
  const { editor } = this;
285
- const { stroke, strokeWidth, area } = editor.config;
487
+ const { stroke, area } = editor.mergeConfig;
286
488
  const { x, y } = e.getInner(this);
287
489
  this.bounds.set(x, y);
288
- this.selectArea.setStyle({ visible: true, stroke, strokeWidth, x, y }, area);
490
+ this.selectArea.setStyle({ visible: true, stroke, x, y }, area);
289
491
  this.selectArea.setBounds(this.bounds.get());
290
492
  this.originList = editor.leafList.clone();
291
493
  }
@@ -299,7 +501,7 @@ this.LeaferIN.editor = (function (exports, core) {
299
501
  const { editor } = this;
300
502
  const total = e.getInnerTotal(this);
301
503
  const dragBounds = this.bounds.clone().unsign();
302
- const list = new core.LeafList(editor.app.find(EditSelectHelper.findBounds, dragBounds));
504
+ const list = new draw.LeafList(editor.app.find(EditSelectHelper.findBounds, dragBounds));
303
505
  this.bounds.width = total.x;
304
506
  this.bounds.height = total.y;
305
507
  this.selectArea.setBounds(dragBounds.get());
@@ -315,8 +517,6 @@ this.LeaferIN.editor = (function (exports, core) {
315
517
  }
316
518
  else {
317
519
  editor.target = this.originList.list;
318
- if (editor.leafList.length)
319
- editor.update();
320
520
  }
321
521
  }
322
522
  }
@@ -335,17 +535,26 @@ this.LeaferIN.editor = (function (exports, core) {
335
535
  return target.leafer !== this.editor.leafer;
336
536
  }
337
537
  allowDrag(e) {
338
- if (this.editor.config.boxSelect && !e.target.draggable) {
339
- return (!this.editor.hasTarget && this.allow(e.target)) || (e.shiftKey && !findOne(e.path));
538
+ if (this.running && this.editor.mergeConfig.boxSelect && !e.target.draggable) {
539
+ return (!this.editor.editing && this.allow(e.target)) || (e.shiftKey && !findOne(e.path));
340
540
  }
341
541
  else {
342
542
  return false;
343
543
  }
344
544
  }
545
+ allowSelect(e) {
546
+ return this.running && !this.isMoveMode && !e.middle;
547
+ }
345
548
  findDeepOne(e) {
346
- const options = { exclude: new core.LeafList(this.editor.editBox.rect) };
549
+ const options = { exclude: new draw.LeafList(this.editor.editBox.rect) };
347
550
  return findOne(e.target.leafer.interaction.findPath(e, options));
348
551
  }
552
+ findUI(e) {
553
+ return this.isMultipleSelect(e) ? this.findDeepOne(e) : findOne(e.path);
554
+ }
555
+ isMultipleSelect(e) {
556
+ return e.shiftKey || this.editor.mergeConfig.continuousSelect;
557
+ }
349
558
  __listenEvents() {
350
559
  const { editor } = this;
351
560
  editor.waitLeafer(() => {
@@ -372,134 +581,128 @@ this.LeaferIN.editor = (function (exports, core) {
372
581
  }
373
582
  }
374
583
  destroy() {
375
- this.editor = this.originList = this.lastDownLeaf = null;
584
+ this.editor = this.originList = this.needRemoveItem = null;
376
585
  this.__removeListenEvents();
377
586
  super.destroy();
378
587
  }
379
588
  }
380
589
 
381
- var IDirection8;
382
- (function (IDirection8) {
383
- IDirection8[IDirection8["topLeft"] = 0] = "topLeft";
384
- IDirection8[IDirection8["top"] = 1] = "top";
385
- IDirection8[IDirection8["topRight"] = 2] = "topRight";
386
- IDirection8[IDirection8["right"] = 3] = "right";
387
- IDirection8[IDirection8["bottomRight"] = 4] = "bottomRight";
388
- IDirection8[IDirection8["bottom"] = 5] = "bottom";
389
- IDirection8[IDirection8["bottomLeft"] = 6] = "bottomLeft";
390
- IDirection8[IDirection8["left"] = 7] = "left";
391
- })(IDirection8 || (IDirection8 = {}));
392
-
393
- const { topLeft: topLeft$1, top: top$1, topRight: topRight$1, right: right$2, bottomRight: bottomRight$1, bottom: bottom$1, bottomLeft: bottomLeft$1, left: left$2 } = IDirection8;
394
- const { toPoint } = core.AroundHelper;
590
+ const { topLeft, top, topRight, right: right$1, bottomRight, bottom, bottomLeft, left: left$1 } = draw.Direction9;
591
+ const { toPoint } = draw.AroundHelper;
395
592
  const EditDataHelper = {
396
593
  getScaleData(bounds, direction, pointMove, lockRatio, around) {
397
- let origin, scaleX = 1, scaleY = 1;
594
+ let align, origin = {}, scaleX = 1, scaleY = 1;
398
595
  const { width, height } = bounds;
399
596
  if (around) {
400
597
  pointMove.x *= 2;
401
598
  pointMove.y *= 2;
402
599
  }
600
+ if (Math.abs(pointMove.x) === width)
601
+ pointMove.x += 0.1;
602
+ if (Math.abs(pointMove.y) === height)
603
+ pointMove.y += 0.1;
403
604
  const topScale = (-pointMove.y + height) / height;
404
605
  const rightScale = (pointMove.x + width) / width;
405
606
  const bottomScale = (pointMove.y + height) / height;
406
607
  const leftScale = (-pointMove.x + width) / width;
407
608
  switch (direction) {
408
- case top$1:
609
+ case top:
409
610
  scaleY = topScale;
410
- origin = { x: 0.5, y: 1 };
611
+ align = 'bottom';
411
612
  break;
412
- case right$2:
613
+ case right$1:
413
614
  scaleX = rightScale;
414
- origin = { x: 0, y: 0.5 };
615
+ align = 'left';
415
616
  break;
416
- case bottom$1:
617
+ case bottom:
417
618
  scaleY = bottomScale;
418
- origin = { x: 0.5, y: 0 };
619
+ align = 'top';
419
620
  break;
420
- case left$2:
621
+ case left$1:
421
622
  scaleX = leftScale;
422
- origin = { x: 1, y: 0.5 };
623
+ align = 'right';
423
624
  break;
424
- case topLeft$1:
625
+ case topLeft:
425
626
  scaleY = topScale;
426
627
  scaleX = leftScale;
427
- origin = { x: 1, y: 1 };
628
+ align = 'bottom-right';
428
629
  break;
429
- case topRight$1:
630
+ case topRight:
430
631
  scaleY = topScale;
431
632
  scaleX = rightScale;
432
- origin = { x: 0, y: 1 };
633
+ align = 'bottom-left';
433
634
  break;
434
- case bottomRight$1:
635
+ case bottomRight:
435
636
  scaleY = bottomScale;
436
637
  scaleX = rightScale;
437
- origin = { x: 0, y: 0 };
638
+ align = 'top-left';
438
639
  break;
439
- case bottomLeft$1:
640
+ case bottomLeft:
440
641
  scaleY = bottomScale;
441
642
  scaleX = leftScale;
442
- origin = { x: 1, y: 0 };
643
+ align = 'top-right';
443
644
  }
444
645
  if (lockRatio) {
445
- if (scaleX !== 1)
446
- scaleY = scaleX;
447
- else
448
- scaleX = scaleY;
646
+ const unlockSide = lockRatio === 'corner' && direction % 2;
647
+ if (!unlockSide) {
648
+ const scale = Math.sqrt(Math.abs(scaleX * scaleY));
649
+ scaleX = scaleX < 0 ? -scale : scale;
650
+ scaleY = scaleY < 0 ? -scale : scale;
651
+ }
449
652
  }
450
- toPoint(around || origin, bounds, origin);
653
+ toPoint(around || align, bounds, origin);
451
654
  return { origin, scaleX, scaleY, direction, lockRatio, around };
452
655
  },
453
656
  getRotateData(bounds, direction, current, last, around) {
454
- let origin;
657
+ let align, origin = {};
455
658
  switch (direction) {
456
- case topLeft$1:
457
- origin = { x: 1, y: 1 };
659
+ case topLeft:
660
+ align = 'bottom-right';
458
661
  break;
459
- case topRight$1:
460
- origin = { x: 0, y: 1 };
662
+ case topRight:
663
+ align = 'bottom-left';
461
664
  break;
462
- case bottomRight$1:
463
- origin = { x: 0, y: 0 };
665
+ case bottomRight:
666
+ align = 'top-left';
464
667
  break;
465
- case bottomLeft$1:
466
- origin = { x: 1, y: 0 };
668
+ case bottomLeft:
669
+ align = 'top-right';
467
670
  break;
468
671
  default:
469
- origin = { x: 0.5, y: 0.5 };
672
+ align = 'center';
470
673
  }
471
- toPoint(around || origin, bounds, origin);
472
- return { origin, rotation: core.PointHelper.getRotation(last, origin, current) };
674
+ toPoint(around || align, bounds, origin);
675
+ return { origin, rotation: draw.PointHelper.getRotation(last, origin, current) };
473
676
  },
474
677
  getSkewData(bounds, direction, move, around) {
475
- let origin, skewX = 0, skewY = 0;
678
+ let align, origin = {}, skewX = 0, skewY = 0;
476
679
  let last;
477
680
  switch (direction) {
478
- case top$1:
681
+ case top:
479
682
  last = { x: 0.5, y: 0 };
480
- origin = { x: 0.5, y: 1 };
683
+ align = 'bottom';
481
684
  skewX = 1;
482
685
  break;
483
- case bottom$1:
686
+ case bottom:
484
687
  last = { x: 0.5, y: 1 };
485
- origin = { x: 0.5, y: 0 };
688
+ align = 'top';
486
689
  skewX = 1;
487
690
  break;
488
- case left$2:
691
+ case left$1:
489
692
  last = { x: 0, y: 0.5 };
490
- origin = { x: 1, y: 0.5 };
693
+ align = 'right';
491
694
  skewY = 1;
492
695
  break;
493
- case right$2:
696
+ case right$1:
494
697
  last = { x: 1, y: 0.5 };
495
- origin = { x: 0, y: 0.5 };
698
+ align = 'left';
496
699
  skewY = 1;
497
700
  }
498
701
  const { x, y, width, height } = bounds;
499
702
  last.x = x + last.x * width;
500
703
  last.y = y + last.y * height;
501
- toPoint(around || origin, bounds, origin);
502
- const rotation = core.PointHelper.getRotation(last, origin, { x: last.x + (skewX ? move.x : 0), y: last.y + (skewY ? move.y : 0) });
704
+ toPoint(around || align, bounds, origin);
705
+ const rotation = draw.PointHelper.getRotation(last, origin, { x: last.x + (skewX ? move.x : 0), y: last.y + (skewY ? move.y : 0) });
503
706
  skewX ? skewX = -rotation : skewY = rotation;
504
707
  return { origin, skewX, skewY };
505
708
  },
@@ -511,69 +714,104 @@ this.LeaferIN.editor = (function (exports, core) {
511
714
  if (direction < 0)
512
715
  direction += totalDirection;
513
716
  return direction;
717
+ },
718
+ getFlipDirection(direction, flipedX, flipedY) {
719
+ if (flipedX) {
720
+ switch (direction) {
721
+ case left$1:
722
+ direction = right$1;
723
+ break;
724
+ case topLeft:
725
+ direction = topRight;
726
+ break;
727
+ case bottomLeft:
728
+ direction = bottomRight;
729
+ break;
730
+ case right$1:
731
+ direction = left$1;
732
+ break;
733
+ case topRight:
734
+ direction = topLeft;
735
+ break;
736
+ case bottomRight:
737
+ direction = bottomLeft;
738
+ break;
739
+ }
740
+ }
741
+ if (flipedY) {
742
+ switch (direction) {
743
+ case top:
744
+ direction = bottom;
745
+ break;
746
+ case topLeft:
747
+ direction = bottomLeft;
748
+ break;
749
+ case topRight:
750
+ direction = bottomRight;
751
+ break;
752
+ case bottom:
753
+ direction = top;
754
+ break;
755
+ case bottomLeft:
756
+ direction = topLeft;
757
+ break;
758
+ case bottomRight:
759
+ direction = topRight;
760
+ break;
761
+ }
762
+ }
763
+ return direction;
514
764
  }
515
765
  };
516
766
 
517
- const { topLeft, top, topRight, right: right$1, bottomRight, bottom, bottomLeft, left: left$1 } = IDirection8;
767
+ const cacheCursors = {};
518
768
  function updateCursor(editor, e) {
519
769
  const { editBox } = editor, point = editBox.enterPoint;
520
- if (!point || !editor.hasTarget || !editBox.visible)
770
+ if (!point || !editor.editing || !editBox.visible)
771
+ return;
772
+ if (point.name === 'circle')
521
773
  return;
522
774
  let { rotation } = editBox;
523
- let { resizeCursor, rotateCursor, resizeable, rotateable } = editor.config;
524
- const { direction, pointType } = point;
525
- editBox.enterPoint = point;
526
- const isResizePoint = pointType === 'resize';
527
- if (isResizePoint && rotateable && (e.metaKey || e.ctrlKey || !resizeable))
528
- resizeCursor = rotateCursor;
529
- if (editBox.flipped) {
530
- const { flippedX, flippedY } = editBox;
531
- mirrorCursors(resizeCursor = [...resizeCursor], flippedX, flippedY);
532
- mirrorCursors(rotateCursor = [...rotateCursor], flippedY, flippedX);
533
- if (editBox.flippedOne)
534
- rotation = -rotation;
775
+ const { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editor.mergeConfig;
776
+ const { pointType } = point, { flippedX, flippedY } = editBox;
777
+ let showResize = pointType === 'resize';
778
+ if (showResize && rotateable && (e.metaKey || e.ctrlKey || !resizeable))
779
+ showResize = false;
780
+ const showSkew = skewable && !showResize && point.name === 'resize-line';
781
+ const cursor = showSkew ? skewCursor : (showResize ? resizeCursor : rotateCursor);
782
+ rotation += (EditDataHelper.getFlipDirection(point.direction, flippedX, flippedY) + 1) * 45;
783
+ rotation = Math.round(draw.MathHelper.formatRotation(rotation, true) / 2) * 2;
784
+ const { url, x, y } = cursor;
785
+ const key = url + rotation;
786
+ if (cacheCursors[key]) {
787
+ point.cursor = cacheCursors[key];
788
+ }
789
+ else {
790
+ cacheCursors[key] = point.cursor = { url: toDataURL(url, rotation), x, y };
535
791
  }
536
- const index = EditDataHelper.getRotateDirection(direction, rotation);
537
- point.cursor = isResizePoint ? resizeCursor[index] : rotateCursor[index];
538
792
  }
539
793
  function updateMoveCursor(editor) {
540
- editor.editBox.rect.cursor = editor.config.moveCursor;
794
+ editor.editBox.rect.cursor = editor.mergeConfig.moveCursor;
541
795
  }
542
- function mirrorCursors(mirror, mirrorX, mirrorY) {
543
- if (mirrorX) {
544
- const topCursor = mirror[top], topLeftCursor = mirror[topLeft], topRightCursor = mirror[topRight];
545
- mirror[top] = mirror[bottom];
546
- mirror[topLeft] = mirror[bottomLeft];
547
- mirror[topRight] = mirror[bottomRight];
548
- mirror[bottom] = topCursor;
549
- mirror[bottomLeft] = topLeftCursor;
550
- mirror[bottomRight] = topRightCursor;
551
- }
552
- if (mirrorY) {
553
- const leftCursor = mirror[left$1], topLeftCursor = mirror[topLeft], bottomLeftCursor = mirror[bottomLeft];
554
- mirror[left$1] = mirror[right$1];
555
- mirror[topLeft] = mirror[topRight];
556
- mirror[bottomLeft] = mirror[bottomRight];
557
- mirror[right$1] = leftCursor;
558
- mirror[topRight] = topLeftCursor;
559
- mirror[bottomRight] = bottomLeftCursor;
560
- }
796
+ function toDataURL(svg, rotation) {
797
+ return '"data:image/svg+xml,' + encodeURIComponent(svg.replace('{{rotation}}', rotation.toString())) + '"';
561
798
  }
562
799
 
563
- class EditPoint extends core.Box {
800
+ class EditPoint extends draw.Box {
564
801
  }
565
802
 
566
803
  const fourDirection = ['top', 'right', 'bottom', 'left'];
567
- class EditBox extends core.Group {
804
+ class EditBox extends draw.Group {
568
805
  get flipped() { return this.flippedX || this.flippedY; }
569
806
  get flippedX() { return this.scaleX < 0; }
570
807
  get flippedY() { return this.scaleY < 0; }
571
808
  get flippedOne() { return this.scaleX * this.scaleY < 0; }
572
809
  constructor(editor) {
573
810
  super();
574
- this.rect = new core.Box({ name: 'rect', hitFill: 'all', hitStroke: 'none', strokeAlign: 'center', hitRadius: 5 });
575
- this.circle = new EditPoint({ name: 'circle', strokeAlign: 'outside', around: 'center', cursor: 'crosshair', hitRadius: 5 });
576
- this.buttons = new core.Group({ around: 'center', hitSelf: false });
811
+ this.view = new draw.Group();
812
+ this.rect = new draw.Box({ name: 'rect', hitFill: 'all', hitStroke: 'none', strokeAlign: 'center', hitRadius: 5 });
813
+ this.circle = new EditPoint({ name: 'circle', strokeAlign: 'center', around: 'center', cursor: 'crosshair', hitRadius: 5 });
814
+ this.buttons = new draw.Group({ around: 'center', hitSelf: false });
577
815
  this.resizePoints = [];
578
816
  this.rotatePoints = [];
579
817
  this.resizeLines = [];
@@ -581,14 +819,15 @@ this.LeaferIN.editor = (function (exports, core) {
581
819
  this.editor = editor;
582
820
  this.visible = false;
583
821
  this.create();
822
+ this.rect.syncEventer = editor;
584
823
  this.__listenEvents();
585
824
  }
586
825
  create() {
587
826
  let rotatePoint, resizeLine, resizePoint;
588
- const { resizePoints, rotatePoints, resizeLines, rect, circle, buttons } = this;
589
- const arounds = [{ x: 1, y: 1 }, { x: 0.5, y: 1 }, { x: 0, y: 1 }, { x: 0, y: 0.5 }, { x: 0, y: 0 }, { x: 0.5, y: 0 }, { x: 1, y: 0 }, { x: 1, y: 0.5 }];
827
+ const { view, resizePoints, rotatePoints, resizeLines, rect, circle, buttons } = this;
828
+ const arounds = ['bottom-right', 'bottom', 'bottom-left', 'left', 'top-left', 'top', 'top-right', 'right'];
590
829
  for (let i = 0; i < 8; i++) {
591
- rotatePoint = new EditPoint({ around: arounds[i], width: 15, height: 15, hitFill: "all" });
830
+ rotatePoint = new EditPoint({ name: 'rotate-point', around: arounds[i], width: 15, height: 15, hitFill: "all" });
592
831
  rotatePoints.push(rotatePoint);
593
832
  this.listenPointEvents(rotatePoint, 'rotate', i);
594
833
  if (i % 2) {
@@ -596,58 +835,82 @@ this.LeaferIN.editor = (function (exports, core) {
596
835
  resizeLines.push(resizeLine);
597
836
  this.listenPointEvents(resizeLine, 'resize', i);
598
837
  }
599
- resizePoint = new EditPoint({ name: 'resize-point', around: 'center', strokeAlign: 'outside', hitRadius: 5 });
838
+ resizePoint = new EditPoint({ name: 'resize-point', hitRadius: 5 });
600
839
  resizePoints.push(resizePoint);
601
840
  this.listenPointEvents(resizePoint, 'resize', i);
602
841
  }
603
842
  buttons.add(circle);
604
843
  this.listenPointEvents(circle, 'rotate', 2);
605
- this.addMany(...rotatePoints, rect, buttons, ...resizeLines, ...resizePoints);
844
+ view.addMany(...rotatePoints, rect, buttons, ...resizeLines, ...resizePoints);
845
+ this.add(view);
606
846
  }
607
- update(bounds) {
608
- const { config, list } = this.editor;
609
- const { width, height } = bounds;
610
- const { rect, circle, resizePoints, rotatePoints, resizeLines } = this;
611
- const { middlePoint, resizeable, rotateable, stroke, strokeWidth } = config;
847
+ load() {
848
+ const { mergeConfig, element, single } = this.editor;
849
+ const { rect, circle, resizePoints } = this;
850
+ const { stroke, strokeWidth, moveable } = mergeConfig;
612
851
  const pointsStyle = this.getPointsStyle();
613
852
  const middlePointsStyle = this.getMiddlePointsStyle();
614
- this.visible = list[0] && !list[0].locked;
615
- let point = {}, style, rotateP, resizeP, resizeL;
853
+ let resizeP;
616
854
  for (let i = 0; i < 8; i++) {
617
- core.AroundHelper.toPoint(core.AroundHelper.directionData[i], bounds, point);
618
- style = this.getPointStyle((i % 2) ? middlePointsStyle[((i - 1) / 2) % middlePointsStyle.length] : pointsStyle[(i / 2) % pointsStyle.length]);
619
- resizeP = resizePoints[i], rotateP = rotatePoints[i], resizeL = resizeLines[Math.floor(i / 2)];
620
- resizeP.set(style);
621
- resizeP.set(point), rotateP.set(point), resizeL.set(point);
622
- resizeP.visible = resizeL.visible = resizeable || rotateable;
623
- rotateP.visible = rotateable && resizeable;
624
- if (i % 2) {
625
- resizeP.visible = rotateP.visible = !!middlePoint;
626
- if (((i + 1) / 2) % 2) {
627
- resizeL.width = width;
628
- if (resizeP.width > width - 30)
629
- resizeP.visible = false;
630
- }
631
- else {
632
- resizeL.height = height;
633
- resizeP.rotation = 90;
634
- if (resizeP.width > height - 30)
635
- resizeP.visible = false;
636
- }
637
- }
638
- else {
855
+ resizeP = resizePoints[i];
856
+ resizeP.set(this.getPointStyle((i % 2) ? middlePointsStyle[((i - 1) / 2) % middlePointsStyle.length] : pointsStyle[(i / 2) % pointsStyle.length]));
857
+ if (!(i % 2))
639
858
  resizeP.rotation = (i / 2) * 90;
859
+ }
860
+ circle.set(this.getPointStyle(mergeConfig.rotatePoint || pointsStyle[0]));
861
+ rect.set(Object.assign({ stroke, strokeWidth }, (mergeConfig.rect || {})));
862
+ rect.hittable = !single && moveable;
863
+ element.syncEventer = (single && moveable) ? rect : null;
864
+ this.app.interaction.bottomList = (single && moveable) ? [{ target: rect, proxy: element }] : null;
865
+ }
866
+ update(bounds) {
867
+ this.visible = !this.editor.element.locked;
868
+ if (this.view.worldOpacity) {
869
+ const { mergeConfig } = this.editor;
870
+ const { width, height } = bounds;
871
+ const { rect, circle, resizePoints, rotatePoints, resizeLines } = this;
872
+ const { middlePoint, resizeable, rotateable, hideOnSmall } = mergeConfig;
873
+ const smallSize = typeof hideOnSmall === 'number' ? hideOnSmall : 10;
874
+ const showPoints = !(hideOnSmall && width < smallSize && height < smallSize);
875
+ let point = {}, rotateP, resizeP, resizeL;
876
+ for (let i = 0; i < 8; i++) {
877
+ draw.AroundHelper.toPoint(draw.AroundHelper.directionData[i], bounds, point);
878
+ resizeP = resizePoints[i];
879
+ rotateP = rotatePoints[i];
880
+ resizeL = resizeLines[Math.floor(i / 2)];
881
+ resizeP.set(point);
882
+ rotateP.set(point);
883
+ resizeL.set(point);
884
+ resizeP.visible = resizeL.visible = showPoints && !!(resizeable || rotateable);
885
+ rotateP.visible = showPoints && rotateable && resizeable && !mergeConfig.rotatePoint;
886
+ if (i % 2) {
887
+ resizeP.visible = rotateP.visible = showPoints && !!middlePoint;
888
+ if (((i + 1) / 2) % 2) {
889
+ resizeL.width = width;
890
+ if (resizeP.width > width - 30)
891
+ resizeP.visible = false;
892
+ }
893
+ else {
894
+ resizeL.height = height;
895
+ resizeP.rotation = 90;
896
+ if (resizeP.width > height - 30)
897
+ resizeP.visible = false;
898
+ }
899
+ }
640
900
  }
901
+ circle.visible = showPoints && rotateable && !!mergeConfig.rotatePoint;
902
+ if (rect.path)
903
+ rect.path = null;
904
+ rect.set(Object.assign(Object.assign({}, bounds), { visible: true }));
905
+ const buttonVisible = showPoints && (circle.visible || this.buttons.children.length > 1);
906
+ this.buttons.visible = buttonVisible;
907
+ if (buttonVisible)
908
+ this.layoutButtons();
641
909
  }
642
- circle.visible = rotateable && !!config.rotatePoint;
643
- circle.set(this.getPointStyle(config.rotatePoint || pointsStyle[0]));
644
- rect.set(Object.assign({ stroke, strokeWidth }, (config.rect || {})));
645
- rect.set(Object.assign(Object.assign({}, bounds), { visible: true }));
646
- this.layoutButtons();
647
910
  }
648
911
  layoutButtons() {
649
912
  const { buttons, resizePoints } = this;
650
- const { buttonsDirection, buttonsFixed, buttonsMargin, middlePoint } = this.editor.config;
913
+ const { buttonsDirection, buttonsFixed, buttonsMargin, middlePoint } = this.editor.mergeConfig;
651
914
  const { flippedX, flippedY } = this;
652
915
  let index = fourDirection.indexOf(buttonsDirection);
653
916
  if ((index % 2 && flippedX) || ((index + 1) % 2 && flippedY)) {
@@ -674,42 +937,58 @@ this.LeaferIN.editor = (function (exports, core) {
674
937
  buttons.scaleY = flippedY ? -1 : 1;
675
938
  }
676
939
  }
940
+ unload() {
941
+ this.visible = false;
942
+ }
677
943
  getPointStyle(userStyle) {
678
- const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.editor.config;
679
- const defaultStyle = { fill: pointFill, stroke, strokeWidth, width: pointSize, height: pointSize, cornerRadius: pointRadius };
944
+ const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.editor.mergeConfig;
945
+ const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', width: pointSize, height: pointSize, cornerRadius: pointRadius };
680
946
  return userStyle ? Object.assign(defaultStyle, userStyle) : defaultStyle;
681
947
  }
682
948
  getPointsStyle() {
683
- const { point } = this.editor.config;
949
+ const { point } = this.editor.mergeConfig;
684
950
  return point instanceof Array ? point : [point];
685
951
  }
686
952
  getMiddlePointsStyle() {
687
- const { middlePoint } = this.editor.config;
953
+ const { middlePoint } = this.editor.mergeConfig;
688
954
  return middlePoint instanceof Array ? middlePoint : (middlePoint ? [middlePoint] : this.getPointsStyle());
689
955
  }
956
+ onSelect(e) {
957
+ if (e.oldList.length === 1) {
958
+ e.oldList[0].syncEventer = null;
959
+ if (this.app)
960
+ this.app.interaction.bottomList = null;
961
+ }
962
+ }
690
963
  onDragStart(e) {
691
964
  this.dragging = true;
692
- if (e.target.name === 'rect')
693
- this.editor.opacity = this.editor.config.hideOnMove ? 0 : 1;
965
+ if (e.current.name === 'rect') {
966
+ const { editor } = this;
967
+ this.moving = true;
968
+ editor.dragStartPoint = { x: editor.element.x, y: editor.element.y };
969
+ editor.opacity = editor.mergeConfig.hideOnMove ? 0 : 1;
970
+ }
694
971
  }
695
972
  onDragEnd(e) {
696
973
  this.dragging = false;
697
- if (e.target.name === 'rect')
974
+ this.moving = false;
975
+ if (e.current.name === 'rect')
698
976
  this.editor.opacity = 1;
699
977
  }
700
978
  onDrag(e) {
701
979
  const { editor } = this;
702
- const point = e.current;
703
- if (point.pointType === 'rotate' || e.metaKey || e.ctrlKey || !editor.config.resizeable) {
704
- if (editor.config.rotateable)
980
+ const point = this.enterPoint = e.current;
981
+ if (point.pointType === 'rotate' || e.metaKey || e.ctrlKey || !editor.mergeConfig.resizeable) {
982
+ if (editor.mergeConfig.rotateable)
705
983
  editor.onRotate(e);
706
984
  }
707
985
  else {
708
986
  editor.onScale(e);
709
987
  }
988
+ updateCursor(editor, e);
710
989
  }
711
990
  onArrow(e) {
712
- if (this.editor.hasTarget) {
991
+ if (this.editor.editing && this.editor.mergeConfig.keyEvent) {
713
992
  const move = { x: 0, y: 0 };
714
993
  const distance = e.shiftKey ? 10 : 1;
715
994
  switch (e.code) {
@@ -725,13 +1004,29 @@ this.LeaferIN.editor = (function (exports, core) {
725
1004
  case 'ArrowRight':
726
1005
  move.x = distance;
727
1006
  }
728
- if (move.x || move.y)
729
- this.editor.move(move.x, move.y);
1007
+ this.editor.move(move);
730
1008
  }
731
1009
  }
732
- onDoubleClick() {
1010
+ onDoubleTap(e) {
1011
+ if (this.editor.mergeConfig.openInner === 'double')
1012
+ this.openInner(e);
1013
+ }
1014
+ onLongPress(e) {
1015
+ if (this.editor.mergeConfig.openInner === 'long')
1016
+ this.openInner(e);
1017
+ }
1018
+ openInner(e) {
733
1019
  const { editor } = this;
734
- if (editor.single && editor.element.isBranch) ;
1020
+ if (editor.single) {
1021
+ const { element } = editor;
1022
+ if (element.isBranch) {
1023
+ editor.openGroup(element);
1024
+ editor.target = editor.selector.findDeepOne(e);
1025
+ }
1026
+ else {
1027
+ editor.openInnerEditor();
1028
+ }
1029
+ }
735
1030
  }
736
1031
  listenPointEvents(point, type, direction) {
737
1032
  const { editor } = this;
@@ -747,12 +1042,15 @@ this.LeaferIN.editor = (function (exports, core) {
747
1042
  __listenEvents() {
748
1043
  const { rect, editor } = this;
749
1044
  this.__eventIds = [
750
- editor.on_(EditorEvent.SELECT, () => { this.visible = editor.hasTarget; }),
1045
+ editor.on_(EditorEvent.SELECT, this.onSelect, this),
751
1046
  rect.on_(core.DragEvent.START, this.onDragStart, this),
752
1047
  rect.on_(core.DragEvent.DRAG, editor.onMove, editor),
753
1048
  rect.on_(core.DragEvent.END, this.onDragEnd, this),
1049
+ rect.on_(core.ZoomEvent.BEFORE_ZOOM, editor.onScale, editor, true),
1050
+ rect.on_(core.RotateEvent.BEFORE_ROTATE, editor.onRotate, editor, true),
754
1051
  rect.on_(core.PointerEvent.ENTER, () => updateMoveCursor(editor)),
755
- rect.on_(core.PointerEvent.DOUBLE_CLICK, this.onDoubleClick, this)
1052
+ rect.on_(core.PointerEvent.DOUBLE_TAP, this.onDoubleTap, this),
1053
+ rect.on_(core.PointerEvent.LONG_PRESS, this.onLongPress, this)
756
1054
  ];
757
1055
  }
758
1056
  __removeListenEvents() {
@@ -766,167 +1064,111 @@ this.LeaferIN.editor = (function (exports, core) {
766
1064
  }
767
1065
  }
768
1066
 
1067
+ class EditMask extends draw.UI {
1068
+ constructor(editor) {
1069
+ super();
1070
+ this.editor = editor;
1071
+ this.hittable = false;
1072
+ }
1073
+ __draw(canvas, options) {
1074
+ const { editor } = this;
1075
+ const { mask } = editor.mergeConfig;
1076
+ if (mask && editor.list.length) {
1077
+ const { rect } = editor.editBox;
1078
+ const { width, height } = rect.__;
1079
+ canvas.resetTransform();
1080
+ canvas.fillWorld(canvas.bounds, mask);
1081
+ canvas.setWorld(rect.__world, options.matrix);
1082
+ canvas.clearRect(0, 0, width, height);
1083
+ }
1084
+ }
1085
+ destroy() {
1086
+ this.editor = null;
1087
+ super.destroy();
1088
+ }
1089
+ }
1090
+
1091
+ const filterStyle = `
1092
+ <feOffset dy="1"/>
1093
+ <feGaussianBlur stdDeviation="1.5"/>
1094
+ <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"/>
1095
+ <feBlend mode="normal" in="SourceGraphic" result="shape"/>`;
1096
+ const resizeSVG = `
1097
+ <svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">
1098
+ <g filter="url(#f)">
1099
+ <g transform="rotate({{rotation}},12,12)">
1100
+ <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"/>
1101
+ <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"/>
1102
+ </g>
1103
+ </g>
1104
+ <defs>
1105
+ <filter id="f" x="-1.6" y="3.9" width="27.2" height="16.9" filterUnits="userSpaceOnUse">
1106
+ ${filterStyle}
1107
+ </filter>
1108
+ </defs>
1109
+ </svg>
1110
+ `;
1111
+ const rotateSVG = `
1112
+ <svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">
1113
+ <g filter="url(#f)">
1114
+ <g transform="rotate(135,12,12),rotate({{rotation}},12,12)">
1115
+ <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"/>
1116
+ <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"/>
1117
+ </g>
1118
+ </g>
1119
+ <defs>
1120
+ <filter id="f" x="-1.6" y="-0.6" width="27.1" height="27.1" filterUnits="userSpaceOnUse">
1121
+ ${filterStyle}
1122
+ </filter>
1123
+ </defs>
1124
+ </svg>
1125
+ `;
1126
+ const skewSVG = `
1127
+ <svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">
1128
+ <g filter="url(#f)">
1129
+ <g transform="rotate(90,12,12),rotate({{rotation}},12,12)">
1130
+ <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"/>
1131
+ <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"/>
1132
+ </g>
1133
+ </g>
1134
+ <defs>
1135
+ <filter x="-2.8" y="1.9" width="29.6" height="23.1" filterUnits="userSpaceOnUse" >
1136
+ ${filterStyle}
1137
+ </filter>
1138
+ </defs>
1139
+ </svg>
1140
+ `;
1141
+
769
1142
  const config = {
770
- editSize: 'auto',
1143
+ editSize: 'size',
1144
+ keyEvent: true,
771
1145
  stroke: '#836DFF',
772
1146
  strokeWidth: 2,
773
1147
  pointFill: '#FFFFFF',
774
- pointSize: 8,
1148
+ pointSize: 10,
775
1149
  pointRadius: 16,
776
1150
  rotateGap: 45,
777
1151
  buttonsDirection: 'bottom',
778
1152
  buttonsMargin: 12,
1153
+ hideOnSmall: true,
779
1154
  moveCursor: 'move',
780
- resizeCursor: ['nwse-resize', 'ns-resize', 'nesw-resize', 'ew-resize', 'nwse-resize', 'ns-resize', 'nesw-resize', 'ew-resize'],
781
- rotateCursor: ['ne-resize', 'e-resize', 'se-resize', 's-resize', 'sw-resize', 'w-resize', 'nw-resize', 'n-resize'],
1155
+ resizeCursor: { url: resizeSVG, x: 12, y: 12 },
1156
+ rotateCursor: { url: rotateSVG, x: 12, y: 12 },
1157
+ skewCursor: { url: skewSVG, x: 12, y: 12 },
782
1158
  selector: true,
783
1159
  hover: true,
1160
+ select: 'press',
1161
+ openInner: 'double',
784
1162
  boxSelect: true,
1163
+ moveable: true,
785
1164
  resizeable: true,
786
1165
  rotateable: true,
787
1166
  skewable: true
788
1167
  };
789
1168
 
790
- class EditTool {
791
- constructor() {
792
- this.tag = 'EditTool';
793
- }
794
- onMove(e) {
795
- const { moveX, moveY, editor } = e;
796
- const { app, list } = editor;
797
- app.lockLayout();
798
- list.forEach(target => {
799
- const move = target.getLocalPoint({ x: moveX, y: moveY }, null, true);
800
- target.move(move.x, move.y);
801
- });
802
- app.unlockLayout();
803
- }
804
- onScale(e) {
805
- const { scaleX, scaleY, transform, worldOrigin, editor } = e;
806
- const { app, list } = editor;
807
- app.lockLayout();
808
- list.forEach(target => {
809
- const resize = editor.getEditSize(target) === 'size';
810
- if (transform) {
811
- target.transform(transform, resize);
812
- }
813
- else {
814
- target.scaleOf(target.getInnerPoint(worldOrigin), scaleX, scaleY, resize);
815
- }
816
- });
817
- app.unlockLayout();
818
- }
819
- onRotate(e) {
820
- const { rotation, worldOrigin, editor } = e;
821
- const { app, list } = editor;
822
- app.lockLayout();
823
- list.forEach(target => {
824
- target.rotateOf(target.getInnerPoint(worldOrigin), rotation);
825
- });
826
- app.unlockLayout();
827
- }
828
- onSkew(e) {
829
- const { skewX, skewY, transform, worldOrigin, editor } = e;
830
- const { app, list } = editor;
831
- app.lockLayout();
832
- list.forEach(target => {
833
- const resize = editor.getEditSize(target) === 'size';
834
- if (transform) {
835
- target.transform(transform, resize);
836
- }
837
- else {
838
- target.skewOf(target.getInnerPoint(worldOrigin), skewX, skewY, resize);
839
- }
840
- });
841
- app.unlockLayout();
842
- }
843
- update(editor) {
844
- const { simulateTarget, element } = editor;
845
- if (editor.multiple)
846
- simulateTarget.parent.updateLayout();
847
- const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = element.getLayoutBounds('box', editor, true);
848
- editor.editBox.set({ x, y, scaleX, scaleY, rotation, skewX, skewY });
849
- editor.editBox.update({ x: 0, y: 0, width, height });
850
- }
851
- }
852
- EditTool.list = [];
853
-
854
- const { left, right } = IDirection8;
855
- class LineEditTool extends EditTool {
856
- constructor() {
857
- super(...arguments);
858
- this.tag = 'LineEditTool';
859
- this.scaleOfEvent = true;
860
- }
861
- onScaleWithDrag(e) {
862
- const { drag, direction, lockRatio, around } = e;
863
- const target = e.target;
864
- const fromPoint = { x: 0, y: 0 };
865
- const { toPoint } = target;
866
- target.rotation = 0;
867
- let { x, y } = drag.getInnerMove(target);
868
- if (lockRatio) {
869
- if (Math.abs(x) > Math.abs(y)) {
870
- y = 0;
871
- }
872
- else {
873
- x = 0;
874
- }
875
- }
876
- if (direction === left) {
877
- fromPoint.x += x;
878
- fromPoint.y += y;
879
- if (around) {
880
- toPoint.x -= x;
881
- toPoint.y -= y;
882
- }
883
- }
884
- else {
885
- if (around) {
886
- fromPoint.x -= x;
887
- fromPoint.y -= y;
888
- }
889
- toPoint.x += x;
890
- toPoint.y += y;
891
- }
892
- target.getLocalPointByInner(fromPoint, null, null, true);
893
- target.getLocalPointByInner(toPoint, null, null, true);
894
- target.x = fromPoint.x;
895
- target.y = fromPoint.y;
896
- target.getInnerPointByLocal(toPoint, null, null, true);
897
- target.toPoint = toPoint;
898
- }
899
- onSkew(_e) {
900
- }
901
- update(editor) {
902
- const { rotatePoints, resizeLines, resizePoints } = editor.editBox;
903
- super.update(editor);
904
- for (let i = 0; i < 8; i++) {
905
- if (i < 4)
906
- resizeLines[i].visible = false;
907
- resizePoints[i].visible = rotatePoints[i].visible = (i === left || i === right);
908
- }
909
- }
910
- }
911
-
912
- function getEditTool(list) {
913
- if (list.length === 1) {
914
- const leaf = list[0];
915
- if (leaf instanceof core.Line && !leaf.points) {
916
- return new LineEditTool();
917
- }
918
- else {
919
- return new EditTool();
920
- }
921
- }
922
- else {
923
- return new EditTool();
924
- }
925
- }
926
-
927
1169
  function simulate(editor) {
928
1170
  const { simulateTarget, leafList: targetList } = editor;
929
- const { x, y, width, height } = new core.Bounds().setListWithFn(targetList.list, (leaf) => leaf.worldBoxBounds);
1171
+ const { x, y, width, height } = new draw.Bounds().setListWithFn(targetList.list, (leaf) => leaf.worldBoxBounds);
930
1172
  const parent = simulateTarget.parent = targetList.list[0].leafer.zoomLayer;
931
1173
  const { scaleX, scaleY, e: worldX, f: worldY } = parent.__world;
932
1174
  simulateTarget.reset({ x: (x - worldX) / scaleX, y: (y - worldY) / scaleY, width: width / scaleX, height: height / scaleY });
@@ -935,13 +1177,14 @@ this.LeaferIN.editor = (function (exports, core) {
935
1177
  function onTarget(editor, oldValue) {
936
1178
  const { target } = editor;
937
1179
  if (target) {
938
- editor.leafList = target instanceof core.LeafList ? target : new core.LeafList(target instanceof Array ? target : target);
1180
+ editor.leafList = target instanceof draw.LeafList ? target : new draw.LeafList(target instanceof Array ? target : target);
939
1181
  }
940
1182
  else {
941
1183
  editor.leafList.reset();
942
1184
  }
943
1185
  editor.emitEvent(new EditorEvent(EditorEvent.SELECT, { editor, value: target, oldValue }));
944
- if (editor.hasTarget) {
1186
+ editor.checkOpenedGroups();
1187
+ if (editor.editing) {
945
1188
  editor.waitLeafer(() => {
946
1189
  if (editor.multiple)
947
1190
  simulate(editor);
@@ -952,6 +1195,7 @@ this.LeaferIN.editor = (function (exports, core) {
952
1195
  });
953
1196
  }
954
1197
  else {
1198
+ editor.updateEditTool();
955
1199
  editor.removeTargetEvents();
956
1200
  }
957
1201
  }
@@ -962,14 +1206,19 @@ this.LeaferIN.editor = (function (exports, core) {
962
1206
  const order = (a, b) => a.parent.children.indexOf(a) - b.parent.children.indexOf(b);
963
1207
  const reverseOrder = (a, b) => b.parent.children.indexOf(b) - a.parent.children.indexOf(a);
964
1208
  const EditorHelper = {
965
- group(list, element, group) {
1209
+ group(list, element, userGroup) {
966
1210
  list.sort(reverseOrder);
967
1211
  const { app, parent } = list[0];
968
- if (!group)
969
- group = new core.Group();
1212
+ let group;
1213
+ if (userGroup && userGroup.add) {
1214
+ group = userGroup;
1215
+ }
1216
+ else {
1217
+ group = new draw.Group(userGroup);
1218
+ }
970
1219
  parent.addAt(group, parent.children.indexOf(list[0]));
971
1220
  list.sort(order);
972
- const matrx = new core.Matrix(element.worldTransform);
1221
+ const matrx = new draw.Matrix(element.worldTransform);
973
1222
  matrx.divideParent(parent.worldTransform);
974
1223
  group.setTransform(matrx);
975
1224
  group.editable = true;
@@ -1015,25 +1264,79 @@ this.LeaferIN.editor = (function (exports, core) {
1015
1264
  }
1016
1265
  };
1017
1266
 
1018
- class Editor extends core.Group {
1267
+ const debug = draw.Debug.get('EditToolCreator');
1268
+ function registerEditTool() {
1269
+ return (target) => {
1270
+ EditToolCreator.register(target);
1271
+ };
1272
+ }
1273
+ const registerInnerEditor = registerEditTool;
1274
+ const EditToolCreator = {
1275
+ list: {},
1276
+ register(EditTool) {
1277
+ const { tag } = EditTool.prototype;
1278
+ list[tag] ? debug.repeat(tag) : (list[tag] = EditTool);
1279
+ },
1280
+ get(tag, editor) {
1281
+ return new list[tag](editor);
1282
+ }
1283
+ };
1284
+ const { list } = EditToolCreator;
1285
+
1286
+ class InnerEditorEvent extends EditorEvent {
1287
+ constructor(type, data) {
1288
+ super(type, data);
1289
+ }
1290
+ }
1291
+ InnerEditorEvent.BEFORE_OPEN = 'innerEditor.before_open';
1292
+ InnerEditorEvent.OPEN = 'innerEditor.open';
1293
+ InnerEditorEvent.BEFORE_CLOSE = 'innerEditor.before_close';
1294
+ InnerEditorEvent.CLOSE = 'innerEditor.close';
1295
+
1296
+ class EditorGroupEvent extends EditorEvent {
1297
+ constructor(type, data) {
1298
+ super(type, data);
1299
+ }
1300
+ }
1301
+ EditorGroupEvent.GROUP = 'editor.group';
1302
+ EditorGroupEvent.BEFORE_UNGROUP = 'editor.before_ungroup';
1303
+ EditorGroupEvent.UNGROUP = 'editor.ungroup';
1304
+ EditorGroupEvent.OPEN = 'editor.open_group';
1305
+ EditorGroupEvent.CLOSE = 'editor.close_group';
1306
+
1307
+ class Editor extends draw.Group {
1308
+ get mergeConfig() {
1309
+ const { element, config } = this;
1310
+ return this.single && element.editConfig ? Object.assign(Object.assign({}, config), element.editConfig) : config;
1311
+ }
1019
1312
  get list() { return this.leafList.list; }
1020
- get hasTarget() { return !!this.list.length; }
1313
+ get editing() { return !!this.list.length; }
1314
+ get groupOpening() { return !!this.openedGroupList.length; }
1021
1315
  get multiple() { return this.list.length > 1; }
1022
1316
  get single() { return this.list.length === 1; }
1317
+ get dragging() { return this.editBox.dragging; }
1023
1318
  get element() { return this.multiple ? this.simulateTarget : this.list[0]; }
1024
1319
  get buttons() { return this.editBox.buttons; }
1025
- get dragging() { return this.editBox.dragging; }
1026
1320
  constructor(userConfig, data) {
1027
1321
  super(data);
1028
1322
  this.config = config;
1029
- this.leafList = new core.LeafList();
1030
- this.simulateTarget = new core.Rect({ visible: false });
1323
+ this.leafList = new draw.LeafList();
1324
+ this.openedGroupList = new draw.LeafList();
1325
+ this.simulateTarget = new draw.Rect({ visible: false });
1031
1326
  this.editBox = new EditBox(this);
1327
+ this.editToolList = {};
1032
1328
  this.selector = new EditSelect(this);
1329
+ this.editMask = new EditMask(this);
1033
1330
  this.targetEventIds = [];
1034
1331
  if (userConfig)
1035
- this.config = core.DataHelper.default(userConfig, this.config);
1036
- this.addMany(this.selector, this.editBox);
1332
+ this.config = draw.DataHelper.default(userConfig, this.config);
1333
+ this.addMany(this.editMask, this.selector, this.editBox);
1334
+ }
1335
+ select(target) {
1336
+ this.target = target;
1337
+ }
1338
+ cancel() {
1339
+ this.target = null;
1037
1340
  }
1038
1341
  hasItem(item) {
1039
1342
  return this.leafList.has(item);
@@ -1050,52 +1353,82 @@ this.LeaferIN.editor = (function (exports, core) {
1050
1353
  this.hasItem(item) ? this.removeItem(item) : this.addItem(item);
1051
1354
  }
1052
1355
  update() {
1053
- if (this.target) {
1054
- this.editTool.update(this);
1356
+ if (this.editing) {
1357
+ if (this.innerEditing)
1358
+ this.innerEditor.update();
1359
+ this.editTool.update();
1055
1360
  this.selector.update();
1056
1361
  }
1057
1362
  }
1363
+ updateEditBox() {
1364
+ if (this.multiple)
1365
+ simulate(this);
1366
+ this.update();
1367
+ }
1058
1368
  updateEditTool() {
1059
- this.editTool = getEditTool(this.list);
1369
+ const tool = this.editTool;
1370
+ if (tool) {
1371
+ this.editBox.unload();
1372
+ tool.unload();
1373
+ this.editTool = null;
1374
+ }
1375
+ if (this.editing) {
1376
+ const tag = this.single ? this.list[0].editOuter : 'EditTool';
1377
+ this.editTool = this.editToolList[tag] = this.editToolList[tag] || EditToolCreator.get(tag, this);
1378
+ this.editBox.load();
1379
+ this.editTool.load();
1380
+ }
1060
1381
  }
1061
- getEditSize(ui) {
1062
- let { editSize } = this.config;
1063
- return editSize === 'auto' ? ui.editSize : editSize;
1382
+ getEditSize(_ui) {
1383
+ return this.mergeConfig.editSize;
1064
1384
  }
1065
1385
  onMove(e) {
1066
- const move = e.getLocalMove(this.element);
1386
+ const total = { x: e.totalX, y: e.totalY };
1067
1387
  if (e.shiftKey) {
1068
- if (Math.abs(move.x) > Math.abs(move.y))
1069
- move.y = 0;
1388
+ if (Math.abs(total.x) > Math.abs(total.y))
1389
+ total.y = 0;
1070
1390
  else
1071
- move.x = 0;
1391
+ total.x = 0;
1072
1392
  }
1073
- this.move(move.x, move.y);
1393
+ this.move(core.DragEvent.getValidMove(this.element, this.dragStartPoint, total));
1074
1394
  }
1075
1395
  onScale(e) {
1076
1396
  const { element } = this;
1077
- const { direction } = e.current;
1078
- let { around, lockRatio } = this.config;
1079
- if (e.shiftKey)
1080
- lockRatio = true;
1081
- const data = EditDataHelper.getScaleData(element.boxBounds, direction, e.getInnerMove(element), lockRatio, EditDataHelper.getAround(around, e.altKey));
1082
- if (this.editTool.onScaleWithDrag) {
1083
- data.drag = e;
1084
- this.scaleWithDrag(data);
1397
+ if (e instanceof core.ZoomEvent) {
1398
+ if (this.mergeConfig.resizeable === 'zoom') {
1399
+ e.stop();
1400
+ this.scaleOf(element.getInnerPoint(e), e.scale, e.scale);
1401
+ }
1085
1402
  }
1086
1403
  else {
1087
- this.scaleOf(data.origin, data.scaleX, data.scaleY);
1404
+ const { direction } = e.current;
1405
+ let { around, lockRatio } = this.mergeConfig;
1406
+ if (e.shiftKey || element.lockRatio)
1407
+ lockRatio = true;
1408
+ const data = EditDataHelper.getScaleData(element.boxBounds, direction, e.getInnerMove(element), lockRatio, EditDataHelper.getAround(around, e.altKey));
1409
+ if (this.editTool.onScaleWithDrag) {
1410
+ data.drag = e;
1411
+ this.scaleWithDrag(data);
1412
+ }
1413
+ else {
1414
+ this.scaleOf(data.origin, data.scaleX, data.scaleY);
1415
+ }
1088
1416
  }
1089
1417
  }
1090
1418
  onRotate(e) {
1091
- const { skewable, around, rotateGap } = this.config;
1419
+ const { skewable, around, rotateGap } = this.mergeConfig;
1092
1420
  const { direction, name } = e.current;
1093
1421
  if (skewable && name === 'resize-line')
1094
1422
  return this.onSkew(e);
1095
- const { element, editBox } = this;
1423
+ const { element } = this;
1096
1424
  let origin, rotation;
1097
1425
  if (e instanceof core.RotateEvent) {
1098
- rotation = e.rotation, origin = element.getInnerPoint(e);
1426
+ if (this.mergeConfig.rotateable === 'rotate') {
1427
+ e.stop();
1428
+ rotation = e.rotation, origin = element.getInnerPoint(e);
1429
+ }
1430
+ else
1431
+ return;
1099
1432
  }
1100
1433
  else {
1101
1434
  const last = { x: e.x - e.moveX, y: e.y - e.moveY };
@@ -1103,24 +1436,26 @@ this.LeaferIN.editor = (function (exports, core) {
1103
1436
  rotation = data.rotation;
1104
1437
  origin = data.origin;
1105
1438
  }
1106
- rotation = core.MathHelper.getGapRotation(rotation, rotateGap, element.rotation);
1439
+ rotation = draw.MathHelper.getGapRotation(rotation, rotateGap, element.rotation);
1107
1440
  if (!rotation)
1108
1441
  return;
1109
- if (editBox.flippedOne)
1442
+ if (element.scaleX * element.scaleY < 0)
1110
1443
  rotation = -rotation;
1111
- this.rotateOf(origin, rotation);
1444
+ this.rotateOf(origin, draw.MathHelper.float(rotation, 2));
1112
1445
  }
1113
1446
  onSkew(e) {
1114
1447
  const { element } = this;
1115
- const { around } = this.config;
1448
+ const { around } = this.mergeConfig;
1116
1449
  const { origin, skewX, skewY } = EditDataHelper.getSkewData(element.boxBounds, e.current.direction, e.getInnerMove(element), EditDataHelper.getAround(around, e.altKey));
1117
1450
  if (!skewX && !skewY)
1118
1451
  return;
1119
1452
  this.skewOf(origin, skewX, skewY);
1120
1453
  }
1121
- move(x, y) {
1454
+ move(x, y = 0) {
1455
+ if (!this.mergeConfig.moveable || this.element.locked)
1456
+ return;
1122
1457
  const { element } = this;
1123
- const world = element.getWorldPointByLocal({ x, y }, null, true);
1458
+ const world = element.getWorldPointByLocal(typeof x === 'object' ? Object.assign({}, x) : { x, y }, null, true);
1124
1459
  const event = new EditorMoveEvent(EditorMoveEvent.MOVE, { target: element, editor: this, moveX: world.x, moveY: world.y });
1125
1460
  this.editTool.onMove(event);
1126
1461
  this.emitEvent(event);
@@ -1128,6 +1463,8 @@ this.LeaferIN.editor = (function (exports, core) {
1128
1463
  element.move(x, y);
1129
1464
  }
1130
1465
  scaleWithDrag(data) {
1466
+ if (!this.mergeConfig.resizeable || this.element.locked)
1467
+ return;
1131
1468
  const { element } = this;
1132
1469
  const worldOrigin = element.getWorldPoint(data.origin);
1133
1470
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, Object.assign(Object.assign({}, data), { target: element, editor: this, worldOrigin }));
@@ -1135,35 +1472,45 @@ this.LeaferIN.editor = (function (exports, core) {
1135
1472
  this.emitEvent(event);
1136
1473
  }
1137
1474
  scaleOf(origin, scaleX, scaleY = scaleX, _resize) {
1475
+ if (!this.mergeConfig.resizeable || this.element.locked)
1476
+ return;
1138
1477
  const { element } = this;
1139
- const worldOrigin = element.getWorldPoint(origin);
1478
+ const worldOrigin = element.getWorldPoint(draw.LeafHelper.getInnerOrigin(element, origin));
1140
1479
  let transform;
1141
1480
  if (this.multiple) {
1142
- const childMatrix = Object.assign({}, element.localTransform);
1481
+ const oldMatrix = new draw.Matrix(element.worldTransform);
1143
1482
  element.scaleOf(origin, scaleX, scaleY);
1144
- transform = new core.Matrix(element.localTransform).divide(childMatrix);
1483
+ transform = new draw.Matrix(element.worldTransform).divide(oldMatrix);
1145
1484
  }
1146
1485
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, { target: element, editor: this, worldOrigin, scaleX, scaleY, transform });
1147
1486
  this.editTool.onScale(event);
1148
1487
  this.emitEvent(event);
1149
1488
  }
1150
1489
  rotateOf(origin, rotation) {
1490
+ if (!this.mergeConfig.rotateable || this.element.locked)
1491
+ return;
1151
1492
  const { element } = this;
1152
- const worldOrigin = element.getWorldPoint(origin);
1153
- const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, { target: element, editor: this, worldOrigin, rotation });
1493
+ const worldOrigin = element.getWorldPoint(draw.LeafHelper.getInnerOrigin(element, origin));
1494
+ let transform;
1495
+ if (this.multiple) {
1496
+ const oldMatrix = new draw.Matrix(element.worldTransform);
1497
+ element.rotateOf(origin, rotation);
1498
+ transform = new draw.Matrix(element.worldTransform).divide(oldMatrix);
1499
+ }
1500
+ const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, { target: element, editor: this, worldOrigin, rotation, transform });
1154
1501
  this.editTool.onRotate(event);
1155
1502
  this.emitEvent(event);
1156
- if (this.multiple)
1157
- element.rotateOf(origin, rotation);
1158
1503
  }
1159
1504
  skewOf(origin, skewX, skewY = 0, _resize) {
1505
+ if (!this.mergeConfig.skewable || this.element.locked)
1506
+ return;
1160
1507
  const { element } = this;
1161
- const worldOrigin = element.getWorldPoint(origin);
1508
+ const worldOrigin = element.getWorldPoint(draw.LeafHelper.getInnerOrigin(element, origin));
1162
1509
  let transform;
1163
1510
  if (this.multiple) {
1164
- const childMatrix = Object.assign({}, element.localTransform);
1511
+ const oldMatrix = new draw.Matrix(element.worldTransform);
1165
1512
  element.skewOf(origin, skewX, skewY);
1166
- transform = new core.Matrix(element.localTransform).divide(childMatrix);
1513
+ transform = new draw.Matrix(element.worldTransform).divide(oldMatrix);
1167
1514
  }
1168
1515
  const event = new EditorSkewEvent(EditorSkewEvent.SKEW, {
1169
1516
  target: element, editor: this, skewX, skewY, transform, worldOrigin
@@ -1171,16 +1518,92 @@ this.LeaferIN.editor = (function (exports, core) {
1171
1518
  this.editTool.onSkew(event);
1172
1519
  this.emitEvent(event);
1173
1520
  }
1174
- group(group) {
1175
- if (this.multiple)
1176
- this.target = EditorHelper.group(this.list, this.element, group);
1521
+ group(userGroup) {
1522
+ if (this.multiple) {
1523
+ this.target = EditorHelper.group(this.list, this.element, userGroup);
1524
+ this.emitGroupEvent(EditorGroupEvent.GROUP, this.target);
1525
+ }
1177
1526
  return this.target;
1178
1527
  }
1179
1528
  ungroup() {
1180
- if (this.list.length)
1181
- this.target = EditorHelper.ungroup(this.list);
1529
+ const { list } = this;
1530
+ if (list.length) {
1531
+ list.forEach(item => item.isBranch && this.emitGroupEvent(EditorGroupEvent.BEFORE_UNGROUP, item));
1532
+ this.target = EditorHelper.ungroup(list);
1533
+ list.forEach(item => item.isBranch && this.emitGroupEvent(EditorGroupEvent.UNGROUP, item));
1534
+ }
1182
1535
  return this.list;
1183
1536
  }
1537
+ openGroup(group) {
1538
+ this.openedGroupList.add(group);
1539
+ group.hitChildren = true;
1540
+ this.emitGroupEvent(EditorGroupEvent.OPEN, group);
1541
+ }
1542
+ closeGroup(group) {
1543
+ this.openedGroupList.remove(group);
1544
+ group.hitChildren = false;
1545
+ this.emitGroupEvent(EditorGroupEvent.CLOSE, group);
1546
+ }
1547
+ checkOpenedGroups() {
1548
+ const opened = this.openedGroupList;
1549
+ if (opened.length) {
1550
+ let { list } = opened;
1551
+ if (this.editing)
1552
+ list = [], opened.forEach(item => this.list.every(leaf => !draw.LeafHelper.hasParent(leaf, item)) && list.push(item));
1553
+ list.forEach(item => this.closeGroup(item));
1554
+ }
1555
+ if (this.editing && !this.selector.dragging)
1556
+ this.checkDeepSelect();
1557
+ }
1558
+ checkDeepSelect() {
1559
+ let parent, { list } = this;
1560
+ for (let i = 0; i < list.length; i++) {
1561
+ parent = list[i].parent;
1562
+ while (parent && !parent.hitChildren) {
1563
+ this.openGroup(parent);
1564
+ parent = parent.parent;
1565
+ }
1566
+ }
1567
+ }
1568
+ emitGroupEvent(type, group) {
1569
+ const event = new EditorGroupEvent(type, { editTarget: group });
1570
+ this.emitEvent(event);
1571
+ group.emitEvent(event);
1572
+ }
1573
+ openInnerEditor(target) {
1574
+ if (target)
1575
+ this.target = target;
1576
+ if (this.single) {
1577
+ const editTarget = this.element;
1578
+ const tag = editTarget.editInner;
1579
+ if (tag && EditToolCreator.list[tag]) {
1580
+ this.editTool.unload();
1581
+ this.innerEditing = true;
1582
+ this.innerEditor = this.editToolList[tag] || EditToolCreator.get(tag, this);
1583
+ this.innerEditor.editTarget = editTarget;
1584
+ this.emitInnerEvent(InnerEditorEvent.BEFORE_OPEN);
1585
+ this.innerEditor.load();
1586
+ this.emitInnerEvent(InnerEditorEvent.OPEN);
1587
+ }
1588
+ }
1589
+ }
1590
+ closeInnerEditor() {
1591
+ if (this.innerEditing) {
1592
+ this.innerEditing = false;
1593
+ this.emitInnerEvent(InnerEditorEvent.BEFORE_CLOSE);
1594
+ this.innerEditor.unload();
1595
+ this.emitInnerEvent(InnerEditorEvent.CLOSE);
1596
+ this.editTool.load();
1597
+ this.innerEditor = null;
1598
+ }
1599
+ }
1600
+ emitInnerEvent(type) {
1601
+ const { innerEditor } = this;
1602
+ const { editTarget } = innerEditor;
1603
+ const event = new InnerEditorEvent(type, { editTarget, innerEditor });
1604
+ this.emitEvent(event);
1605
+ editTarget.emitEvent(event);
1606
+ }
1184
1607
  lock() {
1185
1608
  this.list.forEach(leaf => leaf.locked = true);
1186
1609
  this.update();
@@ -1205,7 +1628,7 @@ this.LeaferIN.editor = (function (exports, core) {
1205
1628
  if (!this.targetEventIds.length) {
1206
1629
  const { leafer } = this.list[0];
1207
1630
  this.targetEventIds = [
1208
- leafer.on_(core.RenderEvent.START, this.update, this),
1631
+ leafer.on_(draw.RenderEvent.START, this.update, this),
1209
1632
  leafer.on_([core.KeyEvent.HOLD, core.KeyEvent.UP], (e) => { updateCursor(this, e); }),
1210
1633
  leafer.on_(core.KeyEvent.DOWN, this.editBox.onArrow, this.editBox)
1211
1634
  ];
@@ -1221,7 +1644,9 @@ this.LeaferIN.editor = (function (exports, core) {
1221
1644
  destroy() {
1222
1645
  if (!this.destroyed) {
1223
1646
  this.simulateTarget.destroy();
1224
- this.target = this.hoverTarget = this.simulateTarget = null;
1647
+ Object.values(this.editToolList).forEach(item => item.destroy());
1648
+ this.editToolList = {};
1649
+ this.target = this.hoverTarget = this.simulateTarget = this.editTool = this.innerEditor = null;
1225
1650
  super.destroy();
1226
1651
  }
1227
1652
  }
@@ -1233,8 +1658,254 @@ this.LeaferIN.editor = (function (exports, core) {
1233
1658
  targetAttr(onTarget)
1234
1659
  ], Editor.prototype, "target", void 0);
1235
1660
 
1236
- core.Creator.editor = function (options) {
1237
- return new Editor(options);
1661
+ class InnerEditor {
1662
+ static registerInnerEditor() {
1663
+ EditToolCreator.register(this);
1664
+ }
1665
+ get tag() { return 'InnerEditor'; }
1666
+ get editBox() { return this.editor.editBox; }
1667
+ constructor(editor) {
1668
+ this.editor = editor;
1669
+ this.create();
1670
+ }
1671
+ onCreate() { }
1672
+ create() {
1673
+ this.view = new draw.Group();
1674
+ this.onCreate();
1675
+ }
1676
+ onLoad() { }
1677
+ load() {
1678
+ this.editor.selector.hittable = this.editor.app.tree.hitChildren = false;
1679
+ this.onLoad();
1680
+ }
1681
+ onUpdate() { }
1682
+ update() { this.onUpdate(); }
1683
+ onUnload() { }
1684
+ unload() {
1685
+ this.editor.selector.hittable = this.editor.app.tree.hitChildren = true;
1686
+ this.onUnload();
1687
+ }
1688
+ onDestroy() { }
1689
+ destroy() {
1690
+ this.onDestroy();
1691
+ if (this.editor) {
1692
+ if (this.view)
1693
+ this.view.destroy();
1694
+ if (this.eventIds)
1695
+ this.editor.off_(this.eventIds);
1696
+ this.editor = this.view = this.eventIds = null;
1697
+ }
1698
+ }
1699
+ }
1700
+
1701
+ exports.EditTool = class EditTool extends InnerEditor {
1702
+ static registerEditTool() {
1703
+ EditToolCreator.register(this);
1704
+ }
1705
+ get tag() { return 'EditTool'; }
1706
+ onMove(e) {
1707
+ const { moveX, moveY, editor } = e;
1708
+ const { app, list } = editor;
1709
+ app.lockLayout();
1710
+ list.forEach(target => {
1711
+ target.moveWorld(moveX, moveY);
1712
+ });
1713
+ app.unlockLayout();
1714
+ }
1715
+ onScale(e) {
1716
+ const { scaleX, scaleY, transform, worldOrigin, editor } = e;
1717
+ const { app, list } = editor;
1718
+ app.lockLayout();
1719
+ list.forEach(target => {
1720
+ const resize = editor.getEditSize(target) !== 'scale';
1721
+ if (transform) {
1722
+ target.transformWorld(transform, resize);
1723
+ }
1724
+ else {
1725
+ target.scaleOfWorld(worldOrigin, scaleX, scaleY, resize);
1726
+ }
1727
+ });
1728
+ app.unlockLayout();
1729
+ }
1730
+ onRotate(e) {
1731
+ const { rotation, transform, worldOrigin, editor } = e;
1732
+ const { app, list } = editor;
1733
+ app.lockLayout();
1734
+ list.forEach(target => {
1735
+ const resize = editor.getEditSize(target) !== 'scale';
1736
+ if (transform) {
1737
+ target.transformWorld(transform, resize);
1738
+ }
1739
+ else {
1740
+ target.rotateOfWorld(worldOrigin, rotation);
1741
+ }
1742
+ });
1743
+ app.unlockLayout();
1744
+ }
1745
+ onSkew(e) {
1746
+ const { skewX, skewY, transform, worldOrigin, editor } = e;
1747
+ const { app, list } = editor;
1748
+ app.lockLayout();
1749
+ list.forEach(target => {
1750
+ const resize = editor.getEditSize(target) !== 'scale';
1751
+ if (transform) {
1752
+ target.transformWorld(transform, resize);
1753
+ }
1754
+ else {
1755
+ target.skewOfWorld(worldOrigin, skewX, skewY, resize);
1756
+ }
1757
+ });
1758
+ app.unlockLayout();
1759
+ }
1760
+ load() {
1761
+ this.editBox.view.visible = true;
1762
+ this.onLoad();
1763
+ }
1764
+ update() {
1765
+ const { editor, editBox } = this;
1766
+ const { simulateTarget, element } = editor;
1767
+ if (editor.multiple)
1768
+ simulateTarget.parent.updateLayout();
1769
+ const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = element.getLayoutBounds('box', editor, true);
1770
+ editBox.set({ x, y, scaleX, scaleY, rotation, skewX, skewY });
1771
+ editBox.update({ x: 0, y: 0, width, height });
1772
+ this.onUpdate();
1773
+ }
1774
+ unload() {
1775
+ this.editBox.view.visible = false;
1776
+ this.onUnload();
1777
+ }
1778
+ };
1779
+ exports.EditTool = __decorate([
1780
+ registerEditTool()
1781
+ ], exports.EditTool);
1782
+
1783
+ const { left, right } = draw.Direction9;
1784
+ const { move, copy } = draw.PointHelper;
1785
+ exports.LineEditTool = class LineEditTool extends exports.EditTool {
1786
+ constructor() {
1787
+ super(...arguments);
1788
+ this.scaleOfEvent = true;
1789
+ }
1790
+ get tag() { return 'LineEditTool'; }
1791
+ onScaleWithDrag(e) {
1792
+ const { drag, direction, lockRatio, around } = e;
1793
+ const line = e.target;
1794
+ const isDragFrom = direction === left;
1795
+ if (line.pathInputed) {
1796
+ const { path } = line.__;
1797
+ const { from, to } = this.getFromToByPath(path);
1798
+ this.dragPoint(from, to, isDragFrom, around, this.getInnerMove(line, drag, lockRatio));
1799
+ path[1] = from.x, path[2] = from.y;
1800
+ path[4] = to.x, path[5] = to.y;
1801
+ line.path = path;
1802
+ }
1803
+ else if (line.points) {
1804
+ const { points } = line;
1805
+ const { from, to } = this.getFromToByPoints(points);
1806
+ this.dragPoint(from, to, isDragFrom, around, this.getInnerMove(line, drag, lockRatio));
1807
+ points[0] = from.x, points[1] = from.y;
1808
+ points[2] = to.x, points[3] = to.y;
1809
+ line.points = points;
1810
+ }
1811
+ else {
1812
+ const from = draw.getPointData();
1813
+ const { toPoint } = line;
1814
+ line.rotation = 0;
1815
+ this.dragPoint(from, toPoint, isDragFrom, around, this.getInnerMove(line, drag, lockRatio));
1816
+ line.getLocalPointByInner(from, null, null, true);
1817
+ line.getLocalPointByInner(toPoint, null, null, true);
1818
+ line.x = from.x;
1819
+ line.y = from.y;
1820
+ line.getInnerPointByLocal(toPoint, null, null, true);
1821
+ line.toPoint = toPoint;
1822
+ }
1823
+ }
1824
+ getInnerMove(ui, event, lockRatio) {
1825
+ const movePoint = event.getInnerMove(ui);
1826
+ if (lockRatio) {
1827
+ if (Math.abs(movePoint.x) > Math.abs(movePoint.y)) {
1828
+ movePoint.y = 0;
1829
+ }
1830
+ else {
1831
+ movePoint.x = 0;
1832
+ }
1833
+ }
1834
+ return movePoint;
1835
+ }
1836
+ getFromToByPath(path) {
1837
+ return {
1838
+ from: { x: path[1], y: path[2] },
1839
+ to: { x: path[4], y: path[5] }
1840
+ };
1841
+ }
1842
+ getFromToByPoints(points) {
1843
+ return {
1844
+ from: { x: points[0], y: points[1] },
1845
+ to: { x: points[2], y: points[3] }
1846
+ };
1847
+ }
1848
+ dragPoint(fromPoint, toPoint, isDragFrom, around, movePoint) {
1849
+ const { x, y } = movePoint;
1850
+ if (isDragFrom) {
1851
+ move(fromPoint, x, y);
1852
+ if (around)
1853
+ move(toPoint, -x, -y);
1854
+ }
1855
+ else {
1856
+ if (around)
1857
+ move(fromPoint, -x, -y);
1858
+ move(toPoint, x, y);
1859
+ }
1860
+ }
1861
+ onSkew(_e) {
1862
+ }
1863
+ onUpdate() {
1864
+ const { editBox } = this, { rotatePoints, resizeLines, resizePoints, rect } = editBox;
1865
+ const line = this.editor.element;
1866
+ let fromTo, leftOrRight;
1867
+ if (line.pathInputed)
1868
+ fromTo = this.getFromToByPath(line.__.path);
1869
+ else if (line.points)
1870
+ fromTo = this.getFromToByPoints(line.__.points);
1871
+ if (fromTo) {
1872
+ const { from, to } = fromTo;
1873
+ line.innerToWorld(from, from, false, editBox);
1874
+ line.innerToWorld(to, to, false, editBox);
1875
+ rect.pen.clearPath().moveTo(from.x, from.y).lineTo(to.x, to.y);
1876
+ copy(resizePoints[7], from);
1877
+ copy(rotatePoints[7], from);
1878
+ copy(resizePoints[3], to);
1879
+ copy(rotatePoints[3], to);
1880
+ }
1881
+ for (let i = 0; i < 8; i++) {
1882
+ if (i < 4)
1883
+ resizeLines[i].visible = false;
1884
+ leftOrRight = i === left || i === right;
1885
+ resizePoints[i].visible = leftOrRight;
1886
+ rotatePoints[i].visible = fromTo ? false : leftOrRight;
1887
+ }
1888
+ }
1889
+ };
1890
+ exports.LineEditTool = __decorate([
1891
+ registerEditTool()
1892
+ ], exports.LineEditTool);
1893
+
1894
+ draw.Creator.editor = function (options) { return new Editor(options); };
1895
+ draw.UI.setEditConfig = function (config) {
1896
+ draw.defineKey(this.prototype, 'editConfig', {
1897
+ get() { return typeof config === 'function' ? config(this) : config; }
1898
+ });
1899
+ };
1900
+ draw.UI.setEditOuter = function (toolName) {
1901
+ draw.defineKey(this.prototype, 'editOuter', {
1902
+ get() { return typeof toolName === 'string' ? toolName : toolName(this); }
1903
+ });
1904
+ };
1905
+ draw.UI.setEditInner = function (editorName) {
1906
+ draw.defineKey(this.prototype, 'editInner', {
1907
+ get() { return typeof editorName === 'string' ? editorName : editorName(this); }
1908
+ });
1238
1909
  };
1239
1910
 
1240
1911
  exports.EditBox = EditBox;
@@ -1242,18 +1913,28 @@ this.LeaferIN.editor = (function (exports, core) {
1242
1913
  exports.EditPoint = EditPoint;
1243
1914
  exports.EditSelect = EditSelect;
1244
1915
  exports.EditSelectHelper = EditSelectHelper;
1245
- exports.EditTool = EditTool;
1916
+ exports.EditToolCreator = EditToolCreator;
1246
1917
  exports.Editor = Editor;
1247
1918
  exports.EditorEvent = EditorEvent;
1919
+ exports.EditorGroupEvent = EditorGroupEvent;
1248
1920
  exports.EditorHelper = EditorHelper;
1249
1921
  exports.EditorMoveEvent = EditorMoveEvent;
1250
1922
  exports.EditorRotateEvent = EditorRotateEvent;
1251
1923
  exports.EditorScaleEvent = EditorScaleEvent;
1252
1924
  exports.EditorSkewEvent = EditorSkewEvent;
1253
- exports.LineEditTool = LineEditTool;
1925
+ exports.InnerEditor = InnerEditor;
1926
+ exports.InnerEditorEvent = InnerEditorEvent;
1927
+ exports.PathScaler = PathScaler;
1254
1928
  exports.SelectArea = SelectArea;
1255
1929
  exports.Stroker = Stroker;
1930
+ exports.registerEditTool = registerEditTool;
1931
+ exports.registerInnerEditor = registerInnerEditor;
1932
+ exports.scaleResize = scaleResize;
1933
+ exports.scaleResizeFontSize = scaleResizeFontSize;
1934
+ exports.scaleResizeGroup = scaleResizeGroup;
1935
+ exports.scaleResizePath = scaleResizePath;
1936
+ exports.scaleResizePoints = scaleResizePoints;
1256
1937
 
1257
1938
  return exports;
1258
1939
 
1259
- })({}, LeaferUI);
1940
+ })({}, LeaferUI, LeaferUI);