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

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