@infinit-canvas/react 0.1.25 → 0.1.27
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/dist/react-infinite-canvas.cjs +2 -2
- package/dist/react-infinite-canvas.js +2275 -2236
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("react/jsx-runtime"),a=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("react/jsx-runtime"),a=require("react"),mr=require("react-dom"),vr=160,br=60;function Or(e){return e&&typeof e=="object"&&"position"in e&&"data"in e}function Ur(e){return e&&typeof e=="object"&&"source"in e&&"target"in e}function wr(e,t){const n=typeof e=="string"?new Set([e]):new Set(Array.isArray(e)?e.map(r=>r.id):[e.id]);return t.filter(r=>n.has(r.source)||n.has(r.target))}function qr(e,t,n){const r=typeof e=="string"?e:e.id,i=new Set;for(const o of n)o.target===r&&i.add(o.source);return t.filter(o=>i.has(o.id))}function Zr(e,t,n){const r=typeof e=="string"?e:e.id,i=new Set;for(const o of n)o.source===r&&i.add(o.target);return t.filter(o=>i.has(o.id))}function Mn(e){if(!e.length)return{x:0,y:0,width:0,height:0};let t=1/0,n=1/0,r=-1/0,i=-1/0;for(const o of e){const c=o.position.x,h=o.position.y,m=o.width||vr,f=o.height||br;c<t&&(t=c),h<n&&(n=h),c+m>r&&(r=c+m),h+f>i&&(i=h+f)}return{x:t,y:n,width:r-t,height:i-n}}function Ut(e,t,n,r=.1){const i=e.width*(1+r*2),o=e.height*(1+r*2),c=Math.min(t/i,n/o,1),h=e.x+e.width/2,m=e.y+e.height/2;return{x:t/2-h*c,y:n/2-m*c,zoom:c}}function Gn(e,t){return{x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}}function Qn(e,t){return{x:Math.min(Math.max(e.x,t[0][0]),t[1][0]),y:Math.min(Math.max(e.y,t[0][1]),t[1][1])}}function er(e){var t,n;return{width:e.width||((t=e.measured)==null?void 0:t.width)||vr,height:e.height||((n=e.measured)==null?void 0:n.height)||br}}function Gr(e,t,n={x:0,y:0,zoom:1},r=!1){const i=t.x,o=t.y,c=t.x+t.width,h=t.y+t.height;return e.filter(m=>{const{width:f,height:y}=er(m),x=m.position.x,k=m.position.y,S=x+f,z=k+y;return r?x<c&&S>i&&k<h&&z>o:x>=i&&S<=c&&k>=o&&z<=h})}function Qr(e){return{x:e.x,y:e.y,x2:e.x+e.width,y2:e.y+e.height}}function Jr(e){return{x:e.x,y:e.y,width:e.x2-e.x,height:e.y2-e.y}}function Vr(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}}function Kr(e,t){const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return n*r}function eo(e){const{width:t,height:n}=er(e);return{x:e.position.x,y:e.position.y,width:t,height:n}}const Mr=`var qa = null, r = null, fr = 0, vr = 0, M = { x: 0, y: 0, zoom: 1 }, Y = [], W = [], C = [], F = !1, Ze = 40, We = !1, Nr = "lines", da = 1, Kt = null, lt = null, Tr = null, It = {}, tl = {}, it = {}, Zt = {}, Ia = 0, L = 160, B = 60, Ga = 8, Do = 5;
|
|
2
2
|
function y(a) {
|
|
3
3
|
return a._absolutePosition || a.position;
|
|
4
4
|
}
|
|
@@ -943,4 +943,4 @@ function Ft() {
|
|
|
943
943
|
}
|
|
944
944
|
}
|
|
945
945
|
}
|
|
946
|
-
`,lr=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",wr],{type:"text/javascript;charset=utf-8"});function eo(e){let t;try{if(t=lr&&(self.URL||self.webkitURL).createObjectURL(lr),!t)throw"";const n=new Worker(t,{type:"module",name:e==null?void 0:e.name});return n.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),n}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(wr),{type:"module",name:e==null?void 0:e.name})}}const Xn=new WeakMap;function to(e,t){if(Xn.has(e))return Xn.get(e);const n=e.transferControlToOffscreen(),r=new eo;r.onerror=o=>console.error("[infinite-canvas] worker error:",o.message,o),r.postMessage({type:"init",data:{...t,canvas:n}},[n]);const i={worker:r};return Xn.set(e,i),i}const ut=160,et=60,no=10;function Mr({cards:e=[],nodes:t=[],edges:n=[],onHudUpdate:r,onNodesProcessed:i,onNodesChange:o,onEdgesChange:c,onConnect:f,onNodeClick:v,onNodeDragStart:d,onNodeDrag:h,onNodeDragStop:w,onEdgeClick:C,onEdgeDoubleClick:E,onEdgeMouseEnter:z,onEdgeMouseMove:W,onEdgeMouseLeave:A,onEdgeContextMenu:B,onNodeDoubleClick:F,onNodeMouseEnter:H,onNodeMouseMove:Y,onNodeMouseLeave:$,onNodeContextMenu:N,onPaneClick:q,onPaneContextMenu:O,onPaneMouseEnter:X,onPaneMouseMove:m,onPaneMouseLeave:g,onSelectionChange:b,onConnectStart:L,onConnectEnd:P,onInit:j,onMoveStart:G,onMove:ie,onMoveEnd:ee,onDelete:le,onBeforeDelete:xe,onError:Me,isValidConnection:we,dark:ne,gridSize:Ce=40,zoomMin:se=.1,zoomMax:de=4,initialCamera:ze={x:0,y:0,zoom:1},fitView:_e=!1,fitViewOptions:ye,nodesDraggable:he=!0,nodesConnectable:Be=!0,elementsSelectable:We=!0,multiSelectionKeyCode:Fe="Shift",selectionOnDrag:je=!1,selectionMode:tt="partial",connectionMode:Le="loose",connectionRadius:ve=20,connectOnClick:De=!1,snapToGrid:nt=!1,snapGrid:$e=[15,15],deleteKeyCode:qe=["Delete","Backspace"],panActivationKeyCode:Ze=" ",panOnScroll:an=!1,panOnScrollMode:Ct="free",panOnScrollSpeed:cn=.5,zoomOnScroll:ln=!0,zoomOnDoubleClick:un=!0,zoomOnPinch:dn=!0,preventScrolling:Xt=!0,translateExtent:gt,nodeExtent:yt,defaultEdgeOptions:Et={},autoPanOnNodeDrag:Nn=!0,autoPanOnConnect:In=!0,autoPanSpeed:rt=5,edgesReconnectable:cr=!1,elevateNodesOnSelect:Tn=!1,elevateEdgesOnSelect:Ln=!1,noDragClassName:St="nodrag",noPanClassName:zt="nopan",onSelectionDragStart:Bn,onSelectionDrag:$n,onSelectionDragStop:jn,edgeRouting:wt=!0}={}){const be=a.useRef(null),Pt=a.useRef(null),Pe=a.useRef(null),fe=a.useRef({...ze}),xt=a.useRef([...e]),te=a.useRef([...t]),Ne=a.useRef([...n]),fn=a.useRef(new Map),Nt=a.useRef(!1),It=a.useRef(null),[Tt,An]=a.useState(!1),Ye=a.useRef(null),Oe=a.useRef(null),Lt=a.useRef(null),ot=a.useRef(null),hn=a.useRef(!1),Ve=a.useRef(null),[gn,yn]=a.useState({x:ze.x,y:ze.y,zoom:ze.zoom}),[Ot,xn]=a.useState(null),pt=a.useMemo(()=>new Set,[]),st=a.useMemo(()=>new Set,[]),Ke=a.useRef(!1),V=a.useRef({});V.current={onHudUpdate:r,onNodesProcessed:i,onNodesChange:o,onEdgesChange:c,onConnect:f,onNodeClick:v,onNodeDragStart:d,onNodeDrag:h,onNodeDragStop:w,onEdgeClick:C,onEdgeDoubleClick:E,onEdgeMouseEnter:z,onEdgeMouseMove:W,onEdgeMouseLeave:A,onEdgeContextMenu:B,onNodeDoubleClick:F,onNodeMouseEnter:H,onNodeMouseMove:Y,onNodeMouseLeave:$,onNodeContextMenu:N,onPaneClick:q,onPaneContextMenu:O,onPaneMouseEnter:X,onPaneMouseMove:m,onPaneMouseLeave:g,onSelectionChange:b,onConnectStart:L,onConnectEnd:P,onInit:j,onMoveStart:G,onMove:ie,onMoveEnd:ee,onDelete:le,onBeforeDelete:xe,onError:Me,onSelectionDragStart:Bn,onSelectionDrag:$n,onSelectionDragStop:jn,isValidConnection:we};const it={get current(){return V.current.onConnect}},Mt={get current(){return V.current.onNodeClick}},Bt={get current(){return V.current.onNodeDragStart}},$t={get current(){return V.current.onNodeDrag}},jt={get current(){return V.current.onNodeDragStop}},mt={get current(){return V.current.onEdgeClick}},At={get current(){return V.current.onPaneClick}},Dt={get current(){return V.current.onSelectionChange}},Ht={get current(){return V.current.onHudUpdate}},_t={get current(){return V.current.onNodesProcessed}};a.useEffect(()=>{const u=l=>{l.key===Fe&&(hn.current=!0),l.key===Ze&&(Ke.current=!0)},y=l=>{l.key===Fe&&(hn.current=!1),l.key===Ze&&(Ke.current=!1)};return window.addEventListener("keydown",u),window.addEventListener("keyup",y),()=>{window.removeEventListener("keydown",u),window.removeEventListener("keyup",y)}},[Fe,Ze]);const Ee={get current(){return V.current.onNodesChange?dt:null}},dt=u=>{var l,p,k;(p=(l=V.current).onNodesChange)==null||p.call(l,u);const y=[];for(let S=0;S<u.length;S++)u[S].type==="select"&&y.push({id:u[S].id,selected:u[S].selected});y.length>0&&((k=Pe.current)==null||k.postMessage({type:"nodeSelections",data:{selections:y}}))},He={get current(){return V.current.onEdgesChange?Dn:null}},Dn=u=>{var l,p,k;(p=(l=V.current).onEdgesChange)==null||p.call(l,u);const y=[];for(let S=0;S<u.length;S++)u[S].type==="select"&&y.push({id:u[S].id,selected:u[S].selected});y.length>0&&((k=Pe.current)==null||k.postMessage({type:"edgeSelections",data:{selections:y}}))},ft=a.useCallback(()=>{var p;const u=te.current.filter(k=>k.selected),y=Ne.current.filter(k=>k.selected),l={nodes:u,edges:y};(p=Dt.current)==null||p.call(Dt,l);for(const k of st)k(l)},[st]);a.useEffect(()=>{var u;xt.current=[...e],(u=Pe.current)==null||u.postMessage({type:"cards",data:{cards:[...e]}})},[e]);const Wt=a.useCallback(u=>{const y={};for(const l of u)y[l.id]=l;return u.map(l=>{if(!l.parentId)return l;const p=y[l.parentId];if(!p)return l;let k=l.position.x,S=l.position.y,x=p;for(;x;)k+=x.position.x,S+=x.position.y,x=x.parentId?y[x.parentId]:null;return{...l,_absolutePosition:{x:k,y:S}}})},[]),at=a.useRef([]),vt=a.useCallback(u=>{const y=fn.current;if(!y||y.size===0)return u;const l={};for(const[,p]of y)l[p.nodeId]||(l[p.nodeId]=[]),l[p.nodeId].push({id:p.id,type:p.type,position:p.position,x:p.x,y:p.y});return u.map(p=>{const k=l[p.id];return k&&k.length>0?{...p,handles:k}:p})},[]),pn=a.useCallback(()=>{var y;if(Ye.current)return;const u=vt(at.current);(y=Pe.current)==null||y.postMessage({type:"nodes",data:{nodes:u}})},[vt]);a.useEffect(()=>{var l,p;if(Ye.current){const k=Ye.current.id,S=new Set([k,...Ye.current.selectedStarts.map(R=>R.id)]),x={};for(const R of te.current)S.has(R.id)&&(x[R.id]={...R.position});te.current=[...t];for(const R of te.current)x[R.id]&&(R.position=x[R.id]);at.current=Wt(te.current);const M=vt(at.current);(l=Pe.current)==null||l.postMessage({type:"nodes",data:{nodes:M}});return}te.current=[...t];const u=Wt(t);at.current=u;const y=vt(u);(p=Pe.current)==null||p.postMessage({type:"nodes",data:{nodes:y}})},[t,Wt,vt]),a.useEffect(()=>{var u;Ne.current=[...n],(u=Pe.current)==null||u.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const Te=a.useCallback((u,y)=>{const l=be.current;if(!l)return{x:0,y:0};const p=l.getBoundingClientRect(),k=fe.current;return{x:(u-p.left-k.x)/k.zoom,y:(y-p.top-k.y)/k.zoom}},[]),ue=a.useCallback((u,y)=>{const l=at.current.length>0?at.current:te.current;let p=null;for(let k=l.length-1;k>=0;k--){const S=l[k];if(S.hidden||S._customRendered)continue;const x=S._absolutePosition||S.position,M=S.width||ut,R=S.height||et;if(u>=x.x&&u<=x.x+M&&y>=x.y&&y<=x.y+R){if(S.type==="group"){p||(p=S);continue}return S}}return p},[]),Ut=a.useCallback((u,y)=>{const l=y.width||ut,p=y.height||et;if(u.x!==void 0&&u.y!==void 0)return{x:y.position.x+u.x,y:y.position.y+u.y};switch(u.position||(u.type==="source"?"right":"left")){case"top":return{x:y.position.x+l/2,y:y.position.y};case"bottom":return{x:y.position.x+l/2,y:y.position.y+p};case"left":return{x:y.position.x,y:y.position.y+p/2};case"right":return{x:y.position.x+l,y:y.position.y+p/2};default:return{x:y.position.x+l,y:y.position.y+p/2}}},[]),qt=a.useCallback(u=>{const y=u.width||ut,l=u.height||et;if(u.handles&&u.handles.length>0)return u.handles.map(R=>{const D=Ut(R,u);return{id:R.id||null,type:R.type,x:D.x,y:D.y}});const p=u.targetPosition||"left",k=u.sourcePosition||"right",S=R=>{switch(R){case"top":return{x:u.position.x+y/2,y:u.position.y};case"bottom":return{x:u.position.x+y/2,y:u.position.y+l};case"left":return{x:u.position.x,y:u.position.y+l/2};case"right":return{x:u.position.x+y,y:u.position.y+l/2};default:return{x:u.position.x+y,y:u.position.y+l/2}}},x=S(p),M=S(k);return[{id:null,type:"target",x:x.x,y:x.y},{id:null,type:"source",x:M.x,y:M.y}]},[Ut]),bt=a.useCallback((u,y)=>{const l=te.current,p=fe.current,k=Math.max(no,ve)/p.zoom;for(let S=l.length-1;S>=0;S--){const x=l[S];if(x.hidden)continue;const M=qt(x);for(const R of M)if(Math.abs(u-R.x)<k&&Math.abs(y-R.y)<k)return{nodeId:x.id,handleId:R.id,type:R.type,x:R.x,y:R.y}}return null},[qt]),Ge=a.useCallback((u,y)=>{const p=8/fe.current.zoom,k=te.current,S={};for(let x=0;x<k.length;x++)S[k[x].id]=k[x];for(let x=Ne.current.length-1;x>=0;x--){const M=Ne.current[x],R=S[M.source],D=S[M.target];if(!R||!D)continue;const T=R.width||ut,U=R.height||et,Q=D.height||et,Z=R.position.x+T,ae=R.position.y+U/2,K=D.position.x,ce=D.position.y+Q/2;if(ro(u,y,Z,ae,K,ce)<p)return M}return null},[]);a.useEffect(()=>{const u=Pt.current,y=be.current;if(!u||!y)return;const l=y.getBoundingClientRect(),p=ne!==void 0?ne:matchMedia("(prefers-color-scheme: dark)").matches,k=Wt(te.current);at.current=k;const S=vt(k),{worker:x}=to(u,{width:l.width,height:l.height,camera:fe.current,cards:xt.current,nodes:S,edges:Ne.current,dark:p,gridSize:Ce,edgeRouting:wt});x.onmessage=T=>{var U,Q,Z,ae;T.data.type==="hud"&&((U=Ht.current)==null||U.call(Ht,T.data.data)),T.data.type==="ready"&&An(!0),T.data.type==="nodesProcessed"&&((Q=_t.current)==null||Q.call(_t,T.data.data)),T.data.type==="error"&&((ae=(Z=V.current).onError)==null||ae.call(Z,"worker-error",T.data.message||"Canvas worker error"))},x.onerror=T=>{var U,Q;(Q=(U=V.current).onError)==null||Q.call(U,"worker-error",T.message||"Canvas worker crashed")},Pe.current=x;const M=new ResizeObserver(T=>{const{width:U,height:Q}=T[0].contentRect;x.postMessage({type:"resize",data:{width:U,height:Q}})});M.observe(y);let R,D;return ne===void 0&&(R=matchMedia("(prefers-color-scheme: dark)"),D=T=>x.postMessage({type:"theme",data:{dark:T.matches}}),R.addEventListener("change",D)),()=>{M.disconnect(),R&&D&&R.removeEventListener("change",D),Pe.current=null}},[]),a.useEffect(()=>{var u;ne!==void 0&&((u=Pe.current)==null||u.postMessage({type:"theme",data:{dark:ne}}))},[ne]),a.useEffect(()=>{var u;(u=Pe.current)==null||u.postMessage({type:"edgeRouting",data:{enabled:wt}})},[wt]);const Zt=a.useRef(0),Re=a.useCallback((u=null)=>{var p,k,S;const y=fe.current;if(gt){const x=be.current;if(x){const M=x.getBoundingClientRect(),R=-gt[1][0]*y.zoom+M.width,D=-gt[1][1]*y.zoom+M.height,T=-gt[0][0]*y.zoom,U=-gt[0][1]*y.zoom;y.x=Math.min(T,Math.max(R,y.x)),y.y=Math.min(U,Math.max(D,y.y))}}(p=Pe.current)==null||p.postMessage({type:"camera",data:{camera:{...y}}});const l={x:y.x,y:y.y,zoom:y.zoom};(S=(k=V.current).onMove)==null||S.call(k,u,l);for(const x of pt)x(l);cancelAnimationFrame(Zt.current),Zt.current=requestAnimationFrame(()=>{yn({x:y.x,y:y.y,zoom:y.zoom})})},[pt,gt]),ct=a.useCallback(()=>{var l,p;const u=Oe.current,y=Lt.current;u&&y?((l=Pe.current)==null||l.postMessage({type:"connecting",data:{from:u.startPos,to:y,_routedPoints:null}}),xn({source:u.sourceId,sourceHandle:u.sourceHandle,target:null,targetHandle:null})):((p=Pe.current)==null||p.postMessage({type:"connecting",data:null}),xn(null))},[]),lt=a.useCallback(()=>{var y,l;const u=ot.current;u?(y=Pe.current)==null||y.postMessage({type:"selectionBox",data:u}):(l=Pe.current)==null||l.postMessage({type:"selectionBox",data:null})},[]),Gt=a.useCallback(u=>{var x,M,R,D,T,U,Q,Z,ae,K,ce,ke,Ae,Xe,Qe,Ue,Jt,ht;const y=te.current.length>0,l=Te(u.clientX,u.clientY),p=hn.current;if(y&&Be&&!p){const J=bt(l.x,l.y);if(De&&Ve.current&&J){const oe=Ve.current;if(J.nodeId!==oe.nodeId){const Je=oe.handleType==="target"?{source:J.nodeId,target:oe.nodeId,sourceHandle:J.handleId||null,targetHandle:oe.handleId}:{source:oe.nodeId,target:J.nodeId,sourceHandle:oe.handleId,targetHandle:J.handleId||null};(V.current.isValidConnection?V.current.isValidConnection(Je):!0)&&((x=it.current)==null||x.call(it,{...Je,...Et}))}Ve.current=null;return}if(Le==="strict"?J&&J.type==="source":J!=null){if(De){Ve.current={nodeId:J.nodeId,handleId:J.handleId||null,handleType:J.type},(R=(M=V.current).onConnectStart)==null||R.call(M,u,{nodeId:J.nodeId,handleId:J.handleId,handleType:J.type});return}Oe.current={sourceId:J.nodeId,sourceHandle:J.handleId||null,sourceType:J.type,startPos:{x:J.x,y:J.y}},Lt.current={x:l.x,y:l.y},(D=be.current)==null||D.setPointerCapture(u.pointerId),(U=(T=V.current).onConnectStart)==null||U.call(T,u,{nodeId:J.nodeId,handleId:J.handleId,handleType:J.type}),ct();return}}const k=J=>{var oe;let me=J;for(;me&&me!==be.current;){if((oe=me.classList)!=null&&oe.contains(St))return!0;me=me.parentElement}return!1},S=J=>{var oe;let me=J;for(;me&&me!==be.current;){if((oe=me.classList)!=null&&oe.contains(zt))return!0;me=me.parentElement}return!1};if(y){const J=ue(l.x,l.y);if(J){if(Ee.current&&We){const me=[];if(p)me.push({id:J.id,type:"select",selected:!J.selected});else if(!J.selected){for(const oe of te.current)oe.id===J.id?me.push({id:oe.id,type:"select",selected:!0}):oe.selected&&me.push({id:oe.id,type:"select",selected:!1});if(He.current){const oe=Ne.current.filter(ge=>ge.selected).map(ge=>({id:ge.id,type:"select",selected:!1}));oe.length&&He.current(oe)}}if(me.length){if(Ee.current(me),Tn&&!p){const oe=te.current.findIndex(ge=>ge.id===J.id);oe>=0&&oe<te.current.length-1&&Ee.current([{id:J.id,type:"remove"},{type:"add",item:{...te.current[oe],selected:!0}}])}ft()}}if((Q=Mt.current)==null||Q.call(Mt,u,J),he&&!k(u.target)){const me=J.selected;let oe=null;if(J.parentId&&J.extent==="parent"){const ge=te.current.find(Je=>Je.id===J.parentId);if(ge){const Je=ge.width||ut,Vt=ge.height||et,vn=J.width||((Z=J.measured)==null?void 0:Z.width)||ut,Kt=J.height||((ae=J.measured)==null?void 0:ae.height)||et;oe={minX:0,minY:0,maxX:Je-vn,maxY:Vt-Kt}}}if(Ye.current={id:J.id,startPos:{...J.position},startMouse:{x:l.x,y:l.y},parentClamp:oe,parentId:J.parentId||null,selectedStarts:me?te.current.filter(ge=>ge.selected&&ge.id!==J.id).map(ge=>{var Vt,vn;let Je=null;if(ge.parentId&&ge.extent==="parent"){const Kt=te.current.find(Yn=>Yn.id===ge.parentId);if(Kt){const Yn=Kt.width||ut,Wr=Kt.height||et,Fr=ge.width||((Vt=ge.measured)==null?void 0:Vt.width)||ut,Yr=ge.height||((vn=ge.measured)==null?void 0:vn.height)||et;Je={minX:0,minY:0,maxX:Yn-Fr,maxY:Wr-Yr}}}return{id:ge.id,startPos:{...ge.position},parentClamp:Je,parentId:ge.parentId||null}}):[]},(K=be.current)==null||K.setPointerCapture(u.pointerId),(ce=Bt.current)==null||ce.call(Bt,u,J),Ye.current.selectedStarts.length>0){const ge=te.current.filter(Je=>Je.selected);(Ae=(ke=V.current).onSelectionDragStart)==null||Ae.call(ke,u,ge)}if(Ee.current){const ge=[{id:J.id,type:"position",dragging:!0}];for(const Je of Ye.current.selectedStarts)ge.push({id:Je.id,type:"position",dragging:!0});Ee.current(ge)}}return}}if(Ne.current.length>0&&We){const J=Ge(l.x,l.y);if(J){if(He.current){const me=[];if(p)me.push({id:J.id,type:"select",selected:!J.selected});else{for(const oe of Ne.current)oe.id===J.id?me.push({id:oe.id,type:"select",selected:!0}):oe.selected&&me.push({id:oe.id,type:"select",selected:!1});if(Ee.current){const oe=te.current.filter(ge=>ge.selected).map(ge=>({id:ge.id,type:"select",selected:!1}));oe.length&&Ee.current(oe)}}if(me.length){if(He.current(me),Ln&&!p){const oe=Ne.current.findIndex(ge=>ge.id===J.id);oe>=0&&oe<Ne.current.length-1&&He.current([{id:J.id,type:"remove"},{type:"add",item:{...Ne.current[oe],selected:!0}}])}ft()}}(Xe=mt.current)==null||Xe.call(mt,u,J);return}}if(!p){const J=te.current.filter(oe=>oe.selected).map(oe=>({id:oe.id,type:"select",selected:!1})),me=Ne.current.filter(oe=>oe.selected).map(oe=>({id:oe.id,type:"select",selected:!1}));J.length&&Ee.current&&Ee.current(J),me.length&&He.current&&He.current(me),(J.length||me.length)&&ft()}if((Qe=At.current)==null||Qe.call(At,u),je||p){ot.current={startWorld:{...l},endWorld:{...l}},(Ue=be.current)==null||Ue.setPointerCapture(u.pointerId),lt();return}S(u.target)||(Nt.current=!0,It.current={x:u.clientX,y:u.clientY},(Jt=be.current)==null||Jt.classList.add("dragging"),(ht=be.current)==null||ht.setPointerCapture(u.pointerId))},[Te,ue,bt,Ge,he,Be,We,je,ct,lt,ft,St,zt]),Qt=a.useCallback(u=>{var l,p,k,S;if(Oe.current){if(Lt.current=Te(u.clientX,u.clientY),ct(),In){const x=be.current;if(x){const M=x.getBoundingClientRect(),R=40,D=u.clientX-M.left,T=u.clientY-M.top;let U=0,Q=0;D<R?U=rt:D>M.width-R&&(U=-rt),T<R?Q=rt:T>M.height-R&&(Q=-rt),(U||Q)&&(fe.current.x+=U,fe.current.y+=Q,Re(u))}}return}if(ot.current){ot.current.endWorld=Te(u.clientX,u.clientY),lt();const x=ot.current,M=Math.min(x.startWorld.x,x.endWorld.x),R=Math.min(x.startWorld.y,x.endWorld.y),D=Math.max(x.startWorld.x,x.endWorld.x),T=Math.max(x.startWorld.y,x.endWorld.y);if(Ee.current){const U=[];for(const Q of te.current){if(Q.hidden)continue;const Z=Q.width||ut,ae=Q.height||et,K=tt==="full"?Q.position.x>=M&&Q.position.x+Z<=D&&Q.position.y>=R&&Q.position.y+ae<=T:Q.position.x+Z>M&&Q.position.x<D&&Q.position.y+ae>R&&Q.position.y<T;K!==!!Q.selected&&U.push({id:Q.id,type:"select",selected:K})}U.length&&Ee.current(U)}return}if(Ye.current){const x=Te(u.clientX,u.clientY),M=Ye.current,R=x.x-M.startMouse.x,D=x.y-M.startMouse.y;let T={x:M.startPos.x+R,y:M.startPos.y+D};if(nt&&(T=Zn(T,$e)),yt&&(T=Gn(T,yt)),M.parentClamp){const K=M.parentClamp;T={x:Math.max(K.minX,Math.min(T.x,K.maxX)),y:Math.max(K.minY,Math.min(T.y,K.maxY))}}const U=[{id:M.id,position:T}];for(const K of M.selectedStarts){let ce={x:K.startPos.x+R,y:K.startPos.y+D};if(nt&&(ce=Zn(ce,$e)),yt&&(ce=Gn(ce,yt)),K.parentClamp){const ke=K.parentClamp;ce={x:Math.max(ke.minX,Math.min(ce.x,ke.maxX)),y:Math.max(ke.minY,Math.min(ce.y,ke.maxY))}}U.push({id:K.id,position:ce})}const Q=[];for(const K of U){const ce=te.current.find(ke=>ke.id===K.id);if(ce){ce.position=K.position,ce.dragging=!0;let ke=K.position;if(ce.parentId){let Ae=te.current.find(Ue=>Ue.id===ce.parentId),Xe=K.position.x,Qe=K.position.y;for(;Ae;)Xe+=Ae.position.x,Qe+=Ae.position.y,Ae=Ae.parentId?te.current.find(Ue=>Ue.id===Ae.parentId):null;ke={x:Xe,y:Qe}}Q.push({id:K.id,position:K.position,_absolutePosition:ke,width:ce.width,height:ce.height,dragging:!0,selected:ce.selected})}}const Z=new Set(U.map(K=>K.id));for(const K of te.current)if(K.parentId&&Z.has(K.parentId)&&!Z.has(K.id)){let ce=te.current.find(Xe=>Xe.id===K.parentId),ke=K.position.x,Ae=K.position.y;for(;ce;)ke+=ce.position.x,Ae+=ce.position.y,ce=ce.parentId?te.current.find(Xe=>Xe.id===ce.parentId):null;Q.push({id:K.id,position:K.position,_absolutePosition:{x:ke,y:Ae},width:K.width,height:K.height,dragging:!1,selected:K.selected})}if((l=Pe.current)==null||l.postMessage({type:"nodePositions",data:{updates:Q}}),Nn){const K=be.current;if(K){const ce=K.getBoundingClientRect(),ke=40,Ae=u.clientX-ce.left,Xe=u.clientY-ce.top;let Qe=0,Ue=0;Ae<ke?Qe=rt:Ae>ce.width-ke&&(Qe=-rt),Xe<ke?Ue=rt:Xe>ce.height-ke&&(Ue=-rt),(Qe||Ue)&&(fe.current.x+=Qe,fe.current.y+=Ue,Re(u))}}const ae=te.current.find(K=>K.id===M.id);if(ae&&((p=$t.current)==null||p.call($t,u,ae)),M.selectedStarts.length>0){const K=te.current.filter(ce=>ce.selected);(S=(k=V.current).onSelectionDrag)==null||S.call(k,u,K)}return}if(!Nt.current)return;const y=fe.current;y.x+=u.clientX-It.current.x,y.y+=u.clientY-It.current.y,It.current={x:u.clientX,y:u.clientY},Re()},[Re,Te,ct,lt]),mn=a.useCallback(u=>{var y,l,p,k,S,x,M,R;if(Oe.current){const D=Te(u.clientX,u.clientY),T=bt(D.x,D.y);if(T&&T.nodeId!==Oe.current.sourceId&&(Le==="loose"||T.type==="target")){const Z=Oe.current.sourceType==="target"?{source:T.nodeId,target:Oe.current.sourceId,sourceHandle:T.handleId||null,targetHandle:Oe.current.sourceHandle}:{source:Oe.current.sourceId,target:T.nodeId,sourceHandle:Oe.current.sourceHandle,targetHandle:T.handleId||null};(V.current.isValidConnection?V.current.isValidConnection(Z):!0)&&((y=it.current)==null||y.call(it,{...Z,...Et}))}(p=(l=V.current).onConnectEnd)==null||p.call(l,u.nativeEvent||u),Oe.current=null,Lt.current=null,ct();return}if(ot.current){ot.current=null,lt(),ft();return}if(Ye.current){const D=Ye.current,T=te.current.find(Z=>Z.id===D.id),U=[{id:D.id,position:T?{...T.position}:D.startPos,_absolutePosition:T?{...T.position}:D.startPos,dragging:!1}];for(const Z of D.selectedStarts){const ae=te.current.find(K=>K.id===Z.id);U.push({id:Z.id,position:ae?{...ae.position}:Z.startPos,_absolutePosition:ae?{...ae.position}:Z.startPos,dragging:!1})}if((k=Pe.current)==null||k.postMessage({type:"nodePositions",data:{updates:U}}),Ee.current){const Z=U.map(ae=>({id:ae.id,type:"position",position:ae.position,dragging:!1}));Ee.current(Z)}if(D.selectedStarts.length>0){const Z=te.current.filter(ae=>ae.selected);(x=(S=V.current).onSelectionDragStop)==null||x.call(S,u,Z)}requestAnimationFrame(()=>{Ye.current=null});const Q=te.current.find(Z=>Z.id===D.id);Q&&((M=jt.current)==null||M.call(jt,u,Q));return}Nt.current=!1,(R=be.current)==null||R.classList.remove("dragging")},[Te,bt,ct,lt,ft]);a.useEffect(()=>{const u=be.current;if(!u)return;const y=l=>{Xt&&l.preventDefault();const p=fe.current;if(an||Ke.current){const R=cn;Ct==="horizontal"?p.x-=l.deltaY*R:(Ct==="vertical"||(p.x-=l.deltaX*R),p.y-=l.deltaY*R),Re(l);return}if(!ln)return;const k=l.deltaY>0?.92:1.08,S=u.getBoundingClientRect(),x=l.clientX-S.left,M=l.clientY-S.top;p.x=x-(x-p.x)*k,p.y=M-(M-p.y)*k,p.zoom=Math.min(de,Math.max(se,p.zoom*k)),Re(l)};return u.addEventListener("wheel",y,{passive:!Xt}),()=>u.removeEventListener("wheel",y)},[Re,se,de,an,Ct,cn,ln,Xt]),a.useEffect(()=>{if(!dn)return;const u=be.current;if(!u)return;let y=0,l=null;const p=x=>{if(x.touches.length===2){const M=x.touches[0].clientX-x.touches[1].clientX,R=x.touches[0].clientY-x.touches[1].clientY;y=Math.hypot(M,R);const D=u.getBoundingClientRect();l={x:(x.touches[0].clientX+x.touches[1].clientX)/2-D.left,y:(x.touches[0].clientY+x.touches[1].clientY)/2-D.top},x.preventDefault()}},k=x=>{if(x.touches.length===2&&y>0){x.preventDefault();const M=x.touches[0].clientX-x.touches[1].clientX,R=x.touches[0].clientY-x.touches[1].clientY,D=Math.hypot(M,R),T=D/y;y=D;const U=fe.current,Q=l.x,Z=l.y;U.x=Q-(Q-U.x)*T,U.y=Z-(Z-U.y)*T,U.zoom=Math.min(de,Math.max(se,U.zoom*T)),Re(x)}},S=()=>{y=0,l=null};return u.addEventListener("touchstart",p,{passive:!1}),u.addEventListener("touchmove",k,{passive:!1}),u.addEventListener("touchend",S),()=>{u.removeEventListener("touchstart",p),u.removeEventListener("touchmove",k),u.removeEventListener("touchend",S)}},[dn,Re,se,de]),a.useEffect(()=>{if(!un)return;const u=be.current;if(!u)return;const y=l=>{var T,U,Q,Z;const p=Te(l.clientX,l.clientY);if(ue(p.x,p.y)){(U=(T=V.current).onNodeDoubleClick)==null||U.call(T,l,ue(p.x,p.y));return}const k=Ge(p.x,p.y);if(k){(Z=(Q=V.current).onEdgeDoubleClick)==null||Z.call(Q,l,k);return}const S=1.5,x=u.getBoundingClientRect(),M=l.clientX-x.left,R=l.clientY-x.top,D=fe.current;D.x=M-(M-D.x)*S,D.y=R-(R-D.y)*S,D.zoom=Math.min(de,Math.max(se,D.zoom*S)),Re(l)};return u.addEventListener("dblclick",y),()=>u.removeEventListener("dblclick",y)},[un,Re,se,de,Te,ue,Ge]),a.useEffect(()=>{const u=be.current;if(!u)return;const y=l=>{var x,M,R,D,T,U;const p=Te(l.clientX,l.clientY),k=ue(p.x,p.y);if(k){(M=(x=V.current).onNodeContextMenu)==null||M.call(x,l,k);return}const S=Ge(p.x,p.y);if(S){(D=(R=V.current).onEdgeContextMenu)==null||D.call(R,l,S);return}(U=(T=V.current).onPaneContextMenu)==null||U.call(T,l)};return u.addEventListener("contextmenu",y),()=>u.removeEventListener("contextmenu",y)},[Te,ue,Ge]),a.useEffect(()=>{const u=be.current;if(!u)return;let y=null,l=null;const p=x=>{var D,T,U,Q,Z,ae,K,ce,ke,Ae,Xe,Qe,Ue,Jt;if((T=(D=V.current).onPaneMouseMove)==null||T.call(D,x),Nt.current||Ye.current||Oe.current||ot.current)return;const M=Te(x.clientX,x.clientY),R=ue(M.x,M.y);if(R!==y&&(y&&((Q=(U=V.current).onNodeMouseLeave)==null||Q.call(U,x,y)),R&&((ae=(Z=V.current).onNodeMouseEnter)==null||ae.call(Z,x,R)),y=R),R&&((ce=(K=V.current).onNodeMouseMove)==null||ce.call(K,x,R)),!R){const ht=Ge(M.x,M.y);ht!==l&&(l&&((Ae=(ke=V.current).onEdgeMouseLeave)==null||Ae.call(ke,x,l)),ht&&((Qe=(Xe=V.current).onEdgeMouseEnter)==null||Qe.call(Xe,x,ht)),l=ht),ht&&((Jt=(Ue=V.current).onEdgeMouseMove)==null||Jt.call(Ue,x,ht))}},k=x=>{var M,R;return(R=(M=V.current).onPaneMouseEnter)==null?void 0:R.call(M,x)},S=x=>{var M,R,D,T,U,Q;(R=(M=V.current).onPaneMouseLeave)==null||R.call(M,x),y&&((T=(D=V.current).onNodeMouseLeave)==null||T.call(D,x,y),y=null),l&&((Q=(U=V.current).onEdgeMouseLeave)==null||Q.call(U,x,l),l=null)};return u.addEventListener("mousemove",p),u.addEventListener("mouseenter",k),u.addEventListener("mouseleave",S),()=>{u.removeEventListener("mousemove",p),u.removeEventListener("mouseenter",k),u.removeEventListener("mouseleave",S)}},[Te,ue,Ge]),a.useEffect(()=>{const u=Array.isArray(qe)?qe:[qe],y=async l=>{var p,k,S,x;if(u.includes(l.key)){if(l.target.tagName==="INPUT"||l.target.tagName==="TEXTAREA"||l.target.isContentEditable)return;const M=te.current.filter(T=>T.selected),R=Ne.current.filter(T=>T.selected);if(!M.length&&!R.length)return;if(V.current.onBeforeDelete)try{if(!await V.current.onBeforeDelete({nodes:M,edges:R}))return}catch(T){(k=(p=V.current).onError)==null||k.call(p,"before-delete-error",T.message||"onBeforeDelete threw an error");return}const D=new Set(M.map(T=>T.id));if(M.length&&Ee.current&&(Ee.current(M.map(T=>({id:T.id,type:"remove"}))),He.current)){const T=Ne.current.filter(U=>D.has(U.source)||D.has(U.target));T.length&&He.current(T.map(U=>({id:U.id,type:"remove"})))}R.length&&He.current&&He.current(R.map(T=>({id:T.id,type:"remove"}))),(x=(S=V.current).onDelete)==null||x.call(S,{nodes:M,edges:R})}if((l.ctrlKey||l.metaKey)&&l.key==="a"){if(l.target.tagName==="INPUT"||l.target.tagName==="TEXTAREA")return;if(l.preventDefault(),Ee.current){const M=te.current.filter(R=>!R.selected).map(R=>({id:R.id,type:"select",selected:!0}));M.length&&Ee.current(M)}if(He.current){const M=Ne.current.filter(R=>!R.selected).map(R=>({id:R.id,type:"select",selected:!0}));M.length&&He.current(M)}}};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[qe]);const Ft=a.useRef(!1);a.useEffect(()=>{var u,y;if(!Ft.current&&Pe.current){if(Ft.current=!0,_e&&te.current.length>0){const l=be.current;if(l){const p=l.getBoundingClientRect(),k=(ye==null?void 0:ye.padding)??.1,S=Mn(te.current),x=Yt(S,p.width,p.height,k);ye!=null&&ye.maxZoom&&(x.zoom=Math.min(x.zoom,ye.maxZoom)),ye!=null&&ye.minZoom&&(x.zoom=Math.max(x.zoom,ye.minZoom)),fe.current=x,Re()}}(y=(u=V.current).onInit)==null||y.call(u,{getNodes:()=>[...te.current],getEdges:()=>[...Ne.current],getNode:l=>te.current.find(p=>p.id===l),getEdge:l=>Ne.current.find(p=>p.id===l),getViewport:()=>({...fe.current}),getZoom:()=>fe.current.zoom,setViewport:l=>{fe.current={x:l.x??fe.current.x,y:l.y??fe.current.y,zoom:l.zoom??fe.current.zoom},Re()},fitView:(l={})=>{const p=be.current;if(!p||!te.current.length)return;const k=p.getBoundingClientRect(),S=l.nodes?te.current.filter(R=>l.nodes.some(D=>D.id===R.id)):te.current;if(!S.length)return;const x=Mn(S),M=Yt(x,k.width,k.height,l.padding??.1);l.maxZoom&&(M.zoom=Math.min(M.zoom,l.maxZoom)),l.minZoom&&(M.zoom=Math.max(M.zoom,l.minZoom)),fe.current=M,Re()},screenToFlowPosition:l=>Te(l.x,l.y),flowToScreenPosition:l=>{const p=fe.current,k=be.current;if(!k)return{x:0,y:0};const S=k.getBoundingClientRect();return{x:l.x*p.zoom+p.x+S.left,y:l.y*p.zoom+p.y+S.top}},zoomIn:()=>{const l=fe.current;l.zoom=Math.min(de,l.zoom*1.2),Re()},zoomOut:()=>{const l=fe.current;l.zoom=Math.max(se,l.zoom/1.2),Re()},zoomTo:l=>{fe.current.zoom=Math.min(de,Math.max(se,l)),Re()},setNodes:l=>{var p,k;(k=(p=V.current).onNodesChange)==null||k.call(p,[...te.current.map(S=>({id:S.id,type:"remove"})),...(typeof l=="function"?l(te.current):l).map(S=>({type:"add",item:S}))])},setEdges:l=>{var p,k;(k=(p=V.current).onEdgesChange)==null||k.call(p,[...Ne.current.map(S=>({id:S.id,type:"remove"})),...(typeof l=="function"?l(Ne.current):l).map(S=>({type:"add",item:S}))])},addNodes:l=>{var k,S;const p=Array.isArray(l)?l:[l];(S=(k=V.current).onNodesChange)==null||S.call(k,p.map(x=>({type:"add",item:x})))},addEdges:l=>{var k,S;const p=Array.isArray(l)?l:[l];(S=(k=V.current).onEdgesChange)==null||S.call(k,p.map(x=>({type:"add",item:x})))},deleteElements:({nodes:l=[],edges:p=[]})=>{var k,S,x,M;l.length&&((S=(k=V.current).onNodesChange)==null||S.call(k,l.map(R=>({id:R.id,type:"remove"})))),p.length&&((M=(x=V.current).onEdgesChange)==null||M.call(x,p.map(R=>({id:R.id,type:"remove"}))))},updateNodeData:(l,p)=>{var x,M;const k=te.current.find(R=>R.id===l);if(!k)return;const S=typeof p=="function"?p(k.data):{...k.data,...p};(M=(x=V.current).onNodesChange)==null||M.call(x,[{id:l,type:"replace",item:{...k,data:S}}])},toObject:()=>({nodes:[...te.current],edges:[...Ne.current],viewport:{...fe.current}}),setCenter:(l,p,k={})=>{const S=be.current;if(!S)return;const x=S.getBoundingClientRect(),M=k.zoom??fe.current.zoom;fe.current={x:x.width/2-l*M,y:x.height/2-p*M,zoom:M},Re()},fitBounds:(l,p={})=>{const k=be.current;if(!k)return;const S=k.getBoundingClientRect(),x=Yt(l,S.width,S.height,p.padding??.1);fe.current=x,Re()}})}});const Hn=a.useCallback(()=>{fe.current={...ze},Re()},[Re,ze]),_n=a.useCallback(u=>{var y;if(u)xt.current.push(u);else{const l=fe.current,p=be.current;if(!p)return;const k=p.getBoundingClientRect(),S=Math.round(-l.x/l.zoom+k.width/2/l.zoom),x=Math.round(-l.y/l.zoom+k.height/2/l.zoom);xt.current.push({x:S-80,y:x-45,w:160,h:90,title:"Note "+(xt.current.length+1),body:"Added at viewport center"})}(y=Pe.current)==null||y.postMessage({type:"cards",data:{cards:[...xt.current]}})},[]),Wn=a.useCallback(u=>{if(u.id||(u.id="node-"+Date.now()),!u.position){const y=fe.current,l=be.current;if(!l)return;const p=l.getBoundingClientRect();u.position={x:Math.round(-y.x/y.zoom+p.width/2/y.zoom)-ut/2,y:Math.round(-y.y/y.zoom+p.height/2/y.zoom)-et/2}}u.data||(u.data={label:u.id}),Ee.current&&Ee.current([{type:"add",item:u}])},[]),Fn=a.useCallback(()=>({...fe.current}),[]),_=a.useCallback(u=>{fe.current={...fe.current,...u},Re()},[Re]),pe=a.useCallback(u=>Te(u.x,u.y),[Te]),re=n,Se=a.useMemo(()=>({wrapRef:be,canvasRef:Pt,workerRef:Pe,cameraRef:fe,nodesRef:te,edgesRef:Ne,handleRegistryRef:fn,syncNodesToWorker:pn,onNodesChangeRef:Ee,onEdgesChangeRef:He,sendCamera:Re,screenToWorld:Te,viewportListeners:pt,selectionListeners:st,zoomMin:se,zoomMax:de,snapToGrid:nt,snapGrid:$e,nodeExtent:yt,defaultEdgeOptions:Et,edgeRouting:wt,resolvedNodesRef:at,noDragClassName:St,noPanClassName:zt,get nodes(){return t},get edges(){return n},get routedEdges(){return re},get viewport(){return gn},get connection(){return Ot}}),[t,n,re,gn,Ot,Re,Te,pn,pt,st,se,de,nt,$e,yt,Et,wt,St,zt]);return{wrapRef:be,canvasRef:Pt,canvasReady:Tt,onPointerDown:Gt,onPointerMove:Qt,onPointerUp:mn,resetView:Hn,addCard:_n,addNode:Wn,getCamera:Fn,setCamera:_,screenToFlowPosition:pe,store:Se}}function ro(e,t,n,r,i,o){const c=i-n,f=o-r,v=c*c+f*f;if(v===0)return Math.hypot(e-n,t-r);let d=((e-n)*c+(t-r)*f)/v;return d=Math.max(0,Math.min(1,d)),Math.hypot(e-(n+d*c),t-(r+d*f))}const ur=e=>{let t;const n=new Set,r=(d,h)=>{const w=typeof d=="function"?d(t):d;if(!Object.is(w,t)){const C=t;t=h??(typeof w!="object"||w===null)?w:Object.assign({},t,w),n.forEach(E=>E(t,C))}},i=()=>t,f={setState:r,getState:i,getInitialState:()=>v,subscribe:d=>(n.add(d),()=>n.delete(d))},v=t=e(r,i,f);return f},oo=(e=>e?ur(e):ur),so=e=>e;function io(e,t=so){const n=a.useSyncExternalStore(e.subscribe,a.useCallback(()=>t(e.getState()),[e,t]),a.useCallback(()=>t(e.getInitialState()),[e,t]));return a.useDebugValue(n),n}const kt=a.createContext(null);function ao(e={}){return oo((t,n)=>({nodes:[],edges:[],viewport:{x:0,y:0,zoom:1},connection:null,minZoom:.1,maxZoom:5,width:0,height:0,domNode:null,nodesRef:{current:[]},edgesRef:{current:[]},cameraRef:{current:{x:0,y:0,zoom:1}},wrapRef:{current:null},workerRef:{current:null},onNodesChangeRef:{current:null},onEdgesChangeRef:{current:null},viewportListeners:new Set,selectionListeners:new Set,edgeLabelContainerRef:{current:null},viewportPortalRef:{current:null},screenToWorld:(r,i)=>{const o=n().cameraRef.current;return{x:(r-o.x)/o.zoom,y:(i-o.y)/o.zoom}},sendCamera:()=>{var i;const r=n();(i=r.workerRef.current)==null||i.postMessage({type:"camera",data:{camera:{...r.cameraRef.current}}})},...e}))}function Ie(e,t){const n=a.useContext(kt);if(!n)throw new Error("useCanvasStore must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");const r=typeof n.getState=="function"&&typeof n.subscribe=="function",i=a.useRef(e),o=a.useRef(t),c=a.useRef(void 0);i.current=e,o.current=t;const f=a.useCallback(v=>{const d=i.current;if(!d)return v;const h=d(v),w=o.current||Object.is;return c.current!==void 0&&w(c.current,h)?c.current:(c.current=h,h)},[]);return r?io(n,e?f:void 0):e?f(n):n}function Rr(){const e=a.useContext(kt);if(!e)throw new Error("useCanvasStoreApi must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");return typeof e.getState=="function"?e:{getState:()=>e,setState:()=>{},subscribe:()=>()=>{}}}const on=a.createContext(null);function co(){return a.useContext(on)}function lo({node:e,nodeType:t}){var z,W,A,B;const n=Ie(),r=a.useRef(n);r.current=n;const i=a.useRef(null),o=e._absolutePosition||e.position,c=a.useRef(null);a.useEffect(()=>{const F=i.current;if(!F)return;const H=new ResizeObserver(Y=>{var q,O,X,m;const{width:$,height:N}=Y[0].contentRect;if($>0&&N>0){const g=r.current,b=g.nodesRef.current.find(j=>j.id===e.id),L=(b==null?void 0:b.width)||((q=b==null?void 0:b.measured)==null?void 0:q.width),P=(b==null?void 0:b.height)||((O=b==null?void 0:b.measured)==null?void 0:O.height);(Math.abs((L||0)-$)>1||Math.abs((P||0)-N)>1)&&((m=(X=g.onNodesChangeRef).current)==null||m.call(X,[{id:e.id,type:"dimensions",dimensions:{width:$,height:N},setAttributes:!0}]))}});return H.observe(F),()=>H.disconnect()},[e.id]);const f=a.useCallback(F=>{var le,xe,Me,we;F.stopPropagation();const H=F.target.tagName;if(H==="INPUT"||H==="TEXTAREA"||H==="SELECT"||H==="BUTTON"||H==="A"||H==="LABEL"||F.target.isContentEditable)return;const Y=r.current.noDragClassName||"nodrag",$=r.current.noPanClassName||"nopan";let N=F.target;for(;N&&N!==i.current;){if((le=N.classList)!=null&&le.contains(Y)||(xe=N.classList)!=null&&xe.contains($))return;N=N.parentElement}if(r.current.onNodesChangeRef.current){const ne=[];if(F.shiftKey)ne.push({id:e.id,type:"select",selected:!e.selected});else for(const se of r.current.nodesRef.current)se.id===e.id&&!se.selected?ne.push({id:se.id,type:"select",selected:!0}):se.id!==e.id&&se.selected&&ne.push({id:se.id,type:"select",selected:!1});ne.length&&r.current.onNodesChangeRef.current(ne)}const q=r.current.cameraRef.current,O=r.current.wrapRef.current;if(!O)return;const X=O.getBoundingClientRect(),m=(F.clientX-X.left-q.x)/q.zoom,g=(F.clientY-X.top-q.y)/q.zoom,L=e.selected?r.current.nodesRef.current.filter(ne=>ne.selected&&ne.id!==e.id).map(ne=>({id:ne.id,startPos:{...ne.position}})):[];c.current={startPos:{...e.position},startMouse:{x:m,y:g},selectedStarts:L};const P=[{id:e.id,type:"position",dragging:!0}];for(const ne of L)P.push({id:ne.id,type:"position",dragging:!0});(we=(Me=r.current.onNodesChangeRef).current)==null||we.call(Me,P);const j=i.current;j&&j.setPointerCapture(F.pointerId);let G=null;const ie=ne=>{var We,Fe,je,tt;if(!c.current)return;const Ce=r.current.cameraRef.current,se=O.getBoundingClientRect(),de=(ne.clientX-se.left-Ce.x)/Ce.zoom,ze=(ne.clientY-se.top-Ce.y)/Ce.zoom,_e=de-c.current.startMouse.x,ye=ze-c.current.startMouse.y;let he={x:c.current.startPos.x+_e,y:c.current.startPos.y+ye};if(r.current.snapToGrid&&r.current.snapGrid&&(he={x:r.current.snapGrid[0]*Math.round(he.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(he.y/r.current.snapGrid[1])}),e.parentId&&e.extent==="parent"){const Le=r.current.nodesRef.current.find(ve=>ve.id===e.parentId);if(Le){const ve=Le.width||160,De=Le.height||60,nt=e.width||((We=e.measured)==null?void 0:We.width)||160,$e=e.height||((Fe=e.measured)==null?void 0:Fe.height)||60;he={x:Math.max(0,Math.min(he.x,ve-nt)),y:Math.max(0,Math.min(he.y,De-$e))}}}j&&(j.style.left=he.x+"px",j.style.top=he.y+"px");const Be=[{id:e.id,position:he,_absolutePosition:he,dragging:!0}];for(const Le of c.current.selectedStarts){let ve={x:Le.startPos.x+_e,y:Le.startPos.y+ye};r.current.snapToGrid&&r.current.snapGrid&&(ve={x:r.current.snapGrid[0]*Math.round(ve.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(ve.y/r.current.snapGrid[1])});const De=O.querySelector(`[data-nodeid="${Le.id}"]`);De&&(De.style.left=ve.x+"px",De.style.top=ve.y+"px"),Be.push({id:Le.id,position:ve,_absolutePosition:ve,dragging:!0})}(tt=(je=r.current.workerRef)==null?void 0:je.current)==null||tt.postMessage({type:"nodePositions",data:{updates:Be}});for(const Le of Be){const ve=r.current.nodesRef.current.find(De=>De.id===Le.id);ve&&(ve.position=Le.position)}G=Be},ee=ne=>{var de,ze,_e,ye;if(!c.current)return;const Ce=[{id:e.id,position:e.position,dragging:!1}];for(const he of c.current.selectedStarts)Ce.push({id:he.id,position:he.startPos,dragging:!1});if(G)for(let he=0;he<G.length;he++)Ce[he]={id:G[he].id,position:G[he].position,dragging:!1};(ze=(de=r.current.workerRef)==null?void 0:de.current)==null||ze.postMessage({type:"nodePositions",data:{updates:Ce}});const se=[];for(const he of Ce)se.push({id:he.id,type:"position",position:he.position,dragging:!1});(ye=(_e=r.current.onNodesChangeRef).current)==null||ye.call(_e,se),c.current=null,G=null,j&&j.releasePointerCapture(ne.pointerId),j==null||j.removeEventListener("pointermove",ie),j==null||j.removeEventListener("pointerup",ee)};j==null||j.addEventListener("pointermove",ie),j==null||j.addEventListener("pointerup",ee)},[e]),v=a.useCallback(F=>{var O,X,m,g,b,L;if(!e.selected)return;const H=F.shiftKey?10:1;let Y=0,$=0;switch(F.key){case"ArrowUp":$=-H;break;case"ArrowDown":$=H;break;case"ArrowLeft":Y=-H;break;case"ArrowRight":Y=H;break;case"Escape":(X=(O=r.current.onNodesChangeRef).current)==null||X.call(O,[{id:e.id,type:"select",selected:!1}]);return;case"Delete":case"Backspace":e.deletable!==!1&&((g=(m=r.current.onNodesChangeRef).current)==null||g.call(m,[{id:e.id,type:"remove"}]));return;default:return}F.preventDefault();const N={x:e.position.x+Y,y:e.position.y+$},q=[{id:e.id,type:"position",position:N}];for(const P of r.current.nodesRef.current)P.selected&&P.id!==e.id&&q.push({id:P.id,type:"position",position:{x:P.position.x+Y,y:P.position.y+$}});(L=(b=r.current.onNodesChangeRef).current)==null||L.call(b,q)},[e]),d=e.width||((z=e.measured)==null?void 0:z.width),h=e.height||((W=e.measured)==null?void 0:W.height),w=!!(d&&h),C=(A=n.pinnedNodeIds)==null?void 0:A.has(e.id),E=a.useCallback(F=>{var H,Y;F.stopPropagation(),(Y=(H=r.current).togglePinNode)==null||Y.call(H,e.id)},[e.id]);return I.jsx(on.Provider,{value:e.id,children:I.jsxs("div",{ref:i,className:`ric-node-wrapper ${e.selected?"selected":""} ${e.dragging?"dragging":""}`,style:{position:"absolute",left:o.x,top:o.y,zIndex:e.type==="group"?0:e.zIndex||1,pointerEvents:e.type==="group"?"none":"all",visibility:w?"visible":"hidden",outline:"none"},"data-nodeid":e.id,tabIndex:e.selectable!==!1?0:void 0,role:"button","aria-label":`Node ${((B=e.data)==null?void 0:B.label)||e.id}`,"aria-selected":!!e.selected,onPointerDown:f,onKeyDown:v,children:[I.jsx(t,{id:e.id,data:e.data,type:e.type,selected:!!e.selected,dragging:!!e.dragging,draggable:e.draggable!==!1,selectable:e.selectable!==!1,deletable:e.deletable!==!1,isConnectable:e.connectable!==!1,zIndex:e.zIndex||0,positionAbsoluteX:o.x,positionAbsoluteY:o.y,width:d,height:h,sourcePosition:e.sourcePosition,targetPosition:e.targetPosition,parentId:e.parentId,dragHandle:e.dragHandle}),n.togglePinNode&&I.jsx("button",{className:"ric-pin-btn nodrag",onClick:E,title:C?"Unpin from DOM":"Pin to DOM",style:{position:"absolute",top:-8,left:-8,width:20,height:20,borderRadius:"50%",border:"1.5px solid "+(C?"#3b82f6":"#ccc"),background:C?"#3b82f6":"#fff",color:C?"#fff":"#999",fontSize:10,lineHeight:"16px",textAlign:"center",cursor:"pointer",padding:0,zIndex:10,pointerEvents:"all",boxShadow:"0 1px 3px rgba(0,0,0,0.12)"},children:"📌"})]})})}const uo=a.memo(lo),kr=160,Cr=60;function dr(e,t,n,r){var f,v;const i=e.width||((f=e.measured)==null?void 0:f.width)||kr,o=e.height||((v=e.measured)==null?void 0:v.height)||Cr,c=e._absolutePosition||e.position;if(e.handleBounds){const d=e.handleBounds[t]||[],h=n?d.find(w=>w.id===n):d[0];if(h&&h.x!==void 0&&h.y!==void 0){const w=h.position||(t==="source"?"right":"left");return{x:c.x+h.x,y:c.y+h.y,position:w}}}if(r){const d=`${e.id}__${n||t}`,h=r.get(d);if(h&&h.x!==void 0&&h.y!==void 0)return{x:c.x+h.x,y:c.y+h.y,position:h.position||(t==="source"?"right":"left")}}if(e.handles&&e.handles.length){for(const d of e.handles)if(d.type===t&&(!n||d.id===n)){if(d.x!==void 0&&d.y!==void 0)return{x:c.x+d.x,y:c.y+d.y,position:d.position||(t==="source"?"right":"left")};const h=d.position||(t==="source"?"right":"left");switch(h){case"top":return{x:c.x+i/2,y:c.y,position:h};case"bottom":return{x:c.x+i/2,y:c.y+o,position:h};case"left":return{x:c.x,y:c.y+o/2,position:h};default:return{x:c.x+i,y:c.y+o/2,position:h}}}}return t==="source"?{x:c.x+i,y:c.y+o/2,position:"right"}:{x:c.x,y:c.y+o/2,position:"left"}}function fo(e,t,n){return n==="left"?e-t:n==="right"?e+t:e}function ho(e,t,n){return n==="top"?e-t:n==="bottom"?e+t:e}function fr({x:e,y:t,position:n,type:r,onPointerDown:i}){return I.jsx("circle",{className:`ric-edge-anchor ric-edge-anchor-${r}`,cx:fo(e,10,n),cy:ho(t,10,n),r:10,stroke:"transparent",fill:"transparent",style:{cursor:"move",pointerEvents:"stroke"},onPointerDown:i})}function go({edge:e,edgeType:t,nodes:n,reconnectable:r}){var O,X;const i=a.useContext(kt),o=a.useRef(typeof i.getState=="function"?i.getState():i);o.current=typeof i.getState=="function"?i.getState():i;const[c,f]=a.useState(null),v=a.useCallback((m,g,b,L)=>{var Me;g.stopPropagation(),g.preventDefault();const P=o.current,j=P.wrapRef.current;if(!j)return;const G=m==="source"?L:b,ie=m==="source"?e.target:e.source;(Me=P.workerRef.current)==null||Me.postMessage({type:"connecting",data:{from:{x:G.x,y:G.y},to:{x:G.x,y:G.y}}});const ee=j.getBoundingClientRect(),le=we=>{var de;const ne=P.cameraRef.current,Ce=(we.clientX-ee.left-ne.x)/ne.zoom,se=(we.clientY-ee.top-ne.y)/ne.zoom;(de=P.workerRef.current)==null||de.postMessage({type:"connecting",data:{from:{x:G.x,y:G.y},to:{x:Ce,y:se}}})},xe=we=>{var he,Be,We,Fe;const ne=P.cameraRef.current,Ce=(we.clientX-ee.left-ne.x)/ne.zoom,se=(we.clientY-ee.top-ne.y)/ne.zoom,de=20/ne.zoom;let ze=null,_e=null;const ye=(he=P.handleRegistryRef)==null?void 0:he.current;for(const je of P.nodesRef.current){if(je.hidden)continue;const tt=je.width||kr,Le=je.height||Cr,ve=je._absolutePosition||je.position,De=[];if(ye)for(const[,$e]of ye)$e.nodeId===je.id&&De.push($e);const nt=De.length>0?De:je.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const $e of nt){let qe,Ze;if($e.x!==void 0&&$e.y!==void 0)qe=ve.x+$e.x,Ze=ve.y+$e.y;else switch($e.position||($e.type==="source"?"right":"left")){case"top":qe=ve.x+tt/2,Ze=ve.y;break;case"bottom":qe=ve.x+tt/2,Ze=ve.y+Le;break;case"left":qe=ve.x,Ze=ve.y+Le/2;break;default:qe=ve.x+tt,Ze=ve.y+Le/2;break}if(Math.abs(Ce-qe)<de&&Math.abs(se-Ze)<de){ze=je,_e=$e.id||null;break}}if(ze)break}if(ze){const je=m==="source"?{source:ze.id,target:ie,sourceHandle:_e,targetHandle:e.targetHandle}:{source:ie,target:ze.id,sourceHandle:e.sourceHandle,targetHandle:_e};(We=(Be=P.onEdgesChangeRef).current)==null||We.call(Be,[{id:e.id,type:"remove"},{type:"add",item:{id:e.id,...je}}])}(Fe=P.workerRef.current)==null||Fe.postMessage({type:"connecting",data:null}),j.removeEventListener("pointermove",le),j.removeEventListener("pointerup",xe)};j.addEventListener("pointermove",le),j.addEventListener("pointerup",xe)},[e]),d=o.current,h=((O=d.nodesRef)==null?void 0:O.current)||n,w=h.find(m=>m.id===e.source),C=h.find(m=>m.id===e.target),[,E]=a.useReducer(m=>m+1,0),z=a.useRef(null),W=(w==null?void 0:w.dragging)||(C==null?void 0:C.dragging);a.useEffect(()=>{if(!W)return;const m=()=>{E(),z.current=requestAnimationFrame(m)};return z.current=requestAnimationFrame(m),()=>cancelAnimationFrame(z.current)},[W]);const A=(X=d.handleRegistryRef)==null?void 0:X.current,B=w?dr(w,"source",e.sourceHandle,A):null,F=C?dr(C,"target",e.targetHandle,A):null,H=e.type==="bezier"||e.type==="simplebezier"||e.type==="default",Y=d.routedEdges||d.edges,$=Y==null?void 0:Y.find(m=>m.id===e.id),N=H?null:($==null?void 0:$._routedPoints)||e._routedPoints||null,q=r!==!1&&e.reconnectable!==!1;return!B||!F?null:I.jsxs("g",{className:`ric-edge-wrapper ${e.selected?"selected":""}`,"data-edgeid":e.id,onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),children:[I.jsx(t,{id:e.id,source:e.source,target:e.target,sourceX:B.x,sourceY:B.y,targetX:F.x,targetY:F.y,sourcePosition:B.position,targetPosition:F.position,sourceHandleId:e.sourceHandle,targetHandleId:e.targetHandle,data:e.data,type:e.type,selected:!!e.selected,animated:!!e.animated,label:e.label,style:e.style,selectable:e.selectable!==!1,deletable:e.deletable!==!1,routedPoints:N}),q&&(c||e.selected)&&I.jsxs(I.Fragment,{children:[I.jsx(fr,{x:B.x,y:B.y,position:B.position,type:"source",onPointerDown:m=>v("source",m,B,F)}),I.jsx(fr,{x:F.x,y:F.y,position:F.position,type:"target",onPointerDown:m=>v("target",m,B,F)})]})]})}const yo=a.memo(go);function Er({selectionKeyCode:e="Shift",selectionMode:t="partial"}){var W;const n=Ie(),[r,i]=a.useState(null),o=a.useRef(null);if(a.useEffect(()=>{const A=n.wrapRef.current;if(!A)return;let B=!1,F=null,H=!1;const Y=X=>{X.key===e&&(H=!0)},$=X=>{X.key===e&&(H=!1)},N=X=>{if(!H)return;const m=X.target;if(m.closest(".ric-node-wrapper")||m.closest(".ric-handle"))return;B=!0;const g=n.cameraRef.current,b=A.getBoundingClientRect(),L=(X.clientX-b.left-g.x)/g.zoom,P=(X.clientY-b.top-g.y)/g.zoom;F={x:L,y:P},i({startX:L,startY:P,endX:L,endY:P}),X.stopPropagation()},q=X=>{if(!B||!F)return;const m=n.cameraRef.current,g=A.getBoundingClientRect(),b=(X.clientX-g.left-m.x)/m.zoom,L=(X.clientY-g.top-m.y)/m.zoom;i({startX:F.x,startY:F.y,endX:b,endY:L})},O=X=>{var G,ie;if(!B||!F)return;B=!1;const m=n.cameraRef.current,g=A.getBoundingClientRect(),b=(X.clientX-g.left-m.x)/m.zoom,L=(X.clientY-g.top-m.y)/m.zoom,P={x:Math.min(F.x,b),y:Math.min(F.y,L),width:Math.abs(b-F.x),height:Math.abs(L-F.y)},j=[];for(const ee of n.nodesRef.current){const le=ee._absolutePosition||ee.position,xe=ee.width||160,Me=ee.height||60;let we;t==="full"?we=le.x>=P.x&&le.y>=P.y&&le.x+xe<=P.x+P.width&&le.y+Me<=P.y+P.height:we=le.x+xe>P.x&&le.x<P.x+P.width&&le.y+Me>P.y&&le.y<P.y+P.height,j.push({id:ee.id,type:"select",selected:we})}j.length&&((ie=(G=n.onNodesChangeRef).current)==null||ie.call(G,j)),F=null,i(null)};return A.addEventListener("pointerdown",N,!0),A.addEventListener("pointermove",q),A.addEventListener("pointerup",O),window.addEventListener("keydown",Y),window.addEventListener("keyup",$),()=>{A.removeEventListener("pointerdown",N,!0),A.removeEventListener("pointermove",q),A.removeEventListener("pointerup",O),window.removeEventListener("keydown",Y),window.removeEventListener("keyup",$)}},[n,e,t]),!r)return null;const c=((W=n.cameraRef)==null?void 0:W.current)||{x:0,y:0,zoom:1},f=Math.min(r.startX,r.endX),v=Math.min(r.startY,r.endY),d=Math.abs(r.endX-r.startX),h=Math.abs(r.endY-r.startY),w=f*c.zoom+c.x,C=v*c.zoom+c.y,E=d*c.zoom,z=h*c.zoom;return I.jsx("div",{ref:o,className:"ric-selection-box",style:{position:"absolute",left:w,top:C,width:E,height:z,border:"1px dashed #3b82f6",background:"rgba(59, 130, 246, 0.08)",pointerEvents:"none",zIndex:100}})}Er.displayName="SelectionBox";const Sr=a.memo(Er);function Qn(e,t,n){switch(e){case"top":return{x:t/2,y:0};case"bottom":return{x:t/2,y:n};case"left":return{x:0,y:n/2};case"right":return{x:t,y:n/2};default:return{x:t,y:n/2}}}function xo(e,t){const n=e.closest(".ric-node-wrapper");if(!n)return null;const r=n.getBoundingClientRect(),i=e.getBoundingClientRect(),o=t||1;return{x:(i.left+i.width/2-r.left)/o,y:(i.top+i.height/2-r.top)/o}}let On=!1,Rt=null;function zr(e){Rt=e,!On&&(On=!0,requestAnimationFrame(()=>{var t;On=!1,(t=Rt==null?void 0:Rt.syncNodesToWorker)==null||t.call(Rt),Rt=null}))}const Jn=new WeakMap;let bn=null;function po(){return bn||(bn=new ResizeObserver(e=>{var t;for(const n of e){const r=Jn.get(n.target);if(!r)continue;const{width:i,height:o}=n.contentRect;if(!i||!o)continue;const c=r.getStore(),f=(t=c.handleRegistryRef)==null?void 0:t.current;if(f){for(const[v,d]of f)if(d.nodeId===r.nodeId){const h=Qn(d.position,i,o);d.x=h.x,d.y=h.y,f.set(v,d)}zr(c)}}}),bn)}function mo({type:e="source",position:t=e==="source"?"right":"left",id:n,isConnectable:r=!0,isConnectableStart:i=!0,isConnectableEnd:o=!0,children:c,className:f="",style:v={},onConnect:d,...h}){const w=a.useContext(on),C=a.useContext(kt),E=a.useRef(null),z=a.useCallback(()=>typeof C.getState=="function"?C.getState():C,[C]),W=a.useRef(z);W.current=z,a.useLayoutEffect(()=>{var m,g,b,L,P,j,G;if(!w)return;const H=W.current(),Y=(m=H.handleRegistryRef)==null?void 0:m.current;if(!Y)return;const $=`${w}__${n||e}`,N=(b=(g=H.nodesRef)==null?void 0:g.current)==null?void 0:b.find(ie=>ie.id===w),q=(N==null?void 0:N.width)||((L=N==null?void 0:N.measured)==null?void 0:L.width),O=(N==null?void 0:N.height)||((P=N==null?void 0:N.measured)==null?void 0:P.height);let X;q&&O?X=Qn(t,q,O):E.current?X=xo(E.current,(G=(j=H.cameraRef)==null?void 0:j.current)==null?void 0:G.zoom):X=Qn(t,160,60),Y.set($,{nodeId:w,id:n||null,type:e,position:t,x:X.x,y:X.y})},[w,n,e,t]),a.useEffect(()=>{if(!w)return;const H=W.current();zr(H);const Y=E.current,$=Y==null?void 0:Y.closest(".ric-node-wrapper");return $&&!Jn.has($)&&(Jn.set($,{nodeId:w,getStore:W.current}),po().observe($)),()=>{var X;const q=(X=W.current().handleRegistryRef)==null?void 0:X.current,O=`${w}__${n||e}`;q==null||q.delete(O)}},[w,n,e,t]);const A=a.useCallback(()=>{var g;const H=W.current(),Y=H.nodesRef.current.find(b=>b.id===w);if(!Y)return null;const $=Y._absolutePosition||Y.position,N=(g=H.handleRegistryRef)==null?void 0:g.current,q=`${w}__${n||e}`,O=N==null?void 0:N.get(q);if(O&&O.x!==void 0&&O.y!==void 0)return{x:$.x+O.x,y:$.y+O.y};const X=Y.width||160,m=Y.height||60;switch(t){case"top":return{x:$.x+X/2,y:$.y};case"bottom":return{x:$.x+X/2,y:$.y+m};case"left":return{x:$.x,y:$.y+m/2};default:return{x:$.x+X,y:$.y+m/2}}},[w,n,e,t]),B=a.useCallback(H=>{var L;if(!r||!i)return;H.stopPropagation(),H.preventDefault();const Y=W.current(),$=Y.cameraRef.current,N=Y.wrapRef.current;if(!N)return;const q=N.getBoundingClientRect(),O=A();if(!O)return;const X=O.x,m=O.y;(L=Y.workerRef.current)==null||L.postMessage({type:"connecting",data:{from:{x:X,y:m},to:{x:X,y:m}}}),N.setPointerCapture(H.pointerId);const g=P=>{var ie;const j=(P.clientX-q.left-$.x)/$.zoom,G=(P.clientY-q.top-$.y)/$.zoom;(ie=Y.workerRef.current)==null||ie.postMessage({type:"connecting",data:{from:{x:X,y:m},to:{x:j,y:G}}})},b=P=>{var Me,we,ne,Ce;const j=(P.clientX-q.left-$.x)/$.zoom,G=(P.clientY-q.top-$.y)/$.zoom,ie=20/$.zoom;let ee=null,le=null;const xe=(Me=Y.handleRegistryRef)==null?void 0:Me.current;for(const se of Y.nodesRef.current){if(se.id===w||se.hidden)continue;const de=se._absolutePosition||se.position,ze=[];if(xe)for(const[,ye]of xe)ye.nodeId===se.id&&ze.push(ye);const _e=ze.length>0?ze:se.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const ye of _e){let he,Be;if(ye.x!==void 0&&ye.y!==void 0)he=de.x+ye.x,Be=de.y+ye.y;else{const We=se.width||160,Fe=se.height||60;switch(ye.position||(ye.type==="source"?"right":"left")){case"top":he=de.x+We/2,Be=de.y;break;case"bottom":he=de.x+We/2,Be=de.y+Fe;break;case"left":he=de.x,Be=de.y+Fe/2;break;default:he=de.x+We,Be=de.y+Fe/2;break}}if(Math.abs(j-he)<ie&&Math.abs(G-Be)<ie){ee=se,le=ye.id||null;break}}if(ee)break}if(ee){const se={source:e==="source"?w:ee.id,target:e==="source"?ee.id:w,sourceHandle:e==="source"?n||null:le,targetHandle:e==="source"?le:n||null};(ne=(we=Y.onEdgesChangeRef)==null?void 0:we.current)==null||ne.call(we,[{type:"add",item:{id:`e-${se.source}-${se.target}`,...se}}])}(Ce=Y.workerRef.current)==null||Ce.postMessage({type:"connecting",data:null}),N.removeEventListener("pointermove",g),N.removeEventListener("pointerup",b)};N.addEventListener("pointermove",g),N.addEventListener("pointerup",b)},[w,n,e,t,r,i,A]),F={top:{top:0,left:"50%",transform:"translate(-50%, -50%)"},bottom:{bottom:0,left:"50%",transform:"translate(-50%, 50%)"},left:{top:"50%",left:0,transform:"translate(-50%, -50%)"},right:{top:"50%",right:0,transform:"translate(50%, -50%)"}}[t]||{};return I.jsx("div",{ref:E,className:`ric-handle ric-handle-${t} ric-handle-${e} ${f}`,"data-handleid":n||null,"data-nodeid":w,"data-handlepos":t,"data-handletype":e,onPointerDown:B,style:{position:"absolute",width:8,height:8,borderRadius:"50%",background:"#1a192b",border:"none",zIndex:10,cursor:r?"crosshair":"default",boxSizing:"border-box",...F,...v},...h,children:c})}const rn=a.memo(mo);function vo({data:e,isConnectable:t,selected:n,targetPosition:r="left",sourcePosition:i="right",hideSourceHandle:o=!1,hideTargetHandle:c=!1}){return I.jsxs("div",{className:`ric-default-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!c&&I.jsx(rn,{type:"target",position:r,isConnectable:t}),I.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!o&&I.jsx(rn,{type:"source",position:i,isConnectable:t})]})}function Pr({data:e,isConnectable:t,selected:n,sourcePosition:r="right",hideSourceHandle:i=!1}){return I.jsxs("div",{className:`ric-input-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderBottom:"2px solid #0041d0",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[I.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!i&&I.jsx(rn,{type:"source",position:r,isConnectable:t})]})}function Nr({data:e,isConnectable:t,selected:n,targetPosition:r="left",hideTargetHandle:i=!1}){return I.jsxs("div",{className:`ric-output-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderTop:"2px solid #ff0072",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!i&&I.jsx(rn,{type:"target",position:r,isConnectable:t}),I.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label})]})}function Ir({data:e,selected:t,width:n,height:r}){return I.jsx("div",{className:`ric-group-node${t?" selected":""}`,style:{width:n||300,height:r||200,background:"rgba(240, 240, 240, 0.25)",border:t?"2px solid #3b82f6":"1px dashed #ccc",borderRadius:8,padding:8,boxSizing:"border-box"},children:(e==null?void 0:e.label)&&I.jsx("div",{style:{fontSize:11,fontWeight:600,color:"#888",userSelect:"none"},children:e.label})})}function Tr({x:e,y:t,label:n,labelStyle:r,labelShowBg:i=!0,labelBgStyle:o,labelBgPadding:c=[2,4],labelBgBorderRadius:f=2,children:v,className:d="",...h}){const[w,C]=a.useState({x:1,y:0,width:0,height:0}),E=a.useRef(null);return a.useEffect(()=>{if(E.current){const z=E.current.getBBox();C({x:z.x,y:z.y,width:z.width,height:z.height})}},[n]),n?I.jsxs("g",{transform:`translate(${e-w.width/2} ${t-w.height/2})`,className:`ric-edge-textwrapper ${d}`,visibility:w.width?"visible":"hidden",...h,children:[i&&I.jsx("rect",{width:w.width+2*c[0],x:-c[0],y:-c[1],height:w.height+2*c[1],className:"ric-edge-textbg",style:o,rx:f,ry:f}),I.jsx("text",{className:"ric-edge-text",y:w.height/2,dy:"0.3em",ref:E,style:r,children:n}),v]}):null}Tr.displayName="EdgeText";const Lr=a.memo(Tr);function hr(e){return e!=null&&e!==""&&!isNaN(Number(e))}function sn({id:e,path:t,labelX:n,labelY:r,label:i,labelStyle:o,labelShowBg:c,labelBgStyle:f,labelBgPadding:v,labelBgBorderRadius:d,interactionWidth:h=20,style:w,markerEnd:C,markerStart:E,className:z="",...W}){return I.jsxs(I.Fragment,{children:[I.jsx("path",{id:e,d:t,fill:"none",stroke:"#b1b1b7",strokeWidth:1.5,className:`ric-edge-path ${z}`,style:w,markerEnd:C,markerStart:E,...W}),h?I.jsx("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:h,className:"ric-edge-interaction",style:{pointerEvents:"stroke"}}):null,i&&hr(n)&&hr(r)?I.jsx(Lr,{x:n,y:r,label:i,labelStyle:o,labelShowBg:c,labelBgStyle:f,labelBgPadding:v,labelBgBorderRadius:d}):null]})}const en=20;function gr(e,t,n){switch(n){case"right":return{x:e+en,y:t};case"left":return{x:e-en,y:t};case"bottom":return{x:e,y:t+en};case"top":return{x:e,y:t-en};default:return{x:e+en,y:t}}}const er=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:c="bottom",targetPosition:f="top",label:v,labelStyle:d,labelShowBg:h,labelBgStyle:w,labelBgPadding:C,labelBgBorderRadius:E,style:z,markerEnd:W,markerStart:A,interactionWidth:B}){let F,H,Y;const $=gr(n,r,c),N=gr(i,o,f),q=Math.abs(N.x-$.x),O=Math.max(50,q*.5);let X,m,g,b;switch(c){case"left":X=$.x-O,m=$.y;break;case"top":X=$.x,m=$.y-O;break;case"bottom":X=$.x,m=$.y+O;break;default:X=$.x+O,m=$.y;break}switch(f){case"right":g=N.x+O,b=N.y;break;case"top":g=N.x,b=N.y-O;break;case"bottom":g=N.x,b=N.y+O;break;default:g=N.x-O,b=N.y;break}F=`M ${n},${r} L ${$.x},${$.y} C ${X},${m} ${g},${b} ${N.x},${N.y} L ${i},${o}`;const L=.5,P=.5;return H=P*P*P*$.x+3*P*P*L*X+3*P*L*L*g+L*L*L*N.x,Y=P*P*P*$.y+3*P*P*L*m+3*P*L*L*b+L*L*L*N.y,I.jsx(sn,{id:t,path:F,labelX:H,labelY:Y,label:v,labelStyle:d,labelShowBg:h,labelBgStyle:w,labelBgPadding:C,labelBgBorderRadius:E,style:z,markerEnd:W,markerStart:A,interactionWidth:B})});er.displayName="BezierEdge";function tr({sourceX:e,sourceY:t,targetX:n,targetY:r}){const i=`M ${e},${t}L ${n},${r}`,o=(e+n)/2,c=(t+r)/2;return[i,o,c,0,0]}function nr({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i="right",targetPosition:o="left",curvature:c=.25}){const f=Math.abs(n-e),v=Math.abs(r-t),d=Math.sqrt(f*f+v*v),h=Math.max(d*c,50);let w,C,E,z;switch(i){case"top":w=e,C=t-h;break;case"bottom":w=e,C=t+h;break;case"left":w=e-h,C=t;break;default:w=e+h,C=t;break}switch(o){case"top":E=n,z=r-h;break;case"bottom":E=n,z=r+h;break;case"right":E=n+h,z=r;break;default:E=n-h,z=r;break}const W=`M ${e},${t} C ${w},${C} ${E},${z} ${n},${r}`,A=.5,B=1-A,F=B*B*B*e+3*B*B*A*w+3*B*A*A*E+A*A*A*n,H=B*B*B*t+3*B*B*A*C+3*B*A*A*z+A*A*A*r;return[W,F,H,0,0]}function rr({sourceX:e,sourceY:t,targetX:n,targetY:r}){const i=Math.abs(n-e),o=Math.max(i*.5,50),c=e+o,f=n-o,v=`M ${e},${t} C ${c},${t} ${f},${r} ${n},${r}`,d=.5,h=.5,w=h*h*h*e+3*h*h*d*c+3*h*d*d*f+d*d*d*n,C=h*h*h*t+3*h*h*d*t+3*h*d*d*r+d*d*d*r;return[v,w,C,0,0]}function Rn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i="right",targetPosition:o="left",borderRadius:c=5,offset:f=20}){const v=i==="left"||i==="right",d=Math.min(c,Math.abs(n-e)/2,Math.abs(r-t)/2);if(v){if(Math.abs(r-t)<1)return[`M ${e},${t} L ${n},${r}`,(e+n)/2,t,0,0];const E=(e+n)/2,z=r>t?1:-1;return[`M ${e},${t} L ${E-d},${t} Q ${E},${t} ${E},${t+z*d} L ${E},${r-z*d} Q ${E},${r} ${E+(n>E?d:-d)},${r} L ${n},${r}`,E,(t+r)/2,0,0]}const h=(t+r)/2,w=n>e?1:-1;return[`M ${e},${t} L ${e},${h-d} Q ${e},${h} ${e+w*d},${h} L ${n-w*d},${h} Q ${n},${h} ${n},${h+(r>h?d:-d)} L ${n},${r}`,(e+n)/2,h,0,0]}function bo({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[,i,o]=nr({sourceX:e,sourceY:t,targetX:n,targetY:r});return[i,o,0,0]}function wo({sourceX:e,sourceY:t,targetX:n,targetY:r}){return[(e+n)/2,(t+r)/2,0,0]}function Mo(e,t,n){const r=n.filter(o=>o.id!==e.id),i={...e,id:e.id,source:t.source,target:t.target,sourceHandle:t.sourceHandle??e.sourceHandle,targetHandle:t.targetHandle??e.targetHandle};return r.push(i),r}const kn=160,Cn=60,tn=20,wn=12,En=20;function yr(e,t,n){var c,f;const r=e.width||((c=e.measured)==null?void 0:c.width)||kn,i=e.height||((f=e.measured)==null?void 0:f.height)||Cn,o=e._absolutePosition||e.position;if(e.handles&&e.handles.length>0){for(const v of e.handles)if(v.type===t&&(!n||v.id===n)){if(v.x!==void 0&&v.y!==void 0)return{x:o.x+v.x,y:o.y+v.y,dir:v.position||(t==="source"?"right":"left")};switch(v.position||(t==="source"?"right":"left")){case"top":return{x:o.x+r/2,y:o.y,dir:"top"};case"bottom":return{x:o.x+r/2,y:o.y+i,dir:"bottom"};case"left":return{x:o.x,y:o.y+i/2,dir:"left"};default:return{x:o.x+r,y:o.y+i/2,dir:"right"}}}}return t==="source"?{x:o.x+r,y:o.y+i/2,dir:"right"}:{x:o.x,y:o.y+i/2,dir:"left"}}function Sn(e,t){switch(e.dir){case"right":return{x:e.x+t,y:e.y,dir:e.dir};case"left":return{x:e.x-t,y:e.y,dir:e.dir};case"bottom":return{x:e.x,y:e.y+t,dir:e.dir};case"top":return{x:e.x,y:e.y-t,dir:e.dir};default:return{x:e.x+t,y:e.y,dir:e.dir}}}function Ro(e,t,n,r,i,o,c,f){const v=Math.min(e,n),d=Math.max(e,n),h=Math.min(t,r),w=Math.max(t,r);if(d<=i||v>=i+c||w<=o||h>=o+f)return!1;const C=.5;if(e>i+C&&e<i+c-C&&t>o+C&&t<o+f-C||n>i+C&&n<i+c-C&&r>o+C&&r<o+f-C)return!0;const E=(e+n)/2,z=(t+r)/2;if(E>i+C&&E<i+c-C&&z>o+C&&z<o+f-C)return!0;const W=[[i,o],[i+c,o],[i+c,o+f],[i,o+f]];for(let A=0;A<4;A++)if(ko(e,t,n,r,W[A][0],W[A][1],W[(A+1)%4][0],W[(A+1)%4][1]))return!0;return!1}function ko(e,t,n,r,i,o,c,f){const v=(c-i)*(t-o)-(f-o)*(e-i),d=(c-i)*(r-o)-(f-o)*(n-i),h=(n-e)*(o-t)-(r-t)*(i-e),w=(n-e)*(f-t)-(r-t)*(c-e);return(v>0&&d<0||v<0&&d>0)&&(h>0&&w<0||h<0&&w>0)}function Vn(e,t,n,r,i){for(let o=0;o<i.length;o++){const c=i[o];if(Ro(e,t,n,r,c.x,c.y,c.w,c.h))return!1}return!0}function Co(e,t,n){for(let r=0;r<n.length;r++){const i=n[r];if(e>i.x&&e<i.x+i.w&&t>i.y&&t<i.y+i.h)return!0}return!1}function or(e,t){var r,i;const n=[];for(let o=0;o<e.length;o++){const c=e[o];if(c.hidden||t&&t.has(c.id)||c.type==="group")continue;const f=c._absolutePosition||c.position,v=c.width||((r=c.measured)==null?void 0:r.width)||kn,d=c.height||((i=c.measured)==null?void 0:i.height)||Cn;n.push({id:c.id,x:f.x-tn,y:f.y-tn,w:v+2*tn,h:d+2*tn})}return n}function Br(e,t,n){if(Vn(e.x,e.y,t.x,t.y,n))return null;const r=new Set,i=new Set;r.add(e.x),r.add(t.x),i.add(e.y),i.add(t.y);const o=tn+5;e.dir==="right"?r.add(e.x+o):e.dir==="left"?r.add(e.x-o):e.dir==="top"?i.add(e.y-o):e.dir==="bottom"&&i.add(e.y+o),t.dir==="right"?r.add(t.x+o):t.dir==="left"?r.add(t.x-o):t.dir==="top"?i.add(t.y-o):t.dir==="bottom"&&i.add(t.y+o);for(let g=0;g<n.length;g++){const b=n[g];r.add(b.x),r.add(b.x+b.w),i.add(b.y),i.add(b.y+b.h)}const c=[...r].sort((g,b)=>g-b),f=[...i].sort((g,b)=>g-b),v=new Map,d=new Map;for(let g=0;g<c.length;g++)v.set(c[g],g);for(let g=0;g<f.length;g++)d.set(f[g],g);const h=c.length,w=f.length,C=(g,b)=>b*h+g,E=v.get(e.x),z=d.get(e.y),W=v.get(t.x),A=d.get(t.y);if(E===void 0||z===void 0||W===void 0||A===void 0)return null;const B=C(E,z),F=C(W,A),H=new Float64Array(h*w).fill(1/0),Y=new Float64Array(h*w).fill(1/0),$=new Int32Array(h*w).fill(-1),N=new Int8Array(h*w).fill(-1),q=new Uint8Array(h*w);H[B]=0,Y[B]=Math.abs(c[W]-e.x)+Math.abs(f[A]-e.y);const O=[B],X=15,m=[[1,0],[-1,0],[0,1],[0,-1]];for(;O.length>0;){let g=0;for(let ee=1;ee<O.length;ee++)Y[O[ee]]<Y[O[g]]&&(g=ee);const b=O[g];if(O[g]=O[O.length-1],O.pop(),b===F){const ee=[];let le=F;for(;le!==-1&&le!==B;){const xe=le/h|0,Me=le%h;ee.unshift({x:c[Me],y:f[xe]}),le=$[le]}return ee.unshift({x:e.x,y:e.y}),Eo(ee,n)}if(q[b])continue;q[b]=1;const L=b/h|0,P=b%h,j=c[P],G=f[L],ie=N[b];for(let ee=0;ee<4;ee++){const le=P+m[ee][0],xe=L+m[ee][1];if(le<0||le>=h||xe<0||xe>=w)continue;const Me=C(le,xe);if(q[Me])continue;const we=c[le],ne=f[xe];if(Co(we,ne,n)||!Vn(j,G,we,ne,n))continue;const Ce=Math.abs(we-j)+Math.abs(ne-G),se=ie>=0&&ie!==ee?X:0,de=H[b]+Ce+se;de<H[Me]&&($[Me]=b,N[Me]=ee,H[Me]=de,Y[Me]=de+Math.abs(c[W]-we)+Math.abs(f[A]-ne),O.push(Me))}}return null}function Eo(e,t){if(!e||e.length<=2)return e;const n=[e[0]];for(let r=1;r<e.length-1;r++){const i=n[n.length-1],o=e[r],c=e[r+1],f=Math.abs(i.x-o.x)<.5&&Math.abs(o.x-c.x)<.5,v=Math.abs(i.y-o.y)<.5&&Math.abs(o.y-c.y)<.5;(f||v)&&Vn(i.x,i.y,c.x,c.y,t)||n.push(o)}return n.push(e[e.length-1]),n}function So(e){const t=new Map,n=new Map;for(const i of e){const o=i._routedPoints;if(!(!o||o.length<2))for(let c=0;c<o.length-1;c++){const f=o[c],v=o[c+1];if(Math.abs(f.y-v.y)<.5){const d=Math.round(f.y*10)/10;t.has(d)||t.set(d,[]),t.get(d).push({edgeId:i.id,segIdx:c,x1:Math.min(f.x,v.x),x2:Math.max(f.x,v.x)})}else if(Math.abs(f.x-v.x)<.5){const d=Math.round(f.x*10)/10;n.has(d)||n.set(d,[]),n.get(d).push({edgeId:i.id,segIdx:c,y1:Math.min(f.y,v.y),y2:Math.max(f.y,v.y)})}}}const r=new Map;for(const i of e)i._routedPoints&&r.set(i.id,i._routedPoints.map(o=>({...o})));for(const[,i]of t){if(i.length<2)continue;const o=xr(i,"x1","x2");for(const c of o){if(c.length<2)continue;const f=(c.length-1)*wn/2;for(let v=0;v<c.length;v++){const d=c[v],h=-f+v*wn,w=r.get(d.edgeId);w&&(w[d.segIdx].y+=h,w[d.segIdx+1].y+=h)}}}for(const[,i]of n){if(i.length<2)continue;const o=xr(i,"y1","y2");for(const c of o){if(c.length<2)continue;const f=(c.length-1)*wn/2;for(let v=0;v<c.length;v++){const d=c[v],h=-f+v*wn,w=r.get(d.edgeId);w&&(w[d.segIdx].x+=h,w[d.segIdx+1].x+=h)}}}return e.map(i=>{const o=r.get(i.id);return o?{...i,_routedPoints:o}:i})}function xr(e,t,n){if(e.length<2)return[];const r=[...e].sort((c,f)=>c[t]-f[t]),i=[];let o=[r[0]];for(let c=1;c<r.length;c++){const f=o[o.length-1];r[c][t]<f[n]?o.push(r[c]):(o.length>1&&i.push(o),o=[r[c]])}return o.length>1&&i.push(o),i}function zn(e,t=6,n=!1){if(!e||e.length<2)return null;if(n)return zo(e);const r=t;let i=`M ${e[0].x},${e[0].y}`;for(let o=1;o<e.length-1;o++){const c=e[o-1],f=e[o],v=e[o+1],d=Math.abs(f.x-c.x)+Math.abs(f.y-c.y),h=Math.abs(v.x-f.x)+Math.abs(v.y-f.y),w=Math.min(r,d/2,h/2);if(w>.5){const C=f.x-c.x,E=f.y-c.y,z=v.x-f.x,W=v.y-f.y,A=Math.sqrt(C*C+E*E)||1,B=Math.sqrt(z*z+W*W)||1;i+=` L ${f.x-C/A*w},${f.y-E/A*w}`,i+=` Q ${f.x},${f.y} ${f.x+z/B*w},${f.y+W/B*w}`}else i+=` L ${f.x},${f.y}`}return i+=` L ${e[e.length-1].x},${e[e.length-1].y}`,i}function zo(e){if(e.length===2)return`M ${e[0].x},${e[0].y} L ${e[1].x},${e[1].y}`;if(e.length===3)return`M ${e[0].x},${e[0].y} Q ${e[1].x},${e[1].y} ${e[2].x},${e[2].y}`;const t=.3;let n=`M ${e[0].x},${e[0].y}`;for(let r=0;r<e.length-1;r++){const i=e[r===0?0:r-1],o=e[r],c=e[r+1],f=e[r+2<e.length?r+2:e.length-1],v=o.x+(c.x-i.x)*t,d=o.y+(c.y-i.y)*t,h=c.x-(f.x-o.x)*t,w=c.y-(f.y-o.y)*t;n+=` C ${v},${d} ${h},${w} ${c.x},${c.y}`}return n}function Pn(e){if(!e||e.length<2)return{x:0,y:0};let t=0;for(let r=1;r<e.length;r++)t+=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);let n=t/2;for(let r=1;r<e.length;r++){const i=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);if(n<=i){const o=i>0?n/i:0;return{x:e[r-1].x+(e[r].x-e[r-1].x)*o,y:e[r-1].y+(e[r].y-e[r-1].y)*o}}n-=i}return{x:e[0].x,y:e[0].y}}function Po(e,t){if(!e||!t||e.length===0||t.length===0)return t;const n={};for(const o of e)n[o.id]=o;const r=or(e,null),i=t.map(o=>{var N,q,O,X;const c=o.type||"default";if(c==="bezier"||c==="simplebezier"||c==="default")return o;const f=n[o.source],v=n[o.target];if(!f||!v||f.hidden||v.hidden)return o;const d=yr(f,"source",o.sourceHandle),h=yr(v,"target",o.targetHandle),w=Sn(d,En),C=Sn(h,En),E=5,z=r.filter(m=>m.id!==o.source&&m.id!==o.target),W=f._absolutePosition||f.position,A=f.width||((N=f.measured)==null?void 0:N.width)||kn,B=f.height||((q=f.measured)==null?void 0:q.height)||Cn;z.push({id:o.source,x:W.x-E,y:W.y-E,w:A+2*E,h:B+2*E});const F=v._absolutePosition||v.position,H=v.width||((O=v.measured)==null?void 0:O.width)||kn,Y=v.height||((X=v.measured)==null?void 0:X.height)||Cn;if(z.push({id:o.target,x:F.x-E,y:F.y-E,w:H+2*E,h:Y+2*E}),z.length===0)return o;const $=Br(w,C,z);return $&&$.length>=2?($.unshift({x:d.x,y:d.y}),$.push({x:h.x,y:h.y}),{...o,_routedPoints:$}):o});return So(i)}function No(e,t,n,r,i,o,c,f){const v=or(c,f?new Set(f):null);if(v.length===0)return null;const d={x:e,y:t,dir:i||"right"},h={x:n,y:r,dir:o||"left"},w=Sn(d,En),C=Sn(h,En),E=Br(w,C,v);return E&&E.length>=2?(E.unshift({x:d.x,y:d.y}),E.push({x:h.x,y:h.y}),E):null}const sr=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,label:c,labelStyle:f,labelShowBg:v,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:w,style:C,markerEnd:E,markerStart:z,interactionWidth:W,routedPoints:A}){let B,F,H;if(A&&A.length>=2){B=zn(A);const Y=Pn(A);F=Y.x,H=Y.y}else[B,F,H]=tr({sourceX:n,sourceY:r,targetX:i,targetY:o});return I.jsx(sn,{id:t,path:B,labelX:F,labelY:H,label:c,labelStyle:f,labelShowBg:v,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:w,style:C,markerEnd:E,markerStart:z,interactionWidth:W})});sr.displayName="StraightEdge";const ir=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:c="bottom",targetPosition:f="top",label:v,labelStyle:d,labelShowBg:h,labelBgStyle:w,labelBgPadding:C,labelBgBorderRadius:E,style:z,markerEnd:W,markerStart:A,pathOptions:B,interactionWidth:F,routedPoints:H}){let Y,$,N;if(H&&H.length>=2){Y=zn(H);const q=Pn(H);$=q.x,N=q.y}else[Y,$,N]=Rn({sourceX:n,sourceY:r,sourcePosition:c,targetX:i,targetY:o,targetPosition:f,borderRadius:B==null?void 0:B.borderRadius,offset:B==null?void 0:B.offset});return I.jsx(sn,{id:t,path:Y,labelX:$,labelY:N,label:v,labelStyle:d,labelShowBg:h,labelBgStyle:w,labelBgPadding:C,labelBgBorderRadius:E,style:z,markerEnd:W,markerStart:A,interactionWidth:F})});ir.displayName="SmoothStepEdge";const $r=a.memo(function({id:t,...n}){var i;const r=a.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(i=n.pathOptions)==null?void 0:i.offset]);return I.jsx(ir,{...n,id:t,pathOptions:r})});$r.displayName="StepEdge";const ar=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:c,targetPosition:f,label:v,labelStyle:d,labelShowBg:h,labelBgStyle:w,labelBgPadding:C,labelBgBorderRadius:E,style:z,markerEnd:W,markerStart:A,interactionWidth:B,routedPoints:F}){let H,Y,$;if(F&&F.length>=2){H=zn(F);const N=Pn(F);Y=N.x,$=N.y}else[H,Y,$]=rr({sourceX:n,sourceY:r,targetX:i,targetY:o});return I.jsx(sn,{id:t,path:H,labelX:Y,labelY:$,label:v,labelStyle:d,labelShowBg:h,labelBgStyle:w,labelBgPadding:C,labelBgBorderRadius:E,style:z,markerEnd:W,markerStart:A,interactionWidth:B})});ar.displayName="SimpleBezierEdge";const Io={input:Pr,output:Nr,group:Ir},To={bezier:er,straight:sr,simplebezier:ar},Lo=160,Bo=60;function $o(e){let t=!1;for(let n=0;n<e.length;n++){const r=e[n];if(!r.measured||r.measured.width==null||r.measured.height==null){t=!0;break}}return t?e.map(n=>{var r,i;return((r=n.measured)==null?void 0:r.width)!=null&&((i=n.measured)==null?void 0:i.height)!=null?n:{...n,measured:{width:n.width||Lo,height:n.height||Bo}}}):e}function jo({cards:e,nodes:t=[],edges:n=[],nodeTypes:r,edgeTypes:i,canvasNodeTypes:o,domNodeLimit:c=50,dark:f,gridSize:v,width:d="100%",height:h="420px",className:w="",style:C={},zoomMin:E,zoomMax:z,initialCamera:W,fitView:A,fitViewOptions:B,onNodesChange:F,onEdgesChange:H,onConnect:Y,onConnectStart:$,onConnectEnd:N,onNodeClick:q,onNodeDoubleClick:O,onNodeMouseEnter:X,onNodeMouseMove:m,onNodeMouseLeave:g,onNodeContextMenu:b,onNodeDragStart:L,onNodeDrag:P,onNodeDragStop:j,onEdgeClick:G,onEdgeDoubleClick:ie,onEdgeMouseEnter:ee,onEdgeMouseMove:le,onEdgeMouseLeave:xe,onEdgeContextMenu:Me,onPaneClick:we,onPaneContextMenu:ne,onPaneMouseEnter:Ce,onPaneMouseMove:se,onPaneMouseLeave:de,onSelectionChange:ze,onInit:_e,onMoveStart:ye,onMove:he,onMoveEnd:Be,onDelete:We,onBeforeDelete:Fe,onError:je,onDragOver:tt,onDrop:Le,onDragEnter:ve,onDragLeave:De,nodesDraggable:nt,nodesConnectable:$e,elementsSelectable:qe,multiSelectionKeyCode:Ze,selectionOnDrag:an,selectionMode:Ct,connectionMode:cn,connectionRadius:ln,connectOnClick:un,isValidConnection:dn,defaultEdgeOptions:Xt,snapToGrid:gt,snapGrid:yt,deleteKeyCode:Et,panActivationKeyCode:Nn,panOnScroll:In,panOnScrollMode:rt,panOnScrollSpeed:cr,zoomOnScroll:Tn,zoomOnDoubleClick:Ln,zoomOnPinch:St,preventScrolling:zt,translateExtent:Bn,nodeExtent:$n,autoPanOnNodeDrag:jn,autoPanOnConnect:wt,autoPanSpeed:be,edgesReconnectable:Pt,elevateNodesOnSelect:Pe,elevateEdgesOnSelect:fe,noDragClassName:xt,noPanClassName:te,onSelectionDragStart:Ne,onSelectionDrag:fn,onSelectionDragStop:Nt,edgeRouting:It=!0,onHudUpdate:Tt,onNodesProcessed:An,showHud:Ye=!0,showHint:Oe=!0,hintText:Lt="Drag to pan · Scroll to zoom",children:ot,...hn}){const[Ve,gn]=a.useState({wx:0,wy:0,zoom:"1.00"}),yn=a.useRef(null),Ot=a.useRef(null),xn=a.useCallback(_=>{gn(_),Tt==null||Tt(_)},[Tt]),pt=a.useMemo(()=>({...Io,...r}),[r]),st=a.useMemo(()=>({...To,...i}),[i]),Ke=a.useMemo(()=>$o(t),[t]),[V,it]=a.useState(()=>new Set),Mt=a.useRef(V);Mt.current=V;const Bt=a.useCallback(_=>{it(pe=>{const re=new Set(pe);return re.add(_),re})},[]),$t=a.useCallback(_=>{it(pe=>{const re=new Set(pe);return re.delete(_),re})},[]),jt=a.useCallback(_=>{it(pe=>{const re=new Set(pe);return re.has(_)?re.delete(_):re.add(_),re})},[]),mt=a.useMemo(()=>Ke.filter(_=>_.type&&pt[_.type]),[Ke,pt]),At=a.useMemo(()=>n.filter(_=>_.type&&st[_.type]),[n,st]),[Dt,Ht]=a.useState(()=>new Set),_t=a.useRef(new Set),Ee=a.useMemo(()=>{const _=new Set(Dt);for(const re of V)_.add(re);for(const re of mt)(re.selected||re.dragging)&&_.add(re.id);const pe=_t.current;if(pe.size===_.size){let re=!0;for(const Se of _)if(!pe.has(Se)){re=!1;break}if(re)return pe}return _t.current=_,_},[mt,V,Dt]),dt=a.useMemo(()=>{if(c===0)return[];const _=Ke.filter(pe=>Ee.has(pe.id));return _.sort((pe,re)=>{const Se=pe.type==="group"||!pe.parentId&&_.some(y=>y.parentId===pe.id),u=re.type==="group"||!re.parentId&&_.some(y=>y.parentId===re.id);return Se&&!u?-1:!Se&&u?1:0})},[Ke,Ee,c]),He=a.useMemo(()=>t.map(_=>Ee.has(_.id)?{..._,_customRendered:!0}:_),[t,Ee]),Dn=a.useMemo(()=>n.map(_=>_.type&&st[_.type]?{..._,_customRendered:!0}:_),[n,st]),{wrapRef:ft,canvasRef:Wt,canvasReady:at,onPointerDown:vt,onPointerMove:pn,onPointerUp:Te,store:ue}=Mr({cards:e,nodes:He,edges:Dn,dark:f,gridSize:v,zoomMin:E,zoomMax:z,initialCamera:W,fitView:A,fitViewOptions:B,onHudUpdate:xn,onNodesProcessed:An,onNodesChange:F,onEdgesChange:H,onConnect:Y,onConnectStart:$,onConnectEnd:N,onNodeClick:q,onNodeDoubleClick:O,onNodeMouseEnter:X,onNodeMouseMove:m,onNodeMouseLeave:g,onNodeContextMenu:b,onNodeDragStart:L,onNodeDrag:P,onNodeDragStop:j,onEdgeClick:G,onEdgeDoubleClick:ie,onEdgeMouseEnter:ee,onEdgeMouseMove:le,onEdgeMouseLeave:xe,onEdgeContextMenu:Me,onPaneClick:we,onPaneContextMenu:ne,onPaneMouseEnter:Ce,onPaneMouseMove:se,onPaneMouseLeave:de,onSelectionChange:ze,onInit:_e,onMoveStart:ye,onMove:he,onMoveEnd:Be,onDelete:We,onBeforeDelete:Fe,onError:je,nodesDraggable:nt,nodesConnectable:$e,elementsSelectable:qe,multiSelectionKeyCode:Ze,selectionOnDrag:an,selectionMode:Ct,connectionMode:cn,connectionRadius:ln,connectOnClick:un,isValidConnection:dn,defaultEdgeOptions:Xt,snapToGrid:gt,snapGrid:yt,deleteKeyCode:Et,panActivationKeyCode:Nn,panOnScroll:In,panOnScrollMode:rt,panOnScrollSpeed:cr,zoomOnScroll:Tn,zoomOnDoubleClick:Ln,zoomOnPinch:St,preventScrolling:zt,translateExtent:Bn,nodeExtent:$n,autoPanOnNodeDrag:jn,autoPanOnConnect:wt,autoPanSpeed:be,edgesReconnectable:Pt,elevateNodesOnSelect:Pe,elevateEdgesOnSelect:fe,noDragClassName:xt,noPanClassName:te,onSelectionDragStart:Ne,onSelectionDrag:fn,onSelectionDragStop:Nt,edgeRouting:It}),Ut=a.useRef(mt);Ut.current=mt;const qt=a.useRef(c);qt.current=c,a.useEffect(()=>{let _;const pe=()=>{const Se=Ut.current,u=qt.current;if(u===0||!Se.length)return;const y=ue.cameraRef.current,l=ue.wrapRef.current;if(!l)return;const p=l.clientWidth,k=l.clientHeight,S=(-y.x+p/2)/y.zoom,x=(-y.y+k/2)/y.zoom,M=Mt.current;let R=M.size;for(const T of Se)(T.selected||T.dragging)&&R++;const D=Math.max(0,u-R);if(D===0)Ht(T=>T.size===0?T:new Set);else{const T=new Set(M);for(const Z of Se)(Z.selected||Z.dragging)&&T.add(Z.id);const U=[];for(let Z=0;Z<Se.length;Z++){const ae=Se[Z];if(T.has(ae.id))continue;const K=ae._absolutePosition||ae.position,ce=K.x+(ae.width||160)/2-S,ke=K.y+(ae.height||60)/2-x;U.push({id:ae.id,dist:ce*ce+ke*ke})}U.sort((Z,ae)=>Z.dist-ae.dist);const Q=new Set;for(let Z=0;Z<Math.min(D,U.length);Z++)Q.add(U[Z].id);Ht(Z=>{if(Z.size!==Q.size)return Q;for(const ae of Q)if(!Z.has(ae))return Q;return Z})}},re=setTimeout(pe,100);return _=setInterval(pe,500),()=>{clearTimeout(re),clearInterval(_)}},[ue.cameraRef,ue.wrapRef]);const bt=a.useRef(new Set);a.useEffect(()=>{if(!o||!ue.workerRef.current)return;let _=!1;async function pe(Se){const u=new Blob([Se],{type:"image/svg+xml"}),y=URL.createObjectURL(u),l=new Image;return l.src=y,await l.decode(),URL.revokeObjectURL(y),createImageBitmap(l)}async function re(){var p,k,S;const Se={},u=[],y={},l={};for(const[x,M]of Object.entries(o)){if(typeof M=="function"){y[x]=M;continue}if(typeof M=="object"&&M!==null&&!(M instanceof ImageBitmap)&&!(M instanceof HTMLImageElement)&&!(M instanceof HTMLCanvasElement)&&("fill"in M||"stroke"in M||"title"in M||"accent"in M)){l[x]=M;continue}try{let R;M instanceof ImageBitmap?R=M:typeof M=="string"?R=await pe(M):M instanceof HTMLImageElement?R=await createImageBitmap(M):M instanceof HTMLCanvasElement&&(R=await createImageBitmap(M)),R&&!_&&(Se[x]=R,u.push(R))}catch(R){console.warn(`[InfiniteCanvas] Failed to convert canvasNodeType "${x}":`,R)}}if(!_&&Object.keys(Se).length>0&&((p=ue.workerRef.current)==null||p.postMessage({type:"nodeTypeBitmaps",data:{bitmaps:Se}},u)),!_&&Object.keys(l).length>0&&((k=ue.workerRef.current)==null||k.postMessage({type:"nodeTypeConfigs",data:{configs:l}})),!_&&Object.keys(y).length>0){const x=new Map,M={},R={},D=[];let T=bt.current.size;for(const U of t){const Q=y[U.type];if(Q)try{const Z=Q(U.data);if(!Z)continue;let ae=x.get(Z);if(!ae&&(ae="bmp_"+T++,x.set(Z,ae),!bt.current.has(Z))){const K=await pe(Z);if(_)return;M[ae]=K,D.push(K),bt.current.add(Z)}R[U.id]=ae}catch(Z){console.warn(`[InfiniteCanvas] canvasNodeType fn error for node "${U.id}":`,Z)}}_||(S=ue.workerRef.current)==null||S.postMessage({type:"nodeBitmaps",data:{cache:M,keys:R}},D)}}return re(),()=>{_=!0}},[o,t,ue.workerRef]);const Ge=a.useContext(kt),Zt=Ge&&typeof Ge.getState=="function";a.useEffect(()=>{Zt&&queueMicrotask(()=>{Ge.setState({nodes:Ke,edges:n,nodesRef:ue.nodesRef,edgesRef:ue.edgesRef,onNodesChangeRef:ue.onNodesChangeRef,onEdgesChangeRef:ue.onEdgesChangeRef,cameraRef:ue.cameraRef,wrapRef:ue.wrapRef,workerRef:ue.workerRef})})},[Zt,Ke,n,ue,Ge]);const Re=a.useMemo(()=>({...ue,edgeLabelContainerRef:yn,viewportPortalRef:Ot,pinNode:Bt,unpinNode:$t,togglePinNode:jt,get pinnedNodeIds(){return Mt.current},get nodes(){return Ke},get edges(){return n},get viewport(){return ue.cameraRef.current},get minZoom(){return ue.zoomMin||.1},get maxZoom(){return ue.zoomMax||5},get domNode(){return ue.wrapRef.current},get width(){var _;return((_=ue.wrapRef.current)==null?void 0:_.clientWidth)||0},get height(){var _;return((_=ue.wrapRef.current)==null?void 0:_.clientHeight)||0}}),[ue,Ke,n,Bt,$t,jt]),ct=a.useRef(null),lt=a.useRef(null),Gt=a.useRef(null),Qt=a.useRef(null),mn=a.useRef(null);a.useEffect(()=>{let _;const pe=()=>{const re=ue.cameraRef.current,Se=`translate(${re.x}px, ${re.y}px) scale(${re.zoom})`,u=`translate(${re.x}, ${re.y}) scale(${re.zoom})`;ct.current&&(ct.current.style.transform=Se),lt.current&<.current.setAttribute("transform",u),Gt.current&&(Gt.current.style.transform=Se),Qt.current&&(Qt.current.style.transform=Se);const y=ft.current;if(y){const l=re.zoom<.15?"lod-minimal":re.zoom<.35?"lod-reduced":null;l!==mn.current&&(y.classList.remove("lod-minimal","lod-reduced"),l&&y.classList.add(l),mn.current=l)}_=requestAnimationFrame(pe)};return _=requestAnimationFrame(pe),()=>cancelAnimationFrame(_)},[ue]);const[Ft,Hn]=a.useState(null);a.useEffect(()=>{if(!dt.length)return;let _;const pe=()=>{var M,R;const re=ue.cameraRef.current,Se=ue.wrapRef.current;if(!Se){_=requestAnimationFrame(pe);return}const u=Se.getBoundingClientRect(),y=200,l=-re.x/re.zoom-y,p=-re.y/re.zoom-y,k=(u.width-re.x)/re.zoom+y,S=(u.height-re.y)/re.zoom+y,x=new Set;for(const D of dt){const T=D._absolutePosition||D.position,U=D.width||((M=D.measured)==null?void 0:M.width)||200,Q=D.height||((R=D.measured)==null?void 0:R.height)||100;T.x+U>=l&&T.x<=k&&T.y+Q>=p&&T.y<=S&&x.add(D.id)}Hn(D=>{if(!D||D.size!==x.size)return x;for(const T of x)if(!D.has(T))return x;return D}),_=requestAnimationFrame(pe)};return _=requestAnimationFrame(pe),()=>cancelAnimationFrame(_)},[dt,ue]);const _n=a.useMemo(()=>Ft?dt.filter(_=>Ft.has(_.id)):dt,[dt,Ft]),Wn=dt.length>0,Fn=At.length>0;return I.jsx(kt.Provider,{value:Re,children:I.jsxs("div",{ref:ft,className:`ric-wrap ${w}`,style:{width:d,height:h,...C},onPointerDown:vt,onPointerMove:pn,onPointerUp:Te,onDragOver:tt,onDrop:Le,onDragEnter:ve,onDragLeave:De,tabIndex:0,children:[I.jsx("canvas",{ref:Wt,className:"ric-canvas"}),!at&&I.jsx("div",{className:"ric-loader",children:I.jsx("div",{className:"ric-spinner"})}),Fn&&I.jsx("svg",{className:"ric-edges-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:I.jsx("g",{ref:lt,children:At.map(_=>I.jsx(yo,{edge:_,edgeType:st[_.type],nodes:t,reconnectable:Pt},_.id))})}),Wn&&I.jsx("div",{ref:ct,className:"ric-nodes-overlay",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:10},children:_n.map(_=>I.jsx(uo,{node:_,nodeType:pt[_.type]},_.id))}),I.jsx("div",{ref:_=>{yn.current=_,Gt.current=_},className:"ric-edge-labels",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:5}}),I.jsx("div",{ref:_=>{Ot.current=_,Qt.current=_},className:"ric-viewport-portal",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:6}}),Oe&&I.jsx("div",{className:"ric-hint",children:Lt}),Ye&&I.jsxs("div",{className:"ric-info",children:["world: (",Ve.wx,", ",Ve.wy,") zoom: ",Ve.zoom,"x",Ve.nodeCount>0&&I.jsxs(I.Fragment,{children:[" nodes: ",Ve.nodeCount]}),Ve.edgeCount>0&&I.jsxs(I.Fragment,{children:[" edges: ",Ve.edgeCount]})]}),I.jsx(Sr,{selectionKeyCode:Ze||"Shift",selectionMode:Ct||"partial"}),ot]})})}function Ao({children:e}){const t=a.useRef(null);return t.current||(t.current=ao()),I.jsx(kt.Provider,{value:t.current,children:e})}function jr(e,t){const n=[],r=new Map,i=[];for(const o of e)if(o.type==="add")i.push(o);else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const c=r.get(o.id);c?c.push(o):r.set(o.id,[o])}for(const o of t){const c=r.get(o.id);if(!c){n.push(o);continue}if(c[0].type==="remove")continue;if(c[0].type==="replace"){n.push({...c[0].item});continue}const f={...o};for(const v of c)Do(v,f);n.push(f)}for(const o of i)o.index!==void 0?n.splice(o.index,0,{...o.item}):n.push({...o.item});return n}function Do(e,t){switch(e.type){case"select":t.selected=e.selected;break;case"position":e.position!==void 0&&(t.position=e.position),e.dragging!==void 0&&(t.dragging=e.dragging);break;case"dimensions":e.dimensions!==void 0&&(t.measured={...e.dimensions},(e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height)),e.handleBounds!==void 0&&(t.handleBounds=e.handleBounds);break}}function Ar(e,t){return jr(e,t)}function Dr(e,t){return jr(e,t)}function Ho(e,t){return!e.source||!e.target?(console.warn("addEdge: source and target are required"),t):t.some(r=>r.source===e.source&&r.target===e.target&&(r.sourceHandle||null)===(e.sourceHandle||null)&&(r.targetHandle||null)===(e.targetHandle||null))?t:[...t,{id:e.id||`e-${e.source}-${e.target}`,...e}]}function _o(e){const[t,n]=a.useState(e),r=a.useCallback(i=>n(o=>Ar(i,o)),[]);return[t,n,r]}function Wo(e){const[t,n]=a.useState(e),r=a.useCallback(i=>n(o=>Dr(i,o)),[]);return[t,n,r]}function Hr(){const e=Rr(),t=a.useCallback(()=>typeof e.getState=="function"?e.getState():e,[e]),n=a.useCallback(()=>[...t().nodesRef.current],[t]),r=a.useCallback(()=>[...t().edgesRef.current],[t]),i=a.useCallback(m=>t().nodesRef.current.find(g=>g.id===m),[t]),o=a.useCallback(m=>t().edgesRef.current.find(g=>g.id===m),[t]),c=a.useCallback(m=>{var g,b,L,P;if(typeof m=="function"){const j=m(t().nodesRef.current);(b=(g=t().onNodesChangeRef).current)==null||b.call(g,[...t().nodesRef.current.map(G=>({id:G.id,type:"remove"})),...j.map(G=>({type:"add",item:G}))])}else(P=(L=t().onNodesChangeRef).current)==null||P.call(L,[...t().nodesRef.current.map(j=>({id:j.id,type:"remove"})),...m.map(j=>({type:"add",item:j}))])},[t]),f=a.useCallback(m=>{var g,b,L,P;if(typeof m=="function"){const j=m(t().edgesRef.current);(b=(g=t().onEdgesChangeRef).current)==null||b.call(g,[...t().edgesRef.current.map(G=>({id:G.id,type:"remove"})),...j.map(G=>({type:"add",item:G}))])}else(P=(L=t().onEdgesChangeRef).current)==null||P.call(L,[...t().edgesRef.current.map(j=>({id:j.id,type:"remove"})),...m.map(j=>({type:"add",item:j}))])},[t]),v=a.useCallback(m=>{var b,L;const g=Array.isArray(m)?m:[m];(L=(b=t().onNodesChangeRef).current)==null||L.call(b,g.map(P=>({type:"add",item:P})))},[t]),d=a.useCallback(m=>{var b,L;const g=Array.isArray(m)?m:[m];(L=(b=t().onEdgesChangeRef).current)==null||L.call(b,g.map(P=>({type:"add",item:P})))},[t]),h=a.useCallback(({nodes:m=[],edges:g=[]})=>{if(m.length&&t().onNodesChangeRef.current){t().onNodesChangeRef.current(m.map(L=>({id:L.id,type:"remove"})));const b=br(m,t().edgesRef.current);b.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(b.map(L=>({id:L.id,type:"remove"})))}g.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(g.map(b=>({id:b.id,type:"remove"})))},[t]),w=a.useCallback(()=>{const m=t().cameraRef.current;return{x:m.x,y:m.y,zoom:m.zoom}},[t]),C=a.useRef(null),E=a.useCallback((m,g)=>{if(C.current&&cancelAnimationFrame(C.current),!g||g<=0){t().cameraRef.current={...m},t().sendCamera();return}const b={...t().cameraRef.current},L=performance.now(),P=j=>{const G=j-L,ie=Math.min(G/g,1),ee=1-Math.pow(1-ie,3);t().cameraRef.current={x:b.x+(m.x-b.x)*ee,y:b.y+(m.y-b.y)*ee,zoom:b.zoom+(m.zoom-b.zoom)*ee},t().sendCamera(),ie<1&&(C.current=requestAnimationFrame(P))};C.current=requestAnimationFrame(P)},[t]),z=a.useCallback((m,g)=>{const b={x:m.x??t().cameraRef.current.x,y:m.y??t().cameraRef.current.y,zoom:m.zoom??t().cameraRef.current.zoom};E(b,g==null?void 0:g.duration)},[t,E]),W=a.useCallback(()=>t().cameraRef.current.zoom,[t]),A=a.useCallback(m=>{const g=t().cameraRef.current,b=t().wrapRef.current;if(!b)return;const L=b.getBoundingClientRect(),P=L.width/2,j=L.height/2,G=1.2,ie={x:P-(P-g.x)*G,y:j-(j-g.y)*G,zoom:Math.min(t().zoomMax,g.zoom*G)};E(ie,m==null?void 0:m.duration)},[t,E]),B=a.useCallback(m=>{const g=t().cameraRef.current,b=t().wrapRef.current;if(!b)return;const L=b.getBoundingClientRect(),P=L.width/2,j=L.height/2,G=1/1.2,ie={x:P-(P-g.x)*G,y:j-(j-g.y)*G,zoom:Math.max(t().zoomMin,g.zoom*G)};E(ie,m==null?void 0:m.duration)},[t,E]),F=a.useCallback((m,g)=>{const b=t().cameraRef.current,L=t().wrapRef.current;if(!L)return;const P=L.getBoundingClientRect(),j=P.width/2,G=P.height/2,ie=Math.min(t().zoomMax,Math.max(t().zoomMin,m)),ee=ie/b.zoom,le={x:j-(j-b.x)*ee,y:G-(G-b.y)*ee,zoom:ie};E(le,g==null?void 0:g.duration)},[t,E]),H=a.useCallback((m={})=>{const g=t().nodesRef.current;if(!g.length)return;const b=t().wrapRef.current;if(!b)return;const L=b.getBoundingClientRect(),P=m.padding??.1,j=m.nodes?g.filter(ee=>m.nodes.some(le=>le.id===ee.id)):g;if(!j.length)return;const G=Mn(j),ie=Yt(G,L.width,L.height,P);m.maxZoom&&(ie.zoom=Math.min(ie.zoom,m.maxZoom)),m.minZoom&&(ie.zoom=Math.max(ie.zoom,m.minZoom)),E(ie,m.duration)},[t,E]),Y=a.useCallback((m,g={})=>{const b=t().wrapRef.current;if(!b)return;const L=b.getBoundingClientRect(),P=g.padding??.1,j=Yt(m,L.width,L.height,P);g.maxZoom&&(j.zoom=Math.min(j.zoom,g.maxZoom)),g.minZoom&&(j.zoom=Math.max(j.zoom,g.minZoom)),E(j,g.duration)},[t,E]),$=a.useCallback((m,g,b={})=>{const L=t().wrapRef.current;if(!L)return;const P=L.getBoundingClientRect(),j=b.zoom??t().cameraRef.current.zoom,G={x:P.width/2-m*j,y:P.height/2-g*j,zoom:j};E(G,b.duration)},[t,E]),N=a.useCallback(()=>({nodes:[...t().nodesRef.current],edges:[...t().edgesRef.current],viewport:{...t().cameraRef.current}}),[t]),q=a.useCallback(m=>t().screenToWorld(m.x,m.y),[t]),O=a.useCallback(m=>{const g=t().cameraRef.current,b=t().wrapRef.current;if(!b)return{x:0,y:0};const L=b.getBoundingClientRect();return{x:m.x*g.zoom+g.x+L.left,y:m.y*g.zoom+g.y+L.top}},[t]),X=a.useCallback((m,g)=>{var P,j;const b=t().nodesRef.current.find(G=>G.id===m);if(!b)return;const L=typeof g=="function"?g(b.data):{...b.data,...g};(j=(P=t().onNodesChangeRef).current)==null||j.call(P,[{id:m,type:"replace",item:{...b,data:L}}])},[t]);return{getNodes:n,getEdges:r,getNode:i,getEdge:o,setNodes:c,setEdges:f,addNodes:v,addEdges:d,deleteElements:h,getViewport:w,setViewport:z,getZoom:W,zoomIn:A,zoomOut:B,zoomTo:F,fitView:H,fitBounds:Y,setCenter:$,screenToFlowPosition:q,flowToScreenPosition:O,updateNodeData:X,toObject:N}}function Fo(){return Ie().nodes}function Yo(){return Ie().edges}function Xo(){return Ie().viewport}function Oo(){return Ie().connection}function Uo(e){const t=Ie(),n=Array.isArray(e)?e:[e];return a.useMemo(()=>n.map(r=>{const i=t.nodes.find(o=>o.id===r);return i?{id:i.id,type:i.type,data:i.data}:null}).filter(Boolean),[t.nodes,...n])}function qo(e){const t=Ie();return a.useMemo(()=>t.edges.filter(n=>n.source===e||n.target===e),[t.edges,e])}function Zo({nodeId:e,type:t,handleId:n}){const r=Ie();return a.useMemo(()=>r.edges.filter(i=>t==="source"?i.source===e&&(n?i.sourceHandle===n:!0):i.target===e&&(n?i.targetHandle===n:!0)),[r.edges,e,t,n])}function Go({onChange:e,onStart:t,onEnd:n}){const r=Ie(),i=a.useRef(e),o=a.useRef(t),c=a.useRef(n);a.useEffect(()=>{i.current=e},[e]),a.useEffect(()=>{o.current=t},[t]),a.useEffect(()=>{c.current=n},[n]),a.useEffect(()=>{const f=v=>{var d;(d=i.current)==null||d.call(i,{x:v.x,y:v.y,zoom:v.zoom})};return r.viewportListeners.add(f),()=>r.viewportListeners.delete(f)},[s])}function Qo({onChange:e}){const t=Ie(),n=a.useRef(e);a.useEffect(()=>{n.current=e},[e]),a.useEffect(()=>{const r=i=>{var o;(o=n.current)==null||o.call(n,i)};return t.selectionListeners.add(r),()=>t.selectionListeners.delete(r)},[s])}function Jo(e){const[t,n]=a.useState(!1),r=Array.isArray(e)?e:[e];return a.useEffect(()=>{const i=c=>{r.includes(c.key)&&n(!0)},o=c=>{r.includes(c.key)&&n(!1)};return window.addEventListener("keydown",i),window.addEventListener("keyup",o),()=>{window.removeEventListener("keydown",i),window.removeEventListener("keyup",o)}},[r.join(",")]),t}function Vo(){const e=Ie();return a.useCallback(t=>{var n;(n=e.workerRef.current)==null||n.postMessage({type:"nodes",data:{nodes:[...s().nodesRef.current]}})},[s])}const Ko=e=>{var t;return((t=e.nodes)==null?void 0:t.length)>0};function es(e={}){return Ie(Ko)}function ts(e){const t=Ie();return a.useMemo(()=>t.nodes.find(n=>n.id===e)||void 0,[t.nodes,e])}function ns(e,t){return Ie(e,t)}function rs(){return Rr()}function os({maxHistorySize:e=100}={}){const t=Ie(),n=a.useRef([]),r=a.useRef([]),[,i]=a.useState(0),o=a.useRef(null),c=a.useCallback(()=>{const d={nodes:s().nodesRef.current.map(h=>({...h,data:{...h.data}})),edges:s().edgesRef.current.map(h=>({...h}))};o.current&&JSON.stringify(o.current.nodes.map(h=>h.id))===JSON.stringify(d.nodes.map(h=>h.id))&&JSON.stringify(o.current.edges.map(h=>h.id))===JSON.stringify(d.edges.map(h=>h.id))||(n.current.push(d),n.current.length>e&&n.current.shift(),r.current=[],o.current=d,i(h=>h+1))},[t,e]),f=a.useCallback(()=>{var h,w,C,E;const d=n.current.pop();d&&(r.current.push({nodes:s().nodesRef.current.map(z=>({...z,data:{...z.data}})),edges:s().edgesRef.current.map(z=>({...z}))}),(w=(h=s().onNodesChangeRef).current)==null||w.call(h,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...d.nodes.map(z=>({type:"add",item:z}))]),(E=(C=s().onEdgesChangeRef).current)==null||E.call(C,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...d.edges.map(z=>({type:"add",item:z}))]),o.current=d,i(z=>z+1))},[s]),v=a.useCallback(()=>{var h,w,C,E;const d=r.current.pop();d&&(n.current.push({nodes:s().nodesRef.current.map(z=>({...z,data:{...z.data}})),edges:s().edgesRef.current.map(z=>({...z}))}),(w=(h=s().onNodesChangeRef).current)==null||w.call(h,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...d.nodes.map(z=>({type:"add",item:z}))]),(E=(C=s().onEdgesChangeRef).current)==null||E.call(C,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...d.edges.map(z=>({type:"add",item:z}))]),o.current=d,i(z=>z+1))},[s]);return{undo:f,redo:v,takeSnapshot:c,canUndo:n.current.length>0,canRedo:r.current.length>0}}function ss(e){const t=a.useRef(e);return a.useEffect(()=>{t.current=e},[e]),a.useCallback(n=>r=>{const i=t.current(r);i!==!1&&i!=null&&n(Array.isArray(i)?i:r)},[])}function is(e){const t=a.useRef(e);return a.useEffect(()=>{t.current=e},[e]),a.useCallback(n=>r=>{const i=t.current(r);i!==!1&&i!=null&&n(Array.isArray(i)?i:r)},[])}const Un=160,qn=60;function as({width:e=200,height:t=150,nodeColor:n="#3b82f6",nodeStrokeColor:r="#fff",maskColor:i="rgba(0,0,0,0.1)",style:o={},className:c=""}){const f=Ie(),v=a.useRef(null),d=a.useRef(null),h=a.useCallback(()=>{const w=v.current;if(!w)return;const C=w.getContext("2d"),E=window.devicePixelRatio||1;w.width=e*E,w.height=t*E,C.scale(E,E),C.clearRect(0,0,e,t);const z=f.nodesRef.current;if(!z.length)return;let W=1/0,A=1/0,B=-1/0,F=-1/0;for(const g of z){const b=g.width||Un,L=g.height||qn;g.position.x<W&&(W=g.position.x),g.position.y<A&&(A=g.position.y),g.position.x+b>B&&(B=g.position.x+b),g.position.y+L>F&&(F=g.position.y+L)}const H=40;W-=H,A-=H,B+=H,F+=H;const Y=B-W,$=F-A,N=Math.min(e/Y,t/$),q=(e-Y*N)/2,O=(t-$*N)/2;for(const g of z){if(g.hidden)continue;const b=g.width||Un,L=g.height||qn,P=(g.position.x-W)*N+q,j=(g.position.y-A)*N+O,G=b*N,ie=L*N;C.fillStyle=g.selected?"#f59e0b":typeof n=="function"?n(g):n,C.fillRect(P,j,Math.max(G,2),Math.max(ie,2))}const X=f.cameraRef.current,m=f.wrapRef.current;if(m){const g=m.getBoundingClientRect(),b=-X.x/X.zoom,L=-X.y/X.zoom,P=g.width/X.zoom,j=g.height/X.zoom;C.fillStyle=i,C.fillRect(0,0,e,t);const G=(b-W)*N+q,ie=(L-A)*N+O,ee=P*N,le=j*N;C.clearRect(G,ie,ee,le);for(const xe of z){if(xe.hidden)continue;const Me=xe.width||Un,we=xe.height||qn,ne=(xe.position.x-W)*N+q,Ce=(xe.position.y-A)*N+O;C.fillStyle=xe.selected?"#f59e0b":typeof n=="function"?n(xe):n,C.fillRect(ne,Ce,Math.max(Me*N,2),Math.max(we*N,2))}C.strokeStyle="#3b82f6",C.lineWidth=1.5,C.strokeRect(G,ie,ee,le)}},[f,e,t,n,r,i]);return a.useEffect(()=>{let w=!0;function C(){w&&(h(),d.current=requestAnimationFrame(C))}const E=setInterval(()=>{cancelAnimationFrame(d.current),d.current=requestAnimationFrame(C)},66);return h(),()=>{w=!1,clearInterval(E),cancelAnimationFrame(d.current)}},[h]),I.jsx("canvas",{ref:v,className:`ric-minimap ${c}`,style:{position:"absolute",bottom:30,right:10,width:e,height:t,borderRadius:4,border:"1px solid rgba(0,0,0,0.1)",background:"rgba(255,255,255,0.9)",pointerEvents:"none",...o}})}function cs(){return I.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[I.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),I.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function ls(){return I.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:I.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function us(){return I.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:I.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}function ds(){return I.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[I.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),I.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function fs(){return I.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[I.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),I.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})}function nn({children:e,className:t="",...n}){return I.jsx("button",{className:`ric-controls-button ${t}`,style:gs,...n,children:e})}function hs({showZoom:e=!0,showFitView:t=!0,showInteractive:n=!1,fitViewOptions:r,onZoomIn:i,onZoomOut:o,onFitView:c,onInteractiveChange:f,position:v="bottom-left",orientation:d="vertical",style:h={},className:w="","aria-label":C="Canvas controls",children:E}){const z=Ie(),{zoomIn:W,zoomOut:A,fitView:B,getZoom:F}=Hr(),[H,Y]=a.useState(!0),$=F()<=z.zoomMin,N=F()>=z.zoomMax,q=a.useCallback(()=>{W(),i==null||i()},[W,i]),O=a.useCallback(()=>{A(),o==null||o()},[A,o]),X=a.useCallback(()=>{B(r||{padding:.1}),c==null||c()},[B,r,c]),m=a.useCallback(()=>{const b=!H;Y(b),f==null||f(b)},[H,f]),g={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:30,left:10},"bottom-right":{bottom:30,right:10},"bottom-center":{bottom:30,left:"50%",transform:"translateX(-50%)"}}[v]||{bottom:30,left:10};return I.jsxs("div",{className:`ric-controls ${w}`,style:{position:"absolute",display:"flex",flexDirection:d==="horizontal"?"row":"column",gap:2,zIndex:5,...g,...h},role:"toolbar","aria-label":C,children:[e&&I.jsxs(I.Fragment,{children:[I.jsx(nn,{onClick:q,disabled:N,title:"Zoom in","aria-label":"Zoom in",className:"ric-controls-zoomin",children:I.jsx(cs,{})}),I.jsx(nn,{onClick:O,disabled:$,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:I.jsx(ls,{})})]}),t&&I.jsx(nn,{onClick:X,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:I.jsx(us,{})}),n&&I.jsx(nn,{onClick:m,title:H?"Lock interactivity":"Unlock interactivity","aria-label":H?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:H?I.jsx(fs,{}):I.jsx(ds,{})}),E]})}const gs={width:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid rgba(0,0,0,0.12)",borderRadius:4,background:"#fff",cursor:"pointer",fontSize:16,lineHeight:1,color:"#333",padding:0},ys=a.memo(hs);function xs({variant:e="lines",gap:t=40,size:n=1,color:r,style:i={},className:o=""}){const c=Ie();return c.workerRef.current&&c.workerRef.current.postMessage({type:"background",data:{variant:e,gap:t,size:n,color:r}}),null}function ps({position:e="top-left",style:t={},className:n="",children:r}){const i={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:10,left:10},"bottom-right":{bottom:10,right:10},"bottom-center":{bottom:10,left:"50%",transform:"translateX(-50%)"}}[e]||{top:10,left:10};return I.jsx("div",{className:`ric-panel ${n}`,style:{position:"absolute",zIndex:5,pointerEvents:"all",...i,...t},onPointerDown:o=>o.stopPropagation(),children:r})}function ms({minWidth:e=10,minHeight:t=10,maxWidth:n=1/0,maxHeight:r=1/0,isVisible:i=!0,handleStyle:o={},lineStyle:c={},color:f="#3b82f6",onResizeStart:v,onResize:d,onResizeEnd:h}){const w=a.useContext(on),C=Ie(),E=a.useRef(null),z=a.useCallback((B,F)=>{B.stopPropagation(),B.preventDefault();const H=C.nodesRef.current.find(N=>N.id===w);if(!H)return;E.current={direction:F,startX:B.clientX,startY:B.clientY,width:H.width||160,height:H.height||60},v==null||v(B,{width:E.current.width,height:E.current.height});const Y=N=>{var L,P;if(!E.current)return;const q=E.current,O=C.cameraRef.current,X=(N.clientX-q.startX)/O.zoom,m=(N.clientY-q.startY)/O.zoom;let g=q.width,b=q.height;q.direction.includes("e")&&(g=Math.min(n,Math.max(e,q.width+X))),q.direction.includes("w")&&(g=Math.min(n,Math.max(e,q.width-X))),q.direction.includes("s")&&(b=Math.min(r,Math.max(t,q.height+m))),q.direction.includes("n")&&(b=Math.min(r,Math.max(t,q.height-m))),(P=(L=C.onNodesChangeRef).current)==null||P.call(L,[{id:w,type:"dimensions",dimensions:{width:g,height:b},setAttributes:!0}]),d==null||d(N,{width:g,height:b})},$=N=>{E.current=null,h==null||h(N,{}),window.removeEventListener("pointermove",Y),window.removeEventListener("pointerup",$)};window.addEventListener("pointermove",Y),window.addEventListener("pointerup",$)},[w,C,e,t,n,r,v,d,h]);if(!i)return null;const W=8,A={position:"absolute",width:W,height:W,background:f,border:"1px solid #fff",borderRadius:2,zIndex:20,...o};return I.jsxs(I.Fragment,{children:[I.jsx("div",{style:{...A,bottom:-W/2,right:-W/2,cursor:"nwse-resize"},onPointerDown:B=>z(B,"se")}),I.jsx("div",{style:{...A,bottom:-W/2,left:-W/2,cursor:"nesw-resize"},onPointerDown:B=>z(B,"sw")}),I.jsx("div",{style:{...A,top:-W/2,right:-W/2,cursor:"nesw-resize"},onPointerDown:B=>z(B,"ne")}),I.jsx("div",{style:{...A,top:-W/2,left:-W/2,cursor:"nwse-resize"},onPointerDown:B=>z(B,"nw")}),I.jsx("div",{style:{...A,top:"50%",right:-W/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:B=>z(B,"e")}),I.jsx("div",{style:{...A,top:"50%",left:-W/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:B=>z(B,"w")}),I.jsx("div",{style:{...A,left:"50%",top:-W/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:B=>z(B,"n")}),I.jsx("div",{style:{...A,left:"50%",bottom:-W/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:B=>z(B,"s")})]})}function vs({isVisible:e,position:t="top",offset:n=10,align:r="center",children:i,style:o={},className:c=""}){const f=a.useContext(on),d=Ie().nodes.find(C=>C.id===f);if(!(e!==void 0?e:d==null?void 0:d.selected))return null;const w={top:{bottom:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginBottom:n},bottom:{top:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginTop:n},left:{right:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginRight:n},right:{left:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginLeft:n}}[t]||{};return I.jsx("div",{className:`ric-node-toolbar ${c}`,style:{position:"absolute",zIndex:1e3,pointerEvents:"all",...w,...o},onPointerDown:C=>C.stopPropagation(),children:i})}function bs({isVisible:e=!1,x:t=0,y:n=0,alignX:r="center",alignY:i="center",children:o,style:c={},className:f=""}){if(!e)return null;const v=r==="center"?"-50%":r==="right"?"-100%":"0",d=i==="center"?"-50%":i==="bottom"?"-100%":"0";return I.jsx("div",{className:`ric-edge-toolbar ${f}`,style:{position:"absolute",left:t,top:n,transform:`translate(${v}, ${d})`,zIndex:1e3,pointerEvents:"all",...c},children:o})}function ws({children:e}){var r;const n=(r=Ie().edgeLabelContainerRef)==null?void 0:r.current;return n?pr.createPortal(e,n):null}function Ms({children:e}){var r;const n=(r=Ie().viewportPortalRef)==null?void 0:r.current;return n?pr.createPortal(e,n):null}function _r({fromX:e,fromY:t,toX:n,toY:r,fromPosition:i="right",toPosition:o="left",connectionLineType:c="default",connectionLineStyle:f,connectionLineComponent:v}){if(v)return I.jsx(v,{fromX:e,fromY:t,toX:n,toY:r,fromPosition:i,toPosition:o});let d;switch(c){case"straight":[d]=tr({sourceX:e,sourceY:t,targetX:n,targetY:r});break;case"step":[d]=Rn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o,borderRadius:0});break;case"smoothstep":[d]=Rn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o});break;case"simplebezier":[d]=rr({sourceX:e,sourceY:t,targetX:n,targetY:r});break;default:[d]=nr({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o});break}return I.jsx("path",{d,fill:"none",className:"ric-connection-line",stroke:"#b1b1b7",strokeWidth:1.5,style:f})}_r.displayName="ConnectionLine";const Rs=a.memo(_r),ks=Object.freeze({Top:"top",Bottom:"bottom",Left:"left",Right:"right"}),Cs=Object.freeze({Arrow:"arrow",ArrowClosed:"arrowclosed"});function Es(e){const t=e.width||e.measured&&e.measured.width||0,n=e.height||e.measured&&e.measured.height||0,r=e._absolutePosition||e.position||{x:0,y:0};return{x:r.x,y:r.y,x2:r.x+t,y2:r.y+n}}exports.Background=xs;exports.BaseEdge=sn;exports.BezierEdge=er;exports.ConnectionLine=Rs;exports.ControlButton=nn;exports.Controls=ys;exports.DefaultNode=vo;exports.EdgeLabelRenderer=ws;exports.EdgeText=Lr;exports.EdgeToolbar=bs;exports.GroupNode=Ir;exports.Handle=rn;exports.InfiniteCanvas=jo;exports.InfiniteCanvasProvider=Ao;exports.InputNode=Pr;exports.MarkerType=Cs;exports.MiniMap=as;exports.NodeResizer=ms;exports.NodeToolbar=vs;exports.OutputNode=Nr;exports.Panel=ps;exports.Position=ks;exports.SelectionBox=Sr;exports.SimpleBezierEdge=ar;exports.SmoothStepEdge=ir;exports.StepEdge=$r;exports.StraightEdge=sr;exports.ViewportPortal=Ms;exports.addEdge=Ho;exports.applyEdgeChanges=Dr;exports.applyNodeChanges=Ar;exports.boxToRect=Qr;exports.buildObstacles=or;exports.clampPosition=Gn;exports.computeRoutedEdges=Po;exports.getBezierEdgeCenter=bo;exports.getBezierPath=nr;exports.getBoundsOfBoxes=Jr;exports.getConnectedEdges=br;exports.getEdgeCenter=wo;exports.getIncomers=Ur;exports.getNodeDimensions=Kn;exports.getNodesBounds=Mn;exports.getNodesInside=Zr;exports.getOutgoers=qr;exports.getOverlappingArea=Vr;exports.getRoutedLabelPosition=Pn;exports.getSimpleBezierPath=rr;exports.getSmoothStepPath=Rn;exports.getStraightPath=tr;exports.getViewportForBounds=Yt;exports.isEdge=Or;exports.isNode=Xr;exports.nodeToBox=Es;exports.nodeToRect=Kr;exports.reconnectEdge=Mo;exports.rectToBox=Gr;exports.routeSinglePath=No;exports.routedPointsToPath=zn;exports.snapPosition=Zn;exports.useConnection=Oo;exports.useEdges=Yo;exports.useEdgesState=Wo;exports.useHandleConnections=Zo;exports.useInfiniteCanvas=Mr;exports.useInternalNode=ts;exports.useKeyPress=Jo;exports.useNodeConnections=qo;exports.useNodeId=co;exports.useNodes=Fo;exports.useNodesData=Uo;exports.useNodesInitialized=es;exports.useNodesState=_o;exports.useOnEdgesChangeMiddleware=is;exports.useOnNodesChangeMiddleware=ss;exports.useOnSelectionChange=Qo;exports.useOnViewportChange=Go;exports.useReactFlow=Hr;exports.useStore=ns;exports.useStoreApi=rs;exports.useUndoRedo=os;exports.useUpdateNodeInternals=Vo;exports.useViewport=Xo;
|
|
946
|
+
`,ur=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",Mr],{type:"text/javascript;charset=utf-8"});function to(e){let t;try{if(t=ur&&(self.URL||self.webkitURL).createObjectURL(ur),!t)throw"";const n=new Worker(t,{type:"module",name:e==null?void 0:e.name});return n.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),n}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(Mr),{type:"module",name:e==null?void 0:e.name})}}const On=new WeakMap;function no(e,t){if(On.has(e))return On.get(e);const n=e.transferControlToOffscreen(),r=new to;r.onerror=o=>console.error("[infinite-canvas] worker error:",o.message,o),r.postMessage({type:"init",data:{...t,canvas:n}},[n]);const i={worker:r};return On.set(e,i),i}const dt=160,tt=60,ro=10;function Rr({cards:e=[],nodes:t=[],edges:n=[],onHudUpdate:r,onNodesProcessed:i,onNodesChange:o,onEdgesChange:c,onConnect:h,onNodeClick:m,onNodeDragStart:f,onNodeDrag:y,onNodeDragStop:x,onEdgeClick:k,onEdgeDoubleClick:S,onEdgeMouseEnter:z,onEdgeMouseMove:W,onEdgeMouseLeave:j,onEdgeContextMenu:H,onNodeDoubleClick:F,onNodeMouseEnter:$,onNodeMouseMove:Y,onNodeMouseLeave:A,onNodeContextMenu:P,onPaneClick:Z,onPaneContextMenu:U,onPaneMouseEnter:X,onPaneMouseMove:M,onPaneMouseLeave:d,onSelectionChange:v,onConnectStart:L,onConnectEnd:T,onInit:B,onMoveStart:Q,onMove:ne,onMoveEnd:ee,onDelete:ae,onBeforeDelete:me,onError:we,isValidConnection:Re,dark:ce,gridSize:pe=40,zoomMin:oe=.1,zoomMax:ge=4,initialCamera:Se={x:0,y:0,zoom:1},fitView:De=!1,fitViewOptions:xe,nodesDraggable:fe=!0,nodesConnectable:Ae=!0,elementsSelectable:Fe=!0,multiSelectionKeyCode:Ye="Shift",selectionOnDrag:nt=!1,selectionMode:He="partial",connectionMode:$e="loose",connectionRadius:Le=20,connectOnClick:ze=!1,snapToGrid:Je=!1,snapGrid:rt=[15,15],deleteKeyCode:_e=["Delete","Backspace"],panActivationKeyCode:Ue=" ",panOnScroll:Ve=!1,panOnScrollMode:zt="free",panOnScrollSpeed:un=.5,zoomOnScroll:dn=!0,zoomOnDoubleClick:fn=!0,zoomOnPinch:hn=!0,preventScrolling:qt=!0,translateExtent:mt,nodeExtent:vt,defaultEdgeOptions:Pt={},autoPanOnNodeDrag:Nn=!0,autoPanOnConnect:In=!0,autoPanSpeed:ot=5,edgesReconnectable:lr=!1,elevateNodesOnSelect:Tn=!1,elevateEdgesOnSelect:Ln=!1,noDragClassName:Nt="nodrag",noPanClassName:It="nopan",onSelectionDragStart:Bn,onSelectionDrag:$n,onSelectionDragStop:An,edgeRouting:kt=!0}={}){const be=a.useRef(null),Tt=a.useRef(null),Pe=a.useRef(null),de=a.useRef({...Se}),bt=a.useRef([...e]),se=a.useRef([...t]),Ne=a.useRef([...n]),ft=a.useRef(null);if(!ft.current){const u=new Map;for(const g of se.current)u.set(g.id,g);ft.current=u}const gn=a.useRef(new Map),Lt=a.useRef(!1),ht=a.useRef(null),[jn,Dn]=a.useState(!1),Xe=a.useRef(null),Oe=a.useRef(null),Bt=a.useRef(null),gt=a.useRef(null),Ke=a.useRef(!1),$t=a.useRef(null),[Zt,yn]=a.useState({x:Se.x,y:Se.y,zoom:Se.zoom}),[xn,At]=a.useState(null),st=a.useMemo(()=>new Set,[]),qe=a.useMemo(()=>new Set,[]),wt=a.useRef(!1),V=a.useRef({});V.current={onHudUpdate:r,onNodesProcessed:i,onNodesChange:o,onEdgesChange:c,onConnect:h,onNodeClick:m,onNodeDragStart:f,onNodeDrag:y,onNodeDragStop:x,onEdgeClick:k,onEdgeDoubleClick:S,onEdgeMouseEnter:z,onEdgeMouseMove:W,onEdgeMouseLeave:j,onEdgeContextMenu:H,onNodeDoubleClick:F,onNodeMouseEnter:$,onNodeMouseMove:Y,onNodeMouseLeave:A,onNodeContextMenu:P,onPaneClick:Z,onPaneContextMenu:U,onPaneMouseEnter:X,onPaneMouseMove:M,onPaneMouseLeave:d,onSelectionChange:v,onConnectStart:L,onConnectEnd:T,onInit:B,onMoveStart:Q,onMove:ne,onMoveEnd:ee,onDelete:ae,onBeforeDelete:me,onError:we,onSelectionDragStart:Bn,onSelectionDrag:$n,onSelectionDragStop:An,isValidConnection:Re};const it={get current(){return V.current.onConnect}},jt={get current(){return V.current.onNodeClick}},Dt={get current(){return V.current.onNodeDragStart}},Ht={get current(){return V.current.onNodeDrag}},yt={get current(){return V.current.onNodeDragStop}},_t={get current(){return V.current.onEdgeClick}},Ct={get current(){return V.current.onPaneClick}},Wt={get current(){return V.current.onSelectionChange}},Ft={get current(){return V.current.onHudUpdate}},Yt={get current(){return V.current.onNodesProcessed}};a.useEffect(()=>{const u=l=>{l.key===Ye&&(Ke.current=!0),l.key===Ue&&(wt.current=!0)},g=l=>{l.key===Ye&&(Ke.current=!1),l.key===Ue&&(wt.current=!1)};return window.addEventListener("keydown",u),window.addEventListener("keyup",g),()=>{window.removeEventListener("keydown",u),window.removeEventListener("keyup",g)}},[Ye,Ue]);const ke={get current(){return V.current.onNodesChange?xt:null}},xt=u=>{var l,p,C;(p=(l=V.current).onNodesChange)==null||p.call(l,u);const g=[];for(let E=0;E<u.length;E++)u[E].type==="select"&&g.push({id:u[E].id,selected:u[E].selected});g.length>0&&((C=Pe.current)==null||C.postMessage({type:"nodeSelections",data:{selections:g}}))},We={get current(){return V.current.onEdgesChange?Hn:null}},Hn=u=>{var l,p,C;(p=(l=V.current).onEdgesChange)==null||p.call(l,u);const g=[];for(let E=0;E<u.length;E++)u[E].type==="select"&&g.push({id:u[E].id,selected:u[E].selected});g.length>0&&((C=Pe.current)==null||C.postMessage({type:"edgeSelections",data:{selections:g}}))},pt=a.useCallback(()=>{var p;const u=se.current.filter(C=>C.selected),g=Ne.current.filter(C=>C.selected),l={nodes:u,edges:g};(p=Wt.current)==null||p.call(Wt,l);for(const C of qe)C(l)},[qe]);a.useEffect(()=>{var u;bt.current=[...e],(u=Pe.current)==null||u.postMessage({type:"cards",data:{cards:[...e]}})},[e]);const Xt=a.useCallback(u=>{const g={};for(const l of u)g[l.id]=l;return u.map(l=>{if(!l.parentId)return l;const p=g[l.parentId];if(!p)return l;let C=l.position.x,E=l.position.y,w=p;for(;w;)C+=w.position.x,E+=w.position.y,w=w.parentId?g[w.parentId]:null;return{...l,_absolutePosition:{x:C,y:E}}})},[]),at=a.useRef([]),Mt=a.useCallback(u=>{const g=gn.current;if(!g||g.size===0)return u;const l={};for(const[,p]of g)l[p.nodeId]||(l[p.nodeId]=[]),l[p.nodeId].push({id:p.id,type:p.type,position:p.position,x:p.x,y:p.y});return u.map(p=>{const C=l[p.id];return C&&C.length>0?{...p,handles:C}:p})},[]),pn=a.useCallback(()=>{var g;if(Xe.current)return;const u=Mt(at.current);(g=Pe.current)==null||g.postMessage({type:"nodes",data:{nodes:u}})},[Mt]);a.useEffect(()=>{var l,p;if(Xe.current){const C=Xe.current.id,E=new Set([C,...Xe.current.selectedStarts.map(R=>R.id)]),w={};for(const R of se.current)E.has(R.id)&&(w[R.id]={...R.position});se.current=[...t];for(const R of se.current)w[R.id]&&(R.position=w[R.id]);{const R=ft.current;R.clear();for(const D of se.current)R.set(D.id,D)}at.current=Xt(se.current);const b=Mt(at.current);(l=Pe.current)==null||l.postMessage({type:"nodes",data:{nodes:b}});return}se.current=[...t];{const C=ft.current;C.clear();for(const E of se.current)C.set(E.id,E)}const u=Xt(t);at.current=u;const g=Mt(u);(p=Pe.current)==null||p.postMessage({type:"nodes",data:{nodes:g}})},[t,Xt,Mt]),a.useEffect(()=>{var u;Ne.current=[...n],(u=Pe.current)==null||u.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const Be=a.useCallback((u,g)=>{const l=be.current;if(!l)return{x:0,y:0};const p=l.getBoundingClientRect(),C=de.current;return{x:(u-p.left-C.x)/C.zoom,y:(g-p.top-C.y)/C.zoom}},[]),le=a.useCallback((u,g)=>{const l=at.current.length>0?at.current:se.current;let p=null;for(let C=l.length-1;C>=0;C--){const E=l[C];if(E.hidden||E._customRendered)continue;const w=E._absolutePosition||E.position,b=E.width||dt,R=E.height||tt;if(u>=w.x&&u<=w.x+b&&g>=w.y&&g<=w.y+R){if(E.type==="group"){p||(p=E);continue}return E}}return p},[]),Gt=a.useCallback((u,g)=>{const l=g.width||dt,p=g.height||tt;if(u.x!==void 0&&u.y!==void 0)return{x:g.position.x+u.x,y:g.position.y+u.y};switch(u.position||(u.type==="source"?"right":"left")){case"top":return{x:g.position.x+l/2,y:g.position.y};case"bottom":return{x:g.position.x+l/2,y:g.position.y+p};case"left":return{x:g.position.x,y:g.position.y+p/2};case"right":return{x:g.position.x+l,y:g.position.y+p/2};default:return{x:g.position.x+l,y:g.position.y+p/2}}},[]),Qt=a.useCallback(u=>{const g=u.width||dt,l=u.height||tt;if(u.handles&&u.handles.length>0)return u.handles.map(R=>{const D=Gt(R,u);return{id:R.id||null,type:R.type,x:D.x,y:D.y}});const p=u.targetPosition||"left",C=u.sourcePosition||"right",E=R=>{switch(R){case"top":return{x:u.position.x+g/2,y:u.position.y};case"bottom":return{x:u.position.x+g/2,y:u.position.y+l};case"left":return{x:u.position.x,y:u.position.y+l/2};case"right":return{x:u.position.x+g,y:u.position.y+l/2};default:return{x:u.position.x+g,y:u.position.y+l/2}}},w=E(p),b=E(C);return[{id:null,type:"target",x:w.x,y:w.y},{id:null,type:"source",x:b.x,y:b.y}]},[Gt]),Rt=a.useCallback((u,g)=>{const l=se.current,p=de.current,C=Math.max(ro,Le)/p.zoom;for(let E=l.length-1;E>=0;E--){const w=l[E];if(w.hidden)continue;const b=Qt(w);for(const R of b)if(Math.abs(u-R.x)<C&&Math.abs(g-R.y)<C)return{nodeId:w.id,handleId:R.id,type:R.type,x:R.x,y:R.y}}return null},[Qt]),Ze=a.useCallback((u,g)=>{const p=8/de.current.zoom,C=ft.current;for(let E=Ne.current.length-1;E>=0;E--){const w=Ne.current[E],b=C.get(w.source),R=C.get(w.target);if(!b||!R)continue;const D=b.width||dt,N=b.height||tt,q=R.height||tt,J=b.position.x+D,O=b.position.y+N/2,ie=R.position.x,Ie=R.position.y+q/2;if(oo(u,g,J,O,ie,Ie)<p)return w}return null},[]);a.useEffect(()=>{const u=Tt.current,g=be.current;if(!u||!g)return;const l=g.getBoundingClientRect(),p=ce!==void 0?ce:matchMedia("(prefers-color-scheme: dark)").matches,C=Xt(se.current);at.current=C;const E=Mt(C),{worker:w}=no(u,{width:l.width,height:l.height,camera:de.current,cards:bt.current,nodes:E,edges:Ne.current,dark:p,gridSize:pe,edgeRouting:kt});w.onmessage=N=>{var q,J,O,ie;N.data.type==="hud"&&((q=Ft.current)==null||q.call(Ft,N.data.data)),N.data.type==="ready"&&Dn(!0),N.data.type==="nodesProcessed"&&((J=Yt.current)==null||J.call(Yt,N.data.data)),N.data.type==="error"&&((ie=(O=V.current).onError)==null||ie.call(O,"worker-error",N.data.message||"Canvas worker error"))},w.onerror=N=>{var q,J;(J=(q=V.current).onError)==null||J.call(q,"worker-error",N.message||"Canvas worker crashed")},Pe.current=w;const b=new ResizeObserver(N=>{const{width:q,height:J}=N[0].contentRect;w.postMessage({type:"resize",data:{width:q,height:J}})});b.observe(g);let R,D;return ce===void 0&&(R=matchMedia("(prefers-color-scheme: dark)"),D=N=>w.postMessage({type:"theme",data:{dark:N.matches}}),R.addEventListener("change",D)),()=>{b.disconnect(),R&&D&&R.removeEventListener("change",D),Pe.current=null}},[]),a.useEffect(()=>{var u;ce!==void 0&&((u=Pe.current)==null||u.postMessage({type:"theme",data:{dark:ce}}))},[ce]),a.useEffect(()=>{var u;(u=Pe.current)==null||u.postMessage({type:"edgeRouting",data:{enabled:kt}})},[kt]);const Jt=a.useRef(0),Me=a.useCallback((u=null)=>{var p,C,E;const g=de.current;if(mt){const w=be.current;if(w){const b=w.getBoundingClientRect(),R=-mt[1][0]*g.zoom+b.width,D=-mt[1][1]*g.zoom+b.height,N=-mt[0][0]*g.zoom,q=-mt[0][1]*g.zoom;g.x=Math.min(N,Math.max(R,g.x)),g.y=Math.min(q,Math.max(D,g.y))}}(p=Pe.current)==null||p.postMessage({type:"camera",data:{camera:{...g}}});const l={x:g.x,y:g.y,zoom:g.zoom};(E=(C=V.current).onMove)==null||E.call(C,u,l);for(const w of st)w(l);cancelAnimationFrame(Jt.current),Jt.current=requestAnimationFrame(()=>{yn({x:g.x,y:g.y,zoom:g.zoom})})},[st,mt]),ct=a.useCallback(()=>{var l,p;const u=Oe.current,g=Bt.current;u&&g?((l=Pe.current)==null||l.postMessage({type:"connecting",data:{from:u.startPos,to:g,_routedPoints:null}}),At({source:u.sourceId,sourceHandle:u.sourceHandle,target:null,targetHandle:null})):((p=Pe.current)==null||p.postMessage({type:"connecting",data:null}),At(null))},[]),lt=a.useCallback(()=>{var g,l;const u=gt.current;u?(g=Pe.current)==null||g.postMessage({type:"selectionBox",data:u}):(l=Pe.current)==null||l.postMessage({type:"selectionBox",data:null})},[]),Vt=a.useCallback(u=>{var w,b,R,D,N,q,J,O,ie,Ie,te,ue,Ee,je,et,Ge,ut,en;const g=se.current.length>0,l=Be(u.clientX,u.clientY),p=Ke.current;if(g&&Ae&&!p){const G=Rt(l.x,l.y);if(ze&&$t.current&&G){const re=$t.current;if(G.nodeId!==re.nodeId){const Qe=re.handleType==="target"?{source:G.nodeId,target:re.nodeId,sourceHandle:G.handleId||null,targetHandle:re.handleId}:{source:re.nodeId,target:G.nodeId,sourceHandle:re.handleId,targetHandle:G.handleId||null};(V.current.isValidConnection?V.current.isValidConnection(Qe):!0)&&((w=it.current)==null||w.call(it,{...Qe,...Pt}))}$t.current=null;return}if($e==="strict"?G&&G.type==="source":G!=null){if(ze){$t.current={nodeId:G.nodeId,handleId:G.handleId||null,handleType:G.type},(R=(b=V.current).onConnectStart)==null||R.call(b,u,{nodeId:G.nodeId,handleId:G.handleId,handleType:G.type});return}Oe.current={sourceId:G.nodeId,sourceHandle:G.handleId||null,sourceType:G.type,startPos:{x:G.x,y:G.y}},Bt.current={x:l.x,y:l.y},(D=be.current)==null||D.setPointerCapture(u.pointerId),(q=(N=V.current).onConnectStart)==null||q.call(N,u,{nodeId:G.nodeId,handleId:G.handleId,handleType:G.type}),ct();return}}const C=G=>{var re;let he=G;for(;he&&he!==be.current;){if((re=he.classList)!=null&&re.contains(Nt))return!0;he=he.parentElement}return!1},E=G=>{var re;let he=G;for(;he&&he!==be.current;){if((re=he.classList)!=null&&re.contains(It))return!0;he=he.parentElement}return!1};if(g){const G=le(l.x,l.y);if(G){if(ke.current&&Fe){const he=[];if(p)he.push({id:G.id,type:"select",selected:!G.selected});else if(!G.selected){for(const re of se.current)re.id===G.id?he.push({id:re.id,type:"select",selected:!0}):re.selected&&he.push({id:re.id,type:"select",selected:!1});if(We.current){const re=Ne.current.filter(ye=>ye.selected).map(ye=>({id:ye.id,type:"select",selected:!1}));re.length&&We.current(re)}}if(he.length){if(ke.current(he),Tn&&!p){const re=se.current.findIndex(ye=>ye.id===G.id);re>=0&&re<se.current.length-1&&ke.current([{id:G.id,type:"remove"},{type:"add",item:{...se.current[re],selected:!0}}])}pt()}}if((J=jt.current)==null||J.call(jt,u,G),fe&&!C(u.target)){const he=G.selected;let re=null;if(G.parentId&&G.extent==="parent"){const ye=se.current.find(Qe=>Qe.id===G.parentId);if(ye){const Qe=ye.width||dt,tn=ye.height||tt,vn=G.width||((O=G.measured)==null?void 0:O.width)||dt,nn=G.height||((ie=G.measured)==null?void 0:ie.height)||tt;re={minX:0,minY:0,maxX:Qe-vn,maxY:tn-nn}}}if(Xe.current={id:G.id,startPos:{...G.position},startMouse:{x:l.x,y:l.y},parentClamp:re,parentId:G.parentId||null,selectedStarts:he?se.current.filter(ye=>ye.selected&&ye.id!==G.id).map(ye=>{var tn,vn;let Qe=null;if(ye.parentId&&ye.extent==="parent"){const nn=se.current.find(Xn=>Xn.id===ye.parentId);if(nn){const Xn=nn.width||dt,Fr=nn.height||tt,Yr=ye.width||((tn=ye.measured)==null?void 0:tn.width)||dt,Xr=ye.height||((vn=ye.measured)==null?void 0:vn.height)||tt;Qe={minX:0,minY:0,maxX:Xn-Yr,maxY:Fr-Xr}}}return{id:ye.id,startPos:{...ye.position},parentClamp:Qe,parentId:ye.parentId||null}}):[]},(Ie=be.current)==null||Ie.setPointerCapture(u.pointerId),(te=Dt.current)==null||te.call(Dt,u,G),Xe.current.selectedStarts.length>0){const ye=se.current.filter(Qe=>Qe.selected);(Ee=(ue=V.current).onSelectionDragStart)==null||Ee.call(ue,u,ye)}if(ke.current){const ye=[{id:G.id,type:"position",dragging:!0}];for(const Qe of Xe.current.selectedStarts)ye.push({id:Qe.id,type:"position",dragging:!0});ke.current(ye)}}return}}if(Ne.current.length>0&&Fe){const G=Ze(l.x,l.y);if(G){if(We.current){const he=[];if(p)he.push({id:G.id,type:"select",selected:!G.selected});else{for(const re of Ne.current)re.id===G.id?he.push({id:re.id,type:"select",selected:!0}):re.selected&&he.push({id:re.id,type:"select",selected:!1});if(ke.current){const re=se.current.filter(ye=>ye.selected).map(ye=>({id:ye.id,type:"select",selected:!1}));re.length&&ke.current(re)}}if(he.length){if(We.current(he),Ln&&!p){const re=Ne.current.findIndex(ye=>ye.id===G.id);re>=0&&re<Ne.current.length-1&&We.current([{id:G.id,type:"remove"},{type:"add",item:{...Ne.current[re],selected:!0}}])}pt()}}(je=_t.current)==null||je.call(_t,u,G);return}}if(!p){const G=se.current.filter(re=>re.selected).map(re=>({id:re.id,type:"select",selected:!1})),he=Ne.current.filter(re=>re.selected).map(re=>({id:re.id,type:"select",selected:!1}));G.length&&ke.current&&ke.current(G),he.length&&We.current&&We.current(he),(G.length||he.length)&&pt()}if((et=Ct.current)==null||et.call(Ct,u),nt||p){gt.current={startWorld:{...l},endWorld:{...l}},(Ge=be.current)==null||Ge.setPointerCapture(u.pointerId),lt();return}E(u.target)||(Lt.current=!0,ht.current={x:u.clientX,y:u.clientY},(ut=be.current)==null||ut.classList.add("dragging"),(en=be.current)==null||en.setPointerCapture(u.pointerId))},[Be,le,Rt,Ze,fe,Ae,Fe,nt,ct,lt,pt,Nt,It]),Kt=a.useCallback(u=>{var l,p,C,E;if(Oe.current){if(Bt.current=Be(u.clientX,u.clientY),ct(),In){const w=be.current;if(w){const b=w.getBoundingClientRect(),R=40,D=u.clientX-b.left,N=u.clientY-b.top;let q=0,J=0;D<R?q=ot:D>b.width-R&&(q=-ot),N<R?J=ot:N>b.height-R&&(J=-ot),(q||J)&&(de.current.x+=q,de.current.y+=J,Me(u))}}return}if(gt.current){gt.current.endWorld=Be(u.clientX,u.clientY),lt();const w=gt.current,b=Math.min(w.startWorld.x,w.endWorld.x),R=Math.min(w.startWorld.y,w.endWorld.y),D=Math.max(w.startWorld.x,w.endWorld.x),N=Math.max(w.startWorld.y,w.endWorld.y);if(ke.current){const q=[];for(const J of se.current){if(J.hidden)continue;const O=J.width||dt,ie=J.height||tt,Ie=He==="full"?J.position.x>=b&&J.position.x+O<=D&&J.position.y>=R&&J.position.y+ie<=N:J.position.x+O>b&&J.position.x<D&&J.position.y+ie>R&&J.position.y<N;Ie!==!!J.selected&&q.push({id:J.id,type:"select",selected:Ie})}q.length&&ke.current(q)}return}if(Xe.current){const w=Be(u.clientX,u.clientY),b=Xe.current,R=w.x-b.startMouse.x,D=w.y-b.startMouse.y;let N={x:b.startPos.x+R,y:b.startPos.y+D};if(Je&&(N=Gn(N,rt)),vt&&(N=Qn(N,vt)),b.parentClamp){const te=b.parentClamp;N={x:Math.max(te.minX,Math.min(N.x,te.maxX)),y:Math.max(te.minY,Math.min(N.y,te.maxY))}}const q=[{id:b.id,position:N}];for(const te of b.selectedStarts){let ue={x:te.startPos.x+R,y:te.startPos.y+D};if(Je&&(ue=Gn(ue,rt)),vt&&(ue=Qn(ue,vt)),te.parentClamp){const Ee=te.parentClamp;ue={x:Math.max(Ee.minX,Math.min(ue.x,Ee.maxX)),y:Math.max(Ee.minY,Math.min(ue.y,Ee.maxY))}}q.push({id:te.id,position:ue})}const J=[],O=ft.current;for(const te of q){const ue=O.get(te.id);if(ue){ue.position=te.position,ue.dragging=!0;let Ee=te.position;if(ue.parentId){let je=O.get(ue.parentId),et=te.position.x,Ge=te.position.y;for(;je;)et+=je.position.x,Ge+=je.position.y,je=je.parentId?O.get(je.parentId):null;Ee={x:et,y:Ge}}J.push({id:te.id,position:te.position,_absolutePosition:Ee,width:ue.width,height:ue.height,dragging:!0,selected:ue.selected})}}const ie=new Set(q.map(te=>te.id));for(const te of se.current)if(te.parentId&&ie.has(te.parentId)&&!ie.has(te.id)){let ue=O.get(te.parentId),Ee=te.position.x,je=te.position.y;for(;ue;)Ee+=ue.position.x,je+=ue.position.y,ue=ue.parentId?O.get(ue.parentId):null;J.push({id:te.id,position:te.position,_absolutePosition:{x:Ee,y:je},width:te.width,height:te.height,dragging:!1,selected:te.selected})}if((l=Pe.current)==null||l.postMessage({type:"nodePositions",data:{updates:J}}),Nn){const te=be.current;if(te){const ue=te.getBoundingClientRect(),Ee=40,je=u.clientX-ue.left,et=u.clientY-ue.top;let Ge=0,ut=0;je<Ee?Ge=ot:je>ue.width-Ee&&(Ge=-ot),et<Ee?ut=ot:et>ue.height-Ee&&(ut=-ot),(Ge||ut)&&(de.current.x+=Ge,de.current.y+=ut,Me(u))}}const Ie=O.get(b.id);if(Ie&&((p=Ht.current)==null||p.call(Ht,u,Ie)),b.selectedStarts.length>0){const te=[];for(const ue of b.selectedStarts){const Ee=O.get(ue.id);Ee&&te.push(Ee)}Ie&&te.push(Ie),(E=(C=V.current).onSelectionDrag)==null||E.call(C,u,te)}return}if(!Lt.current)return;const g=de.current;g.x+=u.clientX-ht.current.x,g.y+=u.clientY-ht.current.y,ht.current={x:u.clientX,y:u.clientY},Me()},[Me,Be,ct,lt]),mn=a.useCallback(u=>{var g,l,p,C,E,w,b,R;if(Oe.current){const D=Be(u.clientX,u.clientY),N=Rt(D.x,D.y);if(N&&N.nodeId!==Oe.current.sourceId&&($e==="loose"||N.type==="target")){const O=Oe.current.sourceType==="target"?{source:N.nodeId,target:Oe.current.sourceId,sourceHandle:N.handleId||null,targetHandle:Oe.current.sourceHandle}:{source:Oe.current.sourceId,target:N.nodeId,sourceHandle:Oe.current.sourceHandle,targetHandle:N.handleId||null};(V.current.isValidConnection?V.current.isValidConnection(O):!0)&&((g=it.current)==null||g.call(it,{...O,...Pt}))}(p=(l=V.current).onConnectEnd)==null||p.call(l,u.nativeEvent||u),Oe.current=null,Bt.current=null,ct();return}if(gt.current){gt.current=null,lt(),pt();return}if(Xe.current){const D=Xe.current,N=se.current.find(O=>O.id===D.id),q=[{id:D.id,position:N?{...N.position}:D.startPos,_absolutePosition:N?{...N.position}:D.startPos,dragging:!1}];for(const O of D.selectedStarts){const ie=se.current.find(Ie=>Ie.id===O.id);q.push({id:O.id,position:ie?{...ie.position}:O.startPos,_absolutePosition:ie?{...ie.position}:O.startPos,dragging:!1})}if((C=Pe.current)==null||C.postMessage({type:"nodePositions",data:{updates:q}}),ke.current){const O=q.map(ie=>({id:ie.id,type:"position",position:ie.position,dragging:!1}));ke.current(O)}if(D.selectedStarts.length>0){const O=se.current.filter(ie=>ie.selected);(w=(E=V.current).onSelectionDragStop)==null||w.call(E,u,O)}requestAnimationFrame(()=>{Xe.current=null});const J=se.current.find(O=>O.id===D.id);J&&((b=yt.current)==null||b.call(yt,u,J));return}Lt.current=!1,(R=be.current)==null||R.classList.remove("dragging")},[Be,Rt,ct,lt,pt]);a.useEffect(()=>{const u=be.current;if(!u)return;const g=l=>{qt&&l.preventDefault();const p=de.current;if(Ve||wt.current){const R=un;zt==="horizontal"?p.x-=l.deltaY*R:(zt==="vertical"||(p.x-=l.deltaX*R),p.y-=l.deltaY*R),Me(l);return}if(!dn)return;const C=l.deltaY>0?.92:1.08,E=u.getBoundingClientRect(),w=l.clientX-E.left,b=l.clientY-E.top;p.x=w-(w-p.x)*C,p.y=b-(b-p.y)*C,p.zoom=Math.min(ge,Math.max(oe,p.zoom*C)),Me(l)};return u.addEventListener("wheel",g,{passive:!qt}),()=>u.removeEventListener("wheel",g)},[Me,oe,ge,Ve,zt,un,dn,qt]),a.useEffect(()=>{if(!hn)return;const u=be.current;if(!u)return;let g=0,l=null;const p=w=>{if(w.touches.length===2){const b=w.touches[0].clientX-w.touches[1].clientX,R=w.touches[0].clientY-w.touches[1].clientY;g=Math.hypot(b,R);const D=u.getBoundingClientRect();l={x:(w.touches[0].clientX+w.touches[1].clientX)/2-D.left,y:(w.touches[0].clientY+w.touches[1].clientY)/2-D.top},w.preventDefault()}},C=w=>{if(w.touches.length===2&&g>0){w.preventDefault();const b=w.touches[0].clientX-w.touches[1].clientX,R=w.touches[0].clientY-w.touches[1].clientY,D=Math.hypot(b,R),N=D/g;g=D;const q=de.current,J=l.x,O=l.y;q.x=J-(J-q.x)*N,q.y=O-(O-q.y)*N,q.zoom=Math.min(ge,Math.max(oe,q.zoom*N)),Me(w)}},E=()=>{g=0,l=null};return u.addEventListener("touchstart",p,{passive:!1}),u.addEventListener("touchmove",C,{passive:!1}),u.addEventListener("touchend",E),()=>{u.removeEventListener("touchstart",p),u.removeEventListener("touchmove",C),u.removeEventListener("touchend",E)}},[hn,Me,oe,ge]),a.useEffect(()=>{if(!fn)return;const u=be.current;if(!u)return;const g=l=>{var N,q,J,O;const p=Be(l.clientX,l.clientY);if(le(p.x,p.y)){(q=(N=V.current).onNodeDoubleClick)==null||q.call(N,l,le(p.x,p.y));return}const C=Ze(p.x,p.y);if(C){(O=(J=V.current).onEdgeDoubleClick)==null||O.call(J,l,C);return}const E=1.5,w=u.getBoundingClientRect(),b=l.clientX-w.left,R=l.clientY-w.top,D=de.current;D.x=b-(b-D.x)*E,D.y=R-(R-D.y)*E,D.zoom=Math.min(ge,Math.max(oe,D.zoom*E)),Me(l)};return u.addEventListener("dblclick",g),()=>u.removeEventListener("dblclick",g)},[fn,Me,oe,ge,Be,le,Ze]),a.useEffect(()=>{const u=be.current;if(!u)return;const g=l=>{var w,b,R,D,N,q;const p=Be(l.clientX,l.clientY),C=le(p.x,p.y);if(C){(b=(w=V.current).onNodeContextMenu)==null||b.call(w,l,C);return}const E=Ze(p.x,p.y);if(E){(D=(R=V.current).onEdgeContextMenu)==null||D.call(R,l,E);return}(q=(N=V.current).onPaneContextMenu)==null||q.call(N,l)};return u.addEventListener("contextmenu",g),()=>u.removeEventListener("contextmenu",g)},[Be,le,Ze]),a.useEffect(()=>{const u=be.current;if(!u)return;let g=null,l=null,p=0;const C=b=>{var q,J,O,ie,Ie,te,ue,Ee,je,et,Ge,ut,en,G;if((J=(q=V.current).onPaneMouseMove)==null||J.call(q,b),Lt.current||Xe.current||Oe.current||gt.current)return;const R=performance.now();if(R-p<32)return;p=R;const D=Be(b.clientX,b.clientY),N=le(D.x,D.y);if(N!==g&&(g&&((ie=(O=V.current).onNodeMouseLeave)==null||ie.call(O,b,g)),N&&((te=(Ie=V.current).onNodeMouseEnter)==null||te.call(Ie,b,N)),g=N),N&&((Ee=(ue=V.current).onNodeMouseMove)==null||Ee.call(ue,b,N)),!N){const he=Ze(D.x,D.y);he!==l&&(l&&((et=(je=V.current).onEdgeMouseLeave)==null||et.call(je,b,l)),he&&((ut=(Ge=V.current).onEdgeMouseEnter)==null||ut.call(Ge,b,he)),l=he),he&&((G=(en=V.current).onEdgeMouseMove)==null||G.call(en,b,he))}},E=b=>{var R,D;return(D=(R=V.current).onPaneMouseEnter)==null?void 0:D.call(R,b)},w=b=>{var R,D,N,q,J,O;(D=(R=V.current).onPaneMouseLeave)==null||D.call(R,b),g&&((q=(N=V.current).onNodeMouseLeave)==null||q.call(N,b,g),g=null),l&&((O=(J=V.current).onEdgeMouseLeave)==null||O.call(J,b,l),l=null)};return u.addEventListener("mousemove",C),u.addEventListener("mouseenter",E),u.addEventListener("mouseleave",w),()=>{u.removeEventListener("mousemove",C),u.removeEventListener("mouseenter",E),u.removeEventListener("mouseleave",w)}},[Be,le,Ze]),a.useEffect(()=>{const u=Array.isArray(_e)?_e:[_e],g=async l=>{var p,C,E,w;if(u.includes(l.key)){if(l.target.tagName==="INPUT"||l.target.tagName==="TEXTAREA"||l.target.isContentEditable)return;const b=se.current.filter(N=>N.selected),R=Ne.current.filter(N=>N.selected);if(!b.length&&!R.length)return;if(V.current.onBeforeDelete)try{if(!await V.current.onBeforeDelete({nodes:b,edges:R}))return}catch(N){(C=(p=V.current).onError)==null||C.call(p,"before-delete-error",N.message||"onBeforeDelete threw an error");return}const D=new Set(b.map(N=>N.id));if(b.length&&ke.current&&(ke.current(b.map(N=>({id:N.id,type:"remove"}))),We.current)){const N=Ne.current.filter(q=>D.has(q.source)||D.has(q.target));N.length&&We.current(N.map(q=>({id:q.id,type:"remove"})))}R.length&&We.current&&We.current(R.map(N=>({id:N.id,type:"remove"}))),(w=(E=V.current).onDelete)==null||w.call(E,{nodes:b,edges:R})}if((l.ctrlKey||l.metaKey)&&l.key==="a"){if(l.target.tagName==="INPUT"||l.target.tagName==="TEXTAREA")return;if(l.preventDefault(),ke.current){const b=se.current.filter(R=>!R.selected).map(R=>({id:R.id,type:"select",selected:!0}));b.length&&ke.current(b)}if(We.current){const b=Ne.current.filter(R=>!R.selected).map(R=>({id:R.id,type:"select",selected:!0}));b.length&&We.current(b)}}};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[_e]);const Ot=a.useRef(!1);a.useEffect(()=>{var u,g;if(!Ot.current&&Pe.current){if(Ot.current=!0,De&&se.current.length>0){const l=be.current;if(l){const p=l.getBoundingClientRect(),C=(xe==null?void 0:xe.padding)??.1,E=Mn(se.current),w=Ut(E,p.width,p.height,C);xe!=null&&xe.maxZoom&&(w.zoom=Math.min(w.zoom,xe.maxZoom)),xe!=null&&xe.minZoom&&(w.zoom=Math.max(w.zoom,xe.minZoom)),de.current=w,Me()}}(g=(u=V.current).onInit)==null||g.call(u,{getNodes:()=>[...se.current],getEdges:()=>[...Ne.current],getNode:l=>ft.current.get(l),getEdge:l=>Ne.current.find(p=>p.id===l),getViewport:()=>({...de.current}),getZoom:()=>de.current.zoom,setViewport:l=>{de.current={x:l.x??de.current.x,y:l.y??de.current.y,zoom:l.zoom??de.current.zoom},Me()},fitView:(l={})=>{const p=be.current;if(!p||!se.current.length)return;const C=p.getBoundingClientRect(),E=l.nodes?se.current.filter(R=>l.nodes.some(D=>D.id===R.id)):se.current;if(!E.length)return;const w=Mn(E),b=Ut(w,C.width,C.height,l.padding??.1);l.maxZoom&&(b.zoom=Math.min(b.zoom,l.maxZoom)),l.minZoom&&(b.zoom=Math.max(b.zoom,l.minZoom)),de.current=b,Me()},screenToFlowPosition:l=>Be(l.x,l.y),flowToScreenPosition:l=>{const p=de.current,C=be.current;if(!C)return{x:0,y:0};const E=C.getBoundingClientRect();return{x:l.x*p.zoom+p.x+E.left,y:l.y*p.zoom+p.y+E.top}},zoomIn:()=>{const l=de.current;l.zoom=Math.min(ge,l.zoom*1.2),Me()},zoomOut:()=>{const l=de.current;l.zoom=Math.max(oe,l.zoom/1.2),Me()},zoomTo:l=>{de.current.zoom=Math.min(ge,Math.max(oe,l)),Me()},setNodes:l=>{var p,C;(C=(p=V.current).onNodesChange)==null||C.call(p,[...se.current.map(E=>({id:E.id,type:"remove"})),...(typeof l=="function"?l(se.current):l).map(E=>({type:"add",item:E}))])},setEdges:l=>{var p,C;(C=(p=V.current).onEdgesChange)==null||C.call(p,[...Ne.current.map(E=>({id:E.id,type:"remove"})),...(typeof l=="function"?l(Ne.current):l).map(E=>({type:"add",item:E}))])},addNodes:l=>{var C,E;const p=Array.isArray(l)?l:[l];(E=(C=V.current).onNodesChange)==null||E.call(C,p.map(w=>({type:"add",item:w})))},addEdges:l=>{var C,E;const p=Array.isArray(l)?l:[l];(E=(C=V.current).onEdgesChange)==null||E.call(C,p.map(w=>({type:"add",item:w})))},deleteElements:({nodes:l=[],edges:p=[]})=>{var C,E,w,b;l.length&&((E=(C=V.current).onNodesChange)==null||E.call(C,l.map(R=>({id:R.id,type:"remove"})))),p.length&&((b=(w=V.current).onEdgesChange)==null||b.call(w,p.map(R=>({id:R.id,type:"remove"}))))},updateNodeData:(l,p)=>{var w,b;const C=se.current.find(R=>R.id===l);if(!C)return;const E=typeof p=="function"?p(C.data):{...C.data,...p};(b=(w=V.current).onNodesChange)==null||b.call(w,[{id:l,type:"replace",item:{...C,data:E}}])},toObject:()=>({nodes:[...se.current],edges:[...Ne.current],viewport:{...de.current}}),setCenter:(l,p,C={})=>{const E=be.current;if(!E)return;const w=E.getBoundingClientRect(),b=C.zoom??de.current.zoom;de.current={x:w.width/2-l*b,y:w.height/2-p*b,zoom:b},Me()},fitBounds:(l,p={})=>{const C=be.current;if(!C)return;const E=C.getBoundingClientRect(),w=Ut(l,E.width,E.height,p.padding??.1);de.current=w,Me()}})}});const _n=a.useCallback(()=>{de.current={...Se},Me()},[Me,Se]),Wn=a.useCallback(u=>{var g;if(u)bt.current.push(u);else{const l=de.current,p=be.current;if(!p)return;const C=p.getBoundingClientRect(),E=Math.round(-l.x/l.zoom+C.width/2/l.zoom),w=Math.round(-l.y/l.zoom+C.height/2/l.zoom);bt.current.push({x:E-80,y:w-45,w:160,h:90,title:"Note "+(bt.current.length+1),body:"Added at viewport center"})}(g=Pe.current)==null||g.postMessage({type:"cards",data:{cards:[...bt.current]}})},[]),Fn=a.useCallback(u=>{if(u.id||(u.id="node-"+Date.now()),!u.position){const g=de.current,l=be.current;if(!l)return;const p=l.getBoundingClientRect();u.position={x:Math.round(-g.x/g.zoom+p.width/2/g.zoom)-dt/2,y:Math.round(-g.y/g.zoom+p.height/2/g.zoom)-tt/2}}u.data||(u.data={label:u.id}),ke.current&&ke.current([{type:"add",item:u}])},[]),Yn=a.useCallback(()=>({...de.current}),[]),_=a.useCallback(u=>{de.current={...de.current,...u},Me()},[Me]),ve=a.useCallback(u=>Be(u.x,u.y),[Be]),K=n,Ce=a.useMemo(()=>({wrapRef:be,canvasRef:Tt,workerRef:Pe,cameraRef:de,nodesRef:se,edgesRef:Ne,handleRegistryRef:gn,syncNodesToWorker:pn,onNodesChangeRef:ke,onEdgesChangeRef:We,sendCamera:Me,screenToWorld:Be,viewportListeners:st,selectionListeners:qe,zoomMin:oe,zoomMax:ge,snapToGrid:Je,snapGrid:rt,nodeExtent:vt,defaultEdgeOptions:Pt,edgeRouting:kt,resolvedNodesRef:at,noDragClassName:Nt,noPanClassName:It,get nodes(){return t},get edges(){return n},get routedEdges(){return K},get viewport(){return Zt},get connection(){return xn}}),[t,n,K,Zt,xn,Me,Be,pn,st,qe,oe,ge,Je,rt,vt,Pt,kt,Nt,It]);return{wrapRef:be,canvasRef:Tt,canvasReady:jn,onPointerDown:Vt,onPointerMove:Kt,onPointerUp:mn,resetView:_n,addCard:Wn,addNode:Fn,getCamera:Yn,setCamera:_,screenToFlowPosition:ve,store:Ce}}function oo(e,t,n,r,i,o){const c=i-n,h=o-r,m=c*c+h*h;if(m===0)return Math.hypot(e-n,t-r);let f=((e-n)*c+(t-r)*h)/m;return f=Math.max(0,Math.min(1,f)),Math.hypot(e-(n+f*c),t-(r+f*h))}const dr=e=>{let t;const n=new Set,r=(f,y)=>{const x=typeof f=="function"?f(t):f;if(!Object.is(x,t)){const k=t;t=y??(typeof x!="object"||x===null)?x:Object.assign({},t,x),n.forEach(S=>S(t,k))}},i=()=>t,h={setState:r,getState:i,getInitialState:()=>m,subscribe:f=>(n.add(f),()=>n.delete(f))},m=t=e(r,i,h);return h},so=(e=>e?dr(e):dr),io=e=>e;function ao(e,t=io){const n=a.useSyncExternalStore(e.subscribe,a.useCallback(()=>t(e.getState()),[e,t]),a.useCallback(()=>t(e.getInitialState()),[e,t]));return a.useDebugValue(n),n}const St=a.createContext(null);function co(e={}){return so((t,n)=>({nodes:[],edges:[],viewport:{x:0,y:0,zoom:1},connection:null,minZoom:.1,maxZoom:5,width:0,height:0,domNode:null,nodesRef:{current:[]},edgesRef:{current:[]},cameraRef:{current:{x:0,y:0,zoom:1}},wrapRef:{current:null},workerRef:{current:null},onNodesChangeRef:{current:null},onEdgesChangeRef:{current:null},viewportListeners:new Set,selectionListeners:new Set,edgeLabelContainerRef:{current:null},viewportPortalRef:{current:null},screenToWorld:(r,i)=>{const o=n().cameraRef.current;return{x:(r-o.x)/o.zoom,y:(i-o.y)/o.zoom}},sendCamera:()=>{var i;const r=n();(i=r.workerRef.current)==null||i.postMessage({type:"camera",data:{camera:{...r.cameraRef.current}}})},...e}))}function Te(e,t){const n=a.useContext(St);if(!n)throw new Error("useCanvasStore must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");const r=typeof n.getState=="function"&&typeof n.subscribe=="function",i=a.useRef(e),o=a.useRef(t),c=a.useRef(void 0);i.current=e,o.current=t;const h=a.useCallback(m=>{const f=i.current;if(!f)return m;const y=f(m),x=o.current||Object.is;return c.current!==void 0&&x(c.current,y)?c.current:(c.current=y,y)},[]);return r?ao(n,e?h:void 0):e?h(n):n}function kr(){const e=a.useContext(St);if(!e)throw new Error("useCanvasStoreApi must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");return typeof e.getState=="function"?e:{getState:()=>e,setState:()=>{},subscribe:()=>()=>{}}}const cn=a.createContext(null);function lo(){return a.useContext(cn)}function uo({node:e,nodeType:t}){var z,W,j,H;const n=Te(),r=a.useRef(n);r.current=n;const i=a.useRef(null),o=e._absolutePosition||e.position,c=a.useRef(null);a.useEffect(()=>{const F=i.current;if(!F)return;const $=new ResizeObserver(Y=>{var Z,U,X,M;const{width:A,height:P}=Y[0].contentRect;if(A>0&&P>0){const d=r.current,v=d.nodesRef.current.find(B=>B.id===e.id),L=(v==null?void 0:v.width)||((Z=v==null?void 0:v.measured)==null?void 0:Z.width),T=(v==null?void 0:v.height)||((U=v==null?void 0:v.measured)==null?void 0:U.height);(Math.abs((L||0)-A)>1||Math.abs((T||0)-P)>1)&&((M=(X=d.onNodesChangeRef).current)==null||M.call(X,[{id:e.id,type:"dimensions",dimensions:{width:A,height:P},setAttributes:!0}]))}});return $.observe(F),()=>$.disconnect()},[e.id]);const h=a.useCallback(F=>{var ae,me,we,Re;F.stopPropagation();const $=F.target.tagName;if($==="INPUT"||$==="TEXTAREA"||$==="SELECT"||$==="BUTTON"||$==="A"||$==="LABEL"||F.target.isContentEditable)return;const Y=r.current.noDragClassName||"nodrag",A=r.current.noPanClassName||"nopan";let P=F.target;for(;P&&P!==i.current;){if((ae=P.classList)!=null&&ae.contains(Y)||(me=P.classList)!=null&&me.contains(A))return;P=P.parentElement}if(r.current.onNodesChangeRef.current){const ce=[];if(F.shiftKey)ce.push({id:e.id,type:"select",selected:!e.selected});else for(const oe of r.current.nodesRef.current)oe.id===e.id&&!oe.selected?ce.push({id:oe.id,type:"select",selected:!0}):oe.id!==e.id&&oe.selected&&ce.push({id:oe.id,type:"select",selected:!1});ce.length&&r.current.onNodesChangeRef.current(ce)}const Z=r.current.cameraRef.current,U=r.current.wrapRef.current;if(!U)return;const X=U.getBoundingClientRect(),M=(F.clientX-X.left-Z.x)/Z.zoom,d=(F.clientY-X.top-Z.y)/Z.zoom,L=e.selected?r.current.nodesRef.current.filter(ce=>ce.selected&&ce.id!==e.id).map(ce=>({id:ce.id,startPos:{...ce.position}})):[];c.current={startPos:{...e.position},startMouse:{x:M,y:d},selectedStarts:L};const T=[{id:e.id,type:"position",dragging:!0}];for(const ce of L)T.push({id:ce.id,type:"position",dragging:!0});(Re=(we=r.current.onNodesChangeRef).current)==null||Re.call(we,T);const B=i.current;B&&B.setPointerCapture(F.pointerId);let Q=null;const ne=ce=>{var Fe,Ye,nt,He;if(!c.current)return;const pe=r.current.cameraRef.current,oe=U.getBoundingClientRect(),ge=(ce.clientX-oe.left-pe.x)/pe.zoom,Se=(ce.clientY-oe.top-pe.y)/pe.zoom,De=ge-c.current.startMouse.x,xe=Se-c.current.startMouse.y;let fe={x:c.current.startPos.x+De,y:c.current.startPos.y+xe};if(r.current.snapToGrid&&r.current.snapGrid&&(fe={x:r.current.snapGrid[0]*Math.round(fe.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(fe.y/r.current.snapGrid[1])}),e.parentId&&e.extent==="parent"){const $e=r.current.nodesRef.current.find(Le=>Le.id===e.parentId);if($e){const Le=$e.width||160,ze=$e.height||60,Je=e.width||((Fe=e.measured)==null?void 0:Fe.width)||160,rt=e.height||((Ye=e.measured)==null?void 0:Ye.height)||60;fe={x:Math.max(0,Math.min(fe.x,Le-Je)),y:Math.max(0,Math.min(fe.y,ze-rt))}}}B&&(B.style.left=fe.x+"px",B.style.top=fe.y+"px");const Ae=[{id:e.id,position:fe,_absolutePosition:fe,dragging:!0}];for(const $e of c.current.selectedStarts){let Le={x:$e.startPos.x+De,y:$e.startPos.y+xe};r.current.snapToGrid&&r.current.snapGrid&&(Le={x:r.current.snapGrid[0]*Math.round(Le.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Le.y/r.current.snapGrid[1])});const ze=U.querySelector(`[data-nodeid="${$e.id}"]`);ze&&(ze.style.left=Le.x+"px",ze.style.top=Le.y+"px"),Ae.push({id:$e.id,position:Le,_absolutePosition:Le,dragging:!0})}(He=(nt=r.current.workerRef)==null?void 0:nt.current)==null||He.postMessage({type:"nodePositions",data:{updates:Ae}});for(const $e of Ae){const Le=r.current.nodesRef.current.find(ze=>ze.id===$e.id);Le&&(Le.position=$e.position)}Q=Ae},ee=ce=>{var ge,Se,De,xe;if(!c.current)return;const pe=[{id:e.id,position:e.position,dragging:!1}];for(const fe of c.current.selectedStarts)pe.push({id:fe.id,position:fe.startPos,dragging:!1});if(Q)for(let fe=0;fe<Q.length;fe++)pe[fe]={id:Q[fe].id,position:Q[fe].position,dragging:!1};(Se=(ge=r.current.workerRef)==null?void 0:ge.current)==null||Se.postMessage({type:"nodePositions",data:{updates:pe}});const oe=[];for(const fe of pe)oe.push({id:fe.id,type:"position",position:fe.position,dragging:!1});(xe=(De=r.current.onNodesChangeRef).current)==null||xe.call(De,oe),c.current=null,Q=null,B&&B.releasePointerCapture(ce.pointerId),B==null||B.removeEventListener("pointermove",ne),B==null||B.removeEventListener("pointerup",ee)};B==null||B.addEventListener("pointermove",ne),B==null||B.addEventListener("pointerup",ee)},[e]),m=a.useCallback(F=>{var U,X,M,d,v,L;if(!e.selected)return;const $=F.shiftKey?10:1;let Y=0,A=0;switch(F.key){case"ArrowUp":A=-$;break;case"ArrowDown":A=$;break;case"ArrowLeft":Y=-$;break;case"ArrowRight":Y=$;break;case"Escape":(X=(U=r.current.onNodesChangeRef).current)==null||X.call(U,[{id:e.id,type:"select",selected:!1}]);return;case"Delete":case"Backspace":e.deletable!==!1&&((d=(M=r.current.onNodesChangeRef).current)==null||d.call(M,[{id:e.id,type:"remove"}]));return;default:return}F.preventDefault();const P={x:e.position.x+Y,y:e.position.y+A},Z=[{id:e.id,type:"position",position:P}];for(const T of r.current.nodesRef.current)T.selected&&T.id!==e.id&&Z.push({id:T.id,type:"position",position:{x:T.position.x+Y,y:T.position.y+A}});(L=(v=r.current.onNodesChangeRef).current)==null||L.call(v,Z)},[e]),f=e.width||((z=e.measured)==null?void 0:z.width),y=e.height||((W=e.measured)==null?void 0:W.height),x=!!(f&&y),k=(j=n.pinnedNodeIds)==null?void 0:j.has(e.id),S=a.useCallback(F=>{var $,Y;F.stopPropagation(),(Y=($=r.current).togglePinNode)==null||Y.call($,e.id)},[e.id]);return I.jsx(cn.Provider,{value:e.id,children:I.jsxs("div",{ref:i,className:`ric-node-wrapper ${e.selected?"selected":""} ${e.dragging?"dragging":""}`,style:{position:"absolute",left:o.x,top:o.y,zIndex:e.type==="group"?0:e.zIndex||1,pointerEvents:e.type==="group"?"none":"all",visibility:x?"visible":"hidden",outline:"none"},"data-nodeid":e.id,tabIndex:e.selectable!==!1?0:void 0,role:"button","aria-label":`Node ${((H=e.data)==null?void 0:H.label)||e.id}`,"aria-selected":!!e.selected,onPointerDown:h,onKeyDown:m,children:[I.jsx(t,{id:e.id,data:e.data,type:e.type,selected:!!e.selected,dragging:!!e.dragging,draggable:e.draggable!==!1,selectable:e.selectable!==!1,deletable:e.deletable!==!1,isConnectable:e.connectable!==!1,zIndex:e.zIndex||0,positionAbsoluteX:o.x,positionAbsoluteY:o.y,width:f,height:y,sourcePosition:e.sourcePosition,targetPosition:e.targetPosition,parentId:e.parentId,dragHandle:e.dragHandle}),n.togglePinNode&&I.jsx("button",{className:"ric-pin-btn nodrag",onClick:S,title:k?"Unpin from DOM":"Pin to DOM",style:{position:"absolute",top:-8,left:-8,width:20,height:20,borderRadius:"50%",border:"1.5px solid "+(k?"#3b82f6":"#ccc"),background:k?"#3b82f6":"#fff",color:k?"#fff":"#999",fontSize:10,lineHeight:"16px",textAlign:"center",cursor:"pointer",padding:0,zIndex:10,pointerEvents:"all",boxShadow:"0 1px 3px rgba(0,0,0,0.12)"},children:"📌"})]})})}const fo=a.memo(uo),Cr=160,Er=60;function fr(e,t,n,r){var m,f;const i=e.width||((m=e.measured)==null?void 0:m.width)||Cr,o=e.height||((f=e.measured)==null?void 0:f.height)||Er,c=e._absolutePosition||e.position;if(e.handleBounds){const y=e.handleBounds[t]||[],x=n?y.find(k=>k.id===n):y[0];if(x&&x.x!==void 0&&x.y!==void 0){const k=x.position||(t==="source"?"right":"left");return{x:c.x+x.x,y:c.y+x.y,position:k}}}if(r){const y=`${e.id}__${n||t}`,x=r.get(y);if(x&&x.x!==void 0&&x.y!==void 0)return{x:c.x+x.x,y:c.y+x.y,position:x.position||(t==="source"?"right":"left")}}if(e.handles&&e.handles.length){for(const y of e.handles)if(y.type===t&&(!n||y.id===n)){if(y.x!==void 0&&y.y!==void 0)return{x:c.x+y.x,y:c.y+y.y,position:y.position||(t==="source"?"right":"left")};const x=y.position||(t==="source"?"right":"left");switch(x){case"top":return{x:c.x+i/2,y:c.y,position:x};case"bottom":return{x:c.x+i/2,y:c.y+o,position:x};case"left":return{x:c.x,y:c.y+o/2,position:x};default:return{x:c.x+i,y:c.y+o/2,position:x}}}}switch(t==="source"?e.sourcePosition||"right":e.targetPosition||"left"){case"top":return{x:c.x+i/2,y:c.y,position:"top"};case"bottom":return{x:c.x+i/2,y:c.y+o,position:"bottom"};case"left":return{x:c.x,y:c.y+o/2,position:"left"};default:return{x:c.x+i,y:c.y+o/2,position:"right"}}}function ho(e,t,n){return n==="left"?e-t:n==="right"?e+t:e}function go(e,t,n){return n==="top"?e-t:n==="bottom"?e+t:e}function hr({x:e,y:t,position:n,type:r,onPointerDown:i}){return I.jsx("circle",{className:`ric-edge-anchor ric-edge-anchor-${r}`,cx:ho(e,10,n),cy:go(t,10,n),r:10,stroke:"transparent",fill:"transparent",style:{cursor:"move",pointerEvents:"stroke"},onPointerDown:i})}function yo({edge:e,edgeType:t,nodes:n,reconnectable:r}){var X,M;const i=a.useContext(St),o=a.useRef(typeof i.getState=="function"?i.getState():i);o.current=typeof i.getState=="function"?i.getState():i;const[c,h]=a.useState(null),m=a.useCallback((d,v,L,T)=>{var Re;v.stopPropagation(),v.preventDefault();const B=o.current,Q=B.wrapRef.current;if(!Q)return;const ne=d==="source"?T:L,ee=d==="source"?e.target:e.source;(Re=B.workerRef.current)==null||Re.postMessage({type:"connecting",data:{from:{x:ne.x,y:ne.y},to:{x:ne.x,y:ne.y}}});const ae=Q.getBoundingClientRect(),me=ce=>{var Se;const pe=B.cameraRef.current,oe=(ce.clientX-ae.left-pe.x)/pe.zoom,ge=(ce.clientY-ae.top-pe.y)/pe.zoom;(Se=B.workerRef.current)==null||Se.postMessage({type:"connecting",data:{from:{x:ne.x,y:ne.y},to:{x:oe,y:ge}}})},we=ce=>{var Ae,Fe,Ye,nt;const pe=B.cameraRef.current,oe=(ce.clientX-ae.left-pe.x)/pe.zoom,ge=(ce.clientY-ae.top-pe.y)/pe.zoom,Se=20/pe.zoom;let De=null,xe=null;const fe=(Ae=B.handleRegistryRef)==null?void 0:Ae.current;for(const He of B.nodesRef.current){if(He.hidden)continue;const $e=He.width||Cr,Le=He.height||Er,ze=He._absolutePosition||He.position,Je=[];if(fe)for(const[,_e]of fe)_e.nodeId===He.id&&Je.push(_e);const rt=Je.length>0?Je:He.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const _e of rt){let Ue,Ve;if(_e.x!==void 0&&_e.y!==void 0)Ue=ze.x+_e.x,Ve=ze.y+_e.y;else switch(_e.position||(_e.type==="source"?"right":"left")){case"top":Ue=ze.x+$e/2,Ve=ze.y;break;case"bottom":Ue=ze.x+$e/2,Ve=ze.y+Le;break;case"left":Ue=ze.x,Ve=ze.y+Le/2;break;default:Ue=ze.x+$e,Ve=ze.y+Le/2;break}if(Math.abs(oe-Ue)<Se&&Math.abs(ge-Ve)<Se){De=He,xe=_e.id||null;break}}if(De)break}if(De){const He=d==="source"?{source:De.id,target:ee,sourceHandle:xe,targetHandle:e.targetHandle}:{source:ee,target:De.id,sourceHandle:e.sourceHandle,targetHandle:xe};(Ye=(Fe=B.onEdgesChangeRef).current)==null||Ye.call(Fe,[{id:e.id,type:"remove"},{type:"add",item:{id:e.id,...He}}])}(nt=B.workerRef.current)==null||nt.postMessage({type:"connecting",data:null}),Q.removeEventListener("pointermove",me),Q.removeEventListener("pointerup",we)};Q.addEventListener("pointermove",me),Q.addEventListener("pointerup",we)},[e]),f=o.current,y=((X=f.nodesRef)==null?void 0:X.current)||n,x=y.find(d=>d.id===e.source),k=y.find(d=>d.id===e.target),[,S]=a.useReducer(d=>d+1,0),z=a.useRef(null),W=(x==null?void 0:x.dragging)||(k==null?void 0:k.dragging);a.useEffect(()=>{if(!W)return;const d=()=>{S(),z.current=requestAnimationFrame(d)};return z.current=requestAnimationFrame(d),()=>cancelAnimationFrame(z.current)},[W]);const j=a.useRef(!1);a.useEffect(()=>{j.current||(j.current=!0,requestAnimationFrame(()=>S()))},[]);const H=(M=f.handleRegistryRef)==null?void 0:M.current,F=x?fr(x,"source",e.sourceHandle,H):null,$=k?fr(k,"target",e.targetHandle,H):null,Y=e.type==="bezier"||e.type==="simplebezier"||e.type==="default",A=f.routedEdges||f.edges,P=A==null?void 0:A.find(d=>d.id===e.id),Z=Y?null:(P==null?void 0:P._routedPoints)||e._routedPoints||null,U=r!==!1&&e.reconnectable!==!1;return!F||!$?null:I.jsxs("g",{className:`ric-edge-wrapper ${e.selected?"selected":""}`,"data-edgeid":e.id,onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),children:[I.jsx(t,{id:e.id,source:e.source,target:e.target,sourceX:F.x,sourceY:F.y,targetX:$.x,targetY:$.y,sourcePosition:F.position,targetPosition:$.position,sourceHandleId:e.sourceHandle,targetHandleId:e.targetHandle,data:e.data,type:e.type,selected:!!e.selected,animated:!!e.animated,label:e.label,style:e.style,selectable:e.selectable!==!1,deletable:e.deletable!==!1,routedPoints:Z}),U&&(c||e.selected)&&I.jsxs(I.Fragment,{children:[I.jsx(hr,{x:F.x,y:F.y,position:F.position,type:"source",onPointerDown:d=>m("source",d,F,$)}),I.jsx(hr,{x:$.x,y:$.y,position:$.position,type:"target",onPointerDown:d=>m("target",d,F,$)})]})]})}const xo=a.memo(yo);function Sr({selectionKeyCode:e="Shift",selectionMode:t="partial"}){var W;const n=Te(),[r,i]=a.useState(null),o=a.useRef(null);if(a.useEffect(()=>{const j=n.wrapRef.current;if(!j)return;let H=!1,F=null,$=!1;const Y=X=>{X.key===e&&($=!0)},A=X=>{X.key===e&&($=!1)},P=X=>{if(!$)return;const M=X.target;if(M.closest(".ric-node-wrapper")||M.closest(".ric-handle"))return;H=!0;const d=n.cameraRef.current,v=j.getBoundingClientRect(),L=(X.clientX-v.left-d.x)/d.zoom,T=(X.clientY-v.top-d.y)/d.zoom;F={x:L,y:T},i({startX:L,startY:T,endX:L,endY:T}),X.stopPropagation()},Z=X=>{if(!H||!F)return;const M=n.cameraRef.current,d=j.getBoundingClientRect(),v=(X.clientX-d.left-M.x)/M.zoom,L=(X.clientY-d.top-M.y)/M.zoom;i({startX:F.x,startY:F.y,endX:v,endY:L})},U=X=>{var Q,ne;if(!H||!F)return;H=!1;const M=n.cameraRef.current,d=j.getBoundingClientRect(),v=(X.clientX-d.left-M.x)/M.zoom,L=(X.clientY-d.top-M.y)/M.zoom,T={x:Math.min(F.x,v),y:Math.min(F.y,L),width:Math.abs(v-F.x),height:Math.abs(L-F.y)},B=[];for(const ee of n.nodesRef.current){const ae=ee._absolutePosition||ee.position,me=ee.width||160,we=ee.height||60;let Re;t==="full"?Re=ae.x>=T.x&&ae.y>=T.y&&ae.x+me<=T.x+T.width&&ae.y+we<=T.y+T.height:Re=ae.x+me>T.x&&ae.x<T.x+T.width&&ae.y+we>T.y&&ae.y<T.y+T.height,B.push({id:ee.id,type:"select",selected:Re})}B.length&&((ne=(Q=n.onNodesChangeRef).current)==null||ne.call(Q,B)),F=null,i(null)};return j.addEventListener("pointerdown",P,!0),j.addEventListener("pointermove",Z),j.addEventListener("pointerup",U),window.addEventListener("keydown",Y),window.addEventListener("keyup",A),()=>{j.removeEventListener("pointerdown",P,!0),j.removeEventListener("pointermove",Z),j.removeEventListener("pointerup",U),window.removeEventListener("keydown",Y),window.removeEventListener("keyup",A)}},[n,e,t]),!r)return null;const c=((W=n.cameraRef)==null?void 0:W.current)||{x:0,y:0,zoom:1},h=Math.min(r.startX,r.endX),m=Math.min(r.startY,r.endY),f=Math.abs(r.endX-r.startX),y=Math.abs(r.endY-r.startY),x=h*c.zoom+c.x,k=m*c.zoom+c.y,S=f*c.zoom,z=y*c.zoom;return I.jsx("div",{ref:o,className:"ric-selection-box",style:{position:"absolute",left:x,top:k,width:S,height:z,border:"1px dashed #3b82f6",background:"rgba(59, 130, 246, 0.08)",pointerEvents:"none",zIndex:100}})}Sr.displayName="SelectionBox";const zr=a.memo(Sr);function Jn(e,t,n){switch(e){case"top":return{x:t/2,y:0};case"bottom":return{x:t/2,y:n};case"left":return{x:0,y:n/2};case"right":return{x:t,y:n/2};default:return{x:t,y:n/2}}}function po(e,t){const n=e.closest(".ric-node-wrapper");if(!n)return null;const r=n.getBoundingClientRect(),i=e.getBoundingClientRect(),o=t||1;return{x:(i.left+i.width/2-r.left)/o,y:(i.top+i.height/2-r.top)/o}}let Un=!1,Et=null;function Pr(e){Et=e,!Un&&(Un=!0,requestAnimationFrame(()=>{var t;Un=!1,(t=Et==null?void 0:Et.syncNodesToWorker)==null||t.call(Et),Et=null}))}const Vn=new WeakMap;let bn=null;function mo(){return bn||(bn=new ResizeObserver(e=>{var t;for(const n of e){const r=Vn.get(n.target);if(!r)continue;const{width:i,height:o}=n.contentRect;if(!i||!o)continue;const c=r.getStore(),h=(t=c.handleRegistryRef)==null?void 0:t.current;if(h){for(const[m,f]of h)if(f.nodeId===r.nodeId){const y=Jn(f.position,i,o);f.x=y.x,f.y=y.y,h.set(m,f)}Pr(c)}}}),bn)}function vo({type:e="source",position:t=e==="source"?"right":"left",id:n,isConnectable:r=!0,isConnectableStart:i=!0,isConnectableEnd:o=!0,children:c,className:h="",style:m={},onConnect:f,...y}){const x=a.useContext(cn),k=a.useContext(St),S=a.useRef(null),z=a.useCallback(()=>typeof k.getState=="function"?k.getState():k,[k]),W=a.useRef(z);W.current=z,a.useLayoutEffect(()=>{var M,d,v,L,T,B,Q;if(!x)return;const $=W.current(),Y=(M=$.handleRegistryRef)==null?void 0:M.current;if(!Y)return;const A=`${x}__${n||e}`,P=(v=(d=$.nodesRef)==null?void 0:d.current)==null?void 0:v.find(ne=>ne.id===x),Z=(P==null?void 0:P.width)||((L=P==null?void 0:P.measured)==null?void 0:L.width),U=(P==null?void 0:P.height)||((T=P==null?void 0:P.measured)==null?void 0:T.height);let X;Z&&U?X=Jn(t,Z,U):S.current?X=po(S.current,(Q=(B=$.cameraRef)==null?void 0:B.current)==null?void 0:Q.zoom):X=Jn(t,160,60),Y.set(A,{nodeId:x,id:n||null,type:e,position:t,x:X.x,y:X.y}),P&&(e==="source"&&(P.sourcePosition=t),e==="target"&&(P.targetPosition=t))},[x,n,e,t]),a.useEffect(()=>{if(!x)return;const $=W.current();Pr($);const Y=S.current,A=Y==null?void 0:Y.closest(".ric-node-wrapper");return A&&!Vn.has(A)&&(Vn.set(A,{nodeId:x,getStore:W.current}),mo().observe(A)),()=>{var X;const Z=(X=W.current().handleRegistryRef)==null?void 0:X.current,U=`${x}__${n||e}`;Z==null||Z.delete(U)}},[x,n,e,t]);const j=a.useCallback(()=>{var d;const $=W.current(),Y=$.nodesRef.current.find(v=>v.id===x);if(!Y)return null;const A=Y._absolutePosition||Y.position,P=(d=$.handleRegistryRef)==null?void 0:d.current,Z=`${x}__${n||e}`,U=P==null?void 0:P.get(Z);if(U&&U.x!==void 0&&U.y!==void 0)return{x:A.x+U.x,y:A.y+U.y};const X=Y.width||160,M=Y.height||60;switch(t){case"top":return{x:A.x+X/2,y:A.y};case"bottom":return{x:A.x+X/2,y:A.y+M};case"left":return{x:A.x,y:A.y+M/2};default:return{x:A.x+X,y:A.y+M/2}}},[x,n,e,t]),H=a.useCallback($=>{var L;if(!r||!i)return;$.stopPropagation(),$.preventDefault();const Y=W.current(),A=Y.cameraRef.current,P=Y.wrapRef.current;if(!P)return;const Z=P.getBoundingClientRect(),U=j();if(!U)return;const X=U.x,M=U.y;(L=Y.workerRef.current)==null||L.postMessage({type:"connecting",data:{from:{x:X,y:M},to:{x:X,y:M}}}),P.setPointerCapture($.pointerId);const d=T=>{var ne;const B=(T.clientX-Z.left-A.x)/A.zoom,Q=(T.clientY-Z.top-A.y)/A.zoom;(ne=Y.workerRef.current)==null||ne.postMessage({type:"connecting",data:{from:{x:X,y:M},to:{x:B,y:Q}}})},v=T=>{var we,Re,ce,pe;const B=(T.clientX-Z.left-A.x)/A.zoom,Q=(T.clientY-Z.top-A.y)/A.zoom,ne=20/A.zoom;let ee=null,ae=null;const me=(we=Y.handleRegistryRef)==null?void 0:we.current;for(const oe of Y.nodesRef.current){if(oe.id===x||oe.hidden)continue;const ge=oe._absolutePosition||oe.position,Se=[];if(me)for(const[,xe]of me)xe.nodeId===oe.id&&Se.push(xe);const De=Se.length>0?Se:oe.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const xe of De){let fe,Ae;if(xe.x!==void 0&&xe.y!==void 0)fe=ge.x+xe.x,Ae=ge.y+xe.y;else{const Fe=oe.width||160,Ye=oe.height||60;switch(xe.position||(xe.type==="source"?"right":"left")){case"top":fe=ge.x+Fe/2,Ae=ge.y;break;case"bottom":fe=ge.x+Fe/2,Ae=ge.y+Ye;break;case"left":fe=ge.x,Ae=ge.y+Ye/2;break;default:fe=ge.x+Fe,Ae=ge.y+Ye/2;break}}if(Math.abs(B-fe)<ne&&Math.abs(Q-Ae)<ne){ee=oe,ae=xe.id||null;break}}if(ee)break}if(ee){const oe={source:e==="source"?x:ee.id,target:e==="source"?ee.id:x,sourceHandle:e==="source"?n||null:ae,targetHandle:e==="source"?ae:n||null};(ce=(Re=Y.onEdgesChangeRef)==null?void 0:Re.current)==null||ce.call(Re,[{type:"add",item:{id:`e-${oe.source}-${oe.target}`,...oe}}])}(pe=Y.workerRef.current)==null||pe.postMessage({type:"connecting",data:null}),P.removeEventListener("pointermove",d),P.removeEventListener("pointerup",v)};P.addEventListener("pointermove",d),P.addEventListener("pointerup",v)},[x,n,e,t,r,i,j]),F={top:{top:0,left:"50%",transform:"translate(-50%, -50%)"},bottom:{bottom:0,left:"50%",transform:"translate(-50%, 50%)"},left:{top:"50%",left:0,transform:"translate(-50%, -50%)"},right:{top:"50%",right:0,transform:"translate(50%, -50%)"}}[t]||{};return I.jsx("div",{ref:S,className:`ric-handle ric-handle-${t} ric-handle-${e} ${h}`,"data-handleid":n||null,"data-nodeid":x,"data-handlepos":t,"data-handletype":e,onPointerDown:H,style:{position:"absolute",width:8,height:8,borderRadius:"50%",background:"#1a192b",border:"none",zIndex:10,cursor:r?"crosshair":"default",boxSizing:"border-box",...F,...m},...y,children:c})}const an=a.memo(vo);function bo({data:e,isConnectable:t,selected:n,targetPosition:r="left",sourcePosition:i="right",hideSourceHandle:o=!1,hideTargetHandle:c=!1}){return I.jsxs("div",{className:`ric-default-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!c&&I.jsx(an,{type:"target",position:r,isConnectable:t}),I.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!o&&I.jsx(an,{type:"source",position:i,isConnectable:t})]})}function Nr({data:e,isConnectable:t,selected:n,sourcePosition:r="right",hideSourceHandle:i=!1}){return I.jsxs("div",{className:`ric-input-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderBottom:"2px solid #0041d0",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[I.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!i&&I.jsx(an,{type:"source",position:r,isConnectable:t})]})}function Ir({data:e,isConnectable:t,selected:n,targetPosition:r="left",hideTargetHandle:i=!1}){return I.jsxs("div",{className:`ric-output-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderTop:"2px solid #ff0072",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!i&&I.jsx(an,{type:"target",position:r,isConnectable:t}),I.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label})]})}function Tr({data:e,selected:t,width:n,height:r}){return I.jsx("div",{className:`ric-group-node${t?" selected":""}`,style:{width:n||300,height:r||200,background:"rgba(240, 240, 240, 0.25)",border:t?"2px solid #3b82f6":"1px dashed #ccc",borderRadius:8,padding:8,boxSizing:"border-box"},children:(e==null?void 0:e.label)&&I.jsx("div",{style:{fontSize:11,fontWeight:600,color:"#888",userSelect:"none"},children:e.label})})}function Lr({x:e,y:t,label:n,labelStyle:r,labelShowBg:i=!0,labelBgStyle:o,labelBgPadding:c=[2,4],labelBgBorderRadius:h=2,children:m,className:f="",...y}){const[x,k]=a.useState({x:1,y:0,width:0,height:0}),S=a.useRef(null);return a.useEffect(()=>{if(S.current){const z=S.current.getBBox();k({x:z.x,y:z.y,width:z.width,height:z.height})}},[n]),n?I.jsxs("g",{transform:`translate(${e-x.width/2} ${t-x.height/2})`,className:`ric-edge-textwrapper ${f}`,visibility:x.width?"visible":"hidden",...y,children:[i&&I.jsx("rect",{width:x.width+2*c[0],x:-c[0],y:-c[1],height:x.height+2*c[1],className:"ric-edge-textbg",style:o,rx:h,ry:h}),I.jsx("text",{className:"ric-edge-text",y:x.height/2,dy:"0.3em",ref:S,style:r,children:n}),m]}):null}Lr.displayName="EdgeText";const Br=a.memo(Lr);function gr(e){return e!=null&&e!==""&&!isNaN(Number(e))}function ln({id:e,path:t,labelX:n,labelY:r,label:i,labelStyle:o,labelShowBg:c,labelBgStyle:h,labelBgPadding:m,labelBgBorderRadius:f,interactionWidth:y=20,style:x,markerEnd:k,markerStart:S,className:z="",...W}){return I.jsxs(I.Fragment,{children:[I.jsx("path",{id:e,d:t,fill:"none",stroke:"#b1b1b7",strokeWidth:1.5,className:`ric-edge-path ${z}`,style:x,markerEnd:k,markerStart:S,...W}),y?I.jsx("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:y,className:"ric-edge-interaction",style:{pointerEvents:"stroke"}}):null,i&&gr(n)&&gr(r)?I.jsx(Br,{x:n,y:r,label:i,labelStyle:o,labelShowBg:c,labelBgStyle:h,labelBgPadding:m,labelBgBorderRadius:f}):null]})}const rn=20;function yr(e,t,n){switch(n){case"right":return{x:e+rn,y:t};case"left":return{x:e-rn,y:t};case"bottom":return{x:e,y:t+rn};case"top":return{x:e,y:t-rn};default:return{x:e+rn,y:t}}}const tr=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:c="bottom",targetPosition:h="top",label:m,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:k,labelBgBorderRadius:S,style:z,markerEnd:W,markerStart:j,interactionWidth:H}){let F,$,Y;const A=yr(n,r,c),P=yr(i,o,h),Z=Math.abs(P.x-A.x),U=Math.max(50,Z*.5);let X,M,d,v;switch(c){case"left":X=A.x-U,M=A.y;break;case"top":X=A.x,M=A.y-U;break;case"bottom":X=A.x,M=A.y+U;break;default:X=A.x+U,M=A.y;break}switch(h){case"right":d=P.x+U,v=P.y;break;case"top":d=P.x,v=P.y-U;break;case"bottom":d=P.x,v=P.y+U;break;default:d=P.x-U,v=P.y;break}F=`M ${n},${r} L ${A.x},${A.y} C ${X},${M} ${d},${v} ${P.x},${P.y} L ${i},${o}`;const L=.5,T=.5;return $=T*T*T*A.x+3*T*T*L*X+3*T*L*L*d+L*L*L*P.x,Y=T*T*T*A.y+3*T*T*L*M+3*T*L*L*v+L*L*L*P.y,I.jsx(ln,{id:t,path:F,labelX:$,labelY:Y,label:m,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:k,labelBgBorderRadius:S,style:z,markerEnd:W,markerStart:j,interactionWidth:H})});tr.displayName="BezierEdge";function nr({sourceX:e,sourceY:t,targetX:n,targetY:r}){const i=`M ${e},${t}L ${n},${r}`,o=(e+n)/2,c=(t+r)/2;return[i,o,c,0,0]}function rr({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i="right",targetPosition:o="left",curvature:c=.25}){const h=Math.abs(n-e),m=Math.abs(r-t),f=Math.sqrt(h*h+m*m),y=Math.max(f*c,50);let x,k,S,z;switch(i){case"top":x=e,k=t-y;break;case"bottom":x=e,k=t+y;break;case"left":x=e-y,k=t;break;default:x=e+y,k=t;break}switch(o){case"top":S=n,z=r-y;break;case"bottom":S=n,z=r+y;break;case"right":S=n+y,z=r;break;default:S=n-y,z=r;break}const W=`M ${e},${t} C ${x},${k} ${S},${z} ${n},${r}`,j=.5,H=1-j,F=H*H*H*e+3*H*H*j*x+3*H*j*j*S+j*j*j*n,$=H*H*H*t+3*H*H*j*k+3*H*j*j*z+j*j*j*r;return[W,F,$,0,0]}function or({sourceX:e,sourceY:t,targetX:n,targetY:r}){const i=Math.abs(n-e),o=Math.max(i*.5,50),c=e+o,h=n-o,m=`M ${e},${t} C ${c},${t} ${h},${r} ${n},${r}`,f=.5,y=.5,x=y*y*y*e+3*y*y*f*c+3*y*f*f*h+f*f*f*n,k=y*y*y*t+3*y*y*f*t+3*y*f*f*r+f*f*f*r;return[m,x,k,0,0]}function Rn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i="right",targetPosition:o="left",borderRadius:c=5,offset:h=20}){const m=i==="left"||i==="right",f=Math.min(c,Math.abs(n-e)/2,Math.abs(r-t)/2);if(m){if(Math.abs(r-t)<1)return[`M ${e},${t} L ${n},${r}`,(e+n)/2,t,0,0];const S=(e+n)/2,z=r>t?1:-1;return[`M ${e},${t} L ${S-f},${t} Q ${S},${t} ${S},${t+z*f} L ${S},${r-z*f} Q ${S},${r} ${S+(n>S?f:-f)},${r} L ${n},${r}`,S,(t+r)/2,0,0]}const y=(t+r)/2,x=n>e?1:-1;return[`M ${e},${t} L ${e},${y-f} Q ${e},${y} ${e+x*f},${y} L ${n-x*f},${y} Q ${n},${y} ${n},${y+(r>y?f:-f)} L ${n},${r}`,(e+n)/2,y,0,0]}function wo({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[,i,o]=rr({sourceX:e,sourceY:t,targetX:n,targetY:r});return[i,o,0,0]}function Mo({sourceX:e,sourceY:t,targetX:n,targetY:r}){return[(e+n)/2,(t+r)/2,0,0]}function Ro(e,t,n){const r=n.filter(o=>o.id!==e.id),i={...e,id:e.id,source:t.source,target:t.target,sourceHandle:t.sourceHandle??e.sourceHandle,targetHandle:t.targetHandle??e.targetHandle};return r.push(i),r}const kn=160,Cn=60,on=20,wn=12,En=20;function xr(e,t,n){var c,h;const r=e.width||((c=e.measured)==null?void 0:c.width)||kn,i=e.height||((h=e.measured)==null?void 0:h.height)||Cn,o=e._absolutePosition||e.position;if(e.handles&&e.handles.length>0){for(const m of e.handles)if(m.type===t&&(!n||m.id===n)){if(m.x!==void 0&&m.y!==void 0)return{x:o.x+m.x,y:o.y+m.y,dir:m.position||(t==="source"?"right":"left")};switch(m.position||(t==="source"?"right":"left")){case"top":return{x:o.x+r/2,y:o.y,dir:"top"};case"bottom":return{x:o.x+r/2,y:o.y+i,dir:"bottom"};case"left":return{x:o.x,y:o.y+i/2,dir:"left"};default:return{x:o.x+r,y:o.y+i/2,dir:"right"}}}}return t==="source"?{x:o.x+r,y:o.y+i/2,dir:"right"}:{x:o.x,y:o.y+i/2,dir:"left"}}function Sn(e,t){switch(e.dir){case"right":return{x:e.x+t,y:e.y,dir:e.dir};case"left":return{x:e.x-t,y:e.y,dir:e.dir};case"bottom":return{x:e.x,y:e.y+t,dir:e.dir};case"top":return{x:e.x,y:e.y-t,dir:e.dir};default:return{x:e.x+t,y:e.y,dir:e.dir}}}function ko(e,t,n,r,i,o,c,h){const m=Math.min(e,n),f=Math.max(e,n),y=Math.min(t,r),x=Math.max(t,r);if(f<=i||m>=i+c||x<=o||y>=o+h)return!1;const k=.5;if(e>i+k&&e<i+c-k&&t>o+k&&t<o+h-k||n>i+k&&n<i+c-k&&r>o+k&&r<o+h-k)return!0;const S=(e+n)/2,z=(t+r)/2;if(S>i+k&&S<i+c-k&&z>o+k&&z<o+h-k)return!0;const W=[[i,o],[i+c,o],[i+c,o+h],[i,o+h]];for(let j=0;j<4;j++)if(Co(e,t,n,r,W[j][0],W[j][1],W[(j+1)%4][0],W[(j+1)%4][1]))return!0;return!1}function Co(e,t,n,r,i,o,c,h){const m=(c-i)*(t-o)-(h-o)*(e-i),f=(c-i)*(r-o)-(h-o)*(n-i),y=(n-e)*(o-t)-(r-t)*(i-e),x=(n-e)*(h-t)-(r-t)*(c-e);return(m>0&&f<0||m<0&&f>0)&&(y>0&&x<0||y<0&&x>0)}function Kn(e,t,n,r,i){for(let o=0;o<i.length;o++){const c=i[o];if(ko(e,t,n,r,c.x,c.y,c.w,c.h))return!1}return!0}function Eo(e,t,n){for(let r=0;r<n.length;r++){const i=n[r];if(e>i.x&&e<i.x+i.w&&t>i.y&&t<i.y+i.h)return!0}return!1}function sr(e,t){var r,i;const n=[];for(let o=0;o<e.length;o++){const c=e[o];if(c.hidden||t&&t.has(c.id)||c.type==="group")continue;const h=c._absolutePosition||c.position,m=c.width||((r=c.measured)==null?void 0:r.width)||kn,f=c.height||((i=c.measured)==null?void 0:i.height)||Cn;n.push({id:c.id,x:h.x-on,y:h.y-on,w:m+2*on,h:f+2*on})}return n}function $r(e,t,n){if(Kn(e.x,e.y,t.x,t.y,n))return null;const r=new Set,i=new Set;r.add(e.x),r.add(t.x),i.add(e.y),i.add(t.y);const o=on+5;e.dir==="right"?r.add(e.x+o):e.dir==="left"?r.add(e.x-o):e.dir==="top"?i.add(e.y-o):e.dir==="bottom"&&i.add(e.y+o),t.dir==="right"?r.add(t.x+o):t.dir==="left"?r.add(t.x-o):t.dir==="top"?i.add(t.y-o):t.dir==="bottom"&&i.add(t.y+o);for(let d=0;d<n.length;d++){const v=n[d];r.add(v.x),r.add(v.x+v.w),i.add(v.y),i.add(v.y+v.h)}const c=[...r].sort((d,v)=>d-v),h=[...i].sort((d,v)=>d-v),m=new Map,f=new Map;for(let d=0;d<c.length;d++)m.set(c[d],d);for(let d=0;d<h.length;d++)f.set(h[d],d);const y=c.length,x=h.length,k=(d,v)=>v*y+d,S=m.get(e.x),z=f.get(e.y),W=m.get(t.x),j=f.get(t.y);if(S===void 0||z===void 0||W===void 0||j===void 0)return null;const H=k(S,z),F=k(W,j),$=new Float64Array(y*x).fill(1/0),Y=new Float64Array(y*x).fill(1/0),A=new Int32Array(y*x).fill(-1),P=new Int8Array(y*x).fill(-1),Z=new Uint8Array(y*x);$[H]=0,Y[H]=Math.abs(c[W]-e.x)+Math.abs(h[j]-e.y);const U=[H],X=15,M=[[1,0],[-1,0],[0,1],[0,-1]];for(;U.length>0;){let d=0;for(let ee=1;ee<U.length;ee++)Y[U[ee]]<Y[U[d]]&&(d=ee);const v=U[d];if(U[d]=U[U.length-1],U.pop(),v===F){const ee=[];let ae=F;for(;ae!==-1&&ae!==H;){const me=ae/y|0,we=ae%y;ee.unshift({x:c[we],y:h[me]}),ae=A[ae]}return ee.unshift({x:e.x,y:e.y}),So(ee,n)}if(Z[v])continue;Z[v]=1;const L=v/y|0,T=v%y,B=c[T],Q=h[L],ne=P[v];for(let ee=0;ee<4;ee++){const ae=T+M[ee][0],me=L+M[ee][1];if(ae<0||ae>=y||me<0||me>=x)continue;const we=k(ae,me);if(Z[we])continue;const Re=c[ae],ce=h[me];if(Eo(Re,ce,n)||!Kn(B,Q,Re,ce,n))continue;const pe=Math.abs(Re-B)+Math.abs(ce-Q),oe=ne>=0&&ne!==ee?X:0,ge=$[v]+pe+oe;ge<$[we]&&(A[we]=v,P[we]=ee,$[we]=ge,Y[we]=ge+Math.abs(c[W]-Re)+Math.abs(h[j]-ce),U.push(we))}}return null}function So(e,t){if(!e||e.length<=2)return e;const n=[e[0]];for(let r=1;r<e.length-1;r++){const i=n[n.length-1],o=e[r],c=e[r+1],h=Math.abs(i.x-o.x)<.5&&Math.abs(o.x-c.x)<.5,m=Math.abs(i.y-o.y)<.5&&Math.abs(o.y-c.y)<.5;(h||m)&&Kn(i.x,i.y,c.x,c.y,t)||n.push(o)}return n.push(e[e.length-1]),n}function zo(e){const t=new Map,n=new Map;for(const i of e){const o=i._routedPoints;if(!(!o||o.length<2))for(let c=0;c<o.length-1;c++){const h=o[c],m=o[c+1];if(Math.abs(h.y-m.y)<.5){const f=Math.round(h.y*10)/10;t.has(f)||t.set(f,[]),t.get(f).push({edgeId:i.id,segIdx:c,x1:Math.min(h.x,m.x),x2:Math.max(h.x,m.x)})}else if(Math.abs(h.x-m.x)<.5){const f=Math.round(h.x*10)/10;n.has(f)||n.set(f,[]),n.get(f).push({edgeId:i.id,segIdx:c,y1:Math.min(h.y,m.y),y2:Math.max(h.y,m.y)})}}}const r=new Map;for(const i of e)i._routedPoints&&r.set(i.id,i._routedPoints.map(o=>({...o})));for(const[,i]of t){if(i.length<2)continue;const o=pr(i,"x1","x2");for(const c of o){if(c.length<2)continue;const h=(c.length-1)*wn/2;for(let m=0;m<c.length;m++){const f=c[m],y=-h+m*wn,x=r.get(f.edgeId);x&&(x[f.segIdx].y+=y,x[f.segIdx+1].y+=y)}}}for(const[,i]of n){if(i.length<2)continue;const o=pr(i,"y1","y2");for(const c of o){if(c.length<2)continue;const h=(c.length-1)*wn/2;for(let m=0;m<c.length;m++){const f=c[m],y=-h+m*wn,x=r.get(f.edgeId);x&&(x[f.segIdx].x+=y,x[f.segIdx+1].x+=y)}}}return e.map(i=>{const o=r.get(i.id);return o?{...i,_routedPoints:o}:i})}function pr(e,t,n){if(e.length<2)return[];const r=[...e].sort((c,h)=>c[t]-h[t]),i=[];let o=[r[0]];for(let c=1;c<r.length;c++){const h=o[o.length-1];r[c][t]<h[n]?o.push(r[c]):(o.length>1&&i.push(o),o=[r[c]])}return o.length>1&&i.push(o),i}function zn(e,t=6,n=!1){if(!e||e.length<2)return null;if(n)return Po(e);const r=t;let i=`M ${e[0].x},${e[0].y}`;for(let o=1;o<e.length-1;o++){const c=e[o-1],h=e[o],m=e[o+1],f=Math.abs(h.x-c.x)+Math.abs(h.y-c.y),y=Math.abs(m.x-h.x)+Math.abs(m.y-h.y),x=Math.min(r,f/2,y/2);if(x>.5){const k=h.x-c.x,S=h.y-c.y,z=m.x-h.x,W=m.y-h.y,j=Math.sqrt(k*k+S*S)||1,H=Math.sqrt(z*z+W*W)||1;i+=` L ${h.x-k/j*x},${h.y-S/j*x}`,i+=` Q ${h.x},${h.y} ${h.x+z/H*x},${h.y+W/H*x}`}else i+=` L ${h.x},${h.y}`}return i+=` L ${e[e.length-1].x},${e[e.length-1].y}`,i}function Po(e){if(e.length===2)return`M ${e[0].x},${e[0].y} L ${e[1].x},${e[1].y}`;if(e.length===3)return`M ${e[0].x},${e[0].y} Q ${e[1].x},${e[1].y} ${e[2].x},${e[2].y}`;const t=.3;let n=`M ${e[0].x},${e[0].y}`;for(let r=0;r<e.length-1;r++){const i=e[r===0?0:r-1],o=e[r],c=e[r+1],h=e[r+2<e.length?r+2:e.length-1],m=o.x+(c.x-i.x)*t,f=o.y+(c.y-i.y)*t,y=c.x-(h.x-o.x)*t,x=c.y-(h.y-o.y)*t;n+=` C ${m},${f} ${y},${x} ${c.x},${c.y}`}return n}function Pn(e){if(!e||e.length<2)return{x:0,y:0};let t=0;for(let r=1;r<e.length;r++)t+=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);let n=t/2;for(let r=1;r<e.length;r++){const i=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);if(n<=i){const o=i>0?n/i:0;return{x:e[r-1].x+(e[r].x-e[r-1].x)*o,y:e[r-1].y+(e[r].y-e[r-1].y)*o}}n-=i}return{x:e[0].x,y:e[0].y}}function No(e,t){if(!e||!t||e.length===0||t.length===0)return t;const n={};for(const o of e)n[o.id]=o;const r=sr(e,null),i=t.map(o=>{var P,Z,U,X;const c=o.type||"default";if(c==="bezier"||c==="simplebezier"||c==="default")return o;const h=n[o.source],m=n[o.target];if(!h||!m||h.hidden||m.hidden)return o;const f=xr(h,"source",o.sourceHandle),y=xr(m,"target",o.targetHandle),x=Sn(f,En),k=Sn(y,En),S=5,z=r.filter(M=>M.id!==o.source&&M.id!==o.target),W=h._absolutePosition||h.position,j=h.width||((P=h.measured)==null?void 0:P.width)||kn,H=h.height||((Z=h.measured)==null?void 0:Z.height)||Cn;z.push({id:o.source,x:W.x-S,y:W.y-S,w:j+2*S,h:H+2*S});const F=m._absolutePosition||m.position,$=m.width||((U=m.measured)==null?void 0:U.width)||kn,Y=m.height||((X=m.measured)==null?void 0:X.height)||Cn;if(z.push({id:o.target,x:F.x-S,y:F.y-S,w:$+2*S,h:Y+2*S}),z.length===0)return o;const A=$r(x,k,z);return A&&A.length>=2?(A.unshift({x:f.x,y:f.y}),A.push({x:y.x,y:y.y}),{...o,_routedPoints:A}):o});return zo(i)}function Io(e,t,n,r,i,o,c,h){const m=sr(c,h?new Set(h):null);if(m.length===0)return null;const f={x:e,y:t,dir:i||"right"},y={x:n,y:r,dir:o||"left"},x=Sn(f,En),k=Sn(y,En),S=$r(x,k,m);return S&&S.length>=2?(S.unshift({x:f.x,y:f.y}),S.push({x:y.x,y:y.y}),S):null}const ir=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,label:c,labelStyle:h,labelShowBg:m,labelBgStyle:f,labelBgPadding:y,labelBgBorderRadius:x,style:k,markerEnd:S,markerStart:z,interactionWidth:W,routedPoints:j}){let H,F,$;if(j&&j.length>=2){H=zn(j);const Y=Pn(j);F=Y.x,$=Y.y}else[H,F,$]=nr({sourceX:n,sourceY:r,targetX:i,targetY:o});return I.jsx(ln,{id:t,path:H,labelX:F,labelY:$,label:c,labelStyle:h,labelShowBg:m,labelBgStyle:f,labelBgPadding:y,labelBgBorderRadius:x,style:k,markerEnd:S,markerStart:z,interactionWidth:W})});ir.displayName="StraightEdge";const ar=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:c="bottom",targetPosition:h="top",label:m,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:k,labelBgBorderRadius:S,style:z,markerEnd:W,markerStart:j,pathOptions:H,interactionWidth:F,routedPoints:$}){let Y,A,P;if($&&$.length>=2){Y=zn($);const Z=Pn($);A=Z.x,P=Z.y}else[Y,A,P]=Rn({sourceX:n,sourceY:r,sourcePosition:c,targetX:i,targetY:o,targetPosition:h,borderRadius:H==null?void 0:H.borderRadius,offset:H==null?void 0:H.offset});return I.jsx(ln,{id:t,path:Y,labelX:A,labelY:P,label:m,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:k,labelBgBorderRadius:S,style:z,markerEnd:W,markerStart:j,interactionWidth:F})});ar.displayName="SmoothStepEdge";const Ar=a.memo(function({id:t,...n}){var i;const r=a.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(i=n.pathOptions)==null?void 0:i.offset]);return I.jsx(ar,{...n,id:t,pathOptions:r})});Ar.displayName="StepEdge";const cr=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:c,targetPosition:h,label:m,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:k,labelBgBorderRadius:S,style:z,markerEnd:W,markerStart:j,interactionWidth:H,routedPoints:F}){let $,Y,A;if(F&&F.length>=2){$=zn(F);const P=Pn(F);Y=P.x,A=P.y}else[$,Y,A]=or({sourceX:n,sourceY:r,targetX:i,targetY:o});return I.jsx(ln,{id:t,path:$,labelX:Y,labelY:A,label:m,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:k,labelBgBorderRadius:S,style:z,markerEnd:W,markerStart:j,interactionWidth:H})});cr.displayName="SimpleBezierEdge";const To={input:Nr,output:Ir,group:Tr},Lo={bezier:tr,straight:ir,simplebezier:cr},Bo=160,$o=60;function Ao(e){let t=!1;for(let n=0;n<e.length;n++){const r=e[n];if(!r.measured||r.measured.width==null||r.measured.height==null){t=!0;break}}return t?e.map(n=>{var r,i;return((r=n.measured)==null?void 0:r.width)!=null&&((i=n.measured)==null?void 0:i.height)!=null?n:{...n,measured:{width:n.width||Bo,height:n.height||$o}}}):e}function jo({cards:e,nodes:t=[],edges:n=[],nodeTypes:r,edgeTypes:i,canvasNodeTypes:o,domNodeLimit:c=50,dark:h,gridSize:m,width:f="100%",height:y="420px",className:x="",style:k={},zoomMin:S,zoomMax:z,initialCamera:W,fitView:j,fitViewOptions:H,onNodesChange:F,onEdgesChange:$,onConnect:Y,onConnectStart:A,onConnectEnd:P,onNodeClick:Z,onNodeDoubleClick:U,onNodeMouseEnter:X,onNodeMouseMove:M,onNodeMouseLeave:d,onNodeContextMenu:v,onNodeDragStart:L,onNodeDrag:T,onNodeDragStop:B,onEdgeClick:Q,onEdgeDoubleClick:ne,onEdgeMouseEnter:ee,onEdgeMouseMove:ae,onEdgeMouseLeave:me,onEdgeContextMenu:we,onPaneClick:Re,onPaneContextMenu:ce,onPaneMouseEnter:pe,onPaneMouseMove:oe,onPaneMouseLeave:ge,onSelectionChange:Se,onInit:De,onMoveStart:xe,onMove:fe,onMoveEnd:Ae,onDelete:Fe,onBeforeDelete:Ye,onError:nt,onDragOver:He,onDrop:$e,onDragEnter:Le,onDragLeave:ze,nodesDraggable:Je,nodesConnectable:rt,elementsSelectable:_e,multiSelectionKeyCode:Ue,selectionOnDrag:Ve,selectionMode:zt,connectionMode:un,connectionRadius:dn,connectOnClick:fn,isValidConnection:hn,defaultEdgeOptions:qt,snapToGrid:mt,snapGrid:vt,deleteKeyCode:Pt,panActivationKeyCode:Nn,panOnScroll:In,panOnScrollMode:ot,panOnScrollSpeed:lr,zoomOnScroll:Tn,zoomOnDoubleClick:Ln,zoomOnPinch:Nt,preventScrolling:It,translateExtent:Bn,nodeExtent:$n,autoPanOnNodeDrag:An,autoPanOnConnect:kt,autoPanSpeed:be,edgesReconnectable:Tt,elevateNodesOnSelect:Pe,elevateEdgesOnSelect:de,noDragClassName:bt,noPanClassName:se,onSelectionDragStart:Ne,onSelectionDrag:ft,onSelectionDragStop:gn,edgeRouting:Lt=!0,onHudUpdate:ht,onNodesProcessed:jn,showHud:Dn=!0,showHint:Xe=!0,hintText:Oe="Drag to pan · Scroll to zoom",children:Bt,...gt}){const[Ke,$t]=a.useState({wx:0,wy:0,zoom:"1.00"}),Zt=a.useRef(null),yn=a.useRef(null),xn=a.useCallback(_=>{$t(_),ht==null||ht(_)},[ht]),At=a.useMemo(()=>({...To,...r}),[r]),st=a.useMemo(()=>({...Lo,...i}),[i]),qe=a.useMemo(()=>Ao(t),[t]),[wt,V]=a.useState(()=>new Set),it=a.useRef(wt);it.current=wt;const jt=a.useCallback(_=>{V(ve=>{const K=new Set(ve);return K.add(_),K})},[]),Dt=a.useCallback(_=>{V(ve=>{const K=new Set(ve);return K.delete(_),K})},[]),Ht=a.useCallback(_=>{V(ve=>{const K=new Set(ve);return K.has(_)?K.delete(_):K.add(_),K})},[]),yt=a.useMemo(()=>qe.filter(_=>_.type&&At[_.type]),[qe,At]),_t=a.useMemo(()=>n.filter(_=>_.type&&st[_.type]),[n,st]),[Ct,Wt]=a.useState(()=>new Set),Ft=a.useRef(new Set),Yt=a.useRef(!0),ke=a.useMemo(()=>{const _=new Set(Ct);for(const K of wt)_.add(K);if(Yt.current&&Ct.size===0)for(const K of yt)_.add(K.id);else Yt.current=!1;for(const K of yt)(K.selected||K.dragging)&&_.add(K.id);const ve=Ft.current;if(ve.size===_.size){let K=!0;for(const Ce of _)if(!ve.has(Ce)){K=!1;break}if(K)return ve}return Ft.current=_,_},[yt,wt,Ct]),xt=a.useMemo(()=>{if(c===0)return[];const _=qe.filter(ve=>ke.has(ve.id));return _.sort((ve,K)=>{const Ce=ve.type==="group"||!ve.parentId&&_.some(g=>g.parentId===ve.id),u=K.type==="group"||!K.parentId&&_.some(g=>g.parentId===K.id);return Ce&&!u?-1:!Ce&&u?1:0})},[qe,ke,c]),We=a.useMemo(()=>t.map(_=>ke.has(_.id)?{..._,_customRendered:!0}:_),[t,ke]),Hn=a.useMemo(()=>n.map(_=>_.type&&st[_.type]?{..._,_customRendered:!0}:_),[n,st]),{wrapRef:pt,canvasRef:Xt,canvasReady:at,onPointerDown:Mt,onPointerMove:pn,onPointerUp:Be,store:le}=Rr({cards:e,nodes:We,edges:Hn,dark:h,gridSize:m,zoomMin:S,zoomMax:z,initialCamera:W,fitView:j,fitViewOptions:H,onHudUpdate:xn,onNodesProcessed:jn,onNodesChange:F,onEdgesChange:$,onConnect:Y,onConnectStart:A,onConnectEnd:P,onNodeClick:Z,onNodeDoubleClick:U,onNodeMouseEnter:X,onNodeMouseMove:M,onNodeMouseLeave:d,onNodeContextMenu:v,onNodeDragStart:L,onNodeDrag:T,onNodeDragStop:B,onEdgeClick:Q,onEdgeDoubleClick:ne,onEdgeMouseEnter:ee,onEdgeMouseMove:ae,onEdgeMouseLeave:me,onEdgeContextMenu:we,onPaneClick:Re,onPaneContextMenu:ce,onPaneMouseEnter:pe,onPaneMouseMove:oe,onPaneMouseLeave:ge,onSelectionChange:Se,onInit:De,onMoveStart:xe,onMove:fe,onMoveEnd:Ae,onDelete:Fe,onBeforeDelete:Ye,onError:nt,nodesDraggable:Je,nodesConnectable:rt,elementsSelectable:_e,multiSelectionKeyCode:Ue,selectionOnDrag:Ve,selectionMode:zt,connectionMode:un,connectionRadius:dn,connectOnClick:fn,isValidConnection:hn,defaultEdgeOptions:qt,snapToGrid:mt,snapGrid:vt,deleteKeyCode:Pt,panActivationKeyCode:Nn,panOnScroll:In,panOnScrollMode:ot,panOnScrollSpeed:lr,zoomOnScroll:Tn,zoomOnDoubleClick:Ln,zoomOnPinch:Nt,preventScrolling:It,translateExtent:Bn,nodeExtent:$n,autoPanOnNodeDrag:An,autoPanOnConnect:kt,autoPanSpeed:be,edgesReconnectable:Tt,elevateNodesOnSelect:Pe,elevateEdgesOnSelect:de,noDragClassName:bt,noPanClassName:se,onSelectionDragStart:Ne,onSelectionDrag:ft,onSelectionDragStop:gn,edgeRouting:Lt}),Gt=a.useRef(yt);Gt.current=yt;const Qt=a.useRef(c);Qt.current=c,a.useEffect(()=>{let _;const ve=()=>{const Ce=Gt.current,u=Qt.current;if(u===0||!Ce.length)return;const g=le.cameraRef.current,l=le.wrapRef.current;if(!l)return;const p=l.clientWidth,C=l.clientHeight,E=(-g.x+p/2)/g.zoom,w=(-g.y+C/2)/g.zoom,b=it.current;let R=b.size;for(const N of Ce)(N.selected||N.dragging)&&R++;const D=Math.max(0,u-R);if(D===0)Wt(N=>N.size===0?N:new Set);else{const N=new Set(b);for(const O of Ce)(O.selected||O.dragging)&&N.add(O.id);const q=[];for(let O=0;O<Ce.length;O++){const ie=Ce[O];if(N.has(ie.id))continue;const Ie=ie._absolutePosition||ie.position,te=Ie.x+(ie.width||160)/2-E,ue=Ie.y+(ie.height||60)/2-w;q.push({id:ie.id,dist:te*te+ue*ue})}q.sort((O,ie)=>O.dist-ie.dist);const J=new Set;for(let O=0;O<Math.min(D,q.length);O++)J.add(q[O].id);Wt(O=>{if(O.size!==J.size)return J;for(const ie of J)if(!O.has(ie))return J;return O})}},K=setTimeout(ve,100);return _=setInterval(ve,500),()=>{clearTimeout(K),clearInterval(_)}},[le.cameraRef,le.wrapRef]);const Rt=a.useRef(new Set);a.useEffect(()=>{if(!o||!le.workerRef.current)return;let _=!1;async function ve(Ce){const u=new Blob([Ce],{type:"image/svg+xml"}),g=URL.createObjectURL(u),l=new Image;return l.src=g,await l.decode(),URL.revokeObjectURL(g),createImageBitmap(l)}async function K(){var p,C,E;const Ce={},u=[],g={},l={};for(const[w,b]of Object.entries(o)){if(typeof b=="function"){g[w]=b;continue}if(typeof b=="object"&&b!==null&&!(b instanceof ImageBitmap)&&!(b instanceof HTMLImageElement)&&!(b instanceof HTMLCanvasElement)&&("fill"in b||"stroke"in b||"title"in b||"accent"in b)){l[w]=b;continue}try{let R;b instanceof ImageBitmap?R=b:typeof b=="string"?R=await ve(b):b instanceof HTMLImageElement?R=await createImageBitmap(b):b instanceof HTMLCanvasElement&&(R=await createImageBitmap(b)),R&&!_&&(Ce[w]=R,u.push(R))}catch(R){console.warn(`[InfiniteCanvas] Failed to convert canvasNodeType "${w}":`,R)}}if(!_&&Object.keys(Ce).length>0&&((p=le.workerRef.current)==null||p.postMessage({type:"nodeTypeBitmaps",data:{bitmaps:Ce}},u)),!_&&Object.keys(l).length>0&&((C=le.workerRef.current)==null||C.postMessage({type:"nodeTypeConfigs",data:{configs:l}})),!_&&Object.keys(g).length>0){const w=new Map,b={},R={},D=[];let N=Rt.current.size;for(const q of t){const J=g[q.type];if(J)try{const O=J(q.data);if(!O)continue;let ie=w.get(O);if(!ie&&(ie="bmp_"+N++,w.set(O,ie),!Rt.current.has(O))){const Ie=await ve(O);if(_)return;b[ie]=Ie,D.push(Ie),Rt.current.add(O)}R[q.id]=ie}catch(O){console.warn(`[InfiniteCanvas] canvasNodeType fn error for node "${q.id}":`,O)}}_||(E=le.workerRef.current)==null||E.postMessage({type:"nodeBitmaps",data:{cache:b,keys:R}},D)}}return K(),()=>{_=!0}},[o,t,le.workerRef]);const Ze=a.useContext(St),Jt=Ze&&typeof Ze.getState=="function";a.useEffect(()=>{Jt&&queueMicrotask(()=>{Ze.setState({nodes:qe,edges:n,nodesRef:le.nodesRef,edgesRef:le.edgesRef,onNodesChangeRef:le.onNodesChangeRef,onEdgesChangeRef:le.onEdgesChangeRef,cameraRef:le.cameraRef,wrapRef:le.wrapRef,workerRef:le.workerRef})})},[Jt,qe,n,le,Ze]);const Me=a.useMemo(()=>({...le,edgeLabelContainerRef:Zt,viewportPortalRef:yn,pinNode:jt,unpinNode:Dt,togglePinNode:Ht,get pinnedNodeIds(){return it.current},get nodes(){return qe},get edges(){return n},get viewport(){return le.cameraRef.current},get minZoom(){return le.zoomMin||.1},get maxZoom(){return le.zoomMax||5},get domNode(){return le.wrapRef.current},get width(){var _;return((_=le.wrapRef.current)==null?void 0:_.clientWidth)||0},get height(){var _;return((_=le.wrapRef.current)==null?void 0:_.clientHeight)||0}}),[le,qe,n,jt,Dt,Ht]),ct=a.useRef(null),lt=a.useRef(null),Vt=a.useRef(null),Kt=a.useRef(null),mn=a.useRef(null);a.useEffect(()=>{let _;const ve=()=>{const K=le.cameraRef.current,Ce=`translate(${K.x}px, ${K.y}px) scale(${K.zoom})`,u=`translate(${K.x}, ${K.y}) scale(${K.zoom})`;ct.current&&(ct.current.style.transform=Ce),lt.current&<.current.setAttribute("transform",u),Vt.current&&(Vt.current.style.transform=Ce),Kt.current&&(Kt.current.style.transform=Ce);const g=pt.current;if(g){const l=K.zoom<.15?"lod-minimal":K.zoom<.35?"lod-reduced":null;l!==mn.current&&(g.classList.remove("lod-minimal","lod-reduced"),l&&g.classList.add(l),mn.current=l)}_=requestAnimationFrame(ve)};return _=requestAnimationFrame(ve),()=>cancelAnimationFrame(_)},[le]);const[Ot,_n]=a.useState(null);a.useEffect(()=>{if(!xt.length)return;let _;const ve=()=>{var b,R;const K=le.cameraRef.current,Ce=le.wrapRef.current;if(!Ce){_=requestAnimationFrame(ve);return}const u=Ce.getBoundingClientRect(),g=200,l=-K.x/K.zoom-g,p=-K.y/K.zoom-g,C=(u.width-K.x)/K.zoom+g,E=(u.height-K.y)/K.zoom+g,w=new Set;for(const D of xt){const N=D._absolutePosition||D.position,q=D.width||((b=D.measured)==null?void 0:b.width)||200,J=D.height||((R=D.measured)==null?void 0:R.height)||100;N.x+q>=l&&N.x<=C&&N.y+J>=p&&N.y<=E&&w.add(D.id)}_n(D=>{if(!D||D.size!==w.size)return w;for(const N of w)if(!D.has(N))return w;return D}),_=requestAnimationFrame(ve)};return _=requestAnimationFrame(ve),()=>cancelAnimationFrame(_)},[xt,le]);const Wn=a.useMemo(()=>Ot?xt.filter(_=>Ot.has(_.id)):xt,[xt,Ot]),Fn=xt.length>0,Yn=_t.length>0;return I.jsx(St.Provider,{value:Me,children:I.jsxs("div",{ref:pt,className:`ric-wrap ${x}`,style:{width:f,height:y,...k},onPointerDown:Mt,onPointerMove:pn,onPointerUp:Be,onDragOver:He,onDrop:$e,onDragEnter:Le,onDragLeave:ze,tabIndex:0,children:[I.jsx("canvas",{ref:Xt,className:"ric-canvas"}),!at&&I.jsx("div",{className:"ric-loader",children:I.jsx("div",{className:"ric-spinner"})}),Yn&&I.jsx("svg",{className:"ric-edges-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:I.jsx("g",{ref:lt,children:_t.map(_=>I.jsx(xo,{edge:_,edgeType:st[_.type],nodes:t,reconnectable:Tt},_.id))})}),Fn&&I.jsx("div",{ref:ct,className:"ric-nodes-overlay",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:10},children:Wn.map(_=>I.jsx(fo,{node:_,nodeType:At[_.type]},_.id))}),I.jsx("div",{ref:_=>{Zt.current=_,Vt.current=_},className:"ric-edge-labels",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:5}}),I.jsx("div",{ref:_=>{yn.current=_,Kt.current=_},className:"ric-viewport-portal",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:6}}),Xe&&I.jsx("div",{className:"ric-hint",children:Oe}),Dn&&I.jsxs("div",{className:"ric-info",children:["world: (",Ke.wx,", ",Ke.wy,") zoom: ",Ke.zoom,"x",Ke.nodeCount>0&&I.jsxs(I.Fragment,{children:[" nodes: ",Ke.nodeCount]}),Ke.edgeCount>0&&I.jsxs(I.Fragment,{children:[" edges: ",Ke.edgeCount]})]}),I.jsx(zr,{selectionKeyCode:Ue||"Shift",selectionMode:zt||"partial"}),Bt]})})}function Do({children:e}){const t=a.useRef(null);return t.current||(t.current=co()),I.jsx(St.Provider,{value:t.current,children:e})}function jr(e,t){const n=[],r=new Map,i=[];for(const o of e)if(o.type==="add")i.push(o);else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const c=r.get(o.id);c?c.push(o):r.set(o.id,[o])}for(const o of t){const c=r.get(o.id);if(!c){n.push(o);continue}if(c[0].type==="remove")continue;if(c[0].type==="replace"){n.push({...c[0].item});continue}const h={...o};for(const m of c)Ho(m,h);n.push(h)}for(const o of i)o.index!==void 0?n.splice(o.index,0,{...o.item}):n.push({...o.item});return n}function Ho(e,t){switch(e.type){case"select":t.selected=e.selected;break;case"position":e.position!==void 0&&(t.position=e.position),e.dragging!==void 0&&(t.dragging=e.dragging);break;case"dimensions":e.dimensions!==void 0&&(t.measured={...e.dimensions},(e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height)),e.handleBounds!==void 0&&(t.handleBounds=e.handleBounds);break}}function Dr(e,t){return jr(e,t)}function Hr(e,t){return jr(e,t)}function _o(e,t){return!e.source||!e.target?(console.warn("addEdge: source and target are required"),t):t.some(r=>r.source===e.source&&r.target===e.target&&(r.sourceHandle||null)===(e.sourceHandle||null)&&(r.targetHandle||null)===(e.targetHandle||null))?t:[...t,{id:e.id||`e-${e.source}-${e.target}`,...e}]}function Wo(e){const[t,n]=a.useState(e),r=a.useCallback(i=>n(o=>Dr(i,o)),[]);return[t,n,r]}function Fo(e){const[t,n]=a.useState(e),r=a.useCallback(i=>n(o=>Hr(i,o)),[]);return[t,n,r]}function _r(){const e=kr(),t=a.useCallback(()=>typeof e.getState=="function"?e.getState():e,[e]),n=a.useCallback(()=>[...t().nodesRef.current],[t]),r=a.useCallback(()=>[...t().edgesRef.current],[t]),i=a.useCallback(M=>t().nodesRef.current.find(d=>d.id===M),[t]),o=a.useCallback(M=>t().edgesRef.current.find(d=>d.id===M),[t]),c=a.useCallback(M=>{var d,v,L,T;if(typeof M=="function"){const B=M(t().nodesRef.current);(v=(d=t().onNodesChangeRef).current)==null||v.call(d,[...t().nodesRef.current.map(Q=>({id:Q.id,type:"remove"})),...B.map(Q=>({type:"add",item:Q}))])}else(T=(L=t().onNodesChangeRef).current)==null||T.call(L,[...t().nodesRef.current.map(B=>({id:B.id,type:"remove"})),...M.map(B=>({type:"add",item:B}))])},[t]),h=a.useCallback(M=>{var d,v,L,T;if(typeof M=="function"){const B=M(t().edgesRef.current);(v=(d=t().onEdgesChangeRef).current)==null||v.call(d,[...t().edgesRef.current.map(Q=>({id:Q.id,type:"remove"})),...B.map(Q=>({type:"add",item:Q}))])}else(T=(L=t().onEdgesChangeRef).current)==null||T.call(L,[...t().edgesRef.current.map(B=>({id:B.id,type:"remove"})),...M.map(B=>({type:"add",item:B}))])},[t]),m=a.useCallback(M=>{var v,L;const d=Array.isArray(M)?M:[M];(L=(v=t().onNodesChangeRef).current)==null||L.call(v,d.map(T=>({type:"add",item:T})))},[t]),f=a.useCallback(M=>{var v,L;const d=Array.isArray(M)?M:[M];(L=(v=t().onEdgesChangeRef).current)==null||L.call(v,d.map(T=>({type:"add",item:T})))},[t]),y=a.useCallback(({nodes:M=[],edges:d=[]})=>{if(M.length&&t().onNodesChangeRef.current){t().onNodesChangeRef.current(M.map(L=>({id:L.id,type:"remove"})));const v=wr(M,t().edgesRef.current);v.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(v.map(L=>({id:L.id,type:"remove"})))}d.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(d.map(v=>({id:v.id,type:"remove"})))},[t]),x=a.useCallback(()=>{const M=t().cameraRef.current;return{x:M.x,y:M.y,zoom:M.zoom}},[t]),k=a.useRef(null),S=a.useCallback((M,d)=>{if(k.current&&cancelAnimationFrame(k.current),!d||d<=0){t().cameraRef.current={...M},t().sendCamera();return}const v={...t().cameraRef.current},L=performance.now(),T=B=>{const Q=B-L,ne=Math.min(Q/d,1),ee=1-Math.pow(1-ne,3);t().cameraRef.current={x:v.x+(M.x-v.x)*ee,y:v.y+(M.y-v.y)*ee,zoom:v.zoom+(M.zoom-v.zoom)*ee},t().sendCamera(),ne<1&&(k.current=requestAnimationFrame(T))};k.current=requestAnimationFrame(T)},[t]),z=a.useCallback((M,d)=>{const v={x:M.x??t().cameraRef.current.x,y:M.y??t().cameraRef.current.y,zoom:M.zoom??t().cameraRef.current.zoom};S(v,d==null?void 0:d.duration)},[t,S]),W=a.useCallback(()=>t().cameraRef.current.zoom,[t]),j=a.useCallback(M=>{const d=t().cameraRef.current,v=t().wrapRef.current;if(!v)return;const L=v.getBoundingClientRect(),T=L.width/2,B=L.height/2,Q=1.2,ne={x:T-(T-d.x)*Q,y:B-(B-d.y)*Q,zoom:Math.min(t().zoomMax,d.zoom*Q)};S(ne,M==null?void 0:M.duration)},[t,S]),H=a.useCallback(M=>{const d=t().cameraRef.current,v=t().wrapRef.current;if(!v)return;const L=v.getBoundingClientRect(),T=L.width/2,B=L.height/2,Q=1/1.2,ne={x:T-(T-d.x)*Q,y:B-(B-d.y)*Q,zoom:Math.max(t().zoomMin,d.zoom*Q)};S(ne,M==null?void 0:M.duration)},[t,S]),F=a.useCallback((M,d)=>{const v=t().cameraRef.current,L=t().wrapRef.current;if(!L)return;const T=L.getBoundingClientRect(),B=T.width/2,Q=T.height/2,ne=Math.min(t().zoomMax,Math.max(t().zoomMin,M)),ee=ne/v.zoom,ae={x:B-(B-v.x)*ee,y:Q-(Q-v.y)*ee,zoom:ne};S(ae,d==null?void 0:d.duration)},[t,S]),$=a.useCallback((M={})=>{const d=t().nodesRef.current;if(!d.length)return;const v=t().wrapRef.current;if(!v)return;const L=v.getBoundingClientRect(),T=M.padding??.1,B=M.nodes?d.filter(ee=>M.nodes.some(ae=>ae.id===ee.id)):d;if(!B.length)return;const Q=Mn(B),ne=Ut(Q,L.width,L.height,T);M.maxZoom&&(ne.zoom=Math.min(ne.zoom,M.maxZoom)),M.minZoom&&(ne.zoom=Math.max(ne.zoom,M.minZoom)),S(ne,M.duration)},[t,S]),Y=a.useCallback((M,d={})=>{const v=t().wrapRef.current;if(!v)return;const L=v.getBoundingClientRect(),T=d.padding??.1,B=Ut(M,L.width,L.height,T);d.maxZoom&&(B.zoom=Math.min(B.zoom,d.maxZoom)),d.minZoom&&(B.zoom=Math.max(B.zoom,d.minZoom)),S(B,d.duration)},[t,S]),A=a.useCallback((M,d,v={})=>{const L=t().wrapRef.current;if(!L)return;const T=L.getBoundingClientRect(),B=v.zoom??t().cameraRef.current.zoom,Q={x:T.width/2-M*B,y:T.height/2-d*B,zoom:B};S(Q,v.duration)},[t,S]),P=a.useCallback(()=>({nodes:[...t().nodesRef.current],edges:[...t().edgesRef.current],viewport:{...t().cameraRef.current}}),[t]),Z=a.useCallback(M=>t().screenToWorld(M.x,M.y),[t]),U=a.useCallback(M=>{const d=t().cameraRef.current,v=t().wrapRef.current;if(!v)return{x:0,y:0};const L=v.getBoundingClientRect();return{x:M.x*d.zoom+d.x+L.left,y:M.y*d.zoom+d.y+L.top}},[t]),X=a.useCallback((M,d)=>{var T,B;const v=t().nodesRef.current.find(Q=>Q.id===M);if(!v)return;const L=typeof d=="function"?d(v.data):{...v.data,...d};(B=(T=t().onNodesChangeRef).current)==null||B.call(T,[{id:M,type:"replace",item:{...v,data:L}}])},[t]);return{getNodes:n,getEdges:r,getNode:i,getEdge:o,setNodes:c,setEdges:h,addNodes:m,addEdges:f,deleteElements:y,getViewport:x,setViewport:z,getZoom:W,zoomIn:j,zoomOut:H,zoomTo:F,fitView:$,fitBounds:Y,setCenter:A,screenToFlowPosition:Z,flowToScreenPosition:U,updateNodeData:X,toObject:P}}function Yo(){return Te().nodes}function Xo(){return Te().edges}function Oo(){return Te().viewport}function Uo(){return Te().connection}function qo(e){const t=Te(),n=Array.isArray(e)?e:[e];return a.useMemo(()=>n.map(r=>{const i=t.nodes.find(o=>o.id===r);return i?{id:i.id,type:i.type,data:i.data}:null}).filter(Boolean),[t.nodes,...n])}function Zo(e){const t=Te();return a.useMemo(()=>t.edges.filter(n=>n.source===e||n.target===e),[t.edges,e])}function Go({nodeId:e,type:t,handleId:n}){const r=Te();return a.useMemo(()=>r.edges.filter(i=>t==="source"?i.source===e&&(n?i.sourceHandle===n:!0):i.target===e&&(n?i.targetHandle===n:!0)),[r.edges,e,t,n])}function Qo({onChange:e,onStart:t,onEnd:n}){const r=Te(),i=a.useRef(e),o=a.useRef(t),c=a.useRef(n);a.useEffect(()=>{i.current=e},[e]),a.useEffect(()=>{o.current=t},[t]),a.useEffect(()=>{c.current=n},[n]),a.useEffect(()=>{const h=m=>{var f;(f=i.current)==null||f.call(i,{x:m.x,y:m.y,zoom:m.zoom})};return r.viewportListeners.add(h),()=>r.viewportListeners.delete(h)},[s])}function Jo({onChange:e}){const t=Te(),n=a.useRef(e);a.useEffect(()=>{n.current=e},[e]),a.useEffect(()=>{const r=i=>{var o;(o=n.current)==null||o.call(n,i)};return t.selectionListeners.add(r),()=>t.selectionListeners.delete(r)},[s])}function Vo(e){const[t,n]=a.useState(!1),r=Array.isArray(e)?e:[e];return a.useEffect(()=>{const i=c=>{r.includes(c.key)&&n(!0)},o=c=>{r.includes(c.key)&&n(!1)};return window.addEventListener("keydown",i),window.addEventListener("keyup",o),()=>{window.removeEventListener("keydown",i),window.removeEventListener("keyup",o)}},[r.join(",")]),t}function Ko(){const e=Te();return a.useCallback(t=>{var n;(n=e.workerRef.current)==null||n.postMessage({type:"nodes",data:{nodes:[...s().nodesRef.current]}})},[s])}const es=e=>{var t;return((t=e.nodes)==null?void 0:t.length)>0};function ts(e={}){return Te(es)}function ns(e){const t=Te();return a.useMemo(()=>t.nodes.find(n=>n.id===e)||void 0,[t.nodes,e])}function rs(e,t){return Te(e,t)}function os(){return kr()}function ss({maxHistorySize:e=100}={}){const t=Te(),n=a.useRef([]),r=a.useRef([]),[,i]=a.useState(0),o=a.useRef(null),c=a.useCallback(()=>{const f={nodes:s().nodesRef.current.map(y=>({...y,data:{...y.data}})),edges:s().edgesRef.current.map(y=>({...y}))};o.current&&JSON.stringify(o.current.nodes.map(y=>y.id))===JSON.stringify(f.nodes.map(y=>y.id))&&JSON.stringify(o.current.edges.map(y=>y.id))===JSON.stringify(f.edges.map(y=>y.id))||(n.current.push(f),n.current.length>e&&n.current.shift(),r.current=[],o.current=f,i(y=>y+1))},[t,e]),h=a.useCallback(()=>{var y,x,k,S;const f=n.current.pop();f&&(r.current.push({nodes:s().nodesRef.current.map(z=>({...z,data:{...z.data}})),edges:s().edgesRef.current.map(z=>({...z}))}),(x=(y=s().onNodesChangeRef).current)==null||x.call(y,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...f.nodes.map(z=>({type:"add",item:z}))]),(S=(k=s().onEdgesChangeRef).current)==null||S.call(k,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...f.edges.map(z=>({type:"add",item:z}))]),o.current=f,i(z=>z+1))},[s]),m=a.useCallback(()=>{var y,x,k,S;const f=r.current.pop();f&&(n.current.push({nodes:s().nodesRef.current.map(z=>({...z,data:{...z.data}})),edges:s().edgesRef.current.map(z=>({...z}))}),(x=(y=s().onNodesChangeRef).current)==null||x.call(y,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...f.nodes.map(z=>({type:"add",item:z}))]),(S=(k=s().onEdgesChangeRef).current)==null||S.call(k,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...f.edges.map(z=>({type:"add",item:z}))]),o.current=f,i(z=>z+1))},[s]);return{undo:h,redo:m,takeSnapshot:c,canUndo:n.current.length>0,canRedo:r.current.length>0}}function is(e){const t=a.useRef(e);return a.useEffect(()=>{t.current=e},[e]),a.useCallback(n=>r=>{const i=t.current(r);i!==!1&&i!=null&&n(Array.isArray(i)?i:r)},[])}function as(e){const t=a.useRef(e);return a.useEffect(()=>{t.current=e},[e]),a.useCallback(n=>r=>{const i=t.current(r);i!==!1&&i!=null&&n(Array.isArray(i)?i:r)},[])}const qn=160,Zn=60;function cs({width:e=200,height:t=150,nodeColor:n="#3b82f6",nodeStrokeColor:r="#fff",maskColor:i="rgba(0,0,0,0.1)",style:o={},className:c=""}){const h=Te(),m=a.useRef(null),f=a.useRef(null),y=a.useCallback(()=>{const x=m.current;if(!x)return;const k=x.getContext("2d"),S=window.devicePixelRatio||1;x.width=e*S,x.height=t*S,k.scale(S,S),k.clearRect(0,0,e,t);const z=h.nodesRef.current;if(!z.length)return;let W=1/0,j=1/0,H=-1/0,F=-1/0;for(const d of z){const v=d.width||qn,L=d.height||Zn;d.position.x<W&&(W=d.position.x),d.position.y<j&&(j=d.position.y),d.position.x+v>H&&(H=d.position.x+v),d.position.y+L>F&&(F=d.position.y+L)}const $=40;W-=$,j-=$,H+=$,F+=$;const Y=H-W,A=F-j,P=Math.min(e/Y,t/A),Z=(e-Y*P)/2,U=(t-A*P)/2;for(const d of z){if(d.hidden)continue;const v=d.width||qn,L=d.height||Zn,T=(d.position.x-W)*P+Z,B=(d.position.y-j)*P+U,Q=v*P,ne=L*P;k.fillStyle=d.selected?"#f59e0b":typeof n=="function"?n(d):n,k.fillRect(T,B,Math.max(Q,2),Math.max(ne,2))}const X=h.cameraRef.current,M=h.wrapRef.current;if(M){const d=M.getBoundingClientRect(),v=-X.x/X.zoom,L=-X.y/X.zoom,T=d.width/X.zoom,B=d.height/X.zoom;k.fillStyle=i,k.fillRect(0,0,e,t);const Q=(v-W)*P+Z,ne=(L-j)*P+U,ee=T*P,ae=B*P;k.clearRect(Q,ne,ee,ae);for(const me of z){if(me.hidden)continue;const we=me.width||qn,Re=me.height||Zn,ce=(me.position.x-W)*P+Z,pe=(me.position.y-j)*P+U;k.fillStyle=me.selected?"#f59e0b":typeof n=="function"?n(me):n,k.fillRect(ce,pe,Math.max(we*P,2),Math.max(Re*P,2))}k.strokeStyle="#3b82f6",k.lineWidth=1.5,k.strokeRect(Q,ne,ee,ae)}},[h,e,t,n,r,i]);return a.useEffect(()=>{let x=!0;function k(){x&&(y(),f.current=requestAnimationFrame(k))}const S=setInterval(()=>{cancelAnimationFrame(f.current),f.current=requestAnimationFrame(k)},66);return y(),()=>{x=!1,clearInterval(S),cancelAnimationFrame(f.current)}},[y]),I.jsx("canvas",{ref:m,className:`ric-minimap ${c}`,style:{position:"absolute",bottom:30,right:10,width:e,height:t,borderRadius:4,border:"1px solid rgba(0,0,0,0.1)",background:"rgba(255,255,255,0.9)",pointerEvents:"none",...o}})}function ls(){return I.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[I.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),I.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function us(){return I.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:I.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function ds(){return I.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:I.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}function fs(){return I.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[I.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),I.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function hs(){return I.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[I.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),I.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})}function sn({children:e,className:t="",...n}){return I.jsx("button",{className:`ric-controls-button ${t}`,style:ys,...n,children:e})}function gs({showZoom:e=!0,showFitView:t=!0,showInteractive:n=!1,fitViewOptions:r,onZoomIn:i,onZoomOut:o,onFitView:c,onInteractiveChange:h,position:m="bottom-left",orientation:f="vertical",style:y={},className:x="","aria-label":k="Canvas controls",children:S}){const z=Te(),{zoomIn:W,zoomOut:j,fitView:H,getZoom:F}=_r(),[$,Y]=a.useState(!0),A=F()<=z.zoomMin,P=F()>=z.zoomMax,Z=a.useCallback(()=>{W(),i==null||i()},[W,i]),U=a.useCallback(()=>{j(),o==null||o()},[j,o]),X=a.useCallback(()=>{H(r||{padding:.1}),c==null||c()},[H,r,c]),M=a.useCallback(()=>{const v=!$;Y(v),h==null||h(v)},[$,h]),d={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:30,left:10},"bottom-right":{bottom:30,right:10},"bottom-center":{bottom:30,left:"50%",transform:"translateX(-50%)"}}[m]||{bottom:30,left:10};return I.jsxs("div",{className:`ric-controls ${x}`,style:{position:"absolute",display:"flex",flexDirection:f==="horizontal"?"row":"column",gap:2,zIndex:5,...d,...y},role:"toolbar","aria-label":k,children:[e&&I.jsxs(I.Fragment,{children:[I.jsx(sn,{onClick:Z,disabled:P,title:"Zoom in","aria-label":"Zoom in",className:"ric-controls-zoomin",children:I.jsx(ls,{})}),I.jsx(sn,{onClick:U,disabled:A,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:I.jsx(us,{})})]}),t&&I.jsx(sn,{onClick:X,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:I.jsx(ds,{})}),n&&I.jsx(sn,{onClick:M,title:$?"Lock interactivity":"Unlock interactivity","aria-label":$?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:$?I.jsx(hs,{}):I.jsx(fs,{})}),S]})}const ys={width:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid rgba(0,0,0,0.12)",borderRadius:4,background:"#fff",cursor:"pointer",fontSize:16,lineHeight:1,color:"#333",padding:0},xs=a.memo(gs);function ps({variant:e="lines",gap:t=40,size:n=1,color:r,style:i={},className:o=""}){const c=Te();return c.workerRef.current&&c.workerRef.current.postMessage({type:"background",data:{variant:e,gap:t,size:n,color:r}}),null}function ms({position:e="top-left",style:t={},className:n="",children:r}){const i={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:10,left:10},"bottom-right":{bottom:10,right:10},"bottom-center":{bottom:10,left:"50%",transform:"translateX(-50%)"}}[e]||{top:10,left:10};return I.jsx("div",{className:`ric-panel ${n}`,style:{position:"absolute",zIndex:5,pointerEvents:"all",...i,...t},onPointerDown:o=>o.stopPropagation(),children:r})}function vs({minWidth:e=10,minHeight:t=10,maxWidth:n=1/0,maxHeight:r=1/0,isVisible:i=!0,handleStyle:o={},lineStyle:c={},color:h="#3b82f6",onResizeStart:m,onResize:f,onResizeEnd:y}){const x=a.useContext(cn),k=Te(),S=a.useRef(null),z=a.useCallback((H,F)=>{H.stopPropagation(),H.preventDefault();const $=k.nodesRef.current.find(P=>P.id===x);if(!$)return;S.current={direction:F,startX:H.clientX,startY:H.clientY,width:$.width||160,height:$.height||60},m==null||m(H,{width:S.current.width,height:S.current.height});const Y=P=>{var L,T;if(!S.current)return;const Z=S.current,U=k.cameraRef.current,X=(P.clientX-Z.startX)/U.zoom,M=(P.clientY-Z.startY)/U.zoom;let d=Z.width,v=Z.height;Z.direction.includes("e")&&(d=Math.min(n,Math.max(e,Z.width+X))),Z.direction.includes("w")&&(d=Math.min(n,Math.max(e,Z.width-X))),Z.direction.includes("s")&&(v=Math.min(r,Math.max(t,Z.height+M))),Z.direction.includes("n")&&(v=Math.min(r,Math.max(t,Z.height-M))),(T=(L=k.onNodesChangeRef).current)==null||T.call(L,[{id:x,type:"dimensions",dimensions:{width:d,height:v},setAttributes:!0}]),f==null||f(P,{width:d,height:v})},A=P=>{S.current=null,y==null||y(P,{}),window.removeEventListener("pointermove",Y),window.removeEventListener("pointerup",A)};window.addEventListener("pointermove",Y),window.addEventListener("pointerup",A)},[x,k,e,t,n,r,m,f,y]);if(!i)return null;const W=8,j={position:"absolute",width:W,height:W,background:h,border:"1px solid #fff",borderRadius:2,zIndex:20,...o};return I.jsxs(I.Fragment,{children:[I.jsx("div",{style:{...j,bottom:-W/2,right:-W/2,cursor:"nwse-resize"},onPointerDown:H=>z(H,"se")}),I.jsx("div",{style:{...j,bottom:-W/2,left:-W/2,cursor:"nesw-resize"},onPointerDown:H=>z(H,"sw")}),I.jsx("div",{style:{...j,top:-W/2,right:-W/2,cursor:"nesw-resize"},onPointerDown:H=>z(H,"ne")}),I.jsx("div",{style:{...j,top:-W/2,left:-W/2,cursor:"nwse-resize"},onPointerDown:H=>z(H,"nw")}),I.jsx("div",{style:{...j,top:"50%",right:-W/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:H=>z(H,"e")}),I.jsx("div",{style:{...j,top:"50%",left:-W/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:H=>z(H,"w")}),I.jsx("div",{style:{...j,left:"50%",top:-W/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:H=>z(H,"n")}),I.jsx("div",{style:{...j,left:"50%",bottom:-W/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:H=>z(H,"s")})]})}function bs({isVisible:e,position:t="top",offset:n=10,align:r="center",children:i,style:o={},className:c=""}){const h=a.useContext(cn),f=Te().nodes.find(k=>k.id===h);if(!(e!==void 0?e:f==null?void 0:f.selected))return null;const x={top:{bottom:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginBottom:n},bottom:{top:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginTop:n},left:{right:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginRight:n},right:{left:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginLeft:n}}[t]||{};return I.jsx("div",{className:`ric-node-toolbar ${c}`,style:{position:"absolute",zIndex:1e3,pointerEvents:"all",...x,...o},onPointerDown:k=>k.stopPropagation(),children:i})}function ws({isVisible:e=!1,x:t=0,y:n=0,alignX:r="center",alignY:i="center",children:o,style:c={},className:h=""}){if(!e)return null;const m=r==="center"?"-50%":r==="right"?"-100%":"0",f=i==="center"?"-50%":i==="bottom"?"-100%":"0";return I.jsx("div",{className:`ric-edge-toolbar ${h}`,style:{position:"absolute",left:t,top:n,transform:`translate(${m}, ${f})`,zIndex:1e3,pointerEvents:"all",...c},children:o})}function Ms({children:e}){var r;const n=(r=Te().edgeLabelContainerRef)==null?void 0:r.current;return n?mr.createPortal(e,n):null}function Rs({children:e}){var r;const n=(r=Te().viewportPortalRef)==null?void 0:r.current;return n?mr.createPortal(e,n):null}function Wr({fromX:e,fromY:t,toX:n,toY:r,fromPosition:i="right",toPosition:o="left",connectionLineType:c="default",connectionLineStyle:h,connectionLineComponent:m}){if(m)return I.jsx(m,{fromX:e,fromY:t,toX:n,toY:r,fromPosition:i,toPosition:o});let f;switch(c){case"straight":[f]=nr({sourceX:e,sourceY:t,targetX:n,targetY:r});break;case"step":[f]=Rn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o,borderRadius:0});break;case"smoothstep":[f]=Rn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o});break;case"simplebezier":[f]=or({sourceX:e,sourceY:t,targetX:n,targetY:r});break;default:[f]=rr({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o});break}return I.jsx("path",{d:f,fill:"none",className:"ric-connection-line",stroke:"#b1b1b7",strokeWidth:1.5,style:h})}Wr.displayName="ConnectionLine";const ks=a.memo(Wr),Cs=Object.freeze({Top:"top",Bottom:"bottom",Left:"left",Right:"right"}),Es=Object.freeze({Arrow:"arrow",ArrowClosed:"arrowclosed"});function Ss(e){const t=e.width||e.measured&&e.measured.width||0,n=e.height||e.measured&&e.measured.height||0,r=e._absolutePosition||e.position||{x:0,y:0};return{x:r.x,y:r.y,x2:r.x+t,y2:r.y+n}}exports.Background=ps;exports.BaseEdge=ln;exports.BezierEdge=tr;exports.ConnectionLine=ks;exports.ControlButton=sn;exports.Controls=xs;exports.DefaultNode=bo;exports.EdgeLabelRenderer=Ms;exports.EdgeText=Br;exports.EdgeToolbar=ws;exports.GroupNode=Tr;exports.Handle=an;exports.InfiniteCanvas=jo;exports.InfiniteCanvasProvider=Do;exports.InputNode=Nr;exports.MarkerType=Es;exports.MiniMap=cs;exports.NodeResizer=vs;exports.NodeToolbar=bs;exports.OutputNode=Ir;exports.Panel=ms;exports.Position=Cs;exports.SelectionBox=zr;exports.SimpleBezierEdge=cr;exports.SmoothStepEdge=ar;exports.StepEdge=Ar;exports.StraightEdge=ir;exports.ViewportPortal=Rs;exports.addEdge=_o;exports.applyEdgeChanges=Hr;exports.applyNodeChanges=Dr;exports.boxToRect=Jr;exports.buildObstacles=sr;exports.clampPosition=Qn;exports.computeRoutedEdges=No;exports.getBezierEdgeCenter=wo;exports.getBezierPath=rr;exports.getBoundsOfBoxes=Vr;exports.getConnectedEdges=wr;exports.getEdgeCenter=Mo;exports.getIncomers=qr;exports.getNodeDimensions=er;exports.getNodesBounds=Mn;exports.getNodesInside=Gr;exports.getOutgoers=Zr;exports.getOverlappingArea=Kr;exports.getRoutedLabelPosition=Pn;exports.getSimpleBezierPath=or;exports.getSmoothStepPath=Rn;exports.getStraightPath=nr;exports.getViewportForBounds=Ut;exports.isEdge=Ur;exports.isNode=Or;exports.nodeToBox=Ss;exports.nodeToRect=eo;exports.reconnectEdge=Ro;exports.rectToBox=Qr;exports.routeSinglePath=Io;exports.routedPointsToPath=zn;exports.snapPosition=Gn;exports.useConnection=Uo;exports.useEdges=Xo;exports.useEdgesState=Fo;exports.useHandleConnections=Go;exports.useInfiniteCanvas=Rr;exports.useInternalNode=ns;exports.useKeyPress=Vo;exports.useNodeConnections=Zo;exports.useNodeId=lo;exports.useNodes=Yo;exports.useNodesData=qo;exports.useNodesInitialized=ts;exports.useNodesState=Wo;exports.useOnEdgesChangeMiddleware=as;exports.useOnNodesChangeMiddleware=is;exports.useOnSelectionChange=Jo;exports.useOnViewportChange=Qo;exports.useReactFlow=_r;exports.useStore=rs;exports.useStoreApi=os;exports.useUndoRedo=ss;exports.useUpdateNodeInternals=Ko;exports.useViewport=Oo;
|