@leafer-in/flow 1.0.2 → 1.0.4
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 +30 -21
- package/dist/flow.esm.js +31 -22
- package/dist/flow.esm.min.js +1 -1
- package/dist/flow.js +30 -21
- package/dist/flow.min.cjs +1 -1
- package/dist/flow.min.js +1 -1
- package/package.json +5 -5
- package/src/index.ts +22 -6
- package/src/layout/common/align.ts +4 -3
package/dist/flow.cjs
CHANGED
|
@@ -13,9 +13,6 @@ const PathScaler = {
|
|
|
13
13
|
command = data[i];
|
|
14
14
|
switch (command) {
|
|
15
15
|
case M:
|
|
16
|
-
scalePoints(data, scaleX, scaleY, i, 1);
|
|
17
|
-
i += 3;
|
|
18
|
-
break;
|
|
19
16
|
case L:
|
|
20
17
|
scalePoints(data, scaleX, scaleY, i, 1);
|
|
21
18
|
i += 3;
|
|
@@ -97,34 +94,34 @@ function scaleResize(leaf, scaleX, scaleY) {
|
|
|
97
94
|
function scaleResizeFontSize(leaf, scaleX, scaleY) {
|
|
98
95
|
const { app } = leaf;
|
|
99
96
|
const editor = app && app.editor;
|
|
97
|
+
let fontScale = scaleX;
|
|
100
98
|
if (editor.editing) {
|
|
101
99
|
const layout = leaf.__layout;
|
|
102
100
|
let { width, height } = layout.boxBounds;
|
|
103
|
-
width *=
|
|
104
|
-
height *=
|
|
101
|
+
width *= scaleY - scaleX;
|
|
102
|
+
height *= scaleX - scaleY;
|
|
105
103
|
switch (editor.resizeDirection) {
|
|
106
104
|
case top:
|
|
107
105
|
case bottom:
|
|
108
|
-
|
|
106
|
+
fontScale = scaleY;
|
|
109
107
|
layout.affectScaleOrRotation ? leaf.moveInner(-width / 2, 0) : leaf.x -= width / 2;
|
|
110
108
|
break;
|
|
111
109
|
case left:
|
|
112
110
|
case right:
|
|
113
|
-
leaf.fontSize *= scaleX;
|
|
114
111
|
layout.affectScaleOrRotation ? leaf.moveInner(0, -height / 2) : leaf.y -= height / 2;
|
|
115
112
|
break;
|
|
116
113
|
case topLeft:
|
|
117
114
|
case topRight:
|
|
118
|
-
leaf.fontSize *= scaleX;
|
|
119
115
|
layout.affectScaleOrRotation ? leaf.moveInner(0, -height) : leaf.y -= height;
|
|
120
116
|
break;
|
|
121
|
-
default:
|
|
122
|
-
leaf.fontSize *= scaleX;
|
|
123
117
|
}
|
|
124
118
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
119
|
+
leaf.fontSize *= fontScale;
|
|
120
|
+
const data = leaf.__;
|
|
121
|
+
if (!data.__autoWidth)
|
|
122
|
+
leaf.width *= fontScale;
|
|
123
|
+
if (!data.__autoHeight)
|
|
124
|
+
leaf.height *= fontScale;
|
|
128
125
|
}
|
|
129
126
|
function scaleResizePath(leaf, scaleX, scaleY) {
|
|
130
127
|
PathScaler.scale(leaf.__.path, scaleX, scaleY);
|
|
@@ -170,7 +167,7 @@ leaf.resizeHeight = function (height) {
|
|
|
170
167
|
this.scaleOf(this.__layout.boxBounds, this.__.lockRatio ? scale : 1, scale, true);
|
|
171
168
|
};
|
|
172
169
|
draw.Text.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
173
|
-
if (this.__.
|
|
170
|
+
if (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size')) {
|
|
174
171
|
scaleResizeFontSize(this, scaleX, scaleY);
|
|
175
172
|
}
|
|
176
173
|
else {
|
|
@@ -295,10 +292,11 @@ const alignToInnerYMap = {
|
|
|
295
292
|
'baseline-right': 'to',
|
|
296
293
|
};
|
|
297
294
|
function alignContent(box, content, align) {
|
|
298
|
-
draw.AlignHelper.toPoint(align, content, box.__layout.contentBounds, point);
|
|
299
295
|
const data = box.__;
|
|
300
|
-
|
|
301
|
-
|
|
296
|
+
const { contentBounds } = box.__layout;
|
|
297
|
+
draw.AlignHelper.toPoint(align, content, contentBounds, point);
|
|
298
|
+
content.x = data.__autoWidth ? contentBounds.x : point.x;
|
|
299
|
+
content.y = data.__autoHeight ? contentBounds.y : point.y;
|
|
302
300
|
}
|
|
303
301
|
|
|
304
302
|
function align$1(box, data, contentAlign, innerXAlign) {
|
|
@@ -691,11 +689,22 @@ function autoBoundsType(defaultValue) {
|
|
|
691
689
|
}));
|
|
692
690
|
}
|
|
693
691
|
|
|
692
|
+
const ui = draw.UI.prototype, box = draw.Box.prototype;
|
|
693
|
+
draw.autoLayoutType(false)(ui, 'flow');
|
|
694
|
+
draw.boundsType(0)(ui, 'gap');
|
|
695
|
+
draw.boundsType('top-left')(ui, 'flowAlign');
|
|
696
|
+
draw.boundsType(false)(ui, 'flowWrap');
|
|
697
|
+
draw.boundsType('box')(ui, 'itemBox');
|
|
698
|
+
draw.boundsType(true)(ui, 'inFlow');
|
|
699
|
+
autoBoundsType()(ui, 'autoWidth');
|
|
700
|
+
autoBoundsType()(ui, 'autoHeight');
|
|
701
|
+
draw.boundsType()(ui, 'lockRatio');
|
|
702
|
+
draw.boundsType()(ui, 'autoBox');
|
|
703
|
+
draw.boundsType()(ui, 'widthRange');
|
|
704
|
+
draw.boundsType()(ui, 'heightRange');
|
|
694
705
|
const { copyAndSpread } = draw.BoundsHelper;
|
|
695
706
|
let doFlowX = flowX, doFlowY = flowY;
|
|
696
|
-
|
|
697
|
-
draw.UI.changeAttr('autoHeight', undefined, autoBoundsType);
|
|
698
|
-
draw.Box.prototype.__updateFlowLayout = function () {
|
|
707
|
+
box.__updateFlowLayout = function () {
|
|
699
708
|
this.leafer.created = false;
|
|
700
709
|
const { flow } = this.__;
|
|
701
710
|
switch (flow) {
|
|
@@ -715,7 +724,7 @@ draw.Box.prototype.__updateFlowLayout = function () {
|
|
|
715
724
|
}
|
|
716
725
|
this.leafer.created = true;
|
|
717
726
|
};
|
|
718
|
-
|
|
727
|
+
box.__updateContentBounds = function () {
|
|
719
728
|
const { padding } = this.__;
|
|
720
729
|
const layout = this.__layout;
|
|
721
730
|
const same = layout.contentBounds === layout.boxBounds;
|
package/dist/flow.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PathCommandMap, MatrixHelper, Direction9, Leaf, Text, Path, Line, Polygon, Group, Box, BoxData, dataProcessor, autoLayoutType, registerUI, AlignHelper, PointHelper, MathHelper, decorateLeafAttr, attr, doBoundsType, UI, BoundsHelper } from '@leafer-ui/draw';
|
|
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
2
|
|
|
3
3
|
const { M, L, C, Q, Z, N, D, X, G, F, O, P, U } = PathCommandMap;
|
|
4
4
|
const PathScaler = {
|
|
@@ -11,9 +11,6 @@ const PathScaler = {
|
|
|
11
11
|
command = data[i];
|
|
12
12
|
switch (command) {
|
|
13
13
|
case M:
|
|
14
|
-
scalePoints(data, scaleX, scaleY, i, 1);
|
|
15
|
-
i += 3;
|
|
16
|
-
break;
|
|
17
14
|
case L:
|
|
18
15
|
scalePoints(data, scaleX, scaleY, i, 1);
|
|
19
16
|
i += 3;
|
|
@@ -95,34 +92,34 @@ function scaleResize(leaf, scaleX, scaleY) {
|
|
|
95
92
|
function scaleResizeFontSize(leaf, scaleX, scaleY) {
|
|
96
93
|
const { app } = leaf;
|
|
97
94
|
const editor = app && app.editor;
|
|
95
|
+
let fontScale = scaleX;
|
|
98
96
|
if (editor.editing) {
|
|
99
97
|
const layout = leaf.__layout;
|
|
100
98
|
let { width, height } = layout.boxBounds;
|
|
101
|
-
width *=
|
|
102
|
-
height *=
|
|
99
|
+
width *= scaleY - scaleX;
|
|
100
|
+
height *= scaleX - scaleY;
|
|
103
101
|
switch (editor.resizeDirection) {
|
|
104
102
|
case top:
|
|
105
103
|
case bottom:
|
|
106
|
-
|
|
104
|
+
fontScale = scaleY;
|
|
107
105
|
layout.affectScaleOrRotation ? leaf.moveInner(-width / 2, 0) : leaf.x -= width / 2;
|
|
108
106
|
break;
|
|
109
107
|
case left:
|
|
110
108
|
case right:
|
|
111
|
-
leaf.fontSize *= scaleX;
|
|
112
109
|
layout.affectScaleOrRotation ? leaf.moveInner(0, -height / 2) : leaf.y -= height / 2;
|
|
113
110
|
break;
|
|
114
111
|
case topLeft:
|
|
115
112
|
case topRight:
|
|
116
|
-
leaf.fontSize *= scaleX;
|
|
117
113
|
layout.affectScaleOrRotation ? leaf.moveInner(0, -height) : leaf.y -= height;
|
|
118
114
|
break;
|
|
119
|
-
default:
|
|
120
|
-
leaf.fontSize *= scaleX;
|
|
121
115
|
}
|
|
122
116
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
117
|
+
leaf.fontSize *= fontScale;
|
|
118
|
+
const data = leaf.__;
|
|
119
|
+
if (!data.__autoWidth)
|
|
120
|
+
leaf.width *= fontScale;
|
|
121
|
+
if (!data.__autoHeight)
|
|
122
|
+
leaf.height *= fontScale;
|
|
126
123
|
}
|
|
127
124
|
function scaleResizePath(leaf, scaleX, scaleY) {
|
|
128
125
|
PathScaler.scale(leaf.__.path, scaleX, scaleY);
|
|
@@ -168,7 +165,7 @@ leaf.resizeHeight = function (height) {
|
|
|
168
165
|
this.scaleOf(this.__layout.boxBounds, this.__.lockRatio ? scale : 1, scale, true);
|
|
169
166
|
};
|
|
170
167
|
Text.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
171
|
-
if (this.__.
|
|
168
|
+
if (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size')) {
|
|
172
169
|
scaleResizeFontSize(this, scaleX, scaleY);
|
|
173
170
|
}
|
|
174
171
|
else {
|
|
@@ -293,10 +290,11 @@ const alignToInnerYMap = {
|
|
|
293
290
|
'baseline-right': 'to',
|
|
294
291
|
};
|
|
295
292
|
function alignContent(box, content, align) {
|
|
296
|
-
AlignHelper.toPoint(align, content, box.__layout.contentBounds, point);
|
|
297
293
|
const data = box.__;
|
|
298
|
-
|
|
299
|
-
|
|
294
|
+
const { contentBounds } = box.__layout;
|
|
295
|
+
AlignHelper.toPoint(align, content, contentBounds, point);
|
|
296
|
+
content.x = data.__autoWidth ? contentBounds.x : point.x;
|
|
297
|
+
content.y = data.__autoHeight ? contentBounds.y : point.y;
|
|
300
298
|
}
|
|
301
299
|
|
|
302
300
|
function align$1(box, data, contentAlign, innerXAlign) {
|
|
@@ -689,11 +687,22 @@ function autoBoundsType(defaultValue) {
|
|
|
689
687
|
}));
|
|
690
688
|
}
|
|
691
689
|
|
|
690
|
+
const ui = UI.prototype, box = Box.prototype;
|
|
691
|
+
autoLayoutType(false)(ui, 'flow');
|
|
692
|
+
boundsType(0)(ui, 'gap');
|
|
693
|
+
boundsType('top-left')(ui, 'flowAlign');
|
|
694
|
+
boundsType(false)(ui, 'flowWrap');
|
|
695
|
+
boundsType('box')(ui, 'itemBox');
|
|
696
|
+
boundsType(true)(ui, 'inFlow');
|
|
697
|
+
autoBoundsType()(ui, 'autoWidth');
|
|
698
|
+
autoBoundsType()(ui, 'autoHeight');
|
|
699
|
+
boundsType()(ui, 'lockRatio');
|
|
700
|
+
boundsType()(ui, 'autoBox');
|
|
701
|
+
boundsType()(ui, 'widthRange');
|
|
702
|
+
boundsType()(ui, 'heightRange');
|
|
692
703
|
const { copyAndSpread } = BoundsHelper;
|
|
693
704
|
let doFlowX = flowX, doFlowY = flowY;
|
|
694
|
-
|
|
695
|
-
UI.changeAttr('autoHeight', undefined, autoBoundsType);
|
|
696
|
-
Box.prototype.__updateFlowLayout = function () {
|
|
705
|
+
box.__updateFlowLayout = function () {
|
|
697
706
|
this.leafer.created = false;
|
|
698
707
|
const { flow } = this.__;
|
|
699
708
|
switch (flow) {
|
|
@@ -713,7 +722,7 @@ Box.prototype.__updateFlowLayout = function () {
|
|
|
713
722
|
}
|
|
714
723
|
this.leafer.created = true;
|
|
715
724
|
};
|
|
716
|
-
|
|
725
|
+
box.__updateContentBounds = function () {
|
|
717
726
|
const { padding } = this.__;
|
|
718
727
|
const layout = this.__layout;
|
|
719
728
|
const same = layout.contentBounds === layout.boxBounds;
|
package/dist/flow.esm.min.js
CHANGED
|
@@ -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 r,Box as a,BoxData as l,dataProcessor as _,autoLayoutType as f,registerUI as u,AlignHelper as g,PointHelper as p,MathHelper as d,decorateLeafAttr as w,attr as y,doBoundsType as b,UI as x,BoundsHelper as G}from"@leafer-ui/draw";const{M:m,L:R,C:z,Q:A,Z:k,N:B,D:v,X:S,G:F,F:X,O:Y,P:C,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 m:case R:W(t,e,o,n,1),n+=3;break;case z:W(t,e,o,n,3),n+=7;break;case A:W(t,e,o,n,2),n+=5;break;case k:n+=1;break;case B:W(t,e,o,n,2),n+=5;break;case v:W(t,e,o,n,2),n+=9;break;case S:W(t,e,o,n,2),n+=6;break;case F:W(t,e,o,n,2),n+=9;break;case X:W(t,e,o,n,2),n+=5;break;case Y:t[n]=F,t.splice(n+4,0,t[n+3],0),W(t,e,o,n,2),n+=9,s+=2;break;case C:t[n]=X,t.splice(n+4,0,t[n+3]),W(t,e,o,n,2),n+=5,s+=1;break;case O:W(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:W}=P,I=e.get(),{topLeft:j,top:E,topRight:H,right:L,bottom:M,left:D}=o;function N(t,e,o){t.pathInputed?U(t,e,o):(1!==e&&(t.width*=e),1!==o&&(t.height*=o))}function Q(t,e,o){const{app:i}=t,n=i&&i.editor;if(n.editing){const i=t.__layout;let{width:s,height:h}=i.boxBounds;switch(s*=(o-e)*(t.scaleX<0?-1:1),h*=(e-o)*(t.scaleY<0?-1:1),n.resizeDirection){case E:case M:t.fontSize*=o,i.affectScaleOrRotation?t.moveInner(-s/2,0):t.x-=s/2;break;case D:case L:t.fontSize*=e,i.affectScaleOrRotation?t.moveInner(0,-h/2):t.y-=h/2;break;case j:case H:t.fontSize*=e,i.affectScaleOrRotation?t.moveInner(0,-h):t.y-=h;break;default:t.fontSize*=e}}else t.fontSize*=e}function U(t,e,o){P.scale(t.__.path,e,o),t.path=t.__.path}function Z(t,e,o){P.scalePoints(t.__.points,e,o),t.points=t.__.points}function q(t,e,o){const{children:i}=t;for(let t=0;t<i.length;t++)I.a=e,I.d=o,i[t].transform(I,!0)}const J=i.prototype;function K(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}J.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))},J.__scaleResize=function(t,e){N(this,t,e)},J.resizeWidth=function(t){const e=t/this.getBounds("box","local").width;this.scaleOf(this.__layout.boxBounds,e,this.__.lockRatio?e:1,!0)},J.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.__.__autoSize&&(this.__.resizeFontSize||this.editConfig&&"font-size"===this.editConfig.editSize)?Q(this,t,e):N(this,t,e)},s.prototype.__scaleResize=function(t,e){U(this,t,e)},h.prototype.__scaleResize=function(t,e){this.pathInputed?U(this,t,e):this.points?Z(this,t,e):this.width*=t},c.prototype.__scaleResize=function(t,e){this.pathInputed?U(this,t,e):this.points?Z(this,t,e):N(this,t,e)},r.prototype.__scaleResize=function(t,e){q(this,t,e)},a.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?q(this,t,e):(N(this,t,e),this.__.resizeChildren&&q(this,t,e))},"function"==typeof SuppressedError&&SuppressedError;let T=class extends a{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}};K([_(class extends l{})],T.prototype,"__",void 0),K([f("x")],T.prototype,"flow",void 0),T=K([u()],T);const V={},$={"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"},tt={"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 et(t,e,o){g.toPoint(o,e,t.__layout.contentBounds,V);const i=t.__;e.x=i.__autoWidth?0:V.x,e.y=i.__autoHeight?0:V.y}const{move:ot}=p;function it(t,e,o,i,n,s){const{children:h}=t;let c,r,{x:a,start:l}=e,_=i;a+=o;for(let t=0,o=e.count;t<o;t++)c=h[s?l-t:l+t],c.__.inFlow&&0!==c.__.visible?(r=c.__flowBounds,"from"!==n&&(_=i+(e.height-r.height)/("center"===n?2:1)),ot(c,a-r.x,_-r.y),a+=r.width+e.gap):o++}function nt(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 st={};function ht(t,e){const{gap:o,flowAlign:i,flowWrap:n,__autoWidth:s,__autoHeight:h}=t.__,c=n&&(e?!s:!h);return"object"==typeof o?(st.xGap=o.x||0,st.yGap=o.y||0):st.xGap=st.yGap=o,st.isAutoXGap="string"==typeof st.xGap&&!s,st.isAutoYGap="string"==typeof st.yGap&&!h,st.complex=c||"top-left"!==i||t.__hasGrow||st.isAutoXGap||st.isAutoYGap,st.wrap=c,st.complex&&(st.isFitXGap="fit"===st.xGap&&!s,st.isFitYGap="fit"===st.yGap&&!h,"object"==typeof i?(st.contentAlign=i.content||"top-left",st.rowXAlign=i.x||"from",st.rowYAlign=i.y||"from"):(st.contentAlign=i,st.rowXAlign=$[i],st.rowYAlign=tt[i])),st}function ct(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 at(t,e){return"box"===e?t.__local:t.__layout.localStrokeBounds}const{within:lt}=d;function _t(t,e,o,i){let n,s,h,c=0,r=e.hasRangeSize&&[],{grow:a,start:l}=e;const _=e.width<o?(o-e.width)/a:0,{children:f}=t;_&&(e.width=o);for(let t=0,o=e.count;t<o;t++)n=f[i?l-t:l+t],n.__.inFlow&&0!==n.__.visible?(s=n.__widthGrow)&&(h=ft(n,n.__flowBounds,_*s),h?(c+=h,a-=s):r&&(n.__.widthRange?r.unshift(n):r.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}))}(r,c,a)}function ft(t,e,o){const{widthRange:i,lockRatio:n}=t.__,s=i?lt(o,i):o,h=s/e.width;return t.scaleResize(h,n?h:1),e.width=s,o-s}const{within:ut}=d;function gt(t,e,o,i){let n,s,h,c=0,r=e.hasRangeSize&&[],{grow:a,start:l}=e;const _=e.height<o?(o-e.height)/a:0,{children:f}=t;_&&(e.height=o);for(let t=0,o=e.count;t<o;t++)n=f[i?l-t:l+t],n.__.inFlow&&0!==n.__.visible?(s=n.__heightGrow)&&(h=pt(n,n.__flowBounds,_*s),h?(c+=h,a-=s):r&&(n.__.heightRange?r.unshift(n):r.push(n))):o++;c&&function(t,e,o){let i,n,s,h;t.forEach((t=>{i=t.__heightGrow,n=e/o*i,h=pt(t,s=t.__flowBounds,s.height+n),e-=n-h,o-=i}))}(r,c,a)}function pt(t,e,o){const{heightRange:i,lockRatio:n}=t.__,s=i?ut(o,i):o,h=s/e.height;return t.scaleResize(n?h:1,h),e.height=s,o-s}const{move:dt}=p;const{move:wt}=p;function yt(t,e,o,i,n,s){const{children:h}=t;let c,r,{y:a,start:l}=e,_=o;a+=i;for(let t=0,i=e.count;t<i;t++)c=h[s?l-t:l+t],c.__.inFlow&&0!==c.__.visible?(r=c.__flowBounds,"from"!==n&&(_=o+(e.width-r.width)/("center"===n?2:1)),wt(c,_-r.x,a-r.y),a+=r.height+e.gap):i++}const{move:bt}=p;function xt(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)&&b(this)}})))}const{copyAndSpread:Gt}=G;let mt=function(t,e){const o="width",{children:i,itemBox:n}=t,s=ht(t,!0),{complex:h,wrap:c,xGap:r,yGap:a,isAutoXGap:l,isFitXGap:_}=s;if(!i.length)return;const f=c&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},u=l?0:r;let g,p,d,w,y,{x:b,y:x,width:G,height:m}=t.__layout.contentBounds;for(let s=0,r=i.length;s<r;s++)g=i[w=e?r-1-s:s],g.__.inFlow&&0!==g.__.visible&&(p=at(g,n),h?(g.__flowBounds=p,y||(y=ct(w,u)),c&&y.count&&y.width+p.width>G&&(y.grow?_t(t,y,G,e):l&&rt(y,o,G,_),nt(f,y,o),y=ct(w,u)),d=p.width,g.__widthGrow&&(y.grow+=g.__widthGrow,d=0,g.__.widthRange&&(y.hasRangeSize=!0)),g.__heightGrow&&pt(g,p,m),y.width+=y.count?d+u:d,y.height=Math.max(y.height,p.height),y.count++):(dt(g,b-p.x,x-p.y),b+=p.width+u));if(h){const{isAutoYGap:i,isFitYGap:n,contentAlign:h,rowXAlign:r,rowYAlign:u}=s;y.count&&(y.grow?_t(t,y,G,e):l&&rt(y,o,G,_),c&&nt(f,y,o)),c?(i?rt(f,"height",m,n):f.gap=a,function(t,e,o,i){et(t,e,o);const{list:n}=e;if(n.length>1&&(i||(i=$[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,f,h,r),function(t,e,o,i){const{list:n}=e,s="reverse"===t.__.flowWrap;let h,{x:c,y:r}=e;for(let a=0,l=n.length;a<l;a++)h=n[s?l-1-a:a],it(t,h,c,r,o,i),r+=h.height+e.gap}(t,f,u,e)):(et(t,y,h),it(t,y,0,y.y,u,e))}},Rt=function(t,e){const o="height",{children:i,itemBox:n}=t,s=ht(t,!1),{complex:h,wrap:c,xGap:r,yGap:a,isAutoYGap:l,isFitYGap:_}=s;if(!i.length)return;const f=c&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},u=l?0:a;let g,p,d,w,y,{x:b,y:x,width:G,height:m}=t.__layout.contentBounds;for(let s=0,r=i.length;s<r;s++)g=i[w=e?r-1-s:s],g.__.inFlow&&0!==g.__.visible&&(p=at(g,n),h?(g.__flowBounds=p,y||(y=ct(w,u)),c&&y.count&&y.height+p.height>m&&(y.grow&>(t,y,m,e),l&&rt(y,o,m,_),nt(f,y,o),y=ct(w,u)),d=p.height,g.__heightGrow&&(y.grow+=g.__heightGrow,d=0,g.__.heightRange&&(y.hasRangeSize=!0)),g.__widthGrow&&ft(g,p,G),y.height+=y.count?d+u:d,y.width=Math.max(y.width,p.width),y.count++):(bt(g,b-p.x,x-p.y),x+=p.height+u));if(h){const{isAutoXGap:i,isFitXGap:n,contentAlign:h,rowXAlign:a,rowYAlign:u}=s;y.count&&(y.grow&>(t,y,m,e),l&&rt(y,o,m,_),c&&nt(f,y,o)),c?(i?rt(f,"width",G,n):f.gap=r,function(t,e,o,i){et(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.y=e.height-t.height,"center"===i&&(t.y/=2)}}(t,f,h,u),function(t,e,o,i){const{list:n}=e,s="reverse"===t.__.flowWrap;let h,{x:c,y:r}=e;for(let a=0,l=n.length;a<l;a++)h=n[s?l-1-a:a],yt(t,h,c,r,o,i),c+=h.width+e.gap}(t,f,a,e)):(et(t,y,h),yt(t,y,y.x,0,a,e))}};x.changeAttr("autoWidth",void 0,xt),x.changeAttr("autoHeight",void 0,xt),a.prototype.__updateFlowLayout=function(){this.leafer.created=!1;const{flow:t}=this.__;switch(t){case"x":case!0:mt(this);break;case"y":Rt(this);break;case"x-reverse":mt(this,!0);break;case"y-reverse":Rt(this,!0)}this.leafer.created=!0},a.prototype.__updateContentBounds=function(){const{padding:t}=this.__,e=this.__layout,o=e.contentBounds===e.boxBounds;t?(o&&e.shrinkContent(),Gt(e.contentBounds,e.boxBounds,t,!0)):o||e.shrinkContentCancel()};export{T as Flow,P as PathScaler,N as scaleResize,Q as scaleResizeFontSize,q as scaleResizeGroup,U as scaleResizePath,Z as scaleResizePoints};
|
|
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 r,Box as a,BoxData as l,dataProcessor as _,autoLayoutType as f,registerUI as u,AlignHelper as g,PointHelper as p,MathHelper as w,decorateLeafAttr as d,attr as y,doBoundsType as x,UI as b,boundsType as G,BoundsHelper as m}from"@leafer-ui/draw";const{M:R,L:z,C:B,Q:A,Z:k,N:v,D:F,X:S,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 R:case z:I(t,e,o,n,1),n+=3;break;case B: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 F:I(t,e,o,n,2),n+=9;break;case S: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:H,top:E,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 E: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 H: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){P.scalePoints(t.__.points,e,o),t.points=t.__.points}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)},r.prototype.__scaleResize=function(t,e){J(this,t,e)},a.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 a{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}};T([_(class extends l{})],V.prototype,"__",void 0),T([f("x")],V.prototype,"flow",void 0),V=T([u()],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;g.toPoint(o,e,n,$),e.x=i.__autoWidth?n.x:$.x,e.y=i.__autoHeight?n.y:$.y}const{move:it}=p;function nt(t,e,o,i,n,s){const{children:h}=t;let c,r,{x:a,start:l}=e,_=i;a+=o;for(let t=0,o=e.count;t<o;t++)c=h[s?l-t:l+t],c.__.inFlow&&0!==c.__.visible?(r=c.__flowBounds,"from"!==n&&(_=i+(e.height-r.height)/("center"===n?2:1)),it(c,a-r.x,_-r.y),a+=r.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 rt(t,e){return{x:0,y:0,width:0,height:0,gap:e,start:t,count:0,grow:0}}function at(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}=w;function ft(t,e,o,i){let n,s,h,c=0,r=e.hasRangeSize&&[],{grow:a,start:l}=e;const _=e.width<o?(o-e.width)/a:0,{children:f}=t;_&&(e.width=o);for(let t=0,o=e.count;t<o;t++)n=f[i?l-t:l+t],n.__.inFlow&&0!==n.__.visible?(s=n.__widthGrow)&&(h=ut(n,n.__flowBounds,_*s),h?(c+=h,a-=s):r&&(n.__.widthRange?r.unshift(n):r.push(n))):o++;c&&function(t,e,o){let i,n,s,h;t.forEach((t=>{i=t.__widthGrow,n=e/o*i,h=ut(t,s=t.__flowBounds,s.width+n),e-=n-h,o-=i}))}(r,c,a)}function ut(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:gt}=w;function pt(t,e,o,i){let n,s,h,c=0,r=e.hasRangeSize&&[],{grow:a,start:l}=e;const _=e.height<o?(o-e.height)/a:0,{children:f}=t;_&&(e.height=o);for(let t=0,o=e.count;t<o;t++)n=f[i?l-t:l+t],n.__.inFlow&&0!==n.__.visible?(s=n.__heightGrow)&&(h=wt(n,n.__flowBounds,_*s),h?(c+=h,a-=s):r&&(n.__.heightRange?r.unshift(n):r.push(n))):o++;c&&function(t,e,o){let i,n,s,h;t.forEach((t=>{i=t.__heightGrow,n=e/o*i,h=wt(t,s=t.__flowBounds,s.height+n),e-=n-h,o-=i}))}(r,c,a)}function wt(t,e,o){const{heightRange:i,lockRatio:n}=t.__,s=i?gt(o,i):o,h=s/e.height;return t.scaleResize(n?h:1,h),e.height=s,o-s}const{move:dt}=p;const{move:yt}=p;function xt(t,e,o,i,n,s){const{children:h}=t;let c,r,{y:a,start:l}=e,_=o;a+=i;for(let t=0,i=e.count;t<i;t++)c=h[s?l-t:l+t],c.__.inFlow&&0!==c.__.visible?(r=c.__flowBounds,"from"!==n&&(_=o+(e.width-r.width)/("center"===n?2:1)),yt(c,_-r.x,a-r.y),a+=r.height+e.gap):i++}const{move:bt}=p;function Gt(t){return d(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 mt=b.prototype,Rt=a.prototype;f(!1)(mt,"flow"),G(0)(mt,"gap"),G("top-left")(mt,"flowAlign"),G(!1)(mt,"flowWrap"),G("box")(mt,"itemBox"),G(!0)(mt,"inFlow"),Gt()(mt,"autoWidth"),Gt()(mt,"autoHeight"),G()(mt,"lockRatio"),G()(mt,"autoBox"),G()(mt,"widthRange"),G()(mt,"heightRange");const{copyAndSpread:zt}=m;let Bt=function(t,e){const o="width",{children:i,itemBox:n}=t,s=ct(t,!0),{complex:h,wrap:c,xGap:r,yGap:a,isAutoXGap:l,isFitXGap:_}=s;if(!i.length)return;const f=c&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},u=l?0:r;let g,p,w,d,y,{x:x,y:b,width:G,height:m}=t.__layout.contentBounds;for(let s=0,r=i.length;s<r;s++)g=i[d=e?r-1-s:s],g.__.inFlow&&0!==g.__.visible&&(p=lt(g,n),h?(g.__flowBounds=p,y||(y=rt(d,u)),c&&y.count&&y.width+p.width>G&&(y.grow?ft(t,y,G,e):l&&at(y,o,G,_),st(f,y,o),y=rt(d,u)),w=p.width,g.__widthGrow&&(y.grow+=g.__widthGrow,w=0,g.__.widthRange&&(y.hasRangeSize=!0)),g.__heightGrow&&wt(g,p,m),y.width+=y.count?w+u:w,y.height=Math.max(y.height,p.height),y.count++):(dt(g,x-p.x,b-p.y),x+=p.width+u));if(h){const{isAutoYGap:i,isFitYGap:n,contentAlign:h,rowXAlign:r,rowYAlign:u}=s;y.count&&(y.grow?ft(t,y,G,e):l&&at(y,o,G,_),c&&st(f,y,o)),c?(i?at(f,"height",m,n):f.gap=a,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,f,h,r),function(t,e,o,i){const{list:n}=e,s="reverse"===t.__.flowWrap;let h,{x:c,y:r}=e;for(let a=0,l=n.length;a<l;a++)h=n[s?l-1-a:a],nt(t,h,c,r,o,i),r+=h.height+e.gap}(t,f,u,e)):(ot(t,y,h),nt(t,y,0,y.y,u,e))}},At=function(t,e){const o="height",{children:i,itemBox:n}=t,s=ct(t,!1),{complex:h,wrap:c,xGap:r,yGap:a,isAutoYGap:l,isFitYGap:_}=s;if(!i.length)return;const f=c&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},u=l?0:a;let g,p,w,d,y,{x:x,y:b,width:G,height:m}=t.__layout.contentBounds;for(let s=0,r=i.length;s<r;s++)g=i[d=e?r-1-s:s],g.__.inFlow&&0!==g.__.visible&&(p=lt(g,n),h?(g.__flowBounds=p,y||(y=rt(d,u)),c&&y.count&&y.height+p.height>m&&(y.grow&&pt(t,y,m,e),l&&at(y,o,m,_),st(f,y,o),y=rt(d,u)),w=p.height,g.__heightGrow&&(y.grow+=g.__heightGrow,w=0,g.__.heightRange&&(y.hasRangeSize=!0)),g.__widthGrow&&ut(g,p,G),y.height+=y.count?w+u:w,y.width=Math.max(y.width,p.width),y.count++):(bt(g,x-p.x,b-p.y),b+=p.height+u));if(h){const{isAutoXGap:i,isFitXGap:n,contentAlign:h,rowXAlign:a,rowYAlign:u}=s;y.count&&(y.grow&&pt(t,y,m,e),l&&at(y,o,m,_),c&&st(f,y,o)),c?(i?at(f,"width",G,n):f.gap=r,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,f,h,u),function(t,e,o,i){const{list:n}=e,s="reverse"===t.__.flowWrap;let h,{x:c,y:r}=e;for(let a=0,l=n.length;a<l;a++)h=n[s?l-1-a:a],xt(t,h,c,r,o,i),c+=h.width+e.gap}(t,f,a,e)):(ot(t,y,h),xt(t,y,y.x,0,a,e))}};Rt.__updateFlowLayout=function(){this.leafer.created=!1;const{flow:t}=this.__;switch(t){case"x":case!0:Bt(this);break;case"y":At(this);break;case"x-reverse":Bt(this,!0);break;case"y-reverse":At(this,!0)}this.leafer.created=!0},Rt.__updateContentBounds=function(){const{padding:t}=this.__,e=this.__layout,o=e.contentBounds===e.boxBounds;t?(o&&e.shrinkContent(),zt(e.contentBounds,e.boxBounds,t,!0)):o||e.shrinkContentCancel()};export{V as Flow,P as PathScaler,Q as scaleResize,U as scaleResizeFontSize,J as scaleResizeGroup,Z as scaleResizePath,q as scaleResizePoints};
|
package/dist/flow.js
CHANGED
|
@@ -13,9 +13,6 @@ this.LeaferIN.flow = (function (exports, draw) {
|
|
|
13
13
|
command = data[i];
|
|
14
14
|
switch (command) {
|
|
15
15
|
case M:
|
|
16
|
-
scalePoints(data, scaleX, scaleY, i, 1);
|
|
17
|
-
i += 3;
|
|
18
|
-
break;
|
|
19
16
|
case L:
|
|
20
17
|
scalePoints(data, scaleX, scaleY, i, 1);
|
|
21
18
|
i += 3;
|
|
@@ -97,34 +94,34 @@ this.LeaferIN.flow = (function (exports, draw) {
|
|
|
97
94
|
function scaleResizeFontSize(leaf, scaleX, scaleY) {
|
|
98
95
|
const { app } = leaf;
|
|
99
96
|
const editor = app && app.editor;
|
|
97
|
+
let fontScale = scaleX;
|
|
100
98
|
if (editor.editing) {
|
|
101
99
|
const layout = leaf.__layout;
|
|
102
100
|
let { width, height } = layout.boxBounds;
|
|
103
|
-
width *=
|
|
104
|
-
height *=
|
|
101
|
+
width *= scaleY - scaleX;
|
|
102
|
+
height *= scaleX - scaleY;
|
|
105
103
|
switch (editor.resizeDirection) {
|
|
106
104
|
case top:
|
|
107
105
|
case bottom:
|
|
108
|
-
|
|
106
|
+
fontScale = scaleY;
|
|
109
107
|
layout.affectScaleOrRotation ? leaf.moveInner(-width / 2, 0) : leaf.x -= width / 2;
|
|
110
108
|
break;
|
|
111
109
|
case left:
|
|
112
110
|
case right:
|
|
113
|
-
leaf.fontSize *= scaleX;
|
|
114
111
|
layout.affectScaleOrRotation ? leaf.moveInner(0, -height / 2) : leaf.y -= height / 2;
|
|
115
112
|
break;
|
|
116
113
|
case topLeft:
|
|
117
114
|
case topRight:
|
|
118
|
-
leaf.fontSize *= scaleX;
|
|
119
115
|
layout.affectScaleOrRotation ? leaf.moveInner(0, -height) : leaf.y -= height;
|
|
120
116
|
break;
|
|
121
|
-
default:
|
|
122
|
-
leaf.fontSize *= scaleX;
|
|
123
117
|
}
|
|
124
118
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
119
|
+
leaf.fontSize *= fontScale;
|
|
120
|
+
const data = leaf.__;
|
|
121
|
+
if (!data.__autoWidth)
|
|
122
|
+
leaf.width *= fontScale;
|
|
123
|
+
if (!data.__autoHeight)
|
|
124
|
+
leaf.height *= fontScale;
|
|
128
125
|
}
|
|
129
126
|
function scaleResizePath(leaf, scaleX, scaleY) {
|
|
130
127
|
PathScaler.scale(leaf.__.path, scaleX, scaleY);
|
|
@@ -170,7 +167,7 @@ this.LeaferIN.flow = (function (exports, draw) {
|
|
|
170
167
|
this.scaleOf(this.__layout.boxBounds, this.__.lockRatio ? scale : 1, scale, true);
|
|
171
168
|
};
|
|
172
169
|
draw.Text.prototype.__scaleResize = function (scaleX, scaleY) {
|
|
173
|
-
if (this.__.
|
|
170
|
+
if (this.__.resizeFontSize || (this.editConfig && this.editConfig.editSize === 'font-size')) {
|
|
174
171
|
scaleResizeFontSize(this, scaleX, scaleY);
|
|
175
172
|
}
|
|
176
173
|
else {
|
|
@@ -295,10 +292,11 @@ this.LeaferIN.flow = (function (exports, draw) {
|
|
|
295
292
|
'baseline-right': 'to',
|
|
296
293
|
};
|
|
297
294
|
function alignContent(box, content, align) {
|
|
298
|
-
draw.AlignHelper.toPoint(align, content, box.__layout.contentBounds, point);
|
|
299
295
|
const data = box.__;
|
|
300
|
-
|
|
301
|
-
|
|
296
|
+
const { contentBounds } = box.__layout;
|
|
297
|
+
draw.AlignHelper.toPoint(align, content, contentBounds, point);
|
|
298
|
+
content.x = data.__autoWidth ? contentBounds.x : point.x;
|
|
299
|
+
content.y = data.__autoHeight ? contentBounds.y : point.y;
|
|
302
300
|
}
|
|
303
301
|
|
|
304
302
|
function align$1(box, data, contentAlign, innerXAlign) {
|
|
@@ -691,11 +689,22 @@ this.LeaferIN.flow = (function (exports, draw) {
|
|
|
691
689
|
}));
|
|
692
690
|
}
|
|
693
691
|
|
|
692
|
+
const ui = draw.UI.prototype, box = draw.Box.prototype;
|
|
693
|
+
draw.autoLayoutType(false)(ui, 'flow');
|
|
694
|
+
draw.boundsType(0)(ui, 'gap');
|
|
695
|
+
draw.boundsType('top-left')(ui, 'flowAlign');
|
|
696
|
+
draw.boundsType(false)(ui, 'flowWrap');
|
|
697
|
+
draw.boundsType('box')(ui, 'itemBox');
|
|
698
|
+
draw.boundsType(true)(ui, 'inFlow');
|
|
699
|
+
autoBoundsType()(ui, 'autoWidth');
|
|
700
|
+
autoBoundsType()(ui, 'autoHeight');
|
|
701
|
+
draw.boundsType()(ui, 'lockRatio');
|
|
702
|
+
draw.boundsType()(ui, 'autoBox');
|
|
703
|
+
draw.boundsType()(ui, 'widthRange');
|
|
704
|
+
draw.boundsType()(ui, 'heightRange');
|
|
694
705
|
const { copyAndSpread } = draw.BoundsHelper;
|
|
695
706
|
let doFlowX = flowX, doFlowY = flowY;
|
|
696
|
-
|
|
697
|
-
draw.UI.changeAttr('autoHeight', undefined, autoBoundsType);
|
|
698
|
-
draw.Box.prototype.__updateFlowLayout = function () {
|
|
707
|
+
box.__updateFlowLayout = function () {
|
|
699
708
|
this.leafer.created = false;
|
|
700
709
|
const { flow } = this.__;
|
|
701
710
|
switch (flow) {
|
|
@@ -715,7 +724,7 @@ this.LeaferIN.flow = (function (exports, draw) {
|
|
|
715
724
|
}
|
|
716
725
|
this.leafer.created = true;
|
|
717
726
|
};
|
|
718
|
-
|
|
727
|
+
box.__updateContentBounds = function () {
|
|
719
728
|
const { padding } = this.__;
|
|
720
729
|
const layout = this.__layout;
|
|
721
730
|
const same = layout.contentBounds === layout.boxBounds;
|
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:r,X:a,G:c,F:l,O:_,P:p,U:f}=t.PathCommandMap,u={scale(t,u,d){if(!t)return;let w,x=0,y=t.length;for(;x<y;)switch(w=t[x],w){case e:case o:g(t,u,d,x,1),x+=3;break;case i:g(t,u,d,x,3),x+=7;break;case n:g(t,u,d,x,2),x+=5;break;case s:x+=1;break;case h:g(t,u,d,x,2),x+=5;break;case r:g(t,u,d,x,2),x+=9;break;case a:g(t,u,d,x,2),x+=6;break;case c:g(t,u,d,x,2),x+=9;break;case l:g(t,u,d,x,2),x+=5;break;case _:t[x]=c,t.splice(x+4,0,t[x+3],0),g(t,u,d,x,2),x+=9,y+=2;break;case p:t[x]=l,t.splice(x+4,0,t[x+3]),g(t,u,d,x,2),x+=5,y+=1;break;case f:g(t,u,d,x,2),x+=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}=u,d=t.MatrixHelper.get(),{topLeft:w,top:x,topRight:y,right:b,bottom:G,left:m}=t.Direction9;function z(t,e,o){t.pathInputed?B(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;if(n.editing){const i=t.__layout;let{width:s,height:h}=i.boxBounds;switch(s*=(o-e)*(t.scaleX<0?-1:1),h*=(e-o)*(t.scaleY<0?-1:1),n.resizeDirection){case x:case G:t.fontSize*=o,i.affectScaleOrRotation?t.moveInner(-s/2,0):t.x-=s/2;break;case m:case b:t.fontSize*=e,i.affectScaleOrRotation?t.moveInner(0,-h/2):t.y-=h/2;break;case w:case y:t.fontSize*=e,i.affectScaleOrRotation?t.moveInner(0,-h):t.y-=h;break;default:t.fontSize*=e}}else t.fontSize*=e}function B(t,e,o){u.scale(t.__.path,e,o),t.path=t.__.path}function A(t,e,o){u.scalePoints(t.__.points,e,o),t.points=t.__.points}function k(t,e,o){const{children:i}=t;for(let t=0;t<i.length;t++)d.a=e,d.d=o,i[t].transform(d,!0)}const v=t.Leaf.prototype;function S(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 r=t.length-1;r>=0;r--)(n=t[r])&&(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}v.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))},v.__scaleResize=function(t,e){z(this,t,e)},v.resizeWidth=function(t){const e=t/this.getBounds("box","local").width;this.scaleOf(this.__layout.boxBounds,e,this.__.lockRatio?e:1,!0)},v.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.__.__autoSize&&(this.__.resizeFontSize||this.editConfig&&"font-size"===this.editConfig.editSize)?R(this,t,e):z(this,t,e)},t.Path.prototype.__scaleResize=function(t,e){B(this,t,e)},t.Line.prototype.__scaleResize=function(t,e){this.pathInputed?B(this,t,e):this.points?A(this,t,e):this.width*=t},t.Polygon.prototype.__scaleResize=function(t,e){this.pathInputed?B(this,t,e):this.points?A(this,t,e):z(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):(z(this,t,e),this.__.resizeChildren&&k(this,t,e))},"function"==typeof SuppressedError&&SuppressedError;class F extends t.BoxData{}exports.Flow=class extends t.Box{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}},S([t.dataProcessor(F)],exports.Flow.prototype,"__",void 0),S([t.autoLayoutType("x")],exports.Flow.prototype,"flow",void 0),exports.Flow=S([t.registerUI()],exports.Flow);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 H(e,o,i){t.AlignHelper.toPoint(i,o,e.__layout.contentBounds,P);const n=e.__;o.x=n.__autoWidth?0:P.x,o.y=n.__autoHeight?0:P.y}const{move:C}=t.PointHelper;function I(t,e,o,i,n,s){const{children:h}=t;let r,a,{x:c,start:l}=e,_=i;c+=o;for(let t=0,o=e.count;t<o;t++)r=h[s?l-t:l+t],r.__.inFlow&&0!==r.__.visible?(a=r.__flowBounds,"from"!==n&&(_=i+(e.height-a.height)/("center"===n?2:1)),C(r,c-a.x,_-a.y),c+=a.width+e.gap):o++}function O(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 L={};function M(t,e){const{gap:o,flowAlign:i,flowWrap:n,__autoWidth:s,__autoHeight:h}=t.__,r=n&&(e?!s:!h);return"object"==typeof o?(L.xGap=o.x||0,L.yGap=o.y||0):L.xGap=L.yGap=o,L.isAutoXGap="string"==typeof L.xGap&&!s,L.isAutoYGap="string"==typeof L.yGap&&!h,L.complex=r||"top-left"!==i||t.__hasGrow||L.isAutoXGap||L.isAutoYGap,L.wrap=r,L.complex&&(L.isFitXGap="fit"===L.xGap&&!s,L.isFitYGap="fit"===L.yGap&&!h,"object"==typeof i?(L.contentAlign=i.content||"top-left",L.rowXAlign=i.x||"from",L.rowYAlign=i.y||"from"):(L.contentAlign=i,L.rowXAlign=X[i],L.rowYAlign=Y[i])),L}function W(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}=t.MathHelper;function U(t,e,o,i){let n,s,h,r=0,a=e.hasRangeSize&&[],{grow:c,start:l}=e;const _=e.width<o?(o-e.width)/c:0,{children:p}=t;_&&(e.width=o);for(let t=0,o=e.count;t<o;t++)n=p[i?l-t:l+t],n.__.inFlow&&0!==n.__.visible?(s=n.__widthGrow)&&(h=T(n,n.__flowBounds,_*s),h?(r+=h,c-=s):a&&(n.__.widthRange?a.unshift(n):a.push(n))):o++;r&&function(t,e,o){let i,n,s,h;t.forEach((t=>{i=t.__widthGrow,n=e/o*i,h=T(t,s=t.__flowBounds,s.width+n),e-=n-h,o-=i}))}(a,r,c)}function T(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}=t.MathHelper;function N(t,e,o,i){let n,s,h,r=0,a=e.hasRangeSize&&[],{grow:c,start:l}=e;const _=e.height<o?(o-e.height)/c:0,{children:p}=t;_&&(e.height=o);for(let t=0,o=e.count;t<o;t++)n=p[i?l-t:l+t],n.__.inFlow&&0!==n.__.visible?(s=n.__heightGrow)&&(h=Q(n,n.__flowBounds,_*s),h?(r+=h,c-=s):a&&(n.__.heightRange?a.unshift(n):a.push(n))):o++;r&&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}))}(a,r,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:Z}=t.PointHelper;const{move:J}=t.PointHelper;function K(t,e,o,i,n,s){const{children:h}=t;let r,a,{y:c,start:l}=e,_=o;c+=i;for(let t=0,i=e.count;t<i;t++)r=h[s?l-t:l+t],r.__.inFlow&&0!==r.__.visible?(a=r.__flowBounds,"from"!==n&&(_=o+(e.width-a.width)/("center"===n?2:1)),J(r,_-a.x,c-a.y),c+=a.height+e.gap):i++}const{move:V}=t.PointHelper;function $(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{copyAndSpread:tt}=t.BoundsHelper;let et=function(t,e){const o="width",{children:i,itemBox:n}=t,s=M(t,!0),{complex:h,wrap:r,xGap:a,yGap:c,isAutoXGap:l,isFitXGap:_}=s;if(!i.length)return;const p=r&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},f=l?0:a;let u,g,d,w,x,{x:y,y:b,width:G,height:m}=t.__layout.contentBounds;for(let s=0,a=i.length;s<a;s++)u=i[w=e?a-1-s:s],u.__.inFlow&&0!==u.__.visible&&(g=D(u,n),h?(u.__flowBounds=g,x||(x=W(w,f)),r&&x.count&&x.width+g.width>G&&(x.grow?U(t,x,G,e):l&&j(x,o,G,_),O(p,x,o),x=W(w,f)),d=g.width,u.__widthGrow&&(x.grow+=u.__widthGrow,d=0,u.__.widthRange&&(x.hasRangeSize=!0)),u.__heightGrow&&Q(u,g,m),x.width+=x.count?d+f:d,x.height=Math.max(x.height,g.height),x.count++):(Z(u,y-g.x,b-g.y),y+=g.width+f));if(h){const{isAutoYGap:i,isFitYGap:n,contentAlign:h,rowXAlign:a,rowYAlign:f}=s;x.count&&(x.grow?U(t,x,G,e):l&&j(x,o,G,_),r&&O(p,x,o)),r?(i?j(p,"height",m,n):p.gap=c,function(t,e,o,i){H(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,p,h,a),function(t,e,o,i){const{list:n}=e,s="reverse"===t.__.flowWrap;let h,{x:r,y:a}=e;for(let c=0,l=n.length;c<l;c++)h=n[s?l-1-c:c],I(t,h,r,a,o,i),a+=h.height+e.gap}(t,p,f,e)):(H(t,x,h),I(t,x,0,x.y,f,e))}},ot=function(t,e){const o="height",{children:i,itemBox:n}=t,s=M(t,!1),{complex:h,wrap:r,xGap:a,yGap:c,isAutoYGap:l,isFitYGap:_}=s;if(!i.length)return;const p=r&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},f=l?0:c;let u,g,d,w,x,{x:y,y:b,width:G,height:m}=t.__layout.contentBounds;for(let s=0,a=i.length;s<a;s++)u=i[w=e?a-1-s:s],u.__.inFlow&&0!==u.__.visible&&(g=D(u,n),h?(u.__flowBounds=g,x||(x=W(w,f)),r&&x.count&&x.height+g.height>m&&(x.grow&&N(t,x,m,e),l&&j(x,o,m,_),O(p,x,o),x=W(w,f)),d=g.height,u.__heightGrow&&(x.grow+=u.__heightGrow,d=0,u.__.heightRange&&(x.hasRangeSize=!0)),u.__widthGrow&&T(u,g,G),x.height+=x.count?d+f:d,x.width=Math.max(x.width,g.width),x.count++):(V(u,y-g.x,b-g.y),b+=g.height+f));if(h){const{isAutoXGap:i,isFitXGap:n,contentAlign:h,rowXAlign:c,rowYAlign:f}=s;x.count&&(x.grow&&N(t,x,m,e),l&&j(x,o,m,_),r&&O(p,x,o)),r?(i?j(p,"width",G,n):p.gap=a,function(t,e,o,i){H(t,e,o);const{list:n}=e;if(n.length>1&&(i||(i=Y[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,p,h,f),function(t,e,o,i){const{list:n}=e,s="reverse"===t.__.flowWrap;let h,{x:r,y:a}=e;for(let c=0,l=n.length;c<l;c++)h=n[s?l-1-c:c],K(t,h,r,a,o,i),r+=h.width+e.gap}(t,p,c,e)):(H(t,x,h),K(t,x,x.x,0,c,e))}};t.UI.changeAttr("autoWidth",void 0,$),t.UI.changeAttr("autoHeight",void 0,$),t.Box.prototype.__updateFlowLayout=function(){this.leafer.created=!1;const{flow:t}=this.__;switch(t){case"x":case!0:et(this);break;case"y":ot(this);break;case"x-reverse":et(this,!0);break;case"y-reverse":ot(this,!0)}this.leafer.created=!0},t.Box.prototype.__updateContentBounds=function(){const{padding:t}=this.__,e=this.__layout,o=e.contentBounds===e.boxBounds;t?(o&&e.shrinkContent(),tt(e.contentBounds,e.boxBounds,t,!0)):o||e.shrinkContentCancel()},exports.PathScaler=u,exports.scaleResize=z,exports.scaleResizeFontSize=R,exports.scaleResizeGroup=k,exports.scaleResizePath=B,exports.scaleResizePoints=A;
|
|
1
|
+
"use strict";var t=require("@leafer-ui/draw");const{M:e,L:o,C:i,Q:n,Z:s,N:h,D:r,X:a,G:c,F:l,O:_,P:p,U:u}=t.PathCommandMap,f={scale(t,f,d){if(!t)return;let w,y=0,x=t.length;for(;y<x;)switch(w=t[y],w){case e:case o:g(t,f,d,y,1),y+=3;break;case i:g(t,f,d,y,3),y+=7;break;case n:g(t,f,d,y,2),y+=5;break;case s:y+=1;break;case h:g(t,f,d,y,2),y+=5;break;case r:g(t,f,d,y,2),y+=9;break;case a:g(t,f,d,y,2),y+=6;break;case c:g(t,f,d,y,2),y+=9;break;case l:g(t,f,d,y,2),y+=5;break;case _:t[y]=c,t.splice(y+4,0,t[y+3],0),g(t,f,d,y,2),y+=9,x+=2;break;case p:t[y]=l,t.splice(y+4,0,t[y+3]),g(t,f,d,y,2),y+=5,x+=1;break;case u:g(t,f,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}=f,d=t.MatrixHelper.get(),{topLeft:w,top:y,topRight:x,right:b,bottom:G,left:m}=t.Direction9;function R(t,e,o){t.pathInputed?B(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:r}=i.boxBounds;switch(h*=o-e,r*=e-o,n.resizeDirection){case y:case G:s=o,i.affectScaleOrRotation?t.moveInner(-h/2,0):t.x-=h/2;break;case m:case b:i.affectScaleOrRotation?t.moveInner(0,-r/2):t.y-=r/2;break;case w:case x:i.affectScaleOrRotation?t.moveInner(0,-r):t.y-=r}}t.fontSize*=s;const h=t.__;h.__autoWidth||(t.width*=s),h.__autoHeight||(t.height*=s)}function B(t,e,o){f.scale(t.__.path,e,o),t.path=t.__.path}function A(t,e,o){f.scalePoints(t.__.points,e,o),t.points=t.__.points}function k(t,e,o){const{children:i}=t;for(let t=0;t<i.length;t++)d.a=e,d.d=o,i[t].transform(d,!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 r=t.length-1;r>=0;r--)(n=t[r])&&(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){R(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?z(this,t,e):R(this,t,e)},t.Path.prototype.__scaleResize=function(t,e){B(this,t,e)},t.Line.prototype.__scaleResize=function(t,e){this.pathInputed?B(this,t,e):this.points?A(this,t,e):this.width*=t},t.Polygon.prototype.__scaleResize=function(t,e){this.pathInputed?B(this,t,e):this.points?A(this,t,e):R(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):(R(this,t,e),this.__.resizeChildren&&k(this,t,e))},"function"==typeof SuppressedError&&SuppressedError;class P extends t.BoxData{}exports.Flow=class extends t.Box{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}},v([t.dataProcessor(P)],exports.Flow.prototype,"__",void 0),v([t.autoLayoutType("x")],exports.Flow.prototype,"flow",void 0),exports.Flow=v([t.registerUI()],exports.Flow);const S={},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 T(e,o,i){const n=e.__,{contentBounds:s}=e.__layout;t.AlignHelper.toPoint(i,o,s,S),o.x=n.__autoWidth?s.x:S.x,o.y=n.__autoHeight?s.y:S.y}const{move:Y}=t.PointHelper;function C(t,e,o,i,n,s){const{children:h}=t;let r,a,{x:c,start:l}=e,_=i;c+=o;for(let t=0,o=e.count;t<o;t++)r=h[s?l-t:l+t],r.__.inFlow&&0!==r.__.visible?(a=r.__flowBounds,"from"!==n&&(_=i+(e.height-a.height)/("center"===n?2:1)),Y(r,c-a.x,_-a.y),c+=a.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 L={};function O(t,e){const{gap:o,flowAlign:i,flowWrap:n,__autoWidth:s,__autoHeight:h}=t.__,r=n&&(e?!s:!h);return"object"==typeof o?(L.xGap=o.x||0,L.yGap=o.y||0):L.xGap=L.yGap=o,L.isAutoXGap="string"==typeof L.xGap&&!s,L.isAutoYGap="string"==typeof L.yGap&&!h,L.complex=r||"top-left"!==i||t.__hasGrow||L.isAutoXGap||L.isAutoYGap,L.wrap=r,L.complex&&(L.isFitXGap="fit"===L.xGap&&!s,L.isFitYGap="fit"===L.yGap&&!h,"object"==typeof i?(L.contentAlign=i.content||"top-left",L.rowXAlign=i.x||"from",L.rowYAlign=i.y||"from"):(L.contentAlign=i,L.rowXAlign=H[i],L.rowYAlign=X[i])),L}function I(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,r=0,a=e.hasRangeSize&&[],{grow:c,start:l}=e;const _=e.width<o?(o-e.width)/c:0,{children:p}=t;_&&(e.width=o);for(let t=0,o=e.count;t<o;t++)n=p[i?l-t:l+t],n.__.inFlow&&0!==n.__.visible?(s=n.__widthGrow)&&(h=U(n,n.__flowBounds,_*s),h?(r+=h,c-=s):a&&(n.__.widthRange?a.unshift(n):a.push(n))):o++;r&&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}))}(a,r,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:q}=t.MathHelper;function N(t,e,o,i){let n,s,h,r=0,a=e.hasRangeSize&&[],{grow:c,start:l}=e;const _=e.height<o?(o-e.height)/c:0,{children:p}=t;_&&(e.height=o);for(let t=0,o=e.count;t<o;t++)n=p[i?l-t:l+t],n.__.inFlow&&0!==n.__.visible?(s=n.__heightGrow)&&(h=Q(n,n.__flowBounds,_*s),h?(r+=h,c-=s):a&&(n.__.heightRange?a.unshift(n):a.push(n))):o++;r&&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}))}(a,r,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:Z}=t.PointHelper;const{move:J}=t.PointHelper;function K(t,e,o,i,n,s){const{children:h}=t;let r,a,{y:c,start:l}=e,_=o;c+=i;for(let t=0,i=e.count;t<i;t++)r=h[s?l-t:l+t],r.__.inFlow&&0!==r.__.visible?(a=r.__flowBounds,"from"!==n&&(_=o+(e.width-a.width)/("center"===n?2:1)),J(r,_-a.x,c-a.y),c+=a.height+e.gap):i++}const{move:V}=t.PointHelper;function $(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 tt=t.UI.prototype,et=t.Box.prototype;t.autoLayoutType(!1)(tt,"flow"),t.boundsType(0)(tt,"gap"),t.boundsType("top-left")(tt,"flowAlign"),t.boundsType(!1)(tt,"flowWrap"),t.boundsType("box")(tt,"itemBox"),t.boundsType(!0)(tt,"inFlow"),$()(tt,"autoWidth"),$()(tt,"autoHeight"),t.boundsType()(tt,"lockRatio"),t.boundsType()(tt,"autoBox"),t.boundsType()(tt,"widthRange"),t.boundsType()(tt,"heightRange");const{copyAndSpread:ot}=t.BoundsHelper;let it=function(t,e){const o="width",{children:i,itemBox:n}=t,s=O(t,!0),{complex:h,wrap:r,xGap:a,yGap:c,isAutoXGap:l,isFitXGap:_}=s;if(!i.length)return;const p=r&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},u=l?0:a;let f,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++)f=i[w=e?a-1-s:s],f.__.inFlow&&0!==f.__.visible&&(g=j(f,n),h?(f.__flowBounds=g,y||(y=I(w,u)),r&&y.count&&y.width+g.width>G&&(y.grow?E(t,y,G,e):l&&M(y,o,G,_),W(p,y,o),y=I(w,u)),d=g.width,f.__widthGrow&&(y.grow+=f.__widthGrow,d=0,f.__.widthRange&&(y.hasRangeSize=!0)),f.__heightGrow&&Q(f,g,m),y.width+=y.count?d+u:d,y.height=Math.max(y.height,g.height),y.count++):(Z(f,x-g.x,b-g.y),x+=g.width+u));if(h){const{isAutoYGap:i,isFitYGap:n,contentAlign:h,rowXAlign:a,rowYAlign:u}=s;y.count&&(y.grow?E(t,y,G,e):l&&M(y,o,G,_),r&&W(p,y,o)),r?(i?M(p,"height",m,n):p.gap=c,function(t,e,o,i){T(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,p,h,a),function(t,e,o,i){const{list:n}=e,s="reverse"===t.__.flowWrap;let h,{x:r,y:a}=e;for(let c=0,l=n.length;c<l;c++)h=n[s?l-1-c:c],C(t,h,r,a,o,i),a+=h.height+e.gap}(t,p,u,e)):(T(t,y,h),C(t,y,0,y.y,u,e))}},nt=function(t,e){const o="height",{children:i,itemBox:n}=t,s=O(t,!1),{complex:h,wrap:r,xGap:a,yGap:c,isAutoYGap:l,isFitYGap:_}=s;if(!i.length)return;const p=r&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},u=l?0:c;let f,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++)f=i[w=e?a-1-s:s],f.__.inFlow&&0!==f.__.visible&&(g=j(f,n),h?(f.__flowBounds=g,y||(y=I(w,u)),r&&y.count&&y.height+g.height>m&&(y.grow&&N(t,y,m,e),l&&M(y,o,m,_),W(p,y,o),y=I(w,u)),d=g.height,f.__heightGrow&&(y.grow+=f.__heightGrow,d=0,f.__.heightRange&&(y.hasRangeSize=!0)),f.__widthGrow&&U(f,g,G),y.height+=y.count?d+u:d,y.width=Math.max(y.width,g.width),y.count++):(V(f,x-g.x,b-g.y),b+=g.height+u));if(h){const{isAutoXGap:i,isFitXGap:n,contentAlign:h,rowXAlign:c,rowYAlign:u}=s;y.count&&(y.grow&&N(t,y,m,e),l&&M(y,o,m,_),r&&W(p,y,o)),r?(i?M(p,"width",G,n):p.gap=a,function(t,e,o,i){T(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,p,h,u),function(t,e,o,i){const{list:n}=e,s="reverse"===t.__.flowWrap;let h,{x:r,y:a}=e;for(let c=0,l=n.length;c<l;c++)h=n[s?l-1-c:c],K(t,h,r,a,o,i),r+=h.width+e.gap}(t,p,c,e)):(T(t,y,h),K(t,y,y.x,0,c,e))}};et.__updateFlowLayout=function(){this.leafer.created=!1;const{flow:t}=this.__;switch(t){case"x":case!0:it(this);break;case"y":nt(this);break;case"x-reverse":it(this,!0);break;case"y-reverse":nt(this,!0)}this.leafer.created=!0},et.__updateContentBounds=function(){const{padding:t}=this.__,e=this.__layout,o=e.contentBounds===e.boxBounds;t?(o&&e.shrinkContent(),ot(e.contentBounds,e.boxBounds,t,!0)):o||e.shrinkContentCancel()},exports.PathScaler=f,exports.scaleResize=R,exports.scaleResizeFontSize=z,exports.scaleResizeGroup=k,exports.scaleResizePath=B,exports.scaleResizePoints=A;
|
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:f,P:u,U:p}=e.PathCommandMap,g={scale(t,e,g){if(!t)return;let w,y=0,x=t.length;for(;y<x;)switch(w=t[y],w){case o:case i:d(t,e,g,y,1),y+=3;break;case n:d(t,e,g,y,3),y+=7;break;case s:d(t,e,g,y,2),y+=5;break;case h:y+=1;break;case a:d(t,e,g,y,2),y+=5;break;case r:d(t,e,g,y,2),y+=9;break;case c:d(t,e,g,y,2),y+=6;break;case l:d(t,e,g,y,2),y+=9;break;case _:d(t,e,g,y,2),y+=5;break;case f:t[y]=l,t.splice(y+4,0,t[y+3],0),d(t,e,g,y,2),y+=9,x+=2;break;case u:t[y]=_,t.splice(y+4,0,t[y+3]),d(t,e,g,y,2),y+=5,x+=1;break;case p:d(t,e,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}=g,w=e.MatrixHelper.get(),{topLeft:y,top:x,topRight:b,right:G,bottom:m,left:z}=e.Direction9;function R(t,e,o){t.pathInputed?A(t,e,o):(1!==e&&(t.width*=e),1!==o&&(t.height*=o))}function B(t,e,o){const{app:i}=t,n=i&&i.editor;if(n.editing){const i=t.__layout;let{width:s,height:h}=i.boxBounds;switch(s*=(o-e)*(t.scaleX<0?-1:1),h*=(e-o)*(t.scaleY<0?-1:1),n.resizeDirection){case x:case m:t.fontSize*=o,i.affectScaleOrRotation?t.moveInner(-s/2,0):t.x-=s/2;break;case z:case G:t.fontSize*=e,i.affectScaleOrRotation?t.moveInner(0,-h/2):t.y-=h/2;break;case y:case b:t.fontSize*=e,i.affectScaleOrRotation?t.moveInner(0,-h):t.y-=h;break;default:t.fontSize*=e}}else t.fontSize*=e}function A(t,e,o){g.scale(t.__.path,e,o),t.path=t.__.path}function k(t,e,o){g.scalePoints(t.__.points,e,o),t.points=t.__.points}function v(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 F(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.__.__autoSize&&(this.__.resizeFontSize||this.editConfig&&"font-size"===this.editConfig.editSize)?B(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){v(this,t,e)},e.Box.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?v(this,t,e):(R(this,t,e),this.__.resizeChildren&&v(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}},F([e.dataProcessor(P)],t.Flow.prototype,"__",void 0),F([e.autoLayoutType("x")],t.Flow.prototype,"flow",void 0),t.Flow=F([e.registerUI()],t.Flow);const X={},Y={"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 I(t,o,i){e.AlignHelper.toPoint(i,o,t.__layout.contentBounds,X);const n=t.__;o.x=n.__autoWidth?0:X.x,o.y=n.__autoHeight?0:X.y}const{move:L}=e.PointHelper;function C(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 O(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 M={};function W(t,e){const{gap:o,flowAlign:i,flowWrap:n,__autoWidth:s,__autoHeight:h}=t.__,a=n&&(e?!s:!h);return"object"==typeof o?(M.xGap=o.x||0,M.yGap=o.y||0):M.xGap=M.yGap=o,M.isAutoXGap="string"==typeof M.xGap&&!s,M.isAutoYGap="string"==typeof M.yGap&&!h,M.complex=a||"top-left"!==i||t.__hasGrow||M.isAutoXGap||M.isAutoYGap,M.wrap=a,M.complex&&(M.isFitXGap="fit"===M.xGap&&!s,M.isFitYGap="fit"===M.yGap&&!h,"object"==typeof i?(M.contentAlign=i.content||"top-left",M.rowXAlign=i.x||"from",M.rowYAlign=i.y||"from"):(M.contentAlign=i,M.rowXAlign=Y[i],M.rowYAlign=H[i])),M}function j(t,e){return{x:0,y:0,width:0,height:0,gap:e,start:t,count:0,grow:0}}function D(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 U(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:f}=t;_&&(e.width=o);for(let t=0,o=e.count;t<o;t++)n=f[i?l-t:l+t],n.__.inFlow&&0!==n.__.visible?(s=n.__widthGrow)&&(h=T(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=T(t,s=t.__flowBounds,s.width+n),e-=n-h,o-=i}))}(r,a,c)}function T(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:f}=t;_&&(e.height=o);for(let t=0,o=e.count;t<o;t++)n=f[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;const{move:K}=e.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:$}=e.PointHelper;function tt(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{copyAndSpread:et}=e.BoundsHelper;let ot=function(t,e){const o="width",{children:i,itemBox:n}=t,s=W(t,!0),{complex:h,wrap:a,xGap:r,yGap:c,isAutoXGap:l,isFitXGap:_}=s;if(!i.length)return;const f=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},u=l?0:r;let p,g,d,w,y,{x:x,y:b,width:G,height:m}=t.__layout.contentBounds;for(let s=0,r=i.length;s<r;s++)p=i[w=e?r-1-s:s],p.__.inFlow&&0!==p.__.visible&&(g=U(p,n),h?(p.__flowBounds=g,y||(y=j(w,u)),a&&y.count&&y.width+g.width>G&&(y.grow?N(t,y,G,e):l&&D(y,o,G,_),O(f,y,o),y=j(w,u)),d=g.width,p.__widthGrow&&(y.grow+=p.__widthGrow,d=0,p.__.widthRange&&(y.hasRangeSize=!0)),p.__heightGrow&&q(p,g,m),y.width+=y.count?d+u:d,y.height=Math.max(y.height,g.height),y.count++):(J(p,x-g.x,b-g.y),x+=g.width+u));if(h){const{isAutoYGap:i,isFitYGap:n,contentAlign:h,rowXAlign:r,rowYAlign:u}=s;y.count&&(y.grow?N(t,y,G,e):l&&D(y,o,G,_),a&&O(f,y,o)),a?(i?D(f,"height",m,n):f.gap=c,function(t,e,o,i){I(t,e,o);const{list:n}=e;if(n.length>1&&(i||(i=Y[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,f,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],C(t,h,a,r,o,i),r+=h.height+e.gap}(t,f,u,e)):(I(t,y,h),C(t,y,0,y.y,u,e))}},it=function(t,e){const o="height",{children:i,itemBox:n}=t,s=W(t,!1),{complex:h,wrap:a,xGap:r,yGap:c,isAutoYGap:l,isFitYGap:_}=s;if(!i.length)return;const f=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},u=l?0:c;let p,g,d,w,y,{x:x,y:b,width:G,height:m}=t.__layout.contentBounds;for(let s=0,r=i.length;s<r;s++)p=i[w=e?r-1-s:s],p.__.inFlow&&0!==p.__.visible&&(g=U(p,n),h?(p.__flowBounds=g,y||(y=j(w,u)),a&&y.count&&y.height+g.height>m&&(y.grow&&Z(t,y,m,e),l&&D(y,o,m,_),O(f,y,o),y=j(w,u)),d=g.height,p.__heightGrow&&(y.grow+=p.__heightGrow,d=0,p.__.heightRange&&(y.hasRangeSize=!0)),p.__widthGrow&&T(p,g,G),y.height+=y.count?d+u:d,y.width=Math.max(y.width,g.width),y.count++):($(p,x-g.x,b-g.y),b+=g.height+u));if(h){const{isAutoXGap:i,isFitXGap:n,contentAlign:h,rowXAlign:c,rowYAlign:u}=s;y.count&&(y.grow&&Z(t,y,m,e),l&&D(y,o,m,_),a&&O(f,y,o)),a?(i?D(f,"width",G,n):f.gap=r,function(t,e,o,i){I(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.y=e.height-t.height,"center"===i&&(t.y/=2)}}(t,f,h,u),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,f,c,e)):(I(t,y,h),V(t,y,y.x,0,c,e))}};return e.UI.changeAttr("autoWidth",void 0,tt),e.UI.changeAttr("autoHeight",void 0,tt),e.Box.prototype.__updateFlowLayout=function(){this.leafer.created=!1;const{flow:t}=this.__;switch(t){case"x":case!0:ot(this);break;case"y":it(this);break;case"x-reverse":ot(this,!0);break;case"y-reverse":it(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(),et(e.contentBounds,e.boxBounds,t,!0)):o||e.shrinkContentCancel()},t.PathScaler=g,t.scaleResize=R,t.scaleResizeFontSize=B,t.scaleResizeGroup=v,t.scaleResizePath=A,t.scaleResizePoints=k,t}({},LeaferUI);
|
|
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,g={scale(t,e,g){if(!t)return;let w,y=0,b=t.length;for(;y<b;)switch(w=t[y],w){case o:case i:d(t,e,g,y,1),y+=3;break;case n:d(t,e,g,y,3),y+=7;break;case s:d(t,e,g,y,2),y+=5;break;case h:y+=1;break;case a:d(t,e,g,y,2),y+=5;break;case r:d(t,e,g,y,2),y+=9;break;case c:d(t,e,g,y,2),y+=6;break;case l:d(t,e,g,y,2),y+=9;break;case _:d(t,e,g,y,2),y+=5;break;case u:t[y]=l,t.splice(y+4,0,t[y+3],0),d(t,e,g,y,2),y+=9,b+=2;break;case p:t[y]=_,t.splice(y+4,0,t[y+3]),d(t,e,g,y,2),y+=5,b+=1;break;case f:d(t,e,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}=g,w=e.MatrixHelper.get(),{topLeft:y,top:b,topRight:x,right:G,bottom:m,left:R}=e.Direction9;function z(t,e,o){t.pathInputed?A(t,e,o):(1!==e&&(t.width*=e),1!==o&&(t.height*=o))}function B(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 b:case m:s=o,i.affectScaleOrRotation?t.moveInner(-h/2,0):t.x-=h/2;break;case R:case G:i.affectScaleOrRotation?t.moveInner(0,-a/2):t.y-=a/2;break;case y: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 A(t,e,o){g.scale(t.__.path,e,o),t.path=t.__.path}function k(t,e,o){g.scalePoints(t.__.points,e,o),t.points=t.__.points}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 v=e.Leaf.prototype;function P(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}v.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))},v.__scaleResize=function(t,e){z(this,t,e)},v.resizeWidth=function(t){const e=t/this.getBounds("box","local").width;this.scaleOf(this.__layout.boxBounds,e,this.__.lockRatio?e:1,!0)},v.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?B(this,t,e):z(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):z(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):(z(this,t,e),this.__.resizeChildren&&F(this,t,e))},"function"==typeof SuppressedError&&SuppressedError;class S extends e.BoxData{}t.Flow=class extends e.Box{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}},P([e.dataProcessor(S)],t.Flow.prototype,"__",void 0),P([e.autoLayoutType("x")],t.Flow.prototype,"flow",void 0),t.Flow=P([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"},L={"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 T(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:Y}=e.PointHelper;function I(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 C(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 W={};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?(W.xGap=o.x||0,W.yGap=o.y||0):W.xGap=W.yGap=o,W.isAutoXGap="string"==typeof W.xGap&&!s,W.isAutoYGap="string"==typeof W.yGap&&!h,W.complex=a||"top-left"!==i||t.__hasGrow||W.isAutoXGap||W.isAutoYGap,W.wrap=a,W.complex&&(W.isFitXGap="fit"===W.xGap&&!s,W.isFitYGap="fit"===W.yGap&&!h,"object"==typeof i?(W.contentAlign=i.content||"top-left",W.rowXAlign=i.x||"from",W.rowYAlign=i.y||"from"):(W.contentAlign=i,W.rowXAlign=X[i],W.rowYAlign=L[i])),W}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;const{move:K}=e.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:$}=e.PointHelper;function tt(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 et=e.UI.prototype,ot=e.Box.prototype;e.autoLayoutType(!1)(et,"flow"),e.boundsType(0)(et,"gap"),e.boundsType("top-left")(et,"flowAlign"),e.boundsType(!1)(et,"flowWrap"),e.boundsType("box")(et,"itemBox"),e.boundsType(!0)(et,"inFlow"),tt()(et,"autoWidth"),tt()(et,"autoHeight"),e.boundsType()(et,"lockRatio"),e.boundsType()(et,"autoBox"),e.boundsType()(et,"widthRange"),e.boundsType()(et,"heightRange");const{copyAndSpread:it}=e.BoundsHelper;let nt=function(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,g,d,w,y,{x:b,y:x,width:G,height:m}=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&&(g=D(f,n),h?(f.__flowBounds=g,y||(y=M(w,p)),a&&y.count&&y.width+g.width>G&&(y.grow?N(t,y,G,e):l&&j(y,o,G,_),C(u,y,o),y=M(w,p)),d=g.width,f.__widthGrow&&(y.grow+=f.__widthGrow,d=0,f.__.widthRange&&(y.hasRangeSize=!0)),f.__heightGrow&&q(f,g,m),y.width+=y.count?d+p:d,y.height=Math.max(y.height,g.height),y.count++):(J(f,b-g.x,x-g.y),b+=g.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&&C(u,y,o)),a?(i?j(u,"height",m,n):u.gap=c,function(t,e,o,i){T(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],I(t,h,a,r,o,i),r+=h.height+e.gap}(t,u,p,e)):(T(t,y,h),I(t,y,0,y.y,p,e))}},st=function(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,g,d,w,y,{x:b,y:x,width:G,height:m}=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&&(g=D(f,n),h?(f.__flowBounds=g,y||(y=M(w,p)),a&&y.count&&y.height+g.height>m&&(y.grow&&Z(t,y,m,e),l&&j(y,o,m,_),C(u,y,o),y=M(w,p)),d=g.height,f.__heightGrow&&(y.grow+=f.__heightGrow,d=0,f.__.heightRange&&(y.hasRangeSize=!0)),f.__widthGrow&&U(f,g,G),y.height+=y.count?d+p:d,y.width=Math.max(y.width,g.width),y.count++):($(f,b-g.x,x-g.y),x+=g.height+p));if(h){const{isAutoXGap:i,isFitXGap:n,contentAlign:h,rowXAlign:c,rowYAlign:p}=s;y.count&&(y.grow&&Z(t,y,m,e),l&&j(y,o,m,_),a&&C(u,y,o)),a?(i?j(u,"width",G,n):u.gap=r,function(t,e,o,i){T(t,e,o);const{list:n}=e;if(n.length>1&&(i||(i=L[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)):(T(t,y,h),V(t,y,y.x,0,c,e))}};return ot.__updateFlowLayout=function(){this.leafer.created=!1;const{flow:t}=this.__;switch(t){case"x":case!0:nt(this);break;case"y":st(this);break;case"x-reverse":nt(this,!0);break;case"y-reverse":st(this,!0)}this.leafer.created=!0},ot.__updateContentBounds=function(){const{padding:t}=this.__,e=this.__layout,o=e.contentBounds===e.boxBounds;t?(o&&e.shrinkContent(),it(e.contentBounds,e.boxBounds,t,!0)):o||e.shrinkContentCancel()},t.PathScaler=g,t.scaleResize=z,t.scaleResizeFontSize=B,t.scaleResizeGroup=F,t.scaleResizePath=A,t.scaleResizePoints=k,t}({},LeaferUI);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-in/flow",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
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
|
"dependencies": {
|
|
37
|
-
"@leafer-ui/draw": "^1.0.
|
|
38
|
-
"@leafer-ui/interface": "^1.0.
|
|
39
|
-
"@leafer-in/resize": "^1.0.
|
|
40
|
-
"@leafer-in/interface": "^1.0.
|
|
37
|
+
"@leafer-ui/draw": "^1.0.4",
|
|
38
|
+
"@leafer-ui/interface": "^1.0.4",
|
|
39
|
+
"@leafer-in/resize": "^1.0.4",
|
|
40
|
+
"@leafer-in/interface": "^1.0.4"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,20 +2,36 @@ export * from '@leafer-in/resize'
|
|
|
2
2
|
|
|
3
3
|
export { Flow } from './Flow'
|
|
4
4
|
|
|
5
|
-
import { BoundsHelper, Box, UI } from '@leafer-ui/draw'
|
|
5
|
+
import { BoundsHelper, Box, UI, autoLayoutType, boundsType } from '@leafer-ui/draw'
|
|
6
6
|
|
|
7
7
|
import { flowX } from './layout/flowX'
|
|
8
8
|
import { flowY } from './layout/flowY'
|
|
9
9
|
import { autoBoundsType } from './decorate'
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
const ui = UI.prototype, box = Box.prototype
|
|
13
|
+
|
|
14
|
+
// addAttr
|
|
15
|
+
autoLayoutType(false)(ui, 'flow')
|
|
16
|
+
boundsType(0)(ui, 'gap')
|
|
17
|
+
boundsType('top-left')(ui, 'flowAlign')
|
|
18
|
+
boundsType(false)(ui, 'flowWrap')
|
|
19
|
+
|
|
20
|
+
boundsType('box')(ui, 'itemBox')
|
|
21
|
+
boundsType(true)(ui, 'inFlow')
|
|
22
|
+
|
|
23
|
+
autoBoundsType()(ui, 'autoWidth')
|
|
24
|
+
autoBoundsType()(ui, 'autoHeight')
|
|
25
|
+
boundsType()(ui, 'lockRatio')
|
|
26
|
+
boundsType()(ui, 'autoBox')
|
|
27
|
+
boundsType()(ui, 'widthRange')
|
|
28
|
+
boundsType()(ui, 'heightRange')
|
|
29
|
+
|
|
30
|
+
|
|
12
31
|
const { copyAndSpread } = BoundsHelper
|
|
13
32
|
let doFlowX = flowX, doFlowY = flowY
|
|
14
33
|
|
|
15
|
-
|
|
16
|
-
UI.changeAttr('autoHeight', undefined, autoBoundsType)
|
|
17
|
-
|
|
18
|
-
Box.prototype.__updateFlowLayout = function (): void {
|
|
34
|
+
box.__updateFlowLayout = function (): void {
|
|
19
35
|
this.leafer.created = false
|
|
20
36
|
const { flow } = this.__
|
|
21
37
|
switch (flow) {
|
|
@@ -36,7 +52,7 @@ Box.prototype.__updateFlowLayout = function (): void {
|
|
|
36
52
|
this.leafer.created = true
|
|
37
53
|
}
|
|
38
54
|
|
|
39
|
-
|
|
55
|
+
box.__updateContentBounds = function (): void {
|
|
40
56
|
const { padding } = this.__
|
|
41
57
|
const layout = this.__layout
|
|
42
58
|
const same = layout.contentBounds === layout.boxBounds
|
|
@@ -37,8 +37,9 @@ export const alignToInnerYMap: IFlowAlignToAxisAlignMap = {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export function alignContent(box: IBox, content: IBoundsData, align: IFlowAlign): void {
|
|
40
|
-
AlignHelper.toPoint(align as any, content, box.__layout.contentBounds, point)
|
|
41
40
|
const data = box.__
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
const { contentBounds } = box.__layout
|
|
42
|
+
AlignHelper.toPoint(align as any, content, contentBounds, point)
|
|
43
|
+
content.x = data.__autoWidth ? contentBounds.x : point.x
|
|
44
|
+
content.y = data.__autoHeight ? contentBounds.y : point.y
|
|
44
45
|
}
|