@leafer-in/flow 1.0.4 → 1.0.5
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 +42 -9
- package/dist/flow.esm.js +42 -9
- package/dist/flow.esm.min.js +1 -1
- package/dist/flow.js +42 -9
- package/dist/flow.min.cjs +1 -1
- package/dist/flow.min.js +1 -1
- package/package.json +8 -8
- package/src/index.ts +52 -10
package/dist/flow.cjs
CHANGED
|
@@ -689,7 +689,7 @@ function autoBoundsType(defaultValue) {
|
|
|
689
689
|
}));
|
|
690
690
|
}
|
|
691
691
|
|
|
692
|
-
const ui = draw.UI.prototype, box = draw.Box.prototype;
|
|
692
|
+
const ui = draw.UI.prototype, box = draw.Box.prototype, { __updateBoxBounds } = draw.Group.prototype;
|
|
693
693
|
draw.autoLayoutType(false)(ui, 'flow');
|
|
694
694
|
draw.boundsType(0)(ui, 'gap');
|
|
695
695
|
draw.boundsType('top-left')(ui, 'flowAlign');
|
|
@@ -703,26 +703,27 @@ draw.boundsType()(ui, 'autoBox');
|
|
|
703
703
|
draw.boundsType()(ui, 'widthRange');
|
|
704
704
|
draw.boundsType()(ui, 'heightRange');
|
|
705
705
|
const { copyAndSpread } = draw.BoundsHelper;
|
|
706
|
-
let doFlowX = flowX, doFlowY = flowY;
|
|
707
706
|
box.__updateFlowLayout = function () {
|
|
708
|
-
|
|
709
|
-
|
|
707
|
+
const { leaferIsCreated, flow } = this;
|
|
708
|
+
if (leaferIsCreated)
|
|
709
|
+
this.leafer.created = false;
|
|
710
710
|
switch (flow) {
|
|
711
711
|
case 'x':
|
|
712
712
|
case true:
|
|
713
|
-
|
|
713
|
+
flowX(this);
|
|
714
714
|
break;
|
|
715
715
|
case 'y':
|
|
716
|
-
|
|
716
|
+
flowY(this);
|
|
717
717
|
break;
|
|
718
718
|
case 'x-reverse':
|
|
719
|
-
|
|
719
|
+
flowX(this, true);
|
|
720
720
|
break;
|
|
721
721
|
case 'y-reverse':
|
|
722
|
-
|
|
722
|
+
flowY(this, true);
|
|
723
723
|
break;
|
|
724
724
|
}
|
|
725
|
-
|
|
725
|
+
if (leaferIsCreated)
|
|
726
|
+
this.leafer.created = true;
|
|
726
727
|
};
|
|
727
728
|
box.__updateContentBounds = function () {
|
|
728
729
|
const { padding } = this.__;
|
|
@@ -738,6 +739,38 @@ box.__updateContentBounds = function () {
|
|
|
738
739
|
layout.shrinkContentCancel();
|
|
739
740
|
}
|
|
740
741
|
};
|
|
742
|
+
box.__updateBoxBounds = function (secondLayout) {
|
|
743
|
+
const data = this.__;
|
|
744
|
+
if (this.children.length) {
|
|
745
|
+
const { flow } = data;
|
|
746
|
+
if (data.__autoSide) {
|
|
747
|
+
flow && !secondLayout ? this.__updateRectBoxBounds() : __updateBoxBounds.call(this);
|
|
748
|
+
const { boxBounds } = this.__layout;
|
|
749
|
+
if (!data.__autoSize) {
|
|
750
|
+
if (data.__autoWidth) {
|
|
751
|
+
if (!flow)
|
|
752
|
+
boxBounds.width += boxBounds.x, boxBounds.x = 0;
|
|
753
|
+
boxBounds.height = data.height, boxBounds.y = 0;
|
|
754
|
+
}
|
|
755
|
+
else {
|
|
756
|
+
if (!flow)
|
|
757
|
+
boxBounds.height += boxBounds.y, boxBounds.y = 0;
|
|
758
|
+
boxBounds.width = data.width, boxBounds.x = 0;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
flow && secondLayout && data.padding && copyAndSpread(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : (data.__autoWidth ? 'width' : 'height'));
|
|
762
|
+
this.__updateNaturalSize();
|
|
763
|
+
}
|
|
764
|
+
else {
|
|
765
|
+
this.__updateRectBoxBounds();
|
|
766
|
+
}
|
|
767
|
+
if (flow)
|
|
768
|
+
this.__updateContentBounds();
|
|
769
|
+
}
|
|
770
|
+
else {
|
|
771
|
+
this.__updateRectBoxBounds();
|
|
772
|
+
}
|
|
773
|
+
};
|
|
741
774
|
|
|
742
775
|
exports.PathScaler = PathScaler;
|
|
743
776
|
exports.scaleResize = scaleResize;
|
package/dist/flow.esm.js
CHANGED
|
@@ -687,7 +687,7 @@ function autoBoundsType(defaultValue) {
|
|
|
687
687
|
}));
|
|
688
688
|
}
|
|
689
689
|
|
|
690
|
-
const ui = UI.prototype, box = Box.prototype;
|
|
690
|
+
const ui = UI.prototype, box = Box.prototype, { __updateBoxBounds } = Group.prototype;
|
|
691
691
|
autoLayoutType(false)(ui, 'flow');
|
|
692
692
|
boundsType(0)(ui, 'gap');
|
|
693
693
|
boundsType('top-left')(ui, 'flowAlign');
|
|
@@ -701,26 +701,27 @@ boundsType()(ui, 'autoBox');
|
|
|
701
701
|
boundsType()(ui, 'widthRange');
|
|
702
702
|
boundsType()(ui, 'heightRange');
|
|
703
703
|
const { copyAndSpread } = BoundsHelper;
|
|
704
|
-
let doFlowX = flowX, doFlowY = flowY;
|
|
705
704
|
box.__updateFlowLayout = function () {
|
|
706
|
-
|
|
707
|
-
|
|
705
|
+
const { leaferIsCreated, flow } = this;
|
|
706
|
+
if (leaferIsCreated)
|
|
707
|
+
this.leafer.created = false;
|
|
708
708
|
switch (flow) {
|
|
709
709
|
case 'x':
|
|
710
710
|
case true:
|
|
711
|
-
|
|
711
|
+
flowX(this);
|
|
712
712
|
break;
|
|
713
713
|
case 'y':
|
|
714
|
-
|
|
714
|
+
flowY(this);
|
|
715
715
|
break;
|
|
716
716
|
case 'x-reverse':
|
|
717
|
-
|
|
717
|
+
flowX(this, true);
|
|
718
718
|
break;
|
|
719
719
|
case 'y-reverse':
|
|
720
|
-
|
|
720
|
+
flowY(this, true);
|
|
721
721
|
break;
|
|
722
722
|
}
|
|
723
|
-
|
|
723
|
+
if (leaferIsCreated)
|
|
724
|
+
this.leafer.created = true;
|
|
724
725
|
};
|
|
725
726
|
box.__updateContentBounds = function () {
|
|
726
727
|
const { padding } = this.__;
|
|
@@ -736,5 +737,37 @@ box.__updateContentBounds = function () {
|
|
|
736
737
|
layout.shrinkContentCancel();
|
|
737
738
|
}
|
|
738
739
|
};
|
|
740
|
+
box.__updateBoxBounds = function (secondLayout) {
|
|
741
|
+
const data = this.__;
|
|
742
|
+
if (this.children.length) {
|
|
743
|
+
const { flow } = data;
|
|
744
|
+
if (data.__autoSide) {
|
|
745
|
+
flow && !secondLayout ? this.__updateRectBoxBounds() : __updateBoxBounds.call(this);
|
|
746
|
+
const { boxBounds } = this.__layout;
|
|
747
|
+
if (!data.__autoSize) {
|
|
748
|
+
if (data.__autoWidth) {
|
|
749
|
+
if (!flow)
|
|
750
|
+
boxBounds.width += boxBounds.x, boxBounds.x = 0;
|
|
751
|
+
boxBounds.height = data.height, boxBounds.y = 0;
|
|
752
|
+
}
|
|
753
|
+
else {
|
|
754
|
+
if (!flow)
|
|
755
|
+
boxBounds.height += boxBounds.y, boxBounds.y = 0;
|
|
756
|
+
boxBounds.width = data.width, boxBounds.x = 0;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
flow && secondLayout && data.padding && copyAndSpread(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : (data.__autoWidth ? 'width' : 'height'));
|
|
760
|
+
this.__updateNaturalSize();
|
|
761
|
+
}
|
|
762
|
+
else {
|
|
763
|
+
this.__updateRectBoxBounds();
|
|
764
|
+
}
|
|
765
|
+
if (flow)
|
|
766
|
+
this.__updateContentBounds();
|
|
767
|
+
}
|
|
768
|
+
else {
|
|
769
|
+
this.__updateRectBoxBounds();
|
|
770
|
+
}
|
|
771
|
+
};
|
|
739
772
|
|
|
740
773
|
export { Flow, PathScaler, scaleResize, scaleResizeFontSize, scaleResizeGroup, scaleResizePath, scaleResizePoints };
|
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 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};
|
|
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 a,Group as c,Box as r,BoxData as l,dataProcessor as _,autoLayoutType as u,registerUI as f,AlignHelper as g,PointHelper as p,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: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:a}=i.boxBounds;switch(h*=o-e,a*=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,-a/2):t.y-=a/2;break;case H:case L: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){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 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}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},a.prototype.__scaleResize=function(t,e){this.pathInputed?Z(this,t,e):this.points?q(this,t,e):Q(this,t,e)},c.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;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 a,c,{x:r,start:l}=e,_=i;r+=o;for(let t=0,o=e.count;t<o;t++)a=h[s?l-t:l+t],a.__.inFlow&&0!==a.__.visible?(c=a.__flowBounds,"from"!==n&&(_=i+(e.height-c.height)/("center"===n?2:1)),it(a,r-c.x,_-c.y),r+=c.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 at(t,e){const{gap:o,flowAlign:i,flowWrap:n,__autoWidth:s,__autoHeight:h}=t.__,a=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=a||"top-left"!==i||t.__hasGrow||ht.isAutoXGap||ht.isAutoYGap,ht.wrap=a,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 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 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,a=0,c=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?(a+=h,r-=s):c&&(n.__.widthRange?c.unshift(n):c.push(n))):o++;a&&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}))}(c,a,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:gt}=d;function pt(t,e,o,i){let n,s,h,a=0,c=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?(a+=h,r-=s):c&&(n.__.heightRange?c.unshift(n):c.push(n))):o++;a&&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}))}(c,a,r)}function dt(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:wt}=p;function yt(t,e){const o="width",{children:i,itemBox:n}=t,s=at(t,!0),{complex:h,wrap:a,xGap:c,yGap:r,isAutoXGap:l,isFitXGap:_}=s;if(!i.length)return;const u=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},f=l?0:c;let g,p,d,w,y,{x:x,y:b,width:G,height:m}=t.__layout.contentBounds;for(let s=0,c=i.length;s<c;s++)g=i[w=e?c-1-s:s],g.__.inFlow&&0!==g.__.visible&&(p=lt(g,n),h?(g.__flowBounds=p,y||(y=ct(w,f)),a&&y.count&&y.width+p.width>G&&(y.grow?ut(t,y,G,e):l&&rt(y,o,G,_),st(u,y,o),y=ct(w,f)),d=p.width,g.__widthGrow&&(y.grow+=g.__widthGrow,d=0,g.__.widthRange&&(y.hasRangeSize=!0)),g.__heightGrow&&dt(g,p,m),y.width+=y.count?d+f:d,y.height=Math.max(y.height,p.height),y.count++):(wt(g,x-p.x,b-p.y),x+=p.width+f));if(h){const{isAutoYGap:i,isFitYGap:n,contentAlign:h,rowXAlign:c,rowYAlign:f}=s;y.count&&(y.grow?ut(t,y,G,e):l&&rt(y,o,G,_),a&&st(u,y,o)),a?(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,c),function(t,e,o,i){const{list:n}=e,s="reverse"===t.__.flowWrap;let h,{x:a,y:c}=e;for(let r=0,l=n.length;r<l;r++)h=n[s?l-1-r:r],nt(t,h,a,c,o,i),c+=h.height+e.gap}(t,u,f,e)):(ot(t,y,h),nt(t,y,0,y.y,f,e))}}const{move:xt}=p;function bt(t,e,o,i,n,s){const{children:h}=t;let a,c,{y:r,start:l}=e,_=o;r+=i;for(let t=0,i=e.count;t<i;t++)a=h[s?l-t:l+t],a.__.inFlow&&0!==a.__.visible?(c=a.__flowBounds,"from"!==n&&(_=o+(e.width-c.width)/("center"===n?2:1)),xt(a,_-c.x,r-c.y),r+=c.height+e.gap):i++}const{move:Gt}=p;function mt(t,e){const o="height",{children:i,itemBox:n}=t,s=at(t,!1),{complex:h,wrap:a,xGap:c,yGap:r,isAutoYGap:l,isFitYGap:_}=s;if(!i.length)return;const u=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},f=l?0:r;let g,p,d,w,y,{x:x,y:b,width:G,height:m}=t.__layout.contentBounds;for(let s=0,c=i.length;s<c;s++)g=i[w=e?c-1-s:s],g.__.inFlow&&0!==g.__.visible&&(p=lt(g,n),h?(g.__flowBounds=p,y||(y=ct(w,f)),a&&y.count&&y.height+p.height>m&&(y.grow&&pt(t,y,m,e),l&&rt(y,o,m,_),st(u,y,o),y=ct(w,f)),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+f:d,y.width=Math.max(y.width,p.width),y.count++):(Gt(g,x-p.x,b-p.y),b+=p.height+f));if(h){const{isAutoXGap:i,isFitXGap:n,contentAlign:h,rowXAlign:r,rowYAlign:f}=s;y.count&&(y.grow&&pt(t,y,m,e),l&&rt(y,o,m,_),a&&st(u,y,o)),a?(i?rt(u,"width",G,n):u.gap=c,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:a,y:c}=e;for(let r=0,l=n.length;r<l;r++)h=n[s?l-1-r:r],bt(t,h,a,c,o,i),a+=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}=c.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,"lockRatio"),G()(Rt,"autoBox"),G()(Rt,"widthRange"),G()(Rt,"heightRange");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};
|
package/dist/flow.js
CHANGED
|
@@ -689,7 +689,7 @@ this.LeaferIN.flow = (function (exports, draw) {
|
|
|
689
689
|
}));
|
|
690
690
|
}
|
|
691
691
|
|
|
692
|
-
const ui = draw.UI.prototype, box = draw.Box.prototype;
|
|
692
|
+
const ui = draw.UI.prototype, box = draw.Box.prototype, { __updateBoxBounds } = draw.Group.prototype;
|
|
693
693
|
draw.autoLayoutType(false)(ui, 'flow');
|
|
694
694
|
draw.boundsType(0)(ui, 'gap');
|
|
695
695
|
draw.boundsType('top-left')(ui, 'flowAlign');
|
|
@@ -703,26 +703,27 @@ this.LeaferIN.flow = (function (exports, draw) {
|
|
|
703
703
|
draw.boundsType()(ui, 'widthRange');
|
|
704
704
|
draw.boundsType()(ui, 'heightRange');
|
|
705
705
|
const { copyAndSpread } = draw.BoundsHelper;
|
|
706
|
-
let doFlowX = flowX, doFlowY = flowY;
|
|
707
706
|
box.__updateFlowLayout = function () {
|
|
708
|
-
|
|
709
|
-
|
|
707
|
+
const { leaferIsCreated, flow } = this;
|
|
708
|
+
if (leaferIsCreated)
|
|
709
|
+
this.leafer.created = false;
|
|
710
710
|
switch (flow) {
|
|
711
711
|
case 'x':
|
|
712
712
|
case true:
|
|
713
|
-
|
|
713
|
+
flowX(this);
|
|
714
714
|
break;
|
|
715
715
|
case 'y':
|
|
716
|
-
|
|
716
|
+
flowY(this);
|
|
717
717
|
break;
|
|
718
718
|
case 'x-reverse':
|
|
719
|
-
|
|
719
|
+
flowX(this, true);
|
|
720
720
|
break;
|
|
721
721
|
case 'y-reverse':
|
|
722
|
-
|
|
722
|
+
flowY(this, true);
|
|
723
723
|
break;
|
|
724
724
|
}
|
|
725
|
-
|
|
725
|
+
if (leaferIsCreated)
|
|
726
|
+
this.leafer.created = true;
|
|
726
727
|
};
|
|
727
728
|
box.__updateContentBounds = function () {
|
|
728
729
|
const { padding } = this.__;
|
|
@@ -738,6 +739,38 @@ this.LeaferIN.flow = (function (exports, draw) {
|
|
|
738
739
|
layout.shrinkContentCancel();
|
|
739
740
|
}
|
|
740
741
|
};
|
|
742
|
+
box.__updateBoxBounds = function (secondLayout) {
|
|
743
|
+
const data = this.__;
|
|
744
|
+
if (this.children.length) {
|
|
745
|
+
const { flow } = data;
|
|
746
|
+
if (data.__autoSide) {
|
|
747
|
+
flow && !secondLayout ? this.__updateRectBoxBounds() : __updateBoxBounds.call(this);
|
|
748
|
+
const { boxBounds } = this.__layout;
|
|
749
|
+
if (!data.__autoSize) {
|
|
750
|
+
if (data.__autoWidth) {
|
|
751
|
+
if (!flow)
|
|
752
|
+
boxBounds.width += boxBounds.x, boxBounds.x = 0;
|
|
753
|
+
boxBounds.height = data.height, boxBounds.y = 0;
|
|
754
|
+
}
|
|
755
|
+
else {
|
|
756
|
+
if (!flow)
|
|
757
|
+
boxBounds.height += boxBounds.y, boxBounds.y = 0;
|
|
758
|
+
boxBounds.width = data.width, boxBounds.x = 0;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
flow && secondLayout && data.padding && copyAndSpread(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : (data.__autoWidth ? 'width' : 'height'));
|
|
762
|
+
this.__updateNaturalSize();
|
|
763
|
+
}
|
|
764
|
+
else {
|
|
765
|
+
this.__updateRectBoxBounds();
|
|
766
|
+
}
|
|
767
|
+
if (flow)
|
|
768
|
+
this.__updateContentBounds();
|
|
769
|
+
}
|
|
770
|
+
else {
|
|
771
|
+
this.__updateRectBoxBounds();
|
|
772
|
+
}
|
|
773
|
+
};
|
|
741
774
|
|
|
742
775
|
exports.PathScaler = PathScaler;
|
|
743
776
|
exports.scaleResize = scaleResize;
|
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: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;
|
|
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,d={scale(t,d,g){if(!t)return;let w,y=0,x=t.length;for(;y<x;)switch(w=t[y],w){case e:case o:f(t,d,g,y,1),y+=3;break;case i:f(t,d,g,y,3),y+=7;break;case n:f(t,d,g,y,2),y+=5;break;case s:y+=1;break;case h:f(t,d,g,y,2),y+=5;break;case a:f(t,d,g,y,2),y+=9;break;case r:f(t,d,g,y,2),y+=6;break;case c:f(t,d,g,y,2),y+=9;break;case l:f(t,d,g,y,2),y+=5;break;case _:t[y]=c,t.splice(y+4,0,t[y+3],0),f(t,d,g,y,2),y+=9,x+=2;break;case u:t[y]=l,t.splice(y+4,0,t[y+3]),f(t,d,g,y,2),y+=5,x+=1;break;case p:f(t,d,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:f}=d,g=t.MatrixHelper.get(),{topLeft:w,top:y,topRight:x,right:b,bottom:G,left:B}=t.Direction9;function R(t,e,o){t.pathInputed?z(t,e,o):(1!==e&&(t.width*=e),1!==o&&(t.height*=o))}function m(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){d.scale(t.__.path,e,o),t.path=t.__.path}function A(t,e,o){d.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++)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){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?m(this,t,e):R(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):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 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:T}=t.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)),T(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 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 d,f,g,w,y,{x:x,y:b,width:G,height:B}=t.__layout.contentBounds;for(let s=0,r=i.length;s<r;s++)d=i[w=e?r-1-s:s],d.__.inFlow&&0!==d.__.visible&&(f=j(d,n),h?(d.__flowBounds=f,y||(y=O(w,p)),a&&y.count&&y.width+f.width>G&&(y.grow?E(t,y,G,e):l&&M(y,o,G,_),W(u,y,o),y=O(w,p)),g=f.width,d.__widthGrow&&(y.grow+=d.__widthGrow,g=0,d.__.widthRange&&(y.hasRangeSize=!0)),d.__heightGrow&&Q(d,f,B),y.width+=y.count?g+p:g,y.height=Math.max(y.height,f.height),y.count++):(Z(d,x-f.x,b-f.y),x+=f.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&&W(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],Y(t,h,a,r,o,i),r+=h.height+e.gap}(t,u,p,e)):(C(t,y,h),Y(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 d,f,g,w,y,{x:x,y:b,width:G,height:B}=t.__layout.contentBounds;for(let s=0,r=i.length;s<r;s++)d=i[w=e?r-1-s:s],d.__.inFlow&&0!==d.__.visible&&(f=j(d,n),h?(d.__flowBounds=f,y||(y=O(w,p)),a&&y.count&&y.height+f.height>B&&(y.grow&&q(t,y,B,e),l&&M(y,o,B,_),W(u,y,o),y=O(w,p)),g=f.height,d.__heightGrow&&(y.grow+=d.__heightGrow,g=0,d.__.heightRange&&(y.hasRangeSize=!0)),d.__widthGrow&&U(d,f,G),y.height+=y.count?g+p:g,y.width=Math.max(y.width,f.width),y.count++):($(d,x-f.x,b-f.y),b+=f.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&&W(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,"lockRatio"),t.boundsType()(ot,"autoBox"),t.boundsType()(ot,"widthRange"),t.boundsType()(ot,"heightRange");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=d,exports.scaleResize=R,exports.scaleResizeFontSize=m,exports.scaleResizeGroup=k,exports.scaleResizePath=z,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: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);
|
|
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:R}=e.Direction9;function m(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 R: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){d.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 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){m(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):m(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):m(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):(m(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 T(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 Y(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=C[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:N}=e.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?N(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?E(t,y,G,e):l&&j(y,o,G,_),Y(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?E(t,y,G,e):l&&j(y,o,G,_),a&&Y(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],T(t,h,a,r,o,i),r+=h.height+e.gap}(t,u,p,e)):(I(t,y,h),T(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,_),Y(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&&Y(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,"lockRatio"),e.boundsType()(it,"autoBox"),e.boundsType()(it,"widthRange"),e.boundsType()(it,"heightRange");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=m,t.scaleResizeFontSize=z,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.5",
|
|
4
4
|
"description": "@leafer-in/flow",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
],
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
24
|
-
"url": "https://github.com/leaferjs/in.git"
|
|
24
|
+
"url": "https://github.com/leaferjs/leafer-in.git"
|
|
25
25
|
},
|
|
26
|
-
"homepage": "https://github.com/leaferjs/in/tree/main/packages/flow",
|
|
27
|
-
"bugs": "https://github.com/leaferjs/in/issues",
|
|
26
|
+
"homepage": "https://github.com/leaferjs/leafer-in/tree/main/packages/flow",
|
|
27
|
+
"bugs": "https://github.com/leaferjs/leafer-in/issues",
|
|
28
28
|
"keywords": [
|
|
29
29
|
"leafer flow",
|
|
30
30
|
"leafer-flow",
|
|
@@ -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.5",
|
|
38
|
+
"@leafer-ui/interface": "^1.0.5",
|
|
39
|
+
"@leafer-in/resize": "^1.0.5",
|
|
40
|
+
"@leafer-in/interface": "^1.0.5"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,14 +2,14 @@ export * from '@leafer-in/resize'
|
|
|
2
2
|
|
|
3
3
|
export { Flow } from './Flow'
|
|
4
4
|
|
|
5
|
-
import { BoundsHelper, Box, UI, autoLayoutType, boundsType } from '@leafer-ui/draw'
|
|
5
|
+
import { BoundsHelper, Box, Group, 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
|
|
12
|
+
const ui = UI.prototype, box = Box.prototype, { __updateBoxBounds } = Group.prototype
|
|
13
13
|
|
|
14
14
|
// addAttr
|
|
15
15
|
autoLayoutType(false)(ui, 'flow')
|
|
@@ -29,27 +29,29 @@ boundsType()(ui, 'heightRange')
|
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
const { copyAndSpread } = BoundsHelper
|
|
32
|
-
let doFlowX = flowX, doFlowY = flowY
|
|
33
32
|
|
|
34
33
|
box.__updateFlowLayout = function (): void {
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
const { leaferIsCreated, flow } = this
|
|
35
|
+
|
|
36
|
+
if (leaferIsCreated) this.leafer.created = false
|
|
37
|
+
|
|
37
38
|
switch (flow) {
|
|
38
39
|
case 'x':
|
|
39
40
|
case true:
|
|
40
|
-
|
|
41
|
+
flowX(this)
|
|
41
42
|
break
|
|
42
43
|
case 'y':
|
|
43
|
-
|
|
44
|
+
flowY(this)
|
|
44
45
|
break
|
|
45
46
|
case 'x-reverse':
|
|
46
|
-
|
|
47
|
+
flowX(this, true)
|
|
47
48
|
break
|
|
48
49
|
case 'y-reverse':
|
|
49
|
-
|
|
50
|
+
flowY(this, true)
|
|
50
51
|
break
|
|
51
52
|
}
|
|
52
|
-
|
|
53
|
+
|
|
54
|
+
if (leaferIsCreated) this.leafer.created = true
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
box.__updateContentBounds = function (): void {
|
|
@@ -65,5 +67,45 @@ box.__updateContentBounds = function (): void {
|
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
|
|
70
|
+
box.__updateBoxBounds = function (secondLayout?: boolean): void { // autoSide且自动布局时需要二次布局
|
|
71
|
+
const data = this.__
|
|
72
|
+
|
|
73
|
+
if (this.children.length) {
|
|
74
|
+
|
|
75
|
+
const { flow } = data
|
|
76
|
+
|
|
77
|
+
if (data.__autoSide) {
|
|
78
|
+
|
|
79
|
+
// this.leafer.layouter.addExtra(this)
|
|
80
|
+
|
|
81
|
+
flow && !secondLayout ? this.__updateRectBoxBounds() : __updateBoxBounds.call(this)
|
|
82
|
+
|
|
83
|
+
const { boxBounds } = this.__layout
|
|
84
|
+
|
|
85
|
+
if (!data.__autoSize) {
|
|
86
|
+
if (data.__autoWidth) {
|
|
87
|
+
if (!flow) boxBounds.width += boxBounds.x, boxBounds.x = 0
|
|
88
|
+
boxBounds.height = data.height, boxBounds.y = 0
|
|
89
|
+
} else {
|
|
90
|
+
if (!flow) boxBounds.height += boxBounds.y, boxBounds.y = 0
|
|
91
|
+
boxBounds.width = data.width, boxBounds.x = 0
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
flow && secondLayout && data.padding && copyAndSpread(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : (data.__autoWidth ? 'width' : 'height'))
|
|
96
|
+
|
|
97
|
+
this.__updateNaturalSize()
|
|
98
|
+
|
|
99
|
+
} else {
|
|
100
|
+
this.__updateRectBoxBounds()
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (flow) this.__updateContentBounds()
|
|
104
|
+
|
|
105
|
+
} else {
|
|
106
|
+
this.__updateRectBoxBounds()
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
68
110
|
|
|
69
111
|
|