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