@leafer-in/editor 1.0.0 → 1.0.1
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 +164 -93
- package/dist/editor.esm.js +165 -94
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.js +164 -93
- package/dist/editor.min.cjs +1 -1
- package/dist/editor.min.js +1 -1
- package/package.json +5 -5
- package/src/Editor.ts +74 -56
- package/src/config.ts +1 -0
- package/src/display/EditBox.ts +35 -30
- package/src/display/EditMask.ts +1 -1
- package/src/display/EditSelect.ts +26 -10
- package/src/editor/cursor.ts +4 -0
- package/src/helper/EditDataHelper.ts +54 -13
- package/types/index.d.ts +13 -6
package/dist/editor.cjs
CHANGED
|
@@ -435,7 +435,7 @@ class EditSelect extends draw.Group {
|
|
|
435
435
|
}
|
|
436
436
|
onPointerMove(e) {
|
|
437
437
|
const { app, editor } = this;
|
|
438
|
-
if (this.running && !this.isMoveMode && app.
|
|
438
|
+
if (this.running && !this.isMoveMode && app.interaction.canHover && !app.interaction.dragging) {
|
|
439
439
|
const find = this.findUI(e);
|
|
440
440
|
editor.hoverTarget = editor.hasItem(find) ? null : find;
|
|
441
441
|
}
|
|
@@ -444,15 +444,27 @@ class EditSelect extends draw.Group {
|
|
|
444
444
|
}
|
|
445
445
|
}
|
|
446
446
|
onBeforeDown(e) {
|
|
447
|
+
if (e.multiTouch)
|
|
448
|
+
return;
|
|
447
449
|
const { select } = this.editor.mergeConfig;
|
|
448
|
-
if (select === 'press')
|
|
449
|
-
this.
|
|
450
|
+
if (select === 'press') {
|
|
451
|
+
if (this.app.config.mobile) {
|
|
452
|
+
this.waitSelect = () => this.checkAndSelect(e);
|
|
453
|
+
}
|
|
454
|
+
else {
|
|
455
|
+
this.checkAndSelect(e);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
450
458
|
}
|
|
451
459
|
onTap(e) {
|
|
460
|
+
if (e.multiTouch)
|
|
461
|
+
return;
|
|
452
462
|
const { editor } = this;
|
|
453
463
|
const { select } = editor.mergeConfig;
|
|
454
464
|
if (select === 'tap')
|
|
455
465
|
this.checkAndSelect(e);
|
|
466
|
+
else if (this.waitSelect)
|
|
467
|
+
this.waitSelect();
|
|
456
468
|
if (this.needRemoveItem) {
|
|
457
469
|
editor.removeItem(this.needRemoveItem);
|
|
458
470
|
}
|
|
@@ -483,6 +495,10 @@ class EditSelect extends draw.Group {
|
|
|
483
495
|
}
|
|
484
496
|
}
|
|
485
497
|
onDragStart(e) {
|
|
498
|
+
if (e.multiTouch)
|
|
499
|
+
return;
|
|
500
|
+
if (this.waitSelect)
|
|
501
|
+
this.waitSelect();
|
|
486
502
|
if (this.allowDrag(e)) {
|
|
487
503
|
const { editor } = this;
|
|
488
504
|
const { stroke, area } = editor.mergeConfig;
|
|
@@ -494,10 +510,10 @@ class EditSelect extends draw.Group {
|
|
|
494
510
|
}
|
|
495
511
|
}
|
|
496
512
|
onDrag(e) {
|
|
497
|
-
if (
|
|
498
|
-
this.onDragEnd();
|
|
513
|
+
if (e.multiTouch)
|
|
499
514
|
return;
|
|
500
|
-
|
|
515
|
+
if (this.editor.dragging)
|
|
516
|
+
return this.onDragEnd(e);
|
|
501
517
|
if (this.dragging) {
|
|
502
518
|
const { editor } = this;
|
|
503
519
|
const total = e.getInnerTotal(this);
|
|
@@ -521,7 +537,9 @@ class EditSelect extends draw.Group {
|
|
|
521
537
|
}
|
|
522
538
|
}
|
|
523
539
|
}
|
|
524
|
-
onDragEnd() {
|
|
540
|
+
onDragEnd(e) {
|
|
541
|
+
if (e.multiTouch)
|
|
542
|
+
return;
|
|
525
543
|
if (this.dragging)
|
|
526
544
|
this.originList = null, this.selectArea.visible = false;
|
|
527
545
|
}
|
|
@@ -567,7 +585,7 @@ class EditSelect extends draw.Group {
|
|
|
567
585
|
app.on_(core.PointerEvent.MOVE, this.onPointerMove, this),
|
|
568
586
|
app.on_(core.PointerEvent.BEFORE_DOWN, this.onBeforeDown, this),
|
|
569
587
|
app.on_(core.PointerEvent.TAP, this.onTap, this),
|
|
570
|
-
app.on_(core.DragEvent.START, this.onDragStart, this),
|
|
588
|
+
app.on_(core.DragEvent.START, this.onDragStart, this, true),
|
|
571
589
|
app.on_(core.DragEvent.DRAG, this.onDrag, this),
|
|
572
590
|
app.on_(core.DragEvent.END, this.onDragEnd, this),
|
|
573
591
|
app.on_(core.MoveEvent.MOVE, this.onAutoMove, this),
|
|
@@ -590,22 +608,32 @@ class EditSelect extends draw.Group {
|
|
|
590
608
|
|
|
591
609
|
const { topLeft, top, topRight, right: right$1, bottomRight, bottom, bottomLeft, left: left$1 } = draw.Direction9;
|
|
592
610
|
const { toPoint } = draw.AroundHelper;
|
|
611
|
+
const { within } = draw.MathHelper;
|
|
593
612
|
const EditDataHelper = {
|
|
594
|
-
getScaleData(
|
|
613
|
+
getScaleData(element, startBounds, direction, totalMove, lockRatio, around, flipable, scaleMode) {
|
|
595
614
|
let align, origin = {}, scaleX = 1, scaleY = 1;
|
|
596
|
-
const {
|
|
615
|
+
const { boxBounds, widthRange, heightRange } = element;
|
|
616
|
+
const { width, height } = startBounds;
|
|
597
617
|
if (around) {
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
const
|
|
606
|
-
const
|
|
607
|
-
|
|
608
|
-
|
|
618
|
+
totalMove.x *= 2;
|
|
619
|
+
totalMove.y *= 2;
|
|
620
|
+
}
|
|
621
|
+
const originChangedScaleX = element.scaleX / startBounds.scaleX;
|
|
622
|
+
const originChangedScaleY = element.scaleY / startBounds.scaleY;
|
|
623
|
+
const signX = originChangedScaleX < 0 ? -1 : 1;
|
|
624
|
+
const signY = originChangedScaleY < 0 ? -1 : 1;
|
|
625
|
+
const changedScaleX = scaleMode ? originChangedScaleX : signX * boxBounds.width / width;
|
|
626
|
+
const changedScaleY = scaleMode ? originChangedScaleY : signY * boxBounds.height / height;
|
|
627
|
+
totalMove.x *= scaleMode ? originChangedScaleX : signX;
|
|
628
|
+
totalMove.y *= scaleMode ? originChangedScaleY : signY;
|
|
629
|
+
if (Math.abs(totalMove.x) === width)
|
|
630
|
+
totalMove.x += 0.1;
|
|
631
|
+
if (Math.abs(totalMove.y) === height)
|
|
632
|
+
totalMove.y += 0.1;
|
|
633
|
+
const topScale = (-totalMove.y + height) / height;
|
|
634
|
+
const rightScale = (totalMove.x + width) / width;
|
|
635
|
+
const bottomScale = (totalMove.y + height) / height;
|
|
636
|
+
const leftScale = (-totalMove.x + width) / width;
|
|
609
637
|
switch (direction) {
|
|
610
638
|
case top:
|
|
611
639
|
scaleY = topScale;
|
|
@@ -651,7 +679,24 @@ const EditDataHelper = {
|
|
|
651
679
|
scaleY = scaleY < 0 ? -scale : scale;
|
|
652
680
|
}
|
|
653
681
|
}
|
|
654
|
-
|
|
682
|
+
scaleX /= changedScaleX;
|
|
683
|
+
scaleY /= changedScaleY;
|
|
684
|
+
if (!flipable) {
|
|
685
|
+
const { worldTransform } = element;
|
|
686
|
+
if (scaleX < 0)
|
|
687
|
+
scaleX = 1 / boxBounds.width / worldTransform.scaleX;
|
|
688
|
+
if (scaleY < 0)
|
|
689
|
+
scaleY = 1 / boxBounds.height / worldTransform.scaleY;
|
|
690
|
+
}
|
|
691
|
+
if (widthRange) {
|
|
692
|
+
const nowWidth = boxBounds.width * element.scaleX;
|
|
693
|
+
scaleX = within(nowWidth * scaleX, widthRange) / nowWidth;
|
|
694
|
+
}
|
|
695
|
+
if (heightRange) {
|
|
696
|
+
const nowHeight = boxBounds.height * element.scaleY;
|
|
697
|
+
scaleY = within(nowHeight * scaleY, heightRange) / nowHeight;
|
|
698
|
+
}
|
|
699
|
+
toPoint(around || align, boxBounds, origin);
|
|
655
700
|
return { origin, scaleX, scaleY, direction, lockRatio, around };
|
|
656
701
|
},
|
|
657
702
|
getRotateData(bounds, direction, current, last, around) {
|
|
@@ -772,6 +817,11 @@ function updateCursor(editor, e) {
|
|
|
772
817
|
return;
|
|
773
818
|
if (point.name === 'circle')
|
|
774
819
|
return;
|
|
820
|
+
if (point.pointType === 'button') {
|
|
821
|
+
if (!point.cursor)
|
|
822
|
+
point.cursor = 'pointer';
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
775
825
|
let { rotation } = editBox;
|
|
776
826
|
const { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editor.mergeConfig;
|
|
777
827
|
const { pointType } = point, { flippedX, flippedY } = editBox;
|
|
@@ -840,9 +890,8 @@ class EditBox extends draw.Group {
|
|
|
840
890
|
resizePoints.push(resizePoint);
|
|
841
891
|
this.listenPointEvents(resizePoint, 'resize', i);
|
|
842
892
|
}
|
|
843
|
-
buttons.add(circle);
|
|
844
893
|
this.listenPointEvents(circle, 'rotate', 2);
|
|
845
|
-
view.addMany(...rotatePoints, rect, buttons, ...resizeLines, ...resizePoints);
|
|
894
|
+
view.addMany(...rotatePoints, rect, circle, buttons, ...resizeLines, ...resizePoints);
|
|
846
895
|
this.add(view);
|
|
847
896
|
}
|
|
848
897
|
load() {
|
|
@@ -858,9 +907,9 @@ class EditBox extends draw.Group {
|
|
|
858
907
|
if (!(i % 2))
|
|
859
908
|
resizeP.rotation = (i / 2) * 90;
|
|
860
909
|
}
|
|
861
|
-
circle.set(this.getPointStyle(mergeConfig.rotatePoint || pointsStyle[0]));
|
|
910
|
+
circle.set(this.getPointStyle(mergeConfig.circle || mergeConfig.rotatePoint || pointsStyle[0]));
|
|
862
911
|
rect.set(Object.assign({ stroke, strokeWidth }, (mergeConfig.rect || {})));
|
|
863
|
-
rect.hittable = !single && moveable;
|
|
912
|
+
rect.hittable = !single && !!moveable;
|
|
864
913
|
element.syncEventer = (single && moveable) ? rect : null;
|
|
865
914
|
this.app.interaction.bottomList = (single && moveable) ? [{ target: rect, proxy: element }] : null;
|
|
866
915
|
}
|
|
@@ -869,7 +918,7 @@ class EditBox extends draw.Group {
|
|
|
869
918
|
if (this.view.worldOpacity) {
|
|
870
919
|
const { mergeConfig } = this.editor;
|
|
871
920
|
const { width, height } = bounds;
|
|
872
|
-
const { rect, circle, resizePoints, rotatePoints, resizeLines } = this;
|
|
921
|
+
const { rect, circle, buttons, resizePoints, rotatePoints, resizeLines } = this;
|
|
873
922
|
const { middlePoint, resizeable, rotateable, hideOnSmall } = mergeConfig;
|
|
874
923
|
const smallSize = typeof hideOnSmall === 'number' ? hideOnSmall : 10;
|
|
875
924
|
const showPoints = !(hideOnSmall && width < smallSize && height < smallSize);
|
|
@@ -899,19 +948,25 @@ class EditBox extends draw.Group {
|
|
|
899
948
|
}
|
|
900
949
|
}
|
|
901
950
|
}
|
|
902
|
-
circle.visible = showPoints && rotateable && !!mergeConfig.rotatePoint;
|
|
951
|
+
circle.visible = showPoints && rotateable && !!(mergeConfig.circle || mergeConfig.rotatePoint);
|
|
952
|
+
if (circle.visible)
|
|
953
|
+
this.layoutCircle(mergeConfig);
|
|
903
954
|
if (rect.path)
|
|
904
955
|
rect.path = null;
|
|
905
956
|
rect.set(Object.assign(Object.assign({}, bounds), { visible: true }));
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
this.layoutButtons();
|
|
957
|
+
buttons.visible = showPoints && buttons.children.length > 0;
|
|
958
|
+
if (buttons.visible)
|
|
959
|
+
this.layoutButtons(mergeConfig);
|
|
910
960
|
}
|
|
911
961
|
}
|
|
912
|
-
|
|
913
|
-
const {
|
|
914
|
-
const
|
|
962
|
+
layoutCircle(config) {
|
|
963
|
+
const { circleDirection, circleMargin, buttonsMargin, buttonsDirection, middlePoint } = config;
|
|
964
|
+
const direction = fourDirection.indexOf(circleDirection || ((this.buttons.children.length && buttonsDirection === 'bottom') ? 'top' : 'bottom'));
|
|
965
|
+
this.setButtonPosition(this.circle, direction, circleMargin || buttonsMargin, !!middlePoint);
|
|
966
|
+
}
|
|
967
|
+
layoutButtons(config) {
|
|
968
|
+
const { buttons } = this;
|
|
969
|
+
const { buttonsDirection, buttonsFixed, buttonsMargin, middlePoint } = config;
|
|
915
970
|
const { flippedX, flippedY } = this;
|
|
916
971
|
let index = fourDirection.indexOf(buttonsDirection);
|
|
917
972
|
if ((index % 2 && flippedX) || ((index + 1) % 2 && flippedY)) {
|
|
@@ -919,11 +974,18 @@ class EditBox extends draw.Group {
|
|
|
919
974
|
index = (index + 2) % 4;
|
|
920
975
|
}
|
|
921
976
|
const direction = buttonsFixed ? EditDataHelper.getRotateDirection(index, this.flippedOne ? this.rotation : -this.rotation, 4) : index;
|
|
922
|
-
|
|
977
|
+
this.setButtonPosition(buttons, direction, buttonsMargin, !!middlePoint);
|
|
978
|
+
if (buttonsFixed)
|
|
979
|
+
buttons.rotation = (direction - index) * 90;
|
|
980
|
+
buttons.scaleX = flippedX ? -1 : 1;
|
|
981
|
+
buttons.scaleY = flippedY ? -1 : 1;
|
|
982
|
+
}
|
|
983
|
+
setButtonPosition(buttons, direction, buttonsMargin, useMiddlePoint) {
|
|
984
|
+
const point = this.resizePoints[direction * 2 + 1];
|
|
923
985
|
const useX = direction % 2;
|
|
924
986
|
const sign = (!direction || direction === 3) ? -1 : 1;
|
|
925
|
-
const useWidth =
|
|
926
|
-
const margin = (buttonsMargin + (useWidth ? ((
|
|
987
|
+
const useWidth = direction % 2;
|
|
988
|
+
const margin = (buttonsMargin + (useWidth ? ((useMiddlePoint ? point.width : 0) + buttons.boxBounds.width) : ((useMiddlePoint ? point.height : 0) + buttons.boxBounds.height)) / 2) * sign;
|
|
927
989
|
if (useX) {
|
|
928
990
|
buttons.x = point.x + margin;
|
|
929
991
|
buttons.y = point.y;
|
|
@@ -932,11 +994,6 @@ class EditBox extends draw.Group {
|
|
|
932
994
|
buttons.x = point.x;
|
|
933
995
|
buttons.y = point.y + margin;
|
|
934
996
|
}
|
|
935
|
-
if (buttonsFixed) {
|
|
936
|
-
buttons.rotation = (direction - index) * 90;
|
|
937
|
-
buttons.scaleX = flippedX ? -1 : 1;
|
|
938
|
-
buttons.scaleY = flippedY ? -1 : 1;
|
|
939
|
-
}
|
|
940
997
|
}
|
|
941
998
|
unload() {
|
|
942
999
|
this.visible = false;
|
|
@@ -963,12 +1020,15 @@ class EditBox extends draw.Group {
|
|
|
963
1020
|
}
|
|
964
1021
|
onDragStart(e) {
|
|
965
1022
|
this.dragging = true;
|
|
1023
|
+
const { editor } = this;
|
|
966
1024
|
if (e.current.name === 'rect') {
|
|
967
|
-
const { editor } = this;
|
|
968
1025
|
this.moving = true;
|
|
969
1026
|
editor.dragStartPoint = { x: editor.element.x, y: editor.element.y };
|
|
970
1027
|
editor.opacity = editor.mergeConfig.hideOnMove ? 0 : 1;
|
|
971
1028
|
}
|
|
1029
|
+
else if (e.current.pointType === 'resize') {
|
|
1030
|
+
editor.dragStartBounds = Object.assign({}, editor.element.getLayoutBounds('box', 'local'));
|
|
1031
|
+
}
|
|
972
1032
|
}
|
|
973
1033
|
onDragEnd(e) {
|
|
974
1034
|
this.dragging = false;
|
|
@@ -983,7 +1043,7 @@ class EditBox extends draw.Group {
|
|
|
983
1043
|
if (editor.mergeConfig.rotateable)
|
|
984
1044
|
editor.onRotate(e);
|
|
985
1045
|
}
|
|
986
|
-
else {
|
|
1046
|
+
else if (point.pointType === 'resize') {
|
|
987
1047
|
editor.onScale(e);
|
|
988
1048
|
}
|
|
989
1049
|
updateCursor(editor, e);
|
|
@@ -1047,8 +1107,6 @@ class EditBox extends draw.Group {
|
|
|
1047
1107
|
rect.on_(core.DragEvent.START, this.onDragStart, this),
|
|
1048
1108
|
rect.on_(core.DragEvent.DRAG, editor.onMove, editor),
|
|
1049
1109
|
rect.on_(core.DragEvent.END, this.onDragEnd, this),
|
|
1050
|
-
rect.on_(core.ZoomEvent.BEFORE_ZOOM, editor.onScale, editor, true),
|
|
1051
|
-
rect.on_(core.RotateEvent.BEFORE_ROTATE, editor.onRotate, editor, true),
|
|
1052
1110
|
rect.on_(core.PointerEvent.ENTER, () => updateMoveCursor(editor)),
|
|
1053
1111
|
rect.on_(core.PointerEvent.DOUBLE_TAP, this.onDoubleTap, this),
|
|
1054
1112
|
rect.on_(core.PointerEvent.LONG_PRESS, this.onLongPress, this)
|
|
@@ -1078,7 +1136,7 @@ class EditMask extends draw.UI {
|
|
|
1078
1136
|
const { rect } = editor.editBox;
|
|
1079
1137
|
const { width, height } = rect.__;
|
|
1080
1138
|
canvas.resetTransform();
|
|
1081
|
-
canvas.fillWorld(canvas.bounds, mask);
|
|
1139
|
+
canvas.fillWorld(canvas.bounds, mask === true ? 'rgba(0,0,0,0.8)' : mask);
|
|
1082
1140
|
canvas.setWorld(rect.__world, options.matrix);
|
|
1083
1141
|
canvas.clearRect(0, 0, width, height);
|
|
1084
1142
|
}
|
|
@@ -1163,6 +1221,7 @@ const config = {
|
|
|
1163
1221
|
boxSelect: true,
|
|
1164
1222
|
moveable: true,
|
|
1165
1223
|
resizeable: true,
|
|
1224
|
+
flipable: true,
|
|
1166
1225
|
rotateable: true,
|
|
1167
1226
|
skewable: true
|
|
1168
1227
|
};
|
|
@@ -1384,29 +1443,39 @@ class Editor extends draw.Group {
|
|
|
1384
1443
|
return this.mergeConfig.editSize;
|
|
1385
1444
|
}
|
|
1386
1445
|
onMove(e) {
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1446
|
+
if (e instanceof core.MoveEvent) {
|
|
1447
|
+
if (e.moveType !== 'drag') {
|
|
1448
|
+
const { moveable, resizeable } = this.mergeConfig;
|
|
1449
|
+
const move = e.getLocalMove(this.element);
|
|
1450
|
+
if (moveable === 'move')
|
|
1451
|
+
e.stop(), this.move(move.x, move.y);
|
|
1452
|
+
else if (resizeable === 'zoom')
|
|
1453
|
+
e.stop();
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
else {
|
|
1457
|
+
const total = { x: e.totalX, y: e.totalY };
|
|
1458
|
+
if (e.shiftKey) {
|
|
1459
|
+
if (Math.abs(total.x) > Math.abs(total.y))
|
|
1460
|
+
total.y = 0;
|
|
1461
|
+
else
|
|
1462
|
+
total.x = 0;
|
|
1463
|
+
}
|
|
1464
|
+
this.move(core.DragEvent.getValidMove(this.element, this.dragStartPoint, total));
|
|
1393
1465
|
}
|
|
1394
|
-
this.move(core.DragEvent.getValidMove(this.element, this.dragStartPoint, total));
|
|
1395
1466
|
}
|
|
1396
1467
|
onScale(e) {
|
|
1397
1468
|
const { element } = this;
|
|
1469
|
+
let { around, lockRatio, resizeable, flipable, editSize } = this.mergeConfig;
|
|
1398
1470
|
if (e instanceof core.ZoomEvent) {
|
|
1399
|
-
if (
|
|
1400
|
-
e.stop();
|
|
1401
|
-
this.scaleOf(element.getInnerPoint(e), e.scale, e.scale);
|
|
1402
|
-
}
|
|
1471
|
+
if (resizeable === 'zoom')
|
|
1472
|
+
e.stop(), this.scaleOf(element.getInnerPoint(e), e.scale, e.scale);
|
|
1403
1473
|
}
|
|
1404
1474
|
else {
|
|
1405
1475
|
const { direction } = e.current;
|
|
1406
|
-
let { around, lockRatio } = this.mergeConfig;
|
|
1407
1476
|
if (e.shiftKey || element.lockRatio)
|
|
1408
1477
|
lockRatio = true;
|
|
1409
|
-
const data = EditDataHelper.getScaleData(element.
|
|
1478
|
+
const data = EditDataHelper.getScaleData(element, this.dragStartBounds, direction, e.getInnerTotal(element), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, this.multiple || editSize === 'scale');
|
|
1410
1479
|
if (this.editTool.onScaleWithDrag) {
|
|
1411
1480
|
data.drag = e;
|
|
1412
1481
|
this.scaleWithDrag(data);
|
|
@@ -1417,23 +1486,21 @@ class Editor extends draw.Group {
|
|
|
1417
1486
|
}
|
|
1418
1487
|
}
|
|
1419
1488
|
onRotate(e) {
|
|
1420
|
-
const { skewable, around, rotateGap } = this.mergeConfig;
|
|
1489
|
+
const { skewable, rotateable, around, rotateGap } = this.mergeConfig;
|
|
1421
1490
|
const { direction, name } = e.current;
|
|
1422
1491
|
if (skewable && name === 'resize-line')
|
|
1423
1492
|
return this.onSkew(e);
|
|
1424
1493
|
const { element } = this;
|
|
1425
1494
|
let origin, rotation;
|
|
1426
1495
|
if (e instanceof core.RotateEvent) {
|
|
1427
|
-
if (
|
|
1428
|
-
e.stop();
|
|
1429
|
-
rotation = e.rotation, origin = element.getInnerPoint(e);
|
|
1430
|
-
}
|
|
1496
|
+
if (rotateable === 'rotate')
|
|
1497
|
+
e.stop(), rotation = e.rotation, origin = element.getInnerPoint(e);
|
|
1431
1498
|
else
|
|
1432
1499
|
return;
|
|
1433
1500
|
}
|
|
1434
1501
|
else {
|
|
1435
1502
|
const last = { x: e.x - e.moveX, y: e.y - e.moveY };
|
|
1436
|
-
const data = EditDataHelper.getRotateData(element.boxBounds, direction, e.getInner(element), element.getInnerPoint(last), e.shiftKey ? null : (around || 'center'));
|
|
1503
|
+
const data = EditDataHelper.getRotateData(element.boxBounds, direction, e.getInner(element), element.getInnerPoint(last), e.shiftKey ? null : (element.around || element.origin || around || 'center'));
|
|
1437
1504
|
rotation = data.rotation;
|
|
1438
1505
|
origin = data.origin;
|
|
1439
1506
|
}
|
|
@@ -1467,8 +1534,7 @@ class Editor extends draw.Group {
|
|
|
1467
1534
|
if (!this.mergeConfig.resizeable || this.element.locked)
|
|
1468
1535
|
return;
|
|
1469
1536
|
const { element } = this;
|
|
1470
|
-
const
|
|
1471
|
-
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, Object.assign(Object.assign({}, data), { target: element, editor: this, worldOrigin }));
|
|
1537
|
+
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, Object.assign(Object.assign({}, data), { target: element, editor: this, worldOrigin: element.getWorldPoint(data.origin) }));
|
|
1472
1538
|
this.editTool.onScaleWithDrag(event);
|
|
1473
1539
|
this.emitEvent(event);
|
|
1474
1540
|
}
|
|
@@ -1476,28 +1542,28 @@ class Editor extends draw.Group {
|
|
|
1476
1542
|
if (!this.mergeConfig.resizeable || this.element.locked)
|
|
1477
1543
|
return;
|
|
1478
1544
|
const { element } = this;
|
|
1479
|
-
const worldOrigin =
|
|
1480
|
-
|
|
1481
|
-
if (this.multiple) {
|
|
1482
|
-
const oldMatrix = new draw.Matrix(element.worldTransform);
|
|
1483
|
-
element.scaleOf(origin, scaleX, scaleY);
|
|
1484
|
-
transform = new draw.Matrix(element.worldTransform).divide(oldMatrix);
|
|
1485
|
-
}
|
|
1545
|
+
const worldOrigin = this.getWorldOrigin(origin);
|
|
1546
|
+
const transform = this.multiple && this.getChangedTransform(() => element.scaleOf(origin, scaleX, scaleY));
|
|
1486
1547
|
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, { target: element, editor: this, worldOrigin, scaleX, scaleY, transform });
|
|
1487
1548
|
this.editTool.onScale(event);
|
|
1488
1549
|
this.emitEvent(event);
|
|
1489
1550
|
}
|
|
1551
|
+
flip(axis) {
|
|
1552
|
+
if (this.element.locked)
|
|
1553
|
+
return;
|
|
1554
|
+
const { element } = this;
|
|
1555
|
+
const worldOrigin = this.getWorldOrigin('center');
|
|
1556
|
+
const transform = this.multiple ? this.getChangedTransform(() => element.flip(axis)) : new draw.Matrix(draw.LeafHelper.getFlipTransform(element, axis));
|
|
1557
|
+
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, { target: element, editor: this, worldOrigin, scaleX: axis === 'x' ? -1 : 1, scaleY: axis === 'y' ? -1 : 1, transform });
|
|
1558
|
+
this.editTool.onScale(event);
|
|
1559
|
+
this.emitEvent(event);
|
|
1560
|
+
}
|
|
1490
1561
|
rotateOf(origin, rotation) {
|
|
1491
1562
|
if (!this.mergeConfig.rotateable || this.element.locked)
|
|
1492
1563
|
return;
|
|
1493
1564
|
const { element } = this;
|
|
1494
|
-
const worldOrigin =
|
|
1495
|
-
|
|
1496
|
-
if (this.multiple) {
|
|
1497
|
-
const oldMatrix = new draw.Matrix(element.worldTransform);
|
|
1498
|
-
element.rotateOf(origin, rotation);
|
|
1499
|
-
transform = new draw.Matrix(element.worldTransform).divide(oldMatrix);
|
|
1500
|
-
}
|
|
1565
|
+
const worldOrigin = this.getWorldOrigin(origin);
|
|
1566
|
+
const transform = this.multiple && this.getChangedTransform(() => element.rotateOf(origin, rotation));
|
|
1501
1567
|
const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, { target: element, editor: this, worldOrigin, rotation, transform });
|
|
1502
1568
|
this.editTool.onRotate(event);
|
|
1503
1569
|
this.emitEvent(event);
|
|
@@ -1506,19 +1572,21 @@ class Editor extends draw.Group {
|
|
|
1506
1572
|
if (!this.mergeConfig.skewable || this.element.locked)
|
|
1507
1573
|
return;
|
|
1508
1574
|
const { element } = this;
|
|
1509
|
-
const worldOrigin =
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
const oldMatrix = new draw.Matrix(element.worldTransform);
|
|
1513
|
-
element.skewOf(origin, skewX, skewY);
|
|
1514
|
-
transform = new draw.Matrix(element.worldTransform).divide(oldMatrix);
|
|
1515
|
-
}
|
|
1516
|
-
const event = new EditorSkewEvent(EditorSkewEvent.SKEW, {
|
|
1517
|
-
target: element, editor: this, skewX, skewY, transform, worldOrigin
|
|
1518
|
-
});
|
|
1575
|
+
const worldOrigin = this.getWorldOrigin(origin);
|
|
1576
|
+
const transform = this.multiple && this.getChangedTransform(() => element.skewOf(origin, skewX, skewY));
|
|
1577
|
+
const event = new EditorSkewEvent(EditorSkewEvent.SKEW, { target: element, editor: this, worldOrigin, skewX, skewY, transform });
|
|
1519
1578
|
this.editTool.onSkew(event);
|
|
1520
1579
|
this.emitEvent(event);
|
|
1521
1580
|
}
|
|
1581
|
+
getWorldOrigin(origin) {
|
|
1582
|
+
return this.element.getWorldPoint(draw.LeafHelper.getInnerOrigin(this.element, origin));
|
|
1583
|
+
}
|
|
1584
|
+
getChangedTransform(func) {
|
|
1585
|
+
const { element } = this;
|
|
1586
|
+
const oldMatrix = new draw.Matrix(element.worldTransform);
|
|
1587
|
+
func();
|
|
1588
|
+
return new draw.Matrix(element.worldTransform).divide(oldMatrix);
|
|
1589
|
+
}
|
|
1522
1590
|
group(userGroup) {
|
|
1523
1591
|
if (this.multiple) {
|
|
1524
1592
|
this.target = EditorHelper.group(this.list, this.element, userGroup);
|
|
@@ -1629,6 +1697,9 @@ class Editor extends draw.Group {
|
|
|
1629
1697
|
if (!this.targetEventIds.length) {
|
|
1630
1698
|
const { leafer } = this.list[0];
|
|
1631
1699
|
this.targetEventIds = [
|
|
1700
|
+
this.app.on_(core.MoveEvent.BEFORE_MOVE, this.onMove, this, true),
|
|
1701
|
+
this.app.on_(core.ZoomEvent.BEFORE_ZOOM, this.onScale, this, true),
|
|
1702
|
+
this.app.on_(core.RotateEvent.BEFORE_ROTATE, this.onRotate, this, true),
|
|
1632
1703
|
leafer.on_(draw.RenderEvent.START, this.update, this),
|
|
1633
1704
|
leafer.on_([core.KeyEvent.HOLD, core.KeyEvent.UP], (e) => { updateCursor(this, e); }),
|
|
1634
1705
|
leafer.on_(core.KeyEvent.DOWN, this.editBox.onArrow, this.editBox)
|