@infinit-canvas/react 0.1.13 → 0.1.14
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 +1 -1
- package/dist/react-infinite-canvas.js +274 -272
- package/package.json +1 -1
|
@@ -864,4 +864,4 @@ function st() {
|
|
|
864
864
|
}
|
|
865
865
|
}
|
|
866
866
|
}
|
|
867
|
-
`,ir=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",vr],{type:"text/javascript;charset=utf-8"});function eo(e){let t;try{if(t=ir&&(self.URL||self.webkitURL).createObjectURL(ir),!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(vr),{type:"module",name:e==null?void 0:e.name})}}const Wn=new WeakMap;function to(e,t){if(Wn.has(e))return Wn.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 a={worker:r};return Wn.set(e,a),a}const at=160,nt=60,no=10;function br({cards:e=[],nodes:t=[],edges:n=[],onHudUpdate:r,onNodesProcessed:a,onNodesChange:o,onEdgesChange:i,onConnect:f,onNodeClick:p,onNodeDragStart:d,onNodeDrag:h,onNodeDragStop:v,onEdgeClick:E,onEdgeDoubleClick:M,onEdgeMouseEnter:z,onEdgeMouseMove:I,onEdgeMouseLeave:k,onEdgeContextMenu:j,onNodeDoubleClick:X,onNodeMouseEnter:D,onNodeMouseMove:_,onNodeMouseLeave:A,onNodeContextMenu:L,onPaneClick:Y,onPaneContextMenu:F,onPaneMouseEnter:B,onPaneMouseMove:b,onPaneMouseLeave:g,onSelectionChange:x,onConnectStart:N,onConnectEnd:$,onInit:W,onMoveStart:Q,onMove:re,onMoveEnd:ee,onDelete:oe,onBeforeDelete:ge,onError:ye,isValidConnection:J,dark:fe,gridSize:me=40,zoomMin:ae=.1,zoomMax:ue=4,initialCamera:Ne={x:0,y:0,zoom:1},fitView:Je=!1,fitViewOptions:le,nodesDraggable:$e=!0,nodesConnectable:Be=!0,elementsSelectable:_e=!0,multiSelectionKeyCode:he="Shift",selectionOnDrag:Me=!1,selectionMode:Oe="partial",connectionMode:je="loose",connectionRadius:it=20,connectOnClick:zt=!1,snapToGrid:Ae=!1,snapGrid:Xe=[15,15],deleteKeyCode:Ze=["Delete","Backspace"],panActivationKeyCode:St=" ",panOnScroll:an=!1,panOnScrollMode:At="free",panOnScrollSpeed:cn=.5,zoomOnScroll:un=!0,zoomOnDoubleClick:ln=!0,zoomOnPinch:dn=!0,preventScrolling:Dt=!0,translateExtent:dt,nodeExtent:ft,defaultEdgeOptions:Nt={},autoPanOnNodeDrag:En=!0,autoPanOnConnect:zn=!0,autoPanSpeed:rt=5,edgesReconnectable:sr=!1,elevateNodesOnSelect:Sn=!1,elevateEdgesOnSelect:Nn=!1,noDragClassName:Pt="nodrag",noPanClassName:It="nopan",onSelectionDragStart:Pn,onSelectionDrag:In,onSelectionDragStop:Ln,edgeRouting:ht=!0}={}){const pe=c.useRef(null),Ht=c.useRef(null),Ee=c.useRef(null),ie=c.useRef({...Ne}),gt=c.useRef([...e]),K=c.useRef([...t]),Re=c.useRef([...n]),fn=c.useRef(new Map),ct=c.useRef(!1),Lt=c.useRef(null),[Tn,$n]=c.useState(!1),We=c.useRef(null),Ye=c.useRef(null),_t=c.useRef(null),De=c.useRef(null),Wt=c.useRef(!1),Mt=c.useRef(null),[Ft,Bn]=c.useState({x:Ne.x,y:Ne.y,zoom:Ne.zoom}),[yt,xt]=c.useState(null),ut=c.useMemo(()=>new Set,[]),Ke=c.useMemo(()=>new Set,[]),Tt=c.useRef(!1),O=c.useRef({});O.current={onHudUpdate:r,onNodesProcessed:a,onNodesChange:o,onEdgesChange:i,onConnect:f,onNodeClick:p,onNodeDragStart:d,onNodeDrag:h,onNodeDragStop:v,onEdgeClick:E,onEdgeDoubleClick:M,onEdgeMouseEnter:z,onEdgeMouseMove:I,onEdgeMouseLeave:k,onEdgeContextMenu:j,onNodeDoubleClick:X,onNodeMouseEnter:D,onNodeMouseMove:_,onNodeMouseLeave:A,onNodeContextMenu:L,onPaneClick:Y,onPaneContextMenu:F,onPaneMouseEnter:B,onPaneMouseMove:b,onPaneMouseLeave:g,onSelectionChange:x,onConnectStart:N,onConnectEnd:$,onInit:W,onMoveStart:Q,onMove:re,onMoveEnd:ee,onDelete:oe,onBeforeDelete:ge,onError:ye,onSelectionDragStart:Pn,onSelectionDrag:In,onSelectionDragStop:Ln,isValidConnection:J};const pt={get current(){return O.current.onConnect}},$t={get current(){return O.current.onNodeClick}},Xt={get current(){return O.current.onNodeDragStart}},Yt={get current(){return O.current.onNodeDrag}},qt={get current(){return O.current.onNodeDragStop}},Ut={get current(){return O.current.onEdgeClick}},Ot={get current(){return O.current.onPaneClick}},we={get current(){return O.current.onSelectionChange}},mt={get current(){return O.current.onHudUpdate}},Bt={get current(){return O.current.onNodesProcessed}};c.useEffect(()=>{const l=u=>{u.key===he&&(Wt.current=!0),u.key===St&&(Tt.current=!0)},w=u=>{u.key===he&&(Wt.current=!1),u.key===St&&(Tt.current=!1)};return window.addEventListener("keydown",l),window.addEventListener("keyup",w),()=>{window.removeEventListener("keydown",l),window.removeEventListener("keyup",w)}},[he,St]);const ze={get current(){return O.current.onNodesChange?Zt:null}},Zt=l=>{var u,y,R;(y=(u=O.current).onNodesChange)==null||y.call(u,l);const w=[];for(let S=0;S<l.length;S++)l[S].type==="select"&&w.push({id:l[S].id,selected:l[S].selected});w.length>0&&((R=Ee.current)==null||R.postMessage({type:"nodeSelections",data:{selections:w}}))},Pe={get current(){return O.current.onEdgesChange?Gt:null}},Gt=l=>{var u,y,R;(y=(u=O.current).onEdgesChange)==null||y.call(u,l);const w=[];for(let S=0;S<l.length;S++)l[S].type==="select"&&w.push({id:l[S].id,selected:l[S].selected});w.length>0&&((R=Ee.current)==null||R.postMessage({type:"edgeSelections",data:{selections:w}}))},ot=c.useCallback(()=>{var y;const l=K.current.filter(R=>R.selected),w=Re.current.filter(R=>R.selected),u={nodes:l,edges:w};(y=we.current)==null||y.call(we,u);for(const R of Ke)R(u)},[Ke]);c.useEffect(()=>{var l;gt.current=[...e],(l=Ee.current)==null||l.postMessage({type:"cards",data:{cards:[...e]}})},[e]);const Rt=c.useCallback(l=>{const w={};for(const u of l)w[u.id]=u;return l.map(u=>{if(!u.parentId)return u;const y=w[u.parentId];if(!y)return u;let R=u.position.x,S=u.position.y,m=y;for(;m;)R+=m.position.x,S+=m.position.y,m=m.parentId?w[m.parentId]:null;return{...u,_absolutePosition:{x:R,y:S}}})},[]),et=c.useRef([]),vt=c.useCallback(l=>{const w=fn.current;if(!w||w.size===0)return l;const u={};for(const[,y]of w)u[y.nodeId]||(u[y.nodeId]=[]),u[y.nodeId].push({id:y.id,type:y.type,position:y.position,x:y.x,y:y.y});return l.map(y=>{const R=u[y.id];return R&&R.length>0?{...y,handles:R}:y})},[]),hn=c.useCallback(()=>{var w;if(We.current)return;const l=vt(et.current);(w=Ee.current)==null||w.postMessage({type:"nodes",data:{nodes:l}})},[vt]);c.useEffect(()=>{var u,y;if(We.current){const R=We.current.id,S=new Set([R,...We.current.selectedStarts.map(C=>C.id)]),m={};for(const C of K.current)S.has(C.id)&&(m[C.id]={...C.position});K.current=[...t];for(const C of K.current)m[C.id]&&(C.position=m[C.id]);et.current=Rt(K.current);const T=vt(et.current);(u=Ee.current)==null||u.postMessage({type:"nodes",data:{nodes:T}});return}K.current=[...t];const l=Rt(t);et.current=l;const w=vt(l);(y=Ee.current)==null||y.postMessage({type:"nodes",data:{nodes:w}})},[t,Rt,vt]),c.useEffect(()=>{var l;Re.current=[...n],(l=Ee.current)==null||l.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const Se=c.useCallback((l,w)=>{const u=pe.current;if(!u)return{x:0,y:0};const y=u.getBoundingClientRect(),R=ie.current;return{x:(l-y.left-R.x)/R.zoom,y:(w-y.top-R.y)/R.zoom}},[]),tt=c.useCallback((l,w)=>{const u=et.current.length>0?et.current:K.current;let y=null;for(let R=u.length-1;R>=0;R--){const S=u[R];if(S.hidden)continue;const m=S._absolutePosition||S.position,T=S.width||at,C=S.height||nt;if(l>=m.x&&l<=m.x+T&&w>=m.y&&w<=m.y+C){if(S.type==="group"){y||(y=S);continue}return S}}return y},[]),V=c.useCallback((l,w)=>{const u=w.width||at,y=w.height||nt;if(l.x!==void 0&&l.y!==void 0)return{x:w.position.x+l.x,y:w.position.y+l.y};switch(l.position||(l.type==="source"?"right":"left")){case"top":return{x:w.position.x+u/2,y:w.position.y};case"bottom":return{x:w.position.x+u/2,y:w.position.y+y};case"left":return{x:w.position.x,y:w.position.y+y/2};case"right":return{x:w.position.x+u,y:w.position.y+y/2};default:return{x:w.position.x+u,y:w.position.y+y/2}}},[]),He=c.useCallback(l=>{const w=l.width||at,u=l.height||nt;if(l.handles&&l.handles.length>0)return l.handles.map(C=>{const U=V(C,l);return{id:C.id||null,type:C.type,x:U.x,y:U.y}});const y=l.targetPosition||"left",R=l.sourcePosition||"right",S=C=>{switch(C){case"top":return{x:l.position.x+w/2,y:l.position.y};case"bottom":return{x:l.position.x+w/2,y:l.position.y+u};case"left":return{x:l.position.x,y:l.position.y+u/2};case"right":return{x:l.position.x+w,y:l.position.y+u/2};default:return{x:l.position.x+w,y:l.position.y+u/2}}},m=S(y),T=S(R);return[{id:null,type:"target",x:m.x,y:m.y},{id:null,type:"source",x:T.x,y:T.y}]},[V]),ve=c.useCallback((l,w)=>{const u=K.current,y=ie.current,R=Math.max(no,it)/y.zoom;for(let S=u.length-1;S>=0;S--){const m=u[S];if(m.hidden)continue;const T=He(m);for(const C of T)if(Math.abs(l-C.x)<R&&Math.abs(w-C.y)<R)return{nodeId:m.id,handleId:C.id,type:C.type,x:C.x,y:C.y}}return null},[He]),Ie=c.useCallback((l,w)=>{const y=8/ie.current.zoom;for(let R=Re.current.length-1;R>=0;R--){const S=Re.current[R],m=K.current.find(se=>se.id===S.source),T=K.current.find(se=>se.id===S.target);if(!m||!T)continue;const C=m.width||at,U=m.height||nt,H=T.height||nt,Z=m.position.x+C,G=m.position.y+U/2,be=T.position.x,Le=T.position.y+H/2;if(ro(l,w,Z,G,be,Le)<y)return S}return null},[]);c.useEffect(()=>{const l=Ht.current,w=pe.current;if(!l||!w)return;const u=w.getBoundingClientRect(),y=fe!==void 0?fe:matchMedia("(prefers-color-scheme: dark)").matches,R=Rt(K.current);et.current=R;const S=vt(R),{worker:m}=to(l,{width:u.width,height:u.height,camera:ie.current,cards:gt.current,nodes:S,edges:Re.current,dark:y,gridSize:me,edgeRouting:ht});m.onmessage=H=>{var Z,G,be,Le;H.data.type==="hud"&&((Z=mt.current)==null||Z.call(mt,H.data.data)),H.data.type==="ready"&&$n(!0),H.data.type==="nodesProcessed"&&((G=Bt.current)==null||G.call(Bt,H.data.data)),H.data.type==="error"&&((Le=(be=O.current).onError)==null||Le.call(be,"worker-error",H.data.message||"Canvas worker error"))},m.onerror=H=>{var Z,G;(G=(Z=O.current).onError)==null||G.call(Z,"worker-error",H.message||"Canvas worker crashed")},Ee.current=m;const T=new ResizeObserver(H=>{const{width:Z,height:G}=H[0].contentRect;m.postMessage({type:"resize",data:{width:Z,height:G}})});T.observe(w);let C,U;return fe===void 0&&(C=matchMedia("(prefers-color-scheme: dark)"),U=H=>m.postMessage({type:"theme",data:{dark:H.matches}}),C.addEventListener("change",U)),()=>{T.disconnect(),C&&U&&C.removeEventListener("change",U),Ee.current=null}},[]),c.useEffect(()=>{var l;fe!==void 0&&((l=Ee.current)==null||l.postMessage({type:"theme",data:{dark:fe}}))},[fe]),c.useEffect(()=>{var l;(l=Ee.current)==null||l.postMessage({type:"edgeRouting",data:{enabled:ht}})},[ht]);const st=c.useRef(0),ce=c.useCallback((l=null)=>{var y,R,S;const w=ie.current;if(dt){const m=pe.current;if(m){const T=m.getBoundingClientRect(),C=-dt[1][0]*w.zoom+T.width,U=-dt[1][1]*w.zoom+T.height,H=-dt[0][0]*w.zoom,Z=-dt[0][1]*w.zoom;w.x=Math.min(H,Math.max(C,w.x)),w.y=Math.min(Z,Math.max(U,w.y))}}(y=Ee.current)==null||y.postMessage({type:"camera",data:{camera:{...w}}});const u={x:w.x,y:w.y,zoom:w.zoom};(S=(R=O.current).onMove)==null||S.call(R,l,u);for(const m of ut)m(u);cancelAnimationFrame(st.current),st.current=requestAnimationFrame(()=>{Bn({x:w.x,y:w.y,zoom:w.zoom})})},[ut,dt]),Ge=c.useCallback(()=>{var u,y;const l=Ye.current,w=_t.current;l&&w?((u=Ee.current)==null||u.postMessage({type:"connecting",data:{from:l.startPos,to:w,_routedPoints:null}}),xt({source:l.sourceId,sourceHandle:l.sourceHandle,target:null,targetHandle:null})):((y=Ee.current)==null||y.postMessage({type:"connecting",data:null}),xt(null))},[]),bt=c.useCallback(()=>{var w,u;const l=De.current;l?(w=Ee.current)==null||w.postMessage({type:"selectionBox",data:l}):(u=Ee.current)==null||u.postMessage({type:"selectionBox",data:null})},[]),jn=c.useCallback(l=>{var m,T,C,U,H,Z,G,be,Le,te,se,ke,Te,Fe,Qe,Ue,Vt,lt;const w=K.current.length>0,u=Se(l.clientX,l.clientY),y=Wt.current;if(w&&Be&&!y){const q=ve(u.x,u.y);if(zt&&Mt.current&&q){const ne=Mt.current;if(q.nodeId!==ne.nodeId){const Ve=ne.handleType==="target"?{source:q.nodeId,target:ne.nodeId,sourceHandle:q.handleId||null,targetHandle:ne.handleId}:{source:ne.nodeId,target:q.nodeId,sourceHandle:ne.handleId,targetHandle:q.handleId||null};(O.current.isValidConnection?O.current.isValidConnection(Ve):!0)&&((m=pt.current)==null||m.call(pt,{...Ve,...Nt}))}Mt.current=null;return}if(je==="strict"?q&&q.type==="source":q!=null){if(zt){Mt.current={nodeId:q.nodeId,handleId:q.handleId||null,handleType:q.type},(C=(T=O.current).onConnectStart)==null||C.call(T,l,{nodeId:q.nodeId,handleId:q.handleId,handleType:q.type});return}Ye.current={sourceId:q.nodeId,sourceHandle:q.handleId||null,sourceType:q.type,startPos:{x:q.x,y:q.y}},_t.current={x:u.x,y:u.y},(U=pe.current)==null||U.setPointerCapture(l.pointerId),(Z=(H=O.current).onConnectStart)==null||Z.call(H,l,{nodeId:q.nodeId,handleId:q.handleId,handleType:q.type}),Ge();return}}const R=q=>{var ne;let xe=q;for(;xe&&xe!==pe.current;){if((ne=xe.classList)!=null&&ne.contains(Pt))return!0;xe=xe.parentElement}return!1},S=q=>{var ne;let xe=q;for(;xe&&xe!==pe.current;){if((ne=xe.classList)!=null&&ne.contains(It))return!0;xe=xe.parentElement}return!1};if(w){const q=tt(u.x,u.y);if(q){if(ze.current&&_e){const xe=[];if(y)xe.push({id:q.id,type:"select",selected:!q.selected});else if(!q.selected){for(const ne of K.current)ne.id===q.id?xe.push({id:ne.id,type:"select",selected:!0}):ne.selected&&xe.push({id:ne.id,type:"select",selected:!1});if(Pe.current){const ne=Re.current.filter(de=>de.selected).map(de=>({id:de.id,type:"select",selected:!1}));ne.length&&Pe.current(ne)}}if(xe.length){if(ze.current(xe),Sn&&!y){const ne=K.current.findIndex(de=>de.id===q.id);ne>=0&&ne<K.current.length-1&&ze.current([{id:q.id,type:"remove"},{type:"add",item:{...K.current[ne],selected:!0}}])}ot()}}if((G=$t.current)==null||G.call($t,l,q),$e&&!R(l.target)){const xe=q.selected;let ne=null;if(q.parentId&&q.extent==="parent"){const de=K.current.find(Ve=>Ve.id===q.parentId);if(de){const Ve=de.width||at,Jt=de.height||nt,yn=q.width||((be=q.measured)==null?void 0:be.width)||at,Kt=q.height||((Le=q.measured)==null?void 0:Le.height)||nt;ne={minX:0,minY:0,maxX:Ve-yn,maxY:Jt-Kt}}}if(We.current={id:q.id,startPos:{...q.position},startMouse:{x:u.x,y:u.y},parentClamp:ne,parentId:q.parentId||null,selectedStarts:xe?K.current.filter(de=>de.selected&&de.id!==q.id).map(de=>{var Jt,yn;let Ve=null;if(de.parentId&&de.extent==="parent"){const Kt=K.current.find(_n=>_n.id===de.parentId);if(Kt){const _n=Kt.width||at,Wr=Kt.height||nt,Fr=de.width||((Jt=de.measured)==null?void 0:Jt.width)||at,Xr=de.height||((yn=de.measured)==null?void 0:yn.height)||nt;Ve={minX:0,minY:0,maxX:_n-Fr,maxY:Wr-Xr}}}return{id:de.id,startPos:{...de.position},parentClamp:Ve,parentId:de.parentId||null}}):[]},(te=pe.current)==null||te.setPointerCapture(l.pointerId),(se=Xt.current)==null||se.call(Xt,l,q),We.current.selectedStarts.length>0){const de=K.current.filter(Ve=>Ve.selected);(Te=(ke=O.current).onSelectionDragStart)==null||Te.call(ke,l,de)}if(ze.current){const de=[{id:q.id,type:"position",dragging:!0}];for(const Ve of We.current.selectedStarts)de.push({id:Ve.id,type:"position",dragging:!0});ze.current(de)}}return}}if(Re.current.length>0&&_e){const q=Ie(u.x,u.y);if(q){if(Pe.current){const xe=[];if(y)xe.push({id:q.id,type:"select",selected:!q.selected});else{for(const ne of Re.current)ne.id===q.id?xe.push({id:ne.id,type:"select",selected:!0}):ne.selected&&xe.push({id:ne.id,type:"select",selected:!1});if(ze.current){const ne=K.current.filter(de=>de.selected).map(de=>({id:de.id,type:"select",selected:!1}));ne.length&&ze.current(ne)}}if(xe.length){if(Pe.current(xe),Nn&&!y){const ne=Re.current.findIndex(de=>de.id===q.id);ne>=0&&ne<Re.current.length-1&&Pe.current([{id:q.id,type:"remove"},{type:"add",item:{...Re.current[ne],selected:!0}}])}ot()}}(Fe=Ut.current)==null||Fe.call(Ut,l,q);return}}if(!y){const q=K.current.filter(ne=>ne.selected).map(ne=>({id:ne.id,type:"select",selected:!1})),xe=Re.current.filter(ne=>ne.selected).map(ne=>({id:ne.id,type:"select",selected:!1}));q.length&&ze.current&&ze.current(q),xe.length&&Pe.current&&Pe.current(xe),(q.length||xe.length)&&ot()}if((Qe=Ot.current)==null||Qe.call(Ot,l),Me||y){De.current={startWorld:{...u},endWorld:{...u}},(Ue=pe.current)==null||Ue.setPointerCapture(l.pointerId),bt();return}S(l.target)||(ct.current=!0,Lt.current={x:l.clientX,y:l.clientY},(Vt=pe.current)==null||Vt.classList.add("dragging"),(lt=pe.current)==null||lt.setPointerCapture(l.pointerId))},[Se,tt,ve,Ie,$e,Be,_e,Me,Ge,bt,ot,Pt,It]),An=c.useCallback(l=>{var u,y,R,S;if(Ye.current){if(_t.current=Se(l.clientX,l.clientY),Ge(),zn){const m=pe.current;if(m){const T=m.getBoundingClientRect(),C=40,U=l.clientX-T.left,H=l.clientY-T.top;let Z=0,G=0;U<C?Z=rt:U>T.width-C&&(Z=-rt),H<C?G=rt:H>T.height-C&&(G=-rt),(Z||G)&&(ie.current.x+=Z,ie.current.y+=G,ce(l))}}return}if(De.current){De.current.endWorld=Se(l.clientX,l.clientY),bt();const m=De.current,T=Math.min(m.startWorld.x,m.endWorld.x),C=Math.min(m.startWorld.y,m.endWorld.y),U=Math.max(m.startWorld.x,m.endWorld.x),H=Math.max(m.startWorld.y,m.endWorld.y);if(ze.current){const Z=[];for(const G of K.current){if(G.hidden)continue;const be=G.width||at,Le=G.height||nt,te=Oe==="full"?G.position.x>=T&&G.position.x+be<=U&&G.position.y>=C&&G.position.y+Le<=H:G.position.x+be>T&&G.position.x<U&&G.position.y+Le>C&&G.position.y<H;te!==!!G.selected&&Z.push({id:G.id,type:"select",selected:te})}Z.length&&ze.current(Z)}return}if(We.current){const m=Se(l.clientX,l.clientY),T=We.current,C=m.x-T.startMouse.x,U=m.y-T.startMouse.y;let H={x:T.startPos.x+C,y:T.startPos.y+U};if(Ae&&(H=qn(H,Xe)),ft&&(H=Un(H,ft)),T.parentClamp){const te=T.parentClamp;H={x:Math.max(te.minX,Math.min(H.x,te.maxX)),y:Math.max(te.minY,Math.min(H.y,te.maxY))}}const Z=[{id:T.id,position:H}];for(const te of T.selectedStarts){let se={x:te.startPos.x+C,y:te.startPos.y+U};if(Ae&&(se=qn(se,Xe)),ft&&(se=Un(se,ft)),te.parentClamp){const ke=te.parentClamp;se={x:Math.max(ke.minX,Math.min(se.x,ke.maxX)),y:Math.max(ke.minY,Math.min(se.y,ke.maxY))}}Z.push({id:te.id,position:se})}const G=[];for(const te of Z){const se=K.current.find(ke=>ke.id===te.id);if(se){se.position=te.position,se.dragging=!0;let ke=te.position;if(se.parentId){let Te=K.current.find(Ue=>Ue.id===se.parentId),Fe=te.position.x,Qe=te.position.y;for(;Te;)Fe+=Te.position.x,Qe+=Te.position.y,Te=Te.parentId?K.current.find(Ue=>Ue.id===Te.parentId):null;ke={x:Fe,y:Qe}}G.push({id:te.id,position:te.position,_absolutePosition:ke,width:se.width,height:se.height,dragging:!0,selected:se.selected})}}const be=new Set(Z.map(te=>te.id));for(const te of K.current)if(te.parentId&&be.has(te.parentId)&&!be.has(te.id)){let se=K.current.find(Fe=>Fe.id===te.parentId),ke=te.position.x,Te=te.position.y;for(;se;)ke+=se.position.x,Te+=se.position.y,se=se.parentId?K.current.find(Fe=>Fe.id===se.parentId):null;G.push({id:te.id,position:te.position,_absolutePosition:{x:ke,y:Te},width:te.width,height:te.height,dragging:!1,selected:te.selected})}if((u=Ee.current)==null||u.postMessage({type:"nodePositions",data:{updates:G}}),En){const te=pe.current;if(te){const se=te.getBoundingClientRect(),ke=40,Te=l.clientX-se.left,Fe=l.clientY-se.top;let Qe=0,Ue=0;Te<ke?Qe=rt:Te>se.width-ke&&(Qe=-rt),Fe<ke?Ue=rt:Fe>se.height-ke&&(Ue=-rt),(Qe||Ue)&&(ie.current.x+=Qe,ie.current.y+=Ue,ce(l))}}const Le=K.current.find(te=>te.id===T.id);if(Le&&((y=Yt.current)==null||y.call(Yt,l,Le)),T.selectedStarts.length>0){const te=K.current.filter(se=>se.selected);(S=(R=O.current).onSelectionDrag)==null||S.call(R,l,te)}return}if(!ct.current)return;const w=ie.current;w.x+=l.clientX-Lt.current.x,w.y+=l.clientY-Lt.current.y,Lt.current={x:l.clientX,y:l.clientY},ce()},[ce,Se,Ge,bt]),kt=c.useCallback(l=>{var w,u,y,R,S,m,T;if(Ye.current){const C=Se(l.clientX,l.clientY),U=ve(C.x,C.y);if(U&&U.nodeId!==Ye.current.sourceId&&(je==="loose"||U.type==="target")){const G=Ye.current.sourceType==="target"?{source:U.nodeId,target:Ye.current.sourceId,sourceHandle:U.handleId||null,targetHandle:Ye.current.sourceHandle}:{source:Ye.current.sourceId,target:U.nodeId,sourceHandle:Ye.current.sourceHandle,targetHandle:U.handleId||null};(O.current.isValidConnection?O.current.isValidConnection(G):!0)&&((w=pt.current)==null||w.call(pt,{...G,...Nt}))}(y=(u=O.current).onConnectEnd)==null||y.call(u,l.nativeEvent||l),Ye.current=null,_t.current=null,Ge();return}if(De.current){De.current=null,bt(),ot();return}if(We.current){const C=We.current;if(ze.current){const H=K.current.find(G=>G.id===C.id),Z=[{id:C.id,type:"position",position:H?{...H.position}:void 0,dragging:!1}];for(const G of C.selectedStarts){const be=K.current.find(Le=>Le.id===G.id);Z.push({id:G.id,type:"position",position:be?{...be.position}:void 0,dragging:!1})}ze.current(Z)}if(C.selectedStarts.length>0){const H=K.current.filter(Z=>Z.selected);(S=(R=O.current).onSelectionDragStop)==null||S.call(R,l,H)}requestAnimationFrame(()=>{We.current=null});const U=K.current.find(H=>H.id===C.id);U&&((m=qt.current)==null||m.call(qt,l,U));return}ct.current=!1,(T=pe.current)==null||T.classList.remove("dragging")},[Se,ve,Ge,bt,ot]);c.useEffect(()=>{const l=pe.current;if(!l)return;const w=u=>{Dt&&u.preventDefault();const y=ie.current;if(an||Tt.current){const C=cn;At==="horizontal"?y.x-=u.deltaY*C:(At==="vertical"||(y.x-=u.deltaX*C),y.y-=u.deltaY*C),ce(u);return}if(!un)return;const R=u.deltaY>0?.92:1.08,S=l.getBoundingClientRect(),m=u.clientX-S.left,T=u.clientY-S.top;y.x=m-(m-y.x)*R,y.y=T-(T-y.y)*R,y.zoom=Math.min(ue,Math.max(ae,y.zoom*R)),ce(u)};return l.addEventListener("wheel",w,{passive:!Dt}),()=>l.removeEventListener("wheel",w)},[ce,ae,ue,an,At,cn,un,Dt]),c.useEffect(()=>{if(!dn)return;const l=pe.current;if(!l)return;let w=0,u=null;const y=m=>{if(m.touches.length===2){const T=m.touches[0].clientX-m.touches[1].clientX,C=m.touches[0].clientY-m.touches[1].clientY;w=Math.hypot(T,C);const U=l.getBoundingClientRect();u={x:(m.touches[0].clientX+m.touches[1].clientX)/2-U.left,y:(m.touches[0].clientY+m.touches[1].clientY)/2-U.top},m.preventDefault()}},R=m=>{if(m.touches.length===2&&w>0){m.preventDefault();const T=m.touches[0].clientX-m.touches[1].clientX,C=m.touches[0].clientY-m.touches[1].clientY,U=Math.hypot(T,C),H=U/w;w=U;const Z=ie.current,G=u.x,be=u.y;Z.x=G-(G-Z.x)*H,Z.y=be-(be-Z.y)*H,Z.zoom=Math.min(ue,Math.max(ae,Z.zoom*H)),ce(m)}},S=()=>{w=0,u=null};return l.addEventListener("touchstart",y,{passive:!1}),l.addEventListener("touchmove",R,{passive:!1}),l.addEventListener("touchend",S),()=>{l.removeEventListener("touchstart",y),l.removeEventListener("touchmove",R),l.removeEventListener("touchend",S)}},[dn,ce,ae,ue]),c.useEffect(()=>{if(!ln)return;const l=pe.current;if(!l)return;const w=u=>{var H,Z,G,be;const y=Se(u.clientX,u.clientY);if(tt(y.x,y.y)){(Z=(H=O.current).onNodeDoubleClick)==null||Z.call(H,u,tt(y.x,y.y));return}const R=Ie(y.x,y.y);if(R){(be=(G=O.current).onEdgeDoubleClick)==null||be.call(G,u,R);return}const S=1.5,m=l.getBoundingClientRect(),T=u.clientX-m.left,C=u.clientY-m.top,U=ie.current;U.x=T-(T-U.x)*S,U.y=C-(C-U.y)*S,U.zoom=Math.min(ue,Math.max(ae,U.zoom*S)),ce(u)};return l.addEventListener("dblclick",w),()=>l.removeEventListener("dblclick",w)},[ln,ce,ae,ue,Se,tt,Ie]),c.useEffect(()=>{const l=pe.current;if(!l)return;const w=u=>{var m,T,C,U,H,Z;const y=Se(u.clientX,u.clientY),R=tt(y.x,y.y);if(R){(T=(m=O.current).onNodeContextMenu)==null||T.call(m,u,R);return}const S=Ie(y.x,y.y);if(S){(U=(C=O.current).onEdgeContextMenu)==null||U.call(C,u,S);return}(Z=(H=O.current).onPaneContextMenu)==null||Z.call(H,u)};return l.addEventListener("contextmenu",w),()=>l.removeEventListener("contextmenu",w)},[Se,tt,Ie]),c.useEffect(()=>{const l=pe.current;if(!l)return;let w=null,u=null;const y=m=>{var U,H,Z,G,be,Le,te,se,ke,Te,Fe,Qe,Ue,Vt;if((H=(U=O.current).onPaneMouseMove)==null||H.call(U,m),ct.current||We.current||Ye.current||De.current)return;const T=Se(m.clientX,m.clientY),C=tt(T.x,T.y);if(C!==w&&(w&&((G=(Z=O.current).onNodeMouseLeave)==null||G.call(Z,m,w)),C&&((Le=(be=O.current).onNodeMouseEnter)==null||Le.call(be,m,C)),w=C),C&&((se=(te=O.current).onNodeMouseMove)==null||se.call(te,m,C)),!C){const lt=Ie(T.x,T.y);lt!==u&&(u&&((Te=(ke=O.current).onEdgeMouseLeave)==null||Te.call(ke,m,u)),lt&&((Qe=(Fe=O.current).onEdgeMouseEnter)==null||Qe.call(Fe,m,lt)),u=lt),lt&&((Vt=(Ue=O.current).onEdgeMouseMove)==null||Vt.call(Ue,m,lt))}},R=m=>{var T,C;return(C=(T=O.current).onPaneMouseEnter)==null?void 0:C.call(T,m)},S=m=>{var T,C,U,H,Z,G;(C=(T=O.current).onPaneMouseLeave)==null||C.call(T,m),w&&((H=(U=O.current).onNodeMouseLeave)==null||H.call(U,m,w),w=null),u&&((G=(Z=O.current).onEdgeMouseLeave)==null||G.call(Z,m,u),u=null)};return l.addEventListener("mousemove",y),l.addEventListener("mouseenter",R),l.addEventListener("mouseleave",S),()=>{l.removeEventListener("mousemove",y),l.removeEventListener("mouseenter",R),l.removeEventListener("mouseleave",S)}},[Se,tt,Ie]),c.useEffect(()=>{const l=Array.isArray(Ze)?Ze:[Ze],w=async u=>{var y,R,S,m;if(l.includes(u.key)){if(u.target.tagName==="INPUT"||u.target.tagName==="TEXTAREA"||u.target.isContentEditable)return;const T=K.current.filter(H=>H.selected),C=Re.current.filter(H=>H.selected);if(!T.length&&!C.length)return;if(O.current.onBeforeDelete)try{if(!await O.current.onBeforeDelete({nodes:T,edges:C}))return}catch(H){(R=(y=O.current).onError)==null||R.call(y,"before-delete-error",H.message||"onBeforeDelete threw an error");return}const U=new Set(T.map(H=>H.id));if(T.length&&ze.current&&(ze.current(T.map(H=>({id:H.id,type:"remove"}))),Pe.current)){const H=Re.current.filter(Z=>U.has(Z.source)||U.has(Z.target));H.length&&Pe.current(H.map(Z=>({id:Z.id,type:"remove"})))}C.length&&Pe.current&&Pe.current(C.map(H=>({id:H.id,type:"remove"}))),(m=(S=O.current).onDelete)==null||m.call(S,{nodes:T,edges:C})}if((u.ctrlKey||u.metaKey)&&u.key==="a"){if(u.target.tagName==="INPUT"||u.target.tagName==="TEXTAREA")return;if(u.preventDefault(),ze.current){const T=K.current.filter(C=>!C.selected).map(C=>({id:C.id,type:"select",selected:!0}));T.length&&ze.current(T)}if(Pe.current){const T=Re.current.filter(C=>!C.selected).map(C=>({id:C.id,type:"select",selected:!0}));T.length&&Pe.current(T)}}};return window.addEventListener("keydown",w),()=>window.removeEventListener("keydown",w)},[Ze]);const Qt=c.useRef(!1);c.useEffect(()=>{var l,w;if(!Qt.current&&Ee.current){if(Qt.current=!0,Je&&K.current.length>0){const u=pe.current;if(u){const y=u.getBoundingClientRect(),R=(le==null?void 0:le.padding)??.1,S=mn(K.current),m=jt(S,y.width,y.height,R);le!=null&&le.maxZoom&&(m.zoom=Math.min(m.zoom,le.maxZoom)),le!=null&&le.minZoom&&(m.zoom=Math.max(m.zoom,le.minZoom)),ie.current=m,ce()}}(w=(l=O.current).onInit)==null||w.call(l,{getNodes:()=>[...K.current],getEdges:()=>[...Re.current],getNode:u=>K.current.find(y=>y.id===u),getEdge:u=>Re.current.find(y=>y.id===u),getViewport:()=>({...ie.current}),getZoom:()=>ie.current.zoom,setViewport:u=>{ie.current={x:u.x??ie.current.x,y:u.y??ie.current.y,zoom:u.zoom??ie.current.zoom},ce()},fitView:(u={})=>{const y=pe.current;if(!y||!K.current.length)return;const R=y.getBoundingClientRect(),S=u.nodes?K.current.filter(C=>u.nodes.some(U=>U.id===C.id)):K.current;if(!S.length)return;const m=mn(S),T=jt(m,R.width,R.height,u.padding??.1);u.maxZoom&&(T.zoom=Math.min(T.zoom,u.maxZoom)),u.minZoom&&(T.zoom=Math.max(T.zoom,u.minZoom)),ie.current=T,ce()},screenToFlowPosition:u=>Se(u.x,u.y),flowToScreenPosition:u=>{const y=ie.current,R=pe.current;if(!R)return{x:0,y:0};const S=R.getBoundingClientRect();return{x:u.x*y.zoom+y.x+S.left,y:u.y*y.zoom+y.y+S.top}},zoomIn:()=>{const u=ie.current;u.zoom=Math.min(ue,u.zoom*1.2),ce()},zoomOut:()=>{const u=ie.current;u.zoom=Math.max(ae,u.zoom/1.2),ce()},zoomTo:u=>{ie.current.zoom=Math.min(ue,Math.max(ae,u)),ce()},setNodes:u=>{var y,R;(R=(y=O.current).onNodesChange)==null||R.call(y,[...K.current.map(S=>({id:S.id,type:"remove"})),...(typeof u=="function"?u(K.current):u).map(S=>({type:"add",item:S}))])},setEdges:u=>{var y,R;(R=(y=O.current).onEdgesChange)==null||R.call(y,[...Re.current.map(S=>({id:S.id,type:"remove"})),...(typeof u=="function"?u(Re.current):u).map(S=>({type:"add",item:S}))])},addNodes:u=>{var R,S;const y=Array.isArray(u)?u:[u];(S=(R=O.current).onNodesChange)==null||S.call(R,y.map(m=>({type:"add",item:m})))},addEdges:u=>{var R,S;const y=Array.isArray(u)?u:[u];(S=(R=O.current).onEdgesChange)==null||S.call(R,y.map(m=>({type:"add",item:m})))},deleteElements:({nodes:u=[],edges:y=[]})=>{var R,S,m,T;u.length&&((S=(R=O.current).onNodesChange)==null||S.call(R,u.map(C=>({id:C.id,type:"remove"})))),y.length&&((T=(m=O.current).onEdgesChange)==null||T.call(m,y.map(C=>({id:C.id,type:"remove"}))))},updateNodeData:(u,y)=>{var m,T;const R=K.current.find(C=>C.id===u);if(!R)return;const S=typeof y=="function"?y(R.data):{...R.data,...y};(T=(m=O.current).onNodesChange)==null||T.call(m,[{id:u,type:"replace",item:{...R,data:S}}])},toObject:()=>({nodes:[...K.current],edges:[...Re.current],viewport:{...ie.current}}),setCenter:(u,y,R={})=>{const S=pe.current;if(!S)return;const m=S.getBoundingClientRect(),T=R.zoom??ie.current.zoom;ie.current={x:m.width/2-u*T,y:m.height/2-y*T,zoom:T},ce()},fitBounds:(u,y={})=>{const R=pe.current;if(!R)return;const S=R.getBoundingClientRect(),m=jt(u,S.width,S.height,y.padding??.1);ie.current=m,ce()}})}});const gn=c.useCallback(()=>{ie.current={...Ne},ce()},[ce,Ne]),qe=c.useCallback(l=>{var w;if(l)gt.current.push(l);else{const u=ie.current,y=pe.current;if(!y)return;const R=y.getBoundingClientRect(),S=Math.round(-u.x/u.zoom+R.width/2/u.zoom),m=Math.round(-u.y/u.zoom+R.height/2/u.zoom);gt.current.push({x:S-80,y:m-45,w:160,h:90,title:"Note "+(gt.current.length+1),body:"Added at viewport center"})}(w=Ee.current)==null||w.postMessage({type:"cards",data:{cards:[...gt.current]}})},[]),wt=c.useCallback(l=>{if(l.id||(l.id="node-"+Date.now()),!l.position){const w=ie.current,u=pe.current;if(!u)return;const y=u.getBoundingClientRect();l.position={x:Math.round(-w.x/w.zoom+y.width/2/w.zoom)-at/2,y:Math.round(-w.y/w.zoom+y.height/2/w.zoom)-nt/2}}l.data||(l.data={label:l.id}),ze.current&&ze.current([{type:"add",item:l}])},[]),Dn=c.useCallback(()=>({...ie.current}),[]),Hn=c.useCallback(l=>{ie.current={...ie.current,...l},ce()},[ce]),Hr=c.useCallback(l=>Se(l.x,l.y),[Se]),ar=n,_r=c.useMemo(()=>({wrapRef:pe,canvasRef:Ht,workerRef:Ee,cameraRef:ie,nodesRef:K,edgesRef:Re,handleRegistryRef:fn,syncNodesToWorker:hn,onNodesChangeRef:ze,onEdgesChangeRef:Pe,sendCamera:ce,screenToWorld:Se,viewportListeners:ut,selectionListeners:Ke,zoomMin:ae,zoomMax:ue,snapToGrid:Ae,snapGrid:Xe,nodeExtent:ft,defaultEdgeOptions:Nt,edgeRouting:ht,resolvedNodesRef:et,noDragClassName:Pt,noPanClassName:It,get nodes(){return t},get edges(){return n},get routedEdges(){return ar},get viewport(){return Ft},get connection(){return yt}}),[t,n,ar,Ft,yt,ce,Se,hn,ut,Ke,ae,ue,Ae,Xe,ft,Nt,ht,Pt,It]);return{wrapRef:pe,canvasRef:Ht,canvasReady:Tn,onPointerDown:jn,onPointerMove:An,onPointerUp:kt,resetView:gn,addCard:qe,addNode:wt,getCamera:Dn,setCamera:Hn,screenToFlowPosition:Hr,store:_r}}function ro(e,t,n,r,a,o){const i=a-n,f=o-r,p=i*i+f*f;if(p===0)return Math.hypot(e-n,t-r);let d=((e-n)*i+(t-r)*f)/p;return d=Math.max(0,Math.min(1,d)),Math.hypot(e-(n+d*i),t-(r+d*f))}const cr=e=>{let t;const n=new Set,r=(d,h)=>{const v=typeof d=="function"?d(t):d;if(!Object.is(v,t)){const E=t;t=h??(typeof v!="object"||v===null)?v:Object.assign({},t,v),n.forEach(M=>M(t,E))}},a=()=>t,f={setState:r,getState:a,getInitialState:()=>p,subscribe:d=>(n.add(d),()=>n.delete(d))},p=t=e(r,a,f);return f},oo=(e=>e?cr(e):cr),so=e=>e;function ao(e,t=so){const n=c.useSyncExternalStore(e.subscribe,c.useCallback(()=>t(e.getState()),[e,t]),c.useCallback(()=>t(e.getInitialState()),[e,t]));return c.useDebugValue(n),n}const Et=c.createContext(null);function io(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,a)=>{const o=n().cameraRef.current;return{x:(r-o.x)/o.zoom,y:(a-o.y)/o.zoom}},sendCamera:()=>{var a;const r=n();(a=r.workerRef.current)==null||a.postMessage({type:"camera",data:{camera:{...r.cameraRef.current}}})},...e}))}function Ce(e,t){const n=c.useContext(Et);if(!n)throw new Error("useCanvasStore must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");const r=typeof n.getState=="function"&&typeof n.subscribe=="function",a=c.useRef(e),o=c.useRef(t),i=c.useRef(void 0);a.current=e,o.current=t;const f=c.useCallback(p=>{const d=a.current;if(!d)return p;const h=d(p),v=o.current||Object.is;return i.current!==void 0&&v(i.current,h)?i.current:(i.current=h,h)},[]);return r?ao(n,e?f:void 0):e?f(n):n}function wr(){const e=c.useContext(Et);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=c.createContext(null);function co(){return c.useContext(on)}function uo({node:e,nodeType:t}){var E,M,z;const n=Ce(),r=c.useRef(n);r.current=n;const a=c.useRef(null),o=e._absolutePosition||e.position,i=c.useRef(null);c.useEffect(()=>{const I=a.current;if(!I)return;const k=new ResizeObserver(j=>{var _,A,L,Y;const{width:X,height:D}=j[0].contentRect;if(X>0&&D>0){const F=r.current,B=F.nodesRef.current.find(x=>x.id===e.id),b=(B==null?void 0:B.width)||((_=B==null?void 0:B.measured)==null?void 0:_.width),g=(B==null?void 0:B.height)||((A=B==null?void 0:B.measured)==null?void 0:A.height);(Math.abs((b||0)-X)>1||Math.abs((g||0)-D)>1)&&((Y=(L=F.onNodesChangeRef).current)==null||Y.call(L,[{id:e.id,type:"dimensions",dimensions:{width:X,height:D},setAttributes:!0}]))}});return k.observe(I),()=>k.disconnect()},[e.id]);const f=c.useCallback(I=>{var ee,oe,ge,ye;I.stopPropagation();const k=I.target.tagName;if(k==="INPUT"||k==="TEXTAREA"||k==="SELECT"||k==="BUTTON"||k==="A"||k==="LABEL"||I.target.isContentEditable)return;const j=r.current.noDragClassName||"nodrag",X=r.current.noPanClassName||"nopan";let D=I.target;for(;D&&D!==a.current;){if((ee=D.classList)!=null&&ee.contains(j)||(oe=D.classList)!=null&&oe.contains(X))return;D=D.parentElement}if(r.current.onNodesChangeRef.current){const J=[];if(I.shiftKey)J.push({id:e.id,type:"select",selected:!e.selected});else for(const me of r.current.nodesRef.current)me.id===e.id&&!me.selected?J.push({id:me.id,type:"select",selected:!0}):me.id!==e.id&&me.selected&&J.push({id:me.id,type:"select",selected:!1});J.length&&r.current.onNodesChangeRef.current(J)}const _=r.current.cameraRef.current,A=r.current.wrapRef.current;if(!A)return;const L=A.getBoundingClientRect(),Y=(I.clientX-L.left-_.x)/_.zoom,F=(I.clientY-L.top-_.y)/_.zoom,b=e.selected?r.current.nodesRef.current.filter(J=>J.selected&&J.id!==e.id).map(J=>({id:J.id,startPos:{...J.position}})):[];i.current={startPos:{...e.position},startMouse:{x:Y,y:F},selectedStarts:b};const g=[{id:e.id,type:"position",dragging:!0}];for(const J of b)g.push({id:J.id,type:"position",dragging:!0});(ye=(ge=r.current.onNodesChangeRef).current)==null||ye.call(ge,g);const x=a.current;x&&x.setPointerCapture(I.pointerId);let N=null,$=null;const W=()=>{var J,fe;$&&((fe=(J=r.current.onNodesChangeRef).current)==null||fe.call(J,$),$=null),N=null},Q=J=>{var Be,_e;if(!i.current)return;const fe=r.current.cameraRef.current,me=A.getBoundingClientRect(),ae=(J.clientX-me.left-fe.x)/fe.zoom,ue=(J.clientY-me.top-fe.y)/fe.zoom,Ne=ae-i.current.startMouse.x,Je=ue-i.current.startMouse.y;let le={x:i.current.startPos.x+Ne,y:i.current.startPos.y+Je};if(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])}),e.parentId&&e.extent==="parent"){const he=r.current.nodesRef.current.find(Me=>Me.id===e.parentId);if(he){const Me=he.width||160,Oe=he.height||60,je=e.width||((Be=e.measured)==null?void 0:Be.width)||160,it=e.height||((_e=e.measured)==null?void 0:_e.height)||60;le={x:Math.max(0,Math.min(le.x,Me-je)),y:Math.max(0,Math.min(le.y,Oe-it))}}}x&&(x.style.left=le.x+"px",x.style.top=le.y+"px");for(const he of i.current.selectedStarts){let Me={x:he.startPos.x+Ne,y:he.startPos.y+Je};r.current.snapToGrid&&r.current.snapGrid&&(Me={x:r.current.snapGrid[0]*Math.round(Me.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Me.y/r.current.snapGrid[1])});const Oe=A.querySelector(`[data-nodeid="${he.id}"]`);Oe&&(Oe.style.left=Me.x+"px",Oe.style.top=Me.y+"px")}const $e=[{id:e.id,type:"position",position:le,dragging:!0}];for(const he of i.current.selectedStarts){let Me={x:he.startPos.x+Ne,y:he.startPos.y+Je};r.current.snapToGrid&&r.current.snapGrid&&(Me={x:r.current.snapGrid[0]*Math.round(Me.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Me.y/r.current.snapGrid[1])}),$e.push({id:he.id,type:"position",position:Me,dragging:!0})}$=$e,N||(N=requestAnimationFrame(W))},re=J=>{var me,ae;if(!i.current)return;N&&(cancelAnimationFrame(N),W());const fe=[{id:e.id,type:"position",dragging:!1}];for(const ue of i.current.selectedStarts)fe.push({id:ue.id,type:"position",dragging:!1});(ae=(me=r.current.onNodesChangeRef).current)==null||ae.call(me,fe),i.current=null,x&&x.releasePointerCapture(J.pointerId),x==null||x.removeEventListener("pointermove",Q),x==null||x.removeEventListener("pointerup",re)};x==null||x.addEventListener("pointermove",Q),x==null||x.addEventListener("pointerup",re)},[e]),p=c.useCallback(I=>{var A,L,Y,F,B,b;if(!e.selected)return;const k=I.shiftKey?10:1;let j=0,X=0;switch(I.key){case"ArrowUp":X=-k;break;case"ArrowDown":X=k;break;case"ArrowLeft":j=-k;break;case"ArrowRight":j=k;break;case"Escape":(L=(A=r.current.onNodesChangeRef).current)==null||L.call(A,[{id:e.id,type:"select",selected:!1}]);return;case"Delete":case"Backspace":e.deletable!==!1&&((F=(Y=r.current.onNodesChangeRef).current)==null||F.call(Y,[{id:e.id,type:"remove"}]));return;default:return}I.preventDefault();const D={x:e.position.x+j,y:e.position.y+X},_=[{id:e.id,type:"position",position:D}];for(const g of r.current.nodesRef.current)g.selected&&g.id!==e.id&&_.push({id:g.id,type:"position",position:{x:g.position.x+j,y:g.position.y+X}});(b=(B=r.current.onNodesChangeRef).current)==null||b.call(B,_)},[e]),d=e.width||((E=e.measured)==null?void 0:E.width),h=e.height||((M=e.measured)==null?void 0:M.height),v=!!(d&&h);return P.jsx(on.Provider,{value:e.id,children:P.jsx("div",{ref:a,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:v?"visible":"hidden",outline:"none"},"data-nodeid":e.id,tabIndex:e.selectable!==!1?0:void 0,role:"button","aria-label":`Node ${((z=e.data)==null?void 0:z.label)||e.id}`,"aria-selected":!!e.selected,onPointerDown:f,onKeyDown:p,children:P.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})})})}const lo=c.memo(uo),Mr=160,Rr=60;function ur(e,t,n,r){var f,p;const a=e.width||((f=e.measured)==null?void 0:f.width)||Mr,o=e.height||((p=e.measured)==null?void 0:p.height)||Rr,i=e._absolutePosition||e.position;if(e.handleBounds){const d=e.handleBounds[t]||[],h=n?d.find(v=>v.id===n):d[0];if(h&&h.x!==void 0&&h.y!==void 0){const v=h.position||(t==="source"?"right":"left");return{x:i.x+h.x,y:i.y+h.y,position:v}}}if(r){const d=`${e.id}__${n||t}`,h=r.get(d);if(h&&h.x!==void 0&&h.y!==void 0)return{x:i.x+h.x,y:i.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:i.x+d.x,y:i.y+d.y,position:d.position||(t==="source"?"right":"left")};const h=d.position||(t==="source"?"right":"left");switch(h){case"top":return{x:i.x+a/2,y:i.y,position:h};case"bottom":return{x:i.x+a/2,y:i.y+o,position:h};case"left":return{x:i.x,y:i.y+o/2,position:h};default:return{x:i.x+a,y:i.y+o/2,position:h}}}}return t==="source"?{x:i.x+a,y:i.y+o/2,position:"right"}:{x:i.x,y:i.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 lr({x:e,y:t,position:n,type:r,onPointerDown:a}){return P.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:a})}function go({edge:e,edgeType:t,nodes:n,reconnectable:r}){var L,Y,F;const a=c.useContext(Et),o=c.useRef(typeof a.getState=="function"?a.getState():a);o.current=typeof a.getState=="function"?a.getState():a;const[i,f]=c.useState(null),p=c.useCallback((B,b,g,x)=>{var ge;b.stopPropagation(),b.preventDefault();const N=o.current,$=N.wrapRef.current;if(!$)return;const W=B==="source"?x:g,Q=B==="source"?e.target:e.source;(ge=N.workerRef.current)==null||ge.postMessage({type:"connecting",data:{from:{x:W.x,y:W.y},to:{x:W.x,y:W.y}}});const re=$.getBoundingClientRect(),ee=ye=>{var ae;const J=N.cameraRef.current,fe=(ye.clientX-re.left-J.x)/J.zoom,me=(ye.clientY-re.top-J.y)/J.zoom;(ae=N.workerRef.current)==null||ae.postMessage({type:"connecting",data:{from:{x:W.x,y:W.y},to:{x:fe,y:me}}})},oe=ye=>{var le,$e,Be,_e;const J=N.cameraRef.current,fe=(ye.clientX-re.left-J.x)/J.zoom,me=(ye.clientY-re.top-J.y)/J.zoom,ae=20/J.zoom;let ue=null,Ne=null;const Je=(le=N.handleRegistryRef)==null?void 0:le.current;for(const he of N.nodesRef.current){if(he.hidden)continue;const Me=he.width||Mr,Oe=he.height||Rr,je=he._absolutePosition||he.position,it=[];if(Je)for(const[,Ae]of Je)Ae.nodeId===he.id&&it.push(Ae);const zt=it.length>0?it:he.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const Ae of zt){let Xe,Ze;if(Ae.x!==void 0&&Ae.y!==void 0)Xe=je.x+Ae.x,Ze=je.y+Ae.y;else switch(Ae.position||(Ae.type==="source"?"right":"left")){case"top":Xe=je.x+Me/2,Ze=je.y;break;case"bottom":Xe=je.x+Me/2,Ze=je.y+Oe;break;case"left":Xe=je.x,Ze=je.y+Oe/2;break;default:Xe=je.x+Me,Ze=je.y+Oe/2;break}if(Math.abs(fe-Xe)<ae&&Math.abs(me-Ze)<ae){ue=he,Ne=Ae.id||null;break}}if(ue)break}if(ue){const he=B==="source"?{source:ue.id,target:Q,sourceHandle:Ne,targetHandle:e.targetHandle}:{source:Q,target:ue.id,sourceHandle:e.sourceHandle,targetHandle:Ne};(Be=($e=N.onEdgesChangeRef).current)==null||Be.call($e,[{id:e.id,type:"remove"},{type:"add",item:{id:e.id,...he}}])}(_e=N.workerRef.current)==null||_e.postMessage({type:"connecting",data:null}),$.removeEventListener("pointermove",ee),$.removeEventListener("pointerup",oe)};$.addEventListener("pointermove",ee),$.addEventListener("pointerup",oe)},[e]),d=n.find(B=>B.id===e.source),h=n.find(B=>B.id===e.target),v=d&&!!(d.width||(L=d.measured)!=null&&L.width),E=h&&!!(h.width||(Y=h.measured)!=null&&Y.width),M=o.current,z=(F=M.handleRegistryRef)==null?void 0:F.current,I=v?ur(d,"source",e.sourceHandle,z):null,k=E?ur(h,"target",e.targetHandle,z):null,j=e.type==="bezier"||e.type==="simplebezier"||e.type==="default",X=M.routedEdges||M.edges,D=X==null?void 0:X.find(B=>B.id===e.id),_=j?null:(D==null?void 0:D._routedPoints)||e._routedPoints||null,A=r!==!1&&e.reconnectable!==!1;return!I||!k?null:P.jsxs("g",{className:`ric-edge-wrapper ${e.selected?"selected":""}`,"data-edgeid":e.id,onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),children:[P.jsx(t,{id:e.id,source:e.source,target:e.target,sourceX:I.x,sourceY:I.y,targetX:k.x,targetY:k.y,sourcePosition:I.position,targetPosition:k.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:_}),A&&(i||e.selected)&&P.jsxs(P.Fragment,{children:[P.jsx(lr,{x:I.x,y:I.y,position:I.position,type:"source",onPointerDown:B=>p("source",B,I,k)}),P.jsx(lr,{x:k.x,y:k.y,position:k.position,type:"target",onPointerDown:B=>p("target",B,I,k)})]})]})}const yo=c.memo(go);function kr({selectionKeyCode:e="Shift",selectionMode:t="partial"}){var I;const n=Ce(),[r,a]=c.useState(null),o=c.useRef(null);if(c.useEffect(()=>{const k=n.wrapRef.current;if(!k)return;let j=!1,X=null,D=!1;const _=B=>{B.key===e&&(D=!0)},A=B=>{B.key===e&&(D=!1)},L=B=>{if(!D)return;const b=B.target;if(b.closest(".ric-node-wrapper")||b.closest(".ric-handle"))return;j=!0;const g=n.cameraRef.current,x=k.getBoundingClientRect(),N=(B.clientX-x.left-g.x)/g.zoom,$=(B.clientY-x.top-g.y)/g.zoom;X={x:N,y:$},a({startX:N,startY:$,endX:N,endY:$}),B.stopPropagation()},Y=B=>{if(!j||!X)return;const b=n.cameraRef.current,g=k.getBoundingClientRect(),x=(B.clientX-g.left-b.x)/b.zoom,N=(B.clientY-g.top-b.y)/b.zoom;a({startX:X.x,startY:X.y,endX:x,endY:N})},F=B=>{var Q,re;if(!j||!X)return;j=!1;const b=n.cameraRef.current,g=k.getBoundingClientRect(),x=(B.clientX-g.left-b.x)/b.zoom,N=(B.clientY-g.top-b.y)/b.zoom,$={x:Math.min(X.x,x),y:Math.min(X.y,N),width:Math.abs(x-X.x),height:Math.abs(N-X.y)},W=[];for(const ee of n.nodesRef.current){const oe=ee._absolutePosition||ee.position,ge=ee.width||160,ye=ee.height||60;let J;t==="full"?J=oe.x>=$.x&&oe.y>=$.y&&oe.x+ge<=$.x+$.width&&oe.y+ye<=$.y+$.height:J=oe.x+ge>$.x&&oe.x<$.x+$.width&&oe.y+ye>$.y&&oe.y<$.y+$.height,W.push({id:ee.id,type:"select",selected:J})}W.length&&((re=(Q=n.onNodesChangeRef).current)==null||re.call(Q,W)),X=null,a(null)};return k.addEventListener("pointerdown",L,!0),k.addEventListener("pointermove",Y),k.addEventListener("pointerup",F),window.addEventListener("keydown",_),window.addEventListener("keyup",A),()=>{k.removeEventListener("pointerdown",L,!0),k.removeEventListener("pointermove",Y),k.removeEventListener("pointerup",F),window.removeEventListener("keydown",_),window.removeEventListener("keyup",A)}},[n,e,t]),!r)return null;const i=((I=n.cameraRef)==null?void 0:I.current)||{x:0,y:0,zoom:1},f=Math.min(r.startX,r.endX),p=Math.min(r.startY,r.endY),d=Math.abs(r.endX-r.startX),h=Math.abs(r.endY-r.startY),v=f*i.zoom+i.x,E=p*i.zoom+i.y,M=d*i.zoom,z=h*i.zoom;return P.jsx("div",{ref:o,className:"ric-selection-box",style:{position:"absolute",left:v,top:E,width:M,height:z,border:"1px dashed #3b82f6",background:"rgba(59, 130, 246, 0.08)",pointerEvents:"none",zIndex:100}})}kr.displayName="SelectionBox";const Cr=c.memo(kr);function On(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(),a=e.getBoundingClientRect(),o=t||1;return{x:(a.left+a.width/2-r.left)/o,y:(a.top+a.height/2-r.top)/o}}let Fn=!1,Ct=null;function Er(e){Ct=e,!Fn&&(Fn=!0,requestAnimationFrame(()=>{var t;Fn=!1,(t=Ct==null?void 0:Ct.syncNodesToWorker)==null||t.call(Ct),Ct=null}))}const Zn=new WeakMap;let xn=null;function po(){return xn||(xn=new ResizeObserver(e=>{var t;for(const n of e){const r=Zn.get(n.target);if(!r)continue;const{width:a,height:o}=n.contentRect;if(!a||!o)continue;const i=r.getStore(),f=(t=i.handleRegistryRef)==null?void 0:t.current;if(f){for(const[p,d]of f)if(d.nodeId===r.nodeId){const h=On(d.position,a,o);d.x=h.x,d.y=h.y,f.set(p,d)}Er(i)}}}),xn)}function mo({type:e="source",position:t=e==="source"?"right":"left",id:n,isConnectable:r=!0,isConnectableStart:a=!0,isConnectableEnd:o=!0,children:i,className:f="",style:p={},onConnect:d,...h}){const v=c.useContext(on),E=c.useContext(Et),M=c.useRef(null),z=c.useCallback(()=>typeof E.getState=="function"?E.getState():E,[E]),I=c.useRef(z);I.current=z,c.useLayoutEffect(()=>{var b,g,x,N,$,W,Q;if(!v)return;const D=I.current(),_=(b=D.handleRegistryRef)==null?void 0:b.current;if(!_)return;const A=`${v}__${n||e}`,L=(x=(g=D.nodesRef)==null?void 0:g.current)==null?void 0:x.find(re=>re.id===v),Y=(L==null?void 0:L.width)||((N=L==null?void 0:L.measured)==null?void 0:N.width),F=(L==null?void 0:L.height)||(($=L==null?void 0:L.measured)==null?void 0:$.height);let B;Y&&F?B=On(t,Y,F):M.current?B=xo(M.current,(Q=(W=D.cameraRef)==null?void 0:W.current)==null?void 0:Q.zoom):B=On(t,160,60),_.set(A,{nodeId:v,id:n||null,type:e,position:t,x:B.x,y:B.y})},[v,n,e,t]),c.useEffect(()=>{if(!v)return;const D=I.current();Er(D);const _=M.current,A=_==null?void 0:_.closest(".ric-node-wrapper");return A&&!Zn.has(A)&&(Zn.set(A,{nodeId:v,getStore:I.current}),po().observe(A)),()=>{var B;const Y=(B=I.current().handleRegistryRef)==null?void 0:B.current,F=`${v}__${n||e}`;Y==null||Y.delete(F)}},[v,n,e,t]);const k=c.useCallback(()=>{var g;const D=I.current(),_=D.nodesRef.current.find(x=>x.id===v);if(!_)return null;const A=_._absolutePosition||_.position,L=(g=D.handleRegistryRef)==null?void 0:g.current,Y=`${v}__${n||e}`,F=L==null?void 0:L.get(Y);if(F&&F.x!==void 0&&F.y!==void 0)return{x:A.x+F.x,y:A.y+F.y};const B=_.width||160,b=_.height||60;switch(t){case"top":return{x:A.x+B/2,y:A.y};case"bottom":return{x:A.x+B/2,y:A.y+b};case"left":return{x:A.x,y:A.y+b/2};default:return{x:A.x+B,y:A.y+b/2}}},[v,n,e,t]),j=c.useCallback(D=>{var N;if(!r||!a)return;D.stopPropagation(),D.preventDefault();const _=I.current(),A=_.cameraRef.current,L=_.wrapRef.current;if(!L)return;const Y=L.getBoundingClientRect(),F=k();if(!F)return;const B=F.x,b=F.y;(N=_.workerRef.current)==null||N.postMessage({type:"connecting",data:{from:{x:B,y:b},to:{x:B,y:b}}}),L.setPointerCapture(D.pointerId);const g=$=>{var re;const W=($.clientX-Y.left-A.x)/A.zoom,Q=($.clientY-Y.top-A.y)/A.zoom;(re=_.workerRef.current)==null||re.postMessage({type:"connecting",data:{from:{x:B,y:b},to:{x:W,y:Q}}})},x=$=>{var ye,J,fe,me;const W=($.clientX-Y.left-A.x)/A.zoom,Q=($.clientY-Y.top-A.y)/A.zoom,re=20/A.zoom;let ee=null,oe=null;const ge=(ye=_.handleRegistryRef)==null?void 0:ye.current;for(const ae of _.nodesRef.current){if(ae.id===v||ae.hidden)continue;const ue=ae._absolutePosition||ae.position,Ne=[];if(ge)for(const[,le]of ge)le.nodeId===ae.id&&Ne.push(le);const Je=Ne.length>0?Ne:ae.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const le of Je){let $e,Be;if(le.x!==void 0&&le.y!==void 0)$e=ue.x+le.x,Be=ue.y+le.y;else{const _e=ae.width||160,he=ae.height||60;switch(le.position||(le.type==="source"?"right":"left")){case"top":$e=ue.x+_e/2,Be=ue.y;break;case"bottom":$e=ue.x+_e/2,Be=ue.y+he;break;case"left":$e=ue.x,Be=ue.y+he/2;break;default:$e=ue.x+_e,Be=ue.y+he/2;break}}if(Math.abs(W-$e)<re&&Math.abs(Q-Be)<re){ee=ae,oe=le.id||null;break}}if(ee)break}if(ee){const ae={source:e==="source"?v:ee.id,target:e==="source"?ee.id:v,sourceHandle:e==="source"?n||null:oe,targetHandle:e==="source"?oe:n||null};(fe=(J=_.onEdgesChangeRef)==null?void 0:J.current)==null||fe.call(J,[{type:"add",item:{id:`e-${ae.source}-${ae.target}`,...ae}}])}(me=_.workerRef.current)==null||me.postMessage({type:"connecting",data:null}),L.removeEventListener("pointermove",g),L.removeEventListener("pointerup",x)};L.addEventListener("pointermove",g),L.addEventListener("pointerup",x)},[v,n,e,t,r,a,k]),X={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 P.jsx("div",{ref:M,className:`ric-handle ric-handle-${t} ric-handle-${e} ${f}`,"data-handleid":n||null,"data-nodeid":v,"data-handlepos":t,"data-handletype":e,onPointerDown:j,style:{position:"absolute",width:8,height:8,borderRadius:"50%",background:"#1a192b",border:"none",zIndex:10,cursor:r?"crosshair":"default",boxSizing:"border-box",...X,...p},...h,children:i})}const rn=c.memo(mo);function vo({data:e,isConnectable:t,selected:n,targetPosition:r="left",sourcePosition:a="right",hideSourceHandle:o=!1,hideTargetHandle:i=!1}){return P.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:[!i&&P.jsx(rn,{type:"target",position:r,isConnectable:t}),P.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!o&&P.jsx(rn,{type:"source",position:a,isConnectable:t})]})}function zr({data:e,isConnectable:t,selected:n,sourcePosition:r="right",hideSourceHandle:a=!1}){return P.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:[P.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!a&&P.jsx(rn,{type:"source",position:r,isConnectable:t})]})}function Sr({data:e,isConnectable:t,selected:n,targetPosition:r="left",hideTargetHandle:a=!1}){return P.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:[!a&&P.jsx(rn,{type:"target",position:r,isConnectable:t}),P.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label})]})}function Nr({data:e,selected:t,width:n,height:r}){return P.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)&&P.jsx("div",{style:{fontSize:11,fontWeight:600,color:"#888",userSelect:"none"},children:e.label})})}function Pr({x:e,y:t,label:n,labelStyle:r,labelShowBg:a=!0,labelBgStyle:o,labelBgPadding:i=[2,4],labelBgBorderRadius:f=2,children:p,className:d="",...h}){const[v,E]=c.useState({x:1,y:0,width:0,height:0}),M=c.useRef(null);return c.useEffect(()=>{if(M.current){const z=M.current.getBBox();E({x:z.x,y:z.y,width:z.width,height:z.height})}},[n]),n?P.jsxs("g",{transform:`translate(${e-v.width/2} ${t-v.height/2})`,className:`ric-edge-textwrapper ${d}`,visibility:v.width?"visible":"hidden",...h,children:[a&&P.jsx("rect",{width:v.width+2*i[0],x:-i[0],y:-i[1],height:v.height+2*i[1],className:"ric-edge-textbg",style:o,rx:f,ry:f}),P.jsx("text",{className:"ric-edge-text",y:v.height/2,dy:"0.3em",ref:M,style:r,children:n}),p]}):null}Pr.displayName="EdgeText";const Ir=c.memo(Pr);function dr(e){return e!=null&&e!==""&&!isNaN(Number(e))}function sn({id:e,path:t,labelX:n,labelY:r,label:a,labelStyle:o,labelShowBg:i,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:d,interactionWidth:h=20,style:v,markerEnd:E,markerStart:M,className:z="",...I}){return P.jsxs(P.Fragment,{children:[P.jsx("path",{id:e,d:t,fill:"none",stroke:"#b1b1b7",strokeWidth:1.5,className:`ric-edge-path ${z}`,style:v,markerEnd:E,markerStart:M,...I}),h?P.jsx("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:h,className:"ric-edge-interaction",style:{pointerEvents:"stroke"}}):null,a&&dr(n)&&dr(r)?P.jsx(Ir,{x:n,y:r,label:a,labelStyle:o,labelShowBg:i,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:d}):null]})}const en=20;function fr(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 Vn=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:i="bottom",targetPosition:f="top",label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,interactionWidth:j}){let X,D,_;const A=fr(n,r,i),L=fr(a,o,f),Y=Math.abs(L.x-A.x),F=Math.max(50,Y*.5);let B,b,g,x;switch(i){case"left":B=A.x-F,b=A.y;break;case"top":B=A.x,b=A.y-F;break;case"bottom":B=A.x,b=A.y+F;break;default:B=A.x+F,b=A.y;break}switch(f){case"right":g=L.x+F,x=L.y;break;case"top":g=L.x,x=L.y-F;break;case"bottom":g=L.x,x=L.y+F;break;default:g=L.x-F,x=L.y;break}X=`M ${n},${r} L ${A.x},${A.y} C ${B},${b} ${g},${x} ${L.x},${L.y} L ${a},${o}`;const N=.5,$=.5;return D=$*$*$*A.x+3*$*$*N*B+3*$*N*N*g+N*N*N*L.x,_=$*$*$*A.y+3*$*$*N*b+3*$*N*N*x+N*N*N*L.y,P.jsx(sn,{id:t,path:X,labelX:D,labelY:_,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,interactionWidth:j})});Vn.displayName="BezierEdge";function Jn({sourceX:e,sourceY:t,targetX:n,targetY:r}){const a=`M ${e},${t}L ${n},${r}`,o=(e+n)/2,i=(t+r)/2;return[a,o,i,0,0]}function Kn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a="right",targetPosition:o="left",curvature:i=.25}){const f=Math.abs(n-e),p=Math.abs(r-t),d=Math.sqrt(f*f+p*p),h=Math.max(d*i,50);let v,E,M,z;switch(a){case"top":v=e,E=t-h;break;case"bottom":v=e,E=t+h;break;case"left":v=e-h,E=t;break;default:v=e+h,E=t;break}switch(o){case"top":M=n,z=r-h;break;case"bottom":M=n,z=r+h;break;case"right":M=n+h,z=r;break;default:M=n-h,z=r;break}const I=`M ${e},${t} C ${v},${E} ${M},${z} ${n},${r}`,k=.5,j=1-k,X=j*j*j*e+3*j*j*k*v+3*j*k*k*M+k*k*k*n,D=j*j*j*t+3*j*j*k*E+3*j*k*k*z+k*k*k*r;return[I,X,D,0,0]}function er({sourceX:e,sourceY:t,targetX:n,targetY:r}){const a=Math.abs(n-e),o=Math.max(a*.5,50),i=e+o,f=n-o,p=`M ${e},${t} C ${i},${t} ${f},${r} ${n},${r}`,d=.5,h=.5,v=h*h*h*e+3*h*h*d*i+3*h*d*d*f+d*d*d*n,E=h*h*h*t+3*h*h*d*t+3*h*d*d*r+d*d*d*r;return[p,v,E,0,0]}function vn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a="right",targetPosition:o="left",borderRadius:i=5,offset:f=20}){const p=a==="left"||a==="right",d=Math.min(i,Math.abs(n-e)/2,Math.abs(r-t)/2);if(p){if(Math.abs(r-t)<1)return[`M ${e},${t} L ${n},${r}`,(e+n)/2,t,0,0];const M=(e+n)/2,z=r>t?1:-1;return[`M ${e},${t} L ${M-d},${t} Q ${M},${t} ${M},${t+z*d} L ${M},${r-z*d} Q ${M},${r} ${M+(n>M?d:-d)},${r} L ${n},${r}`,M,(t+r)/2,0,0]}const h=(t+r)/2,v=n>e?1:-1;return[`M ${e},${t} L ${e},${h-d} Q ${e},${h} ${e+v*d},${h} L ${n-v*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[,a,o]=Kn({sourceX:e,sourceY:t,targetX:n,targetY:r});return[a,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),a={...e,id:e.id,source:t.source,target:t.target,sourceHandle:t.sourceHandle??e.sourceHandle,targetHandle:t.targetHandle??e.targetHandle};return r.push(a),r}const bn=160,wn=60,tn=20,pn=12,Mn=20;function hr(e,t,n){var i,f;const r=e.width||((i=e.measured)==null?void 0:i.width)||bn,a=e.height||((f=e.measured)==null?void 0:f.height)||wn,o=e._absolutePosition||e.position;if(e.handles&&e.handles.length>0){for(const p of e.handles)if(p.type===t&&(!n||p.id===n)){if(p.x!==void 0&&p.y!==void 0)return{x:o.x+p.x,y:o.y+p.y,dir:p.position||(t==="source"?"right":"left")};switch(p.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+a,dir:"bottom"};case"left":return{x:o.x,y:o.y+a/2,dir:"left"};default:return{x:o.x+r,y:o.y+a/2,dir:"right"}}}}return t==="source"?{x:o.x+r,y:o.y+a/2,dir:"right"}:{x:o.x,y:o.y+a/2,dir:"left"}}function Rn(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,a,o,i,f){const p=Math.min(e,n),d=Math.max(e,n),h=Math.min(t,r),v=Math.max(t,r);if(d<=a||p>=a+i||v<=o||h>=o+f)return!1;const E=.5;if(e>a+E&&e<a+i-E&&t>o+E&&t<o+f-E||n>a+E&&n<a+i-E&&r>o+E&&r<o+f-E)return!0;const M=(e+n)/2,z=(t+r)/2;if(M>a+E&&M<a+i-E&&z>o+E&&z<o+f-E)return!0;const I=[[a,o],[a+i,o],[a+i,o+f],[a,o+f]];for(let k=0;k<4;k++)if(ko(e,t,n,r,I[k][0],I[k][1],I[(k+1)%4][0],I[(k+1)%4][1]))return!0;return!1}function ko(e,t,n,r,a,o,i,f){const p=(i-a)*(t-o)-(f-o)*(e-a),d=(i-a)*(r-o)-(f-o)*(n-a),h=(n-e)*(o-t)-(r-t)*(a-e),v=(n-e)*(f-t)-(r-t)*(i-e);return(p>0&&d<0||p<0&&d>0)&&(h>0&&v<0||h<0&&v>0)}function Gn(e,t,n,r,a){for(let o=0;o<a.length;o++){const i=a[o];if(Ro(e,t,n,r,i.x,i.y,i.w,i.h))return!1}return!0}function Co(e,t,n){for(let r=0;r<n.length;r++){const a=n[r];if(e>a.x&&e<a.x+a.w&&t>a.y&&t<a.y+a.h)return!0}return!1}function tr(e,t){var r,a;const n=[];for(let o=0;o<e.length;o++){const i=e[o];if(i.hidden||t&&t.has(i.id)||i.type==="group")continue;const f=i._absolutePosition||i.position,p=i.width||((r=i.measured)==null?void 0:r.width)||bn,d=i.height||((a=i.measured)==null?void 0:a.height)||wn;n.push({id:i.id,x:f.x-tn,y:f.y-tn,w:p+2*tn,h:d+2*tn})}return n}function Lr(e,t,n){if(Gn(e.x,e.y,t.x,t.y,n))return null;const r=new Set,a=new Set;r.add(e.x),r.add(t.x),a.add(e.y),a.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"?a.add(e.y-o):e.dir==="bottom"&&a.add(e.y+o),t.dir==="right"?r.add(t.x+o):t.dir==="left"?r.add(t.x-o):t.dir==="top"?a.add(t.y-o):t.dir==="bottom"&&a.add(t.y+o);for(let g=0;g<n.length;g++){const x=n[g];r.add(x.x),r.add(x.x+x.w),a.add(x.y),a.add(x.y+x.h)}const i=[...r].sort((g,x)=>g-x),f=[...a].sort((g,x)=>g-x),p=new Map,d=new Map;for(let g=0;g<i.length;g++)p.set(i[g],g);for(let g=0;g<f.length;g++)d.set(f[g],g);const h=i.length,v=f.length,E=(g,x)=>x*h+g,M=p.get(e.x),z=d.get(e.y),I=p.get(t.x),k=d.get(t.y);if(M===void 0||z===void 0||I===void 0||k===void 0)return null;const j=E(M,z),X=E(I,k),D=new Float64Array(h*v).fill(1/0),_=new Float64Array(h*v).fill(1/0),A=new Int32Array(h*v).fill(-1),L=new Int8Array(h*v).fill(-1),Y=new Uint8Array(h*v);D[j]=0,_[j]=Math.abs(i[I]-e.x)+Math.abs(f[k]-e.y);const F=[j],B=15,b=[[1,0],[-1,0],[0,1],[0,-1]];for(;F.length>0;){let g=0;for(let ee=1;ee<F.length;ee++)_[F[ee]]<_[F[g]]&&(g=ee);const x=F[g];if(F[g]=F[F.length-1],F.pop(),x===X){const ee=[];let oe=X;for(;oe!==-1&&oe!==j;){const ge=oe/h|0,ye=oe%h;ee.unshift({x:i[ye],y:f[ge]}),oe=A[oe]}return ee.unshift({x:e.x,y:e.y}),Eo(ee,n)}if(Y[x])continue;Y[x]=1;const N=x/h|0,$=x%h,W=i[$],Q=f[N],re=L[x];for(let ee=0;ee<4;ee++){const oe=$+b[ee][0],ge=N+b[ee][1];if(oe<0||oe>=h||ge<0||ge>=v)continue;const ye=E(oe,ge);if(Y[ye])continue;const J=i[oe],fe=f[ge];if(Co(J,fe,n)||!Gn(W,Q,J,fe,n))continue;const me=Math.abs(J-W)+Math.abs(fe-Q),ae=re>=0&&re!==ee?B:0,ue=D[x]+me+ae;ue<D[ye]&&(A[ye]=x,L[ye]=ee,D[ye]=ue,_[ye]=ue+Math.abs(i[I]-J)+Math.abs(f[k]-fe),F.push(ye))}}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 a=n[n.length-1],o=e[r],i=e[r+1],f=Math.abs(a.x-o.x)<.5&&Math.abs(o.x-i.x)<.5,p=Math.abs(a.y-o.y)<.5&&Math.abs(o.y-i.y)<.5;(f||p)&&Gn(a.x,a.y,i.x,i.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 a of e){const o=a._routedPoints;if(!(!o||o.length<2))for(let i=0;i<o.length-1;i++){const f=o[i],p=o[i+1];if(Math.abs(f.y-p.y)<.5){const d=Math.round(f.y*10)/10;t.has(d)||t.set(d,[]),t.get(d).push({edgeId:a.id,segIdx:i,x1:Math.min(f.x,p.x),x2:Math.max(f.x,p.x)})}else if(Math.abs(f.x-p.x)<.5){const d=Math.round(f.x*10)/10;n.has(d)||n.set(d,[]),n.get(d).push({edgeId:a.id,segIdx:i,y1:Math.min(f.y,p.y),y2:Math.max(f.y,p.y)})}}}const r=new Map;for(const a of e)a._routedPoints&&r.set(a.id,a._routedPoints.map(o=>({...o})));for(const[,a]of t){if(a.length<2)continue;const o=gr(a,"x1","x2");for(const i of o){if(i.length<2)continue;const f=(i.length-1)*pn/2;for(let p=0;p<i.length;p++){const d=i[p],h=-f+p*pn,v=r.get(d.edgeId);v&&(v[d.segIdx].y+=h,v[d.segIdx+1].y+=h)}}}for(const[,a]of n){if(a.length<2)continue;const o=gr(a,"y1","y2");for(const i of o){if(i.length<2)continue;const f=(i.length-1)*pn/2;for(let p=0;p<i.length;p++){const d=i[p],h=-f+p*pn,v=r.get(d.edgeId);v&&(v[d.segIdx].x+=h,v[d.segIdx+1].x+=h)}}}return e.map(a=>{const o=r.get(a.id);return o?{...a,_routedPoints:o}:a})}function gr(e,t,n){if(e.length<2)return[];const r=[...e].sort((i,f)=>i[t]-f[t]),a=[];let o=[r[0]];for(let i=1;i<r.length;i++){const f=o[o.length-1];r[i][t]<f[n]?o.push(r[i]):(o.length>1&&a.push(o),o=[r[i]])}return o.length>1&&a.push(o),a}function kn(e,t=6,n=!1){if(!e||e.length<2)return null;if(n)return So(e);const r=t;let a=`M ${e[0].x},${e[0].y}`;for(let o=1;o<e.length-1;o++){const i=e[o-1],f=e[o],p=e[o+1],d=Math.abs(f.x-i.x)+Math.abs(f.y-i.y),h=Math.abs(p.x-f.x)+Math.abs(p.y-f.y),v=Math.min(r,d/2,h/2);if(v>.5){const E=f.x-i.x,M=f.y-i.y,z=p.x-f.x,I=p.y-f.y,k=Math.sqrt(E*E+M*M)||1,j=Math.sqrt(z*z+I*I)||1;a+=` L ${f.x-E/k*v},${f.y-M/k*v}`,a+=` Q ${f.x},${f.y} ${f.x+z/j*v},${f.y+I/j*v}`}else a+=` L ${f.x},${f.y}`}return a+=` L ${e[e.length-1].x},${e[e.length-1].y}`,a}function So(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 a=e[r===0?0:r-1],o=e[r],i=e[r+1],f=e[r+2<e.length?r+2:e.length-1],p=o.x+(i.x-a.x)*t,d=o.y+(i.y-a.y)*t,h=i.x-(f.x-o.x)*t,v=i.y-(f.y-o.y)*t;n+=` C ${p},${d} ${h},${v} ${i.x},${i.y}`}return n}function Cn(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 a=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);if(n<=a){const o=a>0?n/a: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-=a}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=tr(e,null),a=t.map(o=>{var L,Y,F,B;const i=o.type||"default";if(i==="bezier"||i==="simplebezier"||i==="default")return o;const f=n[o.source],p=n[o.target];if(!f||!p||f.hidden||p.hidden)return o;const d=hr(f,"source",o.sourceHandle),h=hr(p,"target",o.targetHandle),v=Rn(d,Mn),E=Rn(h,Mn),M=5,z=r.filter(b=>b.id!==o.source&&b.id!==o.target),I=f._absolutePosition||f.position,k=f.width||((L=f.measured)==null?void 0:L.width)||bn,j=f.height||((Y=f.measured)==null?void 0:Y.height)||wn;z.push({id:o.source,x:I.x-M,y:I.y-M,w:k+2*M,h:j+2*M});const X=p._absolutePosition||p.position,D=p.width||((F=p.measured)==null?void 0:F.width)||bn,_=p.height||((B=p.measured)==null?void 0:B.height)||wn;if(z.push({id:o.target,x:X.x-M,y:X.y-M,w:D+2*M,h:_+2*M}),z.length===0)return o;const A=Lr(v,E,z);return A&&A.length>=2?(A.unshift({x:d.x,y:d.y}),A.push({x:h.x,y:h.y}),{...o,_routedPoints:A}):o});return zo(a)}function Po(e,t,n,r,a,o,i,f){const p=tr(i,f?new Set(f):null);if(p.length===0)return null;const d={x:e,y:t,dir:a||"right"},h={x:n,y:r,dir:o||"left"},v=Rn(d,Mn),E=Rn(h,Mn),M=Lr(v,E,p);return M&&M.length>=2?(M.unshift({x:d.x,y:d.y}),M.push({x:h.x,y:h.y}),M):null}const nr=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,label:i,labelStyle:f,labelShowBg:p,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:v,style:E,markerEnd:M,markerStart:z,interactionWidth:I,routedPoints:k}){let j,X,D;if(k&&k.length>=2){j=kn(k);const _=Cn(k);X=_.x,D=_.y}else[j,X,D]=Jn({sourceX:n,sourceY:r,targetX:a,targetY:o});return P.jsx(sn,{id:t,path:j,labelX:X,labelY:D,label:i,labelStyle:f,labelShowBg:p,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:v,style:E,markerEnd:M,markerStart:z,interactionWidth:I})});nr.displayName="StraightEdge";const rr=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:i="bottom",targetPosition:f="top",label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,pathOptions:j,interactionWidth:X,routedPoints:D}){let _,A,L;if(D&&D.length>=2){_=kn(D);const Y=Cn(D);A=Y.x,L=Y.y}else[_,A,L]=vn({sourceX:n,sourceY:r,sourcePosition:i,targetX:a,targetY:o,targetPosition:f,borderRadius:j==null?void 0:j.borderRadius,offset:j==null?void 0:j.offset});return P.jsx(sn,{id:t,path:_,labelX:A,labelY:L,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,interactionWidth:X})});rr.displayName="SmoothStepEdge";const Tr=c.memo(function({id:t,...n}){var a;const r=c.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(a=n.pathOptions)==null?void 0:a.offset]);return P.jsx(rr,{...n,id:t,pathOptions:r})});Tr.displayName="StepEdge";const or=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:i,targetPosition:f,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,interactionWidth:j,routedPoints:X}){let D,_,A;if(X&&X.length>=2){D=kn(X);const L=Cn(X);_=L.x,A=L.y}else[D,_,A]=er({sourceX:n,sourceY:r,targetX:a,targetY:o});return P.jsx(sn,{id:t,path:D,labelX:_,labelY:A,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,interactionWidth:j})});or.displayName="SimpleBezierEdge";const Io={input:zr,output:Sr,group:Nr},Lo={bezier:Vn,straight:nr,simplebezier:or},To=160,$o=60;function Bo(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,a;return((r=n.measured)==null?void 0:r.width)!=null&&((a=n.measured)==null?void 0:a.height)!=null?n:{...n,measured:{width:n.width||To,height:n.height||$o}}}):e}function jo({cards:e,nodes:t=[],edges:n=[],nodeTypes:r,edgeTypes:a,dark:o,gridSize:i,width:f="100%",height:p="420px",className:d="",style:h={},zoomMin:v,zoomMax:E,initialCamera:M,fitView:z,fitViewOptions:I,onNodesChange:k,onEdgesChange:j,onConnect:X,onConnectStart:D,onConnectEnd:_,onNodeClick:A,onNodeDoubleClick:L,onNodeMouseEnter:Y,onNodeMouseMove:F,onNodeMouseLeave:B,onNodeContextMenu:b,onNodeDragStart:g,onNodeDrag:x,onNodeDragStop:N,onEdgeClick:$,onEdgeDoubleClick:W,onEdgeMouseEnter:Q,onEdgeMouseMove:re,onEdgeMouseLeave:ee,onEdgeContextMenu:oe,onPaneClick:ge,onPaneContextMenu:ye,onPaneMouseEnter:J,onPaneMouseMove:fe,onPaneMouseLeave:me,onSelectionChange:ae,onInit:ue,onMoveStart:Ne,onMove:Je,onMoveEnd:le,onDelete:$e,onBeforeDelete:Be,onError:_e,onDragOver:he,onDrop:Me,onDragEnter:Oe,onDragLeave:je,nodesDraggable:it,nodesConnectable:zt,elementsSelectable:Ae,multiSelectionKeyCode:Xe,selectionOnDrag:Ze,selectionMode:St,connectionMode:an,connectionRadius:At,connectOnClick:cn,isValidConnection:un,defaultEdgeOptions:ln,snapToGrid:dn,snapGrid:Dt,deleteKeyCode:dt,panActivationKeyCode:ft,panOnScroll:Nt,panOnScrollMode:En,panOnScrollSpeed:zn,zoomOnScroll:rt,zoomOnDoubleClick:sr,zoomOnPinch:Sn,preventScrolling:Nn,translateExtent:Pt,nodeExtent:It,autoPanOnNodeDrag:Pn,autoPanOnConnect:In,autoPanSpeed:Ln,edgesReconnectable:ht,elevateNodesOnSelect:pe,elevateEdgesOnSelect:Ht,noDragClassName:Ee,noPanClassName:ie,onSelectionDragStart:gt,onSelectionDrag:K,onSelectionDragStop:Re,edgeRouting:fn=!0,onHudUpdate:ct,onNodesProcessed:Lt,showHud:Tn=!0,showHint:$n=!0,hintText:We="Drag to pan · Scroll to zoom",children:Ye,..._t}){const[De,Wt]=c.useState({wx:0,wy:0,zoom:"1.00"}),Mt=c.useRef(null),Ft=c.useRef(null),Bn=c.useCallback(V=>{Wt(V),ct==null||ct(V)},[ct]),yt=c.useMemo(()=>({...Io,...r}),[r]),xt=c.useMemo(()=>({...Lo,...a}),[a]),ut=c.useMemo(()=>Bo(t),[t]),Ke=c.useMemo(()=>{const V=t.filter(He=>He.type&&yt[He.type]);return V.sort((He,ve)=>{const Ie=He.type==="group"||!He.parentId&&V.some(ce=>ce.parentId===He.id),st=ve.type==="group"||!ve.parentId&&V.some(ce=>ce.parentId===ve.id);return Ie&&!st?-1:!Ie&&st?1:0})},[t,yt]),Tt=c.useMemo(()=>n.filter(V=>V.type&&xt[V.type]),[n,xt]),O=c.useMemo(()=>t.map(V=>V.type&&yt[V.type]?{...V,_customRendered:!0}:V),[t,yt]),pt=c.useMemo(()=>n.map(V=>V.type&&xt[V.type]?{...V,_customRendered:!0}:V),[n,xt]),{wrapRef:$t,canvasRef:Xt,canvasReady:Yt,onPointerDown:qt,onPointerMove:Ut,onPointerUp:Ot,store:we}=br({cards:e,nodes:O,edges:pt,dark:o,gridSize:i,zoomMin:v,zoomMax:E,initialCamera:M,fitView:z,fitViewOptions:I,onHudUpdate:Bn,onNodesProcessed:Lt,onNodesChange:k,onEdgesChange:j,onConnect:X,onConnectStart:D,onConnectEnd:_,onNodeClick:A,onNodeDoubleClick:L,onNodeMouseEnter:Y,onNodeMouseMove:F,onNodeMouseLeave:B,onNodeContextMenu:b,onNodeDragStart:g,onNodeDrag:x,onNodeDragStop:N,onEdgeClick:$,onEdgeDoubleClick:W,onEdgeMouseEnter:Q,onEdgeMouseMove:re,onEdgeMouseLeave:ee,onEdgeContextMenu:oe,onPaneClick:ge,onPaneContextMenu:ye,onPaneMouseEnter:J,onPaneMouseMove:fe,onPaneMouseLeave:me,onSelectionChange:ae,onInit:ue,onMoveStart:Ne,onMove:Je,onMoveEnd:le,onDelete:$e,onBeforeDelete:Be,onError:_e,nodesDraggable:it,nodesConnectable:zt,elementsSelectable:Ae,multiSelectionKeyCode:Xe,selectionOnDrag:Ze,selectionMode:St,connectionMode:an,connectionRadius:At,connectOnClick:cn,isValidConnection:un,defaultEdgeOptions:ln,snapToGrid:dn,snapGrid:Dt,deleteKeyCode:dt,panActivationKeyCode:ft,panOnScroll:Nt,panOnScrollMode:En,panOnScrollSpeed:zn,zoomOnScroll:rt,zoomOnDoubleClick:sr,zoomOnPinch:Sn,preventScrolling:Nn,translateExtent:Pt,nodeExtent:It,autoPanOnNodeDrag:Pn,autoPanOnConnect:In,autoPanSpeed:Ln,edgesReconnectable:ht,elevateNodesOnSelect:pe,elevateEdgesOnSelect:Ht,noDragClassName:Ee,noPanClassName:ie,onSelectionDragStart:gt,onSelectionDrag:K,onSelectionDragStop:Re,edgeRouting:fn}),mt=c.useContext(Et),Bt=mt&&typeof mt.getState=="function";c.useEffect(()=>{Bt&&queueMicrotask(()=>{mt.setState({nodes:ut,edges:n,nodesRef:we.nodesRef,edgesRef:we.edgesRef,onNodesChangeRef:we.onNodesChangeRef,onEdgesChangeRef:we.onEdgesChangeRef,cameraRef:we.cameraRef,wrapRef:we.wrapRef,workerRef:we.workerRef})})},[Bt,ut,n,we,mt]);const ze=c.useMemo(()=>({...we,edgeLabelContainerRef:Mt,viewportPortalRef:Ft,get nodes(){return ut},get edges(){return n},get viewport(){return we.cameraRef.current},get minZoom(){return we.zoomMin||.1},get maxZoom(){return we.zoomMax||5},get domNode(){return we.wrapRef.current},get width(){var V;return((V=we.wrapRef.current)==null?void 0:V.clientWidth)||0},get height(){var V;return((V=we.wrapRef.current)==null?void 0:V.clientHeight)||0}}),[we,ut,n]),Zt=c.useRef(null),Pe=c.useRef(null),Gt=c.useRef(null),ot=c.useRef(null),Rt=c.useRef(null);c.useEffect(()=>{let V;const He=()=>{const ve=we.cameraRef.current,Ie=`translate(${ve.x}px, ${ve.y}px) scale(${ve.zoom})`,st=`translate(${ve.x}, ${ve.y}) scale(${ve.zoom})`;Zt.current&&(Zt.current.style.transform=Ie),Pe.current&&Pe.current.setAttribute("transform",st),Gt.current&&(Gt.current.style.transform=Ie),ot.current&&(ot.current.style.transform=Ie);const ce=$t.current;if(ce){const Ge=ve.zoom<.15?"lod-minimal":ve.zoom<.35?"lod-reduced":null;Ge!==Rt.current&&(ce.classList.remove("lod-minimal","lod-reduced"),Ge&&ce.classList.add(Ge),Rt.current=Ge)}V=requestAnimationFrame(He)};return V=requestAnimationFrame(He),()=>cancelAnimationFrame(V)},[we]);const[et,vt]=c.useState(null);c.useEffect(()=>{if(!Ke.length)return;let V;const He=()=>{var Qt,gn;const ve=we.cameraRef.current,Ie=we.wrapRef.current;if(!Ie){V=requestAnimationFrame(He);return}const st=Ie.getBoundingClientRect(),ce=200,Ge=-ve.x/ve.zoom-ce,bt=-ve.y/ve.zoom-ce,jn=(st.width-ve.x)/ve.zoom+ce,An=(st.height-ve.y)/ve.zoom+ce,kt=new Set;for(const qe of Ke){const wt=qe._absolutePosition||qe.position,Dn=qe.width||((Qt=qe.measured)==null?void 0:Qt.width)||200,Hn=qe.height||((gn=qe.measured)==null?void 0:gn.height)||100;wt.x+Dn>=Ge&&wt.x<=jn&&wt.y+Hn>=bt&&wt.y<=An&&kt.add(qe.id)}vt(qe=>{if(!qe||qe.size!==kt.size)return kt;for(const wt of kt)if(!qe.has(wt))return kt;return qe}),V=requestAnimationFrame(He)};return V=requestAnimationFrame(He),()=>cancelAnimationFrame(V)},[Ke,we]);const hn=c.useMemo(()=>et?Ke.filter(V=>et.has(V.id)):Ke,[Ke,et]),Se=Ke.length>0,tt=Tt.length>0;return P.jsx(Et.Provider,{value:ze,children:P.jsxs("div",{ref:$t,className:`ric-wrap ${d}`,style:{width:f,height:p,...h},onPointerDown:qt,onPointerMove:Ut,onPointerUp:Ot,onDragOver:he,onDrop:Me,onDragEnter:Oe,onDragLeave:je,tabIndex:0,children:[P.jsx("canvas",{ref:Xt,className:"ric-canvas"}),!Yt&&P.jsx("div",{className:"ric-loader",children:P.jsx("div",{className:"ric-spinner"})}),tt&&P.jsx("svg",{className:"ric-edges-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:P.jsx("g",{ref:Pe,children:Tt.map(V=>P.jsx(yo,{edge:V,edgeType:xt[V.type],nodes:t,reconnectable:ht},V.id))})}),Se&&P.jsx("div",{ref:Zt,className:"ric-nodes-overlay",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:10},children:hn.map(V=>P.jsx(lo,{node:V,nodeType:yt[V.type]},V.id))}),P.jsx("div",{ref:V=>{Mt.current=V,Gt.current=V},className:"ric-edge-labels",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:5}}),P.jsx("div",{ref:V=>{Ft.current=V,ot.current=V},className:"ric-viewport-portal",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:6}}),$n&&P.jsx("div",{className:"ric-hint",children:We}),Tn&&P.jsxs("div",{className:"ric-info",children:["world: (",De.wx,", ",De.wy,") zoom: ",De.zoom,"x",De.nodeCount>0&&P.jsxs(P.Fragment,{children:[" nodes: ",De.nodeCount]}),De.edgeCount>0&&P.jsxs(P.Fragment,{children:[" edges: ",De.edgeCount]})]}),P.jsx(Cr,{selectionKeyCode:Xe||"Shift",selectionMode:St||"partial"}),Ye]})})}function Ao({children:e}){const t=c.useRef(null);return t.current||(t.current=io()),P.jsx(Et.Provider,{value:t.current,children:e})}function $r(e,t){const n=[],r=new Map,a=[];for(const o of e)if(o.type==="add")a.push(o);else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const i=r.get(o.id);i?i.push(o):r.set(o.id,[o])}for(const o of t){const i=r.get(o.id);if(!i){n.push(o);continue}if(i[0].type==="remove")continue;if(i[0].type==="replace"){n.push({...i[0].item});continue}const f={...o};for(const p of i)Do(p,f);n.push(f)}for(const o of a)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 Br(e,t){return $r(e,t)}function jr(e,t){return $r(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]=c.useState(e),r=c.useCallback(a=>n(o=>Br(a,o)),[]);return[t,n,r]}function Wo(e){const[t,n]=c.useState(e),r=c.useCallback(a=>n(o=>jr(a,o)),[]);return[t,n,r]}function Ar(){const e=wr(),t=c.useCallback(()=>typeof e.getState=="function"?e.getState():e,[e]),n=c.useCallback(()=>[...t().nodesRef.current],[t]),r=c.useCallback(()=>[...t().edgesRef.current],[t]),a=c.useCallback(b=>t().nodesRef.current.find(g=>g.id===b),[t]),o=c.useCallback(b=>t().edgesRef.current.find(g=>g.id===b),[t]),i=c.useCallback(b=>{var g,x,N,$;if(typeof b=="function"){const W=b(t().nodesRef.current);(x=(g=t().onNodesChangeRef).current)==null||x.call(g,[...t().nodesRef.current.map(Q=>({id:Q.id,type:"remove"})),...W.map(Q=>({type:"add",item:Q}))])}else($=(N=t().onNodesChangeRef).current)==null||$.call(N,[...t().nodesRef.current.map(W=>({id:W.id,type:"remove"})),...b.map(W=>({type:"add",item:W}))])},[t]),f=c.useCallback(b=>{var g,x,N,$;if(typeof b=="function"){const W=b(t().edgesRef.current);(x=(g=t().onEdgesChangeRef).current)==null||x.call(g,[...t().edgesRef.current.map(Q=>({id:Q.id,type:"remove"})),...W.map(Q=>({type:"add",item:Q}))])}else($=(N=t().onEdgesChangeRef).current)==null||$.call(N,[...t().edgesRef.current.map(W=>({id:W.id,type:"remove"})),...b.map(W=>({type:"add",item:W}))])},[t]),p=c.useCallback(b=>{var x,N;const g=Array.isArray(b)?b:[b];(N=(x=t().onNodesChangeRef).current)==null||N.call(x,g.map($=>({type:"add",item:$})))},[t]),d=c.useCallback(b=>{var x,N;const g=Array.isArray(b)?b:[b];(N=(x=t().onEdgesChangeRef).current)==null||N.call(x,g.map($=>({type:"add",item:$})))},[t]),h=c.useCallback(({nodes:b=[],edges:g=[]})=>{if(b.length&&t().onNodesChangeRef.current){t().onNodesChangeRef.current(b.map(N=>({id:N.id,type:"remove"})));const x=mr(b,t().edgesRef.current);x.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(x.map(N=>({id:N.id,type:"remove"})))}g.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(g.map(x=>({id:x.id,type:"remove"})))},[t]),v=c.useCallback(()=>{const b=t().cameraRef.current;return{x:b.x,y:b.y,zoom:b.zoom}},[t]),E=c.useRef(null),M=c.useCallback((b,g)=>{if(E.current&&cancelAnimationFrame(E.current),!g||g<=0){t().cameraRef.current={...b},t().sendCamera();return}const x={...t().cameraRef.current},N=performance.now(),$=W=>{const Q=W-N,re=Math.min(Q/g,1),ee=1-Math.pow(1-re,3);t().cameraRef.current={x:x.x+(b.x-x.x)*ee,y:x.y+(b.y-x.y)*ee,zoom:x.zoom+(b.zoom-x.zoom)*ee},t().sendCamera(),re<1&&(E.current=requestAnimationFrame($))};E.current=requestAnimationFrame($)},[t]),z=c.useCallback((b,g)=>{const x={x:b.x??t().cameraRef.current.x,y:b.y??t().cameraRef.current.y,zoom:b.zoom??t().cameraRef.current.zoom};M(x,g==null?void 0:g.duration)},[t,M]),I=c.useCallback(()=>t().cameraRef.current.zoom,[t]),k=c.useCallback(b=>{const g=t().cameraRef.current,x=t().wrapRef.current;if(!x)return;const N=x.getBoundingClientRect(),$=N.width/2,W=N.height/2,Q=1.2,re={x:$-($-g.x)*Q,y:W-(W-g.y)*Q,zoom:Math.min(t().zoomMax,g.zoom*Q)};M(re,b==null?void 0:b.duration)},[t,M]),j=c.useCallback(b=>{const g=t().cameraRef.current,x=t().wrapRef.current;if(!x)return;const N=x.getBoundingClientRect(),$=N.width/2,W=N.height/2,Q=1/1.2,re={x:$-($-g.x)*Q,y:W-(W-g.y)*Q,zoom:Math.max(t().zoomMin,g.zoom*Q)};M(re,b==null?void 0:b.duration)},[t,M]),X=c.useCallback((b,g)=>{const x=t().cameraRef.current,N=t().wrapRef.current;if(!N)return;const $=N.getBoundingClientRect(),W=$.width/2,Q=$.height/2,re=Math.min(t().zoomMax,Math.max(t().zoomMin,b)),ee=re/x.zoom,oe={x:W-(W-x.x)*ee,y:Q-(Q-x.y)*ee,zoom:re};M(oe,g==null?void 0:g.duration)},[t,M]),D=c.useCallback((b={})=>{const g=t().nodesRef.current;if(!g.length)return;const x=t().wrapRef.current;if(!x)return;const N=x.getBoundingClientRect(),$=b.padding??.1,W=b.nodes?g.filter(ee=>b.nodes.some(oe=>oe.id===ee.id)):g;if(!W.length)return;const Q=mn(W),re=jt(Q,N.width,N.height,$);b.maxZoom&&(re.zoom=Math.min(re.zoom,b.maxZoom)),b.minZoom&&(re.zoom=Math.max(re.zoom,b.minZoom)),M(re,b.duration)},[t,M]),_=c.useCallback((b,g={})=>{const x=t().wrapRef.current;if(!x)return;const N=x.getBoundingClientRect(),$=g.padding??.1,W=jt(b,N.width,N.height,$);g.maxZoom&&(W.zoom=Math.min(W.zoom,g.maxZoom)),g.minZoom&&(W.zoom=Math.max(W.zoom,g.minZoom)),M(W,g.duration)},[t,M]),A=c.useCallback((b,g,x={})=>{const N=t().wrapRef.current;if(!N)return;const $=N.getBoundingClientRect(),W=x.zoom??t().cameraRef.current.zoom,Q={x:$.width/2-b*W,y:$.height/2-g*W,zoom:W};M(Q,x.duration)},[t,M]),L=c.useCallback(()=>({nodes:[...t().nodesRef.current],edges:[...t().edgesRef.current],viewport:{...t().cameraRef.current}}),[t]),Y=c.useCallback(b=>t().screenToWorld(b.x,b.y),[t]),F=c.useCallback(b=>{const g=t().cameraRef.current,x=t().wrapRef.current;if(!x)return{x:0,y:0};const N=x.getBoundingClientRect();return{x:b.x*g.zoom+g.x+N.left,y:b.y*g.zoom+g.y+N.top}},[t]),B=c.useCallback((b,g)=>{var $,W;const x=t().nodesRef.current.find(Q=>Q.id===b);if(!x)return;const N=typeof g=="function"?g(x.data):{...x.data,...g};(W=($=t().onNodesChangeRef).current)==null||W.call($,[{id:b,type:"replace",item:{...x,data:N}}])},[t]);return{getNodes:n,getEdges:r,getNode:a,getEdge:o,setNodes:i,setEdges:f,addNodes:p,addEdges:d,deleteElements:h,getViewport:v,setViewport:z,getZoom:I,zoomIn:k,zoomOut:j,zoomTo:X,fitView:D,fitBounds:_,setCenter:A,screenToFlowPosition:Y,flowToScreenPosition:F,updateNodeData:B,toObject:L}}function Fo(){return Ce().nodes}function Xo(){return Ce().edges}function Yo(){return Ce().viewport}function qo(){return Ce().connection}function Uo(e){const t=Ce(),n=Array.isArray(e)?e:[e];return c.useMemo(()=>n.map(r=>{const a=t.nodes.find(o=>o.id===r);return a?{id:a.id,type:a.type,data:a.data}:null}).filter(Boolean),[t.nodes,...n])}function Oo(e){const t=Ce();return c.useMemo(()=>t.edges.filter(n=>n.source===e||n.target===e),[t.edges,e])}function Zo({nodeId:e,type:t,handleId:n}){const r=Ce();return c.useMemo(()=>r.edges.filter(a=>t==="source"?a.source===e&&(n?a.sourceHandle===n:!0):a.target===e&&(n?a.targetHandle===n:!0)),[r.edges,e,t,n])}function Go({onChange:e,onStart:t,onEnd:n}){const r=Ce(),a=c.useRef(e),o=c.useRef(t),i=c.useRef(n);c.useEffect(()=>{a.current=e},[e]),c.useEffect(()=>{o.current=t},[t]),c.useEffect(()=>{i.current=n},[n]),c.useEffect(()=>{const f=p=>{var d;(d=a.current)==null||d.call(a,{x:p.x,y:p.y,zoom:p.zoom})};return r.viewportListeners.add(f),()=>r.viewportListeners.delete(f)},[s])}function Qo({onChange:e}){const t=Ce(),n=c.useRef(e);c.useEffect(()=>{n.current=e},[e]),c.useEffect(()=>{const r=a=>{var o;(o=n.current)==null||o.call(n,a)};return t.selectionListeners.add(r),()=>t.selectionListeners.delete(r)},[s])}function Vo(e){const[t,n]=c.useState(!1),r=Array.isArray(e)?e:[e];return c.useEffect(()=>{const a=i=>{r.includes(i.key)&&n(!0)},o=i=>{r.includes(i.key)&&n(!1)};return window.addEventListener("keydown",a),window.addEventListener("keyup",o),()=>{window.removeEventListener("keydown",a),window.removeEventListener("keyup",o)}},[r.join(",")]),t}function Jo(){const e=Ce();return c.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 Ce(Ko)}function ts(e){const t=Ce();return c.useMemo(()=>t.nodes.find(n=>n.id===e)||void 0,[t.nodes,e])}function ns(e,t){return Ce(e,t)}function rs(){return wr()}function os({maxHistorySize:e=100}={}){const t=Ce(),n=c.useRef([]),r=c.useRef([]),[,a]=c.useState(0),o=c.useRef(null),i=c.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,a(h=>h+1))},[t,e]),f=c.useCallback(()=>{var h,v,E,M;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}))}),(v=(h=s().onNodesChangeRef).current)==null||v.call(h,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...d.nodes.map(z=>({type:"add",item:z}))]),(M=(E=s().onEdgesChangeRef).current)==null||M.call(E,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...d.edges.map(z=>({type:"add",item:z}))]),o.current=d,a(z=>z+1))},[s]),p=c.useCallback(()=>{var h,v,E,M;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}))}),(v=(h=s().onNodesChangeRef).current)==null||v.call(h,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...d.nodes.map(z=>({type:"add",item:z}))]),(M=(E=s().onEdgesChangeRef).current)==null||M.call(E,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...d.edges.map(z=>({type:"add",item:z}))]),o.current=d,a(z=>z+1))},[s]);return{undo:f,redo:p,takeSnapshot:i,canUndo:n.current.length>0,canRedo:r.current.length>0}}function ss(e){const t=c.useRef(e);return c.useEffect(()=>{t.current=e},[e]),c.useCallback(n=>r=>{const a=t.current(r);a!==!1&&a!=null&&n(Array.isArray(a)?a:r)},[])}function as(e){const t=c.useRef(e);return c.useEffect(()=>{t.current=e},[e]),c.useCallback(n=>r=>{const a=t.current(r);a!==!1&&a!=null&&n(Array.isArray(a)?a:r)},[])}const Xn=160,Yn=60;function is({width:e=200,height:t=150,nodeColor:n="#3b82f6",nodeStrokeColor:r="#fff",maskColor:a="rgba(0,0,0,0.1)",style:o={},className:i=""}){const f=Ce(),p=c.useRef(null),d=c.useRef(null),h=c.useCallback(()=>{const v=p.current;if(!v)return;const E=v.getContext("2d"),M=window.devicePixelRatio||1;v.width=e*M,v.height=t*M,E.scale(M,M),E.clearRect(0,0,e,t);const z=f.nodesRef.current;if(!z.length)return;let I=1/0,k=1/0,j=-1/0,X=-1/0;for(const g of z){const x=g.width||Xn,N=g.height||Yn;g.position.x<I&&(I=g.position.x),g.position.y<k&&(k=g.position.y),g.position.x+x>j&&(j=g.position.x+x),g.position.y+N>X&&(X=g.position.y+N)}const D=40;I-=D,k-=D,j+=D,X+=D;const _=j-I,A=X-k,L=Math.min(e/_,t/A),Y=(e-_*L)/2,F=(t-A*L)/2;for(const g of z){if(g.hidden)continue;const x=g.width||Xn,N=g.height||Yn,$=(g.position.x-I)*L+Y,W=(g.position.y-k)*L+F,Q=x*L,re=N*L;E.fillStyle=g.selected?"#f59e0b":typeof n=="function"?n(g):n,E.fillRect($,W,Math.max(Q,2),Math.max(re,2))}const B=f.cameraRef.current,b=f.wrapRef.current;if(b){const g=b.getBoundingClientRect(),x=-B.x/B.zoom,N=-B.y/B.zoom,$=g.width/B.zoom,W=g.height/B.zoom;E.fillStyle=a,E.fillRect(0,0,e,t);const Q=(x-I)*L+Y,re=(N-k)*L+F,ee=$*L,oe=W*L;E.clearRect(Q,re,ee,oe);for(const ge of z){if(ge.hidden)continue;const ye=ge.width||Xn,J=ge.height||Yn,fe=(ge.position.x-I)*L+Y,me=(ge.position.y-k)*L+F;E.fillStyle=ge.selected?"#f59e0b":typeof n=="function"?n(ge):n,E.fillRect(fe,me,Math.max(ye*L,2),Math.max(J*L,2))}E.strokeStyle="#3b82f6",E.lineWidth=1.5,E.strokeRect(Q,re,ee,oe)}},[f,e,t,n,r,a]);return c.useEffect(()=>{let v=!0;function E(){v&&(h(),d.current=requestAnimationFrame(E))}const M=setInterval(()=>{cancelAnimationFrame(d.current),d.current=requestAnimationFrame(E)},66);return h(),()=>{v=!1,clearInterval(M),cancelAnimationFrame(d.current)}},[h]),P.jsx("canvas",{ref:p,className:`ric-minimap ${i}`,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 P.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:[P.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),P.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function us(){return P.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:P.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function ls(){return P.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:P.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}function ds(){return P.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:[P.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),P.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function fs(){return P.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:[P.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),P.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})}function nn({children:e,className:t="",...n}){return P.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:a,onZoomOut:o,onFitView:i,onInteractiveChange:f,position:p="bottom-left",orientation:d="vertical",style:h={},className:v="","aria-label":E="Canvas controls",children:M}){const z=Ce(),{zoomIn:I,zoomOut:k,fitView:j,getZoom:X}=Ar(),[D,_]=c.useState(!0),A=X()<=z.zoomMin,L=X()>=z.zoomMax,Y=c.useCallback(()=>{I(),a==null||a()},[I,a]),F=c.useCallback(()=>{k(),o==null||o()},[k,o]),B=c.useCallback(()=>{j(r||{padding:.1}),i==null||i()},[j,r,i]),b=c.useCallback(()=>{const x=!D;_(x),f==null||f(x)},[D,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%)"}}[p]||{bottom:30,left:10};return P.jsxs("div",{className:`ric-controls ${v}`,style:{position:"absolute",display:"flex",flexDirection:d==="horizontal"?"row":"column",gap:2,zIndex:5,...g,...h},role:"toolbar","aria-label":E,children:[e&&P.jsxs(P.Fragment,{children:[P.jsx(nn,{onClick:Y,disabled:L,title:"Zoom in","aria-label":"Zoom in",className:"ric-controls-zoomin",children:P.jsx(cs,{})}),P.jsx(nn,{onClick:F,disabled:A,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:P.jsx(us,{})})]}),t&&P.jsx(nn,{onClick:B,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:P.jsx(ls,{})}),n&&P.jsx(nn,{onClick:b,title:D?"Lock interactivity":"Unlock interactivity","aria-label":D?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:D?P.jsx(fs,{}):P.jsx(ds,{})}),M]})}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=c.memo(hs);function xs({variant:e="lines",gap:t=40,size:n=1,color:r,style:a={},className:o=""}){const i=Ce();return i.workerRef.current&&i.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 a={"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 P.jsx("div",{className:`ric-panel ${n}`,style:{position:"absolute",zIndex:5,pointerEvents:"all",...a,...t},onPointerDown:o=>o.stopPropagation(),children:r})}function ms({minWidth:e=10,minHeight:t=10,maxWidth:n=1/0,maxHeight:r=1/0,isVisible:a=!0,handleStyle:o={},lineStyle:i={},color:f="#3b82f6",onResizeStart:p,onResize:d,onResizeEnd:h}){const v=c.useContext(on),E=Ce(),M=c.useRef(null),z=c.useCallback((j,X)=>{j.stopPropagation(),j.preventDefault();const D=E.nodesRef.current.find(L=>L.id===v);if(!D)return;M.current={direction:X,startX:j.clientX,startY:j.clientY,width:D.width||160,height:D.height||60},p==null||p(j,{width:M.current.width,height:M.current.height});const _=L=>{var N,$;if(!M.current)return;const Y=M.current,F=E.cameraRef.current,B=(L.clientX-Y.startX)/F.zoom,b=(L.clientY-Y.startY)/F.zoom;let g=Y.width,x=Y.height;Y.direction.includes("e")&&(g=Math.min(n,Math.max(e,Y.width+B))),Y.direction.includes("w")&&(g=Math.min(n,Math.max(e,Y.width-B))),Y.direction.includes("s")&&(x=Math.min(r,Math.max(t,Y.height+b))),Y.direction.includes("n")&&(x=Math.min(r,Math.max(t,Y.height-b))),($=(N=E.onNodesChangeRef).current)==null||$.call(N,[{id:v,type:"dimensions",dimensions:{width:g,height:x},setAttributes:!0}]),d==null||d(L,{width:g,height:x})},A=L=>{M.current=null,h==null||h(L,{}),window.removeEventListener("pointermove",_),window.removeEventListener("pointerup",A)};window.addEventListener("pointermove",_),window.addEventListener("pointerup",A)},[v,E,e,t,n,r,p,d,h]);if(!a)return null;const I=8,k={position:"absolute",width:I,height:I,background:f,border:"1px solid #fff",borderRadius:2,zIndex:20,...o};return P.jsxs(P.Fragment,{children:[P.jsx("div",{style:{...k,bottom:-I/2,right:-I/2,cursor:"nwse-resize"},onPointerDown:j=>z(j,"se")}),P.jsx("div",{style:{...k,bottom:-I/2,left:-I/2,cursor:"nesw-resize"},onPointerDown:j=>z(j,"sw")}),P.jsx("div",{style:{...k,top:-I/2,right:-I/2,cursor:"nesw-resize"},onPointerDown:j=>z(j,"ne")}),P.jsx("div",{style:{...k,top:-I/2,left:-I/2,cursor:"nwse-resize"},onPointerDown:j=>z(j,"nw")}),P.jsx("div",{style:{...k,top:"50%",right:-I/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:j=>z(j,"e")}),P.jsx("div",{style:{...k,top:"50%",left:-I/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:j=>z(j,"w")}),P.jsx("div",{style:{...k,left:"50%",top:-I/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:j=>z(j,"n")}),P.jsx("div",{style:{...k,left:"50%",bottom:-I/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:j=>z(j,"s")})]})}function vs({isVisible:e,position:t="top",offset:n=10,align:r="center",children:a,style:o={},className:i=""}){const f=c.useContext(on),d=Ce().nodes.find(E=>E.id===f);if(!(e!==void 0?e:d==null?void 0:d.selected))return null;const v={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 P.jsx("div",{className:`ric-node-toolbar ${i}`,style:{position:"absolute",zIndex:1e3,pointerEvents:"all",...v,...o},onPointerDown:E=>E.stopPropagation(),children:a})}function bs({isVisible:e=!1,x:t=0,y:n=0,alignX:r="center",alignY:a="center",children:o,style:i={},className:f=""}){if(!e)return null;const p=r==="center"?"-50%":r==="right"?"-100%":"0",d=a==="center"?"-50%":a==="bottom"?"-100%":"0";return P.jsx("div",{className:`ric-edge-toolbar ${f}`,style:{position:"absolute",left:t,top:n,transform:`translate(${p}, ${d})`,zIndex:1e3,pointerEvents:"all",...i},children:o})}function ws({children:e}){var r;const n=(r=Ce().edgeLabelContainerRef)==null?void 0:r.current;return n?yr.createPortal(e,n):null}function Ms({children:e}){var r;const n=(r=Ce().viewportPortalRef)==null?void 0:r.current;return n?yr.createPortal(e,n):null}function Dr({fromX:e,fromY:t,toX:n,toY:r,fromPosition:a="right",toPosition:o="left",connectionLineType:i="default",connectionLineStyle:f,connectionLineComponent:p}){if(p)return P.jsx(p,{fromX:e,fromY:t,toX:n,toY:r,fromPosition:a,toPosition:o});let d;switch(i){case"straight":[d]=Jn({sourceX:e,sourceY:t,targetX:n,targetY:r});break;case"step":[d]=vn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o,borderRadius:0});break;case"smoothstep":[d]=vn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o});break;case"simplebezier":[d]=er({sourceX:e,sourceY:t,targetX:n,targetY:r});break;default:[d]=Kn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o});break}return P.jsx("path",{d,fill:"none",className:"ric-connection-line",stroke:"#b1b1b7",strokeWidth:1.5,style:f})}Dr.displayName="ConnectionLine";const Rs=c.memo(Dr),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=Vn;exports.ConnectionLine=Rs;exports.ControlButton=nn;exports.Controls=ys;exports.DefaultNode=vo;exports.EdgeLabelRenderer=ws;exports.EdgeText=Ir;exports.EdgeToolbar=bs;exports.GroupNode=Nr;exports.Handle=rn;exports.InfiniteCanvas=jo;exports.InfiniteCanvasProvider=Ao;exports.InputNode=zr;exports.MarkerType=Cs;exports.MiniMap=is;exports.NodeResizer=ms;exports.NodeToolbar=vs;exports.OutputNode=Sr;exports.Panel=ps;exports.Position=ks;exports.SelectionBox=Cr;exports.SimpleBezierEdge=or;exports.SmoothStepEdge=rr;exports.StepEdge=Tr;exports.StraightEdge=nr;exports.ViewportPortal=Ms;exports.addEdge=Ho;exports.applyEdgeChanges=jr;exports.applyNodeChanges=Br;exports.boxToRect=Qr;exports.buildObstacles=tr;exports.clampPosition=Un;exports.computeRoutedEdges=No;exports.getBezierEdgeCenter=bo;exports.getBezierPath=Kn;exports.getBoundsOfBoxes=Vr;exports.getConnectedEdges=mr;exports.getEdgeCenter=wo;exports.getIncomers=Ur;exports.getNodeDimensions=Qn;exports.getNodesBounds=mn;exports.getNodesInside=Zr;exports.getOutgoers=Or;exports.getOverlappingArea=Jr;exports.getRoutedLabelPosition=Cn;exports.getSimpleBezierPath=er;exports.getSmoothStepPath=vn;exports.getStraightPath=Jn;exports.getViewportForBounds=jt;exports.isEdge=qr;exports.isNode=Yr;exports.nodeToBox=Es;exports.nodeToRect=Kr;exports.reconnectEdge=Mo;exports.rectToBox=Gr;exports.routeSinglePath=Po;exports.routedPointsToPath=kn;exports.snapPosition=qn;exports.useConnection=qo;exports.useEdges=Xo;exports.useEdgesState=Wo;exports.useHandleConnections=Zo;exports.useInfiniteCanvas=br;exports.useInternalNode=ts;exports.useKeyPress=Vo;exports.useNodeConnections=Oo;exports.useNodeId=co;exports.useNodes=Fo;exports.useNodesData=Uo;exports.useNodesInitialized=es;exports.useNodesState=_o;exports.useOnEdgesChangeMiddleware=as;exports.useOnNodesChangeMiddleware=ss;exports.useOnSelectionChange=Qo;exports.useOnViewportChange=Go;exports.useReactFlow=Ar;exports.useStore=ns;exports.useStoreApi=rs;exports.useUndoRedo=os;exports.useUpdateNodeInternals=Jo;exports.useViewport=Yo;
|
|
867
|
+
`,ir=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",vr],{type:"text/javascript;charset=utf-8"});function eo(e){let t;try{if(t=ir&&(self.URL||self.webkitURL).createObjectURL(ir),!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(vr),{type:"module",name:e==null?void 0:e.name})}}const Wn=new WeakMap;function to(e,t){if(Wn.has(e))return Wn.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 a={worker:r};return Wn.set(e,a),a}const it=160,rt=60,no=10;function br({cards:e=[],nodes:t=[],edges:n=[],onHudUpdate:r,onNodesProcessed:a,onNodesChange:o,onEdgesChange:i,onConnect:f,onNodeClick:p,onNodeDragStart:d,onNodeDrag:h,onNodeDragStop:v,onEdgeClick:E,onEdgeDoubleClick:M,onEdgeMouseEnter:z,onEdgeMouseMove:I,onEdgeMouseLeave:k,onEdgeContextMenu:j,onNodeDoubleClick:X,onNodeMouseEnter:D,onNodeMouseMove:_,onNodeMouseLeave:A,onNodeContextMenu:L,onPaneClick:Y,onPaneContextMenu:F,onPaneMouseEnter:B,onPaneMouseMove:b,onPaneMouseLeave:g,onSelectionChange:x,onConnectStart:N,onConnectEnd:$,onInit:W,onMoveStart:V,onMove:re,onMoveEnd:ee,onDelete:oe,onBeforeDelete:ge,onError:ye,isValidConnection:J,dark:fe,gridSize:me=40,zoomMin:ae=.1,zoomMax:ue=4,initialCamera:Ne={x:0,y:0,zoom:1},fitView:Je=!1,fitViewOptions:le,nodesDraggable:Be=!0,nodesConnectable:je=!0,elementsSelectable:_e=!0,multiSelectionKeyCode:he="Shift",selectionOnDrag:Me=!1,selectionMode:Oe="partial",connectionMode:Ae="loose",connectionRadius:ct=20,connectOnClick:zt=!1,snapToGrid:De=!1,snapGrid:Xe=[15,15],deleteKeyCode:Ze=["Delete","Backspace"],panActivationKeyCode:St=" ",panOnScroll:an=!1,panOnScrollMode:At="free",panOnScrollSpeed:cn=.5,zoomOnScroll:un=!0,zoomOnDoubleClick:ln=!0,zoomOnPinch:dn=!0,preventScrolling:Dt=!0,translateExtent:dt,nodeExtent:ft,defaultEdgeOptions:Nt={},autoPanOnNodeDrag:En=!0,autoPanOnConnect:zn=!0,autoPanSpeed:ot=5,edgesReconnectable:sr=!1,elevateNodesOnSelect:Sn=!1,elevateEdgesOnSelect:Nn=!1,noDragClassName:Pt="nodrag",noPanClassName:It="nopan",onSelectionDragStart:Pn,onSelectionDrag:In,onSelectionDragStop:Ln,edgeRouting:ht=!0}={}){const pe=c.useRef(null),Ht=c.useRef(null),Ee=c.useRef(null),ie=c.useRef({...Ne}),gt=c.useRef([...e]),K=c.useRef([...t]),Re=c.useRef([...n]),fn=c.useRef(new Map),ut=c.useRef(!1),Lt=c.useRef(null),[Tn,$n]=c.useState(!1),We=c.useRef(null),Ye=c.useRef(null),_t=c.useRef(null),He=c.useRef(null),Wt=c.useRef(!1),Mt=c.useRef(null),[Ft,Bn]=c.useState({x:Ne.x,y:Ne.y,zoom:Ne.zoom}),[yt,xt]=c.useState(null),tt=c.useMemo(()=>new Set,[]),Ke=c.useMemo(()=>new Set,[]),Tt=c.useRef(!1),O=c.useRef({});O.current={onHudUpdate:r,onNodesProcessed:a,onNodesChange:o,onEdgesChange:i,onConnect:f,onNodeClick:p,onNodeDragStart:d,onNodeDrag:h,onNodeDragStop:v,onEdgeClick:E,onEdgeDoubleClick:M,onEdgeMouseEnter:z,onEdgeMouseMove:I,onEdgeMouseLeave:k,onEdgeContextMenu:j,onNodeDoubleClick:X,onNodeMouseEnter:D,onNodeMouseMove:_,onNodeMouseLeave:A,onNodeContextMenu:L,onPaneClick:Y,onPaneContextMenu:F,onPaneMouseEnter:B,onPaneMouseMove:b,onPaneMouseLeave:g,onSelectionChange:x,onConnectStart:N,onConnectEnd:$,onInit:W,onMoveStart:V,onMove:re,onMoveEnd:ee,onDelete:oe,onBeforeDelete:ge,onError:ye,onSelectionDragStart:Pn,onSelectionDrag:In,onSelectionDragStop:Ln,isValidConnection:J};const pt={get current(){return O.current.onConnect}},$t={get current(){return O.current.onNodeClick}},Xt={get current(){return O.current.onNodeDragStart}},Yt={get current(){return O.current.onNodeDrag}},qt={get current(){return O.current.onNodeDragStop}},Ut={get current(){return O.current.onEdgeClick}},Ot={get current(){return O.current.onPaneClick}},we={get current(){return O.current.onSelectionChange}},mt={get current(){return O.current.onHudUpdate}},Bt={get current(){return O.current.onNodesProcessed}};c.useEffect(()=>{const l=u=>{u.key===he&&(Wt.current=!0),u.key===St&&(Tt.current=!0)},w=u=>{u.key===he&&(Wt.current=!1),u.key===St&&(Tt.current=!1)};return window.addEventListener("keydown",l),window.addEventListener("keyup",w),()=>{window.removeEventListener("keydown",l),window.removeEventListener("keyup",w)}},[he,St]);const ze={get current(){return O.current.onNodesChange?Zt:null}},Zt=l=>{var u,y,R;(y=(u=O.current).onNodesChange)==null||y.call(u,l);const w=[];for(let S=0;S<l.length;S++)l[S].type==="select"&&w.push({id:l[S].id,selected:l[S].selected});w.length>0&&((R=Ee.current)==null||R.postMessage({type:"nodeSelections",data:{selections:w}}))},Pe={get current(){return O.current.onEdgesChange?Gt:null}},Gt=l=>{var u,y,R;(y=(u=O.current).onEdgesChange)==null||y.call(u,l);const w=[];for(let S=0;S<l.length;S++)l[S].type==="select"&&w.push({id:l[S].id,selected:l[S].selected});w.length>0&&((R=Ee.current)==null||R.postMessage({type:"edgeSelections",data:{selections:w}}))},st=c.useCallback(()=>{var y;const l=K.current.filter(R=>R.selected),w=Re.current.filter(R=>R.selected),u={nodes:l,edges:w};(y=we.current)==null||y.call(we,u);for(const R of Ke)R(u)},[Ke]);c.useEffect(()=>{var l;gt.current=[...e],(l=Ee.current)==null||l.postMessage({type:"cards",data:{cards:[...e]}})},[e]);const Rt=c.useCallback(l=>{const w={};for(const u of l)w[u.id]=u;return l.map(u=>{if(!u.parentId)return u;const y=w[u.parentId];if(!y)return u;let R=u.position.x,S=u.position.y,m=y;for(;m;)R+=m.position.x,S+=m.position.y,m=m.parentId?w[m.parentId]:null;return{...u,_absolutePosition:{x:R,y:S}}})},[]),et=c.useRef([]),vt=c.useCallback(l=>{const w=fn.current;if(!w||w.size===0)return l;const u={};for(const[,y]of w)u[y.nodeId]||(u[y.nodeId]=[]),u[y.nodeId].push({id:y.id,type:y.type,position:y.position,x:y.x,y:y.y});return l.map(y=>{const R=u[y.id];return R&&R.length>0?{...y,handles:R}:y})},[]),hn=c.useCallback(()=>{var w;if(We.current)return;const l=vt(et.current);(w=Ee.current)==null||w.postMessage({type:"nodes",data:{nodes:l}})},[vt]);c.useEffect(()=>{var u,y;if(We.current){const R=We.current.id,S=new Set([R,...We.current.selectedStarts.map(C=>C.id)]),m={};for(const C of K.current)S.has(C.id)&&(m[C.id]={...C.position});K.current=[...t];for(const C of K.current)m[C.id]&&(C.position=m[C.id]);et.current=Rt(K.current);const T=vt(et.current);(u=Ee.current)==null||u.postMessage({type:"nodes",data:{nodes:T}});return}K.current=[...t];const l=Rt(t);et.current=l;const w=vt(l);(y=Ee.current)==null||y.postMessage({type:"nodes",data:{nodes:w}})},[t,Rt,vt]),c.useEffect(()=>{var l;Re.current=[...n],(l=Ee.current)==null||l.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const Se=c.useCallback((l,w)=>{const u=pe.current;if(!u)return{x:0,y:0};const y=u.getBoundingClientRect(),R=ie.current;return{x:(l-y.left-R.x)/R.zoom,y:(w-y.top-R.y)/R.zoom}},[]),nt=c.useCallback((l,w)=>{const u=et.current.length>0?et.current:K.current;let y=null;for(let R=u.length-1;R>=0;R--){const S=u[R];if(S.hidden)continue;const m=S._absolutePosition||S.position,T=S.width||it,C=S.height||rt;if(l>=m.x&&l<=m.x+T&&w>=m.y&&w<=m.y+C){if(S.type==="group"){y||(y=S);continue}return S}}return y},[]),G=c.useCallback((l,w)=>{const u=w.width||it,y=w.height||rt;if(l.x!==void 0&&l.y!==void 0)return{x:w.position.x+l.x,y:w.position.y+l.y};switch(l.position||(l.type==="source"?"right":"left")){case"top":return{x:w.position.x+u/2,y:w.position.y};case"bottom":return{x:w.position.x+u/2,y:w.position.y+y};case"left":return{x:w.position.x,y:w.position.y+y/2};case"right":return{x:w.position.x+u,y:w.position.y+y/2};default:return{x:w.position.x+u,y:w.position.y+y/2}}},[]),Ie=c.useCallback(l=>{const w=l.width||it,u=l.height||rt;if(l.handles&&l.handles.length>0)return l.handles.map(C=>{const U=G(C,l);return{id:C.id||null,type:C.type,x:U.x,y:U.y}});const y=l.targetPosition||"left",R=l.sourcePosition||"right",S=C=>{switch(C){case"top":return{x:l.position.x+w/2,y:l.position.y};case"bottom":return{x:l.position.x+w/2,y:l.position.y+u};case"left":return{x:l.position.x,y:l.position.y+u/2};case"right":return{x:l.position.x+w,y:l.position.y+u/2};default:return{x:l.position.x+w,y:l.position.y+u/2}}},m=S(y),T=S(R);return[{id:null,type:"target",x:m.x,y:m.y},{id:null,type:"source",x:T.x,y:T.y}]},[G]),ve=c.useCallback((l,w)=>{const u=K.current,y=ie.current,R=Math.max(no,ct)/y.zoom;for(let S=u.length-1;S>=0;S--){const m=u[S];if(m.hidden)continue;const T=Ie(m);for(const C of T)if(Math.abs(l-C.x)<R&&Math.abs(w-C.y)<R)return{nodeId:m.id,handleId:C.id,type:C.type,x:C.x,y:C.y}}return null},[Ie]),Le=c.useCallback((l,w)=>{const y=8/ie.current.zoom;for(let R=Re.current.length-1;R>=0;R--){const S=Re.current[R],m=K.current.find(se=>se.id===S.source),T=K.current.find(se=>se.id===S.target);if(!m||!T)continue;const C=m.width||it,U=m.height||rt,H=T.height||rt,Z=m.position.x+C,Q=m.position.y+U/2,be=T.position.x,Te=T.position.y+H/2;if(ro(l,w,Z,Q,be,Te)<y)return S}return null},[]);c.useEffect(()=>{const l=Ht.current,w=pe.current;if(!l||!w)return;const u=w.getBoundingClientRect(),y=fe!==void 0?fe:matchMedia("(prefers-color-scheme: dark)").matches,R=Rt(K.current);et.current=R;const S=vt(R),{worker:m}=to(l,{width:u.width,height:u.height,camera:ie.current,cards:gt.current,nodes:S,edges:Re.current,dark:y,gridSize:me,edgeRouting:ht});m.onmessage=H=>{var Z,Q,be,Te;H.data.type==="hud"&&((Z=mt.current)==null||Z.call(mt,H.data.data)),H.data.type==="ready"&&$n(!0),H.data.type==="nodesProcessed"&&((Q=Bt.current)==null||Q.call(Bt,H.data.data)),H.data.type==="error"&&((Te=(be=O.current).onError)==null||Te.call(be,"worker-error",H.data.message||"Canvas worker error"))},m.onerror=H=>{var Z,Q;(Q=(Z=O.current).onError)==null||Q.call(Z,"worker-error",H.message||"Canvas worker crashed")},Ee.current=m;const T=new ResizeObserver(H=>{const{width:Z,height:Q}=H[0].contentRect;m.postMessage({type:"resize",data:{width:Z,height:Q}})});T.observe(w);let C,U;return fe===void 0&&(C=matchMedia("(prefers-color-scheme: dark)"),U=H=>m.postMessage({type:"theme",data:{dark:H.matches}}),C.addEventListener("change",U)),()=>{T.disconnect(),C&&U&&C.removeEventListener("change",U),Ee.current=null}},[]),c.useEffect(()=>{var l;fe!==void 0&&((l=Ee.current)==null||l.postMessage({type:"theme",data:{dark:fe}}))},[fe]),c.useEffect(()=>{var l;(l=Ee.current)==null||l.postMessage({type:"edgeRouting",data:{enabled:ht}})},[ht]);const at=c.useRef(0),ce=c.useCallback((l=null)=>{var y,R,S;const w=ie.current;if(dt){const m=pe.current;if(m){const T=m.getBoundingClientRect(),C=-dt[1][0]*w.zoom+T.width,U=-dt[1][1]*w.zoom+T.height,H=-dt[0][0]*w.zoom,Z=-dt[0][1]*w.zoom;w.x=Math.min(H,Math.max(C,w.x)),w.y=Math.min(Z,Math.max(U,w.y))}}(y=Ee.current)==null||y.postMessage({type:"camera",data:{camera:{...w}}});const u={x:w.x,y:w.y,zoom:w.zoom};(S=(R=O.current).onMove)==null||S.call(R,l,u);for(const m of tt)m(u);cancelAnimationFrame(at.current),at.current=requestAnimationFrame(()=>{Bn({x:w.x,y:w.y,zoom:w.zoom})})},[tt,dt]),Ge=c.useCallback(()=>{var u,y;const l=Ye.current,w=_t.current;l&&w?((u=Ee.current)==null||u.postMessage({type:"connecting",data:{from:l.startPos,to:w,_routedPoints:null}}),xt({source:l.sourceId,sourceHandle:l.sourceHandle,target:null,targetHandle:null})):((y=Ee.current)==null||y.postMessage({type:"connecting",data:null}),xt(null))},[]),bt=c.useCallback(()=>{var w,u;const l=He.current;l?(w=Ee.current)==null||w.postMessage({type:"selectionBox",data:l}):(u=Ee.current)==null||u.postMessage({type:"selectionBox",data:null})},[]),jn=c.useCallback(l=>{var m,T,C,U,H,Z,Q,be,Te,te,se,ke,$e,Fe,Qe,Ue,Vt,lt;const w=K.current.length>0,u=Se(l.clientX,l.clientY),y=Wt.current;if(w&&je&&!y){const q=ve(u.x,u.y);if(zt&&Mt.current&&q){const ne=Mt.current;if(q.nodeId!==ne.nodeId){const Ve=ne.handleType==="target"?{source:q.nodeId,target:ne.nodeId,sourceHandle:q.handleId||null,targetHandle:ne.handleId}:{source:ne.nodeId,target:q.nodeId,sourceHandle:ne.handleId,targetHandle:q.handleId||null};(O.current.isValidConnection?O.current.isValidConnection(Ve):!0)&&((m=pt.current)==null||m.call(pt,{...Ve,...Nt}))}Mt.current=null;return}if(Ae==="strict"?q&&q.type==="source":q!=null){if(zt){Mt.current={nodeId:q.nodeId,handleId:q.handleId||null,handleType:q.type},(C=(T=O.current).onConnectStart)==null||C.call(T,l,{nodeId:q.nodeId,handleId:q.handleId,handleType:q.type});return}Ye.current={sourceId:q.nodeId,sourceHandle:q.handleId||null,sourceType:q.type,startPos:{x:q.x,y:q.y}},_t.current={x:u.x,y:u.y},(U=pe.current)==null||U.setPointerCapture(l.pointerId),(Z=(H=O.current).onConnectStart)==null||Z.call(H,l,{nodeId:q.nodeId,handleId:q.handleId,handleType:q.type}),Ge();return}}const R=q=>{var ne;let xe=q;for(;xe&&xe!==pe.current;){if((ne=xe.classList)!=null&&ne.contains(Pt))return!0;xe=xe.parentElement}return!1},S=q=>{var ne;let xe=q;for(;xe&&xe!==pe.current;){if((ne=xe.classList)!=null&&ne.contains(It))return!0;xe=xe.parentElement}return!1};if(w){const q=nt(u.x,u.y);if(q){if(ze.current&&_e){const xe=[];if(y)xe.push({id:q.id,type:"select",selected:!q.selected});else if(!q.selected){for(const ne of K.current)ne.id===q.id?xe.push({id:ne.id,type:"select",selected:!0}):ne.selected&&xe.push({id:ne.id,type:"select",selected:!1});if(Pe.current){const ne=Re.current.filter(de=>de.selected).map(de=>({id:de.id,type:"select",selected:!1}));ne.length&&Pe.current(ne)}}if(xe.length){if(ze.current(xe),Sn&&!y){const ne=K.current.findIndex(de=>de.id===q.id);ne>=0&&ne<K.current.length-1&&ze.current([{id:q.id,type:"remove"},{type:"add",item:{...K.current[ne],selected:!0}}])}st()}}if((Q=$t.current)==null||Q.call($t,l,q),Be&&!R(l.target)){const xe=q.selected;let ne=null;if(q.parentId&&q.extent==="parent"){const de=K.current.find(Ve=>Ve.id===q.parentId);if(de){const Ve=de.width||it,Jt=de.height||rt,yn=q.width||((be=q.measured)==null?void 0:be.width)||it,Kt=q.height||((Te=q.measured)==null?void 0:Te.height)||rt;ne={minX:0,minY:0,maxX:Ve-yn,maxY:Jt-Kt}}}if(We.current={id:q.id,startPos:{...q.position},startMouse:{x:u.x,y:u.y},parentClamp:ne,parentId:q.parentId||null,selectedStarts:xe?K.current.filter(de=>de.selected&&de.id!==q.id).map(de=>{var Jt,yn;let Ve=null;if(de.parentId&&de.extent==="parent"){const Kt=K.current.find(_n=>_n.id===de.parentId);if(Kt){const _n=Kt.width||it,Wr=Kt.height||rt,Fr=de.width||((Jt=de.measured)==null?void 0:Jt.width)||it,Xr=de.height||((yn=de.measured)==null?void 0:yn.height)||rt;Ve={minX:0,minY:0,maxX:_n-Fr,maxY:Wr-Xr}}}return{id:de.id,startPos:{...de.position},parentClamp:Ve,parentId:de.parentId||null}}):[]},(te=pe.current)==null||te.setPointerCapture(l.pointerId),(se=Xt.current)==null||se.call(Xt,l,q),We.current.selectedStarts.length>0){const de=K.current.filter(Ve=>Ve.selected);($e=(ke=O.current).onSelectionDragStart)==null||$e.call(ke,l,de)}if(ze.current){const de=[{id:q.id,type:"position",dragging:!0}];for(const Ve of We.current.selectedStarts)de.push({id:Ve.id,type:"position",dragging:!0});ze.current(de)}}return}}if(Re.current.length>0&&_e){const q=Le(u.x,u.y);if(q){if(Pe.current){const xe=[];if(y)xe.push({id:q.id,type:"select",selected:!q.selected});else{for(const ne of Re.current)ne.id===q.id?xe.push({id:ne.id,type:"select",selected:!0}):ne.selected&&xe.push({id:ne.id,type:"select",selected:!1});if(ze.current){const ne=K.current.filter(de=>de.selected).map(de=>({id:de.id,type:"select",selected:!1}));ne.length&&ze.current(ne)}}if(xe.length){if(Pe.current(xe),Nn&&!y){const ne=Re.current.findIndex(de=>de.id===q.id);ne>=0&&ne<Re.current.length-1&&Pe.current([{id:q.id,type:"remove"},{type:"add",item:{...Re.current[ne],selected:!0}}])}st()}}(Fe=Ut.current)==null||Fe.call(Ut,l,q);return}}if(!y){const q=K.current.filter(ne=>ne.selected).map(ne=>({id:ne.id,type:"select",selected:!1})),xe=Re.current.filter(ne=>ne.selected).map(ne=>({id:ne.id,type:"select",selected:!1}));q.length&&ze.current&&ze.current(q),xe.length&&Pe.current&&Pe.current(xe),(q.length||xe.length)&&st()}if((Qe=Ot.current)==null||Qe.call(Ot,l),Me||y){He.current={startWorld:{...u},endWorld:{...u}},(Ue=pe.current)==null||Ue.setPointerCapture(l.pointerId),bt();return}S(l.target)||(ut.current=!0,Lt.current={x:l.clientX,y:l.clientY},(Vt=pe.current)==null||Vt.classList.add("dragging"),(lt=pe.current)==null||lt.setPointerCapture(l.pointerId))},[Se,nt,ve,Le,Be,je,_e,Me,Ge,bt,st,Pt,It]),An=c.useCallback(l=>{var u,y,R,S;if(Ye.current){if(_t.current=Se(l.clientX,l.clientY),Ge(),zn){const m=pe.current;if(m){const T=m.getBoundingClientRect(),C=40,U=l.clientX-T.left,H=l.clientY-T.top;let Z=0,Q=0;U<C?Z=ot:U>T.width-C&&(Z=-ot),H<C?Q=ot:H>T.height-C&&(Q=-ot),(Z||Q)&&(ie.current.x+=Z,ie.current.y+=Q,ce(l))}}return}if(He.current){He.current.endWorld=Se(l.clientX,l.clientY),bt();const m=He.current,T=Math.min(m.startWorld.x,m.endWorld.x),C=Math.min(m.startWorld.y,m.endWorld.y),U=Math.max(m.startWorld.x,m.endWorld.x),H=Math.max(m.startWorld.y,m.endWorld.y);if(ze.current){const Z=[];for(const Q of K.current){if(Q.hidden)continue;const be=Q.width||it,Te=Q.height||rt,te=Oe==="full"?Q.position.x>=T&&Q.position.x+be<=U&&Q.position.y>=C&&Q.position.y+Te<=H:Q.position.x+be>T&&Q.position.x<U&&Q.position.y+Te>C&&Q.position.y<H;te!==!!Q.selected&&Z.push({id:Q.id,type:"select",selected:te})}Z.length&&ze.current(Z)}return}if(We.current){const m=Se(l.clientX,l.clientY),T=We.current,C=m.x-T.startMouse.x,U=m.y-T.startMouse.y;let H={x:T.startPos.x+C,y:T.startPos.y+U};if(De&&(H=qn(H,Xe)),ft&&(H=Un(H,ft)),T.parentClamp){const te=T.parentClamp;H={x:Math.max(te.minX,Math.min(H.x,te.maxX)),y:Math.max(te.minY,Math.min(H.y,te.maxY))}}const Z=[{id:T.id,position:H}];for(const te of T.selectedStarts){let se={x:te.startPos.x+C,y:te.startPos.y+U};if(De&&(se=qn(se,Xe)),ft&&(se=Un(se,ft)),te.parentClamp){const ke=te.parentClamp;se={x:Math.max(ke.minX,Math.min(se.x,ke.maxX)),y:Math.max(ke.minY,Math.min(se.y,ke.maxY))}}Z.push({id:te.id,position:se})}const Q=[];for(const te of Z){const se=K.current.find(ke=>ke.id===te.id);if(se){se.position=te.position,se.dragging=!0;let ke=te.position;if(se.parentId){let $e=K.current.find(Ue=>Ue.id===se.parentId),Fe=te.position.x,Qe=te.position.y;for(;$e;)Fe+=$e.position.x,Qe+=$e.position.y,$e=$e.parentId?K.current.find(Ue=>Ue.id===$e.parentId):null;ke={x:Fe,y:Qe}}Q.push({id:te.id,position:te.position,_absolutePosition:ke,width:se.width,height:se.height,dragging:!0,selected:se.selected})}}const be=new Set(Z.map(te=>te.id));for(const te of K.current)if(te.parentId&&be.has(te.parentId)&&!be.has(te.id)){let se=K.current.find(Fe=>Fe.id===te.parentId),ke=te.position.x,$e=te.position.y;for(;se;)ke+=se.position.x,$e+=se.position.y,se=se.parentId?K.current.find(Fe=>Fe.id===se.parentId):null;Q.push({id:te.id,position:te.position,_absolutePosition:{x:ke,y:$e},width:te.width,height:te.height,dragging:!1,selected:te.selected})}if((u=Ee.current)==null||u.postMessage({type:"nodePositions",data:{updates:Q}}),En){const te=pe.current;if(te){const se=te.getBoundingClientRect(),ke=40,$e=l.clientX-se.left,Fe=l.clientY-se.top;let Qe=0,Ue=0;$e<ke?Qe=ot:$e>se.width-ke&&(Qe=-ot),Fe<ke?Ue=ot:Fe>se.height-ke&&(Ue=-ot),(Qe||Ue)&&(ie.current.x+=Qe,ie.current.y+=Ue,ce(l))}}const Te=K.current.find(te=>te.id===T.id);if(Te&&((y=Yt.current)==null||y.call(Yt,l,Te)),T.selectedStarts.length>0){const te=K.current.filter(se=>se.selected);(S=(R=O.current).onSelectionDrag)==null||S.call(R,l,te)}return}if(!ut.current)return;const w=ie.current;w.x+=l.clientX-Lt.current.x,w.y+=l.clientY-Lt.current.y,Lt.current={x:l.clientX,y:l.clientY},ce()},[ce,Se,Ge,bt]),kt=c.useCallback(l=>{var w,u,y,R,S,m,T;if(Ye.current){const C=Se(l.clientX,l.clientY),U=ve(C.x,C.y);if(U&&U.nodeId!==Ye.current.sourceId&&(Ae==="loose"||U.type==="target")){const Q=Ye.current.sourceType==="target"?{source:U.nodeId,target:Ye.current.sourceId,sourceHandle:U.handleId||null,targetHandle:Ye.current.sourceHandle}:{source:Ye.current.sourceId,target:U.nodeId,sourceHandle:Ye.current.sourceHandle,targetHandle:U.handleId||null};(O.current.isValidConnection?O.current.isValidConnection(Q):!0)&&((w=pt.current)==null||w.call(pt,{...Q,...Nt}))}(y=(u=O.current).onConnectEnd)==null||y.call(u,l.nativeEvent||l),Ye.current=null,_t.current=null,Ge();return}if(He.current){He.current=null,bt(),st();return}if(We.current){const C=We.current;if(ze.current){const H=K.current.find(Q=>Q.id===C.id),Z=[{id:C.id,type:"position",position:H?{...H.position}:void 0,dragging:!1}];for(const Q of C.selectedStarts){const be=K.current.find(Te=>Te.id===Q.id);Z.push({id:Q.id,type:"position",position:be?{...be.position}:void 0,dragging:!1})}ze.current(Z)}if(C.selectedStarts.length>0){const H=K.current.filter(Z=>Z.selected);(S=(R=O.current).onSelectionDragStop)==null||S.call(R,l,H)}requestAnimationFrame(()=>{We.current=null});const U=K.current.find(H=>H.id===C.id);U&&((m=qt.current)==null||m.call(qt,l,U));return}ut.current=!1,(T=pe.current)==null||T.classList.remove("dragging")},[Se,ve,Ge,bt,st]);c.useEffect(()=>{const l=pe.current;if(!l)return;const w=u=>{Dt&&u.preventDefault();const y=ie.current;if(an||Tt.current){const C=cn;At==="horizontal"?y.x-=u.deltaY*C:(At==="vertical"||(y.x-=u.deltaX*C),y.y-=u.deltaY*C),ce(u);return}if(!un)return;const R=u.deltaY>0?.92:1.08,S=l.getBoundingClientRect(),m=u.clientX-S.left,T=u.clientY-S.top;y.x=m-(m-y.x)*R,y.y=T-(T-y.y)*R,y.zoom=Math.min(ue,Math.max(ae,y.zoom*R)),ce(u)};return l.addEventListener("wheel",w,{passive:!Dt}),()=>l.removeEventListener("wheel",w)},[ce,ae,ue,an,At,cn,un,Dt]),c.useEffect(()=>{if(!dn)return;const l=pe.current;if(!l)return;let w=0,u=null;const y=m=>{if(m.touches.length===2){const T=m.touches[0].clientX-m.touches[1].clientX,C=m.touches[0].clientY-m.touches[1].clientY;w=Math.hypot(T,C);const U=l.getBoundingClientRect();u={x:(m.touches[0].clientX+m.touches[1].clientX)/2-U.left,y:(m.touches[0].clientY+m.touches[1].clientY)/2-U.top},m.preventDefault()}},R=m=>{if(m.touches.length===2&&w>0){m.preventDefault();const T=m.touches[0].clientX-m.touches[1].clientX,C=m.touches[0].clientY-m.touches[1].clientY,U=Math.hypot(T,C),H=U/w;w=U;const Z=ie.current,Q=u.x,be=u.y;Z.x=Q-(Q-Z.x)*H,Z.y=be-(be-Z.y)*H,Z.zoom=Math.min(ue,Math.max(ae,Z.zoom*H)),ce(m)}},S=()=>{w=0,u=null};return l.addEventListener("touchstart",y,{passive:!1}),l.addEventListener("touchmove",R,{passive:!1}),l.addEventListener("touchend",S),()=>{l.removeEventListener("touchstart",y),l.removeEventListener("touchmove",R),l.removeEventListener("touchend",S)}},[dn,ce,ae,ue]),c.useEffect(()=>{if(!ln)return;const l=pe.current;if(!l)return;const w=u=>{var H,Z,Q,be;const y=Se(u.clientX,u.clientY);if(nt(y.x,y.y)){(Z=(H=O.current).onNodeDoubleClick)==null||Z.call(H,u,nt(y.x,y.y));return}const R=Le(y.x,y.y);if(R){(be=(Q=O.current).onEdgeDoubleClick)==null||be.call(Q,u,R);return}const S=1.5,m=l.getBoundingClientRect(),T=u.clientX-m.left,C=u.clientY-m.top,U=ie.current;U.x=T-(T-U.x)*S,U.y=C-(C-U.y)*S,U.zoom=Math.min(ue,Math.max(ae,U.zoom*S)),ce(u)};return l.addEventListener("dblclick",w),()=>l.removeEventListener("dblclick",w)},[ln,ce,ae,ue,Se,nt,Le]),c.useEffect(()=>{const l=pe.current;if(!l)return;const w=u=>{var m,T,C,U,H,Z;const y=Se(u.clientX,u.clientY),R=nt(y.x,y.y);if(R){(T=(m=O.current).onNodeContextMenu)==null||T.call(m,u,R);return}const S=Le(y.x,y.y);if(S){(U=(C=O.current).onEdgeContextMenu)==null||U.call(C,u,S);return}(Z=(H=O.current).onPaneContextMenu)==null||Z.call(H,u)};return l.addEventListener("contextmenu",w),()=>l.removeEventListener("contextmenu",w)},[Se,nt,Le]),c.useEffect(()=>{const l=pe.current;if(!l)return;let w=null,u=null;const y=m=>{var U,H,Z,Q,be,Te,te,se,ke,$e,Fe,Qe,Ue,Vt;if((H=(U=O.current).onPaneMouseMove)==null||H.call(U,m),ut.current||We.current||Ye.current||He.current)return;const T=Se(m.clientX,m.clientY),C=nt(T.x,T.y);if(C!==w&&(w&&((Q=(Z=O.current).onNodeMouseLeave)==null||Q.call(Z,m,w)),C&&((Te=(be=O.current).onNodeMouseEnter)==null||Te.call(be,m,C)),w=C),C&&((se=(te=O.current).onNodeMouseMove)==null||se.call(te,m,C)),!C){const lt=Le(T.x,T.y);lt!==u&&(u&&(($e=(ke=O.current).onEdgeMouseLeave)==null||$e.call(ke,m,u)),lt&&((Qe=(Fe=O.current).onEdgeMouseEnter)==null||Qe.call(Fe,m,lt)),u=lt),lt&&((Vt=(Ue=O.current).onEdgeMouseMove)==null||Vt.call(Ue,m,lt))}},R=m=>{var T,C;return(C=(T=O.current).onPaneMouseEnter)==null?void 0:C.call(T,m)},S=m=>{var T,C,U,H,Z,Q;(C=(T=O.current).onPaneMouseLeave)==null||C.call(T,m),w&&((H=(U=O.current).onNodeMouseLeave)==null||H.call(U,m,w),w=null),u&&((Q=(Z=O.current).onEdgeMouseLeave)==null||Q.call(Z,m,u),u=null)};return l.addEventListener("mousemove",y),l.addEventListener("mouseenter",R),l.addEventListener("mouseleave",S),()=>{l.removeEventListener("mousemove",y),l.removeEventListener("mouseenter",R),l.removeEventListener("mouseleave",S)}},[Se,nt,Le]),c.useEffect(()=>{const l=Array.isArray(Ze)?Ze:[Ze],w=async u=>{var y,R,S,m;if(l.includes(u.key)){if(u.target.tagName==="INPUT"||u.target.tagName==="TEXTAREA"||u.target.isContentEditable)return;const T=K.current.filter(H=>H.selected),C=Re.current.filter(H=>H.selected);if(!T.length&&!C.length)return;if(O.current.onBeforeDelete)try{if(!await O.current.onBeforeDelete({nodes:T,edges:C}))return}catch(H){(R=(y=O.current).onError)==null||R.call(y,"before-delete-error",H.message||"onBeforeDelete threw an error");return}const U=new Set(T.map(H=>H.id));if(T.length&&ze.current&&(ze.current(T.map(H=>({id:H.id,type:"remove"}))),Pe.current)){const H=Re.current.filter(Z=>U.has(Z.source)||U.has(Z.target));H.length&&Pe.current(H.map(Z=>({id:Z.id,type:"remove"})))}C.length&&Pe.current&&Pe.current(C.map(H=>({id:H.id,type:"remove"}))),(m=(S=O.current).onDelete)==null||m.call(S,{nodes:T,edges:C})}if((u.ctrlKey||u.metaKey)&&u.key==="a"){if(u.target.tagName==="INPUT"||u.target.tagName==="TEXTAREA")return;if(u.preventDefault(),ze.current){const T=K.current.filter(C=>!C.selected).map(C=>({id:C.id,type:"select",selected:!0}));T.length&&ze.current(T)}if(Pe.current){const T=Re.current.filter(C=>!C.selected).map(C=>({id:C.id,type:"select",selected:!0}));T.length&&Pe.current(T)}}};return window.addEventListener("keydown",w),()=>window.removeEventListener("keydown",w)},[Ze]);const Qt=c.useRef(!1);c.useEffect(()=>{var l,w;if(!Qt.current&&Ee.current){if(Qt.current=!0,Je&&K.current.length>0){const u=pe.current;if(u){const y=u.getBoundingClientRect(),R=(le==null?void 0:le.padding)??.1,S=mn(K.current),m=jt(S,y.width,y.height,R);le!=null&&le.maxZoom&&(m.zoom=Math.min(m.zoom,le.maxZoom)),le!=null&&le.minZoom&&(m.zoom=Math.max(m.zoom,le.minZoom)),ie.current=m,ce()}}(w=(l=O.current).onInit)==null||w.call(l,{getNodes:()=>[...K.current],getEdges:()=>[...Re.current],getNode:u=>K.current.find(y=>y.id===u),getEdge:u=>Re.current.find(y=>y.id===u),getViewport:()=>({...ie.current}),getZoom:()=>ie.current.zoom,setViewport:u=>{ie.current={x:u.x??ie.current.x,y:u.y??ie.current.y,zoom:u.zoom??ie.current.zoom},ce()},fitView:(u={})=>{const y=pe.current;if(!y||!K.current.length)return;const R=y.getBoundingClientRect(),S=u.nodes?K.current.filter(C=>u.nodes.some(U=>U.id===C.id)):K.current;if(!S.length)return;const m=mn(S),T=jt(m,R.width,R.height,u.padding??.1);u.maxZoom&&(T.zoom=Math.min(T.zoom,u.maxZoom)),u.minZoom&&(T.zoom=Math.max(T.zoom,u.minZoom)),ie.current=T,ce()},screenToFlowPosition:u=>Se(u.x,u.y),flowToScreenPosition:u=>{const y=ie.current,R=pe.current;if(!R)return{x:0,y:0};const S=R.getBoundingClientRect();return{x:u.x*y.zoom+y.x+S.left,y:u.y*y.zoom+y.y+S.top}},zoomIn:()=>{const u=ie.current;u.zoom=Math.min(ue,u.zoom*1.2),ce()},zoomOut:()=>{const u=ie.current;u.zoom=Math.max(ae,u.zoom/1.2),ce()},zoomTo:u=>{ie.current.zoom=Math.min(ue,Math.max(ae,u)),ce()},setNodes:u=>{var y,R;(R=(y=O.current).onNodesChange)==null||R.call(y,[...K.current.map(S=>({id:S.id,type:"remove"})),...(typeof u=="function"?u(K.current):u).map(S=>({type:"add",item:S}))])},setEdges:u=>{var y,R;(R=(y=O.current).onEdgesChange)==null||R.call(y,[...Re.current.map(S=>({id:S.id,type:"remove"})),...(typeof u=="function"?u(Re.current):u).map(S=>({type:"add",item:S}))])},addNodes:u=>{var R,S;const y=Array.isArray(u)?u:[u];(S=(R=O.current).onNodesChange)==null||S.call(R,y.map(m=>({type:"add",item:m})))},addEdges:u=>{var R,S;const y=Array.isArray(u)?u:[u];(S=(R=O.current).onEdgesChange)==null||S.call(R,y.map(m=>({type:"add",item:m})))},deleteElements:({nodes:u=[],edges:y=[]})=>{var R,S,m,T;u.length&&((S=(R=O.current).onNodesChange)==null||S.call(R,u.map(C=>({id:C.id,type:"remove"})))),y.length&&((T=(m=O.current).onEdgesChange)==null||T.call(m,y.map(C=>({id:C.id,type:"remove"}))))},updateNodeData:(u,y)=>{var m,T;const R=K.current.find(C=>C.id===u);if(!R)return;const S=typeof y=="function"?y(R.data):{...R.data,...y};(T=(m=O.current).onNodesChange)==null||T.call(m,[{id:u,type:"replace",item:{...R,data:S}}])},toObject:()=>({nodes:[...K.current],edges:[...Re.current],viewport:{...ie.current}}),setCenter:(u,y,R={})=>{const S=pe.current;if(!S)return;const m=S.getBoundingClientRect(),T=R.zoom??ie.current.zoom;ie.current={x:m.width/2-u*T,y:m.height/2-y*T,zoom:T},ce()},fitBounds:(u,y={})=>{const R=pe.current;if(!R)return;const S=R.getBoundingClientRect(),m=jt(u,S.width,S.height,y.padding??.1);ie.current=m,ce()}})}});const gn=c.useCallback(()=>{ie.current={...Ne},ce()},[ce,Ne]),qe=c.useCallback(l=>{var w;if(l)gt.current.push(l);else{const u=ie.current,y=pe.current;if(!y)return;const R=y.getBoundingClientRect(),S=Math.round(-u.x/u.zoom+R.width/2/u.zoom),m=Math.round(-u.y/u.zoom+R.height/2/u.zoom);gt.current.push({x:S-80,y:m-45,w:160,h:90,title:"Note "+(gt.current.length+1),body:"Added at viewport center"})}(w=Ee.current)==null||w.postMessage({type:"cards",data:{cards:[...gt.current]}})},[]),wt=c.useCallback(l=>{if(l.id||(l.id="node-"+Date.now()),!l.position){const w=ie.current,u=pe.current;if(!u)return;const y=u.getBoundingClientRect();l.position={x:Math.round(-w.x/w.zoom+y.width/2/w.zoom)-it/2,y:Math.round(-w.y/w.zoom+y.height/2/w.zoom)-rt/2}}l.data||(l.data={label:l.id}),ze.current&&ze.current([{type:"add",item:l}])},[]),Dn=c.useCallback(()=>({...ie.current}),[]),Hn=c.useCallback(l=>{ie.current={...ie.current,...l},ce()},[ce]),Hr=c.useCallback(l=>Se(l.x,l.y),[Se]),ar=n,_r=c.useMemo(()=>({wrapRef:pe,canvasRef:Ht,workerRef:Ee,cameraRef:ie,nodesRef:K,edgesRef:Re,handleRegistryRef:fn,syncNodesToWorker:hn,onNodesChangeRef:ze,onEdgesChangeRef:Pe,sendCamera:ce,screenToWorld:Se,viewportListeners:tt,selectionListeners:Ke,zoomMin:ae,zoomMax:ue,snapToGrid:De,snapGrid:Xe,nodeExtent:ft,defaultEdgeOptions:Nt,edgeRouting:ht,resolvedNodesRef:et,noDragClassName:Pt,noPanClassName:It,get nodes(){return t},get edges(){return n},get routedEdges(){return ar},get viewport(){return Ft},get connection(){return yt}}),[t,n,ar,Ft,yt,ce,Se,hn,tt,Ke,ae,ue,De,Xe,ft,Nt,ht,Pt,It]);return{wrapRef:pe,canvasRef:Ht,canvasReady:Tn,onPointerDown:jn,onPointerMove:An,onPointerUp:kt,resetView:gn,addCard:qe,addNode:wt,getCamera:Dn,setCamera:Hn,screenToFlowPosition:Hr,store:_r}}function ro(e,t,n,r,a,o){const i=a-n,f=o-r,p=i*i+f*f;if(p===0)return Math.hypot(e-n,t-r);let d=((e-n)*i+(t-r)*f)/p;return d=Math.max(0,Math.min(1,d)),Math.hypot(e-(n+d*i),t-(r+d*f))}const cr=e=>{let t;const n=new Set,r=(d,h)=>{const v=typeof d=="function"?d(t):d;if(!Object.is(v,t)){const E=t;t=h??(typeof v!="object"||v===null)?v:Object.assign({},t,v),n.forEach(M=>M(t,E))}},a=()=>t,f={setState:r,getState:a,getInitialState:()=>p,subscribe:d=>(n.add(d),()=>n.delete(d))},p=t=e(r,a,f);return f},oo=(e=>e?cr(e):cr),so=e=>e;function ao(e,t=so){const n=c.useSyncExternalStore(e.subscribe,c.useCallback(()=>t(e.getState()),[e,t]),c.useCallback(()=>t(e.getInitialState()),[e,t]));return c.useDebugValue(n),n}const Et=c.createContext(null);function io(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,a)=>{const o=n().cameraRef.current;return{x:(r-o.x)/o.zoom,y:(a-o.y)/o.zoom}},sendCamera:()=>{var a;const r=n();(a=r.workerRef.current)==null||a.postMessage({type:"camera",data:{camera:{...r.cameraRef.current}}})},...e}))}function Ce(e,t){const n=c.useContext(Et);if(!n)throw new Error("useCanvasStore must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");const r=typeof n.getState=="function"&&typeof n.subscribe=="function",a=c.useRef(e),o=c.useRef(t),i=c.useRef(void 0);a.current=e,o.current=t;const f=c.useCallback(p=>{const d=a.current;if(!d)return p;const h=d(p),v=o.current||Object.is;return i.current!==void 0&&v(i.current,h)?i.current:(i.current=h,h)},[]);return r?ao(n,e?f:void 0):e?f(n):n}function wr(){const e=c.useContext(Et);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=c.createContext(null);function co(){return c.useContext(on)}function uo({node:e,nodeType:t}){var E,M,z;const n=Ce(),r=c.useRef(n);r.current=n;const a=c.useRef(null),o=e._absolutePosition||e.position,i=c.useRef(null);c.useEffect(()=>{const I=a.current;if(!I)return;const k=new ResizeObserver(j=>{var _,A,L,Y;const{width:X,height:D}=j[0].contentRect;if(X>0&&D>0){const F=r.current,B=F.nodesRef.current.find(x=>x.id===e.id),b=(B==null?void 0:B.width)||((_=B==null?void 0:B.measured)==null?void 0:_.width),g=(B==null?void 0:B.height)||((A=B==null?void 0:B.measured)==null?void 0:A.height);(Math.abs((b||0)-X)>1||Math.abs((g||0)-D)>1)&&((Y=(L=F.onNodesChangeRef).current)==null||Y.call(L,[{id:e.id,type:"dimensions",dimensions:{width:X,height:D},setAttributes:!0}]))}});return k.observe(I),()=>k.disconnect()},[e.id]);const f=c.useCallback(I=>{var ee,oe,ge,ye;I.stopPropagation();const k=I.target.tagName;if(k==="INPUT"||k==="TEXTAREA"||k==="SELECT"||k==="BUTTON"||k==="A"||k==="LABEL"||I.target.isContentEditable)return;const j=r.current.noDragClassName||"nodrag",X=r.current.noPanClassName||"nopan";let D=I.target;for(;D&&D!==a.current;){if((ee=D.classList)!=null&&ee.contains(j)||(oe=D.classList)!=null&&oe.contains(X))return;D=D.parentElement}if(r.current.onNodesChangeRef.current){const J=[];if(I.shiftKey)J.push({id:e.id,type:"select",selected:!e.selected});else for(const me of r.current.nodesRef.current)me.id===e.id&&!me.selected?J.push({id:me.id,type:"select",selected:!0}):me.id!==e.id&&me.selected&&J.push({id:me.id,type:"select",selected:!1});J.length&&r.current.onNodesChangeRef.current(J)}const _=r.current.cameraRef.current,A=r.current.wrapRef.current;if(!A)return;const L=A.getBoundingClientRect(),Y=(I.clientX-L.left-_.x)/_.zoom,F=(I.clientY-L.top-_.y)/_.zoom,b=e.selected?r.current.nodesRef.current.filter(J=>J.selected&&J.id!==e.id).map(J=>({id:J.id,startPos:{...J.position}})):[];i.current={startPos:{...e.position},startMouse:{x:Y,y:F},selectedStarts:b};const g=[{id:e.id,type:"position",dragging:!0}];for(const J of b)g.push({id:J.id,type:"position",dragging:!0});(ye=(ge=r.current.onNodesChangeRef).current)==null||ye.call(ge,g);const x=a.current;x&&x.setPointerCapture(I.pointerId);let N=null,$=null;const W=()=>{var J,fe;$&&((fe=(J=r.current.onNodesChangeRef).current)==null||fe.call(J,$),$=null),N=null},V=J=>{var je,_e;if(!i.current)return;const fe=r.current.cameraRef.current,me=A.getBoundingClientRect(),ae=(J.clientX-me.left-fe.x)/fe.zoom,ue=(J.clientY-me.top-fe.y)/fe.zoom,Ne=ae-i.current.startMouse.x,Je=ue-i.current.startMouse.y;let le={x:i.current.startPos.x+Ne,y:i.current.startPos.y+Je};if(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])}),e.parentId&&e.extent==="parent"){const he=r.current.nodesRef.current.find(Me=>Me.id===e.parentId);if(he){const Me=he.width||160,Oe=he.height||60,Ae=e.width||((je=e.measured)==null?void 0:je.width)||160,ct=e.height||((_e=e.measured)==null?void 0:_e.height)||60;le={x:Math.max(0,Math.min(le.x,Me-Ae)),y:Math.max(0,Math.min(le.y,Oe-ct))}}}x&&(x.style.left=le.x+"px",x.style.top=le.y+"px");for(const he of i.current.selectedStarts){let Me={x:he.startPos.x+Ne,y:he.startPos.y+Je};r.current.snapToGrid&&r.current.snapGrid&&(Me={x:r.current.snapGrid[0]*Math.round(Me.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Me.y/r.current.snapGrid[1])});const Oe=A.querySelector(`[data-nodeid="${he.id}"]`);Oe&&(Oe.style.left=Me.x+"px",Oe.style.top=Me.y+"px")}const Be=[{id:e.id,type:"position",position:le,dragging:!0}];for(const he of i.current.selectedStarts){let Me={x:he.startPos.x+Ne,y:he.startPos.y+Je};r.current.snapToGrid&&r.current.snapGrid&&(Me={x:r.current.snapGrid[0]*Math.round(Me.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Me.y/r.current.snapGrid[1])}),Be.push({id:he.id,type:"position",position:Me,dragging:!0})}$=Be,N||(N=requestAnimationFrame(W))},re=J=>{var me,ae;if(!i.current)return;N&&(cancelAnimationFrame(N),W());const fe=[{id:e.id,type:"position",dragging:!1}];for(const ue of i.current.selectedStarts)fe.push({id:ue.id,type:"position",dragging:!1});(ae=(me=r.current.onNodesChangeRef).current)==null||ae.call(me,fe),i.current=null,x&&x.releasePointerCapture(J.pointerId),x==null||x.removeEventListener("pointermove",V),x==null||x.removeEventListener("pointerup",re)};x==null||x.addEventListener("pointermove",V),x==null||x.addEventListener("pointerup",re)},[e]),p=c.useCallback(I=>{var A,L,Y,F,B,b;if(!e.selected)return;const k=I.shiftKey?10:1;let j=0,X=0;switch(I.key){case"ArrowUp":X=-k;break;case"ArrowDown":X=k;break;case"ArrowLeft":j=-k;break;case"ArrowRight":j=k;break;case"Escape":(L=(A=r.current.onNodesChangeRef).current)==null||L.call(A,[{id:e.id,type:"select",selected:!1}]);return;case"Delete":case"Backspace":e.deletable!==!1&&((F=(Y=r.current.onNodesChangeRef).current)==null||F.call(Y,[{id:e.id,type:"remove"}]));return;default:return}I.preventDefault();const D={x:e.position.x+j,y:e.position.y+X},_=[{id:e.id,type:"position",position:D}];for(const g of r.current.nodesRef.current)g.selected&&g.id!==e.id&&_.push({id:g.id,type:"position",position:{x:g.position.x+j,y:g.position.y+X}});(b=(B=r.current.onNodesChangeRef).current)==null||b.call(B,_)},[e]),d=e.width||((E=e.measured)==null?void 0:E.width),h=e.height||((M=e.measured)==null?void 0:M.height),v=!!(d&&h);return P.jsx(on.Provider,{value:e.id,children:P.jsx("div",{ref:a,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:v?"visible":"hidden",outline:"none"},"data-nodeid":e.id,tabIndex:e.selectable!==!1?0:void 0,role:"button","aria-label":`Node ${((z=e.data)==null?void 0:z.label)||e.id}`,"aria-selected":!!e.selected,onPointerDown:f,onKeyDown:p,children:P.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})})})}const lo=c.memo(uo),Mr=160,Rr=60;function ur(e,t,n,r){var f,p;const a=e.width||((f=e.measured)==null?void 0:f.width)||Mr,o=e.height||((p=e.measured)==null?void 0:p.height)||Rr,i=e._absolutePosition||e.position;if(e.handleBounds){const d=e.handleBounds[t]||[],h=n?d.find(v=>v.id===n):d[0];if(h&&h.x!==void 0&&h.y!==void 0){const v=h.position||(t==="source"?"right":"left");return{x:i.x+h.x,y:i.y+h.y,position:v}}}if(r){const d=`${e.id}__${n||t}`,h=r.get(d);if(h&&h.x!==void 0&&h.y!==void 0)return{x:i.x+h.x,y:i.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:i.x+d.x,y:i.y+d.y,position:d.position||(t==="source"?"right":"left")};const h=d.position||(t==="source"?"right":"left");switch(h){case"top":return{x:i.x+a/2,y:i.y,position:h};case"bottom":return{x:i.x+a/2,y:i.y+o,position:h};case"left":return{x:i.x,y:i.y+o/2,position:h};default:return{x:i.x+a,y:i.y+o/2,position:h}}}}return t==="source"?{x:i.x+a,y:i.y+o/2,position:"right"}:{x:i.x,y:i.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 lr({x:e,y:t,position:n,type:r,onPointerDown:a}){return P.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:a})}function go({edge:e,edgeType:t,nodes:n,reconnectable:r}){var L,Y,F;const a=c.useContext(Et),o=c.useRef(typeof a.getState=="function"?a.getState():a);o.current=typeof a.getState=="function"?a.getState():a;const[i,f]=c.useState(null),p=c.useCallback((B,b,g,x)=>{var ge;b.stopPropagation(),b.preventDefault();const N=o.current,$=N.wrapRef.current;if(!$)return;const W=B==="source"?x:g,V=B==="source"?e.target:e.source;(ge=N.workerRef.current)==null||ge.postMessage({type:"connecting",data:{from:{x:W.x,y:W.y},to:{x:W.x,y:W.y}}});const re=$.getBoundingClientRect(),ee=ye=>{var ae;const J=N.cameraRef.current,fe=(ye.clientX-re.left-J.x)/J.zoom,me=(ye.clientY-re.top-J.y)/J.zoom;(ae=N.workerRef.current)==null||ae.postMessage({type:"connecting",data:{from:{x:W.x,y:W.y},to:{x:fe,y:me}}})},oe=ye=>{var le,Be,je,_e;const J=N.cameraRef.current,fe=(ye.clientX-re.left-J.x)/J.zoom,me=(ye.clientY-re.top-J.y)/J.zoom,ae=20/J.zoom;let ue=null,Ne=null;const Je=(le=N.handleRegistryRef)==null?void 0:le.current;for(const he of N.nodesRef.current){if(he.hidden)continue;const Me=he.width||Mr,Oe=he.height||Rr,Ae=he._absolutePosition||he.position,ct=[];if(Je)for(const[,De]of Je)De.nodeId===he.id&&ct.push(De);const zt=ct.length>0?ct:he.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const De of zt){let Xe,Ze;if(De.x!==void 0&&De.y!==void 0)Xe=Ae.x+De.x,Ze=Ae.y+De.y;else switch(De.position||(De.type==="source"?"right":"left")){case"top":Xe=Ae.x+Me/2,Ze=Ae.y;break;case"bottom":Xe=Ae.x+Me/2,Ze=Ae.y+Oe;break;case"left":Xe=Ae.x,Ze=Ae.y+Oe/2;break;default:Xe=Ae.x+Me,Ze=Ae.y+Oe/2;break}if(Math.abs(fe-Xe)<ae&&Math.abs(me-Ze)<ae){ue=he,Ne=De.id||null;break}}if(ue)break}if(ue){const he=B==="source"?{source:ue.id,target:V,sourceHandle:Ne,targetHandle:e.targetHandle}:{source:V,target:ue.id,sourceHandle:e.sourceHandle,targetHandle:Ne};(je=(Be=N.onEdgesChangeRef).current)==null||je.call(Be,[{id:e.id,type:"remove"},{type:"add",item:{id:e.id,...he}}])}(_e=N.workerRef.current)==null||_e.postMessage({type:"connecting",data:null}),$.removeEventListener("pointermove",ee),$.removeEventListener("pointerup",oe)};$.addEventListener("pointermove",ee),$.addEventListener("pointerup",oe)},[e]),d=n.find(B=>B.id===e.source),h=n.find(B=>B.id===e.target),v=d&&!!(d.width||(L=d.measured)!=null&&L.width),E=h&&!!(h.width||(Y=h.measured)!=null&&Y.width),M=o.current,z=(F=M.handleRegistryRef)==null?void 0:F.current,I=v?ur(d,"source",e.sourceHandle,z):null,k=E?ur(h,"target",e.targetHandle,z):null,j=e.type==="bezier"||e.type==="simplebezier"||e.type==="default",X=M.routedEdges||M.edges,D=X==null?void 0:X.find(B=>B.id===e.id),_=j?null:(D==null?void 0:D._routedPoints)||e._routedPoints||null,A=r!==!1&&e.reconnectable!==!1;return!I||!k?null:P.jsxs("g",{className:`ric-edge-wrapper ${e.selected?"selected":""}`,"data-edgeid":e.id,onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),children:[P.jsx(t,{id:e.id,source:e.source,target:e.target,sourceX:I.x,sourceY:I.y,targetX:k.x,targetY:k.y,sourcePosition:I.position,targetPosition:k.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:_}),A&&(i||e.selected)&&P.jsxs(P.Fragment,{children:[P.jsx(lr,{x:I.x,y:I.y,position:I.position,type:"source",onPointerDown:B=>p("source",B,I,k)}),P.jsx(lr,{x:k.x,y:k.y,position:k.position,type:"target",onPointerDown:B=>p("target",B,I,k)})]})]})}const yo=c.memo(go);function kr({selectionKeyCode:e="Shift",selectionMode:t="partial"}){var I;const n=Ce(),[r,a]=c.useState(null),o=c.useRef(null);if(c.useEffect(()=>{const k=n.wrapRef.current;if(!k)return;let j=!1,X=null,D=!1;const _=B=>{B.key===e&&(D=!0)},A=B=>{B.key===e&&(D=!1)},L=B=>{if(!D)return;const b=B.target;if(b.closest(".ric-node-wrapper")||b.closest(".ric-handle"))return;j=!0;const g=n.cameraRef.current,x=k.getBoundingClientRect(),N=(B.clientX-x.left-g.x)/g.zoom,$=(B.clientY-x.top-g.y)/g.zoom;X={x:N,y:$},a({startX:N,startY:$,endX:N,endY:$}),B.stopPropagation()},Y=B=>{if(!j||!X)return;const b=n.cameraRef.current,g=k.getBoundingClientRect(),x=(B.clientX-g.left-b.x)/b.zoom,N=(B.clientY-g.top-b.y)/b.zoom;a({startX:X.x,startY:X.y,endX:x,endY:N})},F=B=>{var V,re;if(!j||!X)return;j=!1;const b=n.cameraRef.current,g=k.getBoundingClientRect(),x=(B.clientX-g.left-b.x)/b.zoom,N=(B.clientY-g.top-b.y)/b.zoom,$={x:Math.min(X.x,x),y:Math.min(X.y,N),width:Math.abs(x-X.x),height:Math.abs(N-X.y)},W=[];for(const ee of n.nodesRef.current){const oe=ee._absolutePosition||ee.position,ge=ee.width||160,ye=ee.height||60;let J;t==="full"?J=oe.x>=$.x&&oe.y>=$.y&&oe.x+ge<=$.x+$.width&&oe.y+ye<=$.y+$.height:J=oe.x+ge>$.x&&oe.x<$.x+$.width&&oe.y+ye>$.y&&oe.y<$.y+$.height,W.push({id:ee.id,type:"select",selected:J})}W.length&&((re=(V=n.onNodesChangeRef).current)==null||re.call(V,W)),X=null,a(null)};return k.addEventListener("pointerdown",L,!0),k.addEventListener("pointermove",Y),k.addEventListener("pointerup",F),window.addEventListener("keydown",_),window.addEventListener("keyup",A),()=>{k.removeEventListener("pointerdown",L,!0),k.removeEventListener("pointermove",Y),k.removeEventListener("pointerup",F),window.removeEventListener("keydown",_),window.removeEventListener("keyup",A)}},[n,e,t]),!r)return null;const i=((I=n.cameraRef)==null?void 0:I.current)||{x:0,y:0,zoom:1},f=Math.min(r.startX,r.endX),p=Math.min(r.startY,r.endY),d=Math.abs(r.endX-r.startX),h=Math.abs(r.endY-r.startY),v=f*i.zoom+i.x,E=p*i.zoom+i.y,M=d*i.zoom,z=h*i.zoom;return P.jsx("div",{ref:o,className:"ric-selection-box",style:{position:"absolute",left:v,top:E,width:M,height:z,border:"1px dashed #3b82f6",background:"rgba(59, 130, 246, 0.08)",pointerEvents:"none",zIndex:100}})}kr.displayName="SelectionBox";const Cr=c.memo(kr);function On(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(),a=e.getBoundingClientRect(),o=t||1;return{x:(a.left+a.width/2-r.left)/o,y:(a.top+a.height/2-r.top)/o}}let Fn=!1,Ct=null;function Er(e){Ct=e,!Fn&&(Fn=!0,requestAnimationFrame(()=>{var t;Fn=!1,(t=Ct==null?void 0:Ct.syncNodesToWorker)==null||t.call(Ct),Ct=null}))}const Zn=new WeakMap;let xn=null;function po(){return xn||(xn=new ResizeObserver(e=>{var t;for(const n of e){const r=Zn.get(n.target);if(!r)continue;const{width:a,height:o}=n.contentRect;if(!a||!o)continue;const i=r.getStore(),f=(t=i.handleRegistryRef)==null?void 0:t.current;if(f){for(const[p,d]of f)if(d.nodeId===r.nodeId){const h=On(d.position,a,o);d.x=h.x,d.y=h.y,f.set(p,d)}Er(i)}}}),xn)}function mo({type:e="source",position:t=e==="source"?"right":"left",id:n,isConnectable:r=!0,isConnectableStart:a=!0,isConnectableEnd:o=!0,children:i,className:f="",style:p={},onConnect:d,...h}){const v=c.useContext(on),E=c.useContext(Et),M=c.useRef(null),z=c.useCallback(()=>typeof E.getState=="function"?E.getState():E,[E]),I=c.useRef(z);I.current=z,c.useLayoutEffect(()=>{var b,g,x,N,$,W,V;if(!v)return;const D=I.current(),_=(b=D.handleRegistryRef)==null?void 0:b.current;if(!_)return;const A=`${v}__${n||e}`,L=(x=(g=D.nodesRef)==null?void 0:g.current)==null?void 0:x.find(re=>re.id===v),Y=(L==null?void 0:L.width)||((N=L==null?void 0:L.measured)==null?void 0:N.width),F=(L==null?void 0:L.height)||(($=L==null?void 0:L.measured)==null?void 0:$.height);let B;Y&&F?B=On(t,Y,F):M.current?B=xo(M.current,(V=(W=D.cameraRef)==null?void 0:W.current)==null?void 0:V.zoom):B=On(t,160,60),_.set(A,{nodeId:v,id:n||null,type:e,position:t,x:B.x,y:B.y})},[v,n,e,t]),c.useEffect(()=>{if(!v)return;const D=I.current();Er(D);const _=M.current,A=_==null?void 0:_.closest(".ric-node-wrapper");return A&&!Zn.has(A)&&(Zn.set(A,{nodeId:v,getStore:I.current}),po().observe(A)),()=>{var B;const Y=(B=I.current().handleRegistryRef)==null?void 0:B.current,F=`${v}__${n||e}`;Y==null||Y.delete(F)}},[v,n,e,t]);const k=c.useCallback(()=>{var g;const D=I.current(),_=D.nodesRef.current.find(x=>x.id===v);if(!_)return null;const A=_._absolutePosition||_.position,L=(g=D.handleRegistryRef)==null?void 0:g.current,Y=`${v}__${n||e}`,F=L==null?void 0:L.get(Y);if(F&&F.x!==void 0&&F.y!==void 0)return{x:A.x+F.x,y:A.y+F.y};const B=_.width||160,b=_.height||60;switch(t){case"top":return{x:A.x+B/2,y:A.y};case"bottom":return{x:A.x+B/2,y:A.y+b};case"left":return{x:A.x,y:A.y+b/2};default:return{x:A.x+B,y:A.y+b/2}}},[v,n,e,t]),j=c.useCallback(D=>{var N;if(!r||!a)return;D.stopPropagation(),D.preventDefault();const _=I.current(),A=_.cameraRef.current,L=_.wrapRef.current;if(!L)return;const Y=L.getBoundingClientRect(),F=k();if(!F)return;const B=F.x,b=F.y;(N=_.workerRef.current)==null||N.postMessage({type:"connecting",data:{from:{x:B,y:b},to:{x:B,y:b}}}),L.setPointerCapture(D.pointerId);const g=$=>{var re;const W=($.clientX-Y.left-A.x)/A.zoom,V=($.clientY-Y.top-A.y)/A.zoom;(re=_.workerRef.current)==null||re.postMessage({type:"connecting",data:{from:{x:B,y:b},to:{x:W,y:V}}})},x=$=>{var ye,J,fe,me;const W=($.clientX-Y.left-A.x)/A.zoom,V=($.clientY-Y.top-A.y)/A.zoom,re=20/A.zoom;let ee=null,oe=null;const ge=(ye=_.handleRegistryRef)==null?void 0:ye.current;for(const ae of _.nodesRef.current){if(ae.id===v||ae.hidden)continue;const ue=ae._absolutePosition||ae.position,Ne=[];if(ge)for(const[,le]of ge)le.nodeId===ae.id&&Ne.push(le);const Je=Ne.length>0?Ne:ae.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const le of Je){let Be,je;if(le.x!==void 0&&le.y!==void 0)Be=ue.x+le.x,je=ue.y+le.y;else{const _e=ae.width||160,he=ae.height||60;switch(le.position||(le.type==="source"?"right":"left")){case"top":Be=ue.x+_e/2,je=ue.y;break;case"bottom":Be=ue.x+_e/2,je=ue.y+he;break;case"left":Be=ue.x,je=ue.y+he/2;break;default:Be=ue.x+_e,je=ue.y+he/2;break}}if(Math.abs(W-Be)<re&&Math.abs(V-je)<re){ee=ae,oe=le.id||null;break}}if(ee)break}if(ee){const ae={source:e==="source"?v:ee.id,target:e==="source"?ee.id:v,sourceHandle:e==="source"?n||null:oe,targetHandle:e==="source"?oe:n||null};(fe=(J=_.onEdgesChangeRef)==null?void 0:J.current)==null||fe.call(J,[{type:"add",item:{id:`e-${ae.source}-${ae.target}`,...ae}}])}(me=_.workerRef.current)==null||me.postMessage({type:"connecting",data:null}),L.removeEventListener("pointermove",g),L.removeEventListener("pointerup",x)};L.addEventListener("pointermove",g),L.addEventListener("pointerup",x)},[v,n,e,t,r,a,k]),X={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 P.jsx("div",{ref:M,className:`ric-handle ric-handle-${t} ric-handle-${e} ${f}`,"data-handleid":n||null,"data-nodeid":v,"data-handlepos":t,"data-handletype":e,onPointerDown:j,style:{position:"absolute",width:8,height:8,borderRadius:"50%",background:"#1a192b",border:"none",zIndex:10,cursor:r?"crosshair":"default",boxSizing:"border-box",...X,...p},...h,children:i})}const rn=c.memo(mo);function vo({data:e,isConnectable:t,selected:n,targetPosition:r="left",sourcePosition:a="right",hideSourceHandle:o=!1,hideTargetHandle:i=!1}){return P.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:[!i&&P.jsx(rn,{type:"target",position:r,isConnectable:t}),P.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!o&&P.jsx(rn,{type:"source",position:a,isConnectable:t})]})}function zr({data:e,isConnectable:t,selected:n,sourcePosition:r="right",hideSourceHandle:a=!1}){return P.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:[P.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!a&&P.jsx(rn,{type:"source",position:r,isConnectable:t})]})}function Sr({data:e,isConnectable:t,selected:n,targetPosition:r="left",hideTargetHandle:a=!1}){return P.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:[!a&&P.jsx(rn,{type:"target",position:r,isConnectable:t}),P.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label})]})}function Nr({data:e,selected:t,width:n,height:r}){return P.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)&&P.jsx("div",{style:{fontSize:11,fontWeight:600,color:"#888",userSelect:"none"},children:e.label})})}function Pr({x:e,y:t,label:n,labelStyle:r,labelShowBg:a=!0,labelBgStyle:o,labelBgPadding:i=[2,4],labelBgBorderRadius:f=2,children:p,className:d="",...h}){const[v,E]=c.useState({x:1,y:0,width:0,height:0}),M=c.useRef(null);return c.useEffect(()=>{if(M.current){const z=M.current.getBBox();E({x:z.x,y:z.y,width:z.width,height:z.height})}},[n]),n?P.jsxs("g",{transform:`translate(${e-v.width/2} ${t-v.height/2})`,className:`ric-edge-textwrapper ${d}`,visibility:v.width?"visible":"hidden",...h,children:[a&&P.jsx("rect",{width:v.width+2*i[0],x:-i[0],y:-i[1],height:v.height+2*i[1],className:"ric-edge-textbg",style:o,rx:f,ry:f}),P.jsx("text",{className:"ric-edge-text",y:v.height/2,dy:"0.3em",ref:M,style:r,children:n}),p]}):null}Pr.displayName="EdgeText";const Ir=c.memo(Pr);function dr(e){return e!=null&&e!==""&&!isNaN(Number(e))}function sn({id:e,path:t,labelX:n,labelY:r,label:a,labelStyle:o,labelShowBg:i,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:d,interactionWidth:h=20,style:v,markerEnd:E,markerStart:M,className:z="",...I}){return P.jsxs(P.Fragment,{children:[P.jsx("path",{id:e,d:t,fill:"none",stroke:"#b1b1b7",strokeWidth:1.5,className:`ric-edge-path ${z}`,style:v,markerEnd:E,markerStart:M,...I}),h?P.jsx("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:h,className:"ric-edge-interaction",style:{pointerEvents:"stroke"}}):null,a&&dr(n)&&dr(r)?P.jsx(Ir,{x:n,y:r,label:a,labelStyle:o,labelShowBg:i,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:d}):null]})}const en=20;function fr(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 Vn=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:i="bottom",targetPosition:f="top",label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,interactionWidth:j}){let X,D,_;const A=fr(n,r,i),L=fr(a,o,f),Y=Math.abs(L.x-A.x),F=Math.max(50,Y*.5);let B,b,g,x;switch(i){case"left":B=A.x-F,b=A.y;break;case"top":B=A.x,b=A.y-F;break;case"bottom":B=A.x,b=A.y+F;break;default:B=A.x+F,b=A.y;break}switch(f){case"right":g=L.x+F,x=L.y;break;case"top":g=L.x,x=L.y-F;break;case"bottom":g=L.x,x=L.y+F;break;default:g=L.x-F,x=L.y;break}X=`M ${n},${r} L ${A.x},${A.y} C ${B},${b} ${g},${x} ${L.x},${L.y} L ${a},${o}`;const N=.5,$=.5;return D=$*$*$*A.x+3*$*$*N*B+3*$*N*N*g+N*N*N*L.x,_=$*$*$*A.y+3*$*$*N*b+3*$*N*N*x+N*N*N*L.y,P.jsx(sn,{id:t,path:X,labelX:D,labelY:_,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,interactionWidth:j})});Vn.displayName="BezierEdge";function Jn({sourceX:e,sourceY:t,targetX:n,targetY:r}){const a=`M ${e},${t}L ${n},${r}`,o=(e+n)/2,i=(t+r)/2;return[a,o,i,0,0]}function Kn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a="right",targetPosition:o="left",curvature:i=.25}){const f=Math.abs(n-e),p=Math.abs(r-t),d=Math.sqrt(f*f+p*p),h=Math.max(d*i,50);let v,E,M,z;switch(a){case"top":v=e,E=t-h;break;case"bottom":v=e,E=t+h;break;case"left":v=e-h,E=t;break;default:v=e+h,E=t;break}switch(o){case"top":M=n,z=r-h;break;case"bottom":M=n,z=r+h;break;case"right":M=n+h,z=r;break;default:M=n-h,z=r;break}const I=`M ${e},${t} C ${v},${E} ${M},${z} ${n},${r}`,k=.5,j=1-k,X=j*j*j*e+3*j*j*k*v+3*j*k*k*M+k*k*k*n,D=j*j*j*t+3*j*j*k*E+3*j*k*k*z+k*k*k*r;return[I,X,D,0,0]}function er({sourceX:e,sourceY:t,targetX:n,targetY:r}){const a=Math.abs(n-e),o=Math.max(a*.5,50),i=e+o,f=n-o,p=`M ${e},${t} C ${i},${t} ${f},${r} ${n},${r}`,d=.5,h=.5,v=h*h*h*e+3*h*h*d*i+3*h*d*d*f+d*d*d*n,E=h*h*h*t+3*h*h*d*t+3*h*d*d*r+d*d*d*r;return[p,v,E,0,0]}function vn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a="right",targetPosition:o="left",borderRadius:i=5,offset:f=20}){const p=a==="left"||a==="right",d=Math.min(i,Math.abs(n-e)/2,Math.abs(r-t)/2);if(p){if(Math.abs(r-t)<1)return[`M ${e},${t} L ${n},${r}`,(e+n)/2,t,0,0];const M=(e+n)/2,z=r>t?1:-1;return[`M ${e},${t} L ${M-d},${t} Q ${M},${t} ${M},${t+z*d} L ${M},${r-z*d} Q ${M},${r} ${M+(n>M?d:-d)},${r} L ${n},${r}`,M,(t+r)/2,0,0]}const h=(t+r)/2,v=n>e?1:-1;return[`M ${e},${t} L ${e},${h-d} Q ${e},${h} ${e+v*d},${h} L ${n-v*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[,a,o]=Kn({sourceX:e,sourceY:t,targetX:n,targetY:r});return[a,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),a={...e,id:e.id,source:t.source,target:t.target,sourceHandle:t.sourceHandle??e.sourceHandle,targetHandle:t.targetHandle??e.targetHandle};return r.push(a),r}const bn=160,wn=60,tn=20,pn=12,Mn=20;function hr(e,t,n){var i,f;const r=e.width||((i=e.measured)==null?void 0:i.width)||bn,a=e.height||((f=e.measured)==null?void 0:f.height)||wn,o=e._absolutePosition||e.position;if(e.handles&&e.handles.length>0){for(const p of e.handles)if(p.type===t&&(!n||p.id===n)){if(p.x!==void 0&&p.y!==void 0)return{x:o.x+p.x,y:o.y+p.y,dir:p.position||(t==="source"?"right":"left")};switch(p.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+a,dir:"bottom"};case"left":return{x:o.x,y:o.y+a/2,dir:"left"};default:return{x:o.x+r,y:o.y+a/2,dir:"right"}}}}return t==="source"?{x:o.x+r,y:o.y+a/2,dir:"right"}:{x:o.x,y:o.y+a/2,dir:"left"}}function Rn(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,a,o,i,f){const p=Math.min(e,n),d=Math.max(e,n),h=Math.min(t,r),v=Math.max(t,r);if(d<=a||p>=a+i||v<=o||h>=o+f)return!1;const E=.5;if(e>a+E&&e<a+i-E&&t>o+E&&t<o+f-E||n>a+E&&n<a+i-E&&r>o+E&&r<o+f-E)return!0;const M=(e+n)/2,z=(t+r)/2;if(M>a+E&&M<a+i-E&&z>o+E&&z<o+f-E)return!0;const I=[[a,o],[a+i,o],[a+i,o+f],[a,o+f]];for(let k=0;k<4;k++)if(ko(e,t,n,r,I[k][0],I[k][1],I[(k+1)%4][0],I[(k+1)%4][1]))return!0;return!1}function ko(e,t,n,r,a,o,i,f){const p=(i-a)*(t-o)-(f-o)*(e-a),d=(i-a)*(r-o)-(f-o)*(n-a),h=(n-e)*(o-t)-(r-t)*(a-e),v=(n-e)*(f-t)-(r-t)*(i-e);return(p>0&&d<0||p<0&&d>0)&&(h>0&&v<0||h<0&&v>0)}function Gn(e,t,n,r,a){for(let o=0;o<a.length;o++){const i=a[o];if(Ro(e,t,n,r,i.x,i.y,i.w,i.h))return!1}return!0}function Co(e,t,n){for(let r=0;r<n.length;r++){const a=n[r];if(e>a.x&&e<a.x+a.w&&t>a.y&&t<a.y+a.h)return!0}return!1}function tr(e,t){var r,a;const n=[];for(let o=0;o<e.length;o++){const i=e[o];if(i.hidden||t&&t.has(i.id)||i.type==="group")continue;const f=i._absolutePosition||i.position,p=i.width||((r=i.measured)==null?void 0:r.width)||bn,d=i.height||((a=i.measured)==null?void 0:a.height)||wn;n.push({id:i.id,x:f.x-tn,y:f.y-tn,w:p+2*tn,h:d+2*tn})}return n}function Lr(e,t,n){if(Gn(e.x,e.y,t.x,t.y,n))return null;const r=new Set,a=new Set;r.add(e.x),r.add(t.x),a.add(e.y),a.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"?a.add(e.y-o):e.dir==="bottom"&&a.add(e.y+o),t.dir==="right"?r.add(t.x+o):t.dir==="left"?r.add(t.x-o):t.dir==="top"?a.add(t.y-o):t.dir==="bottom"&&a.add(t.y+o);for(let g=0;g<n.length;g++){const x=n[g];r.add(x.x),r.add(x.x+x.w),a.add(x.y),a.add(x.y+x.h)}const i=[...r].sort((g,x)=>g-x),f=[...a].sort((g,x)=>g-x),p=new Map,d=new Map;for(let g=0;g<i.length;g++)p.set(i[g],g);for(let g=0;g<f.length;g++)d.set(f[g],g);const h=i.length,v=f.length,E=(g,x)=>x*h+g,M=p.get(e.x),z=d.get(e.y),I=p.get(t.x),k=d.get(t.y);if(M===void 0||z===void 0||I===void 0||k===void 0)return null;const j=E(M,z),X=E(I,k),D=new Float64Array(h*v).fill(1/0),_=new Float64Array(h*v).fill(1/0),A=new Int32Array(h*v).fill(-1),L=new Int8Array(h*v).fill(-1),Y=new Uint8Array(h*v);D[j]=0,_[j]=Math.abs(i[I]-e.x)+Math.abs(f[k]-e.y);const F=[j],B=15,b=[[1,0],[-1,0],[0,1],[0,-1]];for(;F.length>0;){let g=0;for(let ee=1;ee<F.length;ee++)_[F[ee]]<_[F[g]]&&(g=ee);const x=F[g];if(F[g]=F[F.length-1],F.pop(),x===X){const ee=[];let oe=X;for(;oe!==-1&&oe!==j;){const ge=oe/h|0,ye=oe%h;ee.unshift({x:i[ye],y:f[ge]}),oe=A[oe]}return ee.unshift({x:e.x,y:e.y}),Eo(ee,n)}if(Y[x])continue;Y[x]=1;const N=x/h|0,$=x%h,W=i[$],V=f[N],re=L[x];for(let ee=0;ee<4;ee++){const oe=$+b[ee][0],ge=N+b[ee][1];if(oe<0||oe>=h||ge<0||ge>=v)continue;const ye=E(oe,ge);if(Y[ye])continue;const J=i[oe],fe=f[ge];if(Co(J,fe,n)||!Gn(W,V,J,fe,n))continue;const me=Math.abs(J-W)+Math.abs(fe-V),ae=re>=0&&re!==ee?B:0,ue=D[x]+me+ae;ue<D[ye]&&(A[ye]=x,L[ye]=ee,D[ye]=ue,_[ye]=ue+Math.abs(i[I]-J)+Math.abs(f[k]-fe),F.push(ye))}}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 a=n[n.length-1],o=e[r],i=e[r+1],f=Math.abs(a.x-o.x)<.5&&Math.abs(o.x-i.x)<.5,p=Math.abs(a.y-o.y)<.5&&Math.abs(o.y-i.y)<.5;(f||p)&&Gn(a.x,a.y,i.x,i.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 a of e){const o=a._routedPoints;if(!(!o||o.length<2))for(let i=0;i<o.length-1;i++){const f=o[i],p=o[i+1];if(Math.abs(f.y-p.y)<.5){const d=Math.round(f.y*10)/10;t.has(d)||t.set(d,[]),t.get(d).push({edgeId:a.id,segIdx:i,x1:Math.min(f.x,p.x),x2:Math.max(f.x,p.x)})}else if(Math.abs(f.x-p.x)<.5){const d=Math.round(f.x*10)/10;n.has(d)||n.set(d,[]),n.get(d).push({edgeId:a.id,segIdx:i,y1:Math.min(f.y,p.y),y2:Math.max(f.y,p.y)})}}}const r=new Map;for(const a of e)a._routedPoints&&r.set(a.id,a._routedPoints.map(o=>({...o})));for(const[,a]of t){if(a.length<2)continue;const o=gr(a,"x1","x2");for(const i of o){if(i.length<2)continue;const f=(i.length-1)*pn/2;for(let p=0;p<i.length;p++){const d=i[p],h=-f+p*pn,v=r.get(d.edgeId);v&&(v[d.segIdx].y+=h,v[d.segIdx+1].y+=h)}}}for(const[,a]of n){if(a.length<2)continue;const o=gr(a,"y1","y2");for(const i of o){if(i.length<2)continue;const f=(i.length-1)*pn/2;for(let p=0;p<i.length;p++){const d=i[p],h=-f+p*pn,v=r.get(d.edgeId);v&&(v[d.segIdx].x+=h,v[d.segIdx+1].x+=h)}}}return e.map(a=>{const o=r.get(a.id);return o?{...a,_routedPoints:o}:a})}function gr(e,t,n){if(e.length<2)return[];const r=[...e].sort((i,f)=>i[t]-f[t]),a=[];let o=[r[0]];for(let i=1;i<r.length;i++){const f=o[o.length-1];r[i][t]<f[n]?o.push(r[i]):(o.length>1&&a.push(o),o=[r[i]])}return o.length>1&&a.push(o),a}function kn(e,t=6,n=!1){if(!e||e.length<2)return null;if(n)return So(e);const r=t;let a=`M ${e[0].x},${e[0].y}`;for(let o=1;o<e.length-1;o++){const i=e[o-1],f=e[o],p=e[o+1],d=Math.abs(f.x-i.x)+Math.abs(f.y-i.y),h=Math.abs(p.x-f.x)+Math.abs(p.y-f.y),v=Math.min(r,d/2,h/2);if(v>.5){const E=f.x-i.x,M=f.y-i.y,z=p.x-f.x,I=p.y-f.y,k=Math.sqrt(E*E+M*M)||1,j=Math.sqrt(z*z+I*I)||1;a+=` L ${f.x-E/k*v},${f.y-M/k*v}`,a+=` Q ${f.x},${f.y} ${f.x+z/j*v},${f.y+I/j*v}`}else a+=` L ${f.x},${f.y}`}return a+=` L ${e[e.length-1].x},${e[e.length-1].y}`,a}function So(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 a=e[r===0?0:r-1],o=e[r],i=e[r+1],f=e[r+2<e.length?r+2:e.length-1],p=o.x+(i.x-a.x)*t,d=o.y+(i.y-a.y)*t,h=i.x-(f.x-o.x)*t,v=i.y-(f.y-o.y)*t;n+=` C ${p},${d} ${h},${v} ${i.x},${i.y}`}return n}function Cn(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 a=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);if(n<=a){const o=a>0?n/a: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-=a}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=tr(e,null),a=t.map(o=>{var L,Y,F,B;const i=o.type||"default";if(i==="bezier"||i==="simplebezier"||i==="default")return o;const f=n[o.source],p=n[o.target];if(!f||!p||f.hidden||p.hidden)return o;const d=hr(f,"source",o.sourceHandle),h=hr(p,"target",o.targetHandle),v=Rn(d,Mn),E=Rn(h,Mn),M=5,z=r.filter(b=>b.id!==o.source&&b.id!==o.target),I=f._absolutePosition||f.position,k=f.width||((L=f.measured)==null?void 0:L.width)||bn,j=f.height||((Y=f.measured)==null?void 0:Y.height)||wn;z.push({id:o.source,x:I.x-M,y:I.y-M,w:k+2*M,h:j+2*M});const X=p._absolutePosition||p.position,D=p.width||((F=p.measured)==null?void 0:F.width)||bn,_=p.height||((B=p.measured)==null?void 0:B.height)||wn;if(z.push({id:o.target,x:X.x-M,y:X.y-M,w:D+2*M,h:_+2*M}),z.length===0)return o;const A=Lr(v,E,z);return A&&A.length>=2?(A.unshift({x:d.x,y:d.y}),A.push({x:h.x,y:h.y}),{...o,_routedPoints:A}):o});return zo(a)}function Po(e,t,n,r,a,o,i,f){const p=tr(i,f?new Set(f):null);if(p.length===0)return null;const d={x:e,y:t,dir:a||"right"},h={x:n,y:r,dir:o||"left"},v=Rn(d,Mn),E=Rn(h,Mn),M=Lr(v,E,p);return M&&M.length>=2?(M.unshift({x:d.x,y:d.y}),M.push({x:h.x,y:h.y}),M):null}const nr=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,label:i,labelStyle:f,labelShowBg:p,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:v,style:E,markerEnd:M,markerStart:z,interactionWidth:I,routedPoints:k}){let j,X,D;if(k&&k.length>=2){j=kn(k);const _=Cn(k);X=_.x,D=_.y}else[j,X,D]=Jn({sourceX:n,sourceY:r,targetX:a,targetY:o});return P.jsx(sn,{id:t,path:j,labelX:X,labelY:D,label:i,labelStyle:f,labelShowBg:p,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:v,style:E,markerEnd:M,markerStart:z,interactionWidth:I})});nr.displayName="StraightEdge";const rr=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:i="bottom",targetPosition:f="top",label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,pathOptions:j,interactionWidth:X,routedPoints:D}){let _,A,L;if(D&&D.length>=2){_=kn(D);const Y=Cn(D);A=Y.x,L=Y.y}else[_,A,L]=vn({sourceX:n,sourceY:r,sourcePosition:i,targetX:a,targetY:o,targetPosition:f,borderRadius:j==null?void 0:j.borderRadius,offset:j==null?void 0:j.offset});return P.jsx(sn,{id:t,path:_,labelX:A,labelY:L,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,interactionWidth:X})});rr.displayName="SmoothStepEdge";const Tr=c.memo(function({id:t,...n}){var a;const r=c.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(a=n.pathOptions)==null?void 0:a.offset]);return P.jsx(rr,{...n,id:t,pathOptions:r})});Tr.displayName="StepEdge";const or=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:i,targetPosition:f,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,interactionWidth:j,routedPoints:X}){let D,_,A;if(X&&X.length>=2){D=kn(X);const L=Cn(X);_=L.x,A=L.y}else[D,_,A]=er({sourceX:n,sourceY:r,targetX:a,targetY:o});return P.jsx(sn,{id:t,path:D,labelX:_,labelY:A,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,interactionWidth:j})});or.displayName="SimpleBezierEdge";const Io={input:zr,output:Sr,group:Nr},Lo={bezier:Vn,straight:nr,simplebezier:or},To=160,$o=60;function Bo(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,a;return((r=n.measured)==null?void 0:r.width)!=null&&((a=n.measured)==null?void 0:a.height)!=null?n:{...n,measured:{width:n.width||To,height:n.height||$o}}}):e}function jo({cards:e,nodes:t=[],edges:n=[],nodeTypes:r,edgeTypes:a,dark:o,gridSize:i,width:f="100%",height:p="420px",className:d="",style:h={},zoomMin:v,zoomMax:E,initialCamera:M,fitView:z,fitViewOptions:I,onNodesChange:k,onEdgesChange:j,onConnect:X,onConnectStart:D,onConnectEnd:_,onNodeClick:A,onNodeDoubleClick:L,onNodeMouseEnter:Y,onNodeMouseMove:F,onNodeMouseLeave:B,onNodeContextMenu:b,onNodeDragStart:g,onNodeDrag:x,onNodeDragStop:N,onEdgeClick:$,onEdgeDoubleClick:W,onEdgeMouseEnter:V,onEdgeMouseMove:re,onEdgeMouseLeave:ee,onEdgeContextMenu:oe,onPaneClick:ge,onPaneContextMenu:ye,onPaneMouseEnter:J,onPaneMouseMove:fe,onPaneMouseLeave:me,onSelectionChange:ae,onInit:ue,onMoveStart:Ne,onMove:Je,onMoveEnd:le,onDelete:Be,onBeforeDelete:je,onError:_e,onDragOver:he,onDrop:Me,onDragEnter:Oe,onDragLeave:Ae,nodesDraggable:ct,nodesConnectable:zt,elementsSelectable:De,multiSelectionKeyCode:Xe,selectionOnDrag:Ze,selectionMode:St,connectionMode:an,connectionRadius:At,connectOnClick:cn,isValidConnection:un,defaultEdgeOptions:ln,snapToGrid:dn,snapGrid:Dt,deleteKeyCode:dt,panActivationKeyCode:ft,panOnScroll:Nt,panOnScrollMode:En,panOnScrollSpeed:zn,zoomOnScroll:ot,zoomOnDoubleClick:sr,zoomOnPinch:Sn,preventScrolling:Nn,translateExtent:Pt,nodeExtent:It,autoPanOnNodeDrag:Pn,autoPanOnConnect:In,autoPanSpeed:Ln,edgesReconnectable:ht,elevateNodesOnSelect:pe,elevateEdgesOnSelect:Ht,noDragClassName:Ee,noPanClassName:ie,onSelectionDragStart:gt,onSelectionDrag:K,onSelectionDragStop:Re,edgeRouting:fn=!0,onHudUpdate:ut,onNodesProcessed:Lt,showHud:Tn=!0,showHint:$n=!0,hintText:We="Drag to pan · Scroll to zoom",children:Ye,..._t}){const[He,Wt]=c.useState({wx:0,wy:0,zoom:"1.00"}),Mt=c.useRef(null),Ft=c.useRef(null),Bn=c.useCallback(G=>{Wt(G),ut==null||ut(G)},[ut]),yt=c.useMemo(()=>({...Io,...r}),[r]),xt=c.useMemo(()=>({...Lo,...a}),[a]),tt=c.useMemo(()=>Bo(t),[t]),Ke=c.useMemo(()=>{const G=tt.filter(Ie=>Ie.type&&yt[Ie.type]&&(Ie.selected||Ie.dragging));return G.sort((Ie,ve)=>{const Le=Ie.type==="group"||!Ie.parentId&&G.some(ce=>ce.parentId===Ie.id),at=ve.type==="group"||!ve.parentId&&G.some(ce=>ce.parentId===ve.id);return Le&&!at?-1:!Le&&at?1:0})},[tt,yt]),Tt=c.useMemo(()=>n.filter(G=>G.type&&xt[G.type]),[n,xt]),O=c.useMemo(()=>t.map(G=>G.type&&yt[G.type]&&(G.selected||G.dragging)?{...G,_customRendered:!0}:G),[t,yt]),pt=c.useMemo(()=>n.map(G=>G.type&&xt[G.type]?{...G,_customRendered:!0}:G),[n,xt]),{wrapRef:$t,canvasRef:Xt,canvasReady:Yt,onPointerDown:qt,onPointerMove:Ut,onPointerUp:Ot,store:we}=br({cards:e,nodes:O,edges:pt,dark:o,gridSize:i,zoomMin:v,zoomMax:E,initialCamera:M,fitView:z,fitViewOptions:I,onHudUpdate:Bn,onNodesProcessed:Lt,onNodesChange:k,onEdgesChange:j,onConnect:X,onConnectStart:D,onConnectEnd:_,onNodeClick:A,onNodeDoubleClick:L,onNodeMouseEnter:Y,onNodeMouseMove:F,onNodeMouseLeave:B,onNodeContextMenu:b,onNodeDragStart:g,onNodeDrag:x,onNodeDragStop:N,onEdgeClick:$,onEdgeDoubleClick:W,onEdgeMouseEnter:V,onEdgeMouseMove:re,onEdgeMouseLeave:ee,onEdgeContextMenu:oe,onPaneClick:ge,onPaneContextMenu:ye,onPaneMouseEnter:J,onPaneMouseMove:fe,onPaneMouseLeave:me,onSelectionChange:ae,onInit:ue,onMoveStart:Ne,onMove:Je,onMoveEnd:le,onDelete:Be,onBeforeDelete:je,onError:_e,nodesDraggable:ct,nodesConnectable:zt,elementsSelectable:De,multiSelectionKeyCode:Xe,selectionOnDrag:Ze,selectionMode:St,connectionMode:an,connectionRadius:At,connectOnClick:cn,isValidConnection:un,defaultEdgeOptions:ln,snapToGrid:dn,snapGrid:Dt,deleteKeyCode:dt,panActivationKeyCode:ft,panOnScroll:Nt,panOnScrollMode:En,panOnScrollSpeed:zn,zoomOnScroll:ot,zoomOnDoubleClick:sr,zoomOnPinch:Sn,preventScrolling:Nn,translateExtent:Pt,nodeExtent:It,autoPanOnNodeDrag:Pn,autoPanOnConnect:In,autoPanSpeed:Ln,edgesReconnectable:ht,elevateNodesOnSelect:pe,elevateEdgesOnSelect:Ht,noDragClassName:Ee,noPanClassName:ie,onSelectionDragStart:gt,onSelectionDrag:K,onSelectionDragStop:Re,edgeRouting:fn}),mt=c.useContext(Et),Bt=mt&&typeof mt.getState=="function";c.useEffect(()=>{Bt&&queueMicrotask(()=>{mt.setState({nodes:tt,edges:n,nodesRef:we.nodesRef,edgesRef:we.edgesRef,onNodesChangeRef:we.onNodesChangeRef,onEdgesChangeRef:we.onEdgesChangeRef,cameraRef:we.cameraRef,wrapRef:we.wrapRef,workerRef:we.workerRef})})},[Bt,tt,n,we,mt]);const ze=c.useMemo(()=>({...we,edgeLabelContainerRef:Mt,viewportPortalRef:Ft,get nodes(){return tt},get edges(){return n},get viewport(){return we.cameraRef.current},get minZoom(){return we.zoomMin||.1},get maxZoom(){return we.zoomMax||5},get domNode(){return we.wrapRef.current},get width(){var G;return((G=we.wrapRef.current)==null?void 0:G.clientWidth)||0},get height(){var G;return((G=we.wrapRef.current)==null?void 0:G.clientHeight)||0}}),[we,tt,n]),Zt=c.useRef(null),Pe=c.useRef(null),Gt=c.useRef(null),st=c.useRef(null),Rt=c.useRef(null);c.useEffect(()=>{let G;const Ie=()=>{const ve=we.cameraRef.current,Le=`translate(${ve.x}px, ${ve.y}px) scale(${ve.zoom})`,at=`translate(${ve.x}, ${ve.y}) scale(${ve.zoom})`;Zt.current&&(Zt.current.style.transform=Le),Pe.current&&Pe.current.setAttribute("transform",at),Gt.current&&(Gt.current.style.transform=Le),st.current&&(st.current.style.transform=Le);const ce=$t.current;if(ce){const Ge=ve.zoom<.15?"lod-minimal":ve.zoom<.35?"lod-reduced":null;Ge!==Rt.current&&(ce.classList.remove("lod-minimal","lod-reduced"),Ge&&ce.classList.add(Ge),Rt.current=Ge)}G=requestAnimationFrame(Ie)};return G=requestAnimationFrame(Ie),()=>cancelAnimationFrame(G)},[we]);const[et,vt]=c.useState(null);c.useEffect(()=>{if(!Ke.length)return;let G;const Ie=()=>{var Qt,gn;const ve=we.cameraRef.current,Le=we.wrapRef.current;if(!Le){G=requestAnimationFrame(Ie);return}const at=Le.getBoundingClientRect(),ce=200,Ge=-ve.x/ve.zoom-ce,bt=-ve.y/ve.zoom-ce,jn=(at.width-ve.x)/ve.zoom+ce,An=(at.height-ve.y)/ve.zoom+ce,kt=new Set;for(const qe of Ke){const wt=qe._absolutePosition||qe.position,Dn=qe.width||((Qt=qe.measured)==null?void 0:Qt.width)||200,Hn=qe.height||((gn=qe.measured)==null?void 0:gn.height)||100;wt.x+Dn>=Ge&&wt.x<=jn&&wt.y+Hn>=bt&&wt.y<=An&&kt.add(qe.id)}vt(qe=>{if(!qe||qe.size!==kt.size)return kt;for(const wt of kt)if(!qe.has(wt))return kt;return qe}),G=requestAnimationFrame(Ie)};return G=requestAnimationFrame(Ie),()=>cancelAnimationFrame(G)},[Ke,we]);const hn=c.useMemo(()=>et?Ke.filter(G=>et.has(G.id)):Ke,[Ke,et]),Se=Ke.length>0,nt=Tt.length>0;return P.jsx(Et.Provider,{value:ze,children:P.jsxs("div",{ref:$t,className:`ric-wrap ${d}`,style:{width:f,height:p,...h},onPointerDown:qt,onPointerMove:Ut,onPointerUp:Ot,onDragOver:he,onDrop:Me,onDragEnter:Oe,onDragLeave:Ae,tabIndex:0,children:[P.jsx("canvas",{ref:Xt,className:"ric-canvas"}),!Yt&&P.jsx("div",{className:"ric-loader",children:P.jsx("div",{className:"ric-spinner"})}),nt&&P.jsx("svg",{className:"ric-edges-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:P.jsx("g",{ref:Pe,children:Tt.map(G=>P.jsx(yo,{edge:G,edgeType:xt[G.type],nodes:t,reconnectable:ht},G.id))})}),Se&&P.jsx("div",{ref:Zt,className:"ric-nodes-overlay",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:10},children:hn.map(G=>P.jsx(lo,{node:G,nodeType:yt[G.type]},G.id))}),P.jsx("div",{ref:G=>{Mt.current=G,Gt.current=G},className:"ric-edge-labels",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:5}}),P.jsx("div",{ref:G=>{Ft.current=G,st.current=G},className:"ric-viewport-portal",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:6}}),$n&&P.jsx("div",{className:"ric-hint",children:We}),Tn&&P.jsxs("div",{className:"ric-info",children:["world: (",He.wx,", ",He.wy,") zoom: ",He.zoom,"x",He.nodeCount>0&&P.jsxs(P.Fragment,{children:[" nodes: ",He.nodeCount]}),He.edgeCount>0&&P.jsxs(P.Fragment,{children:[" edges: ",He.edgeCount]})]}),P.jsx(Cr,{selectionKeyCode:Xe||"Shift",selectionMode:St||"partial"}),Ye]})})}function Ao({children:e}){const t=c.useRef(null);return t.current||(t.current=io()),P.jsx(Et.Provider,{value:t.current,children:e})}function $r(e,t){const n=[],r=new Map,a=[];for(const o of e)if(o.type==="add")a.push(o);else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const i=r.get(o.id);i?i.push(o):r.set(o.id,[o])}for(const o of t){const i=r.get(o.id);if(!i){n.push(o);continue}if(i[0].type==="remove")continue;if(i[0].type==="replace"){n.push({...i[0].item});continue}const f={...o};for(const p of i)Do(p,f);n.push(f)}for(const o of a)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 Br(e,t){return $r(e,t)}function jr(e,t){return $r(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]=c.useState(e),r=c.useCallback(a=>n(o=>Br(a,o)),[]);return[t,n,r]}function Wo(e){const[t,n]=c.useState(e),r=c.useCallback(a=>n(o=>jr(a,o)),[]);return[t,n,r]}function Ar(){const e=wr(),t=c.useCallback(()=>typeof e.getState=="function"?e.getState():e,[e]),n=c.useCallback(()=>[...t().nodesRef.current],[t]),r=c.useCallback(()=>[...t().edgesRef.current],[t]),a=c.useCallback(b=>t().nodesRef.current.find(g=>g.id===b),[t]),o=c.useCallback(b=>t().edgesRef.current.find(g=>g.id===b),[t]),i=c.useCallback(b=>{var g,x,N,$;if(typeof b=="function"){const W=b(t().nodesRef.current);(x=(g=t().onNodesChangeRef).current)==null||x.call(g,[...t().nodesRef.current.map(V=>({id:V.id,type:"remove"})),...W.map(V=>({type:"add",item:V}))])}else($=(N=t().onNodesChangeRef).current)==null||$.call(N,[...t().nodesRef.current.map(W=>({id:W.id,type:"remove"})),...b.map(W=>({type:"add",item:W}))])},[t]),f=c.useCallback(b=>{var g,x,N,$;if(typeof b=="function"){const W=b(t().edgesRef.current);(x=(g=t().onEdgesChangeRef).current)==null||x.call(g,[...t().edgesRef.current.map(V=>({id:V.id,type:"remove"})),...W.map(V=>({type:"add",item:V}))])}else($=(N=t().onEdgesChangeRef).current)==null||$.call(N,[...t().edgesRef.current.map(W=>({id:W.id,type:"remove"})),...b.map(W=>({type:"add",item:W}))])},[t]),p=c.useCallback(b=>{var x,N;const g=Array.isArray(b)?b:[b];(N=(x=t().onNodesChangeRef).current)==null||N.call(x,g.map($=>({type:"add",item:$})))},[t]),d=c.useCallback(b=>{var x,N;const g=Array.isArray(b)?b:[b];(N=(x=t().onEdgesChangeRef).current)==null||N.call(x,g.map($=>({type:"add",item:$})))},[t]),h=c.useCallback(({nodes:b=[],edges:g=[]})=>{if(b.length&&t().onNodesChangeRef.current){t().onNodesChangeRef.current(b.map(N=>({id:N.id,type:"remove"})));const x=mr(b,t().edgesRef.current);x.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(x.map(N=>({id:N.id,type:"remove"})))}g.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(g.map(x=>({id:x.id,type:"remove"})))},[t]),v=c.useCallback(()=>{const b=t().cameraRef.current;return{x:b.x,y:b.y,zoom:b.zoom}},[t]),E=c.useRef(null),M=c.useCallback((b,g)=>{if(E.current&&cancelAnimationFrame(E.current),!g||g<=0){t().cameraRef.current={...b},t().sendCamera();return}const x={...t().cameraRef.current},N=performance.now(),$=W=>{const V=W-N,re=Math.min(V/g,1),ee=1-Math.pow(1-re,3);t().cameraRef.current={x:x.x+(b.x-x.x)*ee,y:x.y+(b.y-x.y)*ee,zoom:x.zoom+(b.zoom-x.zoom)*ee},t().sendCamera(),re<1&&(E.current=requestAnimationFrame($))};E.current=requestAnimationFrame($)},[t]),z=c.useCallback((b,g)=>{const x={x:b.x??t().cameraRef.current.x,y:b.y??t().cameraRef.current.y,zoom:b.zoom??t().cameraRef.current.zoom};M(x,g==null?void 0:g.duration)},[t,M]),I=c.useCallback(()=>t().cameraRef.current.zoom,[t]),k=c.useCallback(b=>{const g=t().cameraRef.current,x=t().wrapRef.current;if(!x)return;const N=x.getBoundingClientRect(),$=N.width/2,W=N.height/2,V=1.2,re={x:$-($-g.x)*V,y:W-(W-g.y)*V,zoom:Math.min(t().zoomMax,g.zoom*V)};M(re,b==null?void 0:b.duration)},[t,M]),j=c.useCallback(b=>{const g=t().cameraRef.current,x=t().wrapRef.current;if(!x)return;const N=x.getBoundingClientRect(),$=N.width/2,W=N.height/2,V=1/1.2,re={x:$-($-g.x)*V,y:W-(W-g.y)*V,zoom:Math.max(t().zoomMin,g.zoom*V)};M(re,b==null?void 0:b.duration)},[t,M]),X=c.useCallback((b,g)=>{const x=t().cameraRef.current,N=t().wrapRef.current;if(!N)return;const $=N.getBoundingClientRect(),W=$.width/2,V=$.height/2,re=Math.min(t().zoomMax,Math.max(t().zoomMin,b)),ee=re/x.zoom,oe={x:W-(W-x.x)*ee,y:V-(V-x.y)*ee,zoom:re};M(oe,g==null?void 0:g.duration)},[t,M]),D=c.useCallback((b={})=>{const g=t().nodesRef.current;if(!g.length)return;const x=t().wrapRef.current;if(!x)return;const N=x.getBoundingClientRect(),$=b.padding??.1,W=b.nodes?g.filter(ee=>b.nodes.some(oe=>oe.id===ee.id)):g;if(!W.length)return;const V=mn(W),re=jt(V,N.width,N.height,$);b.maxZoom&&(re.zoom=Math.min(re.zoom,b.maxZoom)),b.minZoom&&(re.zoom=Math.max(re.zoom,b.minZoom)),M(re,b.duration)},[t,M]),_=c.useCallback((b,g={})=>{const x=t().wrapRef.current;if(!x)return;const N=x.getBoundingClientRect(),$=g.padding??.1,W=jt(b,N.width,N.height,$);g.maxZoom&&(W.zoom=Math.min(W.zoom,g.maxZoom)),g.minZoom&&(W.zoom=Math.max(W.zoom,g.minZoom)),M(W,g.duration)},[t,M]),A=c.useCallback((b,g,x={})=>{const N=t().wrapRef.current;if(!N)return;const $=N.getBoundingClientRect(),W=x.zoom??t().cameraRef.current.zoom,V={x:$.width/2-b*W,y:$.height/2-g*W,zoom:W};M(V,x.duration)},[t,M]),L=c.useCallback(()=>({nodes:[...t().nodesRef.current],edges:[...t().edgesRef.current],viewport:{...t().cameraRef.current}}),[t]),Y=c.useCallback(b=>t().screenToWorld(b.x,b.y),[t]),F=c.useCallback(b=>{const g=t().cameraRef.current,x=t().wrapRef.current;if(!x)return{x:0,y:0};const N=x.getBoundingClientRect();return{x:b.x*g.zoom+g.x+N.left,y:b.y*g.zoom+g.y+N.top}},[t]),B=c.useCallback((b,g)=>{var $,W;const x=t().nodesRef.current.find(V=>V.id===b);if(!x)return;const N=typeof g=="function"?g(x.data):{...x.data,...g};(W=($=t().onNodesChangeRef).current)==null||W.call($,[{id:b,type:"replace",item:{...x,data:N}}])},[t]);return{getNodes:n,getEdges:r,getNode:a,getEdge:o,setNodes:i,setEdges:f,addNodes:p,addEdges:d,deleteElements:h,getViewport:v,setViewport:z,getZoom:I,zoomIn:k,zoomOut:j,zoomTo:X,fitView:D,fitBounds:_,setCenter:A,screenToFlowPosition:Y,flowToScreenPosition:F,updateNodeData:B,toObject:L}}function Fo(){return Ce().nodes}function Xo(){return Ce().edges}function Yo(){return Ce().viewport}function qo(){return Ce().connection}function Uo(e){const t=Ce(),n=Array.isArray(e)?e:[e];return c.useMemo(()=>n.map(r=>{const a=t.nodes.find(o=>o.id===r);return a?{id:a.id,type:a.type,data:a.data}:null}).filter(Boolean),[t.nodes,...n])}function Oo(e){const t=Ce();return c.useMemo(()=>t.edges.filter(n=>n.source===e||n.target===e),[t.edges,e])}function Zo({nodeId:e,type:t,handleId:n}){const r=Ce();return c.useMemo(()=>r.edges.filter(a=>t==="source"?a.source===e&&(n?a.sourceHandle===n:!0):a.target===e&&(n?a.targetHandle===n:!0)),[r.edges,e,t,n])}function Go({onChange:e,onStart:t,onEnd:n}){const r=Ce(),a=c.useRef(e),o=c.useRef(t),i=c.useRef(n);c.useEffect(()=>{a.current=e},[e]),c.useEffect(()=>{o.current=t},[t]),c.useEffect(()=>{i.current=n},[n]),c.useEffect(()=>{const f=p=>{var d;(d=a.current)==null||d.call(a,{x:p.x,y:p.y,zoom:p.zoom})};return r.viewportListeners.add(f),()=>r.viewportListeners.delete(f)},[s])}function Qo({onChange:e}){const t=Ce(),n=c.useRef(e);c.useEffect(()=>{n.current=e},[e]),c.useEffect(()=>{const r=a=>{var o;(o=n.current)==null||o.call(n,a)};return t.selectionListeners.add(r),()=>t.selectionListeners.delete(r)},[s])}function Vo(e){const[t,n]=c.useState(!1),r=Array.isArray(e)?e:[e];return c.useEffect(()=>{const a=i=>{r.includes(i.key)&&n(!0)},o=i=>{r.includes(i.key)&&n(!1)};return window.addEventListener("keydown",a),window.addEventListener("keyup",o),()=>{window.removeEventListener("keydown",a),window.removeEventListener("keyup",o)}},[r.join(",")]),t}function Jo(){const e=Ce();return c.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 Ce(Ko)}function ts(e){const t=Ce();return c.useMemo(()=>t.nodes.find(n=>n.id===e)||void 0,[t.nodes,e])}function ns(e,t){return Ce(e,t)}function rs(){return wr()}function os({maxHistorySize:e=100}={}){const t=Ce(),n=c.useRef([]),r=c.useRef([]),[,a]=c.useState(0),o=c.useRef(null),i=c.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,a(h=>h+1))},[t,e]),f=c.useCallback(()=>{var h,v,E,M;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}))}),(v=(h=s().onNodesChangeRef).current)==null||v.call(h,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...d.nodes.map(z=>({type:"add",item:z}))]),(M=(E=s().onEdgesChangeRef).current)==null||M.call(E,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...d.edges.map(z=>({type:"add",item:z}))]),o.current=d,a(z=>z+1))},[s]),p=c.useCallback(()=>{var h,v,E,M;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}))}),(v=(h=s().onNodesChangeRef).current)==null||v.call(h,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...d.nodes.map(z=>({type:"add",item:z}))]),(M=(E=s().onEdgesChangeRef).current)==null||M.call(E,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...d.edges.map(z=>({type:"add",item:z}))]),o.current=d,a(z=>z+1))},[s]);return{undo:f,redo:p,takeSnapshot:i,canUndo:n.current.length>0,canRedo:r.current.length>0}}function ss(e){const t=c.useRef(e);return c.useEffect(()=>{t.current=e},[e]),c.useCallback(n=>r=>{const a=t.current(r);a!==!1&&a!=null&&n(Array.isArray(a)?a:r)},[])}function as(e){const t=c.useRef(e);return c.useEffect(()=>{t.current=e},[e]),c.useCallback(n=>r=>{const a=t.current(r);a!==!1&&a!=null&&n(Array.isArray(a)?a:r)},[])}const Xn=160,Yn=60;function is({width:e=200,height:t=150,nodeColor:n="#3b82f6",nodeStrokeColor:r="#fff",maskColor:a="rgba(0,0,0,0.1)",style:o={},className:i=""}){const f=Ce(),p=c.useRef(null),d=c.useRef(null),h=c.useCallback(()=>{const v=p.current;if(!v)return;const E=v.getContext("2d"),M=window.devicePixelRatio||1;v.width=e*M,v.height=t*M,E.scale(M,M),E.clearRect(0,0,e,t);const z=f.nodesRef.current;if(!z.length)return;let I=1/0,k=1/0,j=-1/0,X=-1/0;for(const g of z){const x=g.width||Xn,N=g.height||Yn;g.position.x<I&&(I=g.position.x),g.position.y<k&&(k=g.position.y),g.position.x+x>j&&(j=g.position.x+x),g.position.y+N>X&&(X=g.position.y+N)}const D=40;I-=D,k-=D,j+=D,X+=D;const _=j-I,A=X-k,L=Math.min(e/_,t/A),Y=(e-_*L)/2,F=(t-A*L)/2;for(const g of z){if(g.hidden)continue;const x=g.width||Xn,N=g.height||Yn,$=(g.position.x-I)*L+Y,W=(g.position.y-k)*L+F,V=x*L,re=N*L;E.fillStyle=g.selected?"#f59e0b":typeof n=="function"?n(g):n,E.fillRect($,W,Math.max(V,2),Math.max(re,2))}const B=f.cameraRef.current,b=f.wrapRef.current;if(b){const g=b.getBoundingClientRect(),x=-B.x/B.zoom,N=-B.y/B.zoom,$=g.width/B.zoom,W=g.height/B.zoom;E.fillStyle=a,E.fillRect(0,0,e,t);const V=(x-I)*L+Y,re=(N-k)*L+F,ee=$*L,oe=W*L;E.clearRect(V,re,ee,oe);for(const ge of z){if(ge.hidden)continue;const ye=ge.width||Xn,J=ge.height||Yn,fe=(ge.position.x-I)*L+Y,me=(ge.position.y-k)*L+F;E.fillStyle=ge.selected?"#f59e0b":typeof n=="function"?n(ge):n,E.fillRect(fe,me,Math.max(ye*L,2),Math.max(J*L,2))}E.strokeStyle="#3b82f6",E.lineWidth=1.5,E.strokeRect(V,re,ee,oe)}},[f,e,t,n,r,a]);return c.useEffect(()=>{let v=!0;function E(){v&&(h(),d.current=requestAnimationFrame(E))}const M=setInterval(()=>{cancelAnimationFrame(d.current),d.current=requestAnimationFrame(E)},66);return h(),()=>{v=!1,clearInterval(M),cancelAnimationFrame(d.current)}},[h]),P.jsx("canvas",{ref:p,className:`ric-minimap ${i}`,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 P.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:[P.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),P.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function us(){return P.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:P.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function ls(){return P.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:P.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}function ds(){return P.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:[P.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),P.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function fs(){return P.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:[P.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),P.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})}function nn({children:e,className:t="",...n}){return P.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:a,onZoomOut:o,onFitView:i,onInteractiveChange:f,position:p="bottom-left",orientation:d="vertical",style:h={},className:v="","aria-label":E="Canvas controls",children:M}){const z=Ce(),{zoomIn:I,zoomOut:k,fitView:j,getZoom:X}=Ar(),[D,_]=c.useState(!0),A=X()<=z.zoomMin,L=X()>=z.zoomMax,Y=c.useCallback(()=>{I(),a==null||a()},[I,a]),F=c.useCallback(()=>{k(),o==null||o()},[k,o]),B=c.useCallback(()=>{j(r||{padding:.1}),i==null||i()},[j,r,i]),b=c.useCallback(()=>{const x=!D;_(x),f==null||f(x)},[D,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%)"}}[p]||{bottom:30,left:10};return P.jsxs("div",{className:`ric-controls ${v}`,style:{position:"absolute",display:"flex",flexDirection:d==="horizontal"?"row":"column",gap:2,zIndex:5,...g,...h},role:"toolbar","aria-label":E,children:[e&&P.jsxs(P.Fragment,{children:[P.jsx(nn,{onClick:Y,disabled:L,title:"Zoom in","aria-label":"Zoom in",className:"ric-controls-zoomin",children:P.jsx(cs,{})}),P.jsx(nn,{onClick:F,disabled:A,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:P.jsx(us,{})})]}),t&&P.jsx(nn,{onClick:B,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:P.jsx(ls,{})}),n&&P.jsx(nn,{onClick:b,title:D?"Lock interactivity":"Unlock interactivity","aria-label":D?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:D?P.jsx(fs,{}):P.jsx(ds,{})}),M]})}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=c.memo(hs);function xs({variant:e="lines",gap:t=40,size:n=1,color:r,style:a={},className:o=""}){const i=Ce();return i.workerRef.current&&i.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 a={"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 P.jsx("div",{className:`ric-panel ${n}`,style:{position:"absolute",zIndex:5,pointerEvents:"all",...a,...t},onPointerDown:o=>o.stopPropagation(),children:r})}function ms({minWidth:e=10,minHeight:t=10,maxWidth:n=1/0,maxHeight:r=1/0,isVisible:a=!0,handleStyle:o={},lineStyle:i={},color:f="#3b82f6",onResizeStart:p,onResize:d,onResizeEnd:h}){const v=c.useContext(on),E=Ce(),M=c.useRef(null),z=c.useCallback((j,X)=>{j.stopPropagation(),j.preventDefault();const D=E.nodesRef.current.find(L=>L.id===v);if(!D)return;M.current={direction:X,startX:j.clientX,startY:j.clientY,width:D.width||160,height:D.height||60},p==null||p(j,{width:M.current.width,height:M.current.height});const _=L=>{var N,$;if(!M.current)return;const Y=M.current,F=E.cameraRef.current,B=(L.clientX-Y.startX)/F.zoom,b=(L.clientY-Y.startY)/F.zoom;let g=Y.width,x=Y.height;Y.direction.includes("e")&&(g=Math.min(n,Math.max(e,Y.width+B))),Y.direction.includes("w")&&(g=Math.min(n,Math.max(e,Y.width-B))),Y.direction.includes("s")&&(x=Math.min(r,Math.max(t,Y.height+b))),Y.direction.includes("n")&&(x=Math.min(r,Math.max(t,Y.height-b))),($=(N=E.onNodesChangeRef).current)==null||$.call(N,[{id:v,type:"dimensions",dimensions:{width:g,height:x},setAttributes:!0}]),d==null||d(L,{width:g,height:x})},A=L=>{M.current=null,h==null||h(L,{}),window.removeEventListener("pointermove",_),window.removeEventListener("pointerup",A)};window.addEventListener("pointermove",_),window.addEventListener("pointerup",A)},[v,E,e,t,n,r,p,d,h]);if(!a)return null;const I=8,k={position:"absolute",width:I,height:I,background:f,border:"1px solid #fff",borderRadius:2,zIndex:20,...o};return P.jsxs(P.Fragment,{children:[P.jsx("div",{style:{...k,bottom:-I/2,right:-I/2,cursor:"nwse-resize"},onPointerDown:j=>z(j,"se")}),P.jsx("div",{style:{...k,bottom:-I/2,left:-I/2,cursor:"nesw-resize"},onPointerDown:j=>z(j,"sw")}),P.jsx("div",{style:{...k,top:-I/2,right:-I/2,cursor:"nesw-resize"},onPointerDown:j=>z(j,"ne")}),P.jsx("div",{style:{...k,top:-I/2,left:-I/2,cursor:"nwse-resize"},onPointerDown:j=>z(j,"nw")}),P.jsx("div",{style:{...k,top:"50%",right:-I/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:j=>z(j,"e")}),P.jsx("div",{style:{...k,top:"50%",left:-I/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:j=>z(j,"w")}),P.jsx("div",{style:{...k,left:"50%",top:-I/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:j=>z(j,"n")}),P.jsx("div",{style:{...k,left:"50%",bottom:-I/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:j=>z(j,"s")})]})}function vs({isVisible:e,position:t="top",offset:n=10,align:r="center",children:a,style:o={},className:i=""}){const f=c.useContext(on),d=Ce().nodes.find(E=>E.id===f);if(!(e!==void 0?e:d==null?void 0:d.selected))return null;const v={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 P.jsx("div",{className:`ric-node-toolbar ${i}`,style:{position:"absolute",zIndex:1e3,pointerEvents:"all",...v,...o},onPointerDown:E=>E.stopPropagation(),children:a})}function bs({isVisible:e=!1,x:t=0,y:n=0,alignX:r="center",alignY:a="center",children:o,style:i={},className:f=""}){if(!e)return null;const p=r==="center"?"-50%":r==="right"?"-100%":"0",d=a==="center"?"-50%":a==="bottom"?"-100%":"0";return P.jsx("div",{className:`ric-edge-toolbar ${f}`,style:{position:"absolute",left:t,top:n,transform:`translate(${p}, ${d})`,zIndex:1e3,pointerEvents:"all",...i},children:o})}function ws({children:e}){var r;const n=(r=Ce().edgeLabelContainerRef)==null?void 0:r.current;return n?yr.createPortal(e,n):null}function Ms({children:e}){var r;const n=(r=Ce().viewportPortalRef)==null?void 0:r.current;return n?yr.createPortal(e,n):null}function Dr({fromX:e,fromY:t,toX:n,toY:r,fromPosition:a="right",toPosition:o="left",connectionLineType:i="default",connectionLineStyle:f,connectionLineComponent:p}){if(p)return P.jsx(p,{fromX:e,fromY:t,toX:n,toY:r,fromPosition:a,toPosition:o});let d;switch(i){case"straight":[d]=Jn({sourceX:e,sourceY:t,targetX:n,targetY:r});break;case"step":[d]=vn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o,borderRadius:0});break;case"smoothstep":[d]=vn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o});break;case"simplebezier":[d]=er({sourceX:e,sourceY:t,targetX:n,targetY:r});break;default:[d]=Kn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o});break}return P.jsx("path",{d,fill:"none",className:"ric-connection-line",stroke:"#b1b1b7",strokeWidth:1.5,style:f})}Dr.displayName="ConnectionLine";const Rs=c.memo(Dr),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=Vn;exports.ConnectionLine=Rs;exports.ControlButton=nn;exports.Controls=ys;exports.DefaultNode=vo;exports.EdgeLabelRenderer=ws;exports.EdgeText=Ir;exports.EdgeToolbar=bs;exports.GroupNode=Nr;exports.Handle=rn;exports.InfiniteCanvas=jo;exports.InfiniteCanvasProvider=Ao;exports.InputNode=zr;exports.MarkerType=Cs;exports.MiniMap=is;exports.NodeResizer=ms;exports.NodeToolbar=vs;exports.OutputNode=Sr;exports.Panel=ps;exports.Position=ks;exports.SelectionBox=Cr;exports.SimpleBezierEdge=or;exports.SmoothStepEdge=rr;exports.StepEdge=Tr;exports.StraightEdge=nr;exports.ViewportPortal=Ms;exports.addEdge=Ho;exports.applyEdgeChanges=jr;exports.applyNodeChanges=Br;exports.boxToRect=Qr;exports.buildObstacles=tr;exports.clampPosition=Un;exports.computeRoutedEdges=No;exports.getBezierEdgeCenter=bo;exports.getBezierPath=Kn;exports.getBoundsOfBoxes=Vr;exports.getConnectedEdges=mr;exports.getEdgeCenter=wo;exports.getIncomers=Ur;exports.getNodeDimensions=Qn;exports.getNodesBounds=mn;exports.getNodesInside=Zr;exports.getOutgoers=Or;exports.getOverlappingArea=Jr;exports.getRoutedLabelPosition=Cn;exports.getSimpleBezierPath=er;exports.getSmoothStepPath=vn;exports.getStraightPath=Jn;exports.getViewportForBounds=jt;exports.isEdge=qr;exports.isNode=Yr;exports.nodeToBox=Es;exports.nodeToRect=Kr;exports.reconnectEdge=Mo;exports.rectToBox=Gr;exports.routeSinglePath=Po;exports.routedPointsToPath=kn;exports.snapPosition=qn;exports.useConnection=qo;exports.useEdges=Xo;exports.useEdgesState=Wo;exports.useHandleConnections=Zo;exports.useInfiniteCanvas=br;exports.useInternalNode=ts;exports.useKeyPress=Vo;exports.useNodeConnections=Oo;exports.useNodeId=co;exports.useNodes=Fo;exports.useNodesData=Uo;exports.useNodesInitialized=es;exports.useNodesState=_o;exports.useOnEdgesChangeMiddleware=as;exports.useOnNodesChangeMiddleware=ss;exports.useOnSelectionChange=Qo;exports.useOnViewportChange=Go;exports.useReactFlow=Ar;exports.useStore=ns;exports.useStoreApi=rs;exports.useUndoRedo=os;exports.useUpdateNodeInternals=Jo;exports.useViewport=Yo;
|