dsh-memu-memory 1.3.0 → 1.3.2

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.
Files changed (67) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +3 -3
  3. package/README.zh.md +3 -1
  4. package/docs/contributing.md +2 -2
  5. package/docs/env-and-commands.md +12 -1
  6. package/docs/memory-semantics.md +8 -2
  7. package/docs/troubleshooting.md +9 -6
  8. package/lib/auto-link/apply.js +249 -0
  9. package/lib/auto-link/candidates.js +155 -0
  10. package/lib/auto-link/decide.js +304 -0
  11. package/lib/auto-link/normalize.js +99 -0
  12. package/lib/auto-link/policy.js +42 -0
  13. package/lib/auto-link/suppression.js +101 -0
  14. package/lib/auto-link/terminology.js +265 -0
  15. package/lib/binding-diagnostics.js +3 -3
  16. package/lib/client.js +1435 -70
  17. package/lib/consolidation-receipt.js +81 -5
  18. package/lib/consolidation-worker.js +57 -25
  19. package/lib/curator.js +91 -11
  20. package/lib/engine.js +13 -3
  21. package/lib/graph.js +326 -39
  22. package/lib/inject.js +35 -15
  23. package/lib/media.js +8 -1
  24. package/lib/memory.js +27 -1
  25. package/lib/memu.js +26 -12
  26. package/lib/private-links.js +105 -137
  27. package/lib/private.js +280 -53
  28. package/lib/prompts/global-curator.md +6 -3
  29. package/lib/prompts/system-guide.md +4 -5
  30. package/lib/prompts.js +27 -1
  31. package/lib/rpc.js +69 -9
  32. package/lib/state.js +23 -4
  33. package/lib/tools.js +199 -67
  34. package/lib/webui/graph-LICENSE.txt +1 -62
  35. package/lib/webui/graph-view.bundle.js +1 -1
  36. package/lib/webui/graph-view.js +891 -124
  37. package/lib/webui/standalone.js +3 -3
  38. package/package.json +1 -2
  39. package/scripts/build-graph.mjs +3 -3
  40. package/scripts/check-graph-browser.mjs +106 -23
  41. package/scripts/rebuild-auto-links.mjs +252 -0
  42. package/tests/audit-regression.test.mjs +11 -8
  43. package/tests/auto-link-candidates.test.mjs +161 -0
  44. package/tests/auto-link-decide.test.mjs +512 -0
  45. package/tests/auto-link-migration.test.mjs +133 -0
  46. package/tests/client-render.test.mjs +7 -6
  47. package/tests/consolidation-credential.test.mjs +2 -2
  48. package/tests/consolidation-fork.test.mjs +188 -9
  49. package/tests/consolidation-ledger.test.mjs +31 -0
  50. package/tests/consolidation-snapshot.test.mjs +9 -8
  51. package/tests/curator-probe.test.mjs +32 -2
  52. package/tests/cycle.test.mjs +1 -1
  53. package/tests/graph-view.test.mjs +163 -21
  54. package/tests/graph.test.mjs +26 -0
  55. package/tests/help-page.test.mjs +3 -3
  56. package/tests/inject-conflict.test.mjs +1 -1
  57. package/tests/inject.test.mjs +1 -1
  58. package/tests/injection-chain.test.mjs +2 -2
  59. package/tests/injection-rollback.test.mjs +1 -1
  60. package/tests/memory-chain.test.mjs +28 -0
  61. package/tests/memu-resident-route.test.mjs +130 -0
  62. package/tests/mock-llm.test.mjs +1 -1
  63. package/tests/private-links.test.mjs +81 -45
  64. package/tests/prompts.test.mjs +1 -1
  65. package/tests/stubs/child-process-spy.mjs +14 -0
  66. package/tests/tool-schema.test.mjs +2 -1
  67. package/tests/tools.test.mjs +49 -21
@@ -1,2 +1,2 @@
1
1
  /* Generated by scripts/build-graph.mjs. Licenses: graph-LICENSE.txt */
2
- var DshMemuGraph=(()=>{var ht=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var xe=Object.prototype.hasOwnProperty;var pe=(t,e)=>{for(var n in e)ht(t,n,{get:e[n],enumerable:!0})},de=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of he(e))!xe.call(t,a)&&a!==n&&ht(t,a,{get:()=>e[a],enumerable:!(i=ce(e,a))||i.enumerable});return t};var ye=t=>de(ht({},"__esModule",{value:!0}),t);var De={};pe(De,{DEFAULT_OPTIONS:()=>Nt,createGraphView:()=>Te,createLayout:()=>ee,fitCamera:()=>ne,placeLabels:()=>re,zoomCamera:()=>At});function zt(t){let e=+this._x.call(null,t),n=+this._y.call(null,t);return It(this.cover(e,n),e,n,t)}function It(t,e,n,i){if(isNaN(e)||isNaN(n))return t;var a,f=t._root,s={data:i},o=t._x0,u=t._y0,l=t._x1,d=t._y1,y,m,h,v,r,c,p,g;if(!f)return t._root=s,t;for(;f.length;)if((r=e>=(y=(o+l)/2))?o=y:l=y,(c=n>=(m=(u+d)/2))?u=m:d=m,a=f,!(f=f[p=c<<1|r]))return a[p]=s,t;if(h=+t._x.call(null,f.data),v=+t._y.call(null,f.data),e===h&&n===v)return s.next=f,a?a[p]=s:t._root=s,t;do a=a?a[p]=new Array(4):t._root=new Array(4),(r=e>=(y=(o+l)/2))?o=y:l=y,(c=n>=(m=(u+d)/2))?u=m:d=m;while((p=c<<1|r)===(g=(v>=m)<<1|h>=y));return a[g]=f,a[p]=s,t}function St(t){var e,n,i=t.length,a,f,s=new Array(i),o=new Array(i),u=1/0,l=1/0,d=-1/0,y=-1/0;for(n=0;n<i;++n)isNaN(a=+this._x.call(null,e=t[n]))||isNaN(f=+this._y.call(null,e))||(s[n]=a,o[n]=f,a<u&&(u=a),a>d&&(d=a),f<l&&(l=f),f>y&&(y=f));if(u>d||l>y)return this;for(this.cover(u,l).cover(d,y),n=0;n<i;++n)It(this,s[n],o[n],t[n]);return this}function Tt(t,e){if(isNaN(t=+t)||isNaN(e=+e))return this;var n=this._x0,i=this._y0,a=this._x1,f=this._y1;if(isNaN(n))a=(n=Math.floor(t))+1,f=(i=Math.floor(e))+1;else{for(var s=a-n||1,o=this._root,u,l;n>t||t>=a||i>e||e>=f;)switch(l=(e<i)<<1|t<n,u=new Array(4),u[l]=o,o=u,s*=2,l){case 0:a=n+s,f=i+s;break;case 1:n=a-s,f=i+s;break;case 2:a=n+s,i=f-s;break;case 3:n=a-s,i=f-s;break}this._root&&this._root.length&&(this._root=o)}return this._x0=n,this._y0=i,this._x1=a,this._y1=f,this}function Dt(){var t=[];return this.visit(function(e){if(!e.length)do t.push(e.data);while(e=e.next)}),t}function Ct(t){return arguments.length?this.cover(+t[0][0],+t[0][1]).cover(+t[1][0],+t[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]}function E(t,e,n,i,a){this.node=t,this.x0=e,this.y0=n,this.x1=i,this.y1=a}function Pt(t,e,n){var i,a=this._x0,f=this._y0,s,o,u,l,d=this._x1,y=this._y1,m=[],h=this._root,v,r;for(h&&m.push(new E(h,a,f,d,y)),n==null?n=1/0:(a=t-n,f=e-n,d=t+n,y=e+n,n*=n);v=m.pop();)if(!(!(h=v.node)||(s=v.x0)>d||(o=v.y0)>y||(u=v.x1)<a||(l=v.y1)<f))if(h.length){var c=(s+u)/2,p=(o+l)/2;m.push(new E(h[3],c,p,u,l),new E(h[2],s,p,c,l),new E(h[1],c,o,u,p),new E(h[0],s,o,c,p)),(r=(e>=p)<<1|t>=c)&&(v=m[m.length-1],m[m.length-1]=m[m.length-1-r],m[m.length-1-r]=v)}else{var g=t-+this._x.call(null,h.data),b=e-+this._y.call(null,h.data),w=g*g+b*b;if(w<n){var N=Math.sqrt(n=w);a=t-N,f=e-N,d=t+N,y=e+N,i=h.data}}return i}function Et(t){if(isNaN(d=+this._x.call(null,t))||isNaN(y=+this._y.call(null,t)))return this;var e,n=this._root,i,a,f,s=this._x0,o=this._y0,u=this._x1,l=this._y1,d,y,m,h,v,r,c,p;if(!n)return this;if(n.length)for(;;){if((v=d>=(m=(s+u)/2))?s=m:u=m,(r=y>=(h=(o+l)/2))?o=h:l=h,e=n,!(n=n[c=r<<1|v]))return this;if(!n.length)break;(e[c+1&3]||e[c+2&3]||e[c+3&3])&&(i=e,p=c)}for(;n.data!==t;)if(a=n,!(n=n.next))return this;return(f=n.next)&&delete n.next,a?(f?a.next=f:delete a.next,this):e?(f?e[c]=f:delete e[c],(n=e[0]||e[1]||e[2]||e[3])&&n===(e[3]||e[2]||e[1]||e[0])&&!n.length&&(i?i[p]=n:this._root=n),this):(this._root=f,this)}function Ot(t){for(var e=0,n=t.length;e<n;++e)this.remove(t[e]);return this}function jt(){return this._root}function Rt(){var t=0;return this.visit(function(e){if(!e.length)do++t;while(e=e.next)}),t}function Ft(t){var e=[],n,i=this._root,a,f,s,o,u;for(i&&e.push(new E(i,this._x0,this._y0,this._x1,this._y1));n=e.pop();)if(!t(i=n.node,f=n.x0,s=n.y0,o=n.x1,u=n.y1)&&i.length){var l=(f+o)/2,d=(s+u)/2;(a=i[3])&&e.push(new E(a,l,d,o,u)),(a=i[2])&&e.push(new E(a,f,d,l,u)),(a=i[1])&&e.push(new E(a,l,s,o,d)),(a=i[0])&&e.push(new E(a,f,s,l,d))}return this}function Lt(t){var e=[],n=[],i;for(this._root&&e.push(new E(this._root,this._x0,this._y0,this._x1,this._y1));i=e.pop();){var a=i.node;if(a.length){var f,s=i.x0,o=i.y0,u=i.x1,l=i.y1,d=(s+u)/2,y=(o+l)/2;(f=a[0])&&e.push(new E(f,s,o,d,y)),(f=a[1])&&e.push(new E(f,d,o,u,y)),(f=a[2])&&e.push(new E(f,s,y,d,l)),(f=a[3])&&e.push(new E(f,d,y,u,l))}n.push(i)}for(;i=n.pop();)t(i.node,i.x0,i.y0,i.x1,i.y1);return this}function Bt(t){return t[0]}function Wt(t){return arguments.length?(this._x=t,this):this._x}function Yt(t){return t[1]}function Xt(t){return arguments.length?(this._y=t,this):this._y}function q(t,e,n){var i=new xt(e??Bt,n??Yt,NaN,NaN,NaN,NaN);return t==null?i:i.addAll(t)}function xt(t,e,n,i,a,f){this._x=t,this._y=e,this._x0=n,this._y0=i,this._x1=a,this._y1=f,this._root=void 0}function Ht(t){for(var e={data:t.data},n=e;t=t.next;)n=n.next={data:t.data};return e}var j=q.prototype=xt.prototype;j.copy=function(){var t=new xt(this._x,this._y,this._x0,this._y0,this._x1,this._y1),e=this._root,n,i;if(!e)return t;if(!e.length)return t._root=Ht(e),t;for(n=[{source:e,target:t._root=new Array(4)}];e=n.pop();)for(var a=0;a<4;++a)(i=e.source[a])&&(i.length?n.push({source:i,target:e.target[a]=new Array(4)}):e.target[a]=Ht(i));return t};j.add=zt;j.addAll=St;j.cover=Tt;j.data=Dt;j.extent=Ct;j.find=Pt;j.remove=Et;j.removeAll=Ot;j.root=jt;j.size=Rt;j.visit=Ft;j.visitAfter=Lt;j.x=Wt;j.y=Xt;function P(t){return function(){return t}}function X(t){return(t()-.5)*1e-6}function me(t){return t.x+t.vx}function ge(t){return t.y+t.vy}function pt(t){var e,n,i,a=1,f=1;typeof t!="function"&&(t=P(t==null?1:+t));function s(){for(var l,d=e.length,y,m,h,v,r,c,p=0;p<f;++p)for(y=q(e,me,ge).visitAfter(o),l=0;l<d;++l)m=e[l],r=n[m.index],c=r*r,h=m.x+m.vx,v=m.y+m.vy,y.visit(g);function g(b,w,N,z,I){var T=b.data,O=b.r,D=r+O;if(T){if(T.index>m.index){var L=h-T.x-T.vx,B=v-T.y-T.vy,C=L*L+B*B;C<D*D&&(L===0&&(L=X(i),C+=L*L),B===0&&(B=X(i),C+=B*B),C=(D-(C=Math.sqrt(C)))/C*a,m.vx+=(L*=C)*(D=(O*=O)/(c+O)),m.vy+=(B*=C)*D,T.vx-=L*(D=1-D),T.vy-=B*D)}return}return w>h+D||z<h-D||N>v+D||I<v-D}}function o(l){if(l.data)return l.r=n[l.data.index];for(var d=l.r=0;d<4;++d)l[d]&&l[d].r>l.r&&(l.r=l[d].r)}function u(){if(e){var l,d=e.length,y;for(n=new Array(d),l=0;l<d;++l)y=e[l],n[y.index]=+t(y,l,e)}}return s.initialize=function(l,d){e=l,i=d,u()},s.iterations=function(l){return arguments.length?(f=+l,s):f},s.strength=function(l){return arguments.length?(a=+l,s):a},s.radius=function(l){return arguments.length?(t=typeof l=="function"?l:P(+l),u(),s):t},s}function we(t){return t.index}function Qt(t,e){var n=t.get(e);if(!n)throw new Error("node not found: "+e);return n}function dt(t){var e=we,n=y,i,a=P(30),f,s,o,u,l,d=1;t==null&&(t=[]);function y(c){return 1/Math.min(o[c.source.index],o[c.target.index])}function m(c){for(var p=0,g=t.length;p<d;++p)for(var b=0,w,N,z,I,T,O,D;b<g;++b)w=t[b],N=w.source,z=w.target,I=z.x+z.vx-N.x-N.vx||X(l),T=z.y+z.vy-N.y-N.vy||X(l),O=Math.sqrt(I*I+T*T),O=(O-f[b])/O*c*i[b],I*=O,T*=O,z.vx-=I*(D=u[b]),z.vy-=T*D,N.vx+=I*(D=1-D),N.vy+=T*D}function h(){if(s){var c,p=s.length,g=t.length,b=new Map(s.map((N,z)=>[e(N,z,s),N])),w;for(c=0,o=new Array(p);c<g;++c)w=t[c],w.index=c,typeof w.source!="object"&&(w.source=Qt(b,w.source)),typeof w.target!="object"&&(w.target=Qt(b,w.target)),o[w.source.index]=(o[w.source.index]||0)+1,o[w.target.index]=(o[w.target.index]||0)+1;for(c=0,u=new Array(g);c<g;++c)w=t[c],u[c]=o[w.source.index]/(o[w.source.index]+o[w.target.index]);i=new Array(g),v(),f=new Array(g),r()}}function v(){if(s)for(var c=0,p=t.length;c<p;++c)i[c]=+n(t[c],c,t)}function r(){if(s)for(var c=0,p=t.length;c<p;++c)f[c]=+a(t[c],c,t)}return m.initialize=function(c,p){s=c,l=p,h()},m.links=function(c){return arguments.length?(t=c,h(),m):t},m.id=function(c){return arguments.length?(e=c,m):e},m.iterations=function(c){return arguments.length?(d=+c,m):d},m.strength=function(c){return arguments.length?(n=typeof c=="function"?c:P(+c),v(),m):n},m.distance=function(c){return arguments.length?(a=typeof c=="function"?c:P(+c),r(),m):a},m}var ve={value:()=>{}};function Vt(){for(var t=0,e=arguments.length,n={},i;t<e;++t){if(!(i=arguments[t]+"")||i in n||/[\s.]/.test(i))throw new Error("illegal type: "+i);n[i]=[]}return new rt(n)}function rt(t){this._=t}function _e(t,e){return t.trim().split(/^|\s+/).map(function(n){var i="",a=n.indexOf(".");if(a>=0&&(i=n.slice(a+1),n=n.slice(0,a)),n&&!e.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:i}})}rt.prototype=Vt.prototype={constructor:rt,on:function(t,e){var n=this._,i=_e(t+"",n),a,f=-1,s=i.length;if(arguments.length<2){for(;++f<s;)if((a=(t=i[f]).type)&&(a=Me(n[a],t.name)))return a;return}if(e!=null&&typeof e!="function")throw new Error("invalid callback: "+e);for(;++f<s;)if(a=(t=i[f]).type)n[a]=Ut(n[a],t.name,e);else if(e==null)for(a in n)n[a]=Ut(n[a],t.name,null);return this},copy:function(){var t={},e=this._;for(var n in e)t[n]=e[n].slice();return new rt(t)},call:function(t,e){if((a=arguments.length-2)>0)for(var n=new Array(a),i=0,a,f;i<a;++i)n[i]=arguments[i+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(f=this._[t],i=0,a=f.length;i<a;++i)f[i].value.apply(e,n)},apply:function(t,e,n){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var i=this._[t],a=0,f=i.length;a<f;++a)i[a].value.apply(e,n)}};function Me(t,e){for(var n=0,i=t.length,a;n<i;++n)if((a=t[n]).name===e)return a.value}function Ut(t,e,n){for(var i=0,a=t.length;i<a;++i)if(t[i].name===e){t[i]=ve,t=t.slice(0,i).concat(t.slice(i+1));break}return n!=null&&t.push({name:e,value:n}),t}var yt=Vt;var J=0,Z=0,K=0,$t=1e3,it,tt,ot=0,$=0,at=0,et=typeof performance=="object"&&performance.now?performance:Date,Gt=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function wt(){return $||(Gt(be),$=et.now()+at)}function be(){$=0}function mt(){this._call=this._time=this._next=null}mt.prototype=st.prototype={constructor:mt,restart:function(t,e,n){if(typeof t!="function")throw new TypeError("callback is not a function");n=(n==null?wt():+n)+(e==null?0:+e),!this._next&&tt!==this&&(tt?tt._next=this:it=this,tt=this),this._call=t,this._time=n,gt()},stop:function(){this._call&&(this._call=null,this._time=1/0,gt())}};function st(t,e,n){var i=new mt;return i.restart(t,e,n),i}function Jt(){wt(),++J;for(var t=it,e;t;)(e=$-t._time)>=0&&t._call.call(void 0,e),t=t._next;--J}function qt(){$=(ot=et.now())+at,J=Z=0;try{Jt()}finally{J=0,Ne(),$=0}}function Ae(){var t=et.now(),e=t-ot;e>$t&&(at-=e,ot=t)}function Ne(){for(var t,e=it,n,i=1/0;e;)e._call?(i>e._time&&(i=e._time),t=e,e=e._next):(n=e._next,e._next=null,e=t?t._next=n:it=n);tt=t,gt(i)}function gt(t){if(!J){Z&&(Z=clearTimeout(Z));var e=t-$;e>24?(t<1/0&&(Z=setTimeout(qt,t-et.now()-at)),K&&(K=clearInterval(K))):(K||(ot=et.now(),K=setInterval(Ae,$t)),J=1,Gt(qt))}}function Kt(){let t=1;return()=>(t=(1664525*t+1013904223)%4294967296)/4294967296}function Zt(t){return t.x}function te(t){return t.y}var ke=10,ze=Math.PI*(3-Math.sqrt(5));function vt(t){var e,n=1,i=.001,a=1-Math.pow(i,1/300),f=0,s=.6,o=new Map,u=st(y),l=yt("tick","end"),d=Kt();t==null&&(t=[]);function y(){m(),l.call("tick",e),n<i&&(u.stop(),l.call("end",e))}function m(r){var c,p=t.length,g;r===void 0&&(r=1);for(var b=0;b<r;++b)for(n+=(f-n)*a,o.forEach(function(w){w(n)}),c=0;c<p;++c)g=t[c],g.fx==null?g.x+=g.vx*=s:(g.x=g.fx,g.vx=0),g.fy==null?g.y+=g.vy*=s:(g.y=g.fy,g.vy=0);return e}function h(){for(var r=0,c=t.length,p;r<c;++r){if(p=t[r],p.index=r,p.fx!=null&&(p.x=p.fx),p.fy!=null&&(p.y=p.fy),isNaN(p.x)||isNaN(p.y)){var g=ke*Math.sqrt(.5+r),b=r*ze;p.x=g*Math.cos(b),p.y=g*Math.sin(b)}(isNaN(p.vx)||isNaN(p.vy))&&(p.vx=p.vy=0)}}function v(r){return r.initialize&&r.initialize(t,d),r}return h(),e={tick:m,restart:function(){return u.restart(y),e},stop:function(){return u.stop(),e},nodes:function(r){return arguments.length?(t=r,h(),o.forEach(v),e):t},alpha:function(r){return arguments.length?(n=+r,e):n},alphaMin:function(r){return arguments.length?(i=+r,e):i},alphaDecay:function(r){return arguments.length?(a=+r,e):+a},alphaTarget:function(r){return arguments.length?(f=+r,e):f},velocityDecay:function(r){return arguments.length?(s=1-r,e):1-s},randomSource:function(r){return arguments.length?(d=r,o.forEach(v),e):d},force:function(r,c){return arguments.length>1?(c==null?o.delete(r):o.set(r,v(c)),e):o.get(r)},find:function(r,c,p){var g=0,b=t.length,w,N,z,I,T;for(p==null?p=1/0:p*=p,g=0;g<b;++g)I=t[g],w=r-I.x,N=c-I.y,z=w*w+N*N,z<p&&(T=I,p=z);return T},on:function(r,c){return arguments.length>1?(l.on(r,c),e):l.on(r)}}}function _t(){var t,e,n,i,a=P(-30),f,s=1,o=1/0,u=.81;function l(h){var v,r=t.length,c=q(t,Zt,te).visitAfter(y);for(i=h,v=0;v<r;++v)e=t[v],c.visit(m)}function d(){if(t){var h,v=t.length,r;for(f=new Array(v),h=0;h<v;++h)r=t[h],f[r.index]=+a(r,h,t)}}function y(h){var v=0,r,c,p=0,g,b,w;if(h.length){for(g=b=w=0;w<4;++w)(r=h[w])&&(c=Math.abs(r.value))&&(v+=r.value,p+=c,g+=c*r.x,b+=c*r.y);h.x=g/p,h.y=b/p}else{r=h,r.x=r.data.x,r.y=r.data.y;do v+=f[r.data.index];while(r=r.next)}h.value=v}function m(h,v,r,c){if(!h.value)return!0;var p=h.x-e.x,g=h.y-e.y,b=c-v,w=p*p+g*g;if(b*b/u<w)return w<o&&(p===0&&(p=X(n),w+=p*p),g===0&&(g=X(n),w+=g*g),w<s&&(w=Math.sqrt(s*w)),e.vx+=p*h.value*i/w,e.vy+=g*h.value*i/w),!0;if(h.length||w>=o)return;(h.data!==e||h.next)&&(p===0&&(p=X(n),w+=p*p),g===0&&(g=X(n),w+=g*g),w<s&&(w=Math.sqrt(s*w)));do h.data!==e&&(b=f[h.data.index]*i/w,e.vx+=p*b,e.vy+=g*b);while(h=h.next)}return l.initialize=function(h,v){t=h,n=v,d()},l.strength=function(h){return arguments.length?(a=typeof h=="function"?h:P(+h),d(),l):a},l.distanceMin=function(h){return arguments.length?(s=h*h,l):Math.sqrt(s)},l.distanceMax=function(h){return arguments.length?(o=h*h,l):Math.sqrt(o)},l.theta=function(h){return arguments.length?(u=h*h,l):Math.sqrt(u)},l}function Mt(t){var e=P(.1),n,i,a;typeof t!="function"&&(t=P(t==null?0:+t));function f(o){for(var u=0,l=n.length,d;u<l;++u)d=n[u],d.vx+=(a[u]-d.x)*i[u]*o}function s(){if(n){var o,u=n.length;for(i=new Array(u),a=new Array(u),o=0;o<u;++o)i[o]=isNaN(a[o]=+t(n[o],o,n))?0:+e(n[o],o,n)}}return f.initialize=function(o){n=o,s()},f.strength=function(o){return arguments.length?(e=typeof o=="function"?o:P(+o),s(),f):e},f.x=function(o){return arguments.length?(t=typeof o=="function"?o:P(+o),s(),f):t},f}function bt(t){var e=P(.1),n,i,a;typeof t!="function"&&(t=P(t==null?0:+t));function f(o){for(var u=0,l=n.length,d;u<l;++u)d=n[u],d.vy+=(a[u]-d.y)*i[u]*o}function s(){if(n){var o,u=n.length;for(i=new Array(u),a=new Array(u),o=0;o<u;++o)i[o]=isNaN(a[o]=+t(n[o],o,n))?0:+e(n[o],o,n)}}return f.initialize=function(o){n=o,s()},f.strength=function(o){return arguments.length?(e=typeof o=="function"?o:P(+o),s(),f):e},f.y=function(o){return arguments.length?(t=typeof o=="function"?o:P(+o),s(),f):t},f}var Ie=200,Q=(t,e,n)=>Math.max(e,Math.min(n,t)),Nt=Object.freeze({repulsion:120,distance:100,labels:!0,motion:!0});function ee(){let t=new Map,e=[],n=[],i="",a={...Nt},f=vt().stop().alphaDecay(.035).velocityDecay(.48).force("charge",_t().strength(-a.repulsion).distanceMax(1400)).force("collision",pt(o=>o.radius+12).iterations(2)).force("x",Mt(0).strength(.025)).force("y",bt(0).strength(.025));return{simulation:f,update:o=>{let u=[...new Map((o.nodes||[]).slice(0,Ie).map(r=>[r.id,r])).values()].sort((r,c)=>String(r.id).localeCompare(String(c.id))),l=new Set(u.map(r=>r.id)),d=(o.edges||[]).filter(r=>l.has(r.from)&&l.has(r.to)&&r.from!==r.to),y=JSON.stringify([u.map(r=>r.id),d.map(r=>[r.from,r.to]).sort()]),m=i!==y,h=new Map;for(let r of d)h.set(r.from,(h.get(r.from)||0)+1),h.set(r.to,(h.get(r.to)||0)+1);let v=u.filter(r=>!t.has(r.id));for(let r=0;r<v.length;r++){let c=v[r],p=d.filter(z=>z.from===c.id||z.to===c.id).map(z=>t.get(z.from===c.id?z.to:z.from)).filter(Boolean),g=r*2.399963229728653,b=p.length?32:24*Math.sqrt(r+.5),w=p.length?p.reduce((z,I)=>z+I.x,0)/p.length:0,N=p.length?p.reduce((z,I)=>z+I.y,0)/p.length:0;t.set(c.id,{id:c.id,x:w+Math.cos(g)*b,y:N+Math.sin(g)*b,vx:0,vy:0})}e=u.map(r=>Object.assign(t.get(r.id),r,{degree:h.get(r.id)||0,radius:4+Math.min(3,Math.log2(1+(h.get(r.id)||0)))+Q(Number(r.strength)||0,0,1)*2})),n=d.map(r=>({...r,source:t.get(r.from),target:t.get(r.to)})),m&&(f.nodes(e).force("link",dt(n).id(r=>r.id).distance(a.distance).strength(.18)),f.alpha(i?.25:1)),i=y;for(let r of t.keys())t.size>800&&!l.has(r)&&t.delete(r);return m},get nodes(){return e},get edges(){return n},configure(o){a={...a,...o},f.force("charge").strength(-a.repulsion),f.force("link")?.distance(a.distance),f.alpha(Math.max(.25,f.alpha()))},settle(o=200){f.tick(o)},dispose(){f.stop(),t.clear()}}}function ne(t,e,n){if(!t.length)return{x:e/2,y:n/2,k:1};let i=Math.min(...t.map(u=>u.x-u.radius)),a=Math.max(...t.map(u=>u.x+u.radius)),f=Math.min(...t.map(u=>u.y-u.radius)),s=Math.max(...t.map(u=>u.y+u.radius)),o=Q(Math.min(Math.max(32,e-100)/Math.max(120,a-i),Math.max(32,n-96)/Math.max(120,s-f)),.06,1.6);return{x:e/2-(i+a)*o/2,y:n/2-(f+s)*o/2,k:o}}function At(t,e,n){let i=Q(t.k*e,.06,5);return{k:i,x:n.x-(n.x-t.x)*i/t.k,y:n.y-(n.y-t.y)*i/t.k}}var Se=(t,e)=>t.x<e.x+e.width&&t.x+t.width>e.x&&t.y<e.y+e.height&&t.y+t.height>e.y;function re(t,e,n,i){let a=[...e],f=[];for(let s of t){let{x:o,y:u,radius:l,textWidth:d}=s,y=[{x:o-d/2,y:u+l+5},{x:o-d/2,y:u-l-21},{x:o+l+6,y:u-8},{x:o-l-d-6,y:u-8}];if(s.priority)for(let h of[28,48,72])y.push({x:o-d/2,y:u+l+h},{x:o-d/2,y:u-l-16-h},{x:o+l+h,y:u-8},{x:o-l-d-h,y:u-8});let m=y.map(h=>({...h,width:d,height:16})).find(h=>h.x>=5&&h.y>=5&&h.x+h.width<=n-5&&h.y+h.height<=i-5&&!a.some(v=>Se(h,v)));m&&(a.push({x:m.x-3,y:m.y-2,width:m.width+6,height:m.height+4}),f.push({...s,box:m}))}return f}function Te(t,{onFocus:e=()=>{},onZoom:n=()=>{},tooltip:i,reducedMotion:a=!1,emptyLabel:f=""}={}){let s=t.getContext("2d");if(!s)throw new Error("Canvas 2D is unavailable");let o=ee(),u=1,l=1,d=1,y={x:0,y:0,k:1},m={...Nt},h="",v=null,r=null,c=!1,p=!1,g=null,b=0,w=0,N=new Map,z=[],I=t.ownerDocument.defaultView,T=x=>({x:(x.x-y.x)/y.k,y:(x.y-y.y)/y.k}),O=x=>({x:x.x*y.k+y.x,y:x.y*y.k+y.y}),D=x=>Q(x.radius*Math.sqrt(y.k),2.5,22),L=x=>{let _=t.getBoundingClientRect();return{x:(x.clientX-_.left)*u/_.width,y:(x.clientY-_.top)*l/_.height}},B=x=>{let _=null,k=1/0;for(let A of o.nodes){let W=O(A),V=Math.hypot(W.x-x.x,W.y-x.y);V<=Math.max(10,D(A)+4)&&V<k&&(_=A,k=V)}return _},C=()=>{i&&(i.hidden=!0)},ie=(x,_)=>{v!==x&&(v=x,F()),t.style.cursor=r?"grabbing":x?"pointer":"grab",i&&(i.hidden=!x||!!r,!(!x||r)&&(i.textContent=String(x.title||x.id),i.style.left=`${Q(_.x+14,6,Math.max(6,u-Math.min(260,u-12)))}px`,i.style.top=`${(t.offsetTop||0)+Q(_.y+16,6,l-60)}px`))},oe=()=>{s.setTransform(d,0,0,d,0,0),s.clearRect(0,0,u,l);let x=I.getComputedStyle(t),_=x.color,k=x.getPropertyValue("--dsw-alias-bg-layer-1").trim()||"#ffffff",A=v?.id||h,W=new Set(A?[A]:[]);for(let S of o.edges)S.from===A&&W.add(S.to),S.to===A&&W.add(S.from);s.strokeStyle=_;for(let S of o.edges){let Y=O(S.source),M=O(S.target),R=A&&(S.from===A||S.to===A);s.globalAlpha=R?.6:A?.055:.16,s.lineWidth=R?1.5:.8,s.beginPath(),s.moveTo(Y.x,Y.y),s.lineTo(M.x,M.y),s.stroke()}let V=o.nodes.map(S=>({node:S,...O(S),radius:D(S)})).filter(S=>S.x>=-30&&S.x<=u+30&&S.y>=-30&&S.y<=l+30);for(let S of V){let Y=S.node,M=Y.missing?"#92959c":Y.kind==="global"?"#8b7bd8":Y.kind!=="memory"?"#36a582":Y.layer==="must_remember"?"#d97768":"#618fcd";s.globalAlpha=A&&!W.has(Y.id)?.22:1,s.fillStyle=M,s.beginPath(),s.arc(S.x,S.y,S.radius,0,Math.PI*2),s.fill(),Y.id===A&&(s.strokeStyle=M,s.lineWidth=1.5,s.beginPath(),s.arc(S.x,S.y,S.radius+4,0,Math.PI*2),s.stroke())}if(s.globalAlpha=1,m.labels){s.font="12px system-ui, sans-serif";let S=V.filter(M=>!A||W.has(M.node.id)).filter(M=>y.k>=.45||M.node.id===A||M.node.degree>=3||o.nodes.length<30).sort((M,R)=>+(R.node.id===A)-+(M.node.id===A)||R.node.degree-M.node.degree||String(M.node.id).localeCompare(String(R.node.id))).map(M=>{let R=String(M.node.title||M.node.id),H=R;for(;H.length>1&&s.measureText(H).width>Math.min(136,u-24);)H=H.slice(0,-1);return H!==R&&(H=H.slice(0,-2)+"..."),{...M,text:H,textWidth:s.measureText(H).width+4,priority:M.node.degree>=3||M.node.id===A}}),Y=re(S,V.map(M=>({x:M.x-M.radius-2,y:M.y-M.radius-2,width:M.radius*2+4,height:M.radius*2+4})),u,l);s.textAlign="left",s.textBaseline="top";for(let M of Y){let R={x:Q(M.x,M.box.x,M.box.x+M.box.width),y:Q(M.y,M.box.y,M.box.y+M.box.height)};Math.hypot(R.x-M.x,R.y-M.y)>M.radius+18&&(s.globalAlpha=.25,s.strokeStyle=_,s.lineWidth=.7,s.beginPath(),s.moveTo(M.x,M.y),s.lineTo(R.x,R.y),s.stroke()),s.fillStyle=k,s.globalAlpha=.88,s.fillRect(M.box.x-1,M.box.y,M.box.width+2,M.box.height),s.globalAlpha=M.node.id===A?1:.78,s.fillStyle=_,s.fillText(M.text,M.box.x+2,M.box.y+1)}s.globalAlpha=1}!o.nodes.length&&f&&(s.font="13px system-ui, sans-serif",s.textAlign="center",s.textBaseline="middle",s.fillStyle=_,s.globalAlpha=.55,s.fillText(f,u/2,l/2),s.globalAlpha=1)},ae=x=>{if(g=null,!p){if(m.motion&&!a&&o.simulation.alpha()>o.simulation.alphaMin()){for(w+=b?Math.min(64,x-b):17;w>=1e3/60;w-=1e3/60)o.simulation.tick();b=x,F()}else b=0,w=0;oe()}};function F(){!p&&g===null&&(g=I.requestAnimationFrame(ae))}let ft=()=>{n(y.k),F()},lt=()=>{y=ne(o.nodes,u,l),C(),ft()},nt=(x,_={x:u/2,y:l/2})=>{y=At(y,x,_),C(),ft()},ut=()=>{let x=t.getBoundingClientRect();if(!x.width||!x.height)return;let _=x.width,k=x.height;y.x+=(_-u)/2,y.y+=(k-l)/2,u=_,l=k,d=Math.min(2,I.devicePixelRatio||1),t.width=Math.round(u*d),t.height=Math.round(l*d),F()},G=()=>{r?.node&&(r.node.fx=null,r.node.fy=null,r.node.vx=0,r.node.vy=0)},se=()=>{G();let[x,_]=[...N.values()];r={type:"pinch",distance:Math.max(1,Math.hypot(_.x-x.x,_.y-x.y)),camera:{...y},center:{x:(x.x+_.x)/2,y:(x.y+_.y)/2},moved:!0}},fe=x=>{if(x.button!==0&&x.pointerType!=="touch")return;x.preventDefault(),t.focus({preventScroll:!0});let _=L(x);if(N.set(x.pointerId,_),t.setPointerCapture?.(x.pointerId),N.size>=2){se(),C();return}let k=B(_);r={type:k?"node":"pan",node:k,start:_,camera:{...y},moved:!1,offset:k?{x:k.x-T(_).x,y:k.y-T(_).y}:null},k&&(k.fx=k.x,k.fy=k.y,k.vx=0,k.vy=0),C(),t.style.cursor="grabbing"},le=x=>{let _=L(x);if(!N.has(x.pointerId)||!r){ie(B(_),_);return}if(N.set(x.pointerId,_),r.type==="pinch"){if(N.size<2)return;let[k,A]=[...N.values()],W={x:(k.x+A.x)/2,y:(k.y+A.y)/2};y=At(r.camera,Math.hypot(A.x-k.x,A.y-k.y)/r.distance,r.center),y.x+=W.x-r.center.x,y.y+=W.y-r.center.y,ft()}else{if(r.moved||(r.moved=Math.hypot(_.x-r.start.x,_.y-r.start.y)>5),!r.moved)return;if(r.node){let k=T(_),A=r.node;A.x=A.fx=k.x+r.offset.x,A.y=A.fy=k.y+r.offset.y,A.vx=0,A.vy=0,o.simulation.alpha(Math.max(.08,o.simulation.alpha()))}else y.x=r.camera.x+_.x-r.start.x,y.y=r.camera.y+_.y-r.start.y;F()}},ue=x=>{if(!N.has(x.pointerId))return;let _=x.type!=="pointerup",k=r?.node,A=!_&&!r?.moved&&r?.type!=="pinch";G(),N.delete(x.pointerId),r=null,N.size&&(r={type:"pan",start:[...N.values()][0],camera:{...y},moved:!0}),t.hasPointerCapture?.(x.pointerId)&&t.releasePointerCapture(x.pointerId),A&&e(k?.id||""),v=null,t.style.cursor="grab",C(),F()},U=(x,_,k,A)=>{x.addEventListener(_,k,A),z.push(()=>x.removeEventListener(_,k,A))};U(t,"pointerdown",fe),U(t,"pointermove",le);for(let x of["pointerup","pointercancel","lostpointercapture"])U(t,x,ue);U(t,"pointerleave",()=>{r||(v=null,C(),F())}),U(t,"wheel",x=>{x.preventDefault(),nt(Math.exp(-Q(x.deltaY,-160,160)*.0025),L(x))},{passive:!1}),U(t,"keydown",x=>{if(x.key==="+"||x.key==="=")nt(1.25);else if(x.key==="-")nt(.8);else if(x.key==="0"||x.key==="Home")lt();else if(x.key==="Escape")G(),r=null,N.clear(),e(""),C(),F();else if(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(x.key)){let _=x.shiftKey?90:30;y.x+=x.key==="ArrowLeft"?_:x.key==="ArrowRight"?-_:0,y.y+=x.key==="ArrowUp"?_:x.key==="ArrowDown"?-_:0,F()}else return;x.preventDefault()}),U(I,"blur",()=>{G(),r=null,N.clear(),v=null,C(),F()});let kt=I.ResizeObserver?new I.ResizeObserver(ut):null;kt?.observe(t),U(I,"resize",ut);let ct=I.MutationObserver?new I.MutationObserver(F):null;return ct?.observe(t.ownerDocument.documentElement,{attributes:!0,attributeFilter:["class","data-theme","style"]}),t.ownerDocument.body&&ct?.observe(t.ownerDocument.body,{attributes:!0,attributeFilter:["class","data-theme","style"]}),ut(),{update(x,_=""){r?.node&&!x.nodes.some(A=>A.id===r.node.id)&&(G(),r=null,N.clear());let k=o.update(x);h=_,v&&!o.nodes.includes(v)&&(v=null,C()),!c&&o.nodes.length?(o.settle(220),c=!0,lt()):k&&a&&o.settle(180),F()},configure(x){let _=x.repulsion!==void 0&&x.repulsion!==m.repulsion||x.distance!==void 0&&x.distance!==m.distance;m={...m,...x},_&&(o.configure(m),a&&o.settle(180)),F()},fit:lt,zoom:nt,dispose(){p=!0,G(),g!==null&&I.cancelAnimationFrame(g);for(let x of z)x();kt?.disconnect(),ct?.disconnect(),o.dispose(),C()}}}return ye(De);})();
2
+ var DshMemuGraph=(()=>{var Dt=Object.defineProperty;var $t=Object.getOwnPropertyDescriptor;var qt=Object.getOwnPropertyNames;var jt=Object.prototype.hasOwnProperty;var _t=(f,h)=>{for(var B in h)Dt(f,B,{get:h[B],enumerable:!0})},Gt=(f,h,B,L)=>{if(h&&typeof h=="object"||typeof h=="function")for(let z of qt(h))!jt.call(f,z)&&z!==B&&Dt(f,z,{get:()=>h[z],enumerable:!(L=$t(h,z))||L.enumerable});return f};var Wt=f=>Gt(Dt({},"__esModule",{value:!0}),f);var Zt={};_t(Zt,{DEFAULT_OPTIONS:()=>Nt,createForceLayout:()=>Rt,createGraphView:()=>Qt,fitCamera:()=>Et,placeLabels:()=>Xt,zoomCamera:()=>Tt});var Pt=Math.PI*2,Ht=2.399963229728653,Jt=200,Ut=800,Vt=new Set(["x","y","vx","vy","fx","fy"]),U=(f,h,B)=>Math.max(h,Math.min(B,f)),Nt=Object.freeze({repulsion:120,distance:100,center:0,labels:!0,motion:!0,grid:!0,clusterScope:!0}),W=Object.freeze({cell:120,range:150,repel:900,link:.9,centerForce:.012,vDecay:.6,alphaDecay:.025,alphaTarget:.02}),dt=Object.freeze({memory:"#618fcd",must:"#d97768",short:"#8a93a6",entity:"#36a582",provisional:"#b9963f",global:"#8b7bd8",missing:"#92959c"}),Bt=Object.freeze({"entity-mention":"#4f6bdb",conflict:"#d9705f",supersede:"#c08a49","fact-key":"#7a8fbc","worker-quote":"#8a7cc0"}),Yt=(f,h,B)=>f.rule&&Bt[f.rule]?Bt[f.rule]:f.manual?B:h,wt=f=>f.missing?dt.missing:f.kind==="global"?dt.global:f.kind!=="memory"?f.status==="provisional"?dt.provisional:dt.entity:f.layer==="must_remember"?dt.must:f.layer==="short_term"?dt.short:dt.memory,zt=f=>{let h=2166136261,B=String(f);for(let L=0;L<B.length;L++)h^=B.charCodeAt(L),h=Math.imul(h,16777619);return h>>>0},Ft=(f,h)=>`${Math.floor(f/W.cell)},${Math.floor(h/W.cell)}`;function Rt(f={}){let h=new Map,B=new Map,L=[],z=[],X=new Map,e=null,y="",P=1,O={...Nt,...f},j=null,S=!1,$=!1,H=1,V=!1,M=()=>({repel:U(O.repulsion,1,1e3)/120,linkDist:U(O.distance,1,1e3)/100,center:U(O.center,0,20)}),pt=(r,l)=>U(Math.hypot(r.x-l.x,r.y-l.y)||56,48,160),mt=()=>{let r=new Map;for(let l of z)r.has(l.from)||r.set(l.from,new Set),r.has(l.to)||r.set(l.to,new Set),r.get(l.from).add(l.to),r.get(l.to).add(l.from);return r},it=()=>{let r=new Map;for(let l of L){if(r.has(l.id))continue;let u=new Set([l.id]),b=[l.id],v=[];for(let g=0;g<b.length;g++){let o=b[g],I=h.get(o);I&&v.push(I);for(let s of X.get(o)||[])u.has(s)||(u.add(s),b.push(s))}let a={ids:u,members:v};for(let g of u)r.set(g,a)}return r},Q=r=>{P=Math.max(P,r)},rt=r=>O.clusterScope&&e?e.get(r):null,ht=18,J=r=>U(Math.sqrt(900/Math.max(900,r)),.56,1),St=()=>{let r=[],l=new Set;for(let u of L){if(l.has(u.id))continue;let b=e?.get(u.id),v=b?[...b.ids]:[u.id];for(let i of v)l.add(i);let a=new Map(v.map(i=>[i,[]]));for(let i of z)!a.has(i.from)||!a.has(i.to)||(a.get(i.from).push(i.to),a.get(i.to).push(i.from));let g=v[0],o=-1;for(let i of v){let x=h.get(i),A=(a.get(i)?.length||0)*10+(x?.kind==="memory"?0:3);(A>o||A===o&&i<g)&&(g=i,o=A)}let I=new Map([[g,null]]),s=new Map([[g,[]]]),d=new Map([[g,0]]),w=[g];for(let i=0;i<w.length;i++){let x=w[i];for(let A of a.get(x)||[])I.has(A)||(I.set(A,x),s.set(A,[]),d.set(A,d.get(x)+1),s.get(x).push(A),w.push(A))}let p=new Map;for(let i=w.length-1;i>=0;i--){let x=w[i],A=0;for(let t of s.get(x)||[])A+=p.get(t);p.set(x,A||1)}r.push({ids:v,root:g,kids:s,weight:p})}return r.sort((u,b)=>b.ids.length-u.ids.length),r},et=(r,l,u,b)=>{let v=h.get(r.root);if(!v)return;v.x=0,v.y=0;let a=[{id:r.root,x:0,y:0,dir:-Math.PI/2,span:Math.PI*2}];for(;a.length;){let g=a.pop(),o=r.kids.get(g.id);if(!o||!o.length)continue;let I=o.length>1?o.slice().sort((x,A)=>r.weight.get(A)-r.weight.get(x)):o,s=0;for(let x of I)s+=r.weight.get(x);let d=1/0;for(let x of I)d=Math.min(d,g.span*r.weight.get(x)/s);let w=l;I.length>1&&d>1e-6&&(w=Math.max(l,u/(2*Math.sin(Math.min(Math.PI,d)/2)))),w>b&&(w=b);let p=I.length===1?.62:0,i=g.dir-g.span/2;for(let x of I){let A=g.span*r.weight.get(x)/s,t=i+A/2+p,n=h.get(x);n&&(n.x=g.x+Math.cos(t)*w,n.y=g.y+Math.sin(t)*w),a.push({id:x,x:n?n.x:g.x,y:n?n.y:g.y,dir:t,span:A}),i+=A}}},Mt=r=>{let u=new Float64Array(36),b=r[0],v=s=>Math.min(35,Math.floor((s+Math.PI)/(Math.PI*2)*36));for(let s of b.ids){let d=h.get(s);if(!d)continue;let w=Math.hypot(d.x-(b.cx||0),d.y-(b.cy||0)),p=v(Math.atan2(d.y-(b.cy||0),d.x-(b.cx||0)));w>u[p]&&(u[p]=w)}let a=0,g=1/0;for(let s=0;s<36;s++){let d=s/36*Math.PI*2,w=Float64Array.from(u);for(let x=1;x<r.length;x++){let A=r[x],t=Math.hypot(A.ax,A.ay),n=Math.atan2(A.ay,A.ax)+d,c=A.radius;for(let D=0;D<36;D++){let R=-Math.PI+(D+.5)/36*Math.PI*2-n;for(;R>Math.PI;)R-=Math.PI*2;for(;R<-Math.PI;)R+=Math.PI*2;let Y=t*Math.sin(R);if(Math.abs(Y)>=c||Math.abs(R)>=Math.PI/2)continue;let F=t*Math.cos(R)+Math.sqrt(c*c-Y*Y);F>w[D]&&(w[D]=F)}}let p=0;for(let x=0;x<36;x++)p+=w[x];p/=36;let i=0;for(let x=0;x<36;x++)i+=(w[x]-p)*(w[x]-p);i<g&&(g=i,a=d)}if(!a)return;let o=Math.cos(a),I=Math.sin(a);for(let s=1;s<r.length;s++){let d=r[s],w=d.ax,p=d.ay;d.ax=w*o-p*I,d.ay=w*I+p*o}},yt=r=>{let l=r.slice().sort((a,g)=>g.radius-a.radius);if(!l.length)return;l[0].ax=0,l[0].ay=0;let u=l[0].radius+ht,b=1,v=1;for(;b<l.length;){let a=[],g=0,o=b;for(;o<l.length;){let p=l[o],i=u+p.radius,x=(2*p.radius+ht)/Math.max(1,i);if(a.length&&g+x>Math.PI*2)break;a.push({c:p,d:i,need:x}),g+=x,o++}let I=0,s=u;for(let p of a)I+=p.need,s=Math.max(s,p.d+p.c.radius);let d=-Math.PI/2+v*.9,w=0;for(let p of a){let i=(2*p.c.radius+ht)/Math.max(1,p.d),x=d+(w+i/2)/Math.max(1e-6,I)*Math.PI*2;p.c.ax=Math.cos(x)*p.d,p.c.ay=Math.sin(x)*p.d,w+=i}u=s+ht,b=o,v++}l.length<=12&&Mt(l)},lt=(r,l)=>{let u=r.filter(a=>Math.hypot(a.ax,a.ay)>1);if(!u.length)return;let b=0;for(let a of u)b=Math.max(b,Math.hypot(a.ax,a.ay)+a.radius*.5);let v=Math.PI*2/u.length;u.sort((a,g)=>Math.atan2(a.ay,a.ax)-Math.atan2(g.ay,g.ax));for(let a=0;a<u.length;a++){let g=u[a],o=g.ids.map(i=>h.get(i)).filter(Boolean);if(!o.length)continue;let I=1/0,s=-1/0;for(let i of o){let x=i.x-g.ax;x<I&&(I=x),x>s&&(s=x)}let d=Math.max(1,s-I),w=-Math.PI/2+(a+.5)*v,p=Math.min(v*.94,Math.max(1,o.length)*(l/Math.max(b,l)));for(let i of o){let x=i.x-g.ax,A=i.y-g.ay,t=(x-I)/d-.5,n=w+t*p,c=b+U(A,-l,l)*.28;i.x=Math.cos(n)*c,i.y=Math.sin(n)*c}}},at=()=>{if(!L.length)return;let r=J(L.length),l=56*r,u=Math.max(22,44*r),b=l*2.8,v=St();for(let a of v){et(a,l,u,b);let g=1/0,o=-1/0,I=1/0,s=-1/0;for(let p of a.ids){let i=h.get(p);i&&(i.x<g&&(g=i.x),i.x>o&&(o=i.x),i.y<I&&(I=i.y),i.y>s&&(s=i.y))}a.cx=(g+o)/2,a.cy=(I+s)/2;let d=[];for(let p of a.ids){let i=h.get(p);i&&d.push(Math.hypot(i.x-a.cx,i.y-a.cy))}d.sort((p,i)=>p-i);let w=d.length?d[Math.min(d.length-1,Math.floor(d.length*.88))]:0;if(a.radius=w+26,a.cx||a.cy){for(let p of a.ids){let i=h.get(p);i&&(i.x-=a.cx,i.y-=a.cy)}a.cx=0,a.cy=0}}yt(v);for(let a of v)for(let g of a.ids){let o=h.get(g);o&&(o.x+=a.ax,o.y+=a.ay)}v.length<=12&&lt(v,l);for(let a of h.values())a.vx=0,a.vy=0,a.fx=null,a.fy=null,a.locked=!1;for(let a of z){let g=a.source,o=a.target;a.baseLen=g&&o?Math.max(1,Math.hypot(g.x-o.x,g.y-o.y)):56,B.set(JSON.stringify([a.from,a.to,a.kind||""]),a.baseLen)}},ot=r=>{let l=[...new Map((r?.nodes||[]).slice(0,Jt).map(s=>[s.id,s])).values()].sort((s,d)=>String(s.id).localeCompare(String(d.id))),u=new Set(l.map(s=>s.id)),b=(r?.edges||[]).filter(s=>u.has(s.from)&&u.has(s.to)&&s.from!==s.to),v=JSON.stringify([l.map(s=>s.id),b.map(s=>[s.from,s.to]).sort()]),a=y!==v,g=new Map;for(let s of b)g.set(s.from,(g.get(s.from)||0)+1),g.set(s.to,(g.get(s.to)||0)+1);let o=l.filter(s=>!h.has(s.id));for(let s=0;s<o.length;s++){let d=o[s],w=b.filter(t=>t.from===d.id||t.to===d.id).map(t=>h.get(t.from===d.id?t.to:t.from)).filter(Boolean),p=s*Ht,i=w.length?32:24*Math.sqrt(s+.5),x=w.length?w.reduce((t,n)=>t+n.x,0)/w.length:0,A=w.length?w.reduce((t,n)=>t+n.y,0)/w.length:0;h.set(d.id,{id:d.id,x:x+Math.cos(p)*i,y:A+Math.sin(p)*i,vx:0,vy:0,fx:null,fy:null,locked:!1})}L=l.map(s=>{let d=h.get(s.id);for(let[w,p]of Object.entries(s))Vt.has(w)||(d[w]=p);return d.degree=g.get(s.id)||0,d.radius=4+Math.min(3,Math.log2(1+d.degree))+U(Number(s.strength)||0,0,1)*2,d}),z=b.map(s=>{let d=h.get(s.from),w=h.get(s.to),p=JSON.stringify([s.from,s.to,s.kind||""]),i=B.get(p);return i===void 0&&(i=pt(d,w),B.set(p,i)),{...s,source:d,target:w,manual:s.source!=="auto",baseLen:i}}),X=mt(),a&&(e=it());let I=L.length>0&&o.length>=Math.ceil(L.length*.6);a&&L.length&&(!V||I)&&(at(),V=!0),a&&Q(y?.25:1),y=v;for(let s of h.keys())h.size>Ut&&!u.has(s)&&h.delete(s);return B.size>4e3&&B.clear(),a},It=()=>{if(!L.length)return;P+=(W.alphaTarget-P)*W.alphaDecay,P<W.alphaTarget&&(P=W.alphaTarget);let r=M();j&&!S&&!$&&P<.05&&(j=null);let l=j?j.members:L,u=j?j.ids:null,b=new Map;for(let o of L){let I=Ft(o.x,o.y),s=b.get(I);s||b.set(I,s=[]),s.push(o)}let v=W.range*W.range,a=W.repel*r.repel*P;for(let o of l){let I=Math.floor(o.x/W.cell),s=Math.floor(o.y/W.cell);for(let d=-1;d<=1;d++)for(let w=-1;w<=1;w++){let p=b.get(`${I+d},${s+w}`);if(p)for(let i of p){if(i===o)continue;let x=o.x-i.x,A=o.y-i.y,t=x*x+A*A;if(t>v)continue;if(t<1){let D=zt(o.id)^zt(i.id);x=(D&1023)/1023-.5||.25,A=(D>>>10&1023)/1023-.5||.25,t=x*x+A*A+1}let n=Math.sqrt(t),c=a/(t+60);o.vx+=x/n*c,o.vy+=A/n*c}}}let g=W.link*P;for(let o of z){if(u&&(!u.has(o.from)||!u.has(o.to)))continue;let I=o.source,s=o.target;if(!I||!s)continue;let d=s.x-I.x,w=s.y-I.y,p=Math.hypot(d,w)||.01,i=(p-o.baseLen*r.linkDist)/p*g,x=d*i,A=w*i;I.vx+=x,I.vy+=A,s.vx-=x,s.vy-=A}if(r.center>0&&l.length){let o=0,I=0;for(let d of l)o+=d.x,I+=d.y;o/=l.length,I/=l.length;let s=W.centerForce*r.center*P;for(let d of l)d.vx+=(o-d.x)*s,d.vy+=(I-d.y)*s}for(let o of l)if(o.vx=U(o.vx,-24,24),o.vy=U(o.vy,-24,24),o.fx!=null?(o.x=o.fx,o.vx=0):(o.vx*=W.vDecay,o.x+=o.vx),o.fy!=null?(o.y=o.fy,o.vy=0):(o.vy*=W.vDecay,o.y+=o.vy),(!Number.isFinite(o.x)||!Number.isFinite(o.y))&&(o.x=0,o.y=0,o.vx=0,o.vy=0),o.fx==null||!S&&!o.locked){let I=S?12:24/U(H,.06,5),s=I*I,d=Math.floor(o.x/W.cell),w=Math.floor(o.y/W.cell);for(let p=-1;p<=1;p++)for(let i=-1;i<=1;i++){let x=b.get(`${d+p},${w+i}`);if(x)for(let A of x){if(A===o)continue;let t=o.x-A.x,n=o.y-A.y,c=t*t+n*n;if(c>=s)continue;c<1e-4&&(t=1,n=0,c=1);let D=Math.sqrt(c),T=I-D;o.x+=t/D*T,o.y+=n/D*T}}o.vx*=.3,o.vy*=.3,o.fx!=null&&(o.fx=o.x,o.fy=o.y)}};return{get nodes(){return L},get edges(){return z},get alpha(){return P},get active(){return P>W.alphaTarget+1e-4||S},update:ot,tick:It,settle(r=200){$=!0;try{for(let l=0;l<r;l++)It()}finally{$=!1}P=W.alphaTarget},configure(r){let l=r?.distance!==void 0&&r.distance!==O.distance;if(O={...O,...r},l){B.clear();for(let u of z)u.baseLen=pt(u.source,u.target),B.set(JSON.stringify([u.from,u.to,u.kind||""]),u.baseLen)}Q(.25)},reheat:Q,setScale(r){H=Number(r)>0?Number(r):1},pin(r,l,u){let b=h.get(r);b&&(b.fx=l,b.fy=u,b.x=l,b.y=u,b.vx=0,b.vy=0,b.locked=!0,Q(.3))},hold(r,l,u){let b=h.get(r);b&&(b.fx=l,b.fy=u,b.x=l,b.y=u,b.vx=0,b.vy=0,Q(.55))},release(r){let l=h.get(r);if(l){l.fx=null,l.fy=null,l.vx=0,l.vy=0;for(let u of z)u.from!==r&&u.to!==r||(u.baseLen=Math.max(24,Math.hypot(u.source.x-u.target.x,u.source.y-u.target.y)),B.set(JSON.stringify([u.from,u.to,u.kind||""]),u.baseLen));Q(.2)}},unpin(r){let l=h.get(r);l&&(l.fx=null,l.fy=null,l.vx=0,l.vy=0,l.locked=!1,Q(.3))},unpinAll(){for(let r of h.values())r.fx=null,r.fy=null,r.vx=0,r.vy=0,r.locked=!1;Q(.35)},relayout(){at(),j=null,S=!1,P=1},componentOf:rt,startDragScope(r){S=!0;let l=rt(r);return j=l?{ids:l.ids,members:l.members}:null,Q(.35),j},setDragging(r){S=r},clearDragScope(){j=null,S=!1},nodeById:r=>h.get(r),dispose(){h.clear(),B.clear(),L=[],z=[],e=null,X=new Map}}}function Et(f,h,B){if(!f.length)return{x:h/2,y:B/2,k:1};let L=1/0,z=-1/0,X=1/0,e=-1/0;for(let P of f){let O=Number(P.radius)||4;L=Math.min(L,P.x-O),z=Math.max(z,P.x+O),X=Math.min(X,P.y-O),e=Math.max(e,P.y+O)}let y=U(Math.min(Math.max(32,h-100)/Math.max(120,z-L),Math.max(32,B-96)/Math.max(120,e-X)),.06,1.6);return{x:h/2-(L+z)*y/2,y:B/2-(X+e)*y/2,k:y}}function Tt(f,h,B){let L=U(f.k*h,.06,5);return{k:L,x:B.x-(B.x-f.x)*L/f.k,y:B.y-(B.y-f.y)*L/f.k}}var Kt=(f,h)=>f.x<h.x+h.width&&f.x+f.width>h.x&&f.y<h.y+h.height&&f.y+f.height>h.y;function Xt(f,h,B,L){let z=[...h],X=[];for(let e of f){let{x:y,y:P,radius:O,textWidth:j}=e,S=[{x:y-j/2,y:P+O+5},{x:y-j/2,y:P-O-21},{x:y+O+6,y:P-8},{x:y-O-j-6,y:P-8}];if(e.priority)for(let H of[28,48,72])S.push({x:y-j/2,y:P+O+H},{x:y-j/2,y:P-O-16-H},{x:y+O+H,y:P-8},{x:y-O-j-H,y:P-8});let $=S.map(H=>({...H,width:j,height:16})).find(H=>H.x>=5&&H.y>=5&&H.x+H.width<=B-5&&H.y+H.height<=L-5&&!z.some(V=>Kt(H,V)));$&&(z.push({x:$.x-3,y:$.y-2,width:$.width+6,height:$.height+4}),X.push({...e,box:$}))}return X}function Qt(f,{onFocus:h=()=>{},onZoom:B=()=>{},tooltip:L,reducedMotion:z=!1,emptyLabel:X=""}={}){let e=f.getContext("2d");if(!e)throw new Error("Canvas 2D is unavailable");let y=Rt(),P=1,O=1,j=1,S={x:0,y:0,k:1},$={...Nt},H="",V=null,M=null,pt=!1,mt=!1,it=null,Q=0,rt=0,ht=0,J=new Map,St=[],et=f.ownerDocument.defaultView,Mt=t=>({x:(t.x-S.x)/S.k,y:(t.y-S.y)/S.k}),yt=t=>U((Number(t.radius)||4)*Math.sqrt(S.k),2.5,22),lt=t=>{let n=f.getBoundingClientRect();return{x:(t.clientX-n.left)*P/n.width,y:(t.clientY-n.top)*O/n.height}},at=t=>{let n=y.nodes;if(!n.length)return null;let c=Mt(t),D=U(Math.ceil(40/Math.max(S.k,.06)/W.cell),1,8),T=Math.floor(c.x/W.cell),R=Math.floor(c.y/W.cell),Y=new Map;for(let K of n){let nt=Ft(K.x,K.y),tt=Y.get(nt);tt||Y.set(nt,tt=[]),tt.push(K)}let F=null,Z=1/0;for(let K=-D;K<=D;K++)for(let nt=-D;nt<=D;nt++){let tt=Y.get(`${T+K},${R+nt}`);if(tt)for(let st of tt){let m=st.x*S.k+S.x,C=st.y*S.k+S.y,k=Math.hypot(m-t.x,C-t.y);k<=Math.max(10,yt(st)+4)&&k<Z&&(F=st,Z=k)}}return F},ot=()=>{L&&(L.hidden=!0)},It=(t,n)=>{V!==t&&(V=t,v()),f.style.cursor=M?"grabbing":t?"pointer":"grab",L&&(L.hidden=!t||!!M,!(!t||M)&&(L.textContent=String(t.title||t.id),L.style.left=`${U(n.x+14,6,Math.max(6,P-Math.min(260,P-12)))}px`,L.style.top=`${(f.offsetTop||0)+U(n.y+16,6,O-60)}px`))},r=t=>{if(t?.snapshot){for(let n of t.snapshot){let c=y.nodeById(n.id);c&&(c.fx=n.fx,c.fy=n.fy,c.locked=n.locked===!0,c.x=n.x,c.y=n.y,c.vx=0,c.vy=0)}y.clearDragScope()}},l=t=>{let n=34*S.k;if(n<12)return;let c=(S.x%n+n)%n,D=(S.y%n+n)%n;e.fillStyle=e.strokeStyle,e.globalAlpha=t,e.beginPath();for(let T=c;T<P;T+=n)for(let R=D;R<O;R+=n)e.rect(T,R,1.2,1.2);e.fill()},u=()=>{y.setScale(S.k),e.setTransform(j,0,0,j,0,0),e.clearRect(0,0,P,O);let t=et.getComputedStyle(f),n=t.color||"#202020",c=t.getPropertyValue("--dsw-alias-bg-layer-1").trim()||"#ffffff",D=t.getPropertyValue("--dsw-alias-brand-primary").trim()||"#3b5bdb",T=V?.id||H,R=new Set(T?[T]:[]);for(let m of y.edges)m.from===T&&R.add(m.to),m.to===T&&R.add(m.from);e.strokeStyle=n;let Y=$.motion&&!z?.06+.025*Math.sin(Date.now()/900):.07;$.grid!==!1&&l(Y);let F=S.k,Z=S.x,K=S.y,nt=new Map;for(let m of y.edges){let C={x:m.source.x*F+Z,y:m.source.y*F+K},k={x:m.target.x*F+Z,y:m.target.y*F+K};if(C.x<-40&&k.x<-40||C.x>P+40&&k.x>P+40||C.y<-40&&k.y<-40||C.y>O+40&&k.y>O+40)continue;let N=Yt(m,n,D),G=m.source.kind!=="memory"&&m.target.kind!=="memory",E=`${N}|${m.manual?"d":"s"}|${G?"k":"n"}`,q=nt.get(E);q||nt.set(E,q={color:N,manual:m.manual,skeleton:G,list:[]}),q.list.push({edge:m,a:C,b:k})}e.lineWidth=.8;for(let m of nt.values()){e.strokeStyle=m.color,e.globalAlpha=T?.055:m.skeleton?.1:m.manual?.24:.16,e.setLineDash(m.manual?[5,4]:[]),e.beginPath();for(let C of m.list)e.moveTo(C.a.x,C.a.y),e.lineTo(C.b.x,C.b.y);if(e.stroke(),e.setLineDash([]),m.manual&&S.k>=.3){e.fillStyle=m.color,e.globalAlpha=T?.22:.4;for(let C of m.list){if(C.edge.rule==="entity-mention"||C.edge.rule==="conflict")continue;let k=C.b.x-C.a.x,N=C.b.y-C.a.y,G=Math.hypot(k,N);if(G<=22)continue;let E=k/G,q=N/G,ut=yt(C.edge.target)+3,xt=C.b.x-E*ut,gt=C.b.y-q*ut;e.beginPath(),e.moveTo(xt,gt),e.lineTo(xt-E*7-q*3.4,gt-q*7+E*3.4),e.lineTo(xt-E*7+q*3.4,gt-q*7-E*3.4),e.closePath(),e.fill()}}}if(T){e.globalAlpha=.6,e.lineWidth=1.5,e.strokeStyle=D,e.beginPath();for(let m of y.edges)m.from!==T&&m.to!==T||(e.moveTo(m.source.x*F+Z,m.source.y*F+K),e.lineTo(m.target.x*F+Z,m.target.y*F+K));e.stroke()}e.globalAlpha=1,e.strokeStyle=n;let tt=[];for(let m of y.nodes){let C=m.x*F+Z,k=m.y*F+K;C>=-120&&C<=P+120&&k>=-120&&k<=O+120&&tt.push({node:m,x:C,y:k,r:yt(m)})}let st=y.nodes.length>2400&&S.k<.3;if(st){let m=new Map;for(let C of y.nodes){let k=C.x*F+Z,N=C.y*F+K;if(k<0||k>P||N<0||N>O)continue;let G=wt(C),E=m.get(G);E||m.set(G,E=[]),E.push(k,N)}e.globalAlpha=1;for(let[C,k]of m){e.fillStyle=C,e.beginPath();for(let N=0;N<k.length;N+=2)e.rect(k[N]-1,k[N+1]-1,2,2);e.fill()}}else{let m=new Map;for(let k of tt){let N=!!T&&!R.has(k.node.id),G=wt(k.node)+(N?"|d":"|n"),E=m.get(G);E||m.set(G,E=[]),E.push(k)}for(let[k,N]of m){let[G,E]=k.split("|");e.globalAlpha=E==="d"?.22:1,e.fillStyle=G,e.beginPath();for(let q of N)e.moveTo(q.x+q.r,q.y),e.arc(q.x,q.y,q.r,0,Pt);e.fill()}e.globalAlpha=1;let C=String($.query||"").trim().toLowerCase();for(let k of tt){if(k.node.kind==="memory"||k.node.missing)continue;let N=k.r*1.75,G=Math.min(5,N/3),E=k.x-N/2,q=k.y-N/2;e.fillStyle=wt(k.node),e.beginPath(),e.moveTo(E+G,q),e.arcTo(E+N,q,E+N,q+N,G),e.arcTo(E+N,q+N,E,q+N,G),e.arcTo(E,q+N,E,q,G),e.arcTo(E,q,E+N,q,G),e.closePath(),e.fill()}for(let k of tt){let N=k.node;N.status==="provisional"&&(e.strokeStyle=wt(N),e.lineWidth=1.2,e.setLineDash([3,3]),e.beginPath(),e.ellipse(k.x,k.y,k.r+5,k.r+5,0,0,Pt),e.stroke(),e.setLineDash([])),N.locked&&(e.fillStyle=c,e.globalAlpha=.95,e.fillRect(k.x-1.5,k.y-1.5,3,3),e.globalAlpha=1),(N.id===T||N.id===V?.id)&&(e.strokeStyle=N.id===T?D:wt(N),e.lineWidth=1.5,e.beginPath(),e.ellipse(k.x,k.y,k.r+4,k.r+4,0,0,Pt),e.stroke()),C&&String(N.title||N.id).toLowerCase().includes(C)&&(e.strokeStyle=D,e.lineWidth=2,e.beginPath(),e.ellipse(k.x,k.y,k.r+4,k.r+4,0,0,Pt),e.stroke())}}if(e.globalAlpha=1,e.strokeStyle=n,$.labels&&!st){e.font='11.5px -apple-system,"PingFang SC","Microsoft YaHei",sans-serif';let m=tt.filter(_=>_.x>-60&&_.x<P+60&&_.y>-60&&_.y<O+60),C=(S.k>=.55||tt.length<34)&&m.length<=260,k=m.length>260?9999:3,N=U((S.k-.3)/.35,0,1),G=M?.type==="pan"&&M.moved,ut=(M?.type==="node"&&M.moved||G)&&y.nodes.length>400?m.filter(_=>_.node.id===T):C?m:m.filter(_=>_.node.id===T||_.node.degree>=k),xt=ut.length>260?ut.slice(0,260):ut;xt.sort((_,bt)=>+(bt.node.id===T)-+(_.node.id===T)||bt.node.degree-_.node.degree);let gt=[];e.textAlign="center",e.textBaseline="top";for(let _ of xt){if(T&&!R.has(_.node.id))continue;let bt=_.node.id===T;if(!bt&&(!C&&_.node.degree<k||N<.02))continue;let At=String(_.node.title||_.node.id),Ct=e.measureText(At).width,Lt=ft=>({l:_.x-Ct/2-3,t:ft-1,r:_.x+Ct/2+3,b:ft+14}),Ot=ft=>gt.some(vt=>ft.l<vt.r&&ft.r>vt.l&&ft.t<vt.b&&ft.b>vt.t),kt=_.y+_.r+4,ct=Lt(kt);Ot(ct)&&(kt+=16,ct=Lt(kt),Ot(ct))||ct.l<2||ct.r>P-2||ct.b>O-2||(gt.push(ct),e.globalAlpha=bt?1:.78*Math.max(.35,N),e.lineWidth=3.5,e.strokeStyle=c,e.lineJoin="round",e.strokeText(At,_.x,kt),e.fillStyle=n,e.fillText(At,_.x,kt))}e.globalAlpha=1}else if($.labels&&st&&T){let m=y.nodes.find(C=>C.id===T);m&&(e.font="12px system-ui, sans-serif",e.textAlign="center",e.textBaseline="top",e.fillStyle=n,e.fillText(String(m.title||m.id),m.x*F+Z,m.y*F+K+10))}!y.nodes.length&&X&&(e.font="13px system-ui, sans-serif",e.textAlign="center",e.textBaseline="middle",e.fillStyle=n,e.globalAlpha=.55,e.fillText(X,P/2,O/2),e.globalAlpha=1)},b=t=>{if(it=null,mt)return;let n=$.motion&&!z&&y.active;if(n){rt+=Q?Math.min(64,t-Q):17;let c=0;for(;rt>=1e3/60&&c<4;rt-=1e3/60,c++)y.tick();Q=t}else Q=0,rt=0;if(!n&&$.motion&&!z&&ht++%2){v();return}u(),(n||$.motion&&!z)&&v()};function v(){!mt&&it===null&&(it=et.requestAnimationFrame(b))}let a=()=>{B(S.k),v()},g=()=>{S=Et(y.nodes,P,O),ot(),a()},o=(t,n={x:P/2,y:O/2})=>{S=Tt(S,t,n),ot(),a()},I=()=>{let t=f.getBoundingClientRect();if(!t.width||!t.height)return;let n=t.width,c=t.height;S.x+=(n-P)/2,S.y+=(c-O)/2,P=n,O=c,j=Math.min(2,et.devicePixelRatio||1),f.width=Math.round(P*j),f.height=Math.round(O*j),v()},s=()=>{r(M);let[t,n]=[...J.values()];M={type:"pinch",distance:Math.max(1,Math.hypot(n.x-t.x,n.y-t.y)),camera:{...S},center:{x:(t.x+n.x)/2,y:(t.y+n.y)/2},moved:!0}},d=t=>{if(t.button!==0&&t.pointerType!=="touch")return;t.preventDefault(),f.focus({preventScroll:!0});let n=lt(t);if(J.set(t.pointerId,n),f.setPointerCapture?.(t.pointerId),J.size>=2){s(),ot();return}let c=at(n),D=Mt(n),T=c?y.componentOf(c.id):null,R=c&&t.shiftKey&&T?"rigid":"node",Y=R==="rigid"?T.members:c?[c]:[];if(M={type:c?"node":"pan",node:c,mode:R,members:Y,start:n,camera:{...S},moved:!1,offset:c?{x:c.x-D.x,y:c.y-D.y}:null,snapshot:Y.map(F=>({id:F.id,x:F.x,y:F.y,fx:F.fx,fy:F.fy,locked:F.locked}))},c){for(let F of Y)y.hold(F.id,F.x,F.y);y.startDragScope(c.id),y.setDragging(!0)}ot(),f.style.cursor="grabbing"},w=t=>{let n=lt(t);if(!J.has(t.pointerId)||!M){It(at(n),n);return}if(J.set(t.pointerId,n),M.type==="pinch"){if(J.size<2)return;let[c,D]=[...J.values()],T={x:(c.x+D.x)/2,y:(c.y+D.y)/2};S=Tt(M.camera,Math.hypot(D.x-c.x,D.y-c.y)/M.distance,M.center),S.x+=T.x-M.center.x,S.y+=T.y-M.center.y,a()}else{if(M.moved||(M.moved=Math.hypot(n.x-M.start.x,n.y-M.start.y)>5),!M.moved)return;if(M.node){let c=Mt(n),D=M.node;if(M.mode==="rigid"){let T=c.x+M.offset.x,R=c.y+M.offset.y,Y=T-D.fx,F=R-D.fy;for(let Z of M.members)y.hold(Z.id,Z.fx+Y,Z.fy+F)}else y.hold(D.id,c.x+M.offset.x,c.y+M.offset.y);y.settle(2)}else S.x=M.camera.x+n.x-M.start.x,S.y=M.camera.y+n.y-M.start.y;v()}},p=t=>{if(!J.has(t.pointerId))return;let n=t.type!=="pointerup",c=M?.node,D=!n&&!M?.moved&&M?.type!=="pinch"&&(t.detail??1)<2;if(D||n)r(M);else if(c){for(let T of M.snapshot){let R=y.nodeById(T.id);R&&(T.locked||T.fx!=null?(R.fx=R.x,R.fy=R.y,R.locked=!0,R.vx=0,R.vy=0):y.release(T.id))}y.setDragging(!1),z||!$.motion?(y.settle(120),y.clearDragScope()):y.reheat(.3)}J.delete(t.pointerId),M=null,J.size&&(M={type:"pan",start:[...J.values()][0],camera:{...S},moved:!0}),f.hasPointerCapture?.(t.pointerId)&&f.releasePointerCapture(t.pointerId),D&&h(c?.id||""),V=null,f.style.cursor="grab",ot(),v()},i=(t,n,c,D)=>{t.addEventListener(n,c,D),St.push(()=>t.removeEventListener(n,c,D))};i(f,"pointerdown",d),i(f,"pointermove",w);for(let t of["pointerup","pointercancel","lostpointercapture"])i(f,t,p);i(f,"pointerleave",()=>{M||(V=null,ot(),v())}),i(f,"contextmenu",t=>{t.preventDefault();let n=at(lt(t));if(!n)return;let c=y.nodeById(n.id);c&&(c.fx!=null?y.unpin(n.id):y.pin(n.id,c.x,c.y),y.setDragging(!1),(z||!$.motion)&&y.settle(20),v())}),i(f,"dblclick",t=>{h(at(lt(t))?.id||"")}),i(f,"wheel",t=>{t.preventDefault(),o(Math.exp(-U(t.deltaY,-160,160)*.0025),lt(t))},{passive:!1}),i(f,"keydown",t=>{if(t.key==="+"||t.key==="=")o(1.25);else if(t.key==="-")o(.8);else if(t.key==="0"||t.key==="Home")g();else if(t.key==="Escape")r(M),M=null,J.clear(),h(""),ot(),v();else if(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(t.key)){let n=t.shiftKey?90:30;S.x+=t.key==="ArrowLeft"?n:t.key==="ArrowRight"?-n:0,S.y+=t.key==="ArrowUp"?n:t.key==="ArrowDown"?-n:0,v()}else return;t.preventDefault()}),i(et,"blur",()=>{r(M),M=null,J.clear(),V=null,ot(),v()});let x=et.ResizeObserver?new et.ResizeObserver(I):null;x?.observe(f),i(et,"resize",I);let A=et.MutationObserver?new et.MutationObserver(v):null;return A?.observe(f.ownerDocument.documentElement,{attributes:!0,attributeFilter:["class","data-theme","style"]}),f.ownerDocument.body&&A?.observe(f.ownerDocument.body,{attributes:!0,attributeFilter:["class","data-theme","style"]}),I(),{update(t,n=""){M?.node&&!t.nodes.some(D=>D.id===M.node.id)&&(r(M),M=null,J.clear());let c=y.update(t);H=n,V&&!y.nodes.includes(V)&&(V=null,ot()),!pt&&y.nodes.length?(y.settle(220),pt=!0,g()):c&&(z||!$.motion)&&y.settle(180),v()},configure(t){let n=["repulsion","distance","center"].some(c=>t[c]!==void 0&&t[c]!==$[c]);$={...$,...t},n&&(y.configure(t),(z||!$.motion)&&y.settle(160)),v()},fit:g,zoom:o,isPinned(t){return y.nodeById(t)?.locked===!0},pinnedCount(){return y.nodes.reduce((t,n)=>t+(n.locked?1:0),0)},snapshot(){return y.nodes.map(t=>({id:t.id,x:t.x*S.k+S.x,y:t.y*S.k+S.y,r:yt(t),pinned:t.locked===!0,degree:t.degree||0}))},unpinAll(){y.unpinAll(),y.clearDragScope(),(z||!$.motion)&&y.settle(120),v()},relayout(){r(M),M=null,J.clear(),y.relayout(),(z||!$.motion)&&y.settle(220),v()},dispose(){mt=!0,r(M),M=null,J.clear(),it!==null&&et.cancelAnimationFrame(it);for(let t of St)t();x?.disconnect(),A?.disconnect(),y.dispose(),ot()}}}return Wt(Zt);})();