function n(n){var t=0,r=n.children,e=r&&r.length;if(e)for(;--e>=0;)t+=r[e].value;else t=1;n.value=t}function t(n,t){n instanceof Map?(n=[void 0,n],void 0===t&&(t=e)):void 0===t&&(t=r);for(var o,a,f,h,c,l=new u(n),d=[l];o=d.pop();)if((f=t(o.data))&&(c=(f=Array.from(f)).length))for(o.children=f,h=c-1;h>=0;--h)d.push(a=f[h]=new u(f[h])),a.parent=o,a.depth=o.depth+1;return l.eachBefore(i)}function r(n){return n.children}function e(n){return Array.isArray(n)?n[1]:null}function o(n){void 0!==n.data.value&&(n.value=n.data.value),n.data=n.data.data}function i(n){var t=0;do{n.height=t}while((n=n.parent)&&n.height<++t)}function u(n){this.data=n,this.depth=this.height=0,this.parent=null}function a(){return 0}function f(n){return function(){return n}}function h(n){n.x0=Math.round(n.x0),n.y0=Math.round(n.y0),n.x1=Math.round(n.x1),n.y1=Math.round(n.y1)}function c(n,t,r,e,o){for(var i,u=n.children,a=-1,f=u.length,h=n.value&&(e-t)/n.value;++a<f;)(i=u[a]).y0=r,i.y1=o,i.x0=t,i.x1=t+=i.value*h}function l(n,t,r,e,o){for(var i,u=n.children,a=-1,f=u.length,h=n.value&&(o-r)/n.value;++a<f;)(i=u[a]).x0=t,i.x1=e,i.y0=r,i.y1=r+=i.value*h}u.prototype=t.prototype={constructor:u,count:function(){return this.eachAfter(n)},each:function(n,t){let r=-1;for(const e of this)n.call(t,e,++r,this);return this},eachAfter:function(n,t){for(var r,e,o,i=this,u=[i],a=[],f=-1;i=u.pop();)if(a.push(i),r=i.children)for(e=0,o=r.length;e<o;++e)u.push(r[e]);for(;i=a.pop();)n.call(t,i,++f,this);return this},eachBefore:function(n,t){for(var r,e,o=this,i=[o],u=-1;o=i.pop();)if(n.call(t,o,++u,this),r=o.children)for(e=r.length-1;e>=0;--e)i.push(r[e]);return this},find:function(n,t){let r=-1;for(const e of this)if(n.call(t,e,++r,this))return e},sum:function(n){return this.eachAfter(function(t){for(var r=+n(t.data)||0,e=t.children,o=e&&e.length;--o>=0;)r+=e[o].value;t.value=r})},sort:function(n){return this.eachBefore(function(t){t.children&&t.children.sort(n)})},path:function(n){for(var t=this,r=function(n,t){if(n===t)return n;var r=n.ancestors(),e=t.ancestors(),o=null;n=r.pop(),t=e.pop();for(;n===t;)o=n,n=r.pop(),t=e.pop();return o}(t,n),e=[t];t!==r;)t=t.parent,e.push(t);for(var o=e.length;n!==r;)e.splice(o,0,n),n=n.parent;return e},ancestors:function(){for(var n=this,t=[n];n=n.parent;)t.push(n);return t},descendants:function(){return Array.from(this)},leaves:function(){var n=[];return this.eachBefore(function(t){t.children||n.push(t)}),n},links:function(){var n=this,t=[];return n.each(function(r){r!==n&&t.push({source:r.parent,target:r})}),t},copy:function(){return t(this).eachBefore(o)},[Symbol.iterator]:function*(){var n,t,r,e,o=this,i=[o];do{for(n=i.reverse(),i=[];o=n.pop();)if(yield o,t=o.children)for(r=0,e=t.length;r<e;++r)i.push(t[r])}while(i.length)}};const d=function n(t){function r(n,r,e,o,i){!function(n,t,r,e,o,i){for(var u,a,f,h,d,p,s,g,v,y,x,m=[],B=t.children,M=0,w=0,A=B.length,I=t.value;M<A;){f=o-r,h=i-e;do{d=B[w++].value}while(!d&&w<A);for(p=s=d,x=d*d*(y=Math.max(h/f,f/h)/(I*n)),v=Math.max(s/x,x/p);w<A;++w){if(d+=a=B[w].value,a<p&&(p=a),a>s&&(s=a),x=d*d*y,(g=Math.max(s/x,x/p))>v){d-=a;break}v=g}m.push(u={value:d,dice:f<h,children:B.slice(M,w)}),u.dice?c(u,r,e,o,I?e+=h*d/I:i):l(u,r,e,I?r+=f*d/I:o,i),I-=d,M=w}}(t,n,r,e,o,i)}return r.ratio=function(t){return n((t=+t)>1?t:1)},r}((1+Math.sqrt(5))/2);function p(){var n=d,t=!1,r=1,e=1,o=[0],i=a,u=a,c=a,l=a,p=a;function s(n){return n.x0=n.y0=0,n.x1=r,n.y1=e,n.eachBefore(g),o=[0],t&&n.eachBefore(h),n}function g(t){var r=o[t.depth],e=t.x0+r,a=t.y0+r,f=t.x1-r,h=t.y1-r;f<e&&(e=f=(e+f)/2),h<a&&(a=h=(a+h)/2),t.x0=e,t.y0=a,t.x1=f,t.y1=h,t.children&&(r=o[t.depth+1]=i(t)/2,e+=p(t)-r,a+=u(t)-r,(f-=c(t)-r)<e&&(e=f=(e+f)/2),(h-=l(t)-r)<a&&(a=h=(a+h)/2),n(t,e,a,f,h))}return s.round=function(n){return arguments.length?(t=!!n,s):t},s.size=function(n){return arguments.length?(r=+n[0],e=+n[1],s):[r,e]},s.tile=function(t){return arguments.length?(n=function(n){if("function"!=typeof n)throw new Error;return n}(t),s):n},s.padding=function(n){return arguments.length?s.paddingInner(n).paddingOuter(n):s.paddingInner()},s.paddingInner=function(n){return arguments.length?(i="function"==typeof n?n:f(+n),s):i},s.paddingOuter=function(n){return arguments.length?s.paddingTop(n).paddingRight(n).paddingBottom(n).paddingLeft(n):s.paddingTop()},s.paddingTop=function(n){return arguments.length?(u="function"==typeof n?n:f(+n),s):u},s.paddingRight=function(n){return arguments.length?(c="function"==typeof n?n:f(+n),s):c},s.paddingBottom=function(n){return arguments.length?(l="function"==typeof n?n:f(+n),s):l},s.paddingLeft=function(n){return arguments.length?(p="function"==typeof n?n:f(+n),s):p},s}export{t as h,p as t};
