@leafer-in/editor 1.0.0-rc.23 → 1.0.0-rc.25
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 +147 -62
- package/dist/editor.esm.js +143 -64
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.js +147 -62
- package/dist/editor.min.cjs +1 -1
- package/dist/editor.min.js +1 -1
- package/package.json +5 -5
- package/src/display/EditBox.ts +1 -0
- package/src/index.ts +2 -6
- package/src/tool/EditTool.ts +3 -3
- package/src/tool/LineEditTool.ts +88 -36
- package/types/index.d.ts +5 -1
package/dist/editor.cjs
CHANGED
|
@@ -82,6 +82,39 @@ const PathScaler = {
|
|
|
82
82
|
};
|
|
83
83
|
const { scalePoints } = PathScaler;
|
|
84
84
|
|
|
85
|
+
const matrix$1 = draw.MatrixHelper.get();
|
|
86
|
+
function scaleResize(leaf, scaleX, scaleY) {
|
|
87
|
+
if (leaf.pathInputed) {
|
|
88
|
+
scaleResizePath(leaf, scaleX, scaleY);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
leaf.width *= scaleX;
|
|
92
|
+
leaf.height *= scaleY;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function scaleResizeFont(leaf, scaleX, scaleY) {
|
|
96
|
+
if (scaleX !== 1)
|
|
97
|
+
leaf.fontSize *= scaleX;
|
|
98
|
+
else if (scaleY !== 1)
|
|
99
|
+
leaf.fontSize *= scaleY;
|
|
100
|
+
}
|
|
101
|
+
function scaleResizePath(leaf, scaleX, scaleY) {
|
|
102
|
+
PathScaler.scale(leaf.__.path, scaleX, scaleY);
|
|
103
|
+
leaf.path = leaf.__.path;
|
|
104
|
+
}
|
|
105
|
+
function scaleResizePoints(leaf, scaleX, scaleY) {
|
|
106
|
+
PathScaler.scalePoints(leaf.__.points, scaleX, scaleY);
|
|
107
|
+
leaf.points = leaf.__.points;
|
|
108
|
+
}
|
|
109
|
+
function scaleResizeGroup(group, scaleX, scaleY) {
|
|
110
|
+
const { children } = group;
|
|
111
|
+
for (let i = 0; i < children.length; i++) {
|
|
112
|
+
matrix$1.a = scaleX;
|
|
113
|
+
matrix$1.d = scaleY;
|
|
114
|
+
children[i].transform(matrix$1, true);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
85
118
|
draw.Leaf.prototype.scaleResize = function (scaleX, scaleY = scaleX, noResize) {
|
|
86
119
|
const data = this;
|
|
87
120
|
if (noResize) {
|
|
@@ -96,23 +129,26 @@ draw.Leaf.prototype.scaleResize = function (scaleX, scaleY = scaleX, noResize) {
|
|
|
96
129
|
this.__scaleResize(scaleX, scaleY);
|
|
97
130
|
}
|
|
98
131
|
};
|
|
99
|
-
function scaleResize(leaf, scaleX, scaleY) {
|
|
100
|
-
if (scaleX !== 1)
|
|
101
|
-
leaf.width *= scaleX;
|
|
102
|
-
if (scaleY !== 1)
|
|
103
|
-
leaf.height *= scaleY;
|
|
104
|
-
}
|
|
105
132
|
draw.Leaf.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
106
133
|
scaleResize(this, scaleX, scaleY);
|
|
107
134
|
};
|
|
135
|
+
draw.Text.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
136
|
+
if (this.editConfig && this.editConfig.editSize === 'font-size') {
|
|
137
|
+
scaleResizeFont(this, scaleX, scaleY);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
scaleResize(this, scaleX, scaleY);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
108
143
|
draw.Path.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
109
|
-
|
|
110
|
-
this.path = this.__.path;
|
|
144
|
+
scaleResizePath(this, scaleX, scaleY);
|
|
111
145
|
};
|
|
112
146
|
draw.Line.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
113
|
-
if (this.
|
|
114
|
-
|
|
115
|
-
|
|
147
|
+
if (this.pathInputed) {
|
|
148
|
+
scaleResizePath(this, scaleX, scaleY);
|
|
149
|
+
}
|
|
150
|
+
else if (this.points) {
|
|
151
|
+
scaleResizePoints(this, scaleX, scaleY);
|
|
116
152
|
}
|
|
117
153
|
else {
|
|
118
154
|
const point = this.toPoint;
|
|
@@ -122,29 +158,22 @@ draw.Line.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
|
122
158
|
}
|
|
123
159
|
};
|
|
124
160
|
draw.Polygon.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
125
|
-
if (this.
|
|
126
|
-
|
|
127
|
-
|
|
161
|
+
if (this.pathInputed) {
|
|
162
|
+
scaleResizePath(this, scaleX, scaleY);
|
|
163
|
+
}
|
|
164
|
+
else if (this.points) {
|
|
165
|
+
scaleResizePoints(this, scaleX, scaleY);
|
|
128
166
|
}
|
|
129
167
|
else {
|
|
130
168
|
scaleResize(this, scaleX, scaleY);
|
|
131
169
|
}
|
|
132
170
|
};
|
|
133
|
-
const matrix$1 = draw.MatrixHelper.get();
|
|
134
|
-
function groupScaleResize(group, scaleX, scaleY) {
|
|
135
|
-
const { children } = group;
|
|
136
|
-
for (let i = 0; i < children.length; i++) {
|
|
137
|
-
matrix$1.a = scaleX;
|
|
138
|
-
matrix$1.d = scaleY;
|
|
139
|
-
children[i].transform(matrix$1, true);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
171
|
draw.Group.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
143
|
-
|
|
172
|
+
scaleResizeGroup(this, scaleX, scaleY);
|
|
144
173
|
};
|
|
145
174
|
draw.Box.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
146
175
|
if (this.__.__autoSize && this.children.length) {
|
|
147
|
-
|
|
176
|
+
scaleResizeGroup(this, scaleX, scaleY);
|
|
148
177
|
}
|
|
149
178
|
else {
|
|
150
179
|
scaleResize(this, scaleX, scaleY);
|
|
@@ -239,7 +268,7 @@ function targetAttr(fn) {
|
|
|
239
268
|
|
|
240
269
|
const matrix = draw.MatrixHelper.get();
|
|
241
270
|
const { abs } = Math;
|
|
242
|
-
const { copy, scale } = draw.MatrixHelper;
|
|
271
|
+
const { copy: copy$1, scale } = draw.MatrixHelper;
|
|
243
272
|
class Stroker extends draw.UI {
|
|
244
273
|
constructor() {
|
|
245
274
|
super();
|
|
@@ -262,7 +291,7 @@ class Stroker extends draw.UI {
|
|
|
262
291
|
if (bounds && bounds.hit(leaf.__world, options.matrix)) {
|
|
263
292
|
const aScaleX = abs(leaf.__world.scaleX), aScaleY = abs(leaf.__world.scaleY);
|
|
264
293
|
if (aScaleX !== aScaleY) {
|
|
265
|
-
copy(matrix, leaf.__world);
|
|
294
|
+
copy$1(matrix, leaf.__world);
|
|
266
295
|
scale(matrix, 1 / aScaleX, 1 / aScaleY);
|
|
267
296
|
canvas.setWorld(matrix, options.matrix);
|
|
268
297
|
canvas.beginPath();
|
|
@@ -855,6 +884,8 @@ class EditBox extends draw.Group {
|
|
|
855
884
|
}
|
|
856
885
|
}
|
|
857
886
|
circle.visible = showPoints && rotateable && !!mergeConfig.rotatePoint;
|
|
887
|
+
if (rect.path)
|
|
888
|
+
rect.path = null;
|
|
858
889
|
rect.set(Object.assign(Object.assign({}, bounds), { visible: true }));
|
|
859
890
|
const buttonVisible = showPoints && (circle.visible || this.buttons.children.length > 1);
|
|
860
891
|
this.buttons.visible = buttonVisible;
|
|
@@ -1555,7 +1586,7 @@ exports.EditTool = class EditTool extends InnerEditor {
|
|
|
1555
1586
|
const { app, list } = editor;
|
|
1556
1587
|
app.lockLayout();
|
|
1557
1588
|
list.forEach(target => {
|
|
1558
|
-
const resize = editor.getEditSize(target)
|
|
1589
|
+
const resize = editor.getEditSize(target) !== 'scale';
|
|
1559
1590
|
if (transform) {
|
|
1560
1591
|
target.transformWorld(transform, resize);
|
|
1561
1592
|
}
|
|
@@ -1570,7 +1601,7 @@ exports.EditTool = class EditTool extends InnerEditor {
|
|
|
1570
1601
|
const { app, list } = editor;
|
|
1571
1602
|
app.lockLayout();
|
|
1572
1603
|
list.forEach(target => {
|
|
1573
|
-
const resize = editor.getEditSize(target)
|
|
1604
|
+
const resize = editor.getEditSize(target) !== 'scale';
|
|
1574
1605
|
if (transform) {
|
|
1575
1606
|
target.transformWorld(transform, resize);
|
|
1576
1607
|
}
|
|
@@ -1585,7 +1616,7 @@ exports.EditTool = class EditTool extends InnerEditor {
|
|
|
1585
1616
|
const { app, list } = editor;
|
|
1586
1617
|
app.lockLayout();
|
|
1587
1618
|
list.forEach(target => {
|
|
1588
|
-
const resize = editor.getEditSize(target)
|
|
1619
|
+
const resize = editor.getEditSize(target) !== 'scale';
|
|
1589
1620
|
if (transform) {
|
|
1590
1621
|
target.transformWorld(transform, resize);
|
|
1591
1622
|
}
|
|
@@ -1619,6 +1650,7 @@ exports.EditTool = __decorate([
|
|
|
1619
1650
|
], exports.EditTool);
|
|
1620
1651
|
|
|
1621
1652
|
const { left, right } = draw.Direction9;
|
|
1653
|
+
const { move, copy } = draw.PointHelper;
|
|
1622
1654
|
exports.LineEditTool = class LineEditTool extends exports.EditTool {
|
|
1623
1655
|
constructor() {
|
|
1624
1656
|
super(...arguments);
|
|
@@ -1627,50 +1659,100 @@ exports.LineEditTool = class LineEditTool extends exports.EditTool {
|
|
|
1627
1659
|
get tag() { return 'LineEditTool'; }
|
|
1628
1660
|
onScaleWithDrag(e) {
|
|
1629
1661
|
const { drag, direction, lockRatio, around } = e;
|
|
1630
|
-
const
|
|
1631
|
-
const
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1662
|
+
const line = e.target;
|
|
1663
|
+
const isDragFrom = direction === left;
|
|
1664
|
+
if (line.pathInputed) {
|
|
1665
|
+
const { path } = line.__;
|
|
1666
|
+
const { from, to } = this.getFromToByPath(path);
|
|
1667
|
+
this.dragPoint(from, to, isDragFrom, around, this.getInnerMove(line, drag, lockRatio));
|
|
1668
|
+
path[1] = from.x, path[2] = from.y;
|
|
1669
|
+
path[4] = to.x, path[5] = to.y;
|
|
1670
|
+
line.path = path;
|
|
1671
|
+
}
|
|
1672
|
+
else if (line.points) {
|
|
1673
|
+
const { points } = line;
|
|
1674
|
+
const { from, to } = this.getFromToByPoints(points);
|
|
1675
|
+
this.dragPoint(from, to, isDragFrom, around, this.getInnerMove(line, drag, lockRatio));
|
|
1676
|
+
points[0] = from.x, points[1] = from.y;
|
|
1677
|
+
points[2] = to.x, points[3] = to.y;
|
|
1678
|
+
line.points = points;
|
|
1679
|
+
}
|
|
1680
|
+
else {
|
|
1681
|
+
const from = draw.getPointData();
|
|
1682
|
+
const { toPoint } = line;
|
|
1683
|
+
line.rotation = 0;
|
|
1684
|
+
this.dragPoint(from, toPoint, isDragFrom, around, this.getInnerMove(line, drag, lockRatio));
|
|
1685
|
+
line.getLocalPointByInner(from, null, null, true);
|
|
1686
|
+
line.getLocalPointByInner(toPoint, null, null, true);
|
|
1687
|
+
line.x = from.x;
|
|
1688
|
+
line.y = from.y;
|
|
1689
|
+
line.getInnerPointByLocal(toPoint, null, null, true);
|
|
1690
|
+
line.toPoint = toPoint;
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
getInnerMove(ui, event, lockRatio) {
|
|
1694
|
+
const movePoint = event.getInnerMove(ui);
|
|
1635
1695
|
if (lockRatio) {
|
|
1636
|
-
if (Math.abs(x) > Math.abs(y)) {
|
|
1637
|
-
y = 0;
|
|
1696
|
+
if (Math.abs(movePoint.x) > Math.abs(movePoint.y)) {
|
|
1697
|
+
movePoint.y = 0;
|
|
1638
1698
|
}
|
|
1639
1699
|
else {
|
|
1640
|
-
x = 0;
|
|
1700
|
+
movePoint.x = 0;
|
|
1641
1701
|
}
|
|
1642
1702
|
}
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1703
|
+
return movePoint;
|
|
1704
|
+
}
|
|
1705
|
+
getFromToByPath(path) {
|
|
1706
|
+
return {
|
|
1707
|
+
from: { x: path[1], y: path[2] },
|
|
1708
|
+
to: { x: path[4], y: path[5] }
|
|
1709
|
+
};
|
|
1710
|
+
}
|
|
1711
|
+
getFromToByPoints(points) {
|
|
1712
|
+
return {
|
|
1713
|
+
from: { x: points[0], y: points[1] },
|
|
1714
|
+
to: { x: points[2], y: points[3] }
|
|
1715
|
+
};
|
|
1716
|
+
}
|
|
1717
|
+
dragPoint(fromPoint, toPoint, isDragFrom, around, movePoint) {
|
|
1718
|
+
const { x, y } = movePoint;
|
|
1719
|
+
if (isDragFrom) {
|
|
1720
|
+
move(fromPoint, x, y);
|
|
1721
|
+
if (around)
|
|
1722
|
+
move(toPoint, -x, -y);
|
|
1650
1723
|
}
|
|
1651
1724
|
else {
|
|
1652
|
-
if (around)
|
|
1653
|
-
fromPoint
|
|
1654
|
-
|
|
1655
|
-
}
|
|
1656
|
-
toPoint.x += x;
|
|
1657
|
-
toPoint.y += y;
|
|
1725
|
+
if (around)
|
|
1726
|
+
move(fromPoint, -x, -y);
|
|
1727
|
+
move(toPoint, x, y);
|
|
1658
1728
|
}
|
|
1659
|
-
target.getLocalPointByInner(fromPoint, null, null, true);
|
|
1660
|
-
target.getLocalPointByInner(toPoint, null, null, true);
|
|
1661
|
-
target.x = fromPoint.x;
|
|
1662
|
-
target.y = fromPoint.y;
|
|
1663
|
-
target.getInnerPointByLocal(toPoint, null, null, true);
|
|
1664
|
-
target.toPoint = toPoint;
|
|
1665
1729
|
}
|
|
1666
1730
|
onSkew(_e) {
|
|
1667
1731
|
}
|
|
1668
1732
|
onUpdate() {
|
|
1669
|
-
const { rotatePoints, resizeLines, resizePoints } =
|
|
1733
|
+
const { editBox } = this, { rotatePoints, resizeLines, resizePoints, rect } = editBox;
|
|
1734
|
+
const line = this.editor.element;
|
|
1735
|
+
let fromTo, leftOrRight;
|
|
1736
|
+
if (line.pathInputed)
|
|
1737
|
+
fromTo = this.getFromToByPath(line.__.path);
|
|
1738
|
+
else if (line.points)
|
|
1739
|
+
fromTo = this.getFromToByPoints(line.__.points);
|
|
1740
|
+
if (fromTo) {
|
|
1741
|
+
const { from, to } = fromTo;
|
|
1742
|
+
line.innerToWorld(from, from, false, editBox);
|
|
1743
|
+
line.innerToWorld(to, to, false, editBox);
|
|
1744
|
+
rect.pen.clearPath().moveTo(from.x, from.y).lineTo(to.x, to.y);
|
|
1745
|
+
copy(resizePoints[7], from);
|
|
1746
|
+
copy(rotatePoints[7], from);
|
|
1747
|
+
copy(resizePoints[3], to);
|
|
1748
|
+
copy(rotatePoints[3], to);
|
|
1749
|
+
}
|
|
1670
1750
|
for (let i = 0; i < 8; i++) {
|
|
1671
1751
|
if (i < 4)
|
|
1672
1752
|
resizeLines[i].visible = false;
|
|
1673
|
-
|
|
1753
|
+
leftOrRight = i === left || i === right;
|
|
1754
|
+
resizePoints[i].visible = leftOrRight;
|
|
1755
|
+
rotatePoints[i].visible = fromTo ? false : leftOrRight;
|
|
1674
1756
|
}
|
|
1675
1757
|
}
|
|
1676
1758
|
};
|
|
@@ -1694,9 +1776,6 @@ draw.UI.setEditInner = function (editorName) {
|
|
|
1694
1776
|
get() { return typeof editorName === 'string' ? editorName : editorName(this); }
|
|
1695
1777
|
});
|
|
1696
1778
|
};
|
|
1697
|
-
draw.Line.setEditOuter(function (line) {
|
|
1698
|
-
return (line.points || line.pathInputed) ? 'EditTool' : 'LineEditTool';
|
|
1699
|
-
});
|
|
1700
1779
|
|
|
1701
1780
|
exports.EditBox = EditBox;
|
|
1702
1781
|
exports.EditDataHelper = EditDataHelper;
|
|
@@ -1712,7 +1791,13 @@ exports.EditorRotateEvent = EditorRotateEvent;
|
|
|
1712
1791
|
exports.EditorScaleEvent = EditorScaleEvent;
|
|
1713
1792
|
exports.EditorSkewEvent = EditorSkewEvent;
|
|
1714
1793
|
exports.InnerEditor = InnerEditor;
|
|
1794
|
+
exports.PathScaler = PathScaler;
|
|
1715
1795
|
exports.SelectArea = SelectArea;
|
|
1716
1796
|
exports.Stroker = Stroker;
|
|
1717
1797
|
exports.registerEditTool = registerEditTool;
|
|
1718
1798
|
exports.registerInnerEditor = registerInnerEditor;
|
|
1799
|
+
exports.scaleResize = scaleResize;
|
|
1800
|
+
exports.scaleResizeFont = scaleResizeFont;
|
|
1801
|
+
exports.scaleResizeGroup = scaleResizeGroup;
|
|
1802
|
+
exports.scaleResizePath = scaleResizePath;
|
|
1803
|
+
exports.scaleResizePoints = scaleResizePoints;
|
package/dist/editor.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PathCommandMap, Leaf, Path, Line, Polygon,
|
|
1
|
+
import { PathCommandMap, MatrixHelper, Leaf, Text, Path, Line, Polygon, Group, Box, Event, defineKey, UI, Paint, Rect, Answer, Bounds, LeafList, PointHelper, AroundHelper, Direction9, MathHelper, Matrix, Debug, DataHelper, LeafHelper, RenderEvent, getPointData, Creator } from '@leafer-ui/draw';
|
|
2
2
|
import { PointerEvent, DragEvent, MoveEvent, ZoomEvent, RotateEvent, KeyEvent } from '@leafer-ui/core';
|
|
3
3
|
|
|
4
4
|
const { M, L, C, Q, Z, N, D, X, G, F, O, P, U } = PathCommandMap;
|
|
@@ -80,6 +80,39 @@ const PathScaler = {
|
|
|
80
80
|
};
|
|
81
81
|
const { scalePoints } = PathScaler;
|
|
82
82
|
|
|
83
|
+
const matrix$1 = MatrixHelper.get();
|
|
84
|
+
function scaleResize(leaf, scaleX, scaleY) {
|
|
85
|
+
if (leaf.pathInputed) {
|
|
86
|
+
scaleResizePath(leaf, scaleX, scaleY);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
leaf.width *= scaleX;
|
|
90
|
+
leaf.height *= scaleY;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function scaleResizeFont(leaf, scaleX, scaleY) {
|
|
94
|
+
if (scaleX !== 1)
|
|
95
|
+
leaf.fontSize *= scaleX;
|
|
96
|
+
else if (scaleY !== 1)
|
|
97
|
+
leaf.fontSize *= scaleY;
|
|
98
|
+
}
|
|
99
|
+
function scaleResizePath(leaf, scaleX, scaleY) {
|
|
100
|
+
PathScaler.scale(leaf.__.path, scaleX, scaleY);
|
|
101
|
+
leaf.path = leaf.__.path;
|
|
102
|
+
}
|
|
103
|
+
function scaleResizePoints(leaf, scaleX, scaleY) {
|
|
104
|
+
PathScaler.scalePoints(leaf.__.points, scaleX, scaleY);
|
|
105
|
+
leaf.points = leaf.__.points;
|
|
106
|
+
}
|
|
107
|
+
function scaleResizeGroup(group, scaleX, scaleY) {
|
|
108
|
+
const { children } = group;
|
|
109
|
+
for (let i = 0; i < children.length; i++) {
|
|
110
|
+
matrix$1.a = scaleX;
|
|
111
|
+
matrix$1.d = scaleY;
|
|
112
|
+
children[i].transform(matrix$1, true);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
83
116
|
Leaf.prototype.scaleResize = function (scaleX, scaleY = scaleX, noResize) {
|
|
84
117
|
const data = this;
|
|
85
118
|
if (noResize) {
|
|
@@ -94,23 +127,26 @@ Leaf.prototype.scaleResize = function (scaleX, scaleY = scaleX, noResize) {
|
|
|
94
127
|
this.__scaleResize(scaleX, scaleY);
|
|
95
128
|
}
|
|
96
129
|
};
|
|
97
|
-
function scaleResize(leaf, scaleX, scaleY) {
|
|
98
|
-
if (scaleX !== 1)
|
|
99
|
-
leaf.width *= scaleX;
|
|
100
|
-
if (scaleY !== 1)
|
|
101
|
-
leaf.height *= scaleY;
|
|
102
|
-
}
|
|
103
130
|
Leaf.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
104
131
|
scaleResize(this, scaleX, scaleY);
|
|
105
132
|
};
|
|
133
|
+
Text.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
134
|
+
if (this.editConfig && this.editConfig.editSize === 'font-size') {
|
|
135
|
+
scaleResizeFont(this, scaleX, scaleY);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
scaleResize(this, scaleX, scaleY);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
106
141
|
Path.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
107
|
-
|
|
108
|
-
this.path = this.__.path;
|
|
142
|
+
scaleResizePath(this, scaleX, scaleY);
|
|
109
143
|
};
|
|
110
144
|
Line.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
111
|
-
if (this.
|
|
112
|
-
|
|
113
|
-
|
|
145
|
+
if (this.pathInputed) {
|
|
146
|
+
scaleResizePath(this, scaleX, scaleY);
|
|
147
|
+
}
|
|
148
|
+
else if (this.points) {
|
|
149
|
+
scaleResizePoints(this, scaleX, scaleY);
|
|
114
150
|
}
|
|
115
151
|
else {
|
|
116
152
|
const point = this.toPoint;
|
|
@@ -120,29 +156,22 @@ Line.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
|
120
156
|
}
|
|
121
157
|
};
|
|
122
158
|
Polygon.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
123
|
-
if (this.
|
|
124
|
-
|
|
125
|
-
|
|
159
|
+
if (this.pathInputed) {
|
|
160
|
+
scaleResizePath(this, scaleX, scaleY);
|
|
161
|
+
}
|
|
162
|
+
else if (this.points) {
|
|
163
|
+
scaleResizePoints(this, scaleX, scaleY);
|
|
126
164
|
}
|
|
127
165
|
else {
|
|
128
166
|
scaleResize(this, scaleX, scaleY);
|
|
129
167
|
}
|
|
130
168
|
};
|
|
131
|
-
const matrix$1 = MatrixHelper.get();
|
|
132
|
-
function groupScaleResize(group, scaleX, scaleY) {
|
|
133
|
-
const { children } = group;
|
|
134
|
-
for (let i = 0; i < children.length; i++) {
|
|
135
|
-
matrix$1.a = scaleX;
|
|
136
|
-
matrix$1.d = scaleY;
|
|
137
|
-
children[i].transform(matrix$1, true);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
169
|
Group.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
141
|
-
|
|
170
|
+
scaleResizeGroup(this, scaleX, scaleY);
|
|
142
171
|
};
|
|
143
172
|
Box.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
144
173
|
if (this.__.__autoSize && this.children.length) {
|
|
145
|
-
|
|
174
|
+
scaleResizeGroup(this, scaleX, scaleY);
|
|
146
175
|
}
|
|
147
176
|
else {
|
|
148
177
|
scaleResize(this, scaleX, scaleY);
|
|
@@ -237,7 +266,7 @@ function targetAttr(fn) {
|
|
|
237
266
|
|
|
238
267
|
const matrix = MatrixHelper.get();
|
|
239
268
|
const { abs } = Math;
|
|
240
|
-
const { copy, scale } = MatrixHelper;
|
|
269
|
+
const { copy: copy$1, scale } = MatrixHelper;
|
|
241
270
|
class Stroker extends UI {
|
|
242
271
|
constructor() {
|
|
243
272
|
super();
|
|
@@ -260,7 +289,7 @@ class Stroker extends UI {
|
|
|
260
289
|
if (bounds && bounds.hit(leaf.__world, options.matrix)) {
|
|
261
290
|
const aScaleX = abs(leaf.__world.scaleX), aScaleY = abs(leaf.__world.scaleY);
|
|
262
291
|
if (aScaleX !== aScaleY) {
|
|
263
|
-
copy(matrix, leaf.__world);
|
|
292
|
+
copy$1(matrix, leaf.__world);
|
|
264
293
|
scale(matrix, 1 / aScaleX, 1 / aScaleY);
|
|
265
294
|
canvas.setWorld(matrix, options.matrix);
|
|
266
295
|
canvas.beginPath();
|
|
@@ -853,6 +882,8 @@ class EditBox extends Group {
|
|
|
853
882
|
}
|
|
854
883
|
}
|
|
855
884
|
circle.visible = showPoints && rotateable && !!mergeConfig.rotatePoint;
|
|
885
|
+
if (rect.path)
|
|
886
|
+
rect.path = null;
|
|
856
887
|
rect.set(Object.assign(Object.assign({}, bounds), { visible: true }));
|
|
857
888
|
const buttonVisible = showPoints && (circle.visible || this.buttons.children.length > 1);
|
|
858
889
|
this.buttons.visible = buttonVisible;
|
|
@@ -1553,7 +1584,7 @@ let EditTool = class EditTool extends InnerEditor {
|
|
|
1553
1584
|
const { app, list } = editor;
|
|
1554
1585
|
app.lockLayout();
|
|
1555
1586
|
list.forEach(target => {
|
|
1556
|
-
const resize = editor.getEditSize(target)
|
|
1587
|
+
const resize = editor.getEditSize(target) !== 'scale';
|
|
1557
1588
|
if (transform) {
|
|
1558
1589
|
target.transformWorld(transform, resize);
|
|
1559
1590
|
}
|
|
@@ -1568,7 +1599,7 @@ let EditTool = class EditTool extends InnerEditor {
|
|
|
1568
1599
|
const { app, list } = editor;
|
|
1569
1600
|
app.lockLayout();
|
|
1570
1601
|
list.forEach(target => {
|
|
1571
|
-
const resize = editor.getEditSize(target)
|
|
1602
|
+
const resize = editor.getEditSize(target) !== 'scale';
|
|
1572
1603
|
if (transform) {
|
|
1573
1604
|
target.transformWorld(transform, resize);
|
|
1574
1605
|
}
|
|
@@ -1583,7 +1614,7 @@ let EditTool = class EditTool extends InnerEditor {
|
|
|
1583
1614
|
const { app, list } = editor;
|
|
1584
1615
|
app.lockLayout();
|
|
1585
1616
|
list.forEach(target => {
|
|
1586
|
-
const resize = editor.getEditSize(target)
|
|
1617
|
+
const resize = editor.getEditSize(target) !== 'scale';
|
|
1587
1618
|
if (transform) {
|
|
1588
1619
|
target.transformWorld(transform, resize);
|
|
1589
1620
|
}
|
|
@@ -1617,6 +1648,7 @@ EditTool = __decorate([
|
|
|
1617
1648
|
], EditTool);
|
|
1618
1649
|
|
|
1619
1650
|
const { left, right } = Direction9;
|
|
1651
|
+
const { move, copy } = PointHelper;
|
|
1620
1652
|
let LineEditTool = class LineEditTool extends EditTool {
|
|
1621
1653
|
constructor() {
|
|
1622
1654
|
super(...arguments);
|
|
@@ -1625,50 +1657,100 @@ let LineEditTool = class LineEditTool extends EditTool {
|
|
|
1625
1657
|
get tag() { return 'LineEditTool'; }
|
|
1626
1658
|
onScaleWithDrag(e) {
|
|
1627
1659
|
const { drag, direction, lockRatio, around } = e;
|
|
1628
|
-
const
|
|
1629
|
-
const
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1660
|
+
const line = e.target;
|
|
1661
|
+
const isDragFrom = direction === left;
|
|
1662
|
+
if (line.pathInputed) {
|
|
1663
|
+
const { path } = line.__;
|
|
1664
|
+
const { from, to } = this.getFromToByPath(path);
|
|
1665
|
+
this.dragPoint(from, to, isDragFrom, around, this.getInnerMove(line, drag, lockRatio));
|
|
1666
|
+
path[1] = from.x, path[2] = from.y;
|
|
1667
|
+
path[4] = to.x, path[5] = to.y;
|
|
1668
|
+
line.path = path;
|
|
1669
|
+
}
|
|
1670
|
+
else if (line.points) {
|
|
1671
|
+
const { points } = line;
|
|
1672
|
+
const { from, to } = this.getFromToByPoints(points);
|
|
1673
|
+
this.dragPoint(from, to, isDragFrom, around, this.getInnerMove(line, drag, lockRatio));
|
|
1674
|
+
points[0] = from.x, points[1] = from.y;
|
|
1675
|
+
points[2] = to.x, points[3] = to.y;
|
|
1676
|
+
line.points = points;
|
|
1677
|
+
}
|
|
1678
|
+
else {
|
|
1679
|
+
const from = getPointData();
|
|
1680
|
+
const { toPoint } = line;
|
|
1681
|
+
line.rotation = 0;
|
|
1682
|
+
this.dragPoint(from, toPoint, isDragFrom, around, this.getInnerMove(line, drag, lockRatio));
|
|
1683
|
+
line.getLocalPointByInner(from, null, null, true);
|
|
1684
|
+
line.getLocalPointByInner(toPoint, null, null, true);
|
|
1685
|
+
line.x = from.x;
|
|
1686
|
+
line.y = from.y;
|
|
1687
|
+
line.getInnerPointByLocal(toPoint, null, null, true);
|
|
1688
|
+
line.toPoint = toPoint;
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
getInnerMove(ui, event, lockRatio) {
|
|
1692
|
+
const movePoint = event.getInnerMove(ui);
|
|
1633
1693
|
if (lockRatio) {
|
|
1634
|
-
if (Math.abs(x) > Math.abs(y)) {
|
|
1635
|
-
y = 0;
|
|
1694
|
+
if (Math.abs(movePoint.x) > Math.abs(movePoint.y)) {
|
|
1695
|
+
movePoint.y = 0;
|
|
1636
1696
|
}
|
|
1637
1697
|
else {
|
|
1638
|
-
x = 0;
|
|
1698
|
+
movePoint.x = 0;
|
|
1639
1699
|
}
|
|
1640
1700
|
}
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1701
|
+
return movePoint;
|
|
1702
|
+
}
|
|
1703
|
+
getFromToByPath(path) {
|
|
1704
|
+
return {
|
|
1705
|
+
from: { x: path[1], y: path[2] },
|
|
1706
|
+
to: { x: path[4], y: path[5] }
|
|
1707
|
+
};
|
|
1708
|
+
}
|
|
1709
|
+
getFromToByPoints(points) {
|
|
1710
|
+
return {
|
|
1711
|
+
from: { x: points[0], y: points[1] },
|
|
1712
|
+
to: { x: points[2], y: points[3] }
|
|
1713
|
+
};
|
|
1714
|
+
}
|
|
1715
|
+
dragPoint(fromPoint, toPoint, isDragFrom, around, movePoint) {
|
|
1716
|
+
const { x, y } = movePoint;
|
|
1717
|
+
if (isDragFrom) {
|
|
1718
|
+
move(fromPoint, x, y);
|
|
1719
|
+
if (around)
|
|
1720
|
+
move(toPoint, -x, -y);
|
|
1648
1721
|
}
|
|
1649
1722
|
else {
|
|
1650
|
-
if (around)
|
|
1651
|
-
fromPoint
|
|
1652
|
-
|
|
1653
|
-
}
|
|
1654
|
-
toPoint.x += x;
|
|
1655
|
-
toPoint.y += y;
|
|
1723
|
+
if (around)
|
|
1724
|
+
move(fromPoint, -x, -y);
|
|
1725
|
+
move(toPoint, x, y);
|
|
1656
1726
|
}
|
|
1657
|
-
target.getLocalPointByInner(fromPoint, null, null, true);
|
|
1658
|
-
target.getLocalPointByInner(toPoint, null, null, true);
|
|
1659
|
-
target.x = fromPoint.x;
|
|
1660
|
-
target.y = fromPoint.y;
|
|
1661
|
-
target.getInnerPointByLocal(toPoint, null, null, true);
|
|
1662
|
-
target.toPoint = toPoint;
|
|
1663
1727
|
}
|
|
1664
1728
|
onSkew(_e) {
|
|
1665
1729
|
}
|
|
1666
1730
|
onUpdate() {
|
|
1667
|
-
const { rotatePoints, resizeLines, resizePoints } =
|
|
1731
|
+
const { editBox } = this, { rotatePoints, resizeLines, resizePoints, rect } = editBox;
|
|
1732
|
+
const line = this.editor.element;
|
|
1733
|
+
let fromTo, leftOrRight;
|
|
1734
|
+
if (line.pathInputed)
|
|
1735
|
+
fromTo = this.getFromToByPath(line.__.path);
|
|
1736
|
+
else if (line.points)
|
|
1737
|
+
fromTo = this.getFromToByPoints(line.__.points);
|
|
1738
|
+
if (fromTo) {
|
|
1739
|
+
const { from, to } = fromTo;
|
|
1740
|
+
line.innerToWorld(from, from, false, editBox);
|
|
1741
|
+
line.innerToWorld(to, to, false, editBox);
|
|
1742
|
+
rect.pen.clearPath().moveTo(from.x, from.y).lineTo(to.x, to.y);
|
|
1743
|
+
copy(resizePoints[7], from);
|
|
1744
|
+
copy(rotatePoints[7], from);
|
|
1745
|
+
copy(resizePoints[3], to);
|
|
1746
|
+
copy(rotatePoints[3], to);
|
|
1747
|
+
}
|
|
1668
1748
|
for (let i = 0; i < 8; i++) {
|
|
1669
1749
|
if (i < 4)
|
|
1670
1750
|
resizeLines[i].visible = false;
|
|
1671
|
-
|
|
1751
|
+
leftOrRight = i === left || i === right;
|
|
1752
|
+
resizePoints[i].visible = leftOrRight;
|
|
1753
|
+
rotatePoints[i].visible = fromTo ? false : leftOrRight;
|
|
1672
1754
|
}
|
|
1673
1755
|
}
|
|
1674
1756
|
};
|
|
@@ -1692,8 +1774,5 @@ UI.setEditInner = function (editorName) {
|
|
|
1692
1774
|
get() { return typeof editorName === 'string' ? editorName : editorName(this); }
|
|
1693
1775
|
});
|
|
1694
1776
|
};
|
|
1695
|
-
Line.setEditOuter(function (line) {
|
|
1696
|
-
return (line.points || line.pathInputed) ? 'EditTool' : 'LineEditTool';
|
|
1697
|
-
});
|
|
1698
1777
|
|
|
1699
|
-
export { EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, InnerEditor, LineEditTool, SelectArea, Stroker, registerEditTool, registerInnerEditor };
|
|
1778
|
+
export { EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, InnerEditor, LineEditTool, PathScaler, SelectArea, Stroker, registerEditTool, registerInnerEditor, scaleResize, scaleResizeFont, scaleResizeGroup, scaleResizePath, scaleResizePoints };
|