@leafer-in/flow 1.1.0 → 1.1.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,218 +1,7 @@
1
1
  'use strict';
2
2
 
3
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
- case L:
17
- scalePoints(data, scaleX, scaleY, i, 1);
18
- i += 3;
19
- break;
20
- case C:
21
- scalePoints(data, scaleX, scaleY, i, 3);
22
- i += 7;
23
- break;
24
- case Q:
25
- scalePoints(data, scaleX, scaleY, i, 2);
26
- i += 5;
27
- break;
28
- case Z:
29
- i += 1;
30
- break;
31
- case N:
32
- scalePoints(data, scaleX, scaleY, i, 2);
33
- i += 5;
34
- break;
35
- case D:
36
- scalePoints(data, scaleX, scaleY, i, 2);
37
- i += 9;
38
- break;
39
- case X:
40
- scalePoints(data, scaleX, scaleY, i, 2);
41
- i += 6;
42
- break;
43
- case G:
44
- scalePoints(data, scaleX, scaleY, i, 2);
45
- i += 9;
46
- break;
47
- case F:
48
- scalePoints(data, scaleX, scaleY, i, 2);
49
- i += 5;
50
- break;
51
- case O:
52
- data[i] = G;
53
- data.splice(i + 4, 0, data[i + 3], 0);
54
- scalePoints(data, scaleX, scaleY, i, 2);
55
- i += 7 + 2;
56
- len += 2;
57
- break;
58
- case P:
59
- data[i] = F;
60
- data.splice(i + 4, 0, data[i + 3]);
61
- scalePoints(data, scaleX, scaleY, i, 2);
62
- i += 4 + 1;
63
- len += 1;
64
- break;
65
- case U:
66
- scalePoints(data, scaleX, scaleY, i, 2);
67
- i += 6;
68
- break;
69
- }
70
- }
71
- },
72
- scalePoints(data, scaleX, scaleY, start, pointCount) {
73
- for (let i = pointCount ? start + 1 : 0, end = pointCount ? i + pointCount * 2 : data.length; i < end; i += 2) {
74
- data[i] *= scaleX;
75
- data[i + 1] *= scaleY;
76
- }
77
- }
78
- };
79
- const { scalePoints } = PathScaler;
80
-
81
- const matrix = draw.MatrixHelper.get();
82
- const { topLeft, top, topRight, right, bottom, left } = draw.Direction9;
83
- function scaleResize(leaf, scaleX, scaleY) {
84
- if (leaf.pathInputed) {
85
- scaleResizePath(leaf, scaleX, scaleY);
86
- }
87
- else {
88
- if (scaleX !== 1)
89
- leaf.width *= scaleX;
90
- if (scaleY !== 1)
91
- leaf.height *= scaleY;
92
- }
93
- }
94
- function scaleResizeFontSize(leaf, scaleX, scaleY) {
95
- const { app } = leaf;
96
- const editor = app && app.editor;
97
- let fontScale = scaleX;
98
- if (editor.editing) {
99
- const layout = leaf.__layout;
100
- let { width, height } = layout.boxBounds;
101
- width *= scaleY - scaleX;
102
- height *= scaleX - scaleY;
103
- switch (editor.resizeDirection) {
104
- case top:
105
- case bottom:
106
- fontScale = scaleY;
107
- layout.affectScaleOrRotation ? leaf.moveInner(-width / 2, 0) : leaf.x -= width / 2;
108
- break;
109
- case left:
110
- case right:
111
- layout.affectScaleOrRotation ? leaf.moveInner(0, -height / 2) : leaf.y -= height / 2;
112
- break;
113
- case topLeft:
114
- case topRight:
115
- layout.affectScaleOrRotation ? leaf.moveInner(0, -height) : leaf.y -= height;
116
- break;
117
- }
118
- }
119
- leaf.fontSize *= fontScale;
120
- const data = leaf.__;
121
- if (!data.__autoWidth)
122
- leaf.width *= fontScale;
123
- if (!data.__autoHeight)
124
- leaf.height *= fontScale;
125
- }
126
- function scaleResizePath(leaf, scaleX, scaleY) {
127
- PathScaler.scale(leaf.__.path, scaleX, scaleY);
128
- leaf.path = leaf.__.path;
129
- }
130
- function scaleResizePoints(leaf, scaleX, scaleY) {
131
- const { points } = leaf;
132
- typeof points[0] === 'object' ? points.forEach(p => { p.x *= scaleX, p.y *= scaleY; }) : PathScaler.scalePoints(points, scaleX, scaleY);
133
- leaf.points = 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 = draw.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
- draw.Text.prototype.__scaleResize = function (scaleX, scaleY) {
171
- if (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
- draw.Path.prototype.__scaleResize = function (scaleX, scaleY) {
179
- scaleResizePath(this, scaleX, scaleY);
180
- };
181
- draw.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
- draw.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
- draw.Group.prototype.__scaleResize = function (scaleX, scaleY) {
204
- scaleResizeGroup(this, scaleX, scaleY);
205
- };
206
- draw.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
- };
4
+ require('@leafer-in/resize');
216
5
 
217
6
  /******************************************************************************
218
7
  Copyright (c) Microsoft Corporation.
@@ -539,7 +328,7 @@ function flowX(box, reverse) {
539
328
  }
540
329
  }
541
330
  }
542
- if (complex) {
331
+ if (complex && data) {
543
332
  const { isAutoYGap, isFitYGap, contentAlign, rowXAlign, rowYAlign } = pData;
544
333
  if (data.count) {
545
334
  if (data.grow)
@@ -653,7 +442,7 @@ function flowY(box, reverse) {
653
442
  }
654
443
  }
655
444
  }
656
- if (complex) {
445
+ if (complex && data) {
657
446
  const { isAutoXGap, isFitXGap, contentAlign, rowXAlign, rowYAlign } = pData;
658
447
  if (data.count) {
659
448
  if (data.grow)
@@ -769,10 +558,3 @@ box.__updateBoxBounds = function (secondLayout) {
769
558
  this.__updateRectBoxBounds();
770
559
  }
771
560
  };
772
-
773
- exports.PathScaler = PathScaler;
774
- exports.scaleResize = scaleResize;
775
- exports.scaleResizeFontSize = scaleResizeFontSize;
776
- exports.scaleResizeGroup = scaleResizeGroup;
777
- exports.scaleResizePath = scaleResizePath;
778
- exports.scaleResizePoints = scaleResizePoints;
package/dist/flow.esm.js CHANGED
@@ -1,216 +1,5 @@
1
- import { PathCommandMap, MatrixHelper, Direction9, Leaf, Text, Path, Line, Polygon, Group, Box, BoxData, dataProcessor, autoLayoutType, registerUI, AlignHelper, PointHelper, MathHelper, decorateLeafAttr, attr, doBoundsType, UI, boundsType, 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
- case L:
15
- scalePoints(data, scaleX, scaleY, i, 1);
16
- i += 3;
17
- break;
18
- case C:
19
- scalePoints(data, scaleX, scaleY, i, 3);
20
- i += 7;
21
- break;
22
- case Q:
23
- scalePoints(data, scaleX, scaleY, i, 2);
24
- i += 5;
25
- break;
26
- case Z:
27
- i += 1;
28
- break;
29
- case N:
30
- scalePoints(data, scaleX, scaleY, i, 2);
31
- i += 5;
32
- break;
33
- case D:
34
- scalePoints(data, scaleX, scaleY, i, 2);
35
- i += 9;
36
- break;
37
- case X:
38
- scalePoints(data, scaleX, scaleY, i, 2);
39
- i += 6;
40
- break;
41
- case G:
42
- scalePoints(data, scaleX, scaleY, i, 2);
43
- i += 9;
44
- break;
45
- case F:
46
- scalePoints(data, scaleX, scaleY, i, 2);
47
- i += 5;
48
- break;
49
- case O:
50
- data[i] = G;
51
- data.splice(i + 4, 0, data[i + 3], 0);
52
- scalePoints(data, scaleX, scaleY, i, 2);
53
- i += 7 + 2;
54
- len += 2;
55
- break;
56
- case P:
57
- data[i] = F;
58
- data.splice(i + 4, 0, data[i + 3]);
59
- scalePoints(data, scaleX, scaleY, i, 2);
60
- i += 4 + 1;
61
- len += 1;
62
- break;
63
- case U:
64
- scalePoints(data, scaleX, scaleY, i, 2);
65
- i += 6;
66
- break;
67
- }
68
- }
69
- },
70
- scalePoints(data, scaleX, scaleY, start, pointCount) {
71
- for (let i = pointCount ? start + 1 : 0, end = pointCount ? i + pointCount * 2 : data.length; i < end; i += 2) {
72
- data[i] *= scaleX;
73
- data[i + 1] *= scaleY;
74
- }
75
- }
76
- };
77
- const { scalePoints } = PathScaler;
78
-
79
- const matrix = MatrixHelper.get();
80
- const { topLeft, top, topRight, right, bottom, left } = Direction9;
81
- function scaleResize(leaf, scaleX, scaleY) {
82
- if (leaf.pathInputed) {
83
- scaleResizePath(leaf, scaleX, scaleY);
84
- }
85
- else {
86
- if (scaleX !== 1)
87
- leaf.width *= scaleX;
88
- if (scaleY !== 1)
89
- leaf.height *= scaleY;
90
- }
91
- }
92
- function scaleResizeFontSize(leaf, scaleX, scaleY) {
93
- const { app } = leaf;
94
- const editor = app && app.editor;
95
- let fontScale = scaleX;
96
- if (editor.editing) {
97
- const layout = leaf.__layout;
98
- let { width, height } = layout.boxBounds;
99
- width *= scaleY - scaleX;
100
- height *= scaleX - scaleY;
101
- switch (editor.resizeDirection) {
102
- case top:
103
- case bottom:
104
- fontScale = scaleY;
105
- layout.affectScaleOrRotation ? leaf.moveInner(-width / 2, 0) : leaf.x -= width / 2;
106
- break;
107
- case left:
108
- case right:
109
- layout.affectScaleOrRotation ? leaf.moveInner(0, -height / 2) : leaf.y -= height / 2;
110
- break;
111
- case topLeft:
112
- case topRight:
113
- layout.affectScaleOrRotation ? leaf.moveInner(0, -height) : leaf.y -= height;
114
- break;
115
- }
116
- }
117
- leaf.fontSize *= fontScale;
118
- const data = leaf.__;
119
- if (!data.__autoWidth)
120
- leaf.width *= fontScale;
121
- if (!data.__autoHeight)
122
- leaf.height *= fontScale;
123
- }
124
- function scaleResizePath(leaf, scaleX, scaleY) {
125
- PathScaler.scale(leaf.__.path, scaleX, scaleY);
126
- leaf.path = leaf.__.path;
127
- }
128
- function scaleResizePoints(leaf, scaleX, scaleY) {
129
- const { points } = leaf;
130
- typeof points[0] === 'object' ? points.forEach(p => { p.x *= scaleX, p.y *= scaleY; }) : PathScaler.scalePoints(points, scaleX, scaleY);
131
- leaf.points = points;
132
- }
133
- function scaleResizeGroup(group, scaleX, scaleY) {
134
- const { children } = group;
135
- for (let i = 0; i < children.length; i++) {
136
- matrix.a = scaleX;
137
- matrix.d = scaleY;
138
- children[i].transform(matrix, true);
139
- }
140
- }
141
-
142
- const leaf = Leaf.prototype;
143
- leaf.scaleResize = function (scaleX, scaleY = scaleX, noResize) {
144
- const data = this;
145
- if (noResize || (data.editConfig && data.editConfig.editSize === 'scale')) {
146
- data.scaleX *= scaleX;
147
- data.scaleY *= scaleY;
148
- }
149
- else {
150
- if (scaleX < 0)
151
- data.scaleX *= -1, scaleX = -scaleX;
152
- if (scaleY < 0)
153
- data.scaleY *= -1, scaleY = -scaleY;
154
- this.__scaleResize(scaleX, scaleY);
155
- }
156
- };
157
- leaf.__scaleResize = function (scaleX, scaleY) {
158
- scaleResize(this, scaleX, scaleY);
159
- };
160
- leaf.resizeWidth = function (width) {
161
- const scale = width / this.getBounds('box', 'local').width;
162
- this.scaleOf(this.__layout.boxBounds, scale, this.__.lockRatio ? scale : 1, true);
163
- };
164
- leaf.resizeHeight = function (height) {
165
- const scale = height / this.getBounds('box', 'local').height;
166
- this.scaleOf(this.__layout.boxBounds, this.__.lockRatio ? scale : 1, scale, true);
167
- };
168
- Text.prototype.__scaleResize = function (scaleX, scaleY) {
169
- if (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size')) {
170
- scaleResizeFontSize(this, scaleX, scaleY);
171
- }
172
- else {
173
- scaleResize(this, scaleX, scaleY);
174
- }
175
- };
176
- Path.prototype.__scaleResize = function (scaleX, scaleY) {
177
- scaleResizePath(this, scaleX, scaleY);
178
- };
179
- Line.prototype.__scaleResize = function (scaleX, scaleY) {
180
- if (this.pathInputed) {
181
- scaleResizePath(this, scaleX, scaleY);
182
- }
183
- else if (this.points) {
184
- scaleResizePoints(this, scaleX, scaleY);
185
- }
186
- else {
187
- this.width *= scaleX;
188
- }
189
- };
190
- Polygon.prototype.__scaleResize = function (scaleX, scaleY) {
191
- if (this.pathInputed) {
192
- scaleResizePath(this, scaleX, scaleY);
193
- }
194
- else if (this.points) {
195
- scaleResizePoints(this, scaleX, scaleY);
196
- }
197
- else {
198
- scaleResize(this, scaleX, scaleY);
199
- }
200
- };
201
- Group.prototype.__scaleResize = function (scaleX, scaleY) {
202
- scaleResizeGroup(this, scaleX, scaleY);
203
- };
204
- Box.prototype.__scaleResize = function (scaleX, scaleY) {
205
- if (this.__.__autoSize && this.children.length) {
206
- scaleResizeGroup(this, scaleX, scaleY);
207
- }
208
- else {
209
- scaleResize(this, scaleX, scaleY);
210
- if (this.__.resizeChildren)
211
- scaleResizeGroup(this, scaleX, scaleY);
212
- }
213
- };
1
+ import { BoxData, dataProcessor, autoLayoutType, registerUI, Box, AlignHelper, PointHelper, MathHelper, decorateLeafAttr, attr, doBoundsType, UI, Group, boundsType, BoundsHelper } from '@leafer-ui/draw';
2
+ import '@leafer-in/resize';
214
3
 
215
4
  /******************************************************************************
216
5
  Copyright (c) Microsoft Corporation.
@@ -537,7 +326,7 @@ function flowX(box, reverse) {
537
326
  }
538
327
  }
539
328
  }
540
- if (complex) {
329
+ if (complex && data) {
541
330
  const { isAutoYGap, isFitYGap, contentAlign, rowXAlign, rowYAlign } = pData;
542
331
  if (data.count) {
543
332
  if (data.grow)
@@ -651,7 +440,7 @@ function flowY(box, reverse) {
651
440
  }
652
441
  }
653
442
  }
654
- if (complex) {
443
+ if (complex && data) {
655
444
  const { isAutoXGap, isFitXGap, contentAlign, rowXAlign, rowYAlign } = pData;
656
445
  if (data.count) {
657
446
  if (data.grow)
@@ -768,4 +557,4 @@ box.__updateBoxBounds = function (secondLayout) {
768
557
  }
769
558
  };
770
559
 
771
- export { Flow, PathScaler, scaleResize, scaleResizeFontSize, scaleResizeGroup, scaleResizePath, scaleResizePoints };
560
+ export { Flow };
@@ -1 +1 @@
1
- import{PathCommandMap as t,MatrixHelper as e,Direction9 as o,Leaf as i,Text as n,Path as s,Line as h,Polygon as c,Group as a,Box as r,BoxData as l,dataProcessor as _,autoLayoutType as u,registerUI as f,AlignHelper as p,PointHelper as g,MathHelper as d,decorateLeafAttr as w,attr as y,doBoundsType as x,UI as b,boundsType as G,BoundsHelper as m}from"@leafer-ui/draw";const{M:B,L:R,C:z,Q:A,Z:k,N:v,D:S,X:F,G:X,F:Y,O:C,P:W,U:O}=t,P={scale(t,e,o){if(!t)return;let i,n=0,s=t.length;for(;n<s;)switch(i=t[n],i){case B:case R:I(t,e,o,n,1),n+=3;break;case z:I(t,e,o,n,3),n+=7;break;case A:I(t,e,o,n,2),n+=5;break;case k:n+=1;break;case v:I(t,e,o,n,2),n+=5;break;case S:I(t,e,o,n,2),n+=9;break;case F:I(t,e,o,n,2),n+=6;break;case X:I(t,e,o,n,2),n+=9;break;case Y:I(t,e,o,n,2),n+=5;break;case C:t[n]=X,t.splice(n+4,0,t[n+3],0),I(t,e,o,n,2),n+=9,s+=2;break;case W:t[n]=Y,t.splice(n+4,0,t[n+3]),I(t,e,o,n,2),n+=5,s+=1;break;case O:I(t,e,o,n,2),n+=6}},scalePoints(t,e,o,i,n){for(let s=n?i+1:0,h=n?s+2*n:t.length;s<h;s+=2)t[s]*=e,t[s+1]*=o}},{scalePoints:I}=P,j=e.get(),{topLeft:E,top:H,topRight:L,right:M,bottom:D,left:N}=o;function Q(t,e,o){t.pathInputed?Z(t,e,o):(1!==e&&(t.width*=e),1!==o&&(t.height*=o))}function U(t,e,o){const{app:i}=t,n=i&&i.editor;let s=e;if(n.editing){const i=t.__layout;let{width:h,height:c}=i.boxBounds;switch(h*=o-e,c*=e-o,n.resizeDirection){case H:case D:s=o,i.affectScaleOrRotation?t.moveInner(-h/2,0):t.x-=h/2;break;case N:case M:i.affectScaleOrRotation?t.moveInner(0,-c/2):t.y-=c/2;break;case E:case L:i.affectScaleOrRotation?t.moveInner(0,-c):t.y-=c}}t.fontSize*=s;const h=t.__;h.__autoWidth||(t.width*=s),h.__autoHeight||(t.height*=s)}function Z(t,e,o){P.scale(t.__.path,e,o),t.path=t.__.path}function q(t,e,o){const{points:i}=t;"object"==typeof i[0]?i.forEach((t=>{t.x*=e,t.y*=o})):P.scalePoints(i,e,o),t.points=i}function J(t,e,o){const{children:i}=t;for(let t=0;t<i.length;t++)j.a=e,j.d=o,i[t].transform(j,!0)}const K=i.prototype;function T(t,e,o,i){var n,s=arguments.length,h=s<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,o):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)h=Reflect.decorate(t,e,o,i);else for(var c=t.length-1;c>=0;c--)(n=t[c])&&(h=(s<3?n(h):s>3?n(e,o,h):n(e,o))||h);return s>3&&h&&Object.defineProperty(e,o,h),h}K.scaleResize=function(t,e=t,o){const i=this;o||i.editConfig&&"scale"===i.editConfig.editSize?(i.scaleX*=t,i.scaleY*=e):(t<0&&(i.scaleX*=-1,t=-t),e<0&&(i.scaleY*=-1,e=-e),this.__scaleResize(t,e))},K.__scaleResize=function(t,e){Q(this,t,e)},K.resizeWidth=function(t){const e=t/this.getBounds("box","local").width;this.scaleOf(this.__layout.boxBounds,e,this.__.lockRatio?e:1,!0)},K.resizeHeight=function(t){const e=t/this.getBounds("box","local").height;this.scaleOf(this.__layout.boxBounds,this.__.lockRatio?e:1,e,!0)},n.prototype.__scaleResize=function(t,e){this.__.resizeFontSize||this.editConfig&&"font-size"===this.editConfig.editSize?U(this,t,e):Q(this,t,e)},s.prototype.__scaleResize=function(t,e){Z(this,t,e)},h.prototype.__scaleResize=function(t,e){this.pathInputed?Z(this,t,e):this.points?q(this,t,e):this.width*=t},c.prototype.__scaleResize=function(t,e){this.pathInputed?Z(this,t,e):this.points?q(this,t,e):Q(this,t,e)},a.prototype.__scaleResize=function(t,e){J(this,t,e)},r.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?J(this,t,e):(Q(this,t,e),this.__.resizeChildren&&J(this,t,e))},"function"==typeof SuppressedError&&SuppressedError;let V=class extends r{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}};T([_(class extends l{})],V.prototype,"__",void 0),T([u("x")],V.prototype,"flow",void 0),V=T([f()],V);const $={},tt={"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"},et={"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 ot(t,e,o){const i=t.__,{contentBounds:n}=t.__layout;p.toPoint(o,e,n,$),e.x=i.__autoWidth?n.x:$.x,e.y=i.__autoHeight?n.y:$.y}const{move:it}=g;function nt(t,e,o,i,n,s){const{children:h}=t;let c,a,{x:r,start:l}=e,_=i;r+=o;for(let t=0,o=e.count;t<o;t++)c=h[s?l-t:l+t],c.__.inFlow&&0!==c.__.visible?(a=c.__flowBounds,"from"!==n&&(_=i+(e.height-a.height)/("center"===n?2:1)),it(c,r-a.x,_-a.y),r+=a.width+e.gap):o++}function st(t,e,o){const i="width"===o?"height":"width";t[o]=Math.max(t[o],e[o]),t[i]+=t.count?e[i]+t.gap:e[i],t.list.push(e),t.count++}const ht={};function ct(t,e){const{gap:o,flowAlign:i,flowWrap:n,__autoWidth:s,__autoHeight:h}=t.__,c=n&&(e?!s:!h);return"object"==typeof o?(ht.xGap=o.x||0,ht.yGap=o.y||0):ht.xGap=ht.yGap=o,ht.isAutoXGap="string"==typeof ht.xGap&&!s,ht.isAutoYGap="string"==typeof ht.yGap&&!h,ht.complex=c||"top-left"!==i||t.__hasGrow||ht.isAutoXGap||ht.isAutoYGap,ht.wrap=c,ht.complex&&(ht.isFitXGap="fit"===ht.xGap&&!s,ht.isFitYGap="fit"===ht.yGap&&!h,"object"==typeof i?(ht.contentAlign=i.content||"top-left",ht.rowXAlign=i.x||"from",ht.rowYAlign=i.y||"from"):(ht.contentAlign=i,ht.rowXAlign=tt[i],ht.rowYAlign=et[i])),ht}function at(t,e){return{x:0,y:0,width:0,height:0,gap:e,start:t,count:0,grow:0}}function rt(t,e,o,i){const{count:n}=t;n>1&&(o>t[e]||i)&&(t.gap=(o-t[e])/(n-1),t[e]=o)}function lt(t,e){return"box"===e?t.__local:t.__layout.localStrokeBounds}const{within:_t}=d;function ut(t,e,o,i){let n,s,h,c=0,a=e.hasRangeSize&&[],{grow:r,start:l}=e;const _=e.width<o?(o-e.width)/r:0,{children:u}=t;_&&(e.width=o);for(let t=0,o=e.count;t<o;t++)n=u[i?l-t:l+t],n.__.inFlow&&0!==n.__.visible?(s=n.__widthGrow)&&(h=ft(n,n.__flowBounds,_*s),h?(c+=h,r-=s):a&&(n.__.widthRange?a.unshift(n):a.push(n))):o++;c&&function(t,e,o){let i,n,s,h;t.forEach((t=>{i=t.__widthGrow,n=e/o*i,h=ft(t,s=t.__flowBounds,s.width+n),e-=n-h,o-=i}))}(a,c,r)}function ft(t,e,o){const{widthRange:i,lockRatio:n}=t.__,s=i?_t(o,i):o,h=s/e.width;return t.scaleResize(h,n?h:1),e.width=s,o-s}const{within:pt}=d;function gt(t,e,o,i){let n,s,h,c=0,a=e.hasRangeSize&&[],{grow:r,start:l}=e;const _=e.height<o?(o-e.height)/r:0,{children:u}=t;_&&(e.height=o);for(let t=0,o=e.count;t<o;t++)n=u[i?l-t:l+t],n.__.inFlow&&0!==n.__.visible?(s=n.__heightGrow)&&(h=dt(n,n.__flowBounds,_*s),h?(c+=h,r-=s):a&&(n.__.heightRange?a.unshift(n):a.push(n))):o++;c&&function(t,e,o){let i,n,s,h;t.forEach((t=>{i=t.__heightGrow,n=e/o*i,h=dt(t,s=t.__flowBounds,s.height+n),e-=n-h,o-=i}))}(a,c,r)}function dt(t,e,o){const{heightRange:i,lockRatio:n}=t.__,s=i?pt(o,i):o,h=s/e.height;return t.scaleResize(n?h:1,h),e.height=s,o-s}const{move:wt}=g;function yt(t,e){const o="width",{children:i,itemBox:n}=t,s=ct(t,!0),{complex:h,wrap:c,xGap:a,yGap:r,isAutoXGap:l,isFitXGap:_}=s;if(!i.length)return;const u=c&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},f=l?0:a;let p,g,d,w,y,{x:x,y:b,width:G,height:m}=t.__layout.contentBounds;for(let s=0,a=i.length;s<a;s++)p=i[w=e?a-1-s:s],p.__.inFlow&&0!==p.__.visible&&(g=lt(p,n),h?(p.__flowBounds=g,y||(y=at(w,f)),c&&y.count&&y.width+g.width>G&&(y.grow?ut(t,y,G,e):l&&rt(y,o,G,_),st(u,y,o),y=at(w,f)),d=g.width,p.__widthGrow&&(y.grow+=p.__widthGrow,d=0,p.__.widthRange&&(y.hasRangeSize=!0)),p.__heightGrow&&dt(p,g,m),y.width+=y.count?d+f:d,y.height=Math.max(y.height,g.height),y.count++):(wt(p,x-g.x,b-g.y),x+=g.width+f));if(h){const{isAutoYGap:i,isFitYGap:n,contentAlign:h,rowXAlign:a,rowYAlign:f}=s;y.count&&(y.grow?ut(t,y,G,e):l&&rt(y,o,G,_),c&&st(u,y,o)),c?(i?rt(u,"height",m,n):u.gap=r,function(t,e,o,i){ot(t,e,o);const{list:n}=e;if(n.length>1&&(i||(i=tt[o]),"from"!==i)){let t;for(let o=0,s=n.length;o<s;o++)t=n[o],t.x=e.width-t.width,"center"===i&&(t.x/=2)}}(t,u,h,a),function(t,e,o,i){const{list:n}=e,s="reverse"===t.__.flowWrap;let h,{x:c,y:a}=e;for(let r=0,l=n.length;r<l;r++)h=n[s?l-1-r:r],nt(t,h,c,a,o,i),a+=h.height+e.gap}(t,u,f,e)):(ot(t,y,h),nt(t,y,0,y.y,f,e))}}const{move:xt}=g;function bt(t,e,o,i,n,s){const{children:h}=t;let c,a,{y:r,start:l}=e,_=o;r+=i;for(let t=0,i=e.count;t<i;t++)c=h[s?l-t:l+t],c.__.inFlow&&0!==c.__.visible?(a=c.__flowBounds,"from"!==n&&(_=o+(e.width-a.width)/("center"===n?2:1)),xt(c,_-a.x,r-a.y),r+=a.height+e.gap):i++}const{move:Gt}=g;function mt(t,e){const o="height",{children:i,itemBox:n}=t,s=ct(t,!1),{complex:h,wrap:c,xGap:a,yGap:r,isAutoYGap:l,isFitYGap:_}=s;if(!i.length)return;const u=c&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},f=l?0:r;let p,g,d,w,y,{x:x,y:b,width:G,height:m}=t.__layout.contentBounds;for(let s=0,a=i.length;s<a;s++)p=i[w=e?a-1-s:s],p.__.inFlow&&0!==p.__.visible&&(g=lt(p,n),h?(p.__flowBounds=g,y||(y=at(w,f)),c&&y.count&&y.height+g.height>m&&(y.grow&&gt(t,y,m,e),l&&rt(y,o,m,_),st(u,y,o),y=at(w,f)),d=g.height,p.__heightGrow&&(y.grow+=p.__heightGrow,d=0,p.__.heightRange&&(y.hasRangeSize=!0)),p.__widthGrow&&ft(p,g,G),y.height+=y.count?d+f:d,y.width=Math.max(y.width,g.width),y.count++):(Gt(p,x-g.x,b-g.y),b+=g.height+f));if(h){const{isAutoXGap:i,isFitXGap:n,contentAlign:h,rowXAlign:r,rowYAlign:f}=s;y.count&&(y.grow&&gt(t,y,m,e),l&&rt(y,o,m,_),c&&st(u,y,o)),c?(i?rt(u,"width",G,n):u.gap=a,function(t,e,o,i){ot(t,e,o);const{list:n}=e;if(n.length>1&&(i||(i=et[o]),"from"!==i)){let t;for(let o=0,s=n.length;o<s;o++)t=n[o],t.y=e.height-t.height,"center"===i&&(t.y/=2)}}(t,u,h,f),function(t,e,o,i){const{list:n}=e,s="reverse"===t.__.flowWrap;let h,{x:c,y:a}=e;for(let r=0,l=n.length;r<l;r++)h=n[s?l-1-r:r],bt(t,h,c,a,o,i),c+=h.width+e.gap}(t,u,r,e)):(ot(t,y,h),bt(t,y,y.x,0,r,e))}}function Bt(t){return w(t,(t=>y({set(e){const o="number"==typeof e?e:0;"autoWidth"===t?this.__widthGrow=o:this.__heightGrow=o,!o||this.parent&&this.parent.__hasGrow||this.waitParent((()=>{this.parent.__hasGrow=!0})),this.__setAttr(t,e)&&x(this)}})))}const Rt=b.prototype,zt=r.prototype,{__updateBoxBounds:At}=a.prototype;u(!1)(Rt,"flow"),G(0)(Rt,"gap"),G("top-left")(Rt,"flowAlign"),G(!1)(Rt,"flowWrap"),G("box")(Rt,"itemBox"),G(!0)(Rt,"inFlow"),Bt()(Rt,"autoWidth"),Bt()(Rt,"autoHeight"),G()(Rt,"autoBox");const{copyAndSpread:kt}=m;zt.__updateFlowLayout=function(){const{leaferIsCreated:t,flow:e}=this;switch(t&&(this.leafer.created=!1),e){case"x":case!0:yt(this);break;case"y":mt(this);break;case"x-reverse":yt(this,!0);break;case"y-reverse":mt(this,!0)}t&&(this.leafer.created=!0)},zt.__updateContentBounds=function(){const{padding:t}=this.__,e=this.__layout,o=e.contentBounds===e.boxBounds;t?(o&&e.shrinkContent(),kt(e.contentBounds,e.boxBounds,t,!0)):o||e.shrinkContentCancel()},zt.__updateBoxBounds=function(t){const e=this.__;if(this.children.length){const{flow:o}=e;if(e.__autoSide){o&&!t?this.__updateRectBoxBounds():At.call(this);const{boxBounds:i}=this.__layout;e.__autoSize||(e.__autoWidth?(o||(i.width+=i.x,i.x=0),i.height=e.height,i.y=0):(o||(i.height+=i.y,i.y=0),i.width=e.width,i.x=0)),o&&t&&e.padding&&kt(i,i,e.padding,!1,e.__autoSize?null:e.__autoWidth?"width":"height"),this.__updateNaturalSize()}else this.__updateRectBoxBounds();o&&this.__updateContentBounds()}else this.__updateRectBoxBounds()};export{V as Flow,P as PathScaler,Q as scaleResize,U as scaleResizeFontSize,J as scaleResizeGroup,Z as scaleResizePath,q as scaleResizePoints};
1
+ import{BoxData as t,dataProcessor as o,autoLayoutType as e,registerUI as i,Box as n,AlignHelper as h,PointHelper as r,MathHelper as s,decorateLeafAttr as a,attr as c,doBoundsType as l,UI as _,Group as u,boundsType as g,BoundsHelper as f}from"@leafer-ui/draw";import"@leafer-in/resize";function d(t,o,e,i){var n,h=arguments.length,r=h<3?o:null===i?i=Object.getOwnPropertyDescriptor(o,e):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,o,e,i);else for(var s=t.length-1;s>=0;s--)(n=t[s])&&(r=(h<3?n(r):h>3?n(o,e,r):n(o,e))||r);return h>3&&r&&Object.defineProperty(o,e,r),r}"function"==typeof SuppressedError&&SuppressedError;let w=class extends n{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}};d([o(class extends t{})],w.prototype,"__",void 0),d([e("x")],w.prototype,"flow",void 0),w=d([i()],w);const p={},x={"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"},y={"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 G(t,o,e){const i=t.__,{contentBounds:n}=t.__layout;h.toPoint(e,o,n,p),o.x=i.__autoWidth?n.x:p.x,o.y=i.__autoHeight?n.y:p.y}const{move:m}=r;function B(t,o,e,i,n,h){const{children:r}=t;let s,a,{x:c,start:l}=o,_=i;c+=e;for(let t=0,e=o.count;t<e;t++)s=r[h?l-t:l+t],s.__.inFlow&&0!==s.__.visible?(a=s.__flowBounds,"from"!==n&&(_=i+(o.height-a.height)/("center"===n?2:1)),m(s,c-a.x,_-a.y),c+=a.width+o.gap):e++}function b(t,o,e){const i="width"===e?"height":"width";t[e]=Math.max(t[e],o[e]),t[i]+=t.count?o[i]+t.gap:o[i],t.list.push(o),t.count++}const A={};function R(t,o){const{gap:e,flowAlign:i,flowWrap:n,__autoWidth:h,__autoHeight:r}=t.__,s=n&&(o?!h:!r);return"object"==typeof e?(A.xGap=e.x||0,A.yGap=e.y||0):A.xGap=A.yGap=e,A.isAutoXGap="string"==typeof A.xGap&&!h,A.isAutoYGap="string"==typeof A.yGap&&!r,A.complex=s||"top-left"!==i||t.__hasGrow||A.isAutoXGap||A.isAutoYGap,A.wrap=s,A.complex&&(A.isFitXGap="fit"===A.xGap&&!h,A.isFitYGap="fit"===A.yGap&&!r,"object"==typeof i?(A.contentAlign=i.content||"top-left",A.rowXAlign=i.x||"from",A.rowYAlign=i.y||"from"):(A.contentAlign=i,A.rowXAlign=x[i],A.rowYAlign=y[i])),A}function v(t,o){return{x:0,y:0,width:0,height:0,gap:o,start:t,count:0,grow:0}}function F(t,o,e,i){const{count:n}=t;n>1&&(e>t[o]||i)&&(t.gap=(e-t[o])/(n-1),t[o]=e)}function S(t,o){return"box"===o?t.__local:t.__layout.localStrokeBounds}const{within:X}=s;function Y(t,o,e,i){let n,h,r,s=0,a=o.hasRangeSize&&[],{grow:c,start:l}=o;const _=o.width<e?(e-o.width)/c:0,{children:u}=t;_&&(o.width=e);for(let t=0,e=o.count;t<e;t++)n=u[i?l-t:l+t],n.__.inFlow&&0!==n.__.visible?(h=n.__widthGrow)&&(r=z(n,n.__flowBounds,_*h),r?(s+=r,c-=h):a&&(n.__.widthRange?a.unshift(n):a.push(n))):e++;s&&function(t,o,e){let i,n,h,r;t.forEach((t=>{i=t.__widthGrow,n=o/e*i,r=z(t,h=t.__flowBounds,h.width+n),o-=n-r,e-=i}))}(a,s,c)}function z(t,o,e){const{widthRange:i,lockRatio:n}=t.__,h=i?X(e,i):e,r=h/o.width;return t.scaleResize(r,n?r:1),o.width=h,e-h}const{within:W}=s;function k(t,o,e,i){let n,h,r,s=0,a=o.hasRangeSize&&[],{grow:c,start:l}=o;const _=o.height<e?(e-o.height)/c:0,{children:u}=t;_&&(o.height=e);for(let t=0,e=o.count;t<e;t++)n=u[i?l-t:l+t],n.__.inFlow&&0!==n.__.visible?(h=n.__heightGrow)&&(r=C(n,n.__flowBounds,_*h),r?(s+=r,c-=h):a&&(n.__.heightRange?a.unshift(n):a.push(n))):e++;s&&function(t,o,e){let i,n,h,r;t.forEach((t=>{i=t.__heightGrow,n=o/e*i,r=C(t,h=t.__flowBounds,h.height+n),o-=n-r,e-=i}))}(a,s,c)}function C(t,o,e){const{heightRange:i,lockRatio:n}=t.__,h=i?W(e,i):e,r=h/o.height;return t.scaleResize(n?r:1,r),o.height=h,e-h}const{move:j}=r;function E(t,o){const e="width",{children:i,itemBox:n}=t,h=R(t,!0),{complex:r,wrap:s,xGap:a,yGap:c,isAutoXGap:l,isFitXGap:_}=h;if(!i.length)return;const u=s&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},g=l?0:a;let f,d,w,p,y,{x:m,y:A,width:X,height:z}=t.__layout.contentBounds;for(let h=0,a=i.length;h<a;h++)f=i[p=o?a-1-h:h],f.__.inFlow&&0!==f.__.visible&&(d=S(f,n),r?(f.__flowBounds=d,y||(y=v(p,g)),s&&y.count&&y.width+d.width>X&&(y.grow?Y(t,y,X,o):l&&F(y,e,X,_),b(u,y,e),y=v(p,g)),w=d.width,f.__widthGrow&&(y.grow+=f.__widthGrow,w=0,f.__.widthRange&&(y.hasRangeSize=!0)),f.__heightGrow&&C(f,d,z),y.width+=y.count?w+g:w,y.height=Math.max(y.height,d.height),y.count++):(j(f,m-d.x,A-d.y),m+=d.width+g));if(r&&y){const{isAutoYGap:i,isFitYGap:n,contentAlign:r,rowXAlign:a,rowYAlign:g}=h;y.count&&(y.grow?Y(t,y,X,o):l&&F(y,e,X,_),s&&b(u,y,e)),s?(i?F(u,"height",z,n):u.gap=c,function(t,o,e,i){G(t,o,e);const{list:n}=o;if(n.length>1&&(i||(i=x[e]),"from"!==i)){let t;for(let e=0,h=n.length;e<h;e++)t=n[e],t.x=o.width-t.width,"center"===i&&(t.x/=2)}}(t,u,r,a),function(t,o,e,i){const{list:n}=o,h="reverse"===t.__.flowWrap;let r,{x:s,y:a}=o;for(let c=0,l=n.length;c<l;c++)r=n[h?l-1-c:c],B(t,r,s,a,e,i),a+=r.height+o.gap}(t,u,g,o)):(G(t,y,r),B(t,y,0,y.y,g,o))}}const{move:P}=r;function H(t,o,e,i,n,h){const{children:r}=t;let s,a,{y:c,start:l}=o,_=e;c+=i;for(let t=0,i=o.count;t<i;t++)s=r[h?l-t:l+t],s.__.inFlow&&0!==s.__.visible?(a=s.__flowBounds,"from"!==n&&(_=e+(o.width-a.width)/("center"===n?2:1)),P(s,_-a.x,c-a.y),c+=a.height+o.gap):i++}const{move:M}=r;function O(t,o){const e="height",{children:i,itemBox:n}=t,h=R(t,!1),{complex:r,wrap:s,xGap:a,yGap:c,isAutoYGap:l,isFitYGap:_}=h;if(!i.length)return;const u=s&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},g=l?0:c;let f,d,w,p,x,{x:m,y:B,width:A,height:X}=t.__layout.contentBounds;for(let h=0,a=i.length;h<a;h++)f=i[p=o?a-1-h:h],f.__.inFlow&&0!==f.__.visible&&(d=S(f,n),r?(f.__flowBounds=d,x||(x=v(p,g)),s&&x.count&&x.height+d.height>X&&(x.grow&&k(t,x,X,o),l&&F(x,e,X,_),b(u,x,e),x=v(p,g)),w=d.height,f.__heightGrow&&(x.grow+=f.__heightGrow,w=0,f.__.heightRange&&(x.hasRangeSize=!0)),f.__widthGrow&&z(f,d,A),x.height+=x.count?w+g:w,x.width=Math.max(x.width,d.width),x.count++):(M(f,m-d.x,B-d.y),B+=d.height+g));if(r&&x){const{isAutoXGap:i,isFitXGap:n,contentAlign:r,rowXAlign:c,rowYAlign:g}=h;x.count&&(x.grow&&k(t,x,X,o),l&&F(x,e,X,_),s&&b(u,x,e)),s?(i?F(u,"width",A,n):u.gap=a,function(t,o,e,i){G(t,o,e);const{list:n}=o;if(n.length>1&&(i||(i=y[e]),"from"!==i)){let t;for(let e=0,h=n.length;e<h;e++)t=n[e],t.y=o.height-t.height,"center"===i&&(t.y/=2)}}(t,u,r,g),function(t,o,e,i){const{list:n}=o,h="reverse"===t.__.flowWrap;let r,{x:s,y:a}=o;for(let c=0,l=n.length;c<l;c++)r=n[h?l-1-c:c],H(t,r,s,a,e,i),s+=r.width+o.gap}(t,u,c,o)):(G(t,x,r),H(t,x,x.x,0,c,o))}}function L(t){return a(t,(t=>c({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 D=_.prototype,I=n.prototype,{__updateBoxBounds:N}=u.prototype;e(!1)(D,"flow"),g(0)(D,"gap"),g("top-left")(D,"flowAlign"),g(!1)(D,"flowWrap"),g("box")(D,"itemBox"),g(!0)(D,"inFlow"),L()(D,"autoWidth"),L()(D,"autoHeight"),g()(D,"autoBox");const{copyAndSpread:q}=f;I.__updateFlowLayout=function(){const{leaferIsCreated:t,flow:o}=this;switch(t&&(this.leafer.created=!1),o){case"x":case!0:E(this);break;case"y":O(this);break;case"x-reverse":E(this,!0);break;case"y-reverse":O(this,!0)}t&&(this.leafer.created=!0)},I.__updateContentBounds=function(){const{padding:t}=this.__,o=this.__layout,e=o.contentBounds===o.boxBounds;t?(e&&o.shrinkContent(),q(o.contentBounds,o.boxBounds,t,!0)):e||o.shrinkContentCancel()},I.__updateBoxBounds=function(t){const o=this.__;if(this.children.length){const{flow:e}=o;if(o.__autoSide){e&&!t?this.__updateRectBoxBounds():N.call(this);const{boxBounds:i}=this.__layout;o.__autoSize||(o.__autoWidth?(e||(i.width+=i.x,i.x=0),i.height=o.height,i.y=0):(e||(i.height+=i.y,i.y=0),i.width=o.width,i.x=0)),e&&t&&o.padding&&q(i,i,o.padding,!1,o.__autoSize?null:o.__autoWidth?"width":"height"),this.__updateNaturalSize()}else this.__updateRectBoxBounds();e&&this.__updateContentBounds()}else this.__updateRectBoxBounds()};export{w as Flow};
package/dist/flow.js CHANGED
@@ -2,218 +2,6 @@ this.LeaferIN = this.LeaferIN || {};
2
2
  this.LeaferIN.flow = (function (exports, draw) {
3
3
  'use strict';
4
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
- case L:
17
- scalePoints(data, scaleX, scaleY, i, 1);
18
- i += 3;
19
- break;
20
- case C:
21
- scalePoints(data, scaleX, scaleY, i, 3);
22
- i += 7;
23
- break;
24
- case Q:
25
- scalePoints(data, scaleX, scaleY, i, 2);
26
- i += 5;
27
- break;
28
- case Z:
29
- i += 1;
30
- break;
31
- case N:
32
- scalePoints(data, scaleX, scaleY, i, 2);
33
- i += 5;
34
- break;
35
- case D:
36
- scalePoints(data, scaleX, scaleY, i, 2);
37
- i += 9;
38
- break;
39
- case X:
40
- scalePoints(data, scaleX, scaleY, i, 2);
41
- i += 6;
42
- break;
43
- case G:
44
- scalePoints(data, scaleX, scaleY, i, 2);
45
- i += 9;
46
- break;
47
- case F:
48
- scalePoints(data, scaleX, scaleY, i, 2);
49
- i += 5;
50
- break;
51
- case O:
52
- data[i] = G;
53
- data.splice(i + 4, 0, data[i + 3], 0);
54
- scalePoints(data, scaleX, scaleY, i, 2);
55
- i += 7 + 2;
56
- len += 2;
57
- break;
58
- case P:
59
- data[i] = F;
60
- data.splice(i + 4, 0, data[i + 3]);
61
- scalePoints(data, scaleX, scaleY, i, 2);
62
- i += 4 + 1;
63
- len += 1;
64
- break;
65
- case U:
66
- scalePoints(data, scaleX, scaleY, i, 2);
67
- i += 6;
68
- break;
69
- }
70
- }
71
- },
72
- scalePoints(data, scaleX, scaleY, start, pointCount) {
73
- for (let i = pointCount ? start + 1 : 0, end = pointCount ? i + pointCount * 2 : data.length; i < end; i += 2) {
74
- data[i] *= scaleX;
75
- data[i + 1] *= scaleY;
76
- }
77
- }
78
- };
79
- const { scalePoints } = PathScaler;
80
-
81
- const matrix = draw.MatrixHelper.get();
82
- const { topLeft, top, topRight, right, bottom, left } = draw.Direction9;
83
- function scaleResize(leaf, scaleX, scaleY) {
84
- if (leaf.pathInputed) {
85
- scaleResizePath(leaf, scaleX, scaleY);
86
- }
87
- else {
88
- if (scaleX !== 1)
89
- leaf.width *= scaleX;
90
- if (scaleY !== 1)
91
- leaf.height *= scaleY;
92
- }
93
- }
94
- function scaleResizeFontSize(leaf, scaleX, scaleY) {
95
- const { app } = leaf;
96
- const editor = app && app.editor;
97
- let fontScale = scaleX;
98
- if (editor.editing) {
99
- const layout = leaf.__layout;
100
- let { width, height } = layout.boxBounds;
101
- width *= scaleY - scaleX;
102
- height *= scaleX - scaleY;
103
- switch (editor.resizeDirection) {
104
- case top:
105
- case bottom:
106
- fontScale = scaleY;
107
- layout.affectScaleOrRotation ? leaf.moveInner(-width / 2, 0) : leaf.x -= width / 2;
108
- break;
109
- case left:
110
- case right:
111
- layout.affectScaleOrRotation ? leaf.moveInner(0, -height / 2) : leaf.y -= height / 2;
112
- break;
113
- case topLeft:
114
- case topRight:
115
- layout.affectScaleOrRotation ? leaf.moveInner(0, -height) : leaf.y -= height;
116
- break;
117
- }
118
- }
119
- leaf.fontSize *= fontScale;
120
- const data = leaf.__;
121
- if (!data.__autoWidth)
122
- leaf.width *= fontScale;
123
- if (!data.__autoHeight)
124
- leaf.height *= fontScale;
125
- }
126
- function scaleResizePath(leaf, scaleX, scaleY) {
127
- PathScaler.scale(leaf.__.path, scaleX, scaleY);
128
- leaf.path = leaf.__.path;
129
- }
130
- function scaleResizePoints(leaf, scaleX, scaleY) {
131
- const { points } = leaf;
132
- typeof points[0] === 'object' ? points.forEach(p => { p.x *= scaleX, p.y *= scaleY; }) : PathScaler.scalePoints(points, scaleX, scaleY);
133
- leaf.points = 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 = draw.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
- draw.Text.prototype.__scaleResize = function (scaleX, scaleY) {
171
- if (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
- draw.Path.prototype.__scaleResize = function (scaleX, scaleY) {
179
- scaleResizePath(this, scaleX, scaleY);
180
- };
181
- draw.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
- draw.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
- draw.Group.prototype.__scaleResize = function (scaleX, scaleY) {
204
- scaleResizeGroup(this, scaleX, scaleY);
205
- };
206
- draw.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
5
  /******************************************************************************
218
6
  Copyright (c) Microsoft Corporation.
219
7
 
@@ -539,7 +327,7 @@ this.LeaferIN.flow = (function (exports, draw) {
539
327
  }
540
328
  }
541
329
  }
542
- if (complex) {
330
+ if (complex && data) {
543
331
  const { isAutoYGap, isFitYGap, contentAlign, rowXAlign, rowYAlign } = pData;
544
332
  if (data.count) {
545
333
  if (data.grow)
@@ -653,7 +441,7 @@ this.LeaferIN.flow = (function (exports, draw) {
653
441
  }
654
442
  }
655
443
  }
656
- if (complex) {
444
+ if (complex && data) {
657
445
  const { isAutoXGap, isFitXGap, contentAlign, rowXAlign, rowYAlign } = pData;
658
446
  if (data.count) {
659
447
  if (data.grow)
@@ -770,13 +558,6 @@ this.LeaferIN.flow = (function (exports, draw) {
770
558
  }
771
559
  };
772
560
 
773
- exports.PathScaler = PathScaler;
774
- exports.scaleResize = scaleResize;
775
- exports.scaleResizeFontSize = scaleResizeFontSize;
776
- exports.scaleResizeGroup = scaleResizeGroup;
777
- exports.scaleResizePath = scaleResizePath;
778
- exports.scaleResizePoints = scaleResizePoints;
779
-
780
561
  return exports;
781
562
 
782
563
  })({}, LeaferUI);
package/dist/flow.min.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t=require("@leafer-ui/draw");const{M:e,L:o,C:i,Q:n,Z:s,N:h,D:a,X:r,G:c,F:l,O:_,P:u,U:p}=t.PathCommandMap,f={scale(t,f,g){if(!t)return;let w,y=0,x=t.length;for(;y<x;)switch(w=t[y],w){case e:case o:d(t,f,g,y,1),y+=3;break;case i:d(t,f,g,y,3),y+=7;break;case n:d(t,f,g,y,2),y+=5;break;case s:y+=1;break;case h:d(t,f,g,y,2),y+=5;break;case a:d(t,f,g,y,2),y+=9;break;case r:d(t,f,g,y,2),y+=6;break;case c:d(t,f,g,y,2),y+=9;break;case l:d(t,f,g,y,2),y+=5;break;case _:t[y]=c,t.splice(y+4,0,t[y+3],0),d(t,f,g,y,2),y+=9,x+=2;break;case u:t[y]=l,t.splice(y+4,0,t[y+3]),d(t,f,g,y,2),y+=5,x+=1;break;case p:d(t,f,g,y,2),y+=6}},scalePoints(t,e,o,i,n){for(let s=n?i+1:0,h=n?s+2*n:t.length;s<h;s+=2)t[s]*=e,t[s+1]*=o}},{scalePoints:d}=f,g=t.MatrixHelper.get(),{topLeft:w,top:y,topRight:x,right:b,bottom:G,left:B}=t.Direction9;function m(t,e,o){t.pathInputed?z(t,e,o):(1!==e&&(t.width*=e),1!==o&&(t.height*=o))}function R(t,e,o){const{app:i}=t,n=i&&i.editor;let s=e;if(n.editing){const i=t.__layout;let{width:h,height:a}=i.boxBounds;switch(h*=o-e,a*=e-o,n.resizeDirection){case y:case G:s=o,i.affectScaleOrRotation?t.moveInner(-h/2,0):t.x-=h/2;break;case B:case b:i.affectScaleOrRotation?t.moveInner(0,-a/2):t.y-=a/2;break;case w:case x:i.affectScaleOrRotation?t.moveInner(0,-a):t.y-=a}}t.fontSize*=s;const h=t.__;h.__autoWidth||(t.width*=s),h.__autoHeight||(t.height*=s)}function z(t,e,o){f.scale(t.__.path,e,o),t.path=t.__.path}function A(t,e,o){const{points:i}=t;"object"==typeof i[0]?i.forEach((t=>{t.x*=e,t.y*=o})):f.scalePoints(i,e,o),t.points=i}function k(t,e,o){const{children:i}=t;for(let t=0;t<i.length;t++)g.a=e,g.d=o,i[t].transform(g,!0)}const F=t.Leaf.prototype;function v(t,e,o,i){var n,s=arguments.length,h=s<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,o):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)h=Reflect.decorate(t,e,o,i);else for(var a=t.length-1;a>=0;a--)(n=t[a])&&(h=(s<3?n(h):s>3?n(e,o,h):n(e,o))||h);return s>3&&h&&Object.defineProperty(e,o,h),h}F.scaleResize=function(t,e=t,o){const i=this;o||i.editConfig&&"scale"===i.editConfig.editSize?(i.scaleX*=t,i.scaleY*=e):(t<0&&(i.scaleX*=-1,t=-t),e<0&&(i.scaleY*=-1,e=-e),this.__scaleResize(t,e))},F.__scaleResize=function(t,e){m(this,t,e)},F.resizeWidth=function(t){const e=t/this.getBounds("box","local").width;this.scaleOf(this.__layout.boxBounds,e,this.__.lockRatio?e:1,!0)},F.resizeHeight=function(t){const e=t/this.getBounds("box","local").height;this.scaleOf(this.__layout.boxBounds,this.__.lockRatio?e:1,e,!0)},t.Text.prototype.__scaleResize=function(t,e){this.__.resizeFontSize||this.editConfig&&"font-size"===this.editConfig.editSize?R(this,t,e):m(this,t,e)},t.Path.prototype.__scaleResize=function(t,e){z(this,t,e)},t.Line.prototype.__scaleResize=function(t,e){this.pathInputed?z(this,t,e):this.points?A(this,t,e):this.width*=t},t.Polygon.prototype.__scaleResize=function(t,e){this.pathInputed?z(this,t,e):this.points?A(this,t,e):m(this,t,e)},t.Group.prototype.__scaleResize=function(t,e){k(this,t,e)},t.Box.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?k(this,t,e):(m(this,t,e),this.__.resizeChildren&&k(this,t,e))},"function"==typeof SuppressedError&&SuppressedError;class S extends t.BoxData{}exports.Flow=class extends t.Box{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}},v([t.dataProcessor(S)],exports.Flow.prototype,"__",void 0),v([t.autoLayoutType("x")],exports.Flow.prototype,"flow",void 0),exports.Flow=v([t.registerUI()],exports.Flow);const P={},H={"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"},X={"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 C(e,o,i){const n=e.__,{contentBounds:s}=e.__layout;t.AlignHelper.toPoint(i,o,s,P),o.x=n.__autoWidth?s.x:P.x,o.y=n.__autoHeight?s.y:P.y}const{move:Y}=t.PointHelper;function W(t,e,o,i,n,s){const{children:h}=t;let a,r,{x:c,start:l}=e,_=i;c+=o;for(let t=0,o=e.count;t<o;t++)a=h[s?l-t:l+t],a.__.inFlow&&0!==a.__.visible?(r=a.__flowBounds,"from"!==n&&(_=i+(e.height-r.height)/("center"===n?2:1)),Y(a,c-r.x,_-r.y),c+=r.width+e.gap):o++}function T(t,e,o){const i="width"===o?"height":"width";t[o]=Math.max(t[o],e[o]),t[i]+=t.count?e[i]+t.gap:e[i],t.list.push(e),t.count++}const I={};function L(t,e){const{gap:o,flowAlign:i,flowWrap:n,__autoWidth:s,__autoHeight:h}=t.__,a=n&&(e?!s:!h);return"object"==typeof o?(I.xGap=o.x||0,I.yGap=o.y||0):I.xGap=I.yGap=o,I.isAutoXGap="string"==typeof I.xGap&&!s,I.isAutoYGap="string"==typeof I.yGap&&!h,I.complex=a||"top-left"!==i||t.__hasGrow||I.isAutoXGap||I.isAutoYGap,I.wrap=a,I.complex&&(I.isFitXGap="fit"===I.xGap&&!s,I.isFitYGap="fit"===I.yGap&&!h,"object"==typeof i?(I.contentAlign=i.content||"top-left",I.rowXAlign=i.x||"from",I.rowYAlign=i.y||"from"):(I.contentAlign=i,I.rowXAlign=H[i],I.rowYAlign=X[i])),I}function O(t,e){return{x:0,y:0,width:0,height:0,gap:e,start:t,count:0,grow:0}}function M(t,e,o,i){const{count:n}=t;n>1&&(o>t[e]||i)&&(t.gap=(o-t[e])/(n-1),t[e]=o)}function j(t,e){return"box"===e?t.__local:t.__layout.localStrokeBounds}const{within:D}=t.MathHelper;function E(t,e,o,i){let n,s,h,a=0,r=e.hasRangeSize&&[],{grow:c,start:l}=e;const _=e.width<o?(o-e.width)/c:0,{children:u}=t;_&&(e.width=o);for(let t=0,o=e.count;t<o;t++)n=u[i?l-t:l+t],n.__.inFlow&&0!==n.__.visible?(s=n.__widthGrow)&&(h=U(n,n.__flowBounds,_*s),h?(a+=h,c-=s):r&&(n.__.widthRange?r.unshift(n):r.push(n))):o++;a&&function(t,e,o){let i,n,s,h;t.forEach((t=>{i=t.__widthGrow,n=e/o*i,h=U(t,s=t.__flowBounds,s.width+n),e-=n-h,o-=i}))}(r,a,c)}function U(t,e,o){const{widthRange:i,lockRatio:n}=t.__,s=i?D(o,i):o,h=s/e.width;return t.scaleResize(h,n?h:1),e.width=s,o-s}const{within:N}=t.MathHelper;function q(t,e,o,i){let n,s,h,a=0,r=e.hasRangeSize&&[],{grow:c,start:l}=e;const _=e.height<o?(o-e.height)/c:0,{children:u}=t;_&&(e.height=o);for(let t=0,o=e.count;t<o;t++)n=u[i?l-t:l+t],n.__.inFlow&&0!==n.__.visible?(s=n.__heightGrow)&&(h=Q(n,n.__flowBounds,_*s),h?(a+=h,c-=s):r&&(n.__.heightRange?r.unshift(n):r.push(n))):o++;a&&function(t,e,o){let i,n,s,h;t.forEach((t=>{i=t.__heightGrow,n=e/o*i,h=Q(t,s=t.__flowBounds,s.height+n),e-=n-h,o-=i}))}(r,a,c)}function Q(t,e,o){const{heightRange:i,lockRatio:n}=t.__,s=i?N(o,i):o,h=s/e.height;return t.scaleResize(n?h:1,h),e.height=s,o-s}const{move:Z}=t.PointHelper;function J(t,e){const o="width",{children:i,itemBox:n}=t,s=L(t,!0),{complex:h,wrap:a,xGap:r,yGap:c,isAutoXGap:l,isFitXGap:_}=s;if(!i.length)return;const u=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},p=l?0:r;let f,d,g,w,y,{x:x,y:b,width:G,height:B}=t.__layout.contentBounds;for(let s=0,r=i.length;s<r;s++)f=i[w=e?r-1-s:s],f.__.inFlow&&0!==f.__.visible&&(d=j(f,n),h?(f.__flowBounds=d,y||(y=O(w,p)),a&&y.count&&y.width+d.width>G&&(y.grow?E(t,y,G,e):l&&M(y,o,G,_),T(u,y,o),y=O(w,p)),g=d.width,f.__widthGrow&&(y.grow+=f.__widthGrow,g=0,f.__.widthRange&&(y.hasRangeSize=!0)),f.__heightGrow&&Q(f,d,B),y.width+=y.count?g+p:g,y.height=Math.max(y.height,d.height),y.count++):(Z(f,x-d.x,b-d.y),x+=d.width+p));if(h){const{isAutoYGap:i,isFitYGap:n,contentAlign:h,rowXAlign:r,rowYAlign:p}=s;y.count&&(y.grow?E(t,y,G,e):l&&M(y,o,G,_),a&&T(u,y,o)),a?(i?M(u,"height",B,n):u.gap=c,function(t,e,o,i){C(t,e,o);const{list:n}=e;if(n.length>1&&(i||(i=H[o]),"from"!==i)){let t;for(let o=0,s=n.length;o<s;o++)t=n[o],t.x=e.width-t.width,"center"===i&&(t.x/=2)}}(t,u,h,r),function(t,e,o,i){const{list:n}=e,s="reverse"===t.__.flowWrap;let h,{x:a,y:r}=e;for(let c=0,l=n.length;c<l;c++)h=n[s?l-1-c:c],W(t,h,a,r,o,i),r+=h.height+e.gap}(t,u,p,e)):(C(t,y,h),W(t,y,0,y.y,p,e))}}const{move:K}=t.PointHelper;function V(t,e,o,i,n,s){const{children:h}=t;let a,r,{y:c,start:l}=e,_=o;c+=i;for(let t=0,i=e.count;t<i;t++)a=h[s?l-t:l+t],a.__.inFlow&&0!==a.__.visible?(r=a.__flowBounds,"from"!==n&&(_=o+(e.width-r.width)/("center"===n?2:1)),K(a,_-r.x,c-r.y),c+=r.height+e.gap):i++}const{move:$}=t.PointHelper;function tt(t,e){const o="height",{children:i,itemBox:n}=t,s=L(t,!1),{complex:h,wrap:a,xGap:r,yGap:c,isAutoYGap:l,isFitYGap:_}=s;if(!i.length)return;const u=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},p=l?0:c;let f,d,g,w,y,{x:x,y:b,width:G,height:B}=t.__layout.contentBounds;for(let s=0,r=i.length;s<r;s++)f=i[w=e?r-1-s:s],f.__.inFlow&&0!==f.__.visible&&(d=j(f,n),h?(f.__flowBounds=d,y||(y=O(w,p)),a&&y.count&&y.height+d.height>B&&(y.grow&&q(t,y,B,e),l&&M(y,o,B,_),T(u,y,o),y=O(w,p)),g=d.height,f.__heightGrow&&(y.grow+=f.__heightGrow,g=0,f.__.heightRange&&(y.hasRangeSize=!0)),f.__widthGrow&&U(f,d,G),y.height+=y.count?g+p:g,y.width=Math.max(y.width,d.width),y.count++):($(f,x-d.x,b-d.y),b+=d.height+p));if(h){const{isAutoXGap:i,isFitXGap:n,contentAlign:h,rowXAlign:c,rowYAlign:p}=s;y.count&&(y.grow&&q(t,y,B,e),l&&M(y,o,B,_),a&&T(u,y,o)),a?(i?M(u,"width",G,n):u.gap=r,function(t,e,o,i){C(t,e,o);const{list:n}=e;if(n.length>1&&(i||(i=X[o]),"from"!==i)){let t;for(let o=0,s=n.length;o<s;o++)t=n[o],t.y=e.height-t.height,"center"===i&&(t.y/=2)}}(t,u,h,p),function(t,e,o,i){const{list:n}=e,s="reverse"===t.__.flowWrap;let h,{x:a,y:r}=e;for(let c=0,l=n.length;c<l;c++)h=n[s?l-1-c:c],V(t,h,a,r,o,i),a+=h.width+e.gap}(t,u,c,e)):(C(t,y,h),V(t,y,y.x,0,c,e))}}function et(e){return t.decorateLeafAttr(e,(e=>t.attr({set(o){const i="number"==typeof o?o:0;"autoWidth"===e?this.__widthGrow=i:this.__heightGrow=i,!i||this.parent&&this.parent.__hasGrow||this.waitParent((()=>{this.parent.__hasGrow=!0})),this.__setAttr(e,o)&&t.doBoundsType(this)}})))}const ot=t.UI.prototype,it=t.Box.prototype,{__updateBoxBounds:nt}=t.Group.prototype;t.autoLayoutType(!1)(ot,"flow"),t.boundsType(0)(ot,"gap"),t.boundsType("top-left")(ot,"flowAlign"),t.boundsType(!1)(ot,"flowWrap"),t.boundsType("box")(ot,"itemBox"),t.boundsType(!0)(ot,"inFlow"),et()(ot,"autoWidth"),et()(ot,"autoHeight"),t.boundsType()(ot,"autoBox");const{copyAndSpread:st}=t.BoundsHelper;it.__updateFlowLayout=function(){const{leaferIsCreated:t,flow:e}=this;switch(t&&(this.leafer.created=!1),e){case"x":case!0:J(this);break;case"y":tt(this);break;case"x-reverse":J(this,!0);break;case"y-reverse":tt(this,!0)}t&&(this.leafer.created=!0)},it.__updateContentBounds=function(){const{padding:t}=this.__,e=this.__layout,o=e.contentBounds===e.boxBounds;t?(o&&e.shrinkContent(),st(e.contentBounds,e.boxBounds,t,!0)):o||e.shrinkContentCancel()},it.__updateBoxBounds=function(t){const e=this.__;if(this.children.length){const{flow:o}=e;if(e.__autoSide){o&&!t?this.__updateRectBoxBounds():nt.call(this);const{boxBounds:i}=this.__layout;e.__autoSize||(e.__autoWidth?(o||(i.width+=i.x,i.x=0),i.height=e.height,i.y=0):(o||(i.height+=i.y,i.y=0),i.width=e.width,i.x=0)),o&&t&&e.padding&&st(i,i,e.padding,!1,e.__autoSize?null:e.__autoWidth?"width":"height"),this.__updateNaturalSize()}else this.__updateRectBoxBounds();o&&this.__updateContentBounds()}else this.__updateRectBoxBounds()},exports.PathScaler=f,exports.scaleResize=m,exports.scaleResizeFontSize=R,exports.scaleResizeGroup=k,exports.scaleResizePath=z,exports.scaleResizePoints=A;
1
+ "use strict";var t=require("@leafer-ui/draw");function o(t,o,e,i){var n,h=arguments.length,r=h<3?o:null===i?i=Object.getOwnPropertyDescriptor(o,e):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,o,e,i);else for(var s=t.length-1;s>=0;s--)(n=t[s])&&(r=(h<3?n(r):h>3?n(o,e,r):n(o,e))||r);return h>3&&r&&Object.defineProperty(o,e,r),r}require("@leafer-in/resize"),"function"==typeof SuppressedError&&SuppressedError;class e extends t.BoxData{}exports.Flow=class extends t.Box{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}},o([t.dataProcessor(e)],exports.Flow.prototype,"__",void 0),o([t.autoLayoutType("x")],exports.Flow.prototype,"flow",void 0),exports.Flow=o([t.registerUI()],exports.Flow);const i={},n={"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 r(o,e,n){const h=o.__,{contentBounds:r}=o.__layout;t.AlignHelper.toPoint(n,e,r,i),e.x=h.__autoWidth?r.x:i.x,e.y=h.__autoHeight?r.y:i.y}const{move:s}=t.PointHelper;function a(t,o,e,i,n,h){const{children:r}=t;let a,l,{x:c,start:_}=o,u=i;c+=e;for(let t=0,e=o.count;t<e;t++)a=r[h?_-t:_+t],a.__.inFlow&&0!==a.__.visible?(l=a.__flowBounds,"from"!==n&&(u=i+(o.height-l.height)/("center"===n?2:1)),s(a,c-l.x,u-l.y),c+=l.width+o.gap):e++}function l(t,o,e){const i="width"===e?"height":"width";t[e]=Math.max(t[e],o[e]),t[i]+=t.count?o[i]+t.gap:o[i],t.list.push(o),t.count++}const c={};function _(t,o){const{gap:e,flowAlign:i,flowWrap:r,__autoWidth:s,__autoHeight:a}=t.__,l=r&&(o?!s:!a);return"object"==typeof e?(c.xGap=e.x||0,c.yGap=e.y||0):c.xGap=c.yGap=e,c.isAutoXGap="string"==typeof c.xGap&&!s,c.isAutoYGap="string"==typeof c.yGap&&!a,c.complex=l||"top-left"!==i||t.__hasGrow||c.isAutoXGap||c.isAutoYGap,c.wrap=l,c.complex&&(c.isFitXGap="fit"===c.xGap&&!s,c.isFitYGap="fit"===c.yGap&&!a,"object"==typeof i?(c.contentAlign=i.content||"top-left",c.rowXAlign=i.x||"from",c.rowYAlign=i.y||"from"):(c.contentAlign=i,c.rowXAlign=n[i],c.rowYAlign=h[i])),c}function u(t,o){return{x:0,y:0,width:0,height:0,gap:o,start:t,count:0,grow:0}}function p(t,o,e,i){const{count:n}=t;n>1&&(e>t[o]||i)&&(t.gap=(e-t[o])/(n-1),t[o]=e)}function d(t,o){return"box"===o?t.__local:t.__layout.localStrokeBounds}const{within:g}=t.MathHelper;function w(t,o,e,i){let n,h,r,s=0,a=o.hasRangeSize&&[],{grow:l,start:c}=o;const _=o.width<e?(e-o.width)/l:0,{children:u}=t;_&&(o.width=e);for(let t=0,e=o.count;t<e;t++)n=u[i?c-t:c+t],n.__.inFlow&&0!==n.__.visible?(h=n.__widthGrow)&&(r=f(n,n.__flowBounds,_*h),r?(s+=r,l-=h):a&&(n.__.widthRange?a.unshift(n):a.push(n))):e++;s&&function(t,o,e){let i,n,h,r;t.forEach((t=>{i=t.__widthGrow,n=o/e*i,r=f(t,h=t.__flowBounds,h.width+n),o-=n-r,e-=i}))}(a,s,l)}function f(t,o,e){const{widthRange:i,lockRatio:n}=t.__,h=i?g(e,i):e,r=h/o.width;return t.scaleResize(r,n?r:1),o.width=h,e-h}const{within:y}=t.MathHelper;function x(t,o,e,i){let n,h,r,s=0,a=o.hasRangeSize&&[],{grow:l,start:c}=o;const _=o.height<e?(e-o.height)/l:0,{children:u}=t;_&&(o.height=e);for(let t=0,e=o.count;t<e;t++)n=u[i?c-t:c+t],n.__.inFlow&&0!==n.__.visible?(h=n.__heightGrow)&&(r=G(n,n.__flowBounds,_*h),r?(s+=r,l-=h):a&&(n.__.heightRange?a.unshift(n):a.push(n))):e++;s&&function(t,o,e){let i,n,h,r;t.forEach((t=>{i=t.__heightGrow,n=o/e*i,r=G(t,h=t.__flowBounds,h.height+n),o-=n-r,e-=i}))}(a,s,l)}function G(t,o,e){const{heightRange:i,lockRatio:n}=t.__,h=i?y(e,i):e,r=h/o.height;return t.scaleResize(n?r:1,r),o.height=h,e-h}const{move:b}=t.PointHelper;function B(t,o){const e="width",{children:i,itemBox:h}=t,s=_(t,!0),{complex:c,wrap:g,xGap:f,yGap:y,isAutoXGap:x,isFitXGap:B}=s;if(!i.length)return;const m=g&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},A=x?0:f;let F,R,v,S,H,{x:X,y:Y,width:z,height:W}=t.__layout.contentBounds;for(let n=0,r=i.length;n<r;n++)F=i[S=o?r-1-n:n],F.__.inFlow&&0!==F.__.visible&&(R=d(F,h),c?(F.__flowBounds=R,H||(H=u(S,A)),g&&H.count&&H.width+R.width>z&&(H.grow?w(t,H,z,o):x&&p(H,e,z,B),l(m,H,e),H=u(S,A)),v=R.width,F.__widthGrow&&(H.grow+=F.__widthGrow,v=0,F.__.widthRange&&(H.hasRangeSize=!0)),F.__heightGrow&&G(F,R,W),H.width+=H.count?v+A:v,H.height=Math.max(H.height,R.height),H.count++):(b(F,X-R.x,Y-R.y),X+=R.width+A));if(c&&H){const{isAutoYGap:i,isFitYGap:h,contentAlign:c,rowXAlign:_,rowYAlign:u}=s;H.count&&(H.grow?w(t,H,z,o):x&&p(H,e,z,B),g&&l(m,H,e)),g?(i?p(m,"height",W,h):m.gap=y,function(t,o,e,i){r(t,o,e);const{list:h}=o;if(h.length>1&&(i||(i=n[e]),"from"!==i)){let t;for(let e=0,n=h.length;e<n;e++)t=h[e],t.x=o.width-t.width,"center"===i&&(t.x/=2)}}(t,m,c,_),function(t,o,e,i){const{list:n}=o,h="reverse"===t.__.flowWrap;let r,{x:s,y:l}=o;for(let c=0,_=n.length;c<_;c++)r=n[h?_-1-c:c],a(t,r,s,l,e,i),l+=r.height+o.gap}(t,m,u,o)):(r(t,H,c),a(t,H,0,H.y,u,o))}}const{move:m}=t.PointHelper;function A(t,o,e,i,n,h){const{children:r}=t;let s,a,{y:l,start:c}=o,_=e;l+=i;for(let t=0,i=o.count;t<i;t++)s=r[h?c-t:c+t],s.__.inFlow&&0!==s.__.visible?(a=s.__flowBounds,"from"!==n&&(_=e+(o.width-a.width)/("center"===n?2:1)),m(s,_-a.x,l-a.y),l+=a.height+o.gap):i++}const{move:F}=t.PointHelper;function R(t,o){const e="height",{children:i,itemBox:n}=t,s=_(t,!1),{complex:a,wrap:c,xGap:g,yGap:w,isAutoYGap:y,isFitYGap:G}=s;if(!i.length)return;const b=c&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},B=y?0:w;let m,R,v,S,H,{x:X,y:Y,width:z,height:W}=t.__layout.contentBounds;for(let h=0,r=i.length;h<r;h++)m=i[S=o?r-1-h:h],m.__.inFlow&&0!==m.__.visible&&(R=d(m,n),a?(m.__flowBounds=R,H||(H=u(S,B)),c&&H.count&&H.height+R.height>W&&(H.grow&&x(t,H,W,o),y&&p(H,e,W,G),l(b,H,e),H=u(S,B)),v=R.height,m.__heightGrow&&(H.grow+=m.__heightGrow,v=0,m.__.heightRange&&(H.hasRangeSize=!0)),m.__widthGrow&&f(m,R,z),H.height+=H.count?v+B:v,H.width=Math.max(H.width,R.width),H.count++):(F(m,X-R.x,Y-R.y),Y+=R.height+B));if(a&&H){const{isAutoXGap:i,isFitXGap:n,contentAlign:a,rowXAlign:_,rowYAlign:u}=s;H.count&&(H.grow&&x(t,H,W,o),y&&p(H,e,W,G),c&&l(b,H,e)),c?(i?p(b,"width",z,n):b.gap=g,function(t,o,e,i){r(t,o,e);const{list:n}=o;if(n.length>1&&(i||(i=h[e]),"from"!==i)){let t;for(let e=0,h=n.length;e<h;e++)t=n[e],t.y=o.height-t.height,"center"===i&&(t.y/=2)}}(t,b,a,u),function(t,o,e,i){const{list:n}=o,h="reverse"===t.__.flowWrap;let r,{x:s,y:a}=o;for(let l=0,c=n.length;l<c;l++)r=n[h?c-1-l:l],A(t,r,s,a,e,i),s+=r.width+o.gap}(t,b,_,o)):(r(t,H,a),A(t,H,H.x,0,_,o))}}function v(o){return t.decorateLeafAttr(o,(o=>t.attr({set(e){const i="number"==typeof e?e:0;"autoWidth"===o?this.__widthGrow=i:this.__heightGrow=i,!i||this.parent&&this.parent.__hasGrow||this.waitParent((()=>{this.parent.__hasGrow=!0})),this.__setAttr(o,e)&&t.doBoundsType(this)}})))}const S=t.UI.prototype,H=t.Box.prototype,{__updateBoxBounds:X}=t.Group.prototype;t.autoLayoutType(!1)(S,"flow"),t.boundsType(0)(S,"gap"),t.boundsType("top-left")(S,"flowAlign"),t.boundsType(!1)(S,"flowWrap"),t.boundsType("box")(S,"itemBox"),t.boundsType(!0)(S,"inFlow"),v()(S,"autoWidth"),v()(S,"autoHeight"),t.boundsType()(S,"autoBox");const{copyAndSpread:Y}=t.BoundsHelper;H.__updateFlowLayout=function(){const{leaferIsCreated:t,flow:o}=this;switch(t&&(this.leafer.created=!1),o){case"x":case!0:B(this);break;case"y":R(this);break;case"x-reverse":B(this,!0);break;case"y-reverse":R(this,!0)}t&&(this.leafer.created=!0)},H.__updateContentBounds=function(){const{padding:t}=this.__,o=this.__layout,e=o.contentBounds===o.boxBounds;t?(e&&o.shrinkContent(),Y(o.contentBounds,o.boxBounds,t,!0)):e||o.shrinkContentCancel()},H.__updateBoxBounds=function(t){const o=this.__;if(this.children.length){const{flow:e}=o;if(o.__autoSide){e&&!t?this.__updateRectBoxBounds():X.call(this);const{boxBounds:i}=this.__layout;o.__autoSize||(o.__autoWidth?(e||(i.width+=i.x,i.x=0),i.height=o.height,i.y=0):(e||(i.height+=i.y,i.y=0),i.width=o.width,i.x=0)),e&&t&&o.padding&&Y(i,i,o.padding,!1,o.__autoSize?null:o.__autoWidth?"width":"height"),this.__updateNaturalSize()}else this.__updateRectBoxBounds();e&&this.__updateContentBounds()}else this.__updateRectBoxBounds()};
package/dist/flow.min.js CHANGED
@@ -1 +1 @@
1
- this.LeaferIN=this.LeaferIN||{},this.LeaferIN.flow=function(t,e){"use strict";const{M:o,L:i,C:n,Q:s,Z:h,N:a,D:r,X:c,G:l,F:_,O:u,P:p,U:f}=e.PathCommandMap,d={scale(t,e,d){if(!t)return;let w,y=0,x=t.length;for(;y<x;)switch(w=t[y],w){case o:case i:g(t,e,d,y,1),y+=3;break;case n:g(t,e,d,y,3),y+=7;break;case s:g(t,e,d,y,2),y+=5;break;case h:y+=1;break;case a:g(t,e,d,y,2),y+=5;break;case r:g(t,e,d,y,2),y+=9;break;case c:g(t,e,d,y,2),y+=6;break;case l:g(t,e,d,y,2),y+=9;break;case _:g(t,e,d,y,2),y+=5;break;case u:t[y]=l,t.splice(y+4,0,t[y+3],0),g(t,e,d,y,2),y+=9,x+=2;break;case p:t[y]=_,t.splice(y+4,0,t[y+3]),g(t,e,d,y,2),y+=5,x+=1;break;case f:g(t,e,d,y,2),y+=6}},scalePoints(t,e,o,i,n){for(let s=n?i+1:0,h=n?s+2*n:t.length;s<h;s+=2)t[s]*=e,t[s+1]*=o}},{scalePoints:g}=d,w=e.MatrixHelper.get(),{topLeft:y,top:x,topRight:b,right:G,bottom:B,left:m}=e.Direction9;function R(t,e,o){t.pathInputed?A(t,e,o):(1!==e&&(t.width*=e),1!==o&&(t.height*=o))}function z(t,e,o){const{app:i}=t,n=i&&i.editor;let s=e;if(n.editing){const i=t.__layout;let{width:h,height:a}=i.boxBounds;switch(h*=o-e,a*=e-o,n.resizeDirection){case x:case B:s=o,i.affectScaleOrRotation?t.moveInner(-h/2,0):t.x-=h/2;break;case m:case G:i.affectScaleOrRotation?t.moveInner(0,-a/2):t.y-=a/2;break;case y:case b:i.affectScaleOrRotation?t.moveInner(0,-a):t.y-=a}}t.fontSize*=s;const h=t.__;h.__autoWidth||(t.width*=s),h.__autoHeight||(t.height*=s)}function A(t,e,o){d.scale(t.__.path,e,o),t.path=t.__.path}function k(t,e,o){const{points:i}=t;"object"==typeof i[0]?i.forEach((t=>{t.x*=e,t.y*=o})):d.scalePoints(i,e,o),t.points=i}function F(t,e,o){const{children:i}=t;for(let t=0;t<i.length;t++)w.a=e,w.d=o,i[t].transform(w,!0)}const S=e.Leaf.prototype;function v(t,e,o,i){var n,s=arguments.length,h=s<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,o):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)h=Reflect.decorate(t,e,o,i);else for(var a=t.length-1;a>=0;a--)(n=t[a])&&(h=(s<3?n(h):s>3?n(e,o,h):n(e,o))||h);return s>3&&h&&Object.defineProperty(e,o,h),h}S.scaleResize=function(t,e=t,o){const i=this;o||i.editConfig&&"scale"===i.editConfig.editSize?(i.scaleX*=t,i.scaleY*=e):(t<0&&(i.scaleX*=-1,t=-t),e<0&&(i.scaleY*=-1,e=-e),this.__scaleResize(t,e))},S.__scaleResize=function(t,e){R(this,t,e)},S.resizeWidth=function(t){const e=t/this.getBounds("box","local").width;this.scaleOf(this.__layout.boxBounds,e,this.__.lockRatio?e:1,!0)},S.resizeHeight=function(t){const e=t/this.getBounds("box","local").height;this.scaleOf(this.__layout.boxBounds,this.__.lockRatio?e:1,e,!0)},e.Text.prototype.__scaleResize=function(t,e){this.__.resizeFontSize||this.editConfig&&"font-size"===this.editConfig.editSize?z(this,t,e):R(this,t,e)},e.Path.prototype.__scaleResize=function(t,e){A(this,t,e)},e.Line.prototype.__scaleResize=function(t,e){this.pathInputed?A(this,t,e):this.points?k(this,t,e):this.width*=t},e.Polygon.prototype.__scaleResize=function(t,e){this.pathInputed?A(this,t,e):this.points?k(this,t,e):R(this,t,e)},e.Group.prototype.__scaleResize=function(t,e){F(this,t,e)},e.Box.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?F(this,t,e):(R(this,t,e),this.__.resizeChildren&&F(this,t,e))},"function"==typeof SuppressedError&&SuppressedError;class P extends e.BoxData{}t.Flow=class extends e.Box{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}},v([e.dataProcessor(P)],t.Flow.prototype,"__",void 0),v([e.autoLayoutType("x")],t.Flow.prototype,"flow",void 0),t.Flow=v([e.registerUI()],t.Flow);const H={},X={"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"},C={"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 I(t,o,i){const n=t.__,{contentBounds:s}=t.__layout;e.AlignHelper.toPoint(i,o,s,H),o.x=n.__autoWidth?s.x:H.x,o.y=n.__autoHeight?s.y:H.y}const{move:L}=e.PointHelper;function Y(t,e,o,i,n,s){const{children:h}=t;let a,r,{x:c,start:l}=e,_=i;c+=o;for(let t=0,o=e.count;t<o;t++)a=h[s?l-t:l+t],a.__.inFlow&&0!==a.__.visible?(r=a.__flowBounds,"from"!==n&&(_=i+(e.height-r.height)/("center"===n?2:1)),L(a,c-r.x,_-r.y),c+=r.width+e.gap):o++}function W(t,e,o){const i="width"===o?"height":"width";t[o]=Math.max(t[o],e[o]),t[i]+=t.count?e[i]+t.gap:e[i],t.list.push(e),t.count++}const T={};function O(t,e){const{gap:o,flowAlign:i,flowWrap:n,__autoWidth:s,__autoHeight:h}=t.__,a=n&&(e?!s:!h);return"object"==typeof o?(T.xGap=o.x||0,T.yGap=o.y||0):T.xGap=T.yGap=o,T.isAutoXGap="string"==typeof T.xGap&&!s,T.isAutoYGap="string"==typeof T.yGap&&!h,T.complex=a||"top-left"!==i||t.__hasGrow||T.isAutoXGap||T.isAutoYGap,T.wrap=a,T.complex&&(T.isFitXGap="fit"===T.xGap&&!s,T.isFitYGap="fit"===T.yGap&&!h,"object"==typeof i?(T.contentAlign=i.content||"top-left",T.rowXAlign=i.x||"from",T.rowYAlign=i.y||"from"):(T.contentAlign=i,T.rowXAlign=X[i],T.rowYAlign=C[i])),T}function M(t,e){return{x:0,y:0,width:0,height:0,gap:e,start:t,count:0,grow:0}}function j(t,e,o,i){const{count:n}=t;n>1&&(o>t[e]||i)&&(t.gap=(o-t[e])/(n-1),t[e]=o)}function D(t,e){return"box"===e?t.__local:t.__layout.localStrokeBounds}const{within:E}=e.MathHelper;function N(t,e,o,i){let n,s,h,a=0,r=e.hasRangeSize&&[],{grow:c,start:l}=e;const _=e.width<o?(o-e.width)/c:0,{children:u}=t;_&&(e.width=o);for(let t=0,o=e.count;t<o;t++)n=u[i?l-t:l+t],n.__.inFlow&&0!==n.__.visible?(s=n.__widthGrow)&&(h=U(n,n.__flowBounds,_*s),h?(a+=h,c-=s):r&&(n.__.widthRange?r.unshift(n):r.push(n))):o++;a&&function(t,e,o){let i,n,s,h;t.forEach((t=>{i=t.__widthGrow,n=e/o*i,h=U(t,s=t.__flowBounds,s.width+n),e-=n-h,o-=i}))}(r,a,c)}function U(t,e,o){const{widthRange:i,lockRatio:n}=t.__,s=i?E(o,i):o,h=s/e.width;return t.scaleResize(h,n?h:1),e.width=s,o-s}const{within:Q}=e.MathHelper;function Z(t,e,o,i){let n,s,h,a=0,r=e.hasRangeSize&&[],{grow:c,start:l}=e;const _=e.height<o?(o-e.height)/c:0,{children:u}=t;_&&(e.height=o);for(let t=0,o=e.count;t<o;t++)n=u[i?l-t:l+t],n.__.inFlow&&0!==n.__.visible?(s=n.__heightGrow)&&(h=q(n,n.__flowBounds,_*s),h?(a+=h,c-=s):r&&(n.__.heightRange?r.unshift(n):r.push(n))):o++;a&&function(t,e,o){let i,n,s,h;t.forEach((t=>{i=t.__heightGrow,n=e/o*i,h=q(t,s=t.__flowBounds,s.height+n),e-=n-h,o-=i}))}(r,a,c)}function q(t,e,o){const{heightRange:i,lockRatio:n}=t.__,s=i?Q(o,i):o,h=s/e.height;return t.scaleResize(n?h:1,h),e.height=s,o-s}const{move:J}=e.PointHelper;function K(t,e){const o="width",{children:i,itemBox:n}=t,s=O(t,!0),{complex:h,wrap:a,xGap:r,yGap:c,isAutoXGap:l,isFitXGap:_}=s;if(!i.length)return;const u=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},p=l?0:r;let f,d,g,w,y,{x:x,y:b,width:G,height:B}=t.__layout.contentBounds;for(let s=0,r=i.length;s<r;s++)f=i[w=e?r-1-s:s],f.__.inFlow&&0!==f.__.visible&&(d=D(f,n),h?(f.__flowBounds=d,y||(y=M(w,p)),a&&y.count&&y.width+d.width>G&&(y.grow?N(t,y,G,e):l&&j(y,o,G,_),W(u,y,o),y=M(w,p)),g=d.width,f.__widthGrow&&(y.grow+=f.__widthGrow,g=0,f.__.widthRange&&(y.hasRangeSize=!0)),f.__heightGrow&&q(f,d,B),y.width+=y.count?g+p:g,y.height=Math.max(y.height,d.height),y.count++):(J(f,x-d.x,b-d.y),x+=d.width+p));if(h){const{isAutoYGap:i,isFitYGap:n,contentAlign:h,rowXAlign:r,rowYAlign:p}=s;y.count&&(y.grow?N(t,y,G,e):l&&j(y,o,G,_),a&&W(u,y,o)),a?(i?j(u,"height",B,n):u.gap=c,function(t,e,o,i){I(t,e,o);const{list:n}=e;if(n.length>1&&(i||(i=X[o]),"from"!==i)){let t;for(let o=0,s=n.length;o<s;o++)t=n[o],t.x=e.width-t.width,"center"===i&&(t.x/=2)}}(t,u,h,r),function(t,e,o,i){const{list:n}=e,s="reverse"===t.__.flowWrap;let h,{x:a,y:r}=e;for(let c=0,l=n.length;c<l;c++)h=n[s?l-1-c:c],Y(t,h,a,r,o,i),r+=h.height+e.gap}(t,u,p,e)):(I(t,y,h),Y(t,y,0,y.y,p,e))}}const{move:V}=e.PointHelper;function $(t,e,o,i,n,s){const{children:h}=t;let a,r,{y:c,start:l}=e,_=o;c+=i;for(let t=0,i=e.count;t<i;t++)a=h[s?l-t:l+t],a.__.inFlow&&0!==a.__.visible?(r=a.__flowBounds,"from"!==n&&(_=o+(e.width-r.width)/("center"===n?2:1)),V(a,_-r.x,c-r.y),c+=r.height+e.gap):i++}const{move:tt}=e.PointHelper;function et(t,e){const o="height",{children:i,itemBox:n}=t,s=O(t,!1),{complex:h,wrap:a,xGap:r,yGap:c,isAutoYGap:l,isFitYGap:_}=s;if(!i.length)return;const u=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},p=l?0:c;let f,d,g,w,y,{x:x,y:b,width:G,height:B}=t.__layout.contentBounds;for(let s=0,r=i.length;s<r;s++)f=i[w=e?r-1-s:s],f.__.inFlow&&0!==f.__.visible&&(d=D(f,n),h?(f.__flowBounds=d,y||(y=M(w,p)),a&&y.count&&y.height+d.height>B&&(y.grow&&Z(t,y,B,e),l&&j(y,o,B,_),W(u,y,o),y=M(w,p)),g=d.height,f.__heightGrow&&(y.grow+=f.__heightGrow,g=0,f.__.heightRange&&(y.hasRangeSize=!0)),f.__widthGrow&&U(f,d,G),y.height+=y.count?g+p:g,y.width=Math.max(y.width,d.width),y.count++):(tt(f,x-d.x,b-d.y),b+=d.height+p));if(h){const{isAutoXGap:i,isFitXGap:n,contentAlign:h,rowXAlign:c,rowYAlign:p}=s;y.count&&(y.grow&&Z(t,y,B,e),l&&j(y,o,B,_),a&&W(u,y,o)),a?(i?j(u,"width",G,n):u.gap=r,function(t,e,o,i){I(t,e,o);const{list:n}=e;if(n.length>1&&(i||(i=C[o]),"from"!==i)){let t;for(let o=0,s=n.length;o<s;o++)t=n[o],t.y=e.height-t.height,"center"===i&&(t.y/=2)}}(t,u,h,p),function(t,e,o,i){const{list:n}=e,s="reverse"===t.__.flowWrap;let h,{x:a,y:r}=e;for(let c=0,l=n.length;c<l;c++)h=n[s?l-1-c:c],$(t,h,a,r,o,i),a+=h.width+e.gap}(t,u,c,e)):(I(t,y,h),$(t,y,y.x,0,c,e))}}function ot(t){return e.decorateLeafAttr(t,(t=>e.attr({set(o){const i="number"==typeof o?o:0;"autoWidth"===t?this.__widthGrow=i:this.__heightGrow=i,!i||this.parent&&this.parent.__hasGrow||this.waitParent((()=>{this.parent.__hasGrow=!0})),this.__setAttr(t,o)&&e.doBoundsType(this)}})))}const it=e.UI.prototype,nt=e.Box.prototype,{__updateBoxBounds:st}=e.Group.prototype;e.autoLayoutType(!1)(it,"flow"),e.boundsType(0)(it,"gap"),e.boundsType("top-left")(it,"flowAlign"),e.boundsType(!1)(it,"flowWrap"),e.boundsType("box")(it,"itemBox"),e.boundsType(!0)(it,"inFlow"),ot()(it,"autoWidth"),ot()(it,"autoHeight"),e.boundsType()(it,"autoBox");const{copyAndSpread:ht}=e.BoundsHelper;return nt.__updateFlowLayout=function(){const{leaferIsCreated:t,flow:e}=this;switch(t&&(this.leafer.created=!1),e){case"x":case!0:K(this);break;case"y":et(this);break;case"x-reverse":K(this,!0);break;case"y-reverse":et(this,!0)}t&&(this.leafer.created=!0)},nt.__updateContentBounds=function(){const{padding:t}=this.__,e=this.__layout,o=e.contentBounds===e.boxBounds;t?(o&&e.shrinkContent(),ht(e.contentBounds,e.boxBounds,t,!0)):o||e.shrinkContentCancel()},nt.__updateBoxBounds=function(t){const e=this.__;if(this.children.length){const{flow:o}=e;if(e.__autoSide){o&&!t?this.__updateRectBoxBounds():st.call(this);const{boxBounds:i}=this.__layout;e.__autoSize||(e.__autoWidth?(o||(i.width+=i.x,i.x=0),i.height=e.height,i.y=0):(o||(i.height+=i.y,i.y=0),i.width=e.width,i.x=0)),o&&t&&e.padding&&ht(i,i,e.padding,!1,e.__autoSize?null:e.__autoWidth?"width":"height"),this.__updateNaturalSize()}else this.__updateRectBoxBounds();o&&this.__updateContentBounds()}else this.__updateRectBoxBounds()},t.PathScaler=d,t.scaleResize=R,t.scaleResizeFontSize=z,t.scaleResizeGroup=F,t.scaleResizePath=A,t.scaleResizePoints=k,t}({},LeaferUI);
1
+ this.LeaferIN=this.LeaferIN||{},this.LeaferIN.flow=function(t,o){"use strict";function e(t,o,e,i){var n,h=arguments.length,r=h<3?o:null===i?i=Object.getOwnPropertyDescriptor(o,e):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,o,e,i);else for(var s=t.length-1;s>=0;s--)(n=t[s])&&(r=(h<3?n(r):h>3?n(o,e,r):n(o,e))||r);return h>3&&r&&Object.defineProperty(o,e,r),r}"function"==typeof SuppressedError&&SuppressedError;class i extends o.BoxData{}t.Flow=class extends o.Box{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}},e([o.dataProcessor(i)],t.Flow.prototype,"__",void 0),e([o.autoLayoutType("x")],t.Flow.prototype,"flow",void 0),t.Flow=e([o.registerUI()],t.Flow);const n={},h={"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"},r={"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,e,i){const h=t.__,{contentBounds:r}=t.__layout;o.AlignHelper.toPoint(i,e,r,n),e.x=h.__autoWidth?r.x:n.x,e.y=h.__autoHeight?r.y:n.y}const{move:a}=o.PointHelper;function l(t,o,e,i,n,h){const{children:r}=t;let s,l,{x:c,start:_}=o,u=i;c+=e;for(let t=0,e=o.count;t<e;t++)s=r[h?_-t:_+t],s.__.inFlow&&0!==s.__.visible?(l=s.__flowBounds,"from"!==n&&(u=i+(o.height-l.height)/("center"===n?2:1)),a(s,c-l.x,u-l.y),c+=l.width+o.gap):e++}function c(t,o,e){const i="width"===e?"height":"width";t[e]=Math.max(t[e],o[e]),t[i]+=t.count?o[i]+t.gap:o[i],t.list.push(o),t.count++}const _={};function u(t,o){const{gap:e,flowAlign:i,flowWrap:n,__autoWidth:s,__autoHeight:a}=t.__,l=n&&(o?!s:!a);return"object"==typeof e?(_.xGap=e.x||0,_.yGap=e.y||0):_.xGap=_.yGap=e,_.isAutoXGap="string"==typeof _.xGap&&!s,_.isAutoYGap="string"==typeof _.yGap&&!a,_.complex=l||"top-left"!==i||t.__hasGrow||_.isAutoXGap||_.isAutoYGap,_.wrap=l,_.complex&&(_.isFitXGap="fit"===_.xGap&&!s,_.isFitYGap="fit"===_.yGap&&!a,"object"==typeof i?(_.contentAlign=i.content||"top-left",_.rowXAlign=i.x||"from",_.rowYAlign=i.y||"from"):(_.contentAlign=i,_.rowXAlign=h[i],_.rowYAlign=r[i])),_}function p(t,o){return{x:0,y:0,width:0,height:0,gap:o,start:t,count:0,grow:0}}function g(t,o,e,i){const{count:n}=t;n>1&&(e>t[o]||i)&&(t.gap=(e-t[o])/(n-1),t[o]=e)}function d(t,o){return"box"===o?t.__local:t.__layout.localStrokeBounds}const{within:f}=o.MathHelper;function w(t,o,e,i){let n,h,r,s=0,a=o.hasRangeSize&&[],{grow:l,start:c}=o;const _=o.width<e?(e-o.width)/l:0,{children:u}=t;_&&(o.width=e);for(let t=0,e=o.count;t<e;t++)n=u[i?c-t:c+t],n.__.inFlow&&0!==n.__.visible?(h=n.__widthGrow)&&(r=y(n,n.__flowBounds,_*h),r?(s+=r,l-=h):a&&(n.__.widthRange?a.unshift(n):a.push(n))):e++;s&&function(t,o,e){let i,n,h,r;t.forEach((t=>{i=t.__widthGrow,n=o/e*i,r=y(t,h=t.__flowBounds,h.width+n),o-=n-r,e-=i}))}(a,s,l)}function y(t,o,e){const{widthRange:i,lockRatio:n}=t.__,h=i?f(e,i):e,r=h/o.width;return t.scaleResize(r,n?r:1),o.width=h,e-h}const{within:x}=o.MathHelper;function G(t,o,e,i){let n,h,r,s=0,a=o.hasRangeSize&&[],{grow:l,start:c}=o;const _=o.height<e?(e-o.height)/l:0,{children:u}=t;_&&(o.height=e);for(let t=0,e=o.count;t<e;t++)n=u[i?c-t:c+t],n.__.inFlow&&0!==n.__.visible?(h=n.__heightGrow)&&(r=b(n,n.__flowBounds,_*h),r?(s+=r,l-=h):a&&(n.__.heightRange?a.unshift(n):a.push(n))):e++;s&&function(t,o,e){let i,n,h,r;t.forEach((t=>{i=t.__heightGrow,n=o/e*i,r=b(t,h=t.__flowBounds,h.height+n),o-=n-r,e-=i}))}(a,s,l)}function b(t,o,e){const{heightRange:i,lockRatio:n}=t.__,h=i?x(e,i):e,r=h/o.height;return t.scaleResize(n?r:1,r),o.height=h,e-h}const{move:B}=o.PointHelper;function m(t,o){const e="width",{children:i,itemBox:n}=t,r=u(t,!0),{complex:a,wrap:_,xGap:f,yGap:y,isAutoXGap:x,isFitXGap:G}=r;if(!i.length)return;const m=_&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},A=x?0:f;let F,R,v,S,H,{x:X,y:Y,width:W,height:z}=t.__layout.contentBounds;for(let h=0,r=i.length;h<r;h++)F=i[S=o?r-1-h:h],F.__.inFlow&&0!==F.__.visible&&(R=d(F,n),a?(F.__flowBounds=R,H||(H=p(S,A)),_&&H.count&&H.width+R.width>W&&(H.grow?w(t,H,W,o):x&&g(H,e,W,G),c(m,H,e),H=p(S,A)),v=R.width,F.__widthGrow&&(H.grow+=F.__widthGrow,v=0,F.__.widthRange&&(H.hasRangeSize=!0)),F.__heightGrow&&b(F,R,z),H.width+=H.count?v+A:v,H.height=Math.max(H.height,R.height),H.count++):(B(F,X-R.x,Y-R.y),X+=R.width+A));if(a&&H){const{isAutoYGap:i,isFitYGap:n,contentAlign:a,rowXAlign:u,rowYAlign:p}=r;H.count&&(H.grow?w(t,H,W,o):x&&g(H,e,W,G),_&&c(m,H,e)),_?(i?g(m,"height",z,n):m.gap=y,function(t,o,e,i){s(t,o,e);const{list:n}=o;if(n.length>1&&(i||(i=h[e]),"from"!==i)){let t;for(let e=0,h=n.length;e<h;e++)t=n[e],t.x=o.width-t.width,"center"===i&&(t.x/=2)}}(t,m,a,u),function(t,o,e,i){const{list:n}=o,h="reverse"===t.__.flowWrap;let r,{x:s,y:a}=o;for(let c=0,_=n.length;c<_;c++)r=n[h?_-1-c:c],l(t,r,s,a,e,i),a+=r.height+o.gap}(t,m,p,o)):(s(t,H,a),l(t,H,0,H.y,p,o))}}const{move:A}=o.PointHelper;function F(t,o,e,i,n,h){const{children:r}=t;let s,a,{y:l,start:c}=o,_=e;l+=i;for(let t=0,i=o.count;t<i;t++)s=r[h?c-t:c+t],s.__.inFlow&&0!==s.__.visible?(a=s.__flowBounds,"from"!==n&&(_=e+(o.width-a.width)/("center"===n?2:1)),A(s,_-a.x,l-a.y),l+=a.height+o.gap):i++}const{move:R}=o.PointHelper;function v(t,o){const e="height",{children:i,itemBox:n}=t,h=u(t,!1),{complex:a,wrap:l,xGap:_,yGap:f,isAutoYGap:w,isFitYGap:x}=h;if(!i.length)return;const b=l&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},B=w?0:f;let m,A,v,S,H,{x:X,y:Y,width:W,height:z}=t.__layout.contentBounds;for(let h=0,r=i.length;h<r;h++)m=i[S=o?r-1-h:h],m.__.inFlow&&0!==m.__.visible&&(A=d(m,n),a?(m.__flowBounds=A,H||(H=p(S,B)),l&&H.count&&H.height+A.height>z&&(H.grow&&G(t,H,z,o),w&&g(H,e,z,x),c(b,H,e),H=p(S,B)),v=A.height,m.__heightGrow&&(H.grow+=m.__heightGrow,v=0,m.__.heightRange&&(H.hasRangeSize=!0)),m.__widthGrow&&y(m,A,W),H.height+=H.count?v+B:v,H.width=Math.max(H.width,A.width),H.count++):(R(m,X-A.x,Y-A.y),Y+=A.height+B));if(a&&H){const{isAutoXGap:i,isFitXGap:n,contentAlign:a,rowXAlign:u,rowYAlign:p}=h;H.count&&(H.grow&&G(t,H,z,o),w&&g(H,e,z,x),l&&c(b,H,e)),l?(i?g(b,"width",W,n):b.gap=_,function(t,o,e,i){s(t,o,e);const{list:n}=o;if(n.length>1&&(i||(i=r[e]),"from"!==i)){let t;for(let e=0,h=n.length;e<h;e++)t=n[e],t.y=o.height-t.height,"center"===i&&(t.y/=2)}}(t,b,a,p),function(t,o,e,i){const{list:n}=o,h="reverse"===t.__.flowWrap;let r,{x:s,y:a}=o;for(let l=0,c=n.length;l<c;l++)r=n[h?c-1-l:l],F(t,r,s,a,e,i),s+=r.width+o.gap}(t,b,u,o)):(s(t,H,a),F(t,H,H.x,0,u,o))}}function S(t){return o.decorateLeafAttr(t,(t=>o.attr({set(e){const i="number"==typeof e?e:0;"autoWidth"===t?this.__widthGrow=i:this.__heightGrow=i,!i||this.parent&&this.parent.__hasGrow||this.waitParent((()=>{this.parent.__hasGrow=!0})),this.__setAttr(t,e)&&o.doBoundsType(this)}})))}const H=o.UI.prototype,X=o.Box.prototype,{__updateBoxBounds:Y}=o.Group.prototype;o.autoLayoutType(!1)(H,"flow"),o.boundsType(0)(H,"gap"),o.boundsType("top-left")(H,"flowAlign"),o.boundsType(!1)(H,"flowWrap"),o.boundsType("box")(H,"itemBox"),o.boundsType(!0)(H,"inFlow"),S()(H,"autoWidth"),S()(H,"autoHeight"),o.boundsType()(H,"autoBox");const{copyAndSpread:W}=o.BoundsHelper;return X.__updateFlowLayout=function(){const{leaferIsCreated:t,flow:o}=this;switch(t&&(this.leafer.created=!1),o){case"x":case!0:m(this);break;case"y":v(this);break;case"x-reverse":m(this,!0);break;case"y-reverse":v(this,!0)}t&&(this.leafer.created=!0)},X.__updateContentBounds=function(){const{padding:t}=this.__,o=this.__layout,e=o.contentBounds===o.boxBounds;t?(e&&o.shrinkContent(),W(o.contentBounds,o.boxBounds,t,!0)):e||o.shrinkContentCancel()},X.__updateBoxBounds=function(t){const o=this.__;if(this.children.length){const{flow:e}=o;if(o.__autoSide){e&&!t?this.__updateRectBoxBounds():Y.call(this);const{boxBounds:i}=this.__layout;o.__autoSize||(o.__autoWidth?(e||(i.width+=i.x,i.x=0),i.height=o.height,i.y=0):(e||(i.height+=i.y,i.y=0),i.width=o.width,i.x=0)),e&&t&&o.padding&&W(i,i,o.padding,!1,o.__autoSize?null:o.__autoWidth?"width":"height"),this.__updateNaturalSize()}else this.__updateRectBoxBounds();e&&this.__updateContentBounds()}else this.__updateRectBoxBounds()},t}({},LeaferUI);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-in/flow",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "@leafer-in/flow",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -34,9 +34,9 @@
34
34
  "leaferjs"
35
35
  ],
36
36
  "peerDependencies": {
37
- "@leafer-ui/draw": "^1.1.0",
38
- "@leafer-in/resize": "^1.1.0",
39
- "@leafer-ui/interface": "^1.1.0",
40
- "@leafer-in/interface": "^1.1.0"
37
+ "@leafer-ui/draw": "^1.1.2",
38
+ "@leafer-in/resize": "^1.1.2",
39
+ "@leafer-ui/interface": "^1.1.2",
40
+ "@leafer-in/interface": "^1.1.2"
41
41
  }
42
42
  }
package/src/index.ts CHANGED
@@ -1,9 +1,10 @@
1
- export * from '@leafer-in/resize'
2
-
3
1
  export { Flow } from './Flow'
4
2
 
3
+
5
4
  import { BoundsHelper, Box, Group, UI, autoLayoutType, boundsType } from '@leafer-ui/draw'
6
5
 
6
+ import '@leafer-in/resize'
7
+
7
8
  import { flowX } from './layout/flowX'
8
9
  import { flowY } from './layout/flowY'
9
10
  import { autoBoundsType } from './decorate'
@@ -70,7 +70,7 @@ export function flowX(box: IBox, reverse?: boolean): void {
70
70
 
71
71
  }
72
72
 
73
- if (complex) {
73
+ if (complex && data) {
74
74
 
75
75
  const { isAutoYGap, isFitYGap, contentAlign, rowXAlign, rowYAlign } = pData
76
76
 
@@ -68,7 +68,7 @@ export function flowY(box: IBox, reverse?: boolean): void {
68
68
 
69
69
  }
70
70
 
71
- if (complex) {
71
+ if (complex && data) {
72
72
 
73
73
  const { isAutoXGap, isFitXGap, contentAlign, rowXAlign, rowYAlign } = pData
74
74