dsh-memu-memory 1.3.2 → 1.3.3
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/AGENTS.md +6 -3
- package/CHANGELOG.md +30 -0
- package/README.md +5 -4
- package/README.zh.md +5 -4
- package/assets/screenshots/drawer.jpg +0 -0
- package/assets/screenshots/mobile.jpg +0 -0
- package/assets/screenshots/relations.jpg +0 -0
- package/assets/screenshots/settings.jpg +0 -0
- package/assets/screenshots/stats.jpg +0 -0
- package/assets/screenshots/webui-dark.jpg +0 -0
- package/assets/screenshots/webui-memory.jpg +0 -0
- package/docs/client-conventions.md +11 -0
- package/docs/contributing.md +4 -2
- package/docs/troubleshooting.md +15 -0
- package/lib/client.js +106 -12
- package/lib/rpc.js +6 -1
- package/lib/webui/graph-view.bundle.js +1 -1
- package/lib/webui/graph-view.js +53 -25
- package/package.json +1 -1
- package/scripts/build-graph.mjs +32 -4
- package/scripts/check-all.mjs +2 -0
- package/scripts/make-readme-shots.mjs +59 -0
- package/tests/browser.test.mjs +27 -0
- package/tests/client-render.test.mjs +171 -0
- package/tests/graph-view.test.mjs +60 -3
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* Generated by scripts/build-graph.mjs. Licenses: graph-LICENSE.txt */
|
|
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&<(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);})();
|
|
2
|
+
var DshMemuGraph=(()=>{var Tt=Object.defineProperty;var $t=Object.getOwnPropertyDescriptor;var jt=Object.getOwnPropertyNames;var qt=Object.prototype.hasOwnProperty;var _t=(d,y)=>{for(var N in y)Tt(d,N,{get:y[N],enumerable:!0})},Gt=(d,y,N,L)=>{if(y&&typeof y=="object"||typeof y=="function")for(let R of jt(y))!qt.call(d,R)&&R!==N&&Tt(d,R,{get:()=>y[R],enumerable:!(L=$t(y,R))||L.enumerable});return d};var Wt=d=>Gt(Tt({},"__esModule",{value:!0}),d);var Zt={};_t(Zt,{DEFAULT_OPTIONS:()=>Ct,createForceLayout:()=>Rt,createGraphView:()=>Qt,fitCamera:()=>Et,placeLabels:()=>Xt,zoomCamera:()=>Nt});var Pt=Math.PI*2,Ht=2.399963229728653,Jt=200,Ut=800,Vt=new Set(["x","y","vx","vy","fx","fy"]),Y=(d,y,N)=>Math.max(y,Math.min(N,d)),Ct=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"}),zt=Object.freeze({"entity-mention":"#4f6bdb",conflict:"#d9705f",supersede:"#c08a49","fact-key":"#7a8fbc","worker-quote":"#8a7cc0"}),Yt=(d,y,N)=>d.rule&&zt[d.rule]?zt[d.rule]:d.manual?N:y,wt=d=>d.missing?dt.missing:d.kind==="global"?dt.global:d.kind!=="memory"?d.status==="provisional"?dt.provisional:dt.entity:d.layer==="must_remember"?dt.must:d.layer==="short_term"?dt.short:dt.memory,Dt=d=>{let y=2166136261,N=String(d);for(let L=0;L<N.length;L++)y^=N.charCodeAt(L),y=Math.imul(y,16777619);return y>>>0},Ft=(d,y)=>`${Math.floor(d/W.cell)},${Math.floor(y/W.cell)}`;function Rt(d={}){let y=new Map,N=new Map,L=[],R=[],H=new Map,U=null,e="",f=1,T={...Ct,...d},O=null,V=!1,v=!1,z=!1,ht=()=>({repel:Y(T.repulsion,1,1e3)/120,linkDist:Y(T.distance,1,1e3)/100,center:Y(T.center,0,20)}),K=(r,l)=>Y(Math.hypot(r.x-l.x,r.y-l.y)||56,48,160),b=()=>{let r=new Map;for(let l of R)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},St=()=>{let r=new Map;for(let l of L){if(r.has(l.id))continue;let x=new Set([l.id]),k=[l.id],F=[];for(let w=0;w<k.length;w++){let o=k[w],I=y.get(o);I&&F.push(I);for(let m of H.get(o)||[])x.has(m)||(x.add(m),k.push(m))}let s={ids:x,members:F};for(let w of x)r.set(w,s)}return r},Q=r=>{f=Math.max(f,r)},rt=r=>T.clusterScope&&U?U.get(r):null,it=18,yt=r=>Y(Math.sqrt(900/Math.max(900,r)),.56,1),J=()=>{let r=[],l=new Set;for(let x of L){if(l.has(x.id))continue;let k=U?.get(x.id),F=k?[...k.ids]:[x.id];for(let a of F)l.add(a);let s=new Map(F.map(a=>[a,[]]));for(let a of R)!s.has(a.from)||!s.has(a.to)||(s.get(a.from).push(a.to),s.get(a.to).push(a.from));let w=F[0],o=-1;for(let a of F){let c=y.get(a),P=(s.get(a)?.length||0)*10+(c?.kind==="memory"?0:3);(P>o||P===o&&a<w)&&(w=a,o=P)}let I=new Map([[w,null]]),m=new Map([[w,[]]]),i=new Map([[w,0]]),p=[w];for(let a=0;a<p.length;a++){let c=p[a];for(let P of s.get(c)||[])I.has(P)||(I.set(P,c),m.set(P,[]),i.set(P,i.get(c)+1),m.get(c).push(P),p.push(P))}let u=new Map;for(let a=p.length-1;a>=0;a--){let c=p[a],P=0;for(let j of m.get(c)||[])P+=u.get(j);u.set(c,P||1)}r.push({ids:F,root:w,kids:m,weight:u})}return r.sort((x,k)=>k.ids.length-x.ids.length),r},It=(r,l,x,k)=>{let F=y.get(r.root);if(!F)return;F.x=0,F.y=0;let s=[{id:r.root,x:0,y:0,dir:-Math.PI/2,span:Math.PI*2}];for(;s.length;){let w=s.pop(),o=r.kids.get(w.id);if(!o||!o.length)continue;let I=o.length>1?o.slice().sort((c,P)=>r.weight.get(P)-r.weight.get(c)):o,m=0;for(let c of I)m+=r.weight.get(c);let i=1/0;for(let c of I)i=Math.min(i,w.span*r.weight.get(c)/m);let p=l;I.length>1&&i>1e-6&&(p=Math.max(l,x/(2*Math.sin(Math.min(Math.PI,i)/2)))),p>k&&(p=k);let u=I.length===1?.62:0,a=w.dir-w.span/2;for(let c of I){let P=w.span*r.weight.get(c)/m,j=a+P/2+u,t=y.get(c);t&&(t.x=w.x+Math.cos(j)*p,t.y=w.y+Math.sin(j)*p),s.push({id:c,x:t?t.x:w.x,y:t?t.y:w.y,dir:j,span:P}),a+=P}}},et=r=>{let x=new Float64Array(36),k=r[0],F=m=>Math.min(35,Math.floor((m+Math.PI)/(Math.PI*2)*36));for(let m of k.ids){let i=y.get(m);if(!i)continue;let p=Math.hypot(i.x-(k.cx||0),i.y-(k.cy||0)),u=F(Math.atan2(i.y-(k.cy||0),i.x-(k.cx||0)));p>x[u]&&(x[u]=p)}let s=0,w=1/0;for(let m=0;m<36;m++){let i=m/36*Math.PI*2,p=Float64Array.from(x);for(let c=1;c<r.length;c++){let P=r[c],j=Math.hypot(P.ax,P.ay),t=Math.atan2(P.ay,P.ax)+i,n=P.radius;for(let h=0;h<36;h++){let S=-Math.PI+(h+.5)/36*Math.PI*2-t;for(;S>Math.PI;)S-=Math.PI*2;for(;S<-Math.PI;)S+=Math.PI*2;let E=j*Math.sin(S);if(Math.abs(E)>=n||Math.abs(S)>=Math.PI/2)continue;let ot=j*Math.cos(S)+Math.sqrt(n*n-E*E);ot>p[h]&&(p[h]=ot)}}let u=0;for(let c=0;c<36;c++)u+=p[c];u/=36;let a=0;for(let c=0;c<36;c++)a+=(p[c]-u)*(p[c]-u);a<w&&(w=a,s=i)}if(!s)return;let o=Math.cos(s),I=Math.sin(s);for(let m=1;m<r.length;m++){let i=r[m],p=i.ax,u=i.ay;i.ax=p*o-u*I,i.ay=p*I+u*o}},Mt=r=>{let l=r.slice().sort((s,w)=>w.radius-s.radius);if(!l.length)return;l[0].ax=0,l[0].ay=0;let x=l[0].radius+it,k=1,F=1;for(;k<l.length;){let s=[],w=0,o=k;for(;o<l.length;){let u=l[o],a=x+u.radius,c=(2*u.radius+it)/Math.max(1,a);if(s.length&&w+c>Math.PI*2)break;s.push({c:u,d:a,need:c}),w+=c,o++}let I=0,m=x;for(let u of s)I+=u.need,m=Math.max(m,u.d+u.c.radius);let i=-Math.PI/2+F*.9,p=0;for(let u of s){let a=(2*u.c.radius+it)/Math.max(1,u.d),c=i+(p+a/2)/Math.max(1e-6,I)*Math.PI*2;u.c.ax=Math.cos(c)*u.d,u.c.ay=Math.sin(c)*u.d,p+=a}x=m+it,k=o,F++}l.length<=12&&et(l)},ut=(r,l)=>{let x=r.filter(s=>Math.hypot(s.ax,s.ay)>1);if(!x.length)return;let k=0;for(let s of x)k=Math.max(k,Math.hypot(s.ax,s.ay)+s.radius*.5);let F=Math.PI*2/x.length;x.sort((s,w)=>Math.atan2(s.ay,s.ax)-Math.atan2(w.ay,w.ax));for(let s=0;s<x.length;s++){let w=x[s],o=w.ids.map(a=>y.get(a)).filter(Boolean);if(!o.length)continue;let I=1/0,m=-1/0;for(let a of o){let c=a.x-w.ax;c<I&&(I=c),c>m&&(m=c)}let i=Math.max(1,m-I),p=-Math.PI/2+(s+.5)*F,u=Math.min(F*.94,Math.max(1,o.length)*(l/Math.max(k,l)));for(let a of o){let c=a.x-w.ax,P=a.y-w.ay,j=(c-I)/i-.5,t=p+j*u,n=k+Y(P,-l,l)*.28;a.x=Math.cos(t)*n,a.y=Math.sin(t)*n}}},lt=()=>{if(!L.length)return;let r=yt(L.length),l=56*r,x=Math.max(22,44*r),k=l*2.8,F=J();for(let s of F){It(s,l,x,k);let w=1/0,o=-1/0,I=1/0,m=-1/0;for(let u of s.ids){let a=y.get(u);a&&(a.x<w&&(w=a.x),a.x>o&&(o=a.x),a.y<I&&(I=a.y),a.y>m&&(m=a.y))}s.cx=(w+o)/2,s.cy=(I+m)/2;let i=[];for(let u of s.ids){let a=y.get(u);a&&i.push(Math.hypot(a.x-s.cx,a.y-s.cy))}i.sort((u,a)=>u-a);let p=i.length?i[Math.min(i.length-1,Math.floor(i.length*.88))]:0;if(s.radius=p+26,s.cx||s.cy){for(let u of s.ids){let a=y.get(u);a&&(a.x-=s.cx,a.y-=s.cy)}s.cx=0,s.cy=0}}Mt(F);for(let s of F)for(let w of s.ids){let o=y.get(w);o&&(o.x+=s.ax,o.y+=s.ay)}F.length<=12&&ut(F,l);for(let s of y.values())s.vx=0,s.vy=0,s.fx=null,s.fy=null,s.locked=!1;for(let s of R){let w=s.source,o=s.target;s.baseLen=w&&o?Math.max(1,Math.hypot(w.x-o.x,w.y-o.y)):56,N.set(JSON.stringify([s.from,s.to,s.kind||""]),s.baseLen)}},xt=r=>{let l=[...new Map((r?.nodes||[]).slice(0,Jt).map(i=>[i.id,i])).values()].sort((i,p)=>String(i.id).localeCompare(String(p.id))),x=new Set(l.map(i=>i.id)),k=(r?.edges||[]).filter(i=>x.has(i.from)&&x.has(i.to)&&i.from!==i.to),F=JSON.stringify([l.map(i=>i.id),k.map(i=>[i.from,i.to]).sort()]),s=e!==F,w=L.length,o=new Map;for(let i of k)o.set(i.from,(o.get(i.from)||0)+1),o.set(i.to,(o.get(i.to)||0)+1);let I=l.filter(i=>!y.has(i.id));for(let i=0;i<I.length;i++){let p=I[i],u=k.filter(t=>t.from===p.id||t.to===p.id).map(t=>y.get(t.from===p.id?t.to:t.from)).filter(Boolean),a=i*Ht,c=u.length?32:24*Math.sqrt(i+.5),P=u.length?u.reduce((t,n)=>t+n.x,0)/u.length:0,j=u.length?u.reduce((t,n)=>t+n.y,0)/u.length:0;y.set(p.id,{id:p.id,x:P+Math.cos(a)*c,y:j+Math.sin(a)*c,vx:0,vy:0,fx:null,fy:null,locked:!1})}L=l.map(i=>{let p=y.get(i.id);for(let[u,a]of Object.entries(i))Vt.has(u)||(p[u]=a);return p.degree=o.get(i.id)||0,p.radius=4+Math.min(3,Math.log2(1+p.degree))+Y(Number(i.strength)||0,0,1)*2,p}),R=k.map(i=>{let p=y.get(i.from),u=y.get(i.to),a=JSON.stringify([i.from,i.to,i.kind||""]),c=N.get(a);return c===void 0&&(c=K(p,u),N.set(a,c)),{...i,source:p,target:u,manual:i.source!=="auto",baseLen:c}}),H=b(),s&&(U=St());let m=L.length>0&&I.length>=Math.ceil(L.length*.6)&&w<=Math.max(8,L.length*.2);s&&L.length&&(!z||m)&&(lt(),z=!0),s&&Q(e?.25:1),e=F;for(let i of y.keys())y.size>Ut&&!x.has(i)&&y.delete(i);return N.size>4e3&&N.clear(),s},Z=()=>{if(!L.length)return;f+=(W.alphaTarget-f)*W.alphaDecay,f<W.alphaTarget&&(f=W.alphaTarget);let r=ht();O&&!V&&!v&&f<.05&&(O=null);let l=O?O.members:L,x=O?O.ids:null,k=new Map;for(let o of L){let I=Ft(o.x,o.y),m=k.get(I);m||k.set(I,m=[]),m.push(o)}let F=W.range*W.range,s=W.repel*r.repel*f;for(let o of l){let I=Math.floor(o.x/W.cell),m=Math.floor(o.y/W.cell);for(let i=-1;i<=1;i++)for(let p=-1;p<=1;p++){let u=k.get(`${I+i},${m+p}`);if(u)for(let a of u){if(a===o)continue;let c=o.x-a.x,P=o.y-a.y,j=c*c+P*P;if(j>F)continue;if(j<1){let h=Dt(o.id)^Dt(a.id);c=(h&1023)/1023-.5||.25,P=(h>>>10&1023)/1023-.5||.25,j=c*c+P*P+1}let t=Math.sqrt(j),n=s/(j+60);o.vx+=c/t*n,o.vy+=P/t*n}}}let w=W.link*f;for(let o of R){if(x&&(!x.has(o.from)||!x.has(o.to)))continue;let I=o.source,m=o.target;if(!I||!m)continue;let i=m.x-I.x,p=m.y-I.y,u=Math.hypot(i,p)||.01,a=(u-o.baseLen*r.linkDist)/u*w,c=i*a,P=p*a;I.vx+=c,I.vy+=P,m.vx-=c,m.vy-=P}if(r.center>0&&l.length){let o=0,I=0;for(let i of l)o+=i.x,I+=i.y;o/=l.length,I/=l.length;let m=W.centerForce*r.center*f;for(let i of l)i.vx+=(o-i.x)*m,i.vy+=(I-i.y)*m}for(let o of l)if(o.vx=Y(o.vx,-24,24),o.vy=Y(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||!V&&!o.locked){let I=(Number(o.radius)||4)+(V?2:8),m=Math.floor(o.x/W.cell),i=Math.floor(o.y/W.cell);for(let p=-1;p<=1;p++)for(let u=-1;u<=1;u++){let a=k.get(`${m+p},${i+u}`);if(a)for(let c of a){if(c===o)continue;let P=o.x-c.x,j=o.y-c.y,t=P*P+j*j,n=I+(Number(c.radius)||4),h=n*n;if(t>=h)continue;let C=Math.sqrt(t);if(C<.01){let E=Dt(o.id)^Dt(c.id);P=(E&1023)/1023-.5||.25,j=(E>>>10&1023)/1023-.5||.25,C=Math.hypot(P,j)||1}let S=n-C;o.x+=P/C*S,o.y+=j/C*S}}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 R},get alpha(){return f},get active(){return f>W.alphaTarget+1e-4||V},update:xt,tick:Z,settle(r=200){v=!0;try{for(let l=0;l<r;l++)Z()}finally{v=!1}f=W.alphaTarget},configure(r){let l=r?.distance!==void 0&&r.distance!==T.distance;if(T={...T,...r},l){N.clear();for(let x of R)x.baseLen=K(x.source,x.target),N.set(JSON.stringify([x.from,x.to,x.kind||""]),x.baseLen)}Q(.25)},reheat:Q,pin(r,l,x){let k=y.get(r);k&&(k.fx=l,k.fy=x,k.x=l,k.y=x,k.vx=0,k.vy=0,k.locked=!0,Q(.3))},hold(r,l,x){let k=y.get(r);k&&(k.fx=l,k.fy=x,k.x=l,k.y=x,k.vx=0,k.vy=0,Q(.55))},release(r){let l=y.get(r);if(l){l.fx=null,l.fy=null,l.vx=0,l.vy=0;for(let x of R)x.from!==r&&x.to!==r||(x.baseLen=Math.max(24,Math.hypot(x.source.x-x.target.x,x.source.y-x.target.y)),N.set(JSON.stringify([x.from,x.to,x.kind||""]),x.baseLen));Q(.2)}},unpin(r){let l=y.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 y.values())r.fx=null,r.fy=null,r.vx=0,r.vy=0,r.locked=!1;Q(.35)},relayout(){lt(),N.clear();for(let r of R)r.baseLen=K(r.source,r.target),N.set(JSON.stringify([r.from,r.to,r.kind||""]),r.baseLen);O=null,V=!1,f=1},componentOf:rt,startDragScope(r){V=!0;let l=rt(r);return O=l?{ids:l.ids,members:l.members}:null,Q(.35),O},setDragging(r){V=r},clearDragScope(){O=null,V=!1},nodeById:r=>y.get(r),dispose(){y.clear(),N.clear(),L=[],R=[],U=null,H=new Map}}}function Et(d,y,N){if(!d.length)return{x:y/2,y:N/2,k:1};let L=1/0,R=-1/0,H=1/0,U=-1/0;for(let f of d){let T=Number(f.radius)||4;L=Math.min(L,f.x-T),R=Math.max(R,f.x+T),H=Math.min(H,f.y-T),U=Math.max(U,f.y+T)}let e=Y(Math.min(Math.max(32,y-100)/Math.max(120,R-L),Math.max(32,N-96)/Math.max(120,U-H)),.06,1.6);return{x:y/2-(L+R)*e/2,y:N/2-(H+U)*e/2,k:e}}function Nt(d,y,N){let L=Y(d.k*y,.06,5);return{k:L,x:N.x-(N.x-d.x)*L/d.k,y:N.y-(N.y-d.y)*L/d.k}}var Kt=(d,y)=>d.x<y.x+y.width&&d.x+d.width>y.x&&d.y<y.y+y.height&&d.y+d.height>y.y;function Xt(d,y,N,L){let R=[...y],H=[];for(let U of d){let{x:e,y:f,radius:T,textWidth:O}=U,V=[{x:e-O/2,y:f+T+5},{x:e-O/2,y:f-T-21},{x:e+T+6,y:f-8},{x:e-T-O-6,y:f-8}];if(U.priority)for(let z of[28,48,72])V.push({x:e-O/2,y:f+T+z},{x:e-O/2,y:f-T-16-z},{x:e+T+z,y:f-8},{x:e-T-O-z,y:f-8});let v=V.map(z=>({...z,width:O,height:16})).find(z=>z.x>=5&&z.y>=5&&z.x+z.width<=N-5&&z.y+z.height<=L-5&&!R.some(ht=>Kt(z,ht)));v&&(R.push({x:v.x-3,y:v.y-2,width:v.width+6,height:v.height+4}),H.push({...U,box:v}))}return H}function Qt(d,{onFocus:y=()=>{},onZoom:N=()=>{},onPaint:L=()=>{},tooltip:R,reducedMotion:H=!1,emptyLabel:U=""}={}){let e=d.getContext("2d");if(!e)throw new Error("Canvas 2D is unavailable");let f=Rt(),T=1,O=1,V=1,v={x:0,y:0,k:1},z={...Ct},ht="",K=null,b=null,St=!1,Q=!1,rt=null,it=0,yt=0,J=new Map,It=[],et=d.ownerDocument.defaultView,Mt=t=>({x:(t.x-v.x)/v.k,y:(t.y-v.y)/v.k}),ut=t=>Y((Number(t.radius)||4)*Math.sqrt(v.k),2.5,22),lt=t=>{let n=d.getBoundingClientRect();return{x:(t.clientX-n.left)*T/n.width,y:(t.clientY-n.top)*O/n.height}},xt=(t,n)=>{let h=f.nodes;if(!h.length)return null;let C=Mt(t),S=Y(Math.ceil(40/Math.max(v.k,.06)/W.cell),1,8),E=Math.floor(C.x/W.cell),ot=Math.floor(C.y/W.cell),$=new Map;for(let tt of h){let g=Ft(tt.x,tt.y),D=$.get(g);D||$.set(g,D=[]),D.push(tt)}let X=tt=>Math.max(6,ut(tt)+4),nt=null,at=1/0,st=1/0;for(let tt=-S;tt<=S;tt++)for(let g=-S;g<=S;g++){let D=$.get(`${E+tt},${ot+g}`);if(D)for(let M of D){let A=M.x*v.k+v.x,_=M.y*v.k+v.y,B=Math.hypot(A-t.x,_-t.y);M===n&&(st=B),B<=X(M)&&B<at&&(nt=M,at=B)}}return n&&st<=X(n)&&(!nt||at>st-2)?n:nt},Z=()=>{R&&(R.hidden=!0)},r=(t,n)=>{K!==t&&(K=t,s()),d.style.cursor=b?"grabbing":t?"pointer":"grab",R&&(R.hidden=!t||!!b,!(!t||b)&&(R.textContent=String(t.title||t.id),R.style.left=`${Y(n.x+14,6,Math.max(6,T-Math.min(260,T-12)))}px`,R.style.top=`${(d.offsetTop||0)+Y(n.y+16,6,O-60)}px`))},l=t=>{if(t?.snapshot){for(let n of t.snapshot){let h=f.nodeById(n.id);h&&(h.fx=n.fx,h.fy=n.fy,h.locked=n.locked===!0,h.x=n.x,h.y=n.y,h.vx=0,h.vy=0)}f.clearDragScope()}},x=t=>{let n=34*v.k;if(n<12)return;let h=(v.x%n+n)%n,C=(v.y%n+n)%n;e.fillStyle=e.strokeStyle,e.globalAlpha=t,e.beginPath();for(let S=h;S<T;S+=n)for(let E=C;E<O;E+=n)e.rect(S,E,1.2,1.2);e.fill()},k=()=>{e.setTransform(V,0,0,V,0,0),e.clearRect(0,0,T,O);let t=et.getComputedStyle(d),n=t.color||"#202020",h=t.getPropertyValue("--dsw-alias-bg-layer-1").trim()||"#ffffff",C=t.getPropertyValue("--dsw-alias-brand-primary").trim()||"#3b5bdb",S=K?.id||ht,E=new Set(S?[S]:[]);for(let g of f.edges)g.from===S&&E.add(g.to),g.to===S&&E.add(g.from);e.strokeStyle=n;let ot=z.motion&&!H&&f.active?.06+.025*Math.sin(Date.now()/900):.07;z.grid!==!1&&x(ot);let $=v.k,X=v.x,nt=v.y,at=new Map;for(let g of f.edges){let D={x:g.source.x*$+X,y:g.source.y*$+nt},M={x:g.target.x*$+X,y:g.target.y*$+nt};if(D.x<-40&&M.x<-40||D.x>T+40&&M.x>T+40||D.y<-40&&M.y<-40||D.y>O+40&&M.y>O+40)continue;let A=Yt(g,n,C),_=g.source.kind!=="memory"&&g.target.kind!=="memory",B=`${A}|${g.manual?"d":"s"}|${_?"k":"n"}`,q=at.get(B);q||at.set(B,q={color:A,manual:g.manual,skeleton:_,list:[]}),q.list.push({edge:g,a:D,b:M})}e.lineWidth=.8;for(let g of at.values()){e.strokeStyle=g.color,e.globalAlpha=S?.055:g.skeleton?.1:g.manual?.24:.16,e.setLineDash(g.manual?[5,4]:[]),e.beginPath();for(let D of g.list)e.moveTo(D.a.x,D.a.y),e.lineTo(D.b.x,D.b.y);if(e.stroke(),e.setLineDash([]),g.manual&&v.k>=.3){e.fillStyle=g.color,e.globalAlpha=S?.22:.4;for(let D of g.list){if(D.edge.rule==="entity-mention"||D.edge.rule==="conflict")continue;let M=D.b.x-D.a.x,A=D.b.y-D.a.y,_=Math.hypot(M,A);if(_<=22)continue;let B=M/_,q=A/_,gt=ut(D.edge.target)+3,pt=D.b.x-B*gt,mt=D.b.y-q*gt;e.beginPath(),e.moveTo(pt,mt),e.lineTo(pt-B*7-q*3.4,mt-q*7+B*3.4),e.lineTo(pt-B*7+q*3.4,mt-q*7-B*3.4),e.closePath(),e.fill()}}}if(S){e.globalAlpha=.6,e.lineWidth=1.5,e.strokeStyle=C,e.beginPath();for(let g of f.edges)g.from!==S&&g.to!==S||(e.moveTo(g.source.x*$+X,g.source.y*$+nt),e.lineTo(g.target.x*$+X,g.target.y*$+nt));e.stroke()}e.globalAlpha=1,e.strokeStyle=n;let st=[];for(let g of f.nodes){let D=g.x*$+X,M=g.y*$+nt;D>=-120&&D<=T+120&&M>=-120&&M<=O+120&&st.push({node:g,x:D,y:M,r:ut(g)})}let tt=f.nodes.length>2400&&v.k<.3;if(tt){let g=new Map;for(let D of f.nodes){let M=D.x*$+X,A=D.y*$+nt;if(M<0||M>T||A<0||A>O)continue;let _=wt(D),B=g.get(_);B||g.set(_,B=[]),B.push(M,A)}e.globalAlpha=1;for(let[D,M]of g){e.fillStyle=D,e.beginPath();for(let A=0;A<M.length;A+=2)e.rect(M[A]-1,M[A+1]-1,2,2);e.fill()}}else{let g=new Map;for(let M of st){let A=!!S&&!E.has(M.node.id),_=wt(M.node)+(A?"|d":"|n"),B=g.get(_);B||g.set(_,B=[]),B.push(M)}for(let[M,A]of g){let[_,B]=M.split("|");e.globalAlpha=B==="d"?.22:1,e.fillStyle=_,e.beginPath();for(let q of A)e.moveTo(q.x+q.r,q.y),e.arc(q.x,q.y,q.r,0,Pt);e.fill()}e.globalAlpha=1;let D=String(z.query||"").trim().toLowerCase();for(let M of st){if(M.node.kind==="memory"||M.node.missing)continue;let A=M.r*1.75,_=Math.min(5,A/3),B=M.x-A/2,q=M.y-A/2;e.fillStyle=wt(M.node),e.beginPath(),e.moveTo(B+_,q),e.arcTo(B+A,q,B+A,q+A,_),e.arcTo(B+A,q+A,B,q+A,_),e.arcTo(B,q+A,B,q,_),e.arcTo(B,q,B+A,q,_),e.closePath(),e.fill()}for(let M of st){let A=M.node;A.status==="provisional"&&(e.strokeStyle=wt(A),e.lineWidth=1.2,e.setLineDash([3,3]),e.beginPath(),e.ellipse(M.x,M.y,M.r+5,M.r+5,0,0,Pt),e.stroke(),e.setLineDash([])),A.locked&&(e.fillStyle=h,e.globalAlpha=.95,e.fillRect(M.x-1.5,M.y-1.5,3,3),e.globalAlpha=1),(A.id===S||A.id===K?.id)&&(e.strokeStyle=A.id===S?C:wt(A),e.lineWidth=1.5,e.beginPath(),e.ellipse(M.x,M.y,M.r+4,M.r+4,0,0,Pt),e.stroke()),D&&String(A.title||A.id).toLowerCase().includes(D)&&(e.strokeStyle=C,e.lineWidth=2,e.beginPath(),e.ellipse(M.x,M.y,M.r+4,M.r+4,0,0,Pt),e.stroke())}}if(e.globalAlpha=1,e.strokeStyle=n,z.labels&&!tt){e.font='11.5px -apple-system,"PingFang SC","Microsoft YaHei",sans-serif';let g=st.filter(G=>G.x>-60&&G.x<T+60&&G.y>-60&&G.y<O+60),D=(v.k>=.55||st.length<34)&&g.length<=260,M=g.length>260?9999:3,A=Y((v.k-.3)/.35,0,1),_=b?.type==="pan"&&b.moved,gt=(b?.type==="node"&&b.moved||_)&&f.nodes.length>400?g.filter(G=>G.node.id===S):D?g:g.filter(G=>G.node.id===S||G.node.degree>=M),pt=gt.length>260?gt.slice(0,260):gt;pt.sort((G,bt)=>+(bt.node.id===S)-+(G.node.id===S)||bt.node.degree-G.node.degree);let mt=[];e.textAlign="center",e.textBaseline="top";for(let G of pt){if(S&&!E.has(G.node.id))continue;let bt=G.node.id===S;if(!bt&&(!D&&G.node.degree<M||A<.02))continue;let At=String(G.node.title||G.node.id),Lt=e.measureText(At).width,Ot=ft=>({l:G.x-Lt/2-3,t:ft-1,r:G.x+Lt/2+3,b:ft+14}),Bt=ft=>mt.some(vt=>ft.l<vt.r&&ft.r>vt.l&&ft.t<vt.b&&ft.b>vt.t),kt=G.y+G.r+4,ct=Ot(kt);Bt(ct)&&(kt+=16,ct=Ot(kt),Bt(ct))||ct.l<2||ct.r>T-2||ct.b>O-2||(mt.push(ct),e.globalAlpha=bt?1:.78*Math.max(.35,A),e.lineWidth=3.5,e.strokeStyle=h,e.lineJoin="round",e.strokeText(At,G.x,kt),e.fillStyle=n,e.fillText(At,G.x,kt))}e.globalAlpha=1}else if(z.labels&&tt&&S){let g=f.nodes.find(D=>D.id===S);g&&(e.font="12px system-ui, sans-serif",e.textAlign="center",e.textBaseline="top",e.fillStyle=n,e.fillText(String(g.title||g.id),g.x*$+X,g.y*$+nt+10))}!f.nodes.length&&U&&(e.font="13px system-ui, sans-serif",e.textAlign="center",e.textBaseline="middle",e.fillStyle=n,e.globalAlpha=.55,e.fillText(U,T/2,O/2),e.globalAlpha=1),L()},F=t=>{if(rt=null,Q)return;let n=z.motion&&!H&&f.active;if(n){yt+=it?Math.min(64,t-it):17;let h=0;for(;yt>=1e3/60&&h<4;yt-=1e3/60,h++)f.tick();it=t}else it=0,yt=0;k(),n&&s()};function s(){!Q&&rt===null&&(rt=et.requestAnimationFrame(F))}let w=()=>{N(v.k),s()},o=()=>{v=Et(f.nodes,T,O),Z(),w()},I=(t,n={x:T/2,y:O/2})=>{v=Nt(v,t,n),Z(),w()},m=()=>{let t=d.getBoundingClientRect();if(!t.width||!t.height)return;let n=t.width,h=t.height;v.x+=(n-T)/2,v.y+=(h-O)/2,T=n,O=h,V=Math.min(2,et.devicePixelRatio||1),d.width=Math.round(T*V),d.height=Math.round(O*V),s()},i=()=>{l(b);let[t,n]=[...J.values()];b={type:"pinch",distance:Math.max(1,Math.hypot(n.x-t.x,n.y-t.y)),camera:{...v},center:{x:(t.x+n.x)/2,y:(t.y+n.y)/2},moved:!0}},p=t=>{if(t.button!==0&&t.pointerType!=="touch")return;t.preventDefault(),d.focus({preventScroll:!0});let n=lt(t);if(J.set(t.pointerId,n),d.setPointerCapture?.(t.pointerId),J.size>=2){i(),Z();return}let h=xt(n),C=Mt(n),S=h?f.componentOf(h.id):null,E=h&&t.shiftKey&&S?"rigid":"node",ot=E==="rigid"?S.members:h?[h]:[];if(b={type:h?"node":"pan",node:h,mode:E,members:ot,start:n,camera:{...v},moved:!1,offset:h?{x:h.x-C.x,y:h.y-C.y}:null,snapshot:ot.map($=>({id:$.id,x:$.x,y:$.y,fx:$.fx,fy:$.fy,locked:$.locked}))},h){for(let $ of ot)f.hold($.id,$.x,$.y);f.startDragScope(h.id),f.setDragging(!0)}Z(),d.style.cursor="grabbing"},u=t=>{let n=lt(t);if(!J.has(t.pointerId)||!b){r(xt(n,K),n);return}if(J.set(t.pointerId,n),b.type==="pinch"){if(J.size<2)return;let[h,C]=[...J.values()],S={x:(h.x+C.x)/2,y:(h.y+C.y)/2};v=Nt(b.camera,Math.hypot(C.x-h.x,C.y-h.y)/b.distance,b.center),v.x+=S.x-b.center.x,v.y+=S.y-b.center.y,w()}else{if(b.moved||(b.moved=Math.hypot(n.x-b.start.x,n.y-b.start.y)>5),!b.moved)return;if(b.node){let h=Mt(n),C=b.node;if(b.mode==="rigid"){let S=h.x+b.offset.x,E=h.y+b.offset.y,ot=S-C.fx,$=E-C.fy;for(let X of b.members)f.hold(X.id,X.fx+ot,X.fy+$)}else f.hold(C.id,h.x+b.offset.x,h.y+b.offset.y);f.settle(2)}else v.x=b.camera.x+n.x-b.start.x,v.y=b.camera.y+n.y-b.start.y;s()}},a=t=>{if(!J.has(t.pointerId))return;let n=t.type!=="pointerup",h=b?.node,C=!n&&!b?.moved&&b?.type!=="pinch"&&(t.detail??1)<2;if(C||n)l(b);else if(h){for(let S of b.snapshot){let E=f.nodeById(S.id);E&&(S.locked||S.fx!=null?(E.fx=E.x,E.fy=E.y,E.locked=!0,E.vx=0,E.vy=0):f.release(S.id))}f.setDragging(!1),H||!z.motion?(f.settle(120),f.clearDragScope()):f.reheat(.3)}J.delete(t.pointerId),b=null,J.size&&(b={type:"pan",start:[...J.values()][0],camera:{...v},moved:!0}),d.hasPointerCapture?.(t.pointerId)&&d.releasePointerCapture(t.pointerId),C&&y(h?.id||""),K=null,d.style.cursor="grab",Z(),s()},c=(t,n,h,C)=>{t.addEventListener(n,h,C),It.push(()=>t.removeEventListener(n,h,C))};c(d,"pointerdown",p),c(d,"pointermove",u);for(let t of["pointerup","pointercancel","lostpointercapture"])c(d,t,a);c(d,"pointerleave",()=>{b||(K=null,Z(),s())}),c(d,"contextmenu",t=>{t.preventDefault();let n=xt(lt(t));if(!n)return;let h=f.nodeById(n.id);h&&(h.fx!=null?f.unpin(n.id):f.pin(n.id,h.x,h.y),f.setDragging(!1),(H||!z.motion)&&f.settle(20),s())}),c(d,"dblclick",t=>{y(xt(lt(t))?.id||"")}),c(d,"wheel",t=>{t.preventDefault(),I(Math.exp(-Y(t.deltaY,-160,160)*.0025),lt(t))},{passive:!1}),c(d,"keydown",t=>{if(t.key==="+"||t.key==="=")I(1.25);else if(t.key==="-")I(.8);else if(t.key==="0"||t.key==="Home")o();else if(t.key==="Escape")l(b),b=null,J.clear(),y(""),Z(),s();else if(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(t.key)){let n=t.shiftKey?90:30;v.x+=t.key==="ArrowLeft"?n:t.key==="ArrowRight"?-n:0,v.y+=t.key==="ArrowUp"?n:t.key==="ArrowDown"?-n:0,s()}else return;t.preventDefault()}),c(et,"blur",()=>{l(b),b=null,J.clear(),K=null,Z(),s()});let P=et.ResizeObserver?new et.ResizeObserver(m):null;P?.observe(d),c(et,"resize",m);let j=et.MutationObserver?new et.MutationObserver(s):null;return j?.observe(d.ownerDocument.documentElement,{attributes:!0,attributeFilter:["class","data-theme","style"]}),d.ownerDocument.body&&j?.observe(d.ownerDocument.body,{attributes:!0,attributeFilter:["class","data-theme","style"]}),m(),{update(t,n=""){b?.node&&!t.nodes.some(C=>C.id===b.node.id)&&(l(b),b=null,J.clear());let h=f.update(t);ht=n,K&&!f.nodes.includes(K)&&(K=null,Z()),!St&&f.nodes.length?(f.settle(220),St=!0,o()):h&&(H||!z.motion)&&f.settle(180),s()},configure(t){let n=["repulsion","distance","center"].some(h=>t[h]!==void 0&&t[h]!==z[h]);z={...z,...t},n&&(f.configure(t),(H||!z.motion)&&f.settle(160)),s()},fit:o,zoom:I,isPinned(t){return f.nodeById(t)?.locked===!0},pinnedCount(){return f.nodes.reduce((t,n)=>t+(n.locked?1:0),0)},snapshot(){return f.nodes.map(t=>({id:t.id,x:t.x*v.k+v.x,y:t.y*v.k+v.y,r:ut(t),pinned:t.locked===!0,degree:t.degree||0}))},unpinAll(){f.unpinAll(),f.clearDragScope(),(H||!z.motion)&&f.settle(120),s()},relayout(){l(b),b=null,J.clear(),f.relayout(),(H||!z.motion)&&f.settle(220),s()},dispose(){Q=!0,l(b),b=null,J.clear(),rt!==null&&et.cancelAnimationFrame(rt);for(let t of It)t();P?.disconnect(),j?.disconnect(),f.dispose(),Z()}}}return Wt(Zt);})();
|
package/lib/webui/graph-view.js
CHANGED
|
@@ -58,7 +58,7 @@ export function createForceLayout(initialOptions = {}) {
|
|
|
58
58
|
const edgeLengths = new Map()
|
|
59
59
|
let nodes = [], edges = [], adjacency = new Map(), components = null
|
|
60
60
|
let signature = '', alpha = 1, options = { ...DEFAULT_OPTIONS, ...initialOptions }
|
|
61
|
-
let dragComp = null, dragging = false, settling = false
|
|
61
|
+
let dragComp = null, dragging = false, settling = false
|
|
62
62
|
let layoutInitialized = false
|
|
63
63
|
|
|
64
64
|
const factors = () => ({
|
|
@@ -360,6 +360,8 @@ export function createForceLayout(initialOptions = {}) {
|
|
|
360
360
|
const links = (graph?.edges || []).filter(edge => ids.has(edge.from) && ids.has(edge.to) && edge.from !== edge.to)
|
|
361
361
|
const nextSignature = JSON.stringify([input.map(node => node.id), links.map(edge => [edge.from, edge.to]).sort()])
|
|
362
362
|
const changed = signature !== nextSignature
|
|
363
|
+
// 重排判定要用「上一帧的节点数」:nodes 马上就被新数据覆盖了
|
|
364
|
+
const previousCount = nodes.length
|
|
363
365
|
const degree = new Map()
|
|
364
366
|
for (const edge of links) {
|
|
365
367
|
degree.set(edge.from, (degree.get(edge.from) || 0) + 1)
|
|
@@ -398,10 +400,13 @@ export function createForceLayout(initialOptions = {}) {
|
|
|
398
400
|
})
|
|
399
401
|
adjacency = buildAdjacency()
|
|
400
402
|
if (changed) components = buildComponents()
|
|
401
|
-
//
|
|
403
|
+
// 首次拿到真实图(或从空图切到有数据)时用花瓣向心布局铺开:
|
|
402
404
|
// 最大簇居中、外围收成圆。之前只看 signature 是否为空会漏掉「空图先到、
|
|
403
405
|
// 数据后到」的场景,导致新节点按螺旋挤在中心,必须手动点一次重新布局。
|
|
406
|
+
// 但心跳里 200 条上限的截断集合换了一批节点时不能重排:那会让整图跳一下,
|
|
407
|
+
// 极小缩放下就是「所有节点互相打架闪现」。只有上一帧几乎空着才重铺。
|
|
404
408
|
const mostlyFresh = nodes.length > 0 && fresh.length >= Math.ceil(nodes.length * .6)
|
|
409
|
+
&& previousCount <= Math.max(8, nodes.length * .2)
|
|
405
410
|
if (changed && nodes.length && (!layoutInitialized || mostlyFresh)) {
|
|
406
411
|
layoutFlower()
|
|
407
412
|
layoutInitialized = true
|
|
@@ -475,15 +480,14 @@ export function createForceLayout(initialOptions = {}) {
|
|
|
475
480
|
if (node.fx != null) { node.x = node.fx; node.vx = 0 } else { node.vx *= SIM.vDecay; node.x += node.vx }
|
|
476
481
|
if (node.fy != null) { node.y = node.fy; node.vy = 0 } else { node.vy *= SIM.vDecay; node.y += node.vy }
|
|
477
482
|
if (!Number.isFinite(node.x) || !Number.isFinite(node.y)) { node.x = 0; node.y = 0; node.vx = 0; node.vy = 0 }
|
|
478
|
-
//
|
|
479
|
-
//
|
|
480
|
-
//
|
|
481
|
-
//
|
|
482
|
-
//
|
|
483
|
+
// 硬分离:弹簧链会把节点拉回彼此身上,而斥力在 alpha 落到地板后就没了,
|
|
484
|
+
// 两颗粒一旦停在重叠位置就会永远贴着(用户看到的「打架 / 重合」)。
|
|
485
|
+
// 阈值只看世界坐标与节点半径,绝不跟缩放挂钩:之前写成 24 / viewScale,
|
|
486
|
+
// 缩到最小(k≈.06)时等于要求 400 世界像素间距,每帧互相猛推,整图就是打架。
|
|
487
|
+
// 拖动中只做「别完全重合」的软约束,否则整簇会被锁成刚性块、弹簧拉不动邻居;
|
|
488
|
+
// 松手后才用完整间距。冻结节点与右键锁定节点不被推。
|
|
483
489
|
if (node.fx == null || (!dragging && !node.locked)) {
|
|
484
|
-
|
|
485
|
-
// 弹簧拉不动邻居,拖动就只剩一条越拉越长的边。松手后才用 24px 屏幕间距。
|
|
486
|
-
const minSep = dragging ? 12 : 24 / clamp(viewScale, .06, 5), minSep2 = minSep * minSep
|
|
490
|
+
const own = (Number(node.radius) || 4) + (dragging ? 2 : 8)
|
|
487
491
|
const gx = Math.floor(node.x / SIM.cell), gy = Math.floor(node.y / SIM.cell)
|
|
488
492
|
for (let ox = -1; ox <= 1; ox++) for (let oy = -1; oy <= 1; oy++) {
|
|
489
493
|
const list = grid.get(`${gx + ox},${gy + oy}`)
|
|
@@ -491,9 +495,17 @@ export function createForceLayout(initialOptions = {}) {
|
|
|
491
495
|
for (const other of list) {
|
|
492
496
|
if (other === node) continue
|
|
493
497
|
let dx = node.x - other.x, dy = node.y - other.y, d2 = dx * dx + dy * dy
|
|
498
|
+
const minSep = own + (Number(other.radius) || 4), minSep2 = minSep * minSep
|
|
494
499
|
if (d2 >= minSep2) continue
|
|
495
|
-
|
|
496
|
-
|
|
500
|
+
let d = Math.sqrt(d2)
|
|
501
|
+
if (d < .01) {
|
|
502
|
+
// 完全重合:按 id 哈希给一个确定方向分开,避免随机数让位置不可复现。
|
|
503
|
+
const jitter = hashId(node.id) ^ hashId(other.id)
|
|
504
|
+
dx = ((jitter & 1023) / 1023 - .5) || .25
|
|
505
|
+
dy = ((jitter >>> 10 & 1023) / 1023 - .5) || .25
|
|
506
|
+
d = Math.hypot(dx, dy) || 1
|
|
507
|
+
}
|
|
508
|
+
const push = minSep - d
|
|
497
509
|
node.x += dx / d * push; node.y += dy / d * push
|
|
498
510
|
}
|
|
499
511
|
}
|
|
@@ -530,7 +542,6 @@ export function createForceLayout(initialOptions = {}) {
|
|
|
530
542
|
reheat(.25)
|
|
531
543
|
},
|
|
532
544
|
reheat,
|
|
533
|
-
setScale(value) { viewScale = Number(value) > 0 ? Number(value) : 1 },
|
|
534
545
|
// pin = 用户右键锁定(计数、画标记);hold = 拖动落点(留在原地但不计为锁定)。
|
|
535
546
|
pin(id, x, y) {
|
|
536
547
|
const state = cache.get(id)
|
|
@@ -571,6 +582,14 @@ export function createForceLayout(initialOptions = {}) {
|
|
|
571
582
|
},
|
|
572
583
|
relayout() {
|
|
573
584
|
layoutFlower()
|
|
585
|
+
// 重排后必须按新几何重记弹簧原长:否则沿用旧的 baseLen(可能来自上一次拖动
|
|
586
|
+
// 或上一版布局)会把刚铺开的节点硬拽回旧间距,弹簧与斥力互相拉扯,
|
|
587
|
+
// 极小缩放下就是成对节点「打架 / 闪现」。与 configure 改距离时同一套口径。
|
|
588
|
+
edgeLengths.clear()
|
|
589
|
+
for (const edge of edges) {
|
|
590
|
+
edge.baseLen = baseLenOf(edge.source, edge.target)
|
|
591
|
+
edgeLengths.set(JSON.stringify([edge.from, edge.to, edge.kind || '']), edge.baseLen)
|
|
592
|
+
}
|
|
574
593
|
dragComp = null; dragging = false; alpha = 1
|
|
575
594
|
},
|
|
576
595
|
componentOf,
|
|
@@ -635,14 +654,14 @@ export function placeLabels(candidates, obstacles, width, height) {
|
|
|
635
654
|
}
|
|
636
655
|
|
|
637
656
|
// ---- 画布控制器:相机、渲染、指针与键盘 ------------------------------------
|
|
638
|
-
export function createGraphView(canvas, { onFocus = () => {}, onZoom = () => {}, tooltip,
|
|
657
|
+
export function createGraphView(canvas, { onFocus = () => {}, onZoom = () => {}, onPaint = () => {}, tooltip,
|
|
639
658
|
reducedMotion = false, emptyLabel = '' } = {}) {
|
|
640
659
|
const context = canvas.getContext('2d')
|
|
641
660
|
if (!context) throw new Error('Canvas 2D is unavailable')
|
|
642
661
|
const layout = createForceLayout()
|
|
643
662
|
let width = 1, height = 1, ratio = 1, camera = { x: 0, y: 0, k: 1 }
|
|
644
663
|
let options = { ...DEFAULT_OPTIONS }, focused = '', hovered = null, gesture = null
|
|
645
|
-
let initialized = false, disposed = false, frame = null, lastTime = 0, accumulator = 0
|
|
664
|
+
let initialized = false, disposed = false, frame = null, lastTime = 0, accumulator = 0
|
|
646
665
|
const pointers = new Map(), cleanup = []
|
|
647
666
|
const win = canvas.ownerDocument.defaultView
|
|
648
667
|
const world = point => ({ x: (point.x - camera.x) / camera.k, y: (point.y - camera.y) / camera.k })
|
|
@@ -652,7 +671,9 @@ export function createGraphView(canvas, { onFocus = () => {}, onZoom = () => {},
|
|
|
652
671
|
return { x: (event.clientX - rect.left) * width / rect.width, y: (event.clientY - rect.top) * height / rect.height }
|
|
653
672
|
}
|
|
654
673
|
// 命中测试走世界网格;千级节点时避免每次 pointermove 全量扫描。
|
|
655
|
-
|
|
674
|
+
// prefer = 当前 hover:极小缩放下几十个节点会挤进同一个像素邻域,纯最近邻会每帧换人,
|
|
675
|
+
// 看起来就是节点之间"打架闪现"。所以只有明显更近(>25%)才换目标。
|
|
676
|
+
const hit = (p, prefer) => {
|
|
656
677
|
const nodes = layout.nodes
|
|
657
678
|
if (!nodes.length) return null
|
|
658
679
|
const target = world(p), reach = clamp(Math.ceil(40 / Math.max(camera.k, .06) / SIM.cell), 1, 8)
|
|
@@ -663,16 +684,21 @@ export function createGraphView(canvas, { onFocus = () => {}, onZoom = () => {},
|
|
|
663
684
|
if (!list) grid.set(key, list = [])
|
|
664
685
|
list.push(node)
|
|
665
686
|
}
|
|
666
|
-
|
|
687
|
+
const near = node => Math.max(6, radius(node) + 4)
|
|
688
|
+
let closest = null, distance = Infinity, preferDistance = Infinity
|
|
667
689
|
for (let ox = -reach; ox <= reach; ox++) for (let oy = -reach; oy <= reach; oy++) {
|
|
668
690
|
const list = grid.get(`${gx + ox},${gy + oy}`)
|
|
669
691
|
if (!list) continue
|
|
670
692
|
for (const node of list) {
|
|
671
693
|
const sx = node.x * camera.k + camera.x, sy = node.y * camera.k + camera.y
|
|
672
694
|
const d = Math.hypot(sx - p.x, sy - p.y)
|
|
673
|
-
if (
|
|
695
|
+
if (node === prefer) preferDistance = d
|
|
696
|
+
if (d <= near(node) && d < distance) { closest = node; distance = d }
|
|
674
697
|
}
|
|
675
698
|
}
|
|
699
|
+
// 磁滞:只有新候选确实更近(≥2px)才换目标。极小缩放下两颗点可能只差 2-3px,
|
|
700
|
+
// 纯最近邻会随鼠标 1px 抖动来回换人 —— 高亮反复切换就是「打架闪现」。
|
|
701
|
+
if (prefer && preferDistance <= near(prefer) && (!closest || distance > preferDistance - 2)) return prefer
|
|
676
702
|
return closest
|
|
677
703
|
}
|
|
678
704
|
const hideTooltip = () => { if (tooltip) tooltip.hidden = true }
|
|
@@ -707,7 +733,6 @@ export function createGraphView(canvas, { onFocus = () => {}, onZoom = () => {},
|
|
|
707
733
|
context.fill()
|
|
708
734
|
}
|
|
709
735
|
const draw = () => {
|
|
710
|
-
layout.setScale(camera.k)
|
|
711
736
|
context.setTransform(ratio, 0, 0, ratio, 0, 0)
|
|
712
737
|
context.clearRect(0, 0, width, height)
|
|
713
738
|
const style = win.getComputedStyle(canvas)
|
|
@@ -721,8 +746,8 @@ export function createGraphView(canvas, { onFocus = () => {}, onZoom = () => {},
|
|
|
721
746
|
if (edge.to === active) neighbors.add(edge.from)
|
|
722
747
|
}
|
|
723
748
|
context.strokeStyle = foreground
|
|
724
|
-
//
|
|
725
|
-
const breath = options.motion && !reducedMotion ? .06 + .025 * Math.sin(Date.now() / 900) : .07
|
|
749
|
+
// 呼吸只在模拟活跃时出现:冷却后不再为了透明度自续帧(空闲 = 零帧、零 GPU)。
|
|
750
|
+
const breath = options.motion && !reducedMotion && layout.active ? .06 + .025 * Math.sin(Date.now() / 900) : .07
|
|
726
751
|
if (options.grid !== false) drawGrid(breath)
|
|
727
752
|
// 边:自动边实线、手动/worker 边虚线并按「主语 → 宾语」画箭头,两批各自一次 stroke。
|
|
728
753
|
const k = camera.k, ox = camera.x, oy = camera.y
|
|
@@ -917,6 +942,8 @@ export function createGraphView(canvas, { onFocus = () => {}, onZoom = () => {},
|
|
|
917
942
|
context.fillStyle = foreground; context.globalAlpha = .55
|
|
918
943
|
context.fillText(emptyLabel, width / 2, height / 2); context.globalAlpha = 1
|
|
919
944
|
}
|
|
945
|
+
// 每真正重绘一次计数一次:缩略图据此决定要不要拷贝,空闲期不再白拷纹理。
|
|
946
|
+
onPaint()
|
|
920
947
|
}
|
|
921
948
|
const animate = time => {
|
|
922
949
|
frame = null
|
|
@@ -928,10 +955,11 @@ export function createGraphView(canvas, { onFocus = () => {}, onZoom = () => {},
|
|
|
928
955
|
for (; accumulator >= 1000 / 60 && steps < 4; accumulator -= 1000 / 60, steps++) layout.tick()
|
|
929
956
|
lastTime = time
|
|
930
957
|
} else { lastTime = 0; accumulator = 0 }
|
|
931
|
-
// 空闲降到 ~30fps:只重绘不改坐标(呼吸在 drawGrid 里)。
|
|
932
|
-
if (!stepping && options.motion && !reducedMotion && (idleFrame++ % 2)) { requestDraw(); return }
|
|
933
958
|
draw()
|
|
934
|
-
|
|
959
|
+
// 只有物理仍在跑(模拟活跃 / 拖动 / 收敛)才自续帧。
|
|
960
|
+
// 冷却后不再空转重绘:GPU 占用会随布局收敛回落,而不是长期占住一档。
|
|
961
|
+
// 悬停、相机、数据变化、缩放等路径各自 requestDraw 一帧,画面依旧即时更新。
|
|
962
|
+
if (stepping) requestDraw()
|
|
935
963
|
}
|
|
936
964
|
function requestDraw() {
|
|
937
965
|
if (!disposed && frame === null) frame = win.requestAnimationFrame(animate)
|
|
@@ -981,7 +1009,7 @@ export function createGraphView(canvas, { onFocus = () => {}, onZoom = () => {},
|
|
|
981
1009
|
}
|
|
982
1010
|
const move = event => {
|
|
983
1011
|
const p = point(event)
|
|
984
|
-
if (!pointers.has(event.pointerId) || !gesture) { setHover(hit(p), p); return }
|
|
1012
|
+
if (!pointers.has(event.pointerId) || !gesture) { setHover(hit(p, hovered), p); return }
|
|
985
1013
|
pointers.set(event.pointerId, p)
|
|
986
1014
|
if (gesture.type === 'pinch') {
|
|
987
1015
|
if (pointers.size < 2) return
|
package/package.json
CHANGED
package/scripts/build-graph.mjs
CHANGED
|
@@ -1,17 +1,45 @@
|
|
|
1
|
-
import { build } from 'esbuild'
|
|
2
1
|
import fs from 'node:fs'
|
|
3
2
|
import { fileURLToPath } from 'node:url'
|
|
4
3
|
|
|
5
4
|
// 引擎已改为自研力导向,bundle 里不再打包任何第三方运行时代码。
|
|
6
|
-
|
|
5
|
+
// esbuild 只在这里用,而且是 devDependency:静态 import 会让从 npm 装出来的插件
|
|
6
|
+
// 目录里的 `npm run check` 直接崩在模块解析,到不了下面的 skip 分支。
|
|
7
|
+
const target = fileURLToPath(new URL('../lib/webui/graph-view.bundle.js', import.meta.url))
|
|
8
|
+
const shared = {
|
|
7
9
|
entryPoints: [fileURLToPath(new URL('../lib/webui/graph-view.js', import.meta.url))],
|
|
8
|
-
outfile: fileURLToPath(new URL('../lib/webui/graph-view.bundle.js', import.meta.url)),
|
|
9
10
|
bundle: true,
|
|
10
11
|
format: 'iife',
|
|
11
12
|
globalName: 'DshMemuGraph',
|
|
12
13
|
target: ['es2020'],
|
|
13
14
|
minify: true,
|
|
14
15
|
banner: { js: '/* Generated by scripts/build-graph.mjs. Licenses: graph-LICENSE.txt */' },
|
|
15
|
-
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const esbuild = await (async () => {
|
|
19
|
+
try { return (await import('esbuild')).build } catch { return null }
|
|
20
|
+
})()
|
|
21
|
+
|
|
22
|
+
// `--check` 是防漂移闸门:改完引擎忘了重打包,浏览器加载的还是旧 bundle,
|
|
23
|
+
// 源码里的修复(比如最小缩放打架)在真实页面上根本不存在,测试却全绿。
|
|
24
|
+
if (process.argv.includes('--check')) {
|
|
25
|
+
if (!esbuild) {
|
|
26
|
+
console.log('skip graph bundle check: esbuild is not installed (production install has no devDependencies)')
|
|
27
|
+
process.exit(0)
|
|
28
|
+
}
|
|
29
|
+
// write:false:产物只在内存里比对,不在磁盘上留一份「看似 bundle」的副本。
|
|
30
|
+
const result = await esbuild({ ...shared, write: false })
|
|
31
|
+
const drifted = Buffer.from(result.outputFiles[0].text, 'utf8').equals(fs.readFileSync(target)) === false
|
|
32
|
+
if (drifted) {
|
|
33
|
+
console.error('lib/webui/graph-view.bundle.js does not match lib/webui/graph-view.js — run `npm run build:graph`')
|
|
34
|
+
process.exit(1)
|
|
35
|
+
}
|
|
36
|
+
process.exit(0)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!esbuild) {
|
|
40
|
+
console.error('esbuild is required to build the graph bundle: `npm ci` in the plugin directory first')
|
|
41
|
+
process.exit(1)
|
|
42
|
+
}
|
|
43
|
+
await esbuild({ ...shared, outfile: target })
|
|
16
44
|
fs.writeFileSync(new URL('../lib/webui/graph-LICENSE.txt', import.meta.url),
|
|
17
45
|
'graph-view.bundle.js: 本 bundle 无第三方运行时依赖(自研力导向引擎)。\n')
|
package/scripts/check-all.mjs
CHANGED
|
@@ -43,6 +43,8 @@ const budget = (rel, limit) => {
|
|
|
43
43
|
budget('AGENTS.md', 60000)
|
|
44
44
|
|
|
45
45
|
check('i18n', process.execPath, ['scripts/check-i18n.mjs'])
|
|
46
|
+
// 图谱引擎是唯一有产物的模块:浏览器加载的是 bundle,源码改了不重打包就等于没改。
|
|
47
|
+
check('graph bundle', process.execPath, ['scripts/build-graph.mjs', '--check'])
|
|
46
48
|
// npm silently de-duplicates `files` on pack, so a repeated entry only rots in
|
|
47
49
|
// source without any failing check. Pin the whitelist shape here instead.
|
|
48
50
|
check('package.json', process.execPath, ['-e', 'const p=JSON.parse(require("fs").readFileSync("package.json","utf8"));if(!Array.isArray(p.files)||new Set(p.files).size!==p.files.length)throw new Error("package.json: files must be an array with no duplicates")'])
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { chromium } from 'playwright'
|
|
4
|
+
import sharp from 'sharp'
|
|
5
|
+
|
|
6
|
+
// README 的七张图是**产物**:界面一改,它们就跟着过期(1.3.3 之前就漏了「关系图谱」这一页)。
|
|
7
|
+
// 跑法:先起预览,再跑本脚本。
|
|
8
|
+
// node --import ./tests/loader-register.mjs scripts/preview.mjs --port 7789
|
|
9
|
+
// node scripts/make-readme-shots.mjs
|
|
10
|
+
// 预览只在临时 DSH_MEMU_HOME 里造示例数据,不会碰任何真实记忆库。
|
|
11
|
+
const base = process.argv[2] || 'http://127.0.0.1:7789/dsh-memu-memory/ui'
|
|
12
|
+
const out = path.resolve(import.meta.dirname, '../assets/screenshots')
|
|
13
|
+
|
|
14
|
+
const shots = [
|
|
15
|
+
{ name: 'webui-memory', hash: '#/settings/memories', width: 1600, height: 1180, wait: '.dshm-wall-item' },
|
|
16
|
+
{ name: 'drawer', hash: '#/settings/memories', width: 1600, height: 1044, wait: '.dshm-wall-item', then: '.dshm-wall-item', opened: '.dshm-drawer' },
|
|
17
|
+
{ name: 'relations', hash: '#/settings/graph', width: 1440, height: 1293, wait: 'canvas', settle: 2600 },
|
|
18
|
+
{ name: 'settings', hash: '#/settings/settings', width: 1600, height: 1346, wait: '.dshm-card' },
|
|
19
|
+
{ name: 'stats', hash: '#/settings/stats', width: 1400, height: 1740, wait: '.dshm-card' },
|
|
20
|
+
{ name: 'webui-dark', hash: '#/settings/memories', width: 1600, height: 1044, wait: '.dshm-wall-item', dark: true },
|
|
21
|
+
{ name: 'mobile', hash: '#/settings/memories', width: 390, height: 844, wait: '.dshm-wall-item' },
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
// Playwright 想要 1248 号构建;机器上只有更早的构建时直接用那个可执行文件。
|
|
25
|
+
const chromeExe = ['chromium-1248/chrome-win64/chrome.exe', 'chromium-1194/chrome-win/chrome.exe', 'chromium-1117/chrome-win/chrome.exe']
|
|
26
|
+
.map(rel => path.join(process.env.LOCALAPPDATA || '', 'ms-playwright', rel))
|
|
27
|
+
.find(p => fs.existsSync(p))
|
|
28
|
+
if (!chromeExe) throw new Error('no chromium build under %LOCALAPPDATA%/ms-playwright — run `npx playwright install chromium`')
|
|
29
|
+
|
|
30
|
+
const browser = await chromium.launch({ headless: true, executablePath: chromeExe })
|
|
31
|
+
const written = []
|
|
32
|
+
try {
|
|
33
|
+
for (const shot of shots) {
|
|
34
|
+
// 每图一个新 context:主题、选中的库、滚动位置都存在 localStorage 里,
|
|
35
|
+
// 共用的话「深色」那张会把后面所有图都染黑。
|
|
36
|
+
const context = await browser.newContext({ viewport: { width: shot.width, height: shot.height }, deviceScaleFactor: 1 })
|
|
37
|
+
const page = await context.newPage()
|
|
38
|
+
const errors = []
|
|
39
|
+
page.on('pageerror', error => errors.push(String(error.message || error)))
|
|
40
|
+
await page.goto(base + shot.hash, { waitUntil: 'load' })
|
|
41
|
+
await page.waitForSelector('.dshm-root', { timeout: 20000 })
|
|
42
|
+
if (shot.wait) await page.waitForSelector(shot.wait, { timeout: 20000 })
|
|
43
|
+
if (shot.dark) await page.click('#theme')
|
|
44
|
+
if (shot.then) await page.click(shot.then)
|
|
45
|
+
if (shot.opened) await page.waitForSelector(shot.opened, { timeout: 10000 })
|
|
46
|
+
await page.waitForTimeout(shot.settle ?? 900)
|
|
47
|
+
if (errors.length) throw new Error(`${shot.name}: page errors ${errors.join(' | ')}`)
|
|
48
|
+
const png = await page.screenshot()
|
|
49
|
+
const image = await sharp(png).jpeg({ quality: 84, mozjpeg: true }).toBuffer()
|
|
50
|
+
const file = path.join(out, `${shot.name}.jpg`)
|
|
51
|
+
fs.writeFileSync(file, image)
|
|
52
|
+
const meta = await sharp(image).metadata()
|
|
53
|
+
written.push(`${shot.name}.jpg ${meta.width}x${meta.height} ${(image.length / 1024).toFixed(0)}KB`)
|
|
54
|
+
await context.close()
|
|
55
|
+
}
|
|
56
|
+
} finally {
|
|
57
|
+
await browser.close()
|
|
58
|
+
}
|
|
59
|
+
console.log(written.join('\n'))
|
package/tests/browser.test.mjs
CHANGED
|
@@ -314,6 +314,33 @@ test('the global curation picker hides archived and deleted conversations too',
|
|
|
314
314
|
assert.deepEqual(out.sessions.map((s) => s.id), ['global-visible'])
|
|
315
315
|
})
|
|
316
316
|
|
|
317
|
+
// 手动整理按钮按库找会话:listSessions 只多带一个只读 libraryId,
|
|
318
|
+
// 整理本身仍走会话维度的 generatePrivate(与侧边栏同一通道)。
|
|
319
|
+
test('listSessions reports the bound libraryId so a library can be consolidated', async () => {
|
|
320
|
+
const cwd = path.join(home, 'browser-lib-sessions')
|
|
321
|
+
const lib = createLibrary({ name: 'browser-lib-sessions', cwd })
|
|
322
|
+
setSessionBinding('sess-in-lib', { libraryId: lib.id })
|
|
323
|
+
setSessionBinding('sess-elsewhere', { libraryId: 'lib-other' })
|
|
324
|
+
const ctx = {
|
|
325
|
+
get(name) {
|
|
326
|
+
if (name !== 'sessionQuery') return null
|
|
327
|
+
return {
|
|
328
|
+
listSessions: async () => [
|
|
329
|
+
{ header: { id: 'sess-in-lib', cwd }, live: false, persisted: true },
|
|
330
|
+
{ header: { id: 'sess-elsewhere', cwd }, live: false, persisted: true },
|
|
331
|
+
{ header: { id: 'sess-unbound', cwd }, live: false, persisted: true },
|
|
332
|
+
],
|
|
333
|
+
readTitleSnapshots: async (ids) => ids.map((sessionId) => ({ sessionId, status: 'fulfilled', value: {} })),
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
}
|
|
337
|
+
const byId = Object.fromEntries((await dispatch(ctx, 'listSessions', { limit: 80 })).sessions
|
|
338
|
+
.map(row => [row.id, row.libraryId]))
|
|
339
|
+
assert.equal(byId['sess-in-lib'], lib.id, 'a bound conversation reports its library')
|
|
340
|
+
assert.equal(byId['sess-elsewhere'], 'lib-other', 'another library stays itself')
|
|
341
|
+
assert.equal(byId['sess-unbound'], null, 'an unbound conversation reports null, not undefined')
|
|
342
|
+
})
|
|
343
|
+
|
|
317
344
|
// ---- provenance in the browser, and the private review queue ----
|
|
318
345
|
|
|
319
346
|
test('the browser shows where a memory came from, and lets it be corrected', async () => {
|