@leafer-in/editor 1.6.6 → 1.7.0

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,5 +1,5 @@
1
1
  import { Event, defineKey, isNull, MatrixHelper, BoundsHelper, LeafBoundsHelper, getMatrixData, getBoundsData, UI, Paint, Group, Rect, Bounds, LeafList, Direction9, AroundHelper, MathHelper, PointHelper, Box, ResizeEvent, Text, Matrix, Debug, LeafHelper, PropertyEvent, DataHelper, Plugin, RenderEvent, getPointData, Creator, dataType } from '@leafer-ui/draw';
2
- import { PointerEvent, DragEvent, MoveEvent, ZoomEvent, RotateEvent, KeyEvent } from '@leafer-ui/core';
2
+ import { PointerEvent, DragEvent, MoveEvent, ZoomEvent, KeyEvent, RotateEvent, useModule } from '@leafer-ui/core';
3
3
  import '@leafer-in/resize';
4
4
 
5
5
  /******************************************************************************
@@ -45,41 +45,10 @@ class EditorEvent extends Event {
45
45
  }
46
46
  EditorEvent.BEFORE_SELECT = 'editor.before_select';
47
47
  EditorEvent.SELECT = 'editor.select';
48
+ EditorEvent.AFTER_SELECT = 'editor.after_select';
48
49
  EditorEvent.BEFORE_HOVER = 'editor.before_hover';
49
50
  EditorEvent.HOVER = 'editor.hover';
50
51
 
51
- class EditorMoveEvent extends EditorEvent {
52
- constructor(type, data) {
53
- super(type, data);
54
- }
55
- }
56
- EditorMoveEvent.BEFORE_MOVE = 'editor.before_move';
57
- EditorMoveEvent.MOVE = 'editor.move';
58
-
59
- class EditorScaleEvent extends EditorEvent {
60
- constructor(type, data) {
61
- super(type, data);
62
- }
63
- }
64
- EditorScaleEvent.BEFORE_SCALE = 'editor.before_scale';
65
- EditorScaleEvent.SCALE = 'editor.scale';
66
-
67
- class EditorRotateEvent extends EditorEvent {
68
- constructor(type, data) {
69
- super(type, data);
70
- }
71
- }
72
- EditorRotateEvent.BEFORE_ROTATE = 'editor.before_rotate';
73
- EditorRotateEvent.ROTATE = 'editor.rotate';
74
-
75
- class EditorSkewEvent extends EditorEvent {
76
- constructor(type, data) {
77
- super(type, data);
78
- }
79
- }
80
- EditorSkewEvent.BEFORE_SKEW = 'editor.before_skew';
81
- EditorSkewEvent.SKEW = 'editor.skew';
82
-
83
52
  function targetAttr(fn) {
84
53
  return (target, key) => {
85
54
  const privateKey = '_' + key;
@@ -490,16 +459,16 @@ const { topLeft, top, topRight, right: right$1, bottomRight, bottom, bottomLeft,
490
459
  const { toPoint } = AroundHelper;
491
460
  const { within } = MathHelper;
492
461
  const EditDataHelper = {
493
- getScaleData(element, startBounds, direction, totalMove, lockRatio, around, flipable, scaleMode) {
462
+ getScaleData(target, startBounds, direction, totalMove, lockRatio, around, flipable, scaleMode) {
494
463
  let align, origin = {}, scaleX = 1, scaleY = 1;
495
- const { boxBounds, widthRange, heightRange, dragBounds, worldBoxBounds } = element;
464
+ const { boxBounds, widthRange, heightRange, dragBounds, worldBoxBounds } = target;
496
465
  const { width, height } = startBounds;
497
466
  if (around) {
498
467
  totalMove.x *= 2;
499
468
  totalMove.y *= 2;
500
469
  }
501
- const originChangedScaleX = element.scaleX / startBounds.scaleX;
502
- const originChangedScaleY = element.scaleY / startBounds.scaleY;
470
+ const originChangedScaleX = target.scaleX / startBounds.scaleX;
471
+ const originChangedScaleY = target.scaleY / startBounds.scaleY;
503
472
  const signX = originChangedScaleX < 0 ? -1 : 1;
504
473
  const signY = originChangedScaleY < 0 ? -1 : 1;
505
474
  const changedScaleX = scaleMode ? originChangedScaleX : signX * boxBounds.width / width;
@@ -575,7 +544,7 @@ const EditDataHelper = {
575
544
  if (useScaleY)
576
545
  scaleY /= changedScaleY;
577
546
  if (!flipable) {
578
- const { worldTransform } = element;
547
+ const { worldTransform } = target;
579
548
  if (scaleX < 0)
580
549
  scaleX = 1 / boxBounds.width / worldTransform.scaleX;
581
550
  if (scaleY < 0)
@@ -583,9 +552,9 @@ const EditDataHelper = {
583
552
  }
584
553
  toPoint(around || align, boxBounds, origin, true);
585
554
  if (dragBounds) {
586
- const allowBounds = dragBounds === 'parent' ? element.parent.boxBounds : dragBounds;
587
- const localBounds = new Bounds(element.__localBoxBounds);
588
- localBounds.scaleOf(element.getLocalPointByInner(origin), scaleX, scaleY);
555
+ const allowBounds = dragBounds === 'parent' ? target.parent.boxBounds : dragBounds;
556
+ const localBounds = new Bounds(target.__localBoxBounds);
557
+ localBounds.scaleOf(target.getLocalPointByInner(origin), scaleX, scaleY);
589
558
  if (!BoundsHelper.includes(allowBounds, localBounds)) {
590
559
  const realBounds = localBounds.getIntersect(allowBounds);
591
560
  const fitScaleX = realBounds.width / localBounds.width, fitScaleY = realBounds.height / localBounds.height;
@@ -596,11 +565,11 @@ const EditDataHelper = {
596
565
  }
597
566
  }
598
567
  if (useScaleX && widthRange) {
599
- const nowWidth = boxBounds.width * element.scaleX;
568
+ const nowWidth = boxBounds.width * target.scaleX;
600
569
  scaleX = within(nowWidth * scaleX, widthRange) / nowWidth;
601
570
  }
602
571
  if (useScaleY && heightRange) {
603
- const nowHeight = boxBounds.height * element.scaleY;
572
+ const nowHeight = boxBounds.height * target.scaleY;
604
573
  scaleY = within(nowHeight * scaleY, heightRange) / nowHeight;
605
574
  }
606
575
  if (useScaleX && Math.abs(scaleX * worldBoxBounds.width) < 1)
@@ -611,7 +580,7 @@ const EditDataHelper = {
611
580
  scaleY = scaleX = Math.min(scaleX, scaleY);
612
581
  return { origin, scaleX, scaleY, direction, lockRatio, around };
613
582
  },
614
- getRotateData(bounds, direction, current, last, around) {
583
+ getRotateData(target, direction, current, last, around) {
615
584
  let align, origin = {};
616
585
  switch (direction) {
617
586
  case topLeft:
@@ -629,8 +598,8 @@ const EditDataHelper = {
629
598
  default:
630
599
  align = 'center';
631
600
  }
632
- toPoint(around || align, bounds, origin, true);
633
- return { origin, rotation: PointHelper.getRotation(last, origin, current) };
601
+ toPoint(around || align, target.boxBounds, origin, true);
602
+ return { origin, rotation: PointHelper.getRotation(last, target.getWorldPointByBox(origin), current) };
634
603
  },
635
604
  getSkewData(bounds, direction, move, around) {
636
605
  let align, origin = {}, skewX = 0, skewY = 0;
@@ -727,9 +696,9 @@ const EditDataHelper = {
727
696
  };
728
697
 
729
698
  const cacheCursors = {};
730
- function updateCursor(editor, e) {
731
- const { editBox } = editor, point = editBox.enterPoint;
732
- if (!point || !editor.editing || !editBox.visible)
699
+ function updateCursor(editBox, e) {
700
+ const { enterPoint: point } = editBox;
701
+ if (!point || !editBox.editor.editing || !editBox.visible)
733
702
  return;
734
703
  if (point.name === 'circle')
735
704
  return;
@@ -738,9 +707,8 @@ function updateCursor(editor, e) {
738
707
  point.cursor = 'pointer';
739
708
  return;
740
709
  }
741
- let { rotation } = editBox;
742
- const { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editor.mergeConfig;
743
- const { pointType } = point, { flippedX, flippedY } = editBox;
710
+ let { rotation, flippedX, flippedY } = editBox;
711
+ const { pointType } = point, { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editBox.mergeConfig;
744
712
  let showResize = pointType.includes('resize');
745
713
  if (showResize && rotateable && (e.metaKey || e.ctrlKey || !resizeable))
746
714
  showResize = false;
@@ -757,9 +725,9 @@ function updateCursor(editor, e) {
757
725
  cacheCursors[key] = point.cursor = { url: toDataURL(url, rotation), x, y };
758
726
  }
759
727
  }
760
- function updateMoveCursor(editor) {
761
- const { moveCursor, moveable } = editor.mergeConfig;
762
- editor.editBox.rect.cursor = moveable ? moveCursor : undefined;
728
+ function updateMoveCursor(editBox) {
729
+ const { moveCursor, moveable } = editBox.mergeConfig;
730
+ editBox.rect.cursor = moveable ? moveCursor : undefined;
763
731
  }
764
732
  function toDataURL(svg, rotation) {
765
733
  return '"data:image/svg+xml,' + encodeURIComponent(svg.replace('{{rotation}}', rotation.toString())) + '"';
@@ -774,6 +742,15 @@ class EditPoint extends Box {
774
742
 
775
743
  const fourDirection = ['top', 'right', 'bottom', 'left'], editConfig = undefined;
776
744
  class EditBox extends Group {
745
+ get mergeConfig() {
746
+ const { config } = this, { mergeConfig } = this.editor;
747
+ return this.mergedConfig = config ? Object.assign(Object.assign({}, mergeConfig), config) : mergeConfig;
748
+ }
749
+ get target() { return this._target || this.editor.element; }
750
+ set target(target) { this._target = target; }
751
+ get single() { return !!this._target || this.editor.single; }
752
+ get transformTool() { return this._transformTool || this.editor; }
753
+ set transformTool(tool) { this._transformTool = tool; }
777
754
  get flipped() { return this.flippedX || this.flippedY; }
778
755
  get flippedX() { return this.scaleX < 0; }
779
756
  get flippedY() { return this.scaleY < 0; }
@@ -816,8 +793,7 @@ class EditBox extends Group {
816
793
  this.add(view);
817
794
  }
818
795
  load() {
819
- const { mergeConfig, element, single } = this.editor;
820
- const { rect, circle, resizePoints } = this;
796
+ const { target, mergeConfig, single, rect, circle, resizePoints } = this;
821
797
  const { stroke, strokeWidth } = mergeConfig;
822
798
  const pointsStyle = this.getPointsStyle();
823
799
  const middlePointsStyle = this.getMiddlePointsStyle();
@@ -830,18 +806,26 @@ class EditBox extends Group {
830
806
  }
831
807
  circle.set(this.getPointStyle(mergeConfig.circle || mergeConfig.rotatePoint || pointsStyle[0]));
832
808
  rect.set(Object.assign({ stroke, strokeWidth, editConfig }, (mergeConfig.rect || {})));
833
- rect.hittable = !single;
834
- rect.syncEventer = single && this.editor;
835
- if (single) {
836
- element.syncEventer = rect;
837
- this.app.interaction.bottomList = [{ target: rect, proxy: element }];
809
+ const syncEventer = single && this.transformTool.editTool;
810
+ rect.hittable = !syncEventer;
811
+ rect.syncEventer = syncEventer && this.editor;
812
+ if (syncEventer) {
813
+ target.syncEventer = rect;
814
+ this.app.interaction.bottomList = [{ target: rect, proxy: target }];
838
815
  }
816
+ updateMoveCursor(this);
817
+ }
818
+ update() {
819
+ const { editor } = this;
820
+ const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = this.target.getLayoutBounds('box', editor, true);
821
+ this.set({ x, y, scaleX, scaleY, rotation, skewX, skewY });
822
+ this.updateBounds({ x: 0, y: 0, width, height });
839
823
  }
840
- update(bounds) {
841
- const { rect, circle, buttons, resizePoints, rotatePoints, resizeLines, editor } = this;
842
- const { mergeConfig, element, multiple, editMask } = editor;
824
+ updateBounds(bounds) {
825
+ const { editMask } = this.editor;
826
+ const { mergeConfig, single, rect, circle, buttons, resizePoints, rotatePoints, resizeLines } = this;
843
827
  const { middlePoint, resizeable, rotateable, hideOnSmall, editBox, mask } = mergeConfig;
844
- this.visible = !element.locked;
828
+ this.visible = !this.target.locked;
845
829
  editMask.visible = mask ? true : 0;
846
830
  if (this.view.worldOpacity) {
847
831
  const { width, height } = bounds;
@@ -875,25 +859,25 @@ class EditBox extends Group {
875
859
  }
876
860
  circle.visible = showPoints && rotateable && !!(mergeConfig.circle || mergeConfig.rotatePoint);
877
861
  if (circle.visible)
878
- this.layoutCircle(mergeConfig);
862
+ this.layoutCircle();
879
863
  if (rect.path)
880
864
  rect.path = null;
881
- rect.set(Object.assign(Object.assign({}, bounds), { visible: multiple ? true : editBox }));
865
+ rect.set(Object.assign(Object.assign({}, bounds), { visible: single ? editBox : true }));
882
866
  buttons.visible = showPoints && buttons.children.length > 0 || 0;
883
867
  if (buttons.visible)
884
- this.layoutButtons(mergeConfig);
868
+ this.layoutButtons();
885
869
  }
886
870
  else
887
871
  rect.set(bounds);
888
872
  }
889
- layoutCircle(config) {
890
- const { circleDirection, circleMargin, buttonsMargin, buttonsDirection, middlePoint } = config;
873
+ layoutCircle() {
874
+ const { circleDirection, circleMargin, buttonsMargin, buttonsDirection, middlePoint } = this.mergedConfig;
891
875
  const direction = fourDirection.indexOf(circleDirection || ((this.buttons.children.length && buttonsDirection === 'bottom') ? 'top' : 'bottom'));
892
876
  this.setButtonPosition(this.circle, direction, circleMargin || buttonsMargin, !!middlePoint);
893
877
  }
894
- layoutButtons(config) {
878
+ layoutButtons() {
895
879
  const { buttons } = this;
896
- const { buttonsDirection, buttonsFixed, buttonsMargin, middlePoint } = config;
880
+ const { buttonsDirection, buttonsFixed, buttonsMargin, middlePoint } = this.mergedConfig;
897
881
  const { flippedX, flippedY } = this;
898
882
  let index = fourDirection.indexOf(buttonsDirection);
899
883
  if ((index % 2 && flippedX) || ((index + 1) % 2 && flippedY)) {
@@ -926,16 +910,16 @@ class EditBox extends Group {
926
910
  this.visible = false;
927
911
  }
928
912
  getPointStyle(userStyle) {
929
- const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.editor.mergeConfig;
913
+ const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.mergedConfig;
930
914
  const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', width: pointSize, height: pointSize, cornerRadius: pointRadius, offsetX: 0, offsetY: 0, editConfig };
931
915
  return userStyle ? Object.assign(defaultStyle, userStyle) : defaultStyle;
932
916
  }
933
917
  getPointsStyle() {
934
- const { point } = this.editor.mergeConfig;
918
+ const { point } = this.mergedConfig;
935
919
  return point instanceof Array ? point : [point];
936
920
  }
937
921
  getMiddlePointsStyle() {
938
- const { middlePoint } = this.editor.mergeConfig;
922
+ const { middlePoint } = this.mergedConfig;
939
923
  return middlePoint instanceof Array ? middlePoint : (middlePoint ? [middlePoint] : this.getPointsStyle());
940
924
  }
941
925
  onSelect(e) {
@@ -948,16 +932,16 @@ class EditBox extends Group {
948
932
  onDragStart(e) {
949
933
  this.dragging = true;
950
934
  const point = this.dragPoint = e.current, { pointType } = point;
951
- const { editor, dragStartData } = this, { element } = editor;
935
+ const { editor, dragStartData } = this, { target } = this;
952
936
  if (point.name === 'rect') {
953
937
  this.moving = true;
954
- editor.opacity = editor.mergeConfig.hideOnMove ? 0 : 1;
938
+ editor.opacity = this.mergeConfig.hideOnMove ? 0 : 1;
955
939
  }
956
940
  dragStartData.x = e.x;
957
941
  dragStartData.y = e.y;
958
- dragStartData.point = { x: element.x, y: element.y };
959
- dragStartData.bounds = Object.assign({}, element.getLayoutBounds('box', 'local'));
960
- dragStartData.rotation = element.rotation;
942
+ dragStartData.point = { x: target.x, y: target.y };
943
+ dragStartData.bounds = Object.assign({}, target.getLayoutBounds('box', 'local'));
944
+ dragStartData.rotation = target.rotation;
961
945
  if (pointType && pointType.includes('resize'))
962
946
  ResizeEvent.resizingKeys = editor.leafList.keys;
963
947
  }
@@ -972,22 +956,31 @@ class EditBox extends Group {
972
956
  ResizeEvent.resizingKeys = null;
973
957
  }
974
958
  onDrag(e) {
975
- const { editor } = this;
976
- const { pointType } = this.enterPoint = e.current;
977
- if (pointType.includes('rotate') || e.metaKey || e.ctrlKey || !editor.mergeConfig.resizeable) {
978
- editor.onRotate(e);
979
- if (pointType === 'resize-rotate')
980
- editor.onScale(e);
981
- }
982
- else if (pointType === 'resize')
983
- editor.onScale(e);
984
- if (pointType === 'skew')
985
- editor.onSkew(e);
986
- updateCursor(editor, e);
959
+ const { transformTool } = this, point = e.current;
960
+ if (point.name === 'rect') {
961
+ transformTool.onMove(e);
962
+ updateMoveCursor(this);
963
+ }
964
+ else {
965
+ const { pointType } = this.enterPoint = point;
966
+ if (pointType.includes('rotate') || e.metaKey || e.ctrlKey || !this.mergeConfig.resizeable) {
967
+ transformTool.onRotate(e);
968
+ if (pointType === 'resize-rotate')
969
+ transformTool.onScale(e);
970
+ }
971
+ else if (pointType === 'resize')
972
+ transformTool.onScale(e);
973
+ if (pointType === 'skew')
974
+ transformTool.onSkew(e);
975
+ updateCursor(this, e);
976
+ }
977
+ }
978
+ onKey(e) {
979
+ updateCursor(this, e);
987
980
  }
988
981
  onArrow(e) {
989
982
  const { editor } = this;
990
- if (editor.editing && editor.mergeConfig.keyEvent) {
983
+ if (editor.editing && this.mergeConfig.keyEvent) {
991
984
  let x = 0, y = 0;
992
985
  const distance = e.shiftKey ? 10 : 1;
993
986
  switch (e.code) {
@@ -1008,27 +1001,28 @@ class EditBox extends Group {
1008
1001
  }
1009
1002
  }
1010
1003
  onDoubleTap(e) {
1011
- if (this.editor.mergeConfig.openInner === 'double')
1004
+ const { openInner, preventEditInner } = this.mergeConfig;
1005
+ if (openInner === 'double' && !preventEditInner)
1012
1006
  this.openInner(e);
1013
1007
  }
1014
1008
  onLongPress(e) {
1015
- if (this.editor.mergeConfig.openInner === 'long')
1009
+ const { openInner, preventEditInner } = this.mergeConfig;
1010
+ if (openInner === 'long' && preventEditInner)
1016
1011
  this.openInner(e);
1017
1012
  }
1018
1013
  openInner(e) {
1019
- const { editor } = this;
1020
- if (editor.single) {
1021
- const { element } = editor;
1022
- if (element.locked)
1014
+ const { editor, target } = this;
1015
+ if (this.single) {
1016
+ if (target.locked)
1023
1017
  return;
1024
- if (element.isBranch && !element.editInner) {
1025
- if (element.textBox) {
1026
- const { children } = element;
1018
+ if (target.isBranch && !target.editInner) {
1019
+ if (target.textBox) {
1020
+ const { children } = target;
1027
1021
  const find = children.find(item => item.editable && item instanceof Text) || children.find(item => item instanceof Text);
1028
1022
  if (find)
1029
1023
  return editor.openInnerEditor(find);
1030
1024
  }
1031
- editor.openGroup(element);
1025
+ editor.openGroup(target);
1032
1026
  editor.target = editor.selector.findDeepOne(e);
1033
1027
  }
1034
1028
  else {
@@ -1037,7 +1031,6 @@ class EditBox extends Group {
1037
1031
  }
1038
1032
  }
1039
1033
  listenPointEvents(point, type, direction) {
1040
- const { editor } = this;
1041
1034
  point.direction = direction;
1042
1035
  point.pointType = type;
1043
1036
  const events = [
@@ -1047,19 +1040,25 @@ class EditBox extends Group {
1047
1040
  [PointerEvent.LEAVE, () => { this.enterPoint = null; }],
1048
1041
  ];
1049
1042
  if (point.name !== 'circle')
1050
- events.push([PointerEvent.ENTER, (e) => { this.enterPoint = point, updateCursor(editor, e); }]);
1043
+ events.push([PointerEvent.ENTER, (e) => { this.enterPoint = point, updateCursor(this, e); }]);
1051
1044
  this.__eventIds.push(point.on_(events));
1052
1045
  }
1053
1046
  __listenEvents() {
1054
- const { rect, editor } = this;
1055
- this.__eventIds.push(editor.on_(EditorEvent.SELECT, this.onSelect, this), rect.on_([
1047
+ const { rect, editor, __eventIds: events } = this;
1048
+ events.push(editor.on_(EditorEvent.SELECT, this.onSelect, this), rect.on_([
1056
1049
  [DragEvent.START, this.onDragStart, this],
1057
- [DragEvent.DRAG, editor.onMove, editor],
1050
+ [DragEvent.DRAG, this.onDrag, this],
1058
1051
  [DragEvent.END, this.onDragEnd, this],
1059
- [PointerEvent.ENTER, () => updateMoveCursor(editor)],
1052
+ [PointerEvent.ENTER, () => updateMoveCursor(this)],
1060
1053
  [PointerEvent.DOUBLE_TAP, this.onDoubleTap, this],
1061
1054
  [PointerEvent.LONG_PRESS, this.onLongPress, this]
1062
1055
  ]));
1056
+ this.waitLeafer(() => {
1057
+ events.push(editor.app.on_([
1058
+ [[KeyEvent.HOLD, KeyEvent.UP], this.onKey, this],
1059
+ [KeyEvent.DOWN, this.onArrow, this]
1060
+ ]));
1061
+ });
1063
1062
  }
1064
1063
  __removeListenEvents() {
1065
1064
  this.off_(this.__eventIds);
@@ -1090,11 +1089,12 @@ class EditMask extends UI {
1090
1089
  if (options.bounds && !options.bounds.hit(editor.editBox.rect.__world, options.matrix))
1091
1090
  return;
1092
1091
  canvas.saveBlendMode('destination-out');
1092
+ options = Object.assign(Object.assign({}, options), { shape: true });
1093
1093
  editor.list.forEach(item => {
1094
- item.__renderShape(canvas, options);
1095
- const { __box, parent } = item;
1096
- if ((item = __box) || ((item = parent) && parent.textBox))
1097
- item.__renderShape(canvas, options);
1094
+ item.__render(canvas, options);
1095
+ const { parent } = item;
1096
+ if (parent && parent.textBox)
1097
+ parent.__renderShape(canvas, options);
1098
1098
  });
1099
1099
  canvas.restoreBlendMode();
1100
1100
  }
@@ -1189,7 +1189,7 @@ const config = {
1189
1189
  const bounds = new Bounds();
1190
1190
  function simulate(editor) {
1191
1191
  const { simulateTarget, list } = editor;
1192
- const { zoomLayer } = list[0].leafer.zoomLayer;
1192
+ const { zoomLayer } = list[0].leafer;
1193
1193
  simulateTarget.safeChange(() => {
1194
1194
  bounds.setListWithFn(list, (leaf) => leaf.getBounds('box', 'page'));
1195
1195
  if (bounds.width === 0)
@@ -1211,15 +1211,14 @@ function onTarget(editor, oldValue) {
1211
1211
  else {
1212
1212
  editor.simulateTarget.remove();
1213
1213
  editor.leafList.reset();
1214
- editor.closeInnerEditor();
1215
1214
  }
1216
- editor.emitEvent(new EditorEvent(EditorEvent.SELECT, { editor, value: target, oldValue }));
1215
+ editor.closeInnerEditor();
1216
+ const data = { editor, value: target, oldValue };
1217
+ editor.emitEvent(new EditorEvent(EditorEvent.SELECT, data));
1217
1218
  editor.checkOpenedGroups();
1218
1219
  if (editor.editing) {
1219
1220
  editor.waitLeafer(() => {
1220
- updateMoveCursor(editor);
1221
1221
  editor.updateEditTool();
1222
- editor.update();
1223
1222
  editor.listenTargetEvents();
1224
1223
  });
1225
1224
  }
@@ -1227,6 +1226,7 @@ function onTarget(editor, oldValue) {
1227
1226
  editor.updateEditTool();
1228
1227
  editor.removeTargetEvents();
1229
1228
  }
1229
+ editor.emitEvent(new EditorEvent(EditorEvent.AFTER_SELECT, data));
1230
1230
  }
1231
1231
  function onHover(editor, oldValue) {
1232
1232
  editor.emitEvent(new EditorEvent(EditorEvent.HOVER, { editor, value: editor.hoverTarget, oldValue }));
@@ -1398,93 +1398,45 @@ class SimulateElement extends Rect {
1398
1398
  }
1399
1399
  }
1400
1400
 
1401
- class Editor extends Group {
1402
- get list() { return this.leafList.list; }
1403
- get dragHoverExclude() { return [this.editBox.rect]; }
1404
- get editing() { return !!this.list.length; }
1405
- get groupOpening() { return !!this.openedGroupList.length; }
1406
- get multiple() { return this.list.length > 1; }
1407
- get single() { return this.list.length === 1; }
1408
- get dragging() { return this.editBox.dragging; }
1409
- get moving() { return this.editBox.moving; }
1410
- get dragPoint() { return this.editBox.dragPoint; }
1411
- get element() { return this.multiple ? this.simulateTarget : this.list[0]; }
1412
- get buttons() { return this.editBox.buttons; }
1413
- constructor(userConfig, data) {
1414
- super(data);
1415
- this.leafList = new LeafList();
1416
- this.openedGroupList = new LeafList();
1417
- this.simulateTarget = new SimulateElement(this);
1418
- this.editBox = new EditBox(this);
1419
- this.editToolList = {};
1420
- this.selector = new EditSelect(this);
1421
- this.editMask = new EditMask(this);
1422
- this.targetEventIds = [];
1423
- let mergedConfig = DataHelper.clone(config);
1424
- if (userConfig)
1425
- mergedConfig = DataHelper.default(userConfig, mergedConfig);
1426
- this.mergedConfig = this.config = mergedConfig;
1427
- this.addMany(this.editMask, this.selector, this.editBox);
1428
- if (!Plugin.has('resize'))
1429
- this.config.editSize = 'scale';
1430
- }
1431
- select(target) {
1432
- this.target = target;
1433
- }
1434
- cancel() {
1435
- this.target = null;
1436
- }
1437
- hasItem(item) {
1438
- return this.leafList.has(item);
1439
- }
1440
- addItem(item) {
1441
- if (!this.hasItem(item) && !item.locked)
1442
- this.leafList.add(item), this.target = this.leafList.list;
1443
- }
1444
- removeItem(item) {
1445
- if (this.hasItem(item))
1446
- this.leafList.remove(item), this.target = this.leafList.list;
1447
- }
1448
- shiftItem(item) {
1449
- this.hasItem(item) ? this.removeItem(item) : this.addItem(item);
1450
- }
1451
- update() {
1452
- if (this.editing) {
1453
- if (!this.element.parent)
1454
- return this.cancel();
1455
- if (this.innerEditing)
1456
- this.innerEditor.update();
1457
- this.editTool.update();
1458
- this.selector.update();
1459
- }
1401
+ class EditorMoveEvent extends EditorEvent {
1402
+ constructor(type, data) {
1403
+ super(type, data);
1460
1404
  }
1461
- updateEditBox() {
1462
- if (this.multiple)
1463
- simulate(this);
1464
- this.update();
1405
+ }
1406
+ EditorMoveEvent.BEFORE_MOVE = 'editor.before_move';
1407
+ EditorMoveEvent.MOVE = 'editor.move';
1408
+
1409
+ class EditorScaleEvent extends EditorEvent {
1410
+ constructor(type, data) {
1411
+ super(type, data);
1465
1412
  }
1466
- updateEditTool() {
1467
- const tool = this.editTool;
1468
- if (tool) {
1469
- this.editBox.unload();
1470
- tool.unload();
1471
- this.editTool = null;
1472
- }
1473
- if (this.editing) {
1474
- const tag = this.single ? this.list[0].editOuter : 'EditTool';
1475
- this.editTool = this.editToolList[tag] = this.editToolList[tag] || EditToolCreator.get(tag, this);
1476
- this.editBox.load();
1477
- this.editTool.load();
1478
- }
1413
+ }
1414
+ EditorScaleEvent.BEFORE_SCALE = 'editor.before_scale';
1415
+ EditorScaleEvent.SCALE = 'editor.scale';
1416
+
1417
+ class EditorRotateEvent extends EditorEvent {
1418
+ constructor(type, data) {
1419
+ super(type, data);
1479
1420
  }
1480
- getEditSize(_ui) {
1481
- return this.mergeConfig.editSize;
1421
+ }
1422
+ EditorRotateEvent.BEFORE_ROTATE = 'editor.before_rotate';
1423
+ EditorRotateEvent.ROTATE = 'editor.rotate';
1424
+
1425
+ class EditorSkewEvent extends EditorEvent {
1426
+ constructor(type, data) {
1427
+ super(type, data);
1482
1428
  }
1429
+ }
1430
+ EditorSkewEvent.BEFORE_SKEW = 'editor.before_skew';
1431
+ EditorSkewEvent.SKEW = 'editor.skew';
1432
+
1433
+ class TransformTool {
1483
1434
  onMove(e) {
1435
+ const { target, mergeConfig, dragStartData } = this.editBox;
1484
1436
  if (e instanceof MoveEvent) {
1485
1437
  if (e.moveType !== 'drag') {
1486
- const { moveable, resizeable } = this.mergeConfig;
1487
- const move = e.getLocalMove(this.element);
1438
+ const { moveable, resizeable } = mergeConfig;
1439
+ const move = e.getLocalMove(target);
1488
1440
  if (moveable === 'move')
1489
1441
  e.stop(), this.move(move.x, move.y);
1490
1442
  else if (resizeable === 'zoom')
@@ -1499,22 +1451,22 @@ class Editor extends Group {
1499
1451
  else
1500
1452
  total.x = 0;
1501
1453
  }
1502
- this.move(DragEvent.getValidMove(this.element, this.editBox.dragStartData.point, total));
1454
+ this.move(DragEvent.getValidMove(target, dragStartData.point, total));
1503
1455
  }
1504
1456
  }
1505
1457
  onScale(e) {
1506
- const { element } = this;
1507
- let { around, lockRatio, resizeable, flipable, editSize } = this.mergeConfig;
1458
+ const { target, mergeConfig, single, dragStartData } = this.editBox;
1459
+ let { around, lockRatio, resizeable, flipable, editSize } = mergeConfig;
1508
1460
  if (e instanceof ZoomEvent) {
1509
1461
  if (resizeable === 'zoom')
1510
- e.stop(), this.scaleOf(element.getBoxPoint(e), e.scale, e.scale);
1462
+ e.stop(), this.scaleOf(target.getBoxPoint(e), e.scale, e.scale);
1511
1463
  }
1512
1464
  else {
1513
1465
  const { direction } = e.current;
1514
- if (e.shiftKey || element.lockRatio)
1466
+ if (e.shiftKey || target.lockRatio)
1515
1467
  lockRatio = true;
1516
- const data = EditDataHelper.getScaleData(element, this.editBox.dragStartData.bounds, direction, e.getInnerTotal(element), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, this.multiple || editSize === 'scale');
1517
- if (this.editTool.onScaleWithDrag) {
1468
+ const data = EditDataHelper.getScaleData(target, dragStartData.bounds, direction, e.getInnerTotal(target), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, !single || editSize === 'scale');
1469
+ if (this.editTool && this.editTool.onScaleWithDrag) {
1518
1470
  data.drag = e;
1519
1471
  this.scaleWithDrag(data);
1520
1472
  }
@@ -1524,38 +1476,38 @@ class Editor extends Group {
1524
1476
  }
1525
1477
  }
1526
1478
  onRotate(e) {
1527
- const { skewable, rotateable, around, rotateGap } = this.mergeConfig;
1479
+ const { target, mergeConfig, dragStartData } = this.editBox;
1480
+ const { skewable, rotateable, around, rotateGap } = mergeConfig;
1528
1481
  const { direction, name } = e.current;
1529
1482
  if (skewable && name === 'resize-line')
1530
1483
  return this.onSkew(e);
1531
- const { element } = this, { dragStartData } = this.editBox;
1532
1484
  let origin, rotation;
1533
1485
  if (e instanceof RotateEvent) {
1534
1486
  if (rotateable === 'rotate')
1535
- e.stop(), rotation = e.rotation, origin = element.getBoxPoint(e);
1487
+ e.stop(), rotation = e.rotation, origin = target.getBoxPoint(e);
1536
1488
  else
1537
1489
  return;
1538
- if (element.scaleX * element.scaleY < 0)
1490
+ if (target.scaleX * target.scaleY < 0)
1539
1491
  rotation = -rotation;
1540
1492
  }
1541
1493
  else {
1542
- const data = EditDataHelper.getRotateData(element.boxBounds, direction, e.getBoxPoint(element), element.getBoxPoint(dragStartData), e.shiftKey ? null : (element.around || element.origin || around || 'center'));
1494
+ const data = EditDataHelper.getRotateData(target, direction, e, dragStartData, e.shiftKey ? null : (target.around || target.origin || around || 'center'));
1543
1495
  rotation = data.rotation;
1544
1496
  origin = data.origin;
1545
1497
  }
1546
- if (element.scaleX * element.scaleY < 0)
1498
+ if (target.scaleX * target.scaleY < 0)
1547
1499
  rotation = -rotation;
1548
1500
  if (e instanceof DragEvent)
1549
- rotation = dragStartData.rotation + rotation - element.rotation;
1550
- rotation = MathHelper.float(MathHelper.getGapRotation(rotation, rotateGap, element.rotation), 2);
1501
+ rotation = dragStartData.rotation + rotation - target.rotation;
1502
+ rotation = MathHelper.float(MathHelper.getGapRotation(rotation, rotateGap, target.rotation), 2);
1551
1503
  if (!rotation)
1552
1504
  return;
1553
1505
  this.rotateOf(origin, rotation);
1554
1506
  }
1555
1507
  onSkew(e) {
1556
- const { element } = this;
1557
- const { around } = this.mergeConfig;
1558
- const { origin, skewX, skewY } = EditDataHelper.getSkewData(element.boxBounds, e.current.direction, e.getInnerMove(element), EditDataHelper.getAround(around, e.altKey));
1508
+ const { target, mergeConfig } = this.editBox;
1509
+ const { around } = mergeConfig;
1510
+ const { origin, skewX, skewY } = EditDataHelper.getSkewData(target.boxBounds, e.current.direction, e.getInnerMove(target), EditDataHelper.getAround(around, e.altKey));
1559
1511
  if (!skewX && !skewY)
1560
1512
  return;
1561
1513
  this.skewOf(origin, skewX, skewY);
@@ -1565,7 +1517,8 @@ class Editor extends Group {
1565
1517
  return;
1566
1518
  if (typeof x === 'object')
1567
1519
  y = x.y, x = x.x;
1568
- const { element: target } = this, { beforeMove } = this.mergeConfig;
1520
+ const { target, mergeConfig, single, editor } = this.editBox;
1521
+ const { beforeMove } = mergeConfig;
1569
1522
  if (beforeMove) {
1570
1523
  const check = beforeMove({ target, x, y });
1571
1524
  if (typeof check === 'object')
@@ -1574,25 +1527,26 @@ class Editor extends Group {
1574
1527
  return;
1575
1528
  }
1576
1529
  const world = target.getWorldPointByLocal({ x, y }, null, true);
1577
- if (this.multiple)
1530
+ if (!single)
1578
1531
  target.safeChange(() => target.move(x, y));
1579
- const data = { target, editor: this, moveX: world.x, moveY: world.y };
1532
+ const data = { target, editor, moveX: world.x, moveY: world.y };
1580
1533
  this.emitEvent(new EditorMoveEvent(EditorMoveEvent.BEFORE_MOVE, data));
1581
1534
  const event = new EditorMoveEvent(EditorMoveEvent.MOVE, data);
1582
- this.editTool.onMove(event);
1535
+ this.doMove(event);
1583
1536
  this.emitEvent(event);
1584
1537
  }
1585
1538
  scaleWithDrag(data) {
1586
1539
  if (!this.checkTransform('resizeable'))
1587
1540
  return;
1588
- const { element: target } = this, { beforeScale } = this.mergeConfig;
1541
+ const { target, mergeConfig, editor } = this.editBox;
1542
+ const { beforeScale } = mergeConfig;
1589
1543
  if (beforeScale) {
1590
1544
  const { origin, scaleX, scaleY, drag } = data;
1591
1545
  const check = beforeScale({ target, drag, origin, scaleX, scaleY });
1592
1546
  if (check === false)
1593
1547
  return;
1594
1548
  }
1595
- data = Object.assign(Object.assign({}, data), { target, editor: this, worldOrigin: target.getWorldPoint(data.origin) });
1549
+ data = Object.assign(Object.assign({}, data), { target, editor, worldOrigin: target.getWorldPoint(data.origin) });
1596
1550
  this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
1597
1551
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
1598
1552
  this.editTool.onScaleWithDrag(event);
@@ -1601,7 +1555,8 @@ class Editor extends Group {
1601
1555
  scaleOf(origin, scaleX, scaleY = scaleX, _resize) {
1602
1556
  if (!this.checkTransform('resizeable'))
1603
1557
  return;
1604
- const { element: target } = this, { beforeScale } = this.mergeConfig;
1558
+ const { target, mergeConfig, single, editor } = this.editBox;
1559
+ const { beforeScale } = mergeConfig;
1605
1560
  if (beforeScale) {
1606
1561
  const check = beforeScale({ target, origin, scaleX, scaleY });
1607
1562
  if (typeof check === 'object')
@@ -1610,29 +1565,30 @@ class Editor extends Group {
1610
1565
  return;
1611
1566
  }
1612
1567
  const worldOrigin = this.getWorldOrigin(origin);
1613
- const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.scaleOf(origin, scaleX, scaleY)));
1614
- const data = { target, editor: this, worldOrigin, scaleX, scaleY, transform };
1568
+ const transform = !single && this.getChangedTransform(() => target.safeChange(() => target.scaleOf(origin, scaleX, scaleY)));
1569
+ const data = { target, editor, worldOrigin, scaleX, scaleY, transform };
1615
1570
  this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
1616
1571
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
1617
- this.editTool.onScale(event);
1572
+ this.doScale(event);
1618
1573
  this.emitEvent(event);
1619
1574
  }
1620
1575
  flip(axis) {
1621
1576
  if (!this.checkTransform('resizeable'))
1622
1577
  return;
1623
- const { element } = this;
1578
+ const { target, single, editor } = this.editBox;
1624
1579
  const worldOrigin = this.getWorldOrigin('center');
1625
- const transform = this.multiple ? this.getChangedTransform(() => element.safeChange(() => element.flip(axis))) : new Matrix(LeafHelper.getFlipTransform(element, axis));
1626
- const data = { target: element, editor: this, worldOrigin, scaleX: axis === 'x' ? -1 : 1, scaleY: axis === 'y' ? -1 : 1, transform };
1580
+ const transform = !single ? this.getChangedTransform(() => target.safeChange(() => target.flip(axis))) : new Matrix(LeafHelper.getFlipTransform(target, axis));
1581
+ const data = { target, editor, worldOrigin, scaleX: axis === 'x' ? -1 : 1, scaleY: axis === 'y' ? -1 : 1, transform };
1627
1582
  this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
1628
1583
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
1629
- this.editTool.onScale(event);
1584
+ this.doScale(event);
1630
1585
  this.emitEvent(event);
1631
1586
  }
1632
1587
  rotateOf(origin, rotation) {
1633
1588
  if (!this.checkTransform('rotateable'))
1634
1589
  return;
1635
- const { element: target } = this, { beforeRotate } = this.mergeConfig;
1590
+ const { target, mergeConfig, single, editor } = this.editBox;
1591
+ const { beforeRotate } = mergeConfig;
1636
1592
  if (beforeRotate) {
1637
1593
  const check = beforeRotate({ target, origin, rotation });
1638
1594
  if (typeof check === 'number')
@@ -1641,17 +1597,18 @@ class Editor extends Group {
1641
1597
  return;
1642
1598
  }
1643
1599
  const worldOrigin = this.getWorldOrigin(origin);
1644
- const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.rotateOf(origin, rotation)));
1645
- const data = { target, editor: this, worldOrigin, rotation, transform };
1600
+ const transform = !single && this.getChangedTransform(() => target.safeChange(() => target.rotateOf(origin, rotation)));
1601
+ const data = { target, editor, worldOrigin, rotation, transform };
1646
1602
  this.emitEvent(new EditorRotateEvent(EditorRotateEvent.BEFORE_ROTATE, data));
1647
1603
  const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, data);
1648
- this.editTool.onRotate(event);
1604
+ this.doRotate(event);
1649
1605
  this.emitEvent(event);
1650
1606
  }
1651
1607
  skewOf(origin, skewX, skewY = 0, _resize) {
1652
1608
  if (!this.checkTransform('skewable'))
1653
1609
  return;
1654
- const { element: target } = this, { beforeSkew } = this.mergeConfig;
1610
+ const { target, mergeConfig, single, editor } = this.editBox;
1611
+ const { beforeSkew } = mergeConfig;
1655
1612
  if (beforeSkew) {
1656
1613
  const check = beforeSkew({ target, origin, skewX, skewY });
1657
1614
  if (typeof check === 'object')
@@ -1660,25 +1617,142 @@ class Editor extends Group {
1660
1617
  return;
1661
1618
  }
1662
1619
  const worldOrigin = this.getWorldOrigin(origin);
1663
- const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.skewOf(origin, skewX, skewY)));
1664
- const data = { target, editor: this, worldOrigin, skewX, skewY, transform };
1620
+ const transform = !single && this.getChangedTransform(() => target.safeChange(() => target.skewOf(origin, skewX, skewY)));
1621
+ const data = { target, editor, worldOrigin, skewX, skewY, transform };
1665
1622
  this.emitEvent(new EditorSkewEvent(EditorSkewEvent.BEFORE_SKEW, data));
1666
1623
  const event = new EditorSkewEvent(EditorSkewEvent.SKEW, data);
1667
- this.editTool.onSkew(event);
1624
+ this.doSkew(event);
1668
1625
  this.emitEvent(event);
1669
1626
  }
1670
- checkTransform(type) { return this.element && !this.element.locked && this.mergeConfig[type]; }
1627
+ doMove(event) {
1628
+ this.editTool.onMove(event);
1629
+ }
1630
+ doScale(event) {
1631
+ this.editTool.onScale(event);
1632
+ }
1633
+ doRotate(event) {
1634
+ this.editTool.onRotate(event);
1635
+ }
1636
+ doSkew(event) {
1637
+ this.editTool.onSkew(event);
1638
+ }
1639
+ checkTransform(type) {
1640
+ const { target, mergeConfig } = this.editBox;
1641
+ return target && !target.locked && mergeConfig[type];
1642
+ }
1671
1643
  getWorldOrigin(origin) {
1672
- return this.element.getWorldPoint(LeafHelper.getInnerOrigin(this.element, origin));
1644
+ const { target } = this.editBox;
1645
+ return target.getWorldPoint(LeafHelper.getInnerOrigin(target, origin));
1673
1646
  }
1674
1647
  getChangedTransform(func) {
1675
- const { element } = this;
1676
- if (this.multiple && !element.canChange)
1677
- return element.changedTransform;
1678
- const oldMatrix = new Matrix(element.worldTransform);
1648
+ const { target, single } = this.editBox;
1649
+ if (!single && !target.canChange)
1650
+ return target.changedTransform;
1651
+ const oldMatrix = new Matrix(target.worldTransform);
1679
1652
  func();
1680
- return new Matrix(element.worldTransform).divide(oldMatrix);
1653
+ return new Matrix(target.worldTransform).divide(oldMatrix);
1654
+ }
1655
+ emitEvent(event, capture) {
1656
+ this.editBox.editor.emitEvent(event, capture);
1657
+ }
1658
+ }
1659
+
1660
+ let Editor = class Editor extends Group {
1661
+ get list() { return this.leafList.list; }
1662
+ get dragHoverExclude() { return [this.editBox.rect]; }
1663
+ get editing() { return !!this.list.length; }
1664
+ get groupOpening() { return !!this.openedGroupList.length; }
1665
+ get multiple() { return this.list.length > 1; }
1666
+ get single() { return this.list.length === 1; }
1667
+ get dragging() { return this.editBox.dragging; }
1668
+ get moving() { return this.editBox.moving; }
1669
+ get dragPoint() { return this.editBox.dragPoint; }
1670
+ get element() { return this.multiple ? this.simulateTarget : this.list[0]; }
1671
+ get buttons() { return this.editBox.buttons; }
1672
+ constructor(userConfig, data) {
1673
+ super(data);
1674
+ this.leafList = new LeafList();
1675
+ this.openedGroupList = new LeafList();
1676
+ this.simulateTarget = new SimulateElement(this);
1677
+ this.editBox = new EditBox(this);
1678
+ this.editToolList = {};
1679
+ this.selector = new EditSelect(this);
1680
+ this.editMask = new EditMask(this);
1681
+ this.targetEventIds = [];
1682
+ let mergedConfig = DataHelper.clone(config);
1683
+ if (userConfig)
1684
+ mergedConfig = DataHelper.default(userConfig, mergedConfig);
1685
+ this.mergedConfig = this.config = mergedConfig;
1686
+ this.addMany(this.editMask, this.selector, this.editBox);
1687
+ if (!Plugin.has('resize'))
1688
+ this.config.editSize = 'scale';
1689
+ }
1690
+ select(target) {
1691
+ this.target = target;
1692
+ }
1693
+ cancel() {
1694
+ this.target = null;
1695
+ }
1696
+ hasItem(item) {
1697
+ return this.leafList.has(item);
1698
+ }
1699
+ addItem(item) {
1700
+ if (!this.hasItem(item) && !item.locked)
1701
+ this.leafList.add(item), this.target = this.leafList.list;
1702
+ }
1703
+ removeItem(item) {
1704
+ if (this.hasItem(item))
1705
+ this.leafList.remove(item), this.target = this.leafList.list;
1706
+ }
1707
+ shiftItem(item) {
1708
+ this.hasItem(item) ? this.removeItem(item) : this.addItem(item);
1681
1709
  }
1710
+ update() {
1711
+ if (this.editing) {
1712
+ if (!this.element.parent)
1713
+ return this.cancel();
1714
+ if (this.innerEditing)
1715
+ this.innerEditor.update();
1716
+ this.editTool.update();
1717
+ this.selector.update();
1718
+ }
1719
+ }
1720
+ updateEditBox() {
1721
+ if (this.multiple)
1722
+ simulate(this);
1723
+ this.update();
1724
+ }
1725
+ updateEditTool() {
1726
+ let tool = this.editTool;
1727
+ if (tool) {
1728
+ this.editBox.unload();
1729
+ tool.unload();
1730
+ this.editTool = null;
1731
+ }
1732
+ if (this.editing) {
1733
+ const tag = this.element.editOuter || 'EditTool';
1734
+ tool = this.editTool = this.editToolList[tag] = this.editToolList[tag] || EditToolCreator.get(tag, this);
1735
+ this.editBox.load();
1736
+ tool.load();
1737
+ this.update();
1738
+ }
1739
+ }
1740
+ getEditSize(_ui) {
1741
+ return this.mergeConfig.editSize;
1742
+ }
1743
+ onMove(_e) { }
1744
+ onScale(_e) { }
1745
+ onRotate(_e) { }
1746
+ onSkew(_e) { }
1747
+ move(_x, _y = 0) { }
1748
+ scaleWithDrag(_data) { }
1749
+ scaleOf(_origin, scaleX, _scaleY = scaleX, _resize) { }
1750
+ flip(_axis) { }
1751
+ rotateOf(_origin, _rotation) { }
1752
+ skewOf(_origin, _skewX, _skewY = 0, _resize) { }
1753
+ checkTransform(_type) { return undefined; }
1754
+ getWorldOrigin(_origin) { return undefined; }
1755
+ getChangedTransform(_func) { return undefined; }
1682
1756
  group(userGroup) {
1683
1757
  if (this.multiple) {
1684
1758
  this.emitGroupEvent(EditorGroupEvent.BEFORE_GROUP);
@@ -1796,12 +1870,9 @@ class Editor extends Group {
1796
1870
  if (this.targetChanged)
1797
1871
  this.update();
1798
1872
  }
1799
- onKey(e) {
1800
- updateCursor(this, e);
1801
- }
1802
1873
  listenTargetEvents() {
1803
1874
  if (!this.targetEventIds.length) {
1804
- const { app, leafer, editBox, editMask } = this;
1875
+ const { app, leafer, editMask } = this;
1805
1876
  this.targetEventIds = [
1806
1877
  leafer.on_(RenderEvent.START, this.onRenderStart, this),
1807
1878
  app.on_([
@@ -1809,8 +1880,6 @@ class Editor extends Group {
1809
1880
  [MoveEvent.BEFORE_MOVE, this.onMove, this, true],
1810
1881
  [ZoomEvent.BEFORE_ZOOM, this.onScale, this, true],
1811
1882
  [RotateEvent.BEFORE_ROTATE, this.onRotate, this, true],
1812
- [[KeyEvent.HOLD, KeyEvent.UP], this.onKey, this],
1813
- [KeyEvent.DOWN, editBox.onArrow, editBox]
1814
1883
  ])
1815
1884
  ];
1816
1885
  if (editMask.visible)
@@ -1835,7 +1904,7 @@ class Editor extends Group {
1835
1904
  super.destroy();
1836
1905
  }
1837
1906
  }
1838
- }
1907
+ };
1839
1908
  __decorate([
1840
1909
  mergeConfigAttr()
1841
1910
  ], Editor.prototype, "mergeConfig", void 0);
@@ -1845,14 +1914,19 @@ __decorate([
1845
1914
  __decorate([
1846
1915
  targetAttr(onTarget)
1847
1916
  ], Editor.prototype, "target", void 0);
1917
+ Editor = __decorate([
1918
+ useModule(TransformTool, ['editBox', 'editTool', 'emitEvent'])
1919
+ ], Editor);
1848
1920
 
1849
1921
  class InnerEditor {
1850
1922
  static registerInnerEditor() {
1851
1923
  EditToolCreator.register(this);
1852
1924
  }
1853
1925
  get tag() { return 'InnerEditor'; }
1926
+ get mode() { return 'focus'; }
1854
1927
  get editBox() { return this.editor.editBox; }
1855
1928
  constructor(editor) {
1929
+ this.eventIds = [];
1856
1930
  this.editor = editor;
1857
1931
  this.create();
1858
1932
  }
@@ -1865,7 +1939,7 @@ class InnerEditor {
1865
1939
  load() {
1866
1940
  const { editor } = this;
1867
1941
  if (editor) {
1868
- if (editor.app)
1942
+ if (editor.app && this.mode === 'focus')
1869
1943
  editor.selector.hittable = editor.app.tree.hitChildren = false;
1870
1944
  this.onLoad();
1871
1945
  }
@@ -1876,7 +1950,7 @@ class InnerEditor {
1876
1950
  unload() {
1877
1951
  const { editor } = this;
1878
1952
  if (editor) {
1879
- if (editor.app)
1953
+ if (editor.app && this.mode === 'focus')
1880
1954
  editor.selector.hittable = editor.app.tree.hitChildren = true;
1881
1955
  this.onUnload();
1882
1956
  }
@@ -1950,10 +2024,7 @@ let EditTool = class EditTool extends InnerEditor {
1950
2024
  this.onLoad();
1951
2025
  }
1952
2026
  update() {
1953
- const { editor, editBox } = this;
1954
- const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = editor.element.getLayoutBounds('box', editor, true);
1955
- editBox.set({ x, y, scaleX, scaleY, rotation, skewX, skewY });
1956
- editBox.update({ x: 0, y: 0, width, height });
2027
+ this.editBox.update();
1957
2028
  this.onUpdate();
1958
2029
  }
1959
2030
  unload() {
@@ -2088,4 +2159,4 @@ UI.setEditConfig = function (config) { this.changeAttr('editConfig', config); };
2088
2159
  UI.setEditOuter = function (toolName) { this.changeAttr('editOuter', toolName); };
2089
2160
  UI.setEditInner = function (editorName) { this.changeAttr('editInner', editorName); };
2090
2161
 
2091
- export { EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorGroupEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, InnerEditor, InnerEditorEvent, LineEditTool, SelectArea, Stroker, registerEditTool, registerInnerEditor };
2162
+ export { EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorGroupEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, InnerEditor, InnerEditorEvent, LineEditTool, SelectArea, Stroker, TransformTool, registerEditTool, registerInnerEditor };