latticesql 4.3.7 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ var ve=1-Math.pow(.001,.0033333333333333335),ne=1,q=class{nodes=[];links=[];byId=new Map;chargeStrength;linkDistance;linkStrengthFn;linkIterations;collideRadius;collideStrength;collideIterations;center;velocityDecay;jiggle;alpha=1;alphaDecay;alphaMin;alphaTarget;constructor(t={}){this.chargeStrength=t.chargeStrength??(a=>-30*(a.weight??1)),this.linkDistance=t.linkDistance??(()=>30),this.linkStrengthFn=t.linkStrength,this.linkIterations=t.linkIterations??1,this.collideRadius=t.collideRadius??(a=>a.radius??0),this.collideStrength=t.collideStrength??1,this.collideIterations=t.collideIterations??1,this.center=t.center,this.velocityDecay=t.velocityDecay??.6,this.alphaDecay=t.alphaDecay??ve,this.alphaMin=t.alphaMin??.001,this.alphaTarget=t.alphaTarget??0,this.jiggle=t.jiggle??ye()}setNodes(t){return this.nodes=t,this.byId=new Map(t.map(a=>[a.id,a])),this}getNodes(){return this.nodes}setLinks(t){let a=new Map,d=[];for(let n of t){let o=this.resolve(n.source),m=this.resolve(n.target);!o||!m||(d.push({link:n,source:o,target:m,bias:0,strength:0}),a.set(o.id,(a.get(o.id)??0)+1),a.set(m.id,(a.get(m.id)??0)+1))}for(let n of d){let o=a.get(n.source.id)??1,m=a.get(n.target.id)??1;n.bias=o/(o+m),n.strength=this.linkStrengthFn?this.linkStrengthFn(n.link):1/Math.min(o,m)}return this.links=d,this}resolve(t){return typeof t=="string"?this.byId.get(t):t}reheat(t=1,a=this.alphaTarget){return this.alpha=t,this.alphaTarget=a,this}setAlphaTarget(t){return this.alphaTarget=t,this}get settled(){return this.alpha<this.alphaMin&&this.alphaTarget===0}tick(t=1){for(let a=0;a<t;a++)this.alpha+=(this.alphaTarget-this.alpha)*this.alphaDecay,this.applyCharge(this.alpha),this.applyLinks(this.alpha),this.applyCollide(),this.applyCenter(this.alpha),this.integrate();return this.alpha}applyCharge(t){for(let a of this.nodes)for(let d of this.nodes){if(a===d)continue;let n=d.x-a.x,o=d.y-a.y,m=n*n+o*o;n===0&&(n=this.jiggle(),m+=n*n),o===0&&(o=this.jiggle(),m+=o*o),m<ne&&(m=Math.sqrt(ne*m));let A=this.chargeStrength(d)*t/m;a.vx+=n*A,a.vy+=o*A}}applyLinks(t){for(let a=0;a<this.linkIterations;a++)for(let d of this.links){let{source:n,target:o,bias:m,strength:A}=d,L=this.linkDistance(d.link),y=o.x+o.vx-(n.x+n.vx),x=o.y+o.vy-(n.y+n.vy);y===0&&(y=this.jiggle()),x===0&&(x=this.jiggle());let b=Math.sqrt(y*y+x*x);b=(b-L)/b*t*A,y*=b,x*=b,o.vx-=y*m,o.vy-=x*m,n.vx+=y*(1-m),n.vy+=x*(1-m)}}applyCollide(){let t=this.nodes,a=t.length;for(let d=0;d<this.collideIterations;d++)for(let n=0;n<a;n++){let o=t[n];if(!o)continue;let m=this.collideRadius(o);if(m<=0)continue;let A=m*m,L=o.x+o.vx,y=o.y+o.vy;for(let x=n+1;x<a;x++){let b=t[x];if(!b)continue;let w=this.collideRadius(b);if(w<=0)continue;let M=m+w,g=L-(b.x+b.vx),v=y-(b.y+b.vy),s=g*g+v*v;if(s>=M*M)continue;g===0&&(g=this.jiggle(),s+=g*g),v===0&&(v=this.jiggle(),s+=v*v),s=Math.sqrt(s),s=(M-s)/s*this.collideStrength;let I=w*w,N=I/(A+I);o.vx+=(g*=s)*N,o.vy+=(v*=s)*N,N=1-N,b.vx-=g*N,b.vy-=v*N}}}applyCenter(t){if(!this.center)return;let{x:a,y:d,strength:n}=this.center;for(let o of this.nodes)o.vx+=(a-o.x)*n*t,o.vy+=(d-o.y)*n*t}integrate(){for(let t of this.nodes)t.fx==null?(t.vx*=this.velocityDecay,t.x+=t.vx):(t.x=t.fx,t.vx=0),t.fy==null?(t.vy*=this.velocityDecay,t.y+=t.vy):(t.y=t.fy,t.vy=0)}};function ye(){let p=625341585;return()=>(p=p*16807%2147483647,(p/2147483647-.5)*1e-6)}var k="http://www.w3.org/2000/svg",re=.2,xe=4;function se(p,t,a,d,n,o){let m=o-t*d,A=n-o-a*d;return Math.min(Math.max(p,Math.min(m,A)),Math.max(m,A))}function Ne(p,t={}){let a=e=>e.radius??12,d=new q({chargeStrength:e=>-30*(e.radius/6),linkDistance:()=>140,linkStrength:()=>.5,collideRadius:e=>{let r=(e.source.label?e.source.label.length:0)*4.2+14;return Math.max(e.radius+14,r)},collideIterations:3,center:{x:0,y:0,strength:.05}}),n=document.createElementNS(k,"svg");n.setAttribute("class","dm-graph"),n.style.width="100%",n.style.height="100%",n.style.display="block",n.style.cursor="grab",n.style.touchAction="none",n.appendChild(ke());let o=document.createElementNS(k,"g");o.setAttribute("class","dm-stage");let m=document.createElementNS(k,"g"),A=document.createElementNS(k,"g");o.appendChild(m),o.appendChild(A),n.appendChild(o),p.appendChild(n),o.style.visibility="hidden";let L=!1,y=!1,x=document.createElement("div");x.setAttribute("class","graph-loading");let b=document.createElement("div");b.setAttribute("class","graph-spinner"),x.appendChild(b),p.appendChild(x);function w(){L||(L=!0,o.style.visibility="visible",x.remove())}let M=null;if(typeof ResizeObserver<"u"){let e=!1;M=new ResizeObserver(()=>{!p.clientWidth||!p.clientHeight||(e?Math.abs(s.k-I)<.001&&P():(e=!0,P()))}),M.observe(p)}let g=new Map,v=[],s={k:1,x:0,y:0},I=re,N=0,D=0,Y=!1,C=!1,J=0,H=null,X=()=>p.clientWidth||900,z=()=>p.clientHeight||600,R=e=>e.toFixed(2);function j(){o.setAttribute("transform",`translate(${R(s.x)},${R(s.y)}) scale(${R(s.k)})`),n.style.setProperty("--gnode-label-size",`${(13/s.k).toFixed(2)}px`)}function K(){if(!g.size)return;let e=1/0,i=1/0,r=-1/0,c=-1/0;for(let h of g.values())e=Math.min(e,h.x-h.radius),i=Math.min(i,h.y-h.radius),r=Math.max(r,h.x+h.radius),c=Math.max(c,h.y+h.radius);let l=60;s.x=se(s.x,e,r,s.k,X(),l),s.y=se(s.y,i,c,s.k,z(),l)}function B(){for(let e of v)e.line.setAttribute("x1",e.source.x),e.line.setAttribute("y1",e.source.y),e.line.setAttribute("x2",e.target.x),e.line.setAttribute("y2",e.target.y),e.hit&&(e.hit.setAttribute("x1",e.source.x),e.hit.setAttribute("y1",e.source.y),e.hit.setAttribute("x2",e.target.x),e.hit.setAttribute("y2",e.target.y));for(let e of g.values())e.g.setAttribute("transform",`translate(${R(e.x)},${R(e.y)})`)}function U(){if(d.tick(1),B(),J++,!y&&(d.settled||J>400)&&(y=!0),!C&&y&&(C=!0,P()),d.settled){Y=!1;return}N=requestAnimationFrame(U)}function O(){if(!Y){if(t.reducedMotion||typeof requestAnimationFrame!="function"){le();return}Y=!0,N=requestAnimationFrame(U)}}function le(){let e=0;for(;!d.settled&&e<600;)d.tick(1),e++;B(),y=!0,C||(C=!0,P()),w()}function Q(e,i){let r=!1,c=g.size;for(let u of e){if(g.has(u.id))continue;r=!0;let f=c++,E={id:u.id,source:u,radius:a(u),x:Math.cos(f)*40,y:Math.sin(f)*40,vx:0,vy:0,g:document.createElementNS(k,"g"),circle:document.createElementNS(k,"circle")};ce(E),g.set(u.id,E)}let l=new Set(e.map(u=>u.id));for(let[u,f]of g)l.has(u)||(f.g.remove(),g.delete(u),r=!0);let h=new Set(i.map(u=>`${u.source}->${u.target}`));for(let u=v.length-1;u>=0;u--){let f=v[u];f&&!h.has(`${f.edge.source}->${f.edge.target}`)&&(f.line.remove(),f.hit?.remove(),v.splice(u,1),r=!0)}let F=new Set(v.map(u=>`${u.edge.source}->${u.edge.target}`));for(let u of i){let f=`${u.source}->${u.target}`;if(F.has(f))continue;let E=g.get(u.source),$=g.get(u.target);!E||!$||(r=!0,de(u,E,$))}r&&(d.setNodes([...g.values()]),d.setLinks(v.map(u=>({source:u.source.id,target:u.target.id}))),d.reheat(.9),C=!1,O())}function ce(e){let i=e.source;e.g.setAttribute("class",`gnode${i.cls?" "+i.cls:""}`),e.g.setAttribute("data-id",i.id),e.g.style.cursor="pointer";let r=document.createElementNS(k,"circle");if(r.setAttribute("class","gnode-glow"),r.setAttribute("r",e.radius+8),e.g.appendChild(r),e.circle.setAttribute("class","gnode-dot"),e.circle.setAttribute("r",e.radius),e.g.appendChild(e.circle),i.icon){let l=document.createElementNS(k,"text");l.setAttribute("class","gnode-icon"),l.setAttribute("y",e.radius*.34),l.setAttribute("text-anchor","middle"),l.setAttribute("font-size",e.radius*.95),l.textContent=i.icon,e.g.appendChild(l)}if(i.label){let l=document.createElementNS(k,"text");l.setAttribute("class","gnode-label"),l.setAttribute("y",e.radius+15),l.setAttribute("text-anchor","middle"),l.textContent=i.label,e.g.appendChild(l)}let c=document.createElementNS(k,"title");c.textContent=i.title??i.label??i.id,e.g.appendChild(c),ue(e),A.appendChild(e.g)}function de(e,i,r){let c=document.createElementNS(k,"line");if(c.setAttribute("class",`dm-edge${e.cls?" "+e.cls:""}`),c.setAttribute("stroke-width",1.6),c.setAttribute("opacity",.7),e.dash&&c.setAttribute("stroke-dasharray",e.dash),e.marker&&c.setAttribute("marker-end",`url(#dm-arrow-${e.marker})`),e.title){let h=document.createElementNS(k,"title");h.textContent=e.title,c.appendChild(h)}m.insertBefore(c,m.firstChild);let l=null;t.onEdge&&(l=document.createElementNS(k,"line"),l.setAttribute("class","dm-edge-hit"),l.setAttribute("stroke","transparent"),l.setAttribute("stroke-width",12),l.style.cursor="pointer",l.style.pointerEvents="stroke",l.addEventListener("pointerdown",h=>{h.stopPropagation()}),l.addEventListener("click",h=>{h.stopPropagation(),t.onEdge?.(e)}),m.appendChild(l)),v.push({edge:e,source:i,target:r,line:c,hit:l})}function ue(e){let i=!1,r=!1,c=0,l=0;e.g.addEventListener("pointerdown",h=>{h.stopPropagation(),i=!0,r=!1,c=h.clientX,l=h.clientY,e.fx=e.x,e.fy=e.y,d.reheat(Math.max(d.alpha,.3),.3),O(),oe(e.g,h.pointerId)}),e.g.addEventListener("pointermove",h=>{if(!i||!r&&Math.hypot(h.clientX-c,h.clientY-l)<4)return;r=!0;let F=me(h),u=(8-s.x)/s.k+e.radius,f=(X()-8-s.x)/s.k-e.radius,E=(8-s.y)/s.k+e.radius,$=(z()-8-s.y)/s.k-e.radius;e.fx=Math.min(Math.max(F.x,Math.min(u,f)),Math.max(u,f)),e.fy=Math.min(Math.max(F.y,Math.min(E,$)),Math.max(E,$))}),e.g.addEventListener("pointerup",h=>{i=!1,e.fx=null,e.fy=null,d.setAlphaTarget(0),ae(e.g,h.pointerId),r||t.onNode?.(e.source)})}let S=new Map,T=!1,W=0,_=0,G=0;n.addEventListener("pointerdown",e=>{e.target.closest("[data-id]")||(S.set(e.pointerId,{x:e.clientX,y:e.clientY}),oe(n,e.pointerId),S.size===1?(T=!0,W=e.clientX,_=e.clientY,n.style.cursor="grabbing"):S.size===2&&(T=!1,G=te()))}),n.addEventListener("pointermove",e=>{if(S.has(e.pointerId))if(S.set(e.pointerId,{x:e.clientX,y:e.clientY}),S.size>=2&&G){let i=te(),r=he(),c=n.getBoundingClientRect(),l=r.x-c.left,h=r.y-c.top;ee(l,h,s.k*(i/G)),G=i}else T&&(s.x+=e.clientX-W,s.y+=e.clientY-_,W=e.clientX,_=e.clientY,K(),j())});let Z=e=>{S.delete(e.pointerId),ae(n,e.pointerId),S.size<2&&(G=0),S.size===0&&(T=!1,n.style.cursor="grab")};n.addEventListener("pointerup",Z),n.addEventListener("pointercancel",Z),n.addEventListener("wheel",e=>{e.preventDefault();let i=n.getBoundingClientRect(),r=e.deltaY<0?1.1:1/1.1;ee(e.clientX-i.left,e.clientY-i.top,s.k*r)},{passive:!1});function ee(e,i,r){let c=Math.max(I,Math.min(xe,r));s.x=e-(e-s.x)*c/s.k,s.y=i-(i-s.y)*c/s.k,s.k=c,K(),j()}function te(){let e=[...S.values()],i=e[0],r=e[1];return!i||!r?0:Math.hypot(i.x-r.x,i.y-r.y)||1}function he(){let e=[...S.values()],i=e[0],r=e[1];return!i||!r?{x:0,y:0}:{x:(i.x+r.x)/2,y:(i.y+r.y)/2}}function me(e){let i=n.getBoundingClientRect();return{x:(e.clientX-i.left-s.x)/s.k,y:(e.clientY-i.top-s.y)/s.k}}function P(){V([...g.values()]),I=s.k}function V(e){if(!e.length){g.size&&y&&w();return}if(!p.clientWidth||!p.clientHeight){C=!1,typeof requestAnimationFrame=="function"&&(D=requestAnimationFrame(()=>{D=0,C||(C=!0,V(e))}));return}let i=1/0,r=1/0,c=-1/0,l=-1/0;for(let E of e)i=Math.min(i,E.x),r=Math.min(r,E.y),c=Math.max(c,E.x),l=Math.max(l,E.y);let h=90,F=Math.max(1,c-i)+h*2,u=Math.max(1,l-r)+h*2,f=Math.max(re,Math.min(1.4,Math.min(X()/F,z()/u)));s.k=f,s.x=X()/2-(i+c)/2*f,s.y=z()/2-(r+l)/2*f,j(),y&&w()}function ge(e){let i=e?.length?new Set(e):null;for(let r of g.values()){let c=i?.has(r.id)??!1,l=i===null||c;r.g.style.opacity=l?"1":"0.1",r.circle.setAttribute("class",c?"gnode-dot gnode-hot":"gnode-dot")}for(let r of v){let c=i===null||i.has(r.source.id)||i.has(r.target.id);r.line.setAttribute("opacity",c?.7:.06)}if(i!==null){let r=[...g.values()].filter(c=>i.has(c.id));V(r)}}function pe(e){if(H){let i=g.get(H);i?.g.setAttribute("class",`gnode${i.source.cls?" "+i.source.cls:""}`)}if(H=e,e){let i=g.get(e);i?.g.setAttribute("class",`gnode active${i.source.cls?" "+i.source.cls:""}`)}}function ie(){Y=!1,typeof cancelAnimationFrame=="function"&&(N&&cancelAnimationFrame(N),D&&cancelAnimationFrame(D)),N=0,D=0,M&&(M.disconnect(),M=null)}function fe(e=1){d.tick(e),B()}function be(){d.reheat(.7),O()}return j(),t.nodes?.length&&Q(t.nodes,t.edges??[]),t.autostart===!1&&ie(),{setData:Q,setHighlight:ge,setSelected:pe,reheat:be,step:fe,stop:ie}}function ke(){let p=document.createElementNS(k,"defs");for(let t of["fk","m2m"]){let a=document.createElementNS(k,"marker");a.setAttribute("id",`dm-arrow-${t}`),a.setAttribute("viewBox","0 0 10 10"),a.setAttribute("refX","9"),a.setAttribute("refY","5"),a.setAttribute("markerWidth","7"),a.setAttribute("markerHeight","7"),a.setAttribute("orient","auto-start-reverse");let d=document.createElementNS(k,"path");d.setAttribute("d","M0,0 L10,5 L0,10 z"),d.setAttribute("class",`dm-arrow-${t}`),a.appendChild(d),p.appendChild(a)}return p}function oe(p,t){try{p.setPointerCapture(t)}catch{}}function ae(p,t){try{p.releasePointerCapture(t)}catch{}}export{se as clampAxis,Ne as createForceGraph};