@leafer-in/editor 1.4.1 → 1.5.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.
- package/dist/editor.cjs +117 -83
- package/dist/editor.cjs.map +1 -1
- package/dist/editor.esm.js +118 -84
- package/dist/editor.esm.js.map +1 -1
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.esm.min.js.map +1 -1
- package/dist/editor.js +117 -83
- package/dist/editor.js.map +1 -1
- 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 +5 -5
- package/src/Editor.ts +49 -26
- package/src/config.ts +1 -0
- package/src/display/EditBox.ts +28 -27
- package/src/display/EditSelect.ts +3 -3
- package/src/display/Stroker.ts +1 -1
- package/src/editor/cursor.ts +1 -1
- package/src/editor/simulate.ts +6 -1
- package/src/editor/target.ts +10 -2
- package/src/event/EditorGroupEvent.ts +6 -0
- package/src/event/EditorMoveEvent.ts +1 -0
- package/src/event/EditorRotateEvent.ts +1 -0
- package/src/event/EditorScaleEvent.ts +1 -0
- package/src/event/EditorSkewEvent.ts +1 -0
- package/src/helper/EditDataHelper.ts +5 -7
- package/src/index.ts +10 -36
- package/types/index.d.ts +14 -6
package/dist/editor.cjs
CHANGED
|
@@ -53,6 +53,7 @@ class EditorMoveEvent extends EditorEvent {
|
|
|
53
53
|
super(type, data);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
+
EditorMoveEvent.BEFORE_MOVE = 'editor.before_move';
|
|
56
57
|
EditorMoveEvent.MOVE = 'editor.move';
|
|
57
58
|
|
|
58
59
|
class EditorScaleEvent extends EditorEvent {
|
|
@@ -60,6 +61,7 @@ class EditorScaleEvent extends EditorEvent {
|
|
|
60
61
|
super(type, data);
|
|
61
62
|
}
|
|
62
63
|
}
|
|
64
|
+
EditorScaleEvent.BEFORE_SCALE = 'editor.before_scale';
|
|
63
65
|
EditorScaleEvent.SCALE = 'editor.scale';
|
|
64
66
|
|
|
65
67
|
class EditorRotateEvent extends EditorEvent {
|
|
@@ -67,6 +69,7 @@ class EditorRotateEvent extends EditorEvent {
|
|
|
67
69
|
super(type, data);
|
|
68
70
|
}
|
|
69
71
|
}
|
|
72
|
+
EditorRotateEvent.BEFORE_ROTATE = 'editor.before_rotate';
|
|
70
73
|
EditorRotateEvent.ROTATE = 'editor.rotate';
|
|
71
74
|
|
|
72
75
|
class EditorSkewEvent extends EditorEvent {
|
|
@@ -74,6 +77,7 @@ class EditorSkewEvent extends EditorEvent {
|
|
|
74
77
|
super(type, data);
|
|
75
78
|
}
|
|
76
79
|
}
|
|
80
|
+
EditorSkewEvent.BEFORE_SKEW = 'editor.before_skew';
|
|
77
81
|
EditorSkewEvent.SKEW = 'editor.skew';
|
|
78
82
|
|
|
79
83
|
function targetAttr(fn) {
|
|
@@ -126,7 +130,7 @@ class Stroker extends draw.UI {
|
|
|
126
130
|
for (let i = 0; i < list.length; i++) {
|
|
127
131
|
leaf = list[i];
|
|
128
132
|
const { worldTransform, worldRenderBounds } = leaf;
|
|
129
|
-
if (!bounds || bounds.hit(worldRenderBounds, options.matrix)) {
|
|
133
|
+
if (worldRenderBounds.width && worldRenderBounds.height && (!bounds || bounds.hit(worldRenderBounds, options.matrix))) {
|
|
130
134
|
const aScaleX = abs(worldTransform.scaleX), aScaleY = abs(worldTransform.scaleY);
|
|
131
135
|
if (aScaleX !== aScaleY) {
|
|
132
136
|
copy$1(matrix, worldTransform);
|
|
@@ -252,9 +256,9 @@ class EditSelect extends draw.Group {
|
|
|
252
256
|
}
|
|
253
257
|
onSelect() {
|
|
254
258
|
if (this.running) {
|
|
255
|
-
const { mergeConfig
|
|
256
|
-
const { stroke, strokeWidth } =
|
|
257
|
-
this.targetStroker.setTarget(list, { stroke, strokeWidth: Math.max(1, strokeWidth / 2) });
|
|
259
|
+
const { mergeConfig, list } = this.editor;
|
|
260
|
+
const { stroke, strokeWidth, selectedStyle } = mergeConfig;
|
|
261
|
+
this.targetStroker.setTarget(list, Object.assign({ stroke, strokeWidth: Math.max(1, strokeWidth / 2) }, (selectedStyle || {})));
|
|
258
262
|
this.hoverStroker.target = null;
|
|
259
263
|
}
|
|
260
264
|
}
|
|
@@ -441,7 +445,7 @@ const { within } = draw.MathHelper;
|
|
|
441
445
|
const EditDataHelper = {
|
|
442
446
|
getScaleData(element, startBounds, direction, totalMove, lockRatio, around, flipable, scaleMode) {
|
|
443
447
|
let align, origin = {}, scaleX = 1, scaleY = 1;
|
|
444
|
-
const { boxBounds, widthRange, heightRange, dragBounds } = element;
|
|
448
|
+
const { boxBounds, widthRange, heightRange, dragBounds, worldBoxBounds } = element;
|
|
445
449
|
const { width, height } = startBounds;
|
|
446
450
|
if (around) {
|
|
447
451
|
totalMove.x *= 2;
|
|
@@ -455,10 +459,6 @@ const EditDataHelper = {
|
|
|
455
459
|
const changedScaleY = scaleMode ? originChangedScaleY : signY * boxBounds.height / height;
|
|
456
460
|
totalMove.x *= scaleMode ? originChangedScaleX : signX;
|
|
457
461
|
totalMove.y *= scaleMode ? originChangedScaleY : signY;
|
|
458
|
-
if (Math.abs(totalMove.x) === width)
|
|
459
|
-
totalMove.x += 0.1;
|
|
460
|
-
if (Math.abs(totalMove.y) === height)
|
|
461
|
-
totalMove.y += 0.1;
|
|
462
462
|
const topScale = (-totalMove.y + height) / height;
|
|
463
463
|
const rightScale = (totalMove.x + width) / width;
|
|
464
464
|
const bottomScale = (totalMove.y + height) / height;
|
|
@@ -548,6 +548,10 @@ const EditDataHelper = {
|
|
|
548
548
|
const nowHeight = boxBounds.height * element.scaleY;
|
|
549
549
|
scaleY = within(nowHeight * scaleY, heightRange) / nowHeight;
|
|
550
550
|
}
|
|
551
|
+
if (Math.abs(scaleX * worldBoxBounds.width) < 1)
|
|
552
|
+
scaleX = (scaleX < 0 ? -1 : 1) / worldBoxBounds.width;
|
|
553
|
+
if (Math.abs(scaleY * worldBoxBounds.height) < 1)
|
|
554
|
+
scaleY = (scaleY < 0 ? -1 : 1) / worldBoxBounds.height;
|
|
551
555
|
return { origin, scaleX, scaleY, direction, lockRatio, around };
|
|
552
556
|
},
|
|
553
557
|
getRotateData(bounds, direction, current, last, around) {
|
|
@@ -676,7 +680,7 @@ function updateCursor(editor, e) {
|
|
|
676
680
|
let { rotation } = editBox;
|
|
677
681
|
const { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editor.mergeConfig;
|
|
678
682
|
const { pointType } = point, { flippedX, flippedY } = editBox;
|
|
679
|
-
let showResize = pointType
|
|
683
|
+
let showResize = pointType.includes('resize');
|
|
680
684
|
if (showResize && rotateable && (e.metaKey || e.ctrlKey || !resizeable))
|
|
681
685
|
showResize = false;
|
|
682
686
|
const showSkew = skewable && !showResize && point.name === 'resize-line';
|
|
@@ -703,7 +707,7 @@ function toDataURL(svg, rotation) {
|
|
|
703
707
|
class EditPoint extends draw.Box {
|
|
704
708
|
}
|
|
705
709
|
|
|
706
|
-
const fourDirection = ['top', 'right', 'bottom', 'left'];
|
|
710
|
+
const fourDirection = ['top', 'right', 'bottom', 'left'], editConfig = undefined;
|
|
707
711
|
class EditBox extends draw.Group {
|
|
708
712
|
get flipped() { return this.flippedX || this.flippedY; }
|
|
709
713
|
get flippedX() { return this.scaleX < 0; }
|
|
@@ -718,6 +722,7 @@ class EditBox extends draw.Group {
|
|
|
718
722
|
this.resizePoints = [];
|
|
719
723
|
this.rotatePoints = [];
|
|
720
724
|
this.resizeLines = [];
|
|
725
|
+
this.dragStartData = {};
|
|
721
726
|
this.__eventIds = [];
|
|
722
727
|
this.editor = editor;
|
|
723
728
|
this.visible = false;
|
|
@@ -759,7 +764,7 @@ class EditBox extends draw.Group {
|
|
|
759
764
|
resizeP.rotation = (i / 2) * 90;
|
|
760
765
|
}
|
|
761
766
|
circle.set(this.getPointStyle(mergeConfig.circle || mergeConfig.rotatePoint || pointsStyle[0]));
|
|
762
|
-
rect.set(Object.assign({ stroke, strokeWidth }, (mergeConfig.rect || {})));
|
|
767
|
+
rect.set(Object.assign({ stroke, strokeWidth, editConfig }, (mergeConfig.rect || {})));
|
|
763
768
|
rect.hittable = !single;
|
|
764
769
|
rect.syncEventer = single && this.editor;
|
|
765
770
|
if (single) {
|
|
@@ -768,14 +773,14 @@ class EditBox extends draw.Group {
|
|
|
768
773
|
}
|
|
769
774
|
}
|
|
770
775
|
update(bounds) {
|
|
771
|
-
|
|
776
|
+
const { mergeConfig, element, multiple } = this.editor;
|
|
777
|
+
const { middlePoint, resizeable, rotateable, hideOnSmall, editBox } = mergeConfig;
|
|
778
|
+
this.visible = !element.locked;
|
|
772
779
|
if (this.view.worldOpacity) {
|
|
773
|
-
const { mergeConfig } = this.editor;
|
|
774
780
|
const { width, height } = bounds;
|
|
775
781
|
const { rect, circle, buttons, resizePoints, rotatePoints, resizeLines } = this;
|
|
776
|
-
const { middlePoint, resizeable, rotateable, hideOnSmall } = mergeConfig;
|
|
777
782
|
const smallSize = typeof hideOnSmall === 'number' ? hideOnSmall : 10;
|
|
778
|
-
const showPoints = !(hideOnSmall && width < smallSize && height < smallSize);
|
|
783
|
+
const showPoints = editBox && !(hideOnSmall && width < smallSize && height < smallSize);
|
|
779
784
|
let point = {}, rotateP, resizeP, resizeL;
|
|
780
785
|
for (let i = 0; i < 8; i++) {
|
|
781
786
|
draw.AroundHelper.toPoint(draw.AroundHelper.directionData[i], bounds, point);
|
|
@@ -791,13 +796,13 @@ class EditBox extends draw.Group {
|
|
|
791
796
|
resizeP.visible = rotateP.visible = showPoints && !!middlePoint;
|
|
792
797
|
if (((i + 1) / 2) % 2) {
|
|
793
798
|
resizeL.width = width;
|
|
794
|
-
if (resizeP.width > width
|
|
799
|
+
if (hideOnSmall && resizeP.width * 2 > width)
|
|
795
800
|
resizeP.visible = false;
|
|
796
801
|
}
|
|
797
802
|
else {
|
|
798
803
|
resizeL.height = height;
|
|
799
804
|
resizeP.rotation = 90;
|
|
800
|
-
if (resizeP.width > height
|
|
805
|
+
if (hideOnSmall && resizeP.width * 2 > height)
|
|
801
806
|
resizeP.visible = false;
|
|
802
807
|
}
|
|
803
808
|
}
|
|
@@ -807,7 +812,7 @@ class EditBox extends draw.Group {
|
|
|
807
812
|
this.layoutCircle(mergeConfig);
|
|
808
813
|
if (rect.path)
|
|
809
814
|
rect.path = null;
|
|
810
|
-
rect.set(Object.assign(Object.assign({}, bounds), { visible: true }));
|
|
815
|
+
rect.set(Object.assign(Object.assign({}, bounds), { visible: multiple ? true : editBox }));
|
|
811
816
|
buttons.visible = showPoints && buttons.children.length > 0;
|
|
812
817
|
if (buttons.visible)
|
|
813
818
|
this.layoutButtons(mergeConfig);
|
|
@@ -854,7 +859,7 @@ class EditBox extends draw.Group {
|
|
|
854
859
|
}
|
|
855
860
|
getPointStyle(userStyle) {
|
|
856
861
|
const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.editor.mergeConfig;
|
|
857
|
-
const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', width: pointSize, height: pointSize, cornerRadius: pointRadius, offsetX: 0, offsetY: 0 };
|
|
862
|
+
const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', width: pointSize, height: pointSize, cornerRadius: pointRadius, offsetX: 0, offsetY: 0, editConfig };
|
|
858
863
|
return userStyle ? Object.assign(defaultStyle, userStyle) : defaultStyle;
|
|
859
864
|
}
|
|
860
865
|
getPointsStyle() {
|
|
@@ -874,34 +879,32 @@ class EditBox extends draw.Group {
|
|
|
874
879
|
}
|
|
875
880
|
onDragStart(e) {
|
|
876
881
|
this.dragging = true;
|
|
877
|
-
const
|
|
878
|
-
|
|
882
|
+
const point = this.dragPoint = e.current;
|
|
883
|
+
const { editor, dragStartData } = this, { element } = editor;
|
|
884
|
+
if (point.name === 'rect') {
|
|
879
885
|
this.moving = true;
|
|
880
|
-
editor.dragStartPoint = { x: editor.element.x, y: editor.element.y };
|
|
881
886
|
editor.opacity = editor.mergeConfig.hideOnMove ? 0 : 1;
|
|
882
887
|
}
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
}
|
|
888
|
+
dragStartData.x = e.x;
|
|
889
|
+
dragStartData.y = e.y;
|
|
890
|
+
dragStartData.point = { x: element.x, y: element.y };
|
|
891
|
+
dragStartData.bounds = Object.assign({}, element.getLayoutBounds('box', 'local'));
|
|
892
|
+
dragStartData.rotation = element.rotation;
|
|
887
893
|
}
|
|
888
894
|
onDragEnd(e) {
|
|
889
895
|
this.dragging = false;
|
|
896
|
+
this.dragPoint = null;
|
|
890
897
|
this.moving = false;
|
|
891
898
|
if (e.current.name === 'rect')
|
|
892
899
|
this.editor.opacity = 1;
|
|
893
|
-
this.editor.resizeDirection = undefined;
|
|
894
900
|
}
|
|
895
901
|
onDrag(e) {
|
|
896
902
|
const { editor } = this;
|
|
897
|
-
const
|
|
898
|
-
if (
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
}
|
|
902
|
-
else if (point.pointType === 'resize') {
|
|
903
|
+
const { pointType } = this.enterPoint = e.current;
|
|
904
|
+
if (pointType.includes('rotate') || e.metaKey || e.ctrlKey || !editor.mergeConfig.resizeable)
|
|
905
|
+
editor.onRotate(e);
|
|
906
|
+
if (pointType.includes('resize'))
|
|
903
907
|
editor.onScale(e);
|
|
904
|
-
}
|
|
905
908
|
updateCursor(editor, e);
|
|
906
909
|
}
|
|
907
910
|
onArrow(e) {
|
|
@@ -1079,6 +1082,7 @@ const config = {
|
|
|
1079
1082
|
rotateCursor: { url: rotateSVG, x: 12, y: 12 },
|
|
1080
1083
|
skewCursor: { url: skewSVG, x: 12, y: 12 },
|
|
1081
1084
|
selector: true,
|
|
1085
|
+
editBox: true,
|
|
1082
1086
|
hover: true,
|
|
1083
1087
|
select: 'press',
|
|
1084
1088
|
openInner: 'double',
|
|
@@ -1094,14 +1098,25 @@ const bounds = new draw.Bounds();
|
|
|
1094
1098
|
function simulate(editor) {
|
|
1095
1099
|
const { simulateTarget, list } = editor;
|
|
1096
1100
|
const { zoomLayer } = list[0].leafer.zoomLayer;
|
|
1097
|
-
simulateTarget.safeChange(() =>
|
|
1101
|
+
simulateTarget.safeChange(() => {
|
|
1102
|
+
bounds.setListWithFn(list, (leaf) => leaf.getBounds('box', 'page'));
|
|
1103
|
+
if (bounds.width === 0)
|
|
1104
|
+
bounds.width = 0.1;
|
|
1105
|
+
if (bounds.height === 0)
|
|
1106
|
+
bounds.height = 0.1;
|
|
1107
|
+
simulateTarget.reset(bounds.get());
|
|
1108
|
+
});
|
|
1098
1109
|
zoomLayer.add(simulateTarget);
|
|
1099
1110
|
}
|
|
1100
1111
|
|
|
1101
1112
|
function onTarget(editor, oldValue) {
|
|
1102
1113
|
const { target } = editor;
|
|
1103
1114
|
if (target) {
|
|
1104
|
-
editor.leafList = target instanceof draw.LeafList ? target : new draw.LeafList(target instanceof Array ? target : target);
|
|
1115
|
+
const { list } = editor.leafList = target instanceof draw.LeafList ? target : new draw.LeafList(target instanceof Array ? target : target);
|
|
1116
|
+
if (!list.every(checkEditable)) {
|
|
1117
|
+
editor.target = list.filter(checkEditable);
|
|
1118
|
+
return;
|
|
1119
|
+
}
|
|
1105
1120
|
if (editor.multiple)
|
|
1106
1121
|
simulate(editor);
|
|
1107
1122
|
}
|
|
@@ -1128,6 +1143,9 @@ function onTarget(editor, oldValue) {
|
|
|
1128
1143
|
function onHover(editor, oldValue) {
|
|
1129
1144
|
editor.emitEvent(new EditorEvent(EditorEvent.HOVER, { editor, value: editor.hoverTarget, oldValue }));
|
|
1130
1145
|
}
|
|
1146
|
+
function checkEditable(item) {
|
|
1147
|
+
return item.editable && !item.locked;
|
|
1148
|
+
}
|
|
1131
1149
|
|
|
1132
1150
|
const order = (a, b) => a.parent.children.indexOf(a) - b.parent.children.indexOf(b);
|
|
1133
1151
|
const reverseOrder = (a, b) => b.parent.children.indexOf(b) - a.parent.children.indexOf(a);
|
|
@@ -1225,10 +1243,13 @@ class EditorGroupEvent extends EditorEvent {
|
|
|
1225
1243
|
super(type, data);
|
|
1226
1244
|
}
|
|
1227
1245
|
}
|
|
1246
|
+
EditorGroupEvent.BEFORE_GROUP = 'editor.before_group';
|
|
1228
1247
|
EditorGroupEvent.GROUP = 'editor.group';
|
|
1229
1248
|
EditorGroupEvent.BEFORE_UNGROUP = 'editor.before_ungroup';
|
|
1230
1249
|
EditorGroupEvent.UNGROUP = 'editor.ungroup';
|
|
1250
|
+
EditorGroupEvent.BEFORE_OPEN = 'editor.before_open_group';
|
|
1231
1251
|
EditorGroupEvent.OPEN = 'editor.open_group';
|
|
1252
|
+
EditorGroupEvent.BEFORE_CLOSE = 'editor.before_close_group';
|
|
1232
1253
|
EditorGroupEvent.CLOSE = 'editor.close_group';
|
|
1233
1254
|
|
|
1234
1255
|
const { updateMatrix } = draw.LeafHelper;
|
|
@@ -1291,8 +1312,20 @@ class SimulateElement extends draw.Rect {
|
|
|
1291
1312
|
|
|
1292
1313
|
class Editor extends draw.Group {
|
|
1293
1314
|
get mergeConfig() {
|
|
1294
|
-
const { element,
|
|
1295
|
-
|
|
1315
|
+
const { config, element, dragPoint } = this, mergeConfig = Object.assign({}, config);
|
|
1316
|
+
if (element && element.editConfig)
|
|
1317
|
+
Object.assign(mergeConfig, element.editConfig);
|
|
1318
|
+
if (dragPoint) {
|
|
1319
|
+
if (dragPoint.editConfig)
|
|
1320
|
+
Object.assign(mergeConfig, dragPoint.editConfig);
|
|
1321
|
+
if (mergeConfig.editSize === 'font-size')
|
|
1322
|
+
mergeConfig.lockRatio = true;
|
|
1323
|
+
if (dragPoint.pointType === 'resize-rotate') {
|
|
1324
|
+
mergeConfig.around || (mergeConfig.around = 'center');
|
|
1325
|
+
draw.isNull(mergeConfig.lockRatio) && (mergeConfig.lockRatio = true);
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
return mergeConfig;
|
|
1296
1329
|
}
|
|
1297
1330
|
get list() { return this.leafList.list; }
|
|
1298
1331
|
get dragHoverExclude() { return [this.editBox.rect]; }
|
|
@@ -1302,6 +1335,7 @@ class Editor extends draw.Group {
|
|
|
1302
1335
|
get single() { return this.list.length === 1; }
|
|
1303
1336
|
get dragging() { return this.editBox.dragging; }
|
|
1304
1337
|
get moving() { return this.editBox.moving; }
|
|
1338
|
+
get dragPoint() { return this.editBox.dragPoint; }
|
|
1305
1339
|
get element() { return this.multiple ? this.simulateTarget : this.list[0]; }
|
|
1306
1340
|
get buttons() { return this.editBox.buttons; }
|
|
1307
1341
|
constructor(userConfig, data) {
|
|
@@ -1392,7 +1426,7 @@ class Editor extends draw.Group {
|
|
|
1392
1426
|
else
|
|
1393
1427
|
total.x = 0;
|
|
1394
1428
|
}
|
|
1395
|
-
this.move(core.DragEvent.getValidMove(this.element, this.
|
|
1429
|
+
this.move(core.DragEvent.getValidMove(this.element, this.editBox.dragStartData.point, total));
|
|
1396
1430
|
}
|
|
1397
1431
|
}
|
|
1398
1432
|
onScale(e) {
|
|
@@ -1406,7 +1440,7 @@ class Editor extends draw.Group {
|
|
|
1406
1440
|
const { direction } = e.current;
|
|
1407
1441
|
if (e.shiftKey || element.lockRatio)
|
|
1408
1442
|
lockRatio = true;
|
|
1409
|
-
const data = EditDataHelper.getScaleData(element, this.
|
|
1443
|
+
const data = EditDataHelper.getScaleData(element, this.editBox.dragStartData.bounds, direction, e.getInnerTotal(element), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, this.multiple || editSize === 'scale');
|
|
1410
1444
|
if (this.editTool.onScaleWithDrag) {
|
|
1411
1445
|
data.drag = e;
|
|
1412
1446
|
this.scaleWithDrag(data);
|
|
@@ -1421,26 +1455,29 @@ class Editor extends draw.Group {
|
|
|
1421
1455
|
const { direction, name } = e.current;
|
|
1422
1456
|
if (skewable && name === 'resize-line')
|
|
1423
1457
|
return this.onSkew(e);
|
|
1424
|
-
const { element } = this;
|
|
1458
|
+
const { element } = this, { dragStartData } = this.editBox;
|
|
1425
1459
|
let origin, rotation;
|
|
1426
1460
|
if (e instanceof core.RotateEvent) {
|
|
1427
1461
|
if (rotateable === 'rotate')
|
|
1428
1462
|
e.stop(), rotation = e.rotation, origin = element.getBoxPoint(e);
|
|
1429
1463
|
else
|
|
1430
1464
|
return;
|
|
1465
|
+
if (element.scaleX * element.scaleY < 0)
|
|
1466
|
+
rotation = -rotation;
|
|
1431
1467
|
}
|
|
1432
1468
|
else {
|
|
1433
|
-
const
|
|
1434
|
-
const data = EditDataHelper.getRotateData(element.boxBounds, direction, e.getBoxPoint(element), element.getBoxPoint(last), e.shiftKey ? null : (element.around || element.origin || around || 'center'));
|
|
1469
|
+
const data = EditDataHelper.getRotateData(element.boxBounds, direction, e.getBoxPoint(element), element.getBoxPoint(dragStartData), e.shiftKey ? null : (element.around || element.origin || around || 'center'));
|
|
1435
1470
|
rotation = data.rotation;
|
|
1436
1471
|
origin = data.origin;
|
|
1437
1472
|
}
|
|
1438
|
-
rotation = draw.MathHelper.getGapRotation(rotation, rotateGap, element.rotation);
|
|
1439
|
-
if (!rotation)
|
|
1440
|
-
return;
|
|
1441
1473
|
if (element.scaleX * element.scaleY < 0)
|
|
1442
1474
|
rotation = -rotation;
|
|
1443
|
-
|
|
1475
|
+
if (e instanceof core.DragEvent)
|
|
1476
|
+
rotation = dragStartData.rotation + rotation - element.rotation;
|
|
1477
|
+
rotation = draw.MathHelper.float(draw.MathHelper.getGapRotation(rotation, rotateGap, element.rotation), 2);
|
|
1478
|
+
if (!rotation)
|
|
1479
|
+
return;
|
|
1480
|
+
this.rotateOf(origin, rotation);
|
|
1444
1481
|
}
|
|
1445
1482
|
onSkew(e) {
|
|
1446
1483
|
const { element } = this;
|
|
@@ -1457,7 +1494,9 @@ class Editor extends draw.Group {
|
|
|
1457
1494
|
const world = element.getWorldPointByLocal(typeof x === 'object' ? Object.assign({}, x) : { x, y }, null, true);
|
|
1458
1495
|
if (this.multiple)
|
|
1459
1496
|
element.safeChange(() => element.move(x, y));
|
|
1460
|
-
const
|
|
1497
|
+
const data = { target: element, editor: this, moveX: world.x, moveY: world.y };
|
|
1498
|
+
this.emitEvent(new EditorMoveEvent(EditorMoveEvent.BEFORE_MOVE, data));
|
|
1499
|
+
const event = new EditorMoveEvent(EditorMoveEvent.MOVE, data);
|
|
1461
1500
|
this.editTool.onMove(event);
|
|
1462
1501
|
this.emitEvent(event);
|
|
1463
1502
|
}
|
|
@@ -1465,7 +1504,9 @@ class Editor extends draw.Group {
|
|
|
1465
1504
|
if (!this.checkTransform('resizeable'))
|
|
1466
1505
|
return;
|
|
1467
1506
|
const { element } = this;
|
|
1468
|
-
|
|
1507
|
+
data = Object.assign(Object.assign({}, data), { target: element, editor: this, worldOrigin: element.getWorldPoint(data.origin) });
|
|
1508
|
+
this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
|
|
1509
|
+
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
|
|
1469
1510
|
this.editTool.onScaleWithDrag(event);
|
|
1470
1511
|
this.emitEvent(event);
|
|
1471
1512
|
}
|
|
@@ -1475,7 +1516,9 @@ class Editor extends draw.Group {
|
|
|
1475
1516
|
const { element } = this;
|
|
1476
1517
|
const worldOrigin = this.getWorldOrigin(origin);
|
|
1477
1518
|
const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.scaleOf(origin, scaleX, scaleY)));
|
|
1478
|
-
const
|
|
1519
|
+
const data = { target: element, editor: this, worldOrigin, scaleX, scaleY, transform };
|
|
1520
|
+
this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
|
|
1521
|
+
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
|
|
1479
1522
|
this.editTool.onScale(event);
|
|
1480
1523
|
this.emitEvent(event);
|
|
1481
1524
|
}
|
|
@@ -1485,7 +1528,9 @@ class Editor extends draw.Group {
|
|
|
1485
1528
|
const { element } = this;
|
|
1486
1529
|
const worldOrigin = this.getWorldOrigin('center');
|
|
1487
1530
|
const transform = this.multiple ? this.getChangedTransform(() => element.safeChange(() => element.flip(axis))) : new draw.Matrix(draw.LeafHelper.getFlipTransform(element, axis));
|
|
1488
|
-
const
|
|
1531
|
+
const data = { target: element, editor: this, worldOrigin, scaleX: axis === 'x' ? -1 : 1, scaleY: axis === 'y' ? -1 : 1, transform };
|
|
1532
|
+
this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
|
|
1533
|
+
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
|
|
1489
1534
|
this.editTool.onScale(event);
|
|
1490
1535
|
this.emitEvent(event);
|
|
1491
1536
|
}
|
|
@@ -1495,7 +1540,9 @@ class Editor extends draw.Group {
|
|
|
1495
1540
|
const { element } = this;
|
|
1496
1541
|
const worldOrigin = this.getWorldOrigin(origin);
|
|
1497
1542
|
const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.rotateOf(origin, rotation)));
|
|
1498
|
-
const
|
|
1543
|
+
const data = { target: element, editor: this, worldOrigin, rotation, transform };
|
|
1544
|
+
this.emitEvent(new EditorRotateEvent(EditorRotateEvent.BEFORE_ROTATE, data));
|
|
1545
|
+
const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, data);
|
|
1499
1546
|
this.editTool.onRotate(event);
|
|
1500
1547
|
this.emitEvent(event);
|
|
1501
1548
|
}
|
|
@@ -1505,7 +1552,9 @@ class Editor extends draw.Group {
|
|
|
1505
1552
|
const { element } = this;
|
|
1506
1553
|
const worldOrigin = this.getWorldOrigin(origin);
|
|
1507
1554
|
const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.skewOf(origin, skewX, skewY)));
|
|
1508
|
-
const
|
|
1555
|
+
const data = { target: element, editor: this, worldOrigin, skewX, skewY, transform };
|
|
1556
|
+
this.emitEvent(new EditorSkewEvent(EditorSkewEvent.BEFORE_SKEW, data));
|
|
1557
|
+
const event = new EditorSkewEvent(EditorSkewEvent.SKEW, data);
|
|
1509
1558
|
this.editTool.onSkew(event);
|
|
1510
1559
|
this.emitEvent(event);
|
|
1511
1560
|
}
|
|
@@ -1523,6 +1572,7 @@ class Editor extends draw.Group {
|
|
|
1523
1572
|
}
|
|
1524
1573
|
group(userGroup) {
|
|
1525
1574
|
if (this.multiple) {
|
|
1575
|
+
this.emitGroupEvent(EditorGroupEvent.BEFORE_GROUP);
|
|
1526
1576
|
this.target = EditorHelper.group(this.list, this.element, userGroup);
|
|
1527
1577
|
this.emitGroupEvent(EditorGroupEvent.GROUP, this.target);
|
|
1528
1578
|
}
|
|
@@ -1538,11 +1588,13 @@ class Editor extends draw.Group {
|
|
|
1538
1588
|
return this.list;
|
|
1539
1589
|
}
|
|
1540
1590
|
openGroup(group) {
|
|
1591
|
+
this.emitGroupEvent(EditorGroupEvent.BEFORE_OPEN, group);
|
|
1541
1592
|
this.openedGroupList.add(group);
|
|
1542
1593
|
group.hitChildren = true;
|
|
1543
1594
|
this.emitGroupEvent(EditorGroupEvent.OPEN, group);
|
|
1544
1595
|
}
|
|
1545
1596
|
closeGroup(group) {
|
|
1597
|
+
this.emitGroupEvent(EditorGroupEvent.BEFORE_CLOSE, group);
|
|
1546
1598
|
this.openedGroupList.remove(group);
|
|
1547
1599
|
group.hitChildren = false;
|
|
1548
1600
|
this.emitGroupEvent(EditorGroupEvent.CLOSE, group);
|
|
@@ -1571,7 +1623,8 @@ class Editor extends draw.Group {
|
|
|
1571
1623
|
emitGroupEvent(type, group) {
|
|
1572
1624
|
const event = new EditorGroupEvent(type, { editTarget: group });
|
|
1573
1625
|
this.emitEvent(event);
|
|
1574
|
-
group
|
|
1626
|
+
if (group)
|
|
1627
|
+
group.emitEvent(event);
|
|
1575
1628
|
}
|
|
1576
1629
|
openInnerEditor(target, select) {
|
|
1577
1630
|
if (target && select)
|
|
@@ -1901,34 +1954,15 @@ exports.LineEditTool = __decorate([
|
|
|
1901
1954
|
|
|
1902
1955
|
draw.Plugin.add('editor', 'resize');
|
|
1903
1956
|
draw.Creator.editor = function (options) { return new Editor(options); };
|
|
1904
|
-
draw.
|
|
1905
|
-
draw.
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
draw.
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
draw.
|
|
1912
|
-
|
|
1913
|
-
});
|
|
1914
|
-
draw.defineKey(draw.Text.prototype, 'editInner', {
|
|
1915
|
-
get() { return 'TextEditor'; }
|
|
1916
|
-
});
|
|
1917
|
-
draw.UI.setEditConfig = function (config) {
|
|
1918
|
-
draw.defineKey(this.prototype, 'editConfig', {
|
|
1919
|
-
get() { return typeof config === 'function' ? config(this) : config; }
|
|
1920
|
-
});
|
|
1921
|
-
};
|
|
1922
|
-
draw.UI.setEditOuter = function (toolName) {
|
|
1923
|
-
draw.defineKey(this.prototype, 'editOuter', {
|
|
1924
|
-
get() { return typeof toolName === 'string' ? toolName : toolName(this); }
|
|
1925
|
-
});
|
|
1926
|
-
};
|
|
1927
|
-
draw.UI.setEditInner = function (editorName) {
|
|
1928
|
-
draw.defineKey(this.prototype, 'editInner', {
|
|
1929
|
-
get() { return typeof editorName === 'string' ? editorName : editorName(this); }
|
|
1930
|
-
});
|
|
1931
|
-
};
|
|
1957
|
+
draw.Box.addAttr('textBox', false, draw.dataType);
|
|
1958
|
+
draw.UI.addAttr('editConfig', undefined, draw.dataType);
|
|
1959
|
+
draw.UI.addAttr('editOuter', (ui) => ui.__.__isLinePath ? 'LineEditTool' : 'EditTool', draw.dataType);
|
|
1960
|
+
draw.UI.addAttr('editInner', 'PathEditor', draw.dataType);
|
|
1961
|
+
draw.Group.addAttr('editInner', '', draw.dataType);
|
|
1962
|
+
draw.Text.addAttr('editInner', 'TextEditor', draw.dataType);
|
|
1963
|
+
draw.UI.setEditConfig = function (config) { this.changeAttr('editConfig', config); };
|
|
1964
|
+
draw.UI.setEditOuter = function (toolName) { this.changeAttr('editOuter', toolName); };
|
|
1965
|
+
draw.UI.setEditInner = function (editorName) { this.changeAttr('editInner', editorName); };
|
|
1932
1966
|
|
|
1933
1967
|
exports.EditBox = EditBox;
|
|
1934
1968
|
exports.EditDataHelper = EditDataHelper;
|