@leafer-in/editor 1.0.0-rc.21 → 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.
- package/dist/editor.cjs +1718 -0
- package/dist/editor.esm.js +497 -328
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.js +498 -327
- package/dist/editor.min.cjs +1 -0
- package/dist/editor.min.js +1 -1
- package/package.json +12 -6
- package/src/Editor.ts +114 -30
- package/src/config.ts +2 -1
- package/src/display/EditBox.ts +126 -71
- package/src/display/EditPoint.ts +3 -3
- package/src/display/EditSelect.ts +40 -35
- package/src/display/Stroker.ts +16 -19
- package/src/editor/cursor.ts +3 -3
- package/src/editor/target.ts +3 -1
- package/src/event/EditorScaleEvent.ts +3 -2
- package/src/helper/EditDataHelper.ts +34 -33
- package/src/index.ts +29 -6
- package/src/tool/EditTool.ts +36 -12
- package/src/tool/EditToolCreator.ts +32 -0
- package/src/tool/InnerEditor.ts +64 -0
- package/src/tool/LineEditTool.ts +8 -8
- package/types/index.d.ts +96 -43
- package/src/tool/index.ts +0 -21
package/dist/editor.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PathCommandMap, Leaf, Path, Line, Polygon, MatrixHelper, Group, Box, Event, defineKey, UI, Paint, Rect, Answer, Bounds, LeafList, PointHelper, AroundHelper,
|
|
2
|
-
import { PointerEvent, DragEvent, MoveEvent, ZoomEvent, RotateEvent, KeyEvent
|
|
1
|
+
import { PathCommandMap, Leaf, Path, Line, Polygon, MatrixHelper, Group, Box, Event, defineKey, UI, Paint, Rect, Answer, Bounds, LeafList, PointHelper, AroundHelper, Direction9, MathHelper, Matrix, Debug, DataHelper, LeafHelper, RenderEvent, getPointData, Creator } from '@leafer-ui/draw';
|
|
2
|
+
import { PointerEvent, DragEvent, MoveEvent, ZoomEvent, RotateEvent, KeyEvent } from '@leafer-ui/core';
|
|
3
3
|
|
|
4
4
|
const { M, L, C, Q, Z, N, D, X, G, F, O, P, U } = PathCommandMap;
|
|
5
5
|
const PathScaler = {
|
|
@@ -246,34 +246,29 @@ class Stroker extends UI {
|
|
|
246
246
|
this.strokeAlign = 'center';
|
|
247
247
|
}
|
|
248
248
|
setTarget(target, style) {
|
|
249
|
-
|
|
250
|
-
this.set({ stroke, strokeWidth });
|
|
249
|
+
this.set(style);
|
|
251
250
|
this.target = target;
|
|
252
251
|
}
|
|
253
252
|
__draw(canvas, options) {
|
|
254
253
|
const { list } = this;
|
|
255
254
|
if (list.length) {
|
|
256
255
|
let leaf;
|
|
257
|
-
const { stroke, strokeWidth } = this.__;
|
|
256
|
+
const { stroke, strokeWidth, fill } = this.__;
|
|
258
257
|
const { bounds } = options;
|
|
259
258
|
for (let i = 0; i < list.length; i++) {
|
|
260
259
|
leaf = list[i];
|
|
261
260
|
if (bounds && bounds.hit(leaf.__world, options.matrix)) {
|
|
262
|
-
|
|
263
|
-
if (
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
const { x, y, width, height } = leaf.__layout.boxBounds;
|
|
272
|
-
canvas.rect(x * aScaleX, y * aScaleY, width * aScaleX, height * aScaleY);
|
|
273
|
-
drewPath = true;
|
|
274
|
-
}
|
|
261
|
+
const aScaleX = abs(leaf.__world.scaleX), aScaleY = abs(leaf.__world.scaleY);
|
|
262
|
+
if (aScaleX !== aScaleY) {
|
|
263
|
+
copy(matrix, leaf.__world);
|
|
264
|
+
scale(matrix, 1 / aScaleX, 1 / aScaleY);
|
|
265
|
+
canvas.setWorld(matrix, options.matrix);
|
|
266
|
+
canvas.beginPath();
|
|
267
|
+
this.__.strokeWidth = strokeWidth;
|
|
268
|
+
const { x, y, width, height } = leaf.__layout.boxBounds;
|
|
269
|
+
canvas.rect(x * aScaleX, y * aScaleY, width * aScaleX, height * aScaleY);
|
|
275
270
|
}
|
|
276
|
-
|
|
271
|
+
else {
|
|
277
272
|
canvas.setWorld(leaf.__world, options.matrix);
|
|
278
273
|
canvas.beginPath();
|
|
279
274
|
if (leaf.__.__useArrow) {
|
|
@@ -284,7 +279,10 @@ class Stroker extends UI {
|
|
|
284
279
|
}
|
|
285
280
|
this.__.strokeWidth = strokeWidth / abs(leaf.__world.scaleX);
|
|
286
281
|
}
|
|
287
|
-
|
|
282
|
+
if (stroke)
|
|
283
|
+
typeof stroke === 'string' ? Paint.stroke(stroke, this, canvas) : Paint.strokes(stroke, this, canvas);
|
|
284
|
+
if (fill)
|
|
285
|
+
typeof fill === 'string' ? Paint.fill(fill, this, canvas) : Paint.fills(fill, this, canvas);
|
|
288
286
|
}
|
|
289
287
|
}
|
|
290
288
|
this.__.strokeWidth = strokeWidth;
|
|
@@ -354,7 +352,7 @@ const EditSelectHelper = {
|
|
|
354
352
|
const { findOne } = EditSelectHelper;
|
|
355
353
|
class EditSelect extends Group {
|
|
356
354
|
get dragging() { return !!this.originList; }
|
|
357
|
-
get running() { return this.editor.hittable &&
|
|
355
|
+
get running() { const { editor } = this; return this.hittable && editor.visible && editor.hittable && editor.mergeConfig.selector; }
|
|
358
356
|
get isMoveMode() { return this.app && this.app.interaction.moveMode; }
|
|
359
357
|
constructor(editor) {
|
|
360
358
|
super();
|
|
@@ -370,8 +368,8 @@ class EditSelect extends Group {
|
|
|
370
368
|
onHover() {
|
|
371
369
|
const { editor } = this;
|
|
372
370
|
if (this.running && !this.dragging && !editor.dragging) {
|
|
373
|
-
const { stroke, strokeWidth, hover } = editor.
|
|
374
|
-
this.hoverStroker.setTarget(hover ? this.editor.hoverTarget : null, { stroke, strokeWidth });
|
|
371
|
+
const { stroke, strokeWidth, hover, hoverStyle } = editor.mergeConfig;
|
|
372
|
+
this.hoverStroker.setTarget(hover ? this.editor.hoverTarget : null, Object.assign({ stroke, strokeWidth }, (hoverStyle || {})));
|
|
375
373
|
}
|
|
376
374
|
else {
|
|
377
375
|
this.hoverStroker.target = null;
|
|
@@ -379,20 +377,20 @@ class EditSelect extends Group {
|
|
|
379
377
|
}
|
|
380
378
|
onSelect() {
|
|
381
379
|
if (this.running) {
|
|
382
|
-
const { config, list } = this.editor;
|
|
380
|
+
const { mergeConfig: config, list } = this.editor;
|
|
383
381
|
const { stroke, strokeWidth } = config;
|
|
384
382
|
this.targetStroker.setTarget(list, { stroke, strokeWidth: Math.max(1, strokeWidth / 2) });
|
|
385
383
|
this.hoverStroker.target = null;
|
|
386
384
|
}
|
|
387
385
|
}
|
|
388
386
|
update() {
|
|
389
|
-
if (this.
|
|
387
|
+
if (this.targetStroker.target)
|
|
390
388
|
this.targetStroker.forceUpdate();
|
|
391
389
|
}
|
|
392
390
|
onPointerMove(e) {
|
|
393
391
|
const { app, editor } = this;
|
|
394
392
|
if (this.running && !this.isMoveMode && app.config.pointer.hover && !app.interaction.dragging) {
|
|
395
|
-
const find =
|
|
393
|
+
const find = this.findUI(e);
|
|
396
394
|
editor.hoverTarget = editor.hasItem(find) ? null : find;
|
|
397
395
|
}
|
|
398
396
|
if (this.isMoveMode) {
|
|
@@ -400,43 +398,37 @@ class EditSelect extends Group {
|
|
|
400
398
|
}
|
|
401
399
|
}
|
|
402
400
|
onBeforeDown(e) {
|
|
403
|
-
const { select } = this.editor.
|
|
401
|
+
const { select } = this.editor.mergeConfig;
|
|
404
402
|
if (select === 'press')
|
|
405
|
-
this.checkAndSelect(e
|
|
403
|
+
this.checkAndSelect(e);
|
|
406
404
|
}
|
|
407
405
|
onTap(e) {
|
|
408
406
|
const { editor } = this;
|
|
409
|
-
const { select
|
|
407
|
+
const { select } = editor.mergeConfig;
|
|
410
408
|
if (select === 'tap')
|
|
411
409
|
this.checkAndSelect(e);
|
|
412
|
-
if (this.
|
|
413
|
-
|
|
414
|
-
if (find)
|
|
415
|
-
editor.shiftItem(find);
|
|
416
|
-
else if (!e.shiftKey && continuousSelect)
|
|
417
|
-
editor.target = null;
|
|
410
|
+
if (this.needRemoveItem) {
|
|
411
|
+
editor.removeItem(this.needRemoveItem);
|
|
418
412
|
}
|
|
419
413
|
else if (this.isMoveMode) {
|
|
420
414
|
editor.target = null;
|
|
421
415
|
}
|
|
422
|
-
this.lastDownLeaf = null;
|
|
423
416
|
}
|
|
424
|
-
checkAndSelect(e
|
|
425
|
-
|
|
417
|
+
checkAndSelect(e) {
|
|
418
|
+
this.needRemoveItem = null;
|
|
419
|
+
if (this.allowSelect(e)) {
|
|
426
420
|
const { editor } = this;
|
|
427
|
-
const find = this.
|
|
421
|
+
const find = this.findUI(e);
|
|
428
422
|
if (find) {
|
|
429
|
-
if (e
|
|
430
|
-
editor.
|
|
423
|
+
if (this.isMultipleSelect(e)) {
|
|
424
|
+
if (editor.hasItem(find))
|
|
425
|
+
this.needRemoveItem = find;
|
|
426
|
+
else
|
|
427
|
+
editor.addItem(find);
|
|
431
428
|
}
|
|
432
429
|
else {
|
|
433
430
|
editor.target = find;
|
|
434
431
|
}
|
|
435
|
-
if (isDownType) {
|
|
436
|
-
editor.updateLayout();
|
|
437
|
-
if (!find.locked)
|
|
438
|
-
this.app.interaction.updateDownData(e, { findList: [editor.editBox.rect] }, editor.config.dualEvent);
|
|
439
|
-
}
|
|
440
432
|
}
|
|
441
433
|
else if (this.allow(e.target)) {
|
|
442
434
|
if (!e.shiftKey)
|
|
@@ -445,12 +437,12 @@ class EditSelect extends Group {
|
|
|
445
437
|
}
|
|
446
438
|
}
|
|
447
439
|
onDragStart(e) {
|
|
448
|
-
if (this.
|
|
440
|
+
if (this.allowDrag(e)) {
|
|
449
441
|
const { editor } = this;
|
|
450
|
-
const { stroke,
|
|
442
|
+
const { stroke, area } = editor.mergeConfig;
|
|
451
443
|
const { x, y } = e.getInner(this);
|
|
452
444
|
this.bounds.set(x, y);
|
|
453
|
-
this.selectArea.setStyle({ visible: true, stroke,
|
|
445
|
+
this.selectArea.setStyle({ visible: true, stroke, x, y }, area);
|
|
454
446
|
this.selectArea.setBounds(this.bounds.get());
|
|
455
447
|
this.originList = editor.leafList.clone();
|
|
456
448
|
}
|
|
@@ -498,17 +490,26 @@ class EditSelect extends Group {
|
|
|
498
490
|
return target.leafer !== this.editor.leafer;
|
|
499
491
|
}
|
|
500
492
|
allowDrag(e) {
|
|
501
|
-
if (this.editor.
|
|
502
|
-
return (!this.editor.
|
|
493
|
+
if (this.running && this.editor.mergeConfig.boxSelect && !e.target.draggable) {
|
|
494
|
+
return (!this.editor.editing && this.allow(e.target)) || (e.shiftKey && !findOne(e.path));
|
|
503
495
|
}
|
|
504
496
|
else {
|
|
505
497
|
return false;
|
|
506
498
|
}
|
|
507
499
|
}
|
|
500
|
+
allowSelect(e) {
|
|
501
|
+
return this.running && !this.isMoveMode && !e.middle;
|
|
502
|
+
}
|
|
508
503
|
findDeepOne(e) {
|
|
509
504
|
const options = { exclude: new LeafList(this.editor.editBox.rect) };
|
|
510
505
|
return findOne(e.target.leafer.interaction.findPath(e, options));
|
|
511
506
|
}
|
|
507
|
+
findUI(e) {
|
|
508
|
+
return this.isMultipleSelect(e) ? this.findDeepOne(e) : findOne(e.path);
|
|
509
|
+
}
|
|
510
|
+
isMultipleSelect(e) {
|
|
511
|
+
return e.shiftKey || this.editor.mergeConfig.continuousSelect;
|
|
512
|
+
}
|
|
512
513
|
__listenEvents() {
|
|
513
514
|
const { editor } = this;
|
|
514
515
|
editor.waitLeafer(() => {
|
|
@@ -535,29 +536,17 @@ class EditSelect extends Group {
|
|
|
535
536
|
}
|
|
536
537
|
}
|
|
537
538
|
destroy() {
|
|
538
|
-
this.editor = this.originList = this.
|
|
539
|
+
this.editor = this.originList = this.needRemoveItem = null;
|
|
539
540
|
this.__removeListenEvents();
|
|
540
541
|
super.destroy();
|
|
541
542
|
}
|
|
542
543
|
}
|
|
543
544
|
|
|
544
|
-
|
|
545
|
-
(function (IDirection8) {
|
|
546
|
-
IDirection8[IDirection8["topLeft"] = 0] = "topLeft";
|
|
547
|
-
IDirection8[IDirection8["top"] = 1] = "top";
|
|
548
|
-
IDirection8[IDirection8["topRight"] = 2] = "topRight";
|
|
549
|
-
IDirection8[IDirection8["right"] = 3] = "right";
|
|
550
|
-
IDirection8[IDirection8["bottomRight"] = 4] = "bottomRight";
|
|
551
|
-
IDirection8[IDirection8["bottom"] = 5] = "bottom";
|
|
552
|
-
IDirection8[IDirection8["bottomLeft"] = 6] = "bottomLeft";
|
|
553
|
-
IDirection8[IDirection8["left"] = 7] = "left";
|
|
554
|
-
})(IDirection8 || (IDirection8 = {}));
|
|
555
|
-
|
|
556
|
-
const { topLeft, top, topRight, right: right$1, bottomRight, bottom, bottomLeft, left: left$1 } = IDirection8;
|
|
545
|
+
const { topLeft, top, topRight, right: right$1, bottomRight, bottom, bottomLeft, left: left$1 } = Direction9;
|
|
557
546
|
const { toPoint } = AroundHelper;
|
|
558
547
|
const EditDataHelper = {
|
|
559
548
|
getScaleData(bounds, direction, pointMove, lockRatio, around) {
|
|
560
|
-
let origin, scaleX = 1, scaleY = 1;
|
|
549
|
+
let align, origin = {}, scaleX = 1, scaleY = 1;
|
|
561
550
|
const { width, height } = bounds;
|
|
562
551
|
if (around) {
|
|
563
552
|
pointMove.x *= 2;
|
|
@@ -574,101 +563,100 @@ const EditDataHelper = {
|
|
|
574
563
|
switch (direction) {
|
|
575
564
|
case top:
|
|
576
565
|
scaleY = topScale;
|
|
577
|
-
|
|
566
|
+
align = 'bottom';
|
|
578
567
|
break;
|
|
579
568
|
case right$1:
|
|
580
569
|
scaleX = rightScale;
|
|
581
|
-
|
|
570
|
+
align = 'left';
|
|
582
571
|
break;
|
|
583
572
|
case bottom:
|
|
584
573
|
scaleY = bottomScale;
|
|
585
|
-
|
|
574
|
+
align = 'top';
|
|
586
575
|
break;
|
|
587
576
|
case left$1:
|
|
588
577
|
scaleX = leftScale;
|
|
589
|
-
|
|
578
|
+
align = 'right';
|
|
590
579
|
break;
|
|
591
580
|
case topLeft:
|
|
592
581
|
scaleY = topScale;
|
|
593
582
|
scaleX = leftScale;
|
|
594
|
-
|
|
583
|
+
align = 'bottom-right';
|
|
595
584
|
break;
|
|
596
585
|
case topRight:
|
|
597
586
|
scaleY = topScale;
|
|
598
587
|
scaleX = rightScale;
|
|
599
|
-
|
|
588
|
+
align = 'bottom-left';
|
|
600
589
|
break;
|
|
601
590
|
case bottomRight:
|
|
602
591
|
scaleY = bottomScale;
|
|
603
592
|
scaleX = rightScale;
|
|
604
|
-
|
|
593
|
+
align = 'top-left';
|
|
605
594
|
break;
|
|
606
595
|
case bottomLeft:
|
|
607
596
|
scaleY = bottomScale;
|
|
608
597
|
scaleX = leftScale;
|
|
609
|
-
|
|
598
|
+
align = 'top-right';
|
|
610
599
|
}
|
|
611
600
|
if (lockRatio) {
|
|
612
601
|
const unlockSide = lockRatio === 'corner' && direction % 2;
|
|
613
602
|
if (!unlockSide) {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
scaleY = scaleX;
|
|
603
|
+
const scale = Math.sqrt(Math.abs(scaleX * scaleY));
|
|
604
|
+
scaleX = scaleX < 0 ? -scale : scale;
|
|
605
|
+
scaleY = scaleY < 0 ? -scale : scale;
|
|
618
606
|
}
|
|
619
607
|
}
|
|
620
|
-
toPoint(around ||
|
|
608
|
+
toPoint(around || align, bounds, origin);
|
|
621
609
|
return { origin, scaleX, scaleY, direction, lockRatio, around };
|
|
622
610
|
},
|
|
623
611
|
getRotateData(bounds, direction, current, last, around) {
|
|
624
|
-
let origin;
|
|
612
|
+
let align, origin = {};
|
|
625
613
|
switch (direction) {
|
|
626
614
|
case topLeft:
|
|
627
|
-
|
|
615
|
+
align = 'bottom-right';
|
|
628
616
|
break;
|
|
629
617
|
case topRight:
|
|
630
|
-
|
|
618
|
+
align = 'bottom-left';
|
|
631
619
|
break;
|
|
632
620
|
case bottomRight:
|
|
633
|
-
|
|
621
|
+
align = 'top-left';
|
|
634
622
|
break;
|
|
635
623
|
case bottomLeft:
|
|
636
|
-
|
|
624
|
+
align = 'top-right';
|
|
637
625
|
break;
|
|
638
626
|
default:
|
|
639
|
-
|
|
627
|
+
align = 'center';
|
|
640
628
|
}
|
|
641
|
-
toPoint(around ||
|
|
629
|
+
toPoint(around || align, bounds, origin);
|
|
642
630
|
return { origin, rotation: PointHelper.getRotation(last, origin, current) };
|
|
643
631
|
},
|
|
644
632
|
getSkewData(bounds, direction, move, around) {
|
|
645
|
-
let origin, skewX = 0, skewY = 0;
|
|
633
|
+
let align, origin = {}, skewX = 0, skewY = 0;
|
|
646
634
|
let last;
|
|
647
635
|
switch (direction) {
|
|
648
636
|
case top:
|
|
649
637
|
last = { x: 0.5, y: 0 };
|
|
650
|
-
|
|
638
|
+
align = 'bottom';
|
|
651
639
|
skewX = 1;
|
|
652
640
|
break;
|
|
653
641
|
case bottom:
|
|
654
642
|
last = { x: 0.5, y: 1 };
|
|
655
|
-
|
|
643
|
+
align = 'top';
|
|
656
644
|
skewX = 1;
|
|
657
645
|
break;
|
|
658
646
|
case left$1:
|
|
659
647
|
last = { x: 0, y: 0.5 };
|
|
660
|
-
|
|
648
|
+
align = 'right';
|
|
661
649
|
skewY = 1;
|
|
662
650
|
break;
|
|
663
651
|
case right$1:
|
|
664
652
|
last = { x: 1, y: 0.5 };
|
|
665
|
-
|
|
653
|
+
align = 'left';
|
|
666
654
|
skewY = 1;
|
|
667
655
|
}
|
|
668
656
|
const { x, y, width, height } = bounds;
|
|
669
657
|
last.x = x + last.x * width;
|
|
670
658
|
last.y = y + last.y * height;
|
|
671
|
-
toPoint(around ||
|
|
659
|
+
toPoint(around || align, bounds, origin);
|
|
672
660
|
const rotation = PointHelper.getRotation(last, origin, { x: last.x + (skewX ? move.x : 0), y: last.y + (skewY ? move.y : 0) });
|
|
673
661
|
skewX ? skewX = -rotation : skewY = rotation;
|
|
674
662
|
return { origin, skewX, skewY };
|
|
@@ -734,12 +722,12 @@ const EditDataHelper = {
|
|
|
734
722
|
const cacheCursors = {};
|
|
735
723
|
function updateCursor(editor, e) {
|
|
736
724
|
const { editBox } = editor, point = editBox.enterPoint;
|
|
737
|
-
if (!point || !editor.
|
|
725
|
+
if (!point || !editor.editing || !editBox.visible)
|
|
738
726
|
return;
|
|
739
727
|
if (point.name === 'circle')
|
|
740
728
|
return;
|
|
741
729
|
let { rotation } = editBox;
|
|
742
|
-
const { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editor.
|
|
730
|
+
const { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editor.mergeConfig;
|
|
743
731
|
const { pointType } = point, { flippedX, flippedY } = editBox;
|
|
744
732
|
let showResize = pointType === 'resize';
|
|
745
733
|
if (showResize && rotateable && (e.metaKey || e.ctrlKey || !resizeable))
|
|
@@ -758,7 +746,7 @@ function updateCursor(editor, e) {
|
|
|
758
746
|
}
|
|
759
747
|
}
|
|
760
748
|
function updateMoveCursor(editor) {
|
|
761
|
-
editor.editBox.rect.cursor = editor.
|
|
749
|
+
editor.editBox.rect.cursor = editor.mergeConfig.moveCursor;
|
|
762
750
|
}
|
|
763
751
|
function toDataURL(svg, rotation) {
|
|
764
752
|
return '"data:image/svg+xml,' + encodeURIComponent(svg.replace('{{rotation}}', rotation.toString())) + '"';
|
|
@@ -775,6 +763,7 @@ class EditBox extends Group {
|
|
|
775
763
|
get flippedOne() { return this.scaleX * this.scaleY < 0; }
|
|
776
764
|
constructor(editor) {
|
|
777
765
|
super();
|
|
766
|
+
this.view = new Group();
|
|
778
767
|
this.rect = new Box({ name: 'rect', hitFill: 'all', hitStroke: 'none', strokeAlign: 'center', hitRadius: 5 });
|
|
779
768
|
this.circle = new EditPoint({ name: 'circle', strokeAlign: 'center', around: 'center', cursor: 'crosshair', hitRadius: 5 });
|
|
780
769
|
this.buttons = new Group({ around: 'center', hitSelf: false });
|
|
@@ -789,8 +778,8 @@ class EditBox extends Group {
|
|
|
789
778
|
}
|
|
790
779
|
create() {
|
|
791
780
|
let rotatePoint, resizeLine, resizePoint;
|
|
792
|
-
const { resizePoints, rotatePoints, resizeLines, rect, circle, buttons } = this;
|
|
793
|
-
const arounds = [
|
|
781
|
+
const { view, resizePoints, rotatePoints, resizeLines, rect, circle, buttons } = this;
|
|
782
|
+
const arounds = ['bottom-right', 'bottom', 'bottom-left', 'left', 'top-left', 'top', 'top-right', 'right'];
|
|
794
783
|
for (let i = 0; i < 8; i++) {
|
|
795
784
|
rotatePoint = new EditPoint({ name: 'rotate-point', around: arounds[i], width: 15, height: 15, hitFill: "all" });
|
|
796
785
|
rotatePoints.push(rotatePoint);
|
|
@@ -800,62 +789,80 @@ class EditBox extends Group {
|
|
|
800
789
|
resizeLines.push(resizeLine);
|
|
801
790
|
this.listenPointEvents(resizeLine, 'resize', i);
|
|
802
791
|
}
|
|
803
|
-
resizePoint = new EditPoint({ name: 'resize-point',
|
|
792
|
+
resizePoint = new EditPoint({ name: 'resize-point', hitRadius: 5 });
|
|
804
793
|
resizePoints.push(resizePoint);
|
|
805
794
|
this.listenPointEvents(resizePoint, 'resize', i);
|
|
806
795
|
}
|
|
807
796
|
buttons.add(circle);
|
|
808
797
|
this.listenPointEvents(circle, 'rotate', 2);
|
|
809
|
-
|
|
798
|
+
view.addMany(...rotatePoints, rect, buttons, ...resizeLines, ...resizePoints);
|
|
799
|
+
this.add(view);
|
|
810
800
|
}
|
|
811
|
-
|
|
812
|
-
const {
|
|
813
|
-
const {
|
|
814
|
-
const {
|
|
815
|
-
const { middlePoint, resizeable, rotateable, stroke, strokeWidth, hideOnSmall } = config;
|
|
801
|
+
load() {
|
|
802
|
+
const { mergeConfig, element, single } = this.editor;
|
|
803
|
+
const { rect, circle, resizePoints } = this;
|
|
804
|
+
const { stroke, strokeWidth, moveable } = mergeConfig;
|
|
816
805
|
const pointsStyle = this.getPointsStyle();
|
|
817
806
|
const middlePointsStyle = this.getMiddlePointsStyle();
|
|
818
|
-
|
|
819
|
-
const showPoints = !(hideOnSmall && width < smallSize && height < smallSize);
|
|
820
|
-
this.visible = list[0] && !list[0].locked;
|
|
821
|
-
let point = {}, style, rotateP, resizeP, resizeL;
|
|
807
|
+
let resizeP;
|
|
822
808
|
for (let i = 0; i < 8; i++) {
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
resizeP.set(style);
|
|
827
|
-
resizeP.set(point), rotateP.set(point), resizeL.set(point);
|
|
828
|
-
resizeP.visible = resizeL.visible = showPoints && (resizeable || rotateable);
|
|
829
|
-
rotateP.visible = showPoints && rotateable && resizeable && !config.rotatePoint;
|
|
830
|
-
if (i % 2) {
|
|
831
|
-
resizeP.visible = rotateP.visible = showPoints && !!middlePoint;
|
|
832
|
-
if (((i + 1) / 2) % 2) {
|
|
833
|
-
resizeL.width = width;
|
|
834
|
-
if (resizeP.width > width - 30)
|
|
835
|
-
resizeP.visible = false;
|
|
836
|
-
}
|
|
837
|
-
else {
|
|
838
|
-
resizeL.height = height;
|
|
839
|
-
resizeP.rotation = 90;
|
|
840
|
-
if (resizeP.width > height - 30)
|
|
841
|
-
resizeP.visible = false;
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
else {
|
|
809
|
+
resizeP = resizePoints[i];
|
|
810
|
+
resizeP.set(this.getPointStyle((i % 2) ? middlePointsStyle[((i - 1) / 2) % middlePointsStyle.length] : pointsStyle[(i / 2) % pointsStyle.length]));
|
|
811
|
+
if (!(i % 2))
|
|
845
812
|
resizeP.rotation = (i / 2) * 90;
|
|
813
|
+
}
|
|
814
|
+
circle.set(this.getPointStyle(mergeConfig.rotatePoint || pointsStyle[0]));
|
|
815
|
+
rect.set(Object.assign({ stroke, strokeWidth }, (mergeConfig.rect || {})));
|
|
816
|
+
rect.hittable = !single && moveable;
|
|
817
|
+
element.syncEventer = (single && moveable) ? rect : null;
|
|
818
|
+
this.app.interaction.bottomList = (single && moveable) ? [{ target: rect, proxy: element }] : null;
|
|
819
|
+
this.visible = !element.locked;
|
|
820
|
+
}
|
|
821
|
+
update(bounds) {
|
|
822
|
+
if (this.view.worldOpacity) {
|
|
823
|
+
const { mergeConfig } = this.editor;
|
|
824
|
+
const { width, height } = bounds;
|
|
825
|
+
const { rect, circle, resizePoints, rotatePoints, resizeLines } = this;
|
|
826
|
+
const { middlePoint, resizeable, rotateable, hideOnSmall } = mergeConfig;
|
|
827
|
+
const smallSize = typeof hideOnSmall === 'number' ? hideOnSmall : 10;
|
|
828
|
+
const showPoints = !(hideOnSmall && width < smallSize && height < smallSize);
|
|
829
|
+
let point = {}, rotateP, resizeP, resizeL;
|
|
830
|
+
for (let i = 0; i < 8; i++) {
|
|
831
|
+
AroundHelper.toPoint(AroundHelper.directionData[i], bounds, point);
|
|
832
|
+
resizeP = resizePoints[i];
|
|
833
|
+
rotateP = rotatePoints[i];
|
|
834
|
+
resizeL = resizeLines[Math.floor(i / 2)];
|
|
835
|
+
resizeP.set(point);
|
|
836
|
+
rotateP.set(point);
|
|
837
|
+
resizeL.set(point);
|
|
838
|
+
resizeP.visible = resizeL.visible = showPoints && (resizeable || rotateable);
|
|
839
|
+
rotateP.visible = showPoints && rotateable && resizeable && !mergeConfig.rotatePoint;
|
|
840
|
+
if (i % 2) {
|
|
841
|
+
resizeP.visible = rotateP.visible = showPoints && !!middlePoint;
|
|
842
|
+
if (((i + 1) / 2) % 2) {
|
|
843
|
+
resizeL.width = width;
|
|
844
|
+
if (resizeP.width > width - 30)
|
|
845
|
+
resizeP.visible = false;
|
|
846
|
+
}
|
|
847
|
+
else {
|
|
848
|
+
resizeL.height = height;
|
|
849
|
+
resizeP.rotation = 90;
|
|
850
|
+
if (resizeP.width > height - 30)
|
|
851
|
+
resizeP.visible = false;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
846
854
|
}
|
|
855
|
+
circle.visible = showPoints && rotateable && !!mergeConfig.rotatePoint;
|
|
856
|
+
rect.set(Object.assign(Object.assign({}, bounds), { visible: true }));
|
|
857
|
+
const buttonVisible = showPoints && (circle.visible || this.buttons.children.length > 1);
|
|
858
|
+
this.buttons.visible = buttonVisible;
|
|
859
|
+
if (buttonVisible)
|
|
860
|
+
this.layoutButtons();
|
|
847
861
|
}
|
|
848
|
-
circle.visible = showPoints && rotateable && !!config.rotatePoint;
|
|
849
|
-
circle.set(this.getPointStyle(config.rotatePoint || pointsStyle[0]));
|
|
850
|
-
rect.set(Object.assign({ stroke, strokeWidth }, (config.rect || {})));
|
|
851
|
-
rect.set(Object.assign(Object.assign({}, bounds), { visible: true }));
|
|
852
|
-
rect.hittable = config.moveable;
|
|
853
|
-
this.buttons.visible = showPoints;
|
|
854
|
-
this.layoutButtons();
|
|
855
862
|
}
|
|
856
863
|
layoutButtons() {
|
|
857
864
|
const { buttons, resizePoints } = this;
|
|
858
|
-
const { buttonsDirection, buttonsFixed, buttonsMargin, middlePoint } = this.editor.
|
|
865
|
+
const { buttonsDirection, buttonsFixed, buttonsMargin, middlePoint } = this.editor.mergeConfig;
|
|
859
866
|
const { flippedX, flippedY } = this;
|
|
860
867
|
let index = fourDirection.indexOf(buttonsDirection);
|
|
861
868
|
if ((index % 2 && flippedX) || ((index + 1) % 2 && flippedY)) {
|
|
@@ -882,37 +889,46 @@ class EditBox extends Group {
|
|
|
882
889
|
buttons.scaleY = flippedY ? -1 : 1;
|
|
883
890
|
}
|
|
884
891
|
}
|
|
892
|
+
unload() {
|
|
893
|
+
this.visible = false;
|
|
894
|
+
}
|
|
885
895
|
getPointStyle(userStyle) {
|
|
886
|
-
const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.editor.
|
|
887
|
-
const defaultStyle = { fill: pointFill, stroke, strokeWidth, width: pointSize, height: pointSize, cornerRadius: pointRadius };
|
|
896
|
+
const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.editor.mergeConfig;
|
|
897
|
+
const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', width: pointSize, height: pointSize, cornerRadius: pointRadius };
|
|
888
898
|
return userStyle ? Object.assign(defaultStyle, userStyle) : defaultStyle;
|
|
889
899
|
}
|
|
890
900
|
getPointsStyle() {
|
|
891
|
-
const { point } = this.editor.
|
|
901
|
+
const { point } = this.editor.mergeConfig;
|
|
892
902
|
return point instanceof Array ? point : [point];
|
|
893
903
|
}
|
|
894
904
|
getMiddlePointsStyle() {
|
|
895
|
-
const { middlePoint } = this.editor.
|
|
905
|
+
const { middlePoint } = this.editor.mergeConfig;
|
|
896
906
|
return middlePoint instanceof Array ? middlePoint : (middlePoint ? [middlePoint] : this.getPointsStyle());
|
|
897
907
|
}
|
|
908
|
+
onSelect(e) {
|
|
909
|
+
if (e.oldList.length === 1)
|
|
910
|
+
e.oldList[0].syncEventer = this.app.interaction.bottomList = null;
|
|
911
|
+
}
|
|
898
912
|
onDragStart(e) {
|
|
899
913
|
this.dragging = true;
|
|
900
|
-
if (e.
|
|
914
|
+
if (e.current.name === 'rect') {
|
|
915
|
+
const { editor } = this;
|
|
901
916
|
this.moving = true;
|
|
902
|
-
|
|
917
|
+
editor.dragStartPoint = { x: editor.element.x, y: editor.element.y };
|
|
918
|
+
editor.opacity = editor.mergeConfig.hideOnMove ? 0 : 1;
|
|
903
919
|
}
|
|
904
920
|
}
|
|
905
921
|
onDragEnd(e) {
|
|
906
922
|
this.dragging = false;
|
|
907
923
|
this.moving = false;
|
|
908
|
-
if (e.
|
|
924
|
+
if (e.current.name === 'rect')
|
|
909
925
|
this.editor.opacity = 1;
|
|
910
926
|
}
|
|
911
927
|
onDrag(e) {
|
|
912
928
|
const { editor } = this;
|
|
913
929
|
const point = this.enterPoint = e.current;
|
|
914
|
-
if (point.pointType === 'rotate' || e.metaKey || e.ctrlKey || !editor.
|
|
915
|
-
if (editor.
|
|
930
|
+
if (point.pointType === 'rotate' || e.metaKey || e.ctrlKey || !editor.mergeConfig.resizeable) {
|
|
931
|
+
if (editor.mergeConfig.rotateable)
|
|
916
932
|
editor.onRotate(e);
|
|
917
933
|
}
|
|
918
934
|
else {
|
|
@@ -921,7 +937,7 @@ class EditBox extends Group {
|
|
|
921
937
|
updateCursor(editor, e);
|
|
922
938
|
}
|
|
923
939
|
onArrow(e) {
|
|
924
|
-
if (this.editor.
|
|
940
|
+
if (this.editor.editing && this.editor.mergeConfig.keyEvent) {
|
|
925
941
|
const move = { x: 0, y: 0 };
|
|
926
942
|
const distance = e.shiftKey ? 10 : 1;
|
|
927
943
|
switch (e.code) {
|
|
@@ -937,13 +953,29 @@ class EditBox extends Group {
|
|
|
937
953
|
case 'ArrowRight':
|
|
938
954
|
move.x = distance;
|
|
939
955
|
}
|
|
940
|
-
|
|
941
|
-
this.editor.move(move.x, move.y);
|
|
956
|
+
this.editor.move(move);
|
|
942
957
|
}
|
|
943
958
|
}
|
|
944
|
-
|
|
959
|
+
onDoubleTap(e) {
|
|
960
|
+
if (this.editor.mergeConfig.openInner === 'double')
|
|
961
|
+
this.openInner(e);
|
|
962
|
+
}
|
|
963
|
+
onLongPress(e) {
|
|
964
|
+
if (this.editor.mergeConfig.openInner === 'long')
|
|
965
|
+
this.openInner(e);
|
|
966
|
+
}
|
|
967
|
+
openInner(e) {
|
|
945
968
|
const { editor } = this;
|
|
946
|
-
if (editor.single
|
|
969
|
+
if (editor.single) {
|
|
970
|
+
const { element } = editor;
|
|
971
|
+
if (element.isBranch) {
|
|
972
|
+
editor.openGroup(element);
|
|
973
|
+
editor.target = editor.selector.findDeepOne(e);
|
|
974
|
+
}
|
|
975
|
+
else {
|
|
976
|
+
editor.openInnerEditor();
|
|
977
|
+
}
|
|
978
|
+
}
|
|
947
979
|
}
|
|
948
980
|
listenPointEvents(point, type, direction) {
|
|
949
981
|
const { editor } = this;
|
|
@@ -959,12 +991,13 @@ class EditBox extends Group {
|
|
|
959
991
|
__listenEvents() {
|
|
960
992
|
const { rect, editor } = this;
|
|
961
993
|
this.__eventIds = [
|
|
962
|
-
editor.on_(EditorEvent.SELECT,
|
|
994
|
+
editor.on_(EditorEvent.SELECT, this.onSelect, this),
|
|
963
995
|
rect.on_(DragEvent.START, this.onDragStart, this),
|
|
964
996
|
rect.on_(DragEvent.DRAG, editor.onMove, editor),
|
|
965
997
|
rect.on_(DragEvent.END, this.onDragEnd, this),
|
|
966
998
|
rect.on_(PointerEvent.ENTER, () => updateMoveCursor(editor)),
|
|
967
|
-
rect.on_(PointerEvent.
|
|
999
|
+
rect.on_(PointerEvent.DOUBLE_TAP, this.onDoubleTap, this),
|
|
1000
|
+
rect.on_(PointerEvent.LONG_PRESS, this.onLongPress, this)
|
|
968
1001
|
];
|
|
969
1002
|
}
|
|
970
1003
|
__removeListenEvents() {
|
|
@@ -1030,7 +1063,7 @@ ${filterStyle}
|
|
|
1030
1063
|
`;
|
|
1031
1064
|
|
|
1032
1065
|
const config = {
|
|
1033
|
-
editSize: '
|
|
1066
|
+
editSize: 'size',
|
|
1034
1067
|
keyEvent: true,
|
|
1035
1068
|
stroke: '#836DFF',
|
|
1036
1069
|
strokeWidth: 2,
|
|
@@ -1048,6 +1081,7 @@ const config = {
|
|
|
1048
1081
|
selector: true,
|
|
1049
1082
|
hover: true,
|
|
1050
1083
|
select: 'press',
|
|
1084
|
+
openInner: 'double',
|
|
1051
1085
|
boxSelect: true,
|
|
1052
1086
|
moveable: true,
|
|
1053
1087
|
resizeable: true,
|
|
@@ -1055,148 +1089,6 @@ const config = {
|
|
|
1055
1089
|
skewable: true
|
|
1056
1090
|
};
|
|
1057
1091
|
|
|
1058
|
-
class EditTool {
|
|
1059
|
-
constructor() {
|
|
1060
|
-
this.tag = 'EditTool';
|
|
1061
|
-
}
|
|
1062
|
-
onMove(e) {
|
|
1063
|
-
const { moveX, moveY, editor } = e;
|
|
1064
|
-
const { app, list } = editor;
|
|
1065
|
-
app.lockLayout();
|
|
1066
|
-
list.forEach(target => {
|
|
1067
|
-
target.moveWorld(moveX, moveY);
|
|
1068
|
-
});
|
|
1069
|
-
app.unlockLayout();
|
|
1070
|
-
}
|
|
1071
|
-
onScale(e) {
|
|
1072
|
-
const { scaleX, scaleY, transform, worldOrigin, editor } = e;
|
|
1073
|
-
const { app, list } = editor;
|
|
1074
|
-
app.lockLayout();
|
|
1075
|
-
list.forEach(target => {
|
|
1076
|
-
const resize = editor.getEditSize(target) === 'size';
|
|
1077
|
-
if (transform) {
|
|
1078
|
-
target.transformWorld(transform, resize);
|
|
1079
|
-
}
|
|
1080
|
-
else {
|
|
1081
|
-
target.scaleOfWorld(worldOrigin, scaleX, scaleY, resize);
|
|
1082
|
-
}
|
|
1083
|
-
});
|
|
1084
|
-
app.unlockLayout();
|
|
1085
|
-
}
|
|
1086
|
-
onRotate(e) {
|
|
1087
|
-
const { rotation, transform, worldOrigin, editor } = e;
|
|
1088
|
-
const { app, list } = editor;
|
|
1089
|
-
app.lockLayout();
|
|
1090
|
-
list.forEach(target => {
|
|
1091
|
-
const resize = editor.getEditSize(target) === 'size';
|
|
1092
|
-
if (transform) {
|
|
1093
|
-
target.transformWorld(transform, resize);
|
|
1094
|
-
}
|
|
1095
|
-
else {
|
|
1096
|
-
target.rotateOfWorld(worldOrigin, rotation);
|
|
1097
|
-
}
|
|
1098
|
-
});
|
|
1099
|
-
app.unlockLayout();
|
|
1100
|
-
}
|
|
1101
|
-
onSkew(e) {
|
|
1102
|
-
const { skewX, skewY, transform, worldOrigin, editor } = e;
|
|
1103
|
-
const { app, list } = editor;
|
|
1104
|
-
app.lockLayout();
|
|
1105
|
-
list.forEach(target => {
|
|
1106
|
-
const resize = editor.getEditSize(target) === 'size';
|
|
1107
|
-
if (transform) {
|
|
1108
|
-
target.transformWorld(transform, resize);
|
|
1109
|
-
}
|
|
1110
|
-
else {
|
|
1111
|
-
target.skewOfWorld(worldOrigin, skewX, skewY, resize);
|
|
1112
|
-
}
|
|
1113
|
-
});
|
|
1114
|
-
app.unlockLayout();
|
|
1115
|
-
}
|
|
1116
|
-
update(editor) {
|
|
1117
|
-
const { simulateTarget, element } = editor;
|
|
1118
|
-
if (editor.multiple)
|
|
1119
|
-
simulateTarget.parent.updateLayout();
|
|
1120
|
-
const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = element.getLayoutBounds('box', editor, true);
|
|
1121
|
-
editor.editBox.set({ x, y, scaleX, scaleY, rotation, skewX, skewY });
|
|
1122
|
-
editor.editBox.update({ x: 0, y: 0, width, height });
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
EditTool.list = [];
|
|
1126
|
-
|
|
1127
|
-
const { left, right } = IDirection8;
|
|
1128
|
-
class LineEditTool extends EditTool {
|
|
1129
|
-
constructor() {
|
|
1130
|
-
super(...arguments);
|
|
1131
|
-
this.tag = 'LineEditTool';
|
|
1132
|
-
this.scaleOfEvent = true;
|
|
1133
|
-
}
|
|
1134
|
-
onScaleWithDrag(e) {
|
|
1135
|
-
const { drag, direction, lockRatio, around } = e;
|
|
1136
|
-
const target = e.target;
|
|
1137
|
-
const fromPoint = getPointData();
|
|
1138
|
-
const { toPoint } = target;
|
|
1139
|
-
target.rotation = 0;
|
|
1140
|
-
let { x, y } = drag.getInnerMove(target);
|
|
1141
|
-
if (lockRatio) {
|
|
1142
|
-
if (Math.abs(x) > Math.abs(y)) {
|
|
1143
|
-
y = 0;
|
|
1144
|
-
}
|
|
1145
|
-
else {
|
|
1146
|
-
x = 0;
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
if (direction === left) {
|
|
1150
|
-
fromPoint.x += x;
|
|
1151
|
-
fromPoint.y += y;
|
|
1152
|
-
if (around) {
|
|
1153
|
-
toPoint.x -= x;
|
|
1154
|
-
toPoint.y -= y;
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1157
|
-
else {
|
|
1158
|
-
if (around) {
|
|
1159
|
-
fromPoint.x -= x;
|
|
1160
|
-
fromPoint.y -= y;
|
|
1161
|
-
}
|
|
1162
|
-
toPoint.x += x;
|
|
1163
|
-
toPoint.y += y;
|
|
1164
|
-
}
|
|
1165
|
-
target.getLocalPointByInner(fromPoint, null, null, true);
|
|
1166
|
-
target.getLocalPointByInner(toPoint, null, null, true);
|
|
1167
|
-
target.x = fromPoint.x;
|
|
1168
|
-
target.y = fromPoint.y;
|
|
1169
|
-
target.getInnerPointByLocal(toPoint, null, null, true);
|
|
1170
|
-
target.toPoint = toPoint;
|
|
1171
|
-
}
|
|
1172
|
-
onSkew(_e) {
|
|
1173
|
-
}
|
|
1174
|
-
update(editor) {
|
|
1175
|
-
const { rotatePoints, resizeLines, resizePoints } = editor.editBox;
|
|
1176
|
-
super.update(editor);
|
|
1177
|
-
for (let i = 0; i < 8; i++) {
|
|
1178
|
-
if (i < 4)
|
|
1179
|
-
resizeLines[i].visible = false;
|
|
1180
|
-
resizePoints[i].visible = rotatePoints[i].visible = (i === left || i === right);
|
|
1181
|
-
}
|
|
1182
|
-
}
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
function getEditTool(list) {
|
|
1186
|
-
if (list.length === 1) {
|
|
1187
|
-
const leaf = list[0];
|
|
1188
|
-
if (leaf instanceof Line && !leaf.points) {
|
|
1189
|
-
return new LineEditTool();
|
|
1190
|
-
}
|
|
1191
|
-
else {
|
|
1192
|
-
return new EditTool();
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
else {
|
|
1196
|
-
return new EditTool();
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
|
|
1200
1092
|
function simulate(editor) {
|
|
1201
1093
|
const { simulateTarget, leafList: targetList } = editor;
|
|
1202
1094
|
const { x, y, width, height } = new Bounds().setListWithFn(targetList.list, (leaf) => leaf.worldBoxBounds);
|
|
@@ -1214,7 +1106,8 @@ function onTarget(editor, oldValue) {
|
|
|
1214
1106
|
editor.leafList.reset();
|
|
1215
1107
|
}
|
|
1216
1108
|
editor.emitEvent(new EditorEvent(EditorEvent.SELECT, { editor, value: target, oldValue }));
|
|
1217
|
-
|
|
1109
|
+
editor.checkOpenedGroups();
|
|
1110
|
+
if (editor.editing) {
|
|
1218
1111
|
editor.waitLeafer(() => {
|
|
1219
1112
|
if (editor.multiple)
|
|
1220
1113
|
simulate(editor);
|
|
@@ -1225,6 +1118,7 @@ function onTarget(editor, oldValue) {
|
|
|
1225
1118
|
});
|
|
1226
1119
|
}
|
|
1227
1120
|
else {
|
|
1121
|
+
editor.updateEditTool();
|
|
1228
1122
|
editor.removeTargetEvents();
|
|
1229
1123
|
}
|
|
1230
1124
|
}
|
|
@@ -1293,26 +1187,55 @@ const EditorHelper = {
|
|
|
1293
1187
|
}
|
|
1294
1188
|
};
|
|
1295
1189
|
|
|
1190
|
+
const debug = Debug.get('EditToolCreator');
|
|
1191
|
+
function registerEditTool() {
|
|
1192
|
+
return (target) => {
|
|
1193
|
+
EditToolCreator.register(target);
|
|
1194
|
+
};
|
|
1195
|
+
}
|
|
1196
|
+
const registerInnerEditor = registerEditTool;
|
|
1197
|
+
const EditToolCreator = {
|
|
1198
|
+
list: {},
|
|
1199
|
+
register(EditTool) {
|
|
1200
|
+
const { tag } = EditTool.prototype;
|
|
1201
|
+
list[tag] ? debug.repeat(tag) : (list[tag] = EditTool);
|
|
1202
|
+
},
|
|
1203
|
+
get(tag, editor) {
|
|
1204
|
+
return new list[tag](editor);
|
|
1205
|
+
}
|
|
1206
|
+
};
|
|
1207
|
+
const { list } = EditToolCreator;
|
|
1208
|
+
|
|
1296
1209
|
class Editor extends Group {
|
|
1297
1210
|
get list() { return this.leafList.list; }
|
|
1298
|
-
get
|
|
1211
|
+
get editing() { return !!this.list.length; }
|
|
1212
|
+
get groupOpening() { return !!this.openedGroupList.length; }
|
|
1299
1213
|
get multiple() { return this.list.length > 1; }
|
|
1300
1214
|
get single() { return this.list.length === 1; }
|
|
1215
|
+
get dragging() { return this.editBox.dragging; }
|
|
1301
1216
|
get element() { return this.multiple ? this.simulateTarget : this.list[0]; }
|
|
1302
1217
|
get buttons() { return this.editBox.buttons; }
|
|
1303
|
-
get dragging() { return this.editBox.dragging; }
|
|
1304
1218
|
constructor(userConfig, data) {
|
|
1305
1219
|
super(data);
|
|
1306
1220
|
this.config = config;
|
|
1221
|
+
this.mergeConfig = config;
|
|
1307
1222
|
this.leafList = new LeafList();
|
|
1223
|
+
this.openedGroupList = new LeafList();
|
|
1308
1224
|
this.simulateTarget = new Rect({ visible: false });
|
|
1309
1225
|
this.editBox = new EditBox(this);
|
|
1226
|
+
this.editToolList = {};
|
|
1310
1227
|
this.selector = new EditSelect(this);
|
|
1311
1228
|
this.targetEventIds = [];
|
|
1312
1229
|
if (userConfig)
|
|
1313
1230
|
this.config = DataHelper.default(userConfig, this.config);
|
|
1314
1231
|
this.addMany(this.selector, this.editBox);
|
|
1315
1232
|
}
|
|
1233
|
+
select(target) {
|
|
1234
|
+
this.target = target;
|
|
1235
|
+
}
|
|
1236
|
+
cancel() {
|
|
1237
|
+
this.target = null;
|
|
1238
|
+
}
|
|
1316
1239
|
hasItem(item) {
|
|
1317
1240
|
return this.leafList.has(item);
|
|
1318
1241
|
}
|
|
@@ -1328,38 +1251,46 @@ class Editor extends Group {
|
|
|
1328
1251
|
this.hasItem(item) ? this.removeItem(item) : this.addItem(item);
|
|
1329
1252
|
}
|
|
1330
1253
|
update() {
|
|
1331
|
-
if (this.
|
|
1332
|
-
if (this.
|
|
1333
|
-
this.
|
|
1254
|
+
if (this.editing) {
|
|
1255
|
+
if (this.innerEditing)
|
|
1256
|
+
this.innerEditor.update();
|
|
1257
|
+
this.editTool.update();
|
|
1334
1258
|
this.selector.update();
|
|
1335
1259
|
}
|
|
1336
1260
|
}
|
|
1337
1261
|
updateEditTool() {
|
|
1338
|
-
|
|
1262
|
+
const tool = this.editTool;
|
|
1263
|
+
if (tool) {
|
|
1264
|
+
this.editBox.unload();
|
|
1265
|
+
tool.unload();
|
|
1266
|
+
this.editTool = null;
|
|
1267
|
+
}
|
|
1268
|
+
if (this.editing) {
|
|
1269
|
+
const tag = this.single ? this.list[0].editOuter : 'EditTool';
|
|
1270
|
+
this.editTool = this.editToolList[tag] = this.editToolList[tag] || EditToolCreator.get(tag, this);
|
|
1271
|
+
const { editConfig } = this.element;
|
|
1272
|
+
this.mergeConfig = this.single && editConfig ? Object.assign(Object.assign({}, this.mergeConfig), editConfig) : this.config;
|
|
1273
|
+
this.editBox.load();
|
|
1274
|
+
this.editTool.load();
|
|
1275
|
+
}
|
|
1339
1276
|
}
|
|
1340
|
-
getEditSize(
|
|
1341
|
-
|
|
1342
|
-
return editSize === 'auto' ? ui.editSize : editSize;
|
|
1277
|
+
getEditSize(_ui) {
|
|
1278
|
+
return this.mergeConfig.editSize;
|
|
1343
1279
|
}
|
|
1344
1280
|
onMove(e) {
|
|
1345
|
-
const
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
else if (lockMove === 'y')
|
|
1350
|
-
move.x = 0;
|
|
1351
|
-
else if (e.shiftKey) {
|
|
1352
|
-
if (Math.abs(move.x) > Math.abs(move.y))
|
|
1353
|
-
move.y = 0;
|
|
1281
|
+
const total = { x: e.totalX, y: e.totalY };
|
|
1282
|
+
if (e.shiftKey) {
|
|
1283
|
+
if (Math.abs(total.x) > Math.abs(total.y))
|
|
1284
|
+
total.y = 0;
|
|
1354
1285
|
else
|
|
1355
|
-
|
|
1286
|
+
total.x = 0;
|
|
1356
1287
|
}
|
|
1357
|
-
this.move(
|
|
1288
|
+
this.move(DragEvent.getValidMove(this.element, this.dragStartPoint, total));
|
|
1358
1289
|
}
|
|
1359
1290
|
onScale(e) {
|
|
1360
1291
|
const { element } = this;
|
|
1361
1292
|
const { direction } = e.current;
|
|
1362
|
-
let { around, lockRatio } = this.
|
|
1293
|
+
let { around, lockRatio } = this.mergeConfig;
|
|
1363
1294
|
if (e.shiftKey)
|
|
1364
1295
|
lockRatio = true;
|
|
1365
1296
|
const data = EditDataHelper.getScaleData(element.boxBounds, direction, e.getInnerMove(element), lockRatio, EditDataHelper.getAround(around, e.altKey));
|
|
@@ -1372,7 +1303,7 @@ class Editor extends Group {
|
|
|
1372
1303
|
}
|
|
1373
1304
|
}
|
|
1374
1305
|
onRotate(e) {
|
|
1375
|
-
const { skewable, around, rotateGap } = this.
|
|
1306
|
+
const { skewable, around, rotateGap } = this.mergeConfig;
|
|
1376
1307
|
const { direction, name } = e.current;
|
|
1377
1308
|
if (skewable && name === 'resize-line')
|
|
1378
1309
|
return this.onSkew(e);
|
|
@@ -1396,17 +1327,17 @@ class Editor extends Group {
|
|
|
1396
1327
|
}
|
|
1397
1328
|
onSkew(e) {
|
|
1398
1329
|
const { element } = this;
|
|
1399
|
-
const { around } = this.
|
|
1330
|
+
const { around } = this.mergeConfig;
|
|
1400
1331
|
const { origin, skewX, skewY } = EditDataHelper.getSkewData(element.boxBounds, e.current.direction, e.getInnerMove(element), EditDataHelper.getAround(around, e.altKey));
|
|
1401
1332
|
if (!skewX && !skewY)
|
|
1402
1333
|
return;
|
|
1403
1334
|
this.skewOf(origin, skewX, skewY);
|
|
1404
1335
|
}
|
|
1405
|
-
move(x, y) {
|
|
1406
|
-
if (!this.
|
|
1336
|
+
move(x, y = 0) {
|
|
1337
|
+
if (!this.mergeConfig.moveable || this.element.locked)
|
|
1407
1338
|
return;
|
|
1408
1339
|
const { element } = this;
|
|
1409
|
-
const world = element.getWorldPointByLocal({ x, y }, null, true);
|
|
1340
|
+
const world = element.getWorldPointByLocal(typeof x === 'object' ? Object.assign({}, x) : { x, y }, null, true);
|
|
1410
1341
|
const event = new EditorMoveEvent(EditorMoveEvent.MOVE, { target: element, editor: this, moveX: world.x, moveY: world.y });
|
|
1411
1342
|
this.editTool.onMove(event);
|
|
1412
1343
|
this.emitEvent(event);
|
|
@@ -1471,6 +1402,44 @@ class Editor extends Group {
|
|
|
1471
1402
|
this.target = EditorHelper.ungroup(this.list);
|
|
1472
1403
|
return this.list;
|
|
1473
1404
|
}
|
|
1405
|
+
openGroup(group) {
|
|
1406
|
+
this.openedGroupList.add(group);
|
|
1407
|
+
group.hitChildren = true;
|
|
1408
|
+
}
|
|
1409
|
+
closeGroup(group) {
|
|
1410
|
+
this.openedGroupList.remove(group);
|
|
1411
|
+
group.hitChildren = false;
|
|
1412
|
+
}
|
|
1413
|
+
checkOpenedGroups() {
|
|
1414
|
+
const opened = this.openedGroupList;
|
|
1415
|
+
if (opened.length) {
|
|
1416
|
+
let { list } = opened;
|
|
1417
|
+
if (this.editing)
|
|
1418
|
+
list = [], opened.forEach(item => this.list.every(leaf => !LeafHelper.hasParent(leaf, item)) && list.push(item));
|
|
1419
|
+
list.forEach(item => this.closeGroup(item));
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
openInnerEditor() {
|
|
1423
|
+
if (this.single) {
|
|
1424
|
+
const tag = this.element.editInner;
|
|
1425
|
+
if (tag) {
|
|
1426
|
+
if (EditToolCreator.list[tag]) {
|
|
1427
|
+
this.editTool.unload();
|
|
1428
|
+
this.innerEditing = true;
|
|
1429
|
+
this.innerEditor = this.editToolList[tag] || EditToolCreator.get(tag, this);
|
|
1430
|
+
this.innerEditor.load();
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
closeInnerEditor() {
|
|
1436
|
+
if (this.innerEditing) {
|
|
1437
|
+
this.innerEditing = false;
|
|
1438
|
+
this.innerEditor.unload();
|
|
1439
|
+
this.editTool.load();
|
|
1440
|
+
this.innerEditor = null;
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1474
1443
|
lock() {
|
|
1475
1444
|
this.list.forEach(leaf => leaf.locked = true);
|
|
1476
1445
|
this.update();
|
|
@@ -1511,7 +1480,9 @@ class Editor extends Group {
|
|
|
1511
1480
|
destroy() {
|
|
1512
1481
|
if (!this.destroyed) {
|
|
1513
1482
|
this.simulateTarget.destroy();
|
|
1514
|
-
|
|
1483
|
+
Object.values(this.editToolList).forEach(item => item.destroy());
|
|
1484
|
+
this.editToolList = {};
|
|
1485
|
+
this.target = this.hoverTarget = this.simulateTarget = this.editTool = this.innerEditor = null;
|
|
1515
1486
|
super.destroy();
|
|
1516
1487
|
}
|
|
1517
1488
|
}
|
|
@@ -1523,8 +1494,206 @@ __decorate([
|
|
|
1523
1494
|
targetAttr(onTarget)
|
|
1524
1495
|
], Editor.prototype, "target", void 0);
|
|
1525
1496
|
|
|
1526
|
-
|
|
1527
|
-
|
|
1497
|
+
class InnerEditor {
|
|
1498
|
+
static registerInnerEditor() {
|
|
1499
|
+
EditToolCreator.register(this);
|
|
1500
|
+
}
|
|
1501
|
+
get tag() { return 'InnerEditor'; }
|
|
1502
|
+
get editBox() { return this.editor.editBox; }
|
|
1503
|
+
constructor(editor) {
|
|
1504
|
+
this.editor = editor;
|
|
1505
|
+
this.create();
|
|
1506
|
+
}
|
|
1507
|
+
onCreate() { }
|
|
1508
|
+
create() {
|
|
1509
|
+
this.view = new Group();
|
|
1510
|
+
this.onCreate();
|
|
1511
|
+
}
|
|
1512
|
+
onLoad() { }
|
|
1513
|
+
load() {
|
|
1514
|
+
this.editor.selector.hittable = this.editor.app.tree.hitChildren = false;
|
|
1515
|
+
this.onLoad();
|
|
1516
|
+
}
|
|
1517
|
+
onUpdate() { }
|
|
1518
|
+
update() { this.onUpdate(); }
|
|
1519
|
+
onUnload() { }
|
|
1520
|
+
unload() {
|
|
1521
|
+
this.editor.selector.hittable = this.editor.app.tree.hitChildren = true;
|
|
1522
|
+
this.onUnload();
|
|
1523
|
+
}
|
|
1524
|
+
onDestroy() { }
|
|
1525
|
+
destroy() {
|
|
1526
|
+
this.onDestroy();
|
|
1527
|
+
if (this.editor) {
|
|
1528
|
+
if (this.view)
|
|
1529
|
+
this.view.destroy();
|
|
1530
|
+
if (this.eventIds)
|
|
1531
|
+
this.editor.off_(this.eventIds);
|
|
1532
|
+
this.editor = this.view = this.eventIds = null;
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
let EditTool = class EditTool extends InnerEditor {
|
|
1538
|
+
static registerEditTool() {
|
|
1539
|
+
EditToolCreator.register(this);
|
|
1540
|
+
}
|
|
1541
|
+
get tag() { return 'EditTool'; }
|
|
1542
|
+
onMove(e) {
|
|
1543
|
+
const { moveX, moveY, editor } = e;
|
|
1544
|
+
const { app, list } = editor;
|
|
1545
|
+
app.lockLayout();
|
|
1546
|
+
list.forEach(target => {
|
|
1547
|
+
target.moveWorld(moveX, moveY);
|
|
1548
|
+
});
|
|
1549
|
+
app.unlockLayout();
|
|
1550
|
+
}
|
|
1551
|
+
onScale(e) {
|
|
1552
|
+
const { scaleX, scaleY, transform, worldOrigin, editor } = e;
|
|
1553
|
+
const { app, list } = editor;
|
|
1554
|
+
app.lockLayout();
|
|
1555
|
+
list.forEach(target => {
|
|
1556
|
+
const resize = editor.getEditSize(target) === 'size';
|
|
1557
|
+
if (transform) {
|
|
1558
|
+
target.transformWorld(transform, resize);
|
|
1559
|
+
}
|
|
1560
|
+
else {
|
|
1561
|
+
target.scaleOfWorld(worldOrigin, scaleX, scaleY, resize);
|
|
1562
|
+
}
|
|
1563
|
+
});
|
|
1564
|
+
app.unlockLayout();
|
|
1565
|
+
}
|
|
1566
|
+
onRotate(e) {
|
|
1567
|
+
const { rotation, transform, worldOrigin, editor } = e;
|
|
1568
|
+
const { app, list } = editor;
|
|
1569
|
+
app.lockLayout();
|
|
1570
|
+
list.forEach(target => {
|
|
1571
|
+
const resize = editor.getEditSize(target) === 'size';
|
|
1572
|
+
if (transform) {
|
|
1573
|
+
target.transformWorld(transform, resize);
|
|
1574
|
+
}
|
|
1575
|
+
else {
|
|
1576
|
+
target.rotateOfWorld(worldOrigin, rotation);
|
|
1577
|
+
}
|
|
1578
|
+
});
|
|
1579
|
+
app.unlockLayout();
|
|
1580
|
+
}
|
|
1581
|
+
onSkew(e) {
|
|
1582
|
+
const { skewX, skewY, transform, worldOrigin, editor } = e;
|
|
1583
|
+
const { app, list } = editor;
|
|
1584
|
+
app.lockLayout();
|
|
1585
|
+
list.forEach(target => {
|
|
1586
|
+
const resize = editor.getEditSize(target) === 'size';
|
|
1587
|
+
if (transform) {
|
|
1588
|
+
target.transformWorld(transform, resize);
|
|
1589
|
+
}
|
|
1590
|
+
else {
|
|
1591
|
+
target.skewOfWorld(worldOrigin, skewX, skewY, resize);
|
|
1592
|
+
}
|
|
1593
|
+
});
|
|
1594
|
+
app.unlockLayout();
|
|
1595
|
+
}
|
|
1596
|
+
load() {
|
|
1597
|
+
this.editBox.view.visible = true;
|
|
1598
|
+
this.onLoad();
|
|
1599
|
+
}
|
|
1600
|
+
update() {
|
|
1601
|
+
const { editor, editBox } = this;
|
|
1602
|
+
const { simulateTarget, element } = editor;
|
|
1603
|
+
if (editor.multiple)
|
|
1604
|
+
simulateTarget.parent.updateLayout();
|
|
1605
|
+
const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = element.getLayoutBounds('box', editor, true);
|
|
1606
|
+
editBox.set({ x, y, scaleX, scaleY, rotation, skewX, skewY });
|
|
1607
|
+
editBox.update({ x: 0, y: 0, width, height });
|
|
1608
|
+
this.onUpdate();
|
|
1609
|
+
}
|
|
1610
|
+
unload() {
|
|
1611
|
+
this.editBox.view.visible = false;
|
|
1612
|
+
this.onUnload();
|
|
1613
|
+
}
|
|
1614
|
+
};
|
|
1615
|
+
EditTool = __decorate([
|
|
1616
|
+
registerEditTool()
|
|
1617
|
+
], EditTool);
|
|
1618
|
+
|
|
1619
|
+
const { left, right } = Direction9;
|
|
1620
|
+
let LineEditTool = class LineEditTool extends EditTool {
|
|
1621
|
+
constructor() {
|
|
1622
|
+
super(...arguments);
|
|
1623
|
+
this.scaleOfEvent = true;
|
|
1624
|
+
}
|
|
1625
|
+
get tag() { return 'LineEditTool'; }
|
|
1626
|
+
onScaleWithDrag(e) {
|
|
1627
|
+
const { drag, direction, lockRatio, around } = e;
|
|
1628
|
+
const target = e.target;
|
|
1629
|
+
const fromPoint = getPointData();
|
|
1630
|
+
const { toPoint } = target;
|
|
1631
|
+
target.rotation = 0;
|
|
1632
|
+
let { x, y } = drag.getInnerMove(target);
|
|
1633
|
+
if (lockRatio) {
|
|
1634
|
+
if (Math.abs(x) > Math.abs(y)) {
|
|
1635
|
+
y = 0;
|
|
1636
|
+
}
|
|
1637
|
+
else {
|
|
1638
|
+
x = 0;
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
if (direction === left) {
|
|
1642
|
+
fromPoint.x += x;
|
|
1643
|
+
fromPoint.y += y;
|
|
1644
|
+
if (around) {
|
|
1645
|
+
toPoint.x -= x;
|
|
1646
|
+
toPoint.y -= y;
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
else {
|
|
1650
|
+
if (around) {
|
|
1651
|
+
fromPoint.x -= x;
|
|
1652
|
+
fromPoint.y -= y;
|
|
1653
|
+
}
|
|
1654
|
+
toPoint.x += x;
|
|
1655
|
+
toPoint.y += y;
|
|
1656
|
+
}
|
|
1657
|
+
target.getLocalPointByInner(fromPoint, null, null, true);
|
|
1658
|
+
target.getLocalPointByInner(toPoint, null, null, true);
|
|
1659
|
+
target.x = fromPoint.x;
|
|
1660
|
+
target.y = fromPoint.y;
|
|
1661
|
+
target.getInnerPointByLocal(toPoint, null, null, true);
|
|
1662
|
+
target.toPoint = toPoint;
|
|
1663
|
+
}
|
|
1664
|
+
onSkew(_e) {
|
|
1665
|
+
}
|
|
1666
|
+
onUpdate() {
|
|
1667
|
+
const { rotatePoints, resizeLines, resizePoints } = this.editor.editBox;
|
|
1668
|
+
for (let i = 0; i < 8; i++) {
|
|
1669
|
+
if (i < 4)
|
|
1670
|
+
resizeLines[i].visible = false;
|
|
1671
|
+
resizePoints[i].visible = rotatePoints[i].visible = (i === left || i === right);
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
};
|
|
1675
|
+
LineEditTool = __decorate([
|
|
1676
|
+
registerEditTool()
|
|
1677
|
+
], LineEditTool);
|
|
1678
|
+
|
|
1679
|
+
Creator.editor = function (options) { return new Editor(options); };
|
|
1680
|
+
UI.setEditConfig = function (config) {
|
|
1681
|
+
defineKey(this.prototype, 'editConfig', {
|
|
1682
|
+
get() { return typeof config === 'function' ? config(this) : config; }
|
|
1683
|
+
});
|
|
1684
|
+
};
|
|
1685
|
+
UI.setEditOuter = function (toolName) {
|
|
1686
|
+
defineKey(this.prototype, 'editOuter', {
|
|
1687
|
+
get() { return typeof toolName === 'string' ? toolName : toolName(this); }
|
|
1688
|
+
});
|
|
1689
|
+
};
|
|
1690
|
+
UI.setEditInner = function (editorName) {
|
|
1691
|
+
defineKey(this.prototype, 'editInner', {
|
|
1692
|
+
get() { return typeof editorName === 'string' ? editorName : editorName(this); }
|
|
1693
|
+
});
|
|
1528
1694
|
};
|
|
1695
|
+
Line.setEditOuter(function (line) {
|
|
1696
|
+
return (line.points || line.pathInputed) ? 'EditTool' : 'LineEditTool';
|
|
1697
|
+
});
|
|
1529
1698
|
|
|
1530
|
-
export { EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, Editor, EditorEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, LineEditTool, SelectArea, Stroker };
|
|
1699
|
+
export { EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, InnerEditor, LineEditTool, SelectArea, Stroker, registerEditTool, registerInnerEditor };
|