@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 CHANGED
@@ -1,71 +1,82 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var draw = require('@leafer-ui/draw');
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
- case M:
16
- case L:
17
- scalePoints(data, scaleX, scaleY, i, 1);
18
- i += 3;
19
- break;
20
- case C:
21
- scalePoints(data, scaleX, scaleY, i, 3);
22
- i += 7;
23
- break;
24
- case Q:
25
- scalePoints(data, scaleX, scaleY, i, 2);
26
- i += 5;
27
- break;
28
- case Z:
29
- i += 1;
30
- break;
31
- case N:
32
- scalePoints(data, scaleX, scaleY, i, 2);
33
- i += 5;
34
- break;
35
- case D:
36
- scalePoints(data, scaleX, scaleY, i, 2);
37
- i += 9;
38
- break;
39
- case X:
40
- scalePoints(data, scaleX, scaleY, i, 2);
41
- i += 6;
42
- break;
43
- case G:
44
- scalePoints(data, scaleX, scaleY, i, 2);
45
- i += 9;
46
- break;
47
- case F:
48
- scalePoints(data, scaleX, scaleY, i, 2);
49
- i += 5;
50
- break;
51
- case O:
52
- data[i] = G;
53
- data.splice(i + 4, 0, data[i + 3], 0);
54
- scalePoints(data, scaleX, scaleY, i, 2);
55
- i += 7 + 2;
56
- len += 2;
57
- break;
58
- case P:
59
- data[i] = F;
60
- data.splice(i + 4, 0, data[i + 3]);
61
- scalePoints(data, scaleX, scaleY, i, 2);
62
- i += 4 + 1;
63
- len += 1;
64
- break;
65
- case U:
66
- scalePoints(data, scaleX, scaleY, i, 2);
67
- i += 6;
68
- break;
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
- const { scalePoints } = PathScaler;
90
+
91
+ const {scalePoints: scalePoints} = PathScaler;
80
92
 
81
93
  const matrix = draw.MatrixHelper.get();
82
- const { topLeft, top, topRight, right, bottom, left } = draw.Direction9;
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
- else {
88
- if (scaleX !== 1)
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 !== undefined) {
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
- case top:
103
- case bottom:
104
- fontScale = scaleY;
105
- layout.affectScaleOrRotation ? leaf.moveInner(-width / 2, 0) : leaf.x -= width / 2;
106
- break;
107
- case left:
108
- case right:
109
- layout.affectScaleOrRotation ? leaf.moveInner(0, -height / 2) : leaf.y -= height / 2;
110
- break;
111
- case topLeft:
112
- case topRight:
113
- layout.affectScaleOrRotation ? leaf.moveInner(0, -height) : leaf.y -= height;
114
- break;
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 } = data;
119
- if (padding)
120
- leaf.padding = padding instanceof Array ? padding.map(item => item * fontScale) : padding * fontScale;
121
- if (!data.__autoWidth)
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 } = leaf;
132
- typeof points[0] === 'object' ? points.forEach(p => { p.x *= scaleX, p.y *= scaleY; }) : PathScaler.scalePoints(points, scaleX, scaleY);
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 } = group;
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
- leaf.scaleResize = function (scaleX, scaleY = scaleX, noResize) {
161
+
162
+ leaf.scaleResize = function(scaleX, scaleY = scaleX, noResize) {
146
163
  const data = this;
147
- if (noResize || (data.editConfig && data.editConfig.editSize === 'scale')) {
164
+ if (noResize || data.editConfig && data.editConfig.editSize === "scale") {
148
165
  data.scaleX *= scaleX;
149
166
  data.scaleY *= scaleY;
150
- }
151
- else {
152
- if (scaleX < 0)
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
- leaf.__scaleResize = function (scaleX, scaleY) {
173
+
174
+ leaf.__scaleResize = function(scaleX, scaleY) {
160
175
  scaleResize(this, scaleX, scaleY);
161
176
  };
162
- leaf.resizeWidth = function (width) {
163
- const scale = width / this.getBounds('box', 'local').width || 1;
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
- leaf.resizeHeight = function (height) {
167
- const scale = height / this.getBounds('box', 'local').height || 1;
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
- draw.Text.prototype.__scaleResize = function (scaleX, scaleY) {
171
- const { app, editConfig } = this, editor = app && app.editor, dragPoint = editor && editor.dragPoint;
172
- const { __autoWidth, __autoHeight, textAlign, verticalAlign } = this.__, { boxBounds } = this.__layout;
173
- if (__autoWidth && textAlign !== 'left' && scaleX !== 1)
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
- else {
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
- draw.Path.prototype.__scaleResize = function (scaleX, scaleY) {
199
+
200
+ draw.Path.prototype.__scaleResize = function(scaleX, scaleY) {
185
201
  scaleResizePath(this, scaleX, scaleY);
186
202
  };
187
- draw.Line.prototype.__scaleResize = function (scaleX, scaleY) {
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
- draw.Polygon.prototype.__scaleResize = function (scaleX, scaleY) {
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
- draw.Group.prototype.__scaleResize = function (scaleX, scaleY) {
223
+
224
+ draw.Group.prototype.__scaleResize = function(scaleX, scaleY) {
210
225
  scaleResizeGroup(this, scaleX, scaleY);
211
226
  };
212
- draw.Box.prototype.__scaleResize = function (scaleX, scaleY) {
213
- const { resizeChildren, __autoSize } = this.__;
214
- if (!(__autoSize && resizeChildren))
215
- scaleResize(this, scaleX, scaleY);
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('resize');
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;