@kineviz/gl 0.7.1 → 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.
- package/CHANGELOG.md +506 -0
- package/LICENSE +21 -201
- package/NOTICE +9 -1
- package/README.md +1 -1
- package/dist/WebGLForceLayoutController-P6NPZ7WK.mjs +1538 -0
- package/dist/builtins.css +2 -0
- package/dist/builtins.d.mts +61 -0
- package/dist/builtins.d.ts +61 -0
- package/dist/builtins.js +3815 -0
- package/dist/builtins.mjs +2 -0
- package/dist/chunk-4PNV55G2.mjs +394 -0
- package/dist/chunk-67FBXXN6.mjs +2875 -0
- package/dist/chunk-EHGKWZTS.mjs +2 -0
- package/dist/chunk-L6OXJ7GJ.mjs +1245 -0
- package/dist/{chunk-EDTCHJCZ.mjs → chunk-Y34RQAIU.mjs} +2 -2
- package/dist/core-X3TWUvT9.d.ts +934 -0
- package/dist/core-ueqhAojr.d.mts +934 -0
- package/dist/core.css +2 -0
- package/dist/core.d.mts +11 -0
- package/dist/core.d.ts +11 -0
- package/dist/core.js +6187 -0
- package/dist/core.mjs +2 -0
- package/dist/index.css +1 -1
- package/dist/index.d.mts +414 -20112
- package/dist/index.d.ts +414 -20112
- package/dist/index.js +5268 -3479
- package/dist/index.mjs +309 -4564
- package/dist/kineviz-gl.css +1 -1
- package/dist/kineviz-gl.umd.js +5268 -3761
- package/dist/layout-gpu.js +45 -45
- package/dist/layout-gpu.mjs +1 -1
- package/dist/registry-BIPi31x_.d.mts +19930 -0
- package/dist/registry-BIPi31x_.d.ts +19930 -0
- package/dist/schemas.js +1 -1
- package/dist/schemas.mjs +1 -1
- package/dist/{webgpu-YXDFF4ZT.mjs → webgpu-SY2OB4QP.mjs} +2 -2
- package/dist/world-rings-6GQ4OWZC.mjs +2 -0
- package/package.json +22 -3
- package/dist/chunk-3CR3GHJ2.mjs +0 -2
- package/dist/chunk-VTIPA7FV.mjs +0 -2
package/dist/layout-gpu.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var pi=Object.create;var Ke=Object.defineProperty;var hi=Object.getOwnPropertyDescriptor;var mi=Object.getOwnPropertyNames;var gi=Object.getPrototypeOf,yi=Object.prototype.hasOwnProperty;var vi=(e,t)=>{for(var n in t)Ke(e,n,{get:t[n],enumerable:!0})},Ot=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of mi(t))!yi.call(e,r)&&r!==n&&Ke(e,r,{get:()=>t[r],enumerable:!(i=hi(t,r))||i.enumerable});return e};var pe=(e,t,n)=>(n=e!=null?pi(gi(e)):{},Ot(t||!e||!e.__esModule?Ke(n,"default",{value:e,enumerable:!0}):n,e)),xi=e=>Ot(Ke({},"__esModule",{value:!0}),e);var va={};vi(va,{GPUForceLayoutController:()=>Gt,GPUForceLayoutEngine:()=>di,GPULayoutControllerAdapter:()=>Nt,WebGPUForceLayoutController:()=>ft,WebGPULayoutControllerAdapter:()=>pt,createForceLayout:()=>ci,isWebGPUAvailable:()=>Pe});module.exports=xi(va);function bi(e){var t=0,n=e.children,i=n&&n.length;if(!i)t=1;else for(;--i>=0;)t+=n[i].value;e.value=t}function Ht(){return this.eachAfter(bi)}function Xt(e,t){let n=-1;for(let i of this)e.call(t,i,++n,this);return this}function Yt(e,t){for(var n=this,i=[n],r,o,a=-1;n=i.pop();)if(e.call(t,n,++a,this),r=n.children)for(o=r.length-1;o>=0;--o)i.push(r[o]);return this}function $t(e,t){for(var n=this,i=[n],r=[],o,a,s,l=-1;n=i.pop();)if(r.push(n),o=n.children)for(a=0,s=o.length;a<s;++a)i.push(o[a]);for(;n=r.pop();)e.call(t,n,++l,this);return this}function Zt(e,t){let n=-1;for(let i of this)if(e.call(t,i,++n,this))return i}function jt(e){return this.eachAfter(function(t){for(var n=+e(t.data)||0,i=t.children,r=i&&i.length;--r>=0;)n+=i[r].value;t.value=n})}function Vt(e){return this.eachBefore(function(t){t.children&&t.children.sort(e)})}function Wt(e){for(var t=this,n=Mi(t,e),i=[t];t!==n;)t=t.parent,i.push(t);for(var r=i.length;e!==n;)i.splice(r,0,e),e=e.parent;return i}function Mi(e,t){if(e===t)return e;var n=e.ancestors(),i=t.ancestors(),r=null;for(e=n.pop(),t=i.pop();e===t;)r=e,e=n.pop(),t=i.pop();return r}function Kt(){for(var e=this,t=[e];e=e.parent;)t.push(e);return t}function Qt(){return Array.from(this)}function Jt(){var e=[];return this.eachBefore(function(t){t.children||e.push(t)}),e}function en(){var e=this,t=[];return e.each(function(n){n!==e&&t.push({source:n.parent,target:n})}),t}function*tn(){var e=this,t,n=[e],i,r,o;do for(t=n.reverse(),n=[];e=t.pop();)if(yield e,i=e.children)for(r=0,o=i.length;r<o;++r)n.push(i[r]);while(n.length)}function Ae(e,t){e instanceof Map?(e=[void 0,e],t===void 0&&(t=Si)):t===void 0&&(t=_i);for(var n=new be(e),i,r=[n],o,a,s,l;i=r.pop();)if((a=t(i.data))&&(l=(a=Array.from(a)).length))for(i.children=a,s=l-1;s>=0;--s)r.push(o=a[s]=new be(a[s])),o.parent=i,o.depth=i.depth+1;return n.eachBefore(yt)}function wi(){return Ae(this).eachBefore(Ti)}function _i(e){return e.children}function Si(e){return Array.isArray(e)?e[1]:null}function Ti(e){e.data.value!==void 0&&(e.value=e.data.value),e.data=e.data.data}function yt(e){var t=0;do e.height=t;while((e=e.parent)&&e.height<++t)}function be(e){this.data=e,this.depth=this.height=0,this.parent=null}be.prototype=Ae.prototype={constructor:be,count:Ht,each:Xt,eachAfter:$t,eachBefore:Yt,find:Zt,sum:jt,sort:Vt,path:Wt,ancestors:Kt,descendants:Qt,leaves:Jt,links:en,copy:wi,[Symbol.iterator]:tn};function Qe(e){return e==null?null:Pi(e)}function Pi(e){if(typeof e!="function")throw new Error;return e}var Bi={depth:-1},nn={},vt={};function zi(e){return e.id}function Ci(e){return e.parentId}function bt(){var e=zi,t=Ci,n;function i(r){var o=Array.from(r),a=e,s=t,l,u,c,f,d,p,m,g,y=new Map;if(n!=null){let w=o.map((v,b)=>ki(n(v,b,r))),M=w.map(rn),h=new Set(w).add("");for(let v of M)h.has(v)||(h.add(v),w.push(v),M.push(rn(v)),o.push(vt));a=(v,b)=>w[b],s=(v,b)=>M[b]}for(c=0,l=o.length;c<l;++c)u=o[c],p=o[c]=new be(u),(m=a(u,c,r))!=null&&(m+="")&&(g=p.id=m,y.set(g,y.has(g)?nn:p)),(m=s(u,c,r))!=null&&(m+="")&&(p.parent=m);for(c=0;c<l;++c)if(p=o[c],m=p.parent){if(d=y.get(m),!d)throw new Error("missing: "+m);if(d===nn)throw new Error("ambiguous: "+m);d.children?d.children.push(p):d.children=[p],p.parent=d}else{if(f)throw new Error("multiple roots");f=p}if(!f)throw new Error("no root");if(n!=null){for(;f.data===vt&&f.children.length===1;)f=f.children[0],--l;for(let w=o.length-1;w>=0&&(p=o[w],p.data===vt);--w)p.data=null}if(f.parent=Bi,f.eachBefore(function(w){w.depth=w.parent.depth+1,--l}).eachBefore(yt),f.parent=null,l>0)throw new Error("cycle");return f}return i.id=function(r){return arguments.length?(e=Qe(r),i):e},i.parentId=function(r){return arguments.length?(t=Qe(r),i):t},i.path=function(r){return arguments.length?(n=Qe(r),i):n},i}function ki(e){e=`${e}`;let t=e.length;return xt(e,t-1)&&!xt(e,t-2)&&(e=e.slice(0,-1)),e[0]==="/"?e:`/${e}`}function rn(e){let t=e.length;if(t<2)return"";for(;--t>1&&!xt(e,t););return e.slice(0,t)}function xt(e,t){if(e[t]==="/"){let n=0;for(;t>0&&e[--t]==="\\";)++n;if((n&1)===0)return!0}return!1}function Ei(e,t){return e.parent===t.parent?1:2}function Mt(e){var t=e.children;return t?t[0]:e.t}function wt(e){var t=e.children;return t?t[t.length-1]:e.t}function Fi(e,t,n){var i=n/(t.i-e.i);t.c-=i,t.s+=n,e.c+=i,t.z+=n,t.m+=n}function Ii(e){for(var t=0,n=0,i=e.children,r=i.length,o;--r>=0;)o=i[r],o.z+=t,o.m+=t,t+=o.s+(n+=o.c)}function Di(e,t,n){return e.a.parent===t.parent?e.a:n}function Je(e,t){this._=e,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=t}Je.prototype=Object.create(be.prototype);function Ai(e){for(var t=new Je(e,0),n,i=[t],r,o,a,s;n=i.pop();)if(o=n._.children)for(n.children=new Array(s=o.length),a=s-1;a>=0;--a)i.push(r=n.children[a]=new Je(o[a],a)),r.parent=n;return(t.parent=new Je(null,0)).children=[t],t}function He(){var e=Ei,t=1,n=1,i=null;function r(u){var c=Ai(u);if(c.eachAfter(o),c.parent.m=-c.z,c.eachBefore(a),i)u.eachBefore(l);else{var f=u,d=u,p=u;u.eachBefore(function(M){M.x<f.x&&(f=M),M.x>d.x&&(d=M),M.depth>p.depth&&(p=M)});var m=f===d?1:e(f,d)/2,g=m-f.x,y=t/(d.x+m+g),w=n/(p.depth||1);u.eachBefore(function(M){M.x=(M.x+g)*y,M.y=M.depth*w})}return u}function o(u){var c=u.children,f=u.parent.children,d=u.i?f[u.i-1]:null;if(c){Ii(u);var p=(c[0].z+c[c.length-1].z)/2;d?(u.z=d.z+e(u._,d._),u.m=u.z-p):u.z=p}else d&&(u.z=d.z+e(u._,d._));u.parent.A=s(u,d,u.parent.A||f[0])}function a(u){u._.x=u.z+u.parent.m,u.m+=u.parent.m}function s(u,c,f){if(c){for(var d=u,p=u,m=c,g=d.parent.children[0],y=d.m,w=p.m,M=m.m,h=g.m,v;m=wt(m),d=Mt(d),m&&d;)g=Mt(g),p=wt(p),p.a=u,v=m.z+M-d.z-y+e(m._,d._),v>0&&(Fi(Di(m,u,f),u,v),y+=v,w+=v),M+=m.m,y+=d.m,h+=g.m,w+=p.m;m&&!wt(p)&&(p.t=m,p.m+=M-w),d&&!Mt(g)&&(g.t=d,g.m+=y-h,f=u)}return f}function l(u){u.x*=t,u.y=u.depth*n}return r.separation=function(u){return arguments.length?(e=u,r):e},r.size=function(u){return arguments.length?(i=!1,t=+u[0],n=+u[1],r):i?null:[t,n]},r.nodeSize=function(u){return arguments.length?(i=!0,t=+u[0],n=+u[1],r):i?[t,n]:null},r}var Le=pe(require("lodash"),1);var Ri={value:()=>{}};function sn(){for(var e=0,t=arguments.length,n={},i;e<t;++e){if(!(i=arguments[e]+"")||i in n||/[\s.]/.test(i))throw new Error("illegal type: "+i);n[i]=[]}return new et(n)}function et(e){this._=e}function Ui(e,t){return e.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&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:i}})}et.prototype=sn.prototype={constructor:et,on:function(e,t){var n=this._,i=Ui(e+"",n),r,o=-1,a=i.length;if(arguments.length<2){for(;++o<a;)if((r=(e=i[o]).type)&&(r=Li(n[r],e.name)))return r;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++o<a;)if(r=(e=i[o]).type)n[r]=on(n[r],e.name,t);else if(t==null)for(r in n)n[r]=on(n[r],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new et(e)},call:function(e,t){if((r=arguments.length-2)>0)for(var n=new Array(r),i=0,r,o;i<r;++i)n[i]=arguments[i+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(o=this._[e],i=0,r=o.length;i<r;++i)o[i].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var i=this._[e],r=0,o=i.length;r<o;++r)i[r].value.apply(t,n)}};function Li(e,t){for(var n=0,i=e.length,r;n<i;++n)if((r=e[n]).name===t)return r.value}function on(e,t,n){for(var i=0,r=e.length;i<r;++i)if(e[i].name===t){e[i]=Ri,e=e.slice(0,i).concat(e.slice(i+1));break}return n!=null&&e.push({name:t,value:n}),e}var _t=sn;var Re=0,Ye=0,Xe=0,un=1e3,tt,$e,nt=0,ze=0,it=0,Ze=typeof performance=="object"&&performance.now?performance:Date,cn=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Pt(){return ze||(cn(Gi),ze=Ze.now()+it)}function Gi(){ze=0}function St(){this._call=this._time=this._next=null}St.prototype=rt.prototype={constructor:St,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?Pt():+n)+(t==null?0:+t),!this._next&&$e!==this&&($e?$e._next=this:tt=this,$e=this),this._call=e,this._time=n,Tt()},stop:function(){this._call&&(this._call=null,this._time=1/0,Tt())}};function rt(e,t,n){var i=new St;return i.restart(e,t,n),i}function dn(){Pt(),++Re;for(var e=tt,t;e;)(t=ze-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Re}function ln(){ze=(nt=Ze.now())+it,Re=Ye=0;try{dn()}finally{Re=0,qi(),ze=0}}function Ni(){var e=Ze.now(),t=e-nt;t>un&&(it-=t,nt=e)}function qi(){for(var e,t=tt,n,i=1/0;t;)t._call?(i>t._time&&(i=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:tt=n);$e=e,Tt(i)}function Tt(e){if(!Re){Ye&&(Ye=clearTimeout(Ye));var t=e-ze;t>24?(e<1/0&&(Ye=setTimeout(ln,e-Ze.now()-it)),Xe&&(Xe=clearInterval(Xe))):(Xe||(nt=Ze.now(),Xe=setInterval(Ni,un)),Re=1,cn(ln))}}function Me(e){let t=0,n=0,i=0,r=0;for(let[,o]of e)t+=o[0],n+=o[1],i+=o[2],r++;return r===0?[0,0,0]:[t/r,n/r,i/r]}var Se=1;function xe(e,t){let n=new Map;for(let i=0;i<e.nodes.length;i++)n.set(e.nodes[i].id,t[i]);return{positions:n}}function pn(e,t){let n=e.nodes.length;if(n===0)return{positions:new Map};let i=Me(e.positions),r=t?.spacing??Se,o=t?.radius??Math.max(r,n*r/(2*Math.PI)),a=Math.PI*2/n,s=[];for(let l=0;l<n;l++)s.push([o*Math.cos(l*a)+i[0],o*Math.sin(l*a)+i[1],0]);return xe(e,s)}function hn(e,t){let n=e.nodes.length;if(n===0)return{positions:new Map};let i=Me(e.positions),r=t?.columns&&t.columns>0?t.columns:Math.ceil(Math.sqrt(n)),o=t?.spacing??Se,a=o*(r-1),s=[];for(let l=0;l<n;l++)s.push([l%r*o-a/2+i[0],-Math.floor(l/r)*o+a/2+i[1],0]);return xe(e,s)}function mn(e,t){let n=e.nodes.length;if(n===0)return{positions:new Map};let i=Me(e.positions),r=t?.axis??"x",o=t?.spacing??Se,a=o*(n-1),s=[];for(let l=0;l<n;l++){let u=n>1?-a/2+l*o:0,c=[i[0],i[1],i[2]],f=r==="x"?0:r==="y"?1:2;c[f]=u+i[f],s.push(c)}return xe(e,s)}function gn(e,t){let n=e.nodes.length;if(n===0)return{positions:new Map};let i=Me(e.positions),r=t?.spacing??1.5,o=r/(2*Math.PI),a=2*Math.PI,s=[];for(let l=0;l<n;l++){let u=o*a;s.push([u*Math.cos(a)+i[0],u*Math.sin(a)+i[1],0]),a+=r/u}return xe(e,s)}function yn(e,t){let n=e.nodes.length;if(n===0)return{positions:new Map};let i=Me(e.positions),r=Math.cbrt(n),o=Math.floor(r),a=Math.ceil(r),s=t?.size??(n-Math.pow(o,3)>Math.pow(a,3)-n?a:o),l=t?.spacing??Se,u=l*Math.max(s-1,0),c=[];for(let f=0;f<n;f++)c.push([f%s*l-u/2+i[0],-(Math.floor(f/s)%s)*l+u/2+i[1],-Math.floor(f/(s*s))*l+u/2+i[2]]);return xe(e,c)}function vn(e,t){let n=e.nodes.length;if(n<=1){let l=new Map;return n===1&&l.set(e.nodes[0].id,e.positions.get(e.nodes[0].id)??[0,0,0]),{positions:l}}let i=Me(e.positions),r=t?.spacing??Se,o=t?.density!==void 0?Math.sqrt(n/(4*Math.PI*t.density)):r*Math.sqrt(n/(4*Math.PI)),a=t?.radius??Math.max(r,o),s=[];for(let l=0;l<n;l++){let u=Math.acos(1-(2*(l+1)-1)/n),c=Math.sqrt(n*Math.PI)*u;s.push([a*Math.sin(u)*Math.cos(c)+i[0],a*Math.sin(u)*Math.sin(c)+i[1],a*Math.cos(u)+i[2]])}return xe(e,s)}function xn(e,t){let n=e.nodes.length;if(n===0)return{positions:new Map};let i=t?.spacing??Se,r=t?.range??Math.max(i,i*Math.cbrt(n)/2),o=t?.seed??42;function a(){o|=0,o=o+1831565813|0;let l=Math.imul(o^o>>>15,1|o);return l=l+Math.imul(l^l>>>7,61|l)^l,((l^l>>>14)>>>0)/4294967296}let s=[];for(let l=0;l<n;l++)s.push([(a()-.5)*r*2,(a()-.5)*r*2,(a()-.5)*r*2]);return xe(e,s)}function bn(e,t){if(e.nodes.length===0)return{positions:new Map};let i=t?.axis??"x",r=(t?.degrees??90)*Math.PI/180,o=Me(e.positions),a=[];for(let s of e.nodes){let l=e.positions.get(s.id)??[0,0,0],u=l[0]-o[0],c=l[1]-o[1],f=l[2]-o[2],d,p,m,g=Math.cos(r),y=Math.sin(r);i==="x"?(d=u,p=c*g-f*y,m=c*y+f*g):i==="y"?(d=u*g+f*y,p=c,m=-u*y+f*g):(d=u*g-c*y,p=u*y+c*g,m=f),a.push([d+o[0],p+o[1],m+o[2]])}return xe(e,a)}function Mn(e,t){if(e.nodes.length===0)return{positions:new Map};let i=t?.factor,r=i??t?.x??1,o=i??t?.y??1,a=i??t?.z??1,s=Me(e.positions),l=[];for(let u of e.nodes){let c=e.positions.get(u.id)??[0,0,0];l.push([c[0]+(c[0]-s[0])*(r-1),c[1]+(c[1]-s[1])*(o-1),c[2]+(c[2]-s[2])*(a-1)])}return xe(e,l)}function wn(e,t){if(e.nodes.length===0)return{positions:new Map};let i=t?.x??0,r=t?.y??0,o=t?.z??0,a=[];for(let s of e.nodes){let l=e.positions.get(s.id)??[0,0,0];a.push([l[0]+i,l[1]+r,l[2]+o])}return xe(e,a)}function _n(e,t){if(e.nodes.length===0)return{positions:new Map};let i=t?.axis??"x",r=i==="x"?0:i==="y"?1:2,o=1/0,a=-1/0;for(let u of e.nodes){let c=e.positions.get(u.id)??[0,0,0];c[r]<o&&(o=c[r]),c[r]>a&&(a=c[r])}let s=(o+a)/2,l=[];for(let u of e.nodes){let c=e.positions.get(u.id)??[0,0,0],f=[c[0],c[1],c[2]];f[r]=s,l.push(f)}return xe(e,l)}function Sn(e,t){let{depth:n=100,mode:i="tree",orientation:r="right",alongRelationships:o=[]}=t??{},a=t?.spacing??Se,s=t?.spacing===void 0?t?.edgeLength:void 0,l=e.nodes;if(l.length===0)return{positions:new Map};let u=new Set;for(let[x]of e.positions)u.add(x);let c=new Map,f=new Map;for(let x of e.edges)!u.has(x.source)||!u.has(x.target)||(f.set(x.id,x),c.has(x.source)||c.set(x.source,[]),c.has(x.target)||c.set(x.target,[]),c.get(x.source).push({nodeId:x.target,relationship:x.relationship}),c.get(x.target).push({nodeId:x.source,relationship:x.relationship}));let d=o.length>0?new Set(Array.from(c.entries()).filter(([,x])=>x.some(({relationship:C})=>o.includes(C))).map(([x])=>x)):u,p=l.filter(x=>d.has(x.id));if(p.length===0)return{positions:new Map};let m=new Map,g=p.map(x=>[{from:"",to:x.id}]),y=p.map(x=>[[x.id]]),w=p.map(()=>1),M=p.map(()=>[1]),h=p.map(x=>x.id),v=1;for(;v<=n&&Le.sum(y.map(x=>x[v-1]?.length??0))>0;)y.forEach((x,C)=>{let E=x[v-1];if(!E)return;let A=[];E.forEach(R=>{let I=c.get(R)??[],L=I.map(({nodeId:B})=>B);o.length>0&&(L=I.filter(({relationship:B})=>o.includes(B)).map(({nodeId:B})=>B)),L=Le.difference(Le.intersection(L,Array.from(d)),h),L.forEach(B=>{g[C].push({from:R,to:B}),A.push(B),h.push(B)})}),x[v]=A,A.length>0&&(M[C].push(A.length),w[C]++)}),v++;let b=bt().id(x=>x.to).parentId(x=>x.from||null);return p.forEach((x,C)=>{let E=e.positions.get(x.id)??[0,0,0];if(g[C].length<=1){m.set(x.id,[E[0],E[1],E[2]]);return}let A;try{A=b(g[C])}catch{m.set(x.id,[E[0],E[1],E[2]]);return}let R=Math.max(...M[C],1),I=Math.max(w[C]-1,1),L=Math.max(R-1,1),B,F;i==="rings"?(B=2*Math.PI,s!==void 0?F=s*I:F=Math.max(a,a*R/(2*Math.PI))):s!==void 0?(B=s*R*.2*Math.pow(w[C],.3),F=s*I):(B=a*L,F=a*I);let z=He().size([B,F])(A);Tn(i,r,z,z,E,m)}),{positions:m}}function Tn(e,t,n,i,r,o){let a=i.id,s,l;if(e==="tree")switch(t){case"up":s=i.x+r[0]-n.x,l=i.y+r[1]+n.y;break;case"down":s=-i.x+r[0]+n.x,l=-i.y+r[1]-n.y;break;case"right":s=i.y+r[0]-n.y,l=-i.x+r[1]+n.x;break;case"left":s=-i.y+r[0]+n.y,l=i.x+r[1]-n.x;break}else switch(t){case"down":s=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":s=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":s=r[0]+i.y*Math.cos(i.x+Math.PI),l=r[1]+i.y*Math.sin(i.x+Math.PI);break;case"left":s=r[0]+i.y*Math.cos(i.x),l=r[1]+i.y*Math.sin(i.x);break}if(o.set(a,[s,l,r[2]]),i.children)for(let u of i.children)Tn(e,t,n,u,r,o)}var ot=1.5,zt=3;function at(e,t){return t==="category"?e.category:e.properties?.[t]}function st(e,t,n){let i=n&&n.length?new Set(n):null,r=new Set,o=[],a=e.size;for(let s of t){if(i&&!i.has(s.relationship))continue;let l=e.get(s.source),u=e.get(s.target);if(l===void 0||u===void 0||l===u)continue;let c=l*a+u;r.has(c)||(r.add(c),o.push([l,u]))}return o}function Pn(e,t){let n=[],i=new Set;for(let r of e)r!=null&&!i.has(r)&&(i.add(r),n.push(r));if(t){let r=t.filter(a=>i.has(a)),o=new Set(r);return[...r,...n.filter(a=>!o.has(a))]}return n.every(r=>typeof r=="number")?[...n].sort((r,o)=>r-o):n}function Ct(e,t,n){switch(e){case"BT":return[n,t];case"LR":return[t,-n];case"RL":return[-t,-n];default:return[n,-t]}}function lt(e,t){if(t.size===0)return t;let n=0,i=0,r=0;for(let f of e.nodes){let d=e.positions.get(f.id);d&&(n+=d[0],i+=d[1],r++)}r&&(n/=r,i/=r);let o=1/0,a=-1/0,s=1/0,l=-1/0;for(let f of t.values())f[0]<o&&(o=f[0]),f[0]>a&&(a=f[0]),f[1]<s&&(s=f[1]),f[1]>l&&(l=f[1]);let u=n-(o+a)/2,c=i-(s+l)/2;for(let f of t.values())f[0]+=u,f[1]+=c;return t}function Bn(e,t,n){let i=e.length,r=Array.from({length:i},()=>[]),o=new Int32Array(i);for(let[c,f]of t)r[c].push(f),o[f]++;let a;if(n&&n.length){let c=new Set(n);a=[],e.forEach((f,d)=>{c.has(f.id)&&a.push(d)})}else{a=[];for(let c=0;c<i;c++)o[c]===0&&a.push(c);if(!a.length&&i){let c=0;for(let f=1;f<i;f++)r[f].length>r[c].length&&(c=f);a.push(c)}}let s=Array.from({length:i},()=>[]),l=new Uint8Array(i),u=c=>{l[c]=1;let f=[c];for(let d=0;d<f.length;d++){let p=f[d];for(let m of r[p])l[m]||(l[m]=1,s[p].push(m),f.push(m))}};for(let c of a)l[c]||u(c);for(let c=0;c<2;c++)for(let f=0;f<i;f++)l[f]||c===0&&o[f]>0||(a.push(f),u(f));return{roots:a.filter((c,f)=>a.indexOf(c)===f),children:s}}function zn(e,t){let n=e.children.length,i=u=>({i:u,children:[]}),r={i:-1,children:[]},o=[];for(let u of e.roots){let c=i(u);r.children.push(c),o.push(c)}for(;o.length;){let u=o.pop();for(let c of e.children[u.i]){let f=i(c);u.children.push(f),o.push(f)}}let a=Ae(r,u=>u.children);He().nodeSize([t,1]).separation((u,c)=>u.parent===c.parent?1:1.5)(a);let s=new Int32Array(n),l=new Float64Array(n);return a.each(u=>{u.data.i<0||(s[u.data.i]=u.depth-1,l[u.data.i]=u.x)}),{depth:s,across:l}}function Cn(e,t={}){let n=e.nodes,i=new Map(n.map((f,d)=>[f.id,d])),r=Bn(n,st(i,e.edges,t.relationships),t.roots),o=t.nodeGap??ot,a=t.levelGap??zt,s=t.direction??"TB",{depth:l,across:u}=zn(r,o),c=new Map;return n.forEach((f,d)=>{let[p,m]=Ct(s,l[d]*a,u[d]);c.set(f.id,[p,m,0])}),{positions:lt(e,c)}}function kn(e,t={}){let n=e.nodes,i=new Map(n.map((h,v)=>[h.id,v])),r=Bn(n,st(i,e.edges,t.relationships),t.roots),o=t.nodeGap??ot,a=t.levelGap??zt,s=(t.sweep??360)*Math.PI/180,l=(t.startAngle??90)*Math.PI/180,{depth:u,across:c}=zn(r,o),f=r.roots.length===1,d=1/0,p=-1/0,m=0;for(let h=0;h<n.length;h++)c[h]<d&&(d=c[h]),c[h]>p&&(p=c[h]),u[h]>m&&(m=u[h]);let g=Math.abs(s-2*Math.PI)<1e-6,y=Math.max(p-d+(g?o:0),1e-9),w=Math.max(a,y/s/Math.max(m+(f?0:1),1)),M=new Map;return n.forEach((h,v)=>{let b=(u[v]+(f?0:1))*w,x=l-(c[v]-d)/y*s;M.set(h.id,[b*Math.cos(x),b*Math.sin(x),0])}),{positions:lt(e,M)}}function Oi(e){if(e.length<2)return 0;let t=e.slice(),n=new Array(t.length),i=0;for(let r=1;r<t.length;r*=2)for(let o=0;o<t.length-r;o+=2*r){let a=o+r,s=Math.min(o+2*r,t.length),l=o,u=a,c=o;for(;l<a&&u<s;)t[l]<=t[u]?n[c++]=t[l++]:(n[c++]=t[u++],i+=a-l);for(;l<a;)n[c++]=t[l++];for(;u<s;)n[c++]=t[u++];for(let f=o;f<s;f++)t[f]=n[f]}return i}function Hi(e,t){let n=e.length,i=new Array(n);i[0]=0;for(let l=1;l<n;l++)i[l]=i[l-1]+t[l-1];let r=[],o=[];for(let l=0;l<n;l++)for(r.push(e[l]-i[l]),o.push(1);r.length>1&&r[r.length-2]/o[o.length-2]>r[r.length-1]/o[o.length-1];){let u=r.pop(),c=o.pop();r[r.length-1]+=u,o[o.length-1]+=c}let a=new Array(n),s=0;for(let l=0;l<r.length;l++){let u=r[l]/o[l];for(let c=0;c<o[l];c++,s++)a[s]=u+i[s]}return a}function Xi(e,t){let n=Array.from({length:e},()=>[]);t.forEach(([d,p],m)=>n[d].push(m));let i=new Uint8Array(e),r=new Uint8Array(t.length);for(let d=0;d<e;d++){if(i[d])continue;let p=[[d,0]];for(i[d]=1;p.length;){let m=p[p.length-1],[g,y]=m;if(y<n[g].length){m[1]++;let w=n[g][y],M=t[w][1];i[M]===1?r[w]=1:i[M]===0&&(i[M]=1,p.push([M,0]))}else i[g]=2,p.pop()}}let o=t.map(([d,p],m)=>r[m]?[p,d]:[d,p]),a=Array.from({length:e},()=>[]),s=Array.from({length:e},()=>[]),l=new Int32Array(e);for(let[d,p]of o)a[d].push(p),s[p].push(d),l[p]++;let u=[];for(let d=0;d<e;d++)l[d]===0&&u.push(d);for(let d=0;d<u.length;d++)for(let p of a[u[d]])--l[p]===0&&u.push(p);let c=new Array(e).fill(0);for(let d of u)for(let p of a[d])c[p]=Math.max(c[p],c[d]+1);for(let d=u.length-1;d>=0;d--){let p=u[d];if(s[p].length||!a[p].length)continue;let m=1/0;for(let g of a[p])m=Math.min(m,c[g]);c[p]=m-1}let f=Math.min(...c);return{rank:c.map(d=>d-f),dag:o}}function Yi(e,t,n){let i=t.slice(),r=new Array(e).fill(!1),o=Array.from({length:e},()=>[]),a=Array.from({length:e},()=>[]),s=(d,p)=>{a[d].push(p),o[p].push(d)};for(let[d,p]of n){if(i[p]-i[d]<1)continue;let m=d;for(let g=i[d]+1;g<i[p];g++){let y=i.length;i.push(g),r.push(!0),o.push([]),a.push([]),s(m,y),m=y}s(m,p)}let l=i.reduce((d,p)=>Math.max(d,p),0),u=Array.from({length:l+1},()=>[]),c=new Uint8Array(i.length),f=d=>{let p=[d];for(;p.length;){let m=p.pop();if(!c[m]){c[m]=1,u[i[m]].push(m);for(let g=a[m].length-1;g>=0;g--)c[a[m][g]]||p.push(a[m][g])}}};for(let d=0;d<e;d++)o[d].length||f(d);for(let d=0;d<i.length;d++)c[d]||f(d);return{rank:i,isDummy:r,up:o,down:a,layers:u}}function fn(e,t){let n=0;for(let i=0;i+1<e.layers.length;i++){let r=[];for(let o of e.layers[i])for(let a of e.down[o])r.push([t[o],t[a]]);r.sort((o,a)=>o[0]-a[0]||o[1]-a[1]),n+=Oi(r.map(o=>o[1]))}return n}function $i(e,t){let n=new Int32Array(e.rank.length);(()=>{for(let a of e.layers)a.forEach((s,l)=>{n[s]=l})})();let r=fn(e,n),o=e.layers.map(a=>a.slice());for(let a=0;a<t&&r>0;a++){let s=a%2===0,l=s?Array.from({length:e.layers.length-1},(c,f)=>f+1):Array.from({length:e.layers.length-1},(c,f)=>e.layers.length-2-f);for(let c of l){let f=e.layers[c],d=new Map;for(let p of f){let m=s?e.up[p]:e.down[p];d.set(p,m.length?m.reduce((g,y)=>g+n[y],0)/m.length:n[p])}f.sort((p,m)=>d.get(p)-d.get(m)||n[p]-n[m]),f.forEach((p,m)=>{n[p]=m})}let u=fn(e,n);u<r&&(r=u,o=e.layers.map(c=>c.slice()))}e.layers=o}function Zi(e,t){let n=new Float64Array(e.rank.length),i=(a,s)=>t*((e.isDummy[a]?.4:1)+(e.isDummy[s]?.4:1))/2,r=a=>a.slice(1).map((s,l)=>i(a[l],s));for(let a of e.layers){let s=r(a),l=0,u=[0];for(let c of s)u.push(l+=c);a.forEach((c,f)=>{n[c]=u[f]-l/2})}let o=a=>a.reduce((s,l)=>s+n[l],0)/a.length;for(let a=0;a<8;a++){let s=a%2===0,l=e.layers.map((u,c)=>s?c:e.layers.length-1-c);for(let u of l){let c=e.layers[u];if(!c.length)continue;let f=c.map(p=>{let m=e.isDummy[p]||a===7?[...e.up[p],...e.down[p]]:s?e.up[p]:e.down[p];return m.length?o(m):n[p]}),d=Hi(f,r(c));c.forEach((p,m)=>{n[p]=d[m]})}}return n}function En(e,t={}){let n=e.nodes,i=n.length;if(!i)return{positions:new Map};let r=new Map(n.map((p,m)=>[p.id,m])),o=st(r,e.edges,t.relationships),a,s;if(t.rankBy){let p=n.map(y=>at(y,t.rankBy)),m=Pn(p,t.rankOrder),g=new Map(m.map((y,w)=>[y,w]));a=p.map(y=>g.get(y)??m.length),s=o.map(([y,w])=>a[y]<=a[w]?[y,w]:[w,y])}else({rank:a,dag:s}=Xi(i,o));let l=Yi(i,a,s);$i(l,t.sweeps??24);let u=Zi(l,t.nodeGap??ot),c=t.levelGap??zt,f=t.direction??"TB",d=new Map;return n.forEach((p,m)=>{let[g,y]=Ct(f,l.rank[m]*c,u[m]);d.set(p.id,[g,y,0])}),{positions:lt(e,d)}}function Fn(e,t){let n=e.nodes;if(!n.length)return{positions:new Map};if(!t||!t.by)throw new Error("[columnsLayout] option `by` is required");let i=new Map(n.map((M,h)=>[M.id,h])),r=n.map(M=>at(M,t.by)),o=Pn(r,t.order),a=new Map(o.map((M,h)=>[M,h])),s=r.map(M=>a.get(M)??o.length),l=Math.max(...s)+1,u=Array.from({length:l},()=>[]);n.forEach((M,h)=>u[s[h]].push(h));let c=n.map(()=>[]);for(let[M,h]of st(i,e.edges,t.relationships))s[M]!==s[h]&&(c[M].push(h),c[h].push(M));let f=t.sortBy??"barycenter",d=new Float64Array(n.length),p=M=>M.forEach((h,v)=>{d[h]=v-(M.length-1)/2});if(u.forEach(p),f==="barycenter")for(let M=0;M<12;M++){let h=u.map((v,b)=>M%2===0?b:l-1-b);for(let v of h){let b=u[v],x=new Map(b.map(C=>[C,c[C].length?c[C].reduce((E,A)=>E+d[A],0)/c[C].length:d[C]]));b.sort((C,E)=>x.get(C)-x.get(E)||d[C]-d[E]),p(b)}}else if(f==="degree")for(let M of u)M.sort((h,v)=>c[v].length-c[h].length||h-v),p(M);else if(f!=="none")for(let M of u)M.sort((h,v)=>{let b=at(n[h],f),x=at(n[v],f);return typeof b=="number"&&typeof x=="number"?b-x||h-v:String(b??"").localeCompare(String(x??""))||h-v}),p(M);let m=t.nodeGap??ot,g=t.levelGap??4,y=t.direction??"LR",w=new Map;return n.forEach((M,h)=>{let[v,b]=Ct(y,s[h]*g,d[h]*m);w.set(M.id,[v,b,0])}),{positions:lt(e,w)}}function _e(e){if(e==null)return null;let t=Number(e);return Number.isNaN(t)?null:t}function Ce(e,t,n){let[i,r]=t,[o,a]=n;return r===i?(o+a)/2:o+(e-i)/(r-i)*(a-o)}function ke(e,t,n){let i=Math.max(t[0],1e-10),r=Math.max(t[1],1e-10),o=Math.max(e,1e-10),[a,s]=n;return r===i?(a+s)/2:a+(Math.log(o)-Math.log(i))/(Math.log(r)-Math.log(i))*(s-a)}function In(e,t,n){let i=n??_e,r=1/0,o=-1/0;for(let a of e){let s=a.properties?.[t],l=i(s);l!=null&&(l<r&&(r=l),l>o&&(o=l))}return r===1/0?[0,1]:r===o?[r-1,o+1]:[r,o]}function Dn(e,t=5){let[n,i]=e,r=i-n;if(r===0)return[n-1,i+1];let o=r/t,a=Math.pow(10,Math.floor(Math.log10(o))),s=o/a,l;return s<=1.5?l=a:s<=3.5?l=2*a:s<=7.5?l=5*a:l=10*a,[Math.floor(n/l)*l,Math.ceil(i/l)*l]}function An(e,t=5){let[n,i]=e;if(n===i)return[n];let o=(i-n)/t,a=Math.pow(10,Math.floor(Math.log10(o))),s=o/a,l;s<=1.5?l=a:s<=3.5?l=2*a:s<=7.5?l=5*a:l=10*a;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 Bt=[{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 Rn(e,t=5){let[n,i]=e,r=i-n;if(r<=0)return[n];let o=r/t,a=Bt[Bt.length-1];for(let l of Bt)if(l.ms>=o*.6){a=l;break}let s=[];if(a.calendarUnit==="year"){let l=a.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&&s.push(f),c+=l}}else if(a.calendarUnit==="month"){let l=a.calendarStep,u=new Date(n),c=u.getFullYear(),f=Math.ceil(u.getMonth()/l)*l;for(;;){let d=new Date(c,f,1).getTime();if(d>i)break;d>=n&&s.push(d),f+=l,f>=12&&(c+=Math.floor(f/12),f=f%12)}}else{let l=a.ms,u=Math.ceil(n/l)*l;for(let c=u;c<=i;c+=l)s.push(c)}return s}function Un(e,t){let n=t[1]-t[0],i=new Date(e);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 Ue(e,t,n){let i=e.domain??In(t,e.property,e.parse);e.nice&&!e.domain&&(i=Dn(i,e.tickCount));let o=(i[1]-i[0])*n,a=[i[0]-o,i[1]+o],s;e.tickValues?s=e.tickValues:e.isDate?s=Rn(i,e.tickCount):s=An(i,e.tickCount);let l=e.tickFormat;return!l&&e.isDate&&(l=u=>Un(u,i)),{axisInfo:{property:e.property,label:e.property,domain:a,ticks:s,scale:e.scale,tickFormat:l},paddedDomain:a}}function Ln(e,t){let{propertyX:n,propertyY:i,propertyZ:r,range:o=[-2,2],scaleX:a="linear",scaleY:s="linear",scaleZ:l="linear",padding:u=.05}=t,c=t.parseX??_e,f=t.parseY??_e,d=t.parseZ??_e,p=!!n,m=!!i,g=!!r,y=e.nodes,w=new Map,M=new Set,h=[];for(let B of y){let F=0,_=0,z=0,P=!1;if(p){let T=c(B.properties?.[n]);T==null?P=!0:F=T}if(m&&!P){let T=f(B.properties?.[i]);T==null?P=!0:_=T}if(g&&!P){let T=d(B.properties?.[r]);T==null?P=!0:z=T}P?M.add(B.id):h.push({id:B.id,x:F,y:_,z})}let v=p?Ue({property:n,scale:a,domain:t.domainX,parse:c,tickFormat:t.tickFormatX,tickCount:t.tickCountX??5,tickValues:t.tickValuesX,nice:t.niceX??!0,isDate:t.dateAxisX??!1},y,u):null,b=m?Ue({property:i,scale:s,domain:t.domainY,parse:f,tickFormat:t.tickFormatY,tickCount:t.tickCountY??5,tickValues:t.tickValuesY,nice:t.niceY??!0,isDate:t.dateAxisY??!1},y,u):null,x=g?Ue({property:r,scale:l,domain:t.domainZ,parse:d,tickFormat:t.tickFormatZ,tickCount:t.tickCountZ??5,tickValues:t.tickValuesZ,nice:t.niceZ??!0,isDate:t.dateAxisZ??!1},y,u):null,C=a==="log"?ke:Ce,E=s==="log"?ke:Ce,A=l==="log"?ke:Ce,R=t.spread??1,I=[o[0]*R,o[1]*R],L=o[0];for(let B of h){let F=v?C(B.x,v.paddedDomain,I):L,_=b?E(B.y,b.paddedDomain,I):L,z=x?A(B.z,x.paddedDomain,I):0;w.set(B.id,[F,_,z])}return{positions:w,axes:{x:v?.axisInfo,y:b?.axisInfo,z:x?.axisInfo},range:I,baseRange:o,excludedNodeIds:M}}function Gn(e,t){let n=t.range??[-2,2],i=t.spread??1,r=[n[0]*i,n[1]*i],o=t.padding??.05,a=n[0],s=t.unmappedMode??"hide",l=new Map;for(let p of t.mappings)l.set(p.category,p);let u=new Map;for(let p of e.nodes){let m=p.category,g=u.get(m);g||(g=[],u.set(m,g)),g.push(p)}let c=new Map,f=new Set,d={};for(let[p,m]of u){let g=l.get(p);if(!g){if(s==="hide")for(let G of m)f.add(G.id);else{let G;s==="boundary"?G=n[0]:G=(n[0]+n[1])/2;for(let S of m)c.set(S.id,[G,G,0])}continue}let y=!!g.propertyX,w=!!g.propertyY,M=!!g.propertyZ,h=g.scaleX??"linear",v=g.scaleY??"linear",b=g.scaleZ??"linear",x=g.parseX??_e,C=g.parseY??_e,E=g.parseZ??_e,A=g.tickCountX??t.tickCountX??5,R=g.tickCountY??t.tickCountY??5,I=g.tickCountZ??t.tickCountZ??5,L=g.niceX??t.niceX??!0,B=g.niceY??t.niceY??!0,F=g.niceZ??t.niceZ??!0,_=[];for(let G of m){let S=0,D=0,O=0,Y=!1;if(y){let X=x(G.properties?.[g.propertyX]);X==null?Y=!0:S=X}if(w&&!Y){let X=C(G.properties?.[g.propertyY]);X==null?Y=!0:D=X}if(M&&!Y){let X=E(G.properties?.[g.propertyZ]);X==null?Y=!0:O=X}Y?f.add(G.id):_.push({id:G.id,x:S,y:D,z:O})}let z=y?Ue({property:g.propertyX,scale:h,domain:g.domainX,parse:x,tickFormat:g.tickFormatX,tickCount:A,tickValues:g.tickValuesX,nice:L,isDate:g.dateAxisX??!1},m,o):null,P=w?Ue({property:g.propertyY,scale:v,domain:g.domainY,parse:C,tickFormat:g.tickFormatY,tickCount:R,tickValues:g.tickValuesY,nice:B,isDate:g.dateAxisY??!1},m,o):null,T=M?Ue({property:g.propertyZ,scale:b,domain:g.domainZ,parse:E,tickFormat:g.tickFormatZ,tickCount:I,tickValues:g.tickValuesZ,nice:F,isDate:g.dateAxisZ??!1},m,o):null,k=h==="log"?ke:Ce,q=v==="log"?ke:Ce,N=b==="log"?ke:Ce;for(let G of _){let S=z?k(G.x,z.paddedDomain,r):a,D=P?q(G.y,P.paddedDomain,r):a,O=T?N(G.z,T.paddedDomain,r):0;c.set(G.id,[S,D,O])}d[p]={x:z?.axisInfo,y:P?.axisInfo,z:T?.axisInfo}}return{positions:c,axes:{x:void 0,y:void 0,z:void 0},range:r,baseRange:n,excludedNodeIds:f,categoryAxes:d}}var ji=/^[a-z][a-zA-Z0-9]*$/,Vi=/^[a-z][a-z0-9-]*:[A-Za-z][A-Za-z0-9_-]*$/,Nn=class qn{constructor(){this.entries=new Map}register(t,n,i={}){if(!Vi.test(t))throw new Error(`[LayoutRegistry] invalid layout name "${t}": extension layouts must be named "<pack>:<name>" (e.g. "acme:rack")`);return this.add(t,n,!1,i)}registerBuiltin(t,n,i){if(!ji.test(t))throw new Error(`[LayoutRegistry] invalid built-in layout name "${t}"`);this.add(t,n,!0,{description:i})}add(t,n,i,r){if(typeof n!="function")throw new Error(`[LayoutRegistry] layout "${t}" must be a function`);let o=this.entries.get(t);if(o&&(o.builtin||!r.replace))throw new Error(`[LayoutRegistry] layout "${t}" is already registered`);let a={name:t,fn:n,builtin:i,description:r.description};return this.entries.set(t,a),()=>{this.entries.get(t)===a&&this.entries.delete(t)}}has(t){return this.entries.has(t)}get(t){return this.entries.get(t)}list(){let t=[...this.entries.values()];return[...t.filter(n=>n.builtin),...t.filter(n=>!n.builtin)]}execute(t,n,i){let r=this.entries.get(t);if(!r)throw new Error(`[LayoutRegistry] unknown layout "${t}". Registered: ${[...this.entries.keys()].join(", ")}`);return r.fn(n,i)}fork(){let t=new qn;for(let[n,i]of this.entries)t.entries.set(n,i);return t}};function Wi(){let e=new Nn;return e.registerBuiltin("circle",pn,"Nodes on a circle."),e.registerBuiltin("grid",hn,"Nodes on a 2-D grid."),e.registerBuiltin("line",mn,"Nodes along an axis."),e.registerBuiltin("spiral",gn,"Nodes on a spiral."),e.registerBuiltin("cube",yn,"Nodes in a 3-D lattice."),e.registerBuiltin("sphere",vn,"Nodes on a sphere."),e.registerBuiltin("scatter",xn,"Nodes scattered randomly in a range."),e.registerBuiltin("ego",Sn,"Tree or rings around root node(s)."),e.registerBuiltin("tree",Cn,"Tidy tree (org chart, directory); forests supported."),e.registerBuiltin("radialTree",kn,"Tidy tree in polar form, root in the centre."),e.registerBuiltin("layered",En,"Layered (Sugiyama) layout for directed graphs: lineage, call chains, workflows."),e.registerBuiltin("columns",Fn,"One column per property value, crossings reduced inside columns."),e.registerBuiltin("rotate",bn,"Rotate current positions (transform)."),e.registerBuiltin("scale",Mn,"Scale current positions (transform)."),e.registerBuiltin("shift",wn,"Translate current positions (transform)."),e.registerBuiltin("alignBy",_n,"Align nodes by an axis (transform)."),e.registerBuiltin("plotScatter",Ln,"Scatter plot by two properties."),e.registerBuiltin("plotMultiCategoryScatter",Gn,"Scatter plot with category axes."),e}var Ki=Wi();var re=pe(require("three"),1);function Pe(){return typeof navigator<"u"&&!!navigator.gpu}async function $n(e={}){if(!Pe())throw new Error("WebGPU not available: navigator.gpu is undefined. Use the WebGL backend instead.");let t=await navigator.gpu.requestAdapter({powerPreference:e.preferHighPerformance===!1?"low-power":"high-performance"});if(!t)throw new Error("WebGPU adapter request returned null (no compatible adapter found).");let i=(e.requestedFeatures??[]).filter(o=>t.features.has(o)),r=await t.requestDevice({requiredFeatures:i});return{adapter:t,device:r,features:new Set(t.features),limits:t.limits}}function At(e){if(e<=0)return 1;let t=Math.ceil(Math.sqrt(e));return Math.pow(2,Math.ceil(Math.log2(t)))}function qe(e,t,n=10){if(e<=0)return n;let i;return t===3?i=Math.cbrt(e)*2:i=Math.sqrt(e)*.5,Math.max(n,i)}function Qi(){return{type:re.FloatType,format:re.RGBAFormat,minFilter:re.NearestFilter,magFilter:re.NearestFilter,generateMipmaps:!1,depthBuffer:!1,stencilBuffer:!1}}function Ee(e){let t=Qi();return new re.WebGLRenderTarget(e,e,t)}function Oe(e,t){let n=new re.DataTexture(e,t,t,re.RGBAFormat,re.FloatType);return n.minFilter=re.NearestFilter,n.magFilter=re.NearestFilter,n.needsUpdate=!0,n}function Zn(e){let t=[];for(let n=0;n<e;n++)for(let i=0;i<e;i++)t.push(i,n);return new Float32Array(t)}function ye(){return new re.PlaneGeometry(2,2)}function jn(e=1){let r=e;return function(){return r=(1664525*r+1013904223)%4294967296,r/4294967296}}function dt(e){return(e()-.5)*1e-6}function te(e){return()=>e}function Ve(e,t,n){let i=e.length,r=10,o=Math.PI*(3-Math.sqrt(5)),a=Math.PI*20/(9+Math.sqrt(221));for(let s=0;s<i;s++){let l=e[s];if(l.index=s,l.fx!=null&&(l.x=l.fx),l.fy!=null&&(l.y=l.fy),l.fz!=null&&(l.z=l.fz),isNaN(l.x)||t>1&&isNaN(l.y)||t>2&&isNaN(l.z)){let u=r*(t>2?Math.cbrt(.5+s):t>1?Math.sqrt(.5+s):s),c=s*o,f=s*a;t===1?l.x=u:t===2?(l.x=u*Math.cos(c),l.y=u*Math.sin(c)):(l.x=u*Math.sin(c)*Math.cos(f),l.y=u*Math.cos(c),l.z=u*Math.sin(c)*Math.sin(f))}(isNaN(l.vx)||t>1&&isNaN(l.vy)||t>2&&isNaN(l.vz))&&(l.vx=0,t>1&&(l.vy=0),t>2&&(l.vz=0))}}function Vn(e,t){let n=t*t,i=new Float32Array(n*4);for(let r=0;r<e.length;r++){let o=e[r],a=r*4;i[a]=o.x||0,i[a+1]=o.y||0,i[a+2]=o.z||0,i[a+3]=r}return i}function Wn(e,t){let n=t*t,i=new Float32Array(n*4);for(let r=0;r<e.length;r++){let o=e[r],a=r*4;i[a]=o.vx||0,i[a+1]=o.vy||0,i[a+2]=o.vz||0,i[a+3]=0}return i}function Kn(e,t){let n=t*t,i=new Float32Array(n*4);for(let r=0;r<e.length;r++){let o=e[r],a=r*4;i[a]=o.fx!=null||o.fy!=null||o.fz!=null?1:0,i[a+1]=0,i[a+2]=0,i[a+3]=0}return i}function Qn(e,t,n){for(let i=0;i<e.length;i++){let r=e[i],o=i*4;r.fx==null&&(r.x=t[o]),n>1&&r.fy==null&&(r.y=t[o+1]),n>2&&r.fz==null?r.z=t[o+2]:n<=2&&(r.z=0)}}var Ji=`// Position integration compute shader.
|
|
1
|
+
"use strict";var mi=Object.create;var nt=Object.defineProperty;var gi=Object.getOwnPropertyDescriptor;var yi=Object.getOwnPropertyNames;var vi=Object.getPrototypeOf,xi=Object.prototype.hasOwnProperty;var bi=(e,t)=>{for(var n in t)nt(e,n,{get:t[n],enumerable:!0})},Yt=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of yi(t))!xi.call(e,r)&&r!==n&&nt(e,r,{get:()=>t[r],enumerable:!(i=gi(t,r))||i.enumerable});return e};var me=(e,t,n)=>(n=e!=null?mi(vi(e)):{},Yt(t||!e||!e.__esModule?nt(n,"default",{value:e,enumerable:!0}):n,e)),wi=e=>Yt(nt({},"__esModule",{value:!0}),e);var Sa={};bi(Sa,{GPUForceLayoutController:()=>Ht,GPUForceLayoutEngine:()=>hi,GPULayoutControllerAdapter:()=>Xt,WebGPUForceLayoutController:()=>gt,WebGPULayoutControllerAdapter:()=>yt,createForceLayout:()=>pi,isWebGPUAvailable:()=>Ee});module.exports=wi(Sa);function Mi(e){var t=0,n=e.children,i=n&&n.length;if(!i)t=1;else for(;--i>=0;)t+=n[i].value;e.value=t}function $t(){return this.eachAfter(Mi)}function jt(e,t){let n=-1;for(let i of this)e.call(t,i,++n,this);return this}function Zt(e,t){for(var n=this,i=[n],r,o,a=-1;n=i.pop();)if(e.call(t,n,++a,this),r=n.children)for(o=r.length-1;o>=0;--o)i.push(r[o]);return this}function Vt(e,t){for(var n=this,i=[n],r=[],o,a,s,l=-1;n=i.pop();)if(r.push(n),o=n.children)for(a=0,s=o.length;a<s;++a)i.push(o[a]);for(;n=r.pop();)e.call(t,n,++l,this);return this}function Wt(e,t){let n=-1;for(let i of this)if(e.call(t,i,++n,this))return i}function Kt(e){return this.eachAfter(function(t){for(var n=+e(t.data)||0,i=t.children,r=i&&i.length;--r>=0;)n+=i[r].value;t.value=n})}function Qt(e){return this.eachBefore(function(t){t.children&&t.children.sort(e)})}function Jt(e){for(var t=this,n=Si(t,e),i=[t];t!==n;)t=t.parent,i.push(t);for(var r=i.length;e!==n;)i.splice(r,0,e),e=e.parent;return i}function Si(e,t){if(e===t)return e;var n=e.ancestors(),i=t.ancestors(),r=null;for(e=n.pop(),t=i.pop();e===t;)r=e,e=n.pop(),t=i.pop();return r}function en(){for(var e=this,t=[e];e=e.parent;)t.push(e);return t}function tn(){return Array.from(this)}function nn(){var e=[];return this.eachBefore(function(t){t.children||e.push(t)}),e}function rn(){var e=this,t=[];return e.each(function(n){n!==e&&t.push({source:n.parent,target:n})}),t}function*an(){var e=this,t,n=[e],i,r,o;do for(t=n.reverse(),n=[];e=t.pop();)if(yield e,i=e.children)for(r=0,o=i.length;r<o;++r)n.push(i[r]);while(n.length)}function Be(e,t){e instanceof Map?(e=[void 0,e],t===void 0&&(t=Pi)):t===void 0&&(t=Ti);for(var n=new _e(e),i,r=[n],o,a,s,l;i=r.pop();)if((a=t(i.data))&&(l=(a=Array.from(a)).length))for(i.children=a,s=l-1;s>=0;--s)r.push(o=a[s]=new _e(a[s])),o.parent=i,o.depth=i.depth+1;return n.eachBefore(bt)}function _i(){return Be(this).eachBefore(Bi)}function Ti(e){return e.children}function Pi(e){return Array.isArray(e)?e[1]:null}function Bi(e){e.data.value!==void 0&&(e.value=e.data.value),e.data=e.data.data}function bt(e){var t=0;do e.height=t;while((e=e.parent)&&e.height<++t)}function _e(e){this.data=e,this.depth=this.height=0,this.parent=null}_e.prototype=Be.prototype={constructor:_e,count:$t,each:jt,eachAfter:Vt,eachBefore:Zt,find:Wt,sum:Kt,sort:Qt,path:Jt,ancestors:en,descendants:tn,leaves:nn,links:rn,copy:_i,[Symbol.iterator]:an};function it(e){return e==null?null:zi(e)}function zi(e){if(typeof e!="function")throw new Error;return e}var Ci={depth:-1},on={},wt={};function ki(e){return e.id}function Ei(e){return e.parentId}function St(){var e=ki,t=Ei,n;function i(r){var o=Array.from(r),a=e,s=t,l,u,c,d,f,p,h,g,y=new Map;if(n!=null){let M=o.map((v,w)=>Fi(n(v,w,r))),b=M.map(sn),m=new Set(M).add("");for(let v of b)m.has(v)||(m.add(v),M.push(v),b.push(sn(v)),o.push(wt));a=(v,w)=>M[w],s=(v,w)=>b[w]}for(c=0,l=o.length;c<l;++c)u=o[c],p=o[c]=new _e(u),(h=a(u,c,r))!=null&&(h+="")&&(g=p.id=h,y.set(g,y.has(g)?on:p)),(h=s(u,c,r))!=null&&(h+="")&&(p.parent=h);for(c=0;c<l;++c)if(p=o[c],h=p.parent){if(f=y.get(h),!f)throw new Error("missing: "+h);if(f===on)throw new Error("ambiguous: "+h);f.children?f.children.push(p):f.children=[p],p.parent=f}else{if(d)throw new Error("multiple roots");d=p}if(!d)throw new Error("no root");if(n!=null){for(;d.data===wt&&d.children.length===1;)d=d.children[0],--l;for(let M=o.length-1;M>=0&&(p=o[M],p.data===wt);--M)p.data=null}if(d.parent=Ci,d.eachBefore(function(M){M.depth=M.parent.depth+1,--l}).eachBefore(bt),d.parent=null,l>0)throw new Error("cycle");return d}return i.id=function(r){return arguments.length?(e=it(r),i):e},i.parentId=function(r){return arguments.length?(t=it(r),i):t},i.path=function(r){return arguments.length?(n=it(r),i):n},i}function Fi(e){e=`${e}`;let t=e.length;return Mt(e,t-1)&&!Mt(e,t-2)&&(e=e.slice(0,-1)),e[0]==="/"?e:`/${e}`}function sn(e){let t=e.length;if(t<2)return"";for(;--t>1&&!Mt(e,t););return e.slice(0,t)}function Mt(e,t){if(e[t]==="/"){let n=0;for(;t>0&&e[--t]==="\\";)++n;if((n&1)===0)return!0}return!1}function Ii(e,t){return e.parent===t.parent?1:2}function _t(e){var t=e.children;return t?t[0]:e.t}function Tt(e){var t=e.children;return t?t[t.length-1]:e.t}function Di(e,t,n){var i=n/(t.i-e.i);t.c-=i,t.s+=n,e.c+=i,t.z+=n,t.m+=n}function Ai(e){for(var t=0,n=0,i=e.children,r=i.length,o;--r>=0;)o=i[r],o.z+=t,o.m+=t,t+=o.s+(n+=o.c)}function Ri(e,t,n){return e.a.parent===t.parent?e.a:n}function rt(e,t){this._=e,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=t}rt.prototype=Object.create(_e.prototype);function Ui(e){for(var t=new rt(e,0),n,i=[t],r,o,a,s;n=i.pop();)if(o=n._.children)for(n.children=new Array(s=o.length),a=s-1;a>=0;--a)i.push(r=n.children[a]=new rt(o[a],a)),r.parent=n;return(t.parent=new rt(null,0)).children=[t],t}function Fe(){var e=Ii,t=1,n=1,i=null;function r(u){var c=Ui(u);if(c.eachAfter(o),c.parent.m=-c.z,c.eachBefore(a),i)u.eachBefore(l);else{var d=u,f=u,p=u;u.eachBefore(function(b){b.x<d.x&&(d=b),b.x>f.x&&(f=b),b.depth>p.depth&&(p=b)});var h=d===f?1:e(d,f)/2,g=h-d.x,y=t/(f.x+h+g),M=n/(p.depth||1);u.eachBefore(function(b){b.x=(b.x+g)*y,b.y=b.depth*M})}return u}function o(u){var c=u.children,d=u.parent.children,f=u.i?d[u.i-1]:null;if(c){Ai(u);var p=(c[0].z+c[c.length-1].z)/2;f?(u.z=f.z+e(u._,f._),u.m=u.z-p):u.z=p}else f&&(u.z=f.z+e(u._,f._));u.parent.A=s(u,f,u.parent.A||d[0])}function a(u){u._.x=u.z+u.parent.m,u.m+=u.parent.m}function s(u,c,d){if(c){for(var f=u,p=u,h=c,g=f.parent.children[0],y=f.m,M=p.m,b=h.m,m=g.m,v;h=Tt(h),f=_t(f),h&&f;)g=_t(g),p=Tt(p),p.a=u,v=h.z+b-f.z-y+e(h._,f._),v>0&&(Di(Ri(h,u,d),u,v),y+=v,M+=v),b+=h.m,y+=f.m,m+=g.m,M+=p.m;h&&!Tt(p)&&(p.t=h,p.m+=b-M),f&&!_t(g)&&(g.t=f,g.m+=y-m,d=u)}return d}function l(u){u.x*=t,u.y=u.depth*n}return r.separation=function(u){return arguments.length?(e=u,r):e},r.size=function(u){return arguments.length?(i=!1,t=+u[0],n=+u[1],r):i?null:[t,n]},r.nodeSize=function(u){return arguments.length?(i=!0,t=+u[0],n=+u[1],r):i?[t,n]:null},r}var He=me(require("lodash"),1);var Li={value:()=>{}};function un(){for(var e=0,t=arguments.length,n={},i;e<t;++e){if(!(i=arguments[e]+"")||i in n||/[\s.]/.test(i))throw new Error("illegal type: "+i);n[i]=[]}return new at(n)}function at(e){this._=e}function Gi(e,t){return e.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&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:i}})}at.prototype=un.prototype={constructor:at,on:function(e,t){var n=this._,i=Gi(e+"",n),r,o=-1,a=i.length;if(arguments.length<2){for(;++o<a;)if((r=(e=i[o]).type)&&(r=Ni(n[r],e.name)))return r;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++o<a;)if(r=(e=i[o]).type)n[r]=ln(n[r],e.name,t);else if(t==null)for(r in n)n[r]=ln(n[r],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new at(e)},call:function(e,t){if((r=arguments.length-2)>0)for(var n=new Array(r),i=0,r,o;i<r;++i)n[i]=arguments[i+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(o=this._[e],i=0,r=o.length;i<r;++i)o[i].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var i=this._[e],r=0,o=i.length;r<o;++r)i[r].value.apply(t,n)}};function Ni(e,t){for(var n=0,i=e.length,r;n<i;++n)if((r=e[n]).name===t)return r.value}function ln(e,t,n){for(var i=0,r=e.length;i<r;++i)if(e[i].name===t){e[i]=Li,e=e.slice(0,i).concat(e.slice(i+1));break}return n!=null&&e.push({name:t,value:n}),e}var Bt=un;var Ne=0,Ve=0,Ze=0,dn=1e3,ot,We,st=0,Ie=0,lt=0,Ke=typeof performance=="object"&&performance.now?performance:Date,fn=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function kt(){return Ie||(fn(qi),Ie=Ke.now()+lt)}function qi(){Ie=0}function zt(){this._call=this._time=this._next=null}zt.prototype=ut.prototype={constructor:zt,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?kt():+n)+(t==null?0:+t),!this._next&&We!==this&&(We?We._next=this:ot=this,We=this),this._call=e,this._time=n,Ct()},stop:function(){this._call&&(this._call=null,this._time=1/0,Ct())}};function ut(e,t,n){var i=new zt;return i.restart(e,t,n),i}function pn(){kt(),++Ne;for(var e=ot,t;e;)(t=Ie-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Ne}function cn(){Ie=(st=Ke.now())+lt,Ne=Ve=0;try{pn()}finally{Ne=0,Hi(),Ie=0}}function Oi(){var e=Ke.now(),t=e-st;t>dn&&(lt-=t,st=e)}function Hi(){for(var e,t=ot,n,i=1/0;t;)t._call?(i>t._time&&(i=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:ot=n);We=e,Ct(i)}function Ct(e){if(!Ne){Ve&&(Ve=clearTimeout(Ve));var t=e-Ie;t>24?(e<1/0&&(Ve=setTimeout(cn,e-Ke.now()-lt)),Ze&&(Ze=clearInterval(Ze))):(Ze||(st=Ke.now(),Ze=setInterval(Oi,dn)),Ne=1,fn(cn))}}function Te(e){let t=0,n=0,i=0,r=0;for(let[,o]of e)t+=o[0],n+=o[1],i+=o[2],r++;return r===0?[0,0,0]:[t/r,n/r,i/r]}var Ce=1;function Se(e,t){let n=new Map;for(let i=0;i<e.nodes.length;i++)n.set(e.nodes[i].id,t[i]);return{positions:n}}function mn(e,t){let n=e.nodes.length;if(n===0)return{positions:new Map};let i=Te(e.positions),r=t?.spacing??Ce,o=t?.radius??Math.max(r,n*r/(2*Math.PI)),a=Math.PI*2/n,s=[];for(let l=0;l<n;l++)s.push([o*Math.cos(l*a)+i[0],o*Math.sin(l*a)+i[1],0]);return Se(e,s)}function gn(e,t){let n=e.nodes.length;if(n===0)return{positions:new Map};let i=Te(e.positions),r=t?.columns&&t.columns>0?t.columns:Math.ceil(Math.sqrt(n)),o=t?.spacing??Ce,a=o*(r-1),s=[];for(let l=0;l<n;l++)s.push([l%r*o-a/2+i[0],-Math.floor(l/r)*o+a/2+i[1],0]);return Se(e,s)}function yn(e,t){let n=e.nodes.length;if(n===0)return{positions:new Map};let i=Te(e.positions),r=t?.axis??"x",o=t?.spacing??Ce,a=o*(n-1),s=[];for(let l=0;l<n;l++){let u=n>1?-a/2+l*o:0,c=[i[0],i[1],i[2]],d=r==="x"?0:r==="y"?1:2;c[d]=u+i[d],s.push(c)}return Se(e,s)}function vn(e,t){let n=e.nodes.length;if(n===0)return{positions:new Map};let i=Te(e.positions),r=t?.spacing??1.5,o=r/(2*Math.PI),a=2*Math.PI,s=[];for(let l=0;l<n;l++){let u=o*a;s.push([u*Math.cos(a)+i[0],u*Math.sin(a)+i[1],0]),a+=r/u}return Se(e,s)}function xn(e,t){let n=e.nodes.length;if(n===0)return{positions:new Map};let i=Te(e.positions),r=Math.cbrt(n),o=Math.floor(r),a=Math.ceil(r),s=t?.size??(n-Math.pow(o,3)>Math.pow(a,3)-n?a:o),l=t?.spacing??Ce,u=l*Math.max(s-1,0),c=[];for(let d=0;d<n;d++)c.push([d%s*l-u/2+i[0],-(Math.floor(d/s)%s)*l+u/2+i[1],-Math.floor(d/(s*s))*l+u/2+i[2]]);return Se(e,c)}function bn(e,t){let n=e.nodes.length;if(n<=1){let l=new Map;return n===1&&l.set(e.nodes[0].id,e.positions.get(e.nodes[0].id)??[0,0,0]),{positions:l}}let i=Te(e.positions),r=t?.spacing??Ce,o=t?.density!==void 0?Math.sqrt(n/(4*Math.PI*t.density)):r*Math.sqrt(n/(4*Math.PI)),a=t?.radius??Math.max(r,o),s=[];for(let l=0;l<n;l++){let u=Math.acos(1-(2*(l+1)-1)/n),c=Math.sqrt(n*Math.PI)*u;s.push([a*Math.sin(u)*Math.cos(c)+i[0],a*Math.sin(u)*Math.sin(c)+i[1],a*Math.cos(u)+i[2]])}return Se(e,s)}function wn(e,t){let n=e.nodes.length;if(n===0)return{positions:new Map};let i=t?.spacing??Ce,r=t?.range??Math.max(i,i*Math.cbrt(n)/2),o=t?.seed??42;function a(){o|=0,o=o+1831565813|0;let l=Math.imul(o^o>>>15,1|o);return l=l+Math.imul(l^l>>>7,61|l)^l,((l^l>>>14)>>>0)/4294967296}let s=[];for(let l=0;l<n;l++)s.push([(a()-.5)*r*2,(a()-.5)*r*2,(a()-.5)*r*2]);return Se(e,s)}function Mn(e,t){if(e.nodes.length===0)return{positions:new Map};let i=t?.axis??"x",r=(t?.degrees??90)*Math.PI/180,o=Te(e.positions),a=[];for(let s of e.nodes){let l=e.positions.get(s.id)??[0,0,0],u=l[0]-o[0],c=l[1]-o[1],d=l[2]-o[2],f,p,h,g=Math.cos(r),y=Math.sin(r);i==="x"?(f=u,p=c*g-d*y,h=c*y+d*g):i==="y"?(f=u*g+d*y,p=c,h=-u*y+d*g):(f=u*g-c*y,p=u*y+c*g,h=d),a.push([f+o[0],p+o[1],h+o[2]])}return Se(e,a)}function Sn(e,t){if(e.nodes.length===0)return{positions:new Map};let i=t?.factor,r=i??t?.x??1,o=i??t?.y??1,a=i??t?.z??1,s=Te(e.positions),l=[];for(let u of e.nodes){let c=e.positions.get(u.id)??[0,0,0];l.push([c[0]+(c[0]-s[0])*(r-1),c[1]+(c[1]-s[1])*(o-1),c[2]+(c[2]-s[2])*(a-1)])}return Se(e,l)}function _n(e,t){if(e.nodes.length===0)return{positions:new Map};let i=t?.x??0,r=t?.y??0,o=t?.z??0,a=[];for(let s of e.nodes){let l=e.positions.get(s.id)??[0,0,0];a.push([l[0]+i,l[1]+r,l[2]+o])}return Se(e,a)}function Tn(e,t){if(e.nodes.length===0)return{positions:new Map};let i=t?.axis??"x",r=i==="x"?0:i==="y"?1:2,o=1/0,a=-1/0;for(let u of e.nodes){let c=e.positions.get(u.id)??[0,0,0];c[r]<o&&(o=c[r]),c[r]>a&&(a=c[r])}let s=(o+a)/2,l=[];for(let u of e.nodes){let c=e.positions.get(u.id)??[0,0,0],d=[c[0],c[1],c[2]];d[r]=s,l.push(d)}return Se(e,l)}function Pn(e,t){let{depth:n=100,mode:i="tree",orientation:r="right",alongRelationships:o=[]}=t??{},a=t?.spacing??Ce,s=t?.spacing===void 0?t?.edgeLength:void 0,l=e.nodes;if(l.length===0)return{positions:new Map};let u=new Set;for(let[x]of e.positions)u.add(x);let c=new Map,d=new Map;for(let x of e.edges)!u.has(x.source)||!u.has(x.target)||(d.set(x.id,x),c.has(x.source)||c.set(x.source,[]),c.has(x.target)||c.set(x.target,[]),c.get(x.source).push({nodeId:x.target,relationship:x.relationship}),c.get(x.target).push({nodeId:x.source,relationship:x.relationship}));let f=o.length>0?new Set(Array.from(c.entries()).filter(([,x])=>x.some(({relationship:C})=>o.includes(C))).map(([x])=>x)):u,p=l.filter(x=>f.has(x.id));if(p.length===0)return{positions:new Map};let h=new Map,g=p.map(x=>[{from:"",to:x.id}]),y=p.map(x=>[[x.id]]),M=p.map(()=>1),b=p.map(()=>[1]),m=p.map(x=>x.id),v=1;for(;v<=n&&He.sum(y.map(x=>x[v-1]?.length??0))>0;)y.forEach((x,C)=>{let E=x[v-1];if(!E)return;let I=[];E.forEach(R=>{let U=c.get(R)??[],q=U.map(({nodeId:k})=>k);o.length>0&&(q=U.filter(({relationship:k})=>o.includes(k)).map(({nodeId:k})=>k)),q=He.difference(He.intersection(q,Array.from(f)),m),q.forEach(k=>{g[C].push({from:R,to:k}),I.push(k),m.push(k)})}),x[v]=I,I.length>0&&(b[C].push(I.length),M[C]++)}),v++;let w=St().id(x=>x.to).parentId(x=>x.from||null);return p.forEach((x,C)=>{let E=e.positions.get(x.id)??[0,0,0];if(g[C].length<=1){h.set(x.id,[E[0],E[1],E[2]]);return}let I;try{I=w(g[C])}catch{h.set(x.id,[E[0],E[1],E[2]]);return}let R=Math.max(...b[C],1),U=Math.max(M[C]-1,1),q=Math.max(R-1,1),k,A;i==="rings"?(k=2*Math.PI,s!==void 0?A=s*U:A=Math.max(a,a*R/(2*Math.PI))):s!==void 0?(k=s*R*.2*Math.pow(M[C],.3),A=s*U):(k=a*q,A=a*U);let D=Fe().size([k,A])(I);Bn(i,r,D,D,E,h)}),{positions:h}}function Bn(e,t,n,i,r,o){let a=i.id,s,l;if(e==="tree")switch(t){case"up":s=i.x+r[0]-n.x,l=i.y+r[1]+n.y;break;case"down":s=-i.x+r[0]+n.x,l=-i.y+r[1]-n.y;break;case"right":s=i.y+r[0]-n.y,l=-i.x+r[1]+n.x;break;case"left":s=-i.y+r[0]+n.y,l=i.x+r[1]-n.x;break}else switch(t){case"down":s=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":s=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":s=r[0]+i.y*Math.cos(i.x+Math.PI),l=r[1]+i.y*Math.sin(i.x+Math.PI);break;case"left":s=r[0]+i.y*Math.cos(i.x),l=r[1]+i.y*Math.sin(i.x);break}if(o.set(a,[s,l,r[2]]),i.children)for(let u of i.children)Bn(e,t,n,u,r,o)}var dt=1.5,It=3;function ct(e,t){return t==="category"?e.category:e.properties?.[t]}function ft(e,t,n){let i=n&&n.length?new Set(n):null,r=new Set,o=[],a=e.size;for(let s of t){if(i&&!i.has(s.relationship))continue;let l=e.get(s.source),u=e.get(s.target);if(l===void 0||u===void 0||l===u)continue;let c=l*a+u;r.has(c)||(r.add(c),o.push([l,u]))}return o}function zn(e,t){let n=[],i=new Set;for(let r of e)r!=null&&!i.has(r)&&(i.add(r),n.push(r));if(t){let r=t.filter(a=>i.has(a)),o=new Set(r);return[...r,...n.filter(a=>!o.has(a))]}return n.every(r=>typeof r=="number")?[...n].sort((r,o)=>r-o):n}function Qe(e,t,n){switch(e){case"BT":return[n,t];case"LR":return[t,-n];case"RL":return[-t,-n];default:return[n,-t]}}function Oe(e,t){if(t.size===0)return t;let n=0,i=0,r=0;for(let d of e.nodes){let f=e.positions.get(d.id);f&&(n+=f[0],i+=f[1],r++)}r&&(n/=r,i/=r);let o=1/0,a=-1/0,s=1/0,l=-1/0;for(let d of t.values())d[0]<o&&(o=d[0]),d[0]>a&&(a=d[0]),d[1]<s&&(s=d[1]),d[1]>l&&(l=d[1]);let u=n-(o+a)/2,c=i-(s+l)/2;for(let d of t.values())d[0]+=u,d[1]+=c;return t}function Cn(e,t,n){let i=e.length,r=Array.from({length:i},()=>[]),o=new Int32Array(i);for(let[c,d]of t)r[c].push(d),o[d]++;let a;if(n&&n.length){let c=new Set(n);a=[],e.forEach((d,f)=>{c.has(d.id)&&a.push(f)})}else{a=[];for(let c=0;c<i;c++)o[c]===0&&a.push(c);if(!a.length&&i){let c=0;for(let d=1;d<i;d++)r[d].length>r[c].length&&(c=d);a.push(c)}}let s=Array.from({length:i},()=>[]),l=new Uint8Array(i),u=c=>{l[c]=1;let d=[c];for(let f=0;f<d.length;f++){let p=d[f];for(let h of r[p])l[h]||(l[h]=1,s[p].push(h),d.push(h))}};for(let c of a)l[c]||u(c);for(let c=0;c<2;c++)for(let d=0;d<i;d++)l[d]||c===0&&o[d]>0||(a.push(d),u(d));return{roots:a.filter((c,d)=>a.indexOf(c)===d),children:s}}function kn(e,t){let n=e.children.length,i=u=>({i:u,children:[]}),r={i:-1,children:[]},o=[];for(let u of e.roots){let c=i(u);r.children.push(c),o.push(c)}for(;o.length;){let u=o.pop();for(let c of e.children[u.i]){let d=i(c);u.children.push(d),o.push(d)}}let a=Be(r,u=>u.children);Fe().nodeSize([t,1]).separation((u,c)=>u.parent===c.parent?1:1.5)(a);let s=new Int32Array(n),l=new Float64Array(n);return a.each(u=>{u.data.i<0||(s[u.data.i]=u.depth-1,l[u.data.i]=u.x)}),{depth:s,across:l}}function En(e,t={}){let n=e.nodes,i=new Map(n.map((d,f)=>[d.id,f])),r=Cn(n,ft(i,e.edges,t.relationships),t.roots),o=t.nodeGap??dt,a=t.levelGap??It,s=t.direction??"TB",{depth:l,across:u}=kn(r,o),c=new Map;return n.forEach((d,f)=>{let[p,h]=Qe(s,l[f]*a,u[f]);c.set(d.id,[p,h,0])}),{positions:Oe(e,c)}}function Fn(e,t={}){let n=e.nodes,i=new Map(n.map((m,v)=>[m.id,v])),r=Cn(n,ft(i,e.edges,t.relationships),t.roots),o=t.nodeGap??dt,a=t.levelGap??It,s=(t.sweep??360)*Math.PI/180,l=(t.startAngle??90)*Math.PI/180,{depth:u,across:c}=kn(r,o),d=r.roots.length===1,f=1/0,p=-1/0,h=0;for(let m=0;m<n.length;m++)c[m]<f&&(f=c[m]),c[m]>p&&(p=c[m]),u[m]>h&&(h=u[m]);let g=Math.abs(s-2*Math.PI)<1e-6,y=Math.max(p-f+(g?o:0),1e-9),M=Math.max(a,y/s/Math.max(h+(d?0:1),1)),b=new Map;return n.forEach((m,v)=>{let w=(u[v]+(d?0:1))*M,x=l-(c[v]-f)/y*s;b.set(m.id,[w*Math.cos(x),w*Math.sin(x),0])}),{positions:Oe(e,b)}}function Xi(e){if(e.length<2)return 0;let t=e.slice(),n=new Array(t.length),i=0;for(let r=1;r<t.length;r*=2)for(let o=0;o<t.length-r;o+=2*r){let a=o+r,s=Math.min(o+2*r,t.length),l=o,u=a,c=o;for(;l<a&&u<s;)t[l]<=t[u]?n[c++]=t[l++]:(n[c++]=t[u++],i+=a-l);for(;l<a;)n[c++]=t[l++];for(;u<s;)n[c++]=t[u++];for(let d=o;d<s;d++)t[d]=n[d]}return i}function Yi(e,t){let n=e.length,i=new Array(n);i[0]=0;for(let l=1;l<n;l++)i[l]=i[l-1]+t[l-1];let r=[],o=[];for(let l=0;l<n;l++)for(r.push(e[l]-i[l]),o.push(1);r.length>1&&r[r.length-2]/o[o.length-2]>r[r.length-1]/o[o.length-1];){let u=r.pop(),c=o.pop();r[r.length-1]+=u,o[o.length-1]+=c}let a=new Array(n),s=0;for(let l=0;l<r.length;l++){let u=r[l]/o[l];for(let c=0;c<o[l];c++,s++)a[s]=u+i[s]}return a}function $i(e,t){let n=Array.from({length:e},()=>[]);t.forEach(([f,p],h)=>n[f].push(h));let i=new Uint8Array(e),r=new Uint8Array(t.length);for(let f=0;f<e;f++){if(i[f])continue;let p=[[f,0]];for(i[f]=1;p.length;){let h=p[p.length-1],[g,y]=h;if(y<n[g].length){h[1]++;let M=n[g][y],b=t[M][1];i[b]===1?r[M]=1:i[b]===0&&(i[b]=1,p.push([b,0]))}else i[g]=2,p.pop()}}let o=t.map(([f,p],h)=>r[h]?[p,f]:[f,p]),a=Array.from({length:e},()=>[]),s=Array.from({length:e},()=>[]),l=new Int32Array(e);for(let[f,p]of o)a[f].push(p),s[p].push(f),l[p]++;let u=[];for(let f=0;f<e;f++)l[f]===0&&u.push(f);for(let f=0;f<u.length;f++)for(let p of a[u[f]])--l[p]===0&&u.push(p);let c=new Array(e).fill(0);for(let f of u)for(let p of a[f])c[p]=Math.max(c[p],c[f]+1);for(let f=u.length-1;f>=0;f--){let p=u[f];if(s[p].length||!a[p].length)continue;let h=1/0;for(let g of a[p])h=Math.min(h,c[g]);c[p]=h-1}let d=Math.min(...c);return{rank:c.map(f=>f-d),dag:o}}function ji(e,t,n){let i=t.slice(),r=new Array(e).fill(!1),o=Array.from({length:e},()=>[]),a=Array.from({length:e},()=>[]),s=(p,h)=>{a[p].push(h),o[h].push(p)},l=[];for(let[p,h]of n){let g=[];if(l.push(g),i[h]-i[p]<1)continue;let y=p;for(let M=i[p]+1;M<i[h];M++){let b=i.length;i.push(M),r.push(!0),o.push([]),a.push([]),s(y,b),g.push(b),y=b}s(y,h)}let u=i.reduce((p,h)=>Math.max(p,h),0),c=Array.from({length:u+1},()=>[]),d=new Uint8Array(i.length),f=p=>{let h=[p];for(;h.length;){let g=h.pop();if(!d[g]){d[g]=1,c[i[g]].push(g);for(let y=a[g].length-1;y>=0;y--)d[a[g][y]]||h.push(a[g][y])}}};for(let p=0;p<e;p++)o[p].length||f(p);for(let p=0;p<i.length;p++)d[p]||f(p);return{rank:i,isDummy:r,up:o,down:a,layers:c,chains:l}}function hn(e,t){let n=0;for(let i=0;i+1<e.layers.length;i++){let r=[];for(let o of e.layers[i])for(let a of e.down[o])r.push([t[o],t[a]]);r.sort((o,a)=>o[0]-a[0]||o[1]-a[1]),n+=Xi(r.map(o=>o[1]))}return n}function Zi(e,t){let n=new Int32Array(e.rank.length);(()=>{for(let a of e.layers)a.forEach((s,l)=>{n[s]=l})})();let r=hn(e,n),o=e.layers.map(a=>a.slice());for(let a=0;a<t&&r>0;a++){let s=a%2===0,l=s?Array.from({length:e.layers.length-1},(c,d)=>d+1):Array.from({length:e.layers.length-1},(c,d)=>e.layers.length-2-d);for(let c of l){let d=e.layers[c],f=new Map;for(let p of d){let h=s?e.up[p]:e.down[p];f.set(p,h.length?h.reduce((g,y)=>g+n[y],0)/h.length:n[p])}d.sort((p,h)=>f.get(p)-f.get(h)||n[p]-n[h]),d.forEach((p,h)=>{n[p]=h})}let u=hn(e,n);u<r&&(r=u,o=e.layers.map(c=>c.slice()))}e.layers=o}function Vi(e,t){let n=new Float64Array(e.rank.length),i=(a,s)=>t*((e.isDummy[a]?.4:1)+(e.isDummy[s]?.4:1))/2,r=a=>a.slice(1).map((s,l)=>i(a[l],s));for(let a of e.layers){let s=r(a),l=0,u=[0];for(let c of s)u.push(l+=c);a.forEach((c,d)=>{n[c]=u[d]-l/2})}let o=a=>a.reduce((s,l)=>s+n[l],0)/a.length;for(let a=0;a<8;a++){let s=a%2===0,l=e.layers.map((u,c)=>s?c:e.layers.length-1-c);for(let u of l){let c=e.layers[u];if(!c.length)continue;let d=c.map(p=>{let h=e.isDummy[p]||a===7?[...e.up[p],...e.down[p]]:s?e.up[p]:e.down[p];return h.length?o(h):n[p]}),f=Yi(d,r(c));c.forEach((p,h)=>{n[p]=f[h]})}}return n}function In(e,t={}){let n=e.nodes,i=n.length;if(!i)return{positions:new Map};let r=new Map(n.map((x,C)=>[x.id,C])),o=ft(r,e.edges,t.relationships),a,s;if(t.rankBy){let x=n.map(I=>ct(I,t.rankBy)),C=zn(x,t.rankOrder),E=new Map(C.map((I,R)=>[I,R]));a=x.map(I=>E.get(I)??C.length),s=o.map(([I,R])=>a[I]<=a[R]?[I,R]:[R,I])}else({rank:a,dag:s}=$i(i,o));let l=ji(i,a,s);Zi(l,t.sweeps??24);let u=Vi(l,t.nodeGap??dt),c=t.levelGap??It,d=t.direction??"TB",f=new Map;if(n.forEach((x,C)=>{let[E,I]=Qe(d,l.rank[C]*c,u[C]);f.set(x.id,[E,I,0])}),t.edgeShape!=="routed")return{positions:Oe(e,f)};let p=n.length?[...f.get(n[0].id)]:[0,0,0],h=Oe(e,f),g=n.length?h.get(n[0].id):[0,0,0],y=g[0]-p[0],M=g[1]-p[1],b=x=>{let[C,E]=Qe(d,l.rank[x]*c,u[x]);return[C+y,E+M,0]},m=new Map(o.map(([x,C],E)=>[x*i+C,E])),v=t.relationships&&t.relationships.length?new Set(t.relationships):null,w=new Map;for(let x of e.edges){if(v&&!v.has(x.relationship))continue;let C=r.get(x.source),E=r.get(x.target);if(C===void 0||E===void 0||C===E)continue;let I=m.get(C*i+E);if(I===void 0)continue;let R=l.chains[I];if(s[I][0]!==C&&(R=[...R].reverse()),R.length>Et){let U=R.length;R=Array.from({length:Et},(q,k)=>R[Math.round(k*(U-1)/(Et-1))])}w.set(x.id,{shape:"routed",route:R.length?R.map(b):null})}return{positions:h,edgeParams:w}}var Et=16;function Dn(e,t){let n=e.nodes;if(!n.length)return{positions:new Map};if(!t||!t.by)throw new Error("[columnsLayout] option `by` is required");let i=new Map(n.map((b,m)=>[b.id,m])),r=n.map(b=>ct(b,t.by)),o=zn(r,t.order),a=new Map(o.map((b,m)=>[b,m])),s=r.map(b=>a.get(b)??o.length),l=Math.max(...s)+1,u=Array.from({length:l},()=>[]);n.forEach((b,m)=>u[s[m]].push(m));let c=n.map(()=>[]);for(let[b,m]of ft(i,e.edges,t.relationships))s[b]!==s[m]&&(c[b].push(m),c[m].push(b));let d=t.sortBy??"barycenter",f=new Float64Array(n.length),p=b=>b.forEach((m,v)=>{f[m]=v-(b.length-1)/2});if(u.forEach(p),d==="barycenter")for(let b=0;b<12;b++){let m=u.map((v,w)=>b%2===0?w:l-1-w);for(let v of m){let w=u[v],x=new Map(w.map(C=>[C,c[C].length?c[C].reduce((E,I)=>E+f[I],0)/c[C].length:f[C]]));w.sort((C,E)=>x.get(C)-x.get(E)||f[C]-f[E]),p(w)}}else if(d==="degree")for(let b of u)b.sort((m,v)=>c[v].length-c[m].length||m-v),p(b);else if(d!=="none")for(let b of u)b.sort((m,v)=>{let w=ct(n[m],d),x=ct(n[v],d);return typeof w=="number"&&typeof x=="number"?w-x||m-v:String(w??"").localeCompare(String(x??""))||m-v}),p(b);let h=t.nodeGap??dt,g=t.levelGap??4,y=t.direction??"LR",M=new Map;return n.forEach((b,m)=>{let[v,w]=Qe(y,s[m]*g,f[m]*h);M.set(b.id,[v,w,0])}),{positions:Oe(e,M)}}var Wi="PARENT_OF",Ki="SPOUSE_OF";function An(e,t={}){let n=t.parent?.relationship??Wi,i=t.spouse?.relationship??Ki,r=t.spouse?.order,o=t.mode??"descendants",a=t.direction??"TB",s=t.generationGap??3,l=t.siblingGap??1.5,u=t.spouseGap??1,c=new Map(e.nodes.map((S,z)=>[S.id,z])),d=S=>c.has(S),f=new Map,p=new Map,h=[],g=[],y=new Map,M=(S,z,N)=>{let F=S.get(z);F?F.push(N):S.set(z,[N])},b=0;for(let S of e.edges)if(!(S.source===S.target||!d(S.source)||!d(S.target))){if(S.relationship===n)h.push({id:S.id,p:S.source,c:S.target}),(f.get(S.source)??[]).includes(S.target)||(M(f,S.source,S.target),M(p,S.target,S.source));else if(S.relationship===i){g.push({id:S.id,a:S.source,b:S.target});let z=r?S.properties?.[r]:void 0;M(y,S.source,{other:S.target,order:z,k:b}),M(y,S.target,{other:S.source,order:z,k:b}),b++}}let m=S=>f.get(S)??[],v=S=>p.get(S)??[],w=S=>(y.get(S)??[]).map(z=>z.other),x=t.root;if(x!==void 0&&!d(x))throw new Error(`[genealogy] root "${x}" is not among the nodes`);if(x===void 0&&o!=="descendants")throw new Error(`[genealogy] mode "${o}" needs a root`);let C=new Set;if(x===void 0)for(let S of e.nodes)C.add(S.id);else{if(o!=="ancestors"){let S=[x],z=new Set(S);for(;S.length;){let N=S.shift();C.add(N);for(let F of w(N))C.add(F);for(let F of m(N)){for(let W of v(F))C.add(W);z.has(F)||(z.add(F),S.push(F))}}}if(o!=="descendants"){let S=[x],z=new Set(S);for(;S.length;){let N=S.shift();C.add(N);for(let F of v(N))z.has(F)||(z.add(F),S.push(F))}}}let E=e.nodes.map(S=>S.id).filter(S=>C.has(S)),I=new Map(E.map(S=>[S,S])),R=S=>{let z=S;for(;I.get(z)!==z;)z=I.get(z);for(;I.get(S)!==z;){let N=I.get(S);I.set(S,z),S=N}return z},U=new Map,q=(S,z)=>{!C.has(S)||!C.has(z)||S===z||(I.set(R(S),R(z)),U.has(S)||U.set(S,new Set),U.has(z)||U.set(z,new Set),U.get(S).add(z),U.get(z).add(S))};for(let S of g)q(S.a,S.b);for(let S of E){let z=v(S).filter(N=>C.has(N));for(let N=1;N<z.length;N++)q(z[0],z[N])}let k=new Map;for(let S of E)M(k,R(S),S);let A=[],_=new Map;for(let S of k.values()){let z=Qi(S,U,y,c),N=A.length;A.push({members:z});for(let F of z)_.set(F,N)}let D=(S,z)=>A[S].members.indexOf(z),B=S=>{let z=[],N=new Set;for(let W of A[S].members)for(let j of m(W)){if(!C.has(j)||N.has(j))continue;N.add(j);let ne=v(j).map(fe=>D(S,fe)).filter(fe=>fe>=0),ye=ne.reduce((fe,ve)=>fe+ve,0)/ne.length;z.push({c:j,key:ye,at:z.length})}z.sort((W,j)=>W.key-j.key||W.at-j.at);let F=[];for(let{c:W}of z){let j=_.get(W);j!==S&&!F.includes(j)&&F.push(j)}return F},P=S=>{let z=[];for(let N of A[S].members)for(let F of v(N)){if(!C.has(F))continue;let W=_.get(F);W!==S&&!z.includes(W)&&z.push(W)}return z},L=S=>(A[S].members.length-1)*u,Y=(S,z,N)=>{let F=[];for(let W of S){if(N.has(W))continue;N.add(W);let j={u:W,children:[]};F.push(j);let ne=[j];for(;ne.length;){let ye=ne.shift();for(let fe of z(ye.u)){if(N.has(fe))continue;N.add(fe);let ve={u:fe,children:[]};ye.children.push(ve),ne.push(ve)}}}return F},X=S=>{let z=new Map;if(!S.length)return z;let F=Be({u:-1,children:S},j=>j.children),W=j=>j.data.u<0?0:L(j.data.u);return Fe().nodeSize([1,1]).separation((j,ne)=>(W(j)+W(ne))/2+(j.parent===ne.parent?l:l*1.5))(F),F.each(j=>{j.data.u>=0&&z.set(j.data.u,[j.x,j.depth-1])}),z},H=new Map;if(o!=="ancestors"){let S;x!==void 0?S=[_.get(x)]:S=[...A.map((N,F)=>F).filter(N=>A[N].members.every(F=>!v(F).some(W=>C.has(W)))),...A.map((N,F)=>F)];for(let[z,[N,F]]of X(Y(S,B,new Set)))H.set(z,[N,F])}if(o!=="descendants"){let S=_.get(x),z=X(Y([S],P,new Set)),N=(H.get(S)?.[0]??0)-(z.get(S)?.[0]??0);for(let[F,[W,j]]of z)H.has(F)||H.set(F,[W+N,-j])}let T=new Map;for(let[S,[z,N]]of H){let F=A[S].members;F.forEach((W,j)=>{let ne=z+(j-(F.length-1)/2)*u,[ye,fe]=Qe(a,N*s,ne);T.set(W,[ye,fe,0])})}let G={positions:Oe(e,T),edgeRoutingAxis:a==="LR"||a==="RL"?"horizontal":"vertical"};if(t.edgeShapes===!1)return G;let $=new Map,K=(S,z)=>v(S).filter(N=>T.has(N)&&_.get(N)===z).sort((N,F)=>D(z,N)-D(z,F)).join(""),Z=new Map;for(let{p:S,c:z}of h){if(!T.has(S)||!T.has(z))continue;let N=_.get(S),F=K(z,N),W=Z.get(N)??[];W.includes(F)||W.push(F),Z.set(N,W)}for(let[S,z]of Z){let N=F=>{let W=F.split("");return W.reduce((j,ne)=>j+D(S,ne),0)/W.length};z.sort((F,W)=>N(F)-N(W))}for(let{id:S,p:z,c:N}of h){if(!T.has(z)||!T.has(N))continue;let F=_.get(z),j=v(N).filter(ve=>ve!==z&&T.has(ve)).find(ve=>_.get(ve)===F)??null,ne=Z.get(F),ye=ne.indexOf(K(N,F)),fe=ne.length===1?.5:.3+.4*ye/(ne.length-1);$.set(S,{shape:"family",anchor:j,bend:-s*fe})}for(let{id:S,a:z,b:N}of g)!T.has(z)||!T.has(N)||$.set(S,{shape:"orthogonal",bend:null});return G.edgeParams=$,G}function Qi(e,t,n,i){if(e.length===1)return e;let r=(h,g)=>i.get(h)-i.get(g),o=h=>t.get(h)?.size??0,a=[...e].sort((h,g)=>o(g)-o(h)||r(h,g))[0],s=h=>{let g=(n.get(a)??[]).find(y=>y.other===h);return g?[g.order,g.k]:[void 0,Number.MAX_SAFE_INTEGER]},l=(h,g)=>{let[y,M]=s(h),[b,m]=s(g);return y!==void 0&&b!==void 0&&y!==b?typeof y=="number"&&typeof b=="number"?y-b:String(y)<String(b)?-1:1:y!==void 0&&b===void 0?-1:y===void 0&&b!==void 0?1:M-m||r(h,g)},u=[...t.get(a)??[]].filter(h=>e.includes(h)).sort(l),c=[],d=[];u.forEach((h,g)=>(g%2===0?c:d).push(h));let f=new Set([a,...u]),p=e.filter(h=>!f.has(h)).sort(r);for(let h of p){let g=[...t.get(h)??[]].find(y=>f.has(y));(g!==void 0&&c.includes(g)?c:d).push(h),f.add(h)}return[...c.reverse(),a,...d]}function ze(e){if(e==null)return null;let t=Number(e);return Number.isNaN(t)?null:t}function De(e,t,n){let[i,r]=t,[o,a]=n;return r===i?(o+a)/2:o+(e-i)/(r-i)*(a-o)}function Ae(e,t,n){let i=Math.max(t[0],1e-10),r=Math.max(t[1],1e-10),o=Math.max(e,1e-10),[a,s]=n;return r===i?(a+s)/2:a+(Math.log(o)-Math.log(i))/(Math.log(r)-Math.log(i))*(s-a)}function Rn(e,t,n){let i=n??ze,r=1/0,o=-1/0;for(let a of e){let s=a.properties?.[t],l=i(s);l!=null&&(l<r&&(r=l),l>o&&(o=l))}return r===1/0?[0,1]:r===o?[r-1,o+1]:[r,o]}function Un(e,t=5){let[n,i]=e,r=i-n;if(r===0)return[n-1,i+1];let o=r/t,a=Math.pow(10,Math.floor(Math.log10(o))),s=o/a,l;return s<=1.5?l=a:s<=3.5?l=2*a:s<=7.5?l=5*a:l=10*a,[Math.floor(n/l)*l,Math.ceil(i/l)*l]}function Ln(e,t=5){let[n,i]=e;if(n===i)return[n];let o=(i-n)/t,a=Math.pow(10,Math.floor(Math.log10(o))),s=o/a,l;s<=1.5?l=a:s<=3.5?l=2*a:s<=7.5?l=5*a:l=10*a;let u=Math.ceil(n/l)*l,c=[];for(let d=u;d<=i+l*.001;d+=l)c.push(Math.round(d*1e10)/1e10);return c}var Ft=[{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 Gn(e,t=5){let[n,i]=e,r=i-n;if(r<=0)return[n];let o=r/t,a=Ft[Ft.length-1];for(let l of Ft)if(l.ms>=o*.6){a=l;break}let s=[];if(a.calendarUnit==="year"){let l=a.calendarStep,u=new Date(n),c=Math.ceil(u.getFullYear()/l)*l;for(;;){let d=new Date(c,0,1).getTime();if(d>i)break;d>=n&&s.push(d),c+=l}}else if(a.calendarUnit==="month"){let l=a.calendarStep,u=new Date(n),c=u.getFullYear(),d=Math.ceil(u.getMonth()/l)*l;for(;;){let f=new Date(c,d,1).getTime();if(f>i)break;f>=n&&s.push(f),d+=l,d>=12&&(c+=Math.floor(d/12),d=d%12)}}else{let l=a.ms,u=Math.ceil(n/l)*l;for(let c=u;c<=i;c+=l)s.push(c)}return s}function Nn(e,t){let n=t[1]-t[0],i=new Date(e);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 qe(e,t,n){let i=e.domain??Rn(t,e.property,e.parse);e.nice&&!e.domain&&(i=Un(i,e.tickCount));let o=(i[1]-i[0])*n,a=[i[0]-o,i[1]+o],s;e.tickValues?s=e.tickValues:e.isDate?s=Gn(i,e.tickCount):s=Ln(i,e.tickCount);let l=e.tickFormat;return!l&&e.isDate&&(l=u=>Nn(u,i)),{axisInfo:{property:e.property,label:e.property,domain:a,ticks:s,scale:e.scale,tickFormat:l},paddedDomain:a}}function qn(e,t){let{propertyX:n,propertyY:i,propertyZ:r,range:o=[-2,2],scaleX:a="linear",scaleY:s="linear",scaleZ:l="linear",padding:u=.05}=t,c=t.parseX??ze,d=t.parseY??ze,f=t.parseZ??ze,p=!!n,h=!!i,g=!!r,y=e.nodes,M=new Map,b=new Set,m=[];for(let k of y){let A=0,_=0,D=0,B=!1;if(p){let P=c(k.properties?.[n]);P==null?B=!0:A=P}if(h&&!B){let P=d(k.properties?.[i]);P==null?B=!0:_=P}if(g&&!B){let P=f(k.properties?.[r]);P==null?B=!0:D=P}B?b.add(k.id):m.push({id:k.id,x:A,y:_,z:D})}let v=p?qe({property:n,scale:a,domain:t.domainX,parse:c,tickFormat:t.tickFormatX,tickCount:t.tickCountX??5,tickValues:t.tickValuesX,nice:t.niceX??!0,isDate:t.dateAxisX??!1},y,u):null,w=h?qe({property:i,scale:s,domain:t.domainY,parse:d,tickFormat:t.tickFormatY,tickCount:t.tickCountY??5,tickValues:t.tickValuesY,nice:t.niceY??!0,isDate:t.dateAxisY??!1},y,u):null,x=g?qe({property:r,scale:l,domain:t.domainZ,parse:f,tickFormat:t.tickFormatZ,tickCount:t.tickCountZ??5,tickValues:t.tickValuesZ,nice:t.niceZ??!0,isDate:t.dateAxisZ??!1},y,u):null,C=a==="log"?Ae:De,E=s==="log"?Ae:De,I=l==="log"?Ae:De,R=t.spread??1,U=[o[0]*R,o[1]*R],q=o[0];for(let k of m){let A=v?C(k.x,v.paddedDomain,U):q,_=w?E(k.y,w.paddedDomain,U):q,D=x?I(k.z,x.paddedDomain,U):0;M.set(k.id,[A,_,D])}return{positions:M,axes:{x:v?.axisInfo,y:w?.axisInfo,z:x?.axisInfo},range:U,baseRange:o,excludedNodeIds:b}}function On(e,t){let n=t.range??[-2,2],i=t.spread??1,r=[n[0]*i,n[1]*i],o=t.padding??.05,a=n[0],s=t.unmappedMode??"hide",l=new Map;for(let p of t.mappings)l.set(p.category,p);let u=new Map;for(let p of e.nodes){let h=p.category,g=u.get(h);g||(g=[],u.set(h,g)),g.push(p)}let c=new Map,d=new Set,f={};for(let[p,h]of u){let g=l.get(p);if(!g){if(s==="hide")for(let H of h)d.add(H.id);else{let H;s==="boundary"?H=n[0]:H=(n[0]+n[1])/2;for(let T of h)c.set(T.id,[H,H,0])}continue}let y=!!g.propertyX,M=!!g.propertyY,b=!!g.propertyZ,m=g.scaleX??"linear",v=g.scaleY??"linear",w=g.scaleZ??"linear",x=g.parseX??ze,C=g.parseY??ze,E=g.parseZ??ze,I=g.tickCountX??t.tickCountX??5,R=g.tickCountY??t.tickCountY??5,U=g.tickCountZ??t.tickCountZ??5,q=g.niceX??t.niceX??!0,k=g.niceY??t.niceY??!0,A=g.niceZ??t.niceZ??!0,_=[];for(let H of h){let T=0,G=0,$=0,K=!1;if(y){let Z=x(H.properties?.[g.propertyX]);Z==null?K=!0:T=Z}if(M&&!K){let Z=C(H.properties?.[g.propertyY]);Z==null?K=!0:G=Z}if(b&&!K){let Z=E(H.properties?.[g.propertyZ]);Z==null?K=!0:$=Z}K?d.add(H.id):_.push({id:H.id,x:T,y:G,z:$})}let D=y?qe({property:g.propertyX,scale:m,domain:g.domainX,parse:x,tickFormat:g.tickFormatX,tickCount:I,tickValues:g.tickValuesX,nice:q,isDate:g.dateAxisX??!1},h,o):null,B=M?qe({property:g.propertyY,scale:v,domain:g.domainY,parse:C,tickFormat:g.tickFormatY,tickCount:R,tickValues:g.tickValuesY,nice:k,isDate:g.dateAxisY??!1},h,o):null,P=b?qe({property:g.propertyZ,scale:w,domain:g.domainZ,parse:E,tickFormat:g.tickFormatZ,tickCount:U,tickValues:g.tickValuesZ,nice:A,isDate:g.dateAxisZ??!1},h,o):null,L=m==="log"?Ae:De,Y=v==="log"?Ae:De,X=w==="log"?Ae:De;for(let H of _){let T=D?L(H.x,D.paddedDomain,r):a,G=B?Y(H.y,B.paddedDomain,r):a,$=P?X(H.z,P.paddedDomain,r):0;c.set(H.id,[T,G,$])}f[p]={x:D?.axisInfo,y:B?.axisInfo,z:P?.axisInfo}}return{positions:c,axes:{x:void 0,y:void 0,z:void 0},range:r,baseRange:n,excludedNodeIds:d,categoryAxes:f}}var Ji=/^[a-z][a-zA-Z0-9]*$/,er=/^[a-z][a-z0-9-]*:[A-Za-z][A-Za-z0-9_-]*$/,Hn=class Xn{constructor(){this.entries=new Map}register(t,n,i={}){if(!er.test(t))throw new Error(`[LayoutRegistry] invalid layout name "${t}": extension layouts must be named "<pack>:<name>" (e.g. "acme:rack")`);return this.add(t,n,!1,i)}registerBuiltin(t,n,i){if(!Ji.test(t))throw new Error(`[LayoutRegistry] invalid built-in layout name "${t}"`);this.add(t,n,!0,{description:i})}add(t,n,i,r){if(typeof n!="function")throw new Error(`[LayoutRegistry] layout "${t}" must be a function`);let o=this.entries.get(t);if(o&&(o.builtin||!r.replace))throw new Error(`[LayoutRegistry] layout "${t}" is already registered`);let a={name:t,fn:n,builtin:i,description:r.description};return this.entries.set(t,a),()=>{this.entries.get(t)===a&&this.entries.delete(t)}}has(t){return this.entries.has(t)}get(t){return this.entries.get(t)}list(){let t=[...this.entries.values()];return[...t.filter(n=>n.builtin),...t.filter(n=>!n.builtin)]}execute(t,n,i){let r=this.entries.get(t);if(!r)throw new Error(`[LayoutRegistry] unknown layout "${t}". Registered: ${[...this.entries.keys()].join(", ")}`);return r.fn(n,i)}fork(){let t=new Xn;for(let[n,i]of this.entries)t.entries.set(n,i);return t}};function tr(){let e=new Hn;return e.registerBuiltin("circle",mn,"Nodes on a circle."),e.registerBuiltin("grid",gn,"Nodes on a 2-D grid."),e.registerBuiltin("line",yn,"Nodes along an axis."),e.registerBuiltin("spiral",vn,"Nodes on a spiral."),e.registerBuiltin("cube",xn,"Nodes in a 3-D lattice."),e.registerBuiltin("sphere",bn,"Nodes on a sphere."),e.registerBuiltin("scatter",wn,"Nodes scattered randomly in a range."),e.registerBuiltin("ego",Pn,"Tree or rings around root node(s)."),e.registerBuiltin("tree",En,"Tidy tree (org chart, directory); forests supported."),e.registerBuiltin("radialTree",Fn,"Tidy tree in polar form, root in the centre."),e.registerBuiltin("layered",In,"Layered (Sugiyama) layout for directed graphs: lineage, call chains, workflows."),e.registerBuiltin("columns",Dn,"One column per property value, crossings reduced inside columns."),e.registerBuiltin("genealogy",An,"Family tree: couples side by side, children under their parents, shared family lines."),e.registerBuiltin("rotate",Mn,"Rotate current positions (transform)."),e.registerBuiltin("scale",Sn,"Scale current positions (transform)."),e.registerBuiltin("shift",_n,"Translate current positions (transform)."),e.registerBuiltin("alignBy",Tn,"Align nodes by an axis (transform)."),e.registerBuiltin("plotScatter",qn,"Scatter plot by two properties."),e.registerBuiltin("plotMultiCategoryScatter",On,"Scatter plot with category axes."),e}var nr=tr();var se=me(require("three"),1);function Ee(){return typeof navigator<"u"&&!!navigator.gpu}async function Vn(e={}){if(!Ee())throw new Error("WebGPU not available: navigator.gpu is undefined. Use the WebGL backend instead.");let t=await navigator.gpu.requestAdapter({powerPreference:e.preferHighPerformance===!1?"low-power":"high-performance"});if(!t)throw new Error("WebGPU adapter request returned null (no compatible adapter found).");let i=(e.requestedFeatures??[]).filter(o=>t.features.has(o)),r=await t.requestDevice({requiredFeatures:i});return{adapter:t,device:r,features:new Set(t.features),limits:t.limits}}function Gt(e){if(e<=0)return 1;let t=Math.ceil(Math.sqrt(e));return Math.pow(2,Math.ceil(Math.log2(t)))}function $e(e,t,n=10){if(e<=0)return n;let i;return t===3?i=Math.cbrt(e)*2:i=Math.sqrt(e)*.5,Math.max(n,i)}function ir(){return{type:se.FloatType,format:se.RGBAFormat,minFilter:se.NearestFilter,magFilter:se.NearestFilter,generateMipmaps:!1,depthBuffer:!1,stencilBuffer:!1}}function Re(e){let t=ir();return new se.WebGLRenderTarget(e,e,t)}function je(e,t){let n=new se.DataTexture(e,t,t,se.RGBAFormat,se.FloatType);return n.minFilter=se.NearestFilter,n.magFilter=se.NearestFilter,n.needsUpdate=!0,n}function Wn(e){let t=[];for(let n=0;n<e;n++)for(let i=0;i<e;i++)t.push(i,n);return new Float32Array(t)}function we(){return new se.PlaneGeometry(2,2)}function Kn(e=1){let r=e;return function(){return r=(1664525*r+1013904223)%4294967296,r/4294967296}}function mt(e){return(e()-.5)*1e-6}function ae(e){return()=>e}function et(e,t,n){let i=e.length,r=10,o=Math.PI*(3-Math.sqrt(5)),a=Math.PI*20/(9+Math.sqrt(221));for(let s=0;s<i;s++){let l=e[s];if(l.index=s,l.fx!=null&&(l.x=l.fx),l.fy!=null&&(l.y=l.fy),l.fz!=null&&(l.z=l.fz),isNaN(l.x)||t>1&&isNaN(l.y)||t>2&&isNaN(l.z)){let u=r*(t>2?Math.cbrt(.5+s):t>1?Math.sqrt(.5+s):s),c=s*o,d=s*a;t===1?l.x=u:t===2?(l.x=u*Math.cos(c),l.y=u*Math.sin(c)):(l.x=u*Math.sin(c)*Math.cos(d),l.y=u*Math.cos(c),l.z=u*Math.sin(c)*Math.sin(d))}(isNaN(l.vx)||t>1&&isNaN(l.vy)||t>2&&isNaN(l.vz))&&(l.vx=0,t>1&&(l.vy=0),t>2&&(l.vz=0))}}function Qn(e,t){let n=t*t,i=new Float32Array(n*4);for(let r=0;r<e.length;r++){let o=e[r],a=r*4;i[a]=o.x||0,i[a+1]=o.y||0,i[a+2]=o.z||0,i[a+3]=r}return i}function Jn(e,t){let n=t*t,i=new Float32Array(n*4);for(let r=0;r<e.length;r++){let o=e[r],a=r*4;i[a]=o.vx||0,i[a+1]=o.vy||0,i[a+2]=o.vz||0,i[a+3]=0}return i}function ei(e,t){let n=t*t,i=new Float32Array(n*4);for(let r=0;r<e.length;r++){let o=e[r],a=r*4;i[a]=o.fx!=null||o.fy!=null||o.fz!=null?1:0,i[a+1]=0,i[a+2]=0,i[a+3]=0}return i}function ti(e,t,n){for(let i=0;i<e.length;i++){let r=e[i],o=i*4;r.fx==null&&(r.x=t[o]),n>1&&r.fy==null&&(r.y=t[o+1]),n>2&&r.fz==null?r.z=t[o+2]:n<=2&&(r.z=0)}}var rr=`// Position integration compute shader.
|
|
2
2
|
//
|
|
3
3
|
// One invocation per node. Reads accumulated velocity, applies velocityDecay,
|
|
4
4
|
// CLAMPS velocity magnitude to maxVel (matches WebGL FBO path's
|
|
@@ -82,7 +82,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
|
|
82
82
|
// Store the decayed-but-UNCLAMPED velocity so momentum carries to next tick.
|
|
83
83
|
velocities[i] = vec4<f32>(v, 0.0);
|
|
84
84
|
}
|
|
85
|
-
`,
|
|
85
|
+
`,Xe=16,Ye=16,Yn=4,ar=16,or=64;function ni(e,t=3,n={}){let i=e,r=i.length,o=t,a=1,s=.001,l=0,u=1-Math.pow(s,1/300),c=.6,d=0,f=Math.random,p=new Map,h=new Map,g=null,y=null,M=null,b=null,m=null,v=null,w=null,x=null,C=null,E=null,I=!1,R=!1,U=!1;et(i,o,f),(n.device||Ee())&&q();async function q(){try{y=n.device?await n.device:await Vn({preferHighPerformance:n.preferHighPerformance}),_(),D(),k(),p.forEach(T=>B(T)),I=!0,P("ready")}catch(T){console.error("[webgpuForceSimulation] device init failed:",T)}}function k(){if(!y||!M||!b||!m)return;let{device:T}=y;x?.destroy(),x=T.createBuffer({label:"integrate-params",size:ar,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});let G=T.createShaderModule({label:"integrate-shader",code:rr});C=T.createComputePipeline({label:"integrate-pipeline",layout:"auto",compute:{module:G,entryPoint:"main"}}),E=T.createBindGroup({label:"integrate-bind-group",layout:C.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:M}},{binding:1,resource:{buffer:b}},{binding:2,resource:{buffer:m}},{binding:3,resource:{buffer:x}}]})}function A(){if(!y||!x)return;let T=new Float32Array([c,o,r,d]);y.device.queue.writeBuffer(x,0,T)}function _(){if(!y)return;let{device:T}=y;M?.destroy(),b?.destroy(),m?.destroy(),v?.destroy(),w?.destroy(),M=T.createBuffer({label:"positions",size:r*Xe,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST}),b=T.createBuffer({label:"velocities",size:r*Ye,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST}),m=T.createBuffer({label:"pinned",size:r*Yn,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST}),v=T.createBuffer({label:"readback",size:r*Xe,usage:GPUBufferUsage.MAP_READ|GPUBufferUsage.COPY_DST}),w=T.createBuffer({label:"readback-velocity",size:r*Ye,usage:GPUBufferUsage.MAP_READ|GPUBufferUsage.COPY_DST})}function D(){if(!y||!M||!b||!m)return;let{device:T}=y,G=new Float32Array(r*4),$=new Float32Array(r*4),K=new Float32Array(r);for(let Z=0;Z<r;Z++){let S=i[Z];G[Z*4+0]=S.x??0,G[Z*4+1]=S.y??0,G[Z*4+2]=S.z??0,G[Z*4+3]=Z,$[Z*4+0]=S.vx??0,$[Z*4+1]=S.vy??0,$[Z*4+2]=S.vz??0,K[Z]=S.fx!=null||S.fy!=null||S.fz!=null?1:0}T.queue.writeBuffer(M,0,G),T.queue.writeBuffer(b,0,$),T.queue.writeBuffer(m,0,K)}function B(T){if(!y||!M||!b||!m)return;let G={device:y.device,nodeCount:r,nDim:o,positionBuffer:M,velocityBuffer:b,pinnedBuffer:m};T.initGPU(G)}function P(T){let G=h.get(T);if(G)for(let $ of G)$()}function L(T=1){if(!I||!y||!C||!E)return;let{device:G}=y;for(let $=0;$<T;$++){if(a<s){P("end");return}A();let K=G.createCommandEncoder({label:"tick"});p.forEach(S=>S.apply(a,K));let Z=K.beginComputePass({label:"integrate"});Z.setPipeline(C),Z.setBindGroup(0,E),Z.dispatchWorkgroups(Math.ceil(r/or)),Z.end(),G.queue.submit([K.finish()]),a=a+(l-a)*u,P("tick")}}async function Y(){if(!(!y||!M||!v)&&!R){R=!0;try{let{device:T}=y,G=T.createCommandEncoder({label:"readback"});G.copyBufferToBuffer(M,0,v,0,r*Xe),T.queue.submit([G.finish()]);try{await v.mapAsync(GPUMapMode.READ,0,r*Xe)}catch(K){let Z=K?.name;if(Z==="AbortError"||Z==="OperationError")return;throw K}if(!v)return;let $=new Float32Array(v.getMappedRange(0,r*Xe));if(globalThis.__webgpuPathASkip===!0){(!g||g.length<$.length)&&(g=new Float32Array($.length)),g.set($),v.unmap();return}for(let K=0;K<r;K++){let Z=K*4,S=i[K];S.fx==null&&(S.x=$[Z]),o>1&&S.fy==null&&(S.y=$[Z+1]),o>2&&S.fz==null?S.z=$[Z+2]:o<=2&&(S.z=0)}v.unmap()}finally{R=!1}}}async function X(){if(!y||!b||!w)return new Float32Array(0);let{device:T}=y,G=T.createCommandEncoder({label:"readback-vel"});G.copyBufferToBuffer(b,0,w,0,r*Ye),T.queue.submit([G.finish()]);try{await w.mapAsync(GPUMapMode.READ,0,r*Ye)}catch(Z){if(Z?.name==="AbortError")return new Float32Array(0);throw Z}if(!w)return new Float32Array(0);let $=new Float32Array(w.getMappedRange(0,r*Ye)),K=new Float32Array($);return w.unmap(),K}return{tick(T){return L(T??1),this},restart(){return a=1,this},stop(){return this},alpha(T){return arguments.length===0?a:(a=+T,this)},alphaMin(T){return arguments.length===0?s:(s=+T,this)},alphaDecay(T){return arguments.length===0?u:(u=+T,this)},velocityDecay(T){return arguments.length===0?c:(c=+T,this)},alphaTarget(T){return arguments.length===0?l:(l=+T,this)},maxVel(T){return arguments.length===0?d:(d=+T,this)},uploadPosition(T,G,$,K){if(!y||!M||T<0||T>=r)return;let Z=T*Xe,S=new Float32Array([G,$,K,T]);y.device.queue.writeBuffer(M,Z,S);let z=i[T];z&&(z.x=G,z.y=$,z.z=K)},uploadVelocity(T,G,$,K){if(!y||!b||T<0||T>=r)return;let Z=T*Ye,S=new Float32Array([G,$,K,0]);y.device.queue.writeBuffer(b,Z,S);let z=i[T];z&&(z.vx=G,z.vy=$,z.vz=K)},uploadPinned(T,G){if(!y||!m||T<0||T>=r)return;let $=T*Yn;y.device.queue.writeBuffer(m,$,new Float32Array([G?1:0]))},nodes(T){return arguments.length===0?i:(i=T,r=i.length,et(i,o,f),y&&(_(),D(),k(),p.forEach(G=>B(G))),this)},force(T,G){return arguments.length===1?p.get(T):(G==null?p.delete(T):(G.initialize(i,f,o),p.set(T,G),y&&B(G)),this)},numDimensions(T){return arguments.length===0?o:(o=+T,A(),p.forEach(G=>G.initialize(i,f,o)),this)},on(T,G){let $=h.get(T);return $||($=[],h.set(T,$)),$.push(G),this},dispose(){M?.destroy(),b?.destroy(),m?.destroy(),v?.destroy(),w?.destroy(),x?.destroy(),M=b=m=v=null,w=null,x=null,C=null,E=null,p.forEach(T=>T.dispose?.()),p.clear(),I=!1},isReady(){return I},readPositions(){return Y()},readVelocities(){return X()},getDevice(){return y?.device??null},getPositionBuffer(){return M}}}var sr=`// forceCenter \u2014 pass 1 of 2: parallel reduce centroid \u2192 shift vector.
|
|
86
86
|
//
|
|
87
87
|
// Computes mean(positions) across all nodes inside a single workgroup using
|
|
88
88
|
// shared memory, then writes (mean - target) * strength to shift[0].
|
|
@@ -157,7 +157,7 @@ fn main(@builtin(local_invocation_id) lid: vec3<u32>) {
|
|
|
157
157
|
shift[0] = vec4<f32>(s, 0.0);
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
|
-
`,
|
|
160
|
+
`,lr=`// forceCenter \u2014 pass 2 of 2: subtract shift from every node's position.
|
|
161
161
|
//
|
|
162
162
|
// Mirrors d3-force-3d center.js: \`node.x -= shift\`. Pinned nodes are skipped.
|
|
163
163
|
// One invocation per node.
|
|
@@ -192,7 +192,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
|
|
192
192
|
if (params.nDim < 2.0) { p.y = 0.0; }
|
|
193
193
|
positions[i] = vec4<f32>(p, positions[i].w);
|
|
194
194
|
}
|
|
195
|
-
`,
|
|
195
|
+
`,ur=16,cr=32,dr=16,fr=64;function ii(e=0,t=0,n=0){let i=e,r=t,o=n,a=1,s=3,l=0,u=null,c=null,d=null,f=null,p=null,h=null,g=null,y=null;function M(C,E,I){s=I}function b(C){u=C.device,l=C.nodeCount,s=C.nDim,c?.destroy(),c=u.createBuffer({label:"center-shift",size:ur,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST}),d?.destroy(),d=u.createBuffer({label:"center-reduce-params",size:cr,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),f?.destroy(),f=u.createBuffer({label:"center-apply-params",size:dr,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});let E=u.createShaderModule({label:"center-reduce-shader",code:sr});p=u.createComputePipeline({label:"center-reduce-pipeline",layout:"auto",compute:{module:E,entryPoint:"main"}});let I=u.createShaderModule({label:"center-apply-shader",code:lr});h=u.createComputePipeline({label:"center-apply-pipeline",layout:"auto",compute:{module:I,entryPoint:"main"}}),g=u.createBindGroup({label:"center-reduce-bind-group",layout:p.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:C.positionBuffer}},{binding:1,resource:{buffer:c}},{binding:2,resource:{buffer:d}}]}),y=u.createBindGroup({label:"center-apply-bind-group",layout:h.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:C.positionBuffer}},{binding:1,resource:{buffer:C.pinnedBuffer}},{binding:2,resource:{buffer:c}},{binding:3,resource:{buffer:f}}]})}function m(){if(!u||!d||!f)return;let C=new Float32Array([l,s,a,0,i,r,o,0]);u.queue.writeBuffer(d,0,C);let E=new Float32Array([l,s,0,0]);u.queue.writeBuffer(f,0,E)}function v(C,E){if(!p||!h||!g||!y||l===0)return;m();let I=E.beginComputePass({label:"center-reduce"});I.setPipeline(p),I.setBindGroup(0,g),I.dispatchWorkgroups(1),I.end();let R=E.beginComputePass({label:"center-apply"});R.setPipeline(h),R.setBindGroup(0,y),R.dispatchWorkgroups(Math.ceil(l/fr)),R.end()}function w(){c?.destroy(),d?.destroy(),f?.destroy(),c=d=f=null,p=h=null,g=y=null,u=null}let x={initialize:M,initGPU:b,apply:v,dispose:w,x(C){return arguments.length===0?i:(i=+C,x)},y(C){return arguments.length===0?r:(r=+C,x)},z(C){return arguments.length===0?o:(o=+C,x)},strength(C){return arguments.length===0?a:(a=+C,x)}};return x}var pr=`// Per-axis attractive force (forceX / forceY / forceZ).
|
|
196
196
|
//
|
|
197
197
|
// One invocation per node. Adds \`(target - position[axis]) * strength * alpha\`
|
|
198
198
|
// to that node's velocity along the configured axis only \u2014 other axes untouched.
|
|
@@ -241,7 +241,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
|
|
241
241
|
|
|
242
242
|
velocities[i] = vec4<f32>(vel, velocities[i].w);
|
|
243
243
|
}
|
|
244
|
-
`,
|
|
244
|
+
`,hr=32,mr=64;function Nt(e,t){let n=t,i=.1,r=0,o=null,a=null,s=null,l=null;function u(){}function c(g){o=g.device,r=g.nodeCount,a?.destroy(),a=o.createBuffer({label:`position-force-${e}-params`,size:hr,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});let y=o.createShaderModule({label:`position-force-${e}-shader`,code:pr});s=o.createComputePipeline({label:`position-force-${e}-pipeline`,layout:"auto",compute:{module:y,entryPoint:"main"}}),l=o.createBindGroup({label:`position-force-${e}-bind-group`,layout:s.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:g.positionBuffer}},{binding:1,resource:{buffer:g.velocityBuffer}},{binding:2,resource:{buffer:a}}]})}function d(g){if(!o||!a)return;let y=new Float32Array([e,n,i,g,r,0,0,0]);o.queue.writeBuffer(a,0,y)}function f(g,y){if(!s||!l||r===0)return;d(g);let M=y.beginComputePass({label:`position-force-${e}`});M.setPipeline(s),M.setBindGroup(0,l),M.dispatchWorkgroups(Math.ceil(r/mr)),M.end()}function p(){a?.destroy(),a=null,s=null,l=null,o=null}let h={initialize:u,initGPU:c,apply:f,dispose:p,strength(g){return arguments.length===0?i:(i=+g,h)},target(g){return arguments.length===0?n:(n=+g,h)}};return h}function ri(e=0){return Nt(0,e)}function ai(e=0){return Nt(1,e)}function oi(e=0){return Nt(2,e)}var gr=`// forceLink \u2014 per-edge spring constraint.
|
|
245
245
|
//
|
|
246
246
|
// One invocation per edge. For each edge (s, t), computes a delta toward the
|
|
247
247
|
// configured \`linkDistance\` and accumulates contributions into an integer
|
|
@@ -323,7 +323,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
|
|
323
323
|
atomicSub(&velAccum[tIdx * 3u + 1u], i32(tgtShare.y * FIXED_POINT_SCALE));
|
|
324
324
|
atomicSub(&velAccum[tIdx * 3u + 2u], i32(tgtShare.z * FIXED_POINT_SCALE));
|
|
325
325
|
}
|
|
326
|
-
`,
|
|
326
|
+
`,yr=`// forceLink pass 2: drain the i32 atomic accumulator into f32 velocities.
|
|
327
327
|
//
|
|
328
328
|
// One invocation per node. Reads the 3 i32 slots populated by link-force.wgsl,
|
|
329
329
|
// converts back to f32 (divides by FIXED_POINT_SCALE), adds to velocity, then
|
|
@@ -360,7 +360,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
|
|
360
360
|
let delta = vec3<f32>(f32(ax), f32(ay), f32(az)) / FIXED_POINT_SCALE;
|
|
361
361
|
velocities[i] = vec4<f32>(velocities[i].xyz + delta, velocities[i].w);
|
|
362
362
|
}
|
|
363
|
-
`,
|
|
363
|
+
`,vr=12,xr=16,br=16,$n=64;function wr(e){return()=>e}function si(e=[]){let t=e,n=new Int32Array(0),i=30,r=[],o=0,a=null,s=null,l=null,u=null,c=null,d=null,f=null,p=null,h=null,g=null,y=0,M=new Float32Array(0),b=null,m=null;function v(B){let P=B.source,L=B.target,Y=Math.min(n[P]??1,n[L]??1);return Y>0?1/Y:1}let w=v;function x(B,P,L){r=B}function C(){let B=new Map;for(let X=0;X<r.length;X++){let H=r[X];H.id!=null&&B.set(H.id,X),H.index!=null&&B.set(H.index,X)}let P=new Int32Array(r.length),L=[];for(let X=0;X<t.length;X++){let H=t[X],T=E(H.source,B),G=E(H.target,B);T<0||G<0||(P[T]++,P[G]++,L.push({source:T,target:G,index:X}))}n=P;let Y=new Float32Array(L.length*4);M=new Float32Array(L.length);for(let X=0;X<L.length;X++){let H=L[X].source,T=L[X].target,G=P[H]+P[T],$=G>0?P[H]/G:.5;Y[X*4+0]=H,Y[X*4+1]=T,Y[X*4+2]=$,Y[X*4+3]=i,M[X]=+w(L[X],X,L)}return y=L.length,Y}function E(B,P){if(typeof B=="object"&&B!==null){let L=B;return L.index!=null?L.index:L.id!=null?P.get(L.id)??-1:-1}return P.get(B)??-1}function I(){if(!a)return;let B=C();if(s?.destroy(),l?.destroy(),B.length===0){s=null,l=null;return}s=a.createBuffer({label:"link-edges",size:B.byteLength,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST}),a.queue.writeBuffer(s,0,B.buffer,B.byteOffset,B.byteLength),l=a.createBuffer({label:"link-strengths",size:Math.max(M.byteLength,4),usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST}),a.queue.writeBuffer(l,0,M.buffer,M.byteOffset,M.byteLength),m&&b&&U(m,b)}function R(B){a=B.device,o=B.nodeCount,u?.destroy(),u=a.createBuffer({label:"link-vel-accum",size:o*vr,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST});let P=new Int32Array(o*3);a.queue.writeBuffer(u,0,P.buffer,0,P.byteLength),c?.destroy(),c=a.createBuffer({label:"link-params",size:xr,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),d?.destroy(),d=a.createBuffer({label:"link-drain-params",size:br,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});let L=a.createShaderModule({label:"link-force-shader",code:gr});f=a.createComputePipeline({label:"link-force-pipeline",layout:"auto",compute:{module:L,entryPoint:"main"}});let Y=a.createShaderModule({label:"link-drain-shader",code:yr});p=a.createComputePipeline({label:"link-drain-pipeline",layout:"auto",compute:{module:Y,entryPoint:"main"}}),I(),U(B.positionBuffer,B.velocityBuffer)}function U(B,P){!a||!f||!p||!u||!c||!d||(b=P,m=B,s&&l?h=a.createBindGroup({label:"link-force-bind-group",layout:f.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:B}},{binding:1,resource:{buffer:u}},{binding:2,resource:{buffer:s}},{binding:3,resource:{buffer:c}},{binding:4,resource:{buffer:l}},{binding:5,resource:{buffer:P}}]}):h=null,g=a.createBindGroup({label:"link-drain-bind-group",layout:p.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:P}},{binding:1,resource:{buffer:u}},{binding:2,resource:{buffer:d}}]}))}function q(){I()}function k(B){if(!a||!c||!d)return;let P=new Float32Array([y,0,B,0]);a.queue.writeBuffer(c,0,P);let L=new Float32Array([o,0,0,0]);a.queue.writeBuffer(d,0,L)}function A(B,P){if(!f||!p||!g||o===0)return;if(k(B),h&&y>0){let Y=P.beginComputePass({label:"link-force"});Y.setPipeline(f),Y.setBindGroup(0,h),Y.dispatchWorkgroups(Math.ceil(y/$n)),Y.end()}let L=P.beginComputePass({label:"link-drain"});L.setPipeline(p),L.setBindGroup(0,g),L.dispatchWorkgroups(Math.ceil(o/$n)),L.end()}function _(){s?.destroy(),l?.destroy(),u?.destroy(),c?.destroy(),d?.destroy(),s=l=u=c=d=null,f=p=null,h=g=null,b=null,m=null,a=null}let D={initialize:x,initGPU:R,apply:A,dispose:_,links(B){return arguments.length===0?t:(t=B,a&&I(),D)},strength(B){return arguments.length===0?w:(w=typeof B=="function"?B:wr(+B),a&&I(),D)},distance(B){return arguments.length===0?i:(i=+B,a&&I(),D)},rebuildEdgeBuffer:q};return D}var li=64,ke=32,Mr=.9;function Sr(e){return e<=1?1:1<<Math.ceil(Math.log2(e))}function _r(e,t,n){let i=t,r=Sr(i),o=GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC,a=e.createBuffer({label:"lbvh-morton",size:r*4,usage:o}),s=e.createBuffer({label:"lbvh-sortedIndices",size:r*4,usage:o}),l=e.createBuffer({label:"lbvh-internal",size:Math.max(1,i-1)*16,usage:o}),u=e.createBuffer({label:"lbvh-parent",size:Math.max(1,i-1)*4,usage:o}),c=e.createBuffer({label:"lbvh-aabb",size:Math.max(1,2*i-1)*32,usage:o}),d=e.createBuffer({label:"lbvh-com",size:Math.max(1,2*i-1)*16,usage:o}),f=e.createBuffer({label:"lbvh-depth",size:Math.max(1,i-1)*4,usage:o}),p=e.createBuffer({label:"lbvh-bounds",size:32,usage:o}),h=e.createBuffer({label:"lbvh-queueA",size:Math.max(1,i-1)*4,usage:o}),g=e.createBuffer({label:"lbvh-queueB",size:Math.max(1,i-1)*4,usage:o}),y=e.createBuffer({label:"lbvh-frontier",size:(n+1)*4,usage:o}),M=e.createBuffer({label:"lbvh-root",size:4,usage:o});return{paddedN:r,morton:a,sortedIndices:s,internal:l,parent:u,aabb:c,com:d,depth:f,bounds:p,depthQueueA:h,depthQueueB:g,frontierCounts:y,root:M,dispose(){for(let b of[a,s,l,u,c,d,f,p,h,g,y,M])b.destroy()}}}var qt=`// P1: scene AABB via atomicMin/atomicMax on i32 bit-reinterpretation of f32 positions.
|
|
364
364
|
// Uses ordered-i32 trick: for positive floats, integer bit pattern preserves order;
|
|
365
365
|
// for negative, flipping all bits restores order. Inverse on read recovers f32.
|
|
366
366
|
|
|
@@ -387,7 +387,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
|
|
387
387
|
atomicMin(&bounds[2], yi); atomicMax(&bounds[3], yi);
|
|
388
388
|
atomicMin(&bounds[4], zi); atomicMax(&bounds[5], zi);
|
|
389
389
|
}
|
|
390
|
-
`,
|
|
390
|
+
`,Tr=`// P2: per-node Morton code from normalized position. Mirrors mortonReference.ts exactly.
|
|
391
391
|
|
|
392
392
|
struct MortonParams { nodeCount: u32, _pad0: u32, _pad1: u32, _pad2: u32 };
|
|
393
393
|
|
|
@@ -428,7 +428,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
|
|
428
428
|
mortons[i] = mortonExpand10(xi) | (mortonExpand10(yi) << 1u) | (mortonExpand10(zi) << 2u);
|
|
429
429
|
sortedIndices[i] = i;
|
|
430
430
|
}
|
|
431
|
-
`,
|
|
431
|
+
`,Pr=`// P4: Karras-2012 binary radix tree build. One thread per internal node (N-1 threads).
|
|
432
432
|
// Each internal node i covers a range of sorted Morton codes; the split is the largest
|
|
433
433
|
// prefix-difference inside the range.
|
|
434
434
|
//
|
|
@@ -527,7 +527,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
|
|
527
527
|
if (!leftIsLeaf) { parentBuf[leftChild] = i; }
|
|
528
528
|
if (!rightIsLeaf) { parentBuf[rightChild] = i; }
|
|
529
529
|
}
|
|
530
|
-
`,
|
|
530
|
+
`,Br=`// P4b: find the root internal node. The root is the unique internal node with
|
|
531
531
|
// parentBuf[i] == -1 (parentBuf is pre-initialized to -1 by orchestrator; P4 overwrote
|
|
532
532
|
// it for every child of every internal node, so only the root remains at -1).
|
|
533
533
|
|
|
@@ -548,7 +548,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
|
|
548
548
|
rootOut[0] = u32(i);
|
|
549
549
|
}
|
|
550
550
|
}
|
|
551
|
-
`,
|
|
551
|
+
`,zr=`// P5: BFS ping-pong. One dispatch per BFS level (LBVH_MAX_DEPTH total = 32, empty levels are no-ops).
|
|
552
552
|
// FrontierCount comes from a GPU-side counter buffer (no CPU readback). currentDepth
|
|
553
553
|
// is the only per-dispatch param and uses a DEDICATED per-dispatch uniform buffer
|
|
554
554
|
// (one of LBVH_MAX_DEPTH=32, allocated once in orchestrator init).
|
|
@@ -593,7 +593,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
|
|
593
593
|
queueOut[slot] = u32(rightChild);
|
|
594
594
|
}
|
|
595
595
|
}
|
|
596
|
-
`,
|
|
596
|
+
`,Cr=`// P6: COM and AABB reduce.
|
|
597
597
|
// Two entry points, selected by pipeline at dispatch time:
|
|
598
598
|
// leafInit: initialize comBuffer[N-1..2N-2] from leaf positions.
|
|
599
599
|
// levelReduce: for each internal node at depthBuffer[i] == currentLevel, combine
|
|
@@ -650,7 +650,7 @@ fn levelReduce(@builtin(global_invocation_id) gid: vec3<u32>) {
|
|
|
650
650
|
aabbBuffer[2u * i] = vec4<f32>(min(aabbMinL, aabbMinR), 0.0);
|
|
651
651
|
aabbBuffer[2u * i + 1u] = vec4<f32>(max(aabbMaxL, aabbMaxR), 0.0);
|
|
652
652
|
}
|
|
653
|
-
`,
|
|
653
|
+
`,kr=`// P7: per-query-node DFS traversal with Barnes-Hut criterion. One thread per node.
|
|
654
654
|
// Writes accumulated velocity directly to velocities[i].xyz (no atomics needed \u2014
|
|
655
655
|
// each thread owns its own output slot). Self-interaction guard skips the query
|
|
656
656
|
// node's own entry in leaf cells.
|
|
@@ -760,7 +760,7 @@ fn main(
|
|
|
760
760
|
|
|
761
761
|
velocities[queryIdx] = vec4<f32>(velocities[queryIdx].xyz + accum, velocities[queryIdx].w);
|
|
762
762
|
}
|
|
763
|
-
`,
|
|
763
|
+
`,Er=`// P3: one bitonic compare-swap step. Dispatched once per (k, j) in bitonicSortSteps().
|
|
764
764
|
|
|
765
765
|
struct SortParams { n: u32, k: u32, j: u32, _pad: u32 };
|
|
766
766
|
|
|
@@ -789,7 +789,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
|
|
789
789
|
values[partner] = vI;
|
|
790
790
|
}
|
|
791
791
|
}
|
|
792
|
-
`;function
|
|
792
|
+
`;function Fr(e){let t=[];for(let n=2;n<=e;n*=2)for(let i=n/2;i>0;i=i>>1)t.push({k:n,j:i});return t}var Ir=16,Dr=class{constructor(e){this.device=e,this.paramsBuffers=[];let t=e.createShaderModule({label:"lbvh-sort",code:Er});this.pipeline=e.createComputePipeline({label:"lbvh-sort-pipeline",layout:"auto",compute:{module:t,entryPoint:"main"}})}ensureParamsBuffer(e){for(;this.paramsBuffers.length<=e;)this.paramsBuffers.push(this.device.createBuffer({label:`lbvh-sort-params-${this.paramsBuffers.length}`,size:Ir,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}));return this.paramsBuffers[e]}sort(e,t,n,i){let r=Fr(i);for(let o=0;o<r.length;o++){let{k:a,j:s}=r[o],l=this.ensureParamsBuffer(o);this.device.queue.writeBuffer(l,0,new Uint32Array([i,a,s,0]));let u=this.device.createBindGroup({layout:this.pipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:t}},{binding:1,resource:{buffer:n}},{binding:2,resource:{buffer:l}}]}),c=e.beginComputePass({label:`bitonic k=${a} j=${s}`});c.setPipeline(this.pipeline),c.setBindGroup(0,u),c.dispatchWorkgroups(Math.ceil(i/li)),c.end()}}dispose(){for(let e of this.paramsBuffers)e.destroy();this.paramsBuffers=[]}},Ar=class{constructor(e,t){this.ctx=e,this.buffers=t,this.depthsParamsBufs=[],this.reduceParamsBufs=[],this.depthsBG_AtoB=[],this.depthsBG_BtoA=[],this.reduceLevelBGs=[],this.nodeCount=0,this.theta=.9,this.strength=-30,this.distanceMin=1,this.distanceMax=1/0,this.nodeCount=e.nodeCount,this.init()}setTheta(e){this.theta=e}setStrength(e){this.strength=e}setDistanceMin(e){this.distanceMin=e}setDistanceMax(e){this.distanceMax=e}init(){let e=this.ctx.device,t=(o,a=16)=>e.createBuffer({label:o,size:a,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});this.boundsParamsBuf=t("lbvh-bounds-params"),this.mortonParamsBuf=t("lbvh-morton-params"),this.buildParamsBuf=t("lbvh-build-params"),this.findRootParamsBuf=t("lbvh-find-root-params"),this.traverseParamsBuf=t("lbvh-traverse-params",32);for(let o=0;o<ke;o++){let a=t(`lbvh-depths-params-${o}`);e.queue.writeBuffer(a,0,new Uint32Array([this.nodeCount,o,0,0])),this.depthsParamsBufs.push(a)}for(let o=0;o<=ke;o++){let a=t(`lbvh-reduce-params-${o}`);e.queue.writeBuffer(a,0,new Uint32Array([this.nodeCount,o===0?0:o-1,0,0])),this.reduceParamsBufs.push(a)}let n=(o,a)=>e.createShaderModule({label:o,code:a}),i=(o,a,s)=>e.createComputePipeline({label:o,layout:"auto",compute:{module:a,entryPoint:s}});this.boundsPipeline=i("lbvh-bounds",n("lbvh-bounds",qt),"main"),this.mortonPipeline=i("lbvh-morton",n("lbvh-morton",Tr),"main"),this.buildPipeline=i("lbvh-build",n("lbvh-build",Pr),"main"),this.findRootPipeline=i("lbvh-find-root",n("lbvh-find-root",Br),"main"),this.depthsPipeline=i("lbvh-depths",n("lbvh-depths",zr),"main");let r=n("lbvh-reduce",Cr);this.reduceLeafInitPipeline=i("lbvh-reduce-leafInit",r,"leafInit"),this.reduceLevelPipeline=i("lbvh-reduce-level",r,"levelReduce"),this.traversePipeline=i("lbvh-traverse",n("lbvh-traverse",kr),"main"),this.sortPass=new Dr(e),this.bindAll()}bindAll(){let e=this.ctx.device,t=this.buffers,n=this.ctx;this.boundsBG=e.createBindGroup({layout:this.boundsPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:n.positions}},{binding:1,resource:{buffer:t.bounds}},{binding:2,resource:{buffer:this.boundsParamsBuf}}]}),this.mortonBG=e.createBindGroup({layout:this.mortonPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:n.positions}},{binding:1,resource:{buffer:t.bounds}},{binding:2,resource:{buffer:t.morton}},{binding:3,resource:{buffer:t.sortedIndices}},{binding:4,resource:{buffer:this.mortonParamsBuf}}]}),this.buildBG=e.createBindGroup({layout:this.buildPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:t.morton}},{binding:1,resource:{buffer:t.internal}},{binding:2,resource:{buffer:t.parent}},{binding:3,resource:{buffer:t.aabb}},{binding:4,resource:{buffer:t.sortedIndices}},{binding:5,resource:{buffer:n.positions}},{binding:6,resource:{buffer:this.buildParamsBuf}}]}),this.findRootBG=e.createBindGroup({layout:this.findRootPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:t.parent}},{binding:1,resource:{buffer:t.root}},{binding:2,resource:{buffer:this.findRootParamsBuf}}]});for(let i=0;i<ke;i++)this.depthsBG_AtoB.push(e.createBindGroup({layout:this.depthsPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:t.internal}},{binding:1,resource:{buffer:t.depthQueueA}},{binding:2,resource:{buffer:t.depthQueueB}},{binding:3,resource:{buffer:t.frontierCounts}},{binding:4,resource:{buffer:t.depth}},{binding:5,resource:{buffer:this.depthsParamsBufs[i]}}]})),this.depthsBG_BtoA.push(e.createBindGroup({layout:this.depthsPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:t.internal}},{binding:1,resource:{buffer:t.depthQueueB}},{binding:2,resource:{buffer:t.depthQueueA}},{binding:3,resource:{buffer:t.frontierCounts}},{binding:4,resource:{buffer:t.depth}},{binding:5,resource:{buffer:this.depthsParamsBufs[i]}}]}));this.reduceLeafInitBG=e.createBindGroup({layout:this.reduceLeafInitPipeline.getBindGroupLayout(0),entries:[{binding:1,resource:{buffer:t.com}},{binding:4,resource:{buffer:t.sortedIndices}},{binding:5,resource:{buffer:n.positions}},{binding:6,resource:{buffer:this.reduceParamsBufs[0]}}]});for(let i=0;i<ke;i++)this.reduceLevelBGs.push(e.createBindGroup({layout:this.reduceLevelPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:t.internal}},{binding:1,resource:{buffer:t.com}},{binding:2,resource:{buffer:t.aabb}},{binding:3,resource:{buffer:t.depth}},{binding:6,resource:{buffer:this.reduceParamsBufs[i+1]}}]}));this.traverseBG=e.createBindGroup({layout:this.traversePipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:n.positions}},{binding:1,resource:{buffer:n.velocities}},{binding:2,resource:{buffer:t.internal}},{binding:3,resource:{buffer:t.com}},{binding:4,resource:{buffer:t.aabb}},{binding:5,resource:{buffer:t.sortedIndices}},{binding:6,resource:{buffer:t.root}},{binding:7,resource:{buffer:this.traverseParamsBuf}}]}),e.queue.writeBuffer(this.boundsParamsBuf,0,new Uint32Array([this.nodeCount,0,0,0])),e.queue.writeBuffer(this.mortonParamsBuf,0,new Uint32Array([this.nodeCount,0,0,0])),e.queue.writeBuffer(this.buildParamsBuf,0,new Uint32Array([this.nodeCount,0,0,0])),e.queue.writeBuffer(this.findRootParamsBuf,0,new Uint32Array([this.nodeCount,0,0,0]))}apply(e,t){let n=this.ctx.device,i=this.nodeCount;if(i<2)return;let r=li,o=Math.ceil(i/r),a=Math.ceil(Math.max(1,i-1)/r),s=this.buffers.paddedN,l=new Int32Array([2147483647,-2147483648,2147483647,-2147483648,2147483647,-2147483648]);if(n.queue.writeBuffer(this.buffers.bounds,0,l),s>i){let p=new Uint32Array(s-i).fill(4294967295),h=new Uint32Array(s-i).fill(4294967295);n.queue.writeBuffer(this.buffers.morton,i*4,p),n.queue.writeBuffer(this.buffers.sortedIndices,i*4,h)}let u=new Int32Array(Math.max(1,i-1)).fill(-1);n.queue.writeBuffer(this.buffers.parent,0,u);let c=new Uint32Array(ke+1);c[0]=1,n.queue.writeBuffer(this.buffers.frontierCounts,0,c),n.queue.writeBuffer(this.buffers.root,0,new Uint32Array([0]));let d=Number.isFinite(this.distanceMax)?this.distanceMax*this.distanceMax:34e37,f=new ArrayBuffer(32);new Uint32Array(f,0,1)[0]=i,new Float32Array(f,4,5).set([this.strength,e,this.theta*this.theta,this.distanceMin*this.distanceMin,d]),n.queue.writeBuffer(this.traverseParamsBuf,0,f),this.runSimple(t,this.boundsPipeline,this.boundsBG,o,"p1-bounds"),this.runSimple(t,this.mortonPipeline,this.mortonBG,o,"p2-morton"),this.sortPass.sort(t,this.buffers.morton,this.buffers.sortedIndices,s),this.runSimple(t,this.buildPipeline,this.buildBG,Math.max(a,o),"p4-build"),this.runSimple(t,this.findRootPipeline,this.findRootBG,a,"p4b-find-root"),t.copyBufferToBuffer(this.buffers.root,0,this.buffers.depthQueueA,0,4);for(let p=0;p<ke;p++){let g=p%2===0?this.depthsBG_AtoB[p]:this.depthsBG_BtoA[p],y=t.beginComputePass({label:`p5-depths-${p}`});y.setPipeline(this.depthsPipeline),y.setBindGroup(0,g),y.dispatchWorkgroups(a),y.end()}this.runSimple(t,this.reduceLeafInitPipeline,this.reduceLeafInitBG,o,"p6-leafInit");for(let p=ke-1;p>=0;p--)this.runSimple(t,this.reduceLevelPipeline,this.reduceLevelBGs[p],a,`p6-level-${p}`);this.runSimple(t,this.traversePipeline,this.traverseBG,o,"p7-traverse")}runSimple(e,t,n,i,r){let o=e.beginComputePass({label:r});o.setPipeline(t),o.setBindGroup(0,n),o.dispatchWorkgroups(i),o.end()}dispose(){this.sortPass.dispose();for(let e of[this.boundsParamsBuf,this.mortonParamsBuf,this.buildParamsBuf,this.findRootParamsBuf,this.traverseParamsBuf,...this.depthsParamsBufs,...this.reduceParamsBufs])e.destroy()}};function ui(){let e=-30,t=Mr,n=1,i=1/0,r=null,o=null,a={initialize(s,l,u){},initGPU(s){(o||r)&&(o?.dispose(),r?.dispose(),o=null,r=null),r=_r(s.device,s.nodeCount,ke);let l={device:s.device,nodeCount:s.nodeCount,positions:s.positionBuffer,velocities:s.velocityBuffer};o=new Ar(l,r),o.setStrength(e),o.setTheta(t),o.setDistanceMin(n),o.setDistanceMax(i)},apply(s,l){o?.apply(s,l)},dispose(){o?.dispose(),r?.dispose(),o=null,r=null},strength(s){return arguments.length===0?e:(e=+s,o?.setStrength(e),a)},theta(s){return arguments.length===0?t:(t=+s,o?.setTheta(t),a)},distanceMin(s){return arguments.length===0?n:(n=+s,o?.setDistanceMin(n),a)},distanceMax(s){return arguments.length===0?i:(i=+s,o?.setDistanceMax(i),a)}};return a}var ci=`// Clear quadtree cell buffer to zero. One thread per cell slot (4 i32s/cell).
|
|
793
793
|
//
|
|
794
794
|
// Layout:
|
|
795
795
|
// group(0)
|
|
@@ -816,7 +816,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
|
|
816
816
|
if (i >= params.cellSlotCount) { return; }
|
|
817
817
|
atomicStore(&cells[i], 0);
|
|
818
818
|
}
|
|
819
|
-
`,
|
|
819
|
+
`,Rr=`// quad-bin: per-node atomic write of (x, y, mass) into the LEAF cell at MAX level
|
|
820
820
|
// of a fixed-depth 2D quadtree. Reads bounds directly from boundsBuffer (ordered-int
|
|
821
821
|
// encoding produced by lbvh-bounds.wgsl).
|
|
822
822
|
//
|
|
@@ -883,7 +883,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
|
|
883
883
|
atomicAdd(&cells[baseSlot + 1u], yFixed);
|
|
884
884
|
atomicAdd(&cells[baseSlot + 3u], 1i);
|
|
885
885
|
}
|
|
886
|
-
`,
|
|
886
|
+
`,Ur=`// quad-accumulate: bottom-up COM aggregation.
|
|
887
887
|
//
|
|
888
888
|
// Dispatched once per level k (from MAX_LEVEL-1 down to 0). For each cell at
|
|
889
889
|
// level k (4^k cells), read its 4 children at level k+1 (Morton-contiguous:
|
|
@@ -925,7 +925,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
|
|
925
925
|
atomicStore(&cells[parentBase + 1u], sy);
|
|
926
926
|
atomicStore(&cells[parentBase + 3u], sm);
|
|
927
927
|
}
|
|
928
|
-
`,
|
|
928
|
+
`,Lr=`// quad-traverse: per-query-node Barnes-Hut DFS over a fixed-depth 2D quadtree.
|
|
929
929
|
// Matches d3-force-3d's apply() (manyBody.js).
|
|
930
930
|
//
|
|
931
931
|
// Reads bounds directly from boundsBuffer to compute cellWidth at each level.
|
|
@@ -1104,7 +1104,7 @@ fn main(
|
|
|
1104
1104
|
velocities[queryIdx].w,
|
|
1105
1105
|
);
|
|
1106
1106
|
}
|
|
1107
|
-
`,
|
|
1107
|
+
`,Gr=8,Dt=64,jn=64,At=4;function Nr(e){return Math.floor((Math.pow(4,e+1)-1)/3)}function pt(e){return Math.floor((Math.pow(4,e)-1)/3)}var qr=class{constructor(e,t=Gr){this.accumParamsBufs=[],this.accumBGs=[],this.config={strength:-30,theta:.9,distanceMin:1,distanceMax:1/0},this.device=e.device,this.nodeCount=e.nodeCount,this.maxLevel=t,this.totalCells=Nr(t);let n=this.device,i=GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC,r=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST;this.cellsBuffer=n.createBuffer({label:"quad-cells",size:this.totalCells*At*4,usage:i}),this.boundsBuffer=n.createBuffer({label:"quad-bounds",size:32,usage:i}),this.levelOffsetsBuffer=n.createBuffer({label:"quad-level-offsets",size:(t+1)*4,usage:i});let o=new Uint32Array(t+1);for(let d=0;d<=t;d++)o[d]=pt(d);n.queue.writeBuffer(this.levelOffsetsBuffer,0,o),this.boundsParamsBuf=n.createBuffer({label:"quad-bounds-params",size:16,usage:r}),this.clearParamsBuf=n.createBuffer({label:"quad-clear-params",size:16,usage:r}),this.binParamsBuf=n.createBuffer({label:"quad-bin-params",size:16,usage:r}),this.traverseParamsBuf=n.createBuffer({label:"quad-traverse-params",size:48,usage:r});for(let d=0;d<t;d++){let f=n.createBuffer({label:`quad-accum-params-L${d}`,size:16,usage:r}),p=new Uint32Array([pt(d),pt(d+1),Math.pow(4,d),0]);n.queue.writeBuffer(f,0,p),this.accumParamsBufs.push(f)}let a=this.totalCells*At,l=Math.ceil(a/Dt)*Dt;n.queue.writeBuffer(this.clearParamsBuf,0,new Uint32Array([a,l,0,0]));let u=(d,f)=>n.createShaderModule({label:d,code:f}),c=(d,f,p="main")=>n.createComputePipeline({label:d,layout:"auto",compute:{module:f,entryPoint:p}});this.boundsPipeline=c("quad-bounds-pipe",u("quad-bounds",qt)),this.clearPipeline=c("quad-clear-pipe",u("quad-clear",ci)),this.binPipeline=c("quad-bin-pipe",u("quad-bin",Rr)),this.accumPipeline=c("quad-accum-pipe",u("quad-accum",Ur)),this.traversePipeline=c("quad-traverse-pipe",u("quad-traverse",Lr)),this.bindAll(e)}bindAll(e){let t=this.device;this.boundsBG=t.createBindGroup({layout:this.boundsPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:e.positionBuffer}},{binding:1,resource:{buffer:this.boundsBuffer}},{binding:2,resource:{buffer:this.boundsParamsBuf}}]}),this.clearBG=t.createBindGroup({layout:this.clearPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:this.cellsBuffer}},{binding:1,resource:{buffer:this.clearParamsBuf}}]}),this.binBG=t.createBindGroup({layout:this.binPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:e.positionBuffer}},{binding:1,resource:{buffer:this.cellsBuffer}},{binding:2,resource:{buffer:this.boundsBuffer}},{binding:3,resource:{buffer:this.binParamsBuf}}]});for(let i=0;i<this.maxLevel;i++)this.accumBGs.push(t.createBindGroup({layout:this.accumPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:this.cellsBuffer}},{binding:1,resource:{buffer:this.accumParamsBufs[i]}}]}));this.traverseBG=t.createBindGroup({layout:this.traversePipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:e.positionBuffer}},{binding:1,resource:{buffer:e.velocityBuffer}},{binding:2,resource:{buffer:this.cellsBuffer}},{binding:3,resource:{buffer:this.levelOffsetsBuffer}},{binding:4,resource:{buffer:this.boundsBuffer}},{binding:5,resource:{buffer:this.traverseParamsBuf}}]});let n=new ArrayBuffer(16);new Uint32Array(n,0,3).set([this.nodeCount,this.maxLevel,pt(this.maxLevel)]),new Float32Array(n,12,1)[0]=jn,t.queue.writeBuffer(this.binParamsBuf,0,n),t.queue.writeBuffer(this.boundsParamsBuf,0,new Uint32Array([this.nodeCount,0,0,0]))}setConfig(e){Object.assign(this.config,e)}apply(e,t){let n=this.device,i=this.nodeCount,r=Dt,o=new Int32Array([2147483647,-2147483648,2147483647,-2147483648,2147483647,-2147483648]);n.queue.writeBuffer(this.boundsBuffer,0,o),this.run(t,this.boundsPipeline,this.boundsBG,Math.ceil(i/r),"quad-p1-bounds"),this.run(t,this.clearPipeline,this.clearBG,Math.ceil(this.totalCells*At/r),"quad-p2-clear"),this.run(t,this.binPipeline,this.binBG,Math.ceil(i/r),"quad-p3-bin");for(let u=this.maxLevel-1;u>=0;u--)this.run(t,this.accumPipeline,this.accumBGs[u],Math.ceil(Math.pow(4,u)/r),`quad-p4-accum-L${u}`);let a=new ArrayBuffer(48),s=new Uint32Array(a),l=new Float32Array(a);s[0]=i,s[1]=this.maxLevel,l[4]=this.config.strength,l[5]=e,l[6]=this.config.theta*this.config.theta,l[7]=this.config.distanceMin*this.config.distanceMin,l[8]=this.config.distanceMax===1/0?1e30:this.config.distanceMax*this.config.distanceMax,l[9]=jn,n.queue.writeBuffer(this.traverseParamsBuf,0,a),this.run(t,this.traversePipeline,this.traverseBG,Math.ceil(i/r),"quad-p5-traverse")}run(e,t,n,i,r){let o=e.beginComputePass({label:r});o.setPipeline(t),o.setBindGroup(0,n),o.dispatchWorkgroups(i),o.end()}dispose(){this.cellsBuffer.destroy(),this.boundsBuffer.destroy(),this.levelOffsetsBuffer.destroy(),this.boundsParamsBuf.destroy(),this.clearParamsBuf.destroy(),this.binParamsBuf.destroy(),this.traverseParamsBuf.destroy(),this.accumParamsBufs.forEach(e=>e.destroy())}};function Or(){let e=-30,t=1,n=1/0,i=.9,r=null,o={initialize(a,s,l){},initGPU(a){r?.dispose(),r=new qr(a),r.setConfig({strength:e,theta:i,distanceMin:t,distanceMax:n})},apply(a,s){r?.apply(a,s)},dispose(){r?.dispose(),r=null},strength(a){return arguments.length===0?e:(e=+a,r?.setConfig({strength:e}),o)},distanceMin(a){return arguments.length===0?t:(t=+a,r?.setConfig({distanceMin:t}),o)},distanceMax(a){return arguments.length===0?n:(n=+a,r?.setConfig({distanceMax:n}),o)},theta(a){return arguments.length===0?i:(i=+a,r?.setConfig({theta:i}),o)}};return o}var Hr=`// oct-bin: 3D version of quad-bin. Per-node atomic write of (x, y, z, mass)
|
|
1108
1108
|
// into the LEAF cell at MAX level of a fixed-depth 3D octree.
|
|
1109
1109
|
// Cell address: leafOffset + morton3D(cellX, cellY, cellZ).
|
|
1110
1110
|
|
|
@@ -1174,7 +1174,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
|
|
1174
1174
|
atomicAdd(&cells[baseSlot + 2u], zFixed);
|
|
1175
1175
|
atomicAdd(&cells[baseSlot + 3u], 1i);
|
|
1176
1176
|
}
|
|
1177
|
-
`,
|
|
1177
|
+
`,Xr=`// oct-accumulate: bottom-up COM aggregation for 3D octree.
|
|
1178
1178
|
//
|
|
1179
1179
|
// Mirrors d3-force-3d's manyBody accumulate:
|
|
1180
1180
|
// strength += child.value;
|
|
@@ -1222,7 +1222,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
|
|
1222
1222
|
atomicStore(&cells[parentBase + 2u], sz);
|
|
1223
1223
|
atomicStore(&cells[parentBase + 3u], sm);
|
|
1224
1224
|
}
|
|
1225
|
-
`,
|
|
1225
|
+
`,Yr=`// oct-traverse: per-query-node Barnes-Hut DFS over fixed-depth 3D octree.
|
|
1226
1226
|
// Mirrors quad-traverse.wgsl with 8 children per cell + z axis.
|
|
1227
1227
|
//
|
|
1228
1228
|
// BH criterion uses MAX axis extent of bounds (cell width = boundsMax / 2^level).
|
|
@@ -1423,7 +1423,7 @@ fn main(
|
|
|
1423
1423
|
velocities[queryIdx].w,
|
|
1424
1424
|
);
|
|
1425
1425
|
}
|
|
1426
|
-
`,qr=7,Ft=64,Yn=64,uo=Math.sqrt(.5);function Or(e){return Math.floor((Math.pow(8,e+1)-1)/7)}function ct(e){return Math.floor((Math.pow(8,e)-1)/7)}var It=4,Dt=65535,Hr=class{constructor(e,t=qr){this.accumParamsBufs=[],this.accumBGs=[],this.config={strength:-30,theta:.9,distanceMin:1,distanceMax:1/0},this.device=e.device,this.nodeCount=e.nodeCount,this.maxLevel=t,this.totalCells=Or(t);let n=this.device,i=GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC,r=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST;this.cellsBuffer=n.createBuffer({label:"oct-cells",size:this.totalCells*It*4,usage:i}),this.boundsBuffer=n.createBuffer({label:"oct-bounds",size:32,usage:i}),this.levelOffsetsBuffer=n.createBuffer({label:"oct-level-offsets",size:(t+1)*4,usage:i});let o=new Uint32Array(t+1);for(let d=0;d<=t;d++)o[d]=ct(d);n.queue.writeBuffer(this.levelOffsetsBuffer,0,o),this.boundsParamsBuf=n.createBuffer({label:"oct-bounds-params",size:16,usage:r}),this.clearParamsBuf=n.createBuffer({label:"oct-clear-params",size:16,usage:r}),this.binParamsBuf=n.createBuffer({label:"oct-bin-params",size:16,usage:r}),this.traverseParamsBuf=n.createBuffer({label:"oct-traverse-params",size:48,usage:r});for(let d=0;d<t;d++){let p=n.createBuffer({label:`oct-accum-params-L${d}`,size:16,usage:r}),m=new ArrayBuffer(16),g=new Uint32Array(m);g[0]=ct(d),g[1]=ct(d+1),g[2]=Math.pow(8,d),n.queue.writeBuffer(p,0,m),this.accumParamsBufs.push(p)}let a=this.totalCells*It,s=Math.ceil(a/Ft),u=Math.min(s,Dt)*Ft;n.queue.writeBuffer(this.clearParamsBuf,0,new Uint32Array([a,u,0,0]));let c=(d,p)=>n.createShaderModule({label:d,code:p}),f=(d,p,m="main")=>n.createComputePipeline({label:d,layout:"auto",compute:{module:p,entryPoint:m}});this.boundsPipeline=f("oct-bounds-pipe",c("oct-bounds",Ut)),this.clearPipeline=f("oct-clear-pipe",c("oct-clear",si)),this.binPipeline=f("oct-bin-pipe",c("oct-bin",Lr)),this.accumPipeline=f("oct-accum-pipe",c("oct-accum",Gr)),this.traversePipeline=f("oct-traverse-pipe",c("oct-traverse",Nr)),this.bindAll(e)}bindAll(e){let t=this.device;this.boundsBG=t.createBindGroup({layout:this.boundsPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:e.positionBuffer}},{binding:1,resource:{buffer:this.boundsBuffer}},{binding:2,resource:{buffer:this.boundsParamsBuf}}]}),this.clearBG=t.createBindGroup({layout:this.clearPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:this.cellsBuffer}},{binding:1,resource:{buffer:this.clearParamsBuf}}]}),this.binBG=t.createBindGroup({layout:this.binPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:e.positionBuffer}},{binding:1,resource:{buffer:this.cellsBuffer}},{binding:2,resource:{buffer:this.boundsBuffer}},{binding:3,resource:{buffer:this.binParamsBuf}}]});for(let i=0;i<this.maxLevel;i++)this.accumBGs.push(t.createBindGroup({layout:this.accumPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:this.cellsBuffer}},{binding:1,resource:{buffer:this.accumParamsBufs[i]}}]}));this.traverseBG=t.createBindGroup({layout:this.traversePipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:e.positionBuffer}},{binding:1,resource:{buffer:e.velocityBuffer}},{binding:2,resource:{buffer:this.cellsBuffer}},{binding:3,resource:{buffer:this.levelOffsetsBuffer}},{binding:4,resource:{buffer:this.boundsBuffer}},{binding:5,resource:{buffer:this.traverseParamsBuf}}]}),t.queue.writeBuffer(this.boundsParamsBuf,0,new Uint32Array([this.nodeCount,0,0,0]));let n=new ArrayBuffer(16);new Uint32Array(n,0,3).set([this.nodeCount,this.maxLevel,ct(this.maxLevel)]),new Float32Array(n,12,1)[0]=Yn,t.queue.writeBuffer(this.binParamsBuf,0,n)}setConfig(e){Object.assign(this.config,e)}apply(e,t){let n=this.device,i=this.nodeCount,r=Ft,o=new Int32Array([2147483647,-2147483648,2147483647,-2147483648,2147483647,-2147483648]);n.queue.writeBuffer(this.boundsBuffer,0,o),this.run(t,this.boundsPipeline,this.boundsBG,Math.ceil(i/r),"oct-p1-bounds");let a=Math.ceil(this.totalCells*It/r),s=Math.min(a,Dt),l=Math.ceil(a/Dt);this.run2D(t,this.clearPipeline,this.clearBG,s,l,"oct-p2-clear"),this.run(t,this.binPipeline,this.binBG,Math.ceil(i/r),"oct-p3-bin");for(let d=this.maxLevel-1;d>=0;d--)this.run(t,this.accumPipeline,this.accumBGs[d],Math.ceil(Math.pow(8,d)/r),`oct-p4-accum-L${d}`);let u=new ArrayBuffer(48),c=new Uint32Array(u),f=new Float32Array(u);c[0]=i,c[1]=this.maxLevel,f[4]=this.config.strength,f[5]=e,f[6]=this.config.theta*this.config.theta,f[7]=this.config.distanceMin*this.config.distanceMin,f[8]=this.config.distanceMax===1/0?1e30:this.config.distanceMax*this.config.distanceMax,f[9]=Yn,n.queue.writeBuffer(this.traverseParamsBuf,0,u),this.run(t,this.traversePipeline,this.traverseBG,Math.ceil(i/r),"oct-p5-traverse")}run(e,t,n,i,r){let o=e.beginComputePass({label:r});o.setPipeline(t),o.setBindGroup(0,n),o.dispatchWorkgroups(i),o.end()}run2D(e,t,n,i,r,o){let a=e.beginComputePass({label:o});a.setPipeline(t),a.setBindGroup(0,n),a.dispatchWorkgroups(i,r,1),a.end()}dispose(){this.cellsBuffer.destroy(),this.boundsBuffer.destroy(),this.levelOffsetsBuffer.destroy(),this.boundsParamsBuf.destroy(),this.clearParamsBuf.destroy(),this.binParamsBuf.destroy(),this.traverseParamsBuf.destroy(),this.accumParamsBufs.forEach(e=>e.destroy())}};function Xr(){let e=-30,t=1,n=1/0,i=.9,r=null,o={initialize(a,s,l){},initGPU(a){r?.dispose(),r=new Hr(a),r.setConfig({strength:e,theta:i,distanceMin:t,distanceMax:n})},apply(a,s){r?.apply(a,s)},dispose(){r?.dispose(),r=null},strength(a){return arguments.length===0?e:(e=+a,r?.setConfig({strength:e}),o)},distanceMin(a){return arguments.length===0?t:(t=+a,r?.setConfig({distanceMin:t}),o)},distanceMax(a){return arguments.length===0?n:(n=+a,r?.setConfig({distanceMax:n}),o)},theta(a){return arguments.length===0?i:(i=+a,r?.setConfig({theta:i}),o)}};return o}var Yr={charge:-.01,gravity:.1,linkStrength:1,linkDistance:.5,collision:.15,heightCompress:1,alpha:.6,alphaDecay:.1,velocityDecay:.3,dimensions:3,gravityX:1,gravityY:1,gravityZ:1,octreeTheta:.9},je=240;function $r(e,t,n){let i=globalThis,r=i.__webgpuPathATiming;r||(r={tick:new Float32Array(je),read:new Float32Array(je),sync:new Float32Array(je),i:0,filled:0,reset(){this.i=0,this.filled=0},summary(){let o=this.filled;if(o===0)return null;let a=s=>{let l=0,u=1/0,c=-1/0;for(let f=0;f<o;f++){let d=s[f];l+=d,d<u&&(u=d),d>c&&(c=d)}return{mean:+(l/o).toFixed(3),min:+u.toFixed(3),max:+c.toFixed(3),n:o}};return{skipFlag:!!globalThis.__webgpuPathASkip,tickMs:a(this.tick),readMs:a(this.read),syncMs:a(this.sync),totalMs:{mean:+(this.tick.reduce((s,l)=>s+l,0)/o+this.read.reduce((s,l)=>s+l,0)/o+this.sync.reduce((s,l)=>s+l,0)/o).toFixed(3)}}}},i.__webgpuPathATiming=r),r.tick[r.i]=e,r.read[r.i]=t,r.sync[r.i]=n,r.i=(r.i+1)%je,r.filled<je&&r.filled++}var ft=class{constructor(e,t,n={}){if(this.sharedArray=new Float32Array(0),this.nodeIdToIndex=new Map,this.isFinish=!1,this._enable=!0,this.getOptions=()=>null,this._readbackTimingSink=null,this.simulation=null,this.simNodes=[],this._loopRunning=!1,this._currentSpaceSize=10,this.forceCharge=null,this.forceLinkInstance=null,this.forceXInstance=null,this.forceYInstance=null,this.forceZInstance=null,this.forceCenterInstance=null,this._linkDegree=new Int32Array(0),this._linkStrengthFn=i=>{let r=i.source,o=i.target,a=Math.min(this._linkDegree[r]??1,this._linkDegree[o]??1);return this.params.linkStrength*(a>0?1/a:1)},this._readbackTickCounter=0,!Pe())throw new Error("[WebGPUForceLayoutController] navigator.gpu unavailable in this environment. Use the WebGL-backed GPUForceLayoutController instead.");this.params={...Yr},this.options=n,this.graph=e??{layoutNodes:[],layoutEdges:[],renderNeedsUpdate:!0}}setReadbackTimingSink(e){return this._readbackTimingSink=e,this}config(e){this.getOptions=e;let t=e();return t&&this.applyConfig(t),this}configure(e){return this.config(e)}applyConfig(e){e.charge!==void 0&&(this.params.charge=e.charge),e.gravity!==void 0&&(this.params.gravity=e.gravity),e.linkStrength!==void 0&&(this.params.linkStrength=e.linkStrength),e.linkDistance!==void 0&&(this.params.linkDistance=e.linkDistance),e.collision!==void 0&&(this.params.collision=e.collision),e.heightCompress!==void 0&&(this.params.heightCompress=e.heightCompress),e.alpha!==void 0&&(this.params.alpha=e.alpha),e.alphaDecay!==void 0&&(this.params.alphaDecay=e.alphaDecay),e.velocityDecay!==void 0&&(this.params.velocityDecay=e.velocityDecay),e.friction!==void 0&&(this.params.velocityDecay=e.friction),e.dimensions!==void 0&&(this.params.dimensions=e.dimensions),e.gravityX!==void 0&&(this.params.gravityX=e.gravityX),e.gravityY!==void 0&&(this.params.gravityY=e.gravityY),e.gravityZ!==void 0&&(this.params.gravityZ=e.gravityZ),e.octreeTheta!==void 0&&(this.params.octreeTheta=e.octreeTheta)}startLayout(e=0,t=0,n=!1){let i=this.params.dimensions,r=this.getOptions();r&&this.applyConfig(r),this.params.dimensions=i,this.disposeSimulation(),this.buildSimulation(n),this.simulation&&(this._enable=!0,this.isFinish=!1,this.graph.renderNeedsUpdate=!0,this._loopRunning=!1,this.runLoop())}restartLayout(){if(!this._enable)return;let e=this.getOptions();if(e){let i=this.params.dimensions;this.applyConfig(e),this.params.dimensions=i}this.applyForceParams();let t=this.graph.layoutNodes.length,n=this.simNodes.length;this.simulation&&t===n?(this.simulation.alpha(this.params.alpha),this.isFinish=!1,this.graph.renderNeedsUpdate=!0,this.runLoop()):this.startLayout()}stopLayout(){this._enable=!1,this.isFinish=!0,this.graph.renderNeedsUpdate=!1}destroy(){this.stopLayout(),this.disposeSimulation()}disposeSimulation(){this.simulation?.dispose(),this.simulation=null,this.forceCharge=null,this.forceLinkInstance=null,this.forceXInstance=null,this.forceYInstance=null,this.forceZInstance=null,this.forceCenterInstance=null}buildSimulation(e=!1){let t=this.graph.layoutNodes,n=this.graph.layoutEdges,i=t.length;if(i===0)return;let r=this.params.dimensions,o=t.some(g=>Math.abs(g.position.z)>1e-6),a=r>2&&!o&&!e,s=Math.cbrt(t.length)*2,u=Math.min(10,Math.pow(2,29)/(Math.pow(i,1.5)*64)),c=r===2&&!a&&!e,f=Math.PI*(3-Math.sqrt(5));this.simNodes=t.map((g,y)=>{let w={id:g.id,index:y};if(g.pinned)w.fx=g.position.x,w.fy=g.position.y,w.fz=g.position.z,w.x=g.position.x,w.y=g.position.y,w.z=g.position.z;else if(a){let M=Math.random(),h=Math.random(),v=Math.random(),b=2*Math.PI*M,x=Math.acos(2*h-1),C=Math.cbrt(v)*s;w.x=C*Math.sin(x)*Math.cos(b),w.y=C*Math.sin(x)*Math.sin(b),w.z=C*Math.cos(x)}else if(c){let M=u*Math.sqrt(.5+y),h=y*f;w.x=M*Math.cos(h),w.y=M*Math.sin(h),w.z=0}else e&&(w.x=g.position.x,w.y=g.position.y,w.z=r<=2?0:g.position.z);return w}),this.nodeIdToIndex.clear();for(let g=0;g<i;g++)this.nodeIdToIndex.set(this.simNodes[g].id,g*3);this.sharedArray=new Float32Array(i*3),this._currentSpaceSize=Math.max(10,2*(this.params.dimensions===2?10*Math.sqrt(i):10*Math.cbrt(i)));let d=Jn(this.simNodes,this.params.dimensions,{device:this.options.device});d.alpha(this.params.alpha).alphaDecay(this.params.alphaDecay).velocityDecay(this.params.velocityDecay).alphaTarget(0).maxVel(this.staticMaxVel(this.simNodes.length));let{forcexy:p,forcez:m}=this.calculateAxisForces();if(this.forceXInstance=ti(0).strength(p*this.params.gravityX),this.forceYInstance=ni(0).strength(p*this.params.gravityY),d.force("x",this.forceXInstance),d.force("y",this.forceYInstance),this.params.dimensions>2&&(this.forceZInstance=ii(0).strength(m*this.params.gravityZ),d.force("z",this.forceZInstance)),this.forceCharge=this.makeChargeForce(i),d.force("charge",this.forceCharge),n.length){let g=n.map(w=>{let M=this.nodeIdToIndex.get(w.sourceId),h=this.nodeIdToIndex.get(w.targetId);return M===void 0||h===void 0?null:{id:w.id,source:M/3,target:h/3}}).filter(w=>w!==null),y=g.length;this._linkDegree=new Int32Array(i);for(let w=0;w<y;w++)this._linkDegree[g[w].source]++,this._linkDegree[g[w].target]++;this.forceLinkInstance=ri(g).strength(this._linkStrengthFn).distance(this.params.linkDistance),d.force("link",this.forceLinkInstance)}this.forceCenterInstance=ei(0,0,0).strength(1),d.force("center",this.forceCenterInstance),this.simulation=d}makeChargeForce(e){if(this.params.dimensions===2){let n=Ur();return n.theta?.(this.params.octreeTheta),n.strength(this.params.charge),n}if(e>=1e4){let n=oi();return n.theta(this.params.octreeTheta),n.strength(this.params.charge),n}let t=Xr();return t.theta?.(this.params.octreeTheta),t.strength(this.params.charge),t}calculateAxisForces(){let e,t;if(this.params.dimensions===2)e=this.params.gravity*1.5,t=0;else{let n=this.params.heightCompress;t=Math.min(10,this.params.gravity*Math.sqrt(n)),e=this.params.gravity/Math.sqrt(n)}return{forcexy:e,forcez:t}}applyForceParams(){if(!this.simulation)return;this.simulation.alphaDecay(this.params.alphaDecay),this.simulation.velocityDecay(this.params.velocityDecay);let{forcexy:e,forcez:t}=this.calculateAxisForces();this.forceXInstance?.strength(e*this.params.gravityX),this.forceYInstance?.strength(e*this.params.gravityY),this.forceZInstance?.strength(t*this.params.gravityZ),this.forceCharge?.strength(this.params.charge),this.forceLinkInstance&&(this.forceLinkInstance.strength(this._linkStrengthFn),this.forceLinkInstance.distance(this.params.linkDistance))}afterTick(e){let t=this.options.onTick;if(t)try{t({positionBuffer:e.getPositionBuffer(),nodeCount:this.simNodes.length})}catch{}}async runLoop(){if(!this._loopRunning){this._loopRunning=!0;try{let e=this.simulation;for(e&&!e.isReady()&&await new Promise(t=>e.on("ready",()=>t()));this._enable&&this.simulation&&(await this.waitForFrame(),!!this._enable);){let t=this.simulation;if(!t)break;let n=performance.now();t.tick(1),this.afterTick(t);let i=performance.now(),r=Math.max(1,Math.floor(globalThis.__webgpuReadbackInterval??1));this._readbackTickCounter++;let o=this._readbackTickCounter>=r,a=t.alpha()<t.alphaMin(),s=o||a,l=i,u=i;if(s){this._readbackTickCounter=0;try{await t.readPositions()}catch(c){console.warn("[WebGPUForceLayoutController] readPositions threw, skipping:",c);continue}if(t!==this.simulation||!this._enable)break;l=performance.now(),this.syncPositionsToSharedArray(),u=performance.now(),this.graph.renderNeedsUpdate=!0}if($r(i-n,l-i,u-l),s&&this._readbackTimingSink)try{this._readbackTimingSink(u-i)}catch{}if(a){this.isFinish=!0,this.graph.renderNeedsUpdate=!1;break}}}finally{this._loopRunning=!1}}}waitForFrame(){return new Promise(e=>requestAnimationFrame(()=>e()))}syncPositionsToSharedArray(){let e=this.sharedArray,t=this.graph.layoutNodes,n=this.simNodes,i=Math.min(e.length/3,n.length,t.length);if(globalThis.__webgpuPathASkip===!0){let o=0;for(let a=0;a<e.length;a++){let s=e[a],l=s<0?-s:s;l>o&&(o=l)}this._currentSpaceSize=Math.max(10,2*o);return}let r=0;for(let o=0;o<i;o++){let a=n[o],s=a.x??0,l=a.y??0,u=a.z??0;e[o*3]=s,e[o*3+1]=l,e[o*3+2]=u;let c=t[o];c?.position&&(c.position.x=s,c.position.y=l,c.position.z=u);let f=Math.max(Math.abs(s),Math.abs(l),Math.abs(u));f>r&&(r=f)}this._currentSpaceSize=Math.max(10,2*r)}staticMaxVel(e){let t=this.params.dimensions===2?Math.max(10,Math.sqrt(e)*.5):Math.max(10,Math.cbrt(e)*2);return Math.min(2,t*.1)}updateLayoutOption(e,t){if(e==="friction"?this.params.velocityDecay=t:this.params[e]=t,!this.simulation||!this._enable)return;let n=()=>{this.simulation.alpha(Math.max(this.simulation.alpha(),.3)),this.isFinish=!1,this.runLoop()};switch(e){case"charge":this.forceCharge?.strength(t),n();break;case"linkDistance":this.forceLinkInstance?.distance(t),n();break;case"linkStrength":this.forceLinkInstance?.strength(this._linkStrengthFn),n();break;case"gravity":case"gravityX":case"gravityY":case"gravityZ":case"heightCompress":{let{forcexy:i,forcez:r}=this.calculateAxisForces();this.forceXInstance?.strength(i*this.params.gravityX),this.forceYInstance?.strength(i*this.params.gravityY),this.forceZInstance?.strength(r*this.params.gravityZ),n();break}case"velocityDecay":case"friction":this.simulation.velocityDecay(this.params.velocityDecay);break;case"alpha":case"alphaDecay":this.restartLayout();return;default:this.restartLayout();return}this.graph.renderNeedsUpdate=!0}pinNodes(e){this.simulation&&(e.forEach(t=>{let n=this.nodeIdToIndex.get(t.id);if(n===void 0)return;let i=n/3,r=this.simNodes[i];r&&(t.pinned?(r.fx=t.position.x,r.fy=t.position.y,r.fz=t.position.z,r.x=t.position.x,r.y=t.position.y,r.z=t.position.z,this.simulation.uploadPosition(i,t.position.x,t.position.y,t.position.z),this.simulation.uploadPinned(i,!0)):(delete r.fx,delete r.fy,delete r.fz,this.simulation.uploadPinned(i,!1)))}),this.simulation.alpha(Math.max(this.simulation.alpha(),.3)),this.isFinish=!1,this.runLoop(),this.graph.renderNeedsUpdate=!0)}unpinNodes(e){this.simulation&&(e.forEach(t=>{let n=this.nodeIdToIndex.get(t);if(n===void 0)return;let i=n/3,r=this.simNodes[i];r&&(delete r.fx,delete r.fy,delete r.fz,this.simulation.uploadPinned(i,!1))}),this.simulation.alpha(Math.max(this.simulation.alpha(),.3)),this.isFinish=!1,this.runLoop(),this.graph.renderNeedsUpdate=!0)}transitionDimensions(e,t=600){this.params.dimensions!==e&&(e===2?(this.readBackPositions(),this.params.dimensions=2,this.startLayout(0,0,!0)):(this.readBackPositions(),this.params.dimensions=3,this.startLayout()))}cancelDimensionTransition(){}getDimensions(){return this.params.dimensions}getPositionTexture(){return null}getTextureSize(){return 0}getSpaceSize(){return this._currentSpaceSize}readBackPositions(){if(this.simNodes.length===0)return;this.syncPositionsToSharedArray();let e=this.params.dimensions,t=this.graph.layoutNodes;for(let n=0;n<this.simNodes.length;n++){let i=this.simNodes[n],r=t[n];!r||!r.position||(r.position.x=i.x??0,r.position.y=i.y??0,r.position.z=e>2?i.z??0:0)}}setExpectedNodeCount(e){}clearExpectedNodeCount(){}updateGraph(e,t,n=!1){this.graph.layoutNodes=e,this.graph.layoutEdges=t}},pt=class{constructor(e){this.c=e,this.mode="cpu"}getPositionTexture(){return null}getTextureSize(){return 0}getSpaceSize(){return this.c.getSpaceSize()}get sharedArray(){return this.c.sharedArray}getPositions(){return this.c.sharedArray}tick(){}start(){this.c.startLayout()}restart(){this.c.restartLayout()}stop(){this.c.stopLayout()}get graph(){return this.c.graph}get needsUpdate(){return!this.c.isFinish}clearNeedsUpdate(){}pinNodes(e){this.c.pinNodes(e)}unpinNodes(e){this.c.unpinNodes(e)}readBackPositions(){this.c.readBackPositions()}transitionDimensions(e,t){this.c.transitionDimensions(e,t)}getDimensions(){return this.c.getDimensions()}updateOption(e,t){this.c.updateLayoutOption(e,t)}};var ue=pe(require("three"),1);var Q=pe(require("three"),1),Fe=pe(require("three"),1),$=pe(require("three"),1),Z=pe(require("three"),1),ne=pe(require("three"),1),Ie=pe(require("three"),1),ae=pe(require("three"),1),oe=pe(require("three"),1),se=pe(require("three"),1),De=pe(require("three"),1),ui=pe(require("three"),1),he=`/**
|
|
1426
|
+
`,$r=7,Rt=64,Zn=64,mo=Math.sqrt(.5);function jr(e){return Math.floor((Math.pow(8,e+1)-1)/7)}function ht(e){return Math.floor((Math.pow(8,e)-1)/7)}var Ut=4,Lt=65535,Zr=class{constructor(e,t=$r){this.accumParamsBufs=[],this.accumBGs=[],this.config={strength:-30,theta:.9,distanceMin:1,distanceMax:1/0},this.device=e.device,this.nodeCount=e.nodeCount,this.maxLevel=t,this.totalCells=jr(t);let n=this.device,i=GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC,r=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST;this.cellsBuffer=n.createBuffer({label:"oct-cells",size:this.totalCells*Ut*4,usage:i}),this.boundsBuffer=n.createBuffer({label:"oct-bounds",size:32,usage:i}),this.levelOffsetsBuffer=n.createBuffer({label:"oct-level-offsets",size:(t+1)*4,usage:i});let o=new Uint32Array(t+1);for(let f=0;f<=t;f++)o[f]=ht(f);n.queue.writeBuffer(this.levelOffsetsBuffer,0,o),this.boundsParamsBuf=n.createBuffer({label:"oct-bounds-params",size:16,usage:r}),this.clearParamsBuf=n.createBuffer({label:"oct-clear-params",size:16,usage:r}),this.binParamsBuf=n.createBuffer({label:"oct-bin-params",size:16,usage:r}),this.traverseParamsBuf=n.createBuffer({label:"oct-traverse-params",size:48,usage:r});for(let f=0;f<t;f++){let p=n.createBuffer({label:`oct-accum-params-L${f}`,size:16,usage:r}),h=new ArrayBuffer(16),g=new Uint32Array(h);g[0]=ht(f),g[1]=ht(f+1),g[2]=Math.pow(8,f),n.queue.writeBuffer(p,0,h),this.accumParamsBufs.push(p)}let a=this.totalCells*Ut,s=Math.ceil(a/Rt),u=Math.min(s,Lt)*Rt;n.queue.writeBuffer(this.clearParamsBuf,0,new Uint32Array([a,u,0,0]));let c=(f,p)=>n.createShaderModule({label:f,code:p}),d=(f,p,h="main")=>n.createComputePipeline({label:f,layout:"auto",compute:{module:p,entryPoint:h}});this.boundsPipeline=d("oct-bounds-pipe",c("oct-bounds",qt)),this.clearPipeline=d("oct-clear-pipe",c("oct-clear",ci)),this.binPipeline=d("oct-bin-pipe",c("oct-bin",Hr)),this.accumPipeline=d("oct-accum-pipe",c("oct-accum",Xr)),this.traversePipeline=d("oct-traverse-pipe",c("oct-traverse",Yr)),this.bindAll(e)}bindAll(e){let t=this.device;this.boundsBG=t.createBindGroup({layout:this.boundsPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:e.positionBuffer}},{binding:1,resource:{buffer:this.boundsBuffer}},{binding:2,resource:{buffer:this.boundsParamsBuf}}]}),this.clearBG=t.createBindGroup({layout:this.clearPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:this.cellsBuffer}},{binding:1,resource:{buffer:this.clearParamsBuf}}]}),this.binBG=t.createBindGroup({layout:this.binPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:e.positionBuffer}},{binding:1,resource:{buffer:this.cellsBuffer}},{binding:2,resource:{buffer:this.boundsBuffer}},{binding:3,resource:{buffer:this.binParamsBuf}}]});for(let i=0;i<this.maxLevel;i++)this.accumBGs.push(t.createBindGroup({layout:this.accumPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:this.cellsBuffer}},{binding:1,resource:{buffer:this.accumParamsBufs[i]}}]}));this.traverseBG=t.createBindGroup({layout:this.traversePipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:e.positionBuffer}},{binding:1,resource:{buffer:e.velocityBuffer}},{binding:2,resource:{buffer:this.cellsBuffer}},{binding:3,resource:{buffer:this.levelOffsetsBuffer}},{binding:4,resource:{buffer:this.boundsBuffer}},{binding:5,resource:{buffer:this.traverseParamsBuf}}]}),t.queue.writeBuffer(this.boundsParamsBuf,0,new Uint32Array([this.nodeCount,0,0,0]));let n=new ArrayBuffer(16);new Uint32Array(n,0,3).set([this.nodeCount,this.maxLevel,ht(this.maxLevel)]),new Float32Array(n,12,1)[0]=Zn,t.queue.writeBuffer(this.binParamsBuf,0,n)}setConfig(e){Object.assign(this.config,e)}apply(e,t){let n=this.device,i=this.nodeCount,r=Rt,o=new Int32Array([2147483647,-2147483648,2147483647,-2147483648,2147483647,-2147483648]);n.queue.writeBuffer(this.boundsBuffer,0,o),this.run(t,this.boundsPipeline,this.boundsBG,Math.ceil(i/r),"oct-p1-bounds");let a=Math.ceil(this.totalCells*Ut/r),s=Math.min(a,Lt),l=Math.ceil(a/Lt);this.run2D(t,this.clearPipeline,this.clearBG,s,l,"oct-p2-clear"),this.run(t,this.binPipeline,this.binBG,Math.ceil(i/r),"oct-p3-bin");for(let f=this.maxLevel-1;f>=0;f--)this.run(t,this.accumPipeline,this.accumBGs[f],Math.ceil(Math.pow(8,f)/r),`oct-p4-accum-L${f}`);let u=new ArrayBuffer(48),c=new Uint32Array(u),d=new Float32Array(u);c[0]=i,c[1]=this.maxLevel,d[4]=this.config.strength,d[5]=e,d[6]=this.config.theta*this.config.theta,d[7]=this.config.distanceMin*this.config.distanceMin,d[8]=this.config.distanceMax===1/0?1e30:this.config.distanceMax*this.config.distanceMax,d[9]=Zn,n.queue.writeBuffer(this.traverseParamsBuf,0,u),this.run(t,this.traversePipeline,this.traverseBG,Math.ceil(i/r),"oct-p5-traverse")}run(e,t,n,i,r){let o=e.beginComputePass({label:r});o.setPipeline(t),o.setBindGroup(0,n),o.dispatchWorkgroups(i),o.end()}run2D(e,t,n,i,r,o){let a=e.beginComputePass({label:o});a.setPipeline(t),a.setBindGroup(0,n),a.dispatchWorkgroups(i,r,1),a.end()}dispose(){this.cellsBuffer.destroy(),this.boundsBuffer.destroy(),this.levelOffsetsBuffer.destroy(),this.boundsParamsBuf.destroy(),this.clearParamsBuf.destroy(),this.binParamsBuf.destroy(),this.traverseParamsBuf.destroy(),this.accumParamsBufs.forEach(e=>e.destroy())}};function Vr(){let e=-30,t=1,n=1/0,i=.9,r=null,o={initialize(a,s,l){},initGPU(a){r?.dispose(),r=new Zr(a),r.setConfig({strength:e,theta:i,distanceMin:t,distanceMax:n})},apply(a,s){r?.apply(a,s)},dispose(){r?.dispose(),r=null},strength(a){return arguments.length===0?e:(e=+a,r?.setConfig({strength:e}),o)},distanceMin(a){return arguments.length===0?t:(t=+a,r?.setConfig({distanceMin:t}),o)},distanceMax(a){return arguments.length===0?n:(n=+a,r?.setConfig({distanceMax:n}),o)},theta(a){return arguments.length===0?i:(i=+a,r?.setConfig({theta:i}),o)}};return o}var Wr={charge:-.01,gravity:.1,linkStrength:1,linkDistance:.5,collision:.15,heightCompress:1,alpha:.6,alphaDecay:.1,velocityDecay:.3,dimensions:3,gravityX:1,gravityY:1,gravityZ:1,octreeTheta:.9},Je=240;function Kr(e,t,n){let i=globalThis,r=i.__webgpuPathATiming;r||(r={tick:new Float32Array(Je),read:new Float32Array(Je),sync:new Float32Array(Je),i:0,filled:0,reset(){this.i=0,this.filled=0},summary(){let o=this.filled;if(o===0)return null;let a=s=>{let l=0,u=1/0,c=-1/0;for(let d=0;d<o;d++){let f=s[d];l+=f,f<u&&(u=f),f>c&&(c=f)}return{mean:+(l/o).toFixed(3),min:+u.toFixed(3),max:+c.toFixed(3),n:o}};return{skipFlag:!!globalThis.__webgpuPathASkip,tickMs:a(this.tick),readMs:a(this.read),syncMs:a(this.sync),totalMs:{mean:+(this.tick.reduce((s,l)=>s+l,0)/o+this.read.reduce((s,l)=>s+l,0)/o+this.sync.reduce((s,l)=>s+l,0)/o).toFixed(3)}}}},i.__webgpuPathATiming=r),r.tick[r.i]=e,r.read[r.i]=t,r.sync[r.i]=n,r.i=(r.i+1)%Je,r.filled<Je&&r.filled++}var gt=class{constructor(e,t,n={}){if(this.sharedArray=new Float32Array(0),this.nodeIdToIndex=new Map,this.isFinish=!1,this._enable=!0,this.getOptions=()=>null,this._readbackTimingSink=null,this.simulation=null,this.simNodes=[],this._loopRunning=!1,this._currentSpaceSize=10,this.forceCharge=null,this.forceLinkInstance=null,this.forceXInstance=null,this.forceYInstance=null,this.forceZInstance=null,this.forceCenterInstance=null,this._linkDegree=new Int32Array(0),this._linkStrengthFn=i=>{let r=i.source,o=i.target,a=Math.min(this._linkDegree[r]??1,this._linkDegree[o]??1);return this.params.linkStrength*(a>0?1/a:1)},this._readbackTickCounter=0,this._readbackInterval=null,!Ee())throw new Error("[WebGPUForceLayoutController] navigator.gpu unavailable in this environment. Use the WebGL-backed GPUForceLayoutController instead.");this.params={...Wr},this.options=n,this.graph=e??{layoutNodes:[],layoutEdges:[],renderNeedsUpdate:!0}}setReadbackTimingSink(e){return this._readbackTimingSink=e,this}config(e){this.getOptions=e;let t=e();return t&&this.applyConfig(t),this}configure(e){return this.config(e)}applyConfig(e){e.charge!==void 0&&(this.params.charge=e.charge),e.gravity!==void 0&&(this.params.gravity=e.gravity),e.linkStrength!==void 0&&(this.params.linkStrength=e.linkStrength),e.linkDistance!==void 0&&(this.params.linkDistance=e.linkDistance),e.collision!==void 0&&(this.params.collision=e.collision),e.heightCompress!==void 0&&(this.params.heightCompress=e.heightCompress),e.alpha!==void 0&&(this.params.alpha=e.alpha),e.alphaDecay!==void 0&&(this.params.alphaDecay=e.alphaDecay),e.velocityDecay!==void 0&&(this.params.velocityDecay=e.velocityDecay),e.friction!==void 0&&(this.params.velocityDecay=e.friction),e.dimensions!==void 0&&(this.params.dimensions=e.dimensions),e.gravityX!==void 0&&(this.params.gravityX=e.gravityX),e.gravityY!==void 0&&(this.params.gravityY=e.gravityY),e.gravityZ!==void 0&&(this.params.gravityZ=e.gravityZ),e.octreeTheta!==void 0&&(this.params.octreeTheta=e.octreeTheta)}startLayout(e=0,t=0,n=!1){let i=this.params.dimensions,r=this.getOptions();r&&this.applyConfig(r),this.params.dimensions=i,this.disposeSimulation(),this.buildSimulation(n),this.simulation&&(this._enable=!0,this.isFinish=!1,this.graph.renderNeedsUpdate=!0,this._loopRunning=!1,this.runLoop())}restartLayout(){if(!this._enable)return;let e=this.getOptions();if(e){let i=this.params.dimensions;this.applyConfig(e),this.params.dimensions=i}this.applyForceParams();let t=this.graph.layoutNodes.length,n=this.simNodes.length;this.simulation&&t===n?(this.simulation.alpha(this.params.alpha),this.isFinish=!1,this.graph.renderNeedsUpdate=!0,this.runLoop()):this.startLayout()}stopLayout(){this._enable=!1,this.isFinish=!0,this.graph.renderNeedsUpdate=!1}destroy(){this.stopLayout(),this.disposeSimulation()}disposeSimulation(){this.simulation?.dispose(),this.simulation=null,this.forceCharge=null,this.forceLinkInstance=null,this.forceXInstance=null,this.forceYInstance=null,this.forceZInstance=null,this.forceCenterInstance=null}buildSimulation(e=!1){let t=this.graph.layoutNodes,n=this.graph.layoutEdges,i=t.length;if(i===0)return;let r=this.params.dimensions,o=t.some(g=>Math.abs(g.position.z)>1e-6),a=r>2&&!o&&!e,s=Math.cbrt(t.length)*2,u=Math.min(10,Math.pow(2,29)/(Math.pow(i,1.5)*64)),c=r===2&&!a&&!e,d=Math.PI*(3-Math.sqrt(5));this.simNodes=t.map((g,y)=>{let M={id:g.id,index:y};if(g.pinned)M.fx=g.position.x,M.fy=g.position.y,M.fz=g.position.z,M.x=g.position.x,M.y=g.position.y,M.z=g.position.z;else if(a){let b=Math.random(),m=Math.random(),v=Math.random(),w=2*Math.PI*b,x=Math.acos(2*m-1),C=Math.cbrt(v)*s;M.x=C*Math.sin(x)*Math.cos(w),M.y=C*Math.sin(x)*Math.sin(w),M.z=C*Math.cos(x)}else if(c){let b=u*Math.sqrt(.5+y),m=y*d;M.x=b*Math.cos(m),M.y=b*Math.sin(m),M.z=0}else e&&(M.x=g.position.x,M.y=g.position.y,M.z=r<=2?0:g.position.z);return M}),this.nodeIdToIndex.clear();for(let g=0;g<i;g++)this.nodeIdToIndex.set(this.simNodes[g].id,g*3);this.sharedArray=new Float32Array(i*3),this._currentSpaceSize=Math.max(10,2*(this.params.dimensions===2?10*Math.sqrt(i):10*Math.cbrt(i)));let f=ni(this.simNodes,this.params.dimensions,{device:this.options.device});f.alpha(this.params.alpha).alphaDecay(this.params.alphaDecay).velocityDecay(this.params.velocityDecay).alphaTarget(0).maxVel(this.staticMaxVel(this.simNodes.length));let{forcexy:p,forcez:h}=this.calculateAxisForces();if(this.forceXInstance=ri(0).strength(p*this.params.gravityX),this.forceYInstance=ai(0).strength(p*this.params.gravityY),f.force("x",this.forceXInstance),f.force("y",this.forceYInstance),this.params.dimensions>2&&(this.forceZInstance=oi(0).strength(h*this.params.gravityZ),f.force("z",this.forceZInstance)),this.forceCharge=this.makeChargeForce(i),f.force("charge",this.forceCharge),n.length){let g=n.map(M=>{let b=this.nodeIdToIndex.get(M.sourceId),m=this.nodeIdToIndex.get(M.targetId);return b===void 0||m===void 0?null:{id:M.id,source:b/3,target:m/3}}).filter(M=>M!==null),y=g.length;this._linkDegree=new Int32Array(i);for(let M=0;M<y;M++)this._linkDegree[g[M].source]++,this._linkDegree[g[M].target]++;this.forceLinkInstance=si(g).strength(this._linkStrengthFn).distance(this.params.linkDistance),f.force("link",this.forceLinkInstance)}this.forceCenterInstance=ii(0,0,0).strength(1),f.force("center",this.forceCenterInstance),this.simulation=f}makeChargeForce(e){if(this.params.dimensions===2){let n=Or();return n.theta?.(this.params.octreeTheta),n.strength(this.params.charge),n}if(e>=1e4){let n=ui();return n.theta(this.params.octreeTheta),n.strength(this.params.charge),n}let t=Vr();return t.theta?.(this.params.octreeTheta),t.strength(this.params.charge),t}calculateAxisForces(){let e,t;if(this.params.dimensions===2)e=this.params.gravity*1.5,t=0;else{let n=this.params.heightCompress;t=Math.min(10,this.params.gravity*Math.sqrt(n)),e=this.params.gravity/Math.sqrt(n)}return{forcexy:e,forcez:t}}applyForceParams(){if(!this.simulation)return;this.simulation.alphaDecay(this.params.alphaDecay),this.simulation.velocityDecay(this.params.velocityDecay);let{forcexy:e,forcez:t}=this.calculateAxisForces();this.forceXInstance?.strength(e*this.params.gravityX),this.forceYInstance?.strength(e*this.params.gravityY),this.forceZInstance?.strength(t*this.params.gravityZ),this.forceCharge?.strength(this.params.charge),this.forceLinkInstance&&(this.forceLinkInstance.strength(this._linkStrengthFn),this.forceLinkInstance.distance(this.params.linkDistance))}setReadbackInterval(e){this._readbackInterval=e===null?null:Math.max(1,Math.floor(e))}afterTick(e){let t=this.options.onTick;if(t)try{t({positionBuffer:e.getPositionBuffer(),nodeCount:this.simNodes.length,dimensions:this.params.dimensions})}catch{}}async runLoop(){if(!this._loopRunning){this._loopRunning=!0;try{let e=this.simulation;for(e&&!e.isReady()&&await new Promise(t=>e.on("ready",()=>t()));this._enable&&this.simulation&&(await this.waitForFrame(),!!this._enable);){let t=this.simulation;if(!t)break;let n=performance.now();t.tick(1),this.afterTick(t);let i=performance.now(),r=this._readbackInterval??Math.max(1,Math.floor(globalThis.__webgpuReadbackInterval??1));this._readbackTickCounter++;let o=this._readbackTickCounter>=r,a=t.alpha()<t.alphaMin(),s=o||a,l=i,u=i;if(s){this._readbackTickCounter=0;try{await t.readPositions()}catch(c){console.warn("[WebGPUForceLayoutController] readPositions threw, skipping:",c);continue}if(t!==this.simulation||!this._enable)break;l=performance.now(),this.syncPositionsToSharedArray(),u=performance.now(),this.graph.renderNeedsUpdate=!0}if(Kr(i-n,l-i,u-l),s&&this._readbackTimingSink)try{this._readbackTimingSink(u-i)}catch{}if(a){this.isFinish=!0,this.graph.renderNeedsUpdate=!1;break}}}finally{this._loopRunning=!1}}}waitForFrame(){return new Promise(e=>requestAnimationFrame(()=>e()))}syncPositionsToSharedArray(){let e=this.sharedArray,t=this.graph.layoutNodes,n=this.simNodes,i=Math.min(e.length/3,n.length,t.length);if(globalThis.__webgpuPathASkip===!0){let o=0;for(let a=0;a<e.length;a++){let s=e[a],l=s<0?-s:s;l>o&&(o=l)}this._currentSpaceSize=Math.max(10,2*o);return}let r=0;for(let o=0;o<i;o++){let a=n[o],s=a.x??0,l=a.y??0,u=a.z??0;e[o*3]=s,e[o*3+1]=l,e[o*3+2]=u;let c=t[o];c?.position&&(c.position.x=s,c.position.y=l,c.position.z=u);let d=Math.max(Math.abs(s),Math.abs(l),Math.abs(u));d>r&&(r=d)}this._currentSpaceSize=Math.max(10,2*r)}staticMaxVel(e){let t=this.params.dimensions===2?Math.max(10,Math.sqrt(e)*.5):Math.max(10,Math.cbrt(e)*2);return Math.min(2,t*.1)}updateLayoutOption(e,t){if(e==="friction"?this.params.velocityDecay=t:this.params[e]=t,!this.simulation||!this._enable)return;let n=()=>{this.simulation.alpha(Math.max(this.simulation.alpha(),.3)),this.isFinish=!1,this.runLoop()};switch(e){case"charge":this.forceCharge?.strength(t),n();break;case"linkDistance":this.forceLinkInstance?.distance(t),n();break;case"linkStrength":this.forceLinkInstance?.strength(this._linkStrengthFn),n();break;case"gravity":case"gravityX":case"gravityY":case"gravityZ":case"heightCompress":{let{forcexy:i,forcez:r}=this.calculateAxisForces();this.forceXInstance?.strength(i*this.params.gravityX),this.forceYInstance?.strength(i*this.params.gravityY),this.forceZInstance?.strength(r*this.params.gravityZ),n();break}case"velocityDecay":case"friction":this.simulation.velocityDecay(this.params.velocityDecay);break;case"alpha":case"alphaDecay":this.restartLayout();return;default:this.restartLayout();return}this.graph.renderNeedsUpdate=!0}pinNodes(e){this.simulation&&(e.forEach(t=>{let n=this.nodeIdToIndex.get(t.id);if(n===void 0)return;let i=n/3,r=this.simNodes[i];r&&(t.pinned?(r.fx=t.position.x,r.fy=t.position.y,r.fz=t.position.z,r.x=t.position.x,r.y=t.position.y,r.z=t.position.z,this.simulation.uploadPosition(i,t.position.x,t.position.y,t.position.z),this.simulation.uploadPinned(i,!0)):(delete r.fx,delete r.fy,delete r.fz,this.simulation.uploadPinned(i,!1)))}),this.simulation.alpha(Math.max(this.simulation.alpha(),.3)),this.isFinish=!1,this.runLoop(),this.graph.renderNeedsUpdate=!0)}unpinNodes(e){this.simulation&&(e.forEach(t=>{let n=this.nodeIdToIndex.get(t);if(n===void 0)return;let i=n/3,r=this.simNodes[i];r&&(delete r.fx,delete r.fy,delete r.fz,this.simulation.uploadPinned(i,!1))}),this.simulation.alpha(Math.max(this.simulation.alpha(),.3)),this.isFinish=!1,this.runLoop(),this.graph.renderNeedsUpdate=!0)}transitionDimensions(e,t=600){this.params.dimensions!==e&&(e===2?(this.readBackPositions(),this.params.dimensions=2,this.startLayout(0,0,!0)):(this.readBackPositions(),this.params.dimensions=3,this.startLayout()))}cancelDimensionTransition(){}getDimensions(){return this.params.dimensions}getPositionTexture(){return null}getTextureSize(){return 0}getSpaceSize(){return this._currentSpaceSize}readBackPositions(){if(this.simNodes.length===0)return;this.syncPositionsToSharedArray();let e=this.params.dimensions,t=this.graph.layoutNodes;for(let n=0;n<this.simNodes.length;n++){let i=this.simNodes[n],r=t[n];!r||!r.position||(r.position.x=i.x??0,r.position.y=i.y??0,r.position.z=e>2?i.z??0:0)}}setExpectedNodeCount(e){}clearExpectedNodeCount(){}updateGraph(e,t,n=!1){this.graph.layoutNodes=e,this.graph.layoutEdges=t}},yt=class{constructor(e){this.c=e,this.mode="cpu"}getPositionTexture(){return null}getTextureSize(){return 0}getSpaceSize(){return this.c.getSpaceSize()}get sharedArray(){return this.c.sharedArray}getPositions(){return this.c.sharedArray}tick(){}start(){this.c.startLayout()}restart(){this.c.restartLayout()}stop(){this.c.stopLayout()}get graph(){return this.c.graph}get needsUpdate(){return!this.c.isFinish}clearNeedsUpdate(){}pinNodes(e){this.c.pinNodes(e)}unpinNodes(e){this.c.unpinNodes(e)}readBackPositions(){this.c.readBackPositions()}transitionDimensions(e,t){this.c.transitionDimensions(e,t)}getDimensions(){return this.c.getDimensions()}updateOption(e,t){this.c.updateLayoutOption(e,t)}};var pe=me(require("three"),1);var te=me(require("three"),1),Ue=me(require("three"),1),Q=me(require("three"),1),J=me(require("three"),1),oe=me(require("three"),1),Le=me(require("three"),1),le=me(require("three"),1),ue=me(require("three"),1),ce=me(require("three"),1),Ge=me(require("three"),1),fi=me(require("three"),1),ge=`/**
|
|
1427
1427
|
* Simple vertex shader for full-screen quad rendering
|
|
1428
1428
|
* Used by all GPU compute passes
|
|
1429
1429
|
*/
|
|
@@ -1433,7 +1433,7 @@ void main() {
|
|
|
1433
1433
|
vUv = uv;
|
|
1434
1434
|
gl_Position = vec4(position, 1.0);
|
|
1435
1435
|
}
|
|
1436
|
-
`,
|
|
1436
|
+
`,Qr=`/**
|
|
1437
1437
|
* Position update shader
|
|
1438
1438
|
*
|
|
1439
1439
|
* Applies accumulated velocity to position, with:
|
|
@@ -1493,7 +1493,7 @@ void main() {
|
|
|
1493
1493
|
|
|
1494
1494
|
gl_FragColor = vec4(newPos, pos.w);
|
|
1495
1495
|
}
|
|
1496
|
-
`,
|
|
1496
|
+
`,di=`/**
|
|
1497
1497
|
* Clear shader - outputs zero for all fragments
|
|
1498
1498
|
* Used to reset velocity buffer at the start of each tick
|
|
1499
1499
|
*
|
|
@@ -1506,7 +1506,7 @@ precision highp float;
|
|
|
1506
1506
|
void main() {
|
|
1507
1507
|
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
|
1508
1508
|
}
|
|
1509
|
-
`,
|
|
1509
|
+
`,Jr=`/**
|
|
1510
1510
|
* Copy shader - copies one texture to another
|
|
1511
1511
|
* Used for initializing FBOs with data textures
|
|
1512
1512
|
*/
|
|
@@ -1518,7 +1518,7 @@ varying vec2 vUv;
|
|
|
1518
1518
|
void main() {
|
|
1519
1519
|
gl_FragColor = texture2D(sourceTexture, vUv);
|
|
1520
1520
|
}
|
|
1521
|
-
`,
|
|
1521
|
+
`,ea=`/**
|
|
1522
1522
|
* Velocity decay shader
|
|
1523
1523
|
*
|
|
1524
1524
|
* Applies velocity decay (friction) to existing velocity.
|
|
@@ -1542,7 +1542,7 @@ void main() {
|
|
|
1542
1542
|
|
|
1543
1543
|
gl_FragColor = vec4(vel.xyz, 1.0);
|
|
1544
1544
|
}
|
|
1545
|
-
`,
|
|
1545
|
+
`,ta=3;function na(e,t,n){let i=Math.min(ta,Math.max(1,Math.round(t||3))),r,o=1,a=.001,s=1-Math.pow(a,1/300),l=0,u=.6,c=Kn(),d=new Map,f=null,p=Bt("tick","end");e==null&&(e=[]);let h,g,y,M,b=!1,m=0,v=0,w=null,x=null,C=0,E=null,I=null,R=0,U=null,q=null,k=null,A=null,_=null,D=null,B=null,P=null,L=1e3/10,Y=0,X=!1;function H(){if(b)return;if(n)h=n;else{let V=document.createElement("canvas");V.style.display="none",h=new pe.WebGLRenderer({canvas:V,alpha:!0,antialias:!1}),h.setSize(256,256)}g=new pe.Scene,y=new pe.OrthographicCamera(-1,1,1,-1,0,1);let O=we();_=new pe.ShaderMaterial({uniforms:{},vertexShader:ge,fragmentShader:di,blending:pe.NoBlending,depthTest:!1,depthWrite:!1}),D=new pe.ShaderMaterial({uniforms:{sourceTexture:{value:null}},vertexShader:ge,fragmentShader:Jr,depthTest:!1,depthWrite:!1}),A=new pe.ShaderMaterial({uniforms:{positionTexture:{value:null},velocityTexture:{value:null},pinnedTexture:{value:null},friction:{value:1},spaceSize:{value:10},nDim:{value:i}},vertexShader:ge,fragmentShader:Qr,depthTest:!1,depthWrite:!1}),B=new pe.ShaderMaterial({uniforms:{velocityTexture:{value:null},decay:{value:u}},vertexShader:ge,fragmentShader:ea,depthTest:!1,depthWrite:!1}),M=new pe.Mesh(O,_),g.add(M),b=!0}function T(){if(b||H(),v=e.length,v===0)return;m=Gt(v);let O=$e(v,i),V=h.getContext(),ee=V.getParameter(V.MAX_TEXTURE_SIZE);w?.dispose(),x?.dispose(),E?.dispose(),I?.dispose(),U?.dispose(),q?.dispose(),k?.dispose(),w=Re(m),x=Re(m),E=Re(m),I=Re(m),U=Re(m),C=0,R=0;let de=Qn(e,m),ie=je(de,m),Me=Jn(e,m),xe=je(Me,m),he=ei(e,m);q=je(he,m);let re=m*m,Pe=new Float32Array(re*4);for(let be=0;be<re;be++)Pe[be*4]=(c()-.5)*2,Pe[be*4+1]=(c()-.5)*2,Pe[be*4+2]=(c()-.5)*2,Pe[be*4+3]=c();k=je(Pe,m),D.uniforms.sourceTexture.value=ie,M.material=D,h.setRenderTarget(w),h.render(g,y),h.setRenderTarget(x),h.render(g,y),D.uniforms.sourceTexture.value=xe,h.setRenderTarget(E),h.render(g,y),h.setRenderTarget(I),h.render(g,y),M.material=_,h.setRenderTarget(U),h.render(g,y),h.setRenderTarget(null),ie.dispose(),xe.dispose(),A.uniforms.spaceSize.value=O;let tt={renderer:h,scene:g,camera:y,textureSize:m,nodeCount:v};d.forEach(be=>{if(be.initGPU)try{be.initGPU(tt)}catch{}})}function G(){return C===0?w:x}function $(){return C===0?x:w}function K(){C=1-C}function Z(){return R===0?E:I}function S(){return R===0?I:E}function z(){R=1-R}function N(){F(),p.call("tick",r),o<a&&(f?.stop(),p.call("end",r))}function F(O){O===void 0&&(O=1);for(let V=0;V<O;V++)o+=(l-o)*s,b&&v>0?ne():ye();return r}let W=0,j=0;function ne(){W++;let O=performance.now();(W%50===0||O-j>2e3)&&(j=O);let V=$(),ee=G(),de=S(),ie=Z(),Me=$e(v,i);for(let[,re]of d)if(typeof re.getSpaceSize=="function"){Me=re.getSpaceSize();break}let xe=Me;D.uniforms.sourceTexture.value=de.texture,M.material=D,h.setRenderTarget(U),h.render(g,y),d.forEach(re=>{try{re.apply(o,V.texture,U)}catch{}}),B.uniforms.velocityTexture.value=U.texture,B.uniforms.decay.value=u,M.material=B,h.setRenderTarget(ie),h.render(g,y),A.uniforms.positionTexture.value=V.texture,A.uniforms.velocityTexture.value=ie.texture,A.uniforms.pinnedTexture.value=q,A.uniforms.friction.value=1,A.uniforms.spaceSize.value=xe,M.material=A,h.setRenderTarget(ee),h.render(g,y),h.setRenderTarget(null);let he=d.get("center");if(he&&he.applyToPosition&&(he.applyToPosition(ee.texture,V,o),D.uniforms.sourceTexture.value=V.texture,M.material=D,h.setRenderTarget(ee),h.render(g,y),h.setRenderTarget(null)),K(),z(),!X){let re=performance.now();re-Y>=L&&(Y=re,ve())}}function ye(){d.forEach(O=>{O.apply(o)});for(let O=0;O<e.length;O++){let V=e[O];V.fx==null?V.x+=V.vx*=u:(V.x=V.fx,V.vx=0),i>1&&(V.fy==null?V.y+=V.vy*=u:(V.y=V.fy,V.vy=0)),i>2&&(V.fz==null?V.z+=V.vz*=u:(V.z=V.fz,V.vz=0))}}let fe=0;function ve(){if(!b||v===0)return;let O=$(),V=new Float32Array(m*m*4);try{h.readRenderTargetPixels(O,0,0,m,m,V),ti(e,V,i),fe++}catch{}}function xt(O){return O.initialize(e,c,i),b&&O.initGPU&&O.initGPU({renderer:h,scene:g,camera:y,textureSize:m,nodeCount:v}),O}return et(e,i,c),r={tick:function(O){return F(O),this},restart:function(){return e.length>0&&!b&&(H(),T()),f?f.restart(N):f=ut(N),this},stop:function(){return f?.stop(),this},numDimensions:function(O){return arguments.length===0?i:this},nodes:function(O){return arguments.length===0?e:(e=O,et(e,i,c),T(),d.forEach(xt),this)},alpha:function(O){return arguments.length===0?o:(o=+O,this)},alphaMin:function(O){return arguments.length===0?a:(a=+O,this)},alphaDecay:function(O){return arguments.length===0?s:(s=+O,this)},alphaTarget:function(O){return arguments.length===0?l:(l=+O,this)},velocityDecay:function(O){return arguments.length===0?1-u:(u=1-O,B&&(B.uniforms.decay.value=u),this)},randomSource:function(O){return arguments.length===0?c:(c=O,d.forEach(xt),this)},force:function(O,V){if(arguments.length===1)return d.get(O);if(V==null){let ee=d.get(O);ee?.dispose&&ee.dispose(),d.delete(O)}else{let ee=xt(V);if(d.set(O,ee),b&&ee.initGPU&&v>0&&m>0)try{ee.initGPU({renderer:h,scene:g,camera:y,textureSize:m,nodeCount:v})}catch{}}return this},find:function(O,V,ee,de){V=V??0,ee=ee??0,de=de??1/0;let ie,Me=de*de;for(let xe=0;xe<e.length;xe++){let he=e[xe],re=O-(he.x||0),Pe=V-(he.y||0),tt=ee-(he.z||0),be=re*re+Pe*Pe+tt*tt;be<Me&&(ie=he,Me=be)}return ie},on:function(O,V){return arguments.length===1?p.on(O):(p.on(O,V),this)},getPositionTexture:function(){if(!b||v===0)return null;let O=$();return!O||!O.texture?null:O.texture},getTextureSize:function(){return m},getSpaceSize:function(){if(!b||v===0)return 10;for(let[,O]of d)if(typeof O.getSpaceSize=="function")return O.getSpaceSize();return $e(v,i)},setSkipCPUReadback:function(O){X=O},getSkipCPUReadback:function(){return X},readBackPositions:function(){ve()},uploadNodePositions:function(O){if(!b||v===0||O.length===0)return;let V=$();if(!V)return;let ee=new Float32Array(m*m*4);try{h.readRenderTargetPixels(V,0,0,m,m,ee)}catch{return}for(let{index:ie,x:Me,y:xe,z:he}of O)if(ie>=0&&ie<v){let re=ie*4;ee[re]=Me,ee[re+1]=xe,ee[re+2]=he}let de=je(ee,m);D.uniforms.sourceTexture.value=de,M.material=D,h.setRenderTarget(V),h.render(g,y),h.setRenderTarget(null),de.dispose()},updatePinnedNodes:function(O){if(!q||!b||v===0||O.length===0)return;let V=q.image.data;for(let{index:ee,isPinned:de}of O)ee>=0&&ee<v&&(V[ee*4]=de?1:0);q.needsUpdate=!0},debugPositions:function(O=5){if(!b||v===0)return null;let V=$(),ee=new Float32Array(m*m*4);try{h.readRenderTargetPixels(V,0,0,m,m,ee);let de=[];for(let ie=0;ie<Math.min(O,v);ie++){let Me=ee[ie*4],xe=ee[ie*4+1],he=ee[ie*4+2],re=ee[ie*4+3];de.push({x:Me,y:xe,z:he,w:re})}return de}catch{return null}},dispose:function(){f?.stop(),d.forEach(O=>{O.dispose&&O.dispose()}),d.clear(),w?.dispose(),x?.dispose(),E?.dispose(),I?.dispose(),U?.dispose(),q?.dispose(),k?.dispose(),A?.dispose(),_?.dispose(),D?.dispose(),B?.dispose(),M&&(M.geometry.dispose(),g?.remove(M)),!n&&h&&h.dispose()}},H(),e.length>0&&T(),r}var ia=`/**
|
|
1546
1546
|
* Center force shader
|
|
1547
1547
|
*
|
|
1548
1548
|
* Implements d3-force's forceCenter behavior:
|
|
@@ -1600,7 +1600,7 @@ void main() {
|
|
|
1600
1600
|
// Note: alpha must be 1.0 for THREE.AdditiveBlending to work (uses SrcAlphaFactor)
|
|
1601
1601
|
gl_FragColor = vec4(shift, 1.0);
|
|
1602
1602
|
}
|
|
1603
|
-
`,
|
|
1603
|
+
`,ra=`/**
|
|
1604
1604
|
* Center force position shader
|
|
1605
1605
|
*
|
|
1606
1606
|
* Implements d3-force's forceCenter behavior correctly:
|
|
@@ -1663,7 +1663,7 @@ void main() {
|
|
|
1663
1663
|
|
|
1664
1664
|
gl_FragColor = vec4(newPos, pos.w);
|
|
1665
1665
|
}
|
|
1666
|
-
`,
|
|
1666
|
+
`,aa=`/**
|
|
1667
1667
|
* Center of mass calculation - vertex shader
|
|
1668
1668
|
*
|
|
1669
1669
|
* Renders each node as a point to a 1x1 texture.
|
|
@@ -1702,7 +1702,7 @@ void main() {
|
|
|
1702
1702
|
// Multiple points at the same location with additive blending will sum up
|
|
1703
1703
|
gl_PointSize = 1.0;
|
|
1704
1704
|
}
|
|
1705
|
-
`,
|
|
1705
|
+
`,oa=`/**
|
|
1706
1706
|
* Center of mass calculation - fragment shader
|
|
1707
1707
|
*
|
|
1708
1708
|
* Outputs position.xyz as RGB and 1.0 as A (for counting).
|
|
@@ -1723,7 +1723,7 @@ void main() {
|
|
|
1723
1723
|
// Output position (xyz) and count (1.0)
|
|
1724
1724
|
gl_FragColor = vec4(pos.xyz, 1.0);
|
|
1725
1725
|
}
|
|
1726
|
-
`;function
|
|
1726
|
+
`;function sa(e,t,n){let i=[],r=2,o=e??0,a=t??0,s=n??0,l=1,u=null,c=null,d=null,f=null,p=0,h=0,g=null,y=null,M=null,b=null,m=null,v=null,w=null,x=null,C=null,E=null,I=null,R=null;function U(_,D,B){if(!u||!D||!B||h===0){q(_);return}}function q(_){let D=0,B=0,P=0,L=i.length;for(let T=0;T<L;T++){let G=i[T];D+=G.x||0,B+=G.y||0,P+=G.z||0}let Y=(D/L-o)*l,X=(B/L-a)*l,H=(P/L-s)*l;for(let T=0;T<L;T++){let G=i[T];Y&&(G.x-=Y),r>1&&X&&(G.y-=X),r>2&&H&&(G.z-=H)}}function k(_,D,B){}function A(_,D,B=1){if(!u||!y||!M||!E||!R||!f){console.warn("[GPU ForceCenter] applyToPosition: missing resources");return}g.remove(M);let P=new te.Mesh(we(),v);if(g.add(P),u.setRenderTarget(y),u.render(g,f),g.remove(P),P.geometry.dispose(),g.add(M),m.uniforms.positionTexture.value=_,m.uniforms.textureSize.value=p,m.uniforms.nodeCount.value=h,u.setRenderTarget(y),u.render(g,f),Math.random()<.02){let L=new Float32Array(4);u.readRenderTargetPixels(y,0,0,1,1,L);let Y=L[0],X=L[1],H=L[2],T=L[3],G=T>0?Y/T:0,$=T>0?X/T:0,K=T>0?H/T:0;console.log(`[GPU ForceCenter] Centermass: sum=(${Y.toFixed(2)}, ${X.toFixed(2)}, ${H.toFixed(2)}), count=${T}, avg=(${G.toFixed(4)}, ${$.toFixed(4)}, ${K.toFixed(4)})`)}R.uniforms.positionTexture.value=_,R.uniforms.centermassTexture.value=y.texture,R.uniforms.centerX.value=o,R.uniforms.centerY.value=a,R.uniforms.centerZ.value=s,R.uniforms.strength.value=l,R.uniforms.alpha.value=B,R.uniforms.textureSize.value=p,R.uniforms.nodeCount.value=h,R.uniforms.nDim.value=r,u.setRenderTarget(D),u.render(E,d),u.setRenderTarget(null)}return U.initialize=function(_,D,B){i=_,r=B},U.initGPU=function(_){u=_.renderer,d=_.camera,p=_.textureSize,h=_.nodeCount,f=new te.OrthographicCamera(-1,1,1,-1,0,1),g=new te.Scene,y=Re(1);let D=Wn(p);b=new te.BufferGeometry,b.setAttribute("pointIndex",new te.BufferAttribute(D,2));let B=p*p,P=new Float32Array(B*3);b.setAttribute("position",new te.BufferAttribute(P,3)),m=new te.ShaderMaterial({uniforms:{positionTexture:{value:null},textureSize:{value:p},nodeCount:{value:h}},vertexShader:aa,fragmentShader:oa,blending:te.AdditiveBlending,depthTest:!1,depthWrite:!1}),M=new te.Points(b,m),g.add(M),console.log(`[GPU ForceCenter] Initialized centermass: ${D.length/2} points, textureSize=${p}, nodeCount=${h}`),console.log(`[GPU ForceCenter] Initialized centermass calculation: ${D.length/2} points, textureSize=${p}, nodeCount=${h}`),v=new te.ShaderMaterial({uniforms:{},vertexShader:ge,fragmentShader:di,blending:te.NoBlending,depthTest:!1,depthWrite:!1}),w=new te.Scene,C=new te.ShaderMaterial({uniforms:{positionTexture:{value:null},centermassTexture:{value:null},centerX:{value:o},centerY:{value:a},centerZ:{value:s},strength:{value:l},textureSize:{value:p},nodeCount:{value:h},nDim:{value:r}},vertexShader:ge,fragmentShader:ia,blending:te.AdditiveBlending,depthTest:!1,depthWrite:!1}),x=new te.Mesh(we(),C),w.add(x),E=new te.Scene,R=new te.ShaderMaterial({uniforms:{positionTexture:{value:null},centermassTexture:{value:null},centerX:{value:o},centerY:{value:a},centerZ:{value:s},strength:{value:l},alpha:{value:1},textureSize:{value:p},nodeCount:{value:h},nDim:{value:r}},vertexShader:ge,fragmentShader:ra,blending:te.NoBlending,depthTest:!1,depthWrite:!1}),I=new te.Mesh(we(),R),E.add(I)},U.dispose=function(){y?.dispose(),b?.dispose(),m?.dispose(),v?.dispose(),C?.dispose(),R?.dispose(),x&&x.geometry.dispose(),I&&I.geometry.dispose()},U.apply=U,U.applyToPosition=A,U.x=function(_){return arguments.length===0?o:(o=+_,U)},U.y=function(_){return arguments.length===0?a:(a=+_,U)},U.z=function(_){return arguments.length===0?s:(s=+_,U)},U.strength=function(_){return arguments.length===0?l:(l=+_,U)},U}var la=`/**
|
|
1727
1727
|
* Quadtree build vertex shader
|
|
1728
1728
|
*
|
|
1729
1729
|
* Accumulates node positions into quadtree cells using point rendering.
|
|
@@ -1784,7 +1784,7 @@ void main() {
|
|
|
1784
1784
|
gl_Position = vec4(levelPosition, 0.0, 1.0);
|
|
1785
1785
|
gl_PointSize = 1.0;
|
|
1786
1786
|
}
|
|
1787
|
-
`,
|
|
1787
|
+
`,ua=`/**
|
|
1788
1788
|
* Quadtree build fragment shader
|
|
1789
1789
|
*
|
|
1790
1790
|
* Simply passes through the accumulated data.
|
|
@@ -1797,7 +1797,7 @@ varying vec4 vData;
|
|
|
1797
1797
|
void main() {
|
|
1798
1798
|
gl_FragColor = vData;
|
|
1799
1799
|
}
|
|
1800
|
-
`;function
|
|
1800
|
+
`;function ca(e,t){e=Math.min(e,t);let n=t-e,i=`
|
|
1801
1801
|
// Match d3-force manyBody.js line 84: skip if beyond distanceMax
|
|
1802
1802
|
if (l >= distanceMax2) {
|
|
1803
1803
|
// Skip this cell (too far)
|
|
@@ -1808,7 +1808,7 @@ void main() {
|
|
|
1808
1808
|
float c = alpha * strength * centermass.b;
|
|
1809
1809
|
addVelocity += calculateAdditionalVelocity(vec2(x, y), l, c, random.rg);
|
|
1810
1810
|
}
|
|
1811
|
-
`;function r(s){if(s>=t)return i;{let l=Math.pow(2,s+1),u=new Array(s+1-n).fill(0).map((f
|
|
1811
|
+
`;function r(s){if(s>=t)return i;{let l=Math.pow(2,s+1),u=new Array(s+1-n).fill(0).map((d,f)=>`pow(2.0, ${s-(f+n)}.0) * i${f+n}`).join("+"),c=new Array(s+1-n).fill(0).map((d,f)=>`pow(2.0, ${s-(f+n)}.0) * j${f+n}`).join("+");return`
|
|
1812
1812
|
for (float ij${s} = 0.0; ij${s} < 4.0; ij${s} += 1.0) {
|
|
1813
1813
|
float i${s} = 0.0;
|
|
1814
1814
|
float j${s} = 0.0;
|
|
@@ -1936,12 +1936,12 @@ void main() {
|
|
|
1936
1936
|
// Note: alpha must be 1.0 for THREE.AdditiveBlending to work correctly
|
|
1937
1937
|
gl_FragColor = vec4(velocity, 0.0, 1.0);
|
|
1938
1938
|
}
|
|
1939
|
-
`}function
|
|
1939
|
+
`}function da(){let e=[],t=2,n=-30,i=.9,r=1,o=1/0,a=null,s=null,l=0,u=0,c=10,d=0,f=[],p=null,h=null,g=null,y=null,M=null,b=null,m=null;function v(U,q,k){!a||!q||!k||u===0||(C(q),I(U,q,k))}let w=[],x=0;function C(U){if(!a||!h||!g||!s)return;g.uniforms.positionTexture.value=U;let q=a.autoClear,k=a.getClearColor(new Q.Color),A=a.getClearAlpha();a.autoClear=!0,a.setClearColor(0,0);for(let _=0;_<d;_++){let D=w[_];g.uniforms.levelTextureSize.value=D.textureSize,g.uniforms.cellSize.value=D.cellSize,a.setRenderTarget(f[_]),a.render(h,s)}a.autoClear=q,a.setClearColor(k,A),a.setRenderTarget(null)}let E=!1;function I(U,q,k){if(!a||!M||!b||!s)return;if(b.uniforms.positionsTexture.value=q,b.uniforms.alpha.value=U,!E){b.uniforms.randomValues.value=p?.texture,b.uniforms.strength.value=n,b.uniforms.theta.value=i,b.uniforms.spaceSize.value=c,b.uniforms.distanceMin.value=r,b.uniforms.distanceMax.value=o===1/0?c*10:o;for(let _=0;_<d;_++)b.uniforms[`level${_}`].value=f[_].texture;E=!0}let A=a.autoClear;a.autoClear=!1,a.setRenderTarget(k),a.render(M,s),a.autoClear=A,a.setRenderTarget(null)}let R=Math.random;return v.initialize=function(U,q,k){e=U,t=k,R=q},v.initGPU=function(U){a=U.renderer,s=U.camera,l=U.textureSize,u=U.nodeCount;let q=$e(u,t),A=Math.max(10,q*2);c=Math.pow(2,Math.ceil(Math.log2(A)));let _=Math.floor(Math.log2(c));d=Math.min(_+4,13);let B=d,P=Math.min(d,14),L=Math.min(d,P),Y=d-L,X=new Float32Array(l*l*4);for(let z=0;z<l*l;z++)X[z*4]=R(),X[z*4+1]=R(),X[z*4+2]=0,X[z*4+3]=0;let H=new Q.DataTexture(X,l,l,Q.RGBAFormat,Q.FloatType);H.needsUpdate=!0,p?.dispose(),p=new Q.WebGLRenderTarget(l,l,{type:Q.FloatType,format:Q.RGBAFormat,minFilter:Q.NearestFilter,magFilter:Q.NearestFilter,generateMipmaps:!1,depthBuffer:!1,stencilBuffer:!1});let T=new Q.ShaderMaterial({uniforms:{tDiffuse:{value:H}},vertexShader:ge,fragmentShader:`
|
|
1940
1940
|
precision highp float;
|
|
1941
1941
|
uniform sampler2D tDiffuse;
|
|
1942
1942
|
varying vec2 vUv;
|
|
1943
1943
|
void main() { gl_FragColor = texture2D(tDiffuse, vUv); }
|
|
1944
|
-
`}),
|
|
1944
|
+
`}),G=new Q.Scene,$=new Q.Mesh(we(),T);G.add($),a.setRenderTarget(p),a.render(G,s),a.setRenderTarget(null),T.dispose(),$.geometry.dispose(),H.dispose(),f.forEach(z=>z.dispose()),f=[],w=[];for(let z=0;z<d;z++){let N=Math.pow(2,z+1),F=new Q.WebGLRenderTarget(N,N,{type:Q.FloatType,format:Q.RGBAFormat,minFilter:Q.NearestFilter,magFilter:Q.NearestFilter,generateMipmaps:!1,depthBuffer:!1,stencilBuffer:!1});f.push(F),w.push({textureSize:N,cellSize:c/N})}let K;if(u!==x){let z=new Float32Array(u*2),N=new Float32Array(u*3);for(let F=0;F<u;F++)z[F*2]=F%l,z[F*2+1]=Math.floor(F/l),N[F*3]=0,N[F*3+1]=0,N[F*3+2]=0;K=new Q.BufferGeometry,K.setAttribute("position",new Q.BufferAttribute(N,3)),K.setAttribute("pointIndex",new Q.BufferAttribute(z,2)),x=u}else K=y.geometry;if(g?.dispose(),g=new Q.ShaderMaterial({uniforms:{positionTexture:{value:null},pointsTextureSize:{value:l},levelTextureSize:{value:2},cellSize:{value:c/2},spaceSize:{value:c}},vertexShader:la,fragmentShader:ua,blending:Q.AdditiveBlending,depthTest:!1,depthWrite:!1}),h||(h=new Q.Scene),y){if(y.material=g,u!==x){let z=y.geometry;y.geometry=K,z.dispose()}}else y=new Q.Points(K,g),h.add(y);b?.dispose(),E=!1;let Z={positionsTexture:{value:null},randomValues:{value:null},spaceSize:{value:c},strength:{value:n},theta:{value:i},alpha:{value:1},distanceMin:{value:r},distanceMax:{value:o===1/0?c*10:o}};for(let z=0;z<d;z++)Z[`level${z}`]={value:null};let S=ca(L,d);b=new Q.ShaderMaterial({uniforms:Z,vertexShader:ge,fragmentShader:S,blending:Q.AdditiveBlending,depthTest:!1,depthWrite:!1}),M||(M=new Q.Scene),m?m.material=b:(m=new Q.Mesh(we(),b),M.add(m))},v.dispose=function(){f.forEach(U=>U.dispose()),f=[],w=[],E=!1,p?.dispose(),p=null,g?.dispose(),b?.dispose(),y?.geometry.dispose(),m?.geometry.dispose()},v.apply=v,v.strength=function(U){return arguments.length===0?n:(n=+U,b&&(b.uniforms.strength.value=n),v)},v.theta=function(U){return arguments.length===0?i:(i=+U,E=!1,v)},v.distanceMin=function(U){return arguments.length===0?r:(r=+U,E=!1,v)},v.distanceMax=function(U){return arguments.length===0?o:(o=+U,E=!1,v)},v}var fa=`
|
|
1945
1945
|
precision highp float;
|
|
1946
1946
|
|
|
1947
1947
|
uniform sampler2D positionTexture;
|
|
@@ -1990,20 +1990,20 @@ void main() {
|
|
|
1990
1990
|
gl_Position = vec4(levelPosition, 0.0, 1.0);
|
|
1991
1991
|
gl_PointSize = 1.0;
|
|
1992
1992
|
}
|
|
1993
|
-
`,
|
|
1993
|
+
`,pa=`
|
|
1994
1994
|
precision highp float;
|
|
1995
1995
|
varying vec4 vData;
|
|
1996
1996
|
void main() {
|
|
1997
1997
|
gl_FragColor = vData;
|
|
1998
1998
|
}
|
|
1999
|
-
`;function
|
|
1999
|
+
`;function ha(e,t){e=Math.min(e,t);let n=t-e;function i(s){let l=t-1-Math.min(s,t-1);return`
|
|
2000
2000
|
if (l >= distanceMax2) {
|
|
2001
2001
|
// Skip this cell (too far)
|
|
2002
2002
|
} else {
|
|
2003
2003
|
float c = alpha * strength * centermass.w * ${Math.pow(Math.sqrt(4/8),l).toFixed(6)};
|
|
2004
2004
|
addVelocity += calculateAdditionalVelocity(vec3(dx, dy, dz), l, c, random.rgb);
|
|
2005
2005
|
}
|
|
2006
|
-
`}function r(s){if(s>=t)return i(t-1);{let l=Math.pow(2,s+1),u=new Array(s+1-n).fill(0).map((
|
|
2006
|
+
`}function r(s){if(s>=t)return i(t-1);{let l=Math.pow(2,s+1),u=new Array(s+1-n).fill(0).map((f,p)=>`pow(2.0, ${s-(p+n)}.0) * i${p+n}`).join("+"),c=new Array(s+1-n).fill(0).map((f,p)=>`pow(2.0, ${s-(p+n)}.0) * j${p+n}`).join("+"),d=new Array(s+1-n).fill(0).map((f,p)=>`pow(2.0, ${s-(p+n)}.0) * k${p+n}`).join("+");return`
|
|
2007
2007
|
for (float ijk${s} = 0.0; ijk${s} < 8.0; ijk${s} += 1.0) {
|
|
2008
2008
|
float i${s} = mod(ijk${s}, 2.0);
|
|
2009
2009
|
float j${s} = mod(floor(ijk${s} / 2.0), 2.0);
|
|
@@ -2011,7 +2011,7 @@ void main() {
|
|
|
2011
2011
|
|
|
2012
2012
|
float cellI = pow(2.0, ${e}.0) * outerI / width${s+1} + ${u};
|
|
2013
2013
|
float cellJ = pow(2.0, ${e}.0) * outerJ / width${s+1} + ${c};
|
|
2014
|
-
float cellK = pow(2.0, ${e}.0) * outerK / width${s+1} + ${
|
|
2014
|
+
float cellK = pow(2.0, ${e}.0) * outerK / width${s+1} + ${d};
|
|
2015
2015
|
|
|
2016
2016
|
// Sample from flattened 2D texture
|
|
2017
2017
|
// 3D (cellI, cellJ, cellK) \u2192 2D (cellI + cellK * gridSize, cellJ)
|
|
@@ -2130,12 +2130,12 @@ void main() {
|
|
|
2130
2130
|
// Output 3D velocity (xyz) with alpha = 1.0 for blending
|
|
2131
2131
|
gl_FragColor = vec4(velocity, 1.0);
|
|
2132
2132
|
}
|
|
2133
|
-
`}function
|
|
2133
|
+
`}function ma(){let e=[],t=2,n=-30,i=.5,r=1,o=1/0,a=null,s=null,l=null,u=0,c=0,d=10,f=0,p=[],h=null,g=null,y=null,M=null,b=null,m=null,v=null;function w(q,k,A){!s||!k||!A||c===0||(E(k),R(q,k,A))}let x=[],C=0;function E(q){if(!s||!g||!y||!l)return;y.uniforms.positionTexture.value=q;let k=s.autoClear,A=s.getClearColor(new J.Color),_=s.getClearAlpha();s.autoClear=!0,s.setClearColor(0,0);for(let D=0;D<f;D++){let B=x[D];y.uniforms.levelSize.value=B.levelSize,y.uniforms.levelTextureWidth.value=B.textureWidth,y.uniforms.levelTextureHeight.value=B.textureHeight,y.uniforms.cellSize.value=B.cellSize,s.setRenderTarget(p[D]),s.render(g,l)}s.autoClear=k,s.setClearColor(A,_),s.setRenderTarget(null)}let I=!1;function R(q,k,A){if(!s||!b||!m||!l)return;if(m.uniforms.positionsTexture.value=k,m.uniforms.alpha.value=q,!I){m.uniforms.randomValues.value=h?.texture,m.uniforms.strength.value=n,m.uniforms.theta.value=i,m.uniforms.spaceSize.value=d,m.uniforms.distanceMin.value=r,m.uniforms.distanceMax.value=o===1/0?d*10:o;for(let D=0;D<f;D++)m.uniforms[`level${D}`].value=p[D].texture;I=!0}let _=s.autoClear;s.autoClear=!1,s.setRenderTarget(A),s.render(b,l),s.autoClear=_,s.setRenderTarget(null)}let U=Math.random;return w.initialize=function(q,k,A){e=q,t=A,U=k},w.initGPU=function(q){s=q.renderer,l=q.camera,u=q.textureSize,c=q.nodeCount;let k=$e(c,t),A=Math.min(20,6+Math.log10(Math.max(c,2))),_=Math.max(40,k*A);_>8192&&console.warn(`[ManyBody Octree 3D] paddedSpaceSize=${_.toFixed(0)} exceeds cap 8192; clamping. N=${c} may have boundary spike. Consider Option B adaptive resize.`),d=Math.min(8192,Math.pow(2,Math.ceil(Math.log2(_))));let D=s.getContext(),B=D.getParameter(D.MAX_TEXTURE_SIZE);console.log(`[ManyBody Octree 3D] GPU MAX_TEXTURE_SIZE = ${B}`);let P=Math.floor(Math.log2(B)/2),L=Math.min(Math.floor(Math.log2(d)),P,8);f=a!==null?Math.min(a,L):L,console.log(`[ManyBody Octree 3D] nodeCount=${c}, spaceSize=${d}, maxGPUTexture=${B}`),console.log(`[ManyBody Octree 3D] calculatedLevels=${L}, initialOctreeLevels=${f}`),console.log(`[ManyBody Octree 3D] theta=${i}, strength=${n}`);let Y=new Float32Array(u*u*4);for(let F=0;F<u*u;F++)Y[F*4]=U(),Y[F*4+1]=U(),Y[F*4+2]=U(),Y[F*4+3]=0;let X=new J.DataTexture(Y,u,u,J.RGBAFormat,J.FloatType);X.needsUpdate=!0,h?.dispose(),h=new J.WebGLRenderTarget(u,u,{type:J.FloatType,format:J.RGBAFormat,minFilter:J.NearestFilter,magFilter:J.NearestFilter,generateMipmaps:!1,depthBuffer:!1,stencilBuffer:!1});let H=new J.ShaderMaterial({uniforms:{tDiffuse:{value:X}},vertexShader:ge,fragmentShader:`
|
|
2134
2134
|
precision highp float;
|
|
2135
2135
|
uniform sampler2D tDiffuse;
|
|
2136
2136
|
varying vec2 vUv;
|
|
2137
2137
|
void main() { gl_FragColor = texture2D(tDiffuse, vUv); }
|
|
2138
|
-
`}),
|
|
2138
|
+
`}),T=new J.Scene,G=new J.Mesh(we(),H);T.add(G),s.setRenderTarget(h),s.render(T,l),s.setRenderTarget(null),H.dispose(),G.geometry.dispose(),X.dispose(),p.forEach(F=>F.dispose()),p=[],x=[];for(let F=0;F<f;F++){let W=Math.pow(2,F+1),j=W*W,ne=W;if(j>B||ne>B){console.error(`[ManyBody Octree 3D] Level ${F} texture ${j}\xD7${ne} exceeds GPU limit ${B}! Skipping remaining levels.`),f=F;break}let ye=new J.WebGLRenderTarget(j,ne,{type:J.FloatType,format:J.RGBAFormat,minFilter:J.NearestFilter,magFilter:J.NearestFilter,generateMipmaps:!1,depthBuffer:!1,stencilBuffer:!1});p.push(ye),x.push({levelSize:W,textureWidth:j,textureHeight:ne,cellSize:d/W}),console.log(`[ManyBody Octree 3D] Level ${F}: grid=${W}\xB3, texture=${j}\xD7${ne}`)}let $=Math.min(f,8),K=Math.min(f,$),Z=f-K;console.log(`[ManyBody Octree 3D] Final: octreeLevels=${f}, shaderStartLevel=${K}, delta=${Z}`);let S;if(c!==C){let F=new Float32Array(c*2),W=new Float32Array(c*3);for(let j=0;j<c;j++)F[j*2]=j%u,F[j*2+1]=Math.floor(j/u),W[j*3]=0,W[j*3+1]=0,W[j*3+2]=0;S=new J.BufferGeometry,S.setAttribute("position",new J.BufferAttribute(W,3)),S.setAttribute("pointIndex",new J.BufferAttribute(F,2)),C=c}else S=M.geometry;if(y?.dispose(),y=new J.ShaderMaterial({uniforms:{positionTexture:{value:null},pointsTextureSize:{value:u},levelSize:{value:2},levelTextureWidth:{value:4},levelTextureHeight:{value:2},cellSize:{value:d/2},spaceSize:{value:d}},vertexShader:fa,fragmentShader:pa,blending:J.AdditiveBlending,depthTest:!1,depthWrite:!1}),g||(g=new J.Scene),M){if(M.material=y,c!==C){let F=M.geometry;M.geometry=S,F.dispose()}}else M=new J.Points(S,y),g.add(M);m?.dispose(),I=!1;let z={positionsTexture:{value:null},randomValues:{value:null},spaceSize:{value:d},strength:{value:n},theta:{value:i},alpha:{value:1},distanceMin:{value:r},distanceMax:{value:o===1/0?d*10:o}};for(let F=0;F<f;F++)z[`level${F}`]={value:null};let N=ha(K,f);m=new J.ShaderMaterial({uniforms:z,vertexShader:ge,fragmentShader:N,blending:J.AdditiveBlending,depthTest:!1,depthWrite:!1}),b||(b=new J.Scene),v?v.material=m:(v=new J.Mesh(we(),m),b.add(v))},w.dispose=function(){p.forEach(q=>q.dispose()),p=[],x=[],I=!1,h?.dispose(),h=null,y?.dispose(),m?.dispose(),M?.geometry.dispose(),v?.geometry.dispose()},w.apply=w,w.strength=function(q){return arguments.length===0?n:(n=+q,m&&(m.uniforms.strength.value=n),w)},w.theta=function(q){return arguments.length===0?i:(i=+q,I=!1,w)},w.distanceMin=function(q){return arguments.length===0?r:(r=+q,I=!1,w)},w.distanceMax=function(q){return arguments.length===0?o:(o=+q,I=!1,w)},w.maxLevels=function(q){return arguments.length===0?a??null:(a=q>0?Math.min(q,8):null,I=!1,w)},w.getSpaceSize=function(){return typeof d=="number"&&d>0?d:10},w}var ga=`/**
|
|
2139
2139
|
* Link force vertex shader
|
|
2140
2140
|
*
|
|
2141
2141
|
* Each point represents one endpoint of a link.
|
|
@@ -2167,7 +2167,7 @@ void main() {
|
|
|
2167
2167
|
gl_Position = vec4(pos, 0.0, 1.0);
|
|
2168
2168
|
gl_PointSize = 1.0;
|
|
2169
2169
|
}
|
|
2170
|
-
`,
|
|
2170
|
+
`,ya=`/**
|
|
2171
2171
|
* Link force fragment shader
|
|
2172
2172
|
*
|
|
2173
2173
|
* Implements d3-force's forceLink spring behavior:
|
|
@@ -2267,7 +2267,7 @@ void main() {
|
|
|
2267
2267
|
// Note: alpha must be 1.0 for THREE.AdditiveBlending to work (uses SrcAlphaFactor)
|
|
2268
2268
|
gl_FragColor = vec4(velocity, 1.0);
|
|
2269
2269
|
}
|
|
2270
|
-
`;function
|
|
2270
|
+
`;function va(e){let t=[],n=e||[],i=2,r=Math.random,o=k=>k.index,a=C,s=ae(30),l=1,u=[],c=[],d=[],f=[],p=null,h=null,g=null,y=0,M=0,b=null,m=null,v=null,w=null,x=0;function C(k){let A=typeof k.source=="object"?k.source.index:0,_=typeof k.target=="object"?k.target.index:0;return 1/Math.min(u[A]||1,u[_]||1)}function E(){if(!t||t.length===0)return;let k=t.length,A=n.length,_=new Map;for(let P=0;P<k;P++)_.set(o(t[P],P,t),t[P]);u=new Array(k).fill(0);for(let P=0;P<A;P++){let L=n[P];if(L.index=P,typeof L.source!="object"){let Y=_.get(L.source);if(!Y)throw new Error(`Link source not found: ${L.source}`);L.source=Y}if(typeof L.target!="object"){let Y=_.get(L.target);if(!Y)throw new Error(`Link target not found: ${L.target}`);L.target=Y}u[L.source.index]++,u[L.target.index]++}c=new Array(A);for(let P=0;P<A;P++){let L=n[P],Y=L.source.index,X=L.target.index;c[P]=u[Y]/(u[Y]+u[X])}d=new Array(A),f=new Array(A);let D=typeof a=="function"?a:()=>a,B=typeof s=="function"?s:()=>s;for(let P=0;P<A;P++)d[P]=+D(n[P],P,n),f[P]=+B(n[P],P,n);I()}function I(){if(!w||n.length===0)return;let k=w.image.data;for(let A=0;A<n.length;A++){let _=n[A],D=_.source.index,B=_.target.index,P=A*4;k[P]=D,k[P+1]=B,k[P+2]=f[A],k[P+3]=d[A]}w.needsUpdate=!0}function R(k,A,_){if(n.length!==0){if(!p||!A||!_||M===0){U(k);return}q(k,A,_)}}function U(k){for(let A=0;A<l;A++)for(let _=0;_<n.length;_++){let D=n[_],B=D.source,P=D.target,L=(P.x||0)+(P.vx||0)-(B.x||0)-(B.vx||0)||mt(r),Y=i>1?(P.y||0)+(P.vy||0)-(B.y||0)-(B.vy||0)||mt(r):0,X=i>2?(P.z||0)+(P.vz||0)-(B.z||0)-(B.vz||0)||mt(r):0,H=Math.sqrt(L*L+Y*Y+X*X);H=(H-f[_])/H*k*d[_],L*=H,Y*=H,X*=H;let T=c[_];P.vx-=L*T,i>1&&(P.vy-=Y*T),i>2&&(P.vz-=X*T),B.vx+=L*(1-T),i>1&&(B.vy+=Y*(1-T)),i>2&&(B.vz+=X*(1-T))}}function q(k,A,_){if(!b||!v)return;v.uniforms.positionTexture.value=A,v.uniforms.linkTexture.value=w,v.uniforms.linkTextureSize.value=x,v.uniforms.nodeTextureSize.value=y,v.uniforms.nodeCount.value=M,v.uniforms.alpha.value=k,v.uniforms.nDim.value=i;let D=p.autoClear;p.autoClear=!1;for(let B=0;B<l;B++)p.setRenderTarget(_),h&&p.render(h,g);p.autoClear=D,p.setRenderTarget(null)}return R.initialize=function(k,A,_){t=k,r=A,i=_,E()},R.initGPU=function(k){if(p=k.renderer,g=k.camera,y=k.textureSize,M=k.nodeCount,n.length===0)return;x=Gt(n.length);let A=new Float32Array(x*x*4);A.fill(-1);for(let P=0;P<n.length;P++){let L=n[P],Y=L.source.index,X=L.target.index,H=P*4;A[H]=Y,A[H+1]=X,A[H+2]=f[P],A[H+3]=d[P]}w?.dispose(),w=new oe.DataTexture(A,x,x,oe.RGBAFormat,oe.FloatType),w.needsUpdate=!0;let _=n.length*2,D=new Float32Array(_*2);for(let P=0;P<n.length;P++){let L=n[P],Y=L.source.index,X=L.target.index;D[P*4]=P*2,D[P*4+1]=Y,D[P*4+2]=P*2+1,D[P*4+3]=X}m?.dispose(),m=new oe.BufferGeometry,m.setAttribute("linkEndpoint",new oe.BufferAttribute(D,2));let B=new Float32Array(D.length/2*3);m.setAttribute("position",new oe.BufferAttribute(B,3)),v?.dispose(),v=new oe.ShaderMaterial({uniforms:{positionTexture:{value:null},linkTexture:{value:w},linkTextureSize:{value:x},nodeTextureSize:{value:y},nodeCount:{value:M},alpha:{value:1},nDim:{value:i}},vertexShader:ga,fragmentShader:ya,blending:oe.AdditiveBlending,depthTest:!1,depthWrite:!1}),b&&h&&h.remove(b),h=new oe.Scene,b=new oe.Points(m,v),h.add(b)},R.dispose=function(){w?.dispose(),m?.dispose(),v?.dispose(),b&&h?.remove(b)},R.apply=R,R.links=function(k){return arguments.length===0?n:(n=k,E(),R)},R.id=function(k){return arguments.length===0?o:(o=k,R)},R.iterations=function(k){return arguments.length===0?l:(l=+k,R)},R.strength=function(k){return arguments.length===0?a:(a=typeof k=="function"?k:ae(+k),E(),I(),R)},R.distance=function(k){return arguments.length===0?s:(s=typeof k=="function"?k:ae(+k),E(),I(),R)},R}var Ot=`/**
|
|
2271
2271
|
* Position force shader (forceX/Y/Z)
|
|
2272
2272
|
*
|
|
2273
2273
|
* Implements d3-force's forceX/forceY/forceZ:
|
|
@@ -2324,5 +2324,5 @@ void main() {
|
|
|
2324
2324
|
// Note: alpha must be 1.0 for THREE.AdditiveBlending to work (uses SrcAlphaFactor)
|
|
2325
2325
|
gl_FragColor = vec4(velocity, 1.0);
|
|
2326
2326
|
}
|
|
2327
|
-
`;function ha(e){let t=[],n=te(.1),i=e==null?te(0):typeof e=="function"?e:te(+e),r=[],o=[],a=null,s=null,l=null,u=0,c=0,f=null,d=null,p=null;function m(){if(!t)return;let h=t.length;r=new Array(h),o=new Array(h);let v=typeof i=="function"?i:()=>i,b=typeof n=="function"?n:()=>n;for(let x=0;x<h;x++)o[x]=+v(t[x],x,t),r[x]=isNaN(o[x])?0:+b(t[x],x,t);p&&u>0&&g()}function g(){let h=u*u,v=new Float32Array(h*4);for(let b=0;b<t.length;b++){let x=b*4;v[x]=o[b]??0,v[x+1]=r[b]??0,v[x+2]=0,v[x+3]=0}p.image.data.set(v),p.needsUpdate=!0}function y(h,v,b){if(!a||!v||!b||c===0||!d||!p){w(h);return}M(h,v,b)}function w(h){for(let v=0;v<t.length;v++){let b=t[v];b.vx+=(o[v]-(b.x||0))*r[v]*h}}function M(h,v,b){d.uniforms.positionTexture.value=v,d.uniforms.targetTexture.value=p,d.uniforms.alpha.value=h,d.uniforms.textureSize.value=u,d.uniforms.nodeCount.value=c,d.uniforms.axis.value=0;let x=a.autoClear;a.autoClear=!1,a.setRenderTarget(b),a.render(s,l),a.autoClear=x,a.setRenderTarget(null)}return y.initialize=function(h,v,b){t=h,m()},y.initGPU=function(h){a=h.renderer,l=h.camera,u=h.textureSize,c=h.nodeCount,t.length>0&&(o.length===0||r.length===0)&&m();let v=u*u,b=new Float32Array(v*4),x=0,C=0;for(let E=0;E<t.length;E++){let A=E*4;b[A]=o[E]??0,b[A+1]=r[E]??0,b[A+2]=0,b[A+3]=0,E<10&&(x+=r[E]??0,C+=o[E]??0)}p?.dispose(),p=new ae.DataTexture(b,u,u,ae.RGBAFormat,ae.FloatType),p.minFilter=ae.NearestFilter,p.magFilter=ae.NearestFilter,p.needsUpdate=!0,s=new ae.Scene,d=new ae.ShaderMaterial({uniforms:{positionTexture:{value:null},targetTexture:{value:p},alpha:{value:1},textureSize:{value:u},nodeCount:{value:c},axis:{value:0}},vertexShader:he,fragmentShader:Lt,blending:ae.AdditiveBlending,depthTest:!1,depthWrite:!1}),f=new ae.Mesh(ye(),d),s.add(f)},y.dispose=function(){p?.dispose(),d?.dispose(),f&&(f.geometry.dispose(),s?.remove(f))},y.apply=y,y.strength=function(h){return arguments.length===0?n:(n=typeof h=="function"?h:te(+h),m(),y)},y.x=function(h){return arguments.length===0?i:(i=typeof h=="function"?h:te(+h),m(),y)},y}function ma(e){let t=[],n=te(.1),i=e==null?te(0):typeof e=="function"?e:te(+e),r=[],o=[],a=null,s=null,l=null,u=0,c=0,f=null,d=null,p=null;function m(){if(!t)return;let h=t.length;r=new Array(h),o=new Array(h);let v=typeof i=="function"?i:()=>i,b=typeof n=="function"?n:()=>n;for(let x=0;x<h;x++)o[x]=+v(t[x],x,t),r[x]=isNaN(o[x])?0:+b(t[x],x,t);p&&u>0&&g()}function g(){let h=u*u,v=new Float32Array(h*4);for(let b=0;b<t.length;b++){let x=b*4;v[x]=o[b]??0,v[x+1]=r[b]??0,v[x+2]=0,v[x+3]=0}p.image.data.set(v),p.needsUpdate=!0}function y(h,v,b){if(!a||!v||!b||c===0||!d||!p){w(h);return}M(h,v,b)}function w(h){for(let v=0;v<t.length;v++){let b=t[v];b.vy+=(o[v]-(b.y||0))*r[v]*h}}function M(h,v,b){d.uniforms.positionTexture.value=v,d.uniforms.targetTexture.value=p,d.uniforms.alpha.value=h,d.uniforms.textureSize.value=u,d.uniforms.nodeCount.value=c,d.uniforms.axis.value=1;let x=a.autoClear;a.autoClear=!1,a.setRenderTarget(b),a.render(s,l),a.autoClear=x,a.setRenderTarget(null)}return y.initialize=function(h,v,b){t=h,m()},y.initGPU=function(h){a=h.renderer,l=h.camera,u=h.textureSize,c=h.nodeCount,t.length>0&&(o.length===0||r.length===0)&&m();let v=u*u,b=new Float32Array(v*4),x=0,C=0;for(let E=0;E<t.length;E++){let A=E*4,R=o[E]??0,I=r[E]??0;b[A]=R,b[A+1]=I,b[A+2]=0,b[A+3]=0,E<10&&(x+=R,C+=I)}t.length>0,p?.dispose(),p=new oe.DataTexture(b,u,u,oe.RGBAFormat,oe.FloatType),p.minFilter=oe.NearestFilter,p.magFilter=oe.NearestFilter,p.needsUpdate=!0,s=new oe.Scene,d=new oe.ShaderMaterial({uniforms:{positionTexture:{value:null},targetTexture:{value:p},alpha:{value:1},textureSize:{value:u},nodeCount:{value:c},axis:{value:1}},vertexShader:he,fragmentShader:Lt,blending:oe.AdditiveBlending,depthTest:!1,depthWrite:!1}),f=new oe.Mesh(ye(),d),s.add(f)},y.dispose=function(){p?.dispose(),d?.dispose(),f&&(f.geometry.dispose(),s?.remove(f))},y.apply=y,y.strength=function(h){return arguments.length===0?n:(n=typeof h=="function"?h:te(+h),m(),y)},y.y=function(h){return arguments.length===0?i:(i=typeof h=="function"?h:te(+h),m(),y)},y}function ga(e){let t=[],n=te(.1),i=e==null?te(0):typeof e=="function"?e:te(+e),r=[],o=[],a=null,s=null,l=null,u=0,c=0,f=null,d=null,p=null;function m(){if(!t)return;let h=t.length;r=new Array(h),o=new Array(h);let v=typeof i=="function"?i:()=>i,b=typeof n=="function"?n:()=>n;for(let x=0;x<h;x++)o[x]=+v(t[x],x,t),r[x]=isNaN(o[x])?0:+b(t[x],x,t);p&&u>0&&g()}function g(){let h=u*u,v=new Float32Array(h*4);for(let b=0;b<t.length;b++){let x=b*4;v[x]=o[b]??0,v[x+1]=r[b]??0,v[x+2]=0,v[x+3]=0}p.image.data.set(v),p.needsUpdate=!0}function y(h,v,b){if(!a||!v||!b||c===0||!d||!p){w(h);return}M(h,v,b)}function w(h){for(let v=0;v<t.length;v++){let b=t[v];b.vz+=(o[v]-(b.z||0))*r[v]*h}}function M(h,v,b){d.uniforms.positionTexture.value=v,d.uniforms.targetTexture.value=p,d.uniforms.alpha.value=h,d.uniforms.textureSize.value=u,d.uniforms.nodeCount.value=c,d.uniforms.axis.value=2;let x=a.autoClear;a.autoClear=!1,a.setRenderTarget(b),a.render(s,l),a.autoClear=x,a.setRenderTarget(null)}return y.initialize=function(h,v,b){t=h,m()},y.initGPU=function(h){a=h.renderer,l=h.camera,u=h.textureSize,c=h.nodeCount,t.length>0&&(o.length===0||r.length===0)&&m();let v=u*u,b=new Float32Array(v*4);for(let x=0;x<t.length;x++){let C=x*4;b[C]=o[x]??0,b[C+1]=r[x]??0,b[C+2]=0,b[C+3]=0}p?.dispose(),p=new se.DataTexture(b,u,u,se.RGBAFormat,se.FloatType),p.minFilter=se.NearestFilter,p.magFilter=se.NearestFilter,p.needsUpdate=!0,s=new se.Scene,d=new se.ShaderMaterial({uniforms:{positionTexture:{value:null},targetTexture:{value:p},alpha:{value:1},textureSize:{value:u},nodeCount:{value:c},axis:{value:2}},vertexShader:he,fragmentShader:Lt,blending:se.AdditiveBlending,depthTest:!1,depthWrite:!1}),f=new se.Mesh(ye(),d),s.add(f)},y.dispose=function(){p?.dispose(),d?.dispose(),f&&(f.geometry.dispose(),s?.remove(f))},y.apply=y,y.strength=function(h){return arguments.length===0?n:(n=typeof h=="function"?h:te(+h),m(),y)},y.z=function(h){return arguments.length===0?i:(i=typeof h=="function"?h:te(+h),m(),y)},y}var ht={charge:-.01,gravity:.1,linkStrength:1,linkDistance:.5,collision:.15,heightCompress:1,alpha:.6,alphaDecay:.1,velocityDecay:.3,dimensions:3,gravityX:1,gravityY:1,gravityZ:1,octreeTheta:.9},Gt=class{constructor(e,t){if(this.simulation=null,this.getOptions=null,this._enable=!0,this._isFinish=!1,this.nodeIdToIndex=new Map,this.lastUpdateTime=0,this.updateIntervalMs=1e3/24,this.skipCPUPositionUpdate=!1,this._dimTransition=null,this._gpuZZeroed=!1,this.graph=e,t)this.renderer=t;else{let n=document.createElement("canvas");n.style.display="none",this.renderer=new ui.WebGLRenderer({canvas:n,alpha:!0,antialias:!1}),this.renderer.setSize(256,256)}this.params={...ht}}config(e){if(this.getOptions=e,e){let t=e();t&&this.applyConfig(t)}return this}configure(e){return this.config(e)}applyConfig(e){e.friction!==void 0&&e.velocityDecay===void 0&&(e.velocityDecay=e.friction),Object.assign(this.params,e)}calculateForces(){let e=this.params.heightCompress??1,t=this.params.gravity??.1,n=this.params.dimensions??3,i,r,o,a;return n===2?(r=t*1.5,i=0,o=.02,a=.8):(i=t*Math.sqrt(e),r=t/Math.sqrt(e),i=i>10?10:i,o=ht.alphaDecay??.1,a=ht.alpha??.6),{forcexy:r,forcez:i,alphaDecay:o,alpha:a}}startLayout(e=0,t=0,n=!1){let i=this.params.dimensions;if(this.getOptions){let _=this.getOptions();_&&this.applyConfig(_)}this.params.dimensions=i,this._gpuZZeroed=!1;let r=this.graph.layoutNodes||[],o=this.graph.layoutEdges||[];if(r.length===0)return;this.nodeIdToIndex.clear(),r.forEach((_,z)=>{this.nodeIdToIndex.set(_.id,z)});let a=this.params.dimensions??3;this.params.dimensions=a;let s=r.some(_=>Math.abs(_.position.z)>1e-6),l=Math.cbrt(r.length)*2,u=a>2&&!s&&!n,c=r.map((_,z)=>{let P=_.position.x,T=_.position.y,k=a<=2?0:_.position.z;if(u&&!_.pinned){let q=Math.random(),N=Math.random(),G=Math.random(),S=2*Math.PI*q,D=Math.acos(2*N-1),O=Math.cbrt(G)*l;P=O*Math.sin(D)*Math.cos(S),T=O*Math.sin(D)*Math.sin(S),k=O*Math.cos(D)}return{..._,index:z,x:P,y:T,z:k,vx:0,vy:0,vz:0,fx:_.pinned?_.position.x:null,fy:_.pinned?_.position.y:null,fz:_.pinned?_.position.z:null}}),f=o.filter(_=>{let z=this.nodeIdToIndex.get(_.sourceId),P=this.nodeIdToIndex.get(_.targetId);return z!==void 0&&P!==void 0}).map(_=>({source:_.sourceId,target:_.targetId}));this.simulation&&(this.simulation.stop(),this.simulation.dispose()),this.simulation=Kr(c,a,this.renderer);let{forcexy:d,forcez:p,alphaDecay:m,alpha:g}=this.calculateForces(),y=this.params.charge??-.01,w=r.length,M=this.params.gravityX??1,h=this.params.gravityY??1,v=this.params.gravityZ??1,b=this.params.linkDistance??.5,x=this.params.linkStrength??1,C=d*this.params.gravityX,E=d*this.params.gravityY,A=p*this.params.gravityZ,R=ha(0).strength(C),I=ma(0).strength(E);if(this.simulation.force("x",R),this.simulation.force("y",I),a>2){let _=ga(0).strength(A);this.simulation.force("z",_)}if(this.simulation.force("center",na(0,0,0).strength(1)),a>2){let _=ca();_.strength(y);let z=this.params.octreeTheta??.8,P=r.length,T=Math.max(.2,Math.min(1,1.2-.1*Math.log10(Math.max(P,1)))),k=z*T;_.theta(k);let q=this.params.octreeLevels;q!==void 0&&_.maxLevels(q),this.simulation.force("charge",_)}else{let _=oa();_.strength(y);let z=this.params.quadtreeTheta??.9,P=Math.max(.5,Math.min(1,500/Math.sqrt(r.length))),T=z*P;_.theta(T),this.simulation.force("charge",_)}if(f.length>0){let _=pa(f);_.distance(b),_.strength(x),_.id(z=>z.id),this.simulation.force("link",_)}(this.params.collision??.15)>0;let B=this.params.velocityDecay??ht.velocityDecay;this.simulation.alpha(g).alphaMin(.001).alphaDecay(m).velocityDecay(B),this.simulation.on("tick",()=>{this.onTick()}),this.simulation.on("end",()=>{this._isFinish=!0,this.graph.renderNeedsUpdate=!1}),this._isFinish=!1,this._enable=!0,this.graph.renderNeedsUpdate=!0,this.skipCPUPositionUpdate&&this.simulation.setSkipCPUReadback(!0),this.simulation.restart()}onTick(){if(!this._enable||!this.simulation)return;if(this.skipCPUPositionUpdate){(this.params.dimensions??3)<=2&&this.ensureGPUZeroZ(),this.graph.renderNeedsUpdate=!0;return}let e=performance.now();if(e-this.lastUpdateTime<this.updateIntervalMs)return;this.lastUpdateTime=e;let t=this.simulation.nodes(),n=this.params.dimensions??3;t.forEach(i=>{let r=this.nodeIdToIndex.get(i.id);if(r!==void 0&&r<this.graph.layoutNodes.length){let o=this.graph.layoutNodes[r];o&&!o.pinned&&i.fx==null&&(o.position.x=i.x??0,o.position.y=i.y??0,n>2?o.position.z=i.z??0:o.position.z=0,o.isPositionDirty=!0)}}),this.graph.renderNeedsUpdate=!0}ensureGPUZeroZ(){if(this._gpuZZeroed||!this.simulation)return;this._gpuZZeroed=!0,this.simulation.readBackPositions();let e=this.simulation.nodes(),t=[];e.forEach((i,r)=>{Math.abs(i.z??0)>1e-6&&t.push({index:r,x:i.x??0,y:i.y??0,z:0})}),t.length>0&&this.simulation.uploadNodePositions(t);let n=this.graph.layoutNodes;for(let i=0;i<n.length;i++)n[i].position.z=0}restartLayout(){if(!this.simulation||!this._enable)return;if(this.getOptions){let w=this.getOptions();w&&this.applyConfig(w)}let e=this.params.dimensions??3,{forcexy:t,forcez:n,alphaDecay:i,alpha:r}=this.calculateForces(),o=this.params.charge??-.01,a=this.params.linkDistance??.5,s=this.params.linkStrength??1,l=t*(this.params.gravityX??1),u=t*(this.params.gravityY??1),c=n*(this.params.gravityZ??1),f=this.simulation.force("x"),d=this.simulation.force("y"),p=this.simulation.force("z"),m=this.simulation.force("charge"),g=this.simulation.force("link");f&&f.strength(l),d&&d.strength(u),p&&e>2&&p.strength(c),m&&m.strength(o),g&&(g.distance(a),g.strength(s));let y=this.params.velocityDecay??.3;this.simulation.alpha(r).alphaDecay(i).velocityDecay(y).restart(),this._isFinish=!1,this.graph.renderNeedsUpdate=!0}stopLayout(){this.simulation&&this.simulation.stop(),this._isFinish=!0,this.graph.renderNeedsUpdate=!1}updateLayoutOption(e,t){if(e==="friction"?this.params.velocityDecay=t:this.params[e]=t,!this.simulation||!this._enable)return;let n=this.simulation.force("charge"),i=this.simulation.force("link"),r=this.simulation.force("x"),o=this.simulation.force("y"),a=this.simulation.force("z");switch(e){case"charge":n&&(n.strength(t),this.simulation.alpha(Math.max(this.simulation.alpha(),.3)).restart());break;case"linkDistance":i&&(i.distance(t),this.simulation.alpha(Math.max(this.simulation.alpha(),.3)).restart());break;case"linkStrength":i&&(i.strength(t),this.simulation.alpha(Math.max(this.simulation.alpha(),.3)).restart());break;case"gravity":case"gravityX":case"gravityY":case"gravityZ":case"heightCompress":let{forcexy:s,forcez:l}=this.calculateForces(),u=s*(this.params.gravityX??1),c=s*(this.params.gravityY??1),f=l*(this.params.gravityZ??1);r&&r.strength(u),o&&o.strength(c),a&&a.strength(f),this.simulation.alpha(Math.max(this.simulation.alpha(),.3)).restart();break;case"velocityDecay":case"friction":this.simulation.velocityDecay(this.params.velocityDecay??.3);break;case"alpha":case"alphaDecay":this.restartLayout();break;default:this.restartLayout();break}this.graph.renderNeedsUpdate=!0}pinNodes(e){if(!this.simulation)return;let t=this.simulation.nodes(),n=[];e.forEach(r=>{let o=this.nodeIdToIndex.get(r.id);if(o!==void 0){let a=this.graph.layoutNodes[o];a&&(a.pinned=!0);let s=t[o];s&&(s.fx=r.position.x,s.fy=r.position.y,s.fz=r.position.z,n.push({index:o,x:r.position.x,y:r.position.y,z:r.position.z}))}}),n.length>0&&this.simulation.uploadNodePositions(n);let i=n.map(r=>({index:r.index,isPinned:!0}));this.simulation.updatePinnedNodes(i),this._enable&&this.simulation.alpha()<.1&&this.simulation.alpha(.3).restart(),this.graph.renderNeedsUpdate=!0}unpinNodes(e){if(!this.simulation)return;let t=this.simulation.nodes(),n=[];for(let i of e){let r=this.nodeIdToIndex.get(i);if(r===void 0)continue;let o=this.graph.layoutNodes[r];o&&(o.pinned=!1);let a=t[r];a&&(a.fx=null,a.fy=null,a.fz=null),n.push({index:r,isPinned:!1})}n.length>0&&this.simulation.updatePinnedNodes(n),this._enable&&this.simulation.alpha()<.05&&this.simulation.alpha(.15).restart(),this.graph.renderNeedsUpdate=!0}set enable(e){this._enable=e,!e&&this.simulation&&this.simulation.stop(),this._isFinish=!e,this.graph.renderNeedsUpdate=e}get enable(){return this._enable}get isFinish(){return this._isFinish}setExpectedNodeCount(e){}clearExpectedNodeCount(){}updateGraph(e,t,n=!1){this.startLayout()}destroy(){this.cancelDimensionTransition(),this.simulation&&(this.simulation.stop(),this.simulation.dispose(),this.simulation=null)}transitionDimensions(e,t=600){(this.params.dimensions??3)!==e&&(e===2?this.transition3Dto2D(t):this.transition2Dto3D())}transition3Dto2D(e){this.readBackPositions(),this.params.dimensions=2,this.startLayout(0,0,!0)}transition2Dto3D(){this.readBackPositions(),this.params.dimensions=3,this.startLayout()}cancelDimensionTransition(){this._dimTransition=null}getDimensions(){return this.params.dimensions??3}debugNodePositions(){let e=this.simulation?this.simulation.nodes():[];if(this.simulation&&e.length>0)for(let n=0;n<Math.min(3,e.length);n++){let i=e[n]}let t=this.graph.layoutNodes||[];if(t.length>0){for(let n=0;n<Math.min(3,t.length);n++){let i=t[n]}if(this.simulation&&e.length>0)for(let n=0;n<Math.min(3,Math.min(e.length,t.length));n++){let i=e[n],r=t.find(o=>o.id===i.id);if(r){let o=Math.abs((i.x??0)-r.position.x)<.001&&Math.abs((i.y??0)-r.position.y)<.001&&Math.abs((i.z??0)-r.position.z)<.001}}}}getPositionTexture(){return this.simulation?this.simulation.getPositionTexture():null}getTextureSize(){return this.simulation?this.simulation.getTextureSize():0}getSpaceSize(){return this.simulation?this.simulation.getSpaceSize():10}debugGPUPositions(e=5){return this.simulation?this.simulation.debugPositions(e):null}setSkipCPUReadback(e){this.skipCPUPositionUpdate=e,this.simulation&&this.simulation.setSkipCPUReadback(e)}readBackPositions(){if(this.simulation){this.simulation.readBackPositions();let e=this.simulation.nodes(),t=this.params.dimensions??3;e.forEach(n=>{let i=this.nodeIdToIndex.get(n.id);if(i!==void 0&&i<this.graph.layoutNodes.length){let r=this.graph.layoutNodes[i];r&&(r.position.x=n.x??0,r.position.y=n.y??0,r.position.z=t>2?n.z??0:0)}})}}debugTick(){if(!this.simulation)return;this.simulation.nodes().length>0,this.simulation.tick(1),this.simulation.nodes().length>0,this.onTick()}debugZDistribution(){if(!this.simulation)return;let e=this.simulation.nodes();if(e.length===0)return;let t=1/0,n=-1/0,i=0,r=0,o=[];e.forEach(m=>{let g=m.z||0;t=Math.min(t,g),n=Math.max(n,g),i+=g,r++,o.push(g)});let a=i/r,s=n-t,l=0;o.forEach(m=>{l+=Math.pow(m-a,2)});let u=Math.sqrt(l/r),c=s*.1,f=o.filter(m=>Math.abs(m-t)<c).length,d=o.filter(m=>Math.abs(m-n)<c).length,p=(f+d)/r}},Nt=class{constructor(e){this.c=e,this.mode="gpu"}getPositionTexture(){return this.c.getPositionTexture()}getTextureSize(){return this.c.getTextureSize()}getSpaceSize(){return this.c.getSpaceSize()}tick(){}start(){this.c.startLayout()}stop(){this.c.stopLayout()}get graph(){return this.c.graph}get needsUpdate(){return!this.c.isFinish}clearNeedsUpdate(){}pinNodes(e){this.c.pinNodes(e)}unpinNodes(e){this.c.unpinNodes(e)}transitionDimensions(e,t){this.c.transitionDimensions(e,t)}getDimensions(){return this.c.getDimensions()}updateOption(e,t){this.c.updateLayoutOption(e,t)}};function ci(e){let{backend:t="auto",renderer:n,config:i,graph:r,autoStart:o=!0}=e,a;t==="webgpu"?Pe()?a="webgpu":(console.warn('[createForceLayout] backend="webgpu" requested but navigator.gpu is unavailable; falling back to WebGL.'),a="webgl"):t==="webgl"?a="webgl":a=Pe()?"webgpu":"webgl";let s=r??{layoutNodes:[],layoutEdges:[],renderNeedsUpdate:!0};if(a==="webgpu"){let l=new ft(s);l.config(i);let u=new pt(l);return o&&l.startLayout(),{controller:l,adapter:u,backend:"webgpu"}}else{let l=new Gt(s,n);l.config(i);let u=new Nt(l);return o&&l.startLayout(),{controller:l,adapter:u,backend:"webgl"}}}function ya(e,t){let n=new Map(e.nodes.map(a=>[a.id,{...a}])),i=new Map(e.edges.map(a=>[a.id,{...a}]));for(let a of t.addNodes??[])n.set(a.id,a);for(let a of t.addEdges??[])i.set(a.id,a);for(let a of t.updateNodes??[]){let s=n.get(a.id);s&&n.set(a.id,{...s,...a.changes})}for(let a of t.updateEdges??[]){let s=i.get(a.id);s&&i.set(a.id,{...s,...a.changes})}for(let a of t.removeNodeIds??[])n.delete(a);for(let a of t.removeEdgeIds??[])i.delete(a);for(let a of t.positionPatches??[]){let s=n.get(a.id);s&&n.set(a.id,{...s,position:a.position})}for(let a of t.pinPatches??[]){let s=n.get(a.id);if(s){let l={...s,pinned:a.pinned};a.position&&(l.position=a.position),n.set(a.id,l)}}let r=Array.from(n.values()).map((a,s)=>({...a,index:s})),o=Array.from(i.values()).map((a,s)=>({...a,index:s}));return{...e,version:t.graphVersion,nodes:r,edges:o}}var di=class{constructor(e,t,n={}){this.mode="gpu",this._status="idle",this._snapshot=null,this._tickCount=0,this._listeners=new Map,this.id=e,this.controller=t,this._settings={dimensions:3,...n}}get status(){return this._status}getCapabilities(){return{mode:"gpu",supportsGpuTexture:!0,supportsCpuReadback:!1,supportsIncrementalDelta:!1,supportsPinning:!0,supportsDimensions:!0}}init(e,t){this._status!=="disposed"&&(this._snapshot=e,t&&(this._settings={...this._settings,...t}),this._feedSnapshotToController(e),this._status="idle")}applyDelta(e){if(!this._snapshot||this._status==="disposed")return;this._snapshot=ya(this._snapshot,e);let t=this._status==="running";this._feedSnapshotToController(this._snapshot),t&&this._controllerStart()}tick(e){this._tickCount++,this.controller.tick&&this.controller.tick();let t=this._readNeedsUpdate(),n={tick:this._tickCount,didChangePositions:t,alpha:void 0};return this._emit("tick",n),n}start(){this._status!=="disposed"&&(this._controllerStart(),this._status="running",this._emit("started",{}))}stop(){this._status!=="disposed"&&(this._controllerStop(),this._status="stopped",this._emit("stopped",{}))}dispose(){this._controllerStop(),typeof this.controller.dispose=="function"?this.controller.dispose():typeof this.controller.destroy=="function"&&this.controller.destroy(),this._status="disposed",this._snapshot=null,this._listeners.clear()}getSettings(){return{...this._settings}}updateSettings(e){this._settings={...this._settings,...e}}setDimensions(e){this._settings={...this._settings,dimensions:e},typeof this.controller.transitionDimensions=="function"&&this.controller.transitionDimensions(e)}getReadback(){return{positions:null,texture:this.controller.getPositionTexture(),textureSize:this.controller.getTextureSize(),spaceSize:this.controller.getSpaceSize()}}getNodePosition(e){return null}setNodePosition(e,t){}pinNodes(e){this._status!=="disposed"&&typeof this.controller.pinNodes=="function"&&this.controller.pinNodes(e)}unpinNodes(e){this._status!=="disposed"&&typeof this.controller.unpinNodes=="function"&&this.controller.unpinNodes(e)}on(e,t){return this._listeners.has(e)||this._listeners.set(e,new Set),this._listeners.get(e).add(t),()=>this._listeners.get(e)?.delete(t)}_feedSnapshotToController(e){this._settings={...this._settings,dimensions:e.dimensions},typeof this.controller.startLayout=="function"&&this.controller.startLayout()}_controllerStart(){typeof this.controller.startLayout=="function"?this.controller.startLayout():typeof this.controller.start=="function"&&this.controller.start()}_controllerStop(){typeof this.controller.stopLayout=="function"?this.controller.stopLayout():typeof this.controller.stop=="function"&&this.controller.stop()}_readNeedsUpdate(){return this.controller.needsUpdate!==void 0?!!this.controller.needsUpdate:this.controller.graph!==void 0?!!this.controller.graph.renderNeedsUpdate:!1}_emit(e,t){this._listeners.get(e)?.forEach(n=>n(t))}};
|
|
2327
|
+
`;function xa(e){let t=[],n=ae(.1),i=e==null?ae(0):typeof e=="function"?e:ae(+e),r=[],o=[],a=null,s=null,l=null,u=0,c=0,d=null,f=null,p=null;function h(){if(!t)return;let m=t.length;r=new Array(m),o=new Array(m);let v=typeof i=="function"?i:()=>i,w=typeof n=="function"?n:()=>n;for(let x=0;x<m;x++)o[x]=+v(t[x],x,t),r[x]=isNaN(o[x])?0:+w(t[x],x,t);p&&u>0&&g()}function g(){let m=u*u,v=new Float32Array(m*4);for(let w=0;w<t.length;w++){let x=w*4;v[x]=o[w]??0,v[x+1]=r[w]??0,v[x+2]=0,v[x+3]=0}p.image.data.set(v),p.needsUpdate=!0}function y(m,v,w){if(!a||!v||!w||c===0||!f||!p){M(m);return}b(m,v,w)}function M(m){for(let v=0;v<t.length;v++){let w=t[v];w.vx+=(o[v]-(w.x||0))*r[v]*m}}function b(m,v,w){f.uniforms.positionTexture.value=v,f.uniforms.targetTexture.value=p,f.uniforms.alpha.value=m,f.uniforms.textureSize.value=u,f.uniforms.nodeCount.value=c,f.uniforms.axis.value=0;let x=a.autoClear;a.autoClear=!1,a.setRenderTarget(w),a.render(s,l),a.autoClear=x,a.setRenderTarget(null)}return y.initialize=function(m,v,w){t=m,h()},y.initGPU=function(m){a=m.renderer,l=m.camera,u=m.textureSize,c=m.nodeCount,t.length>0&&(o.length===0||r.length===0)&&h();let v=u*u,w=new Float32Array(v*4),x=0,C=0;for(let E=0;E<t.length;E++){let I=E*4;w[I]=o[E]??0,w[I+1]=r[E]??0,w[I+2]=0,w[I+3]=0,E<10&&(x+=r[E]??0,C+=o[E]??0)}p?.dispose(),p=new le.DataTexture(w,u,u,le.RGBAFormat,le.FloatType),p.minFilter=le.NearestFilter,p.magFilter=le.NearestFilter,p.needsUpdate=!0,s=new le.Scene,f=new le.ShaderMaterial({uniforms:{positionTexture:{value:null},targetTexture:{value:p},alpha:{value:1},textureSize:{value:u},nodeCount:{value:c},axis:{value:0}},vertexShader:ge,fragmentShader:Ot,blending:le.AdditiveBlending,depthTest:!1,depthWrite:!1}),d=new le.Mesh(we(),f),s.add(d)},y.dispose=function(){p?.dispose(),f?.dispose(),d&&(d.geometry.dispose(),s?.remove(d))},y.apply=y,y.strength=function(m){return arguments.length===0?n:(n=typeof m=="function"?m:ae(+m),h(),y)},y.x=function(m){return arguments.length===0?i:(i=typeof m=="function"?m:ae(+m),h(),y)},y}function ba(e){let t=[],n=ae(.1),i=e==null?ae(0):typeof e=="function"?e:ae(+e),r=[],o=[],a=null,s=null,l=null,u=0,c=0,d=null,f=null,p=null;function h(){if(!t)return;let m=t.length;r=new Array(m),o=new Array(m);let v=typeof i=="function"?i:()=>i,w=typeof n=="function"?n:()=>n;for(let x=0;x<m;x++)o[x]=+v(t[x],x,t),r[x]=isNaN(o[x])?0:+w(t[x],x,t);p&&u>0&&g()}function g(){let m=u*u,v=new Float32Array(m*4);for(let w=0;w<t.length;w++){let x=w*4;v[x]=o[w]??0,v[x+1]=r[w]??0,v[x+2]=0,v[x+3]=0}p.image.data.set(v),p.needsUpdate=!0}function y(m,v,w){if(!a||!v||!w||c===0||!f||!p){M(m);return}b(m,v,w)}function M(m){for(let v=0;v<t.length;v++){let w=t[v];w.vy+=(o[v]-(w.y||0))*r[v]*m}}function b(m,v,w){f.uniforms.positionTexture.value=v,f.uniforms.targetTexture.value=p,f.uniforms.alpha.value=m,f.uniforms.textureSize.value=u,f.uniforms.nodeCount.value=c,f.uniforms.axis.value=1;let x=a.autoClear;a.autoClear=!1,a.setRenderTarget(w),a.render(s,l),a.autoClear=x,a.setRenderTarget(null)}return y.initialize=function(m,v,w){t=m,h()},y.initGPU=function(m){a=m.renderer,l=m.camera,u=m.textureSize,c=m.nodeCount,t.length>0&&(o.length===0||r.length===0)&&h();let v=u*u,w=new Float32Array(v*4),x=0,C=0;for(let E=0;E<t.length;E++){let I=E*4,R=o[E]??0,U=r[E]??0;w[I]=R,w[I+1]=U,w[I+2]=0,w[I+3]=0,E<10&&(x+=R,C+=U)}t.length>0,p?.dispose(),p=new ue.DataTexture(w,u,u,ue.RGBAFormat,ue.FloatType),p.minFilter=ue.NearestFilter,p.magFilter=ue.NearestFilter,p.needsUpdate=!0,s=new ue.Scene,f=new ue.ShaderMaterial({uniforms:{positionTexture:{value:null},targetTexture:{value:p},alpha:{value:1},textureSize:{value:u},nodeCount:{value:c},axis:{value:1}},vertexShader:ge,fragmentShader:Ot,blending:ue.AdditiveBlending,depthTest:!1,depthWrite:!1}),d=new ue.Mesh(we(),f),s.add(d)},y.dispose=function(){p?.dispose(),f?.dispose(),d&&(d.geometry.dispose(),s?.remove(d))},y.apply=y,y.strength=function(m){return arguments.length===0?n:(n=typeof m=="function"?m:ae(+m),h(),y)},y.y=function(m){return arguments.length===0?i:(i=typeof m=="function"?m:ae(+m),h(),y)},y}function wa(e){let t=[],n=ae(.1),i=e==null?ae(0):typeof e=="function"?e:ae(+e),r=[],o=[],a=null,s=null,l=null,u=0,c=0,d=null,f=null,p=null;function h(){if(!t)return;let m=t.length;r=new Array(m),o=new Array(m);let v=typeof i=="function"?i:()=>i,w=typeof n=="function"?n:()=>n;for(let x=0;x<m;x++)o[x]=+v(t[x],x,t),r[x]=isNaN(o[x])?0:+w(t[x],x,t);p&&u>0&&g()}function g(){let m=u*u,v=new Float32Array(m*4);for(let w=0;w<t.length;w++){let x=w*4;v[x]=o[w]??0,v[x+1]=r[w]??0,v[x+2]=0,v[x+3]=0}p.image.data.set(v),p.needsUpdate=!0}function y(m,v,w){if(!a||!v||!w||c===0||!f||!p){M(m);return}b(m,v,w)}function M(m){for(let v=0;v<t.length;v++){let w=t[v];w.vz+=(o[v]-(w.z||0))*r[v]*m}}function b(m,v,w){f.uniforms.positionTexture.value=v,f.uniforms.targetTexture.value=p,f.uniforms.alpha.value=m,f.uniforms.textureSize.value=u,f.uniforms.nodeCount.value=c,f.uniforms.axis.value=2;let x=a.autoClear;a.autoClear=!1,a.setRenderTarget(w),a.render(s,l),a.autoClear=x,a.setRenderTarget(null)}return y.initialize=function(m,v,w){t=m,h()},y.initGPU=function(m){a=m.renderer,l=m.camera,u=m.textureSize,c=m.nodeCount,t.length>0&&(o.length===0||r.length===0)&&h();let v=u*u,w=new Float32Array(v*4);for(let x=0;x<t.length;x++){let C=x*4;w[C]=o[x]??0,w[C+1]=r[x]??0,w[C+2]=0,w[C+3]=0}p?.dispose(),p=new ce.DataTexture(w,u,u,ce.RGBAFormat,ce.FloatType),p.minFilter=ce.NearestFilter,p.magFilter=ce.NearestFilter,p.needsUpdate=!0,s=new ce.Scene,f=new ce.ShaderMaterial({uniforms:{positionTexture:{value:null},targetTexture:{value:p},alpha:{value:1},textureSize:{value:u},nodeCount:{value:c},axis:{value:2}},vertexShader:ge,fragmentShader:Ot,blending:ce.AdditiveBlending,depthTest:!1,depthWrite:!1}),d=new ce.Mesh(we(),f),s.add(d)},y.dispose=function(){p?.dispose(),f?.dispose(),d&&(d.geometry.dispose(),s?.remove(d))},y.apply=y,y.strength=function(m){return arguments.length===0?n:(n=typeof m=="function"?m:ae(+m),h(),y)},y.z=function(m){return arguments.length===0?i:(i=typeof m=="function"?m:ae(+m),h(),y)},y}var vt={charge:-.01,gravity:.1,linkStrength:1,linkDistance:.5,collision:.15,heightCompress:1,alpha:.6,alphaDecay:.1,velocityDecay:.3,dimensions:3,gravityX:1,gravityY:1,gravityZ:1,octreeTheta:.9},Ht=class{constructor(e,t){if(this.simulation=null,this.getOptions=null,this._enable=!0,this._isFinish=!1,this.nodeIdToIndex=new Map,this.lastUpdateTime=0,this.updateIntervalMs=1e3/24,this.skipCPUPositionUpdate=!1,this._dimTransition=null,this._gpuZZeroed=!1,this.graph=e,t)this.renderer=t;else{let n=document.createElement("canvas");n.style.display="none",this.renderer=new fi.WebGLRenderer({canvas:n,alpha:!0,antialias:!1}),this.renderer.setSize(256,256)}this.params={...vt}}config(e){if(this.getOptions=e,e){let t=e();t&&this.applyConfig(t)}return this}configure(e){return this.config(e)}applyConfig(e){e.friction!==void 0&&e.velocityDecay===void 0&&(e.velocityDecay=e.friction),Object.assign(this.params,e)}calculateForces(){let e=this.params.heightCompress??1,t=this.params.gravity??.1,n=this.params.dimensions??3,i,r,o,a;return n===2?(r=t*1.5,i=0,o=.02,a=.8):(i=t*Math.sqrt(e),r=t/Math.sqrt(e),i=i>10?10:i,o=vt.alphaDecay??.1,a=vt.alpha??.6),{forcexy:r,forcez:i,alphaDecay:o,alpha:a}}startLayout(e=0,t=0,n=!1){let i=this.params.dimensions;if(this.getOptions){let _=this.getOptions();_&&this.applyConfig(_)}this.params.dimensions=i,this._gpuZZeroed=!1;let r=this.graph.layoutNodes||[],o=this.graph.layoutEdges||[];if(r.length===0)return;this.nodeIdToIndex.clear(),r.forEach((_,D)=>{this.nodeIdToIndex.set(_.id,D)});let a=this.params.dimensions??3;this.params.dimensions=a;let s=r.some(_=>Math.abs(_.position.z)>1e-6),l=Math.cbrt(r.length)*2,u=a>2&&!s&&!n,c=r.map((_,D)=>{let B=_.position.x,P=_.position.y,L=a<=2?0:_.position.z;if(u&&!_.pinned){let Y=Math.random(),X=Math.random(),H=Math.random(),T=2*Math.PI*Y,G=Math.acos(2*X-1),$=Math.cbrt(H)*l;B=$*Math.sin(G)*Math.cos(T),P=$*Math.sin(G)*Math.sin(T),L=$*Math.cos(G)}return{..._,index:D,x:B,y:P,z:L,vx:0,vy:0,vz:0,fx:_.pinned?_.position.x:null,fy:_.pinned?_.position.y:null,fz:_.pinned?_.position.z:null}}),d=o.filter(_=>{let D=this.nodeIdToIndex.get(_.sourceId),B=this.nodeIdToIndex.get(_.targetId);return D!==void 0&&B!==void 0}).map(_=>({source:_.sourceId,target:_.targetId}));this.simulation&&(this.simulation.stop(),this.simulation.dispose()),this.simulation=na(c,a,this.renderer);let{forcexy:f,forcez:p,alphaDecay:h,alpha:g}=this.calculateForces(),y=this.params.charge??-.01,M=r.length,b=this.params.gravityX??1,m=this.params.gravityY??1,v=this.params.gravityZ??1,w=this.params.linkDistance??.5,x=this.params.linkStrength??1,C=f*this.params.gravityX,E=f*this.params.gravityY,I=p*this.params.gravityZ,R=xa(0).strength(C),U=ba(0).strength(E);if(this.simulation.force("x",R),this.simulation.force("y",U),a>2){let _=wa(0).strength(I);this.simulation.force("z",_)}if(this.simulation.force("center",sa(0,0,0).strength(1)),a>2){let _=ma();_.strength(y);let D=this.params.octreeTheta??.8,B=r.length,P=Math.max(.2,Math.min(1,1.2-.1*Math.log10(Math.max(B,1)))),L=D*P;_.theta(L);let Y=this.params.octreeLevels;Y!==void 0&&_.maxLevels(Y),this.simulation.force("charge",_)}else{let _=da();_.strength(y);let D=this.params.quadtreeTheta??.9,B=Math.max(.5,Math.min(1,500/Math.sqrt(r.length))),P=D*B;_.theta(P),this.simulation.force("charge",_)}if(d.length>0){let _=va(d);_.distance(w),_.strength(x),_.id(D=>D.id),this.simulation.force("link",_)}(this.params.collision??.15)>0;let k=this.params.velocityDecay??vt.velocityDecay;this.simulation.alpha(g).alphaMin(.001).alphaDecay(h).velocityDecay(k),this.simulation.on("tick",()=>{this.onTick()}),this.simulation.on("end",()=>{this._isFinish=!0,this.graph.renderNeedsUpdate=!1}),this._isFinish=!1,this._enable=!0,this.graph.renderNeedsUpdate=!0,this.skipCPUPositionUpdate&&this.simulation.setSkipCPUReadback(!0),this.simulation.restart()}onTick(){if(!this._enable||!this.simulation)return;if(this.skipCPUPositionUpdate){(this.params.dimensions??3)<=2&&this.ensureGPUZeroZ(),this.graph.renderNeedsUpdate=!0;return}let e=performance.now();if(e-this.lastUpdateTime<this.updateIntervalMs)return;this.lastUpdateTime=e;let t=this.simulation.nodes(),n=this.params.dimensions??3;t.forEach(i=>{let r=this.nodeIdToIndex.get(i.id);if(r!==void 0&&r<this.graph.layoutNodes.length){let o=this.graph.layoutNodes[r];o&&!o.pinned&&i.fx==null&&(o.position.x=i.x??0,o.position.y=i.y??0,n>2?o.position.z=i.z??0:o.position.z=0,o.isPositionDirty=!0)}}),this.graph.renderNeedsUpdate=!0}ensureGPUZeroZ(){if(this._gpuZZeroed||!this.simulation)return;this._gpuZZeroed=!0,this.simulation.readBackPositions();let e=this.simulation.nodes(),t=[];e.forEach((i,r)=>{Math.abs(i.z??0)>1e-6&&t.push({index:r,x:i.x??0,y:i.y??0,z:0})}),t.length>0&&this.simulation.uploadNodePositions(t);let n=this.graph.layoutNodes;for(let i=0;i<n.length;i++)n[i].position.z=0}restartLayout(){if(!this.simulation||!this._enable)return;if(this.getOptions){let M=this.getOptions();M&&this.applyConfig(M)}let e=this.params.dimensions??3,{forcexy:t,forcez:n,alphaDecay:i,alpha:r}=this.calculateForces(),o=this.params.charge??-.01,a=this.params.linkDistance??.5,s=this.params.linkStrength??1,l=t*(this.params.gravityX??1),u=t*(this.params.gravityY??1),c=n*(this.params.gravityZ??1),d=this.simulation.force("x"),f=this.simulation.force("y"),p=this.simulation.force("z"),h=this.simulation.force("charge"),g=this.simulation.force("link");d&&d.strength(l),f&&f.strength(u),p&&e>2&&p.strength(c),h&&h.strength(o),g&&(g.distance(a),g.strength(s));let y=this.params.velocityDecay??.3;this.simulation.alpha(r).alphaDecay(i).velocityDecay(y).restart(),this._isFinish=!1,this.graph.renderNeedsUpdate=!0}stopLayout(){this.simulation&&this.simulation.stop(),this._isFinish=!0,this.graph.renderNeedsUpdate=!1}updateLayoutOption(e,t){if(e==="friction"?this.params.velocityDecay=t:this.params[e]=t,!this.simulation||!this._enable)return;let n=this.simulation.force("charge"),i=this.simulation.force("link"),r=this.simulation.force("x"),o=this.simulation.force("y"),a=this.simulation.force("z");switch(e){case"charge":n&&(n.strength(t),this.simulation.alpha(Math.max(this.simulation.alpha(),.3)).restart());break;case"linkDistance":i&&(i.distance(t),this.simulation.alpha(Math.max(this.simulation.alpha(),.3)).restart());break;case"linkStrength":i&&(i.strength(t),this.simulation.alpha(Math.max(this.simulation.alpha(),.3)).restart());break;case"gravity":case"gravityX":case"gravityY":case"gravityZ":case"heightCompress":let{forcexy:s,forcez:l}=this.calculateForces(),u=s*(this.params.gravityX??1),c=s*(this.params.gravityY??1),d=l*(this.params.gravityZ??1);r&&r.strength(u),o&&o.strength(c),a&&a.strength(d),this.simulation.alpha(Math.max(this.simulation.alpha(),.3)).restart();break;case"velocityDecay":case"friction":this.simulation.velocityDecay(this.params.velocityDecay??.3);break;case"alpha":case"alphaDecay":this.restartLayout();break;default:this.restartLayout();break}this.graph.renderNeedsUpdate=!0}pinNodes(e){if(!this.simulation)return;let t=this.simulation.nodes(),n=[];e.forEach(r=>{let o=this.nodeIdToIndex.get(r.id);if(o!==void 0){let a=this.graph.layoutNodes[o];a&&(a.pinned=!0);let s=t[o];s&&(s.fx=r.position.x,s.fy=r.position.y,s.fz=r.position.z,n.push({index:o,x:r.position.x,y:r.position.y,z:r.position.z}))}}),n.length>0&&this.simulation.uploadNodePositions(n);let i=n.map(r=>({index:r.index,isPinned:!0}));this.simulation.updatePinnedNodes(i),this._enable&&this.simulation.alpha()<.1&&this.simulation.alpha(.3).restart(),this.graph.renderNeedsUpdate=!0}unpinNodes(e){if(!this.simulation)return;let t=this.simulation.nodes(),n=[];for(let i of e){let r=this.nodeIdToIndex.get(i);if(r===void 0)continue;let o=this.graph.layoutNodes[r];o&&(o.pinned=!1);let a=t[r];a&&(a.fx=null,a.fy=null,a.fz=null),n.push({index:r,isPinned:!1})}n.length>0&&this.simulation.updatePinnedNodes(n),this._enable&&this.simulation.alpha()<.05&&this.simulation.alpha(.15).restart(),this.graph.renderNeedsUpdate=!0}set enable(e){this._enable=e,!e&&this.simulation&&this.simulation.stop(),this._isFinish=!e,this.graph.renderNeedsUpdate=e}get enable(){return this._enable}get isFinish(){return this._isFinish}setExpectedNodeCount(e){}clearExpectedNodeCount(){}updateGraph(e,t,n=!1){this.startLayout()}destroy(){this.cancelDimensionTransition(),this.simulation&&(this.simulation.stop(),this.simulation.dispose(),this.simulation=null)}transitionDimensions(e,t=600){(this.params.dimensions??3)!==e&&(e===2?this.transition3Dto2D(t):this.transition2Dto3D())}transition3Dto2D(e){this.readBackPositions(),this.params.dimensions=2,this.startLayout(0,0,!0)}transition2Dto3D(){this.readBackPositions(),this.params.dimensions=3,this.startLayout()}cancelDimensionTransition(){this._dimTransition=null}getDimensions(){return this.params.dimensions??3}debugNodePositions(){let e=this.simulation?this.simulation.nodes():[];if(this.simulation&&e.length>0)for(let n=0;n<Math.min(3,e.length);n++){let i=e[n]}let t=this.graph.layoutNodes||[];if(t.length>0){for(let n=0;n<Math.min(3,t.length);n++){let i=t[n]}if(this.simulation&&e.length>0)for(let n=0;n<Math.min(3,Math.min(e.length,t.length));n++){let i=e[n],r=t.find(o=>o.id===i.id);if(r){let o=Math.abs((i.x??0)-r.position.x)<.001&&Math.abs((i.y??0)-r.position.y)<.001&&Math.abs((i.z??0)-r.position.z)<.001}}}}getPositionTexture(){return this.simulation?this.simulation.getPositionTexture():null}getTextureSize(){return this.simulation?this.simulation.getTextureSize():0}getSpaceSize(){return this.simulation?this.simulation.getSpaceSize():10}debugGPUPositions(e=5){return this.simulation?this.simulation.debugPositions(e):null}setSkipCPUReadback(e){this.skipCPUPositionUpdate=e,this.simulation&&this.simulation.setSkipCPUReadback(e)}readBackPositions(){if(this.simulation){this.simulation.readBackPositions();let e=this.simulation.nodes(),t=this.params.dimensions??3;e.forEach(n=>{let i=this.nodeIdToIndex.get(n.id);if(i!==void 0&&i<this.graph.layoutNodes.length){let r=this.graph.layoutNodes[i];r&&(r.position.x=n.x??0,r.position.y=n.y??0,r.position.z=t>2?n.z??0:0)}})}}debugTick(){if(!this.simulation)return;this.simulation.nodes().length>0,this.simulation.tick(1),this.simulation.nodes().length>0,this.onTick()}debugZDistribution(){if(!this.simulation)return;let e=this.simulation.nodes();if(e.length===0)return;let t=1/0,n=-1/0,i=0,r=0,o=[];e.forEach(h=>{let g=h.z||0;t=Math.min(t,g),n=Math.max(n,g),i+=g,r++,o.push(g)});let a=i/r,s=n-t,l=0;o.forEach(h=>{l+=Math.pow(h-a,2)});let u=Math.sqrt(l/r),c=s*.1,d=o.filter(h=>Math.abs(h-t)<c).length,f=o.filter(h=>Math.abs(h-n)<c).length,p=(d+f)/r}},Xt=class{constructor(e){this.c=e,this.mode="gpu"}getPositionTexture(){return this.c.getPositionTexture()}getTextureSize(){return this.c.getTextureSize()}getSpaceSize(){return this.c.getSpaceSize()}tick(){}start(){this.c.startLayout()}stop(){this.c.stopLayout()}get graph(){return this.c.graph}get needsUpdate(){return!this.c.isFinish}clearNeedsUpdate(){}pinNodes(e){this.c.pinNodes(e)}unpinNodes(e){this.c.unpinNodes(e)}transitionDimensions(e,t){this.c.transitionDimensions(e,t)}getDimensions(){return this.c.getDimensions()}updateOption(e,t){this.c.updateLayoutOption(e,t)}};function pi(e){let{backend:t="auto",renderer:n,config:i,graph:r,autoStart:o=!0}=e,a;t==="webgpu"?Ee()?a="webgpu":(console.warn('[createForceLayout] backend="webgpu" requested but navigator.gpu is unavailable; falling back to WebGL.'),a="webgl"):t==="webgl"?a="webgl":a=Ee()?"webgpu":"webgl";let s=r??{layoutNodes:[],layoutEdges:[],renderNeedsUpdate:!0};if(a==="webgpu"){let l=new gt(s);l.config(i);let u=new yt(l);return o&&l.startLayout(),{controller:l,adapter:u,backend:"webgpu"}}else{let l=new Ht(s,n);l.config(i);let u=new Xt(l);return o&&l.startLayout(),{controller:l,adapter:u,backend:"webgl"}}}function Ma(e,t){let n=new Map(e.nodes.map(a=>[a.id,{...a}])),i=new Map(e.edges.map(a=>[a.id,{...a}]));for(let a of t.addNodes??[])n.set(a.id,a);for(let a of t.addEdges??[])i.set(a.id,a);for(let a of t.updateNodes??[]){let s=n.get(a.id);s&&n.set(a.id,{...s,...a.changes})}for(let a of t.updateEdges??[]){let s=i.get(a.id);s&&i.set(a.id,{...s,...a.changes})}for(let a of t.removeNodeIds??[])n.delete(a);for(let a of t.removeEdgeIds??[])i.delete(a);for(let a of t.positionPatches??[]){let s=n.get(a.id);s&&n.set(a.id,{...s,position:a.position})}for(let a of t.pinPatches??[]){let s=n.get(a.id);if(s){let l={...s,pinned:a.pinned};a.position&&(l.position=a.position),n.set(a.id,l)}}let r=Array.from(n.values()).map((a,s)=>({...a,index:s})),o=Array.from(i.values()).map((a,s)=>({...a,index:s}));return{...e,version:t.graphVersion,nodes:r,edges:o}}var hi=class{constructor(e,t,n={}){this.mode="gpu",this._status="idle",this._snapshot=null,this._tickCount=0,this._listeners=new Map,this.id=e,this.controller=t,this._settings={dimensions:3,...n}}get status(){return this._status}getCapabilities(){return{mode:"gpu",supportsGpuTexture:!0,supportsCpuReadback:!1,supportsIncrementalDelta:!1,supportsPinning:!0,supportsDimensions:!0}}init(e,t){this._status!=="disposed"&&(this._snapshot=e,t&&(this._settings={...this._settings,...t}),this._feedSnapshotToController(e),this._status="idle")}applyDelta(e){if(!this._snapshot||this._status==="disposed")return;this._snapshot=Ma(this._snapshot,e);let t=this._status==="running";this._feedSnapshotToController(this._snapshot),t&&this._controllerStart()}tick(e){this._tickCount++,this.controller.tick&&this.controller.tick();let t=this._readNeedsUpdate(),n={tick:this._tickCount,didChangePositions:t,alpha:void 0};return this._emit("tick",n),n}start(){this._status!=="disposed"&&(this._controllerStart(),this._status="running",this._emit("started",{}))}stop(){this._status!=="disposed"&&(this._controllerStop(),this._status="stopped",this._emit("stopped",{}))}dispose(){this._controllerStop(),typeof this.controller.dispose=="function"?this.controller.dispose():typeof this.controller.destroy=="function"&&this.controller.destroy(),this._status="disposed",this._snapshot=null,this._listeners.clear()}getSettings(){return{...this._settings}}updateSettings(e){this._settings={...this._settings,...e}}setDimensions(e){this._settings={...this._settings,dimensions:e},typeof this.controller.transitionDimensions=="function"&&this.controller.transitionDimensions(e)}getReadback(){return{positions:null,texture:this.controller.getPositionTexture(),textureSize:this.controller.getTextureSize(),spaceSize:this.controller.getSpaceSize()}}getNodePosition(e){return null}setNodePosition(e,t){}pinNodes(e){this._status!=="disposed"&&typeof this.controller.pinNodes=="function"&&this.controller.pinNodes(e)}unpinNodes(e){this._status!=="disposed"&&typeof this.controller.unpinNodes=="function"&&this.controller.unpinNodes(e)}on(e,t){return this._listeners.has(e)||this._listeners.set(e,new Set),this._listeners.get(e).add(t),()=>this._listeners.get(e)?.delete(t)}_feedSnapshotToController(e){this._settings={...this._settings,dimensions:e.dimensions},typeof this.controller.startLayout=="function"&&this.controller.startLayout()}_controllerStart(){typeof this.controller.startLayout=="function"?this.controller.startLayout():typeof this.controller.start=="function"&&this.controller.start()}_controllerStop(){typeof this.controller.stopLayout=="function"?this.controller.stopLayout():typeof this.controller.stop=="function"&&this.controller.stop()}_readNeedsUpdate(){return this.controller.needsUpdate!==void 0?!!this.controller.needsUpdate:this.controller.graph!==void 0?!!this.controller.graph.renderNeedsUpdate:!1}_emit(e,t){this._listeners.get(e)?.forEach(n=>n(t))}};
|
|
2328
2328
|
//# sourceMappingURL=layout-gpu.js.map
|