@leafer-in/editor 1.9.9 → 1.9.11
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 +65 -49
- package/dist/editor.esm.js +67 -51
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.esm.min.js.map +1 -1
- package/dist/editor.js +65 -48
- package/dist/editor.min.cjs +1 -1
- package/dist/editor.min.cjs.map +1 -1
- package/dist/editor.min.js +1 -1
- package/dist/editor.min.js.map +1 -1
- package/package.json +6 -6
- package/src/decorator/data.ts +13 -2
- package/src/display/EditBox.ts +39 -32
- package/src/display/EditSelect.ts +4 -2
- package/src/helper/EditDataHelper.ts +17 -14
- package/types/index.d.ts +2 -0
package/dist/editor.cjs
CHANGED
|
@@ -68,7 +68,10 @@ function targetAttr(fn) {
|
|
|
68
68
|
t.setDimOthers(false);
|
|
69
69
|
t.setBright(false);
|
|
70
70
|
if (draw.isArray(value) && value.length > 1 && value[0].locked) value.splice(0, 1);
|
|
71
|
-
if (t.single)
|
|
71
|
+
if (t.single) {
|
|
72
|
+
delete t.element.syncEventer;
|
|
73
|
+
delete t.element.__world.ignorePixelSnap;
|
|
74
|
+
}
|
|
72
75
|
}
|
|
73
76
|
const type = isSelect ? EditorEvent.BEFORE_SELECT : EditorEvent.BEFORE_HOVER;
|
|
74
77
|
if (this.hasEvent(type)) this.emitEvent(new EditorEvent(type, {
|
|
@@ -89,7 +92,15 @@ function mergeConfigAttr() {
|
|
|
89
92
|
draw.defineKey(target, key, {
|
|
90
93
|
get() {
|
|
91
94
|
const {config: config, element: element, dragPoint: dragPoint, editBox: editBox, app: app} = this, mergeConfig = Object.assign({}, config);
|
|
92
|
-
if (element && element.editConfig)
|
|
95
|
+
if (element && element.editConfig) {
|
|
96
|
+
let {editConfig: editConfig} = element;
|
|
97
|
+
if (editConfig.hover || editConfig.hoverStyle) {
|
|
98
|
+
editConfig = Object.assign({}, editConfig);
|
|
99
|
+
delete editConfig.hover;
|
|
100
|
+
delete editConfig.hoverStyle;
|
|
101
|
+
}
|
|
102
|
+
Object.assign(mergeConfig, editConfig);
|
|
103
|
+
}
|
|
93
104
|
if (editBox.config) Object.assign(mergeConfig, editBox.config);
|
|
94
105
|
if (dragPoint) {
|
|
95
106
|
if (dragPoint.editConfig) Object.assign(mergeConfig, dragPoint.editConfig);
|
|
@@ -106,7 +117,7 @@ function mergeConfigAttr() {
|
|
|
106
117
|
};
|
|
107
118
|
}
|
|
108
119
|
|
|
109
|
-
const {abs: abs} = Math;
|
|
120
|
+
const {abs: abs$1} = Math;
|
|
110
121
|
|
|
111
122
|
const {copy: copy$1, scale: scale} = draw.MatrixHelper;
|
|
112
123
|
|
|
@@ -149,7 +160,7 @@ class Stroker extends draw.UI {
|
|
|
149
160
|
leaf = list[i];
|
|
150
161
|
const {worldTransform: worldTransform, worldRenderBounds: worldRenderBounds} = leaf;
|
|
151
162
|
if (worldRenderBounds.width && worldRenderBounds.height && (!bounds || bounds.hit(worldRenderBounds, options.matrix))) {
|
|
152
|
-
const aScaleX = abs(worldTransform.scaleX), aScaleY = abs(worldTransform.scaleY);
|
|
163
|
+
const aScaleX = abs$1(worldTransform.scaleX), aScaleY = abs$1(worldTransform.scaleY);
|
|
153
164
|
copy$1(matrix, worldTransform);
|
|
154
165
|
matrix.half = strokeWidth % 2;
|
|
155
166
|
if (aScaleX !== aScaleY) {
|
|
@@ -163,7 +174,7 @@ class Stroker extends draw.UI {
|
|
|
163
174
|
canvas.setWorld(matrix, options.matrix);
|
|
164
175
|
canvas.beginPath();
|
|
165
176
|
if (leaf.__.__useArrow) leaf.__drawPath(canvas); else leaf.__.__pathForRender ? leaf.__drawRenderPath(canvas) : leaf.__drawPathByBox(canvas);
|
|
166
|
-
data.strokeWidth = strokeWidth / abs(worldTransform.scaleX);
|
|
177
|
+
data.strokeWidth = strokeWidth / abs$1(worldTransform.scaleX);
|
|
167
178
|
}
|
|
168
179
|
if (stroke) draw.isString(stroke) ? draw.Paint.stroke(stroke, this, canvas) : draw.Paint.strokes(stroke, this, canvas);
|
|
169
180
|
if (fill) draw.isString(fill) ? draw.Paint.fill(fill, this, canvas) : draw.Paint.fills(fill, this, canvas);
|
|
@@ -275,8 +286,10 @@ class EditSelect extends draw.Group {
|
|
|
275
286
|
onHover() {
|
|
276
287
|
const {editor: editor} = this;
|
|
277
288
|
if (this.running && !this.dragging && !editor.dragging) {
|
|
278
|
-
const {
|
|
279
|
-
|
|
289
|
+
const {hoverTarget: hoverTarget, mergeConfig: mergeConfig} = editor, config = Object.assign({}, mergeConfig);
|
|
290
|
+
if (hoverTarget && hoverTarget.editConfig) Object.assign(config, hoverTarget.editConfig);
|
|
291
|
+
const {stroke: stroke, strokeWidth: strokeWidth, hover: hover, hoverStyle: hoverStyle} = config;
|
|
292
|
+
this.hoverStroker.setTarget(hover ? hoverTarget : null, Object.assign({
|
|
280
293
|
stroke: stroke,
|
|
281
294
|
strokeWidth: strokeWidth
|
|
282
295
|
}, hoverStyle || {}));
|
|
@@ -456,13 +469,11 @@ class EditSelect extends draw.Group {
|
|
|
456
469
|
|
|
457
470
|
const {topLeft: topLeft, top: top, topRight: topRight, right: right$1, bottomRight: bottomRight, bottom: bottom, bottomLeft: bottomLeft, left: left$1} = draw.Direction9;
|
|
458
471
|
|
|
459
|
-
const {toPoint: toPoint} = draw.AroundHelper;
|
|
460
|
-
|
|
461
|
-
const {within: within, sign: sign} = draw.MathHelper;
|
|
472
|
+
const {toPoint: toPoint} = draw.AroundHelper, {within: within, sign: sign} = draw.MathHelper, {abs: abs} = Math;
|
|
462
473
|
|
|
463
474
|
const EditDataHelper = {
|
|
464
475
|
getScaleData(target, startBounds, direction, totalMoveOrScale, lockRatio, around, flipable, scaleMode) {
|
|
465
|
-
let align, origin = {}, scaleX = 1, scaleY = 1;
|
|
476
|
+
let align, origin = {}, scaleX = 1, scaleY = 1, lockScale;
|
|
466
477
|
const {boxBounds: boxBounds, widthRange: widthRange, heightRange: heightRange, dragBounds: dragBounds, worldBoxBounds: worldBoxBounds} = target;
|
|
467
478
|
const {width: width, height: height} = startBounds;
|
|
468
479
|
const originChangedScaleX = target.scaleX / startBounds.scaleX;
|
|
@@ -532,23 +543,22 @@ const EditDataHelper = {
|
|
|
532
543
|
if (lockRatio === "corner" && direction % 2) {
|
|
533
544
|
lockRatio = false;
|
|
534
545
|
} else {
|
|
535
|
-
let scale;
|
|
536
546
|
switch (direction) {
|
|
537
547
|
case top:
|
|
538
548
|
case bottom:
|
|
539
|
-
|
|
549
|
+
scaleX = scaleY;
|
|
540
550
|
break;
|
|
541
551
|
|
|
542
552
|
case left$1:
|
|
543
553
|
case right$1:
|
|
544
|
-
|
|
554
|
+
scaleY = scaleX;
|
|
545
555
|
break;
|
|
546
556
|
|
|
547
557
|
default:
|
|
548
|
-
|
|
558
|
+
lockScale = Math.sqrt(abs(scaleX * scaleY));
|
|
559
|
+
scaleX = sign(scaleX) * lockScale;
|
|
560
|
+
scaleY = sign(scaleY) * lockScale;
|
|
549
561
|
}
|
|
550
|
-
scaleX = scaleX < 0 ? -scale : scale;
|
|
551
|
-
scaleY = scaleY < 0 ? -scale : scale;
|
|
552
562
|
}
|
|
553
563
|
}
|
|
554
564
|
}
|
|
@@ -566,7 +576,7 @@ const EditDataHelper = {
|
|
|
566
576
|
x: scaleX,
|
|
567
577
|
y: scaleY
|
|
568
578
|
};
|
|
569
|
-
|
|
579
|
+
core.DragBoundsHelper.limitScaleOf(target, origin, scaleData, lockRatio);
|
|
570
580
|
scaleX = scaleData.x;
|
|
571
581
|
scaleY = scaleData.y;
|
|
572
582
|
}
|
|
@@ -578,9 +588,13 @@ const EditDataHelper = {
|
|
|
578
588
|
const nowHeight = boxBounds.height * target.scaleY;
|
|
579
589
|
scaleY = within(nowHeight * scaleY, heightRange) / nowHeight;
|
|
580
590
|
}
|
|
581
|
-
if (useScaleX &&
|
|
582
|
-
if (useScaleY &&
|
|
583
|
-
if (lockRatio && scaleX !== scaleY)
|
|
591
|
+
if (useScaleX && abs(scaleX * worldBoxBounds.width) < 1) scaleX = sign(scaleX) / worldBoxBounds.width;
|
|
592
|
+
if (useScaleY && abs(scaleY * worldBoxBounds.height) < 1) scaleY = sign(scaleY) / worldBoxBounds.height;
|
|
593
|
+
if (lockRatio && scaleX !== scaleY) {
|
|
594
|
+
lockScale = Math.min(abs(scaleX), abs(scaleY));
|
|
595
|
+
scaleX = sign(scaleX) * lockScale;
|
|
596
|
+
scaleY = sign(scaleY) * lockScale;
|
|
597
|
+
}
|
|
584
598
|
return {
|
|
585
599
|
origin: origin,
|
|
586
600
|
scaleX: scaleX,
|
|
@@ -830,7 +844,7 @@ class EditBox extends draw.Group {
|
|
|
830
844
|
return this.scaleX * this.scaleY < 0;
|
|
831
845
|
}
|
|
832
846
|
get canUse() {
|
|
833
|
-
return this.
|
|
847
|
+
return this.app && this.editor.editing;
|
|
834
848
|
}
|
|
835
849
|
get canGesture() {
|
|
836
850
|
if (!this.canUse) return false;
|
|
@@ -911,7 +925,7 @@ class EditBox extends draw.Group {
|
|
|
911
925
|
}
|
|
912
926
|
load() {
|
|
913
927
|
const {target: target, mergeConfig: mergeConfig, single: single, rect: rect, circle: circle, resizePoints: resizePoints, resizeLines: resizeLines} = this;
|
|
914
|
-
const {stroke: stroke, strokeWidth: strokeWidth, resizeLine: resizeLine} = mergeConfig;
|
|
928
|
+
const {stroke: stroke, strokeWidth: strokeWidth, resizeLine: resizeLine, ignorePixelSnap: ignorePixelSnap} = mergeConfig;
|
|
915
929
|
const pointsStyle = this.getPointsStyle();
|
|
916
930
|
const middlePointsStyle = this.getMiddlePointsStyle();
|
|
917
931
|
this.visible = !target.locked;
|
|
@@ -931,16 +945,16 @@ class EditBox extends draw.Group {
|
|
|
931
945
|
strokeWidth: strokeWidth,
|
|
932
946
|
editConfig: editConfig
|
|
933
947
|
}, mergeConfig.rect || {}));
|
|
934
|
-
const
|
|
935
|
-
rect.hittable = !
|
|
936
|
-
|
|
937
|
-
if (syncEventer) {
|
|
948
|
+
const rectThrough = draw.isNull(mergeConfig.rectThrough) ? single : mergeConfig.rectThrough;
|
|
949
|
+
rect.hittable = !rectThrough;
|
|
950
|
+
if (rectThrough) {
|
|
938
951
|
target.syncEventer = rect;
|
|
939
952
|
this.app.interaction.bottomList = [ {
|
|
940
953
|
target: rect,
|
|
941
954
|
proxy: target
|
|
942
955
|
} ];
|
|
943
956
|
}
|
|
957
|
+
if (single) draw.DataHelper.stintSet(target.__world, "ignorePixelSnap", ignorePixelSnap);
|
|
944
958
|
updateMoveCursor(this);
|
|
945
959
|
}
|
|
946
960
|
update() {
|
|
@@ -1104,29 +1118,25 @@ class EditBox extends draw.Group {
|
|
|
1104
1118
|
this.dragPoint = null;
|
|
1105
1119
|
}
|
|
1106
1120
|
onTransformStart(e) {
|
|
1107
|
-
if (this.
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
dragStartData.rotation = target.rotation;
|
|
1120
|
-
}
|
|
1121
|
+
if (this.moving) this.editor.opacity = this.mergedConfig.hideOnMove ? 0 : 1;
|
|
1122
|
+
if (this.resizing) draw.ResizeEvent.resizingKeys = this.editor.leafList.keys;
|
|
1123
|
+
const {dragStartData: dragStartData, target: target} = this;
|
|
1124
|
+
dragStartData.x = e.x;
|
|
1125
|
+
dragStartData.y = e.y;
|
|
1126
|
+
dragStartData.totalOffset = draw.getPointData();
|
|
1127
|
+
dragStartData.point = {
|
|
1128
|
+
x: target.x,
|
|
1129
|
+
y: target.y
|
|
1130
|
+
};
|
|
1131
|
+
dragStartData.bounds = Object.assign({}, target.getLayoutBounds("box", "local"));
|
|
1132
|
+
dragStartData.rotation = target.rotation;
|
|
1121
1133
|
}
|
|
1122
1134
|
onTransformEnd(e) {
|
|
1123
|
-
if (this.
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
this.update();
|
|
1129
|
-
}
|
|
1135
|
+
if (this.canDragLimitAnimate && (e instanceof core.DragEvent || e instanceof core.MoveEvent)) this.transformTool.onMove(e);
|
|
1136
|
+
if (this.resizing) draw.ResizeEvent.resizingKeys = null;
|
|
1137
|
+
this.dragging = this.gesturing = this.moving = this.resizing = this.rotating = this.skewing = false;
|
|
1138
|
+
this.editor.opacity = 1;
|
|
1139
|
+
this.editor.update();
|
|
1130
1140
|
}
|
|
1131
1141
|
onMove(e) {
|
|
1132
1142
|
if (this.canGesture && e.moveType !== "drag") {
|
|
@@ -1155,6 +1165,12 @@ class EditBox extends draw.Group {
|
|
|
1155
1165
|
}
|
|
1156
1166
|
}
|
|
1157
1167
|
}
|
|
1168
|
+
onGestureStart(e) {
|
|
1169
|
+
if (this.canGesture && e.moveType !== "drag") this.onTransformStart(e);
|
|
1170
|
+
}
|
|
1171
|
+
onGestureEnd(e) {
|
|
1172
|
+
if (this.canGesture && e.moveType !== "drag") this.onTransformEnd(e);
|
|
1173
|
+
}
|
|
1158
1174
|
isHoldRotateKey(e) {
|
|
1159
1175
|
const {rotateKey: rotateKey} = this.mergedConfig;
|
|
1160
1176
|
if (rotateKey) return e.isHoldKeys(rotateKey);
|
|
@@ -1224,7 +1240,7 @@ class EditBox extends draw.Group {
|
|
|
1224
1240
|
const {rect: rect, editor: editor, __eventIds: events} = this;
|
|
1225
1241
|
events.push(rect.on_([ [ core.PointerEvent.DOUBLE_TAP, this.onDoubleTap, this ], [ core.PointerEvent.LONG_PRESS, this.onLongPress, this ] ]));
|
|
1226
1242
|
this.waitLeafer(() => {
|
|
1227
|
-
events.push(editor.app.on_([ [ [ core.KeyEvent.HOLD, core.KeyEvent.UP ], this.onKey, this ], [ core.KeyEvent.DOWN, this.onArrow, this ], [
|
|
1243
|
+
events.push(editor.app.on_([ [ [ core.KeyEvent.HOLD, core.KeyEvent.UP ], this.onKey, this ], [ core.KeyEvent.DOWN, this.onArrow, this ], [ core.MoveEvent.BEFORE_MOVE, this.onMove, this, true ], [ core.ZoomEvent.BEFORE_ZOOM, this.onScale, this, true ], [ core.RotateEvent.BEFORE_ROTATE, this.onRotate, this, true ], [ [ core.MoveEvent.START, core.ZoomEvent.START, core.RotateEvent.START ], this.onGestureStart, this ], [ [ core.MoveEvent.END, core.ZoomEvent.END, core.RotateEvent.END ], this.onGestureEnd, this ] ]));
|
|
1228
1244
|
});
|
|
1229
1245
|
}
|
|
1230
1246
|
__removeListenEvents() {
|
package/dist/editor.esm.js
CHANGED
|
@@ -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, isNumber,
|
|
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, Box, DataHelper, ResizeEvent, getPointData, Text, Matrix, Debug, LeafHelper, PropertyEvent, Plugin, RenderEvent, LeaferEvent, Creator, dataType } from "@leafer-ui/draw";
|
|
2
2
|
|
|
3
|
-
import { PointerEvent, DragEvent, MoveEvent, ZoomEvent, RotateEvent, KeyEvent, useModule } from "@leafer-ui/core";
|
|
3
|
+
import { PointerEvent, DragEvent, MoveEvent, ZoomEvent, DragBoundsHelper, RotateEvent, KeyEvent, useModule } from "@leafer-ui/core";
|
|
4
4
|
|
|
5
5
|
import "@leafer-in/resize";
|
|
6
6
|
|
|
@@ -66,7 +66,10 @@ function targetAttr(fn) {
|
|
|
66
66
|
t.setDimOthers(false);
|
|
67
67
|
t.setBright(false);
|
|
68
68
|
if (isArray(value) && value.length > 1 && value[0].locked) value.splice(0, 1);
|
|
69
|
-
if (t.single)
|
|
69
|
+
if (t.single) {
|
|
70
|
+
delete t.element.syncEventer;
|
|
71
|
+
delete t.element.__world.ignorePixelSnap;
|
|
72
|
+
}
|
|
70
73
|
}
|
|
71
74
|
const type = isSelect ? EditorEvent.BEFORE_SELECT : EditorEvent.BEFORE_HOVER;
|
|
72
75
|
if (this.hasEvent(type)) this.emitEvent(new EditorEvent(type, {
|
|
@@ -87,7 +90,15 @@ function mergeConfigAttr() {
|
|
|
87
90
|
defineKey(target, key, {
|
|
88
91
|
get() {
|
|
89
92
|
const {config: config, element: element, dragPoint: dragPoint, editBox: editBox, app: app} = this, mergeConfig = Object.assign({}, config);
|
|
90
|
-
if (element && element.editConfig)
|
|
93
|
+
if (element && element.editConfig) {
|
|
94
|
+
let {editConfig: editConfig} = element;
|
|
95
|
+
if (editConfig.hover || editConfig.hoverStyle) {
|
|
96
|
+
editConfig = Object.assign({}, editConfig);
|
|
97
|
+
delete editConfig.hover;
|
|
98
|
+
delete editConfig.hoverStyle;
|
|
99
|
+
}
|
|
100
|
+
Object.assign(mergeConfig, editConfig);
|
|
101
|
+
}
|
|
91
102
|
if (editBox.config) Object.assign(mergeConfig, editBox.config);
|
|
92
103
|
if (dragPoint) {
|
|
93
104
|
if (dragPoint.editConfig) Object.assign(mergeConfig, dragPoint.editConfig);
|
|
@@ -104,7 +115,7 @@ function mergeConfigAttr() {
|
|
|
104
115
|
};
|
|
105
116
|
}
|
|
106
117
|
|
|
107
|
-
const {abs: abs} = Math;
|
|
118
|
+
const {abs: abs$1} = Math;
|
|
108
119
|
|
|
109
120
|
const {copy: copy$1, scale: scale} = MatrixHelper;
|
|
110
121
|
|
|
@@ -147,7 +158,7 @@ class Stroker extends UI {
|
|
|
147
158
|
leaf = list[i];
|
|
148
159
|
const {worldTransform: worldTransform, worldRenderBounds: worldRenderBounds} = leaf;
|
|
149
160
|
if (worldRenderBounds.width && worldRenderBounds.height && (!bounds || bounds.hit(worldRenderBounds, options.matrix))) {
|
|
150
|
-
const aScaleX = abs(worldTransform.scaleX), aScaleY = abs(worldTransform.scaleY);
|
|
161
|
+
const aScaleX = abs$1(worldTransform.scaleX), aScaleY = abs$1(worldTransform.scaleY);
|
|
151
162
|
copy$1(matrix, worldTransform);
|
|
152
163
|
matrix.half = strokeWidth % 2;
|
|
153
164
|
if (aScaleX !== aScaleY) {
|
|
@@ -161,7 +172,7 @@ class Stroker extends UI {
|
|
|
161
172
|
canvas.setWorld(matrix, options.matrix);
|
|
162
173
|
canvas.beginPath();
|
|
163
174
|
if (leaf.__.__useArrow) leaf.__drawPath(canvas); else leaf.__.__pathForRender ? leaf.__drawRenderPath(canvas) : leaf.__drawPathByBox(canvas);
|
|
164
|
-
data.strokeWidth = strokeWidth / abs(worldTransform.scaleX);
|
|
175
|
+
data.strokeWidth = strokeWidth / abs$1(worldTransform.scaleX);
|
|
165
176
|
}
|
|
166
177
|
if (stroke) isString(stroke) ? Paint.stroke(stroke, this, canvas) : Paint.strokes(stroke, this, canvas);
|
|
167
178
|
if (fill) isString(fill) ? Paint.fill(fill, this, canvas) : Paint.fills(fill, this, canvas);
|
|
@@ -273,8 +284,10 @@ class EditSelect extends Group {
|
|
|
273
284
|
onHover() {
|
|
274
285
|
const {editor: editor} = this;
|
|
275
286
|
if (this.running && !this.dragging && !editor.dragging) {
|
|
276
|
-
const {
|
|
277
|
-
|
|
287
|
+
const {hoverTarget: hoverTarget, mergeConfig: mergeConfig} = editor, config = Object.assign({}, mergeConfig);
|
|
288
|
+
if (hoverTarget && hoverTarget.editConfig) Object.assign(config, hoverTarget.editConfig);
|
|
289
|
+
const {stroke: stroke, strokeWidth: strokeWidth, hover: hover, hoverStyle: hoverStyle} = config;
|
|
290
|
+
this.hoverStroker.setTarget(hover ? hoverTarget : null, Object.assign({
|
|
278
291
|
stroke: stroke,
|
|
279
292
|
strokeWidth: strokeWidth
|
|
280
293
|
}, hoverStyle || {}));
|
|
@@ -454,13 +467,11 @@ class EditSelect extends Group {
|
|
|
454
467
|
|
|
455
468
|
const {topLeft: topLeft, top: top, topRight: topRight, right: right$1, bottomRight: bottomRight, bottom: bottom, bottomLeft: bottomLeft, left: left$1} = Direction9;
|
|
456
469
|
|
|
457
|
-
const {toPoint: toPoint} = AroundHelper;
|
|
458
|
-
|
|
459
|
-
const {within: within, sign: sign} = MathHelper;
|
|
470
|
+
const {toPoint: toPoint} = AroundHelper, {within: within, sign: sign} = MathHelper, {abs: abs} = Math;
|
|
460
471
|
|
|
461
472
|
const EditDataHelper = {
|
|
462
473
|
getScaleData(target, startBounds, direction, totalMoveOrScale, lockRatio, around, flipable, scaleMode) {
|
|
463
|
-
let align, origin = {}, scaleX = 1, scaleY = 1;
|
|
474
|
+
let align, origin = {}, scaleX = 1, scaleY = 1, lockScale;
|
|
464
475
|
const {boxBounds: boxBounds, widthRange: widthRange, heightRange: heightRange, dragBounds: dragBounds, worldBoxBounds: worldBoxBounds} = target;
|
|
465
476
|
const {width: width, height: height} = startBounds;
|
|
466
477
|
const originChangedScaleX = target.scaleX / startBounds.scaleX;
|
|
@@ -530,23 +541,22 @@ const EditDataHelper = {
|
|
|
530
541
|
if (lockRatio === "corner" && direction % 2) {
|
|
531
542
|
lockRatio = false;
|
|
532
543
|
} else {
|
|
533
|
-
let scale;
|
|
534
544
|
switch (direction) {
|
|
535
545
|
case top:
|
|
536
546
|
case bottom:
|
|
537
|
-
|
|
547
|
+
scaleX = scaleY;
|
|
538
548
|
break;
|
|
539
549
|
|
|
540
550
|
case left$1:
|
|
541
551
|
case right$1:
|
|
542
|
-
|
|
552
|
+
scaleY = scaleX;
|
|
543
553
|
break;
|
|
544
554
|
|
|
545
555
|
default:
|
|
546
|
-
|
|
556
|
+
lockScale = Math.sqrt(abs(scaleX * scaleY));
|
|
557
|
+
scaleX = sign(scaleX) * lockScale;
|
|
558
|
+
scaleY = sign(scaleY) * lockScale;
|
|
547
559
|
}
|
|
548
|
-
scaleX = scaleX < 0 ? -scale : scale;
|
|
549
|
-
scaleY = scaleY < 0 ? -scale : scale;
|
|
550
560
|
}
|
|
551
561
|
}
|
|
552
562
|
}
|
|
@@ -564,7 +574,7 @@ const EditDataHelper = {
|
|
|
564
574
|
x: scaleX,
|
|
565
575
|
y: scaleY
|
|
566
576
|
};
|
|
567
|
-
DragBoundsHelper.limitScaleOf(target, origin, scaleData);
|
|
577
|
+
DragBoundsHelper.limitScaleOf(target, origin, scaleData, lockRatio);
|
|
568
578
|
scaleX = scaleData.x;
|
|
569
579
|
scaleY = scaleData.y;
|
|
570
580
|
}
|
|
@@ -576,9 +586,13 @@ const EditDataHelper = {
|
|
|
576
586
|
const nowHeight = boxBounds.height * target.scaleY;
|
|
577
587
|
scaleY = within(nowHeight * scaleY, heightRange) / nowHeight;
|
|
578
588
|
}
|
|
579
|
-
if (useScaleX &&
|
|
580
|
-
if (useScaleY &&
|
|
581
|
-
if (lockRatio && scaleX !== scaleY)
|
|
589
|
+
if (useScaleX && abs(scaleX * worldBoxBounds.width) < 1) scaleX = sign(scaleX) / worldBoxBounds.width;
|
|
590
|
+
if (useScaleY && abs(scaleY * worldBoxBounds.height) < 1) scaleY = sign(scaleY) / worldBoxBounds.height;
|
|
591
|
+
if (lockRatio && scaleX !== scaleY) {
|
|
592
|
+
lockScale = Math.min(abs(scaleX), abs(scaleY));
|
|
593
|
+
scaleX = sign(scaleX) * lockScale;
|
|
594
|
+
scaleY = sign(scaleY) * lockScale;
|
|
595
|
+
}
|
|
582
596
|
return {
|
|
583
597
|
origin: origin,
|
|
584
598
|
scaleX: scaleX,
|
|
@@ -828,7 +842,7 @@ class EditBox extends Group {
|
|
|
828
842
|
return this.scaleX * this.scaleY < 0;
|
|
829
843
|
}
|
|
830
844
|
get canUse() {
|
|
831
|
-
return this.
|
|
845
|
+
return this.app && this.editor.editing;
|
|
832
846
|
}
|
|
833
847
|
get canGesture() {
|
|
834
848
|
if (!this.canUse) return false;
|
|
@@ -909,7 +923,7 @@ class EditBox extends Group {
|
|
|
909
923
|
}
|
|
910
924
|
load() {
|
|
911
925
|
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;
|
|
926
|
+
const {stroke: stroke, strokeWidth: strokeWidth, resizeLine: resizeLine, ignorePixelSnap: ignorePixelSnap} = mergeConfig;
|
|
913
927
|
const pointsStyle = this.getPointsStyle();
|
|
914
928
|
const middlePointsStyle = this.getMiddlePointsStyle();
|
|
915
929
|
this.visible = !target.locked;
|
|
@@ -929,16 +943,16 @@ class EditBox extends Group {
|
|
|
929
943
|
strokeWidth: strokeWidth,
|
|
930
944
|
editConfig: editConfig
|
|
931
945
|
}, mergeConfig.rect || {}));
|
|
932
|
-
const
|
|
933
|
-
rect.hittable = !
|
|
934
|
-
|
|
935
|
-
if (syncEventer) {
|
|
946
|
+
const rectThrough = isNull(mergeConfig.rectThrough) ? single : mergeConfig.rectThrough;
|
|
947
|
+
rect.hittable = !rectThrough;
|
|
948
|
+
if (rectThrough) {
|
|
936
949
|
target.syncEventer = rect;
|
|
937
950
|
this.app.interaction.bottomList = [ {
|
|
938
951
|
target: rect,
|
|
939
952
|
proxy: target
|
|
940
953
|
} ];
|
|
941
954
|
}
|
|
955
|
+
if (single) DataHelper.stintSet(target.__world, "ignorePixelSnap", ignorePixelSnap);
|
|
942
956
|
updateMoveCursor(this);
|
|
943
957
|
}
|
|
944
958
|
update() {
|
|
@@ -1102,29 +1116,25 @@ class EditBox extends Group {
|
|
|
1102
1116
|
this.dragPoint = null;
|
|
1103
1117
|
}
|
|
1104
1118
|
onTransformStart(e) {
|
|
1105
|
-
if (this.
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
dragStartData.rotation = target.rotation;
|
|
1118
|
-
}
|
|
1119
|
+
if (this.moving) this.editor.opacity = this.mergedConfig.hideOnMove ? 0 : 1;
|
|
1120
|
+
if (this.resizing) ResizeEvent.resizingKeys = this.editor.leafList.keys;
|
|
1121
|
+
const {dragStartData: dragStartData, target: target} = this;
|
|
1122
|
+
dragStartData.x = e.x;
|
|
1123
|
+
dragStartData.y = e.y;
|
|
1124
|
+
dragStartData.totalOffset = getPointData();
|
|
1125
|
+
dragStartData.point = {
|
|
1126
|
+
x: target.x,
|
|
1127
|
+
y: target.y
|
|
1128
|
+
};
|
|
1129
|
+
dragStartData.bounds = Object.assign({}, target.getLayoutBounds("box", "local"));
|
|
1130
|
+
dragStartData.rotation = target.rotation;
|
|
1119
1131
|
}
|
|
1120
1132
|
onTransformEnd(e) {
|
|
1121
|
-
if (this.
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
this.update();
|
|
1127
|
-
}
|
|
1133
|
+
if (this.canDragLimitAnimate && (e instanceof DragEvent || e instanceof MoveEvent)) this.transformTool.onMove(e);
|
|
1134
|
+
if (this.resizing) ResizeEvent.resizingKeys = null;
|
|
1135
|
+
this.dragging = this.gesturing = this.moving = this.resizing = this.rotating = this.skewing = false;
|
|
1136
|
+
this.editor.opacity = 1;
|
|
1137
|
+
this.editor.update();
|
|
1128
1138
|
}
|
|
1129
1139
|
onMove(e) {
|
|
1130
1140
|
if (this.canGesture && e.moveType !== "drag") {
|
|
@@ -1153,6 +1163,12 @@ class EditBox extends Group {
|
|
|
1153
1163
|
}
|
|
1154
1164
|
}
|
|
1155
1165
|
}
|
|
1166
|
+
onGestureStart(e) {
|
|
1167
|
+
if (this.canGesture && e.moveType !== "drag") this.onTransformStart(e);
|
|
1168
|
+
}
|
|
1169
|
+
onGestureEnd(e) {
|
|
1170
|
+
if (this.canGesture && e.moveType !== "drag") this.onTransformEnd(e);
|
|
1171
|
+
}
|
|
1156
1172
|
isHoldRotateKey(e) {
|
|
1157
1173
|
const {rotateKey: rotateKey} = this.mergedConfig;
|
|
1158
1174
|
if (rotateKey) return e.isHoldKeys(rotateKey);
|
|
@@ -1222,7 +1238,7 @@ class EditBox extends Group {
|
|
|
1222
1238
|
const {rect: rect, editor: editor, __eventIds: events} = this;
|
|
1223
1239
|
events.push(rect.on_([ [ PointerEvent.DOUBLE_TAP, this.onDoubleTap, this ], [ PointerEvent.LONG_PRESS, this.onLongPress, this ] ]));
|
|
1224
1240
|
this.waitLeafer(() => {
|
|
1225
|
-
events.push(editor.app.on_([ [ [ KeyEvent.HOLD, KeyEvent.UP ], this.onKey, this ], [ KeyEvent.DOWN, this.onArrow, this ], [
|
|
1241
|
+
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.START, ZoomEvent.START, RotateEvent.START ], this.onGestureStart, this ], [ [ MoveEvent.END, ZoomEvent.END, RotateEvent.END ], this.onGestureEnd, this ] ]));
|
|
1226
1242
|
});
|
|
1227
1243
|
}
|
|
1228
1244
|
__removeListenEvents() {
|