@leafer-in/flow 1.0.0-rc.28 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/flow.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t=require("@leafer-in/resize"),e=require("@leafer-ui/draw");function o(t,e,o,n){var i,r=arguments.length,h=r<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)h=Reflect.decorate(t,e,o,n);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(h=(r<3?i(h):r>3?i(e,o,h):i(e,o))||h);return r>3&&h&&Object.defineProperty(e,o,h),h}"function"==typeof SuppressedError&&SuppressedError;class n extends e.BoxData{}exports.Flow=class extends e.Box{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}},o([e.dataProcessor(n)],exports.Flow.prototype,"__",void 0),o([e.autoLayoutType("x")],exports.Flow.prototype,"flow",void 0),exports.Flow=o([e.registerUI()],exports.Flow);const i={},r={"top-left":"from",top:"center","top-right":"to",right:"to","bottom-right":"to",bottom:"center","bottom-left":"from",left:"from",center:"center","baseline-left":"from","baseline-center":"center","baseline-right":"to"},h={"top-left":"from",top:"from","top-right":"from",right:"center","bottom-right":"to",bottom:"to","bottom-left":"to",left:"center",center:"center","baseline-left":"to","baseline-center":"to","baseline-right":"to"};function s(t,o,n){e.AlignHelper.toPoint(n,o,t.__layout.contentBounds,i);const r=t.__;o.x=r.__autoWidth?0:i.x,o.y=r.__autoHeight?0:i.y}const{move:c}=e.PointHelper;function a(t,e,o,n,i,r){const{children:h}=t;let s,a,{x:l,start:_}=e,u=n;l+=o;for(let t=0,o=e.count;t<o;t++)s=h[r?_-t:_+t],s.__.inFlow&&0!==s.__.visible?(a=s.__flowBounds,"from"!==i&&(u=n+(e.height-a.height)/("center"===i?2:1)),c(s,l-a.x,u-a.y),l+=a.width+e.gap):o++}function l(t,e,o){const n="width"===o?"height":"width";t[o]=Math.max(t[o],e[o]),t[n]+=t.count?e[n]+t.gap:e[n],t.list.push(e),t.count++}const _={};function u(t,e){const{gap:o,flowAlign:n,flowWrap:i,__autoWidth:s,__autoHeight:c}=t.__,a=i&&(e?!s:!c);return"object"==typeof o?(_.xGap=o.x||0,_.yGap=o.y||0):_.xGap=_.yGap=o,_.isAutoXGap="string"==typeof _.xGap&&!s,_.isAutoYGap="string"==typeof _.yGap&&!c,_.complex=a||"top-left"!==n||t.__hasGrow||_.isAutoXGap||_.isAutoYGap,_.wrap=a,_.complex&&(_.isFitXGap="fit"===_.xGap&&!s,_.isFitYGap="fit"===_.yGap&&!c,"object"==typeof n?(_.contentAlign=n.content||"top-left",_.rowXAlign=n.x||"from",_.rowYAlign=n.y||"from"):(_.contentAlign=n,_.rowXAlign=r[n],_.rowYAlign=h[n])),_}function g(t,e){return{x:0,y:0,width:0,height:0,gap:e,start:t,count:0,grow:0}}function p(t,e,o,n){const{count:i}=t;i>1&&(o>t[e]||n)&&(t.gap=(o-t[e])/(i-1),t[e]=o)}function f(t,e){return"box"===e?t.__local:t.__layout.localStrokeBounds}const{within:w}=e.MathHelper;function d(t,e,o,n){let i,r,h,s=0,c=e.hasRangeSize&&[],{grow:a,start:l}=e;const _=e.width<o?(o-e.width)/a:0,{children:u}=t;_&&(e.width=o);for(let t=0,o=e.count;t<o;t++)i=u[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(r=i.__widthGrow)&&(h=y(i,i.__flowBounds,_*r),h?(s+=h,a-=r):c&&(i.__.widthRange?c.unshift(i):c.push(i))):o++;s&&function(t,e,o){let n,i,r,h;t.forEach((t=>{n=t.__widthGrow,i=e/o*n,h=y(t,r=t.__flowBounds,r.width+i),e-=i-h,o-=n}))}(c,s,a)}function y(t,e,o){const{widthRange:n,lockRatio:i}=t.__,r=n?w(o,n.min,n.max):o,h=r/e.width;return t.scaleResize(h,i?h:1),e.width=r,o-r}const{within:x}=e.MathHelper;function G(t,e,o,n){let i,r,h,s=0,c=e.hasRangeSize&&[],{grow:a,start:l}=e;const _=e.height<o?(o-e.height)/a:0,{children:u}=t;_&&(e.height=o);for(let t=0,o=e.count;t<o;t++)i=u[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(r=i.__heightGrow)&&(h=m(i,i.__flowBounds,_*r),h?(s+=h,a-=r):c&&(i.__.heightRange?c.unshift(i):c.push(i))):o++;s&&function(t,e,o){let n,i,r,h;t.forEach((t=>{n=t.__heightGrow,i=e/o*n,h=m(t,r=t.__flowBounds,r.height+i),e-=i-h,o-=n}))}(c,s,a)}function m(t,e,o){const{heightRange:n,lockRatio:i}=t.__,r=n?x(o,n.min,n.max):o,h=r/e.height;return t.scaleResize(i?h:1,h),e.height=r,o-r}const{move:b}=e.PointHelper;const{move:A}=e.PointHelper;function B(t,e,o,n,i,r){const{children:h}=t;let s,c,{y:a,start:l}=e,_=o;a+=n;for(let t=0,n=e.count;t<n;t++)s=h[r?l-t:l+t],s.__.inFlow&&0!==s.__.visible?(c=s.__flowBounds,"from"!==i&&(_=o+(e.width-c.width)/("center"===i?2:1)),A(s,_-c.x,a-c.y),a+=c.height+e.gap):n++}const{move:v}=e.PointHelper;const F=e.inviteCode;function R(t){return e.decorateLeafAttr(t,(t=>e.attr({set(o){const n="number"==typeof o?o:0;"autoWidth"===t?this.__widthGrow=n:this.__heightGrow=n,!n||this.parent&&this.parent.__hasGrow||this.waitParent((()=>{this.parent.__hasGrow=!0})),this.__setAttr(t,o)&&e.doBoundsType(this)}})))}function H(t){return t.length>6&&"e"===t[6]}const{copyAndSpread:P}=e.BoundsHelper;let X=function(t,e){const o="width",{children:n,itemBox:i}=t,h=u(t,!0),{complex:c,wrap:_,xGap:w,yGap:y,isAutoXGap:x,isFitXGap:G}=h;if(!n.length)return;const A=_&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},B=x?0:w;let v,F,R,H,P,{x:X,y:Y,width:j,height:k}=t.__layout.contentBounds;for(let r=0,h=n.length;r<h;r++)v=n[H=e?h-1-r:r],v.__.inFlow&&0!==v.__.visible&&(F=f(v,i),c?(v.__flowBounds=F,P||(P=g(H,B)),_&&P.count&&P.width+F.width>j&&(P.grow?d(t,P,j,e):x&&p(P,o,j,G),l(A,P,o),P=g(H,B)),R=F.width,v.__widthGrow&&(P.grow+=v.__widthGrow,R=0,v.__.widthRange&&(P.hasRangeSize=!0)),v.__heightGrow&&m(v,F,k),P.width+=P.count?R+B:R,P.height=Math.max(P.height,F.height),P.count++):(b(v,X-F.x,Y-F.y),X+=F.width+B));if(c){const{isAutoYGap:n,isFitYGap:i,contentAlign:c,rowXAlign:u,rowYAlign:g}=h;P.count&&(P.grow?d(t,P,j,e):x&&p(P,o,j,G),_&&l(A,P,o)),_?(n?p(A,"height",k,i):A.gap=y,function(t,e,o,n){s(t,e,o);const{list:i}=e;if(i.length>1&&(n||(n=r[o]),"from"!==n)){let t;for(let o=0,r=i.length;o<r;o++)t=i[o],t.x=e.width-t.width,"center"===n&&(t.x/=2)}}(t,A,c,u),function(t,e,o,n){const{list:i}=e,r="reverse"===t.__.flowWrap;let h,{x:s,y:c}=e;for(let l=0,_=i.length;l<_;l++)h=i[r?_-1-l:l],a(t,h,s,c,o,n),c+=h.height+e.gap}(t,A,g,e)):(s(t,P,c),a(t,P,0,P.y,g,e))}},Y=function(t,e){const o="height",{children:n,itemBox:i}=t,r=u(t,!1),{complex:c,wrap:a,xGap:_,yGap:w,isAutoYGap:d,isFitYGap:x}=r;if(!n.length)return;const m=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},b=d?0:w;let A,F,R,H,P,{x:X,y:Y,width:j,height:k}=t.__layout.contentBounds;for(let r=0,h=n.length;r<h;r++)A=n[H=e?h-1-r:r],A.__.inFlow&&0!==A.__.visible&&(F=f(A,i),c?(A.__flowBounds=F,P||(P=g(H,b)),a&&P.count&&P.height+F.height>k&&(P.grow&&G(t,P,k,e),d&&p(P,o,k,x),l(m,P,o),P=g(H,b)),R=F.height,A.__heightGrow&&(P.grow+=A.__heightGrow,R=0,A.__.heightRange&&(P.hasRangeSize=!0)),A.__widthGrow&&y(A,F,j),P.height+=P.count?R+b:R,P.width=Math.max(P.width,F.width),P.count++):(v(A,X-F.x,Y-F.y),Y+=F.height+b));if(c){const{isAutoXGap:n,isFitXGap:i,contentAlign:c,rowXAlign:u,rowYAlign:g}=r;P.count&&(P.grow&&G(t,P,k,e),d&&p(P,o,k,x),a&&l(m,P,o)),a?(n?p(m,"width",j,i):m.gap=_,function(t,e,o,n){s(t,e,o);const{list:i}=e;if(i.length>1&&(n||(n=h[o]),"from"!==n)){let t;for(let o=0,r=i.length;o<r;o++)t=i[o],t.y=e.height-t.height,"center"===n&&(t.y/=2)}}(t,m,c,g),function(t,e,o,n){const{list:i}=e,r="reverse"===t.__.flowWrap;let h,{x:s,y:c}=e;for(let a=0,l=i.length;a<l;a++)h=i[r?l-1-a:a],B(t,h,s,c,o,n),s+=h.width+e.gap}(t,m,u,e)):(s(t,P,c),B(t,P,P.x,0,u,e))}};e.UI.changeAttr("autoWidth",void 0,R),e.UI.changeAttr("autoHeight",void 0,R),e.Box.prototype.__updateFlowLayout=function(){this.leafer.created=!1;const{flow:t}=this.__;switch(t){case"x":case!0:X(this);break;case"y":Y(this);break;case"x-reverse":X(this,!0);break;case"y-reverse":Y(this,!0)}this.leafer.created=!0},setTimeout((function(){Object.values(F).some(H)||(X=()=>{Y=X})})),e.Box.prototype.__updateContentBounds=function(){const{padding:t}=this.__,e=this.__layout,o=e.contentBounds===e.boxBounds;t?(o&&e.shrinkContent(),P(e.contentBounds,e.boxBounds,t,!0)):o||e.shrinkContentCancel()},Object.keys(t).forEach((function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})}));
1
+ "use strict";var t=require("@leafer-in/resize"),e=require("@leafer-ui/draw");function o(t,e,o,n){var i,r=arguments.length,h=r<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)h=Reflect.decorate(t,e,o,n);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(h=(r<3?i(h):r>3?i(e,o,h):i(e,o))||h);return r>3&&h&&Object.defineProperty(e,o,h),h}"function"==typeof SuppressedError&&SuppressedError;class n extends e.BoxData{}exports.Flow=class extends e.Box{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}},o([e.dataProcessor(n)],exports.Flow.prototype,"__",void 0),o([e.autoLayoutType("x")],exports.Flow.prototype,"flow",void 0),exports.Flow=o([e.registerUI()],exports.Flow);const i={},r={"top-left":"from",top:"center","top-right":"to",right:"to","bottom-right":"to",bottom:"center","bottom-left":"from",left:"from",center:"center","baseline-left":"from","baseline-center":"center","baseline-right":"to"},h={"top-left":"from",top:"from","top-right":"from",right:"center","bottom-right":"to",bottom:"to","bottom-left":"to",left:"center",center:"center","baseline-left":"to","baseline-center":"to","baseline-right":"to"};function s(t,o,n){e.AlignHelper.toPoint(n,o,t.__layout.contentBounds,i);const r=t.__;o.x=r.__autoWidth?0:i.x,o.y=r.__autoHeight?0:i.y}const{move:c}=e.PointHelper;function a(t,e,o,n,i,r){const{children:h}=t;let s,a,{x:l,start:_}=e,u=n;l+=o;for(let t=0,o=e.count;t<o;t++)s=h[r?_-t:_+t],s.__.inFlow&&0!==s.__.visible?(a=s.__flowBounds,"from"!==i&&(u=n+(e.height-a.height)/("center"===i?2:1)),c(s,l-a.x,u-a.y),l+=a.width+e.gap):o++}function l(t,e,o){const n="width"===o?"height":"width";t[o]=Math.max(t[o],e[o]),t[n]+=t.count?e[n]+t.gap:e[n],t.list.push(e),t.count++}const _={};function u(t,e){const{gap:o,flowAlign:n,flowWrap:i,__autoWidth:s,__autoHeight:c}=t.__,a=i&&(e?!s:!c);return"object"==typeof o?(_.xGap=o.x||0,_.yGap=o.y||0):_.xGap=_.yGap=o,_.isAutoXGap="string"==typeof _.xGap&&!s,_.isAutoYGap="string"==typeof _.yGap&&!c,_.complex=a||"top-left"!==n||t.__hasGrow||_.isAutoXGap||_.isAutoYGap,_.wrap=a,_.complex&&(_.isFitXGap="fit"===_.xGap&&!s,_.isFitYGap="fit"===_.yGap&&!c,"object"==typeof n?(_.contentAlign=n.content||"top-left",_.rowXAlign=n.x||"from",_.rowYAlign=n.y||"from"):(_.contentAlign=n,_.rowXAlign=r[n],_.rowYAlign=h[n])),_}function g(t,e){return{x:0,y:0,width:0,height:0,gap:e,start:t,count:0,grow:0}}function p(t,e,o,n){const{count:i}=t;i>1&&(o>t[e]||n)&&(t.gap=(o-t[e])/(i-1),t[e]=o)}function f(t,e){return"box"===e?t.__local:t.__layout.localStrokeBounds}const{within:w}=e.MathHelper;function d(t,e,o,n){let i,r,h,s=0,c=e.hasRangeSize&&[],{grow:a,start:l}=e;const _=e.width<o?(o-e.width)/a:0,{children:u}=t;_&&(e.width=o);for(let t=0,o=e.count;t<o;t++)i=u[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(r=i.__widthGrow)&&(h=y(i,i.__flowBounds,_*r),h?(s+=h,a-=r):c&&(i.__.widthRange?c.unshift(i):c.push(i))):o++;s&&function(t,e,o){let n,i,r,h;t.forEach((t=>{n=t.__widthGrow,i=e/o*n,h=y(t,r=t.__flowBounds,r.width+i),e-=i-h,o-=n}))}(c,s,a)}function y(t,e,o){const{widthRange:n,lockRatio:i}=t.__,r=n?w(o,n.min,n.max):o,h=r/e.width;return t.scaleResize(h,i?h:1),e.width=r,o-r}const{within:x}=e.MathHelper;function G(t,e,o,n){let i,r,h,s=0,c=e.hasRangeSize&&[],{grow:a,start:l}=e;const _=e.height<o?(o-e.height)/a:0,{children:u}=t;_&&(e.height=o);for(let t=0,o=e.count;t<o;t++)i=u[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(r=i.__heightGrow)&&(h=m(i,i.__flowBounds,_*r),h?(s+=h,a-=r):c&&(i.__.heightRange?c.unshift(i):c.push(i))):o++;s&&function(t,e,o){let n,i,r,h;t.forEach((t=>{n=t.__heightGrow,i=e/o*n,h=m(t,r=t.__flowBounds,r.height+i),e-=i-h,o-=n}))}(c,s,a)}function m(t,e,o){const{heightRange:n,lockRatio:i}=t.__,r=n?x(o,n.min,n.max):o,h=r/e.height;return t.scaleResize(i?h:1,h),e.height=r,o-r}const{move:b}=e.PointHelper;const{move:A}=e.PointHelper;function B(t,e,o,n,i,r){const{children:h}=t;let s,c,{y:a,start:l}=e,_=o;a+=n;for(let t=0,n=e.count;t<n;t++)s=h[r?l-t:l+t],s.__.inFlow&&0!==s.__.visible?(c=s.__flowBounds,"from"!==i&&(_=o+(e.width-c.width)/("center"===i?2:1)),A(s,_-c.x,a-c.y),a+=c.height+e.gap):n++}const{move:v}=e.PointHelper;function F(t){return e.decorateLeafAttr(t,(t=>e.attr({set(o){const n="number"==typeof o?o:0;"autoWidth"===t?this.__widthGrow=n:this.__heightGrow=n,!n||this.parent&&this.parent.__hasGrow||this.waitParent((()=>{this.parent.__hasGrow=!0})),this.__setAttr(t,o)&&e.doBoundsType(this)}})))}const{copyAndSpread:R}=e.BoundsHelper;let H=function(t,e){const o="width",{children:n,itemBox:i}=t,h=u(t,!0),{complex:c,wrap:_,xGap:w,yGap:y,isAutoXGap:x,isFitXGap:G}=h;if(!n.length)return;const A=_&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},B=x?0:w;let v,F,R,H,P,{x:X,y:Y,width:k,height:j}=t.__layout.contentBounds;for(let r=0,h=n.length;r<h;r++)v=n[H=e?h-1-r:r],v.__.inFlow&&0!==v.__.visible&&(F=f(v,i),c?(v.__flowBounds=F,P||(P=g(H,B)),_&&P.count&&P.width+F.width>k&&(P.grow?d(t,P,k,e):x&&p(P,o,k,G),l(A,P,o),P=g(H,B)),R=F.width,v.__widthGrow&&(P.grow+=v.__widthGrow,R=0,v.__.widthRange&&(P.hasRangeSize=!0)),v.__heightGrow&&m(v,F,j),P.width+=P.count?R+B:R,P.height=Math.max(P.height,F.height),P.count++):(b(v,X-F.x,Y-F.y),X+=F.width+B));if(c){const{isAutoYGap:n,isFitYGap:i,contentAlign:c,rowXAlign:u,rowYAlign:g}=h;P.count&&(P.grow?d(t,P,k,e):x&&p(P,o,k,G),_&&l(A,P,o)),_?(n?p(A,"height",j,i):A.gap=y,function(t,e,o,n){s(t,e,o);const{list:i}=e;if(i.length>1&&(n||(n=r[o]),"from"!==n)){let t;for(let o=0,r=i.length;o<r;o++)t=i[o],t.x=e.width-t.width,"center"===n&&(t.x/=2)}}(t,A,c,u),function(t,e,o,n){const{list:i}=e,r="reverse"===t.__.flowWrap;let h,{x:s,y:c}=e;for(let l=0,_=i.length;l<_;l++)h=i[r?_-1-l:l],a(t,h,s,c,o,n),c+=h.height+e.gap}(t,A,g,e)):(s(t,P,c),a(t,P,0,P.y,g,e))}},P=function(t,e){const o="height",{children:n,itemBox:i}=t,r=u(t,!1),{complex:c,wrap:a,xGap:_,yGap:w,isAutoYGap:d,isFitYGap:x}=r;if(!n.length)return;const m=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},b=d?0:w;let A,F,R,H,P,{x:X,y:Y,width:k,height:j}=t.__layout.contentBounds;for(let r=0,h=n.length;r<h;r++)A=n[H=e?h-1-r:r],A.__.inFlow&&0!==A.__.visible&&(F=f(A,i),c?(A.__flowBounds=F,P||(P=g(H,b)),a&&P.count&&P.height+F.height>j&&(P.grow&&G(t,P,j,e),d&&p(P,o,j,x),l(m,P,o),P=g(H,b)),R=F.height,A.__heightGrow&&(P.grow+=A.__heightGrow,R=0,A.__.heightRange&&(P.hasRangeSize=!0)),A.__widthGrow&&y(A,F,k),P.height+=P.count?R+b:R,P.width=Math.max(P.width,F.width),P.count++):(v(A,X-F.x,Y-F.y),Y+=F.height+b));if(c){const{isAutoXGap:n,isFitXGap:i,contentAlign:c,rowXAlign:u,rowYAlign:g}=r;P.count&&(P.grow&&G(t,P,j,e),d&&p(P,o,j,x),a&&l(m,P,o)),a?(n?p(m,"width",k,i):m.gap=_,function(t,e,o,n){s(t,e,o);const{list:i}=e;if(i.length>1&&(n||(n=h[o]),"from"!==n)){let t;for(let o=0,r=i.length;o<r;o++)t=i[o],t.y=e.height-t.height,"center"===n&&(t.y/=2)}}(t,m,c,g),function(t,e,o,n){const{list:i}=e,r="reverse"===t.__.flowWrap;let h,{x:s,y:c}=e;for(let a=0,l=i.length;a<l;a++)h=i[r?l-1-a:a],B(t,h,s,c,o,n),s+=h.width+e.gap}(t,m,u,e)):(s(t,P,c),B(t,P,P.x,0,u,e))}};e.UI.changeAttr("autoWidth",void 0,F),e.UI.changeAttr("autoHeight",void 0,F),e.Box.prototype.__updateFlowLayout=function(){this.leafer.created=!1;const{flow:t}=this.__;switch(t){case"x":case!0:H(this);break;case"y":P(this);break;case"x-reverse":H(this,!0);break;case"y-reverse":P(this,!0)}this.leafer.created=!0},e.Box.prototype.__updateContentBounds=function(){const{padding:t}=this.__,e=this.__layout,o=e.contentBounds===e.boxBounds;t?(o&&e.shrinkContent(),R(e.contentBounds,e.boxBounds,t,!0)):o||e.shrinkContentCancel()},Object.keys(t).forEach((function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})}));
package/dist/flow.esm.js CHANGED
@@ -1 +1 @@
1
- export*from"@leafer-in/resize";import{BoxData as t,dataProcessor as o,autoLayoutType as e,registerUI as n,Box as i,AlignHelper as h,PointHelper as r,MathHelper as s,decorateLeafAttr as c,attr as a,doBoundsType as l,inviteCode as _,UI as g,BoundsHelper as u}from"@leafer-ui/draw";function f(t,o,e,n){var i,h=arguments.length,r=h<3?o:null===n?n=Object.getOwnPropertyDescriptor(o,e):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,o,e,n);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(r=(h<3?i(r):h>3?i(o,e,r):i(o,e))||r);return h>3&&r&&Object.defineProperty(o,e,r),r}"function"==typeof SuppressedError&&SuppressedError;let w=class extends i{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}};f([o(class extends t{})],w.prototype,"__",void 0),f([e("x")],w.prototype,"flow",void 0),w=f([n()],w);const p={},d={"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 x(t,o,e){h.toPoint(e,o,t.__layout.contentBounds,p);const n=t.__;o.x=n.__autoWidth?0:p.x,o.y=n.__autoHeight?0:p.y}const{move:m}=r;function G(t,o,e,n,i,h){const{children:r}=t;let s,c,{x:a,start:l}=o,_=n;a+=e;for(let t=0,e=o.count;t<e;t++)s=r[h?l-t:l+t],s.__.inFlow&&0!==s.__.visible?(c=s.__flowBounds,"from"!==i&&(_=n+(o.height-c.height)/("center"===i?2:1)),m(s,a-c.x,_-c.y),a+=c.width+o.gap):e++}function b(t,o,e){const n="width"===e?"height":"width";t[e]=Math.max(t[e],o[e]),t[n]+=t.count?o[n]+t.gap:o[n],t.list.push(o),t.count++}const A={};function v(t,o){const{gap:e,flowAlign:n,flowWrap:i,__autoWidth:h,__autoHeight:r}=t.__,s=i&&(o?!h:!r);return"object"==typeof e?(A.xGap=e.x||0,A.yGap=e.y||0):A.xGap=A.yGap=e,A.isAutoXGap="string"==typeof A.xGap&&!h,A.isAutoYGap="string"==typeof A.yGap&&!r,A.complex=s||"top-left"!==n||t.__hasGrow||A.isAutoXGap||A.isAutoYGap,A.wrap=s,A.complex&&(A.isFitXGap="fit"===A.xGap&&!h,A.isFitYGap="fit"===A.yGap&&!r,"object"==typeof n?(A.contentAlign=n.content||"top-left",A.rowXAlign=n.x||"from",A.rowYAlign=n.y||"from"):(A.contentAlign=n,A.rowXAlign=d[n],A.rowYAlign=y[n])),A}function B(t,o){return{x:0,y:0,width:0,height:0,gap:o,start:t,count:0,grow:0}}function R(t,o,e,n){const{count:i}=t;i>1&&(e>t[o]||n)&&(t.gap=(e-t[o])/(i-1),t[o]=e)}function F(t,o){return"box"===o?t.__local:t.__layout.localStrokeBounds}const{within:X}=s;function Y(t,o,e,n){let i,h,r,s=0,c=o.hasRangeSize&&[],{grow:a,start:l}=o;const _=o.width<e?(e-o.width)/a:0,{children:g}=t;_&&(o.width=e);for(let t=0,e=o.count;t<e;t++)i=g[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(h=i.__widthGrow)&&(r=k(i,i.__flowBounds,_*h),r?(s+=r,a-=h):c&&(i.__.widthRange?c.unshift(i):c.push(i))):e++;s&&function(t,o,e){let n,i,h,r;t.forEach((t=>{n=t.__widthGrow,i=o/e*n,r=k(t,h=t.__flowBounds,h.width+i),o-=i-r,e-=n}))}(c,s,a)}function k(t,o,e){const{widthRange:n,lockRatio:i}=t.__,h=n?X(e,n.min,n.max):e,r=h/o.width;return t.scaleResize(r,i?r:1),o.width=h,e-h}const{within:S}=s;function z(t,o,e,n){let i,h,r,s=0,c=o.hasRangeSize&&[],{grow:a,start:l}=o;const _=o.height<e?(e-o.height)/a:0,{children:g}=t;_&&(o.height=e);for(let t=0,e=o.count;t<e;t++)i=g[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(h=i.__heightGrow)&&(r=W(i,i.__flowBounds,_*h),r?(s+=r,a-=h):c&&(i.__.heightRange?c.unshift(i):c.push(i))):e++;s&&function(t,o,e){let n,i,h,r;t.forEach((t=>{n=t.__heightGrow,i=o/e*n,r=W(t,h=t.__flowBounds,h.height+i),o-=i-r,e-=n}))}(c,s,a)}function W(t,o,e){const{heightRange:n,lockRatio:i}=t.__,h=n?S(e,n.min,n.max):e,r=h/o.height;return t.scaleResize(i?r:1,r),o.height=h,e-h}const{move:j}=r;const{move:C}=r;function E(t,o,e,n,i,h){const{children:r}=t;let s,c,{y:a,start:l}=o,_=e;a+=n;for(let t=0,n=o.count;t<n;t++)s=r[h?l-t:l+t],s.__.inFlow&&0!==s.__.visible?(c=s.__flowBounds,"from"!==i&&(_=e+(o.width-c.width)/("center"===i?2:1)),C(s,_-c.x,a-c.y),a+=c.height+o.gap):n++}const{move:O}=r;const P=_;function H(t){return c(t,(t=>a({set(o){const e="number"==typeof o?o:0;"autoWidth"===t?this.__widthGrow=e:this.__heightGrow=e,!e||this.parent&&this.parent.__hasGrow||this.waitParent((()=>{this.parent.__hasGrow=!0})),this.__setAttr(t,o)&&l(this)}})))}function M(t){return t.length>6&&"e"===t[6]}const{copyAndSpread:L}=u;let D=function(t,o){const e="width",{children:n,itemBox:i}=t,h=v(t,!0),{complex:r,wrap:s,xGap:c,yGap:a,isAutoXGap:l,isFitXGap:_}=h;if(!n.length)return;const g=s&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},u=l?0:c;let f,w,p,y,m,{x:A,y:X,width:k,height:S}=t.__layout.contentBounds;for(let h=0,c=n.length;h<c;h++)f=n[y=o?c-1-h:h],f.__.inFlow&&0!==f.__.visible&&(w=F(f,i),r?(f.__flowBounds=w,m||(m=B(y,u)),s&&m.count&&m.width+w.width>k&&(m.grow?Y(t,m,k,o):l&&R(m,e,k,_),b(g,m,e),m=B(y,u)),p=w.width,f.__widthGrow&&(m.grow+=f.__widthGrow,p=0,f.__.widthRange&&(m.hasRangeSize=!0)),f.__heightGrow&&W(f,w,S),m.width+=m.count?p+u:p,m.height=Math.max(m.height,w.height),m.count++):(j(f,A-w.x,X-w.y),A+=w.width+u));if(r){const{isAutoYGap:n,isFitYGap:i,contentAlign:r,rowXAlign:c,rowYAlign:u}=h;m.count&&(m.grow?Y(t,m,k,o):l&&R(m,e,k,_),s&&b(g,m,e)),s?(n?R(g,"height",S,i):g.gap=a,function(t,o,e,n){x(t,o,e);const{list:i}=o;if(i.length>1&&(n||(n=d[e]),"from"!==n)){let t;for(let e=0,h=i.length;e<h;e++)t=i[e],t.x=o.width-t.width,"center"===n&&(t.x/=2)}}(t,g,r,c),function(t,o,e,n){const{list:i}=o,h="reverse"===t.__.flowWrap;let r,{x:s,y:c}=o;for(let a=0,l=i.length;a<l;a++)r=i[h?l-1-a:a],G(t,r,s,c,e,n),c+=r.height+o.gap}(t,g,u,o)):(x(t,m,r),G(t,m,0,m.y,u,o))}},T=function(t,o){const e="height",{children:n,itemBox:i}=t,h=v(t,!1),{complex:r,wrap:s,xGap:c,yGap:a,isAutoYGap:l,isFitYGap:_}=h;if(!n.length)return;const g=s&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},u=l?0:a;let f,w,p,d,m,{x:G,y:A,width:X,height:Y}=t.__layout.contentBounds;for(let h=0,c=n.length;h<c;h++)f=n[d=o?c-1-h:h],f.__.inFlow&&0!==f.__.visible&&(w=F(f,i),r?(f.__flowBounds=w,m||(m=B(d,u)),s&&m.count&&m.height+w.height>Y&&(m.grow&&z(t,m,Y,o),l&&R(m,e,Y,_),b(g,m,e),m=B(d,u)),p=w.height,f.__heightGrow&&(m.grow+=f.__heightGrow,p=0,f.__.heightRange&&(m.hasRangeSize=!0)),f.__widthGrow&&k(f,w,X),m.height+=m.count?p+u:p,m.width=Math.max(m.width,w.width),m.count++):(O(f,G-w.x,A-w.y),A+=w.height+u));if(r){const{isAutoXGap:n,isFitXGap:i,contentAlign:r,rowXAlign:a,rowYAlign:u}=h;m.count&&(m.grow&&z(t,m,Y,o),l&&R(m,e,Y,_),s&&b(g,m,e)),s?(n?R(g,"width",X,i):g.gap=c,function(t,o,e,n){x(t,o,e);const{list:i}=o;if(i.length>1&&(n||(n=y[e]),"from"!==n)){let t;for(let e=0,h=i.length;e<h;e++)t=i[e],t.y=o.height-t.height,"center"===n&&(t.y/=2)}}(t,g,r,u),function(t,o,e,n){const{list:i}=o,h="reverse"===t.__.flowWrap;let r,{x:s,y:c}=o;for(let a=0,l=i.length;a<l;a++)r=i[h?l-1-a:a],E(t,r,s,c,e,n),s+=r.width+o.gap}(t,g,a,o)):(x(t,m,r),E(t,m,m.x,0,a,o))}};g.changeAttr("autoWidth",void 0,H),g.changeAttr("autoHeight",void 0,H),i.prototype.__updateFlowLayout=function(){this.leafer.created=!1;const{flow:t}=this.__;switch(t){case"x":case!0:D(this);break;case"y":T(this);break;case"x-reverse":D(this,!0);break;case"y-reverse":T(this,!0)}this.leafer.created=!0},setTimeout((function(){Object.values(P).some(M)||(D=()=>{T=D})})),i.prototype.__updateContentBounds=function(){const{padding:t}=this.__,o=this.__layout,e=o.contentBounds===o.boxBounds;t?(e&&o.shrinkContent(),L(o.contentBounds,o.boxBounds,t,!0)):e||o.shrinkContentCancel()};export{w as Flow};
1
+ export*from"@leafer-in/resize";import{BoxData as t,dataProcessor as o,autoLayoutType as e,registerUI as n,Box as i,AlignHelper as h,PointHelper as r,MathHelper as s,decorateLeafAttr as c,attr as a,doBoundsType as l,UI as _,BoundsHelper as g}from"@leafer-ui/draw";function u(t,o,e,n){var i,h=arguments.length,r=h<3?o:null===n?n=Object.getOwnPropertyDescriptor(o,e):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,o,e,n);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(r=(h<3?i(r):h>3?i(o,e,r):i(o,e))||r);return h>3&&r&&Object.defineProperty(o,e,r),r}"function"==typeof SuppressedError&&SuppressedError;let f=class extends i{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}};u([o(class extends t{})],f.prototype,"__",void 0),u([e("x")],f.prototype,"flow",void 0),f=u([n()],f);const w={},p={"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"},d={"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 y(t,o,e){h.toPoint(e,o,t.__layout.contentBounds,w);const n=t.__;o.x=n.__autoWidth?0:w.x,o.y=n.__autoHeight?0:w.y}const{move:x}=r;function G(t,o,e,n,i,h){const{children:r}=t;let s,c,{x:a,start:l}=o,_=n;a+=e;for(let t=0,e=o.count;t<e;t++)s=r[h?l-t:l+t],s.__.inFlow&&0!==s.__.visible?(c=s.__flowBounds,"from"!==i&&(_=n+(o.height-c.height)/("center"===i?2:1)),x(s,a-c.x,_-c.y),a+=c.width+o.gap):e++}function m(t,o,e){const n="width"===e?"height":"width";t[e]=Math.max(t[e],o[e]),t[n]+=t.count?o[n]+t.gap:o[n],t.list.push(o),t.count++}const b={};function A(t,o){const{gap:e,flowAlign:n,flowWrap:i,__autoWidth:h,__autoHeight:r}=t.__,s=i&&(o?!h:!r);return"object"==typeof e?(b.xGap=e.x||0,b.yGap=e.y||0):b.xGap=b.yGap=e,b.isAutoXGap="string"==typeof b.xGap&&!h,b.isAutoYGap="string"==typeof b.yGap&&!r,b.complex=s||"top-left"!==n||t.__hasGrow||b.isAutoXGap||b.isAutoYGap,b.wrap=s,b.complex&&(b.isFitXGap="fit"===b.xGap&&!h,b.isFitYGap="fit"===b.yGap&&!r,"object"==typeof n?(b.contentAlign=n.content||"top-left",b.rowXAlign=n.x||"from",b.rowYAlign=n.y||"from"):(b.contentAlign=n,b.rowXAlign=p[n],b.rowYAlign=d[n])),b}function v(t,o){return{x:0,y:0,width:0,height:0,gap:o,start:t,count:0,grow:0}}function B(t,o,e,n){const{count:i}=t;i>1&&(e>t[o]||n)&&(t.gap=(e-t[o])/(i-1),t[o]=e)}function R(t,o){return"box"===o?t.__local:t.__layout.localStrokeBounds}const{within:F}=s;function X(t,o,e,n){let i,h,r,s=0,c=o.hasRangeSize&&[],{grow:a,start:l}=o;const _=o.width<e?(e-o.width)/a:0,{children:g}=t;_&&(o.width=e);for(let t=0,e=o.count;t<e;t++)i=g[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(h=i.__widthGrow)&&(r=Y(i,i.__flowBounds,_*h),r?(s+=r,a-=h):c&&(i.__.widthRange?c.unshift(i):c.push(i))):e++;s&&function(t,o,e){let n,i,h,r;t.forEach((t=>{n=t.__widthGrow,i=o/e*n,r=Y(t,h=t.__flowBounds,h.width+i),o-=i-r,e-=n}))}(c,s,a)}function Y(t,o,e){const{widthRange:n,lockRatio:i}=t.__,h=n?F(e,n.min,n.max):e,r=h/o.width;return t.scaleResize(r,i?r:1),o.width=h,e-h}const{within:k}=s;function S(t,o,e,n){let i,h,r,s=0,c=o.hasRangeSize&&[],{grow:a,start:l}=o;const _=o.height<e?(e-o.height)/a:0,{children:g}=t;_&&(o.height=e);for(let t=0,e=o.count;t<e;t++)i=g[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(h=i.__heightGrow)&&(r=z(i,i.__flowBounds,_*h),r?(s+=r,a-=h):c&&(i.__.heightRange?c.unshift(i):c.push(i))):e++;s&&function(t,o,e){let n,i,h,r;t.forEach((t=>{n=t.__heightGrow,i=o/e*n,r=z(t,h=t.__flowBounds,h.height+i),o-=i-r,e-=n}))}(c,s,a)}function z(t,o,e){const{heightRange:n,lockRatio:i}=t.__,h=n?k(e,n.min,n.max):e,r=h/o.height;return t.scaleResize(i?r:1,r),o.height=h,e-h}const{move:W}=r;const{move:j}=r;function C(t,o,e,n,i,h){const{children:r}=t;let s,c,{y:a,start:l}=o,_=e;a+=n;for(let t=0,n=o.count;t<n;t++)s=r[h?l-t:l+t],s.__.inFlow&&0!==s.__.visible?(c=s.__flowBounds,"from"!==i&&(_=e+(o.width-c.width)/("center"===i?2:1)),j(s,_-c.x,a-c.y),a+=c.height+o.gap):n++}const{move:E}=r;function P(t){return c(t,(t=>a({set(o){const e="number"==typeof o?o:0;"autoWidth"===t?this.__widthGrow=e:this.__heightGrow=e,!e||this.parent&&this.parent.__hasGrow||this.waitParent((()=>{this.parent.__hasGrow=!0})),this.__setAttr(t,o)&&l(this)}})))}const{copyAndSpread:H}=g;let M=function(t,o){const e="width",{children:n,itemBox:i}=t,h=A(t,!0),{complex:r,wrap:s,xGap:c,yGap:a,isAutoXGap:l,isFitXGap:_}=h;if(!n.length)return;const g=s&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},u=l?0:c;let f,w,d,x,b,{x:F,y:Y,width:k,height:S}=t.__layout.contentBounds;for(let h=0,c=n.length;h<c;h++)f=n[x=o?c-1-h:h],f.__.inFlow&&0!==f.__.visible&&(w=R(f,i),r?(f.__flowBounds=w,b||(b=v(x,u)),s&&b.count&&b.width+w.width>k&&(b.grow?X(t,b,k,o):l&&B(b,e,k,_),m(g,b,e),b=v(x,u)),d=w.width,f.__widthGrow&&(b.grow+=f.__widthGrow,d=0,f.__.widthRange&&(b.hasRangeSize=!0)),f.__heightGrow&&z(f,w,S),b.width+=b.count?d+u:d,b.height=Math.max(b.height,w.height),b.count++):(W(f,F-w.x,Y-w.y),F+=w.width+u));if(r){const{isAutoYGap:n,isFitYGap:i,contentAlign:r,rowXAlign:c,rowYAlign:u}=h;b.count&&(b.grow?X(t,b,k,o):l&&B(b,e,k,_),s&&m(g,b,e)),s?(n?B(g,"height",S,i):g.gap=a,function(t,o,e,n){y(t,o,e);const{list:i}=o;if(i.length>1&&(n||(n=p[e]),"from"!==n)){let t;for(let e=0,h=i.length;e<h;e++)t=i[e],t.x=o.width-t.width,"center"===n&&(t.x/=2)}}(t,g,r,c),function(t,o,e,n){const{list:i}=o,h="reverse"===t.__.flowWrap;let r,{x:s,y:c}=o;for(let a=0,l=i.length;a<l;a++)r=i[h?l-1-a:a],G(t,r,s,c,e,n),c+=r.height+o.gap}(t,g,u,o)):(y(t,b,r),G(t,b,0,b.y,u,o))}},O=function(t,o){const e="height",{children:n,itemBox:i}=t,h=A(t,!1),{complex:r,wrap:s,xGap:c,yGap:a,isAutoYGap:l,isFitYGap:_}=h;if(!n.length)return;const g=s&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},u=l?0:a;let f,w,p,x,G,{x:b,y:F,width:X,height:k}=t.__layout.contentBounds;for(let h=0,c=n.length;h<c;h++)f=n[x=o?c-1-h:h],f.__.inFlow&&0!==f.__.visible&&(w=R(f,i),r?(f.__flowBounds=w,G||(G=v(x,u)),s&&G.count&&G.height+w.height>k&&(G.grow&&S(t,G,k,o),l&&B(G,e,k,_),m(g,G,e),G=v(x,u)),p=w.height,f.__heightGrow&&(G.grow+=f.__heightGrow,p=0,f.__.heightRange&&(G.hasRangeSize=!0)),f.__widthGrow&&Y(f,w,X),G.height+=G.count?p+u:p,G.width=Math.max(G.width,w.width),G.count++):(E(f,b-w.x,F-w.y),F+=w.height+u));if(r){const{isAutoXGap:n,isFitXGap:i,contentAlign:r,rowXAlign:a,rowYAlign:u}=h;G.count&&(G.grow&&S(t,G,k,o),l&&B(G,e,k,_),s&&m(g,G,e)),s?(n?B(g,"width",X,i):g.gap=c,function(t,o,e,n){y(t,o,e);const{list:i}=o;if(i.length>1&&(n||(n=d[e]),"from"!==n)){let t;for(let e=0,h=i.length;e<h;e++)t=i[e],t.y=o.height-t.height,"center"===n&&(t.y/=2)}}(t,g,r,u),function(t,o,e,n){const{list:i}=o,h="reverse"===t.__.flowWrap;let r,{x:s,y:c}=o;for(let a=0,l=i.length;a<l;a++)r=i[h?l-1-a:a],C(t,r,s,c,e,n),s+=r.width+o.gap}(t,g,a,o)):(y(t,G,r),C(t,G,G.x,0,a,o))}};_.changeAttr("autoWidth",void 0,P),_.changeAttr("autoHeight",void 0,P),i.prototype.__updateFlowLayout=function(){this.leafer.created=!1;const{flow:t}=this.__;switch(t){case"x":case!0:M(this);break;case"y":O(this);break;case"x-reverse":M(this,!0);break;case"y-reverse":O(this,!0)}this.leafer.created=!0},i.prototype.__updateContentBounds=function(){const{padding:t}=this.__,o=this.__layout,e=o.contentBounds===o.boxBounds;t?(e&&o.shrinkContent(),H(o.contentBounds,o.boxBounds,t,!0)):e||o.shrinkContentCancel()};export{f as Flow};
@@ -1 +1 @@
1
- export*from"@leafer-in/resize";import{BoxData as t,dataProcessor as o,autoLayoutType as e,registerUI as n,Box as i,AlignHelper as h,PointHelper as r,MathHelper as s,decorateLeafAttr as c,attr as a,doBoundsType as l,inviteCode as _,UI as g,BoundsHelper as u}from"@leafer-ui/draw";function f(t,o,e,n){var i,h=arguments.length,r=h<3?o:null===n?n=Object.getOwnPropertyDescriptor(o,e):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,o,e,n);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(r=(h<3?i(r):h>3?i(o,e,r):i(o,e))||r);return h>3&&r&&Object.defineProperty(o,e,r),r}"function"==typeof SuppressedError&&SuppressedError;let w=class extends i{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}};f([o(class extends t{})],w.prototype,"__",void 0),f([e("x")],w.prototype,"flow",void 0),w=f([n()],w);const p={},d={"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 x(t,o,e){h.toPoint(e,o,t.__layout.contentBounds,p);const n=t.__;o.x=n.__autoWidth?0:p.x,o.y=n.__autoHeight?0:p.y}const{move:m}=r;function G(t,o,e,n,i,h){const{children:r}=t;let s,c,{x:a,start:l}=o,_=n;a+=e;for(let t=0,e=o.count;t<e;t++)s=r[h?l-t:l+t],s.__.inFlow&&0!==s.__.visible?(c=s.__flowBounds,"from"!==i&&(_=n+(o.height-c.height)/("center"===i?2:1)),m(s,a-c.x,_-c.y),a+=c.width+o.gap):e++}function b(t,o,e){const n="width"===e?"height":"width";t[e]=Math.max(t[e],o[e]),t[n]+=t.count?o[n]+t.gap:o[n],t.list.push(o),t.count++}const A={};function v(t,o){const{gap:e,flowAlign:n,flowWrap:i,__autoWidth:h,__autoHeight:r}=t.__,s=i&&(o?!h:!r);return"object"==typeof e?(A.xGap=e.x||0,A.yGap=e.y||0):A.xGap=A.yGap=e,A.isAutoXGap="string"==typeof A.xGap&&!h,A.isAutoYGap="string"==typeof A.yGap&&!r,A.complex=s||"top-left"!==n||t.__hasGrow||A.isAutoXGap||A.isAutoYGap,A.wrap=s,A.complex&&(A.isFitXGap="fit"===A.xGap&&!h,A.isFitYGap="fit"===A.yGap&&!r,"object"==typeof n?(A.contentAlign=n.content||"top-left",A.rowXAlign=n.x||"from",A.rowYAlign=n.y||"from"):(A.contentAlign=n,A.rowXAlign=d[n],A.rowYAlign=y[n])),A}function B(t,o){return{x:0,y:0,width:0,height:0,gap:o,start:t,count:0,grow:0}}function R(t,o,e,n){const{count:i}=t;i>1&&(e>t[o]||n)&&(t.gap=(e-t[o])/(i-1),t[o]=e)}function F(t,o){return"box"===o?t.__local:t.__layout.localStrokeBounds}const{within:X}=s;function Y(t,o,e,n){let i,h,r,s=0,c=o.hasRangeSize&&[],{grow:a,start:l}=o;const _=o.width<e?(e-o.width)/a:0,{children:g}=t;_&&(o.width=e);for(let t=0,e=o.count;t<e;t++)i=g[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(h=i.__widthGrow)&&(r=k(i,i.__flowBounds,_*h),r?(s+=r,a-=h):c&&(i.__.widthRange?c.unshift(i):c.push(i))):e++;s&&function(t,o,e){let n,i,h,r;t.forEach((t=>{n=t.__widthGrow,i=o/e*n,r=k(t,h=t.__flowBounds,h.width+i),o-=i-r,e-=n}))}(c,s,a)}function k(t,o,e){const{widthRange:n,lockRatio:i}=t.__,h=n?X(e,n.min,n.max):e,r=h/o.width;return t.scaleResize(r,i?r:1),o.width=h,e-h}const{within:S}=s;function z(t,o,e,n){let i,h,r,s=0,c=o.hasRangeSize&&[],{grow:a,start:l}=o;const _=o.height<e?(e-o.height)/a:0,{children:g}=t;_&&(o.height=e);for(let t=0,e=o.count;t<e;t++)i=g[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(h=i.__heightGrow)&&(r=W(i,i.__flowBounds,_*h),r?(s+=r,a-=h):c&&(i.__.heightRange?c.unshift(i):c.push(i))):e++;s&&function(t,o,e){let n,i,h,r;t.forEach((t=>{n=t.__heightGrow,i=o/e*n,r=W(t,h=t.__flowBounds,h.height+i),o-=i-r,e-=n}))}(c,s,a)}function W(t,o,e){const{heightRange:n,lockRatio:i}=t.__,h=n?S(e,n.min,n.max):e,r=h/o.height;return t.scaleResize(i?r:1,r),o.height=h,e-h}const{move:j}=r;const{move:C}=r;function E(t,o,e,n,i,h){const{children:r}=t;let s,c,{y:a,start:l}=o,_=e;a+=n;for(let t=0,n=o.count;t<n;t++)s=r[h?l-t:l+t],s.__.inFlow&&0!==s.__.visible?(c=s.__flowBounds,"from"!==i&&(_=e+(o.width-c.width)/("center"===i?2:1)),C(s,_-c.x,a-c.y),a+=c.height+o.gap):n++}const{move:O}=r;const P=_;function H(t){return c(t,(t=>a({set(o){const e="number"==typeof o?o:0;"autoWidth"===t?this.__widthGrow=e:this.__heightGrow=e,!e||this.parent&&this.parent.__hasGrow||this.waitParent((()=>{this.parent.__hasGrow=!0})),this.__setAttr(t,o)&&l(this)}})))}function M(t){return t.length>6&&"e"===t[6]}const{copyAndSpread:L}=u;let D=function(t,o){const e="width",{children:n,itemBox:i}=t,h=v(t,!0),{complex:r,wrap:s,xGap:c,yGap:a,isAutoXGap:l,isFitXGap:_}=h;if(!n.length)return;const g=s&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},u=l?0:c;let f,w,p,y,m,{x:A,y:X,width:k,height:S}=t.__layout.contentBounds;for(let h=0,c=n.length;h<c;h++)f=n[y=o?c-1-h:h],f.__.inFlow&&0!==f.__.visible&&(w=F(f,i),r?(f.__flowBounds=w,m||(m=B(y,u)),s&&m.count&&m.width+w.width>k&&(m.grow?Y(t,m,k,o):l&&R(m,e,k,_),b(g,m,e),m=B(y,u)),p=w.width,f.__widthGrow&&(m.grow+=f.__widthGrow,p=0,f.__.widthRange&&(m.hasRangeSize=!0)),f.__heightGrow&&W(f,w,S),m.width+=m.count?p+u:p,m.height=Math.max(m.height,w.height),m.count++):(j(f,A-w.x,X-w.y),A+=w.width+u));if(r){const{isAutoYGap:n,isFitYGap:i,contentAlign:r,rowXAlign:c,rowYAlign:u}=h;m.count&&(m.grow?Y(t,m,k,o):l&&R(m,e,k,_),s&&b(g,m,e)),s?(n?R(g,"height",S,i):g.gap=a,function(t,o,e,n){x(t,o,e);const{list:i}=o;if(i.length>1&&(n||(n=d[e]),"from"!==n)){let t;for(let e=0,h=i.length;e<h;e++)t=i[e],t.x=o.width-t.width,"center"===n&&(t.x/=2)}}(t,g,r,c),function(t,o,e,n){const{list:i}=o,h="reverse"===t.__.flowWrap;let r,{x:s,y:c}=o;for(let a=0,l=i.length;a<l;a++)r=i[h?l-1-a:a],G(t,r,s,c,e,n),c+=r.height+o.gap}(t,g,u,o)):(x(t,m,r),G(t,m,0,m.y,u,o))}},T=function(t,o){const e="height",{children:n,itemBox:i}=t,h=v(t,!1),{complex:r,wrap:s,xGap:c,yGap:a,isAutoYGap:l,isFitYGap:_}=h;if(!n.length)return;const g=s&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},u=l?0:a;let f,w,p,d,m,{x:G,y:A,width:X,height:Y}=t.__layout.contentBounds;for(let h=0,c=n.length;h<c;h++)f=n[d=o?c-1-h:h],f.__.inFlow&&0!==f.__.visible&&(w=F(f,i),r?(f.__flowBounds=w,m||(m=B(d,u)),s&&m.count&&m.height+w.height>Y&&(m.grow&&z(t,m,Y,o),l&&R(m,e,Y,_),b(g,m,e),m=B(d,u)),p=w.height,f.__heightGrow&&(m.grow+=f.__heightGrow,p=0,f.__.heightRange&&(m.hasRangeSize=!0)),f.__widthGrow&&k(f,w,X),m.height+=m.count?p+u:p,m.width=Math.max(m.width,w.width),m.count++):(O(f,G-w.x,A-w.y),A+=w.height+u));if(r){const{isAutoXGap:n,isFitXGap:i,contentAlign:r,rowXAlign:a,rowYAlign:u}=h;m.count&&(m.grow&&z(t,m,Y,o),l&&R(m,e,Y,_),s&&b(g,m,e)),s?(n?R(g,"width",X,i):g.gap=c,function(t,o,e,n){x(t,o,e);const{list:i}=o;if(i.length>1&&(n||(n=y[e]),"from"!==n)){let t;for(let e=0,h=i.length;e<h;e++)t=i[e],t.y=o.height-t.height,"center"===n&&(t.y/=2)}}(t,g,r,u),function(t,o,e,n){const{list:i}=o,h="reverse"===t.__.flowWrap;let r,{x:s,y:c}=o;for(let a=0,l=i.length;a<l;a++)r=i[h?l-1-a:a],E(t,r,s,c,e,n),s+=r.width+o.gap}(t,g,a,o)):(x(t,m,r),E(t,m,m.x,0,a,o))}};g.changeAttr("autoWidth",void 0,H),g.changeAttr("autoHeight",void 0,H),i.prototype.__updateFlowLayout=function(){this.leafer.created=!1;const{flow:t}=this.__;switch(t){case"x":case!0:D(this);break;case"y":T(this);break;case"x-reverse":D(this,!0);break;case"y-reverse":T(this,!0)}this.leafer.created=!0},setTimeout((function(){Object.values(P).some(M)||(D=()=>{T=D})})),i.prototype.__updateContentBounds=function(){const{padding:t}=this.__,o=this.__layout,e=o.contentBounds===o.boxBounds;t?(e&&o.shrinkContent(),L(o.contentBounds,o.boxBounds,t,!0)):e||o.shrinkContentCancel()};export{w as Flow};
1
+ export*from"@leafer-in/resize";import{BoxData as t,dataProcessor as o,autoLayoutType as e,registerUI as n,Box as i,AlignHelper as h,PointHelper as r,MathHelper as s,decorateLeafAttr as c,attr as a,doBoundsType as l,UI as _,BoundsHelper as g}from"@leafer-ui/draw";function u(t,o,e,n){var i,h=arguments.length,r=h<3?o:null===n?n=Object.getOwnPropertyDescriptor(o,e):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,o,e,n);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(r=(h<3?i(r):h>3?i(o,e,r):i(o,e))||r);return h>3&&r&&Object.defineProperty(o,e,r),r}"function"==typeof SuppressedError&&SuppressedError;let f=class extends i{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}};u([o(class extends t{})],f.prototype,"__",void 0),u([e("x")],f.prototype,"flow",void 0),f=u([n()],f);const w={},p={"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"},d={"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 y(t,o,e){h.toPoint(e,o,t.__layout.contentBounds,w);const n=t.__;o.x=n.__autoWidth?0:w.x,o.y=n.__autoHeight?0:w.y}const{move:x}=r;function G(t,o,e,n,i,h){const{children:r}=t;let s,c,{x:a,start:l}=o,_=n;a+=e;for(let t=0,e=o.count;t<e;t++)s=r[h?l-t:l+t],s.__.inFlow&&0!==s.__.visible?(c=s.__flowBounds,"from"!==i&&(_=n+(o.height-c.height)/("center"===i?2:1)),x(s,a-c.x,_-c.y),a+=c.width+o.gap):e++}function m(t,o,e){const n="width"===e?"height":"width";t[e]=Math.max(t[e],o[e]),t[n]+=t.count?o[n]+t.gap:o[n],t.list.push(o),t.count++}const b={};function A(t,o){const{gap:e,flowAlign:n,flowWrap:i,__autoWidth:h,__autoHeight:r}=t.__,s=i&&(o?!h:!r);return"object"==typeof e?(b.xGap=e.x||0,b.yGap=e.y||0):b.xGap=b.yGap=e,b.isAutoXGap="string"==typeof b.xGap&&!h,b.isAutoYGap="string"==typeof b.yGap&&!r,b.complex=s||"top-left"!==n||t.__hasGrow||b.isAutoXGap||b.isAutoYGap,b.wrap=s,b.complex&&(b.isFitXGap="fit"===b.xGap&&!h,b.isFitYGap="fit"===b.yGap&&!r,"object"==typeof n?(b.contentAlign=n.content||"top-left",b.rowXAlign=n.x||"from",b.rowYAlign=n.y||"from"):(b.contentAlign=n,b.rowXAlign=p[n],b.rowYAlign=d[n])),b}function v(t,o){return{x:0,y:0,width:0,height:0,gap:o,start:t,count:0,grow:0}}function B(t,o,e,n){const{count:i}=t;i>1&&(e>t[o]||n)&&(t.gap=(e-t[o])/(i-1),t[o]=e)}function R(t,o){return"box"===o?t.__local:t.__layout.localStrokeBounds}const{within:F}=s;function X(t,o,e,n){let i,h,r,s=0,c=o.hasRangeSize&&[],{grow:a,start:l}=o;const _=o.width<e?(e-o.width)/a:0,{children:g}=t;_&&(o.width=e);for(let t=0,e=o.count;t<e;t++)i=g[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(h=i.__widthGrow)&&(r=Y(i,i.__flowBounds,_*h),r?(s+=r,a-=h):c&&(i.__.widthRange?c.unshift(i):c.push(i))):e++;s&&function(t,o,e){let n,i,h,r;t.forEach((t=>{n=t.__widthGrow,i=o/e*n,r=Y(t,h=t.__flowBounds,h.width+i),o-=i-r,e-=n}))}(c,s,a)}function Y(t,o,e){const{widthRange:n,lockRatio:i}=t.__,h=n?F(e,n.min,n.max):e,r=h/o.width;return t.scaleResize(r,i?r:1),o.width=h,e-h}const{within:k}=s;function S(t,o,e,n){let i,h,r,s=0,c=o.hasRangeSize&&[],{grow:a,start:l}=o;const _=o.height<e?(e-o.height)/a:0,{children:g}=t;_&&(o.height=e);for(let t=0,e=o.count;t<e;t++)i=g[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(h=i.__heightGrow)&&(r=z(i,i.__flowBounds,_*h),r?(s+=r,a-=h):c&&(i.__.heightRange?c.unshift(i):c.push(i))):e++;s&&function(t,o,e){let n,i,h,r;t.forEach((t=>{n=t.__heightGrow,i=o/e*n,r=z(t,h=t.__flowBounds,h.height+i),o-=i-r,e-=n}))}(c,s,a)}function z(t,o,e){const{heightRange:n,lockRatio:i}=t.__,h=n?k(e,n.min,n.max):e,r=h/o.height;return t.scaleResize(i?r:1,r),o.height=h,e-h}const{move:W}=r;const{move:j}=r;function C(t,o,e,n,i,h){const{children:r}=t;let s,c,{y:a,start:l}=o,_=e;a+=n;for(let t=0,n=o.count;t<n;t++)s=r[h?l-t:l+t],s.__.inFlow&&0!==s.__.visible?(c=s.__flowBounds,"from"!==i&&(_=e+(o.width-c.width)/("center"===i?2:1)),j(s,_-c.x,a-c.y),a+=c.height+o.gap):n++}const{move:E}=r;function P(t){return c(t,(t=>a({set(o){const e="number"==typeof o?o:0;"autoWidth"===t?this.__widthGrow=e:this.__heightGrow=e,!e||this.parent&&this.parent.__hasGrow||this.waitParent((()=>{this.parent.__hasGrow=!0})),this.__setAttr(t,o)&&l(this)}})))}const{copyAndSpread:H}=g;let M=function(t,o){const e="width",{children:n,itemBox:i}=t,h=A(t,!0),{complex:r,wrap:s,xGap:c,yGap:a,isAutoXGap:l,isFitXGap:_}=h;if(!n.length)return;const g=s&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},u=l?0:c;let f,w,d,x,b,{x:F,y:Y,width:k,height:S}=t.__layout.contentBounds;for(let h=0,c=n.length;h<c;h++)f=n[x=o?c-1-h:h],f.__.inFlow&&0!==f.__.visible&&(w=R(f,i),r?(f.__flowBounds=w,b||(b=v(x,u)),s&&b.count&&b.width+w.width>k&&(b.grow?X(t,b,k,o):l&&B(b,e,k,_),m(g,b,e),b=v(x,u)),d=w.width,f.__widthGrow&&(b.grow+=f.__widthGrow,d=0,f.__.widthRange&&(b.hasRangeSize=!0)),f.__heightGrow&&z(f,w,S),b.width+=b.count?d+u:d,b.height=Math.max(b.height,w.height),b.count++):(W(f,F-w.x,Y-w.y),F+=w.width+u));if(r){const{isAutoYGap:n,isFitYGap:i,contentAlign:r,rowXAlign:c,rowYAlign:u}=h;b.count&&(b.grow?X(t,b,k,o):l&&B(b,e,k,_),s&&m(g,b,e)),s?(n?B(g,"height",S,i):g.gap=a,function(t,o,e,n){y(t,o,e);const{list:i}=o;if(i.length>1&&(n||(n=p[e]),"from"!==n)){let t;for(let e=0,h=i.length;e<h;e++)t=i[e],t.x=o.width-t.width,"center"===n&&(t.x/=2)}}(t,g,r,c),function(t,o,e,n){const{list:i}=o,h="reverse"===t.__.flowWrap;let r,{x:s,y:c}=o;for(let a=0,l=i.length;a<l;a++)r=i[h?l-1-a:a],G(t,r,s,c,e,n),c+=r.height+o.gap}(t,g,u,o)):(y(t,b,r),G(t,b,0,b.y,u,o))}},O=function(t,o){const e="height",{children:n,itemBox:i}=t,h=A(t,!1),{complex:r,wrap:s,xGap:c,yGap:a,isAutoYGap:l,isFitYGap:_}=h;if(!n.length)return;const g=s&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},u=l?0:a;let f,w,p,x,G,{x:b,y:F,width:X,height:k}=t.__layout.contentBounds;for(let h=0,c=n.length;h<c;h++)f=n[x=o?c-1-h:h],f.__.inFlow&&0!==f.__.visible&&(w=R(f,i),r?(f.__flowBounds=w,G||(G=v(x,u)),s&&G.count&&G.height+w.height>k&&(G.grow&&S(t,G,k,o),l&&B(G,e,k,_),m(g,G,e),G=v(x,u)),p=w.height,f.__heightGrow&&(G.grow+=f.__heightGrow,p=0,f.__.heightRange&&(G.hasRangeSize=!0)),f.__widthGrow&&Y(f,w,X),G.height+=G.count?p+u:p,G.width=Math.max(G.width,w.width),G.count++):(E(f,b-w.x,F-w.y),F+=w.height+u));if(r){const{isAutoXGap:n,isFitXGap:i,contentAlign:r,rowXAlign:a,rowYAlign:u}=h;G.count&&(G.grow&&S(t,G,k,o),l&&B(G,e,k,_),s&&m(g,G,e)),s?(n?B(g,"width",X,i):g.gap=c,function(t,o,e,n){y(t,o,e);const{list:i}=o;if(i.length>1&&(n||(n=d[e]),"from"!==n)){let t;for(let e=0,h=i.length;e<h;e++)t=i[e],t.y=o.height-t.height,"center"===n&&(t.y/=2)}}(t,g,r,u),function(t,o,e,n){const{list:i}=o,h="reverse"===t.__.flowWrap;let r,{x:s,y:c}=o;for(let a=0,l=i.length;a<l;a++)r=i[h?l-1-a:a],C(t,r,s,c,e,n),s+=r.width+o.gap}(t,g,a,o)):(y(t,G,r),C(t,G,G.x,0,a,o))}};_.changeAttr("autoWidth",void 0,P),_.changeAttr("autoHeight",void 0,P),i.prototype.__updateFlowLayout=function(){this.leafer.created=!1;const{flow:t}=this.__;switch(t){case"x":case!0:M(this);break;case"y":O(this);break;case"x-reverse":M(this,!0);break;case"y-reverse":O(this,!0)}this.leafer.created=!0},i.prototype.__updateContentBounds=function(){const{padding:t}=this.__,o=this.__layout,e=o.contentBounds===o.boxBounds;t?(e&&o.shrinkContent(),H(o.contentBounds,o.boxBounds,t,!0)):e||o.shrinkContentCancel()};export{f as Flow};
package/dist/flow.js CHANGED
@@ -1 +1 @@
1
- this.LeaferIN=this.LeaferIN||{},this.LeaferIN.flow=function(t,e,o){"use strict";function n(t,e,o,n){var i,r=arguments.length,h=r<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)h=Reflect.decorate(t,e,o,n);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(h=(r<3?i(h):r>3?i(e,o,h):i(e,o))||h);return r>3&&h&&Object.defineProperty(e,o,h),h}"function"==typeof SuppressedError&&SuppressedError;class i extends o.BoxData{}t.Flow=class extends o.Box{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}},n([o.dataProcessor(i)],t.Flow.prototype,"__",void 0),n([o.autoLayoutType("x")],t.Flow.prototype,"flow",void 0),t.Flow=n([o.registerUI()],t.Flow);const r={},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"},s={"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(t,e,n){o.AlignHelper.toPoint(n,e,t.__layout.contentBounds,r);const i=t.__;e.x=i.__autoWidth?0:r.x,e.y=i.__autoHeight?0:r.y}const{move:a}=o.PointHelper;function l(t,e,o,n,i,r){const{children:h}=t;let s,c,{x:l,start:_}=e,u=n;l+=o;for(let t=0,o=e.count;t<o;t++)s=h[r?_-t:_+t],s.__.inFlow&&0!==s.__.visible?(c=s.__flowBounds,"from"!==i&&(u=n+(e.height-c.height)/("center"===i?2:1)),a(s,l-c.x,u-c.y),l+=c.width+e.gap):o++}function _(t,e,o){const n="width"===o?"height":"width";t[o]=Math.max(t[o],e[o]),t[n]+=t.count?e[n]+t.gap:e[n],t.list.push(e),t.count++}const u={};function f(t,e){const{gap:o,flowAlign:n,flowWrap:i,__autoWidth:r,__autoHeight:c}=t.__,a=i&&(e?!r:!c);return"object"==typeof o?(u.xGap=o.x||0,u.yGap=o.y||0):u.xGap=u.yGap=o,u.isAutoXGap="string"==typeof u.xGap&&!r,u.isAutoYGap="string"==typeof u.yGap&&!c,u.complex=a||"top-left"!==n||t.__hasGrow||u.isAutoXGap||u.isAutoYGap,u.wrap=a,u.complex&&(u.isFitXGap="fit"===u.xGap&&!r,u.isFitYGap="fit"===u.yGap&&!c,"object"==typeof n?(u.contentAlign=n.content||"top-left",u.rowXAlign=n.x||"from",u.rowYAlign=n.y||"from"):(u.contentAlign=n,u.rowXAlign=h[n],u.rowYAlign=s[n])),u}function g(t,e){return{x:0,y:0,width:0,height:0,gap:e,start:t,count:0,grow:0}}function w(t,e,o,n){const{count:i}=t;i>1&&(o>t[e]||n)&&(t.gap=(o-t[e])/(i-1),t[e]=o)}function p(t,e){return"box"===e?t.__local:t.__layout.localStrokeBounds}const{within:d}=o.MathHelper;function y(t,e,o,n){let i,r,h,s=0,c=e.hasRangeSize&&[],{grow:a,start:l}=e;const _=e.width<o?(o-e.width)/a:0,{children:u}=t;_&&(e.width=o);for(let t=0,o=e.count;t<o;t++)i=u[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(r=i.__widthGrow)&&(h=x(i,i.__flowBounds,_*r),h?(s+=h,a-=r):c&&(i.__.widthRange?c.unshift(i):c.push(i))):o++;s&&function(t,e,o){let n,i,r,h;t.forEach((t=>{n=t.__widthGrow,i=e/o*n,h=x(t,r=t.__flowBounds,r.width+i),e-=i-h,o-=n}))}(c,s,a)}function x(t,e,o){const{widthRange:n,lockRatio:i}=t.__,r=n?d(o,n.min,n.max):o,h=r/e.width;return t.scaleResize(h,i?h:1),e.width=r,o-r}const{within:G}=o.MathHelper;function m(t,e,o,n){let i,r,h,s=0,c=e.hasRangeSize&&[],{grow:a,start:l}=e;const _=e.height<o?(o-e.height)/a:0,{children:u}=t;_&&(e.height=o);for(let t=0,o=e.count;t<o;t++)i=u[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(r=i.__heightGrow)&&(h=b(i,i.__flowBounds,_*r),h?(s+=h,a-=r):c&&(i.__.heightRange?c.unshift(i):c.push(i))):o++;s&&function(t,e,o){let n,i,r,h;t.forEach((t=>{n=t.__heightGrow,i=e/o*n,h=b(t,r=t.__flowBounds,r.height+i),e-=i-h,o-=n}))}(c,s,a)}function b(t,e,o){const{heightRange:n,lockRatio:i}=t.__,r=n?G(o,n.min,n.max):o,h=r/e.height;return t.scaleResize(i?h:1,h),e.height=r,o-r}const{move:A}=o.PointHelper;const{move:B}=o.PointHelper;function v(t,e,o,n,i,r){const{children:h}=t;let s,c,{y:a,start:l}=e,_=o;a+=n;for(let t=0,n=e.count;t<n;t++)s=h[r?l-t:l+t],s.__.inFlow&&0!==s.__.visible?(c=s.__flowBounds,"from"!==i&&(_=o+(e.width-c.width)/("center"===i?2:1)),B(s,_-c.x,a-c.y),a+=c.height+e.gap):n++}const{move:F}=o.PointHelper;const R=o.inviteCode;function H(t){return o.decorateLeafAttr(t,(t=>o.attr({set(e){const n="number"==typeof e?e:0;"autoWidth"===t?this.__widthGrow=n:this.__heightGrow=n,!n||this.parent&&this.parent.__hasGrow||this.waitParent((()=>{this.parent.__hasGrow=!0})),this.__setAttr(t,e)&&o.doBoundsType(this)}})))}function P(t){return t.length>6&&"e"===t[6]}const{copyAndSpread:X}=o.BoundsHelper;let Y=function(t,e){const o="width",{children:n,itemBox:i}=t,r=f(t,!0),{complex:s,wrap:a,xGap:u,yGap:d,isAutoXGap:x,isFitXGap:G}=r;if(!n.length)return;const m=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},B=x?0:u;let v,F,R,H,P,{x:X,y:Y,width:j,height:k}=t.__layout.contentBounds;for(let r=0,h=n.length;r<h;r++)v=n[H=e?h-1-r:r],v.__.inFlow&&0!==v.__.visible&&(F=p(v,i),s?(v.__flowBounds=F,P||(P=g(H,B)),a&&P.count&&P.width+F.width>j&&(P.grow?y(t,P,j,e):x&&w(P,o,j,G),_(m,P,o),P=g(H,B)),R=F.width,v.__widthGrow&&(P.grow+=v.__widthGrow,R=0,v.__.widthRange&&(P.hasRangeSize=!0)),v.__heightGrow&&b(v,F,k),P.width+=P.count?R+B:R,P.height=Math.max(P.height,F.height),P.count++):(A(v,X-F.x,Y-F.y),X+=F.width+B));if(s){const{isAutoYGap:n,isFitYGap:i,contentAlign:s,rowXAlign:u,rowYAlign:f}=r;P.count&&(P.grow?y(t,P,j,e):x&&w(P,o,j,G),a&&_(m,P,o)),a?(n?w(m,"height",k,i):m.gap=d,function(t,e,o,n){c(t,e,o);const{list:i}=e;if(i.length>1&&(n||(n=h[o]),"from"!==n)){let t;for(let o=0,r=i.length;o<r;o++)t=i[o],t.x=e.width-t.width,"center"===n&&(t.x/=2)}}(t,m,s,u),function(t,e,o,n){const{list:i}=e,r="reverse"===t.__.flowWrap;let h,{x:s,y:c}=e;for(let a=0,_=i.length;a<_;a++)h=i[r?_-1-a:a],l(t,h,s,c,o,n),c+=h.height+e.gap}(t,m,f,e)):(c(t,P,s),l(t,P,0,P.y,f,e))}},j=function(t,e){const o="height",{children:n,itemBox:i}=t,r=f(t,!1),{complex:h,wrap:a,xGap:l,yGap:u,isAutoYGap:d,isFitYGap:y}=r;if(!n.length)return;const G=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},b=d?0:u;let A,B,R,H,P,{x:X,y:Y,width:j,height:k}=t.__layout.contentBounds;for(let r=0,s=n.length;r<s;r++)A=n[H=e?s-1-r:r],A.__.inFlow&&0!==A.__.visible&&(B=p(A,i),h?(A.__flowBounds=B,P||(P=g(H,b)),a&&P.count&&P.height+B.height>k&&(P.grow&&m(t,P,k,e),d&&w(P,o,k,y),_(G,P,o),P=g(H,b)),R=B.height,A.__heightGrow&&(P.grow+=A.__heightGrow,R=0,A.__.heightRange&&(P.hasRangeSize=!0)),A.__widthGrow&&x(A,B,j),P.height+=P.count?R+b:R,P.width=Math.max(P.width,B.width),P.count++):(F(A,X-B.x,Y-B.y),Y+=B.height+b));if(h){const{isAutoXGap:n,isFitXGap:i,contentAlign:h,rowXAlign:u,rowYAlign:f}=r;P.count&&(P.grow&&m(t,P,k,e),d&&w(P,o,k,y),a&&_(G,P,o)),a?(n?w(G,"width",j,i):G.gap=l,function(t,e,o,n){c(t,e,o);const{list:i}=e;if(i.length>1&&(n||(n=s[o]),"from"!==n)){let t;for(let o=0,r=i.length;o<r;o++)t=i[o],t.y=e.height-t.height,"center"===n&&(t.y/=2)}}(t,G,h,f),function(t,e,o,n){const{list:i}=e,r="reverse"===t.__.flowWrap;let h,{x:s,y:c}=e;for(let a=0,l=i.length;a<l;a++)h=i[r?l-1-a:a],v(t,h,s,c,o,n),s+=h.width+e.gap}(t,G,u,e)):(c(t,P,h),v(t,P,P.x,0,u,e))}};return o.UI.changeAttr("autoWidth",void 0,H),o.UI.changeAttr("autoHeight",void 0,H),o.Box.prototype.__updateFlowLayout=function(){this.leafer.created=!1;const{flow:t}=this.__;switch(t){case"x":case!0:Y(this);break;case"y":j(this);break;case"x-reverse":Y(this,!0);break;case"y-reverse":j(this,!0)}this.leafer.created=!0},setTimeout((function(){Object.values(R).some(P)||(Y=()=>{j=Y})})),o.Box.prototype.__updateContentBounds=function(){const{padding:t}=this.__,e=this.__layout,o=e.contentBounds===e.boxBounds;t?(o&&e.shrinkContent(),X(e.contentBounds,e.boxBounds,t,!0)):o||e.shrinkContentCancel()},Object.keys(e).forEach((function(o){"default"===o||Object.prototype.hasOwnProperty.call(t,o)||Object.defineProperty(t,o,{enumerable:!0,get:function(){return e[o]}})})),t}({},LeaferIN.resize,LeaferUI);
1
+ this.LeaferIN=this.LeaferIN||{},this.LeaferIN.flow=function(t,e,o){"use strict";function n(t,e,o,n){var i,r=arguments.length,h=r<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)h=Reflect.decorate(t,e,o,n);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(h=(r<3?i(h):r>3?i(e,o,h):i(e,o))||h);return r>3&&h&&Object.defineProperty(e,o,h),h}"function"==typeof SuppressedError&&SuppressedError;class i extends o.BoxData{}t.Flow=class extends o.Box{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}},n([o.dataProcessor(i)],t.Flow.prototype,"__",void 0),n([o.autoLayoutType("x")],t.Flow.prototype,"flow",void 0),t.Flow=n([o.registerUI()],t.Flow);const r={},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"},s={"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(t,e,n){o.AlignHelper.toPoint(n,e,t.__layout.contentBounds,r);const i=t.__;e.x=i.__autoWidth?0:r.x,e.y=i.__autoHeight?0:r.y}const{move:a}=o.PointHelper;function l(t,e,o,n,i,r){const{children:h}=t;let s,c,{x:l,start:_}=e,u=n;l+=o;for(let t=0,o=e.count;t<o;t++)s=h[r?_-t:_+t],s.__.inFlow&&0!==s.__.visible?(c=s.__flowBounds,"from"!==i&&(u=n+(e.height-c.height)/("center"===i?2:1)),a(s,l-c.x,u-c.y),l+=c.width+e.gap):o++}function _(t,e,o){const n="width"===o?"height":"width";t[o]=Math.max(t[o],e[o]),t[n]+=t.count?e[n]+t.gap:e[n],t.list.push(e),t.count++}const u={};function g(t,e){const{gap:o,flowAlign:n,flowWrap:i,__autoWidth:r,__autoHeight:c}=t.__,a=i&&(e?!r:!c);return"object"==typeof o?(u.xGap=o.x||0,u.yGap=o.y||0):u.xGap=u.yGap=o,u.isAutoXGap="string"==typeof u.xGap&&!r,u.isAutoYGap="string"==typeof u.yGap&&!c,u.complex=a||"top-left"!==n||t.__hasGrow||u.isAutoXGap||u.isAutoYGap,u.wrap=a,u.complex&&(u.isFitXGap="fit"===u.xGap&&!r,u.isFitYGap="fit"===u.yGap&&!c,"object"==typeof n?(u.contentAlign=n.content||"top-left",u.rowXAlign=n.x||"from",u.rowYAlign=n.y||"from"):(u.contentAlign=n,u.rowXAlign=h[n],u.rowYAlign=s[n])),u}function f(t,e){return{x:0,y:0,width:0,height:0,gap:e,start:t,count:0,grow:0}}function w(t,e,o,n){const{count:i}=t;i>1&&(o>t[e]||n)&&(t.gap=(o-t[e])/(i-1),t[e]=o)}function p(t,e){return"box"===e?t.__local:t.__layout.localStrokeBounds}const{within:d}=o.MathHelper;function y(t,e,o,n){let i,r,h,s=0,c=e.hasRangeSize&&[],{grow:a,start:l}=e;const _=e.width<o?(o-e.width)/a:0,{children:u}=t;_&&(e.width=o);for(let t=0,o=e.count;t<o;t++)i=u[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(r=i.__widthGrow)&&(h=x(i,i.__flowBounds,_*r),h?(s+=h,a-=r):c&&(i.__.widthRange?c.unshift(i):c.push(i))):o++;s&&function(t,e,o){let n,i,r,h;t.forEach((t=>{n=t.__widthGrow,i=e/o*n,h=x(t,r=t.__flowBounds,r.width+i),e-=i-h,o-=n}))}(c,s,a)}function x(t,e,o){const{widthRange:n,lockRatio:i}=t.__,r=n?d(o,n.min,n.max):o,h=r/e.width;return t.scaleResize(h,i?h:1),e.width=r,o-r}const{within:G}=o.MathHelper;function m(t,e,o,n){let i,r,h,s=0,c=e.hasRangeSize&&[],{grow:a,start:l}=e;const _=e.height<o?(o-e.height)/a:0,{children:u}=t;_&&(e.height=o);for(let t=0,o=e.count;t<o;t++)i=u[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(r=i.__heightGrow)&&(h=b(i,i.__flowBounds,_*r),h?(s+=h,a-=r):c&&(i.__.heightRange?c.unshift(i):c.push(i))):o++;s&&function(t,e,o){let n,i,r,h;t.forEach((t=>{n=t.__heightGrow,i=e/o*n,h=b(t,r=t.__flowBounds,r.height+i),e-=i-h,o-=n}))}(c,s,a)}function b(t,e,o){const{heightRange:n,lockRatio:i}=t.__,r=n?G(o,n.min,n.max):o,h=r/e.height;return t.scaleResize(i?h:1,h),e.height=r,o-r}const{move:A}=o.PointHelper;const{move:B}=o.PointHelper;function v(t,e,o,n,i,r){const{children:h}=t;let s,c,{y:a,start:l}=e,_=o;a+=n;for(let t=0,n=e.count;t<n;t++)s=h[r?l-t:l+t],s.__.inFlow&&0!==s.__.visible?(c=s.__flowBounds,"from"!==i&&(_=o+(e.width-c.width)/("center"===i?2:1)),B(s,_-c.x,a-c.y),a+=c.height+e.gap):n++}const{move:F}=o.PointHelper;function R(t){return o.decorateLeafAttr(t,(t=>o.attr({set(e){const n="number"==typeof e?e:0;"autoWidth"===t?this.__widthGrow=n:this.__heightGrow=n,!n||this.parent&&this.parent.__hasGrow||this.waitParent((()=>{this.parent.__hasGrow=!0})),this.__setAttr(t,e)&&o.doBoundsType(this)}})))}const{copyAndSpread:H}=o.BoundsHelper;let P=function(t,e){const o="width",{children:n,itemBox:i}=t,r=g(t,!0),{complex:s,wrap:a,xGap:u,yGap:d,isAutoXGap:x,isFitXGap:G}=r;if(!n.length)return;const m=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},B=x?0:u;let v,F,R,H,P,{x:X,y:Y,width:k,height:L}=t.__layout.contentBounds;for(let r=0,h=n.length;r<h;r++)v=n[H=e?h-1-r:r],v.__.inFlow&&0!==v.__.visible&&(F=p(v,i),s?(v.__flowBounds=F,P||(P=f(H,B)),a&&P.count&&P.width+F.width>k&&(P.grow?y(t,P,k,e):x&&w(P,o,k,G),_(m,P,o),P=f(H,B)),R=F.width,v.__widthGrow&&(P.grow+=v.__widthGrow,R=0,v.__.widthRange&&(P.hasRangeSize=!0)),v.__heightGrow&&b(v,F,L),P.width+=P.count?R+B:R,P.height=Math.max(P.height,F.height),P.count++):(A(v,X-F.x,Y-F.y),X+=F.width+B));if(s){const{isAutoYGap:n,isFitYGap:i,contentAlign:s,rowXAlign:u,rowYAlign:g}=r;P.count&&(P.grow?y(t,P,k,e):x&&w(P,o,k,G),a&&_(m,P,o)),a?(n?w(m,"height",L,i):m.gap=d,function(t,e,o,n){c(t,e,o);const{list:i}=e;if(i.length>1&&(n||(n=h[o]),"from"!==n)){let t;for(let o=0,r=i.length;o<r;o++)t=i[o],t.x=e.width-t.width,"center"===n&&(t.x/=2)}}(t,m,s,u),function(t,e,o,n){const{list:i}=e,r="reverse"===t.__.flowWrap;let h,{x:s,y:c}=e;for(let a=0,_=i.length;a<_;a++)h=i[r?_-1-a:a],l(t,h,s,c,o,n),c+=h.height+e.gap}(t,m,g,e)):(c(t,P,s),l(t,P,0,P.y,g,e))}},X=function(t,e){const o="height",{children:n,itemBox:i}=t,r=g(t,!1),{complex:h,wrap:a,xGap:l,yGap:u,isAutoYGap:d,isFitYGap:y}=r;if(!n.length)return;const G=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},b=d?0:u;let A,B,R,H,P,{x:X,y:Y,width:k,height:L}=t.__layout.contentBounds;for(let r=0,s=n.length;r<s;r++)A=n[H=e?s-1-r:r],A.__.inFlow&&0!==A.__.visible&&(B=p(A,i),h?(A.__flowBounds=B,P||(P=f(H,b)),a&&P.count&&P.height+B.height>L&&(P.grow&&m(t,P,L,e),d&&w(P,o,L,y),_(G,P,o),P=f(H,b)),R=B.height,A.__heightGrow&&(P.grow+=A.__heightGrow,R=0,A.__.heightRange&&(P.hasRangeSize=!0)),A.__widthGrow&&x(A,B,k),P.height+=P.count?R+b:R,P.width=Math.max(P.width,B.width),P.count++):(F(A,X-B.x,Y-B.y),Y+=B.height+b));if(h){const{isAutoXGap:n,isFitXGap:i,contentAlign:h,rowXAlign:u,rowYAlign:g}=r;P.count&&(P.grow&&m(t,P,L,e),d&&w(P,o,L,y),a&&_(G,P,o)),a?(n?w(G,"width",k,i):G.gap=l,function(t,e,o,n){c(t,e,o);const{list:i}=e;if(i.length>1&&(n||(n=s[o]),"from"!==n)){let t;for(let o=0,r=i.length;o<r;o++)t=i[o],t.y=e.height-t.height,"center"===n&&(t.y/=2)}}(t,G,h,g),function(t,e,o,n){const{list:i}=e,r="reverse"===t.__.flowWrap;let h,{x:s,y:c}=e;for(let a=0,l=i.length;a<l;a++)h=i[r?l-1-a:a],v(t,h,s,c,o,n),s+=h.width+e.gap}(t,G,u,e)):(c(t,P,h),v(t,P,P.x,0,u,e))}};return o.UI.changeAttr("autoWidth",void 0,R),o.UI.changeAttr("autoHeight",void 0,R),o.Box.prototype.__updateFlowLayout=function(){this.leafer.created=!1;const{flow:t}=this.__;switch(t){case"x":case!0:P(this);break;case"y":X(this);break;case"x-reverse":P(this,!0);break;case"y-reverse":X(this,!0)}this.leafer.created=!0},o.Box.prototype.__updateContentBounds=function(){const{padding:t}=this.__,e=this.__layout,o=e.contentBounds===e.boxBounds;t?(o&&e.shrinkContent(),H(e.contentBounds,e.boxBounds,t,!0)):o||e.shrinkContentCancel()},Object.keys(e).forEach((function(o){"default"===o||Object.prototype.hasOwnProperty.call(t,o)||Object.defineProperty(t,o,{enumerable:!0,get:function(){return e[o]}})})),t}({},LeaferIN.resize,LeaferUI);
package/dist/flow.min.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t=require("@leafer-in/resize"),e=require("@leafer-ui/draw");function o(t,e,o,n){var i,r=arguments.length,h=r<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)h=Reflect.decorate(t,e,o,n);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(h=(r<3?i(h):r>3?i(e,o,h):i(e,o))||h);return r>3&&h&&Object.defineProperty(e,o,h),h}"function"==typeof SuppressedError&&SuppressedError;class n extends e.BoxData{}exports.Flow=class extends e.Box{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}},o([e.dataProcessor(n)],exports.Flow.prototype,"__",void 0),o([e.autoLayoutType("x")],exports.Flow.prototype,"flow",void 0),exports.Flow=o([e.registerUI()],exports.Flow);const i={},r={"top-left":"from",top:"center","top-right":"to",right:"to","bottom-right":"to",bottom:"center","bottom-left":"from",left:"from",center:"center","baseline-left":"from","baseline-center":"center","baseline-right":"to"},h={"top-left":"from",top:"from","top-right":"from",right:"center","bottom-right":"to",bottom:"to","bottom-left":"to",left:"center",center:"center","baseline-left":"to","baseline-center":"to","baseline-right":"to"};function s(t,o,n){e.AlignHelper.toPoint(n,o,t.__layout.contentBounds,i);const r=t.__;o.x=r.__autoWidth?0:i.x,o.y=r.__autoHeight?0:i.y}const{move:c}=e.PointHelper;function a(t,e,o,n,i,r){const{children:h}=t;let s,a,{x:l,start:_}=e,u=n;l+=o;for(let t=0,o=e.count;t<o;t++)s=h[r?_-t:_+t],s.__.inFlow&&0!==s.__.visible?(a=s.__flowBounds,"from"!==i&&(u=n+(e.height-a.height)/("center"===i?2:1)),c(s,l-a.x,u-a.y),l+=a.width+e.gap):o++}function l(t,e,o){const n="width"===o?"height":"width";t[o]=Math.max(t[o],e[o]),t[n]+=t.count?e[n]+t.gap:e[n],t.list.push(e),t.count++}const _={};function u(t,e){const{gap:o,flowAlign:n,flowWrap:i,__autoWidth:s,__autoHeight:c}=t.__,a=i&&(e?!s:!c);return"object"==typeof o?(_.xGap=o.x||0,_.yGap=o.y||0):_.xGap=_.yGap=o,_.isAutoXGap="string"==typeof _.xGap&&!s,_.isAutoYGap="string"==typeof _.yGap&&!c,_.complex=a||"top-left"!==n||t.__hasGrow||_.isAutoXGap||_.isAutoYGap,_.wrap=a,_.complex&&(_.isFitXGap="fit"===_.xGap&&!s,_.isFitYGap="fit"===_.yGap&&!c,"object"==typeof n?(_.contentAlign=n.content||"top-left",_.rowXAlign=n.x||"from",_.rowYAlign=n.y||"from"):(_.contentAlign=n,_.rowXAlign=r[n],_.rowYAlign=h[n])),_}function g(t,e){return{x:0,y:0,width:0,height:0,gap:e,start:t,count:0,grow:0}}function p(t,e,o,n){const{count:i}=t;i>1&&(o>t[e]||n)&&(t.gap=(o-t[e])/(i-1),t[e]=o)}function f(t,e){return"box"===e?t.__local:t.__layout.localStrokeBounds}const{within:w}=e.MathHelper;function d(t,e,o,n){let i,r,h,s=0,c=e.hasRangeSize&&[],{grow:a,start:l}=e;const _=e.width<o?(o-e.width)/a:0,{children:u}=t;_&&(e.width=o);for(let t=0,o=e.count;t<o;t++)i=u[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(r=i.__widthGrow)&&(h=y(i,i.__flowBounds,_*r),h?(s+=h,a-=r):c&&(i.__.widthRange?c.unshift(i):c.push(i))):o++;s&&function(t,e,o){let n,i,r,h;t.forEach((t=>{n=t.__widthGrow,i=e/o*n,h=y(t,r=t.__flowBounds,r.width+i),e-=i-h,o-=n}))}(c,s,a)}function y(t,e,o){const{widthRange:n,lockRatio:i}=t.__,r=n?w(o,n.min,n.max):o,h=r/e.width;return t.scaleResize(h,i?h:1),e.width=r,o-r}const{within:x}=e.MathHelper;function G(t,e,o,n){let i,r,h,s=0,c=e.hasRangeSize&&[],{grow:a,start:l}=e;const _=e.height<o?(o-e.height)/a:0,{children:u}=t;_&&(e.height=o);for(let t=0,o=e.count;t<o;t++)i=u[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(r=i.__heightGrow)&&(h=m(i,i.__flowBounds,_*r),h?(s+=h,a-=r):c&&(i.__.heightRange?c.unshift(i):c.push(i))):o++;s&&function(t,e,o){let n,i,r,h;t.forEach((t=>{n=t.__heightGrow,i=e/o*n,h=m(t,r=t.__flowBounds,r.height+i),e-=i-h,o-=n}))}(c,s,a)}function m(t,e,o){const{heightRange:n,lockRatio:i}=t.__,r=n?x(o,n.min,n.max):o,h=r/e.height;return t.scaleResize(i?h:1,h),e.height=r,o-r}const{move:b}=e.PointHelper;const{move:A}=e.PointHelper;function B(t,e,o,n,i,r){const{children:h}=t;let s,c,{y:a,start:l}=e,_=o;a+=n;for(let t=0,n=e.count;t<n;t++)s=h[r?l-t:l+t],s.__.inFlow&&0!==s.__.visible?(c=s.__flowBounds,"from"!==i&&(_=o+(e.width-c.width)/("center"===i?2:1)),A(s,_-c.x,a-c.y),a+=c.height+e.gap):n++}const{move:v}=e.PointHelper;const F=e.inviteCode;function R(t){return e.decorateLeafAttr(t,(t=>e.attr({set(o){const n="number"==typeof o?o:0;"autoWidth"===t?this.__widthGrow=n:this.__heightGrow=n,!n||this.parent&&this.parent.__hasGrow||this.waitParent((()=>{this.parent.__hasGrow=!0})),this.__setAttr(t,o)&&e.doBoundsType(this)}})))}function H(t){return t.length>6&&"e"===t[6]}const{copyAndSpread:P}=e.BoundsHelper;let X=function(t,e){const o="width",{children:n,itemBox:i}=t,h=u(t,!0),{complex:c,wrap:_,xGap:w,yGap:y,isAutoXGap:x,isFitXGap:G}=h;if(!n.length)return;const A=_&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},B=x?0:w;let v,F,R,H,P,{x:X,y:Y,width:j,height:k}=t.__layout.contentBounds;for(let r=0,h=n.length;r<h;r++)v=n[H=e?h-1-r:r],v.__.inFlow&&0!==v.__.visible&&(F=f(v,i),c?(v.__flowBounds=F,P||(P=g(H,B)),_&&P.count&&P.width+F.width>j&&(P.grow?d(t,P,j,e):x&&p(P,o,j,G),l(A,P,o),P=g(H,B)),R=F.width,v.__widthGrow&&(P.grow+=v.__widthGrow,R=0,v.__.widthRange&&(P.hasRangeSize=!0)),v.__heightGrow&&m(v,F,k),P.width+=P.count?R+B:R,P.height=Math.max(P.height,F.height),P.count++):(b(v,X-F.x,Y-F.y),X+=F.width+B));if(c){const{isAutoYGap:n,isFitYGap:i,contentAlign:c,rowXAlign:u,rowYAlign:g}=h;P.count&&(P.grow?d(t,P,j,e):x&&p(P,o,j,G),_&&l(A,P,o)),_?(n?p(A,"height",k,i):A.gap=y,function(t,e,o,n){s(t,e,o);const{list:i}=e;if(i.length>1&&(n||(n=r[o]),"from"!==n)){let t;for(let o=0,r=i.length;o<r;o++)t=i[o],t.x=e.width-t.width,"center"===n&&(t.x/=2)}}(t,A,c,u),function(t,e,o,n){const{list:i}=e,r="reverse"===t.__.flowWrap;let h,{x:s,y:c}=e;for(let l=0,_=i.length;l<_;l++)h=i[r?_-1-l:l],a(t,h,s,c,o,n),c+=h.height+e.gap}(t,A,g,e)):(s(t,P,c),a(t,P,0,P.y,g,e))}},Y=function(t,e){const o="height",{children:n,itemBox:i}=t,r=u(t,!1),{complex:c,wrap:a,xGap:_,yGap:w,isAutoYGap:d,isFitYGap:x}=r;if(!n.length)return;const m=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},b=d?0:w;let A,F,R,H,P,{x:X,y:Y,width:j,height:k}=t.__layout.contentBounds;for(let r=0,h=n.length;r<h;r++)A=n[H=e?h-1-r:r],A.__.inFlow&&0!==A.__.visible&&(F=f(A,i),c?(A.__flowBounds=F,P||(P=g(H,b)),a&&P.count&&P.height+F.height>k&&(P.grow&&G(t,P,k,e),d&&p(P,o,k,x),l(m,P,o),P=g(H,b)),R=F.height,A.__heightGrow&&(P.grow+=A.__heightGrow,R=0,A.__.heightRange&&(P.hasRangeSize=!0)),A.__widthGrow&&y(A,F,j),P.height+=P.count?R+b:R,P.width=Math.max(P.width,F.width),P.count++):(v(A,X-F.x,Y-F.y),Y+=F.height+b));if(c){const{isAutoXGap:n,isFitXGap:i,contentAlign:c,rowXAlign:u,rowYAlign:g}=r;P.count&&(P.grow&&G(t,P,k,e),d&&p(P,o,k,x),a&&l(m,P,o)),a?(n?p(m,"width",j,i):m.gap=_,function(t,e,o,n){s(t,e,o);const{list:i}=e;if(i.length>1&&(n||(n=h[o]),"from"!==n)){let t;for(let o=0,r=i.length;o<r;o++)t=i[o],t.y=e.height-t.height,"center"===n&&(t.y/=2)}}(t,m,c,g),function(t,e,o,n){const{list:i}=e,r="reverse"===t.__.flowWrap;let h,{x:s,y:c}=e;for(let a=0,l=i.length;a<l;a++)h=i[r?l-1-a:a],B(t,h,s,c,o,n),s+=h.width+e.gap}(t,m,u,e)):(s(t,P,c),B(t,P,P.x,0,u,e))}};e.UI.changeAttr("autoWidth",void 0,R),e.UI.changeAttr("autoHeight",void 0,R),e.Box.prototype.__updateFlowLayout=function(){this.leafer.created=!1;const{flow:t}=this.__;switch(t){case"x":case!0:X(this);break;case"y":Y(this);break;case"x-reverse":X(this,!0);break;case"y-reverse":Y(this,!0)}this.leafer.created=!0},setTimeout((function(){Object.values(F).some(H)||(X=()=>{Y=X})})),e.Box.prototype.__updateContentBounds=function(){const{padding:t}=this.__,e=this.__layout,o=e.contentBounds===e.boxBounds;t?(o&&e.shrinkContent(),P(e.contentBounds,e.boxBounds,t,!0)):o||e.shrinkContentCancel()},Object.keys(t).forEach((function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})}));
1
+ "use strict";var t=require("@leafer-in/resize"),e=require("@leafer-ui/draw");function o(t,e,o,n){var i,r=arguments.length,h=r<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)h=Reflect.decorate(t,e,o,n);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(h=(r<3?i(h):r>3?i(e,o,h):i(e,o))||h);return r>3&&h&&Object.defineProperty(e,o,h),h}"function"==typeof SuppressedError&&SuppressedError;class n extends e.BoxData{}exports.Flow=class extends e.Box{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}},o([e.dataProcessor(n)],exports.Flow.prototype,"__",void 0),o([e.autoLayoutType("x")],exports.Flow.prototype,"flow",void 0),exports.Flow=o([e.registerUI()],exports.Flow);const i={},r={"top-left":"from",top:"center","top-right":"to",right:"to","bottom-right":"to",bottom:"center","bottom-left":"from",left:"from",center:"center","baseline-left":"from","baseline-center":"center","baseline-right":"to"},h={"top-left":"from",top:"from","top-right":"from",right:"center","bottom-right":"to",bottom:"to","bottom-left":"to",left:"center",center:"center","baseline-left":"to","baseline-center":"to","baseline-right":"to"};function s(t,o,n){e.AlignHelper.toPoint(n,o,t.__layout.contentBounds,i);const r=t.__;o.x=r.__autoWidth?0:i.x,o.y=r.__autoHeight?0:i.y}const{move:c}=e.PointHelper;function a(t,e,o,n,i,r){const{children:h}=t;let s,a,{x:l,start:_}=e,u=n;l+=o;for(let t=0,o=e.count;t<o;t++)s=h[r?_-t:_+t],s.__.inFlow&&0!==s.__.visible?(a=s.__flowBounds,"from"!==i&&(u=n+(e.height-a.height)/("center"===i?2:1)),c(s,l-a.x,u-a.y),l+=a.width+e.gap):o++}function l(t,e,o){const n="width"===o?"height":"width";t[o]=Math.max(t[o],e[o]),t[n]+=t.count?e[n]+t.gap:e[n],t.list.push(e),t.count++}const _={};function u(t,e){const{gap:o,flowAlign:n,flowWrap:i,__autoWidth:s,__autoHeight:c}=t.__,a=i&&(e?!s:!c);return"object"==typeof o?(_.xGap=o.x||0,_.yGap=o.y||0):_.xGap=_.yGap=o,_.isAutoXGap="string"==typeof _.xGap&&!s,_.isAutoYGap="string"==typeof _.yGap&&!c,_.complex=a||"top-left"!==n||t.__hasGrow||_.isAutoXGap||_.isAutoYGap,_.wrap=a,_.complex&&(_.isFitXGap="fit"===_.xGap&&!s,_.isFitYGap="fit"===_.yGap&&!c,"object"==typeof n?(_.contentAlign=n.content||"top-left",_.rowXAlign=n.x||"from",_.rowYAlign=n.y||"from"):(_.contentAlign=n,_.rowXAlign=r[n],_.rowYAlign=h[n])),_}function g(t,e){return{x:0,y:0,width:0,height:0,gap:e,start:t,count:0,grow:0}}function p(t,e,o,n){const{count:i}=t;i>1&&(o>t[e]||n)&&(t.gap=(o-t[e])/(i-1),t[e]=o)}function f(t,e){return"box"===e?t.__local:t.__layout.localStrokeBounds}const{within:w}=e.MathHelper;function d(t,e,o,n){let i,r,h,s=0,c=e.hasRangeSize&&[],{grow:a,start:l}=e;const _=e.width<o?(o-e.width)/a:0,{children:u}=t;_&&(e.width=o);for(let t=0,o=e.count;t<o;t++)i=u[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(r=i.__widthGrow)&&(h=y(i,i.__flowBounds,_*r),h?(s+=h,a-=r):c&&(i.__.widthRange?c.unshift(i):c.push(i))):o++;s&&function(t,e,o){let n,i,r,h;t.forEach((t=>{n=t.__widthGrow,i=e/o*n,h=y(t,r=t.__flowBounds,r.width+i),e-=i-h,o-=n}))}(c,s,a)}function y(t,e,o){const{widthRange:n,lockRatio:i}=t.__,r=n?w(o,n.min,n.max):o,h=r/e.width;return t.scaleResize(h,i?h:1),e.width=r,o-r}const{within:x}=e.MathHelper;function G(t,e,o,n){let i,r,h,s=0,c=e.hasRangeSize&&[],{grow:a,start:l}=e;const _=e.height<o?(o-e.height)/a:0,{children:u}=t;_&&(e.height=o);for(let t=0,o=e.count;t<o;t++)i=u[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(r=i.__heightGrow)&&(h=m(i,i.__flowBounds,_*r),h?(s+=h,a-=r):c&&(i.__.heightRange?c.unshift(i):c.push(i))):o++;s&&function(t,e,o){let n,i,r,h;t.forEach((t=>{n=t.__heightGrow,i=e/o*n,h=m(t,r=t.__flowBounds,r.height+i),e-=i-h,o-=n}))}(c,s,a)}function m(t,e,o){const{heightRange:n,lockRatio:i}=t.__,r=n?x(o,n.min,n.max):o,h=r/e.height;return t.scaleResize(i?h:1,h),e.height=r,o-r}const{move:b}=e.PointHelper;const{move:A}=e.PointHelper;function B(t,e,o,n,i,r){const{children:h}=t;let s,c,{y:a,start:l}=e,_=o;a+=n;for(let t=0,n=e.count;t<n;t++)s=h[r?l-t:l+t],s.__.inFlow&&0!==s.__.visible?(c=s.__flowBounds,"from"!==i&&(_=o+(e.width-c.width)/("center"===i?2:1)),A(s,_-c.x,a-c.y),a+=c.height+e.gap):n++}const{move:v}=e.PointHelper;function F(t){return e.decorateLeafAttr(t,(t=>e.attr({set(o){const n="number"==typeof o?o:0;"autoWidth"===t?this.__widthGrow=n:this.__heightGrow=n,!n||this.parent&&this.parent.__hasGrow||this.waitParent((()=>{this.parent.__hasGrow=!0})),this.__setAttr(t,o)&&e.doBoundsType(this)}})))}const{copyAndSpread:R}=e.BoundsHelper;let H=function(t,e){const o="width",{children:n,itemBox:i}=t,h=u(t,!0),{complex:c,wrap:_,xGap:w,yGap:y,isAutoXGap:x,isFitXGap:G}=h;if(!n.length)return;const A=_&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},B=x?0:w;let v,F,R,H,P,{x:X,y:Y,width:k,height:j}=t.__layout.contentBounds;for(let r=0,h=n.length;r<h;r++)v=n[H=e?h-1-r:r],v.__.inFlow&&0!==v.__.visible&&(F=f(v,i),c?(v.__flowBounds=F,P||(P=g(H,B)),_&&P.count&&P.width+F.width>k&&(P.grow?d(t,P,k,e):x&&p(P,o,k,G),l(A,P,o),P=g(H,B)),R=F.width,v.__widthGrow&&(P.grow+=v.__widthGrow,R=0,v.__.widthRange&&(P.hasRangeSize=!0)),v.__heightGrow&&m(v,F,j),P.width+=P.count?R+B:R,P.height=Math.max(P.height,F.height),P.count++):(b(v,X-F.x,Y-F.y),X+=F.width+B));if(c){const{isAutoYGap:n,isFitYGap:i,contentAlign:c,rowXAlign:u,rowYAlign:g}=h;P.count&&(P.grow?d(t,P,k,e):x&&p(P,o,k,G),_&&l(A,P,o)),_?(n?p(A,"height",j,i):A.gap=y,function(t,e,o,n){s(t,e,o);const{list:i}=e;if(i.length>1&&(n||(n=r[o]),"from"!==n)){let t;for(let o=0,r=i.length;o<r;o++)t=i[o],t.x=e.width-t.width,"center"===n&&(t.x/=2)}}(t,A,c,u),function(t,e,o,n){const{list:i}=e,r="reverse"===t.__.flowWrap;let h,{x:s,y:c}=e;for(let l=0,_=i.length;l<_;l++)h=i[r?_-1-l:l],a(t,h,s,c,o,n),c+=h.height+e.gap}(t,A,g,e)):(s(t,P,c),a(t,P,0,P.y,g,e))}},P=function(t,e){const o="height",{children:n,itemBox:i}=t,r=u(t,!1),{complex:c,wrap:a,xGap:_,yGap:w,isAutoYGap:d,isFitYGap:x}=r;if(!n.length)return;const m=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},b=d?0:w;let A,F,R,H,P,{x:X,y:Y,width:k,height:j}=t.__layout.contentBounds;for(let r=0,h=n.length;r<h;r++)A=n[H=e?h-1-r:r],A.__.inFlow&&0!==A.__.visible&&(F=f(A,i),c?(A.__flowBounds=F,P||(P=g(H,b)),a&&P.count&&P.height+F.height>j&&(P.grow&&G(t,P,j,e),d&&p(P,o,j,x),l(m,P,o),P=g(H,b)),R=F.height,A.__heightGrow&&(P.grow+=A.__heightGrow,R=0,A.__.heightRange&&(P.hasRangeSize=!0)),A.__widthGrow&&y(A,F,k),P.height+=P.count?R+b:R,P.width=Math.max(P.width,F.width),P.count++):(v(A,X-F.x,Y-F.y),Y+=F.height+b));if(c){const{isAutoXGap:n,isFitXGap:i,contentAlign:c,rowXAlign:u,rowYAlign:g}=r;P.count&&(P.grow&&G(t,P,j,e),d&&p(P,o,j,x),a&&l(m,P,o)),a?(n?p(m,"width",k,i):m.gap=_,function(t,e,o,n){s(t,e,o);const{list:i}=e;if(i.length>1&&(n||(n=h[o]),"from"!==n)){let t;for(let o=0,r=i.length;o<r;o++)t=i[o],t.y=e.height-t.height,"center"===n&&(t.y/=2)}}(t,m,c,g),function(t,e,o,n){const{list:i}=e,r="reverse"===t.__.flowWrap;let h,{x:s,y:c}=e;for(let a=0,l=i.length;a<l;a++)h=i[r?l-1-a:a],B(t,h,s,c,o,n),s+=h.width+e.gap}(t,m,u,e)):(s(t,P,c),B(t,P,P.x,0,u,e))}};e.UI.changeAttr("autoWidth",void 0,F),e.UI.changeAttr("autoHeight",void 0,F),e.Box.prototype.__updateFlowLayout=function(){this.leafer.created=!1;const{flow:t}=this.__;switch(t){case"x":case!0:H(this);break;case"y":P(this);break;case"x-reverse":H(this,!0);break;case"y-reverse":P(this,!0)}this.leafer.created=!0},e.Box.prototype.__updateContentBounds=function(){const{padding:t}=this.__,e=this.__layout,o=e.contentBounds===e.boxBounds;t?(o&&e.shrinkContent(),R(e.contentBounds,e.boxBounds,t,!0)):o||e.shrinkContentCancel()},Object.keys(t).forEach((function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})}));
package/dist/flow.min.js CHANGED
@@ -1 +1 @@
1
- this.LeaferIN=this.LeaferIN||{},this.LeaferIN.flow=function(t,e,o){"use strict";function n(t,e,o,n){var i,r=arguments.length,h=r<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)h=Reflect.decorate(t,e,o,n);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(h=(r<3?i(h):r>3?i(e,o,h):i(e,o))||h);return r>3&&h&&Object.defineProperty(e,o,h),h}"function"==typeof SuppressedError&&SuppressedError;class i extends o.BoxData{}t.Flow=class extends o.Box{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}},n([o.dataProcessor(i)],t.Flow.prototype,"__",void 0),n([o.autoLayoutType("x")],t.Flow.prototype,"flow",void 0),t.Flow=n([o.registerUI()],t.Flow);const r={},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"},s={"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(t,e,n){o.AlignHelper.toPoint(n,e,t.__layout.contentBounds,r);const i=t.__;e.x=i.__autoWidth?0:r.x,e.y=i.__autoHeight?0:r.y}const{move:a}=o.PointHelper;function l(t,e,o,n,i,r){const{children:h}=t;let s,c,{x:l,start:_}=e,u=n;l+=o;for(let t=0,o=e.count;t<o;t++)s=h[r?_-t:_+t],s.__.inFlow&&0!==s.__.visible?(c=s.__flowBounds,"from"!==i&&(u=n+(e.height-c.height)/("center"===i?2:1)),a(s,l-c.x,u-c.y),l+=c.width+e.gap):o++}function _(t,e,o){const n="width"===o?"height":"width";t[o]=Math.max(t[o],e[o]),t[n]+=t.count?e[n]+t.gap:e[n],t.list.push(e),t.count++}const u={};function f(t,e){const{gap:o,flowAlign:n,flowWrap:i,__autoWidth:r,__autoHeight:c}=t.__,a=i&&(e?!r:!c);return"object"==typeof o?(u.xGap=o.x||0,u.yGap=o.y||0):u.xGap=u.yGap=o,u.isAutoXGap="string"==typeof u.xGap&&!r,u.isAutoYGap="string"==typeof u.yGap&&!c,u.complex=a||"top-left"!==n||t.__hasGrow||u.isAutoXGap||u.isAutoYGap,u.wrap=a,u.complex&&(u.isFitXGap="fit"===u.xGap&&!r,u.isFitYGap="fit"===u.yGap&&!c,"object"==typeof n?(u.contentAlign=n.content||"top-left",u.rowXAlign=n.x||"from",u.rowYAlign=n.y||"from"):(u.contentAlign=n,u.rowXAlign=h[n],u.rowYAlign=s[n])),u}function g(t,e){return{x:0,y:0,width:0,height:0,gap:e,start:t,count:0,grow:0}}function w(t,e,o,n){const{count:i}=t;i>1&&(o>t[e]||n)&&(t.gap=(o-t[e])/(i-1),t[e]=o)}function p(t,e){return"box"===e?t.__local:t.__layout.localStrokeBounds}const{within:d}=o.MathHelper;function y(t,e,o,n){let i,r,h,s=0,c=e.hasRangeSize&&[],{grow:a,start:l}=e;const _=e.width<o?(o-e.width)/a:0,{children:u}=t;_&&(e.width=o);for(let t=0,o=e.count;t<o;t++)i=u[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(r=i.__widthGrow)&&(h=x(i,i.__flowBounds,_*r),h?(s+=h,a-=r):c&&(i.__.widthRange?c.unshift(i):c.push(i))):o++;s&&function(t,e,o){let n,i,r,h;t.forEach((t=>{n=t.__widthGrow,i=e/o*n,h=x(t,r=t.__flowBounds,r.width+i),e-=i-h,o-=n}))}(c,s,a)}function x(t,e,o){const{widthRange:n,lockRatio:i}=t.__,r=n?d(o,n.min,n.max):o,h=r/e.width;return t.scaleResize(h,i?h:1),e.width=r,o-r}const{within:G}=o.MathHelper;function m(t,e,o,n){let i,r,h,s=0,c=e.hasRangeSize&&[],{grow:a,start:l}=e;const _=e.height<o?(o-e.height)/a:0,{children:u}=t;_&&(e.height=o);for(let t=0,o=e.count;t<o;t++)i=u[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(r=i.__heightGrow)&&(h=b(i,i.__flowBounds,_*r),h?(s+=h,a-=r):c&&(i.__.heightRange?c.unshift(i):c.push(i))):o++;s&&function(t,e,o){let n,i,r,h;t.forEach((t=>{n=t.__heightGrow,i=e/o*n,h=b(t,r=t.__flowBounds,r.height+i),e-=i-h,o-=n}))}(c,s,a)}function b(t,e,o){const{heightRange:n,lockRatio:i}=t.__,r=n?G(o,n.min,n.max):o,h=r/e.height;return t.scaleResize(i?h:1,h),e.height=r,o-r}const{move:A}=o.PointHelper;const{move:B}=o.PointHelper;function v(t,e,o,n,i,r){const{children:h}=t;let s,c,{y:a,start:l}=e,_=o;a+=n;for(let t=0,n=e.count;t<n;t++)s=h[r?l-t:l+t],s.__.inFlow&&0!==s.__.visible?(c=s.__flowBounds,"from"!==i&&(_=o+(e.width-c.width)/("center"===i?2:1)),B(s,_-c.x,a-c.y),a+=c.height+e.gap):n++}const{move:F}=o.PointHelper;const R=o.inviteCode;function H(t){return o.decorateLeafAttr(t,(t=>o.attr({set(e){const n="number"==typeof e?e:0;"autoWidth"===t?this.__widthGrow=n:this.__heightGrow=n,!n||this.parent&&this.parent.__hasGrow||this.waitParent((()=>{this.parent.__hasGrow=!0})),this.__setAttr(t,e)&&o.doBoundsType(this)}})))}function P(t){return t.length>6&&"e"===t[6]}const{copyAndSpread:X}=o.BoundsHelper;let Y=function(t,e){const o="width",{children:n,itemBox:i}=t,r=f(t,!0),{complex:s,wrap:a,xGap:u,yGap:d,isAutoXGap:x,isFitXGap:G}=r;if(!n.length)return;const m=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},B=x?0:u;let v,F,R,H,P,{x:X,y:Y,width:j,height:k}=t.__layout.contentBounds;for(let r=0,h=n.length;r<h;r++)v=n[H=e?h-1-r:r],v.__.inFlow&&0!==v.__.visible&&(F=p(v,i),s?(v.__flowBounds=F,P||(P=g(H,B)),a&&P.count&&P.width+F.width>j&&(P.grow?y(t,P,j,e):x&&w(P,o,j,G),_(m,P,o),P=g(H,B)),R=F.width,v.__widthGrow&&(P.grow+=v.__widthGrow,R=0,v.__.widthRange&&(P.hasRangeSize=!0)),v.__heightGrow&&b(v,F,k),P.width+=P.count?R+B:R,P.height=Math.max(P.height,F.height),P.count++):(A(v,X-F.x,Y-F.y),X+=F.width+B));if(s){const{isAutoYGap:n,isFitYGap:i,contentAlign:s,rowXAlign:u,rowYAlign:f}=r;P.count&&(P.grow?y(t,P,j,e):x&&w(P,o,j,G),a&&_(m,P,o)),a?(n?w(m,"height",k,i):m.gap=d,function(t,e,o,n){c(t,e,o);const{list:i}=e;if(i.length>1&&(n||(n=h[o]),"from"!==n)){let t;for(let o=0,r=i.length;o<r;o++)t=i[o],t.x=e.width-t.width,"center"===n&&(t.x/=2)}}(t,m,s,u),function(t,e,o,n){const{list:i}=e,r="reverse"===t.__.flowWrap;let h,{x:s,y:c}=e;for(let a=0,_=i.length;a<_;a++)h=i[r?_-1-a:a],l(t,h,s,c,o,n),c+=h.height+e.gap}(t,m,f,e)):(c(t,P,s),l(t,P,0,P.y,f,e))}},j=function(t,e){const o="height",{children:n,itemBox:i}=t,r=f(t,!1),{complex:h,wrap:a,xGap:l,yGap:u,isAutoYGap:d,isFitYGap:y}=r;if(!n.length)return;const G=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},b=d?0:u;let A,B,R,H,P,{x:X,y:Y,width:j,height:k}=t.__layout.contentBounds;for(let r=0,s=n.length;r<s;r++)A=n[H=e?s-1-r:r],A.__.inFlow&&0!==A.__.visible&&(B=p(A,i),h?(A.__flowBounds=B,P||(P=g(H,b)),a&&P.count&&P.height+B.height>k&&(P.grow&&m(t,P,k,e),d&&w(P,o,k,y),_(G,P,o),P=g(H,b)),R=B.height,A.__heightGrow&&(P.grow+=A.__heightGrow,R=0,A.__.heightRange&&(P.hasRangeSize=!0)),A.__widthGrow&&x(A,B,j),P.height+=P.count?R+b:R,P.width=Math.max(P.width,B.width),P.count++):(F(A,X-B.x,Y-B.y),Y+=B.height+b));if(h){const{isAutoXGap:n,isFitXGap:i,contentAlign:h,rowXAlign:u,rowYAlign:f}=r;P.count&&(P.grow&&m(t,P,k,e),d&&w(P,o,k,y),a&&_(G,P,o)),a?(n?w(G,"width",j,i):G.gap=l,function(t,e,o,n){c(t,e,o);const{list:i}=e;if(i.length>1&&(n||(n=s[o]),"from"!==n)){let t;for(let o=0,r=i.length;o<r;o++)t=i[o],t.y=e.height-t.height,"center"===n&&(t.y/=2)}}(t,G,h,f),function(t,e,o,n){const{list:i}=e,r="reverse"===t.__.flowWrap;let h,{x:s,y:c}=e;for(let a=0,l=i.length;a<l;a++)h=i[r?l-1-a:a],v(t,h,s,c,o,n),s+=h.width+e.gap}(t,G,u,e)):(c(t,P,h),v(t,P,P.x,0,u,e))}};return o.UI.changeAttr("autoWidth",void 0,H),o.UI.changeAttr("autoHeight",void 0,H),o.Box.prototype.__updateFlowLayout=function(){this.leafer.created=!1;const{flow:t}=this.__;switch(t){case"x":case!0:Y(this);break;case"y":j(this);break;case"x-reverse":Y(this,!0);break;case"y-reverse":j(this,!0)}this.leafer.created=!0},setTimeout((function(){Object.values(R).some(P)||(Y=()=>{j=Y})})),o.Box.prototype.__updateContentBounds=function(){const{padding:t}=this.__,e=this.__layout,o=e.contentBounds===e.boxBounds;t?(o&&e.shrinkContent(),X(e.contentBounds,e.boxBounds,t,!0)):o||e.shrinkContentCancel()},Object.keys(e).forEach((function(o){"default"===o||Object.prototype.hasOwnProperty.call(t,o)||Object.defineProperty(t,o,{enumerable:!0,get:function(){return e[o]}})})),t}({},LeaferIN.resize,LeaferUI);
1
+ this.LeaferIN=this.LeaferIN||{},this.LeaferIN.flow=function(t,e,o){"use strict";function n(t,e,o,n){var i,r=arguments.length,h=r<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)h=Reflect.decorate(t,e,o,n);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(h=(r<3?i(h):r>3?i(e,o,h):i(e,o))||h);return r>3&&h&&Object.defineProperty(e,o,h),h}"function"==typeof SuppressedError&&SuppressedError;class i extends o.BoxData{}t.Flow=class extends o.Box{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}},n([o.dataProcessor(i)],t.Flow.prototype,"__",void 0),n([o.autoLayoutType("x")],t.Flow.prototype,"flow",void 0),t.Flow=n([o.registerUI()],t.Flow);const r={},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"},s={"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(t,e,n){o.AlignHelper.toPoint(n,e,t.__layout.contentBounds,r);const i=t.__;e.x=i.__autoWidth?0:r.x,e.y=i.__autoHeight?0:r.y}const{move:a}=o.PointHelper;function l(t,e,o,n,i,r){const{children:h}=t;let s,c,{x:l,start:_}=e,u=n;l+=o;for(let t=0,o=e.count;t<o;t++)s=h[r?_-t:_+t],s.__.inFlow&&0!==s.__.visible?(c=s.__flowBounds,"from"!==i&&(u=n+(e.height-c.height)/("center"===i?2:1)),a(s,l-c.x,u-c.y),l+=c.width+e.gap):o++}function _(t,e,o){const n="width"===o?"height":"width";t[o]=Math.max(t[o],e[o]),t[n]+=t.count?e[n]+t.gap:e[n],t.list.push(e),t.count++}const u={};function g(t,e){const{gap:o,flowAlign:n,flowWrap:i,__autoWidth:r,__autoHeight:c}=t.__,a=i&&(e?!r:!c);return"object"==typeof o?(u.xGap=o.x||0,u.yGap=o.y||0):u.xGap=u.yGap=o,u.isAutoXGap="string"==typeof u.xGap&&!r,u.isAutoYGap="string"==typeof u.yGap&&!c,u.complex=a||"top-left"!==n||t.__hasGrow||u.isAutoXGap||u.isAutoYGap,u.wrap=a,u.complex&&(u.isFitXGap="fit"===u.xGap&&!r,u.isFitYGap="fit"===u.yGap&&!c,"object"==typeof n?(u.contentAlign=n.content||"top-left",u.rowXAlign=n.x||"from",u.rowYAlign=n.y||"from"):(u.contentAlign=n,u.rowXAlign=h[n],u.rowYAlign=s[n])),u}function f(t,e){return{x:0,y:0,width:0,height:0,gap:e,start:t,count:0,grow:0}}function w(t,e,o,n){const{count:i}=t;i>1&&(o>t[e]||n)&&(t.gap=(o-t[e])/(i-1),t[e]=o)}function p(t,e){return"box"===e?t.__local:t.__layout.localStrokeBounds}const{within:d}=o.MathHelper;function y(t,e,o,n){let i,r,h,s=0,c=e.hasRangeSize&&[],{grow:a,start:l}=e;const _=e.width<o?(o-e.width)/a:0,{children:u}=t;_&&(e.width=o);for(let t=0,o=e.count;t<o;t++)i=u[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(r=i.__widthGrow)&&(h=x(i,i.__flowBounds,_*r),h?(s+=h,a-=r):c&&(i.__.widthRange?c.unshift(i):c.push(i))):o++;s&&function(t,e,o){let n,i,r,h;t.forEach((t=>{n=t.__widthGrow,i=e/o*n,h=x(t,r=t.__flowBounds,r.width+i),e-=i-h,o-=n}))}(c,s,a)}function x(t,e,o){const{widthRange:n,lockRatio:i}=t.__,r=n?d(o,n.min,n.max):o,h=r/e.width;return t.scaleResize(h,i?h:1),e.width=r,o-r}const{within:G}=o.MathHelper;function m(t,e,o,n){let i,r,h,s=0,c=e.hasRangeSize&&[],{grow:a,start:l}=e;const _=e.height<o?(o-e.height)/a:0,{children:u}=t;_&&(e.height=o);for(let t=0,o=e.count;t<o;t++)i=u[n?l-t:l+t],i.__.inFlow&&0!==i.__.visible?(r=i.__heightGrow)&&(h=b(i,i.__flowBounds,_*r),h?(s+=h,a-=r):c&&(i.__.heightRange?c.unshift(i):c.push(i))):o++;s&&function(t,e,o){let n,i,r,h;t.forEach((t=>{n=t.__heightGrow,i=e/o*n,h=b(t,r=t.__flowBounds,r.height+i),e-=i-h,o-=n}))}(c,s,a)}function b(t,e,o){const{heightRange:n,lockRatio:i}=t.__,r=n?G(o,n.min,n.max):o,h=r/e.height;return t.scaleResize(i?h:1,h),e.height=r,o-r}const{move:A}=o.PointHelper;const{move:B}=o.PointHelper;function v(t,e,o,n,i,r){const{children:h}=t;let s,c,{y:a,start:l}=e,_=o;a+=n;for(let t=0,n=e.count;t<n;t++)s=h[r?l-t:l+t],s.__.inFlow&&0!==s.__.visible?(c=s.__flowBounds,"from"!==i&&(_=o+(e.width-c.width)/("center"===i?2:1)),B(s,_-c.x,a-c.y),a+=c.height+e.gap):n++}const{move:F}=o.PointHelper;function R(t){return o.decorateLeafAttr(t,(t=>o.attr({set(e){const n="number"==typeof e?e:0;"autoWidth"===t?this.__widthGrow=n:this.__heightGrow=n,!n||this.parent&&this.parent.__hasGrow||this.waitParent((()=>{this.parent.__hasGrow=!0})),this.__setAttr(t,e)&&o.doBoundsType(this)}})))}const{copyAndSpread:H}=o.BoundsHelper;let P=function(t,e){const o="width",{children:n,itemBox:i}=t,r=g(t,!0),{complex:s,wrap:a,xGap:u,yGap:d,isAutoXGap:x,isFitXGap:G}=r;if(!n.length)return;const m=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},B=x?0:u;let v,F,R,H,P,{x:X,y:Y,width:k,height:L}=t.__layout.contentBounds;for(let r=0,h=n.length;r<h;r++)v=n[H=e?h-1-r:r],v.__.inFlow&&0!==v.__.visible&&(F=p(v,i),s?(v.__flowBounds=F,P||(P=f(H,B)),a&&P.count&&P.width+F.width>k&&(P.grow?y(t,P,k,e):x&&w(P,o,k,G),_(m,P,o),P=f(H,B)),R=F.width,v.__widthGrow&&(P.grow+=v.__widthGrow,R=0,v.__.widthRange&&(P.hasRangeSize=!0)),v.__heightGrow&&b(v,F,L),P.width+=P.count?R+B:R,P.height=Math.max(P.height,F.height),P.count++):(A(v,X-F.x,Y-F.y),X+=F.width+B));if(s){const{isAutoYGap:n,isFitYGap:i,contentAlign:s,rowXAlign:u,rowYAlign:g}=r;P.count&&(P.grow?y(t,P,k,e):x&&w(P,o,k,G),a&&_(m,P,o)),a?(n?w(m,"height",L,i):m.gap=d,function(t,e,o,n){c(t,e,o);const{list:i}=e;if(i.length>1&&(n||(n=h[o]),"from"!==n)){let t;for(let o=0,r=i.length;o<r;o++)t=i[o],t.x=e.width-t.width,"center"===n&&(t.x/=2)}}(t,m,s,u),function(t,e,o,n){const{list:i}=e,r="reverse"===t.__.flowWrap;let h,{x:s,y:c}=e;for(let a=0,_=i.length;a<_;a++)h=i[r?_-1-a:a],l(t,h,s,c,o,n),c+=h.height+e.gap}(t,m,g,e)):(c(t,P,s),l(t,P,0,P.y,g,e))}},X=function(t,e){const o="height",{children:n,itemBox:i}=t,r=g(t,!1),{complex:h,wrap:a,xGap:l,yGap:u,isAutoYGap:d,isFitYGap:y}=r;if(!n.length)return;const G=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},b=d?0:u;let A,B,R,H,P,{x:X,y:Y,width:k,height:L}=t.__layout.contentBounds;for(let r=0,s=n.length;r<s;r++)A=n[H=e?s-1-r:r],A.__.inFlow&&0!==A.__.visible&&(B=p(A,i),h?(A.__flowBounds=B,P||(P=f(H,b)),a&&P.count&&P.height+B.height>L&&(P.grow&&m(t,P,L,e),d&&w(P,o,L,y),_(G,P,o),P=f(H,b)),R=B.height,A.__heightGrow&&(P.grow+=A.__heightGrow,R=0,A.__.heightRange&&(P.hasRangeSize=!0)),A.__widthGrow&&x(A,B,k),P.height+=P.count?R+b:R,P.width=Math.max(P.width,B.width),P.count++):(F(A,X-B.x,Y-B.y),Y+=B.height+b));if(h){const{isAutoXGap:n,isFitXGap:i,contentAlign:h,rowXAlign:u,rowYAlign:g}=r;P.count&&(P.grow&&m(t,P,L,e),d&&w(P,o,L,y),a&&_(G,P,o)),a?(n?w(G,"width",k,i):G.gap=l,function(t,e,o,n){c(t,e,o);const{list:i}=e;if(i.length>1&&(n||(n=s[o]),"from"!==n)){let t;for(let o=0,r=i.length;o<r;o++)t=i[o],t.y=e.height-t.height,"center"===n&&(t.y/=2)}}(t,G,h,g),function(t,e,o,n){const{list:i}=e,r="reverse"===t.__.flowWrap;let h,{x:s,y:c}=e;for(let a=0,l=i.length;a<l;a++)h=i[r?l-1-a:a],v(t,h,s,c,o,n),s+=h.width+e.gap}(t,G,u,e)):(c(t,P,h),v(t,P,P.x,0,u,e))}};return o.UI.changeAttr("autoWidth",void 0,R),o.UI.changeAttr("autoHeight",void 0,R),o.Box.prototype.__updateFlowLayout=function(){this.leafer.created=!1;const{flow:t}=this.__;switch(t){case"x":case!0:P(this);break;case"y":X(this);break;case"x-reverse":P(this,!0);break;case"y-reverse":X(this,!0)}this.leafer.created=!0},o.Box.prototype.__updateContentBounds=function(){const{padding:t}=this.__,e=this.__layout,o=e.contentBounds===e.boxBounds;t?(o&&e.shrinkContent(),H(e.contentBounds,e.boxBounds,t,!0)):o||e.shrinkContentCancel()},Object.keys(e).forEach((function(o){"default"===o||Object.prototype.hasOwnProperty.call(t,o)||Object.defineProperty(t,o,{enumerable:!0,get:function(){return e[o]}})})),t}({},LeaferIN.resize,LeaferUI);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-in/flow",
3
- "version": "1.0.0-rc.28",
3
+ "version": "1.0.0",
4
4
  "description": "@leafer-in/flow",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -27,9 +27,9 @@
27
27
  "leaferjs"
28
28
  ],
29
29
  "dependencies": {
30
- "@leafer-ui/draw": "1.0.0-rc.28",
31
- "@leafer-ui/interface": "1.0.0-rc.28",
32
- "@leafer-in/resize": "1.0.0-rc.28",
33
- "@leafer-in/interface": "1.0.0-rc.28"
30
+ "@leafer-ui/draw": "1.0.0",
31
+ "@leafer-ui/interface": "1.0.0",
32
+ "@leafer-in/resize": "1.0.0",
33
+ "@leafer-in/interface": "1.0.0"
34
34
  }
35
35
  }
package/types/index.d.ts CHANGED
@@ -5,7 +5,7 @@ import { Box } from '@leafer-ui/draw';
5
5
  declare class Flow extends Box implements IFlow {
6
6
  get __tag(): string;
7
7
  __: IFlowData;
8
- flow: IFlowType;
8
+ flow?: IFlowType;
9
9
  constructor(data?: IFlowInputData);
10
10
  }
11
11