@leafer-in/resize 1.8.0 → 1.9.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/resize.cjs +153 -134
- package/dist/resize.esm.js +147 -133
- package/dist/resize.esm.min.js +1 -1
- package/dist/resize.esm.min.js.map +1 -1
- package/dist/resize.js +131 -141
- package/dist/resize.min.cjs +1 -1
- package/dist/resize.min.cjs.map +1 -1
- package/dist/resize.min.js +1 -1
- package/dist/resize.min.js.map +1 -1
- package/package.json +4 -4
- package/src/resize.ts +3 -4
- package/src/scaler.ts +4 -4
package/dist/resize.cjs
CHANGED
|
@@ -1,71 +1,82 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
var draw = require(
|
|
3
|
+
var draw = require("@leafer-ui/draw");
|
|
4
|
+
|
|
5
|
+
const {M: M, L: L, C: C, Q: Q, Z: Z, N: N, D: D, X: X, G: G, F: F, O: O, P: P, U: U} = draw.PathCommandMap;
|
|
4
6
|
|
|
5
|
-
const { M, L, C, Q, Z, N, D, X, G, F, O, P, U } = draw.PathCommandMap;
|
|
6
7
|
const PathScaler = {
|
|
7
8
|
scale(data, scaleX, scaleY) {
|
|
8
|
-
if (!data)
|
|
9
|
-
return;
|
|
9
|
+
if (!data) return;
|
|
10
10
|
let command;
|
|
11
11
|
let i = 0, len = data.length;
|
|
12
12
|
while (i < len) {
|
|
13
13
|
command = data[i];
|
|
14
14
|
switch (command) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
15
|
+
case M:
|
|
16
|
+
case L:
|
|
17
|
+
scalePoints(data, scaleX, scaleY, i, 1);
|
|
18
|
+
i += 3;
|
|
19
|
+
break;
|
|
20
|
+
|
|
21
|
+
case C:
|
|
22
|
+
scalePoints(data, scaleX, scaleY, i, 3);
|
|
23
|
+
i += 7;
|
|
24
|
+
break;
|
|
25
|
+
|
|
26
|
+
case Q:
|
|
27
|
+
scalePoints(data, scaleX, scaleY, i, 2);
|
|
28
|
+
i += 5;
|
|
29
|
+
break;
|
|
30
|
+
|
|
31
|
+
case Z:
|
|
32
|
+
i += 1;
|
|
33
|
+
break;
|
|
34
|
+
|
|
35
|
+
case N:
|
|
36
|
+
scalePoints(data, scaleX, scaleY, i, 2);
|
|
37
|
+
i += 5;
|
|
38
|
+
break;
|
|
39
|
+
|
|
40
|
+
case D:
|
|
41
|
+
scalePoints(data, scaleX, scaleY, i, 2);
|
|
42
|
+
i += 9;
|
|
43
|
+
break;
|
|
44
|
+
|
|
45
|
+
case X:
|
|
46
|
+
scalePoints(data, scaleX, scaleY, i, 2);
|
|
47
|
+
i += 6;
|
|
48
|
+
break;
|
|
49
|
+
|
|
50
|
+
case G:
|
|
51
|
+
scalePoints(data, scaleX, scaleY, i, 2);
|
|
52
|
+
i += 9;
|
|
53
|
+
break;
|
|
54
|
+
|
|
55
|
+
case F:
|
|
56
|
+
scalePoints(data, scaleX, scaleY, i, 2);
|
|
57
|
+
i += 5;
|
|
58
|
+
break;
|
|
59
|
+
|
|
60
|
+
case O:
|
|
61
|
+
data[i] = G;
|
|
62
|
+
data.splice(i + 4, 0, data[i + 3], 0);
|
|
63
|
+
scalePoints(data, scaleX, scaleY, i, 2);
|
|
64
|
+
i += 7 + 2;
|
|
65
|
+
len += 2;
|
|
66
|
+
break;
|
|
67
|
+
|
|
68
|
+
case P:
|
|
69
|
+
data[i] = F;
|
|
70
|
+
data.splice(i + 4, 0, data[i + 3]);
|
|
71
|
+
scalePoints(data, scaleX, scaleY, i, 2);
|
|
72
|
+
i += 4 + 1;
|
|
73
|
+
len += 1;
|
|
74
|
+
break;
|
|
75
|
+
|
|
76
|
+
case U:
|
|
77
|
+
scalePoints(data, scaleX, scaleY, i, 2);
|
|
78
|
+
i += 6;
|
|
79
|
+
break;
|
|
69
80
|
}
|
|
70
81
|
}
|
|
71
82
|
},
|
|
@@ -76,64 +87,69 @@ const PathScaler = {
|
|
|
76
87
|
}
|
|
77
88
|
}
|
|
78
89
|
};
|
|
79
|
-
|
|
90
|
+
|
|
91
|
+
const {scalePoints: scalePoints} = PathScaler;
|
|
80
92
|
|
|
81
93
|
const matrix = draw.MatrixHelper.get();
|
|
82
|
-
|
|
94
|
+
|
|
95
|
+
const {topLeft: topLeft, top: top, topRight: topRight, right: right, bottom: bottom, left: left} = draw.Direction9;
|
|
96
|
+
|
|
83
97
|
function scaleResize(leaf, scaleX, scaleY) {
|
|
84
98
|
if (leaf.pathInputed) {
|
|
85
99
|
scaleResizePath(leaf, scaleX, scaleY);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (
|
|
89
|
-
leaf.width *= scaleX;
|
|
90
|
-
if (scaleY !== 1)
|
|
91
|
-
leaf.height *= scaleY;
|
|
100
|
+
} else {
|
|
101
|
+
if (scaleX !== 1) leaf.width *= scaleX;
|
|
102
|
+
if (scaleY !== 1) leaf.height *= scaleY;
|
|
92
103
|
}
|
|
93
104
|
}
|
|
105
|
+
|
|
94
106
|
function scaleResizeFontSize(leaf, scaleX, scaleY, direction) {
|
|
95
107
|
let fontScale = scaleX;
|
|
96
|
-
if (direction
|
|
108
|
+
if (!draw.isUndefined(direction)) {
|
|
97
109
|
const layout = leaf.__layout;
|
|
98
|
-
let { width, height } = layout.boxBounds;
|
|
110
|
+
let {width: width, height: height} = layout.boxBounds;
|
|
99
111
|
width *= scaleY - scaleX;
|
|
100
112
|
height *= scaleX - scaleY;
|
|
101
113
|
switch (direction) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
114
|
+
case top:
|
|
115
|
+
case bottom:
|
|
116
|
+
fontScale = scaleY;
|
|
117
|
+
layout.affectScaleOrRotation ? leaf.moveInner(-width / 2, 0) : leaf.x -= width / 2;
|
|
118
|
+
break;
|
|
119
|
+
|
|
120
|
+
case left:
|
|
121
|
+
case right:
|
|
122
|
+
layout.affectScaleOrRotation ? leaf.moveInner(0, -height / 2) : leaf.y -= height / 2;
|
|
123
|
+
break;
|
|
124
|
+
|
|
125
|
+
case topLeft:
|
|
126
|
+
case topRight:
|
|
127
|
+
layout.affectScaleOrRotation ? leaf.moveInner(0, -height) : leaf.y -= height;
|
|
128
|
+
break;
|
|
115
129
|
}
|
|
116
130
|
}
|
|
117
131
|
leaf.fontSize *= fontScale;
|
|
118
|
-
const data = leaf.__, { padding
|
|
119
|
-
if (padding)
|
|
120
|
-
|
|
121
|
-
if (!data.
|
|
122
|
-
leaf.width *= fontScale;
|
|
123
|
-
if (!data.__autoHeight)
|
|
124
|
-
leaf.height *= fontScale;
|
|
132
|
+
const data = leaf.__, {padding: padding} = data;
|
|
133
|
+
if (padding) leaf.padding = draw.isArray(padding) ? padding.map(item => item * fontScale) : padding * fontScale;
|
|
134
|
+
if (!data.__autoWidth) leaf.width *= fontScale;
|
|
135
|
+
if (!data.__autoHeight) leaf.height *= fontScale;
|
|
125
136
|
}
|
|
137
|
+
|
|
126
138
|
function scaleResizePath(leaf, scaleX, scaleY) {
|
|
127
139
|
PathScaler.scale(leaf.__.path, scaleX, scaleY);
|
|
128
140
|
leaf.path = leaf.__.path;
|
|
129
141
|
}
|
|
142
|
+
|
|
130
143
|
function scaleResizePoints(leaf, scaleX, scaleY) {
|
|
131
|
-
const { points
|
|
132
|
-
|
|
144
|
+
const {points: points} = leaf;
|
|
145
|
+
draw.isObject(points[0]) ? points.forEach(p => {
|
|
146
|
+
p.x *= scaleX, p.y *= scaleY;
|
|
147
|
+
}) : PathScaler.scalePoints(points, scaleX, scaleY);
|
|
133
148
|
leaf.points = points;
|
|
134
149
|
}
|
|
150
|
+
|
|
135
151
|
function scaleResizeGroup(group, scaleX, scaleY) {
|
|
136
|
-
const { children
|
|
152
|
+
const {children: children} = group;
|
|
137
153
|
for (let i = 0; i < children.length; i++) {
|
|
138
154
|
matrix.a = scaleX;
|
|
139
155
|
matrix.d = scaleY;
|
|
@@ -142,86 +158,89 @@ function scaleResizeGroup(group, scaleX, scaleY) {
|
|
|
142
158
|
}
|
|
143
159
|
|
|
144
160
|
const leaf = draw.Leaf.prototype;
|
|
145
|
-
|
|
161
|
+
|
|
162
|
+
leaf.scaleResize = function(scaleX, scaleY = scaleX, noResize) {
|
|
146
163
|
const data = this;
|
|
147
|
-
if (noResize ||
|
|
164
|
+
if (noResize || data.editConfig && data.editConfig.editSize === "scale") {
|
|
148
165
|
data.scaleX *= scaleX;
|
|
149
166
|
data.scaleY *= scaleY;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (
|
|
153
|
-
data.scaleX *= -1, scaleX = -scaleX;
|
|
154
|
-
if (scaleY < 0)
|
|
155
|
-
data.scaleY *= -1, scaleY = -scaleY;
|
|
167
|
+
} else {
|
|
168
|
+
if (scaleX < 0) data.scaleX *= -1, scaleX = -scaleX;
|
|
169
|
+
if (scaleY < 0) data.scaleY *= -1, scaleY = -scaleY;
|
|
156
170
|
this.__scaleResize(scaleX, scaleY);
|
|
157
171
|
}
|
|
158
172
|
};
|
|
159
|
-
|
|
173
|
+
|
|
174
|
+
leaf.__scaleResize = function(scaleX, scaleY) {
|
|
160
175
|
scaleResize(this, scaleX, scaleY);
|
|
161
176
|
};
|
|
162
|
-
|
|
163
|
-
|
|
177
|
+
|
|
178
|
+
leaf.resizeWidth = function(width) {
|
|
179
|
+
const scale = width / this.getBounds("box", "local").width || 1;
|
|
164
180
|
this.scaleOf(this.__layout.boxBounds, scale, this.__.lockRatio ? scale : 1, true);
|
|
165
181
|
};
|
|
166
|
-
|
|
167
|
-
|
|
182
|
+
|
|
183
|
+
leaf.resizeHeight = function(height) {
|
|
184
|
+
const scale = height / this.getBounds("box", "local").height || 1;
|
|
168
185
|
this.scaleOf(this.__layout.boxBounds, this.__.lockRatio ? scale : 1, scale, true);
|
|
169
186
|
};
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const {
|
|
173
|
-
if (
|
|
174
|
-
this.x += boxBounds.x;
|
|
175
|
-
if (__autoHeight && verticalAlign !== 'top' && scaleY !== 1)
|
|
176
|
-
this.y += boxBounds.y;
|
|
177
|
-
if (this.__.resizeFontSize || (editConfig && editConfig.editSize === 'font-size') || (dragPoint && editor.mergedConfig.editSize === 'font-size')) {
|
|
187
|
+
|
|
188
|
+
draw.Text.prototype.__scaleResize = function(scaleX, scaleY) {
|
|
189
|
+
const {app: app, editConfig: editConfig} = this, editor = app && app.editor, dragPoint = editor && editor.dragPoint;
|
|
190
|
+
if (this.__.resizeFontSize || editConfig && editConfig.editSize === "font-size" || dragPoint && editor.mergedConfig.editSize === "font-size") {
|
|
178
191
|
scaleResizeFontSize(this, scaleX, scaleY, dragPoint && dragPoint.direction);
|
|
179
|
-
}
|
|
180
|
-
|
|
192
|
+
} else {
|
|
193
|
+
const {__autoWidth: __autoWidth, __autoHeight: __autoHeight, textAlign: textAlign, verticalAlign: verticalAlign} = this.__, {boxBounds: boxBounds} = this.__layout;
|
|
194
|
+
if (__autoWidth && textAlign !== "left" && scaleX !== 1) this.x += boxBounds.x;
|
|
195
|
+
if (__autoHeight && verticalAlign !== "top" && scaleY !== 1) this.y += boxBounds.y;
|
|
181
196
|
scaleResize(this, scaleX, scaleY);
|
|
182
197
|
}
|
|
183
198
|
};
|
|
184
|
-
|
|
199
|
+
|
|
200
|
+
draw.Path.prototype.__scaleResize = function(scaleX, scaleY) {
|
|
185
201
|
scaleResizePath(this, scaleX, scaleY);
|
|
186
202
|
};
|
|
187
|
-
|
|
203
|
+
|
|
204
|
+
draw.Line.prototype.__scaleResize = function(scaleX, scaleY) {
|
|
188
205
|
if (this.pathInputed) {
|
|
189
206
|
scaleResizePath(this, scaleX, scaleY);
|
|
190
|
-
}
|
|
191
|
-
else if (this.points) {
|
|
207
|
+
} else if (this.points) {
|
|
192
208
|
scaleResizePoints(this, scaleX, scaleY);
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
209
|
+
} else {
|
|
195
210
|
this.width *= scaleX;
|
|
196
211
|
}
|
|
197
212
|
};
|
|
198
|
-
|
|
213
|
+
|
|
214
|
+
draw.Polygon.prototype.__scaleResize = function(scaleX, scaleY) {
|
|
199
215
|
if (this.pathInputed) {
|
|
200
216
|
scaleResizePath(this, scaleX, scaleY);
|
|
201
|
-
}
|
|
202
|
-
else if (this.points) {
|
|
217
|
+
} else if (this.points) {
|
|
203
218
|
scaleResizePoints(this, scaleX, scaleY);
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
219
|
+
} else {
|
|
206
220
|
scaleResize(this, scaleX, scaleY);
|
|
207
221
|
}
|
|
208
222
|
};
|
|
209
|
-
|
|
223
|
+
|
|
224
|
+
draw.Group.prototype.__scaleResize = function(scaleX, scaleY) {
|
|
210
225
|
scaleResizeGroup(this, scaleX, scaleY);
|
|
211
226
|
};
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
if (resizeChildren)
|
|
217
|
-
scaleResizeGroup(this, scaleX, scaleY);
|
|
227
|
+
|
|
228
|
+
draw.Box.prototype.__scaleResize = function(scaleX, scaleY) {
|
|
229
|
+
const {resizeChildren: resizeChildren, __autoSize: __autoSize} = this.__;
|
|
230
|
+
if (!(__autoSize && resizeChildren)) scaleResize(this, scaleX, scaleY);
|
|
231
|
+
if (resizeChildren) scaleResizeGroup(this, scaleX, scaleY);
|
|
218
232
|
};
|
|
219
233
|
|
|
220
|
-
draw.Plugin.add(
|
|
234
|
+
draw.Plugin.add("resize");
|
|
221
235
|
|
|
222
236
|
exports.PathScaler = PathScaler;
|
|
237
|
+
|
|
223
238
|
exports.scaleResize = scaleResize;
|
|
239
|
+
|
|
224
240
|
exports.scaleResizeFontSize = scaleResizeFontSize;
|
|
241
|
+
|
|
225
242
|
exports.scaleResizeGroup = scaleResizeGroup;
|
|
243
|
+
|
|
226
244
|
exports.scaleResizePath = scaleResizePath;
|
|
245
|
+
|
|
227
246
|
exports.scaleResizePoints = scaleResizePoints;
|