@leafer-in/flow 1.0.0-rc.24

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023-present, Chao (Leafer) Wan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # @leafer-in/flow
package/dist/flow.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var t=require("@leafer-ui/draw");function e(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 o extends t.BoxData{}exports.Flow=class extends t.Box{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}},e([t.dataProcessor(o)],exports.Flow.prototype,"__",void 0),e([t.autoLayoutType("x")],exports.Flow.prototype,"flow",void 0),exports.Flow=e([t.registerUI()],exports.Flow);const n={},i={"top-left":"from",top:"center","top-right":"to",right:"to","bottom-right":"to",bottom:"center","bottom-left":"from",left:"from",center:"center","baseline-left":"from","baseline-center":"center","baseline-right":"to"},r={"top-left":"from",top:"from","top-right":"from",right:"center","bottom-right":"to",bottom:"to","bottom-left":"to",left:"center",center:"center","baseline-left":"to","baseline-center":"to","baseline-right":"to"};function h(e,o,i){t.AlignHelper.toPoint(i,o,e.__layout.contentBounds,n);const r=e.__;o.x=r.__autoWidth?0:n.x,o.y=r.__autoHeight?0:n.y}const{move:s}=t.PointHelper;function c(t,e,o,n,i,r){const{children:h}=t;let c,l,{x:a,start:_}=e,u=n;a+=o;for(let t=0,o=e.count;t<o;t++)c=h[r?_-t:_+t],c.__.inFlow&&0!==c.__.visible?(l=c.__flowBounds,"from"!==i&&(u=n+(e.height-l.height)/("center"===i?2:1)),s(c,a-l.x,u-l.y),a+=l.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 a={};function _(t,e){const{gap:o,flowAlign:n,flowWrap:h,__autoWidth:s,__autoHeight:c}=t.__,l=h&&(e?!s:!c);return"object"==typeof o?(a.xGap=o.x||0,a.yGap=o.y||0):a.xGap=a.yGap=o,a.isAutoXGap="string"==typeof a.xGap&&!s,a.isAutoYGap="string"==typeof a.yGap&&!c,a.complex=l||"top-left"!==n||t.__hasGrow||a.isAutoXGap||a.isAutoYGap,a.wrap=l,a.complex&&(a.isFitXGap="fit"===a.xGap&&!s,a.isFitYGap="fit"===a.yGap&&!c,"object"==typeof n?(a.contentAlign=n.content||"top-left",a.rowXAlign=n.x||"from",a.rowYAlign=n.y||"from"):(a.contentAlign=n,a.rowXAlign=i[n],a.rowYAlign=r[n])),a}function u(t,e){return{x:0,y:0,width:0,height:0,gap:e,start:t,count:0,grow:0}}function g(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:w}=t.MathHelper;function f(t,e,o,n){let i,r,h,s=0,c=e.hasRangeSize&&[],{grow:l,start:a}=e;const _=e.width<o?(o-e.width)/l:0,{children:u}=t;_&&(e.width=o);for(let t=0,o=e.count;t<o;t++)i=u[n?a-t:a+t],i.__.inFlow&&0!==i.__.visible?(r=i.__widthGrow)&&(h=d(i,i.__flowBounds,_*r),h?(s+=h,l-=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=d(t,r=t.__flowBounds,r.width+i),e-=i-h,o-=n}))}(c,s,l)}function d(t,e,o){const{widthRange:n}=t.__,i=n?w(o,n.min,n.max):o;return t.scaleResize(i/e.width,1),e.width=i,o-i}const{within:x}=t.MathHelper;function y(t,e,o,n){let i,r,h,s=0,c=e.hasRangeSize&&[],{grow:l,start:a}=e;const _=e.height<o?(o-e.height)/l:0,{children:u}=t;_&&(e.height=o);for(let t=0,o=e.count;t<o;t++)i=u[n?a-t:a+t],i.__.inFlow&&0!==i.__.visible?(r=i.__heightGrow)&&(h=G(i,i.__flowBounds,_*r),h?(s+=h,l-=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=G(t,r=t.__flowBounds,r.height+i),e-=i-h,o-=n}))}(c,s,l)}function G(t,e,o){const{heightRange:n}=t.__,i=n?x(o,n.min,n.max):o;return t.scaleResize(1,i/e.height),e.height=i,o-i}const{move:m}=t.PointHelper;const{move:b}=t.PointHelper;function A(t,e,o,n,i,r){const{children:h}=t;let s,c,{y:l,start:a}=e,_=o;l+=n;for(let t=0,n=e.count;t<n;t++)s=h[r?a-t:a+t],s.__.inFlow&&0!==s.__.visible?(c=s.__flowBounds,"from"!==i&&(_=o+(e.width-c.width)/("center"===i?2:1)),b(s,_-c.x,l-c.y),l+=c.height+e.gap):n++}const{move:B}=t.PointHelper;const v=t.inviteCode;function F(e){return t.decorateLeafAttr(e,(e=>t.attr({set(o){const n="number"==typeof o?o:0;"autoWidth"===e?this.__widthGrow=n:this.__heightGrow=n,!n||this.parent&&this.parent.__hasGrow||this.waitParent((()=>{this.parent.__hasGrow=!0})),this.__setAttr(e,o)&&t.doBoundsType(this)}})))}function R(t){return t.length>6&&"e"===t[6]}const{copyAndSpread:H}=t.BoundsHelper;let X=function(t,e){const o="width",{children:n,itemBox:r}=t,s=_(t,!0),{complex:a,wrap:w,xGap:d,yGap:x,isAutoXGap:y,isFitXGap:b}=s;if(!n.length)return;const A=w&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},B=y?0:d;let v,F,R,H,X,{x:Y,y:P,width:S,height:W}=t.__layout.contentBounds;for(let i=0,h=n.length;i<h;i++)v=n[H=e?h-1-i:i],v.__.inFlow&&0!==v.__.visible&&(F=p(v,r),a?(v.__flowBounds=F,X||(X=u(H,B)),w&&X.count&&X.width+F.width>S&&(X.grow?f(t,X,S,e):y&&g(X,o,S,b),l(A,X,o),X=u(H,B)),R=F.width,v.__widthGrow&&(X.grow+=v.__widthGrow,R=0,v.__.widthRange&&(X.hasRangeSize=!0)),v.__heightGrow&&G(v,F,W),X.width+=X.count?R+B:R,X.height=Math.max(X.height,F.height),X.count++):(m(v,Y-F.x,P-F.y),Y+=F.width+B));if(a){const{isAutoYGap:n,isFitYGap:r,contentAlign:a,rowXAlign:_,rowYAlign:u}=s;X.count&&(X.grow?f(t,X,S,e):y&&g(X,o,S,b),w&&l(A,X,o)),w?(n?g(A,"height",W,r):A.gap=x,function(t,e,o,n){h(t,e,o);const{list:r}=e;if(r.length>1&&(n||(n=i[o]),"from"!==n)){let t;for(let o=0,i=r.length;o<i;o++)t=r[o],t.x=e.width-t.width,"center"===n&&(t.x/=2)}}(t,A,a,_),function(t,e,o,n){const{list:i}=e,r="reverse"===t.__.flowWrap;let h,{x:s,y:l}=e;for(let a=0,_=i.length;a<_;a++)h=i[r?_-1-a:a],c(t,h,s,l,o,n),l+=h.height+e.gap}(t,A,u,e)):(h(t,X,a),c(t,X,0,X.y,u,e))}},Y=function(t,e){const o="height",{children:n,itemBox:i}=t,s=_(t,!1),{complex:c,wrap:a,xGap:w,yGap:f,isAutoYGap:x,isFitYGap:G}=s;if(!n.length)return;const m=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},b=x?0:f;let v,F,R,H,X,{x:Y,y:P,width:S,height:W}=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),c?(v.__flowBounds=F,X||(X=u(H,b)),a&&X.count&&X.height+F.height>W&&(X.grow&&y(t,X,W,e),x&&g(X,o,W,G),l(m,X,o),X=u(H,b)),R=F.height,v.__heightGrow&&(X.grow+=v.__heightGrow,R=0,v.__.heightRange&&(X.hasRangeSize=!0)),v.__widthGrow&&d(v,F,S),X.height+=X.count?R+b:R,X.width=Math.max(X.width,F.width),X.count++):(B(v,Y-F.x,P-F.y),P+=F.height+b));if(c){const{isAutoXGap:n,isFitXGap:i,contentAlign:c,rowXAlign:_,rowYAlign:u}=s;X.count&&(X.grow&&y(t,X,W,e),x&&g(X,o,W,G),a&&l(m,X,o)),a?(n?g(m,"width",S,i):m.gap=w,function(t,e,o,n){h(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.y=e.height-t.height,"center"===n&&(t.y/=2)}}(t,m,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,a=i.length;l<a;l++)h=i[r?a-1-l:l],A(t,h,s,c,o,n),s+=h.width+e.gap}(t,m,_,e)):(h(t,X,c),A(t,X,X.x,0,_,e))}};t.UI.changeAttr("autoWidth",void 0,F),t.UI.changeAttr("autoHeight",void 0,F),t.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(v).some(R)||(X=()=>{Y=X})})),t.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()};
@@ -0,0 +1 @@
1
+ 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=S(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=S(t,h=t.__flowBounds,h.width+i),o-=i-r,e-=n}))}(c,s,a)}function S(t,o,e){const{widthRange:n}=t.__,i=n?X(e,n.min,n.max):e;return t.scaleResize(i/o.width,1),o.width=i,e-i}const{within:W}=s;function j(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=k(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=k(t,h=t.__flowBounds,h.height+i),o-=i-r,e-=n}))}(c,s,a)}function k(t,o,e){const{heightRange:n}=t.__,i=n?W(e,n.min,n.max):e;return t.scaleResize(1,i/o.height),o.height=i,e-i}const{move:z}=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:S,height:W}=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>S&&(m.grow?Y(t,m,S,o):l&&R(m,e,S,_),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&&k(f,w,W),m.width+=m.count?p+u:p,m.height=Math.max(m.height,w.height),m.count++):(z(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,S,o):l&&R(m,e,S,_),s&&b(g,m,e)),s?(n?R(g,"height",W,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&&j(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&&S(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&&j(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};
@@ -0,0 +1 @@
1
+ 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=S(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=S(t,h=t.__flowBounds,h.width+i),o-=i-r,e-=n}))}(c,s,a)}function S(t,o,e){const{widthRange:n}=t.__,i=n?X(e,n.min,n.max):e;return t.scaleResize(i/o.width,1),o.width=i,e-i}const{within:W}=s;function j(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=k(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=k(t,h=t.__flowBounds,h.height+i),o-=i-r,e-=n}))}(c,s,a)}function k(t,o,e){const{heightRange:n}=t.__,i=n?W(e,n.min,n.max):e;return t.scaleResize(1,i/o.height),o.height=i,e-i}const{move:z}=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:S,height:W}=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>S&&(m.grow?Y(t,m,S,o):l&&R(m,e,S,_),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&&k(f,w,W),m.width+=m.count?p+u:p,m.height=Math.max(m.height,w.height),m.count++):(z(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,S,o):l&&R(m,e,S,_),s&&b(g,m,e)),s?(n?R(g,"height",W,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&&j(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&&S(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&&j(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};
package/dist/flow.js ADDED
@@ -0,0 +1 @@
1
+ this.LeaferIN=this.LeaferIN||{},this.LeaferIN.flow=function(t,e){"use strict";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{}t.Flow=class extends e.Box{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}},o([e.dataProcessor(n)],t.Flow.prototype,"__",void 0),o([e.autoLayoutType("x")],t.Flow.prototype,"flow",void 0),t.Flow=o([e.registerUI()],t.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 f(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 w(t,e){return"box"===e?t.__local:t.__layout.localStrokeBounds}const{within:p}=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}=t.__,i=n?p(o,n.min,n.max):o;return t.scaleResize(i/e.width,1),e.width=i,o-i}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}=t.__,i=n?x(o,n.min,n.max):o;return t.scaleResize(1,i/e.height),e.height=i,o-i}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:X}=e.BoundsHelper;let Y=function(t,e){const o="width",{children:n,itemBox:i}=t,h=u(t,!0),{complex:c,wrap:_,xGap:p,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:p;let v,F,R,H,X,{x:Y,y:P,width:L,height:S}=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=w(v,i),c?(v.__flowBounds=F,X||(X=g(H,B)),_&&X.count&&X.width+F.width>L&&(X.grow?d(t,X,L,e):x&&f(X,o,L,G),l(A,X,o),X=g(H,B)),R=F.width,v.__widthGrow&&(X.grow+=v.__widthGrow,R=0,v.__.widthRange&&(X.hasRangeSize=!0)),v.__heightGrow&&m(v,F,S),X.width+=X.count?R+B:R,X.height=Math.max(X.height,F.height),X.count++):(b(v,Y-F.x,P-F.y),Y+=F.width+B));if(c){const{isAutoYGap:n,isFitYGap:i,contentAlign:c,rowXAlign:u,rowYAlign:g}=h;X.count&&(X.grow?d(t,X,L,e):x&&f(X,o,L,G),_&&l(A,X,o)),_?(n?f(A,"height",S,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,X,c),a(t,X,0,X.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:p,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:p;let A,F,R,H,X,{x:Y,y:P,width:L,height:S}=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=w(A,i),c?(A.__flowBounds=F,X||(X=g(H,b)),a&&X.count&&X.height+F.height>S&&(X.grow&&G(t,X,S,e),d&&f(X,o,S,x),l(m,X,o),X=g(H,b)),R=F.height,A.__heightGrow&&(X.grow+=A.__heightGrow,R=0,A.__.heightRange&&(X.hasRangeSize=!0)),A.__widthGrow&&y(A,F,L),X.height+=X.count?R+b:R,X.width=Math.max(X.width,F.width),X.count++):(v(A,Y-F.x,P-F.y),P+=F.height+b));if(c){const{isAutoXGap:n,isFitXGap:i,contentAlign:c,rowXAlign:u,rowYAlign:g}=r;X.count&&(X.grow&&G(t,X,S,e),d&&f(X,o,S,x),a&&l(m,X,o)),a?(n?f(m,"width",L,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,X,c),B(t,X,X.x,0,u,e))}};return 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:Y(this);break;case"y":P(this);break;case"x-reverse":Y(this,!0);break;case"y-reverse":P(this,!0)}this.leafer.created=!0},setTimeout((function(){Object.values(F).some(H)||(Y=()=>{P=Y})})),e.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()},t}({},LeaferUI);
@@ -0,0 +1 @@
1
+ "use strict";var t=require("@leafer-ui/draw");function e(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 o extends t.BoxData{}exports.Flow=class extends t.Box{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}},e([t.dataProcessor(o)],exports.Flow.prototype,"__",void 0),e([t.autoLayoutType("x")],exports.Flow.prototype,"flow",void 0),exports.Flow=e([t.registerUI()],exports.Flow);const n={},i={"top-left":"from",top:"center","top-right":"to",right:"to","bottom-right":"to",bottom:"center","bottom-left":"from",left:"from",center:"center","baseline-left":"from","baseline-center":"center","baseline-right":"to"},r={"top-left":"from",top:"from","top-right":"from",right:"center","bottom-right":"to",bottom:"to","bottom-left":"to",left:"center",center:"center","baseline-left":"to","baseline-center":"to","baseline-right":"to"};function h(e,o,i){t.AlignHelper.toPoint(i,o,e.__layout.contentBounds,n);const r=e.__;o.x=r.__autoWidth?0:n.x,o.y=r.__autoHeight?0:n.y}const{move:s}=t.PointHelper;function c(t,e,o,n,i,r){const{children:h}=t;let c,l,{x:a,start:_}=e,u=n;a+=o;for(let t=0,o=e.count;t<o;t++)c=h[r?_-t:_+t],c.__.inFlow&&0!==c.__.visible?(l=c.__flowBounds,"from"!==i&&(u=n+(e.height-l.height)/("center"===i?2:1)),s(c,a-l.x,u-l.y),a+=l.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 a={};function _(t,e){const{gap:o,flowAlign:n,flowWrap:h,__autoWidth:s,__autoHeight:c}=t.__,l=h&&(e?!s:!c);return"object"==typeof o?(a.xGap=o.x||0,a.yGap=o.y||0):a.xGap=a.yGap=o,a.isAutoXGap="string"==typeof a.xGap&&!s,a.isAutoYGap="string"==typeof a.yGap&&!c,a.complex=l||"top-left"!==n||t.__hasGrow||a.isAutoXGap||a.isAutoYGap,a.wrap=l,a.complex&&(a.isFitXGap="fit"===a.xGap&&!s,a.isFitYGap="fit"===a.yGap&&!c,"object"==typeof n?(a.contentAlign=n.content||"top-left",a.rowXAlign=n.x||"from",a.rowYAlign=n.y||"from"):(a.contentAlign=n,a.rowXAlign=i[n],a.rowYAlign=r[n])),a}function u(t,e){return{x:0,y:0,width:0,height:0,gap:e,start:t,count:0,grow:0}}function g(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:w}=t.MathHelper;function f(t,e,o,n){let i,r,h,s=0,c=e.hasRangeSize&&[],{grow:l,start:a}=e;const _=e.width<o?(o-e.width)/l:0,{children:u}=t;_&&(e.width=o);for(let t=0,o=e.count;t<o;t++)i=u[n?a-t:a+t],i.__.inFlow&&0!==i.__.visible?(r=i.__widthGrow)&&(h=d(i,i.__flowBounds,_*r),h?(s+=h,l-=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=d(t,r=t.__flowBounds,r.width+i),e-=i-h,o-=n}))}(c,s,l)}function d(t,e,o){const{widthRange:n}=t.__,i=n?w(o,n.min,n.max):o;return t.scaleResize(i/e.width,1),e.width=i,o-i}const{within:x}=t.MathHelper;function y(t,e,o,n){let i,r,h,s=0,c=e.hasRangeSize&&[],{grow:l,start:a}=e;const _=e.height<o?(o-e.height)/l:0,{children:u}=t;_&&(e.height=o);for(let t=0,o=e.count;t<o;t++)i=u[n?a-t:a+t],i.__.inFlow&&0!==i.__.visible?(r=i.__heightGrow)&&(h=G(i,i.__flowBounds,_*r),h?(s+=h,l-=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=G(t,r=t.__flowBounds,r.height+i),e-=i-h,o-=n}))}(c,s,l)}function G(t,e,o){const{heightRange:n}=t.__,i=n?x(o,n.min,n.max):o;return t.scaleResize(1,i/e.height),e.height=i,o-i}const{move:m}=t.PointHelper;const{move:b}=t.PointHelper;function A(t,e,o,n,i,r){const{children:h}=t;let s,c,{y:l,start:a}=e,_=o;l+=n;for(let t=0,n=e.count;t<n;t++)s=h[r?a-t:a+t],s.__.inFlow&&0!==s.__.visible?(c=s.__flowBounds,"from"!==i&&(_=o+(e.width-c.width)/("center"===i?2:1)),b(s,_-c.x,l-c.y),l+=c.height+e.gap):n++}const{move:B}=t.PointHelper;const v=t.inviteCode;function F(e){return t.decorateLeafAttr(e,(e=>t.attr({set(o){const n="number"==typeof o?o:0;"autoWidth"===e?this.__widthGrow=n:this.__heightGrow=n,!n||this.parent&&this.parent.__hasGrow||this.waitParent((()=>{this.parent.__hasGrow=!0})),this.__setAttr(e,o)&&t.doBoundsType(this)}})))}function R(t){return t.length>6&&"e"===t[6]}const{copyAndSpread:H}=t.BoundsHelper;let X=function(t,e){const o="width",{children:n,itemBox:r}=t,s=_(t,!0),{complex:a,wrap:w,xGap:d,yGap:x,isAutoXGap:y,isFitXGap:b}=s;if(!n.length)return;const A=w&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},B=y?0:d;let v,F,R,H,X,{x:Y,y:P,width:S,height:W}=t.__layout.contentBounds;for(let i=0,h=n.length;i<h;i++)v=n[H=e?h-1-i:i],v.__.inFlow&&0!==v.__.visible&&(F=p(v,r),a?(v.__flowBounds=F,X||(X=u(H,B)),w&&X.count&&X.width+F.width>S&&(X.grow?f(t,X,S,e):y&&g(X,o,S,b),l(A,X,o),X=u(H,B)),R=F.width,v.__widthGrow&&(X.grow+=v.__widthGrow,R=0,v.__.widthRange&&(X.hasRangeSize=!0)),v.__heightGrow&&G(v,F,W),X.width+=X.count?R+B:R,X.height=Math.max(X.height,F.height),X.count++):(m(v,Y-F.x,P-F.y),Y+=F.width+B));if(a){const{isAutoYGap:n,isFitYGap:r,contentAlign:a,rowXAlign:_,rowYAlign:u}=s;X.count&&(X.grow?f(t,X,S,e):y&&g(X,o,S,b),w&&l(A,X,o)),w?(n?g(A,"height",W,r):A.gap=x,function(t,e,o,n){h(t,e,o);const{list:r}=e;if(r.length>1&&(n||(n=i[o]),"from"!==n)){let t;for(let o=0,i=r.length;o<i;o++)t=r[o],t.x=e.width-t.width,"center"===n&&(t.x/=2)}}(t,A,a,_),function(t,e,o,n){const{list:i}=e,r="reverse"===t.__.flowWrap;let h,{x:s,y:l}=e;for(let a=0,_=i.length;a<_;a++)h=i[r?_-1-a:a],c(t,h,s,l,o,n),l+=h.height+e.gap}(t,A,u,e)):(h(t,X,a),c(t,X,0,X.y,u,e))}},Y=function(t,e){const o="height",{children:n,itemBox:i}=t,s=_(t,!1),{complex:c,wrap:a,xGap:w,yGap:f,isAutoYGap:x,isFitYGap:G}=s;if(!n.length)return;const m=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},b=x?0:f;let v,F,R,H,X,{x:Y,y:P,width:S,height:W}=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),c?(v.__flowBounds=F,X||(X=u(H,b)),a&&X.count&&X.height+F.height>W&&(X.grow&&y(t,X,W,e),x&&g(X,o,W,G),l(m,X,o),X=u(H,b)),R=F.height,v.__heightGrow&&(X.grow+=v.__heightGrow,R=0,v.__.heightRange&&(X.hasRangeSize=!0)),v.__widthGrow&&d(v,F,S),X.height+=X.count?R+b:R,X.width=Math.max(X.width,F.width),X.count++):(B(v,Y-F.x,P-F.y),P+=F.height+b));if(c){const{isAutoXGap:n,isFitXGap:i,contentAlign:c,rowXAlign:_,rowYAlign:u}=s;X.count&&(X.grow&&y(t,X,W,e),x&&g(X,o,W,G),a&&l(m,X,o)),a?(n?g(m,"width",S,i):m.gap=w,function(t,e,o,n){h(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.y=e.height-t.height,"center"===n&&(t.y/=2)}}(t,m,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,a=i.length;l<a;l++)h=i[r?a-1-l:l],A(t,h,s,c,o,n),s+=h.width+e.gap}(t,m,_,e)):(h(t,X,c),A(t,X,X.x,0,_,e))}};t.UI.changeAttr("autoWidth",void 0,F),t.UI.changeAttr("autoHeight",void 0,F),t.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(v).some(R)||(X=()=>{Y=X})})),t.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()};
@@ -0,0 +1 @@
1
+ this.LeaferIN=this.LeaferIN||{},this.LeaferIN.flow=function(t,e){"use strict";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{}t.Flow=class extends e.Box{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}},o([e.dataProcessor(n)],t.Flow.prototype,"__",void 0),o([e.autoLayoutType("x")],t.Flow.prototype,"flow",void 0),t.Flow=o([e.registerUI()],t.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 f(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 w(t,e){return"box"===e?t.__local:t.__layout.localStrokeBounds}const{within:p}=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}=t.__,i=n?p(o,n.min,n.max):o;return t.scaleResize(i/e.width,1),e.width=i,o-i}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}=t.__,i=n?x(o,n.min,n.max):o;return t.scaleResize(1,i/e.height),e.height=i,o-i}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:X}=e.BoundsHelper;let Y=function(t,e){const o="width",{children:n,itemBox:i}=t,h=u(t,!0),{complex:c,wrap:_,xGap:p,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:p;let v,F,R,H,X,{x:Y,y:P,width:L,height:S}=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=w(v,i),c?(v.__flowBounds=F,X||(X=g(H,B)),_&&X.count&&X.width+F.width>L&&(X.grow?d(t,X,L,e):x&&f(X,o,L,G),l(A,X,o),X=g(H,B)),R=F.width,v.__widthGrow&&(X.grow+=v.__widthGrow,R=0,v.__.widthRange&&(X.hasRangeSize=!0)),v.__heightGrow&&m(v,F,S),X.width+=X.count?R+B:R,X.height=Math.max(X.height,F.height),X.count++):(b(v,Y-F.x,P-F.y),Y+=F.width+B));if(c){const{isAutoYGap:n,isFitYGap:i,contentAlign:c,rowXAlign:u,rowYAlign:g}=h;X.count&&(X.grow?d(t,X,L,e):x&&f(X,o,L,G),_&&l(A,X,o)),_?(n?f(A,"height",S,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,X,c),a(t,X,0,X.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:p,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:p;let A,F,R,H,X,{x:Y,y:P,width:L,height:S}=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=w(A,i),c?(A.__flowBounds=F,X||(X=g(H,b)),a&&X.count&&X.height+F.height>S&&(X.grow&&G(t,X,S,e),d&&f(X,o,S,x),l(m,X,o),X=g(H,b)),R=F.height,A.__heightGrow&&(X.grow+=A.__heightGrow,R=0,A.__.heightRange&&(X.hasRangeSize=!0)),A.__widthGrow&&y(A,F,L),X.height+=X.count?R+b:R,X.width=Math.max(X.width,F.width),X.count++):(v(A,Y-F.x,P-F.y),P+=F.height+b));if(c){const{isAutoXGap:n,isFitXGap:i,contentAlign:c,rowXAlign:u,rowYAlign:g}=r;X.count&&(X.grow&&G(t,X,S,e),d&&f(X,o,S,x),a&&l(m,X,o)),a?(n?f(m,"width",L,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,X,c),B(t,X,X.x,0,u,e))}};return 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:Y(this);break;case"y":P(this);break;case"x-reverse":Y(this,!0);break;case"y-reverse":P(this,!0)}this.leafer.created=!0},setTimeout((function(){Object.values(F).some(H)||(Y=()=>{P=Y})})),e.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()},t}({},LeaferUI);
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@leafer-in/flow",
3
+ "version": "1.0.0-rc.24",
4
+ "description": "@leafer-in/flow",
5
+ "author": "Chao (Leafer) Wan",
6
+ "license": "MIT",
7
+ "main": "dist/flow.esm.js",
8
+ "unpkg": "dist/flow.js",
9
+ "jsdelivr": "dist/flow.js",
10
+ "types": "types/index.d.ts",
11
+ "files": ["types","dist"],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/leaferjs/in.git"
15
+ },
16
+ "homepage": "https://github.com/leaferjs/in/tree/main/packages/flow",
17
+ "bugs": "https://github.com/leaferjs/in/issues",
18
+ "keywords": [
19
+ "leafer flow",
20
+ "leafer-flow",
21
+ "leafer-in",
22
+ "flow",
23
+ "leafer-ui",
24
+ "leaferjs"
25
+ ],
26
+ "dependencies": {
27
+ "@leafer-ui/draw": "1.0.0-rc.24",
28
+ "@leafer-ui/interface": "1.0.0-rc.24",
29
+ "@leafer-in/interface": "1.0.0-rc.24"
30
+ }
31
+ }
@@ -0,0 +1,11 @@
1
+ import { IFlow, IFlowData, IFlowType, IFlowInputData } from '@leafer-ui/interface';
2
+ import { Box } from '@leafer-ui/draw';
3
+
4
+ declare class Flow extends Box implements IFlow {
5
+ get __tag(): string;
6
+ __: IFlowData;
7
+ flow: IFlowType;
8
+ constructor(data?: IFlowInputData);
9
+ }
10
+
11
+ export { Flow };