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