@leafer-in/flow 1.7.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/flow.cjs +242 -269
- package/dist/flow.esm.js +240 -267
- package/dist/flow.esm.min.js +1 -1
- package/dist/flow.esm.min.js.map +1 -1
- package/dist/flow.js +203 -286
- package/dist/flow.min.cjs +1 -1
- package/dist/flow.min.cjs.map +1 -1
- package/dist/flow.min.js +1 -1
- package/dist/flow.min.js.map +1 -1
- package/package.json +5 -5
- package/src/decorate.ts +2 -2
- package/src/index.ts +1 -3
- package/src/layout/common/data.ts +7 -5
package/dist/flow.cjs
CHANGED
|
@@ -1,89 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var draw = require(
|
|
4
|
-
require('@leafer-in/resize');
|
|
5
|
-
|
|
6
|
-
/******************************************************************************
|
|
7
|
-
Copyright (c) Microsoft Corporation.
|
|
8
|
-
|
|
9
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
10
|
-
purpose with or without fee is hereby granted.
|
|
11
|
-
|
|
12
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
14
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
-
***************************************************************************** */
|
|
20
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function __decorate(decorators, target, key, desc) {
|
|
24
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
25
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
26
|
-
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;
|
|
27
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
31
|
-
var e = new Error(message);
|
|
32
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
33
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var draw = require("@leafer-ui/draw");
|
|
34
4
|
|
|
35
|
-
|
|
5
|
+
require("@leafer-in/resize");
|
|
6
|
+
|
|
7
|
+
function __decorate(decorators, target, key, desc) {
|
|
8
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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;
|
|
10
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
36
11
|
}
|
|
37
12
|
|
|
13
|
+
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
14
|
+
var e = new Error(message);
|
|
15
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
class FlowData extends draw.BoxData {}
|
|
19
|
+
|
|
38
20
|
exports.Flow = class Flow extends draw.Box {
|
|
39
|
-
get __tag() {
|
|
21
|
+
get __tag() {
|
|
22
|
+
return "Flow";
|
|
23
|
+
}
|
|
40
24
|
constructor(data) {
|
|
41
25
|
super(data);
|
|
42
26
|
this.__hasAutoLayout = true;
|
|
43
27
|
}
|
|
44
28
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
__decorate([
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
exports.Flow = __decorate([
|
|
52
|
-
draw.registerUI()
|
|
53
|
-
], exports.Flow);
|
|
29
|
+
|
|
30
|
+
__decorate([ draw.dataProcessor(FlowData) ], exports.Flow.prototype, "__", void 0);
|
|
31
|
+
|
|
32
|
+
__decorate([ draw.autoLayoutType("x") ], exports.Flow.prototype, "flow", void 0);
|
|
33
|
+
|
|
34
|
+
exports.Flow = __decorate([ draw.registerUI() ], exports.Flow);
|
|
54
35
|
|
|
55
36
|
const point = {};
|
|
37
|
+
|
|
56
38
|
const alignToInnerXMap = {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
39
|
+
"top-left": "from",
|
|
40
|
+
top: "center",
|
|
41
|
+
"top-right": "to",
|
|
42
|
+
right: "to",
|
|
43
|
+
"bottom-right": "to",
|
|
44
|
+
bottom: "center",
|
|
45
|
+
"bottom-left": "from",
|
|
46
|
+
left: "from",
|
|
47
|
+
center: "center",
|
|
48
|
+
"baseline-left": "from",
|
|
49
|
+
"baseline-center": "center",
|
|
50
|
+
"baseline-right": "to"
|
|
69
51
|
};
|
|
52
|
+
|
|
70
53
|
const alignToInnerYMap = {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
54
|
+
"top-left": "from",
|
|
55
|
+
top: "from",
|
|
56
|
+
"top-right": "from",
|
|
57
|
+
right: "center",
|
|
58
|
+
"bottom-right": "to",
|
|
59
|
+
bottom: "to",
|
|
60
|
+
"bottom-left": "to",
|
|
61
|
+
left: "center",
|
|
62
|
+
center: "center",
|
|
63
|
+
"baseline-left": "to",
|
|
64
|
+
"baseline-center": "to",
|
|
65
|
+
"baseline-right": "to"
|
|
83
66
|
};
|
|
67
|
+
|
|
84
68
|
function alignContent(box, content, align) {
|
|
85
69
|
const data = box.__;
|
|
86
|
-
const { contentBounds
|
|
70
|
+
const {contentBounds: contentBounds} = box.__layout;
|
|
87
71
|
draw.AlignHelper.toPoint(align, content, contentBounds, point);
|
|
88
72
|
content.x = data.__autoWidth ? contentBounds.x : point.x;
|
|
89
73
|
content.y = data.__autoHeight ? contentBounds.y : point.y;
|
|
@@ -91,53 +75,51 @@ function alignContent(box, content, align) {
|
|
|
91
75
|
|
|
92
76
|
function align$1(box, data, contentAlign, innerXAlign) {
|
|
93
77
|
alignContent(box, data, contentAlign);
|
|
94
|
-
const { list
|
|
78
|
+
const {list: list} = data;
|
|
95
79
|
if (list.length > 1) {
|
|
96
|
-
if (!innerXAlign)
|
|
97
|
-
|
|
98
|
-
if (innerXAlign !== 'from') {
|
|
80
|
+
if (!innerXAlign) innerXAlign = alignToInnerXMap[contentAlign];
|
|
81
|
+
if (innerXAlign !== "from") {
|
|
99
82
|
let row;
|
|
100
83
|
for (let i = 0, len = list.length; i < len; i++) {
|
|
101
84
|
row = list[i];
|
|
102
85
|
row.x = data.width - row.width;
|
|
103
|
-
if (innerXAlign ===
|
|
104
|
-
row.x /= 2;
|
|
86
|
+
if (innerXAlign === "center") row.x /= 2;
|
|
105
87
|
}
|
|
106
88
|
}
|
|
107
89
|
}
|
|
108
90
|
}
|
|
109
91
|
|
|
110
|
-
const {
|
|
92
|
+
const {move: move$3} = draw.PointHelper;
|
|
93
|
+
|
|
111
94
|
function layout$1(box, data, rowYAlign, reverse) {
|
|
112
|
-
const { list
|
|
113
|
-
let row, { x, y } = data;
|
|
95
|
+
const {list: list} = data, reverseWrap = box.__.flowWrap === "reverse";
|
|
96
|
+
let row, {x: x, y: y} = data;
|
|
114
97
|
for (let i = 0, len = list.length; i < len; i++) {
|
|
115
98
|
row = list[reverseWrap ? len - 1 - i : i];
|
|
116
99
|
layoutX(box, row, x, y, rowYAlign, reverse);
|
|
117
100
|
y += row.height + data.gap;
|
|
118
101
|
}
|
|
119
102
|
}
|
|
103
|
+
|
|
120
104
|
function layoutX(box, row, fromX, fromY, rowYAlign, reverse) {
|
|
121
|
-
const { children
|
|
122
|
-
let child, local, { x, start } = row, y = fromY;
|
|
105
|
+
const {children: children} = box;
|
|
106
|
+
let child, local, {x: x, start: start} = row, y = fromY;
|
|
123
107
|
x += fromX;
|
|
124
108
|
for (let j = 0, end = row.count; j < end; j++) {
|
|
125
109
|
child = children[reverse ? start - j : start + j];
|
|
126
110
|
if (child.__.inFlow && child.__.visible !== 0) {
|
|
127
111
|
local = child.__flowBounds;
|
|
128
|
-
if (rowYAlign !==
|
|
129
|
-
y = fromY + (row.height - local.height) / (rowYAlign === 'center' ? 2 : 1);
|
|
112
|
+
if (rowYAlign !== "from") y = fromY + (row.height - local.height) / (rowYAlign === "center" ? 2 : 1);
|
|
130
113
|
move$3(child, x - local.x, y - local.y);
|
|
131
114
|
x += local.width + row.gap;
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
115
|
+
} else {
|
|
134
116
|
end++;
|
|
135
117
|
}
|
|
136
118
|
}
|
|
137
119
|
}
|
|
138
120
|
|
|
139
121
|
function flowWrap(wrapData, data, wrapSide) {
|
|
140
|
-
const otherSide = wrapSide ===
|
|
122
|
+
const otherSide = wrapSide === "width" ? "height" : "width";
|
|
141
123
|
wrapData[wrapSide] = Math.max(wrapData[wrapSide], data[wrapSide]);
|
|
142
124
|
wrapData[otherSide] += wrapData.count ? data[otherSide] + wrapData.gap : data[otherSide];
|
|
143
125
|
wrapData.list.push(data);
|
|
@@ -145,29 +127,28 @@ function flowWrap(wrapData, data, wrapSide) {
|
|
|
145
127
|
}
|
|
146
128
|
|
|
147
129
|
const p = {};
|
|
130
|
+
|
|
148
131
|
function getParseData(box, isFlowX) {
|
|
149
|
-
const { gap, flowAlign: align, flowWrap: wrap, __autoWidth, __autoHeight } = box.__;
|
|
132
|
+
const {gap: gap, flowAlign: align, flowWrap: wrap, __autoWidth: __autoWidth, __autoHeight: __autoHeight} = box.__;
|
|
150
133
|
const needWrap = wrap && (isFlowX ? !__autoWidth : !__autoHeight);
|
|
151
|
-
if (
|
|
134
|
+
if (draw.isObject(gap)) {
|
|
152
135
|
p.xGap = gap.x || 0;
|
|
153
136
|
p.yGap = gap.y || 0;
|
|
137
|
+
} else {
|
|
138
|
+
p.xGap = p.yGap = draw.tryToNumber(gap);
|
|
154
139
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
p.isAutoXGap = typeof p.xGap === 'string' && !__autoWidth;
|
|
159
|
-
p.isAutoYGap = typeof p.yGap === 'string' && !__autoHeight;
|
|
160
|
-
p.complex = needWrap || align !== 'top-left' || box.__hasGrow || p.isAutoXGap || p.isAutoYGap;
|
|
140
|
+
p.isAutoXGap = draw.isString(p.xGap) && !__autoWidth;
|
|
141
|
+
p.isAutoYGap = draw.isString(p.yGap) && !__autoHeight;
|
|
142
|
+
p.complex = needWrap || align !== "top-left" || box.__hasGrow || p.isAutoXGap || p.isAutoYGap;
|
|
161
143
|
p.wrap = needWrap;
|
|
162
144
|
if (p.complex) {
|
|
163
|
-
p.isFitXGap = p.xGap ===
|
|
164
|
-
p.isFitYGap = p.yGap ===
|
|
165
|
-
if (
|
|
166
|
-
p.contentAlign = align.content ||
|
|
167
|
-
p.rowXAlign = align.x ||
|
|
168
|
-
p.rowYAlign = align.y ||
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
145
|
+
p.isFitXGap = p.xGap === "fit" && !__autoWidth;
|
|
146
|
+
p.isFitYGap = p.yGap === "fit" && !__autoHeight;
|
|
147
|
+
if (draw.isObject(align)) {
|
|
148
|
+
p.contentAlign = align.content || "top-left";
|
|
149
|
+
p.rowXAlign = align.x || "from";
|
|
150
|
+
p.rowYAlign = align.y || "from";
|
|
151
|
+
} else {
|
|
171
152
|
p.contentAlign = align;
|
|
172
153
|
p.rowXAlign = alignToInnerXMap[align];
|
|
173
154
|
p.rowYAlign = alignToInnerYMap[align];
|
|
@@ -175,15 +156,34 @@ function getParseData(box, isFlowX) {
|
|
|
175
156
|
}
|
|
176
157
|
return p;
|
|
177
158
|
}
|
|
159
|
+
|
|
178
160
|
function getDrawData(start, gap) {
|
|
179
|
-
return {
|
|
161
|
+
return {
|
|
162
|
+
x: 0,
|
|
163
|
+
y: 0,
|
|
164
|
+
width: 0,
|
|
165
|
+
height: 0,
|
|
166
|
+
gap: gap,
|
|
167
|
+
start: start,
|
|
168
|
+
count: 0,
|
|
169
|
+
grow: 0
|
|
170
|
+
};
|
|
180
171
|
}
|
|
172
|
+
|
|
181
173
|
function getWrapDrawData() {
|
|
182
|
-
return {
|
|
174
|
+
return {
|
|
175
|
+
x: 0,
|
|
176
|
+
y: 0,
|
|
177
|
+
width: 0,
|
|
178
|
+
height: 0,
|
|
179
|
+
gap: 0,
|
|
180
|
+
count: 0,
|
|
181
|
+
list: []
|
|
182
|
+
};
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
function autoGap(data, side, sideTotal, fit) {
|
|
186
|
-
const { count
|
|
186
|
+
const {count: count} = data;
|
|
187
187
|
if (count > 1 && (sideTotal > data[side] || fit)) {
|
|
188
188
|
data.gap = (sideTotal - data[side]) / (count - 1);
|
|
189
189
|
data[side] = sideTotal;
|
|
@@ -191,15 +191,15 @@ function autoGap(data, side, sideTotal, fit) {
|
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
function getItemBounds(child, itemBox) {
|
|
194
|
-
return itemBox ===
|
|
194
|
+
return itemBox === "box" ? child.__local : child.__layout.localStrokeBounds;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
const {
|
|
197
|
+
const {within: within$1} = draw.MathHelper;
|
|
198
|
+
|
|
198
199
|
function growX(box, row, width, reverse) {
|
|
199
|
-
let child, grow, remainSpace, remainTotalSpace = 0, list = row.hasRangeSize && [], {
|
|
200
|
-
const growSize = (width - row.width) / totalGrow, { children
|
|
201
|
-
if (growSize <= 0)
|
|
202
|
-
return;
|
|
200
|
+
let child, grow, remainSpace, remainTotalSpace = 0, list = row.hasRangeSize && [], {grow: totalGrow, start: start} = row;
|
|
201
|
+
const growSize = (width - row.width) / totalGrow, {children: children} = box;
|
|
202
|
+
if (growSize <= 0) return;
|
|
203
203
|
row.width = width;
|
|
204
204
|
for (let j = 0, end = row.count; j < end; j++) {
|
|
205
205
|
child = children[reverse ? start - j : start + j];
|
|
@@ -209,19 +209,17 @@ function growX(box, row, width, reverse) {
|
|
|
209
209
|
if (remainSpace) {
|
|
210
210
|
remainTotalSpace += remainSpace;
|
|
211
211
|
totalGrow -= grow;
|
|
212
|
-
}
|
|
213
|
-
else if (list) {
|
|
212
|
+
} else if (list) {
|
|
214
213
|
child.__.widthRange ? list.unshift(child) : list.push(child);
|
|
215
214
|
}
|
|
216
215
|
}
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
216
|
+
} else {
|
|
219
217
|
end++;
|
|
220
218
|
}
|
|
221
219
|
}
|
|
222
|
-
if (remainTotalSpace)
|
|
223
|
-
assignRemainSpace$1(list, remainTotalSpace, totalGrow);
|
|
220
|
+
if (remainTotalSpace) assignRemainSpace$1(list, remainTotalSpace, totalGrow);
|
|
224
221
|
}
|
|
222
|
+
|
|
225
223
|
function assignRemainSpace$1(list, totalSpace, countGrow) {
|
|
226
224
|
let grow, space, local, remain;
|
|
227
225
|
list.forEach(child => {
|
|
@@ -232,8 +230,9 @@ function assignRemainSpace$1(list, totalSpace, countGrow) {
|
|
|
232
230
|
countGrow -= grow;
|
|
233
231
|
});
|
|
234
232
|
}
|
|
233
|
+
|
|
235
234
|
function resizeWidth(child, local, size) {
|
|
236
|
-
const { widthRange, lockRatio } = child.__;
|
|
235
|
+
const {widthRange: widthRange, lockRatio: lockRatio} = child.__;
|
|
237
236
|
const realSize = widthRange ? within$1(size, widthRange) : size;
|
|
238
237
|
const scale = realSize / local.width;
|
|
239
238
|
child.scaleResize(scale, lockRatio ? scale : 1);
|
|
@@ -241,12 +240,12 @@ function resizeWidth(child, local, size) {
|
|
|
241
240
|
return size - realSize;
|
|
242
241
|
}
|
|
243
242
|
|
|
244
|
-
const { within
|
|
243
|
+
const {within: within} = draw.MathHelper;
|
|
244
|
+
|
|
245
245
|
function growY(box, row, height, reverse) {
|
|
246
|
-
let child, grow, remainSpace, remainTotalSpace = 0, list = row.hasRangeSize && [], {
|
|
247
|
-
const growSize = (height - row.height) / totalGrow, { children
|
|
248
|
-
if (growSize <= 0)
|
|
249
|
-
return;
|
|
246
|
+
let child, grow, remainSpace, remainTotalSpace = 0, list = row.hasRangeSize && [], {grow: totalGrow, start: start} = row;
|
|
247
|
+
const growSize = (height - row.height) / totalGrow, {children: children} = box;
|
|
248
|
+
if (growSize <= 0) return;
|
|
250
249
|
row.height = height;
|
|
251
250
|
for (let j = 0, end = row.count; j < end; j++) {
|
|
252
251
|
child = children[reverse ? start - j : start + j];
|
|
@@ -256,19 +255,17 @@ function growY(box, row, height, reverse) {
|
|
|
256
255
|
if (remainSpace) {
|
|
257
256
|
remainTotalSpace += remainSpace;
|
|
258
257
|
totalGrow -= grow;
|
|
259
|
-
}
|
|
260
|
-
else if (list) {
|
|
258
|
+
} else if (list) {
|
|
261
259
|
child.__.heightRange ? list.unshift(child) : list.push(child);
|
|
262
260
|
}
|
|
263
261
|
}
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
262
|
+
} else {
|
|
266
263
|
end++;
|
|
267
264
|
}
|
|
268
265
|
}
|
|
269
|
-
if (remainTotalSpace)
|
|
270
|
-
assignRemainSpace(list, remainTotalSpace, totalGrow);
|
|
266
|
+
if (remainTotalSpace) assignRemainSpace(list, remainTotalSpace, totalGrow);
|
|
271
267
|
}
|
|
268
|
+
|
|
272
269
|
function assignRemainSpace(list, totalSpace, countGrow) {
|
|
273
270
|
let grow, space, local, remain;
|
|
274
271
|
list.forEach(child => {
|
|
@@ -279,8 +276,9 @@ function assignRemainSpace(list, totalSpace, countGrow) {
|
|
|
279
276
|
countGrow -= grow;
|
|
280
277
|
});
|
|
281
278
|
}
|
|
279
|
+
|
|
282
280
|
function resizeHeight(child, local, size) {
|
|
283
|
-
const { heightRange, lockRatio } = child.__;
|
|
281
|
+
const {heightRange: heightRange, lockRatio: lockRatio} = child.__;
|
|
284
282
|
const realSize = heightRange ? within(size, heightRange) : size;
|
|
285
283
|
const scale = realSize / local.height;
|
|
286
284
|
child.scaleResize(lockRatio ? scale : 1, scale);
|
|
@@ -288,67 +286,52 @@ function resizeHeight(child, local, size) {
|
|
|
288
286
|
return size - realSize;
|
|
289
287
|
}
|
|
290
288
|
|
|
291
|
-
const {
|
|
289
|
+
const {move: move$2} = draw.PointHelper;
|
|
290
|
+
|
|
292
291
|
function flowX(box, reverse) {
|
|
293
|
-
const side =
|
|
294
|
-
const { complex, wrap, xGap, yGap, isAutoXGap, isFitXGap } = pData;
|
|
295
|
-
if (!children.length)
|
|
296
|
-
return;
|
|
292
|
+
const side = "width", {children: children, itemBox: itemBox} = box, pData = getParseData(box, true);
|
|
293
|
+
const {complex: complex, wrap: wrap, xGap: xGap, yGap: yGap, isAutoXGap: isAutoXGap, isFitXGap: isFitXGap} = pData;
|
|
294
|
+
if (!children.length) return;
|
|
297
295
|
const wrapData = wrap && getWrapDrawData(), xGapTempNum = isAutoXGap ? 0 : xGap;
|
|
298
|
-
let child, local, localWidth, index, data, { x, y, width, height } = box.__layout.contentBounds;
|
|
296
|
+
let child, local, localWidth, index, data, {x: x, y: y, width: width, height: height} = box.__layout.contentBounds;
|
|
299
297
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
300
298
|
child = children[index = reverse ? len - 1 - i : i];
|
|
301
299
|
if (child.__.inFlow && child.__.visible !== 0) {
|
|
302
300
|
local = getItemBounds(child, itemBox);
|
|
303
301
|
if (complex) {
|
|
304
302
|
child.__flowBounds = local;
|
|
305
|
-
if (!data)
|
|
306
|
-
data = getDrawData(index, xGapTempNum);
|
|
303
|
+
if (!data) data = getDrawData(index, xGapTempNum);
|
|
307
304
|
if (wrap && data.count && data.width + local.width > width) {
|
|
308
|
-
if (data.grow)
|
|
309
|
-
growX(box, data, width, reverse);
|
|
310
|
-
else if (isAutoXGap)
|
|
311
|
-
autoGap(data, side, width, isFitXGap);
|
|
305
|
+
if (data.grow) growX(box, data, width, reverse); else if (isAutoXGap) autoGap(data, side, width, isFitXGap);
|
|
312
306
|
flowWrap(wrapData, data, side);
|
|
313
307
|
data = getDrawData(index, xGapTempNum);
|
|
314
308
|
}
|
|
315
309
|
localWidth = local.width;
|
|
316
310
|
if (child.__widthGrow) {
|
|
317
311
|
data.grow += child.__widthGrow, localWidth = 0;
|
|
318
|
-
if (child.__.widthRange)
|
|
319
|
-
data.hasRangeSize = true;
|
|
312
|
+
if (child.__.widthRange) data.hasRangeSize = true;
|
|
320
313
|
}
|
|
321
|
-
if (child.__heightGrow)
|
|
322
|
-
resizeHeight(child, local, height);
|
|
314
|
+
if (child.__heightGrow) resizeHeight(child, local, height);
|
|
323
315
|
data.width += data.count ? localWidth + xGapTempNum : localWidth;
|
|
324
316
|
data.height = Math.max(data.height, local.height);
|
|
325
317
|
data.count++;
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
318
|
+
} else {
|
|
328
319
|
move$2(child, x - local.x, y - local.y);
|
|
329
320
|
x += local.width + xGapTempNum;
|
|
330
321
|
}
|
|
331
322
|
}
|
|
332
323
|
}
|
|
333
324
|
if (complex && data) {
|
|
334
|
-
const { isAutoYGap, isFitYGap, contentAlign, rowXAlign, rowYAlign } = pData;
|
|
325
|
+
const {isAutoYGap: isAutoYGap, isFitYGap: isFitYGap, contentAlign: contentAlign, rowXAlign: rowXAlign, rowYAlign: rowYAlign} = pData;
|
|
335
326
|
if (data.count) {
|
|
336
|
-
if (data.grow)
|
|
337
|
-
|
|
338
|
-
else if (isAutoXGap)
|
|
339
|
-
autoGap(data, side, width, isFitXGap);
|
|
340
|
-
if (wrap)
|
|
341
|
-
flowWrap(wrapData, data, side);
|
|
327
|
+
if (data.grow) growX(box, data, width, reverse); else if (isAutoXGap) autoGap(data, side, width, isFitXGap);
|
|
328
|
+
if (wrap) flowWrap(wrapData, data, side);
|
|
342
329
|
}
|
|
343
330
|
if (wrap) {
|
|
344
|
-
if (isAutoYGap)
|
|
345
|
-
autoGap(wrapData, 'height', height, isFitYGap);
|
|
346
|
-
else
|
|
347
|
-
wrapData.height += (wrapData.gap = yGap) * (wrapData.list.length - 1);
|
|
331
|
+
if (isAutoYGap) autoGap(wrapData, "height", height, isFitYGap); else wrapData.height += (wrapData.gap = yGap) * (wrapData.list.length - 1);
|
|
348
332
|
align$1(box, wrapData, contentAlign, rowXAlign);
|
|
349
333
|
layout$1(box, wrapData, rowYAlign, reverse);
|
|
350
|
-
}
|
|
351
|
-
else {
|
|
334
|
+
} else {
|
|
352
335
|
alignContent(box, data, contentAlign);
|
|
353
336
|
layoutX(box, data, 0, data.y, rowYAlign, reverse);
|
|
354
337
|
}
|
|
@@ -357,112 +340,97 @@ function flowX(box, reverse) {
|
|
|
357
340
|
|
|
358
341
|
function align(box, data, contentAlign, rowYAlign) {
|
|
359
342
|
alignContent(box, data, contentAlign);
|
|
360
|
-
const { list
|
|
343
|
+
const {list: list} = data;
|
|
361
344
|
if (list.length > 1) {
|
|
362
|
-
if (!rowYAlign)
|
|
363
|
-
|
|
364
|
-
if (rowYAlign !== 'from') {
|
|
345
|
+
if (!rowYAlign) rowYAlign = alignToInnerYMap[contentAlign];
|
|
346
|
+
if (rowYAlign !== "from") {
|
|
365
347
|
let row;
|
|
366
348
|
for (let i = 0, len = list.length; i < len; i++) {
|
|
367
349
|
row = list[i];
|
|
368
350
|
row.y = data.height - row.height;
|
|
369
|
-
if (rowYAlign ===
|
|
370
|
-
row.y /= 2;
|
|
351
|
+
if (rowYAlign === "center") row.y /= 2;
|
|
371
352
|
}
|
|
372
353
|
}
|
|
373
354
|
}
|
|
374
355
|
}
|
|
375
356
|
|
|
376
|
-
const {
|
|
357
|
+
const {move: move$1} = draw.PointHelper;
|
|
358
|
+
|
|
377
359
|
function layout(box, data, rowXAlign, reverse) {
|
|
378
|
-
const { list
|
|
379
|
-
let row, { x, y } = data;
|
|
360
|
+
const {list: list} = data, reverseWrap = box.__.flowWrap === "reverse";
|
|
361
|
+
let row, {x: x, y: y} = data;
|
|
380
362
|
for (let i = 0, len = list.length; i < len; i++) {
|
|
381
363
|
row = list[reverseWrap ? len - 1 - i : i];
|
|
382
364
|
layoutY(box, row, x, y, rowXAlign, reverse);
|
|
383
365
|
x += row.width + data.gap;
|
|
384
366
|
}
|
|
385
367
|
}
|
|
368
|
+
|
|
386
369
|
function layoutY(box, row, fromX, fromY, rowXAlign, reverse) {
|
|
387
|
-
const { children
|
|
388
|
-
let child, local, { y, start } = row, x = fromX;
|
|
370
|
+
const {children: children} = box;
|
|
371
|
+
let child, local, {y: y, start: start} = row, x = fromX;
|
|
389
372
|
y += fromY;
|
|
390
373
|
for (let j = 0, end = row.count; j < end; j++) {
|
|
391
374
|
child = children[reverse ? start - j : start + j];
|
|
392
375
|
if (child.__.inFlow && child.__.visible !== 0) {
|
|
393
376
|
local = child.__flowBounds;
|
|
394
|
-
if (rowXAlign !==
|
|
395
|
-
x = fromX + (row.width - local.width) / (rowXAlign === 'center' ? 2 : 1);
|
|
377
|
+
if (rowXAlign !== "from") x = fromX + (row.width - local.width) / (rowXAlign === "center" ? 2 : 1);
|
|
396
378
|
move$1(child, x - local.x, y - local.y);
|
|
397
379
|
y += local.height + row.gap;
|
|
398
|
-
}
|
|
399
|
-
else {
|
|
380
|
+
} else {
|
|
400
381
|
end++;
|
|
401
382
|
}
|
|
402
383
|
}
|
|
403
384
|
}
|
|
404
385
|
|
|
405
|
-
const { move
|
|
386
|
+
const {move: move} = draw.PointHelper;
|
|
387
|
+
|
|
406
388
|
function flowY(box, reverse) {
|
|
407
|
-
const side =
|
|
408
|
-
const { complex, wrap, xGap, yGap, isAutoYGap, isFitYGap } = pData;
|
|
409
|
-
if (!children.length)
|
|
410
|
-
return;
|
|
389
|
+
const side = "height", {children: children, itemBox: itemBox} = box, pData = getParseData(box, false);
|
|
390
|
+
const {complex: complex, wrap: wrap, xGap: xGap, yGap: yGap, isAutoYGap: isAutoYGap, isFitYGap: isFitYGap} = pData;
|
|
391
|
+
if (!children.length) return;
|
|
411
392
|
const wrapData = wrap && getWrapDrawData(), yGapTempNum = isAutoYGap ? 0 : yGap;
|
|
412
|
-
let child, local, localHeight, index, data, { x, y, width, height } = box.__layout.contentBounds;
|
|
393
|
+
let child, local, localHeight, index, data, {x: x, y: y, width: width, height: height} = box.__layout.contentBounds;
|
|
413
394
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
414
395
|
child = children[index = reverse ? len - 1 - i : i];
|
|
415
396
|
if (child.__.inFlow && child.__.visible !== 0) {
|
|
416
397
|
local = getItemBounds(child, itemBox);
|
|
417
398
|
if (complex) {
|
|
418
399
|
child.__flowBounds = local;
|
|
419
|
-
if (!data)
|
|
420
|
-
data = getDrawData(index, yGapTempNum);
|
|
400
|
+
if (!data) data = getDrawData(index, yGapTempNum);
|
|
421
401
|
if (wrap && data.count && data.height + local.height > height) {
|
|
422
|
-
if (data.grow)
|
|
423
|
-
|
|
424
|
-
if (isAutoYGap)
|
|
425
|
-
autoGap(data, side, height, isFitYGap);
|
|
402
|
+
if (data.grow) growY(box, data, height, reverse);
|
|
403
|
+
if (isAutoYGap) autoGap(data, side, height, isFitYGap);
|
|
426
404
|
flowWrap(wrapData, data, side);
|
|
427
405
|
data = getDrawData(index, yGapTempNum);
|
|
428
406
|
}
|
|
429
407
|
localHeight = local.height;
|
|
430
408
|
if (child.__heightGrow) {
|
|
431
409
|
data.grow += child.__heightGrow, localHeight = 0;
|
|
432
|
-
if (child.__.heightRange)
|
|
433
|
-
data.hasRangeSize = true;
|
|
410
|
+
if (child.__.heightRange) data.hasRangeSize = true;
|
|
434
411
|
}
|
|
435
|
-
if (child.__widthGrow)
|
|
436
|
-
resizeWidth(child, local, width);
|
|
412
|
+
if (child.__widthGrow) resizeWidth(child, local, width);
|
|
437
413
|
data.height += data.count ? localHeight + yGapTempNum : localHeight;
|
|
438
414
|
data.width = Math.max(data.width, local.width);
|
|
439
415
|
data.count++;
|
|
440
|
-
}
|
|
441
|
-
else {
|
|
416
|
+
} else {
|
|
442
417
|
move(child, x - local.x, y - local.y);
|
|
443
418
|
y += local.height + yGapTempNum;
|
|
444
419
|
}
|
|
445
420
|
}
|
|
446
421
|
}
|
|
447
422
|
if (complex && data) {
|
|
448
|
-
const { isAutoXGap, isFitXGap, contentAlign, rowXAlign, rowYAlign } = pData;
|
|
423
|
+
const {isAutoXGap: isAutoXGap, isFitXGap: isFitXGap, contentAlign: contentAlign, rowXAlign: rowXAlign, rowYAlign: rowYAlign} = pData;
|
|
449
424
|
if (data.count) {
|
|
450
|
-
if (data.grow)
|
|
451
|
-
|
|
452
|
-
if (
|
|
453
|
-
autoGap(data, side, height, isFitYGap);
|
|
454
|
-
if (wrap)
|
|
455
|
-
flowWrap(wrapData, data, side);
|
|
425
|
+
if (data.grow) growY(box, data, height, reverse);
|
|
426
|
+
if (isAutoYGap) autoGap(data, side, height, isFitYGap);
|
|
427
|
+
if (wrap) flowWrap(wrapData, data, side);
|
|
456
428
|
}
|
|
457
429
|
if (wrap) {
|
|
458
|
-
if (isAutoXGap)
|
|
459
|
-
autoGap(wrapData, 'width', width, isFitXGap);
|
|
460
|
-
else
|
|
461
|
-
wrapData.width += (wrapData.gap = xGap) * (wrapData.list.length - 1);
|
|
430
|
+
if (isAutoXGap) autoGap(wrapData, "width", width, isFitXGap); else wrapData.width += (wrapData.gap = xGap) * (wrapData.list.length - 1);
|
|
462
431
|
align(box, wrapData, contentAlign, rowYAlign);
|
|
463
432
|
layout(box, wrapData, rowXAlign, reverse);
|
|
464
|
-
}
|
|
465
|
-
else {
|
|
433
|
+
} else {
|
|
466
434
|
alignContent(box, data, contentAlign);
|
|
467
435
|
layoutY(box, data, data.x, 0, rowXAlign, reverse);
|
|
468
436
|
}
|
|
@@ -470,96 +438,101 @@ function flowY(box, reverse) {
|
|
|
470
438
|
}
|
|
471
439
|
|
|
472
440
|
function autoBoundsType(defaultValue) {
|
|
473
|
-
return draw.decorateLeafAttr(defaultValue,
|
|
441
|
+
return draw.decorateLeafAttr(defaultValue, key => draw.attr({
|
|
474
442
|
set(value) {
|
|
475
|
-
const grow =
|
|
476
|
-
key ===
|
|
477
|
-
if (grow && !(this.parent && this.parent.__hasGrow))
|
|
478
|
-
this.
|
|
443
|
+
const grow = draw.isNumber(value) ? value : 0;
|
|
444
|
+
key === "autoWidth" ? this.__widthGrow = grow : this.__heightGrow = grow;
|
|
445
|
+
if (grow && !(this.parent && this.parent.__hasGrow)) this.waitParent(() => {
|
|
446
|
+
this.parent.__hasGrow = true;
|
|
447
|
+
});
|
|
479
448
|
this.__setAttr(key, value) && draw.doBoundsType(this);
|
|
480
449
|
}
|
|
481
450
|
}));
|
|
482
451
|
}
|
|
483
452
|
|
|
484
|
-
draw.Plugin.add(
|
|
485
|
-
|
|
486
|
-
draw.
|
|
487
|
-
|
|
488
|
-
draw.UI.addAttr(
|
|
489
|
-
|
|
490
|
-
draw.UI.addAttr(
|
|
491
|
-
|
|
492
|
-
draw.UI.addAttr(
|
|
493
|
-
|
|
494
|
-
draw.UI.addAttr(
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
453
|
+
draw.Plugin.add("flow", "resize");
|
|
454
|
+
|
|
455
|
+
const box = draw.Box.prototype, {__updateBoxBounds: __updateBoxBounds} = draw.Group.prototype;
|
|
456
|
+
|
|
457
|
+
draw.UI.addAttr("flow", false, draw.autoLayoutType);
|
|
458
|
+
|
|
459
|
+
draw.UI.addAttr("gap", 0, draw.boundsType);
|
|
460
|
+
|
|
461
|
+
draw.UI.addAttr("flowAlign", "top-left", draw.boundsType);
|
|
462
|
+
|
|
463
|
+
draw.UI.addAttr("flowWrap", false, draw.boundsType);
|
|
464
|
+
|
|
465
|
+
draw.UI.addAttr("itemBox", "box", draw.boundsType);
|
|
466
|
+
|
|
467
|
+
draw.UI.addAttr("inFlow", true, draw.boundsType);
|
|
468
|
+
|
|
469
|
+
draw.UI.addAttr("autoWidth", undefined, autoBoundsType);
|
|
470
|
+
|
|
471
|
+
draw.UI.addAttr("autoHeight", undefined, autoBoundsType);
|
|
472
|
+
|
|
473
|
+
draw.UI.addAttr("autoBox", undefined, draw.boundsType);
|
|
474
|
+
|
|
475
|
+
const {copyAndSpread: copyAndSpread} = draw.BoundsHelper;
|
|
476
|
+
|
|
477
|
+
box.__updateFlowLayout = function() {
|
|
478
|
+
const {leaferIsCreated: leaferIsCreated, flow: flow} = this;
|
|
479
|
+
if (leaferIsCreated) this.leafer.created = false;
|
|
500
480
|
switch (flow) {
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
481
|
+
case "x":
|
|
482
|
+
case true:
|
|
483
|
+
flowX(this);
|
|
484
|
+
break;
|
|
485
|
+
|
|
486
|
+
case "y":
|
|
487
|
+
flowY(this);
|
|
488
|
+
break;
|
|
489
|
+
|
|
490
|
+
case "x-reverse":
|
|
491
|
+
flowX(this, true);
|
|
492
|
+
break;
|
|
493
|
+
|
|
494
|
+
case "y-reverse":
|
|
495
|
+
flowY(this, true);
|
|
496
|
+
break;
|
|
514
497
|
}
|
|
515
|
-
if (leaferIsCreated)
|
|
516
|
-
this.leafer.created = true;
|
|
498
|
+
if (leaferIsCreated) this.leafer.created = true;
|
|
517
499
|
};
|
|
518
|
-
|
|
519
|
-
|
|
500
|
+
|
|
501
|
+
box.__updateContentBounds = function() {
|
|
502
|
+
const {padding: padding} = this.__;
|
|
520
503
|
const layout = this.__layout;
|
|
521
504
|
const same = layout.contentBounds === layout.boxBounds;
|
|
522
505
|
if (padding) {
|
|
523
|
-
if (same)
|
|
524
|
-
layout.shrinkContent();
|
|
506
|
+
if (same) layout.shrinkContent();
|
|
525
507
|
copyAndSpread(layout.contentBounds, layout.boxBounds, padding, true);
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
if (!same)
|
|
529
|
-
layout.shrinkContentCancel();
|
|
508
|
+
} else {
|
|
509
|
+
if (!same) layout.shrinkContentCancel();
|
|
530
510
|
}
|
|
531
511
|
};
|
|
532
|
-
|
|
533
|
-
|
|
512
|
+
|
|
513
|
+
box.__updateBoxBounds = function(secondLayout) {
|
|
534
514
|
if (this.children.length && !this.pathInputed) {
|
|
535
|
-
const { flow
|
|
515
|
+
const data = this.__, {flow: flow} = data;
|
|
536
516
|
if (data.__autoSide) {
|
|
537
|
-
if (data.__hasSurface)
|
|
538
|
-
this.__extraUpdate();
|
|
517
|
+
if (data.__hasSurface) this.__extraUpdate();
|
|
539
518
|
flow && !secondLayout ? this.__updateRectBoxBounds() : __updateBoxBounds.call(this);
|
|
540
|
-
const { boxBounds
|
|
519
|
+
const {boxBounds: boxBounds} = this.__layout;
|
|
541
520
|
if (!data.__autoSize) {
|
|
542
521
|
if (data.__autoWidth) {
|
|
543
|
-
if (!flow)
|
|
544
|
-
boxBounds.width += boxBounds.x, boxBounds.x = 0;
|
|
522
|
+
if (!flow) boxBounds.width += boxBounds.x, boxBounds.x = 0;
|
|
545
523
|
boxBounds.height = data.height, boxBounds.y = 0;
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
if (!flow)
|
|
549
|
-
boxBounds.height += boxBounds.y, boxBounds.y = 0;
|
|
524
|
+
} else {
|
|
525
|
+
if (!flow) boxBounds.height += boxBounds.y, boxBounds.y = 0;
|
|
550
526
|
boxBounds.width = data.width, boxBounds.x = 0;
|
|
551
527
|
}
|
|
552
528
|
}
|
|
553
|
-
flow && secondLayout && data.padding && copyAndSpread(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null :
|
|
529
|
+
flow && secondLayout && data.padding && copyAndSpread(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : data.__autoWidth ? "width" : "height");
|
|
554
530
|
this.__updateNaturalSize();
|
|
555
|
-
}
|
|
556
|
-
else {
|
|
531
|
+
} else {
|
|
557
532
|
this.__updateRectBoxBounds();
|
|
558
533
|
}
|
|
559
|
-
if (flow)
|
|
560
|
-
|
|
561
|
-
}
|
|
562
|
-
else {
|
|
534
|
+
if (flow) this.__updateContentBounds();
|
|
535
|
+
} else {
|
|
563
536
|
this.__updateRectBoxBounds();
|
|
564
537
|
}
|
|
565
538
|
};
|