@leafer-in/flow 1.0.0-rc.30 → 1.0.1
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/flow.cjs +716 -1
- package/dist/flow.esm.js +709 -1
- package/dist/flow.esm.min.js +1 -1
- package/dist/flow.js +720 -1
- package/dist/flow.min.cjs +1 -1
- package/dist/flow.min.js +1 -1
- package/package.json +5 -5
package/dist/flow.js
CHANGED
|
@@ -1 +1,720 @@
|
|
|
1
|
-
this.LeaferIN
|
|
1
|
+
this.LeaferIN = this.LeaferIN || {};
|
|
2
|
+
this.LeaferIN.flow = (function (exports, draw) {
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
const { M, L, C, Q, Z, N, D, X, G, F, O, P, U } = draw.PathCommandMap;
|
|
6
|
+
const PathScaler = {
|
|
7
|
+
scale(data, scaleX, scaleY) {
|
|
8
|
+
if (!data)
|
|
9
|
+
return;
|
|
10
|
+
let command;
|
|
11
|
+
let i = 0, len = data.length;
|
|
12
|
+
while (i < len) {
|
|
13
|
+
command = data[i];
|
|
14
|
+
switch (command) {
|
|
15
|
+
case M:
|
|
16
|
+
scalePoints(data, scaleX, scaleY, i, 1);
|
|
17
|
+
i += 3;
|
|
18
|
+
break;
|
|
19
|
+
case L:
|
|
20
|
+
scalePoints(data, scaleX, scaleY, i, 1);
|
|
21
|
+
i += 3;
|
|
22
|
+
break;
|
|
23
|
+
case C:
|
|
24
|
+
scalePoints(data, scaleX, scaleY, i, 3);
|
|
25
|
+
i += 7;
|
|
26
|
+
break;
|
|
27
|
+
case Q:
|
|
28
|
+
scalePoints(data, scaleX, scaleY, i, 2);
|
|
29
|
+
i += 5;
|
|
30
|
+
break;
|
|
31
|
+
case Z:
|
|
32
|
+
i += 1;
|
|
33
|
+
break;
|
|
34
|
+
case N:
|
|
35
|
+
scalePoints(data, scaleX, scaleY, i, 2);
|
|
36
|
+
i += 5;
|
|
37
|
+
break;
|
|
38
|
+
case D:
|
|
39
|
+
scalePoints(data, scaleX, scaleY, i, 2);
|
|
40
|
+
i += 9;
|
|
41
|
+
break;
|
|
42
|
+
case X:
|
|
43
|
+
scalePoints(data, scaleX, scaleY, i, 2);
|
|
44
|
+
i += 6;
|
|
45
|
+
break;
|
|
46
|
+
case G:
|
|
47
|
+
scalePoints(data, scaleX, scaleY, i, 2);
|
|
48
|
+
i += 9;
|
|
49
|
+
break;
|
|
50
|
+
case F:
|
|
51
|
+
scalePoints(data, scaleX, scaleY, i, 2);
|
|
52
|
+
i += 5;
|
|
53
|
+
break;
|
|
54
|
+
case O:
|
|
55
|
+
data[i] = G;
|
|
56
|
+
data.splice(i + 4, 0, data[i + 3], 0);
|
|
57
|
+
scalePoints(data, scaleX, scaleY, i, 2);
|
|
58
|
+
i += 7 + 2;
|
|
59
|
+
len += 2;
|
|
60
|
+
break;
|
|
61
|
+
case P:
|
|
62
|
+
data[i] = F;
|
|
63
|
+
data.splice(i + 4, 0, data[i + 3]);
|
|
64
|
+
scalePoints(data, scaleX, scaleY, i, 2);
|
|
65
|
+
i += 4 + 1;
|
|
66
|
+
len += 1;
|
|
67
|
+
break;
|
|
68
|
+
case U:
|
|
69
|
+
scalePoints(data, scaleX, scaleY, i, 2);
|
|
70
|
+
i += 6;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
scalePoints(data, scaleX, scaleY, start, pointCount) {
|
|
76
|
+
for (let i = pointCount ? start + 1 : 0, end = pointCount ? i + pointCount * 2 : data.length; i < end; i += 2) {
|
|
77
|
+
data[i] *= scaleX;
|
|
78
|
+
data[i + 1] *= scaleY;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const { scalePoints } = PathScaler;
|
|
83
|
+
|
|
84
|
+
const matrix = draw.MatrixHelper.get();
|
|
85
|
+
function scaleResize(leaf, scaleX, scaleY) {
|
|
86
|
+
if (leaf.pathInputed) {
|
|
87
|
+
scaleResizePath(leaf, scaleX, scaleY);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
if (scaleX !== 1)
|
|
91
|
+
leaf.width *= scaleX;
|
|
92
|
+
if (scaleY !== 1)
|
|
93
|
+
leaf.height *= scaleY;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function scaleResizeFontSize(leaf, scaleX, scaleY) {
|
|
97
|
+
const { width, height } = leaf.__localBoxBounds;
|
|
98
|
+
if (scaleX !== 1) {
|
|
99
|
+
leaf.fontSize *= scaleX;
|
|
100
|
+
leaf.y -= height * (scaleX - scaleY) / 2;
|
|
101
|
+
}
|
|
102
|
+
else if (scaleY !== 1) {
|
|
103
|
+
leaf.fontSize *= scaleY;
|
|
104
|
+
leaf.x -= width * (scaleY - scaleX) / 2;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function scaleResizePath(leaf, scaleX, scaleY) {
|
|
108
|
+
PathScaler.scale(leaf.__.path, scaleX, scaleY);
|
|
109
|
+
leaf.path = leaf.__.path;
|
|
110
|
+
}
|
|
111
|
+
function scaleResizePoints(leaf, scaleX, scaleY) {
|
|
112
|
+
PathScaler.scalePoints(leaf.__.points, scaleX, scaleY);
|
|
113
|
+
leaf.points = leaf.__.points;
|
|
114
|
+
}
|
|
115
|
+
function scaleResizeGroup(group, scaleX, scaleY) {
|
|
116
|
+
const { children } = group;
|
|
117
|
+
for (let i = 0; i < children.length; i++) {
|
|
118
|
+
matrix.a = scaleX;
|
|
119
|
+
matrix.d = scaleY;
|
|
120
|
+
children[i].transform(matrix, true);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const leaf = draw.Leaf.prototype;
|
|
125
|
+
leaf.scaleResize = function (scaleX, scaleY = scaleX, noResize) {
|
|
126
|
+
const data = this;
|
|
127
|
+
if (noResize || (data.editConfig && data.editConfig.editSize === 'scale')) {
|
|
128
|
+
data.scaleX *= scaleX;
|
|
129
|
+
data.scaleY *= scaleY;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
if (scaleX < 0)
|
|
133
|
+
data.scaleX *= -1, scaleX = -scaleX;
|
|
134
|
+
if (scaleY < 0)
|
|
135
|
+
data.scaleY *= -1, scaleY = -scaleY;
|
|
136
|
+
this.__scaleResize(scaleX, scaleY);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
leaf.__scaleResize = function (scaleX, scaleY) {
|
|
140
|
+
scaleResize(this, scaleX, scaleY);
|
|
141
|
+
};
|
|
142
|
+
leaf.resizeWidth = function (width) {
|
|
143
|
+
const scale = width / this.getBounds('box', 'local').width;
|
|
144
|
+
this.scaleOf(this.__layout.boxBounds, scale, this.__.lockRatio ? scale : 1, true);
|
|
145
|
+
};
|
|
146
|
+
leaf.resizeHeight = function (height) {
|
|
147
|
+
const scale = height / this.getBounds('box', 'local').height;
|
|
148
|
+
this.scaleOf(this.__layout.boxBounds, this.__.lockRatio ? scale : 1, scale, true);
|
|
149
|
+
};
|
|
150
|
+
draw.Text.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
151
|
+
if (this.__.__autoSize && (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size'))) {
|
|
152
|
+
scaleResizeFontSize(this, scaleX, scaleY);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
scaleResize(this, scaleX, scaleY);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
draw.Path.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
159
|
+
scaleResizePath(this, scaleX, scaleY);
|
|
160
|
+
};
|
|
161
|
+
draw.Line.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
162
|
+
if (this.pathInputed) {
|
|
163
|
+
scaleResizePath(this, scaleX, scaleY);
|
|
164
|
+
}
|
|
165
|
+
else if (this.points) {
|
|
166
|
+
scaleResizePoints(this, scaleX, scaleY);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
this.width *= scaleX;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
draw.Polygon.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
173
|
+
if (this.pathInputed) {
|
|
174
|
+
scaleResizePath(this, scaleX, scaleY);
|
|
175
|
+
}
|
|
176
|
+
else if (this.points) {
|
|
177
|
+
scaleResizePoints(this, scaleX, scaleY);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
scaleResize(this, scaleX, scaleY);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
draw.Group.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
184
|
+
scaleResizeGroup(this, scaleX, scaleY);
|
|
185
|
+
};
|
|
186
|
+
draw.Box.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
187
|
+
if (this.__.__autoSize && this.children.length) {
|
|
188
|
+
scaleResizeGroup(this, scaleX, scaleY);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
scaleResize(this, scaleX, scaleY);
|
|
192
|
+
if (this.__.resizeChildren)
|
|
193
|
+
scaleResizeGroup(this, scaleX, scaleY);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
/******************************************************************************
|
|
198
|
+
Copyright (c) Microsoft Corporation.
|
|
199
|
+
|
|
200
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
201
|
+
purpose with or without fee is hereby granted.
|
|
202
|
+
|
|
203
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
204
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
205
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
206
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
207
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
208
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
209
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
210
|
+
***************************************************************************** */
|
|
211
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
function __decorate(decorators, target, key, desc) {
|
|
215
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
216
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
217
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
218
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
222
|
+
var e = new Error(message);
|
|
223
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
class FlowData extends draw.BoxData {
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
exports.Flow = class Flow extends draw.Box {
|
|
230
|
+
get __tag() { return 'Flow'; }
|
|
231
|
+
constructor(data) {
|
|
232
|
+
super(data);
|
|
233
|
+
this.__hasAutoLayout = true;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
__decorate([
|
|
237
|
+
draw.dataProcessor(FlowData)
|
|
238
|
+
], exports.Flow.prototype, "__", void 0);
|
|
239
|
+
__decorate([
|
|
240
|
+
draw.autoLayoutType('x')
|
|
241
|
+
], exports.Flow.prototype, "flow", void 0);
|
|
242
|
+
exports.Flow = __decorate([
|
|
243
|
+
draw.registerUI()
|
|
244
|
+
], exports.Flow);
|
|
245
|
+
|
|
246
|
+
const point = {};
|
|
247
|
+
const alignToInnerXMap = {
|
|
248
|
+
'top-left': 'from',
|
|
249
|
+
'top': 'center',
|
|
250
|
+
'top-right': 'to',
|
|
251
|
+
'right': 'to',
|
|
252
|
+
'bottom-right': 'to',
|
|
253
|
+
'bottom': 'center',
|
|
254
|
+
'bottom-left': 'from',
|
|
255
|
+
'left': 'from',
|
|
256
|
+
'center': 'center',
|
|
257
|
+
'baseline-left': 'from',
|
|
258
|
+
'baseline-center': 'center',
|
|
259
|
+
'baseline-right': 'to',
|
|
260
|
+
};
|
|
261
|
+
const alignToInnerYMap = {
|
|
262
|
+
'top-left': 'from',
|
|
263
|
+
'top': 'from',
|
|
264
|
+
'top-right': 'from',
|
|
265
|
+
'right': 'center',
|
|
266
|
+
'bottom-right': 'to',
|
|
267
|
+
'bottom': 'to',
|
|
268
|
+
'bottom-left': 'to',
|
|
269
|
+
'left': 'center',
|
|
270
|
+
'center': 'center',
|
|
271
|
+
'baseline-left': 'to',
|
|
272
|
+
'baseline-center': 'to',
|
|
273
|
+
'baseline-right': 'to',
|
|
274
|
+
};
|
|
275
|
+
function alignContent(box, content, align) {
|
|
276
|
+
draw.AlignHelper.toPoint(align, content, box.__layout.contentBounds, point);
|
|
277
|
+
const data = box.__;
|
|
278
|
+
content.x = data.__autoWidth ? 0 : point.x;
|
|
279
|
+
content.y = data.__autoHeight ? 0 : point.y;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function align$1(box, data, contentAlign, innerXAlign) {
|
|
283
|
+
alignContent(box, data, contentAlign);
|
|
284
|
+
const { list } = data;
|
|
285
|
+
if (list.length > 1) {
|
|
286
|
+
if (!innerXAlign)
|
|
287
|
+
innerXAlign = alignToInnerXMap[contentAlign];
|
|
288
|
+
if (innerXAlign !== 'from') {
|
|
289
|
+
let row;
|
|
290
|
+
for (let i = 0, len = list.length; i < len; i++) {
|
|
291
|
+
row = list[i];
|
|
292
|
+
row.x = data.width - row.width;
|
|
293
|
+
if (innerXAlign === 'center')
|
|
294
|
+
row.x /= 2;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const { move: move$3 } = draw.PointHelper;
|
|
301
|
+
function layout$1(box, data, rowYAlign, reverse) {
|
|
302
|
+
const { list } = data, reverseWrap = box.__.flowWrap === 'reverse';
|
|
303
|
+
let row, { x, y } = data;
|
|
304
|
+
for (let i = 0, len = list.length; i < len; i++) {
|
|
305
|
+
row = list[reverseWrap ? len - 1 - i : i];
|
|
306
|
+
layoutX(box, row, x, y, rowYAlign, reverse);
|
|
307
|
+
y += row.height + data.gap;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
function layoutX(box, row, fromX, fromY, rowYAlign, reverse) {
|
|
311
|
+
const { children } = box;
|
|
312
|
+
let child, local, { x, start } = row, y = fromY;
|
|
313
|
+
x += fromX;
|
|
314
|
+
for (let j = 0, end = row.count; j < end; j++) {
|
|
315
|
+
child = children[reverse ? start - j : start + j];
|
|
316
|
+
if (child.__.inFlow && child.__.visible !== 0) {
|
|
317
|
+
local = child.__flowBounds;
|
|
318
|
+
if (rowYAlign !== 'from')
|
|
319
|
+
y = fromY + (row.height - local.height) / (rowYAlign === 'center' ? 2 : 1);
|
|
320
|
+
move$3(child, x - local.x, y - local.y);
|
|
321
|
+
x += local.width + row.gap;
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
end++;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function flowWrap(wrapData, data, wrapSide) {
|
|
330
|
+
const otherSide = wrapSide === 'width' ? 'height' : 'width';
|
|
331
|
+
wrapData[wrapSide] = Math.max(wrapData[wrapSide], data[wrapSide]);
|
|
332
|
+
wrapData[otherSide] += wrapData.count ? data[otherSide] + wrapData.gap : data[otherSide];
|
|
333
|
+
wrapData.list.push(data);
|
|
334
|
+
wrapData.count++;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const p = {};
|
|
338
|
+
function getParseData(box, isFlowX) {
|
|
339
|
+
const { gap, flowAlign: align, flowWrap: wrap, __autoWidth, __autoHeight } = box.__;
|
|
340
|
+
const needWrap = wrap && (isFlowX ? !__autoWidth : !__autoHeight);
|
|
341
|
+
if (typeof gap === 'object') {
|
|
342
|
+
p.xGap = gap.x || 0;
|
|
343
|
+
p.yGap = gap.y || 0;
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
p.xGap = p.yGap = gap;
|
|
347
|
+
}
|
|
348
|
+
p.isAutoXGap = typeof p.xGap === 'string' && !__autoWidth;
|
|
349
|
+
p.isAutoYGap = typeof p.yGap === 'string' && !__autoHeight;
|
|
350
|
+
p.complex = needWrap || align !== 'top-left' || box.__hasGrow || p.isAutoXGap || p.isAutoYGap;
|
|
351
|
+
p.wrap = needWrap;
|
|
352
|
+
if (p.complex) {
|
|
353
|
+
p.isFitXGap = p.xGap === 'fit' && !__autoWidth;
|
|
354
|
+
p.isFitYGap = p.yGap === 'fit' && !__autoHeight;
|
|
355
|
+
if (typeof align === 'object') {
|
|
356
|
+
p.contentAlign = align.content || 'top-left';
|
|
357
|
+
p.rowXAlign = align.x || 'from';
|
|
358
|
+
p.rowYAlign = align.y || 'from';
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
p.contentAlign = align;
|
|
362
|
+
p.rowXAlign = alignToInnerXMap[align];
|
|
363
|
+
p.rowYAlign = alignToInnerYMap[align];
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return p;
|
|
367
|
+
}
|
|
368
|
+
function getDrawData(start, gap) {
|
|
369
|
+
return { x: 0, y: 0, width: 0, height: 0, gap, start, count: 0, grow: 0 };
|
|
370
|
+
}
|
|
371
|
+
function getWrapDrawData() {
|
|
372
|
+
return { x: 0, y: 0, width: 0, height: 0, gap: 0, count: 0, list: [] };
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function autoGap(data, side, sideTotal, fit) {
|
|
376
|
+
const { count } = data;
|
|
377
|
+
if (count > 1 && (sideTotal > data[side] || fit)) {
|
|
378
|
+
data.gap = (sideTotal - data[side]) / (count - 1);
|
|
379
|
+
data[side] = sideTotal;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function getItemBounds(child, itemBox) {
|
|
384
|
+
return itemBox === 'box' ? child.__local : child.__layout.localStrokeBounds;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const { within: within$1 } = draw.MathHelper;
|
|
388
|
+
function growX(box, row, width, reverse) {
|
|
389
|
+
let child, grow, remainSpace, remainTotalSpace = 0, list = row.hasRangeSize && [], { grow: totalGrow, start } = row;
|
|
390
|
+
const growSize = row.width < width ? (width - row.width) / totalGrow : 0, { children } = box;
|
|
391
|
+
if (growSize)
|
|
392
|
+
row.width = width;
|
|
393
|
+
for (let j = 0, end = row.count; j < end; j++) {
|
|
394
|
+
child = children[reverse ? start - j : start + j];
|
|
395
|
+
if (child.__.inFlow && child.__.visible !== 0) {
|
|
396
|
+
if (grow = child.__widthGrow) {
|
|
397
|
+
remainSpace = resizeWidth(child, child.__flowBounds, growSize * grow);
|
|
398
|
+
if (remainSpace) {
|
|
399
|
+
remainTotalSpace += remainSpace;
|
|
400
|
+
totalGrow -= grow;
|
|
401
|
+
}
|
|
402
|
+
else if (list) {
|
|
403
|
+
child.__.widthRange ? list.unshift(child) : list.push(child);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
else {
|
|
408
|
+
end++;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
if (remainTotalSpace)
|
|
412
|
+
assignRemainSpace$1(list, remainTotalSpace, totalGrow);
|
|
413
|
+
}
|
|
414
|
+
function assignRemainSpace$1(list, totalSpace, countGrow) {
|
|
415
|
+
let grow, space, local, remain;
|
|
416
|
+
list.forEach(child => {
|
|
417
|
+
grow = child.__widthGrow;
|
|
418
|
+
space = totalSpace / countGrow * grow;
|
|
419
|
+
remain = resizeWidth(child, local = child.__flowBounds, local.width + space);
|
|
420
|
+
totalSpace -= space - remain;
|
|
421
|
+
countGrow -= grow;
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
function resizeWidth(child, local, size) {
|
|
425
|
+
const { widthRange, lockRatio } = child.__;
|
|
426
|
+
const realSize = widthRange ? within$1(size, widthRange) : size;
|
|
427
|
+
const scale = realSize / local.width;
|
|
428
|
+
child.scaleResize(scale, lockRatio ? scale : 1);
|
|
429
|
+
local.width = realSize;
|
|
430
|
+
return size - realSize;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
const { within } = draw.MathHelper;
|
|
434
|
+
function growY(box, row, height, reverse) {
|
|
435
|
+
let child, grow, remainSpace, remainTotalSpace = 0, list = row.hasRangeSize && [], { grow: totalGrow, start } = row;
|
|
436
|
+
const growSize = row.height < height ? (height - row.height) / totalGrow : 0, { children } = box;
|
|
437
|
+
if (growSize)
|
|
438
|
+
row.height = height;
|
|
439
|
+
for (let j = 0, end = row.count; j < end; j++) {
|
|
440
|
+
child = children[reverse ? start - j : start + j];
|
|
441
|
+
if (child.__.inFlow && child.__.visible !== 0) {
|
|
442
|
+
if (grow = child.__heightGrow) {
|
|
443
|
+
remainSpace = resizeHeight(child, child.__flowBounds, growSize * grow);
|
|
444
|
+
if (remainSpace) {
|
|
445
|
+
remainTotalSpace += remainSpace;
|
|
446
|
+
totalGrow -= grow;
|
|
447
|
+
}
|
|
448
|
+
else if (list) {
|
|
449
|
+
child.__.heightRange ? list.unshift(child) : list.push(child);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
end++;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
if (remainTotalSpace)
|
|
458
|
+
assignRemainSpace(list, remainTotalSpace, totalGrow);
|
|
459
|
+
}
|
|
460
|
+
function assignRemainSpace(list, totalSpace, countGrow) {
|
|
461
|
+
let grow, space, local, remain;
|
|
462
|
+
list.forEach(child => {
|
|
463
|
+
grow = child.__heightGrow;
|
|
464
|
+
space = totalSpace / countGrow * grow;
|
|
465
|
+
remain = resizeHeight(child, local = child.__flowBounds, local.height + space);
|
|
466
|
+
totalSpace -= space - remain;
|
|
467
|
+
countGrow -= grow;
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
function resizeHeight(child, local, size) {
|
|
471
|
+
const { heightRange, lockRatio } = child.__;
|
|
472
|
+
const realSize = heightRange ? within(size, heightRange) : size;
|
|
473
|
+
const scale = realSize / local.height;
|
|
474
|
+
child.scaleResize(lockRatio ? scale : 1, scale);
|
|
475
|
+
local.height = realSize;
|
|
476
|
+
return size - realSize;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
const { move: move$2 } = draw.PointHelper;
|
|
480
|
+
function flowX(box, reverse) {
|
|
481
|
+
const side = 'width', { children, itemBox } = box, pData = getParseData(box, true);
|
|
482
|
+
const { complex, wrap, xGap, yGap, isAutoXGap, isFitXGap } = pData;
|
|
483
|
+
if (!children.length)
|
|
484
|
+
return;
|
|
485
|
+
const wrapData = wrap && getWrapDrawData(), xGapTempNum = isAutoXGap ? 0 : xGap;
|
|
486
|
+
let child, local, localWidth, index, data, { x, y, width, height } = box.__layout.contentBounds;
|
|
487
|
+
for (let i = 0, len = children.length; i < len; i++) {
|
|
488
|
+
child = children[index = reverse ? len - 1 - i : i];
|
|
489
|
+
if (child.__.inFlow && child.__.visible !== 0) {
|
|
490
|
+
local = getItemBounds(child, itemBox);
|
|
491
|
+
if (complex) {
|
|
492
|
+
child.__flowBounds = local;
|
|
493
|
+
if (!data)
|
|
494
|
+
data = getDrawData(index, xGapTempNum);
|
|
495
|
+
if (wrap && data.count && data.width + local.width > width) {
|
|
496
|
+
if (data.grow)
|
|
497
|
+
growX(box, data, width, reverse);
|
|
498
|
+
else if (isAutoXGap)
|
|
499
|
+
autoGap(data, side, width, isFitXGap);
|
|
500
|
+
flowWrap(wrapData, data, side);
|
|
501
|
+
data = getDrawData(index, xGapTempNum);
|
|
502
|
+
}
|
|
503
|
+
localWidth = local.width;
|
|
504
|
+
if (child.__widthGrow) {
|
|
505
|
+
data.grow += child.__widthGrow, localWidth = 0;
|
|
506
|
+
if (child.__.widthRange)
|
|
507
|
+
data.hasRangeSize = true;
|
|
508
|
+
}
|
|
509
|
+
if (child.__heightGrow)
|
|
510
|
+
resizeHeight(child, local, height);
|
|
511
|
+
data.width += data.count ? localWidth + xGapTempNum : localWidth;
|
|
512
|
+
data.height = Math.max(data.height, local.height);
|
|
513
|
+
data.count++;
|
|
514
|
+
}
|
|
515
|
+
else {
|
|
516
|
+
move$2(child, x - local.x, y - local.y);
|
|
517
|
+
x += local.width + xGapTempNum;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
if (complex) {
|
|
522
|
+
const { isAutoYGap, isFitYGap, contentAlign, rowXAlign, rowYAlign } = pData;
|
|
523
|
+
if (data.count) {
|
|
524
|
+
if (data.grow)
|
|
525
|
+
growX(box, data, width, reverse);
|
|
526
|
+
else if (isAutoXGap)
|
|
527
|
+
autoGap(data, side, width, isFitXGap);
|
|
528
|
+
if (wrap)
|
|
529
|
+
flowWrap(wrapData, data, side);
|
|
530
|
+
}
|
|
531
|
+
if (wrap) {
|
|
532
|
+
if (isAutoYGap)
|
|
533
|
+
autoGap(wrapData, 'height', height, isFitYGap);
|
|
534
|
+
else
|
|
535
|
+
wrapData.gap = yGap;
|
|
536
|
+
align$1(box, wrapData, contentAlign, rowXAlign);
|
|
537
|
+
layout$1(box, wrapData, rowYAlign, reverse);
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
alignContent(box, data, contentAlign);
|
|
541
|
+
layoutX(box, data, 0, data.y, rowYAlign, reverse);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
function align(box, data, contentAlign, rowYAlign) {
|
|
547
|
+
alignContent(box, data, contentAlign);
|
|
548
|
+
const { list } = data;
|
|
549
|
+
if (list.length > 1) {
|
|
550
|
+
if (!rowYAlign)
|
|
551
|
+
rowYAlign = alignToInnerYMap[contentAlign];
|
|
552
|
+
if (rowYAlign !== 'from') {
|
|
553
|
+
let row;
|
|
554
|
+
for (let i = 0, len = list.length; i < len; i++) {
|
|
555
|
+
row = list[i];
|
|
556
|
+
row.y = data.height - row.height;
|
|
557
|
+
if (rowYAlign === 'center')
|
|
558
|
+
row.y /= 2;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
const { move: move$1 } = draw.PointHelper;
|
|
565
|
+
function layout(box, data, rowXAlign, reverse) {
|
|
566
|
+
const { list } = data, reverseWrap = box.__.flowWrap === 'reverse';
|
|
567
|
+
let row, { x, y } = data;
|
|
568
|
+
for (let i = 0, len = list.length; i < len; i++) {
|
|
569
|
+
row = list[reverseWrap ? len - 1 - i : i];
|
|
570
|
+
layoutY(box, row, x, y, rowXAlign, reverse);
|
|
571
|
+
x += row.width + data.gap;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
function layoutY(box, row, fromX, fromY, rowXAlign, reverse) {
|
|
575
|
+
const { children } = box;
|
|
576
|
+
let child, local, { y, start } = row, x = fromX;
|
|
577
|
+
y += fromY;
|
|
578
|
+
for (let j = 0, end = row.count; j < end; j++) {
|
|
579
|
+
child = children[reverse ? start - j : start + j];
|
|
580
|
+
if (child.__.inFlow && child.__.visible !== 0) {
|
|
581
|
+
local = child.__flowBounds;
|
|
582
|
+
if (rowXAlign !== 'from')
|
|
583
|
+
x = fromX + (row.width - local.width) / (rowXAlign === 'center' ? 2 : 1);
|
|
584
|
+
move$1(child, x - local.x, y - local.y);
|
|
585
|
+
y += local.height + row.gap;
|
|
586
|
+
}
|
|
587
|
+
else {
|
|
588
|
+
end++;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
const { move } = draw.PointHelper;
|
|
594
|
+
function flowY(box, reverse) {
|
|
595
|
+
const side = 'height', { children, itemBox } = box, pData = getParseData(box, false);
|
|
596
|
+
const { complex, wrap, xGap, yGap, isAutoYGap, isFitYGap } = pData;
|
|
597
|
+
if (!children.length)
|
|
598
|
+
return;
|
|
599
|
+
const wrapData = wrap && getWrapDrawData(), yGapTempNum = isAutoYGap ? 0 : yGap;
|
|
600
|
+
let child, local, localHeight, index, data, { x, y, width, height } = box.__layout.contentBounds;
|
|
601
|
+
for (let i = 0, len = children.length; i < len; i++) {
|
|
602
|
+
child = children[index = reverse ? len - 1 - i : i];
|
|
603
|
+
if (child.__.inFlow && child.__.visible !== 0) {
|
|
604
|
+
local = getItemBounds(child, itemBox);
|
|
605
|
+
if (complex) {
|
|
606
|
+
child.__flowBounds = local;
|
|
607
|
+
if (!data)
|
|
608
|
+
data = getDrawData(index, yGapTempNum);
|
|
609
|
+
if (wrap && data.count && data.height + local.height > height) {
|
|
610
|
+
if (data.grow)
|
|
611
|
+
growY(box, data, height, reverse);
|
|
612
|
+
if (isAutoYGap)
|
|
613
|
+
autoGap(data, side, height, isFitYGap);
|
|
614
|
+
flowWrap(wrapData, data, side);
|
|
615
|
+
data = getDrawData(index, yGapTempNum);
|
|
616
|
+
}
|
|
617
|
+
localHeight = local.height;
|
|
618
|
+
if (child.__heightGrow) {
|
|
619
|
+
data.grow += child.__heightGrow, localHeight = 0;
|
|
620
|
+
if (child.__.heightRange)
|
|
621
|
+
data.hasRangeSize = true;
|
|
622
|
+
}
|
|
623
|
+
if (child.__widthGrow)
|
|
624
|
+
resizeWidth(child, local, width);
|
|
625
|
+
data.height += data.count ? localHeight + yGapTempNum : localHeight;
|
|
626
|
+
data.width = Math.max(data.width, local.width);
|
|
627
|
+
data.count++;
|
|
628
|
+
}
|
|
629
|
+
else {
|
|
630
|
+
move(child, x - local.x, y - local.y);
|
|
631
|
+
y += local.height + yGapTempNum;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
if (complex) {
|
|
636
|
+
const { isAutoXGap, isFitXGap, contentAlign, rowXAlign, rowYAlign } = pData;
|
|
637
|
+
if (data.count) {
|
|
638
|
+
if (data.grow)
|
|
639
|
+
growY(box, data, height, reverse);
|
|
640
|
+
if (isAutoYGap)
|
|
641
|
+
autoGap(data, side, height, isFitYGap);
|
|
642
|
+
if (wrap)
|
|
643
|
+
flowWrap(wrapData, data, side);
|
|
644
|
+
}
|
|
645
|
+
if (wrap) {
|
|
646
|
+
if (!isAutoXGap)
|
|
647
|
+
wrapData.gap = xGap;
|
|
648
|
+
else
|
|
649
|
+
autoGap(wrapData, 'width', width, isFitXGap);
|
|
650
|
+
align(box, wrapData, contentAlign, rowYAlign);
|
|
651
|
+
layout(box, wrapData, rowXAlign, reverse);
|
|
652
|
+
}
|
|
653
|
+
else {
|
|
654
|
+
alignContent(box, data, contentAlign);
|
|
655
|
+
layoutY(box, data, data.x, 0, rowXAlign, reverse);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
function autoBoundsType(defaultValue) {
|
|
661
|
+
return draw.decorateLeafAttr(defaultValue, (key) => draw.attr({
|
|
662
|
+
set(value) {
|
|
663
|
+
const grow = typeof value === 'number' ? value : 0;
|
|
664
|
+
key === 'autoWidth' ? this.__widthGrow = grow : this.__heightGrow = grow;
|
|
665
|
+
if (grow && !(this.parent && this.parent.__hasGrow))
|
|
666
|
+
this.waitParent(() => { this.parent.__hasGrow = true; });
|
|
667
|
+
this.__setAttr(key, value) && draw.doBoundsType(this);
|
|
668
|
+
}
|
|
669
|
+
}));
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
const { copyAndSpread } = draw.BoundsHelper;
|
|
673
|
+
let doFlowX = flowX, doFlowY = flowY;
|
|
674
|
+
draw.UI.changeAttr('autoWidth', undefined, autoBoundsType);
|
|
675
|
+
draw.UI.changeAttr('autoHeight', undefined, autoBoundsType);
|
|
676
|
+
draw.Box.prototype.__updateFlowLayout = function () {
|
|
677
|
+
this.leafer.created = false;
|
|
678
|
+
const { flow } = this.__;
|
|
679
|
+
switch (flow) {
|
|
680
|
+
case 'x':
|
|
681
|
+
case true:
|
|
682
|
+
doFlowX(this);
|
|
683
|
+
break;
|
|
684
|
+
case 'y':
|
|
685
|
+
doFlowY(this);
|
|
686
|
+
break;
|
|
687
|
+
case 'x-reverse':
|
|
688
|
+
doFlowX(this, true);
|
|
689
|
+
break;
|
|
690
|
+
case 'y-reverse':
|
|
691
|
+
doFlowY(this, true);
|
|
692
|
+
break;
|
|
693
|
+
}
|
|
694
|
+
this.leafer.created = true;
|
|
695
|
+
};
|
|
696
|
+
draw.Box.prototype.__updateContentBounds = function () {
|
|
697
|
+
const { padding } = this.__;
|
|
698
|
+
const layout = this.__layout;
|
|
699
|
+
const same = layout.contentBounds === layout.boxBounds;
|
|
700
|
+
if (padding) {
|
|
701
|
+
if (same)
|
|
702
|
+
layout.shrinkContent();
|
|
703
|
+
copyAndSpread(layout.contentBounds, layout.boxBounds, padding, true);
|
|
704
|
+
}
|
|
705
|
+
else {
|
|
706
|
+
if (!same)
|
|
707
|
+
layout.shrinkContentCancel();
|
|
708
|
+
}
|
|
709
|
+
};
|
|
710
|
+
|
|
711
|
+
exports.PathScaler = PathScaler;
|
|
712
|
+
exports.scaleResize = scaleResize;
|
|
713
|
+
exports.scaleResizeFontSize = scaleResizeFontSize;
|
|
714
|
+
exports.scaleResizeGroup = scaleResizeGroup;
|
|
715
|
+
exports.scaleResizePath = scaleResizePath;
|
|
716
|
+
exports.scaleResizePoints = scaleResizePoints;
|
|
717
|
+
|
|
718
|
+
return exports;
|
|
719
|
+
|
|
720
|
+
})({}, LeaferUI);
|