backpack-viewer 0.2.7 → 0.2.9

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/bin/serve.js CHANGED
@@ -7,7 +7,7 @@ import http from "node:http";
7
7
 
8
8
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
9
  const root = path.resolve(__dirname, "..");
10
- const distDir = path.resolve(root, "dist");
10
+ const distDir = path.resolve(root, "dist/app");
11
11
  const port = parseInt(process.env.PORT || "5173", 10);
12
12
 
13
13
  const hasDistBuild = fs.existsSync(path.join(distDir, "index.html"));
package/dist/api.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import type { OntologyData, OntologySummary } from "backpack-ontology";
2
+ export declare function listOntologies(): Promise<OntologySummary[]>;
3
+ export declare function loadOntology(name: string): Promise<OntologyData>;
4
+ export declare function saveOntology(name: string, data: OntologyData): Promise<void>;
5
+ export declare function renameOntology(oldName: string, newName: string): Promise<void>;
package/dist/api.js ADDED
@@ -0,0 +1,30 @@
1
+ export async function listOntologies() {
2
+ const res = await fetch("/api/ontologies");
3
+ if (!res.ok)
4
+ return [];
5
+ return res.json();
6
+ }
7
+ export async function loadOntology(name) {
8
+ const res = await fetch(`/api/ontologies/${encodeURIComponent(name)}`);
9
+ if (!res.ok)
10
+ throw new Error(`Failed to load ontology: ${name}`);
11
+ return res.json();
12
+ }
13
+ export async function saveOntology(name, data) {
14
+ const res = await fetch(`/api/ontologies/${encodeURIComponent(name)}`, {
15
+ method: "PUT",
16
+ headers: { "Content-Type": "application/json" },
17
+ body: JSON.stringify(data),
18
+ });
19
+ if (!res.ok)
20
+ throw new Error(`Failed to save ontology: ${name}`);
21
+ }
22
+ export async function renameOntology(oldName, newName) {
23
+ const res = await fetch(`/api/ontologies/${encodeURIComponent(oldName)}/rename`, {
24
+ method: "POST",
25
+ headers: { "Content-Type": "application/json" },
26
+ body: JSON.stringify({ name: newName }),
27
+ });
28
+ if (!res.ok)
29
+ throw new Error(`Failed to rename ontology: ${oldName}`);
30
+ }
@@ -0,0 +1 @@
1
+ (function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const d of document.querySelectorAll('link[rel="modulepreload"]'))t(d);new MutationObserver(d=>{for(const e of d)if(e.type==="childList")for(const c of e.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&t(c)}).observe(document,{childList:!0,subtree:!0});function o(d){const e={};return d.integrity&&(e.integrity=d.integrity),d.referrerPolicy&&(e.referrerPolicy=d.referrerPolicy),d.crossOrigin==="use-credentials"?e.credentials="include":d.crossOrigin==="anonymous"?e.credentials="omit":e.credentials="same-origin",e}function t(d){if(d.ep)return;d.ep=!0;const e=o(d);fetch(d.href,e)}})();async function ie(){const a=await fetch("/api/ontologies");return a.ok?a.json():[]}async function le(a){const n=await fetch(`/api/ontologies/${encodeURIComponent(a)}`);if(!n.ok)throw new Error(`Failed to load ontology: ${a}`);return n.json()}async function Se(a,n){if(!(await fetch(`/api/ontologies/${encodeURIComponent(a)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)})).ok)throw new Error(`Failed to save ontology: ${a}`)}async function Me(a,n){if(!(await fetch(`/api/ontologies/${encodeURIComponent(a)}/rename`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n})})).ok)throw new Error(`Failed to rename ontology: ${a}`)}function Ie(a,n){const o=typeof n=="function"?{onSelect:n}:n,t=document.createElement("h2");t.textContent="Backpack Ontology Viewer";const d=document.createElement("input");d.type="text",d.placeholder="Filter...",d.id="filter";const e=document.createElement("ul");e.id="ontology-list";const c=document.createElement("div");c.className="sidebar-footer",c.innerHTML='<a href="mailto:support@backpackontology.com">support@backpackontology.com</a><span>Feedback & support</span>',a.appendChild(t),a.appendChild(d),a.appendChild(e),a.appendChild(c);let b=[],f="";return d.addEventListener("input",()=>{const h=d.value.toLowerCase();for(const m of b){const i=m.dataset.name??"";m.style.display=i.includes(h)?"":"none"}}),{setSummaries(h){e.innerHTML="",b=h.map(m=>{const i=document.createElement("li");i.className="ontology-item",i.dataset.name=m.name;const y=document.createElement("span");y.className="name",y.textContent=m.name;const M=document.createElement("span");if(M.className="stats",M.textContent=`${m.nodeCount} nodes, ${m.edgeCount} edges`,i.appendChild(y),i.appendChild(M),o.onRename){const I=document.createElement("button");I.className="sidebar-edit-btn",I.textContent="✎",I.title="Rename";const _=o.onRename;I.addEventListener("click",u=>{u.stopPropagation();const v=document.createElement("input");v.type="text",v.className="sidebar-rename-input",v.value=m.name,y.textContent="",y.appendChild(v),I.style.display="none",v.focus(),v.select();const r=()=>{const E=v.value.trim();E&&E!==m.name?_(m.name,E):(y.textContent=m.name,I.style.display="")};v.addEventListener("blur",r),v.addEventListener("keydown",E=>{E.key==="Enter"&&v.blur(),E.key==="Escape"&&(v.value=m.name,v.blur())})}),i.appendChild(I)}return i.addEventListener("click",()=>o.onSelect(m.name)),e.appendChild(i),i}),f&&this.setActive(f)},setActive(h){f=h;for(const m of b)m.classList.toggle("active",m.dataset.name===h)}}}const ke=5e3,Ae=.005,Ee=150,me=.9,fe=.01,he=30,de=50;function Te(a,n){for(const o of Object.values(a))if(typeof o=="string")return o;return n}function Oe(a){const n=Math.sqrt(a.nodes.length)*Ee*.5,o=new Map,t=a.nodes.map((e,c)=>{const b=2*Math.PI*c/a.nodes.length,f={id:e.id,x:Math.cos(b)*n,y:Math.sin(b)*n,vx:0,vy:0,label:Te(e.properties,e.id),type:e.type};return o.set(e.id,f),f}),d=a.edges.map(e=>({sourceId:e.sourceId,targetId:e.targetId,type:e.type}));return{nodes:t,edges:d,nodeMap:o}}function De(a,n){const{nodes:o,edges:t,nodeMap:d}=a;for(let e=0;e<o.length;e++)for(let c=e+1;c<o.length;c++){const b=o[e],f=o[c];let h=f.x-b.x,m=f.y-b.y,i=Math.sqrt(h*h+m*m);i<he&&(i=he);const y=ke*n/(i*i),M=h/i*y,I=m/i*y;b.vx-=M,b.vy-=I,f.vx+=M,f.vy+=I}for(const e of t){const c=d.get(e.sourceId),b=d.get(e.targetId);if(!c||!b)continue;const f=b.x-c.x,h=b.y-c.y,m=Math.sqrt(f*f+h*h);if(m===0)continue;const i=Ae*(m-Ee)*n,y=f/m*i,M=h/m*i;c.vx+=y,c.vy+=M,b.vx-=y,b.vy-=M}for(const e of o)e.vx-=e.x*fe*n,e.vy-=e.y*fe*n;for(const e of o){e.vx*=me,e.vy*=me;const c=Math.sqrt(e.vx*e.vx+e.vy*e.vy);c>de&&(e.vx=e.vx/c*de,e.vy=e.vy/c*de),e.x+=e.vx,e.y+=e.vy}return n*.995}const ye=["#d4a27f","#c17856","#b07a5e","#d4956b","#a67c5a","#cc9e7c","#c4866a","#cb8e6c","#b8956e","#a88a70","#d9b08c","#c4a882","#e8b898","#b5927a","#a8886e","#d1a990"],ge=new Map;function ee(a){const n=ge.get(a);if(n)return n;let o=0;for(let d=0;d<a.length;d++)o=(o<<5)-o+a.charCodeAt(d)|0;const t=ye[Math.abs(o)%ye.length];return ge.set(a,t),t}function q(a){return getComputedStyle(document.documentElement).getPropertyValue(a).trim()}const Q=20,Pe=.001;function Be(a,n){const o=a.querySelector("canvas"),t=o.getContext("2d"),d=window.devicePixelRatio||1;let e={x:0,y:0,scale:1},c=null,b=1,f=0,h=new Set,m=null,i=null,y=null;const M=300;function I(){o.width=o.clientWidth*d,o.height=o.clientHeight*d,r()}const _=new ResizeObserver(I);_.observe(a),I();function u(s,l){return[s/e.scale+e.x,l/e.scale+e.y]}function v(s,l){if(!c)return null;const[p,x]=u(s,l);for(let C=c.nodes.length-1;C>=0;C--){const B=c.nodes[C],L=p-B.x,R=x-B.y;if(L*L+R*R<=Q*Q)return B}return null}function r(){if(!c){t.clearRect(0,0,o.width,o.height);return}const s=q("--canvas-edge"),l=q("--canvas-edge-highlight"),p=q("--canvas-edge-dim"),x=q("--canvas-edge-label"),C=q("--canvas-edge-label-highlight"),B=q("--canvas-edge-label-dim"),L=q("--canvas-arrow"),R=q("--canvas-arrow-highlight"),Y=q("--canvas-node-label"),k=q("--canvas-node-label-dim"),G=q("--canvas-type-badge"),ne=q("--canvas-type-badge-dim"),be=q("--canvas-selection-border"),Le=q("--canvas-node-border");t.save(),t.setTransform(d,0,0,d,0,0),t.clearRect(0,0,o.clientWidth,o.clientHeight),t.save(),t.translate(-e.x*e.scale,-e.y*e.scale),t.scale(e.scale,e.scale);for(const O of c.edges){const K=c.nodeMap.get(O.sourceId),V=c.nodeMap.get(O.targetId);if(!K||!V)continue;const ce=m===null||m.has(O.sourceId),oe=m===null||m.has(O.targetId),te=ce&&oe;if(m!==null&&!ce&&!oe)continue;const J=h.size>0&&(h.has(O.sourceId)||h.has(O.targetId))||m!==null&&te,ue=m!==null&&!te;if(O.sourceId===O.targetId){S(K,O.type,J,s,l,x,C);continue}t.beginPath(),t.moveTo(K.x,K.y),t.lineTo(V.x,V.y),t.strokeStyle=J?l:ue?p:s,t.lineWidth=J?2.5:1.5,t.stroke(),E(K.x,K.y,V.x,V.y,J,L,R);const we=(K.x+V.x)/2,Ne=(K.y+V.y)/2;t.fillStyle=J?C:ue?B:x,t.font="9px system-ui, sans-serif",t.textAlign="center",t.textBaseline="bottom",t.fillText(O.type,we,Ne-4)}for(const O of c.nodes){const K=ee(O.type),V=h.has(O.id),ce=h.size>0&&c.edges.some(J=>h.has(J.sourceId)&&J.targetId===O.id||h.has(J.targetId)&&J.sourceId===O.id),oe=m!==null&&!m.has(O.id),te=oe||h.size>0&&!V&&!ce;V&&(t.save(),t.shadowColor=K,t.shadowBlur=20,t.beginPath(),t.arc(O.x,O.y,Q+3,0,Math.PI*2),t.fillStyle=K,t.globalAlpha=.3,t.fill(),t.restore()),t.beginPath(),t.arc(O.x,O.y,Q,0,Math.PI*2),t.fillStyle=K,t.globalAlpha=oe?.1:te?.3:1,t.fill(),t.strokeStyle=V?be:Le,t.lineWidth=V?3:1.5,t.stroke();const pe=O.label.length>24?O.label.slice(0,22)+"...":O.label;t.fillStyle=te?k:Y,t.font="11px system-ui, sans-serif",t.textAlign="center",t.textBaseline="top",t.fillText(pe,O.x,O.y+Q+4),t.fillStyle=te?ne:G,t.font="9px system-ui, sans-serif",t.textBaseline="bottom",t.fillText(O.type,O.x,O.y-Q-3),t.globalAlpha=1}t.restore(),t.restore()}function E(s,l,p,x,C,B,L){const R=Math.atan2(x-l,p-s),Y=p-Math.cos(R)*Q,k=x-Math.sin(R)*Q,G=8;t.beginPath(),t.moveTo(Y,k),t.lineTo(Y-G*Math.cos(R-.4),k-G*Math.sin(R-.4)),t.lineTo(Y-G*Math.cos(R+.4),k-G*Math.sin(R+.4)),t.closePath(),t.fillStyle=C?L:B,t.fill()}function S(s,l,p,x,C,B,L){const R=s.x+Q+15,Y=s.y-Q-15;t.beginPath(),t.arc(R,Y,15,0,Math.PI*2),t.strokeStyle=p?C:x,t.lineWidth=p?2.5:1.5,t.stroke(),t.fillStyle=p?L:B,t.font="9px system-ui, sans-serif",t.textAlign="center",t.fillText(l,R,Y-18)}function D(){if(!i||!y)return;const s=performance.now()-y.time,l=Math.min(s/M,1),p=1-Math.pow(1-l,3);e.x=y.x+(i.x-y.x)*p,e.y=y.y+(i.y-y.y)*p,r(),l<1?requestAnimationFrame(D):(i=null,y=null)}function X(){!c||b<Pe||(b=De(c,b),r(),f=requestAnimationFrame(X))}let F=!1,j=!1,W=0,U=0;o.addEventListener("mousedown",s=>{F=!0,j=!1,W=s.clientX,U=s.clientY}),o.addEventListener("mousemove",s=>{if(!F)return;const l=s.clientX-W,p=s.clientY-U;(Math.abs(l)>2||Math.abs(p)>2)&&(j=!0),e.x-=l/e.scale,e.y-=p/e.scale,W=s.clientX,U=s.clientY,r()}),o.addEventListener("mouseup",s=>{if(F=!1,j)return;const l=o.getBoundingClientRect(),p=s.clientX-l.left,x=s.clientY-l.top,C=v(p,x),B=s.ctrlKey||s.metaKey;if(C){B?h.has(C.id)?h.delete(C.id):h.add(C.id):h.size===1&&h.has(C.id)?h.clear():(h.clear(),h.add(C.id));const L=[...h];n==null||n(L.length>0?L:null)}else h.clear(),n==null||n(null);r()}),o.addEventListener("mouseleave",()=>{F=!1}),o.addEventListener("wheel",s=>{s.preventDefault();const l=o.getBoundingClientRect(),p=s.clientX-l.left,x=s.clientY-l.top,[C,B]=u(p,x),L=s.ctrlKey?1-s.deltaY*.01:s.deltaY>0?.9:1.1;e.scale=Math.max(.05,Math.min(10,e.scale*L)),e.x=C-p/e.scale,e.y=B-x/e.scale,r()},{passive:!1});let z=[],T=0,P=1;o.addEventListener("touchstart",s=>{s.preventDefault(),z=Array.from(s.touches),z.length===2?(T=H(z[0],z[1]),P=e.scale):z.length===1&&(W=z[0].clientX,U=z[0].clientY)},{passive:!1}),o.addEventListener("touchmove",s=>{s.preventDefault();const l=Array.from(s.touches);if(l.length===2&&z.length===2){const x=H(l[0],l[1])/T;e.scale=Math.max(.05,Math.min(10,P*x)),r()}else if(l.length===1){const p=l[0].clientX-W,x=l[0].clientY-U;e.x-=p/e.scale,e.y-=x/e.scale,W=l[0].clientX,U=l[0].clientY,r()}z=l},{passive:!1});function H(s,l){const p=s.clientX-l.clientX,x=s.clientY-l.clientY;return Math.sqrt(p*p+x*x)}const $=document.createElement("div");$.className="zoom-controls";const w=document.createElement("button");w.className="zoom-btn",w.textContent="+",w.title="Zoom in",w.addEventListener("click",()=>{const s=o.clientWidth/2,l=o.clientHeight/2,[p,x]=u(s,l);e.scale=Math.min(10,e.scale*1.3),e.x=p-s/e.scale,e.y=x-l/e.scale,r()});const A=document.createElement("button");A.className="zoom-btn",A.textContent="−",A.title="Zoom out",A.addEventListener("click",()=>{const s=o.clientWidth/2,l=o.clientHeight/2,[p,x]=u(s,l);e.scale=Math.max(.05,e.scale/1.3),e.x=p-s/e.scale,e.y=x-l/e.scale,r()});const g=document.createElement("button");return g.className="zoom-btn",g.textContent="○",g.title="Reset zoom",g.addEventListener("click",()=>{if(c){if(e={x:0,y:0,scale:1},c.nodes.length>0){let s=1/0,l=1/0,p=-1/0,x=-1/0;for(const L of c.nodes)L.x<s&&(s=L.x),L.y<l&&(l=L.y),L.x>p&&(p=L.x),L.y>x&&(x=L.y);const C=(s+p)/2,B=(l+x)/2;e.x=C-o.clientWidth/2,e.y=B-o.clientHeight/2}r()}}),$.appendChild(w),$.appendChild(g),$.appendChild(A),a.appendChild($),{loadGraph(s){if(cancelAnimationFrame(f),c=Oe(s),b=1,h=new Set,m=null,e={x:0,y:0,scale:1},c.nodes.length>0){let l=1/0,p=1/0,x=-1/0,C=-1/0;for(const k of c.nodes)k.x<l&&(l=k.x),k.y<p&&(p=k.y),k.x>x&&(x=k.x),k.y>C&&(C=k.y);const B=(l+x)/2,L=(p+C)/2,R=o.clientWidth,Y=o.clientHeight;e.x=B-R/2,e.y=L-Y/2}X()},setFilteredNodeIds(s){m=s,r()},panToNode(s){if(!c)return;const l=c.nodeMap.get(s);if(!l)return;h=new Set([s]),n==null||n([s]);const p=o.clientWidth,x=o.clientHeight;y={x:e.x,y:e.y,time:performance.now()},i={x:l.x-p/(2*e.scale),y:l.y-x/(2*e.scale)},D()},destroy(){cancelAnimationFrame(f),_.disconnect()}}}function se(a){for(const n of Object.values(a.properties))if(typeof n=="string")return n;return a.id}const Re="✎";function ze(a,n,o){const t=document.createElement("div");t.id="info-panel",t.className="info-panel hidden",a.appendChild(t);let d=!1,e=[],c=-1,b=!1,f=null;function h(){t.classList.add("hidden"),t.classList.remove("info-panel-maximized"),t.innerHTML="",d=!1,e=[],c=-1}function m(u){!f||!o||(c<e.length-1&&(e=e.slice(0,c+1)),e.push(u),c=e.length-1,b=!0,o(u),b=!1)}function i(){c<=0||!f||!o||(c--,b=!0,o(e[c]),b=!1)}function y(){c>=e.length-1||!f||!o||(c++,b=!0,o(e[c]),b=!1)}function M(){const u=document.createElement("div");u.className="info-panel-toolbar";const v=document.createElement("button");v.className="info-toolbar-btn",v.textContent="←",v.title="Back",v.disabled=c<=0,v.addEventListener("click",i),u.appendChild(v);const r=document.createElement("button");r.className="info-toolbar-btn",r.textContent="→",r.title="Forward",r.disabled=c>=e.length-1,r.addEventListener("click",y),u.appendChild(r);const E=document.createElement("button");E.className="info-toolbar-btn",E.textContent=d?"⎘":"⛶",E.title=d?"Restore":"Maximize",E.addEventListener("click",()=>{d=!d,t.classList.toggle("info-panel-maximized",d),E.textContent=d?"⎘":"⛶",E.title=d?"Restore":"Maximize"}),u.appendChild(E);const S=document.createElement("button");return S.className="info-toolbar-btn info-close-btn",S.textContent="×",S.title="Close",S.addEventListener("click",h),u.appendChild(S),u}function I(u,v){const r=v.nodes.find(w=>w.id===u);if(!r)return;const E=v.edges.filter(w=>w.sourceId===u||w.targetId===u);t.innerHTML="",t.classList.remove("hidden"),d&&t.classList.add("info-panel-maximized"),t.appendChild(M());const S=document.createElement("div");S.className="info-header";const D=document.createElement("span");if(D.className="info-type-badge",D.textContent=r.type,D.style.backgroundColor=ee(r.type),n){D.classList.add("info-editable");const w=document.createElement("button");w.className="info-inline-edit",w.textContent=Re,w.addEventListener("click",A=>{A.stopPropagation();const g=document.createElement("input");g.type="text",g.className="info-edit-inline-input",g.value=r.type,D.textContent="",D.appendChild(g),g.focus(),g.select();const s=()=>{const l=g.value.trim();l&&l!==r.type?n.onChangeNodeType(u,l):(D.textContent=r.type,D.appendChild(w))};g.addEventListener("blur",s),g.addEventListener("keydown",l=>{l.key==="Enter"&&g.blur(),l.key==="Escape"&&(g.value=r.type,g.blur())})}),D.appendChild(w)}const X=document.createElement("h3");X.className="info-label",X.textContent=se(r);const F=document.createElement("span");F.className="info-id",F.textContent=r.id,S.appendChild(D),S.appendChild(X),S.appendChild(F),t.appendChild(S);const j=Object.keys(r.properties),W=ae("Properties");if(j.length>0){const w=document.createElement("dl");w.className="info-props";for(const A of j){const g=document.createElement("dt");g.textContent=A;const s=document.createElement("dd");if(n){const l=re(r.properties[A]),p=document.createElement("input");p.type="text",p.className="info-edit-input",p.value=l,p.addEventListener("keydown",C=>{C.key==="Enter"&&p.blur()}),p.addEventListener("blur",()=>{const C=p.value;C!==l&&n.onUpdateNode(u,{[A]:$e(C)})}),s.appendChild(p);const x=document.createElement("button");x.className="info-delete-prop",x.textContent="×",x.title=`Remove ${A}`,x.addEventListener("click",()=>{const C={...r.properties};delete C[A],n.onUpdateNode(u,C)}),s.appendChild(x)}else s.appendChild(He(r.properties[A]));w.appendChild(g),w.appendChild(s)}W.appendChild(w)}if(n){const w=document.createElement("button");w.className="info-add-btn",w.textContent="+ Add property",w.addEventListener("click",()=>{const A=document.createElement("div");A.className="info-add-row";const g=document.createElement("input");g.type="text",g.className="info-edit-input",g.placeholder="key";const s=document.createElement("input");s.type="text",s.className="info-edit-input",s.placeholder="value";const l=document.createElement("button");l.className="info-add-save",l.textContent="Add",l.addEventListener("click",()=>{g.value&&n.onAddProperty(u,g.value,s.value)}),A.appendChild(g),A.appendChild(s),A.appendChild(l),W.appendChild(A),g.focus()}),W.appendChild(w)}if(t.appendChild(W),E.length>0){const w=ae(`Connections (${E.length})`),A=document.createElement("ul");A.className="info-connections";for(const g of E){const s=g.sourceId===u,l=s?g.targetId:g.sourceId,p=v.nodes.find(k=>k.id===l),x=p?se(p):l,C=document.createElement("li");if(C.className="info-connection",o&&p&&(C.classList.add("info-connection-link"),C.addEventListener("click",k=>{k.target.closest(".info-delete-edge")||m(l)})),p){const k=document.createElement("span");k.className="info-target-dot",k.style.backgroundColor=ee(p.type),C.appendChild(k)}const B=document.createElement("span");B.className="info-arrow",B.textContent=s?"→":"←";const L=document.createElement("span");L.className="info-edge-type",L.textContent=g.type;const R=document.createElement("span");R.className="info-target",R.textContent=x,C.appendChild(B),C.appendChild(L),C.appendChild(R);const Y=Object.keys(g.properties);if(Y.length>0){const k=document.createElement("div");k.className="info-edge-props";for(const G of Y){const ne=document.createElement("span");ne.className="info-edge-prop",ne.textContent=`${G}: ${re(g.properties[G])}`,k.appendChild(ne)}C.appendChild(k)}if(n){const k=document.createElement("button");k.className="info-delete-edge",k.textContent="×",k.title="Remove connection",k.addEventListener("click",G=>{G.stopPropagation(),n.onDeleteEdge(g.id)}),C.appendChild(k)}A.appendChild(C)}w.appendChild(A),t.appendChild(w)}const U=ae("Timestamps"),z=document.createElement("dl");z.className="info-props";const T=document.createElement("dt");T.textContent="created";const P=document.createElement("dd");P.textContent=Ce(r.createdAt);const H=document.createElement("dt");H.textContent="updated";const $=document.createElement("dd");if($.textContent=Ce(r.updatedAt),z.appendChild(T),z.appendChild(P),z.appendChild(H),z.appendChild($),U.appendChild(z),t.appendChild(U),n){const w=document.createElement("div");w.className="info-section info-danger";const A=document.createElement("button");A.className="info-delete-node",A.textContent="Delete node",A.addEventListener("click",()=>{n.onDeleteNode(u),h()}),w.appendChild(A),t.appendChild(w)}}function _(u,v){const r=new Set(u),E=v.nodes.filter(T=>r.has(T.id));if(E.length===0)return;const S=v.edges.filter(T=>r.has(T.sourceId)&&r.has(T.targetId));t.innerHTML="",t.classList.remove("hidden"),d&&t.classList.add("info-panel-maximized"),t.appendChild(M());const D=document.createElement("div");D.className="info-header";const X=document.createElement("h3");X.className="info-label",X.textContent=`${E.length} nodes selected`,D.appendChild(X);const F=document.createElement("div");F.style.cssText="display:flex;flex-wrap:wrap;gap:4px;margin-top:6px";const j=new Map;for(const T of E)j.set(T.type,(j.get(T.type)??0)+1);for(const[T,P]of j){const H=document.createElement("span");H.className="info-type-badge",H.style.backgroundColor=ee(T),H.textContent=P>1?`${T} (${P})`:T,F.appendChild(H)}D.appendChild(F),t.appendChild(D);const W=ae("Selected Nodes"),U=document.createElement("ul");U.className="info-connections";for(const T of E){const P=document.createElement("li");P.className="info-connection",o&&(P.classList.add("info-connection-link"),P.addEventListener("click",()=>{m(T.id)}));const H=document.createElement("span");H.className="info-target-dot",H.style.backgroundColor=ee(T.type);const $=document.createElement("span");$.className="info-target",$.textContent=se(T);const w=document.createElement("span");w.className="info-edge-type",w.textContent=T.type,P.appendChild(H),P.appendChild($),P.appendChild(w),U.appendChild(P)}W.appendChild(U),t.appendChild(W);const z=ae(S.length>0?`Connections Between Selected (${S.length})`:"Connections Between Selected");if(S.length===0){const T=document.createElement("p");T.style.cssText="font-size:12px;color:var(--text-dim)",T.textContent="No direct connections between selected nodes",z.appendChild(T)}else{const T=document.createElement("ul");T.className="info-connections";for(const P of S){const H=v.nodes.find(L=>L.id===P.sourceId),$=v.nodes.find(L=>L.id===P.targetId),w=H?se(H):P.sourceId,A=$?se($):P.targetId,g=document.createElement("li");if(g.className="info-connection",H){const L=document.createElement("span");L.className="info-target-dot",L.style.backgroundColor=ee(H.type),g.appendChild(L)}const s=document.createElement("span");s.className="info-target",s.textContent=w;const l=document.createElement("span");l.className="info-arrow",l.textContent="→";const p=document.createElement("span");p.className="info-edge-type",p.textContent=P.type;const x=document.createElement("span");if(x.className="info-arrow",x.textContent="→",g.appendChild(s),g.appendChild(l),g.appendChild(p),g.appendChild(x),$){const L=document.createElement("span");L.className="info-target-dot",L.style.backgroundColor=ee($.type),g.appendChild(L)}const C=document.createElement("span");C.className="info-target",C.textContent=A,g.appendChild(C);const B=Object.keys(P.properties);if(B.length>0){const L=document.createElement("div");L.className="info-edge-props";for(const R of B){const Y=document.createElement("span");Y.className="info-edge-prop",Y.textContent=`${R}: ${re(P.properties[R])}`,L.appendChild(Y)}g.appendChild(L)}T.appendChild(g)}z.appendChild(T)}t.appendChild(z)}return{show(u,v){if(f=v,u.length===1&&!b){const r=u[0];e[c]!==r&&(c<e.length-1&&(e=e.slice(0,c+1)),e.push(r),c=e.length-1)}u.length===1?I(u[0],v):u.length>1&&_(u,v)},hide:h,get visible(){return!t.classList.contains("hidden")}}}function ae(a){const n=document.createElement("div");n.className="info-section";const o=document.createElement("h4");return o.className="info-section-title",o.textContent=a,n.appendChild(o),n}function He(a){if(Array.isArray(a)){const o=document.createElement("div");o.className="info-array";for(const t of a){const d=document.createElement("span");d.className="info-tag",d.textContent=String(t),o.appendChild(d)}return o}if(a!==null&&typeof a=="object"){const o=document.createElement("pre");return o.className="info-json",o.textContent=JSON.stringify(a,null,2),o}const n=document.createElement("span");return n.className="info-value",n.textContent=String(a??""),n}function re(a){return Array.isArray(a)?a.map(String).join(", "):a!==null&&typeof a=="object"?JSON.stringify(a):String(a??"")}function $e(a){const n=a.trim();if(n==="true")return!0;if(n==="false")return!1;if(n!==""&&!isNaN(Number(n)))return Number(n);if(n.startsWith("[")&&n.endsWith("]")||n.startsWith("{")&&n.endsWith("}"))try{return JSON.parse(n)}catch{return a}return a}function Ce(a){try{return new Date(a).toLocaleString()}catch{return a}}function ve(a){for(const n of Object.values(a.properties))if(typeof n=="string")return n;return a.id}function xe(a,n){const o=n.toLowerCase();if(ve(a).toLowerCase().includes(o)||a.type.toLowerCase().includes(o))return!0;for(const t of Object.values(a.properties))if(typeof t=="string"&&t.toLowerCase().includes(o))return!0;return!1}function Ye(a){let n=null,o=null,t=null,d=new Set,e=null;const c=document.createElement("div");c.className="search-overlay hidden";const b=document.createElement("div");b.className="search-input-wrap";const f=document.createElement("input");f.className="search-input",f.type="text",f.placeholder="Search nodes...",f.setAttribute("autocomplete","off"),f.setAttribute("spellcheck","false");const h=document.createElement("kbd");h.className="search-kbd",h.textContent="/",b.appendChild(f),b.appendChild(h);const m=document.createElement("ul");m.className="search-results hidden";const i=document.createElement("div");i.className="type-chips",c.appendChild(b),c.appendChild(m),c.appendChild(i),a.appendChild(c);function y(){if(i.innerHTML="",!n)return;const u=new Map;for(const r of n.nodes)u.set(r.type,(u.get(r.type)??0)+1);const v=[...u.keys()].sort();d=new Set;for(const r of v){const E=document.createElement("button");E.className="type-chip",E.dataset.type=r;const S=document.createElement("span");S.className="type-chip-dot",S.style.backgroundColor=ee(r);const D=document.createElement("span");D.textContent=`${r} (${u.get(r)})`,E.appendChild(S),E.appendChild(D),E.addEventListener("click",()=>{d.has(r)?(d.delete(r),E.classList.remove("active")):(d.add(r),E.classList.add("active")),I()}),i.appendChild(E)}}function M(){if(!n)return null;const u=f.value.trim(),v=d.size===0,r=u.length===0;if(r&&v)return null;const E=new Set;for(const S of n.nodes)!v&&!d.has(S.type)||(r||xe(S,u))&&E.add(S.id);return E}function I(){const u=M();o==null||o(u),_()}function _(){m.innerHTML="";const u=f.value.trim();if(!n||u.length===0){m.classList.add("hidden");return}const v=d.size===0,r=[];for(const E of n.nodes)if(!(!v&&!d.has(E.type))&&xe(E,u)&&(r.push(E),r.length>=8))break;if(r.length===0){m.classList.add("hidden");return}for(const E of r){const S=document.createElement("li");S.className="search-result-item";const D=document.createElement("span");D.className="search-result-dot",D.style.backgroundColor=ee(E.type);const X=document.createElement("span");X.className="search-result-label";const F=ve(E);X.textContent=F.length>36?F.slice(0,34)+"...":F;const j=document.createElement("span");j.className="search-result-type",j.textContent=E.type,S.appendChild(D),S.appendChild(X),S.appendChild(j),S.addEventListener("click",()=>{t==null||t(E.id),f.value="",m.classList.add("hidden"),I()}),m.appendChild(S)}m.classList.remove("hidden")}return f.addEventListener("input",()=>{e&&clearTimeout(e),e=setTimeout(I,150)}),f.addEventListener("keydown",u=>{if(u.key==="Escape")f.value="",f.blur(),m.classList.add("hidden"),I();else if(u.key==="Enter"){const v=m.querySelector(".search-result-item");v==null||v.click()}}),document.addEventListener("click",u=>{c.contains(u.target)||m.classList.add("hidden")}),f.addEventListener("focus",()=>h.classList.add("hidden")),f.addEventListener("blur",()=>{f.value.length===0&&h.classList.remove("hidden")}),{setOntologyData(u){n=u,f.value="",m.classList.add("hidden"),n&&n.nodes.length>0?(c.classList.remove("hidden"),y()):c.classList.add("hidden")},onFilterChange(u){o=u},onNodeSelect(u){t=u},clear(){f.value="",m.classList.add("hidden"),d.clear(),o==null||o(null)},focus(){f.focus()}}}let Z="",N=null;async function Fe(){const a=document.getElementById("canvas-container"),n=window.matchMedia("(prefers-color-scheme: dark)"),t=localStorage.getItem("backpack-theme")??(n.matches?"dark":"light");document.documentElement.setAttribute("data-theme",t);const d=document.createElement("button");d.className="theme-toggle",d.textContent=t==="light"?"☾":"☼",d.title="Toggle light/dark mode",d.addEventListener("click",()=>{const y=document.documentElement.getAttribute("data-theme")==="light"?"dark":"light";document.documentElement.setAttribute("data-theme",y),localStorage.setItem("backpack-theme",y),d.textContent=y==="light"?"☾":"☼"}),a.appendChild(d);async function e(){if(!Z||!N)return;N.metadata.updatedAt=new Date().toISOString(),await Se(Z,N),c.loadGraph(N),f.setOntologyData(N);const i=await ie();h.setSummaries(i)}let c;const b=ze(a,{onUpdateNode(i,y){if(!N)return;const M=N.nodes.find(I=>I.id===i);M&&(M.properties={...M.properties,...y},M.updatedAt=new Date().toISOString(),e().then(()=>b.show([i],N)))},onChangeNodeType(i,y){if(!N)return;const M=N.nodes.find(I=>I.id===i);M&&(M.type=y,M.updatedAt=new Date().toISOString(),e().then(()=>b.show([i],N)))},onDeleteNode(i){N&&(N.nodes=N.nodes.filter(y=>y.id!==i),N.edges=N.edges.filter(y=>y.sourceId!==i&&y.targetId!==i),e())},onDeleteEdge(i){var M;if(!N)return;const y=(M=N.edges.find(I=>I.id===i))==null?void 0:M.sourceId;N.edges=N.edges.filter(I=>I.id!==i),e().then(()=>{y&&N&&b.show([y],N)})},onAddProperty(i,y,M){if(!N)return;const I=N.nodes.find(_=>_.id===i);I&&(I.properties[y]=M,I.updatedAt=new Date().toISOString(),e().then(()=>b.show([i],N)))}},i=>{c.panToNode(i)});c=Be(a,i=>{i&&i.length>0&&N?b.show(i,N):b.hide()});const f=Ye(a);f.onFilterChange(i=>{c.setFilteredNodeIds(i)}),f.onNodeSelect(i=>{c.panToNode(i),N&&b.show([i],N)});const h=Ie(document.getElementById("sidebar"),{onSelect:async i=>{Z=i,h.setActive(i),b.hide(),f.clear(),N=await le(i),c.loadGraph(N),f.setOntologyData(N)},onRename:async(i,y)=>{await Me(i,y),Z===i&&(Z=y);const M=await ie();h.setSummaries(M),h.setActive(Z),Z===y&&(N=await le(y),c.loadGraph(N),f.setOntologyData(N))}}),m=await ie();h.setSummaries(m),m.length>0&&(Z=m[0].name,h.setActive(Z),N=await le(Z),c.loadGraph(N),f.setOntologyData(N)),document.addEventListener("keydown",i=>{i.target instanceof HTMLInputElement||i.target instanceof HTMLTextAreaElement||(i.key==="/"||i.key==="k"&&(i.metaKey||i.ctrlKey))&&(i.preventDefault(),f.focus())})}Fe();
@@ -0,0 +1 @@
1
+ *{margin:0;padding:0;box-sizing:border-box}:root{--bg: #141414;--bg-surface: #1a1a1a;--bg-hover: #222222;--bg-active: #2a2a2a;--bg-elevated: #1e1e1e;--bg-inset: #111111;--border: #2a2a2a;--text: #d4d4d4;--text-strong: #e5e5e5;--text-muted: #737373;--text-dim: #525252;--accent: #d4a27f;--accent-hover: #e8b898;--badge-text: #141414;--glass-bg: rgba(20, 20, 20, .85);--glass-border: rgba(255, 255, 255, .08);--chip-bg: rgba(42, 42, 42, .7);--chip-bg-active: rgba(42, 42, 42, .9);--chip-bg-hover: rgba(50, 50, 50, .9);--chip-border-active: rgba(255, 255, 255, .06);--shadow: rgba(0, 0, 0, .6);--shadow-strong: rgba(0, 0, 0, .5);--canvas-edge: rgba(255, 255, 255, .08);--canvas-edge-highlight: rgba(212, 162, 127, .5);--canvas-edge-dim: rgba(255, 255, 255, .03);--canvas-edge-label: rgba(255, 255, 255, .2);--canvas-edge-label-highlight: rgba(212, 162, 127, .7);--canvas-edge-label-dim: rgba(255, 255, 255, .05);--canvas-arrow: rgba(255, 255, 255, .12);--canvas-arrow-highlight: rgba(212, 162, 127, .5);--canvas-node-label: #a3a3a3;--canvas-node-label-dim: rgba(212, 212, 212, .2);--canvas-type-badge: rgba(115, 115, 115, .5);--canvas-type-badge-dim: rgba(115, 115, 115, .15);--canvas-selection-border: #d4d4d4;--canvas-node-border: rgba(255, 255, 255, .15)}[data-theme=light]{--bg: #f5f5f4;--bg-surface: #fafaf9;--bg-hover: #f0efee;--bg-active: #e7e5e4;--bg-elevated: #f0efee;--bg-inset: #e7e5e4;--border: #d6d3d1;--text: #292524;--text-strong: #1c1917;--text-muted: #78716c;--text-dim: #a8a29e;--accent: #c17856;--accent-hover: #b07a5e;--badge-text: #fafaf9;--glass-bg: rgba(250, 250, 249, .85);--glass-border: rgba(0, 0, 0, .08);--chip-bg: rgba(214, 211, 209, .5);--chip-bg-active: rgba(214, 211, 209, .8);--chip-bg-hover: rgba(200, 197, 195, .8);--chip-border-active: rgba(0, 0, 0, .08);--shadow: rgba(0, 0, 0, .1);--shadow-strong: rgba(0, 0, 0, .15);--canvas-edge: rgba(0, 0, 0, .1);--canvas-edge-highlight: rgba(193, 120, 86, .6);--canvas-edge-dim: rgba(0, 0, 0, .03);--canvas-edge-label: rgba(0, 0, 0, .25);--canvas-edge-label-highlight: rgba(193, 120, 86, .8);--canvas-edge-label-dim: rgba(0, 0, 0, .06);--canvas-arrow: rgba(0, 0, 0, .15);--canvas-arrow-highlight: rgba(193, 120, 86, .6);--canvas-node-label: #57534e;--canvas-node-label-dim: rgba(87, 83, 78, .2);--canvas-type-badge: rgba(87, 83, 78, .5);--canvas-type-badge-dim: rgba(87, 83, 78, .15);--canvas-selection-border: #292524;--canvas-node-border: rgba(0, 0, 0, .1)}body{font-family:system-ui,-apple-system,sans-serif;background:var(--bg);color:var(--text);overflow:hidden}#app{display:flex;height:100vh;width:100vw}#sidebar{width:280px;min-width:280px;background:var(--bg-surface);border-right:1px solid var(--border);display:flex;flex-direction:column;padding:16px;overflow-y:auto}#sidebar h2{font-size:13px;font-weight:600;text-transform:uppercase;letter-spacing:.05em;color:var(--text-muted);margin-bottom:14px}#sidebar input{width:100%;padding:8px 12px;border:1px solid var(--border);border-radius:6px;background:var(--bg);color:var(--text);font-size:13px;outline:none;margin-bottom:12px}#sidebar input:focus{border-color:var(--accent)}#sidebar input::placeholder{color:var(--text-dim)}#ontology-list{list-style:none;display:flex;flex-direction:column;gap:2px}.ontology-item{padding:10px 12px;border-radius:6px;cursor:pointer;transition:background .15s}.ontology-item:hover{background:var(--bg-hover)}.ontology-item.active{background:var(--bg-active)}.ontology-item .name{display:block;font-size:13px;font-weight:500;color:var(--text)}.ontology-item .stats{display:block;font-size:11px;color:var(--text-dim);margin-top:2px}.sidebar-edit-btn{position:absolute;right:8px;top:10px;background:none;border:none;color:var(--text-dim);font-size:11px;cursor:pointer;opacity:0;transition:opacity .1s}.ontology-item{position:relative}.ontology-item:hover .sidebar-edit-btn{opacity:.7}.sidebar-edit-btn:hover{opacity:1!important;color:var(--text)}.sidebar-rename-input{background:transparent;border:none;border-bottom:1px solid var(--accent);color:var(--text);font:inherit;font-size:13px;font-weight:500;outline:none;width:100%;padding:0}.sidebar-footer{margin-top:auto;padding-top:16px;border-top:1px solid var(--border);text-align:center}.sidebar-footer a{display:block;font-size:12px;font-weight:500;color:var(--accent);text-decoration:none;margin-bottom:4px}.sidebar-footer a:hover{color:var(--accent-hover)}.sidebar-footer span{display:block;font-size:10px;color:var(--text-dim)}.theme-toggle{position:absolute;top:16px;right:16px;z-index:30;background:var(--bg-surface);border:1px solid var(--border);border-radius:8px;color:var(--text-muted);font-size:18px;cursor:pointer;padding:6px 10px;line-height:1;transition:color .15s,border-color .15s,background .15s;box-shadow:0 2px 8px var(--shadow)}.theme-toggle:hover{color:var(--text);border-color:var(--text-muted);background:var(--bg-hover)}.zoom-controls{position:absolute;top:16px;right:16px;z-index:30;display:flex;gap:4px;transition:right .2s ease}.theme-toggle~.zoom-controls{right:58px}.zoom-btn{background:var(--bg-surface);border:1px solid var(--border);border-radius:8px;color:var(--text-muted);font-size:18px;cursor:pointer;padding:6px 10px;line-height:1;transition:color .15s,border-color .15s,background .15s;box-shadow:0 2px 8px var(--shadow)}.zoom-btn:hover{color:var(--text);border-color:var(--text-muted);background:var(--bg-hover)}#canvas-container{flex:1;position:relative;overflow:hidden}#graph-canvas{position:absolute;top:0;left:0;width:100%;height:100%;cursor:grab}#graph-canvas:active{cursor:grabbing}.search-overlay{position:absolute;top:16px;left:50%;transform:translate(-50%);z-index:20;display:flex;flex-direction:column;align-items:center;gap:8px;max-height:calc(100vh - 48px);pointer-events:none}.search-overlay>*{pointer-events:auto}.search-overlay.hidden{display:none}.search-input-wrap{position:relative;width:380px;max-width:calc(100vw - 340px)}.search-input{width:100%;padding:10px 36px 10px 16px;border:1px solid var(--glass-border);border-radius:10px;background:var(--glass-bg);backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px);color:var(--text);font-size:14px;outline:none;transition:border-color .15s,box-shadow .15s}.search-input:focus{border-color:#d4a27f66;box-shadow:0 0 0 3px #d4a27f1a}.search-input::placeholder{color:var(--text-dim)}.search-kbd{position:absolute;right:10px;top:50%;transform:translateY(-50%);padding:2px 7px;border:1px solid var(--border);border-radius:4px;background:var(--bg-surface);color:var(--text-dim);font-size:11px;font-family:monospace;pointer-events:none}.search-kbd.hidden{display:none}.search-results{list-style:none;width:380px;max-width:calc(100vw - 340px);background:var(--glass-bg);backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px);border:1px solid var(--border);border-radius:10px;overflow:hidden;box-shadow:0 8px 32px var(--shadow-strong)}.search-results.hidden{display:none}.search-result-item{display:flex;align-items:center;gap:8px;padding:8px 14px;cursor:pointer;transition:background .1s}.search-result-item:hover{background:var(--bg-hover)}.search-result-dot{width:8px;height:8px;border-radius:50%;flex-shrink:0}.search-result-label{font-size:13px;color:var(--text);flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.search-result-type{font-size:11px;color:var(--text-dim);flex-shrink:0}.type-chips{display:flex;flex-wrap:wrap;gap:4px;justify-content:center;max-width:500px;max-height:200px;overflow-y:auto;padding:4px;border-radius:10px}.type-chip{display:flex;align-items:center;gap:4px;padding:3px 10px;border:1px solid transparent;border-radius:12px;background:var(--chip-bg);color:var(--text-dim);font-size:11px;cursor:pointer;transition:all .15s;white-space:nowrap}.type-chip.active{background:var(--chip-bg-active);color:var(--text-muted);border-color:var(--chip-border-active)}.type-chip:hover{background:var(--chip-bg-hover)}.type-chip-dot{width:6px;height:6px;border-radius:50%;flex-shrink:0}.type-chip:not(.active) .type-chip-dot{opacity:.3}.info-panel{position:absolute;top:56px;right:16px;width:360px;max-height:calc(100vh - 72px);background:var(--bg-surface);border:1px solid var(--border);border-radius:10px;overflow-y:auto;padding:20px;z-index:10;box-shadow:0 8px 32px var(--shadow);transition:top .25s ease,right .25s ease,bottom .25s ease,left .25s ease,width .25s ease,max-height .25s ease,border-radius .25s ease}.info-panel.hidden{display:none}.info-panel.info-panel-maximized{top:0;right:0;bottom:0;left:0;width:auto;max-height:none;border-radius:0;z-index:40}.info-panel-toolbar{position:absolute;top:12px;right:14px;display:flex;align-items:center;gap:2px;z-index:1}.info-toolbar-btn{background:none;border:none;color:var(--text-muted);font-size:16px;cursor:pointer;padding:4px 6px;line-height:1;border-radius:4px;transition:color .15s,background .15s}.info-toolbar-btn:hover:not(:disabled){color:var(--text);background:var(--bg-hover)}.info-toolbar-btn:disabled{color:var(--text-dim);cursor:default;opacity:.3}.info-close-btn{font-size:20px}.info-connection-link{cursor:pointer;transition:background .15s}.info-connection-link:hover{background:var(--bg-active)}.info-connection-link .info-target{color:var(--accent);text-decoration:underline;text-decoration-color:transparent;transition:text-decoration-color .15s}.info-connection-link:hover .info-target{text-decoration-color:var(--accent)}.info-header{margin-bottom:16px}.info-type-badge{display:inline-block;padding:3px 10px;border-radius:12px;font-size:11px;font-weight:600;color:var(--badge-text);margin-bottom:8px}.info-label{font-size:18px;font-weight:600;color:var(--text-strong);margin-bottom:4px;word-break:break-word}.info-id{display:block;font-size:11px;color:var(--text-dim);font-family:monospace}.info-section{margin-bottom:16px}.info-section-title{font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.05em;color:var(--text-muted);margin-bottom:8px;padding-bottom:4px;border-bottom:1px solid var(--border)}.info-props{display:grid;grid-template-columns:auto 1fr;gap:4px 12px}.info-props dt{font-size:12px;color:var(--text-muted);padding-top:2px}.info-props dd{font-size:12px;color:var(--text);word-break:break-word;display:flex;align-items:center;gap:4px}.info-value{white-space:pre-wrap}.info-array{display:flex;flex-wrap:wrap;gap:4px}.info-tag{display:inline-block;padding:2px 8px;background:var(--bg-hover);border-radius:4px;font-size:11px;color:var(--text-muted)}.info-json{font-size:11px;font-family:monospace;color:var(--text-muted);background:var(--bg-inset);padding:6px 8px;border-radius:4px;overflow-x:auto;white-space:pre}.info-connections{list-style:none;display:flex;flex-direction:column;gap:6px}.info-connection{display:flex;align-items:center;gap:6px;padding:6px 8px;background:var(--bg-elevated);border-radius:6px;font-size:12px;flex-wrap:wrap}.info-target-dot{width:8px;height:8px;border-radius:50%;flex-shrink:0}.info-arrow{color:var(--text-dim);font-size:14px;flex-shrink:0}.info-edge-type{color:var(--text-muted);font-size:11px;font-weight:500}.info-target{color:var(--text);font-weight:500}.info-edge-props{width:100%;padding-top:4px;padding-left:20px}.info-edge-prop{display:block;font-size:11px;color:var(--text-dim)}.info-editable{cursor:default;position:relative}.info-inline-edit{background:none;border:none;color:var(--badge-text);opacity:0;font-size:10px;cursor:pointer;margin-left:4px;transition:opacity .15s}.info-editable:hover .info-inline-edit{opacity:.8}.info-inline-edit:hover{opacity:1!important}.info-edit-inline-input{background:transparent;border:none;border-bottom:1px solid var(--accent);color:var(--badge-text);font:inherit;font-size:inherit;outline:none;width:100%;padding:0}.info-edit-input{background:var(--bg-inset);border:1px solid var(--border);border-radius:4px;padding:3px 6px;font-size:12px;color:var(--text);flex:1;min-width:0}.info-edit-input:focus{outline:none;border-color:var(--accent)}.info-delete-prop{background:none;border:none;color:var(--text-dim);font-size:14px;cursor:pointer;padding:0 2px;flex-shrink:0;opacity:0;transition:opacity .1s,color .1s}.info-props dd:hover .info-delete-prop{opacity:1}.info-delete-prop:hover{color:#ef4444}.info-add-btn{background:none;border:1px dashed var(--border);border-radius:4px;padding:6px 10px;font-size:12px;color:var(--text-dim);cursor:pointer;width:100%;margin-top:8px;transition:border-color .15s,color .15s}.info-add-btn:hover{border-color:var(--accent);color:var(--text)}.info-add-row{display:flex;gap:4px;margin-top:6px}.info-add-save{background:var(--accent);border:none;border-radius:4px;padding:3px 10px;font-size:12px;color:var(--badge-text);cursor:pointer;flex-shrink:0}.info-add-save:hover{background:var(--accent-hover)}.info-delete-edge{background:none;border:none;color:var(--text-dim);font-size:14px;cursor:pointer;margin-left:auto;padding:0 2px;opacity:0;transition:opacity .1s,color .1s}.info-connection:hover .info-delete-edge{opacity:1}.info-delete-edge:hover{color:#ef4444}.info-danger{margin-top:8px;padding-top:12px;border-top:1px solid var(--border)}.info-delete-node{background:none;border:1px solid rgba(239,68,68,.3);border-radius:6px;padding:6px 12px;font-size:12px;color:#ef4444;cursor:pointer;width:100%;transition:background .15s}.info-delete-node:hover{background:#ef44441a}
@@ -4,8 +4,8 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Backpack Ontology Viewer</title>
7
- <script type="module" crossorigin src="/assets/index-CCGK0wTJ.js"></script>
8
- <link rel="stylesheet" crossorigin href="/assets/index-Bm7EACmJ.css">
7
+ <script type="module" crossorigin src="/assets/index-BHUjYf4x.js"></script>
8
+ <link rel="stylesheet" crossorigin href="/assets/index-CLyb9OCm.css">
9
9
  </head>
10
10
  <body>
11
11
  <div id="app">
@@ -0,0 +1,7 @@
1
+ import type { OntologyData } from "backpack-ontology";
2
+ export declare function initCanvas(container: HTMLElement, onNodeClick?: (nodeIds: string[] | null) => void): {
3
+ loadGraph(data: OntologyData): void;
4
+ setFilteredNodeIds(ids: Set<string> | null): void;
5
+ panToNode(nodeId: string): void;
6
+ destroy(): void;
7
+ };
package/dist/canvas.js ADDED
@@ -0,0 +1,470 @@
1
+ import { createLayout, tick } from "./layout";
2
+ import { getColor } from "./colors";
3
+ /** Read a CSS custom property from :root. */
4
+ function cssVar(name) {
5
+ return getComputedStyle(document.documentElement).getPropertyValue(name).trim();
6
+ }
7
+ const NODE_RADIUS = 20;
8
+ const ALPHA_MIN = 0.001;
9
+ export function initCanvas(container, onNodeClick) {
10
+ const canvas = container.querySelector("canvas");
11
+ const ctx = canvas.getContext("2d");
12
+ const dpr = window.devicePixelRatio || 1;
13
+ let camera = { x: 0, y: 0, scale: 1 };
14
+ let state = null;
15
+ let alpha = 1;
16
+ let animFrame = 0;
17
+ let selectedNodeIds = new Set();
18
+ let filteredNodeIds = null; // null = no filter (show all)
19
+ // Pan animation state
20
+ let panTarget = null;
21
+ let panStart = null;
22
+ const PAN_DURATION = 300;
23
+ // --- Sizing ---
24
+ function resize() {
25
+ canvas.width = canvas.clientWidth * dpr;
26
+ canvas.height = canvas.clientHeight * dpr;
27
+ render();
28
+ }
29
+ const observer = new ResizeObserver(resize);
30
+ observer.observe(container);
31
+ resize();
32
+ // --- Coordinate transforms ---
33
+ function screenToWorld(sx, sy) {
34
+ return [
35
+ sx / camera.scale + camera.x,
36
+ sy / camera.scale + camera.y,
37
+ ];
38
+ }
39
+ // --- Hit testing ---
40
+ function nodeAtScreen(sx, sy) {
41
+ if (!state)
42
+ return null;
43
+ const [wx, wy] = screenToWorld(sx, sy);
44
+ // Iterate in reverse so topmost (last drawn) nodes are hit first
45
+ for (let i = state.nodes.length - 1; i >= 0; i--) {
46
+ const node = state.nodes[i];
47
+ const dx = wx - node.x;
48
+ const dy = wy - node.y;
49
+ if (dx * dx + dy * dy <= NODE_RADIUS * NODE_RADIUS) {
50
+ return node;
51
+ }
52
+ }
53
+ return null;
54
+ }
55
+ // --- Rendering ---
56
+ function render() {
57
+ if (!state) {
58
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
59
+ return;
60
+ }
61
+ // Read theme colors from CSS variables each frame
62
+ const edgeColor = cssVar("--canvas-edge");
63
+ const edgeHighlight = cssVar("--canvas-edge-highlight");
64
+ const edgeDimColor = cssVar("--canvas-edge-dim");
65
+ const edgeLabel = cssVar("--canvas-edge-label");
66
+ const edgeLabelHighlight = cssVar("--canvas-edge-label-highlight");
67
+ const edgeLabelDim = cssVar("--canvas-edge-label-dim");
68
+ const arrowColor = cssVar("--canvas-arrow");
69
+ const arrowHighlight = cssVar("--canvas-arrow-highlight");
70
+ const nodeLabel = cssVar("--canvas-node-label");
71
+ const nodeLabelDim = cssVar("--canvas-node-label-dim");
72
+ const typeBadge = cssVar("--canvas-type-badge");
73
+ const typeBadgeDim = cssVar("--canvas-type-badge-dim");
74
+ const selectionBorder = cssVar("--canvas-selection-border");
75
+ const nodeBorder = cssVar("--canvas-node-border");
76
+ ctx.save();
77
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
78
+ ctx.clearRect(0, 0, canvas.clientWidth, canvas.clientHeight);
79
+ ctx.save();
80
+ ctx.translate(-camera.x * camera.scale, -camera.y * camera.scale);
81
+ ctx.scale(camera.scale, camera.scale);
82
+ // Draw edges
83
+ for (const edge of state.edges) {
84
+ const source = state.nodeMap.get(edge.sourceId);
85
+ const target = state.nodeMap.get(edge.targetId);
86
+ if (!source || !target)
87
+ continue;
88
+ const sourceMatch = filteredNodeIds === null || filteredNodeIds.has(edge.sourceId);
89
+ const targetMatch = filteredNodeIds === null || filteredNodeIds.has(edge.targetId);
90
+ const bothMatch = sourceMatch && targetMatch;
91
+ // Hide edges where neither endpoint matches the filter
92
+ if (filteredNodeIds !== null && !sourceMatch && !targetMatch)
93
+ continue;
94
+ const isConnected = selectedNodeIds.size > 0 &&
95
+ (selectedNodeIds.has(edge.sourceId) || selectedNodeIds.has(edge.targetId));
96
+ const highlighted = isConnected || (filteredNodeIds !== null && bothMatch);
97
+ const edgeDimmed = filteredNodeIds !== null && !bothMatch;
98
+ // Self-loop
99
+ if (edge.sourceId === edge.targetId) {
100
+ drawSelfLoop(source, edge.type, highlighted, edgeColor, edgeHighlight, edgeLabel, edgeLabelHighlight);
101
+ continue;
102
+ }
103
+ // Line
104
+ ctx.beginPath();
105
+ ctx.moveTo(source.x, source.y);
106
+ ctx.lineTo(target.x, target.y);
107
+ ctx.strokeStyle = highlighted
108
+ ? edgeHighlight
109
+ : edgeDimmed
110
+ ? edgeDimColor
111
+ : edgeColor;
112
+ ctx.lineWidth = highlighted ? 2.5 : 1.5;
113
+ ctx.stroke();
114
+ // Arrowhead
115
+ drawArrowhead(source.x, source.y, target.x, target.y, highlighted, arrowColor, arrowHighlight);
116
+ // Edge label at midpoint
117
+ const mx = (source.x + target.x) / 2;
118
+ const my = (source.y + target.y) / 2;
119
+ ctx.fillStyle = highlighted
120
+ ? edgeLabelHighlight
121
+ : edgeDimmed
122
+ ? edgeLabelDim
123
+ : edgeLabel;
124
+ ctx.font = "9px system-ui, sans-serif";
125
+ ctx.textAlign = "center";
126
+ ctx.textBaseline = "bottom";
127
+ ctx.fillText(edge.type, mx, my - 4);
128
+ }
129
+ // Draw nodes
130
+ for (const node of state.nodes) {
131
+ const color = getColor(node.type);
132
+ const isSelected = selectedNodeIds.has(node.id);
133
+ const isNeighbor = selectedNodeIds.size > 0 &&
134
+ state.edges.some((e) => (selectedNodeIds.has(e.sourceId) && e.targetId === node.id) ||
135
+ (selectedNodeIds.has(e.targetId) && e.sourceId === node.id));
136
+ const filteredOut = filteredNodeIds !== null && !filteredNodeIds.has(node.id);
137
+ const dimmed = filteredOut ||
138
+ (selectedNodeIds.size > 0 && !isSelected && !isNeighbor);
139
+ // Glow for selected node
140
+ if (isSelected) {
141
+ ctx.save();
142
+ ctx.shadowColor = color;
143
+ ctx.shadowBlur = 20;
144
+ ctx.beginPath();
145
+ ctx.arc(node.x, node.y, NODE_RADIUS + 3, 0, Math.PI * 2);
146
+ ctx.fillStyle = color;
147
+ ctx.globalAlpha = 0.3;
148
+ ctx.fill();
149
+ ctx.restore();
150
+ }
151
+ // Circle
152
+ ctx.beginPath();
153
+ ctx.arc(node.x, node.y, NODE_RADIUS, 0, Math.PI * 2);
154
+ ctx.fillStyle = color;
155
+ ctx.globalAlpha = filteredOut ? 0.1 : dimmed ? 0.3 : 1;
156
+ ctx.fill();
157
+ ctx.strokeStyle = isSelected ? selectionBorder : nodeBorder;
158
+ ctx.lineWidth = isSelected ? 3 : 1.5;
159
+ ctx.stroke();
160
+ // Label below
161
+ const label = node.label.length > 24 ? node.label.slice(0, 22) + "..." : node.label;
162
+ ctx.fillStyle = dimmed ? nodeLabelDim : nodeLabel;
163
+ ctx.font = "11px system-ui, sans-serif";
164
+ ctx.textAlign = "center";
165
+ ctx.textBaseline = "top";
166
+ ctx.fillText(label, node.x, node.y + NODE_RADIUS + 4);
167
+ // Type badge above
168
+ ctx.fillStyle = dimmed ? typeBadgeDim : typeBadge;
169
+ ctx.font = "9px system-ui, sans-serif";
170
+ ctx.textBaseline = "bottom";
171
+ ctx.fillText(node.type, node.x, node.y - NODE_RADIUS - 3);
172
+ ctx.globalAlpha = 1;
173
+ }
174
+ ctx.restore();
175
+ ctx.restore();
176
+ }
177
+ function drawArrowhead(sx, sy, tx, ty, highlighted, arrowColor, arrowHighlight) {
178
+ const angle = Math.atan2(ty - sy, tx - sx);
179
+ const tipX = tx - Math.cos(angle) * NODE_RADIUS;
180
+ const tipY = ty - Math.sin(angle) * NODE_RADIUS;
181
+ const size = 8;
182
+ ctx.beginPath();
183
+ ctx.moveTo(tipX, tipY);
184
+ ctx.lineTo(tipX - size * Math.cos(angle - 0.4), tipY - size * Math.sin(angle - 0.4));
185
+ ctx.lineTo(tipX - size * Math.cos(angle + 0.4), tipY - size * Math.sin(angle + 0.4));
186
+ ctx.closePath();
187
+ ctx.fillStyle = highlighted ? arrowHighlight : arrowColor;
188
+ ctx.fill();
189
+ }
190
+ function drawSelfLoop(node, type, highlighted, edgeColor, edgeHighlight, labelColor, labelHighlight) {
191
+ const cx = node.x + NODE_RADIUS + 15;
192
+ const cy = node.y - NODE_RADIUS - 15;
193
+ ctx.beginPath();
194
+ ctx.arc(cx, cy, 15, 0, Math.PI * 2);
195
+ ctx.strokeStyle = highlighted ? edgeHighlight : edgeColor;
196
+ ctx.lineWidth = highlighted ? 2.5 : 1.5;
197
+ ctx.stroke();
198
+ ctx.fillStyle = highlighted ? labelHighlight : labelColor;
199
+ ctx.font = "9px system-ui, sans-serif";
200
+ ctx.textAlign = "center";
201
+ ctx.fillText(type, cx, cy - 18);
202
+ }
203
+ // --- Simulation loop ---
204
+ function animatePan() {
205
+ if (!panTarget || !panStart)
206
+ return;
207
+ const elapsed = performance.now() - panStart.time;
208
+ const t = Math.min(elapsed / PAN_DURATION, 1);
209
+ // Ease out cubic
210
+ const ease = 1 - Math.pow(1 - t, 3);
211
+ camera.x = panStart.x + (panTarget.x - panStart.x) * ease;
212
+ camera.y = panStart.y + (panTarget.y - panStart.y) * ease;
213
+ render();
214
+ if (t < 1) {
215
+ requestAnimationFrame(animatePan);
216
+ }
217
+ else {
218
+ panTarget = null;
219
+ panStart = null;
220
+ }
221
+ }
222
+ function simulate() {
223
+ if (!state || alpha < ALPHA_MIN)
224
+ return;
225
+ alpha = tick(state, alpha);
226
+ render();
227
+ animFrame = requestAnimationFrame(simulate);
228
+ }
229
+ // --- Interaction: Pan + Click ---
230
+ let dragging = false;
231
+ let didDrag = false;
232
+ let lastX = 0;
233
+ let lastY = 0;
234
+ canvas.addEventListener("mousedown", (e) => {
235
+ dragging = true;
236
+ didDrag = false;
237
+ lastX = e.clientX;
238
+ lastY = e.clientY;
239
+ });
240
+ canvas.addEventListener("mousemove", (e) => {
241
+ if (!dragging)
242
+ return;
243
+ const dx = e.clientX - lastX;
244
+ const dy = e.clientY - lastY;
245
+ if (Math.abs(dx) > 2 || Math.abs(dy) > 2)
246
+ didDrag = true;
247
+ camera.x -= dx / camera.scale;
248
+ camera.y -= dy / camera.scale;
249
+ lastX = e.clientX;
250
+ lastY = e.clientY;
251
+ render();
252
+ });
253
+ canvas.addEventListener("mouseup", (e) => {
254
+ dragging = false;
255
+ if (didDrag)
256
+ return;
257
+ // Click — hit test for node selection
258
+ const rect = canvas.getBoundingClientRect();
259
+ const mx = e.clientX - rect.left;
260
+ const my = e.clientY - rect.top;
261
+ const hit = nodeAtScreen(mx, my);
262
+ const multiSelect = e.ctrlKey || e.metaKey;
263
+ if (hit) {
264
+ if (multiSelect) {
265
+ // Toggle node in/out of multi-selection
266
+ if (selectedNodeIds.has(hit.id)) {
267
+ selectedNodeIds.delete(hit.id);
268
+ }
269
+ else {
270
+ selectedNodeIds.add(hit.id);
271
+ }
272
+ }
273
+ else {
274
+ // Single click — toggle if already the only selection, otherwise replace
275
+ if (selectedNodeIds.size === 1 && selectedNodeIds.has(hit.id)) {
276
+ selectedNodeIds.clear();
277
+ }
278
+ else {
279
+ selectedNodeIds.clear();
280
+ selectedNodeIds.add(hit.id);
281
+ }
282
+ }
283
+ const ids = [...selectedNodeIds];
284
+ onNodeClick?.(ids.length > 0 ? ids : null);
285
+ }
286
+ else {
287
+ selectedNodeIds.clear();
288
+ onNodeClick?.(null);
289
+ }
290
+ render();
291
+ });
292
+ canvas.addEventListener("mouseleave", () => {
293
+ dragging = false;
294
+ });
295
+ // --- Interaction: Zoom (wheel + pinch) ---
296
+ canvas.addEventListener("wheel", (e) => {
297
+ e.preventDefault();
298
+ const rect = canvas.getBoundingClientRect();
299
+ const mx = e.clientX - rect.left;
300
+ const my = e.clientY - rect.top;
301
+ const [wx, wy] = screenToWorld(mx, my);
302
+ const factor = e.ctrlKey
303
+ ? 1 - e.deltaY * 0.01
304
+ : e.deltaY > 0
305
+ ? 0.9
306
+ : 1.1;
307
+ camera.scale = Math.max(0.05, Math.min(10, camera.scale * factor));
308
+ camera.x = wx - mx / camera.scale;
309
+ camera.y = wy - my / camera.scale;
310
+ render();
311
+ }, { passive: false });
312
+ // --- Interaction: Touch (pinch zoom + drag) ---
313
+ let touches = [];
314
+ let initialPinchDist = 0;
315
+ let initialPinchScale = 1;
316
+ canvas.addEventListener("touchstart", (e) => {
317
+ e.preventDefault();
318
+ touches = Array.from(e.touches);
319
+ if (touches.length === 2) {
320
+ initialPinchDist = touchDistance(touches[0], touches[1]);
321
+ initialPinchScale = camera.scale;
322
+ }
323
+ else if (touches.length === 1) {
324
+ lastX = touches[0].clientX;
325
+ lastY = touches[0].clientY;
326
+ }
327
+ }, { passive: false });
328
+ canvas.addEventListener("touchmove", (e) => {
329
+ e.preventDefault();
330
+ const current = Array.from(e.touches);
331
+ if (current.length === 2 && touches.length === 2) {
332
+ const dist = touchDistance(current[0], current[1]);
333
+ const ratio = dist / initialPinchDist;
334
+ camera.scale = Math.max(0.05, Math.min(10, initialPinchScale * ratio));
335
+ render();
336
+ }
337
+ else if (current.length === 1) {
338
+ const dx = current[0].clientX - lastX;
339
+ const dy = current[0].clientY - lastY;
340
+ camera.x -= dx / camera.scale;
341
+ camera.y -= dy / camera.scale;
342
+ lastX = current[0].clientX;
343
+ lastY = current[0].clientY;
344
+ render();
345
+ }
346
+ touches = current;
347
+ }, { passive: false });
348
+ function touchDistance(a, b) {
349
+ const dx = a.clientX - b.clientX;
350
+ const dy = a.clientY - b.clientY;
351
+ return Math.sqrt(dx * dx + dy * dy);
352
+ }
353
+ // --- Zoom controls ---
354
+ const zoomControls = document.createElement("div");
355
+ zoomControls.className = "zoom-controls";
356
+ const zoomInBtn = document.createElement("button");
357
+ zoomInBtn.className = "zoom-btn";
358
+ zoomInBtn.textContent = "+";
359
+ zoomInBtn.title = "Zoom in";
360
+ zoomInBtn.addEventListener("click", () => {
361
+ const cx = canvas.clientWidth / 2;
362
+ const cy = canvas.clientHeight / 2;
363
+ const [wx, wy] = screenToWorld(cx, cy);
364
+ camera.scale = Math.min(10, camera.scale * 1.3);
365
+ camera.x = wx - cx / camera.scale;
366
+ camera.y = wy - cy / camera.scale;
367
+ render();
368
+ });
369
+ const zoomOutBtn = document.createElement("button");
370
+ zoomOutBtn.className = "zoom-btn";
371
+ zoomOutBtn.textContent = "\u2212";
372
+ zoomOutBtn.title = "Zoom out";
373
+ zoomOutBtn.addEventListener("click", () => {
374
+ const cx = canvas.clientWidth / 2;
375
+ const cy = canvas.clientHeight / 2;
376
+ const [wx, wy] = screenToWorld(cx, cy);
377
+ camera.scale = Math.max(0.05, camera.scale / 1.3);
378
+ camera.x = wx - cx / camera.scale;
379
+ camera.y = wy - cy / camera.scale;
380
+ render();
381
+ });
382
+ const zoomResetBtn = document.createElement("button");
383
+ zoomResetBtn.className = "zoom-btn";
384
+ zoomResetBtn.textContent = "\u25CB";
385
+ zoomResetBtn.title = "Reset zoom";
386
+ zoomResetBtn.addEventListener("click", () => {
387
+ if (!state)
388
+ return;
389
+ camera = { x: 0, y: 0, scale: 1 };
390
+ if (state.nodes.length > 0) {
391
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
392
+ for (const n of state.nodes) {
393
+ if (n.x < minX)
394
+ minX = n.x;
395
+ if (n.y < minY)
396
+ minY = n.y;
397
+ if (n.x > maxX)
398
+ maxX = n.x;
399
+ if (n.y > maxY)
400
+ maxY = n.y;
401
+ }
402
+ const cx = (minX + maxX) / 2;
403
+ const cy = (minY + maxY) / 2;
404
+ camera.x = cx - canvas.clientWidth / 2;
405
+ camera.y = cy - canvas.clientHeight / 2;
406
+ }
407
+ render();
408
+ });
409
+ zoomControls.appendChild(zoomInBtn);
410
+ zoomControls.appendChild(zoomResetBtn);
411
+ zoomControls.appendChild(zoomOutBtn);
412
+ container.appendChild(zoomControls);
413
+ // --- Public API ---
414
+ return {
415
+ loadGraph(data) {
416
+ cancelAnimationFrame(animFrame);
417
+ state = createLayout(data);
418
+ alpha = 1;
419
+ selectedNodeIds = new Set();
420
+ filteredNodeIds = null;
421
+ // Center camera on the graph
422
+ camera = { x: 0, y: 0, scale: 1 };
423
+ if (state.nodes.length > 0) {
424
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
425
+ for (const n of state.nodes) {
426
+ if (n.x < minX)
427
+ minX = n.x;
428
+ if (n.y < minY)
429
+ minY = n.y;
430
+ if (n.x > maxX)
431
+ maxX = n.x;
432
+ if (n.y > maxY)
433
+ maxY = n.y;
434
+ }
435
+ const cx = (minX + maxX) / 2;
436
+ const cy = (minY + maxY) / 2;
437
+ const w = canvas.clientWidth;
438
+ const h = canvas.clientHeight;
439
+ camera.x = cx - w / 2;
440
+ camera.y = cy - h / 2;
441
+ }
442
+ simulate();
443
+ },
444
+ setFilteredNodeIds(ids) {
445
+ filteredNodeIds = ids;
446
+ render();
447
+ },
448
+ panToNode(nodeId) {
449
+ if (!state)
450
+ return;
451
+ const node = state.nodeMap.get(nodeId);
452
+ if (!node)
453
+ return;
454
+ selectedNodeIds = new Set([nodeId]);
455
+ onNodeClick?.([nodeId]);
456
+ const w = canvas.clientWidth;
457
+ const h = canvas.clientHeight;
458
+ panStart = { x: camera.x, y: camera.y, time: performance.now() };
459
+ panTarget = {
460
+ x: node.x - w / (2 * camera.scale),
461
+ y: node.y - h / (2 * camera.scale),
462
+ };
463
+ animatePan();
464
+ },
465
+ destroy() {
466
+ cancelAnimationFrame(animFrame);
467
+ observer.disconnect();
468
+ },
469
+ };
470
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Deterministic type → color mapping.
3
+ * Earth-tone accent palette on a neutral gray UI.
4
+ * These are the only warm colors in the interface —
5
+ * everything else is grayscale.
6
+ */
7
+ export declare function getColor(type: string): string;