2 lines
15 KiB
JavaScript
2 lines
15 KiB
JavaScript
!function(a,b){"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?module.exports=b():a.computeLayout=b()}(this,function(){var a=function(){function a(b){if((!b.layout||b.isDirty)&&(b.layout={width:void 0,height:void 0,top:0,left:0,right:0,bottom:0}),b.style||(b.style={}),b.children||(b.children=[]),b.style.measure&&b.children&&b.children.length)throw new Error("Using custom measure function is supported only for leaf nodes.");return b.children.forEach(a),b}function b(a){return void 0===a||Number.isNaN(a)}function c(a){return a===da||a===ea}function d(a){return a===fa||a===ga}function e(a){return void 0===a.style.flex?0:a.style.flex}function f(a){return W?!0:e(a)<=0}function g(a){return e(a)>0?e(a):0}function h(a){if(W){if(0!==e(a))return 1}else if(e(a)<0)return 1;return 0}function i(a,b){if(void 0!==a.style.marginStart&&c(b))return a.style.marginStart;var d=null;switch(b){case"row":d=a.style.marginLeft;break;case"row-reverse":d=a.style.marginRight;break;case"column":d=a.style.marginTop;break;case"column-reverse":d=a.style.marginBottom}return void 0!==d?d:void 0!==a.style.margin?a.style.margin:0}function j(a,b){if(void 0!==a.style.marginEnd&&c(b))return a.style.marginEnd;var d=null;switch(b){case"row":d=a.style.marginRight;break;case"row-reverse":d=a.style.marginLeft;break;case"column":d=a.style.marginBottom;break;case"column-reverse":d=a.style.marginTop}return null!=d?d:void 0!==a.style.margin?a.style.margin:0}function k(a,b){if(void 0!==a.style.paddingStart&&a.style.paddingStart>=0&&c(b))return a.style.paddingStart;var d=null;switch(b){case"row":d=a.style.paddingLeft;break;case"row-reverse":d=a.style.paddingRight;break;case"column":d=a.style.paddingTop;break;case"column-reverse":d=a.style.paddingBottom}return null!=d&&d>=0?d:void 0!==a.style.padding&&a.style.padding>=0?a.style.padding:0}function l(a,b){if(void 0!==a.style.paddingEnd&&a.style.paddingEnd>=0&&c(b))return a.style.paddingEnd;var d=null;switch(b){case"row":d=a.style.paddingRight;break;case"row-reverse":d=a.style.paddingLeft;break;case"column":d=a.style.paddingBottom;break;case"column-reverse":d=a.style.paddingTop}return null!=d&&d>=0?d:void 0!==a.style.padding&&a.style.padding>=0?a.style.padding:0}function m(a,b){if(void 0!==a.style.borderStartWidth&&a.style.borderStartWidth>=0&&c(b))return a.style.borderStartWidth;var d=null;switch(b){case"row":d=a.style.borderLeftWidth;break;case"row-reverse":d=a.style.borderRightWidth;break;case"column":d=a.style.borderTopWidth;break;case"column-reverse":d=a.style.borderBottomWidth}return null!=d&&d>=0?d:void 0!==a.style.borderWidth&&a.style.borderWidth>=0?a.style.borderWidth:0}function n(a,b){if(void 0!==a.style.borderEndWidth&&a.style.borderEndWidth>=0&&c(b))return a.style.borderEndWidth;var d=null;switch(b){case"row":d=a.style.borderRightWidth;break;case"row-reverse":d=a.style.borderLeftWidth;break;case"column":d=a.style.borderBottomWidth;break;case"column-reverse":d=a.style.borderTopWidth}return null!=d&&d>=0?d:void 0!==a.style.borderWidth&&a.style.borderWidth>=0?a.style.borderWidth:0}function o(a,b){return k(a,b)+m(a,b)}function p(a,b){return l(a,b)+n(a,b)}function q(a,b){return i(a,b)+j(a,b)}function r(a,b){return o(a,b)+p(a,b)}function s(a){return a.style.justifyContent?a.style.justifyContent:"flex-start"}function t(a){return a.style.alignContent?a.style.alignContent:"flex-start"}function u(a,b){return b.style.alignSelf?b.style.alignSelf:a.style.alignItems?a.style.alignItems:"stretch"}function v(a,b){if(b===ca){if(a===da)return ea;if(a===ea)return da}return a}function w(a,b){var c;return c=a.style.direction?a.style.direction:aa,c===aa&&(c=void 0===b?ba:b),c}function x(a){return a.style.flexDirection?a.style.flexDirection:fa}function y(a,b){return d(a)?v(da,b):fa}function z(a){return a.style.position?a.style.position:qa}function A(a){return a.style.overflow?a.style.overflow:sa}function B(a){return z(a)===qa&&void 0!==a.style.flex&&0!==a.style.flex}function C(a){return"wrap"===a.style.flexWrap}function D(a,b){return a.layout[Ba[b]]+q(a,b)}function E(a,b){return void 0!==a.style[Aa[b]]&&a.style[Aa[b]]>=0}function F(a,b){return void 0!==a.layout[Ba[b]]&&a.layout[Ba[b]]>=0}function G(a,b){return void 0!==a.style[b]}function H(a){return void 0!==a.style.measure}function I(a,b){return void 0!==a.style[b]?a.style[b]:0}function J(a,b,c){var d={row:a.style.minWidth,"row-reverse":a.style.minWidth,column:a.style.minHeight,"column-reverse":a.style.minHeight}[b],e={row:a.style.maxWidth,"row-reverse":a.style.maxWidth,column:a.style.maxHeight,"column-reverse":a.style.maxHeight}[b],f=c;return void 0!==e&&e>=0&&f>e&&(f=e),void 0!==d&&d>=0&&d>f&&(f=d),f}function K(a,b){return b>a?a:b}function L(a,b){return a>b?a:b}function M(a,b,c){return L(J(a,b,c),r(a,b))}function N(a,b,c){var d=z(b)===ra?0:b.layout[Ba[c]];b.layout[ya[c]]=a.layout[Ba[c]]-d-b.layout[za[c]]}function O(a,b){return void 0!==a.style[xa[b]]?I(a,xa[b]):-I(a,ya[b])}function P(a,b){var c=v(x(a),b),d=y(c,b);a.layout[xa[c]]=i(a,c)+O(a,c),a.layout[ya[c]]=j(a,c)+O(a,c),a.layout[xa[d]]=i(a,d)+O(a,d),a.layout[ya[d]]=j(a,d)+O(a,d)}function Q(a,b){if(!a)throw new Error(b)}function R(a,d,e,k,l,O,R){Q(b(d)?l===ua:!0,"availableWidth is indefinite so widthMeasureMode must be CSS_MEASURE_MODE_UNDEFINED"),Q(b(e)?O===ua:!0,"availableHeight is indefinite so heightMeasureMode must be CSS_MEASURE_MODE_UNDEFINED");var S=r(a,da),U=r(a,fa),W=q(a,da),X=q(a,fa),aa=w(a,k);if(a.layout.direction=aa,H(a)){var ba=d-W-S,ca=e-X-U;if(l===va&&O===va)a.layout.measuredWidth=M(a,da,d-W),a.layout.measuredHeight=M(a,fa,e-X);else if(0>=ba||0>=ca)a.layout.measuredWidth=M(a,da,0),a.layout.measuredHeight=M(a,fa,0);else{var sa=a.style.measure(ba,l,ca,O);a.layout.measuredWidth=M(a,da,l===ua||l===wa?sa.width+S:d-W),a.layout.measuredHeight=M(a,fa,O===ua||O===wa?sa.height+U:e-X)}}else{var Aa=a.children.length;if(0===Aa)return a.layout.measuredWidth=M(a,da,l===ua||l===wa?S:d-W),void(a.layout.measuredHeight=M(a,fa,O===ua||O===wa?U:e-X));if(!R){if(l===wa&&0>=d&&O===wa&&0>=e)return a.layout.measuredWidth=M(a,da,0),void(a.layout.measuredHeight=M(a,fa,0));if(l===wa&&0>=d)return a.layout.measuredWidth=M(a,da,0),void(a.layout.measuredHeight=M(a,fa,b(e)?0:e-X));if(O===wa&&0>=e)return a.layout.measuredWidth=M(a,da,b(d)?0:d-W),void(a.layout.measuredHeight=M(a,fa,0));if(l===va&&O===va)return a.layout.measuredWidth=M(a,da,d-W),void(a.layout.measuredHeight=M(a,fa,e-X))}var Ca,Da,Ea,Fa,Ga,Ha,Ia=v(x(a),aa),Ja=y(Ia,aa),Ka=c(Ia),La=s(a),Ma=C(a),Na=void 0,Oa=void 0,Pa=o(a,Ia),Qa=p(a,Ia),Ra=o(a,Ja),Sa=r(a,Ia),Ta=r(a,Ja),Ua=Ka?l:O,Va=Ka?O:l,Wa=d-W-S,Xa=e-X-U,Ya=Ka?Wa:Xa,Za=Ka?Xa:Wa;for(Da=0;Aa>Da;Da++){if(Ca=a.children[Da],R){var $a=w(Ca,aa);P(Ca,$a)}z(Ca)===ra?(void 0===Na&&(Na=Ca),void 0!==Oa&&(Oa.nextChild=Ca),Oa=Ca,Ca.nextChild=void 0):Ka&&E(Ca,da)?Ca.layout.flexBasis=L(Ca.style.width,r(Ca,da)):!Ka&&E(Ca,fa)?Ca.layout.flexBasis=L(Ca.style.height,r(Ca,fa)):f(Ca)||b(Ya)?(Ea=V,Fa=V,Ga=ua,Ha=ua,E(Ca,da)&&(Ea=Ca.style.width+q(Ca,da),Ga=va),E(Ca,fa)&&(Fa=Ca.style.height+q(Ca,fa),Ha=va),Ka||!b(Ea)||b(Wa)||(Ea=Wa,Ga=wa),A(a)===ta&&Ka&&b(Fa)&&!b(Xa)&&(Fa=Xa,Ha=wa),Ka||b(Wa)||E(Ca,da)||l!=va||u(a,Ca)!=pa||(Ea=Wa,Ga=va),!Ka||b(Xa)||E(Ca,fa)||O!=va||u(a,Ca)!=pa||(Fa=Xa,Ha=va),T(Ca,Ea,Fa,aa,Ga,Ha,!1,"measure"),Ca.layout.flexBasis=L(Ka?Ca.layout.measuredWidth:Ca.layout.measuredHeight,r(Ca,Ia))):Ca.layout.flexBasis=L(0,r(Ca,Ia))}for(var _a=0,ab=0,bb=0,cb=0,db=0;Aa>ab;){var eb=0,fb=0,gb=0,hb=0;Da=_a;for(var ib=void 0,jb=void 0;Aa>Da;){if(Ca=a.children[Da],Ca.lineIndex=bb,z(Ca)!==ra){var kb=Ca.layout.flexBasis+q(Ca,Ia);if(fb+kb>Ya&&Ma&&eb>0)break;fb+=kb,eb++,B(Ca)&&(gb+=g(Ca),hb+=h(Ca)*Ca.layout.flexBasis),void 0===ib&&(ib=Ca),void 0!==jb&&(jb.nextChild=Ca),jb=Ca,Ca.nextChild=void 0}Da++,ab++}var lb=!R&&Va===va,mb=0,nb=0,ob=0;b(Ya)?0>fb&&(ob=-fb):ob=Ya-fb;var pb=ob,qb=0;if(!lb){var rb,sb,tb,ub,vb,wb=0,xb=0;for(jb=ib;void 0!==jb;)rb=jb.layout.flexBasis,0>ob?(sb=h(jb)*rb,0!==sb&&(ub=rb+ob/hb*sb,vb=M(jb,Ia,ub),ub!==vb&&(qb-=vb-rb,wb-=sb))):ob>0&&(tb=g(jb),0!==tb&&(ub=rb+ob/gb*tb,vb=M(jb,Ia,ub),ub!==vb&&(qb-=vb-rb,xb-=tb))),jb=jb.nextChild;for(hb+=wb,gb+=xb,ob+=qb,qb=0,jb=ib;void 0!==jb;){rb=jb.layout.flexBasis;var yb=rb;0>ob?(sb=h(jb)*rb,0!==sb&&(yb=M(jb,Ia,rb+ob/hb*sb))):ob>0&&(tb=g(jb),0!==tb&&(yb=M(jb,Ia,rb+ob/gb*tb))),qb-=yb-rb,Ka?(Ea=yb+q(jb,da),Ga=va,b(Za)||E(jb,fa)||O!=va||u(a,jb)!=pa?E(jb,fa)?(Fa=jb.style.height+q(jb,fa),Ha=va):(Fa=Za,Ha=b(Fa)?ua:wa):(Fa=Za,Ha=va)):(Fa=yb+q(jb,fa),Ha=va,b(Za)||E(jb,da)||l!=va||u(a,jb)!=pa?E(jb,da)?(Ea=jb.style.width+q(jb,da),Ga=va):(Ea=Za,Ga=b(Ea)?ua:wa):(Ea=Za,Ga=va));var zb=!E(jb,Ja)&&u(a,jb)===pa;T(jb,Ea,Fa,aa,Ga,Ha,R&&!zb,"flex"),jb=jb.nextChild}}ob=pb+qb,Ua===wa&&(ob=0),La!==ha&&(La===ia?mb=ob/2:La===ja?mb=ob:La===ka?(ob=L(ob,0),nb=eb>1?ob/(eb-1):0):La===la&&(nb=ob/eb,mb=nb/2));var Ab=Pa+mb,Bb=0;for(Da=_a;ab>Da;++Da)Ca=a.children[Da],z(Ca)===ra&&G(Ca,xa[Ia])?R&&(Ca.layout[za[Ia]]=I(Ca,xa[Ia])+m(a,Ia)+i(Ca,Ia)):(R&&(Ca.layout[za[Ia]]+=Ab),z(Ca)===qa&&(lb?(Ab+=nb+q(Ca,Ia)+Ca.layout.flexBasis,Bb=Za):(Ab+=nb+D(Ca,Ia),Bb=L(Bb,D(Ca,Ja)))));Ab+=Qa;var Cb=Za;if((Va===ua||Va===wa)&&(Cb=M(a,Ja,Bb+Ta)-Ta,Va===wa&&(Cb=K(Cb,Za))),Ma||Va!==va||(Bb=Za),Bb=M(a,Ja,Bb+Ta)-Ta,R)for(Da=_a;ab>Da;++Da)if(Ca=a.children[Da],z(Ca)===ra)G(Ca,xa[Ja])?Ca.layout[za[Ja]]=I(Ca,xa[Ja])+m(a,Ja)+i(Ca,Ja):Ca.layout[za[Ja]]=Ra+i(Ca,Ja);else{var Db=Ra,Eb=u(a,Ca);if(Eb===pa){Ea=Ca.layout.measuredWidth+q(Ca,da),Fa=Ca.layout.measuredHeight+q(Ca,fa);var Fb=!1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ea||Ia===ga)&&(Qb=!0),(Ja===ea||Ja===ga)&&(Rb=!0),Qb||Rb)for(Da=0;Aa>Da;++Da)Ca=a.children[Da],Qb&&N(a,Ca,Ia),Rb&&N(a,Ca,Ja)}for(Oa=Na;void 0!==Oa;)R&&(Ea=V,Fa=V,E(Oa,da)?Ea=Oa.style.width+q(Oa,da):G(Oa,Y)&&G(Oa,$)&&(Ea=a.layout.measuredWidth-(m(a,da)+n(a,da))-(Oa.style[Y]+Oa.style[$]),Ea=M(Oa,da,Ea)),E(Oa,fa)?Fa=Oa.style.height+q(Oa,fa):G(Oa,Z)&&G(Oa,_)&&(Fa=a.layout.measuredHeight-(m(a,fa)+n(a,fa))-(Oa.style[Z]+Oa.style[_]),Fa=M(Oa,fa,Fa)),(b(Ea)||b(Fa))&&(Ga=b(Ea)?ua:va,Ha=b(Fa)?ua:va,Ka||!b(Ea)||b(Wa)||(Ea=Wa,Ga=wa),A(a)===ta&&Ka&&b(Fa)&&!b(Xa)&&(Fa=Xa,Ha=wa),T(Oa,Ea,Fa,aa,Ga,Ha,!1,"abs-measure"),Ea=Oa.layout.measuredWidth+q(Oa,da),Fa=Oa.layout.measuredHeight+q(Oa,fa)),T(Oa,Ea,Fa,aa,va,va,!0,"abs-layout"),G(Oa,ya[da])&&!G(Oa,xa[da])&&(Oa.layout[xa[da]]=a.layout[Ba[da]]-Oa.layout[Ba[da]]-I(Oa,ya[da])),G(Oa,ya[fa])&&!G(Oa,xa[fa])&&(Oa.layout[xa[fa]]=a.layout[Ba[fa]]-Oa.layout[Ba[fa]]-I(Oa,ya[fa]))),Oa=Oa.nextChild}}function S(a,b,c,d,e,f,g,h){var i=h.heightMeasureMode==ua&&g==ua||h.heightMeasureMode==g&&h.availableHeight==c,j=h.widthMeasureMode==ua&&f==ua||h.widthMeasureMode==f&&h.availableWidth==b;if(i&&j)return!0;var k=h.heightMeasureMode==ua&&g==wa&&h.computedHeight<=c-e||g==va&&h.computedHeight==c-e;if(j&&k)return!0;var l=h.widthMeasureMode==ua&&f==wa&&h.computedWidth<=b-d||f==va&&h.computedWidth==b-d;if(i&&l)return!0;if(k&&l)return!0;if(a){if(j)return g==ua?!0:g==wa&&h.computedHeight<c-e?!0:(h.computedHeight=c-e,!0);if(h.widthMeasureMode==ua&&(f==ua||f==wa&&h.computedWidth<=b-d))return!0}return!1}function T(a,b,c,d,e,f,g,h){var i=a.layout,j=a.isDirty&&i.generationCount!==X||i.lastParentDirection!==d;j&&(void 0!==i.cachedMeasurements&&(i.cachedMeasurements=[]),void 0!==i.cachedLayout&&(i.cachedLayout.widthMeasureMode=void 0,i.cachedLayout.heightMeasureMode=void 0));var k,l,m;if(H(a)){var n=q(a,da),o=q(a,fa);if(i.cachedLayout&&S(a.isTextNode,b,c,n,o,e,f,i.cachedLayout))m=i.cachedLayout;else if(i.cachedMeasurements)for(k=0,l=i.cachedMeasurements.length;l>k;k++)if(S(a.isTextNode,b,c,n,o,e,f,i.cachedMeasurements[k])){m=i.cachedMeasurements[k];break}}else if(g)i.cachedLayout&&i.cachedLayout.availableWidth===b&&i.cachedLayout.availableHeight===c&&i.cachedLayout.widthMeasureMode===e&&i.cachedLayout.heightMeasureMode===f&&(m=i.cachedLayout);else if(i.cachedMeasurements)for(k=0,l=i.cachedMeasurements.length;l>k;k++)if(i.cachedMeasurements[k].availableWidth===b&&i.cachedMeasurements[k].availableHeight===c&&i.cachedMeasurements[k].widthMeasureMode===e&&i.cachedMeasurements[k].heightMeasureMode===f){m=i.cachedMeasurements[k];break}if(j||void 0===m){if(R(a,b,c,d,e,f,g),i.lastParentDirection=d,void 0===m){var p;g?(void 0===i.cachedLayout&&(i.cachedLayout={}),p=i.cachedLayout):(void 0===i.cachedMeasurements&&(i.cachedMeasurements=[]),p={},i.cachedMeasurements.push(p)),p.availableWidth=b,p.availableHeight=c,p.widthMeasureMode=e,p.heightMeasureMode=f,p.computedWidth=i.measuredWidth,p.computedHeight=i.measuredHeight}}else i.measureWidth=m.computedWidth,i.measureHeight=m.computedHeight;return g&&(a.layout.width=a.layout.measuredWidth,a.layout.height=a.layout.measuredHeight,i.shouldUpdate=!0),i.generationCount=X,j||void 0===m}function U(a,c,d,e){X++;var f=ua,g=ua;b(c)?E(a,da)?(c=a.style.width+q(a,da),f=va):a.style.maxWidth>=0&&(c=a.style.maxWidth,f=wa):f=va,b(d)?E(a,fa)?(d=a.style.height+q(a,fa),g=va):a.style.maxHeight>=0&&(d=a.style.maxHeight,g=wa):g=va,T(a,c,d,e,f,g,!0,"initial")&&P(a,a.layout.direction)}var V,W=!1,X=0,Y="left",Z="top",$="right",_="bottom",aa="inherit",ba="ltr",ca="rtl",da="row",ea="row-reverse",fa="column",ga="column-reverse",ha="flex-start",ia="center",ja="flex-end",ka="space-between",la="space-around",ma="flex-start",na="center",oa="flex-end",pa="stretch",qa="relative",ra="absolute",sa="visible",ta="hidden",ua="undefined",va="exactly",wa="at-most",xa={row:"left","row-reverse":"right",column:"top","column-reverse":"bottom"},ya={row:"right","row-reverse":"left",column:"bottom","column-reverse":"top"},za={row:"left","row-reverse":"right",column:"top","column-reverse":"bottom"},Aa={row:"width","row-reverse":"width",column:"height","column-reverse":"height"},Ba={row:"measuredWidth","row-reverse":"measuredWidth",column:"measuredHeight","column-reverse":"measuredHeight"};return{layoutNodeImpl:R,computeLayout:U,fillNodes:a,canUseCachedMeasurement:S}}();return"object"==typeof exports&&(module.exports=a),function(b){a.fillNodes(b),a.computeLayout(b)}});
|
|
//# sourceMappingURL=css-layout.min.js.map
|