@leafer-in/flow 1.0.0 → 1.0.2

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