function C(n){var r=0,u=n.children,i=u&&u.length;if(!i)r=1;else for(;--i>=0;)r+=u[i].value;n.value=r}function D(){return this.eachAfter(C)}function F(n,r){let u=-1;for(let i of this)n.call(r,i,++u,this);return this}function G(n,r){for(var u=this,i=[u],e,o,a=-1;u=i.pop();)if(n.call(r,u,++a,this),e=u.children)for(o=e.length-1;o>=0;--o)i.push(e[o]);return this}function H(n,r){for(var u=this,i=[u],e=[],o,a,h,l=-1;u=i.pop();)if(e.push(u),o=u.children)for(a=0,h=o.length;a<h;++a)i.push(o[a]);for(;u=e.pop();)n.call(r,u,++l,this);return this}function J(n,r){let u=-1;for(let i of this)if(n.call(r,i,++u,this))return i}function K(n){return this.eachAfter(function(r){for(var u=+n(r.data)||0,i=r.children,e=i&&i.length;--e>=0;)u+=i[e].value;r.value=u})}function N(n){return this.eachBefore(function(r){r.children&&r.children.sort(n)})}function P(n){for(var r=this,u=Q(r,n),i=[r];r!==u;)r=r.parent,i.push(r);for(var e=i.length;n!==u;)i.splice(e,0,n),n=n.parent;return i}function Q(n,r){if(n===r)return n;var u=n.ancestors(),i=r.ancestors(),e=null;for(n=u.pop(),r=i.pop();n===r;)e=n,n=u.pop(),r=i.pop();return e}function U(){for(var n=this,r=[n];n=n.parent;)r.push(n);return r}function V(){return Array.from(this)}function W(){var n=[];return this.eachBefore(function(r){r.children||n.push(r)}),n}function X(){var n=this,r=[];return n.each(function(u){u!==n&&r.push({source:u.parent,target:u})}),r}function*Y(){var n=this,r,u=[n],i,e,o;do for(r=u.reverse(),u=[];n=r.pop();)if(yield n,i=n.children)for(e=0,o=i.length;e<o;++e)u.push(i[e]);while(u.length)}function I(n,r){n instanceof Map?(n=[void 0,n],r===void 0&&(r=S)):r===void 0&&(r=$);for(var u=new A(n),i,e=[u],o,a,h,l;i=e.pop();)if((a=r(i.data))&&(l=(a=Array.from(a)).length))for(i.children=a,h=l-1;h>=0;--h)e.push(o=a[h]=new A(a[h])),o.parent=i,o.depth=i.depth+1;return u.eachBefore(O)}function Z(){return I(this).eachBefore(_)}function $(n){return n.children}function S(n){return Array.isArray(n)?n[1]:null}function _(n){n.data.value!==void 0&&(n.value=n.data.value),n.data=n.data.data}function O(n){var r=0;do n.height=r;while((n=n.parent)&&n.height<++r)}function A(n){this.data=n,this.depth=this.height=0,this.parent=null}A.prototype=I.prototype={constructor:A,count:D,each:F,eachAfter:H,eachBefore:G,find:J,sum:K,sort:N,path:P,ancestors:U,descendants:V,leaves:W,links:X,copy:Z,[Symbol.iterator]:Y};function nn(n){return n==null?null:E(n)}function E(n){if(typeof n!="function")throw Error();return n}function m(){return 0}function M(n){return function(){return n}}function L(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 R(n,r,u,i,e){for(var o=n.children,a,h=-1,l=o.length,v=n.value&&(i-r)/n.value;++h<l;)a=o[h],a.y0=u,a.y1=e,a.x0=r,a.x1=r+=a.value*v}function b(n,r,u,i,e){for(var o=n.children,a,h=-1,l=o.length,v=n.value&&(e-u)/n.value;++h<l;)a=o[h],a.x0=r,a.x1=i,a.y0=u,a.y1=u+=a.value*v}var j=(1+Math.sqrt(5))/2;function q(n,r,u,i,e,o){for(var a=[],h=r.children,l,v,f=0,y=0,t=h.length,s,p,d=r.value,c,g,B,w,T,k,x;f<t;){s=e-u,p=o-i;do c=h[y++].value;while(!c&&y<t);for(g=B=c,k=Math.max(p/s,s/p)/(d*n),x=c*c*k,T=Math.max(B/x,x/g);y<t;++y){if(c+=v=h[y].value,v<g&&(g=v),v>B&&(B=v),x=c*c*k,w=Math.max(B/x,x/g),w>T){c-=v;break}T=w}a.push(l={value:c,dice:s<p,children:h.slice(f,y)}),l.dice?R(l,u,i,e,d?i+=p*c/d:o):b(l,u,i,d?u+=s*c/d:e,o),d-=c,f=y}return a}var z=(function n(r){function u(i,e,o,a,h){q(r,i,e,o,a,h)}return u.ratio=function(i){return n((i=+i)>1?i:1)},u})(j);function rn(){var n=z,r=!1,u=1,i=1,e=[0],o=m,a=m,h=m,l=m,v=m;function f(t){return t.x0=t.y0=0,t.x1=u,t.y1=i,t.eachBefore(y),e=[0],r&&t.eachBefore(L),t}function y(t){var s=e[t.depth],p=t.x0+s,d=t.y0+s,c=t.x1-s,g=t.y1-s;c<p&&(p=c=(p+c)/2),g<d&&(d=g=(d+g)/2),t.x0=p,t.y0=d,t.x1=c,t.y1=g,t.children&&(s=e[t.depth+1]=o(t)/2,p+=v(t)-s,d+=a(t)-s,c-=h(t)-s,g-=l(t)-s,c<p&&(p=c=(p+c)/2),g<d&&(d=g=(d+g)/2),n(t,p,d,c,g))}return f.round=function(t){return arguments.length?(r=!!t,f):r},f.size=function(t){return arguments.length?(u=+t[0],i=+t[1],f):[u,i]},f.tile=function(t){return arguments.length?(n=E(t),f):n},f.padding=function(t){return arguments.length?f.paddingInner(t).paddingOuter(t):f.paddingInner()},f.paddingInner=function(t){return arguments.length?(o=typeof t=="function"?t:M(+t),f):o},f.paddingOuter=function(t){return arguments.length?f.paddingTop(t).paddingRight(t).paddingBottom(t).paddingLeft(t):f.paddingTop()},f.paddingTop=function(t){return arguments.length?(a=typeof t=="function"?t:M(+t),f):a},f.paddingRight=function(t){return arguments.length?(h=typeof t=="function"?t:M(+t),f):h},f.paddingBottom=function(t){return arguments.length?(l=typeof t=="function"?t:M(+t),f):l},f.paddingLeft=function(t){return arguments.length?(v=typeof t=="function"?t:M(+t),f):v},f}export{b as a,m as c,A as d,O as f,z as i,M as l,j as n,R as o,I as p,q as r,L as s,rn as t,nn as u};
