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