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