@kineviz/gl 0.7.0 → 0.8.0

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 Wn(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 de(){return this.eachAfter(Wn)}function ge(t,e){let n=-1;for(let i of this)t.call(e,i,++n,this);return this}function me(t,e){for(var n=this,i=[n],s,r,o=-1;n=i.pop();)if(t.call(e,n,++o,this),s=n.children)for(r=s.length-1;r>=0;--r)i.push(s[r]);return this}function ye(t,e){for(var n=this,i=[n],s=[],r,o,a,l=-1;n=i.pop();)if(s.push(n),r=n.children)for(o=0,a=r.length;o<a;++o)i.push(r[o]);for(;n=s.pop();)t.call(e,n,++l,this);return this}function _e(t,e){let n=-1;for(let i of this)if(t.call(e,i,++n,this))return i}function xe(t){return this.eachAfter(function(e){for(var n=+t(e.data)||0,i=e.children,s=i&&i.length;--s>=0;)n+=i[s].value;e.value=n})}function we(t){return this.eachBefore(function(e){e.children&&e.children.sort(t)})}function ve(t){for(var e=this,n=Kn(e,t),i=[e];e!==n;)e=e.parent,i.push(e);for(var s=i.length;t!==n;)i.splice(s,0,t),t=t.parent;return i}function Kn(t,e){if(t===e)return t;var n=t.ancestors(),i=e.ancestors(),s=null;for(t=n.pop(),e=i.pop();t===e;)s=t,t=n.pop(),e=i.pop();return s}function Me(){for(var t=this,e=[t];t=t.parent;)e.push(t);return e}function ke(){return Array.from(this)}function Ae(){var t=[];return this.eachBefore(function(e){e.children||t.push(e)}),t}function ze(){var t=this,e=[];return t.each(function(n){n!==t&&e.push({source:n.parent,target:n})}),e}function*Ne(){var t=this,e,n=[t],i,s,r;do for(e=n.reverse(),n=[];t=e.pop();)if(yield t,i=t.children)for(s=0,r=i.length;s<r;++s)n.push(i[s]);while(n.length)}function ut(t,e){t instanceof Map?(t=[void 0,t],e===void 0&&(e=ti)):e===void 0&&(e=Jn);for(var n=new ct(t),i,s=[n],r,o,a,l;i=s.pop();)if((o=e(i.data))&&(l=(o=Array.from(o)).length))for(i.children=o,a=l-1;a>=0;--a)s.push(r=o[a]=new ct(o[a])),r.parent=i,r.depth=i.depth+1;return n.eachBefore(Zt)}function Qn(){return ut(this).eachBefore(ei)}function Jn(t){return t.children}function ti(t){return Array.isArray(t)?t[1]:null}function ei(t){t.data.value!==void 0&&(t.value=t.data.value),t.data=t.data.data}function Zt(t){var e=0;do t.height=e;while((t=t.parent)&&t.height<++e)}function ct(t){this.data=t,this.depth=this.height=0,this.parent=null}ct.prototype=ut.prototype={constructor:ct,count:de,each:ge,eachAfter:ye,eachBefore:me,find:_e,sum:xe,sort:we,path:ve,ancestors:Me,descendants:ke,leaves:Ae,links:ze,copy:Qn,[Symbol.iterator]:Ne};function Et(t){return t==null?null:ni(t)}function ni(t){if(typeof t!="function")throw new Error;return t}var ii={depth:-1},Ie={},Ot={};function si(t){return t.id}function ri(t){return t.parentId}function Ut(){var t=si,e=ri,n;function i(s){var r=Array.from(s),o=t,a=e,l,f,c,u,h,p,d,m,x=new Map;if(n!=null){let g=r.map((v,M)=>oi(n(v,M,s))),y=g.map(Se),w=new Set(g).add("");for(let v of y)w.has(v)||(w.add(v),g.push(v),y.push(Se(v)),r.push(Ot));o=(v,M)=>g[M],a=(v,M)=>y[M]}for(c=0,l=r.length;c<l;++c)f=r[c],p=r[c]=new ct(f),(d=o(f,c,s))!=null&&(d+="")&&(m=p.id=d,x.set(m,x.has(m)?Ie:p)),(d=a(f,c,s))!=null&&(d+="")&&(p.parent=d);for(c=0;c<l;++c)if(p=r[c],d=p.parent){if(h=x.get(d),!h)throw new Error("missing: "+d);if(h===Ie)throw new Error("ambiguous: "+d);h.children?h.children.push(p):h.children=[p],p.parent=h}else{if(u)throw new Error("multiple roots");u=p}if(!u)throw new Error("no root");if(n!=null){for(;u.data===Ot&&u.children.length===1;)u=u.children[0],--l;for(let g=r.length-1;g>=0&&(p=r[g],p.data===Ot);--g)p.data=null}if(u.parent=ii,u.eachBefore(function(g){g.depth=g.parent.depth+1,--l}).eachBefore(Zt),u.parent=null,l>0)throw new Error("cycle");return u}return i.id=function(s){return arguments.length?(t=Et(s),i):t},i.parentId=function(s){return arguments.length?(e=Et(s),i):e},i.path=function(s){return arguments.length?(n=Et(s),i):n},i}function oi(t){t=`${t}`;let e=t.length;return Gt(t,e-1)&&!Gt(t,e-2)&&(t=t.slice(0,-1)),t[0]==="/"?t:`/${t}`}function Se(t){let e=t.length;if(e<2)return"";for(;--e>1&&!Gt(t,e););return t.slice(0,e)}function Gt(t,e){if(t[e]==="/"){let n=0;for(;e>0&&t[--e]==="\\";)++n;if((n&1)===0)return!0}return!1}function ai(t,e){return t.parent===e.parent?1:2}function $t(t){var e=t.children;return e?e[0]:t.t}function jt(t){var e=t.children;return e?e[e.length-1]:t.t}function li(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 ci(t){for(var e=0,n=0,i=t.children,s=i.length,r;--s>=0;)r=i[s],r.z+=e,r.m+=e,e+=r.s+(n+=r.c)}function fi(t,e,n){return t.a.parent===e.parent?t.a:n}function Pt(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}Pt.prototype=Object.create(ct.prototype);function ui(t){for(var e=new Pt(t,0),n,i=[e],s,r,o,a;n=i.pop();)if(r=n._.children)for(n.children=new Array(a=r.length),o=a-1;o>=0;--o)i.push(s=n.children[o]=new Pt(r[o],o)),s.parent=n;return(e.parent=new Pt(null,0)).children=[e],e}function pt(){var t=ai,e=1,n=1,i=null;function s(f){var c=ui(f);if(c.eachAfter(r),c.parent.m=-c.z,c.eachBefore(o),i)f.eachBefore(l);else{var u=f,h=f,p=f;f.eachBefore(function(y){y.x<u.x&&(u=y),y.x>h.x&&(h=y),y.depth>p.depth&&(p=y)});var d=u===h?1:t(u,h)/2,m=d-u.x,x=e/(h.x+d+m),g=n/(p.depth||1);f.eachBefore(function(y){y.x=(y.x+m)*x,y.y=y.depth*g})}return f}function r(f){var c=f.children,u=f.parent.children,h=f.i?u[f.i-1]:null;if(c){ci(f);var p=(c[0].z+c[c.length-1].z)/2;h?(f.z=h.z+t(f._,h._),f.m=f.z-p):f.z=p}else h&&(f.z=h.z+t(f._,h._));f.parent.A=a(f,h,f.parent.A||u[0])}function o(f){f._.x=f.z+f.parent.m,f.m+=f.parent.m}function a(f,c,u){if(c){for(var h=f,p=f,d=c,m=h.parent.children[0],x=h.m,g=p.m,y=d.m,w=m.m,v;d=jt(d),h=$t(h),d&&h;)m=$t(m),p=jt(p),p.a=f,v=d.z+y-h.z-x+t(d._,h._),v>0&&(li(fi(d,f,u),f,v),x+=v,g+=v),y+=d.m,x+=h.m,w+=m.m,g+=p.m;d&&!jt(p)&&(p.t=d,p.m+=y-g),h&&!$t(m)&&(m.t=h,m.m+=x-w,u=f)}return u}function l(f){f.x*=e,f.y=f.depth*n}return s.separation=function(f){return arguments.length?(t=f,s):t},s.size=function(f){return arguments.length?(i=!1,e=+f[0],n=+f[1],s):i?null:[e,n]},s.nodeSize=function(f){return arguments.length?(i=!0,e=+f[0],n=+f[1],s):i?[e,n]:null},s}import*as zt from"lodash";function be(t){let e=+this._x.call(null,t);return De(this.cover(e),e,t)}function De(t,e,n){if(isNaN(e))return t;var i,s=t._root,r={data:n},o=t._x0,a=t._x1,l,f,c,u,h;if(!s)return t._root=r,t;for(;s.length;)if((c=e>=(l=(o+a)/2))?o=l:a=l,i=s,!(s=s[u=+c]))return i[u]=r,t;if(f=+t._x.call(null,s.data),e===f)return r.next=s,i?i[u]=r:t._root=r,t;do i=i?i[u]=new Array(2):t._root=new Array(2),(c=e>=(l=(o+a)/2))?o=l:a=l;while((u=+c)==(h=+(f>=l)));return i[h]=s,i[u]=r,t}function Ee(t){Array.isArray(t)||(t=Array.from(t));let e=t.length,n=new Float64Array(e),i=1/0,s=-1/0;for(let r=0,o;r<e;++r)isNaN(o=+this._x.call(null,t[r]))||(n[r]=o,o<i&&(i=o),o>s&&(s=o));if(i>s)return this;this.cover(i).cover(s);for(let r=0;r<e;++r)De(this,n[r],t[r]);return this}function Pe(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,s=this._root,r,o;e>t||t>=n;)switch(o=+(t<e),r=new Array(2),r[o]=s,s=r,i*=2,o){case 0:n=e+i;break;case 1:e=n-i;break}this._root&&this._root.length&&(this._root=s)}return this._x0=e,this._x1=n,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]).cover(+t[1][0]):isNaN(this._x0)?void 0:[[this._x0],[this._x1]]}function it(t,e,n){this.node=t,this.x0=e,this.x1=n}function Ce(t,e){var n,i=this._x0,s,r,o=this._x1,a=[],l=this._root,f,c;for(l&&a.push(new it(l,i,o)),e==null?e=1/0:(i=t-e,o=t+e);f=a.pop();)if(!(!(l=f.node)||(s=f.x0)>o||(r=f.x1)<i))if(l.length){var u=(s+r)/2;a.push(new it(l[1],u,r),new it(l[0],s,u)),(c=+(t>=u))&&(f=a[a.length-1],a[a.length-1]=a[a.length-1-c],a[a.length-1-c]=f)}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 Fe(t){if(isNaN(l=+this._x.call(null,t)))return this;var e,n=this._root,i,s,r,o=this._x0,a=this._x1,l,f,c,u,h;if(!n)return this;if(n.length)for(;;){if((c=l>=(f=(o+a)/2))?o=f:a=f,e=n,!(n=n[u=+c]))return this;if(!n.length)break;e[u+1&1]&&(i=e,h=u)}for(;n.data!==t;)if(s=n,!(n=n.next))return this;return(r=n.next)&&delete n.next,s?(r?s.next=r:delete s.next,this):e?(r?e[u]=r:delete e[u],(n=e[0]||e[1])&&n===(e[1]||e[0])&&!n.length&&(i?i[h]=n:this._root=n),this):(this._root=r,this)}function Be(t){for(var e=0,n=t.length;e<n;++e)this.remove(t[e]);return this}function Re(){return this._root}function Xe(){var t=0;return this.visit(function(e){if(!e.length)do++t;while(e=e.next)}),t}function Ye(t){var e=[],n,i=this._root,s,r,o;for(i&&e.push(new it(i,this._x0,this._x1));n=e.pop();)if(!t(i=n.node,r=n.x0,o=n.x1)&&i.length){var a=(r+o)/2;(s=i[1])&&e.push(new it(s,a,o)),(s=i[0])&&e.push(new it(s,r,a))}return this}function qe(t){var e=[],n=[],i;for(this._root&&e.push(new it(this._root,this._x0,this._x1));i=e.pop();){var s=i.node;if(s.length){var r,o=i.x0,a=i.x1,l=(o+a)/2;(r=s[0])&&e.push(new it(r,o,l)),(r=s[1])&&e.push(new it(r,l,a))}n.push(i)}for(;i=n.pop();)t(i.node,i.x0,i.x1);return this}function Ze(t){return t[0]}function Oe(t){return arguments.length?(this._x=t,this):this._x}function dt(t,e){var n=new Ht(e??Ze,NaN,NaN);return t==null?n:n.addAll(t)}function Ht(t,e,n){this._x=t,this._x0=e,this._x1=n,this._root=void 0}function Ge(t){for(var e={data:t.data},n=e;t=t.next;)n=n.next={data:t.data};return e}var tt=dt.prototype=Ht.prototype;tt.copy=function(){var t=new Ht(this._x,this._x0,this._x1),e=this._root,n,i;if(!e)return t;if(!e.length)return t._root=Ge(e),t;for(n=[{source:e,target:t._root=new Array(2)}];e=n.pop();)for(var s=0;s<2;++s)(i=e.source[s])&&(i.length?n.push({source:i,target:e.target[s]=new Array(2)}):e.target[s]=Ge(i));return t};tt.add=be;tt.addAll=Ee;tt.cover=Pe;tt.data=Le;tt.extent=Te;tt.find=Ce;tt.remove=Fe;tt.removeAll=Be;tt.root=Re;tt.size=Xe;tt.visit=Ye;tt.visitAfter=qe;tt.x=Oe;function Ue(t){let e=+this._x.call(null,t),n=+this._y.call(null,t);return $e(this.cover(e,n),e,n,t)}function $e(t,e,n,i){if(isNaN(e)||isNaN(n))return t;var s,r=t._root,o={data:i},a=t._x0,l=t._y0,f=t._x1,c=t._y1,u,h,p,d,m,x,g,y;if(!r)return t._root=o,t;for(;r.length;)if((m=e>=(u=(a+f)/2))?a=u:f=u,(x=n>=(h=(l+c)/2))?l=h:c=h,s=r,!(r=r[g=x<<1|m]))return s[g]=o,t;if(p=+t._x.call(null,r.data),d=+t._y.call(null,r.data),e===p&&n===d)return o.next=r,s?s[g]=o:t._root=o,t;do s=s?s[g]=new Array(4):t._root=new Array(4),(m=e>=(u=(a+f)/2))?a=u:f=u,(x=n>=(h=(l+c)/2))?l=h:c=h;while((g=x<<1|m)===(y=(d>=h)<<1|p>=u));return s[y]=r,s[g]=o,t}function je(t){var e,n,i=t.length,s,r,o=new Array(i),a=new Array(i),l=1/0,f=1/0,c=-1/0,u=-1/0;for(n=0;n<i;++n)isNaN(s=+this._x.call(null,e=t[n]))||isNaN(r=+this._y.call(null,e))||(o[n]=s,a[n]=r,s<l&&(l=s),s>c&&(c=s),r<f&&(f=r),r>u&&(u=r));if(l>c||f>u)return this;for(this.cover(l,f).cover(c,u),n=0;n<i;++n)$e(this,o[n],a[n],t[n]);return this}function Ve(t,e){if(isNaN(t=+t)||isNaN(e=+e))return this;var n=this._x0,i=this._y0,s=this._x1,r=this._y1;if(isNaN(n))s=(n=Math.floor(t))+1,r=(i=Math.floor(e))+1;else{for(var o=s-n||1,a=this._root,l,f;n>t||t>=s||i>e||e>=r;)switch(f=(e<i)<<1|t<n,l=new Array(4),l[f]=a,a=l,o*=2,f){case 0:s=n+o,r=i+o;break;case 1:n=s-o,r=i+o;break;case 2:s=n+o,i=r-o;break;case 3:n=s-o,i=r-o;break}this._root&&this._root.length&&(this._root=a)}return this._x0=n,this._y0=i,this._x1=s,this._y1=r,this}function He(){var t=[];return this.visit(function(e){if(!e.length)do t.push(e.data);while(e=e.next)}),t}function We(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 U(t,e,n,i,s){this.node=t,this.x0=e,this.y0=n,this.x1=i,this.y1=s}function Ke(t,e,n){var i,s=this._x0,r=this._y0,o,a,l,f,c=this._x1,u=this._y1,h=[],p=this._root,d,m;for(p&&h.push(new U(p,s,r,c,u)),n==null?n=1/0:(s=t-n,r=e-n,c=t+n,u=e+n,n*=n);d=h.pop();)if(!(!(p=d.node)||(o=d.x0)>c||(a=d.y0)>u||(l=d.x1)<s||(f=d.y1)<r))if(p.length){var x=(o+l)/2,g=(a+f)/2;h.push(new U(p[3],x,g,l,f),new U(p[2],o,g,x,f),new U(p[1],x,a,l,g),new U(p[0],o,a,x,g)),(m=(e>=g)<<1|t>=x)&&(d=h[h.length-1],h[h.length-1]=h[h.length-1-m],h[h.length-1-m]=d)}else{var y=t-+this._x.call(null,p.data),w=e-+this._y.call(null,p.data),v=y*y+w*w;if(v<n){var M=Math.sqrt(n=v);s=t-M,r=e-M,c=t+M,u=e+M,i=p.data}}return i}function Qe(t){if(isNaN(c=+this._x.call(null,t))||isNaN(u=+this._y.call(null,t)))return this;var e,n=this._root,i,s,r,o=this._x0,a=this._y0,l=this._x1,f=this._y1,c,u,h,p,d,m,x,g;if(!n)return this;if(n.length)for(;;){if((d=c>=(h=(o+l)/2))?o=h:l=h,(m=u>=(p=(a+f)/2))?a=p:f=p,e=n,!(n=n[x=m<<1|d]))return this;if(!n.length)break;(e[x+1&3]||e[x+2&3]||e[x+3&3])&&(i=e,g=x)}for(;n.data!==t;)if(s=n,!(n=n.next))return this;return(r=n.next)&&delete n.next,s?(r?s.next=r:delete s.next,this):e?(r?e[x]=r:delete e[x],(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=r,this)}function Je(t){for(var e=0,n=t.length;e<n;++e)this.remove(t[e]);return this}function tn(){return this._root}function en(){var t=0;return this.visit(function(e){if(!e.length)do++t;while(e=e.next)}),t}function nn(t){var e=[],n,i=this._root,s,r,o,a,l;for(i&&e.push(new U(i,this._x0,this._y0,this._x1,this._y1));n=e.pop();)if(!t(i=n.node,r=n.x0,o=n.y0,a=n.x1,l=n.y1)&&i.length){var f=(r+a)/2,c=(o+l)/2;(s=i[3])&&e.push(new U(s,f,c,a,l)),(s=i[2])&&e.push(new U(s,r,c,f,l)),(s=i[1])&&e.push(new U(s,f,o,a,c)),(s=i[0])&&e.push(new U(s,r,o,f,c))}return this}function sn(t){var e=[],n=[],i;for(this._root&&e.push(new U(this._root,this._x0,this._y0,this._x1,this._y1));i=e.pop();){var s=i.node;if(s.length){var r,o=i.x0,a=i.y0,l=i.x1,f=i.y1,c=(o+l)/2,u=(a+f)/2;(r=s[0])&&e.push(new U(r,o,a,c,u)),(r=s[1])&&e.push(new U(r,c,a,l,u)),(r=s[2])&&e.push(new U(r,o,u,c,f)),(r=s[3])&&e.push(new U(r,c,u,l,f))}n.push(i)}for(;i=n.pop();)t(i.node,i.x0,i.y0,i.x1,i.y1);return this}function rn(t){return t[0]}function on(t){return arguments.length?(this._x=t,this):this._x}function an(t){return t[1]}function ln(t){return arguments.length?(this._y=t,this):this._y}function gt(t,e,n){var i=new Wt(e??rn,n??an,NaN,NaN,NaN,NaN);return t==null?i:i.addAll(t)}function Wt(t,e,n,i,s,r){this._x=t,this._y=e,this._x0=n,this._y0=i,this._x1=s,this._y1=r,this._root=void 0}function cn(t){for(var e={data:t.data},n=e;t=t.next;)n=n.next={data:t.data};return e}var K=gt.prototype=Wt.prototype;K.copy=function(){var t=new Wt(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=cn(e),t;for(n=[{source:e,target:t._root=new Array(4)}];e=n.pop();)for(var s=0;s<4;++s)(i=e.source[s])&&(i.length?n.push({source:i,target:e.target[s]=new Array(4)}):e.target[s]=cn(i));return t};K.add=Ue;K.addAll=je;K.cover=Ve;K.data=He;K.extent=We;K.find=Ke;K.remove=Qe;K.removeAll=Je;K.root=tn;K.size=en;K.visit=nn;K.visitAfter=sn;K.x=on;K.y=ln;function fn(t){let e=+this._x.call(null,t),n=+this._y.call(null,t),i=+this._z.call(null,t);return un(this.cover(e,n,i),e,n,i,t)}function un(t,e,n,i,s){if(isNaN(e)||isNaN(n)||isNaN(i))return t;var r,o=t._root,a={data:s},l=t._x0,f=t._y0,c=t._z0,u=t._x1,h=t._y1,p=t._z1,d,m,x,g,y,w,v,M,_,A,N;if(!o)return t._root=a,t;for(;o.length;)if((v=e>=(d=(l+u)/2))?l=d:u=d,(M=n>=(m=(f+h)/2))?f=m:h=m,(_=i>=(x=(c+p)/2))?c=x:p=x,r=o,!(o=o[A=_<<2|M<<1|v]))return r[A]=a,t;if(g=+t._x.call(null,o.data),y=+t._y.call(null,o.data),w=+t._z.call(null,o.data),e===g&&n===y&&i===w)return a.next=o,r?r[A]=a:t._root=a,t;do r=r?r[A]=new Array(8):t._root=new Array(8),(v=e>=(d=(l+u)/2))?l=d:u=d,(M=n>=(m=(f+h)/2))?f=m:h=m,(_=i>=(x=(c+p)/2))?c=x:p=x;while((A=_<<2|M<<1|v)===(N=(w>=x)<<2|(y>=m)<<1|g>=d));return r[N]=o,r[A]=a,t}function hn(t){Array.isArray(t)||(t=Array.from(t));let e=t.length,n=new Float64Array(e),i=new Float64Array(e),s=new Float64Array(e),r=1/0,o=1/0,a=1/0,l=-1/0,f=-1/0,c=-1/0;for(let u=0,h,p,d,m;u<e;++u)isNaN(p=+this._x.call(null,h=t[u]))||isNaN(d=+this._y.call(null,h))||isNaN(m=+this._z.call(null,h))||(n[u]=p,i[u]=d,s[u]=m,p<r&&(r=p),p>l&&(l=p),d<o&&(o=d),d>f&&(f=d),m<a&&(a=m),m>c&&(c=m));if(r>l||o>f||a>c)return this;this.cover(r,o,a).cover(l,f,c);for(let u=0;u<e;++u)un(this,n[u],i[u],s[u],t[u]);return this}function pn(t,e,n){if(isNaN(t=+t)||isNaN(e=+e)||isNaN(n=+n))return this;var i=this._x0,s=this._y0,r=this._z0,o=this._x1,a=this._y1,l=this._z1;if(isNaN(i))o=(i=Math.floor(t))+1,a=(s=Math.floor(e))+1,l=(r=Math.floor(n))+1;else{for(var f=o-i||1,c=this._root,u,h;i>t||t>=o||s>e||e>=a||r>n||n>=l;)switch(h=(n<r)<<2|(e<s)<<1|t<i,u=new Array(8),u[h]=c,c=u,f*=2,h){case 0:o=i+f,a=s+f,l=r+f;break;case 1:i=o-f,a=s+f,l=r+f;break;case 2:o=i+f,s=a-f,l=r+f;break;case 3:i=o-f,s=a-f,l=r+f;break;case 4:o=i+f,a=s+f,r=l-f;break;case 5:i=o-f,a=s+f,r=l-f;break;case 6:o=i+f,s=a-f,r=l-f;break;case 7:i=o-f,s=a-f,r=l-f;break}this._root&&this._root.length&&(this._root=c)}return this._x0=i,this._y0=s,this._z0=r,this._x1=o,this._y1=a,this._z1=l,this}function dn(){var t=[];return this.visit(function(e){if(!e.length)do t.push(e.data);while(e=e.next)}),t}function gn(t){return arguments.length?this.cover(+t[0][0],+t[0][1],+t[0][2]).cover(+t[1][0],+t[1][1],+t[1][2]):isNaN(this._x0)?void 0:[[this._x0,this._y0,this._z0],[this._x1,this._y1,this._z1]]}function B(t,e,n,i,s,r,o){this.node=t,this.x0=e,this.y0=n,this.z0=i,this.x1=s,this.y1=r,this.z1=o}function mn(t,e,n,i){var s,r=this._x0,o=this._y0,a=this._z0,l,f,c,u,h,p,d=this._x1,m=this._y1,x=this._z1,g=[],y=this._root,w,v;for(y&&g.push(new B(y,r,o,a,d,m,x)),i==null?i=1/0:(r=t-i,o=e-i,a=n-i,d=t+i,m=e+i,x=n+i,i*=i);w=g.pop();)if(!(!(y=w.node)||(l=w.x0)>d||(f=w.y0)>m||(c=w.z0)>x||(u=w.x1)<r||(h=w.y1)<o||(p=w.z1)<a))if(y.length){var M=(l+u)/2,_=(f+h)/2,A=(c+p)/2;g.push(new B(y[7],M,_,A,u,h,p),new B(y[6],l,_,A,M,h,p),new B(y[5],M,f,A,u,_,p),new B(y[4],l,f,A,M,_,p),new B(y[3],M,_,c,u,h,A),new B(y[2],l,_,c,M,h,A),new B(y[1],M,f,c,u,_,A),new B(y[0],l,f,c,M,_,A)),(v=(n>=A)<<2|(e>=_)<<1|t>=M)&&(w=g[g.length-1],g[g.length-1]=g[g.length-1-v],g[g.length-1-v]=w)}else{var N=t-+this._x.call(null,y.data),b=e-+this._y.call(null,y.data),D=n-+this._z.call(null,y.data),P=N*N+b*b+D*D;if(P<i){var E=Math.sqrt(i=P);r=t-E,o=e-E,a=n-E,d=t+E,m=e+E,x=n+E,s=y.data}}return s}var hi=(t,e,n,i,s,r)=>Math.sqrt((t-i)**2+(e-s)**2+(n-r)**2);function yn(t,e,n,i){let s=[],r=t-i,o=e-i,a=n-i,l=t+i,f=e+i,c=n+i;return this.visit((u,h,p,d,m,x,g)=>{if(!u.length)do{let y=u.data;hi(t,e,n,this._x(y),this._y(y),this._z(y))<=i&&s.push(y)}while(u=u.next);return h>l||p>f||d>c||m<r||x<o||g<a}),s}function _n(t){if(isNaN(h=+this._x.call(null,t))||isNaN(p=+this._y.call(null,t))||isNaN(d=+this._z.call(null,t)))return this;var e,n=this._root,i,s,r,o=this._x0,a=this._y0,l=this._z0,f=this._x1,c=this._y1,u=this._z1,h,p,d,m,x,g,y,w,v,M,_;if(!n)return this;if(n.length)for(;;){if((y=h>=(m=(o+f)/2))?o=m:f=m,(w=p>=(x=(a+c)/2))?a=x:c=x,(v=d>=(g=(l+u)/2))?l=g:u=g,e=n,!(n=n[M=v<<2|w<<1|y]))return this;if(!n.length)break;(e[M+1&7]||e[M+2&7]||e[M+3&7]||e[M+4&7]||e[M+5&7]||e[M+6&7]||e[M+7&7])&&(i=e,_=M)}for(;n.data!==t;)if(s=n,!(n=n.next))return this;return(r=n.next)&&delete n.next,s?(r?s.next=r:delete s.next,this):e?(r?e[M]=r:delete e[M],(n=e[0]||e[1]||e[2]||e[3]||e[4]||e[5]||e[6]||e[7])&&n===(e[7]||e[6]||e[5]||e[4]||e[3]||e[2]||e[1]||e[0])&&!n.length&&(i?i[_]=n:this._root=n),this):(this._root=r,this)}function xn(t){for(var e=0,n=t.length;e<n;++e)this.remove(t[e]);return this}function wn(){return this._root}function vn(){var t=0;return this.visit(function(e){if(!e.length)do++t;while(e=e.next)}),t}function Mn(t){var e=[],n,i=this._root,s,r,o,a,l,f,c;for(i&&e.push(new B(i,this._x0,this._y0,this._z0,this._x1,this._y1,this._z1));n=e.pop();)if(!t(i=n.node,r=n.x0,o=n.y0,a=n.z0,l=n.x1,f=n.y1,c=n.z1)&&i.length){var u=(r+l)/2,h=(o+f)/2,p=(a+c)/2;(s=i[7])&&e.push(new B(s,u,h,p,l,f,c)),(s=i[6])&&e.push(new B(s,r,h,p,u,f,c)),(s=i[5])&&e.push(new B(s,u,o,p,l,h,c)),(s=i[4])&&e.push(new B(s,r,o,p,u,h,c)),(s=i[3])&&e.push(new B(s,u,h,a,l,f,p)),(s=i[2])&&e.push(new B(s,r,h,a,u,f,p)),(s=i[1])&&e.push(new B(s,u,o,a,l,h,p)),(s=i[0])&&e.push(new B(s,r,o,a,u,h,p))}return this}function kn(t){var e=[],n=[],i;for(this._root&&e.push(new B(this._root,this._x0,this._y0,this._z0,this._x1,this._y1,this._z1));i=e.pop();){var s=i.node;if(s.length){var r,o=i.x0,a=i.y0,l=i.z0,f=i.x1,c=i.y1,u=i.z1,h=(o+f)/2,p=(a+c)/2,d=(l+u)/2;(r=s[0])&&e.push(new B(r,o,a,l,h,p,d)),(r=s[1])&&e.push(new B(r,h,a,l,f,p,d)),(r=s[2])&&e.push(new B(r,o,p,l,h,c,d)),(r=s[3])&&e.push(new B(r,h,p,l,f,c,d)),(r=s[4])&&e.push(new B(r,o,a,d,h,p,u)),(r=s[5])&&e.push(new B(r,h,a,d,f,p,u)),(r=s[6])&&e.push(new B(r,o,p,d,h,c,u)),(r=s[7])&&e.push(new B(r,h,p,d,f,c,u))}n.push(i)}for(;i=n.pop();)t(i.node,i.x0,i.y0,i.z0,i.x1,i.y1,i.z1);return this}function An(t){return t[0]}function zn(t){return arguments.length?(this._x=t,this):this._x}function Nn(t){return t[1]}function In(t){return arguments.length?(this._y=t,this):this._y}function Sn(t){return t[2]}function bn(t){return arguments.length?(this._z=t,this):this._z}function mt(t,e,n,i){var s=new Kt(e??An,n??Nn,i??Sn,NaN,NaN,NaN,NaN,NaN,NaN);return t==null?s:s.addAll(t)}function Kt(t,e,n,i,s,r,o,a,l){this._x=t,this._y=e,this._z=n,this._x0=i,this._y0=s,this._z0=r,this._x1=o,this._y1=a,this._z1=l,this._root=void 0}function Dn(t){for(var e={data:t.data},n=e;t=t.next;)n=n.next={data:t.data};return e}var V=mt.prototype=Kt.prototype;V.copy=function(){var t=new Kt(this._x,this._y,this._z,this._x0,this._y0,this._z0,this._x1,this._y1,this._z1),e=this._root,n,i;if(!e)return t;if(!e.length)return t._root=Dn(e),t;for(n=[{source:e,target:t._root=new Array(8)}];e=n.pop();)for(var s=0;s<8;++s)(i=e.source[s])&&(i.length?n.push({source:i,target:e.target[s]=new Array(8)}):e.target[s]=Dn(i));return t};V.add=fn;V.addAll=hn;V.cover=pn;V.data=dn;V.extent=gn;V.find=mn;V.findAllWithinRadius=yn;V.remove=_n;V.removeAll=xn;V.root=wn;V.size=vn;V.visit=Mn;V.visitAfter=kn;V.x=zn;V.y=In;V.z=bn;function Y(t){return function(){return t}}function Q(t){return(t()-.5)*1e-6}function Qt(t){return t.x+t.vx}function En(t){return t.y+t.vy}function pi(t){return t.z+t.vz}function Jt(t){var e,n,i,s,r=1,o=1;typeof t!="function"&&(t=Y(t==null?1:+t));function a(){for(var c,u=e.length,h,p,d,m,x,g,y,w=0;w<o;++w)for(h=(n===1?dt(e,Qt):n===2?gt(e,Qt,En):n===3?mt(e,Qt,En,pi):null).visitAfter(l),c=0;c<u;++c)p=e[c],g=i[p.index],y=g*g,d=p.x+p.vx,n>1&&(m=p.y+p.vy),n>2&&(x=p.z+p.vz),h.visit(v);function v(M,_,A,N,b,D,P){var E=[_,A,N,b,D,P],L=E[0],X=E[1],Z=E[2],G=E[n],J=E[n+1],H=E[n+2],W=M.data,ot=M.r,q=g+ot;if(W){if(W.index>p.index){var F=d-W.x-W.vx,R=n>1?m-W.y-W.vy:0,$=n>2?x-W.z-W.vz:0,O=F*F+R*R+$*$;O<q*q&&(F===0&&(F=Q(s),O+=F*F),n>1&&R===0&&(R=Q(s),O+=R*R),n>2&&$===0&&($=Q(s),O+=$*$),O=(q-(O=Math.sqrt(O)))/O*r,p.vx+=(F*=O)*(q=(ot*=ot)/(y+ot)),n>1&&(p.vy+=(R*=O)*q),n>2&&(p.vz+=($*=O)*q),W.vx-=F*(q=1-q),n>1&&(W.vy-=R*q),n>2&&(W.vz-=$*q))}return}return L>d+q||G<d-q||n>1&&(X>m+q||J<m-q)||n>2&&(Z>x+q||H<x-q)}}function l(c){if(c.data)return c.r=i[c.data.index];for(var u=c.r=0;u<Math.pow(2,n);++u)c[u]&&c[u].r>c.r&&(c.r=c[u].r)}function f(){if(e){var c,u=e.length,h;for(i=new Array(u),c=0;c<u;++c)h=e[c],i[h.index]=+t(h,c,e)}}return a.initialize=function(c,...u){e=c,s=u.find(h=>typeof h=="function")||Math.random,n=u.find(h=>[1,2,3].includes(h))||2,f()},a.iterations=function(c){return arguments.length?(o=+c,a):o},a.strength=function(c){return arguments.length?(r=+c,a):r},a.radius=function(c){return arguments.length?(t=typeof c=="function"?c:Y(+c),f(),a):t},a}function di(t){return t.index}function Pn(t,e){var n=t.get(e);if(!n)throw new Error("node not found: "+e);return n}function te(t){var e=di,n=h,i,s=Y(30),r,o,a,l,f,c,u=1;t==null&&(t=[]);function h(g){return 1/Math.min(l[g.source.index],l[g.target.index])}function p(g){for(var y=0,w=t.length;y<u;++y)for(var v=0,M,_,A,N=0,b=0,D=0,P,E;v<w;++v)M=t[v],_=M.source,A=M.target,N=A.x+A.vx-_.x-_.vx||Q(c),a>1&&(b=A.y+A.vy-_.y-_.vy||Q(c)),a>2&&(D=A.z+A.vz-_.z-_.vz||Q(c)),P=Math.sqrt(N*N+b*b+D*D),P=(P-r[v])/P*g*i[v],N*=P,b*=P,D*=P,A.vx-=N*(E=f[v]),a>1&&(A.vy-=b*E),a>2&&(A.vz-=D*E),_.vx+=N*(E=1-E),a>1&&(_.vy+=b*E),a>2&&(_.vz+=D*E)}function d(){if(o){var g,y=o.length,w=t.length,v=new Map(o.map((_,A)=>[e(_,A,o),_])),M;for(g=0,l=new Array(y);g<w;++g)M=t[g],M.index=g,typeof M.source!="object"&&(M.source=Pn(v,M.source)),typeof M.target!="object"&&(M.target=Pn(v,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,f=new Array(w);g<w;++g)M=t[g],f[g]=l[M.source.index]/(l[M.source.index]+l[M.target.index]);i=new Array(w),m(),r=new Array(w),x()}}function m(){if(o)for(var g=0,y=t.length;g<y;++g)i[g]=+n(t[g],g,t)}function x(){if(o)for(var g=0,y=t.length;g<y;++g)r[g]=+s(t[g],g,t)}return p.initialize=function(g,...y){o=g,c=y.find(w=>typeof w=="function")||Math.random,a=y.find(w=>[1,2,3].includes(w))||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?(u=+g,p):u},p.strength=function(g){return arguments.length?(n=typeof g=="function"?g:Y(+g),m(),p):n},p.distance=function(g){return arguments.length?(s=typeof g=="function"?g:Y(+g),x(),p):s},p}var gi={value:()=>{}};function Tn(){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 Lt(n)}function Lt(t){this._=t}function mi(t,e){return t.trim().split(/^|\s+/).map(function(n){var i="",s=n.indexOf(".");if(s>=0&&(i=n.slice(s+1),n=n.slice(0,s)),n&&!e.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:i}})}Lt.prototype=Tn.prototype={constructor:Lt,on:function(t,e){var n=this._,i=mi(t+"",n),s,r=-1,o=i.length;if(arguments.length<2){for(;++r<o;)if((s=(t=i[r]).type)&&(s=yi(n[s],t.name)))return s;return}if(e!=null&&typeof e!="function")throw new Error("invalid callback: "+e);for(;++r<o;)if(s=(t=i[r]).type)n[s]=Ln(n[s],t.name,e);else if(e==null)for(s in n)n[s]=Ln(n[s],t.name,null);return this},copy:function(){var t={},e=this._;for(var n in e)t[n]=e[n].slice();return new Lt(t)},call:function(t,e){if((s=arguments.length-2)>0)for(var n=new Array(s),i=0,s,r;i<s;++i)n[i]=arguments[i+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(r=this._[t],i=0,s=r.length;i<s;++i)r[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],s=0,r=i.length;s<r;++s)i[s].value.apply(e,n)}};function yi(t,e){for(var n=0,i=t.length,s;n<i;++n)if((s=t[n]).name===e)return s.value}function Ln(t,e,n){for(var i=0,s=t.length;i<s;++i)if(t[i].name===e){t[i]=gi,t=t.slice(0,i).concat(t.slice(i+1));break}return n!=null&&t.push({name:e,value:n}),t}var ee=Tn;var wt=0,It=0,Nt=0,Fn=1e3,Tt,St,Ct=0,yt=0,Ft=0,bt=typeof performance=="object"&&performance.now?performance:Date,Bn=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function se(){return yt||(Bn(_i),yt=bt.now()+Ft)}function _i(){yt=0}function ne(){this._call=this._time=this._next=null}ne.prototype=Bt.prototype={constructor:ne,restart:function(t,e,n){if(typeof t!="function")throw new TypeError("callback is not a function");n=(n==null?se():+n)+(e==null?0:+e),!this._next&&St!==this&&(St?St._next=this:Tt=this,St=this),this._call=t,this._time=n,ie()},stop:function(){this._call&&(this._call=null,this._time=1/0,ie())}};function Bt(t,e,n){var i=new ne;return i.restart(t,e,n),i}function Rn(){se(),++wt;for(var t=Tt,e;t;)(e=yt-t._time)>=0&&t._call.call(void 0,e),t=t._next;--wt}function Cn(){yt=(Ct=bt.now())+Ft,wt=It=0;try{Rn()}finally{wt=0,wi(),yt=0}}function xi(){var t=bt.now(),e=t-Ct;e>Fn&&(Ft-=e,Ct=t)}function wi(){for(var t,e=Tt,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:Tt=n);St=t,ie(i)}function ie(t){if(!wt){It&&(It=clearTimeout(It));var e=t-yt;e>24?(t<1/0&&(It=setTimeout(Cn,t-bt.now()-Ft)),Nt&&(Nt=clearInterval(Nt))):(Nt||(Ct=bt.now(),Nt=setInterval(xi,Fn)),wt=1,Bn(Cn))}}function Xn(){let t=1;return()=>(t=(1664525*t+1013904223)%4294967296)/4294967296}var Yn=3;function Rt(t){return t.x}function re(t){return t.y}function qn(t){return t.z}var vi=10,Mi=Math.PI*(3-Math.sqrt(5)),ki=Math.PI*20/(9+Math.sqrt(221));function oe(t,e){e=e||2;var n=Math.min(Yn,Math.max(1,Math.round(e))),i,s=1,r=.001,o=1-Math.pow(r,1/300),a=0,l=.6,f=new Map,c=Bt(p),u=ee("tick","end"),h=Xn();t==null&&(t=[]);function p(){d(),u.call("tick",i),s<r&&(c.stop(),u.call("end",i))}function d(g){var y,w=t.length,v;g===void 0&&(g=1);for(var M=0;M<g;++M)for(s+=(a-s)*o,f.forEach(function(_){_(s)}),y=0;y<w;++y)v=t[y],v.fx==null?v.x+=v.vx*=l:(v.x=v.fx,v.vx=0),n>1&&(v.fy==null?v.y+=v.vy*=l:(v.y=v.fy,v.vy=0)),n>2&&(v.fz==null?v.z+=v.vz*=l:(v.z=v.fz,v.vz=0));return i}function m(){for(var g=0,y=t.length,w;g<y;++g){if(w=t[g],w.index=g,w.fx!=null&&(w.x=w.fx),w.fy!=null&&(w.y=w.fy),w.fz!=null&&(w.z=w.fz),isNaN(w.x)||n>1&&isNaN(w.y)||n>2&&isNaN(w.z)){var v=vi*(n>2?Math.cbrt(.5+g):n>1?Math.sqrt(.5+g):g),M=g*Mi,_=g*ki;n===1?w.x=v:n===2?(w.x=v*Math.cos(M),w.y=v*Math.sin(M)):(w.x=v*Math.sin(M)*Math.cos(_),w.y=v*Math.cos(M),w.z=v*Math.sin(M)*Math.sin(_))}(isNaN(w.vx)||n>1&&isNaN(w.vy)||n>2&&isNaN(w.vz))&&(w.vx=0,n>1&&(w.vy=0),n>2&&(w.vz=0))}}function x(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(Yn,Math.max(1,Math.round(g))),f.forEach(x),i):n},nodes:function(g){return arguments.length?(t=g,m(),f.forEach(x),i):t},alpha:function(g){return arguments.length?(s=+g,i):s},alphaMin:function(g){return arguments.length?(r=+g,i):r},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,f.forEach(x),i):h},force:function(g,y){return arguments.length>1?(y==null?f.delete(g):f.set(g,x(y)),i):f.get(g)},find:function(){var g=Array.prototype.slice.call(arguments),y=g.shift()||0,w=(n>1?g.shift():null)||0,v=(n>2?g.shift():null)||0,M=g.shift()||1/0,_=0,A=t.length,N,b,D,P,E,L;for(M*=M,_=0;_<A;++_)E=t[_],N=y-E.x,b=w-(E.y||0),D=v-(E.z||0),P=N*N+b*b+D*D,P<M&&(L=E,M=P);return L},on:function(g,y){return arguments.length>1?(u.on(g,y),i):u.on(g)}}}function ae(){var t,e,n,i,s,r=Y(-30),o,a=1,l=1/0,f=.81;function c(d){var m,x=t.length,g=(e===1?dt(t,Rt):e===2?gt(t,Rt,re):e===3?mt(t,Rt,re,qn):null).visitAfter(h);for(s=d,m=0;m<x;++m)n=t[m],g.visit(p)}function u(){if(t){var d,m=t.length,x;for(o=new Array(m),d=0;d<m;++d)x=t[d],o[x.index]=+r(x,d,t)}}function h(d){var m=0,x,g,y=0,w,v,M,_,A=d.length;if(A){for(w=v=M=_=0;_<A;++_)(x=d[_])&&(g=Math.abs(x.value))&&(m+=x.value,y+=g,w+=g*(x.x||0),v+=g*(x.y||0),M+=g*(x.z||0));m*=Math.sqrt(4/A),d.x=w/y,e>1&&(d.y=v/y),e>2&&(d.z=M/y)}else{x=d,x.x=x.data.x,e>1&&(x.y=x.data.y),e>2&&(x.z=x.data.z);do m+=o[x.data.index];while(x=x.next)}d.value=m}function p(d,m,x,g,y){if(!d.value)return!0;var w=[x,g,y][e-1],v=d.x-n.x,M=e>1?d.y-n.y:0,_=e>2?d.z-n.z:0,A=w-m,N=v*v+M*M+_*_;if(A*A/f<N)return N<l&&(v===0&&(v=Q(i),N+=v*v),e>1&&M===0&&(M=Q(i),N+=M*M),e>2&&_===0&&(_=Q(i),N+=_*_),N<a&&(N=Math.sqrt(a*N)),n.vx+=v*d.value*s/N,e>1&&(n.vy+=M*d.value*s/N),e>2&&(n.vz+=_*d.value*s/N)),!0;if(d.length||N>=l)return;(d.data!==n||d.next)&&(v===0&&(v=Q(i),N+=v*v),e>1&&M===0&&(M=Q(i),N+=M*M),e>2&&_===0&&(_=Q(i),N+=_*_),N<a&&(N=Math.sqrt(a*N)));do d.data!==n&&(A=o[d.data.index]*s/N,n.vx+=v*A,e>1&&(n.vy+=M*A),e>2&&(n.vz+=_*A));while(d=d.next)}return c.initialize=function(d,...m){t=d,i=m.find(x=>typeof x=="function")||Math.random,e=m.find(x=>[1,2,3].includes(x))||2,u()},c.strength=function(d){return arguments.length?(r=typeof d=="function"?d:Y(+d),u(),c):r},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?(f=d*d,c):Math.sqrt(f)},c}function le(t){var e=Y(.1),n,i,s;typeof t!="function"&&(t=Y(t==null?0:+t));function r(a){for(var l=0,f=n.length,c;l<f;++l)c=n[l],c.vx+=(s[l]-c.x)*i[l]*a}function o(){if(n){var a,l=n.length;for(i=new Array(l),s=new Array(l),a=0;a<l;++a)i[a]=isNaN(s[a]=+t(n[a],a,n))?0:+e(n[a],a,n)}}return r.initialize=function(a){n=a,o()},r.strength=function(a){return arguments.length?(e=typeof a=="function"?a:Y(+a),o(),r):e},r.x=function(a){return arguments.length?(t=typeof a=="function"?a:Y(+a),o(),r):t},r}function ce(t){var e=Y(.1),n,i,s;typeof t!="function"&&(t=Y(t==null?0:+t));function r(a){for(var l=0,f=n.length,c;l<f;++l)c=n[l],c.vy+=(s[l]-c.y)*i[l]*a}function o(){if(n){var a,l=n.length;for(i=new Array(l),s=new Array(l),a=0;a<l;++a)i[a]=isNaN(s[a]=+t(n[a],a,n))?0:+e(n[a],a,n)}}return r.initialize=function(a){n=a,o()},r.strength=function(a){return arguments.length?(e=typeof a=="function"?a:Y(+a),o(),r):e},r.y=function(a){return arguments.length?(t=typeof a=="function"?a:Y(+a),o(),r):t},r}function fe(t){var e=Y(.1),n,i,s;typeof t!="function"&&(t=Y(t==null?0:+t));function r(a){for(var l=0,f=n.length,c;l<f;++l)c=n[l],c.vz+=(s[l]-c.z)*i[l]*a}function o(){if(n){var a,l=n.length;for(i=new Array(l),s=new Array(l),a=0;a<l;++a)i[a]=isNaN(s[a]=+t(n[a],a,n))?0:+e(n[a],a,n)}}return r.initialize=function(a){n=a,o()},r.strength=function(a){return arguments.length?(e=typeof a=="function"?a:Y(+a),o(),r):e},r.z=function(a){return arguments.length?(t=typeof a=="function"?a:Y(+a),o(),r):t},r}function ht(t){let e=0,n=0,i=0,s=0;for(let[,r]of t)e+=r[0],n+=r[1],i+=r[2],s++;return s===0?[0,0,0]:[e/s,n/s,i/s]}var xt=1;function st(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 Ai(t,e){let n=t.nodes.length;if(n===0)return{positions:new Map};let i=ht(t.positions),s=e?.spacing??xt,r=e?.radius??Math.max(s,n*s/(2*Math.PI)),o=Math.PI*2/n,a=[];for(let l=0;l<n;l++)a.push([r*Math.cos(l*o)+i[0],r*Math.sin(l*o)+i[1],0]);return st(t,a)}function zi(t,e){let n=t.nodes.length;if(n===0)return{positions:new Map};let i=ht(t.positions),s=e?.columns&&e.columns>0?e.columns:Math.ceil(Math.sqrt(n)),r=e?.spacing??xt,o=r*(s-1),a=[];for(let l=0;l<n;l++)a.push([l%s*r-o/2+i[0],-Math.floor(l/s)*r+o/2+i[1],0]);return st(t,a)}function Ni(t,e){let n=t.nodes.length;if(n===0)return{positions:new Map};let i=ht(t.positions),s=e?.axis??"x",r=e?.spacing??xt,o=r*(n-1),a=[];for(let l=0;l<n;l++){let f=n>1?-o/2+l*r:0,c=[i[0],i[1],i[2]],u=s==="x"?0:s==="y"?1:2;c[u]=f+i[u],a.push(c)}return st(t,a)}function Ii(t,e){let n=t.nodes.length;if(n===0)return{positions:new Map};let i=ht(t.positions),s=e?.spacing??1.5,r=s/(2*Math.PI),o=2*Math.PI,a=[];for(let l=0;l<n;l++){let f=r*o;a.push([f*Math.cos(o)+i[0],f*Math.sin(o)+i[1],0]),o+=s/f}return st(t,a)}function Si(t,e){let n=t.nodes.length;if(n===0)return{positions:new Map};let i=ht(t.positions),s=Math.cbrt(n),r=Math.floor(s),o=Math.ceil(s),a=e?.size??(n-Math.pow(r,3)>Math.pow(o,3)-n?o:r),l=e?.spacing??xt,f=l*Math.max(a-1,0),c=[];for(let u=0;u<n;u++)c.push([u%a*l-f/2+i[0],-(Math.floor(u/a)%a)*l+f/2+i[1],-Math.floor(u/(a*a))*l+f/2+i[2]]);return st(t,c)}function bi(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=ht(t.positions),s=e?.spacing??xt,r=e?.density!==void 0?Math.sqrt(n/(4*Math.PI*e.density)):s*Math.sqrt(n/(4*Math.PI)),o=e?.radius??Math.max(s,r),a=[];for(let l=0;l<n;l++){let f=Math.acos(1-(2*(l+1)-1)/n),c=Math.sqrt(n*Math.PI)*f;a.push([o*Math.sin(f)*Math.cos(c)+i[0],o*Math.sin(f)*Math.sin(c)+i[1],o*Math.cos(f)+i[2]])}return st(t,a)}function Di(t,e){let n=t.nodes.length;if(n===0)return{positions:new Map};let i=e?.spacing??xt,s=e?.range??Math.max(i,i*Math.cbrt(n)/2),r=e?.seed??42;function o(){r|=0,r=r+1831565813|0;let l=Math.imul(r^r>>>15,1|r);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)*s*2,(o()-.5)*s*2,(o()-.5)*s*2]);return st(t,a)}function Ei(t,e){if(t.nodes.length===0)return{positions:new Map};let i=e?.axis??"x",s=(e?.degrees??90)*Math.PI/180,r=ht(t.positions),o=[];for(let a of t.nodes){let l=t.positions.get(a.id)??[0,0,0],f=l[0]-r[0],c=l[1]-r[1],u=l[2]-r[2],h,p,d,m=Math.cos(s),x=Math.sin(s);i==="x"?(h=f,p=c*m-u*x,d=c*x+u*m):i==="y"?(h=f*m+u*x,p=c,d=-f*x+u*m):(h=f*m-c*x,p=f*x+c*m,d=u),o.push([h+r[0],p+r[1],d+r[2]])}return st(t,o)}function Pi(t,e){if(t.nodes.length===0)return{positions:new Map};let i=e?.factor,s=i??e?.x??1,r=i??e?.y??1,o=i??e?.z??1,a=ht(t.positions),l=[];for(let f of t.nodes){let c=t.positions.get(f.id)??[0,0,0];l.push([c[0]+(c[0]-a[0])*(s-1),c[1]+(c[1]-a[1])*(r-1),c[2]+(c[2]-a[2])*(o-1)])}return st(t,l)}function Li(t,e){if(t.nodes.length===0)return{positions:new Map};let i=e?.x??0,s=e?.y??0,r=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]+s,l[2]+r])}return st(t,o)}function Ti(t,e){if(t.nodes.length===0)return{positions:new Map};let i=e?.axis??"x",s=i==="x"?0:i==="y"?1:2,r=1/0,o=-1/0;for(let f of t.nodes){let c=t.positions.get(f.id)??[0,0,0];c[s]<r&&(r=c[s]),c[s]>o&&(o=c[s])}let a=(r+o)/2,l=[];for(let f of t.nodes){let c=t.positions.get(f.id)??[0,0,0],u=[c[0],c[1],c[2]];u[s]=a,l.push(u)}return st(t,l)}function Ci(t,e){let{depth:n=100,mode:i="tree",orientation:s="right",alongRelationships:r=[]}=e??{},o=e?.spacing??xt,a=e?.spacing===void 0?e?.edgeLength:void 0,l=t.nodes;if(l.length===0)return{positions:new Map};let f=new Set;for(let[_]of t.positions)f.add(_);let c=new Map,u=new Map;for(let _ of t.edges)!f.has(_.source)||!f.has(_.target)||(u.set(_.id,_),c.has(_.source)||c.set(_.source,[]),c.has(_.target)||c.set(_.target,[]),c.get(_.source).push({nodeId:_.target,relationship:_.relationship}),c.get(_.target).push({nodeId:_.source,relationship:_.relationship}));let h=r.length>0?new Set(Array.from(c.entries()).filter(([,_])=>_.some(({relationship:A})=>r.includes(A))).map(([_])=>_)):f,p=l.filter(_=>h.has(_.id));if(p.length===0)return{positions:new Map};let d=new Map,m=p.map(_=>[{from:"",to:_.id}]),x=p.map(_=>[[_.id]]),g=p.map(()=>1),y=p.map(()=>[1]),w=p.map(_=>_.id),v=1;for(;v<=n&&zt.sum(x.map(_=>_[v-1]?.length??0))>0;)x.forEach((_,A)=>{let N=_[v-1];if(!N)return;let b=[];N.forEach(D=>{let P=c.get(D)??[],E=P.map(({nodeId:L})=>L);r.length>0&&(E=P.filter(({relationship:L})=>r.includes(L)).map(({nodeId:L})=>L)),E=zt.difference(zt.intersection(E,Array.from(h)),w),E.forEach(L=>{m[A].push({from:D,to:L}),b.push(L),w.push(L)})}),_[v]=b,b.length>0&&(y[A].push(b.length),g[A]++)}),v++;let M=Ut().id(_=>_.to).parentId(_=>_.from||null);return p.forEach((_,A)=>{let N=t.positions.get(_.id)??[0,0,0];if(m[A].length<=1){d.set(_.id,[N[0],N[1],N[2]]);return}let b;try{b=M(m[A])}catch{d.set(_.id,[N[0],N[1],N[2]]);return}let D=Math.max(...y[A],1),P=Math.max(g[A]-1,1),E=Math.max(D-1,1),L,X;i==="rings"?(L=2*Math.PI,a!==void 0?X=a*P:X=Math.max(o,o*D/(2*Math.PI))):a!==void 0?(L=a*D*.2*Math.pow(g[A],.3),X=a*P):(L=o*E,X=o*P);let G=pt().size([L,X])(b);Gn(i,s,G,G,N,d)}),{positions:d}}function Gn(t,e,n,i,s,r){let o=i.id,a,l;if(t==="tree")switch(e){case"up":a=i.x+s[0]-n.x,l=i.y+s[1]+n.y;break;case"down":a=-i.x+s[0]+n.x,l=-i.y+s[1]-n.y;break;case"right":a=i.y+s[0]-n.y,l=-i.x+s[1]+n.x;break;case"left":a=-i.y+s[0]+n.y,l=i.x+s[1]-n.x;break}else switch(e){case"down":a=s[0]+i.y*Math.cos(i.x+Math.PI/2),l=s[1]+i.y*Math.sin(i.x+Math.PI/2);break;case"up":a=s[0]+i.y*Math.cos(i.x+3*Math.PI/2),l=s[1]+i.y*Math.sin(i.x+3*Math.PI/2);break;case"right":a=s[0]+i.y*Math.cos(i.x+Math.PI),l=s[1]+i.y*Math.sin(i.x+Math.PI);break;case"left":a=s[0]+i.y*Math.cos(i.x),l=s[1]+i.y*Math.sin(i.x);break}if(r.set(o,[a,l,s[2]]),i.children)for(let f of i.children)Gn(t,e,n,f,s,r)}var Yt=1.5,pe=3;function Xt(t,e){return e==="category"?t.category:t.properties?.[e]}function qt(t,e,n){let i=n&&n.length?new Set(n):null,s=new Set,r=[],o=t.size;for(let a of e){if(i&&!i.has(a.relationship))continue;let l=t.get(a.source),f=t.get(a.target);if(l===void 0||f===void 0||l===f)continue;let c=l*o+f;s.has(c)||(s.add(c),r.push([l,f]))}return r}function Un(t,e){let n=[],i=new Set;for(let s of t)s!=null&&!i.has(s)&&(i.add(s),n.push(s));if(e){let s=e.filter(o=>i.has(o)),r=new Set(s);return[...s,...n.filter(o=>!r.has(o))]}return n.every(s=>typeof s=="number")?[...n].sort((s,r)=>s-r):n}function Dt(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 At(t,e){if(e.size===0)return e;let n=0,i=0,s=0;for(let u of t.nodes){let h=t.positions.get(u.id);h&&(n+=h[0],i+=h[1],s++)}s&&(n/=s,i/=s);let r=1/0,o=-1/0,a=1/0,l=-1/0;for(let u of e.values())u[0]<r&&(r=u[0]),u[0]>o&&(o=u[0]),u[1]<a&&(a=u[1]),u[1]>l&&(l=u[1]);let f=n-(r+o)/2,c=i-(a+l)/2;for(let u of e.values())u[0]+=f,u[1]+=c;return e}function $n(t,e,n){let i=t.length,s=Array.from({length:i},()=>[]),r=new Int32Array(i);for(let[c,u]of e)s[c].push(u),r[u]++;let o;if(n&&n.length){let c=new Set(n);o=[],t.forEach((u,h)=>{c.has(u.id)&&o.push(h)})}else{o=[];for(let c=0;c<i;c++)r[c]===0&&o.push(c);if(!o.length&&i){let c=0;for(let u=1;u<i;u++)s[u].length>s[c].length&&(c=u);o.push(c)}}let a=Array.from({length:i},()=>[]),l=new Uint8Array(i),f=c=>{l[c]=1;let u=[c];for(let h=0;h<u.length;h++){let p=u[h];for(let d of s[p])l[d]||(l[d]=1,a[p].push(d),u.push(d))}};for(let c of o)l[c]||f(c);for(let c=0;c<2;c++)for(let u=0;u<i;u++)l[u]||c===0&&r[u]>0||(o.push(u),f(u));return{roots:o.filter((c,u)=>o.indexOf(c)===u),children:a}}function jn(t,e){let n=t.children.length,i=f=>({i:f,children:[]}),s={i:-1,children:[]},r=[];for(let f of t.roots){let c=i(f);s.children.push(c),r.push(c)}for(;r.length;){let f=r.pop();for(let c of t.children[f.i]){let u=i(c);f.children.push(u),r.push(u)}}let o=ut(s,f=>f.children);pt().nodeSize([e,1]).separation((f,c)=>f.parent===c.parent?1:1.5)(o);let a=new Int32Array(n),l=new Float64Array(n);return o.each(f=>{f.data.i<0||(a[f.data.i]=f.depth-1,l[f.data.i]=f.x)}),{depth:a,across:l}}function Fi(t,e={}){let n=t.nodes,i=new Map(n.map((u,h)=>[u.id,h])),s=$n(n,qt(i,t.edges,e.relationships),e.roots),r=e.nodeGap??Yt,o=e.levelGap??pe,a=e.direction??"TB",{depth:l,across:f}=jn(s,r),c=new Map;return n.forEach((u,h)=>{let[p,d]=Dt(a,l[h]*o,f[h]);c.set(u.id,[p,d,0])}),{positions:At(t,c)}}function Bi(t,e={}){let n=t.nodes,i=new Map(n.map((w,v)=>[w.id,v])),s=$n(n,qt(i,t.edges,e.relationships),e.roots),r=e.nodeGap??Yt,o=e.levelGap??pe,a=(e.sweep??360)*Math.PI/180,l=(e.startAngle??90)*Math.PI/180,{depth:f,across:c}=jn(s,r),u=s.roots.length===1,h=1/0,p=-1/0,d=0;for(let w=0;w<n.length;w++)c[w]<h&&(h=c[w]),c[w]>p&&(p=c[w]),f[w]>d&&(d=f[w]);let m=Math.abs(a-2*Math.PI)<1e-6,x=Math.max(p-h+(m?r:0),1e-9),g=Math.max(o,x/a/Math.max(d+(u?0:1),1)),y=new Map;return n.forEach((w,v)=>{let M=(f[v]+(u?0:1))*g,_=l-(c[v]-h)/x*a;y.set(w.id,[M*Math.cos(_),M*Math.sin(_),0])}),{positions:At(t,y)}}function Ri(t){if(t.length<2)return 0;let e=t.slice(),n=new Array(e.length),i=0;for(let s=1;s<e.length;s*=2)for(let r=0;r<e.length-s;r+=2*s){let o=r+s,a=Math.min(r+2*s,e.length),l=r,f=o,c=r;for(;l<o&&f<a;)e[l]<=e[f]?n[c++]=e[l++]:(n[c++]=e[f++],i+=o-l);for(;l<o;)n[c++]=e[l++];for(;f<a;)n[c++]=e[f++];for(let u=r;u<a;u++)e[u]=n[u]}return i}function Xi(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 s=[],r=[];for(let l=0;l<n;l++)for(s.push(t[l]-i[l]),r.push(1);s.length>1&&s[s.length-2]/r[r.length-2]>s[s.length-1]/r[r.length-1];){let f=s.pop(),c=r.pop();s[s.length-1]+=f,r[r.length-1]+=c}let o=new Array(n),a=0;for(let l=0;l<s.length;l++){let f=s[l]/r[l];for(let c=0;c<r[l];c++,a++)o[a]=f+i[a]}return o}function Yi(t,e){let n=Array.from({length:t},()=>[]);e.forEach(([h,p],d)=>n[h].push(d));let i=new Uint8Array(t),s=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,x]=d;if(x<n[m].length){d[1]++;let g=n[m][x],y=e[g][1];i[y]===1?s[g]=1:i[y]===0&&(i[y]=1,p.push([y,0]))}else i[m]=2,p.pop()}}let r=e.map(([h,p],d)=>s[d]?[p,h]:[h,p]),o=Array.from({length:t},()=>[]),a=Array.from({length:t},()=>[]),l=new Int32Array(t);for(let[h,p]of r)o[h].push(p),a[p].push(h),l[p]++;let f=[];for(let h=0;h<t;h++)l[h]===0&&f.push(h);for(let h=0;h<f.length;h++)for(let p of o[f[h]])--l[p]===0&&f.push(p);let c=new Array(t).fill(0);for(let h of f)for(let p of o[h])c[p]=Math.max(c[p],c[h]+1);for(let h=f.length-1;h>=0;h--){let p=f[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 u=Math.min(...c);return{rank:c.map(h=>h-u),dag:r}}function qi(t,e,n){let i=e.slice(),s=new Array(t).fill(!1),r=Array.from({length:t},()=>[]),o=Array.from({length:t},()=>[]),a=(p,d)=>{o[p].push(d),r[d].push(p)},l=[];for(let[p,d]of n){let m=[];if(l.push(m),i[d]-i[p]<1)continue;let x=p;for(let g=i[p]+1;g<i[d];g++){let y=i.length;i.push(g),s.push(!0),r.push([]),o.push([]),a(x,y),m.push(y),x=y}a(x,d)}let f=i.reduce((p,d)=>Math.max(p,d),0),c=Array.from({length:f+1},()=>[]),u=new Uint8Array(i.length),h=p=>{let d=[p];for(;d.length;){let m=d.pop();if(!u[m]){u[m]=1,c[i[m]].push(m);for(let x=o[m].length-1;x>=0;x--)u[o[m][x]]||d.push(o[m][x])}}};for(let p=0;p<t;p++)r[p].length||h(p);for(let p=0;p<i.length;p++)u[p]||h(p);return{rank:i,isDummy:s,up:r,down:o,layers:c,chains:l}}function Zn(t,e){let n=0;for(let i=0;i+1<t.layers.length;i++){let s=[];for(let r of t.layers[i])for(let o of t.down[r])s.push([e[r],e[o]]);s.sort((r,o)=>r[0]-o[0]||r[1]-o[1]),n+=Ri(s.map(r=>r[1]))}return n}function Zi(t,e){let n=new Int32Array(t.rank.length);(()=>{for(let o of t.layers)o.forEach((a,l)=>{n[a]=l})})();let s=Zn(t,n),r=t.layers.map(o=>o.slice());for(let o=0;o<e&&s>0;o++){let a=o%2===0,l=a?Array.from({length:t.layers.length-1},(c,u)=>u+1):Array.from({length:t.layers.length-1},(c,u)=>t.layers.length-2-u);for(let c of l){let u=t.layers[c],h=new Map;for(let p of u){let d=a?t.up[p]:t.down[p];h.set(p,d.length?d.reduce((m,x)=>m+n[x],0)/d.length:n[p])}u.sort((p,d)=>h.get(p)-h.get(d)||n[p]-n[d]),u.forEach((p,d)=>{n[p]=d})}let f=Zn(t,n);f<s&&(s=f,r=t.layers.map(c=>c.slice()))}t.layers=r}function Oi(t,e){let n=new Float64Array(t.rank.length),i=(o,a)=>e*((t.isDummy[o]?.4:1)+(t.isDummy[a]?.4:1))/2,s=o=>o.slice(1).map((a,l)=>i(o[l],a));for(let o of t.layers){let a=s(o),l=0,f=[0];for(let c of a)f.push(l+=c);o.forEach((c,u)=>{n[c]=f[u]-l/2})}let r=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((f,c)=>a?c:t.layers.length-1-c);for(let f of l){let c=t.layers[f];if(!c.length)continue;let u=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?r(d):n[p]}),h=Xi(u,s(c));c.forEach((p,d)=>{n[p]=h[d]})}}return n}function Gi(t,e={}){let n=t.nodes,i=n.length;if(!i)return{positions:new Map};let s=new Map(n.map((_,A)=>[_.id,A])),r=qt(s,t.edges,e.relationships),o,a;if(e.rankBy){let _=n.map(b=>Xt(b,e.rankBy)),A=Un(_,e.rankOrder),N=new Map(A.map((b,D)=>[b,D]));o=_.map(b=>N.get(b)??A.length),a=r.map(([b,D])=>o[b]<=o[D]?[b,D]:[D,b])}else({rank:o,dag:a}=Yi(i,r));let l=qi(i,o,a);Zi(l,e.sweeps??24);let f=Oi(l,e.nodeGap??Yt),c=e.levelGap??pe,u=e.direction??"TB",h=new Map;if(n.forEach((_,A)=>{let[N,b]=Dt(u,l.rank[A]*c,f[A]);h.set(_.id,[N,b,0])}),e.edgeShape!=="routed")return{positions:At(t,h)};let p=n.length?[...h.get(n[0].id)]:[0,0,0],d=At(t,h),m=n.length?d.get(n[0].id):[0,0,0],x=m[0]-p[0],g=m[1]-p[1],y=_=>{let[A,N]=Dt(u,l.rank[_]*c,f[_]);return[A+x,N+g,0]},w=new Map(r.map(([_,A],N)=>[_*i+A,N])),v=e.relationships&&e.relationships.length?new Set(e.relationships):null,M=new Map;for(let _ of t.edges){if(v&&!v.has(_.relationship))continue;let A=s.get(_.source),N=s.get(_.target);if(A===void 0||N===void 0||A===N)continue;let b=w.get(A*i+N);if(b===void 0)continue;let D=l.chains[b];if(a[b][0]!==A&&(D=[...D].reverse()),D.length>ue){let P=D.length;D=Array.from({length:ue},(E,L)=>D[Math.round(L*(P-1)/(ue-1))])}M.set(_.id,{shape:"routed",route:D.length?D.map(y):null})}return{positions:d,edgeParams:M}}var ue=16;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((y,w)=>[y.id,w])),s=n.map(y=>Xt(y,e.by)),r=Un(s,e.order),o=new Map(r.map((y,w)=>[y,w])),a=s.map(y=>o.get(y)??r.length),l=Math.max(...a)+1,f=Array.from({length:l},()=>[]);n.forEach((y,w)=>f[a[w]].push(w));let c=n.map(()=>[]);for(let[y,w]of qt(i,t.edges,e.relationships))a[y]!==a[w]&&(c[y].push(w),c[w].push(y));let u=e.sortBy??"barycenter",h=new Float64Array(n.length),p=y=>y.forEach((w,v)=>{h[w]=v-(y.length-1)/2});if(f.forEach(p),u==="barycenter")for(let y=0;y<12;y++){let w=f.map((v,M)=>y%2===0?M:l-1-M);for(let v of w){let M=f[v],_=new Map(M.map(A=>[A,c[A].length?c[A].reduce((N,b)=>N+h[b],0)/c[A].length:h[A]]));M.sort((A,N)=>_.get(A)-_.get(N)||h[A]-h[N]),p(M)}}else if(u==="degree")for(let y of f)y.sort((w,v)=>c[v].length-c[w].length||w-v),p(y);else if(u!=="none")for(let y of f)y.sort((w,v)=>{let M=Xt(n[w],u),_=Xt(n[v],u);return typeof M=="number"&&typeof _=="number"?M-_||w-v:String(M??"").localeCompare(String(_??""))||w-v}),p(y);let d=e.nodeGap??Yt,m=e.levelGap??4,x=e.direction??"LR",g=new Map;return n.forEach((y,w)=>{let[v,M]=Dt(x,a[w]*m,h[w]*d);g.set(y.id,[v,M,0])}),{positions:At(t,g)}}var $i="PARENT_OF",ji="SPOUSE_OF";function Vi(t,e={}){let n=e.parent?.relationship??$i,i=e.spouse?.relationship??ji,s=e.spouse?.order,r=e.mode??"descendants",o=e.direction??"TB",a=e.generationGap??3,l=e.siblingGap??1.5,f=e.spouseGap??1,c=new Map(t.nodes.map((k,z)=>[k.id,z])),u=k=>c.has(k),h=new Map,p=new Map,d=[],m=[],x=new Map,g=(k,z,I)=>{let S=k.get(z);S?S.push(I):k.set(z,[I])},y=0;for(let k of t.edges)if(!(k.source===k.target||!u(k.source)||!u(k.target))){if(k.relationship===n)d.push({id:k.id,p:k.source,c:k.target}),(h.get(k.source)??[]).includes(k.target)||(g(h,k.source,k.target),g(p,k.target,k.source));else if(k.relationship===i){m.push({id:k.id,a:k.source,b:k.target});let z=s?k.properties?.[s]:void 0;g(x,k.source,{other:k.target,order:z,k:y}),g(x,k.target,{other:k.source,order:z,k:y}),y++}}let w=k=>h.get(k)??[],v=k=>p.get(k)??[],M=k=>(x.get(k)??[]).map(z=>z.other),_=e.root;if(_!==void 0&&!u(_))throw new Error(`[genealogy] root "${_}" is not among the nodes`);if(_===void 0&&r!=="descendants")throw new Error(`[genealogy] mode "${r}" needs a root`);let A=new Set;if(_===void 0)for(let k of t.nodes)A.add(k.id);else{if(r!=="ancestors"){let k=[_],z=new Set(k);for(;k.length;){let I=k.shift();A.add(I);for(let S of M(I))A.add(S);for(let S of w(I)){for(let C of v(S))A.add(C);z.has(S)||(z.add(S),k.push(S))}}}if(r!=="descendants"){let k=[_],z=new Set(k);for(;k.length;){let I=k.shift();A.add(I);for(let S of v(I))z.has(S)||(z.add(S),k.push(S))}}}let N=t.nodes.map(k=>k.id).filter(k=>A.has(k)),b=new Map(N.map(k=>[k,k])),D=k=>{let z=k;for(;b.get(z)!==z;)z=b.get(z);for(;b.get(k)!==z;){let I=b.get(k);b.set(k,z),k=I}return z},P=new Map,E=(k,z)=>{!A.has(k)||!A.has(z)||k===z||(b.set(D(k),D(z)),P.has(k)||P.set(k,new Set),P.has(z)||P.set(z,new Set),P.get(k).add(z),P.get(z).add(k))};for(let k of m)E(k.a,k.b);for(let k of N){let z=v(k).filter(I=>A.has(I));for(let I=1;I<z.length;I++)E(z[0],z[I])}let L=new Map;for(let k of N)g(L,D(k),k);let X=[],Z=new Map;for(let k of L.values()){let z=Hi(k,P,x,c),I=X.length;X.push({members:z});for(let S of z)Z.set(S,I)}let G=(k,z)=>X[k].members.indexOf(z),J=k=>{let z=[],I=new Set;for(let C of X[k].members)for(let T of w(C)){if(!A.has(T)||I.has(T))continue;I.add(T);let j=v(T).map(nt=>G(k,nt)).filter(nt=>nt>=0),ft=j.reduce((nt,lt)=>nt+lt,0)/j.length;z.push({c:T,key:ft,at:z.length})}z.sort((C,T)=>C.key-T.key||C.at-T.at);let S=[];for(let{c:C}of z){let T=Z.get(C);T!==k&&!S.includes(T)&&S.push(T)}return S},H=k=>{let z=[];for(let I of X[k].members)for(let S of v(I)){if(!A.has(S))continue;let C=Z.get(S);C!==k&&!z.includes(C)&&z.push(C)}return z},W=k=>(X[k].members.length-1)*f,ot=(k,z,I)=>{let S=[];for(let C of k){if(I.has(C))continue;I.add(C);let T={u:C,children:[]};S.push(T);let j=[T];for(;j.length;){let ft=j.shift();for(let nt of z(ft.u)){if(I.has(nt))continue;I.add(nt);let lt={u:nt,children:[]};ft.children.push(lt),j.push(lt)}}}return S},q=k=>{let z=new Map;if(!k.length)return z;let S=ut({u:-1,children:k},T=>T.children),C=T=>T.data.u<0?0:W(T.data.u);return pt().nodeSize([1,1]).separation((T,j)=>(C(T)+C(j))/2+(T.parent===j.parent?l:l*1.5))(S),S.each(T=>{T.data.u>=0&&z.set(T.data.u,[T.x,T.depth-1])}),z},F=new Map;if(r!=="ancestors"){let k;_!==void 0?k=[Z.get(_)]:k=[...X.map((I,S)=>S).filter(I=>X[I].members.every(S=>!v(S).some(C=>A.has(C)))),...X.map((I,S)=>S)];for(let[z,[I,S]]of q(ot(k,J,new Set)))F.set(z,[I,S])}if(r!=="descendants"){let k=Z.get(_),z=q(ot([k],H,new Set)),I=(F.get(k)?.[0]??0)-(z.get(k)?.[0]??0);for(let[S,[C,T]]of z)F.has(S)||F.set(S,[C+I,-T])}let R=new Map;for(let[k,[z,I]]of F){let S=X[k].members;S.forEach((C,T)=>{let j=z+(T-(S.length-1)/2)*f,[ft,nt]=Dt(o,I*a,j);R.set(C,[ft,nt,0])})}let $={positions:At(t,R),edgeRoutingAxis:o==="LR"||o==="RL"?"horizontal":"vertical"};if(e.edgeShapes===!1)return $;let O=new Map,at=(k,z)=>v(k).filter(I=>R.has(I)&&Z.get(I)===z).sort((I,S)=>G(z,I)-G(z,S)).join(""),et=new Map;for(let{p:k,c:z}of d){if(!R.has(k)||!R.has(z))continue;let I=Z.get(k),S=at(z,I),C=et.get(I)??[];C.includes(S)||C.push(S),et.set(I,C)}for(let[k,z]of et){let I=S=>{let C=S.split("");return C.reduce((T,j)=>T+G(k,j),0)/C.length};z.sort((S,C)=>I(S)-I(C))}for(let{id:k,p:z,c:I}of d){if(!R.has(z)||!R.has(I))continue;let S=Z.get(z),T=v(I).filter(lt=>lt!==z&&R.has(lt)).find(lt=>Z.get(lt)===S)??null,j=et.get(S),ft=j.indexOf(at(I,S)),nt=j.length===1?.5:.3+.4*ft/(j.length-1);O.set(k,{shape:"family",anchor:T,bend:-a*nt})}for(let{id:k,a:z,b:I}of m)!R.has(z)||!R.has(I)||O.set(k,{shape:"orthogonal",bend:null});return $.edgeParams=O,$}function Hi(t,e,n,i){if(t.length===1)return t;let s=(d,m)=>i.get(d)-i.get(m),r=d=>e.get(d)?.size??0,o=[...t].sort((d,m)=>r(m)-r(d)||s(d,m))[0],a=d=>{let m=(n.get(o)??[]).find(x=>x.other===d);return m?[m.order,m.k]:[void 0,Number.MAX_SAFE_INTEGER]},l=(d,m)=>{let[x,g]=a(d),[y,w]=a(m);return x!==void 0&&y!==void 0&&x!==y?typeof x=="number"&&typeof y=="number"?x-y:String(x)<String(y)?-1:1:x!==void 0&&y===void 0?-1:x===void 0&&y!==void 0?1:g-w||s(d,m)},f=[...e.get(o)??[]].filter(d=>t.includes(d)).sort(l),c=[],u=[];f.forEach((d,m)=>(m%2===0?c:u).push(d));let h=new Set([o,...f]),p=t.filter(d=>!h.has(d)).sort(s);for(let d of p){let m=[...e.get(d)??[]].find(x=>h.has(x));(m!==void 0&&c.includes(m)?c:u).push(d),h.add(d)}return[...c.reverse(),o,...u]}function _t(t){if(t==null)return null;let e=Number(t);return Number.isNaN(e)?null:e}function vt(t,e,n){let[i,s]=e,[r,o]=n;return s===i?(r+o)/2:r+(t-i)/(s-i)*(o-r)}function Mt(t,e,n){let i=Math.max(e[0],1e-10),s=Math.max(e[1],1e-10),r=Math.max(t,1e-10),[o,a]=n;return s===i?(o+a)/2:o+(Math.log(r)-Math.log(i))/(Math.log(s)-Math.log(i))*(a-o)}function Wi(t,e,n){let i=n??_t,s=1/0,r=-1/0;for(let o of t){let a=o.properties?.[e],l=i(a);l!=null&&(l<s&&(s=l),l>r&&(r=l))}return s===1/0?[0,1]:s===r?[s-1,r+1]:[s,r]}function Ki(t,e=5){let[n,i]=t,s=i-n;if(s===0)return[n-1,i+1];let r=s/e,o=Math.pow(10,Math.floor(Math.log10(r))),a=r/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 Qi(t,e=5){let[n,i]=t;if(n===i)return[n];let r=(i-n)/e,o=Math.pow(10,Math.floor(Math.log10(r))),a=r/o,l;a<=1.5?l=o:a<=3.5?l=2*o:a<=7.5?l=5*o:l=10*o;let f=Math.ceil(n/l)*l,c=[];for(let u=f;u<=i+l*.001;u+=l)c.push(Math.round(u*1e10)/1e10);return c}var he=[{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 Ji(t,e=5){let[n,i]=t,s=i-n;if(s<=0)return[n];let r=s/e,o=he[he.length-1];for(let l of he)if(l.ms>=r*.6){o=l;break}let a=[];if(o.calendarUnit==="year"){let l=o.calendarStep,f=new Date(n),c=Math.ceil(f.getFullYear()/l)*l;for(;;){let u=new Date(c,0,1).getTime();if(u>i)break;u>=n&&a.push(u),c+=l}}else if(o.calendarUnit==="month"){let l=o.calendarStep,f=new Date(n),c=f.getFullYear(),u=Math.ceil(f.getMonth()/l)*l;for(;;){let h=new Date(c,u,1).getTime();if(h>i)break;h>=n&&a.push(h),u+=l,u>=12&&(c+=Math.floor(u/12),u=u%12)}}else{let l=o.ms,f=Math.ceil(n/l)*l;for(let c=f;c<=i;c+=l)a.push(c)}return a}function ts(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 kt(t,e,n){let i=t.domain??Wi(e,t.property,t.parse);t.nice&&!t.domain&&(i=Ki(i,t.tickCount));let r=(i[1]-i[0])*n,o=[i[0]-r,i[1]+r],a;t.tickValues?a=t.tickValues:t.isDate?a=Ji(i,t.tickCount):a=Qi(i,t.tickCount);let l=t.tickFormat;return!l&&t.isDate&&(l=f=>ts(f,i)),{axisInfo:{property:t.property,label:t.property,domain:o,ticks:a,scale:t.scale,tickFormat:l},paddedDomain:o}}function es(t,e){let{propertyX:n,propertyY:i,propertyZ:s,range:r=[-2,2],scaleX:o="linear",scaleY:a="linear",scaleZ:l="linear",padding:f=.05}=e,c=e.parseX??_t,u=e.parseY??_t,h=e.parseZ??_t,p=!!n,d=!!i,m=!!s,x=t.nodes,g=new Map,y=new Set,w=[];for(let L of x){let X=0,Z=0,G=0,J=!1;if(p){let H=c(L.properties?.[n]);H==null?J=!0:X=H}if(d&&!J){let H=u(L.properties?.[i]);H==null?J=!0:Z=H}if(m&&!J){let H=h(L.properties?.[s]);H==null?J=!0:G=H}J?y.add(L.id):w.push({id:L.id,x:X,y:Z,z:G})}let v=p?kt({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},x,f):null,M=d?kt({property:i,scale:a,domain:e.domainY,parse:u,tickFormat:e.tickFormatY,tickCount:e.tickCountY??5,tickValues:e.tickValuesY,nice:e.niceY??!0,isDate:e.dateAxisY??!1},x,f):null,_=m?kt({property:s,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},x,f):null,A=o==="log"?Mt:vt,N=a==="log"?Mt:vt,b=l==="log"?Mt:vt,D=e.spread??1,P=[r[0]*D,r[1]*D],E=r[0];for(let L of w){let X=v?A(L.x,v.paddedDomain,P):E,Z=M?N(L.y,M.paddedDomain,P):E,G=_?b(L.z,_.paddedDomain,P):0;g.set(L.id,[X,Z,G])}return{positions:g,axes:{x:v?.axisInfo,y:M?.axisInfo,z:_?.axisInfo},range:P,baseRange:r,excludedNodeIds:y}}function ns(t,e){let n=e.range??[-2,2],i=e.spread??1,s=[n[0]*i,n[1]*i],r=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 f=new Map;for(let p of t.nodes){let d=p.category,m=f.get(d);m||(m=[],f.set(d,m)),m.push(p)}let c=new Map,u=new Set,h={};for(let[p,d]of f){let m=l.get(p);if(!m){if(a==="hide")for(let F of d)u.add(F.id);else{let F;a==="boundary"?F=n[0]:F=(n[0]+n[1])/2;for(let R of d)c.set(R.id,[F,F,0])}continue}let x=!!m.propertyX,g=!!m.propertyY,y=!!m.propertyZ,w=m.scaleX??"linear",v=m.scaleY??"linear",M=m.scaleZ??"linear",_=m.parseX??_t,A=m.parseY??_t,N=m.parseZ??_t,b=m.tickCountX??e.tickCountX??5,D=m.tickCountY??e.tickCountY??5,P=m.tickCountZ??e.tickCountZ??5,E=m.niceX??e.niceX??!0,L=m.niceY??e.niceY??!0,X=m.niceZ??e.niceZ??!0,Z=[];for(let F of d){let R=0,$=0,O=0,at=!1;if(x){let et=_(F.properties?.[m.propertyX]);et==null?at=!0:R=et}if(g&&!at){let et=A(F.properties?.[m.propertyY]);et==null?at=!0:$=et}if(y&&!at){let et=N(F.properties?.[m.propertyZ]);et==null?at=!0:O=et}at?u.add(F.id):Z.push({id:F.id,x:R,y:$,z:O})}let G=x?kt({property:m.propertyX,scale:w,domain:m.domainX,parse:_,tickFormat:m.tickFormatX,tickCount:b,tickValues:m.tickValuesX,nice:E,isDate:m.dateAxisX??!1},d,r):null,J=g?kt({property:m.propertyY,scale:v,domain:m.domainY,parse:A,tickFormat:m.tickFormatY,tickCount:D,tickValues:m.tickValuesY,nice:L,isDate:m.dateAxisY??!1},d,r):null,H=y?kt({property:m.propertyZ,scale:M,domain:m.domainZ,parse:N,tickFormat:m.tickFormatZ,tickCount:P,tickValues:m.tickValuesZ,nice:X,isDate:m.dateAxisZ??!1},d,r):null,W=w==="log"?Mt:vt,ot=v==="log"?Mt:vt,q=M==="log"?Mt:vt;for(let F of Z){let R=G?W(F.x,G.paddedDomain,s):o,$=J?ot(F.y,J.paddedDomain,s):o,O=H?q(F.z,H.paddedDomain,s):0;c.set(F.id,[R,$,O])}h[p]={x:G?.axisInfo,y:J?.axisInfo,z:H?.axisInfo}}return{positions:c,axes:{x:void 0,y:void 0,z:void 0},range:s,baseRange:n,excludedNodeIds:u,categoryAxes:h}}var is=/^[a-z][a-zA-Z0-9]*$/,ss=/^[a-z][a-z0-9-]*:[A-Za-z][A-Za-z0-9_-]*$/,rs=class Vn{constructor(){this.entries=new Map}register(e,n,i={}){if(!ss.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(!is.test(e))throw new Error(`[LayoutRegistry] invalid built-in layout name "${e}"`);this.add(e,n,!0,{description:i})}add(e,n,i,s){if(typeof n!="function")throw new Error(`[LayoutRegistry] layout "${e}" must be a function`);let r=this.entries.get(e);if(r&&(r.builtin||!s.replace))throw new Error(`[LayoutRegistry] layout "${e}" is already registered`);let o={name:e,fn:n,builtin:i,description:s.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 s=this.entries.get(e);if(!s)throw new Error(`[LayoutRegistry] unknown layout "${e}". Registered: ${[...this.entries.keys()].join(", ")}`);return s.fn(n,i)}fork(){let e=new Vn;for(let[n,i]of this.entries)e.entries.set(n,i);return e}};function os(){let t=new rs;return t.registerBuiltin("circle",Ai,"Nodes on a circle."),t.registerBuiltin("grid",zi,"Nodes on a 2-D grid."),t.registerBuiltin("line",Ni,"Nodes along an axis."),t.registerBuiltin("spiral",Ii,"Nodes on a spiral."),t.registerBuiltin("cube",Si,"Nodes in a 3-D lattice."),t.registerBuiltin("sphere",bi,"Nodes on a sphere."),t.registerBuiltin("scatter",Di,"Nodes scattered randomly in a range."),t.registerBuiltin("ego",Ci,"Tree or rings around root node(s)."),t.registerBuiltin("tree",Fi,"Tidy tree (org chart, directory); forests supported."),t.registerBuiltin("radialTree",Bi,"Tidy tree in polar form, root in the centre."),t.registerBuiltin("layered",Gi,"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("genealogy",Vi,"Family tree: couples side by side, children under their parents, shared family lines."),t.registerBuiltin("rotate",Ei,"Rotate current positions (transform)."),t.registerBuiltin("scale",Pi,"Scale current positions (transform)."),t.registerBuiltin("shift",Li,"Translate current positions (transform)."),t.registerBuiltin("alignBy",Ti,"Align nodes by an axis (transform)."),t.registerBuiltin("plotScatter",es,"Scatter plot by two properties."),t.registerBuiltin("plotMultiCategoryScatter",ns,"Scatter plot with category axes."),t}var Hn=os();function va(){return Hn.fork()}function Ma(t,e){let n=Hn.get(e.type);return n?n.fn(t,e.options):{positions:new Map}}var as={linear:t=>t,easeIn:t=>t*t,easeOut:t=>t*(2-t),easeInOut:t=>t<.5?2*t*t:-1+(4-2*t)*t},ka=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=as[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),s=new Map;for(let[r,o]of this.endPositions){let a=this.startPositions.get(r)??o;s.set(r,[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?.()),s}},Aa=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,s=this._positions.get(i);s&&(e[n*3]=s.x,e[n*3+1]=s.y,e[n*3+2]=s.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 On(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 s=Array.from(n.values()).map((o,a)=>({...o,index:a})),r=Array.from(i.values()).map((o,a)=>({...o,index:a}));return{...t,version:e.graphVersion,nodes:s,edges:r}}var rt={dimensions:3,alpha:.6,alphaDecay:.1,velocityDecay:.3,charge:-.01,gravity:.1,collision:.15,linkDistance:.5,linkStrength:1,warmupTicks:0},Na=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={...rt,...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=On(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 s=this._simNodes[i];s.x=n.position.x,s.y=n.position.y,s.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 s=this._simNodes[i];if(n.pinned){let r=n.position??{x:s.x,y:s.y,z:s.z};s.fx=r.x,s.fy=r.y,s.fz=r.z}else s.fx=null,s.fy=null,s.fz=null}this._snapshot=On(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??rt.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 s=n*4;this._positions[s]=e.x,this._positions[s+1]=e.y,this._positions[s+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,s=i.charge??rt.charge,r=i.gravity??rt.gravity,o=i.linkDistance??rt.linkDistance,a=i.linkStrength??rt.linkStrength,l=i.collision??rt.collision,f=i.alpha??rt.alpha,c=i.alphaDecay??rt.alphaDecay,u=i.velocityDecay??rt.velocityDecay;this._simulation=oe(this._simNodes,e).alpha(f).alphaDecay(c).velocityDecay(u).force("charge",ae().strength(s)).force("link",te(n).distance(o).strength(a)).force("x",le().strength(r)).force("y",ce().strength(r)).force("z",fe().strength(e===2?0:r)).force("collision",Jt().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{ee as a,Bt as b,ht as c,Ai as d,zi as e,Ni as f,Ii as g,Si as h,bi as i,Di as j,Ei as k,Pi as l,Li as m,Ti as n,Ci as o,Fi as p,Bi as q,Gi as r,Ui as s,Vi as t,_t as u,vt as v,Mt as w,Wi as x,Qi as y,es as z,ns as A,rs as B,Hn as C,va as D,Ma as E,ka as F,Aa as G,Na as H};
2
+ //# sourceMappingURL=chunk-EHGKWZTS.mjs.map