@leafer-in/editor 1.0.0-rc.22 → 1.0.0-rc.24

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