@kineviz/gl 0.7.0 → 0.7.1

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.
@@ -0,0 +1,2 @@
1
+ function dn(t){var e=0,n=t.children,i=n&&n.length;if(!i)e=1;else for(;--i>=0;)e+=n[i].value;t.value=e}function Kt(){return this.eachAfter(dn)}function Jt(t,e){let n=-1;for(let i of this)t.call(e,i,++n,this);return this}function te(t,e){for(var n=this,i=[n],r,s,o=-1;n=i.pop();)if(t.call(e,n,++o,this),r=n.children)for(s=r.length-1;s>=0;--s)i.push(r[s]);return this}function ee(t,e){for(var n=this,i=[n],r=[],s,o,a,l=-1;n=i.pop();)if(r.push(n),s=n.children)for(o=0,a=s.length;o<a;++o)i.push(s[o]);for(;n=r.pop();)t.call(e,n,++l,this);return this}function ne(t,e){let n=-1;for(let i of this)if(t.call(e,i,++n,this))return i}function ie(t){return this.eachAfter(function(e){for(var n=+t(e.data)||0,i=e.children,r=i&&i.length;--r>=0;)n+=i[r].value;e.value=n})}function re(t){return this.eachBefore(function(e){e.children&&e.children.sort(t)})}function se(t){for(var e=this,n=gn(e,t),i=[e];e!==n;)e=e.parent,i.push(e);for(var r=i.length;t!==n;)i.splice(r,0,t),t=t.parent;return i}function gn(t,e){if(t===e)return t;var n=t.ancestors(),i=e.ancestors(),r=null;for(t=n.pop(),e=i.pop();t===e;)r=t,t=n.pop(),e=i.pop();return r}function oe(){for(var t=this,e=[t];t=t.parent;)e.push(t);return e}function ae(){return Array.from(this)}function le(){var t=[];return this.eachBefore(function(e){e.children||t.push(e)}),t}function ce(){var t=this,e=[];return t.each(function(n){n!==t&&e.push({source:n.parent,target:n})}),e}function*ue(){var t=this,e,n=[t],i,r,s;do for(e=n.reverse(),n=[];t=e.pop();)if(yield t,i=t.children)for(r=0,s=i.length;r<s;++r)n.push(i[r]);while(n.length)}function st(t,e){t instanceof Map?(t=[void 0,t],e===void 0&&(e=xn)):e===void 0&&(e=yn);for(var n=new H(t),i,r=[n],s,o,a,l;i=r.pop();)if((o=e(i.data))&&(l=(o=Array.from(o)).length))for(i.children=o,a=l-1;a>=0;--a)r.push(s=o[a]=new H(o[a])),s.parent=i,s.depth=i.depth+1;return n.eachBefore(Nt)}function mn(){return st(this).eachBefore(_n)}function yn(t){return t.children}function xn(t){return Array.isArray(t)?t[1]:null}function _n(t){t.data.value!==void 0&&(t.value=t.data.value),t.data=t.data.data}function Nt(t){var e=0;do t.height=e;while((t=t.parent)&&t.height<++e)}function H(t){this.data=t,this.depth=this.height=0,this.parent=null}H.prototype=st.prototype={constructor:H,count:Kt,each:Jt,eachAfter:ee,eachBefore:te,find:ne,sum:ie,sort:re,path:se,ancestors:oe,descendants:ae,leaves:le,links:ce,copy:mn,[Symbol.iterator]:ue};function mt(t){return t==null?null:wn(t)}function wn(t){if(typeof t!="function")throw new Error;return t}var vn={depth:-1},fe={},Dt={};function Mn(t){return t.id}function kn(t){return t.parentId}function Et(){var t=Mn,e=kn,n;function i(r){var s=Array.from(r),o=t,a=e,l,u,c,f,h,p,d,m,y=new Map;if(n!=null){let g=s.map((_,M)=>An(n(_,M,r))),w=g.map(he),x=new Set(g).add("");for(let _ of w)x.has(_)||(x.add(_),g.push(_),w.push(he(_)),s.push(Dt));o=(_,M)=>g[M],a=(_,M)=>w[M]}for(c=0,l=s.length;c<l;++c)u=s[c],p=s[c]=new H(u),(d=o(u,c,r))!=null&&(d+="")&&(m=p.id=d,y.set(m,y.has(m)?fe:p)),(d=a(u,c,r))!=null&&(d+="")&&(p.parent=d);for(c=0;c<l;++c)if(p=s[c],d=p.parent){if(h=y.get(d),!h)throw new Error("missing: "+d);if(h===fe)throw new Error("ambiguous: "+d);h.children?h.children.push(p):h.children=[p],p.parent=h}else{if(f)throw new Error("multiple roots");f=p}if(!f)throw new Error("no root");if(n!=null){for(;f.data===Dt&&f.children.length===1;)f=f.children[0],--l;for(let g=s.length-1;g>=0&&(p=s[g],p.data===Dt);--g)p.data=null}if(f.parent=vn,f.eachBefore(function(g){g.depth=g.parent.depth+1,--l}).eachBefore(Nt),f.parent=null,l>0)throw new Error("cycle");return f}return i.id=function(r){return arguments.length?(t=mt(r),i):t},i.parentId=function(r){return arguments.length?(e=mt(r),i):e},i.path=function(r){return arguments.length?(n=mt(r),i):n},i}function An(t){t=`${t}`;let e=t.length;return bt(t,e-1)&&!bt(t,e-2)&&(t=t.slice(0,-1)),t[0]==="/"?t:`/${t}`}function he(t){let e=t.length;if(e<2)return"";for(;--e>1&&!bt(t,e););return t.slice(0,e)}function bt(t,e){if(t[e]==="/"){let n=0;for(;e>0&&t[--e]==="\\";)++n;if((n&1)===0)return!0}return!1}function zn(t,e){return t.parent===e.parent?1:2}function Ct(t){var e=t.children;return e?e[0]:t.t}function Pt(t){var e=t.children;return e?e[e.length-1]:t.t}function In(t,e,n){var i=n/(e.i-t.i);e.c-=i,e.s+=n,t.c+=i,e.z+=n,e.m+=n}function Sn(t){for(var e=0,n=0,i=t.children,r=i.length,s;--r>=0;)s=i[r],s.z+=e,s.m+=e,e+=s.s+(n+=s.c)}function Nn(t,e,n){return t.a.parent===e.parent?t.a:n}function yt(t,e){this._=t,this.parent=null,this.children=null,this.A=null,this.a=this,this.z=0,this.m=0,this.c=0,this.s=0,this.t=null,this.i=e}yt.prototype=Object.create(H.prototype);function Dn(t){for(var e=new yt(t,0),n,i=[e],r,s,o,a;n=i.pop();)if(s=n._.children)for(n.children=new Array(a=s.length),o=a-1;o>=0;--o)i.push(r=n.children[o]=new yt(s[o],o)),r.parent=n;return(e.parent=new yt(null,0)).children=[e],e}function ft(){var t=zn,e=1,n=1,i=null;function r(u){var c=Dn(u);if(c.eachAfter(s),c.parent.m=-c.z,c.eachBefore(o),i)u.eachBefore(l);else{var f=u,h=u,p=u;u.eachBefore(function(w){w.x<f.x&&(f=w),w.x>h.x&&(h=w),w.depth>p.depth&&(p=w)});var d=f===h?1:t(f,h)/2,m=d-f.x,y=e/(h.x+d+m),g=n/(p.depth||1);u.eachBefore(function(w){w.x=(w.x+m)*y,w.y=w.depth*g})}return u}function s(u){var c=u.children,f=u.parent.children,h=u.i?f[u.i-1]:null;if(c){Sn(u);var p=(c[0].z+c[c.length-1].z)/2;h?(u.z=h.z+t(u._,h._),u.m=u.z-p):u.z=p}else h&&(u.z=h.z+t(u._,h._));u.parent.A=a(u,h,u.parent.A||f[0])}function o(u){u._.x=u.z+u.parent.m,u.m+=u.parent.m}function a(u,c,f){if(c){for(var h=u,p=u,d=c,m=h.parent.children[0],y=h.m,g=p.m,w=d.m,x=m.m,_;d=Pt(d),h=Ct(h),d&&h;)m=Ct(m),p=Pt(p),p.a=u,_=d.z+w-h.z-y+t(d._,h._),_>0&&(In(Nn(d,u,f),u,_),y+=_,g+=_),w+=d.m,y+=h.m,x+=m.m,g+=p.m;d&&!Pt(p)&&(p.t=d,p.m+=w-g),h&&!Ct(m)&&(m.t=h,m.m+=y-x,f=u)}return f}function l(u){u.x*=e,u.y=u.depth*n}return r.separation=function(u){return arguments.length?(t=u,r):t},r.size=function(u){return arguments.length?(i=!1,e=+u[0],n=+u[1],r):i?null:[e,n]},r.nodeSize=function(u){return arguments.length?(i=!0,e=+u[0],n=+u[1],r):i?[e,n]:null},r}import*as ut from"lodash";function de(t){let e=+this._x.call(null,t);return ge(this.cover(e),e,t)}function ge(t,e,n){if(isNaN(e))return t;var i,r=t._root,s={data:n},o=t._x0,a=t._x1,l,u,c,f,h;if(!r)return t._root=s,t;for(;r.length;)if((c=e>=(l=(o+a)/2))?o=l:a=l,i=r,!(r=r[f=+c]))return i[f]=s,t;if(u=+t._x.call(null,r.data),e===u)return s.next=r,i?i[f]=s:t._root=s,t;do i=i?i[f]=new Array(2):t._root=new Array(2),(c=e>=(l=(o+a)/2))?o=l:a=l;while((f=+c)==(h=+(u>=l)));return i[h]=r,i[f]=s,t}function me(t){Array.isArray(t)||(t=Array.from(t));let e=t.length,n=new Float64Array(e),i=1/0,r=-1/0;for(let s=0,o;s<e;++s)isNaN(o=+this._x.call(null,t[s]))||(n[s]=o,o<i&&(i=o),o>r&&(r=o));if(i>r)return this;this.cover(i).cover(r);for(let s=0;s<e;++s)ge(this,n[s],t[s]);return this}function ye(t){if(isNaN(t=+t))return this;var e=this._x0,n=this._x1;if(isNaN(e))n=(e=Math.floor(t))+1;else{for(var i=n-e||1,r=this._root,s,o;e>t||t>=n;)switch(o=+(t<e),s=new Array(2),s[o]=r,r=s,i*=2,o){case 0:n=e+i;break;case 1:e=n-i;break}this._root&&this._root.length&&(this._root=r)}return this._x0=e,this._x1=n,this}function xe(){var t=[];return this.visit(function(e){if(!e.length)do t.push(e.data);while(e=e.next)}),t}function _e(t){return arguments.length?this.cover(+t[0][0]).cover(+t[1][0]):isNaN(this._x0)?void 0:[[this._x0],[this._x1]]}function $(t,e,n){this.node=t,this.x0=e,this.x1=n}function we(t,e){var n,i=this._x0,r,s,o=this._x1,a=[],l=this._root,u,c;for(l&&a.push(new $(l,i,o)),e==null?e=1/0:(i=t-e,o=t+e);u=a.pop();)if(!(!(l=u.node)||(r=u.x0)>o||(s=u.x1)<i))if(l.length){var f=(r+s)/2;a.push(new $(l[1],f,s),new $(l[0],r,f)),(c=+(t>=f))&&(u=a[a.length-1],a[a.length-1]=a[a.length-1-c],a[a.length-1-c]=u)}else{var h=Math.abs(t-+this._x.call(null,l.data));h<e&&(e=h,i=t-h,o=t+h,n=l.data)}return n}function ve(t){if(isNaN(l=+this._x.call(null,t)))return this;var e,n=this._root,i,r,s,o=this._x0,a=this._x1,l,u,c,f,h;if(!n)return this;if(n.length)for(;;){if((c=l>=(u=(o+a)/2))?o=u:a=u,e=n,!(n=n[f=+c]))return this;if(!n.length)break;e[f+1&1]&&(i=e,h=f)}for(;n.data!==t;)if(r=n,!(n=n.next))return this;return(s=n.next)&&delete n.next,r?(s?r.next=s:delete r.next,this):e?(s?e[f]=s:delete e[f],(n=e[0]||e[1])&&n===(e[1]||e[0])&&!n.length&&(i?i[h]=n:this._root=n),this):(this._root=s,this)}function Me(t){for(var e=0,n=t.length;e<n;++e)this.remove(t[e]);return this}function ke(){return this._root}function Ae(){var t=0;return this.visit(function(e){if(!e.length)do++t;while(e=e.next)}),t}function ze(t){var e=[],n,i=this._root,r,s,o;for(i&&e.push(new $(i,this._x0,this._x1));n=e.pop();)if(!t(i=n.node,s=n.x0,o=n.x1)&&i.length){var a=(s+o)/2;(r=i[1])&&e.push(new $(r,a,o)),(r=i[0])&&e.push(new $(r,s,a))}return this}function Ie(t){var e=[],n=[],i;for(this._root&&e.push(new $(this._root,this._x0,this._x1));i=e.pop();){var r=i.node;if(r.length){var s,o=i.x0,a=i.x1,l=(o+a)/2;(s=r[0])&&e.push(new $(s,o,l)),(s=r[1])&&e.push(new $(s,l,a))}n.push(i)}for(;i=n.pop();)t(i.node,i.x0,i.x1);return this}function Se(t){return t[0]}function Ne(t){return arguments.length?(this._x=t,this):this._x}function K(t,e){var n=new Lt(e??Se,NaN,NaN);return t==null?n:n.addAll(t)}function Lt(t,e,n){this._x=t,this._x0=e,this._x1=n,this._root=void 0}function De(t){for(var e={data:t.data},n=e;t=t.next;)n=n.next={data:t.data};return e}var R=K.prototype=Lt.prototype;R.copy=function(){var t=new Lt(this._x,this._x0,this._x1),e=this._root,n,i;if(!e)return t;if(!e.length)return t._root=De(e),t;for(n=[{source:e,target:t._root=new Array(2)}];e=n.pop();)for(var r=0;r<2;++r)(i=e.source[r])&&(i.length?n.push({source:i,target:e.target[r]=new Array(2)}):e.target[r]=De(i));return t};R.add=de;R.addAll=me;R.cover=ye;R.data=xe;R.extent=_e;R.find=we;R.remove=ve;R.removeAll=Me;R.root=ke;R.size=Ae;R.visit=ze;R.visitAfter=Ie;R.x=Ne;function be(t){let e=+this._x.call(null,t),n=+this._y.call(null,t);return Ee(this.cover(e,n),e,n,t)}function Ee(t,e,n,i){if(isNaN(e)||isNaN(n))return t;var r,s=t._root,o={data:i},a=t._x0,l=t._y0,u=t._x1,c=t._y1,f,h,p,d,m,y,g,w;if(!s)return t._root=o,t;for(;s.length;)if((m=e>=(f=(a+u)/2))?a=f:u=f,(y=n>=(h=(l+c)/2))?l=h:c=h,r=s,!(s=s[g=y<<1|m]))return r[g]=o,t;if(p=+t._x.call(null,s.data),d=+t._y.call(null,s.data),e===p&&n===d)return o.next=s,r?r[g]=o:t._root=o,t;do r=r?r[g]=new Array(4):t._root=new Array(4),(m=e>=(f=(a+u)/2))?a=f:u=f,(y=n>=(h=(l+c)/2))?l=h:c=h;while((g=y<<1|m)===(w=(d>=h)<<1|p>=f));return r[w]=s,r[g]=o,t}function Ce(t){var e,n,i=t.length,r,s,o=new Array(i),a=new Array(i),l=1/0,u=1/0,c=-1/0,f=-1/0;for(n=0;n<i;++n)isNaN(r=+this._x.call(null,e=t[n]))||isNaN(s=+this._y.call(null,e))||(o[n]=r,a[n]=s,r<l&&(l=r),r>c&&(c=r),s<u&&(u=s),s>f&&(f=s));if(l>c||u>f)return this;for(this.cover(l,u).cover(c,f),n=0;n<i;++n)Ee(this,o[n],a[n],t[n]);return this}function Pe(t,e){if(isNaN(t=+t)||isNaN(e=+e))return this;var n=this._x0,i=this._y0,r=this._x1,s=this._y1;if(isNaN(n))r=(n=Math.floor(t))+1,s=(i=Math.floor(e))+1;else{for(var o=r-n||1,a=this._root,l,u;n>t||t>=r||i>e||e>=s;)switch(u=(e<i)<<1|t<n,l=new Array(4),l[u]=a,a=l,o*=2,u){case 0:r=n+o,s=i+o;break;case 1:n=r-o,s=i+o;break;case 2:r=n+o,i=s-o;break;case 3:n=r-o,i=s-o;break}this._root&&this._root.length&&(this._root=a)}return this._x0=n,this._y0=i,this._x1=r,this._y1=s,this}function Le(){var t=[];return this.visit(function(e){if(!e.length)do t.push(e.data);while(e=e.next)}),t}function Te(t){return arguments.length?this.cover(+t[0][0],+t[0][1]).cover(+t[1][0],+t[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]}function P(t,e,n,i,r){this.node=t,this.x0=e,this.y0=n,this.x1=i,this.y1=r}function Fe(t,e,n){var i,r=this._x0,s=this._y0,o,a,l,u,c=this._x1,f=this._y1,h=[],p=this._root,d,m;for(p&&h.push(new P(p,r,s,c,f)),n==null?n=1/0:(r=t-n,s=e-n,c=t+n,f=e+n,n*=n);d=h.pop();)if(!(!(p=d.node)||(o=d.x0)>c||(a=d.y0)>f||(l=d.x1)<r||(u=d.y1)<s))if(p.length){var y=(o+l)/2,g=(a+u)/2;h.push(new P(p[3],y,g,l,u),new P(p[2],o,g,y,u),new P(p[1],y,a,l,g),new P(p[0],o,a,y,g)),(m=(e>=g)<<1|t>=y)&&(d=h[h.length-1],h[h.length-1]=h[h.length-1-m],h[h.length-1-m]=d)}else{var w=t-+this._x.call(null,p.data),x=e-+this._y.call(null,p.data),_=w*w+x*x;if(_<n){var M=Math.sqrt(n=_);r=t-M,s=e-M,c=t+M,f=e+M,i=p.data}}return i}function Be(t){if(isNaN(c=+this._x.call(null,t))||isNaN(f=+this._y.call(null,t)))return this;var e,n=this._root,i,r,s,o=this._x0,a=this._y0,l=this._x1,u=this._y1,c,f,h,p,d,m,y,g;if(!n)return this;if(n.length)for(;;){if((d=c>=(h=(o+l)/2))?o=h:l=h,(m=f>=(p=(a+u)/2))?a=p:u=p,e=n,!(n=n[y=m<<1|d]))return this;if(!n.length)break;(e[y+1&3]||e[y+2&3]||e[y+3&3])&&(i=e,g=y)}for(;n.data!==t;)if(r=n,!(n=n.next))return this;return(s=n.next)&&delete n.next,r?(s?r.next=s:delete r.next,this):e?(s?e[y]=s:delete e[y],(n=e[0]||e[1]||e[2]||e[3])&&n===(e[3]||e[2]||e[1]||e[0])&&!n.length&&(i?i[g]=n:this._root=n),this):(this._root=s,this)}function Ye(t){for(var e=0,n=t.length;e<n;++e)this.remove(t[e]);return this}function Xe(){return this._root}function Re(){var t=0;return this.visit(function(e){if(!e.length)do++t;while(e=e.next)}),t}function qe(t){var e=[],n,i=this._root,r,s,o,a,l;for(i&&e.push(new P(i,this._x0,this._y0,this._x1,this._y1));n=e.pop();)if(!t(i=n.node,s=n.x0,o=n.y0,a=n.x1,l=n.y1)&&i.length){var u=(s+a)/2,c=(o+l)/2;(r=i[3])&&e.push(new P(r,u,c,a,l)),(r=i[2])&&e.push(new P(r,s,c,u,l)),(r=i[1])&&e.push(new P(r,u,o,a,c)),(r=i[0])&&e.push(new P(r,s,o,u,c))}return this}function Ze(t){var e=[],n=[],i;for(this._root&&e.push(new P(this._root,this._x0,this._y0,this._x1,this._y1));i=e.pop();){var r=i.node;if(r.length){var s,o=i.x0,a=i.y0,l=i.x1,u=i.y1,c=(o+l)/2,f=(a+u)/2;(s=r[0])&&e.push(new P(s,o,a,c,f)),(s=r[1])&&e.push(new P(s,c,a,l,f)),(s=r[2])&&e.push(new P(s,o,f,c,u)),(s=r[3])&&e.push(new P(s,c,f,l,u))}n.push(i)}for(;i=n.pop();)t(i.node,i.x0,i.y0,i.x1,i.y1);return this}function Ge(t){return t[0]}function Ue(t){return arguments.length?(this._x=t,this):this._x}function $e(t){return t[1]}function Oe(t){return arguments.length?(this._y=t,this):this._y}function J(t,e,n){var i=new Tt(e??Ge,n??$e,NaN,NaN,NaN,NaN);return t==null?i:i.addAll(t)}function Tt(t,e,n,i,r,s){this._x=t,this._y=e,this._x0=n,this._y0=i,this._x1=r,this._y1=s,this._root=void 0}function Ve(t){for(var e={data:t.data},n=e;t=t.next;)n=n.next={data:t.data};return e}var F=J.prototype=Tt.prototype;F.copy=function(){var t=new Tt(this._x,this._y,this._x0,this._y0,this._x1,this._y1),e=this._root,n,i;if(!e)return t;if(!e.length)return t._root=Ve(e),t;for(n=[{source:e,target:t._root=new Array(4)}];e=n.pop();)for(var r=0;r<4;++r)(i=e.source[r])&&(i.length?n.push({source:i,target:e.target[r]=new Array(4)}):e.target[r]=Ve(i));return t};F.add=be;F.addAll=Ce;F.cover=Pe;F.data=Le;F.extent=Te;F.find=Fe;F.remove=Be;F.removeAll=Ye;F.root=Xe;F.size=Re;F.visit=qe;F.visitAfter=Ze;F.x=Ue;F.y=Oe;import{octree as bn}from"d3-octree";function b(t){return function(){return t}}function B(t){return(t()-.5)*1e-6}function Ft(t){return t.x+t.vx}function je(t){return t.y+t.vy}function En(t){return t.z+t.vz}function Bt(t){var e,n,i,r,s=1,o=1;typeof t!="function"&&(t=b(t==null?1:+t));function a(){for(var c,f=e.length,h,p,d,m,y,g,w,x=0;x<o;++x)for(h=(n===1?K(e,Ft):n===2?J(e,Ft,je):n===3?bn(e,Ft,je,En):null).visitAfter(l),c=0;c<f;++c)p=e[c],g=i[p.index],w=g*g,d=p.x+p.vx,n>1&&(m=p.y+p.vy),n>2&&(y=p.z+p.vz),h.visit(_);function _(M,v,k,A,N,E,S){var z=[v,k,A,N,E,S],I=z[0],Y=z[1],V=z[2],q=z[n],U=z[n+1],X=z[n+2],Z=M.data,it=M.r,C=g+it;if(Z){if(Z.index>p.index){var D=d-Z.x-Z.vx,T=n>1?m-Z.y-Z.vy:0,G=n>2?y-Z.z-Z.vz:0,L=D*D+T*T+G*G;L<C*C&&(D===0&&(D=B(r),L+=D*D),n>1&&T===0&&(T=B(r),L+=T*T),n>2&&G===0&&(G=B(r),L+=G*G),L=(C-(L=Math.sqrt(L)))/L*s,p.vx+=(D*=L)*(C=(it*=it)/(w+it)),n>1&&(p.vy+=(T*=L)*C),n>2&&(p.vz+=(G*=L)*C),Z.vx-=D*(C=1-C),n>1&&(Z.vy-=T*C),n>2&&(Z.vz-=G*C))}return}return I>d+C||q<d-C||n>1&&(Y>m+C||U<m-C)||n>2&&(V>y+C||X<y-C)}}function l(c){if(c.data)return c.r=i[c.data.index];for(var f=c.r=0;f<Math.pow(2,n);++f)c[f]&&c[f].r>c.r&&(c.r=c[f].r)}function u(){if(e){var c,f=e.length,h;for(i=new Array(f),c=0;c<f;++c)h=e[c],i[h.index]=+t(h,c,e)}}return a.initialize=function(c,...f){e=c,r=f.find(h=>typeof h=="function")||Math.random,n=f.find(h=>[1,2,3].includes(h))||2,u()},a.iterations=function(c){return arguments.length?(o=+c,a):o},a.strength=function(c){return arguments.length?(s=+c,a):s},a.radius=function(c){return arguments.length?(t=typeof c=="function"?c:b(+c),u(),a):t},a}function Cn(t){return t.index}function He(t,e){var n=t.get(e);if(!n)throw new Error("node not found: "+e);return n}function Yt(t){var e=Cn,n=h,i,r=b(30),s,o,a,l,u,c,f=1;t==null&&(t=[]);function h(g){return 1/Math.min(l[g.source.index],l[g.target.index])}function p(g){for(var w=0,x=t.length;w<f;++w)for(var _=0,M,v,k,A=0,N=0,E=0,S,z;_<x;++_)M=t[_],v=M.source,k=M.target,A=k.x+k.vx-v.x-v.vx||B(c),a>1&&(N=k.y+k.vy-v.y-v.vy||B(c)),a>2&&(E=k.z+k.vz-v.z-v.vz||B(c)),S=Math.sqrt(A*A+N*N+E*E),S=(S-s[_])/S*g*i[_],A*=S,N*=S,E*=S,k.vx-=A*(z=u[_]),a>1&&(k.vy-=N*z),a>2&&(k.vz-=E*z),v.vx+=A*(z=1-z),a>1&&(v.vy+=N*z),a>2&&(v.vz+=E*z)}function d(){if(o){var g,w=o.length,x=t.length,_=new Map(o.map((v,k)=>[e(v,k,o),v])),M;for(g=0,l=new Array(w);g<x;++g)M=t[g],M.index=g,typeof M.source!="object"&&(M.source=He(_,M.source)),typeof M.target!="object"&&(M.target=He(_,M.target)),l[M.source.index]=(l[M.source.index]||0)+1,l[M.target.index]=(l[M.target.index]||0)+1;for(g=0,u=new Array(x);g<x;++g)M=t[g],u[g]=l[M.source.index]/(l[M.source.index]+l[M.target.index]);i=new Array(x),m(),s=new Array(x),y()}}function m(){if(o)for(var g=0,w=t.length;g<w;++g)i[g]=+n(t[g],g,t)}function y(){if(o)for(var g=0,w=t.length;g<w;++g)s[g]=+r(t[g],g,t)}return p.initialize=function(g,...w){o=g,c=w.find(x=>typeof x=="function")||Math.random,a=w.find(x=>[1,2,3].includes(x))||2,d()},p.links=function(g){return arguments.length?(t=g,d(),p):t},p.id=function(g){return arguments.length?(e=g,p):e},p.iterations=function(g){return arguments.length?(f=+g,p):f},p.strength=function(g){return arguments.length?(n=typeof g=="function"?g:b(+g),m(),p):n},p.distance=function(g){return arguments.length?(r=typeof g=="function"?g:b(+g),y(),p):r},p}import{octree as Zn}from"d3-octree";var Pn={value:()=>{}};function Qe(){for(var t=0,e=arguments.length,n={},i;t<e;++t){if(!(i=arguments[t]+"")||i in n||/[\s.]/.test(i))throw new Error("illegal type: "+i);n[i]=[]}return new xt(n)}function xt(t){this._=t}function Ln(t,e){return t.trim().split(/^|\s+/).map(function(n){var i="",r=n.indexOf(".");if(r>=0&&(i=n.slice(r+1),n=n.slice(0,r)),n&&!e.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:i}})}xt.prototype=Qe.prototype={constructor:xt,on:function(t,e){var n=this._,i=Ln(t+"",n),r,s=-1,o=i.length;if(arguments.length<2){for(;++s<o;)if((r=(t=i[s]).type)&&(r=Tn(n[r],t.name)))return r;return}if(e!=null&&typeof e!="function")throw new Error("invalid callback: "+e);for(;++s<o;)if(r=(t=i[s]).type)n[r]=We(n[r],t.name,e);else if(e==null)for(r in n)n[r]=We(n[r],t.name,null);return this},copy:function(){var t={},e=this._;for(var n in e)t[n]=e[n].slice();return new xt(t)},call:function(t,e){if((r=arguments.length-2)>0)for(var n=new Array(r),i=0,r,s;i<r;++i)n[i]=arguments[i+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(s=this._[t],i=0,r=s.length;i<r;++i)s[i].value.apply(e,n)},apply:function(t,e,n){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var i=this._[t],r=0,s=i.length;r<s;++r)i[r].value.apply(e,n)}};function Tn(t,e){for(var n=0,i=t.length,r;n<i;++n)if((r=t[n]).name===e)return r.value}function We(t,e,n){for(var i=0,r=t.length;i<r;++i)if(t[i].name===e){t[i]=Pn,t=t.slice(0,i).concat(t.slice(i+1));break}return n!=null&&t.push({name:e,value:n}),t}var Xt=Qe;var ot=0,pt=0,ht=0,Je=1e3,_t,dt,wt=0,tt=0,vt=0,gt=typeof performance=="object"&&performance.now?performance:Date,tn=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function Zt(){return tt||(tn(Fn),tt=gt.now()+vt)}function Fn(){tt=0}function Rt(){this._call=this._time=this._next=null}Rt.prototype=Mt.prototype={constructor:Rt,restart:function(t,e,n){if(typeof t!="function")throw new TypeError("callback is not a function");n=(n==null?Zt():+n)+(e==null?0:+e),!this._next&&dt!==this&&(dt?dt._next=this:_t=this,dt=this),this._call=t,this._time=n,qt()},stop:function(){this._call&&(this._call=null,this._time=1/0,qt())}};function Mt(t,e,n){var i=new Rt;return i.restart(t,e,n),i}function en(){Zt(),++ot;for(var t=_t,e;t;)(e=tt-t._time)>=0&&t._call.call(void 0,e),t=t._next;--ot}function Ke(){tt=(wt=gt.now())+vt,ot=pt=0;try{en()}finally{ot=0,Yn(),tt=0}}function Bn(){var t=gt.now(),e=t-wt;e>Je&&(vt-=e,wt=t)}function Yn(){for(var t,e=_t,n,i=1/0;e;)e._call?(i>e._time&&(i=e._time),t=e,e=e._next):(n=e._next,e._next=null,e=t?t._next=n:_t=n);dt=t,qt(i)}function qt(t){if(!ot){pt&&(pt=clearTimeout(pt));var e=t-tt;e>24?(t<1/0&&(pt=setTimeout(Ke,t-gt.now()-vt)),ht&&(ht=clearInterval(ht))):(ht||(wt=gt.now(),ht=setInterval(Bn,Je)),ot=1,tn(Ke))}}function nn(){let t=1;return()=>(t=(1664525*t+1013904223)%4294967296)/4294967296}var rn=3;function kt(t){return t.x}function Gt(t){return t.y}function sn(t){return t.z}var Xn=10,Rn=Math.PI*(3-Math.sqrt(5)),qn=Math.PI*20/(9+Math.sqrt(221));function Ut(t,e){e=e||2;var n=Math.min(rn,Math.max(1,Math.round(e))),i,r=1,s=.001,o=1-Math.pow(s,1/300),a=0,l=.6,u=new Map,c=Mt(p),f=Xt("tick","end"),h=nn();t==null&&(t=[]);function p(){d(),f.call("tick",i),r<s&&(c.stop(),f.call("end",i))}function d(g){var w,x=t.length,_;g===void 0&&(g=1);for(var M=0;M<g;++M)for(r+=(a-r)*o,u.forEach(function(v){v(r)}),w=0;w<x;++w)_=t[w],_.fx==null?_.x+=_.vx*=l:(_.x=_.fx,_.vx=0),n>1&&(_.fy==null?_.y+=_.vy*=l:(_.y=_.fy,_.vy=0)),n>2&&(_.fz==null?_.z+=_.vz*=l:(_.z=_.fz,_.vz=0));return i}function m(){for(var g=0,w=t.length,x;g<w;++g){if(x=t[g],x.index=g,x.fx!=null&&(x.x=x.fx),x.fy!=null&&(x.y=x.fy),x.fz!=null&&(x.z=x.fz),isNaN(x.x)||n>1&&isNaN(x.y)||n>2&&isNaN(x.z)){var _=Xn*(n>2?Math.cbrt(.5+g):n>1?Math.sqrt(.5+g):g),M=g*Rn,v=g*qn;n===1?x.x=_:n===2?(x.x=_*Math.cos(M),x.y=_*Math.sin(M)):(x.x=_*Math.sin(M)*Math.cos(v),x.y=_*Math.cos(M),x.z=_*Math.sin(M)*Math.sin(v))}(isNaN(x.vx)||n>1&&isNaN(x.vy)||n>2&&isNaN(x.vz))&&(x.vx=0,n>1&&(x.vy=0),n>2&&(x.vz=0))}}function y(g){return g.initialize&&g.initialize(t,h,n),g}return m(),i={tick:d,restart:function(){return c.restart(p),i},stop:function(){return c.stop(),i},numDimensions:function(g){return arguments.length?(n=Math.min(rn,Math.max(1,Math.round(g))),u.forEach(y),i):n},nodes:function(g){return arguments.length?(t=g,m(),u.forEach(y),i):t},alpha:function(g){return arguments.length?(r=+g,i):r},alphaMin:function(g){return arguments.length?(s=+g,i):s},alphaDecay:function(g){return arguments.length?(o=+g,i):+o},alphaTarget:function(g){return arguments.length?(a=+g,i):a},velocityDecay:function(g){return arguments.length?(l=1-g,i):1-l},randomSource:function(g){return arguments.length?(h=g,u.forEach(y),i):h},force:function(g,w){return arguments.length>1?(w==null?u.delete(g):u.set(g,y(w)),i):u.get(g)},find:function(){var g=Array.prototype.slice.call(arguments),w=g.shift()||0,x=(n>1?g.shift():null)||0,_=(n>2?g.shift():null)||0,M=g.shift()||1/0,v=0,k=t.length,A,N,E,S,z,I;for(M*=M,v=0;v<k;++v)z=t[v],A=w-z.x,N=x-(z.y||0),E=_-(z.z||0),S=A*A+N*N+E*E,S<M&&(I=z,M=S);return I},on:function(g,w){return arguments.length>1?(f.on(g,w),i):f.on(g)}}}function $t(){var t,e,n,i,r,s=b(-30),o,a=1,l=1/0,u=.81;function c(d){var m,y=t.length,g=(e===1?K(t,kt):e===2?J(t,kt,Gt):e===3?Zn(t,kt,Gt,sn):null).visitAfter(h);for(r=d,m=0;m<y;++m)n=t[m],g.visit(p)}function f(){if(t){var d,m=t.length,y;for(o=new Array(m),d=0;d<m;++d)y=t[d],o[y.index]=+s(y,d,t)}}function h(d){var m=0,y,g,w=0,x,_,M,v,k=d.length;if(k){for(x=_=M=v=0;v<k;++v)(y=d[v])&&(g=Math.abs(y.value))&&(m+=y.value,w+=g,x+=g*(y.x||0),_+=g*(y.y||0),M+=g*(y.z||0));m*=Math.sqrt(4/k),d.x=x/w,e>1&&(d.y=_/w),e>2&&(d.z=M/w)}else{y=d,y.x=y.data.x,e>1&&(y.y=y.data.y),e>2&&(y.z=y.data.z);do m+=o[y.data.index];while(y=y.next)}d.value=m}function p(d,m,y,g,w){if(!d.value)return!0;var x=[y,g,w][e-1],_=d.x-n.x,M=e>1?d.y-n.y:0,v=e>2?d.z-n.z:0,k=x-m,A=_*_+M*M+v*v;if(k*k/u<A)return A<l&&(_===0&&(_=B(i),A+=_*_),e>1&&M===0&&(M=B(i),A+=M*M),e>2&&v===0&&(v=B(i),A+=v*v),A<a&&(A=Math.sqrt(a*A)),n.vx+=_*d.value*r/A,e>1&&(n.vy+=M*d.value*r/A),e>2&&(n.vz+=v*d.value*r/A)),!0;if(d.length||A>=l)return;(d.data!==n||d.next)&&(_===0&&(_=B(i),A+=_*_),e>1&&M===0&&(M=B(i),A+=M*M),e>2&&v===0&&(v=B(i),A+=v*v),A<a&&(A=Math.sqrt(a*A)));do d.data!==n&&(k=o[d.data.index]*r/A,n.vx+=_*k,e>1&&(n.vy+=M*k),e>2&&(n.vz+=v*k));while(d=d.next)}return c.initialize=function(d,...m){t=d,i=m.find(y=>typeof y=="function")||Math.random,e=m.find(y=>[1,2,3].includes(y))||2,f()},c.strength=function(d){return arguments.length?(s=typeof d=="function"?d:b(+d),f(),c):s},c.distanceMin=function(d){return arguments.length?(a=d*d,c):Math.sqrt(a)},c.distanceMax=function(d){return arguments.length?(l=d*d,c):Math.sqrt(l)},c.theta=function(d){return arguments.length?(u=d*d,c):Math.sqrt(u)},c}function Ot(t){var e=b(.1),n,i,r;typeof t!="function"&&(t=b(t==null?0:+t));function s(a){for(var l=0,u=n.length,c;l<u;++l)c=n[l],c.vx+=(r[l]-c.x)*i[l]*a}function o(){if(n){var a,l=n.length;for(i=new Array(l),r=new Array(l),a=0;a<l;++a)i[a]=isNaN(r[a]=+t(n[a],a,n))?0:+e(n[a],a,n)}}return s.initialize=function(a){n=a,o()},s.strength=function(a){return arguments.length?(e=typeof a=="function"?a:b(+a),o(),s):e},s.x=function(a){return arguments.length?(t=typeof a=="function"?a:b(+a),o(),s):t},s}function Vt(t){var e=b(.1),n,i,r;typeof t!="function"&&(t=b(t==null?0:+t));function s(a){for(var l=0,u=n.length,c;l<u;++l)c=n[l],c.vy+=(r[l]-c.y)*i[l]*a}function o(){if(n){var a,l=n.length;for(i=new Array(l),r=new Array(l),a=0;a<l;++a)i[a]=isNaN(r[a]=+t(n[a],a,n))?0:+e(n[a],a,n)}}return s.initialize=function(a){n=a,o()},s.strength=function(a){return arguments.length?(e=typeof a=="function"?a:b(+a),o(),s):e},s.y=function(a){return arguments.length?(t=typeof a=="function"?a:b(+a),o(),s):t},s}function jt(t){var e=b(.1),n,i,r;typeof t!="function"&&(t=b(t==null?0:+t));function s(a){for(var l=0,u=n.length,c;l<u;++l)c=n[l],c.vz+=(r[l]-c.z)*i[l]*a}function o(){if(n){var a,l=n.length;for(i=new Array(l),r=new Array(l),a=0;a<l;++a)i[a]=isNaN(r[a]=+t(n[a],a,n))?0:+e(n[a],a,n)}}return s.initialize=function(a){n=a,o()},s.strength=function(a){return arguments.length?(e=typeof a=="function"?a:b(+a),o(),s):e},s.z=function(a){return arguments.length?(t=typeof a=="function"?a:b(+a),o(),s):t},s}function Q(t){let e=0,n=0,i=0,r=0;for(let[,s]of t)e+=s[0],n+=s[1],i+=s[2],r++;return r===0?[0,0,0]:[e/r,n/r,i/r]}var nt=1;function O(t,e){let n=new Map;for(let i=0;i<t.nodes.length;i++)n.set(t.nodes[i].id,e[i]);return{positions:n}}function Gn(t,e){let n=t.nodes.length;if(n===0)return{positions:new Map};let i=Q(t.positions),r=e?.spacing??nt,s=e?.radius??Math.max(r,n*r/(2*Math.PI)),o=Math.PI*2/n,a=[];for(let l=0;l<n;l++)a.push([s*Math.cos(l*o)+i[0],s*Math.sin(l*o)+i[1],0]);return O(t,a)}function Un(t,e){let n=t.nodes.length;if(n===0)return{positions:new Map};let i=Q(t.positions),r=e?.columns&&e.columns>0?e.columns:Math.ceil(Math.sqrt(n)),s=e?.spacing??nt,o=s*(r-1),a=[];for(let l=0;l<n;l++)a.push([l%r*s-o/2+i[0],-Math.floor(l/r)*s+o/2+i[1],0]);return O(t,a)}function $n(t,e){let n=t.nodes.length;if(n===0)return{positions:new Map};let i=Q(t.positions),r=e?.axis??"x",s=e?.spacing??nt,o=s*(n-1),a=[];for(let l=0;l<n;l++){let u=n>1?-o/2+l*s:0,c=[i[0],i[1],i[2]],f=r==="x"?0:r==="y"?1:2;c[f]=u+i[f],a.push(c)}return O(t,a)}function On(t,e){let n=t.nodes.length;if(n===0)return{positions:new Map};let i=Q(t.positions),r=e?.spacing??1.5,s=r/(2*Math.PI),o=2*Math.PI,a=[];for(let l=0;l<n;l++){let u=s*o;a.push([u*Math.cos(o)+i[0],u*Math.sin(o)+i[1],0]),o+=r/u}return O(t,a)}function Vn(t,e){let n=t.nodes.length;if(n===0)return{positions:new Map};let i=Q(t.positions),r=Math.cbrt(n),s=Math.floor(r),o=Math.ceil(r),a=e?.size??(n-Math.pow(s,3)>Math.pow(o,3)-n?o:s),l=e?.spacing??nt,u=l*Math.max(a-1,0),c=[];for(let f=0;f<n;f++)c.push([f%a*l-u/2+i[0],-(Math.floor(f/a)%a)*l+u/2+i[1],-Math.floor(f/(a*a))*l+u/2+i[2]]);return O(t,c)}function jn(t,e){let n=t.nodes.length;if(n<=1){let l=new Map;return n===1&&l.set(t.nodes[0].id,t.positions.get(t.nodes[0].id)??[0,0,0]),{positions:l}}let i=Q(t.positions),r=e?.spacing??nt,s=e?.density!==void 0?Math.sqrt(n/(4*Math.PI*e.density)):r*Math.sqrt(n/(4*Math.PI)),o=e?.radius??Math.max(r,s),a=[];for(let l=0;l<n;l++){let u=Math.acos(1-(2*(l+1)-1)/n),c=Math.sqrt(n*Math.PI)*u;a.push([o*Math.sin(u)*Math.cos(c)+i[0],o*Math.sin(u)*Math.sin(c)+i[1],o*Math.cos(u)+i[2]])}return O(t,a)}function Hn(t,e){let n=t.nodes.length;if(n===0)return{positions:new Map};let i=e?.spacing??nt,r=e?.range??Math.max(i,i*Math.cbrt(n)/2),s=e?.seed??42;function o(){s|=0,s=s+1831565813|0;let l=Math.imul(s^s>>>15,1|s);return l=l+Math.imul(l^l>>>7,61|l)^l,((l^l>>>14)>>>0)/4294967296}let a=[];for(let l=0;l<n;l++)a.push([(o()-.5)*r*2,(o()-.5)*r*2,(o()-.5)*r*2]);return O(t,a)}function Wn(t,e){if(t.nodes.length===0)return{positions:new Map};let i=e?.axis??"x",r=(e?.degrees??90)*Math.PI/180,s=Q(t.positions),o=[];for(let a of t.nodes){let l=t.positions.get(a.id)??[0,0,0],u=l[0]-s[0],c=l[1]-s[1],f=l[2]-s[2],h,p,d,m=Math.cos(r),y=Math.sin(r);i==="x"?(h=u,p=c*m-f*y,d=c*y+f*m):i==="y"?(h=u*m+f*y,p=c,d=-u*y+f*m):(h=u*m-c*y,p=u*y+c*m,d=f),o.push([h+s[0],p+s[1],d+s[2]])}return O(t,o)}function Qn(t,e){if(t.nodes.length===0)return{positions:new Map};let i=e?.factor,r=i??e?.x??1,s=i??e?.y??1,o=i??e?.z??1,a=Q(t.positions),l=[];for(let u of t.nodes){let c=t.positions.get(u.id)??[0,0,0];l.push([c[0]+(c[0]-a[0])*(r-1),c[1]+(c[1]-a[1])*(s-1),c[2]+(c[2]-a[2])*(o-1)])}return O(t,l)}function Kn(t,e){if(t.nodes.length===0)return{positions:new Map};let i=e?.x??0,r=e?.y??0,s=e?.z??0,o=[];for(let a of t.nodes){let l=t.positions.get(a.id)??[0,0,0];o.push([l[0]+i,l[1]+r,l[2]+s])}return O(t,o)}function Jn(t,e){if(t.nodes.length===0)return{positions:new Map};let i=e?.axis??"x",r=i==="x"?0:i==="y"?1:2,s=1/0,o=-1/0;for(let u of t.nodes){let c=t.positions.get(u.id)??[0,0,0];c[r]<s&&(s=c[r]),c[r]>o&&(o=c[r])}let a=(s+o)/2,l=[];for(let u of t.nodes){let c=t.positions.get(u.id)??[0,0,0],f=[c[0],c[1],c[2]];f[r]=a,l.push(f)}return O(t,l)}function ti(t,e){let{depth:n=100,mode:i="tree",orientation:r="right",alongRelationships:s=[]}=e??{},o=e?.spacing??nt,a=e?.spacing===void 0?e?.edgeLength:void 0,l=t.nodes;if(l.length===0)return{positions:new Map};let u=new Set;for(let[v]of t.positions)u.add(v);let c=new Map,f=new Map;for(let v of t.edges)!u.has(v.source)||!u.has(v.target)||(f.set(v.id,v),c.has(v.source)||c.set(v.source,[]),c.has(v.target)||c.set(v.target,[]),c.get(v.source).push({nodeId:v.target,relationship:v.relationship}),c.get(v.target).push({nodeId:v.source,relationship:v.relationship}));let h=s.length>0?new Set(Array.from(c.entries()).filter(([,v])=>v.some(({relationship:k})=>s.includes(k))).map(([v])=>v)):u,p=l.filter(v=>h.has(v.id));if(p.length===0)return{positions:new Map};let d=new Map,m=p.map(v=>[{from:"",to:v.id}]),y=p.map(v=>[[v.id]]),g=p.map(()=>1),w=p.map(()=>[1]),x=p.map(v=>v.id),_=1;for(;_<=n&&ut.sum(y.map(v=>v[_-1]?.length??0))>0;)y.forEach((v,k)=>{let A=v[_-1];if(!A)return;let N=[];A.forEach(E=>{let S=c.get(E)??[],z=S.map(({nodeId:I})=>I);s.length>0&&(z=S.filter(({relationship:I})=>s.includes(I)).map(({nodeId:I})=>I)),z=ut.difference(ut.intersection(z,Array.from(h)),x),z.forEach(I=>{m[k].push({from:E,to:I}),N.push(I),x.push(I)})}),v[_]=N,N.length>0&&(w[k].push(N.length),g[k]++)}),_++;let M=Et().id(v=>v.to).parentId(v=>v.from||null);return p.forEach((v,k)=>{let A=t.positions.get(v.id)??[0,0,0];if(m[k].length<=1){d.set(v.id,[A[0],A[1],A[2]]);return}let N;try{N=M(m[k])}catch{d.set(v.id,[A[0],A[1],A[2]]);return}let E=Math.max(...w[k],1),S=Math.max(g[k]-1,1),z=Math.max(E-1,1),I,Y;i==="rings"?(I=2*Math.PI,a!==void 0?Y=a*S:Y=Math.max(o,o*E/(2*Math.PI))):a!==void 0?(I=a*E*.2*Math.pow(g[k],.3),Y=a*S):(I=o*z,Y=o*S);let q=ft().size([I,Y])(N);ln(i,r,q,q,A,d)}),{positions:d}}function ln(t,e,n,i,r,s){let o=i.id,a,l;if(t==="tree")switch(e){case"up":a=i.x+r[0]-n.x,l=i.y+r[1]+n.y;break;case"down":a=-i.x+r[0]+n.x,l=-i.y+r[1]-n.y;break;case"right":a=i.y+r[0]-n.y,l=-i.x+r[1]+n.x;break;case"left":a=-i.y+r[0]+n.y,l=i.x+r[1]-n.x;break}else switch(e){case"down":a=r[0]+i.y*Math.cos(i.x+Math.PI/2),l=r[1]+i.y*Math.sin(i.x+Math.PI/2);break;case"up":a=r[0]+i.y*Math.cos(i.x+3*Math.PI/2),l=r[1]+i.y*Math.sin(i.x+3*Math.PI/2);break;case"right":a=r[0]+i.y*Math.cos(i.x+Math.PI),l=r[1]+i.y*Math.sin(i.x+Math.PI);break;case"left":a=r[0]+i.y*Math.cos(i.x),l=r[1]+i.y*Math.sin(i.x);break}if(s.set(o,[a,l,r[2]]),i.children)for(let u of i.children)ln(t,e,n,u,r,s)}var zt=1.5,Wt=3;function At(t,e){return e==="category"?t.category:t.properties?.[e]}function It(t,e,n){let i=n&&n.length?new Set(n):null,r=new Set,s=[],o=t.size;for(let a of e){if(i&&!i.has(a.relationship))continue;let l=t.get(a.source),u=t.get(a.target);if(l===void 0||u===void 0||l===u)continue;let c=l*o+u;r.has(c)||(r.add(c),s.push([l,u]))}return s}function cn(t,e){let n=[],i=new Set;for(let r of t)r!=null&&!i.has(r)&&(i.add(r),n.push(r));if(e){let r=e.filter(o=>i.has(o)),s=new Set(r);return[...r,...n.filter(o=>!s.has(o))]}return n.every(r=>typeof r=="number")?[...n].sort((r,s)=>r-s):n}function Qt(t,e,n){switch(t){case"BT":return[n,e];case"LR":return[e,-n];case"RL":return[-e,-n];default:return[n,-e]}}function St(t,e){if(e.size===0)return e;let n=0,i=0,r=0;for(let f of t.nodes){let h=t.positions.get(f.id);h&&(n+=h[0],i+=h[1],r++)}r&&(n/=r,i/=r);let s=1/0,o=-1/0,a=1/0,l=-1/0;for(let f of e.values())f[0]<s&&(s=f[0]),f[0]>o&&(o=f[0]),f[1]<a&&(a=f[1]),f[1]>l&&(l=f[1]);let u=n-(s+o)/2,c=i-(a+l)/2;for(let f of e.values())f[0]+=u,f[1]+=c;return e}function un(t,e,n){let i=t.length,r=Array.from({length:i},()=>[]),s=new Int32Array(i);for(let[c,f]of e)r[c].push(f),s[f]++;let o;if(n&&n.length){let c=new Set(n);o=[],t.forEach((f,h)=>{c.has(f.id)&&o.push(h)})}else{o=[];for(let c=0;c<i;c++)s[c]===0&&o.push(c);if(!o.length&&i){let c=0;for(let f=1;f<i;f++)r[f].length>r[c].length&&(c=f);o.push(c)}}let a=Array.from({length:i},()=>[]),l=new Uint8Array(i),u=c=>{l[c]=1;let f=[c];for(let h=0;h<f.length;h++){let p=f[h];for(let d of r[p])l[d]||(l[d]=1,a[p].push(d),f.push(d))}};for(let c of o)l[c]||u(c);for(let c=0;c<2;c++)for(let f=0;f<i;f++)l[f]||c===0&&s[f]>0||(o.push(f),u(f));return{roots:o.filter((c,f)=>o.indexOf(c)===f),children:a}}function fn(t,e){let n=t.children.length,i=u=>({i:u,children:[]}),r={i:-1,children:[]},s=[];for(let u of t.roots){let c=i(u);r.children.push(c),s.push(c)}for(;s.length;){let u=s.pop();for(let c of t.children[u.i]){let f=i(c);u.children.push(f),s.push(f)}}let o=st(r,u=>u.children);ft().nodeSize([e,1]).separation((u,c)=>u.parent===c.parent?1:1.5)(o);let a=new Int32Array(n),l=new Float64Array(n);return o.each(u=>{u.data.i<0||(a[u.data.i]=u.depth-1,l[u.data.i]=u.x)}),{depth:a,across:l}}function ei(t,e={}){let n=t.nodes,i=new Map(n.map((f,h)=>[f.id,h])),r=un(n,It(i,t.edges,e.relationships),e.roots),s=e.nodeGap??zt,o=e.levelGap??Wt,a=e.direction??"TB",{depth:l,across:u}=fn(r,s),c=new Map;return n.forEach((f,h)=>{let[p,d]=Qt(a,l[h]*o,u[h]);c.set(f.id,[p,d,0])}),{positions:St(t,c)}}function ni(t,e={}){let n=t.nodes,i=new Map(n.map((x,_)=>[x.id,_])),r=un(n,It(i,t.edges,e.relationships),e.roots),s=e.nodeGap??zt,o=e.levelGap??Wt,a=(e.sweep??360)*Math.PI/180,l=(e.startAngle??90)*Math.PI/180,{depth:u,across:c}=fn(r,s),f=r.roots.length===1,h=1/0,p=-1/0,d=0;for(let x=0;x<n.length;x++)c[x]<h&&(h=c[x]),c[x]>p&&(p=c[x]),u[x]>d&&(d=u[x]);let m=Math.abs(a-2*Math.PI)<1e-6,y=Math.max(p-h+(m?s:0),1e-9),g=Math.max(o,y/a/Math.max(d+(f?0:1),1)),w=new Map;return n.forEach((x,_)=>{let M=(u[_]+(f?0:1))*g,v=l-(c[_]-h)/y*a;w.set(x.id,[M*Math.cos(v),M*Math.sin(v),0])}),{positions:St(t,w)}}function ii(t){if(t.length<2)return 0;let e=t.slice(),n=new Array(e.length),i=0;for(let r=1;r<e.length;r*=2)for(let s=0;s<e.length-r;s+=2*r){let o=s+r,a=Math.min(s+2*r,e.length),l=s,u=o,c=s;for(;l<o&&u<a;)e[l]<=e[u]?n[c++]=e[l++]:(n[c++]=e[u++],i+=o-l);for(;l<o;)n[c++]=e[l++];for(;u<a;)n[c++]=e[u++];for(let f=s;f<a;f++)e[f]=n[f]}return i}function ri(t,e){let n=t.length,i=new Array(n);i[0]=0;for(let l=1;l<n;l++)i[l]=i[l-1]+e[l-1];let r=[],s=[];for(let l=0;l<n;l++)for(r.push(t[l]-i[l]),s.push(1);r.length>1&&r[r.length-2]/s[s.length-2]>r[r.length-1]/s[s.length-1];){let u=r.pop(),c=s.pop();r[r.length-1]+=u,s[s.length-1]+=c}let o=new Array(n),a=0;for(let l=0;l<r.length;l++){let u=r[l]/s[l];for(let c=0;c<s[l];c++,a++)o[a]=u+i[a]}return o}function si(t,e){let n=Array.from({length:t},()=>[]);e.forEach(([h,p],d)=>n[h].push(d));let i=new Uint8Array(t),r=new Uint8Array(e.length);for(let h=0;h<t;h++){if(i[h])continue;let p=[[h,0]];for(i[h]=1;p.length;){let d=p[p.length-1],[m,y]=d;if(y<n[m].length){d[1]++;let g=n[m][y],w=e[g][1];i[w]===1?r[g]=1:i[w]===0&&(i[w]=1,p.push([w,0]))}else i[m]=2,p.pop()}}let s=e.map(([h,p],d)=>r[d]?[p,h]:[h,p]),o=Array.from({length:t},()=>[]),a=Array.from({length:t},()=>[]),l=new Int32Array(t);for(let[h,p]of s)o[h].push(p),a[p].push(h),l[p]++;let u=[];for(let h=0;h<t;h++)l[h]===0&&u.push(h);for(let h=0;h<u.length;h++)for(let p of o[u[h]])--l[p]===0&&u.push(p);let c=new Array(t).fill(0);for(let h of u)for(let p of o[h])c[p]=Math.max(c[p],c[h]+1);for(let h=u.length-1;h>=0;h--){let p=u[h];if(a[p].length||!o[p].length)continue;let d=1/0;for(let m of o[p])d=Math.min(d,c[m]);c[p]=d-1}let f=Math.min(...c);return{rank:c.map(h=>h-f),dag:s}}function oi(t,e,n){let i=e.slice(),r=new Array(t).fill(!1),s=Array.from({length:t},()=>[]),o=Array.from({length:t},()=>[]),a=(h,p)=>{o[h].push(p),s[p].push(h)};for(let[h,p]of n){if(i[p]-i[h]<1)continue;let d=h;for(let m=i[h]+1;m<i[p];m++){let y=i.length;i.push(m),r.push(!0),s.push([]),o.push([]),a(d,y),d=y}a(d,p)}let l=i.reduce((h,p)=>Math.max(h,p),0),u=Array.from({length:l+1},()=>[]),c=new Uint8Array(i.length),f=h=>{let p=[h];for(;p.length;){let d=p.pop();if(!c[d]){c[d]=1,u[i[d]].push(d);for(let m=o[d].length-1;m>=0;m--)c[o[d][m]]||p.push(o[d][m])}}};for(let h=0;h<t;h++)s[h].length||f(h);for(let h=0;h<i.length;h++)c[h]||f(h);return{rank:i,isDummy:r,up:s,down:o,layers:u}}function on(t,e){let n=0;for(let i=0;i+1<t.layers.length;i++){let r=[];for(let s of t.layers[i])for(let o of t.down[s])r.push([e[s],e[o]]);r.sort((s,o)=>s[0]-o[0]||s[1]-o[1]),n+=ii(r.map(s=>s[1]))}return n}function ai(t,e){let n=new Int32Array(t.rank.length);(()=>{for(let o of t.layers)o.forEach((a,l)=>{n[a]=l})})();let r=on(t,n),s=t.layers.map(o=>o.slice());for(let o=0;o<e&&r>0;o++){let a=o%2===0,l=a?Array.from({length:t.layers.length-1},(c,f)=>f+1):Array.from({length:t.layers.length-1},(c,f)=>t.layers.length-2-f);for(let c of l){let f=t.layers[c],h=new Map;for(let p of f){let d=a?t.up[p]:t.down[p];h.set(p,d.length?d.reduce((m,y)=>m+n[y],0)/d.length:n[p])}f.sort((p,d)=>h.get(p)-h.get(d)||n[p]-n[d]),f.forEach((p,d)=>{n[p]=d})}let u=on(t,n);u<r&&(r=u,s=t.layers.map(c=>c.slice()))}t.layers=s}function li(t,e){let n=new Float64Array(t.rank.length),i=(o,a)=>e*((t.isDummy[o]?.4:1)+(t.isDummy[a]?.4:1))/2,r=o=>o.slice(1).map((a,l)=>i(o[l],a));for(let o of t.layers){let a=r(o),l=0,u=[0];for(let c of a)u.push(l+=c);o.forEach((c,f)=>{n[c]=u[f]-l/2})}let s=o=>o.reduce((a,l)=>a+n[l],0)/o.length;for(let o=0;o<8;o++){let a=o%2===0,l=t.layers.map((u,c)=>a?c:t.layers.length-1-c);for(let u of l){let c=t.layers[u];if(!c.length)continue;let f=c.map(p=>{let d=t.isDummy[p]||o===7?[...t.up[p],...t.down[p]]:a?t.up[p]:t.down[p];return d.length?s(d):n[p]}),h=ri(f,r(c));c.forEach((p,d)=>{n[p]=h[d]})}}return n}function ci(t,e={}){let n=t.nodes,i=n.length;if(!i)return{positions:new Map};let r=new Map(n.map((p,d)=>[p.id,d])),s=It(r,t.edges,e.relationships),o,a;if(e.rankBy){let p=n.map(y=>At(y,e.rankBy)),d=cn(p,e.rankOrder),m=new Map(d.map((y,g)=>[y,g]));o=p.map(y=>m.get(y)??d.length),a=s.map(([y,g])=>o[y]<=o[g]?[y,g]:[g,y])}else({rank:o,dag:a}=si(i,s));let l=oi(i,o,a);ai(l,e.sweeps??24);let u=li(l,e.nodeGap??zt),c=e.levelGap??Wt,f=e.direction??"TB",h=new Map;return n.forEach((p,d)=>{let[m,y]=Qt(f,l.rank[d]*c,u[d]);h.set(p.id,[m,y,0])}),{positions:St(t,h)}}function ui(t,e){let n=t.nodes;if(!n.length)return{positions:new Map};if(!e||!e.by)throw new Error("[columnsLayout] option `by` is required");let i=new Map(n.map((w,x)=>[w.id,x])),r=n.map(w=>At(w,e.by)),s=cn(r,e.order),o=new Map(s.map((w,x)=>[w,x])),a=r.map(w=>o.get(w)??s.length),l=Math.max(...a)+1,u=Array.from({length:l},()=>[]);n.forEach((w,x)=>u[a[x]].push(x));let c=n.map(()=>[]);for(let[w,x]of It(i,t.edges,e.relationships))a[w]!==a[x]&&(c[w].push(x),c[x].push(w));let f=e.sortBy??"barycenter",h=new Float64Array(n.length),p=w=>w.forEach((x,_)=>{h[x]=_-(w.length-1)/2});if(u.forEach(p),f==="barycenter")for(let w=0;w<12;w++){let x=u.map((_,M)=>w%2===0?M:l-1-M);for(let _ of x){let M=u[_],v=new Map(M.map(k=>[k,c[k].length?c[k].reduce((A,N)=>A+h[N],0)/c[k].length:h[k]]));M.sort((k,A)=>v.get(k)-v.get(A)||h[k]-h[A]),p(M)}}else if(f==="degree")for(let w of u)w.sort((x,_)=>c[_].length-c[x].length||x-_),p(w);else if(f!=="none")for(let w of u)w.sort((x,_)=>{let M=At(n[x],f),v=At(n[_],f);return typeof M=="number"&&typeof v=="number"?M-v||x-_:String(M??"").localeCompare(String(v??""))||x-_}),p(w);let d=e.nodeGap??zt,m=e.levelGap??4,y=e.direction??"LR",g=new Map;return n.forEach((w,x)=>{let[_,M]=Qt(y,a[x]*m,h[x]*d);g.set(w.id,[_,M,0])}),{positions:St(t,g)}}function et(t){if(t==null)return null;let e=Number(t);return Number.isNaN(e)?null:e}function at(t,e,n){let[i,r]=e,[s,o]=n;return r===i?(s+o)/2:s+(t-i)/(r-i)*(o-s)}function lt(t,e,n){let i=Math.max(e[0],1e-10),r=Math.max(e[1],1e-10),s=Math.max(t,1e-10),[o,a]=n;return r===i?(o+a)/2:o+(Math.log(s)-Math.log(i))/(Math.log(r)-Math.log(i))*(a-o)}function fi(t,e,n){let i=n??et,r=1/0,s=-1/0;for(let o of t){let a=o.properties?.[e],l=i(a);l!=null&&(l<r&&(r=l),l>s&&(s=l))}return r===1/0?[0,1]:r===s?[r-1,s+1]:[r,s]}function hi(t,e=5){let[n,i]=t,r=i-n;if(r===0)return[n-1,i+1];let s=r/e,o=Math.pow(10,Math.floor(Math.log10(s))),a=s/o,l;return a<=1.5?l=o:a<=3.5?l=2*o:a<=7.5?l=5*o:l=10*o,[Math.floor(n/l)*l,Math.ceil(i/l)*l]}function pi(t,e=5){let[n,i]=t;if(n===i)return[n];let s=(i-n)/e,o=Math.pow(10,Math.floor(Math.log10(s))),a=s/o,l;a<=1.5?l=o:a<=3.5?l=2*o:a<=7.5?l=5*o:l=10*o;let u=Math.ceil(n/l)*l,c=[];for(let f=u;f<=i+l*.001;f+=l)c.push(Math.round(f*1e10)/1e10);return c}var Ht=[{name:"1s",ms:1e3},{name:"5s",ms:5e3},{name:"15s",ms:15e3},{name:"30s",ms:3e4},{name:"1m",ms:6e4},{name:"5m",ms:3e5},{name:"15m",ms:9e5},{name:"30m",ms:18e5},{name:"1h",ms:36e5},{name:"3h",ms:108e5},{name:"6h",ms:216e5},{name:"12h",ms:432e5},{name:"1d",ms:864e5},{name:"3d",ms:2592e5},{name:"1w",ms:6048e5},{name:"1mo",ms:2592e6,calendarUnit:"month",calendarStep:1},{name:"3mo",ms:7776e6,calendarUnit:"month",calendarStep:3},{name:"6mo",ms:15552e6,calendarUnit:"month",calendarStep:6},{name:"1y",ms:31536e6,calendarUnit:"year",calendarStep:1},{name:"2y",ms:63072e6,calendarUnit:"year",calendarStep:2},{name:"5y",ms:15768e7,calendarUnit:"year",calendarStep:5},{name:"10y",ms:31536e7,calendarUnit:"year",calendarStep:10},{name:"20y",ms:63072e7,calendarUnit:"year",calendarStep:20},{name:"50y",ms:15768e8,calendarUnit:"year",calendarStep:50}];function di(t,e=5){let[n,i]=t,r=i-n;if(r<=0)return[n];let s=r/e,o=Ht[Ht.length-1];for(let l of Ht)if(l.ms>=s*.6){o=l;break}let a=[];if(o.calendarUnit==="year"){let l=o.calendarStep,u=new Date(n),c=Math.ceil(u.getFullYear()/l)*l;for(;;){let f=new Date(c,0,1).getTime();if(f>i)break;f>=n&&a.push(f),c+=l}}else if(o.calendarUnit==="month"){let l=o.calendarStep,u=new Date(n),c=u.getFullYear(),f=Math.ceil(u.getMonth()/l)*l;for(;;){let h=new Date(c,f,1).getTime();if(h>i)break;h>=n&&a.push(h),f+=l,f>=12&&(c+=Math.floor(f/12),f=f%12)}}else{let l=o.ms,u=Math.ceil(n/l)*l;for(let c=u;c<=i;c+=l)a.push(c)}return a}function gi(t,e){let n=e[1]-e[0],i=new Date(t);return n>365*864e5*2?String(i.getFullYear()):n>60*864e5?`${i.getFullYear()}-${String(i.getMonth()+1).padStart(2,"0")}`:n>2*864e5?`${i.getMonth()+1}/${i.getDate()}`:n>2*36e5?`${String(i.getHours()).padStart(2,"0")}:${String(i.getMinutes()).padStart(2,"0")}`:`${String(i.getHours()).padStart(2,"0")}:${String(i.getMinutes()).padStart(2,"0")}:${String(i.getSeconds()).padStart(2,"0")}`}function ct(t,e,n){let i=t.domain??fi(e,t.property,t.parse);t.nice&&!t.domain&&(i=hi(i,t.tickCount));let s=(i[1]-i[0])*n,o=[i[0]-s,i[1]+s],a;t.tickValues?a=t.tickValues:t.isDate?a=di(i,t.tickCount):a=pi(i,t.tickCount);let l=t.tickFormat;return!l&&t.isDate&&(l=u=>gi(u,i)),{axisInfo:{property:t.property,label:t.property,domain:o,ticks:a,scale:t.scale,tickFormat:l},paddedDomain:o}}function mi(t,e){let{propertyX:n,propertyY:i,propertyZ:r,range:s=[-2,2],scaleX:o="linear",scaleY:a="linear",scaleZ:l="linear",padding:u=.05}=e,c=e.parseX??et,f=e.parseY??et,h=e.parseZ??et,p=!!n,d=!!i,m=!!r,y=t.nodes,g=new Map,w=new Set,x=[];for(let I of y){let Y=0,V=0,q=0,U=!1;if(p){let X=c(I.properties?.[n]);X==null?U=!0:Y=X}if(d&&!U){let X=f(I.properties?.[i]);X==null?U=!0:V=X}if(m&&!U){let X=h(I.properties?.[r]);X==null?U=!0:q=X}U?w.add(I.id):x.push({id:I.id,x:Y,y:V,z:q})}let _=p?ct({property:n,scale:o,domain:e.domainX,parse:c,tickFormat:e.tickFormatX,tickCount:e.tickCountX??5,tickValues:e.tickValuesX,nice:e.niceX??!0,isDate:e.dateAxisX??!1},y,u):null,M=d?ct({property:i,scale:a,domain:e.domainY,parse:f,tickFormat:e.tickFormatY,tickCount:e.tickCountY??5,tickValues:e.tickValuesY,nice:e.niceY??!0,isDate:e.dateAxisY??!1},y,u):null,v=m?ct({property:r,scale:l,domain:e.domainZ,parse:h,tickFormat:e.tickFormatZ,tickCount:e.tickCountZ??5,tickValues:e.tickValuesZ,nice:e.niceZ??!0,isDate:e.dateAxisZ??!1},y,u):null,k=o==="log"?lt:at,A=a==="log"?lt:at,N=l==="log"?lt:at,E=e.spread??1,S=[s[0]*E,s[1]*E],z=s[0];for(let I of x){let Y=_?k(I.x,_.paddedDomain,S):z,V=M?A(I.y,M.paddedDomain,S):z,q=v?N(I.z,v.paddedDomain,S):0;g.set(I.id,[Y,V,q])}return{positions:g,axes:{x:_?.axisInfo,y:M?.axisInfo,z:v?.axisInfo},range:S,baseRange:s,excludedNodeIds:w}}function yi(t,e){let n=e.range??[-2,2],i=e.spread??1,r=[n[0]*i,n[1]*i],s=e.padding??.05,o=n[0],a=e.unmappedMode??"hide",l=new Map;for(let p of e.mappings)l.set(p.category,p);let u=new Map;for(let p of t.nodes){let d=p.category,m=u.get(d);m||(m=[],u.set(d,m)),m.push(p)}let c=new Map,f=new Set,h={};for(let[p,d]of u){let m=l.get(p);if(!m){if(a==="hide")for(let D of d)f.add(D.id);else{let D;a==="boundary"?D=n[0]:D=(n[0]+n[1])/2;for(let T of d)c.set(T.id,[D,D,0])}continue}let y=!!m.propertyX,g=!!m.propertyY,w=!!m.propertyZ,x=m.scaleX??"linear",_=m.scaleY??"linear",M=m.scaleZ??"linear",v=m.parseX??et,k=m.parseY??et,A=m.parseZ??et,N=m.tickCountX??e.tickCountX??5,E=m.tickCountY??e.tickCountY??5,S=m.tickCountZ??e.tickCountZ??5,z=m.niceX??e.niceX??!0,I=m.niceY??e.niceY??!0,Y=m.niceZ??e.niceZ??!0,V=[];for(let D of d){let T=0,G=0,L=0,rt=!1;if(y){let W=v(D.properties?.[m.propertyX]);W==null?rt=!0:T=W}if(g&&!rt){let W=k(D.properties?.[m.propertyY]);W==null?rt=!0:G=W}if(w&&!rt){let W=A(D.properties?.[m.propertyZ]);W==null?rt=!0:L=W}rt?f.add(D.id):V.push({id:D.id,x:T,y:G,z:L})}let q=y?ct({property:m.propertyX,scale:x,domain:m.domainX,parse:v,tickFormat:m.tickFormatX,tickCount:N,tickValues:m.tickValuesX,nice:z,isDate:m.dateAxisX??!1},d,s):null,U=g?ct({property:m.propertyY,scale:_,domain:m.domainY,parse:k,tickFormat:m.tickFormatY,tickCount:E,tickValues:m.tickValuesY,nice:I,isDate:m.dateAxisY??!1},d,s):null,X=w?ct({property:m.propertyZ,scale:M,domain:m.domainZ,parse:A,tickFormat:m.tickFormatZ,tickCount:S,tickValues:m.tickValuesZ,nice:Y,isDate:m.dateAxisZ??!1},d,s):null,Z=x==="log"?lt:at,it=_==="log"?lt:at,C=M==="log"?lt:at;for(let D of V){let T=q?Z(D.x,q.paddedDomain,r):o,G=U?it(D.y,U.paddedDomain,r):o,L=X?C(D.z,X.paddedDomain,r):0;c.set(D.id,[T,G,L])}h[p]={x:q?.axisInfo,y:U?.axisInfo,z:X?.axisInfo}}return{positions:c,axes:{x:void 0,y:void 0,z:void 0},range:r,baseRange:n,excludedNodeIds:f,categoryAxes:h}}var xi=/^[a-z][a-zA-Z0-9]*$/,_i=/^[a-z][a-z0-9-]*:[A-Za-z][A-Za-z0-9_-]*$/,wi=class hn{constructor(){this.entries=new Map}register(e,n,i={}){if(!_i.test(e))throw new Error(`[LayoutRegistry] invalid layout name "${e}": extension layouts must be named "<pack>:<name>" (e.g. "acme:rack")`);return this.add(e,n,!1,i)}registerBuiltin(e,n,i){if(!xi.test(e))throw new Error(`[LayoutRegistry] invalid built-in layout name "${e}"`);this.add(e,n,!0,{description:i})}add(e,n,i,r){if(typeof n!="function")throw new Error(`[LayoutRegistry] layout "${e}" must be a function`);let s=this.entries.get(e);if(s&&(s.builtin||!r.replace))throw new Error(`[LayoutRegistry] layout "${e}" is already registered`);let o={name:e,fn:n,builtin:i,description:r.description};return this.entries.set(e,o),()=>{this.entries.get(e)===o&&this.entries.delete(e)}}has(e){return this.entries.has(e)}get(e){return this.entries.get(e)}list(){let e=[...this.entries.values()];return[...e.filter(n=>n.builtin),...e.filter(n=>!n.builtin)]}execute(e,n,i){let r=this.entries.get(e);if(!r)throw new Error(`[LayoutRegistry] unknown layout "${e}". Registered: ${[...this.entries.keys()].join(", ")}`);return r.fn(n,i)}fork(){let e=new hn;for(let[n,i]of this.entries)e.entries.set(n,i);return e}};function vi(){let t=new wi;return t.registerBuiltin("circle",Gn,"Nodes on a circle."),t.registerBuiltin("grid",Un,"Nodes on a 2-D grid."),t.registerBuiltin("line",$n,"Nodes along an axis."),t.registerBuiltin("spiral",On,"Nodes on a spiral."),t.registerBuiltin("cube",Vn,"Nodes in a 3-D lattice."),t.registerBuiltin("sphere",jn,"Nodes on a sphere."),t.registerBuiltin("scatter",Hn,"Nodes scattered randomly in a range."),t.registerBuiltin("ego",ti,"Tree or rings around root node(s)."),t.registerBuiltin("tree",ei,"Tidy tree (org chart, directory); forests supported."),t.registerBuiltin("radialTree",ni,"Tidy tree in polar form, root in the centre."),t.registerBuiltin("layered",ci,"Layered (Sugiyama) layout for directed graphs: lineage, call chains, workflows."),t.registerBuiltin("columns",ui,"One column per property value, crossings reduced inside columns."),t.registerBuiltin("rotate",Wn,"Rotate current positions (transform)."),t.registerBuiltin("scale",Qn,"Scale current positions (transform)."),t.registerBuiltin("shift",Kn,"Translate current positions (transform)."),t.registerBuiltin("alignBy",Jn,"Align nodes by an axis (transform)."),t.registerBuiltin("plotScatter",mi,"Scatter plot by two properties."),t.registerBuiltin("plotMultiCategoryScatter",yi,"Scatter plot with category axes."),t}var pn=vi();function to(){return pn.fork()}function eo(t,e){let n=pn.get(e.type);return n?n.fn(t,e.options):{positions:new Map}}var Mi={linear:t=>t,easeIn:t=>t*t,easeOut:t=>t*(2-t),easeInOut:t=>t<.5?2*t*t:-1+(4-2*t)*t},no=class{constructor(t,e,n){this._done=!1,this.startPositions=t,this.endPositions=e,this.startTime=performance.now(),this.duration=n?.duration??800,this.easingFn=Mi[n?.easing??"easeInOut"],this.onComplete=n?.onComplete}get done(){return this._done}tick(t){let e=t-this.startTime,n=Math.min(e/this.duration,1),i=this.easingFn(n),r=new Map;for(let[s,o]of this.endPositions){let a=this.startPositions.get(s)??o;r.set(s,[a[0]+(o[0]-a[0])*i,a[1]+(o[1]-a[1])*i,a[2]+(o[2]-a[2])*i])}return n>=1&&!this._done&&(this._done=!0,this.onComplete?.()),r}},io=class{constructor(t,e,n={}){this.mode="cpu",this._status="idle",this._snapshot=null,this._positions=new Map,this._listeners=new Map,this._tickCount=0,this.id=t,this.compute=e,this._settings={dimensions:3,...n}}get status(){return this._status}getCapabilities(){return{mode:this.mode,supportsGpuTexture:!1,supportsCpuReadback:!0,supportsIncrementalDelta:!1,supportsPinning:!1,supportsDimensions:!0}}init(t,e){this._status!=="disposed"&&(this._snapshot=t,e&&(this._settings={...this._settings,...e}),this._positions=this.compute(this._snapshot,this._settings),this._status="idle")}applyDelta(t){if(!(!this._snapshot||this._status==="disposed")&&t.positionPatches){for(let e of t.positionPatches)this._positions.set(e.id,e.position);this._emit("positionsChanged",{nodeIds:t.positionPatches.map(e=>e.id)})}}tick(t){return this._tickCount++,{tick:this._tickCount,didChangePositions:!1,alpha:0}}start(){this._status!=="disposed"&&(this._status="running",this._emit("started",{}),this._status="stopped",this._emit("settled",{}))}stop(){this._status!=="disposed"&&(this._status="stopped",this._emit("stopped",{}))}dispose(){this._status="disposed",this._positions.clear(),this._snapshot=null,this._listeners.clear()}getSettings(){return{...this._settings}}updateSettings(t){this._settings={...this._settings,...t},this._snapshot&&this._status!=="disposed"&&(this._positions=this.compute(this._snapshot,this._settings),this._emit("positionsChanged",{}))}setDimensions(t){this.updateSettings({dimensions:t})}getReadback(){if(!this._snapshot)return{positions:null};let t=this._snapshot.nodes.length,e=new Float32Array(t*3);for(let n=0;n<t;n++){let i=this._snapshot.nodes[n].id,r=this._positions.get(i);r&&(e[n*3]=r.x,e[n*3+1]=r.y,e[n*3+2]=r.z)}return{positions:e}}getNodePosition(t){return this._positions.get(t)??null}setNodePosition(t,e){this._status!=="disposed"&&(this._positions.set(t,e),this._emit("positionsChanged",{nodeIds:[t]}))}pinNodes(t){}unpinNodes(t){}on(t,e){return this._listeners.has(t)||this._listeners.set(t,new Set),this._listeners.get(t).add(e),()=>this._listeners.get(t)?.delete(e)}_emit(t,e){this._listeners.get(t)?.forEach(n=>n(e))}};function an(t,e){let n=new Map(t.nodes.map(o=>[o.id,{...o}])),i=new Map(t.edges.map(o=>[o.id,{...o}]));for(let o of e.addNodes??[])n.set(o.id,o);for(let o of e.addEdges??[])i.set(o.id,o);for(let o of e.updateNodes??[]){let a=n.get(o.id);a&&n.set(o.id,{...a,...o.changes})}for(let o of e.updateEdges??[]){let a=i.get(o.id);a&&i.set(o.id,{...a,...o.changes})}for(let o of e.removeNodeIds??[])n.delete(o);for(let o of e.removeEdgeIds??[])i.delete(o);for(let o of e.positionPatches??[]){let a=n.get(o.id);a&&n.set(o.id,{...a,position:o.position})}for(let o of e.pinPatches??[]){let a=n.get(o.id);if(a){let l={...a,pinned:o.pinned};o.position&&(l.position=o.position),n.set(o.id,l)}}let r=Array.from(n.values()).map((o,a)=>({...o,index:a})),s=Array.from(i.values()).map((o,a)=>({...o,index:a}));return{...t,version:e.graphVersion,nodes:r,edges:s}}var j={dimensions:3,alpha:.6,alphaDecay:.1,velocityDecay:.3,charge:-.01,gravity:.1,collision:.15,linkDistance:.5,linkStrength:1,warmupTicks:0},so=class{constructor(t,e={}){this.mode="cpu",this._status="idle",this._snapshot=null,this._tickCount=0,this._listeners=new Map,this._simulation=null,this._simNodes=[],this._nodeIdToIndex=new Map,this._positions=new Float32Array(0),this.id=t,this._settings={...j,...e}}get status(){return this._status}getCapabilities(){return{mode:"cpu",supportsGpuTexture:!1,supportsCpuReadback:!0,supportsIncrementalDelta:!1,supportsPinning:!0,supportsDimensions:!0}}init(t,e){this._status!=="disposed"&&(this._snapshot=t,e&&(this._settings={...this._settings,...e}),this._buildSimulation(t),this._status="idle")}applyDelta(t){if(!this._snapshot||this._status==="disposed")return;if(t.addNodes&&t.addNodes.length>0||t.removeNodeIds&&t.removeNodeIds.length>0||t.addEdges&&t.addEdges.length>0||t.removeEdgeIds&&t.removeEdgeIds.length>0){this._snapshot=an(this._snapshot,t);let n=this._status==="running";this._buildSimulation(this._snapshot),n&&(this._status="running");return}if(t.positionPatches)for(let n of t.positionPatches){let i=this._nodeIdToIndex.get(n.id);if(i===void 0)continue;let r=this._simNodes[i];r.x=n.position.x,r.y=n.position.y,r.z=n.position.z}if(t.pinPatches)for(let n of t.pinPatches){let i=this._nodeIdToIndex.get(n.id);if(i===void 0)continue;let r=this._simNodes[i];if(n.pinned){let s=n.position??{x:r.x,y:r.y,z:r.z};r.fx=s.x,r.fy=s.y,r.fz=s.z}else r.fx=null,r.fy=null,r.fz=null}this._snapshot=an(this._snapshot,t)}tick(t){if(this._tickCount++,!this._simulation||this._status!=="running")return{tick:this._tickCount,didChangePositions:!1,alpha:0};this._simulation.tick(1),this._readPositionsFromSimulation();let e=this._simulation.alpha(),n={tick:this._tickCount,didChangePositions:!0,alpha:e};return this._emit("tick",n),e<(this._simulation.alphaMin?.()??.001)&&this._emit("settled",{}),n}start(){if(this._status!=="disposed"){if(this._simulation){let t=this._settings.alpha??j.alpha;this._simulation.alpha(t)}this._status="running",this._emit("started",{})}}stop(){this._status!=="disposed"&&(this._status="stopped",this._emit("stopped",{}))}dispose(){this._simulation&&(this._simulation.stop(),this._simulation=null),this._simNodes=[],this._nodeIdToIndex.clear(),this._positions=new Float32Array(0),this._snapshot=null,this._status="disposed",this._listeners.clear()}getSettings(){return{...this._settings}}updateSettings(t){this._settings={...this._settings,...t},this._simulation&&this._applySettingsToSimulation()}setDimensions(t){this._settings={...this._settings,dimensions:t},this._snapshot&&(this._snapshot={...this._snapshot,dimensions:t},this._buildSimulation(this._snapshot))}getReadback(){return{positions:this._positions.length>0?this._positions:null}}getNodePosition(t){let e=this._nodeIdToIndex.get(t);if(e===void 0)return null;let n=this._simNodes[e];return{x:n.x,y:n.y,z:n.z}}setNodePosition(t,e){if(this._status==="disposed")return;let n=this._nodeIdToIndex.get(t);if(n===void 0)return;let i=this._simNodes[n];i.x=e.x,i.y=e.y,i.z=e.z,i.fx=e.x,i.fy=e.y,i.fz=e.z;let r=n*4;this._positions[r]=e.x,this._positions[r+1]=e.y,this._positions[r+2]=e.z}pinNodes(t){if(this._status!=="disposed")for(let e of t){let n=this._nodeIdToIndex.get(e);if(n===void 0)continue;let i=this._simNodes[n];i.fx=i.x,i.fy=i.y,i.fz=i.z}}unpinNodes(t){if(this._status!=="disposed")for(let e of t){let n=this._nodeIdToIndex.get(e);if(n===void 0)continue;let i=this._simNodes[n];i.fx=null,i.fy=null,i.fz=null}}on(t,e){return this._listeners.has(t)||this._listeners.set(t,new Set),this._listeners.get(t).add(e),()=>this._listeners.get(t)?.delete(e)}_buildSimulation(t){let e=t.dimensions??this._settings.dimensions??3;this._simNodes=t.nodes.map(h=>{let p={id:h.id,x:h.position.x,y:h.position.y,z:h.position.z};return h.pinned&&(p.fx=h.position.x,p.fy=h.position.y,p.fz=h.position.z),p}),this._nodeIdToIndex=new Map;for(let h=0;h<this._simNodes.length;h++)this._nodeIdToIndex.set(this._simNodes[h].id,h);let n=[];for(let h of t.edges){let p=this._nodeIdToIndex.get(h.source),d=this._nodeIdToIndex.get(h.target);p!==void 0&&d!==void 0&&n.push({source:p,target:d})}let i=this._settings,r=i.charge??j.charge,s=i.gravity??j.gravity,o=i.linkDistance??j.linkDistance,a=i.linkStrength??j.linkStrength,l=i.collision??j.collision,u=i.alpha??j.alpha,c=i.alphaDecay??j.alphaDecay,f=i.velocityDecay??j.velocityDecay;this._simulation=Ut(this._simNodes,e).alpha(u).alphaDecay(c).velocityDecay(f).force("charge",$t().strength(r)).force("link",Yt(n).distance(o).strength(a)).force("x",Ot().strength(s)).force("y",Vt().strength(s)).force("z",jt().strength(e===2?0:s)).force("collision",Bt().radius(l)).stop(),this._positions=new Float32Array(this._simNodes.length*4),this._readPositionsFromSimulation()}_applySettingsToSimulation(){if(!this._simulation)return;let t=this._settings;if(t.charge!==void 0&&this._simulation.force("charge")?.strength(t.charge),t.linkDistance!==void 0&&this._simulation.force("link")?.distance(t.linkDistance),t.linkStrength!==void 0&&this._simulation.force("link")?.strength(t.linkStrength),t.gravity!==void 0){let e=t.dimensions??this._snapshot?.dimensions??3;this._simulation.force("x")?.strength(t.gravity),this._simulation.force("y")?.strength(t.gravity),this._simulation.force("z")?.strength(e===2?0:t.gravity)}t.collision!==void 0&&this._simulation.force("collision")?.radius(t.collision),t.alpha!==void 0&&this._simulation.alpha(t.alpha),t.alphaDecay!==void 0&&this._simulation.alphaDecay(t.alphaDecay),t.velocityDecay!==void 0&&this._simulation.velocityDecay(t.velocityDecay)}_readPositionsFromSimulation(){for(let t=0;t<this._simNodes.length;t++){let e=this._simNodes[t],n=t*4;this._positions[n]=e.x??0,this._positions[n+1]=e.y??0,this._positions[n+2]=e.z??0,this._positions[n+3]=1}}_emit(t,e){this._listeners.get(t)?.forEach(n=>n(e))}};export{Xt as a,Mt as b,Q as c,Gn as d,Un as e,$n as f,On as g,Vn as h,jn as i,Hn as j,Wn as k,Qn as l,Kn as m,Jn as n,ti as o,ei as p,ni as q,ci as r,ui as s,et as t,at as u,lt as v,fi as w,pi as x,mi as y,yi as z,wi as A,pn as B,to as C,eo as D,no as E,io as F,so as G};
2
+ //# sourceMappingURL=chunk-3CR3GHJ2.mjs.map