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