var running=!1;let pixiApp,graphRenderer,batchFraction=1,minBatchFraction=.3,dt=1,targetFPS=40,startingCameraRect={minX:-1,minY:-1,maxX:1,maxY:1},mouseWorldPos={x:void 0,y:void 0},scrollVelocity=0,averageFPS=2*targetFPS;class GraphAssembly{static nodeCount=0;static linkCount=0;static hoveredNode=-1;static#e=0;static#r=0;static#t=0;static#a=0;static#s=0;static linkSources=new Int32Array(0);static linkTargets=new Int32Array(0);static radii=new Float32Array(0);static maxRadius=0;static averageRadius=0;static minRadius=0;static init(e){GraphAssembly.nodeCount=e.nodeCount,GraphAssembly.linkCount=e.linkCount;let r=new Float32Array(2*GraphAssembly.nodeCount);GraphAssembly.radii=new Float32Array(e.radii),GraphAssembly.linkSources=new Int32Array(e.linkSources),GraphAssembly.linkTargets=new Int32Array(e.linkTargets),GraphAssembly.#e=Module._malloc(r.byteLength),GraphAssembly.#r=r.byteLength,GraphAssembly.#t=Module._malloc(GraphAssembly.radii.byteLength),GraphAssembly.#a=Module._malloc(GraphAssembly.linkSources.byteLength),GraphAssembly.#s=Module._malloc(GraphAssembly.linkTargets.byteLength),GraphAssembly.maxRadius=GraphAssembly.radii.reduce(((e,r)=>Math.max(e,r))),GraphAssembly.averageRadius=GraphAssembly.radii.reduce(((e,r)=>e+r))/GraphAssembly.radii.length,GraphAssembly.minRadius=GraphAssembly.radii.reduce(((e,r)=>Math.min(e,r))),r=this.loadState(),Module.HEAP32.set(new Int32Array(r.buffer),GraphAssembly.#e/r.BYTES_PER_ELEMENT),Module.HEAP32.set(new Int32Array(GraphAssembly.radii.buffer),GraphAssembly.#t/GraphAssembly.radii.BYTES_PER_ELEMENT),Module.HEAP32.set(new Int32Array(GraphAssembly.linkSources.buffer),GraphAssembly.#a/GraphAssembly.linkSources.BYTES_PER_ELEMENT),Module.HEAP32.set(new Int32Array(GraphAssembly.linkTargets.buffer),GraphAssembly.#s/GraphAssembly.linkTargets.BYTES_PER_ELEMENT),Module._Init(GraphAssembly.#e,GraphAssembly.#t,GraphAssembly.#a,GraphAssembly.#s,GraphAssembly.nodeCount,GraphAssembly.linkCount,batchFraction,dt,e.graphOptions.attractionForce,e.graphOptions.linkLength,e.graphOptions.repulsionForce,e.graphOptions.centralForce)}static get positions(){return Module.HEAP32.buffer.slice(GraphAssembly.#e,GraphAssembly.#e+GraphAssembly.#r)}static saveState(e){localStorage.setItem("positions",JSON.stringify(new Float32Array(GraphAssembly.positions).map((e=>Math.round(e)))))}static loadState(){let e=localStorage.getItem("positions"),r=null;if(e&&(r=new Float32Array(Object.values(JSON.parse(e)))),!r||!e||r.length!=2*GraphAssembly.nodeCount){r=new Float32Array(2*GraphAssembly.nodeCount);let e=GraphAssembly.averageRadius*Math.sqrt(GraphAssembly.nodeCount)*2;for(let t=0;t{try{var e=graphRenderer.canvasSidebar.classList.contains("is-collapsed")}catch(e){return}running&&e?running=!1:running||e||(running=!0,graphRenderer.autoResizeCanvas(),graphRenderer.centerCamera())}),1e3))}let firstUpdate=!0;function updateGraph(){if(running&&!graphRenderer.canvasSidebar.classList.contains("is-collapsed")&&(firstUpdate&&(setTimeout((()=>graphRenderer?.canvas?.classList.remove("hide")),500),firstUpdate=!1),GraphAssembly.update(mouseWorldPos,graphRenderer.grabbedNode,graphRenderer.cameraScale),GraphAssembly.hoveredNode!=graphRenderer.hoveredNode&&(graphRenderer.hoveredNode=GraphAssembly.hoveredNode,graphRenderer.canvas.style.cursor=-1==GraphAssembly.hoveredNode?"default":"pointer"),graphRenderer.autoResizeCanvas(),graphRenderer.draw(GraphAssembly.positions),averageFPS=.95*averageFPS+.05*pixiApp.ticker.FPS,averageFPS<.8*targetFPS&&batchFraction>minBatchFraction&&(batchFraction=Math.max(batchFraction-.5/targetFPS,minBatchFraction),GraphAssembly.batchFraction=batchFraction,GraphAssembly.repulsionForce=graphData.graphOptions.repulsionForce/batchFraction),averageFPS>1.2*targetFPS&&batchFraction<1&&(batchFraction=Math.min(batchFraction+.5/targetFPS,1),GraphAssembly.batchFraction=batchFraction,GraphAssembly.repulsionForce=graphData.graphOptions.repulsionForce/batchFraction),0!=scrollVelocity)){graphRenderer.getCameraCenterWorldspace();Math.abs(scrollVelocity)<.001&&(scrollVelocity=0),zoomGraphViewAroundPoint(mouseWorldPos,scrollVelocity),scrollVelocity*=.65}}function zoomGraphViewAroundPoint(e,r,t=.15,a=15){let s=graphRenderer.getCameraCenterWorldspace();if(graphRenderer.cameraScale=Math.max(Math.min(graphRenderer.cameraScale+r*graphRenderer.cameraScale,a),t),graphRenderer.cameraScale!=t&&graphRenderer.cameraScale!=a&&scrollVelocity>0&&null!=mouseWorldPos.x&&null!=mouseWorldPos.y){let t={x:e.x-s.x,y:e.y-s.y},a={x:s.x+t.x*r,y:s.y+t.y*r};graphRenderer.setCameraCenterWorldspace(a)}else graphRenderer.setCameraCenterWorldspace(s)}function scaleGraphViewAroundPoint(e,r,t=.15,a=15){let s=graphRenderer.getCameraCenterWorldspace(),i=graphRenderer.cameraScale;graphRenderer.cameraScale=Math.max(Math.min(r*graphRenderer.cameraScale,a),t);let o=(i-graphRenderer.cameraScale)/i;if(graphRenderer.cameraScale!=t&&graphRenderer.cameraScale!=a&&0!=r){let r={x:e.x-s.x,y:e.y-s.y},t={x:s.x-r.x*o,y:s.y-r.y*o};graphRenderer.setCameraCenterWorldspace(t)}else graphRenderer.setCameraCenterWorldspace(s)}function initializeGraphEvents(){window.addEventListener("beforeunload",(()=>{running=!1,GraphAssembly.free()}));let e=!1,r=graphRenderer.canvas.width;window.addEventListener("resize",(()=>{(e||graphRenderer.canvas.width!=r)&&(graphRenderer.autoResizeCanvas(),graphRenderer.centerCamera())}));let t=document.querySelector(".graph-view-container");function a(e){e.composedPath().includes(t)||s()}function s(){let r=t.clientWidth,s=t.clientHeight;t.classList.add("scale-down"),t.animate({opacity:0},{duration:100,easing:"ease-in",fill:"forwards"}).addEventListener("finish",(function(){t.classList.toggle("expanded"),graphRenderer.autoResizeCanvas(),graphRenderer.centerCamera();let e=t.clientWidth,a=t.clientHeight;graphRenderer.cameraScale*=(e/r+a/s)/2,t.classList.remove("scale-down"),t.classList.add("scale-up"),updateGraph(),t.animate({opacity:1},{duration:200,easing:"ease-out",fill:"forwards"}).addEventListener("finish",(function(){t.classList.remove("scale-up")}))})),e=!e,e?document.addEventListener("pointerdown",a):document.removeEventListener("pointerdown",a)}function i(e){var r=graphRenderer.canvas.getBoundingClientRect();let t=getPointerPosition(e);return{x:t.x-r.left,y:t.y-r.top}}let o={x:0,y:0},n={x:0,y:0},h={x:0,y:0},d={x:0,y:0},l={x:0,y:0},c=0,p=!1,m=!1,g=!1,u=document.querySelector(".graph-view-container"),y=-1;u.addEventListener("pointerenter",(function(r){let t=0,a=!1;function b(e){n=i(e),mouseWorldPos=graphRenderer.vecToWorldspace(n),d={x:n.x-h.x,y:n.y-h.y},h=n,-1!=graphRenderer.grabbedNode&&(l={x:n.x-o.x,y:n.y-o.y}),p&&-1!=graphRenderer.hoveredNode&&-1==graphRenderer.grabbedNode&&graphRenderer.hoveredNode!=graphRenderer.grabbedNode&&(graphRenderer.grabbedNode=graphRenderer.hoveredNode),p&&-1==graphRenderer.hoveredNode&&-1==graphRenderer.grabbedNode||m?graphRenderer.cameraOffset={x:graphRenderer.cameraOffset.x+d.x,y:graphRenderer.cameraOffset.y+d.y}:-1!=graphRenderer.hoveredNode?graphRenderer.canvas.style.cursor="pointer":graphRenderer.canvas.style.cursor="default"}function v(e){if(1==e.touches?.length)return a&&(h=i(e),a=!1),void b(e);if(2==e.touches?.length){let r=getTouchPosition(e.touches[0]),s=getTouchPosition(e.touches[1]);n=i(e),d={x:n.x-h.x,y:n.y-h.y},h=n;let o=Math.sqrt(Math.pow(r.x-s.x,2)+Math.pow(r.y-s.y,2));a||(a=!0,t=o,d={x:0,y:0},mouseWorldPos={x:void 0,y:void 0},graphRenderer.grabbedNode=-1,graphRenderer.hoveredNode=-1);let l=(o-t)/t;scaleGraphViewAroundPoint(graphRenderer.vecToWorldspace(n),1+l,.15,15),graphRenderer.cameraOffset={x:graphRenderer.cameraOffset.x+d.x,y:graphRenderer.cameraOffset.y+d.y},t=o}}function f(r){document.removeEventListener("pointerup",f);let t=Date.now();setTimeout((()=>{p&&-1!=graphRenderer.hoveredNode&&Math.abs(l.x)<=4&&Math.abs(l.y)<=4&&t-c<300&&async function(r){e?s():GraphAssembly.saveState(graphRenderer);let t=graphData.paths[r];window.location.pathname.endsWith(graphData.paths[r])||await loadDocument(t,!0,!0)}(graphRenderer.hoveredNode),p&&-1!=graphRenderer.grabbedNode&&(graphRenderer.grabbedNode=-1),0==r.button&&(p=!1),"touch"==r.pointerType&&y==r.pointerId&&(y=-1,p=!1),1==r.button&&(m=!1),g||(document.removeEventListener("mousemove",b),document.removeEventListener("touchmove",v))}),0)}function R(e){document.addEventListener("pointerup",f),mouseWorldPos=graphRenderer.vecToWorldspace(n),l={x:0,y:0},0==e.button&&(p=!0),"touch"==e.pointerType&&-1==y&&(y=e.pointerId,p=!0),1==e.button&&(m=!0),o=n,c=Date.now(),p&&-1!=graphRenderer.hoveredNode&&(graphRenderer.grabbedNode=graphRenderer.hoveredNode)}n=i(r),mouseWorldPos=graphRenderer.vecToWorldspace(n),h=i(r),g=!0,document.addEventListener("mousemove",b),document.addEventListener("touchmove",v),u.addEventListener("pointerdown",R),u.addEventListener("pointerleave",(function e(r){setTimeout((()=>{g=!1,p||(document.removeEventListener("mousemove",b),document.removeEventListener("touchmove",v),mouseWorldPos={x:void 0,y:void 0}),u.removeEventListener("pointerdown",R),u.removeEventListener("pointerleave",e)}),1)}))})),document.querySelector(".graph-expand.graph-icon")?.addEventListener("click",(e=>{e.stopPropagation(),s()})),u.addEventListener("wheel",(function(e){let r=.09;e.deltaY>0?(scrollVelocity>=-.09&&(scrollVelocity=-.09),scrollVelocity*=1.4):(scrollVelocity<=r&&(scrollVelocity=r),scrollVelocity*=1.4)})),u.addEventListener("dblclick",(function(e){graphRenderer.fitToNodes()})),document.querySelector(".theme-toggle-input")?.addEventListener("change",(e=>{setTimeout((()=>graphRenderer.resampleColors()),0)}))}window.addEventListener("load",(()=>{waitLoadScripts(["pixi","graph-data","graph-render-worker","graph-wasm"],(()=>{Module.onRuntimeInitialized=initializeGraphView,setTimeout((()=>Module.onRuntimeInitialized()),300)}))}))