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