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