@leafer-in/flow 1.0.0 → 1.0.1

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