@leafer-in/editor 1.9.6 → 1.9.8
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 +200 -161
- package/dist/editor.esm.js +202 -163
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.esm.min.js.map +1 -1
- package/dist/editor.js +197 -158
- package/dist/editor.min.cjs +1 -1
- package/dist/editor.min.cjs.map +1 -1
- package/dist/editor.min.js +1 -1
- package/dist/editor.min.js.map +1 -1
- package/package.json +6 -6
- package/src/Editor.ts +19 -3
- package/src/decorator/data.ts +11 -6
- package/src/display/EditBox.ts +78 -68
- package/src/display/EditSelect.ts +5 -5
- package/src/editor/cursor.ts +10 -4
- package/src/helper/EditDataHelper.ts +76 -69
- package/src/tool/TransformTool.ts +35 -30
- package/types/index.d.ts +13 -9
package/dist/editor.cjs
CHANGED
|
@@ -54,22 +54,25 @@ function targetAttr(fn) {
|
|
|
54
54
|
set(value) {
|
|
55
55
|
const old = this[privateKey];
|
|
56
56
|
if (old !== value) {
|
|
57
|
-
|
|
57
|
+
const t = this;
|
|
58
|
+
if (t.config) {
|
|
58
59
|
const isSelect = key === "target";
|
|
59
60
|
if (isSelect) {
|
|
60
|
-
|
|
61
|
-
if (this.single) this.element.syncEventer = null;
|
|
62
|
-
const {beforeSelect: beforeSelect} = this.config;
|
|
61
|
+
const {beforeSelect: beforeSelect} = t.config;
|
|
63
62
|
if (beforeSelect) {
|
|
64
63
|
const check = beforeSelect({
|
|
65
64
|
target: value
|
|
66
65
|
});
|
|
67
66
|
if (draw.isObject(check)) value = check; else if (check === false) return;
|
|
68
67
|
}
|
|
68
|
+
t.setDimOthers(false);
|
|
69
|
+
t.setBright(false);
|
|
70
|
+
if (draw.isArray(value) && value.length > 1 && value[0].locked) value.splice(0, 1);
|
|
71
|
+
if (t.single) t.element.syncEventer = null;
|
|
69
72
|
}
|
|
70
73
|
const type = isSelect ? EditorEvent.BEFORE_SELECT : EditorEvent.BEFORE_HOVER;
|
|
71
74
|
if (this.hasEvent(type)) this.emitEvent(new EditorEvent(type, {
|
|
72
|
-
editor:
|
|
75
|
+
editor: t,
|
|
73
76
|
value: value,
|
|
74
77
|
oldValue: old
|
|
75
78
|
}));
|
|
@@ -251,11 +254,12 @@ class EditSelect extends draw.Group {
|
|
|
251
254
|
return !!this.originList;
|
|
252
255
|
}
|
|
253
256
|
get running() {
|
|
254
|
-
const {editor: editor} = this;
|
|
255
|
-
return this.hittable && editor.visible && editor.hittable && editor.mergeConfig.selector &&
|
|
257
|
+
const {editor: editor, app: app} = this;
|
|
258
|
+
return this.hittable && editor.visible && editor.hittable && editor.mergeConfig.selector && (app && app.mode === "normal");
|
|
256
259
|
}
|
|
257
260
|
get isMoveMode() {
|
|
258
|
-
|
|
261
|
+
const {app: app} = this;
|
|
262
|
+
return app && app.interaction.moveMode;
|
|
259
263
|
}
|
|
260
264
|
constructor(editor) {
|
|
261
265
|
super();
|
|
@@ -318,12 +322,12 @@ class EditSelect extends draw.Group {
|
|
|
318
322
|
onTap(e) {
|
|
319
323
|
if (e.multiTouch) return;
|
|
320
324
|
const {editor: editor} = this;
|
|
321
|
-
const {select: select} = editor.mergeConfig;
|
|
325
|
+
const {select: select, selectKeep: selectKeep} = editor.mergeConfig;
|
|
322
326
|
if (select === "tap") this.checkAndSelect(e); else if (this.waitSelect) this.waitSelect();
|
|
323
327
|
if (this.needRemoveItem) {
|
|
324
328
|
editor.removeItem(this.needRemoveItem);
|
|
325
329
|
} else if (this.isMoveMode) {
|
|
326
|
-
editor.target = null;
|
|
330
|
+
if (!selectKeep) editor.target = null;
|
|
327
331
|
}
|
|
328
332
|
}
|
|
329
333
|
checkAndSelect(e) {
|
|
@@ -338,7 +342,7 @@ class EditSelect extends draw.Group {
|
|
|
338
342
|
editor.target = find;
|
|
339
343
|
}
|
|
340
344
|
} else if (this.allow(e.target)) {
|
|
341
|
-
if (!this.isHoldMultipleSelectKey(e)) editor.target = null;
|
|
345
|
+
if (!this.isHoldMultipleSelectKey(e) && !this.editor.mergedConfig.selectKeep) editor.target = null;
|
|
342
346
|
}
|
|
343
347
|
}
|
|
344
348
|
}
|
|
@@ -457,91 +461,95 @@ const {toPoint: toPoint} = draw.AroundHelper;
|
|
|
457
461
|
const {within: within, sign: sign} = draw.MathHelper;
|
|
458
462
|
|
|
459
463
|
const EditDataHelper = {
|
|
460
|
-
getScaleData(target, startBounds, direction,
|
|
464
|
+
getScaleData(target, startBounds, direction, totalMoveOrScale, lockRatio, around, flipable, scaleMode) {
|
|
461
465
|
let align, origin = {}, scaleX = 1, scaleY = 1;
|
|
462
466
|
const {boxBounds: boxBounds, widthRange: widthRange, heightRange: heightRange, dragBounds: dragBounds, worldBoxBounds: worldBoxBounds} = target;
|
|
463
467
|
const {width: width, height: height} = startBounds;
|
|
464
|
-
if (around) {
|
|
465
|
-
totalMove.x *= 2;
|
|
466
|
-
totalMove.y *= 2;
|
|
467
|
-
}
|
|
468
468
|
const originChangedScaleX = target.scaleX / startBounds.scaleX;
|
|
469
469
|
const originChangedScaleY = target.scaleY / startBounds.scaleY;
|
|
470
470
|
const signX = sign(originChangedScaleX);
|
|
471
471
|
const signY = sign(originChangedScaleY);
|
|
472
472
|
const changedScaleX = scaleMode ? originChangedScaleX : signX * boxBounds.width / width;
|
|
473
473
|
const changedScaleY = scaleMode ? originChangedScaleY : signY * boxBounds.height / height;
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
scaleY = bottomScale;
|
|
493
|
-
align = "top";
|
|
494
|
-
break;
|
|
474
|
+
if (draw.isNumber(totalMoveOrScale)) {
|
|
475
|
+
scaleX = scaleY = Math.sqrt(totalMoveOrScale);
|
|
476
|
+
} else {
|
|
477
|
+
if (around) {
|
|
478
|
+
totalMoveOrScale.x *= 2;
|
|
479
|
+
totalMoveOrScale.y *= 2;
|
|
480
|
+
}
|
|
481
|
+
totalMoveOrScale.x *= scaleMode ? originChangedScaleX : signX;
|
|
482
|
+
totalMoveOrScale.y *= scaleMode ? originChangedScaleY : signY;
|
|
483
|
+
const topScale = (-totalMoveOrScale.y + height) / height;
|
|
484
|
+
const rightScale = (totalMoveOrScale.x + width) / width;
|
|
485
|
+
const bottomScale = (totalMoveOrScale.y + height) / height;
|
|
486
|
+
const leftScale = (-totalMoveOrScale.x + width) / width;
|
|
487
|
+
switch (direction) {
|
|
488
|
+
case top:
|
|
489
|
+
scaleY = topScale;
|
|
490
|
+
align = "bottom";
|
|
491
|
+
break;
|
|
495
492
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
493
|
+
case right$1:
|
|
494
|
+
scaleX = rightScale;
|
|
495
|
+
align = "left";
|
|
496
|
+
break;
|
|
500
497
|
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
break;
|
|
498
|
+
case bottom:
|
|
499
|
+
scaleY = bottomScale;
|
|
500
|
+
align = "top";
|
|
501
|
+
break;
|
|
506
502
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
break;
|
|
503
|
+
case left$1:
|
|
504
|
+
scaleX = leftScale;
|
|
505
|
+
align = "right";
|
|
506
|
+
break;
|
|
512
507
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
508
|
+
case topLeft:
|
|
509
|
+
scaleY = topScale;
|
|
510
|
+
scaleX = leftScale;
|
|
511
|
+
align = "bottom-right";
|
|
512
|
+
break;
|
|
518
513
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
if (lockRatio) {
|
|
525
|
-
if (lockRatio === "corner" && direction % 2) {
|
|
526
|
-
lockRatio = false;
|
|
527
|
-
} else {
|
|
528
|
-
let scale;
|
|
529
|
-
switch (direction) {
|
|
530
|
-
case top:
|
|
531
|
-
case bottom:
|
|
532
|
-
scale = scaleY;
|
|
533
|
-
break;
|
|
514
|
+
case topRight:
|
|
515
|
+
scaleY = topScale;
|
|
516
|
+
scaleX = rightScale;
|
|
517
|
+
align = "bottom-left";
|
|
518
|
+
break;
|
|
534
519
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
520
|
+
case bottomRight:
|
|
521
|
+
scaleY = bottomScale;
|
|
522
|
+
scaleX = rightScale;
|
|
523
|
+
align = "top-left";
|
|
524
|
+
break;
|
|
539
525
|
|
|
540
|
-
|
|
541
|
-
|
|
526
|
+
case bottomLeft:
|
|
527
|
+
scaleY = bottomScale;
|
|
528
|
+
scaleX = leftScale;
|
|
529
|
+
align = "top-right";
|
|
530
|
+
}
|
|
531
|
+
if (lockRatio) {
|
|
532
|
+
if (lockRatio === "corner" && direction % 2) {
|
|
533
|
+
lockRatio = false;
|
|
534
|
+
} else {
|
|
535
|
+
let scale;
|
|
536
|
+
switch (direction) {
|
|
537
|
+
case top:
|
|
538
|
+
case bottom:
|
|
539
|
+
scale = scaleY;
|
|
540
|
+
break;
|
|
541
|
+
|
|
542
|
+
case left$1:
|
|
543
|
+
case right$1:
|
|
544
|
+
scale = scaleX;
|
|
545
|
+
break;
|
|
546
|
+
|
|
547
|
+
default:
|
|
548
|
+
scale = Math.sqrt(Math.abs(scaleX * scaleY));
|
|
549
|
+
}
|
|
550
|
+
scaleX = scaleX < 0 ? -scale : scale;
|
|
551
|
+
scaleY = scaleY < 0 ? -scale : scale;
|
|
542
552
|
}
|
|
543
|
-
scaleX = scaleX < 0 ? -scale : scale;
|
|
544
|
-
scaleY = scaleY < 0 ? -scale : scale;
|
|
545
553
|
}
|
|
546
554
|
}
|
|
547
555
|
const useScaleX = scaleX !== 1, useScaleY = scaleY !== 1;
|
|
@@ -740,13 +748,18 @@ const cacheCursors = {};
|
|
|
740
748
|
function updatePointCursor(editBox, e) {
|
|
741
749
|
const {enterPoint: point, dragging: dragging, skewing: skewing, resizing: resizing, flippedX: flippedX, flippedY: flippedY} = editBox;
|
|
742
750
|
if (!point || !editBox.editor.editing || !editBox.canUse) return;
|
|
751
|
+
if (point.name === "rect") return updateMoveCursor(editBox);
|
|
743
752
|
if (point.name === "circle") return;
|
|
744
|
-
|
|
753
|
+
let {rotation: rotation} = editBox;
|
|
754
|
+
const {pointType: pointType} = point, {moveCursor: moveCursor, resizeCursor: resizeCursor, rotateCursor: rotateCursor, skewCursor: skewCursor, moveable: moveable, resizeable: resizeable, rotateable: rotateable, skewable: skewable} = editBox.mergeConfig;
|
|
755
|
+
if (pointType === "move") {
|
|
756
|
+
point.cursor = moveCursor;
|
|
757
|
+
if (!moveable) point.visible = false;
|
|
758
|
+
return;
|
|
759
|
+
} else if (pointType === "button") {
|
|
745
760
|
if (!point.cursor) point.cursor = "pointer";
|
|
746
761
|
return;
|
|
747
762
|
}
|
|
748
|
-
let {rotation: rotation} = editBox;
|
|
749
|
-
const {pointType: pointType} = point, {resizeCursor: resizeCursor, rotateCursor: rotateCursor, skewCursor: skewCursor, resizeable: resizeable, rotateable: rotateable, skewable: skewable} = editBox.mergeConfig;
|
|
750
763
|
let showResize = pointType.includes("resize");
|
|
751
764
|
if (showResize && rotateable && (editBox.isHoldRotateKey(e) || !resizeable)) showResize = false;
|
|
752
765
|
const showSkew = skewable && !showResize && (point.name === "resize-line" || pointType === "skew");
|
|
@@ -824,10 +837,13 @@ class EditBox extends draw.Group {
|
|
|
824
837
|
const {moveable: moveable, resizeable: resizeable, rotateable: rotateable} = this.mergeConfig;
|
|
825
838
|
return draw.isString(moveable) || draw.isString(resizeable) || draw.isString(rotateable);
|
|
826
839
|
}
|
|
840
|
+
get canDragLimitAnimate() {
|
|
841
|
+
return this.moving && this.mergeConfig.dragLimitAnimate && this.target.dragBounds;
|
|
842
|
+
}
|
|
827
843
|
constructor(editor) {
|
|
828
844
|
super();
|
|
829
845
|
this.view = new draw.Group;
|
|
830
|
-
this.rect = new
|
|
846
|
+
this.rect = new EditPoint({
|
|
831
847
|
name: "rect",
|
|
832
848
|
hitFill: "all",
|
|
833
849
|
hitStroke: "none",
|
|
@@ -889,12 +905,13 @@ class EditBox extends draw.Group {
|
|
|
889
905
|
this.listenPointEvents(resizePoint, "resize", i);
|
|
890
906
|
}
|
|
891
907
|
this.listenPointEvents(circle, "rotate", 2);
|
|
908
|
+
this.listenPointEvents(rect, "move", 8);
|
|
892
909
|
view.addMany(...rotatePoints, rect, circle, buttons, ...resizeLines, ...resizePoints);
|
|
893
910
|
this.add(view);
|
|
894
911
|
}
|
|
895
912
|
load() {
|
|
896
|
-
const {target: target, mergeConfig: mergeConfig, single: single, rect: rect, circle: circle, resizePoints: resizePoints} = this;
|
|
897
|
-
const {stroke: stroke, strokeWidth: strokeWidth} = mergeConfig;
|
|
913
|
+
const {target: target, mergeConfig: mergeConfig, single: single, rect: rect, circle: circle, resizePoints: resizePoints, resizeLines: resizeLines} = this;
|
|
914
|
+
const {stroke: stroke, strokeWidth: strokeWidth, resizeLine: resizeLine} = mergeConfig;
|
|
898
915
|
const pointsStyle = this.getPointsStyle();
|
|
899
916
|
const middlePointsStyle = this.getMiddlePointsStyle();
|
|
900
917
|
this.visible = !target.locked;
|
|
@@ -903,6 +920,10 @@ class EditBox extends draw.Group {
|
|
|
903
920
|
resizeP = resizePoints[i];
|
|
904
921
|
resizeP.set(this.getPointStyle(i % 2 ? middlePointsStyle[(i - 1) / 2 % middlePointsStyle.length] : pointsStyle[i / 2 % pointsStyle.length]));
|
|
905
922
|
resizeP.rotation = (i - (i % 2 ? 1 : 0)) / 2 * 90;
|
|
923
|
+
if (i % 2) resizeLines[(i - 1) / 2].set(Object.assign({
|
|
924
|
+
pointType: "resize",
|
|
925
|
+
rotation: (i - 1) / 2 * 90
|
|
926
|
+
}, resizeLine || {}));
|
|
906
927
|
}
|
|
907
928
|
circle.set(this.getPointStyle(mergeConfig.circle || mergeConfig.rotatePoint || pointsStyle[0]));
|
|
908
929
|
rect.set(Object.assign({
|
|
@@ -947,10 +968,12 @@ class EditBox extends draw.Group {
|
|
|
947
968
|
if (this.app) this.rect.syncEventer = this.app.interaction.bottomList = null;
|
|
948
969
|
}
|
|
949
970
|
updateBounds(bounds) {
|
|
950
|
-
const {
|
|
951
|
-
const {
|
|
952
|
-
const {middlePoint: middlePoint, resizeable: resizeable, rotateable: rotateable, hideOnSmall: hideOnSmall, editBox: editBox, mask: mask, spread: spread, hideRotatePoints: hideRotatePoints, hideResizeLines: hideResizeLines} = mergeConfig;
|
|
971
|
+
const {editor: editor, mergeConfig: mergeConfig, single: single, rect: rect, circle: circle, buttons: buttons, resizePoints: resizePoints, rotatePoints: rotatePoints, resizeLines: resizeLines} = this;
|
|
972
|
+
const {editMask: editMask} = editor;
|
|
973
|
+
const {middlePoint: middlePoint, resizeable: resizeable, rotateable: rotateable, hideOnSmall: hideOnSmall, editBox: editBox, mask: mask, dimOthers: dimOthers, bright: bright, spread: spread, hideRotatePoints: hideRotatePoints, hideResizeLines: hideResizeLines} = mergeConfig;
|
|
953
974
|
editMask.visible = mask ? true : 0;
|
|
975
|
+
editor.setDimOthers(dimOthers);
|
|
976
|
+
editor.setBright(!!dimOthers || bright);
|
|
954
977
|
if (spread) draw.BoundsHelper.spread(bounds, spread);
|
|
955
978
|
if (this.view.worldOpacity) {
|
|
956
979
|
const {width: width, height: height} = bounds;
|
|
@@ -971,10 +994,10 @@ class EditBox extends draw.Group {
|
|
|
971
994
|
resizeL.visible = resizeP.visible && !hideResizeLines;
|
|
972
995
|
resizeP.visible = rotateP.visible = showPoints && !!middlePoint;
|
|
973
996
|
if ((i + 1) / 2 % 2) {
|
|
974
|
-
resizeL.width = width;
|
|
997
|
+
resizeL.width = width + resizeL.height;
|
|
975
998
|
if (hideOnSmall && resizeP.width * 2 > width) resizeP.visible = false;
|
|
976
999
|
} else {
|
|
977
|
-
resizeL.
|
|
1000
|
+
resizeL.width = height + resizeL.height;
|
|
978
1001
|
if (hideOnSmall && resizeP.width * 2 > height) resizeP.visible = false;
|
|
979
1002
|
}
|
|
980
1003
|
}
|
|
@@ -1050,10 +1073,9 @@ class EditBox extends draw.Group {
|
|
|
1050
1073
|
onDragStart(e) {
|
|
1051
1074
|
this.dragging = true;
|
|
1052
1075
|
const point = this.dragPoint = e.current, {pointType: pointType} = point;
|
|
1053
|
-
const {
|
|
1054
|
-
if (
|
|
1076
|
+
const {moveable: moveable, resizeable: resizeable, rotateable: rotateable, skewable: skewable} = this.mergeConfig;
|
|
1077
|
+
if (pointType === "move") {
|
|
1055
1078
|
moveable && (this.moving = true);
|
|
1056
|
-
editor.opacity = hideOnMove ? 0 : 1;
|
|
1057
1079
|
} else {
|
|
1058
1080
|
if (pointType.includes("rotate") || this.isHoldRotateKey(e) || !resizeable) {
|
|
1059
1081
|
rotateable && (this.rotating = true);
|
|
@@ -1062,69 +1084,74 @@ class EditBox extends draw.Group {
|
|
|
1062
1084
|
} else if (pointType === "resize") resizeable && (this.resizing = true);
|
|
1063
1085
|
if (pointType === "skew") skewable && (this.skewing = true);
|
|
1064
1086
|
}
|
|
1065
|
-
|
|
1066
|
-
dragStartData.y = e.y;
|
|
1067
|
-
dragStartData.point = {
|
|
1068
|
-
x: target.x,
|
|
1069
|
-
y: target.y
|
|
1070
|
-
};
|
|
1071
|
-
dragStartData.bounds = Object.assign({}, target.getLayoutBounds("box", "local"));
|
|
1072
|
-
dragStartData.rotation = target.rotation;
|
|
1073
|
-
if (pointType && pointType.includes("resize")) draw.ResizeEvent.resizingKeys = editor.leafList.keys;
|
|
1074
|
-
}
|
|
1075
|
-
onDragEnd(e) {
|
|
1076
|
-
if (this.moving && this.mergeConfig.dragLimitAnimate && this.target.dragBounds) this.transformTool.onMove(e);
|
|
1077
|
-
this.dragPoint = null;
|
|
1078
|
-
this.resetDoing();
|
|
1079
|
-
const {name: name, pointType: pointType} = e.current;
|
|
1080
|
-
if (name === "rect") this.editor.opacity = 1;
|
|
1081
|
-
if (pointType && pointType.includes("resize")) draw.ResizeEvent.resizingKeys = null;
|
|
1087
|
+
this.onTransformStart(e);
|
|
1082
1088
|
}
|
|
1083
1089
|
onDrag(e) {
|
|
1084
1090
|
const {transformTool: transformTool, moving: moving, resizing: resizing, rotating: rotating, skewing: skewing} = this;
|
|
1085
1091
|
if (moving) {
|
|
1086
1092
|
transformTool.onMove(e);
|
|
1087
|
-
updateMoveCursor(this);
|
|
1088
1093
|
} else if (resizing || rotating || skewing) {
|
|
1089
1094
|
const point = e.current;
|
|
1090
1095
|
if (point.pointType) this.enterPoint = point;
|
|
1091
1096
|
if (rotating) transformTool.onRotate(e);
|
|
1092
1097
|
if (resizing) transformTool.onScale(e);
|
|
1093
1098
|
if (skewing) transformTool.onSkew(e);
|
|
1094
|
-
updatePointCursor(this, e);
|
|
1095
1099
|
}
|
|
1100
|
+
updatePointCursor(this, e);
|
|
1096
1101
|
}
|
|
1097
|
-
|
|
1098
|
-
|
|
1102
|
+
onDragEnd(e) {
|
|
1103
|
+
this.onTransformEnd(e);
|
|
1104
|
+
this.dragPoint = null;
|
|
1105
|
+
}
|
|
1106
|
+
onTransformStart(e) {
|
|
1107
|
+
if (this.canUse) {
|
|
1108
|
+
if (this.moving) this.editor.opacity = this.mergedConfig.hideOnMove ? 0 : 1;
|
|
1109
|
+
if (this.resizing) draw.ResizeEvent.resizingKeys = this.editor.leafList.keys;
|
|
1110
|
+
const {dragStartData: dragStartData, target: target} = this;
|
|
1111
|
+
dragStartData.x = e.x;
|
|
1112
|
+
dragStartData.y = e.y;
|
|
1113
|
+
dragStartData.totalOffset = draw.getPointData();
|
|
1114
|
+
dragStartData.point = {
|
|
1115
|
+
x: target.x,
|
|
1116
|
+
y: target.y
|
|
1117
|
+
};
|
|
1118
|
+
dragStartData.bounds = Object.assign({}, target.getLayoutBounds("box", "local"));
|
|
1119
|
+
dragStartData.rotation = target.rotation;
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
onTransformEnd(e) {
|
|
1123
|
+
if (this.canUse) {
|
|
1124
|
+
if (this.canDragLimitAnimate && (e instanceof core.DragEvent || e instanceof core.MoveEvent)) this.transformTool.onMove(e);
|
|
1125
|
+
if (this.resizing) draw.ResizeEvent.resizingKeys = null;
|
|
1126
|
+
this.dragging = this.gesturing = this.moving = this.resizing = this.rotating = this.skewing = false;
|
|
1127
|
+
this.editor.opacity = 1;
|
|
1128
|
+
this.update();
|
|
1129
|
+
}
|
|
1099
1130
|
}
|
|
1100
1131
|
onMove(e) {
|
|
1101
1132
|
if (this.canGesture && e.moveType !== "drag") {
|
|
1102
1133
|
e.stop();
|
|
1103
|
-
if (draw.isString(this.
|
|
1134
|
+
if (draw.isString(this.mergedConfig.moveable)) {
|
|
1104
1135
|
this.gesturing = this.moving = true;
|
|
1105
|
-
this.transformTool.onMove(e);
|
|
1136
|
+
e.type === core.MoveEvent.START ? this.onTransformStart(e) : this.transformTool.onMove(e);
|
|
1106
1137
|
}
|
|
1107
1138
|
}
|
|
1108
1139
|
}
|
|
1109
|
-
onMoveEnd(e) {
|
|
1110
|
-
if (this.moving) this.transformTool.onMove(e);
|
|
1111
|
-
this.resetDoing();
|
|
1112
|
-
}
|
|
1113
1140
|
onScale(e) {
|
|
1114
1141
|
if (this.canGesture) {
|
|
1115
1142
|
e.stop();
|
|
1116
|
-
if (draw.isString(this.
|
|
1143
|
+
if (draw.isString(this.mergedConfig.resizeable)) {
|
|
1117
1144
|
this.gesturing = this.resizing = true;
|
|
1118
|
-
this.transformTool.onScale(e);
|
|
1145
|
+
e.type === core.ZoomEvent.START ? this.onTransformStart(e) : this.transformTool.onScale(e);
|
|
1119
1146
|
}
|
|
1120
1147
|
}
|
|
1121
1148
|
}
|
|
1122
1149
|
onRotate(e) {
|
|
1123
1150
|
if (this.canGesture) {
|
|
1124
1151
|
e.stop();
|
|
1125
|
-
if (draw.isString(this.
|
|
1152
|
+
if (draw.isString(this.mergedConfig.rotateable)) {
|
|
1126
1153
|
this.gesturing = this.rotating = true;
|
|
1127
|
-
this.transformTool.onRotate(e);
|
|
1154
|
+
e.type === core.RotateEvent.START ? this.onTransformStart(e) : this.transformTool.onRotate(e);
|
|
1128
1155
|
}
|
|
1129
1156
|
}
|
|
1130
1157
|
}
|
|
@@ -1137,8 +1164,7 @@ class EditBox extends draw.Group {
|
|
|
1137
1164
|
updatePointCursor(this, e);
|
|
1138
1165
|
}
|
|
1139
1166
|
onArrow(e) {
|
|
1140
|
-
|
|
1141
|
-
if (this.canUse && editor.editing && this.mergeConfig.keyEvent) {
|
|
1167
|
+
if (this.canUse && this.mergeConfig.keyEvent) {
|
|
1142
1168
|
let x = 0, y = 0;
|
|
1143
1169
|
const distance = e.shiftKey ? 10 : 1;
|
|
1144
1170
|
switch (e.code) {
|
|
@@ -1157,7 +1183,7 @@ class EditBox extends draw.Group {
|
|
|
1157
1183
|
case "ArrowRight":
|
|
1158
1184
|
x = distance;
|
|
1159
1185
|
}
|
|
1160
|
-
if (x || y) transformTool.move(x, y);
|
|
1186
|
+
if (x || y) this.transformTool.move(x, y);
|
|
1161
1187
|
}
|
|
1162
1188
|
}
|
|
1163
1189
|
onDoubleTap(e) {
|
|
@@ -1188,19 +1214,17 @@ class EditBox extends draw.Group {
|
|
|
1188
1214
|
listenPointEvents(point, type, direction) {
|
|
1189
1215
|
point.direction = direction;
|
|
1190
1216
|
point.pointType = type;
|
|
1191
|
-
|
|
1192
|
-
this.enterPoint = null;
|
|
1193
|
-
} ] ];
|
|
1194
|
-
if (point.name !== "circle") events.push([ core.PointerEvent.ENTER, e => {
|
|
1217
|
+
this.__eventIds.push(point.on_([ [ core.DragEvent.START, this.onDragStart, this ], [ core.DragEvent.DRAG, this.onDrag, this ], [ core.DragEvent.END, this.onDragEnd, this ], [ core.PointerEvent.ENTER, e => {
|
|
1195
1218
|
this.enterPoint = point, updatePointCursor(this, e);
|
|
1196
|
-
} ])
|
|
1197
|
-
|
|
1219
|
+
} ], [ core.PointerEvent.LEAVE, () => {
|
|
1220
|
+
this.enterPoint = null;
|
|
1221
|
+
} ] ]));
|
|
1198
1222
|
}
|
|
1199
1223
|
__listenEvents() {
|
|
1200
1224
|
const {rect: rect, editor: editor, __eventIds: events} = this;
|
|
1201
|
-
events.push(rect.on_([ [ core.
|
|
1225
|
+
events.push(rect.on_([ [ core.PointerEvent.DOUBLE_TAP, this.onDoubleTap, this ], [ core.PointerEvent.LONG_PRESS, this.onLongPress, this ] ]));
|
|
1202
1226
|
this.waitLeafer(() => {
|
|
1203
|
-
events.push(editor.app.on_([ [ [ core.KeyEvent.HOLD, core.KeyEvent.UP ], this.onKey, this ], [ core.KeyEvent.DOWN, this.onArrow, this ], [ core.MoveEvent.BEFORE_MOVE, this.onMove, this, true ], [ core.ZoomEvent.BEFORE_ZOOM, this.onScale, this, true ], [ core.RotateEvent.BEFORE_ROTATE, this.onRotate, this, true ], [ core.MoveEvent.END,
|
|
1227
|
+
events.push(editor.app.on_([ [ [ core.KeyEvent.HOLD, core.KeyEvent.UP ], this.onKey, this ], [ core.KeyEvent.DOWN, this.onArrow, this ], [ [ core.MoveEvent.START, core.MoveEvent.BEFORE_MOVE ], this.onMove, this, true ], [ [ core.ZoomEvent.START, core.ZoomEvent.BEFORE_ZOOM ], this.onScale, this, true ], [ [ core.RotateEvent.START, core.RotateEvent.BEFORE_ROTATE ], this.onRotate, this, true ], [ [ core.MoveEvent.END, core.ZoomEvent.END, core.RotateEvent.END ], this.onTransformEnd, this ] ]));
|
|
1204
1228
|
});
|
|
1205
1229
|
}
|
|
1206
1230
|
__removeListenEvents() {
|
|
@@ -1598,56 +1622,61 @@ class TransformTool {
|
|
|
1598
1622
|
const isMoveEnd = e.type === core.MoveEvent.END || e.type === core.DragEvent.END;
|
|
1599
1623
|
const axisDrag = draw.isString(target.draggable);
|
|
1600
1624
|
const checkLimitMove = !dragLimitAnimate || isMoveEnd || axisDrag;
|
|
1625
|
+
const total = {
|
|
1626
|
+
x: e.totalX,
|
|
1627
|
+
y: e.totalY
|
|
1628
|
+
};
|
|
1601
1629
|
if (e instanceof core.MoveEvent) {
|
|
1602
|
-
move
|
|
1603
|
-
if (checkLimitMove) core.DragEvent.limitMove(target, move);
|
|
1604
|
-
} else {
|
|
1605
|
-
const total = {
|
|
1606
|
-
x: e.totalX,
|
|
1607
|
-
y: e.totalY
|
|
1608
|
-
};
|
|
1609
|
-
if (e.shiftKey) {
|
|
1610
|
-
if (Math.abs(total.x) > Math.abs(total.y)) total.y = 0; else total.x = 0;
|
|
1611
|
-
}
|
|
1612
|
-
move = core.DragEvent.getValidMove(target, dragStartData.point, total, checkLimitMove);
|
|
1630
|
+
draw.PointHelper.move(total, target.getWorldPointByLocal(dragStartData.totalOffset, null, true));
|
|
1613
1631
|
}
|
|
1632
|
+
if (e.shiftKey) {
|
|
1633
|
+
if (Math.abs(total.x) > Math.abs(total.y)) total.y = 0; else total.x = 0;
|
|
1634
|
+
}
|
|
1635
|
+
move = core.DragEvent.getValidMove(target, dragStartData.point, total, checkLimitMove);
|
|
1614
1636
|
if (move.x || move.y) {
|
|
1615
1637
|
if (dragLimitAnimate && !axisDrag && isMoveEnd) draw.LeafHelper.animateMove(this, move, draw.isNumber(dragLimitAnimate) ? dragLimitAnimate : .3); else this.move(move);
|
|
1616
1638
|
}
|
|
1617
1639
|
}
|
|
1618
1640
|
onScale(e) {
|
|
1619
1641
|
const {target: target, mergeConfig: mergeConfig, single: single, dragStartData: dragStartData} = this.editBox;
|
|
1620
|
-
let {around: around, lockRatio: lockRatio, flipable: flipable, editSize: editSize} = mergeConfig;
|
|
1642
|
+
let {around: around, lockRatio: lockRatio, flipable: flipable, editSize: editSize} = mergeConfig, totalMove;
|
|
1621
1643
|
if (e instanceof core.ZoomEvent) {
|
|
1622
|
-
|
|
1644
|
+
around = target.getBoxPoint(e);
|
|
1645
|
+
totalMove = e.totalScale;
|
|
1623
1646
|
} else {
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1647
|
+
totalMove = e.getInnerTotal(target);
|
|
1648
|
+
}
|
|
1649
|
+
const {direction: direction} = e.current;
|
|
1650
|
+
if (e.shiftKey || target.lockRatio) lockRatio = true;
|
|
1651
|
+
const data = EditDataHelper.getScaleData(target, dragStartData.bounds, direction, totalMove, lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, !single || editSize === "scale");
|
|
1652
|
+
const targetX = target.x, targetY = target.y;
|
|
1653
|
+
if (e instanceof core.DragEvent && this.editTool && this.editTool.onScaleWithDrag) {
|
|
1654
|
+
data.drag = e;
|
|
1655
|
+
this.scaleWithDrag(data);
|
|
1656
|
+
} else {
|
|
1657
|
+
this.scaleOf(data.origin, data.scaleX, data.scaleY);
|
|
1633
1658
|
}
|
|
1659
|
+
draw.PointHelper.move(dragStartData.totalOffset, target.x - targetX, target.y - targetY);
|
|
1634
1660
|
}
|
|
1635
1661
|
onRotate(e) {
|
|
1636
1662
|
const {target: target, mergeConfig: mergeConfig, dragStartData: dragStartData} = this.editBox;
|
|
1637
|
-
const {around: around, rotateAround: rotateAround, rotateGap: rotateGap} = mergeConfig;
|
|
1663
|
+
const {around: around, rotateAround: rotateAround, rotateGap: rotateGap, diagonalRotateKey: diagonalRotateKey} = mergeConfig;
|
|
1638
1664
|
const {direction: direction} = e.current;
|
|
1639
1665
|
let origin, rotation;
|
|
1640
1666
|
if (e instanceof core.RotateEvent) {
|
|
1641
1667
|
rotation = e.rotation;
|
|
1642
1668
|
origin = rotateAround ? draw.AroundHelper.getPoint(rotateAround, target.boxBounds) : target.getBoxPoint(e);
|
|
1643
1669
|
} else {
|
|
1644
|
-
const
|
|
1670
|
+
const isDiagonalRotate = diagonalRotateKey ? e.isHoldKeys(diagonalRotateKey) : e.shiftKey;
|
|
1671
|
+
const data = EditDataHelper.getRotateData(target, direction, e, dragStartData, isDiagonalRotate ? null : rotateAround || target.around || target.origin || around || "center");
|
|
1645
1672
|
rotation = dragStartData.rotation + data.rotation - target.rotation;
|
|
1646
1673
|
origin = data.origin;
|
|
1647
1674
|
}
|
|
1648
1675
|
rotation = draw.MathHelper.float(draw.MathHelper.getGapRotation(rotation, rotateGap, target.rotation), 2);
|
|
1649
1676
|
if (!rotation) return;
|
|
1677
|
+
const targetX = target.x, targetY = target.y;
|
|
1650
1678
|
this.rotateOf(origin, rotation);
|
|
1679
|
+
draw.PointHelper.move(dragStartData.totalOffset, target.x - targetX, target.y - targetY);
|
|
1651
1680
|
}
|
|
1652
1681
|
onSkew(e) {
|
|
1653
1682
|
const {target: target, mergeConfig: mergeConfig} = this.editBox;
|
|
@@ -1926,6 +1955,16 @@ exports.Editor = class Editor extends draw.Group {
|
|
|
1926
1955
|
shiftItem(item) {
|
|
1927
1956
|
this.hasItem(item) ? this.removeItem(item) : this.addItem(item);
|
|
1928
1957
|
}
|
|
1958
|
+
setDimOthers(value, attrName = "dim", list) {
|
|
1959
|
+
if (!list) {
|
|
1960
|
+
const {dimTarget: dimTarget, targetLeafer: targetLeafer} = this;
|
|
1961
|
+
list = dimTarget ? draw.isArray(dimTarget) ? dimTarget : [ dimTarget ] : [ targetLeafer ];
|
|
1962
|
+
}
|
|
1963
|
+
if (list[0] && list[0][attrName] !== (value || false)) list.forEach(item => draw.DataHelper.stintSet(item, attrName, value));
|
|
1964
|
+
}
|
|
1965
|
+
setBright(value) {
|
|
1966
|
+
this.setDimOthers(value, "bright", this.list);
|
|
1967
|
+
}
|
|
1929
1968
|
update() {
|
|
1930
1969
|
if (this.editing) {
|
|
1931
1970
|
if (!this.element.parent) return this.cancel();
|
|
@@ -2148,10 +2187,10 @@ exports.Editor = class Editor extends draw.Group {
|
|
|
2148
2187
|
|
|
2149
2188
|
__decorate([ mergeConfigAttr() ], exports.Editor.prototype, "mergeConfig", void 0);
|
|
2150
2189
|
|
|
2151
|
-
__decorate([ targetAttr(onHover) ], exports.Editor.prototype, "hoverTarget", void 0);
|
|
2152
|
-
|
|
2153
2190
|
__decorate([ targetAttr(onTarget) ], exports.Editor.prototype, "target", void 0);
|
|
2154
2191
|
|
|
2192
|
+
__decorate([ targetAttr(onHover) ], exports.Editor.prototype, "hoverTarget", void 0);
|
|
2193
|
+
|
|
2155
2194
|
exports.Editor = __decorate([ core.useModule(TransformTool, [ "editBox", "editTool", "emitEvent" ]) ], exports.Editor);
|
|
2156
2195
|
|
|
2157
2196
|
class InnerEditor {
|