@infinit-canvas/react 0.1.24 → 0.1.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/react-infinite-canvas.cjs +2 -2
- package/dist/react-infinite-canvas.js +2233 -2216
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("react/jsx-runtime"),a=require("react"),pr=require("react-dom"),mr=160,vr=60;function Xr(e){return e&&typeof e=="object"&&"position"in e&&"data"in e}function Or(e){return e&&typeof e=="object"&&"source"in e&&"target"in e}function br(e,t){const n=typeof e=="string"?new Set([e]):new Set(Array.isArray(e)?e.map(r=>r.id):[e.id]);return t.filter(r=>n.has(r.source)||n.has(r.target))}function Ur(e,t,n){const r=typeof e=="string"?e:e.id,i=new Set;for(const o of n)o.target===r&&i.add(o.source);return t.filter(o=>i.has(o.id))}function qr(e,t,n){const r=typeof e=="string"?e:e.id,i=new Set;for(const o of n)o.source===r&&i.add(o.target);return t.filter(o=>i.has(o.id))}function Mn(e){if(!e.length)return{x:0,y:0,width:0,height:0};let t=1/0,n=1/0,r=-1/0,i=-1/0;for(const o of e){const l=o.position.x,h=o.position.y,v=o.width||mr,f=o.height||vr;l<t&&(t=l),h<n&&(n=h),l+v>r&&(r=l+v),h+f>i&&(i=h+f)}return{x:t,y:n,width:r-t,height:i-n}}function Xt(e,t,n,r=.1){const i=e.width*(1+r*2),o=e.height*(1+r*2),l=Math.min(t/i,n/o,1),h=e.x+e.width/2,v=e.y+e.height/2;return{x:t/2-h*l,y:n/2-v*l,zoom:l}}function Zn(e,t){return{x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}}function Gn(e,t){return{x:Math.min(Math.max(e.x,t[0][0]),t[1][0]),y:Math.min(Math.max(e.y,t[0][1]),t[1][1])}}function Kn(e){var t,n;return{width:e.width||((t=e.measured)==null?void 0:t.width)||mr,height:e.height||((n=e.measured)==null?void 0:n.height)||vr}}function Zr(e,t,n={x:0,y:0,zoom:1},r=!1){const i=t.x,o=t.y,l=t.x+t.width,h=t.y+t.height;return e.filter(v=>{const{width:f,height:y}=Kn(v),x=v.position.x,R=v.position.y,C=x+f,z=R+y;return r?x<l&&C>i&&R<h&&z>o:x>=i&&C<=l&&R>=o&&z<=h})}function Gr(e){return{x:e.x,y:e.y,x2:e.x+e.width,y2:e.y+e.height}}function Qr(e){return{x:e.x,y:e.y,width:e.x2-e.x,height:e.y2-e.y}}function Jr(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}}function Vr(e,t){const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return n*r}function Kr(e){const{width:t,height:n}=Kn(e);return{x:e.position.x,y:e.position.y,width:t,height:n}}const wr=`var qa = null, r = null, fr = 0, vr = 0, M = { x: 0, y: 0, zoom: 1 }, Y = [], W = [], C = [], F = !1, Ze = 40, We = !1, Nr = "lines", da = 1, Kt = null, lt = null, Tr = null, It = {}, tl = {}, it = {}, Zt = {}, Ia = 0, L = 160, B = 60, Ga = 8, Do = 5;
|
|
2
2
|
function y(a) {
|
|
3
3
|
return a._absolutePosition || a.position;
|
|
4
4
|
}
|
|
@@ -943,4 +943,4 @@ function Ft() {
|
|
|
943
943
|
}
|
|
944
944
|
}
|
|
945
945
|
}
|
|
946
|
-
`,lr=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",wr],{type:"text/javascript;charset=utf-8"});function eo(e){let t;try{if(t=lr&&(self.URL||self.webkitURL).createObjectURL(lr),!t)throw"";const n=new Worker(t,{type:"module",name:e==null?void 0:e.name});return n.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),n}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(wr),{type:"module",name:e==null?void 0:e.name})}}const Xn=new WeakMap;function to(e,t){if(Xn.has(e))return Xn.get(e);const n=e.transferControlToOffscreen(),r=new eo;r.onerror=o=>console.error("[infinite-canvas] worker error:",o.message,o),r.postMessage({type:"init",data:{...t,canvas:n}},[n]);const i={worker:r};return Xn.set(e,i),i}const ft=160,nt=60,no=10;function Mr({cards:e=[],nodes:t=[],edges:n=[],onHudUpdate:r,onNodesProcessed:i,onNodesChange:o,onEdgesChange:c,onConnect:f,onNodeClick:m,onNodeDragStart:d,onNodeDrag:h,onNodeDragStop:b,onEdgeClick:k,onEdgeDoubleClick:S,onEdgeMouseEnter:P,onEdgeMouseMove:F,onEdgeMouseLeave:j,onEdgeContextMenu:A,onNodeDoubleClick:X,onNodeMouseEnter:B,onNodeMouseMove:_,onNodeMouseLeave:$,onNodeContextMenu:N,onPaneClick:O,onPaneContextMenu:U,onPaneMouseEnter:Y,onPaneMouseMove:w,onPaneMouseLeave:g,onSelectionChange:v,onConnectStart:L,onConnectEnd:E,onInit:D,onMoveStart:K,onMove:ae,onMoveEnd:ee,onDelete:oe,onBeforeDelete:ye,onError:we,isValidConnection:Me,dark:le,gridSize:Se=40,zoomMin:se=.1,zoomMax:fe=4,initialCamera:be={x:0,y:0,zoom:1},fitView:We=!1,fitViewOptions:xe,nodesDraggable:ue=!0,nodesConnectable:Te=!0,elementsSelectable:He=!0,multiSelectionKeyCode:Fe="Shift",selectionOnDrag:rt=!1,selectionMode:ht="partial",connectionMode:$e="loose",connectionRadius:Le=20,connectOnClick:ze=!1,snapToGrid:Qe=!1,snapGrid:Je=[15,15],deleteKeyCode:Ae=["Delete","Backspace"],panActivationKeyCode:ot=" ",panOnScroll:zt=!1,panOnScrollMode:De="free",panOnScrollSpeed:et=.5,zoomOnScroll:tt=!0,zoomOnDoubleClick:un=!0,zoomOnPinch:dn=!0,preventScrolling:qt=!0,translateExtent:pt,nodeExtent:mt,defaultEdgeOptions:Pt={},autoPanOnNodeDrag:Nn=!0,autoPanOnConnect:In=!0,autoPanSpeed:st=5,edgesReconnectable:cr=!1,elevateNodesOnSelect:Tn=!1,elevateEdgesOnSelect:Ln=!1,noDragClassName:Nt="nodrag",noPanClassName:It="nopan",onSelectionDragStart:Bn,onSelectionDrag:$n,onSelectionDragStop:jn,edgeRouting:kt=!0}={}){const ve=a.useRef(null),Tt=a.useRef(null),Pe=a.useRef(null),he=a.useRef({...be}),vt=a.useRef([...e]),te=a.useRef([...t]),Ne=a.useRef([...n]),fn=a.useRef(new Map),Lt=a.useRef(!1),Bt=a.useRef(null),[$t,An]=a.useState(!1),Ye=a.useRef(null),Oe=a.useRef(null),jt=a.useRef(null),it=a.useRef(null),hn=a.useRef(!1),Ve=a.useRef(null),[gn,yn]=a.useState({x:be.x,y:be.y,zoom:be.zoom}),[Zt,xn]=a.useState(null),bt=a.useMemo(()=>new Set,[]),at=a.useMemo(()=>new Set,[]),Ke=a.useRef(!1),J=a.useRef({});J.current={onHudUpdate:r,onNodesProcessed:i,onNodesChange:o,onEdgesChange:c,onConnect:f,onNodeClick:m,onNodeDragStart:d,onNodeDrag:h,onNodeDragStop:b,onEdgeClick:k,onEdgeDoubleClick:S,onEdgeMouseEnter:P,onEdgeMouseMove:F,onEdgeMouseLeave:j,onEdgeContextMenu:A,onNodeDoubleClick:X,onNodeMouseEnter:B,onNodeMouseMove:_,onNodeMouseLeave:$,onNodeContextMenu:N,onPaneClick:O,onPaneContextMenu:U,onPaneMouseEnter:Y,onPaneMouseMove:w,onPaneMouseLeave:g,onSelectionChange:v,onConnectStart:L,onConnectEnd:E,onInit:D,onMoveStart:K,onMove:ae,onMoveEnd:ee,onDelete:oe,onBeforeDelete:ye,onError:we,onSelectionDragStart:Bn,onSelectionDrag:$n,onSelectionDragStop:jn,isValidConnection:Me};const ct={get current(){return J.current.onConnect}},Ct={get current(){return J.current.onNodeClick}},At={get current(){return J.current.onNodeDragStart}},Dt={get current(){return J.current.onNodeDrag}},Ht={get current(){return J.current.onNodeDragStop}},wt={get current(){return J.current.onEdgeClick}},_t={get current(){return J.current.onPaneClick}},Wt={get current(){return J.current.onSelectionChange}},Ft={get current(){return J.current.onHudUpdate}},Yt={get current(){return J.current.onNodesProcessed}};a.useEffect(()=>{const u=l=>{l.key===Fe&&(hn.current=!0),l.key===ot&&(Ke.current=!0)},y=l=>{l.key===Fe&&(hn.current=!1),l.key===ot&&(Ke.current=!1)};return window.addEventListener("keydown",u),window.addEventListener("keyup",y),()=>{window.removeEventListener("keydown",u),window.removeEventListener("keyup",y)}},[Fe,ot]);const Ce={get current(){return J.current.onNodesChange?gt:null}},gt=u=>{var l,p,C;(p=(l=J.current).onNodesChange)==null||p.call(l,u);const y=[];for(let z=0;z<u.length;z++)u[z].type==="select"&&y.push({id:u[z].id,selected:u[z].selected});y.length>0&&((C=Pe.current)==null||C.postMessage({type:"nodeSelections",data:{selections:y}}))},_e={get current(){return J.current.onEdgesChange?Dn:null}},Dn=u=>{var l,p,C;(p=(l=J.current).onEdgesChange)==null||p.call(l,u);const y=[];for(let z=0;z<u.length;z++)u[z].type==="select"&&y.push({id:u[z].id,selected:u[z].selected});y.length>0&&((C=Pe.current)==null||C.postMessage({type:"edgeSelections",data:{selections:y}}))},yt=a.useCallback(()=>{var p;const u=te.current.filter(C=>C.selected),y=Ne.current.filter(C=>C.selected),l={nodes:u,edges:y};(p=Wt.current)==null||p.call(Wt,l);for(const C of at)C(l)},[at]);a.useEffect(()=>{var u;vt.current=[...e],(u=Pe.current)==null||u.postMessage({type:"cards",data:{cards:[...e]}})},[e]);const Xt=a.useCallback(u=>{const y={};for(const l of u)y[l.id]=l;return u.map(l=>{if(!l.parentId)return l;const p=y[l.parentId];if(!p)return l;let C=l.position.x,z=l.position.y,x=p;for(;x;)C+=x.position.x,z+=x.position.y,x=x.parentId?y[x.parentId]:null;return{...l,_absolutePosition:{x:C,y:z}}})},[]),lt=a.useRef([]),Mt=a.useCallback(u=>{const y=fn.current;if(!y||y.size===0)return u;const l={};for(const[,p]of y)l[p.nodeId]||(l[p.nodeId]=[]),l[p.nodeId].push({id:p.id,type:p.type,position:p.position,x:p.x,y:p.y});return u.map(p=>{const C=l[p.id];return C&&C.length>0?{...p,handles:C}:p})},[]),pn=a.useCallback(()=>{var y;if(Ye.current)return;const u=Mt(lt.current);(y=Pe.current)==null||y.postMessage({type:"nodes",data:{nodes:u}})},[Mt]);a.useEffect(()=>{var l,p;if(Ye.current){const C=Ye.current.id,z=new Set([C,...Ye.current.selectedStarts.map(R=>R.id)]),x={};for(const R of te.current)z.has(R.id)&&(x[R.id]={...R.position});te.current=[...t];for(const R of te.current)x[R.id]&&(R.position=x[R.id]);lt.current=Xt(te.current);const M=Mt(lt.current);(l=Pe.current)==null||l.postMessage({type:"nodes",data:{nodes:M}});return}te.current=[...t];const u=Xt(t);lt.current=u;const y=Mt(u);(p=Pe.current)==null||p.postMessage({type:"nodes",data:{nodes:y}})},[t,Xt,Mt]),a.useEffect(()=>{var u;Ne.current=[...n],(u=Pe.current)==null||u.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const Be=a.useCallback((u,y)=>{const l=ve.current;if(!l)return{x:0,y:0};const p=l.getBoundingClientRect(),C=he.current;return{x:(u-p.left-C.x)/C.zoom,y:(y-p.top-C.y)/C.zoom}},[]),de=a.useCallback((u,y)=>{const l=lt.current.length>0?lt.current:te.current;let p=null;for(let C=l.length-1;C>=0;C--){const z=l[C];if(z.hidden||z._customRendered)continue;const x=z._absolutePosition||z.position,M=z.width||ft,R=z.height||nt;if(u>=x.x&&u<=x.x+M&&y>=x.y&&y<=x.y+R){if(z.type==="group"){p||(p=z);continue}return z}}return p},[]),Gt=a.useCallback((u,y)=>{const l=y.width||ft,p=y.height||nt;if(u.x!==void 0&&u.y!==void 0)return{x:y.position.x+u.x,y:y.position.y+u.y};switch(u.position||(u.type==="source"?"right":"left")){case"top":return{x:y.position.x+l/2,y:y.position.y};case"bottom":return{x:y.position.x+l/2,y:y.position.y+p};case"left":return{x:y.position.x,y:y.position.y+p/2};case"right":return{x:y.position.x+l,y:y.position.y+p/2};default:return{x:y.position.x+l,y:y.position.y+p/2}}},[]),Qt=a.useCallback(u=>{const y=u.width||ft,l=u.height||nt;if(u.handles&&u.handles.length>0)return u.handles.map(R=>{const H=Gt(R,u);return{id:R.id||null,type:R.type,x:H.x,y:H.y}});const p=u.targetPosition||"left",C=u.sourcePosition||"right",z=R=>{switch(R){case"top":return{x:u.position.x+y/2,y:u.position.y};case"bottom":return{x:u.position.x+y/2,y:u.position.y+l};case"left":return{x:u.position.x,y:u.position.y+l/2};case"right":return{x:u.position.x+y,y:u.position.y+l/2};default:return{x:u.position.x+y,y:u.position.y+l/2}}},x=z(p),M=z(C);return[{id:null,type:"target",x:x.x,y:x.y},{id:null,type:"source",x:M.x,y:M.y}]},[Gt]),Rt=a.useCallback((u,y)=>{const l=te.current,p=he.current,C=Math.max(no,Le)/p.zoom;for(let z=l.length-1;z>=0;z--){const x=l[z];if(x.hidden)continue;const M=Qt(x);for(const R of M)if(Math.abs(u-R.x)<C&&Math.abs(y-R.y)<C)return{nodeId:x.id,handleId:R.id,type:R.type,x:R.x,y:R.y}}return null},[Qt]),qe=a.useCallback((u,y)=>{const p=8/he.current.zoom,C=te.current,z={};for(let x=0;x<C.length;x++)z[C[x].id]=C[x];for(let x=Ne.current.length-1;x>=0;x--){const M=Ne.current[x],R=z[M.source],H=z[M.target];if(!R||!H)continue;const T=R.width||ft,q=R.height||nt,G=H.height||nt,Z=R.position.x+T,ie=R.position.y+q/2,V=H.position.x,ce=H.position.y+G/2;if(ro(u,y,Z,ie,V,ce)<p)return M}return null},[]);a.useEffect(()=>{const u=Tt.current,y=ve.current;if(!u||!y)return;const l=y.getBoundingClientRect(),p=le!==void 0?le:matchMedia("(prefers-color-scheme: dark)").matches,C=Xt(te.current);lt.current=C;const z=Mt(C),{worker:x}=to(u,{width:l.width,height:l.height,camera:he.current,cards:vt.current,nodes:z,edges:Ne.current,dark:p,gridSize:Se,edgeRouting:kt});x.onmessage=T=>{var q,G,Z,ie;T.data.type==="hud"&&((q=Ft.current)==null||q.call(Ft,T.data.data)),T.data.type==="ready"&&An(!0),T.data.type==="nodesProcessed"&&((G=Yt.current)==null||G.call(Yt,T.data.data)),T.data.type==="error"&&((ie=(Z=J.current).onError)==null||ie.call(Z,"worker-error",T.data.message||"Canvas worker error"))},x.onerror=T=>{var q,G;(G=(q=J.current).onError)==null||G.call(q,"worker-error",T.message||"Canvas worker crashed")},Pe.current=x;const M=new ResizeObserver(T=>{const{width:q,height:G}=T[0].contentRect;x.postMessage({type:"resize",data:{width:q,height:G}})});M.observe(y);let R,H;return le===void 0&&(R=matchMedia("(prefers-color-scheme: dark)"),H=T=>x.postMessage({type:"theme",data:{dark:T.matches}}),R.addEventListener("change",H)),()=>{M.disconnect(),R&&H&&R.removeEventListener("change",H),Pe.current=null}},[]),a.useEffect(()=>{var u;le!==void 0&&((u=Pe.current)==null||u.postMessage({type:"theme",data:{dark:le}}))},[le]),a.useEffect(()=>{var u;(u=Pe.current)==null||u.postMessage({type:"edgeRouting",data:{enabled:kt}})},[kt]);const Jt=a.useRef(0),Re=a.useCallback((u=null)=>{var p,C,z;const y=he.current;if(pt){const x=ve.current;if(x){const M=x.getBoundingClientRect(),R=-pt[1][0]*y.zoom+M.width,H=-pt[1][1]*y.zoom+M.height,T=-pt[0][0]*y.zoom,q=-pt[0][1]*y.zoom;y.x=Math.min(T,Math.max(R,y.x)),y.y=Math.min(q,Math.max(H,y.y))}}(p=Pe.current)==null||p.postMessage({type:"camera",data:{camera:{...y}}});const l={x:y.x,y:y.y,zoom:y.zoom};(z=(C=J.current).onMove)==null||z.call(C,u,l);for(const x of bt)x(l);cancelAnimationFrame(Jt.current),Jt.current=requestAnimationFrame(()=>{yn({x:y.x,y:y.y,zoom:y.zoom})})},[bt,pt]),ut=a.useCallback(()=>{var l,p;const u=Oe.current,y=jt.current;u&&y?((l=Pe.current)==null||l.postMessage({type:"connecting",data:{from:u.startPos,to:y,_routedPoints:null}}),xn({source:u.sourceId,sourceHandle:u.sourceHandle,target:null,targetHandle:null})):((p=Pe.current)==null||p.postMessage({type:"connecting",data:null}),xn(null))},[]),dt=a.useCallback(()=>{var y,l;const u=it.current;u?(y=Pe.current)==null||y.postMessage({type:"selectionBox",data:u}):(l=Pe.current)==null||l.postMessage({type:"selectionBox",data:null})},[]),Vt=a.useCallback(u=>{var x,M,R,H,T,q,G,Z,ie,V,ce,ke,je,Xe,Ze,Ue,en,xt;const y=te.current.length>0,l=Be(u.clientX,u.clientY),p=hn.current;if(y&&Te&&!p){const Q=Rt(l.x,l.y);if(ze&&Ve.current&&Q){const re=Ve.current;if(Q.nodeId!==re.nodeId){const Ge=re.handleType==="target"?{source:Q.nodeId,target:re.nodeId,sourceHandle:Q.handleId||null,targetHandle:re.handleId}:{source:re.nodeId,target:Q.nodeId,sourceHandle:re.handleId,targetHandle:Q.handleId||null};(J.current.isValidConnection?J.current.isValidConnection(Ge):!0)&&((x=ct.current)==null||x.call(ct,{...Ge,...Pt}))}Ve.current=null;return}if($e==="strict"?Q&&Q.type==="source":Q!=null){if(ze){Ve.current={nodeId:Q.nodeId,handleId:Q.handleId||null,handleType:Q.type},(R=(M=J.current).onConnectStart)==null||R.call(M,u,{nodeId:Q.nodeId,handleId:Q.handleId,handleType:Q.type});return}Oe.current={sourceId:Q.nodeId,sourceHandle:Q.handleId||null,sourceType:Q.type,startPos:{x:Q.x,y:Q.y}},jt.current={x:l.x,y:l.y},(H=ve.current)==null||H.setPointerCapture(u.pointerId),(q=(T=J.current).onConnectStart)==null||q.call(T,u,{nodeId:Q.nodeId,handleId:Q.handleId,handleType:Q.type}),ut();return}}const C=Q=>{var re;let me=Q;for(;me&&me!==ve.current;){if((re=me.classList)!=null&&re.contains(Nt))return!0;me=me.parentElement}return!1},z=Q=>{var re;let me=Q;for(;me&&me!==ve.current;){if((re=me.classList)!=null&&re.contains(It))return!0;me=me.parentElement}return!1};if(y){const Q=de(l.x,l.y);if(Q){if(Ce.current&&He){const me=[];if(p)me.push({id:Q.id,type:"select",selected:!Q.selected});else if(!Q.selected){for(const re of te.current)re.id===Q.id?me.push({id:re.id,type:"select",selected:!0}):re.selected&&me.push({id:re.id,type:"select",selected:!1});if(_e.current){const re=Ne.current.filter(ge=>ge.selected).map(ge=>({id:ge.id,type:"select",selected:!1}));re.length&&_e.current(re)}}if(me.length){if(Ce.current(me),Tn&&!p){const re=te.current.findIndex(ge=>ge.id===Q.id);re>=0&&re<te.current.length-1&&Ce.current([{id:Q.id,type:"remove"},{type:"add",item:{...te.current[re],selected:!0}}])}yt()}}if((G=Ct.current)==null||G.call(Ct,u,Q),ue&&!C(u.target)){const me=Q.selected;let re=null;if(Q.parentId&&Q.extent==="parent"){const ge=te.current.find(Ge=>Ge.id===Q.parentId);if(ge){const Ge=ge.width||ft,tn=ge.height||nt,vn=Q.width||((Z=Q.measured)==null?void 0:Z.width)||ft,nn=Q.height||((ie=Q.measured)==null?void 0:ie.height)||nt;re={minX:0,minY:0,maxX:Ge-vn,maxY:tn-nn}}}if(Ye.current={id:Q.id,startPos:{...Q.position},startMouse:{x:l.x,y:l.y},parentClamp:re,parentId:Q.parentId||null,selectedStarts:me?te.current.filter(ge=>ge.selected&&ge.id!==Q.id).map(ge=>{var tn,vn;let Ge=null;if(ge.parentId&&ge.extent==="parent"){const nn=te.current.find(Yn=>Yn.id===ge.parentId);if(nn){const Yn=nn.width||ft,Wr=nn.height||nt,Fr=ge.width||((tn=ge.measured)==null?void 0:tn.width)||ft,Yr=ge.height||((vn=ge.measured)==null?void 0:vn.height)||nt;Ge={minX:0,minY:0,maxX:Yn-Fr,maxY:Wr-Yr}}}return{id:ge.id,startPos:{...ge.position},parentClamp:Ge,parentId:ge.parentId||null}}):[]},(V=ve.current)==null||V.setPointerCapture(u.pointerId),(ce=At.current)==null||ce.call(At,u,Q),Ye.current.selectedStarts.length>0){const ge=te.current.filter(Ge=>Ge.selected);(je=(ke=J.current).onSelectionDragStart)==null||je.call(ke,u,ge)}if(Ce.current){const ge=[{id:Q.id,type:"position",dragging:!0}];for(const Ge of Ye.current.selectedStarts)ge.push({id:Ge.id,type:"position",dragging:!0});Ce.current(ge)}}return}}if(Ne.current.length>0&&He){const Q=qe(l.x,l.y);if(Q){if(_e.current){const me=[];if(p)me.push({id:Q.id,type:"select",selected:!Q.selected});else{for(const re of Ne.current)re.id===Q.id?me.push({id:re.id,type:"select",selected:!0}):re.selected&&me.push({id:re.id,type:"select",selected:!1});if(Ce.current){const re=te.current.filter(ge=>ge.selected).map(ge=>({id:ge.id,type:"select",selected:!1}));re.length&&Ce.current(re)}}if(me.length){if(_e.current(me),Ln&&!p){const re=Ne.current.findIndex(ge=>ge.id===Q.id);re>=0&&re<Ne.current.length-1&&_e.current([{id:Q.id,type:"remove"},{type:"add",item:{...Ne.current[re],selected:!0}}])}yt()}}(Xe=wt.current)==null||Xe.call(wt,u,Q);return}}if(!p){const Q=te.current.filter(re=>re.selected).map(re=>({id:re.id,type:"select",selected:!1})),me=Ne.current.filter(re=>re.selected).map(re=>({id:re.id,type:"select",selected:!1}));Q.length&&Ce.current&&Ce.current(Q),me.length&&_e.current&&_e.current(me),(Q.length||me.length)&&yt()}if((Ze=_t.current)==null||Ze.call(_t,u),rt||p){it.current={startWorld:{...l},endWorld:{...l}},(Ue=ve.current)==null||Ue.setPointerCapture(u.pointerId),dt();return}z(u.target)||(Lt.current=!0,Bt.current={x:u.clientX,y:u.clientY},(en=ve.current)==null||en.classList.add("dragging"),(xt=ve.current)==null||xt.setPointerCapture(u.pointerId))},[Be,de,Rt,qe,ue,Te,He,rt,ut,dt,yt,Nt,It]),Kt=a.useCallback(u=>{var l,p,C,z;if(Oe.current){if(jt.current=Be(u.clientX,u.clientY),ut(),In){const x=ve.current;if(x){const M=x.getBoundingClientRect(),R=40,H=u.clientX-M.left,T=u.clientY-M.top;let q=0,G=0;H<R?q=st:H>M.width-R&&(q=-st),T<R?G=st:T>M.height-R&&(G=-st),(q||G)&&(he.current.x+=q,he.current.y+=G,Re(u))}}return}if(it.current){it.current.endWorld=Be(u.clientX,u.clientY),dt();const x=it.current,M=Math.min(x.startWorld.x,x.endWorld.x),R=Math.min(x.startWorld.y,x.endWorld.y),H=Math.max(x.startWorld.x,x.endWorld.x),T=Math.max(x.startWorld.y,x.endWorld.y);if(Ce.current){const q=[];for(const G of te.current){if(G.hidden)continue;const Z=G.width||ft,ie=G.height||nt,V=ht==="full"?G.position.x>=M&&G.position.x+Z<=H&&G.position.y>=R&&G.position.y+ie<=T:G.position.x+Z>M&&G.position.x<H&&G.position.y+ie>R&&G.position.y<T;V!==!!G.selected&&q.push({id:G.id,type:"select",selected:V})}q.length&&Ce.current(q)}return}if(Ye.current){const x=Be(u.clientX,u.clientY),M=Ye.current,R=x.x-M.startMouse.x,H=x.y-M.startMouse.y;let T={x:M.startPos.x+R,y:M.startPos.y+H};if(Qe&&(T=Zn(T,Je)),mt&&(T=Gn(T,mt)),M.parentClamp){const V=M.parentClamp;T={x:Math.max(V.minX,Math.min(T.x,V.maxX)),y:Math.max(V.minY,Math.min(T.y,V.maxY))}}const q=[{id:M.id,position:T}];for(const V of M.selectedStarts){let ce={x:V.startPos.x+R,y:V.startPos.y+H};if(Qe&&(ce=Zn(ce,Je)),mt&&(ce=Gn(ce,mt)),V.parentClamp){const ke=V.parentClamp;ce={x:Math.max(ke.minX,Math.min(ce.x,ke.maxX)),y:Math.max(ke.minY,Math.min(ce.y,ke.maxY))}}q.push({id:V.id,position:ce})}const G=[];for(const V of q){const ce=te.current.find(ke=>ke.id===V.id);if(ce){ce.position=V.position,ce.dragging=!0;let ke=V.position;if(ce.parentId){let je=te.current.find(Ue=>Ue.id===ce.parentId),Xe=V.position.x,Ze=V.position.y;for(;je;)Xe+=je.position.x,Ze+=je.position.y,je=je.parentId?te.current.find(Ue=>Ue.id===je.parentId):null;ke={x:Xe,y:Ze}}G.push({id:V.id,position:V.position,_absolutePosition:ke,width:ce.width,height:ce.height,dragging:!0,selected:ce.selected})}}const Z=new Set(q.map(V=>V.id));for(const V of te.current)if(V.parentId&&Z.has(V.parentId)&&!Z.has(V.id)){let ce=te.current.find(Xe=>Xe.id===V.parentId),ke=V.position.x,je=V.position.y;for(;ce;)ke+=ce.position.x,je+=ce.position.y,ce=ce.parentId?te.current.find(Xe=>Xe.id===ce.parentId):null;G.push({id:V.id,position:V.position,_absolutePosition:{x:ke,y:je},width:V.width,height:V.height,dragging:!1,selected:V.selected})}if((l=Pe.current)==null||l.postMessage({type:"nodePositions",data:{updates:G}}),Nn){const V=ve.current;if(V){const ce=V.getBoundingClientRect(),ke=40,je=u.clientX-ce.left,Xe=u.clientY-ce.top;let Ze=0,Ue=0;je<ke?Ze=st:je>ce.width-ke&&(Ze=-st),Xe<ke?Ue=st:Xe>ce.height-ke&&(Ue=-st),(Ze||Ue)&&(he.current.x+=Ze,he.current.y+=Ue,Re(u))}}const ie=te.current.find(V=>V.id===M.id);if(ie&&((p=Dt.current)==null||p.call(Dt,u,ie)),M.selectedStarts.length>0){const V=te.current.filter(ce=>ce.selected);(z=(C=J.current).onSelectionDrag)==null||z.call(C,u,V)}return}if(!Lt.current)return;const y=he.current;y.x+=u.clientX-Bt.current.x,y.y+=u.clientY-Bt.current.y,Bt.current={x:u.clientX,y:u.clientY},Re()},[Re,Be,ut,dt]),mn=a.useCallback(u=>{var y,l,p,C,z,x,M,R;if(Oe.current){const H=Be(u.clientX,u.clientY),T=Rt(H.x,H.y);if(T&&T.nodeId!==Oe.current.sourceId&&($e==="loose"||T.type==="target")){const Z=Oe.current.sourceType==="target"?{source:T.nodeId,target:Oe.current.sourceId,sourceHandle:T.handleId||null,targetHandle:Oe.current.sourceHandle}:{source:Oe.current.sourceId,target:T.nodeId,sourceHandle:Oe.current.sourceHandle,targetHandle:T.handleId||null};(J.current.isValidConnection?J.current.isValidConnection(Z):!0)&&((y=ct.current)==null||y.call(ct,{...Z,...Pt}))}(p=(l=J.current).onConnectEnd)==null||p.call(l,u.nativeEvent||u),Oe.current=null,jt.current=null,ut();return}if(it.current){it.current=null,dt(),yt();return}if(Ye.current){const H=Ye.current,T=te.current.find(Z=>Z.id===H.id),q=[{id:H.id,position:T?{...T.position}:H.startPos,_absolutePosition:T?{...T.position}:H.startPos,dragging:!1}];for(const Z of H.selectedStarts){const ie=te.current.find(V=>V.id===Z.id);q.push({id:Z.id,position:ie?{...ie.position}:Z.startPos,_absolutePosition:ie?{...ie.position}:Z.startPos,dragging:!1})}if((C=Pe.current)==null||C.postMessage({type:"nodePositions",data:{updates:q}}),Ce.current){const Z=q.map(ie=>({id:ie.id,type:"position",position:ie.position,dragging:!1}));Ce.current(Z)}if(H.selectedStarts.length>0){const Z=te.current.filter(ie=>ie.selected);(x=(z=J.current).onSelectionDragStop)==null||x.call(z,u,Z)}requestAnimationFrame(()=>{Ye.current=null});const G=te.current.find(Z=>Z.id===H.id);G&&((M=Ht.current)==null||M.call(Ht,u,G));return}Lt.current=!1,(R=ve.current)==null||R.classList.remove("dragging")},[Be,Rt,ut,dt,yt]);a.useEffect(()=>{const u=ve.current;if(!u)return;const y=l=>{qt&&l.preventDefault();const p=he.current;if(zt||Ke.current){const R=et;De==="horizontal"?p.x-=l.deltaY*R:(De==="vertical"||(p.x-=l.deltaX*R),p.y-=l.deltaY*R),Re(l);return}if(!tt)return;const C=l.deltaY>0?.92:1.08,z=u.getBoundingClientRect(),x=l.clientX-z.left,M=l.clientY-z.top;p.x=x-(x-p.x)*C,p.y=M-(M-p.y)*C,p.zoom=Math.min(fe,Math.max(se,p.zoom*C)),Re(l)};return u.addEventListener("wheel",y,{passive:!qt}),()=>u.removeEventListener("wheel",y)},[Re,se,fe,zt,De,et,tt,qt]),a.useEffect(()=>{if(!dn)return;const u=ve.current;if(!u)return;let y=0,l=null;const p=x=>{if(x.touches.length===2){const M=x.touches[0].clientX-x.touches[1].clientX,R=x.touches[0].clientY-x.touches[1].clientY;y=Math.hypot(M,R);const H=u.getBoundingClientRect();l={x:(x.touches[0].clientX+x.touches[1].clientX)/2-H.left,y:(x.touches[0].clientY+x.touches[1].clientY)/2-H.top},x.preventDefault()}},C=x=>{if(x.touches.length===2&&y>0){x.preventDefault();const M=x.touches[0].clientX-x.touches[1].clientX,R=x.touches[0].clientY-x.touches[1].clientY,H=Math.hypot(M,R),T=H/y;y=H;const q=he.current,G=l.x,Z=l.y;q.x=G-(G-q.x)*T,q.y=Z-(Z-q.y)*T,q.zoom=Math.min(fe,Math.max(se,q.zoom*T)),Re(x)}},z=()=>{y=0,l=null};return u.addEventListener("touchstart",p,{passive:!1}),u.addEventListener("touchmove",C,{passive:!1}),u.addEventListener("touchend",z),()=>{u.removeEventListener("touchstart",p),u.removeEventListener("touchmove",C),u.removeEventListener("touchend",z)}},[dn,Re,se,fe]),a.useEffect(()=>{if(!un)return;const u=ve.current;if(!u)return;const y=l=>{var T,q,G,Z;const p=Be(l.clientX,l.clientY);if(de(p.x,p.y)){(q=(T=J.current).onNodeDoubleClick)==null||q.call(T,l,de(p.x,p.y));return}const C=qe(p.x,p.y);if(C){(Z=(G=J.current).onEdgeDoubleClick)==null||Z.call(G,l,C);return}const z=1.5,x=u.getBoundingClientRect(),M=l.clientX-x.left,R=l.clientY-x.top,H=he.current;H.x=M-(M-H.x)*z,H.y=R-(R-H.y)*z,H.zoom=Math.min(fe,Math.max(se,H.zoom*z)),Re(l)};return u.addEventListener("dblclick",y),()=>u.removeEventListener("dblclick",y)},[un,Re,se,fe,Be,de,qe]),a.useEffect(()=>{const u=ve.current;if(!u)return;const y=l=>{var x,M,R,H,T,q;const p=Be(l.clientX,l.clientY),C=de(p.x,p.y);if(C){(M=(x=J.current).onNodeContextMenu)==null||M.call(x,l,C);return}const z=qe(p.x,p.y);if(z){(H=(R=J.current).onEdgeContextMenu)==null||H.call(R,l,z);return}(q=(T=J.current).onPaneContextMenu)==null||q.call(T,l)};return u.addEventListener("contextmenu",y),()=>u.removeEventListener("contextmenu",y)},[Be,de,qe]),a.useEffect(()=>{const u=ve.current;if(!u)return;let y=null,l=null;const p=x=>{var H,T,q,G,Z,ie,V,ce,ke,je,Xe,Ze,Ue,en;if((T=(H=J.current).onPaneMouseMove)==null||T.call(H,x),Lt.current||Ye.current||Oe.current||it.current)return;const M=Be(x.clientX,x.clientY),R=de(M.x,M.y);if(R!==y&&(y&&((G=(q=J.current).onNodeMouseLeave)==null||G.call(q,x,y)),R&&((ie=(Z=J.current).onNodeMouseEnter)==null||ie.call(Z,x,R)),y=R),R&&((ce=(V=J.current).onNodeMouseMove)==null||ce.call(V,x,R)),!R){const xt=qe(M.x,M.y);xt!==l&&(l&&((je=(ke=J.current).onEdgeMouseLeave)==null||je.call(ke,x,l)),xt&&((Ze=(Xe=J.current).onEdgeMouseEnter)==null||Ze.call(Xe,x,xt)),l=xt),xt&&((en=(Ue=J.current).onEdgeMouseMove)==null||en.call(Ue,x,xt))}},C=x=>{var M,R;return(R=(M=J.current).onPaneMouseEnter)==null?void 0:R.call(M,x)},z=x=>{var M,R,H,T,q,G;(R=(M=J.current).onPaneMouseLeave)==null||R.call(M,x),y&&((T=(H=J.current).onNodeMouseLeave)==null||T.call(H,x,y),y=null),l&&((G=(q=J.current).onEdgeMouseLeave)==null||G.call(q,x,l),l=null)};return u.addEventListener("mousemove",p),u.addEventListener("mouseenter",C),u.addEventListener("mouseleave",z),()=>{u.removeEventListener("mousemove",p),u.removeEventListener("mouseenter",C),u.removeEventListener("mouseleave",z)}},[Be,de,qe]),a.useEffect(()=>{const u=Array.isArray(Ae)?Ae:[Ae],y=async l=>{var p,C,z,x;if(u.includes(l.key)){if(l.target.tagName==="INPUT"||l.target.tagName==="TEXTAREA"||l.target.isContentEditable)return;const M=te.current.filter(T=>T.selected),R=Ne.current.filter(T=>T.selected);if(!M.length&&!R.length)return;if(J.current.onBeforeDelete)try{if(!await J.current.onBeforeDelete({nodes:M,edges:R}))return}catch(T){(C=(p=J.current).onError)==null||C.call(p,"before-delete-error",T.message||"onBeforeDelete threw an error");return}const H=new Set(M.map(T=>T.id));if(M.length&&Ce.current&&(Ce.current(M.map(T=>({id:T.id,type:"remove"}))),_e.current)){const T=Ne.current.filter(q=>H.has(q.source)||H.has(q.target));T.length&&_e.current(T.map(q=>({id:q.id,type:"remove"})))}R.length&&_e.current&&_e.current(R.map(T=>({id:T.id,type:"remove"}))),(x=(z=J.current).onDelete)==null||x.call(z,{nodes:M,edges:R})}if((l.ctrlKey||l.metaKey)&&l.key==="a"){if(l.target.tagName==="INPUT"||l.target.tagName==="TEXTAREA")return;if(l.preventDefault(),Ce.current){const M=te.current.filter(R=>!R.selected).map(R=>({id:R.id,type:"select",selected:!0}));M.length&&Ce.current(M)}if(_e.current){const M=Ne.current.filter(R=>!R.selected).map(R=>({id:R.id,type:"select",selected:!0}));M.length&&_e.current(M)}}};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[Ae]);const Ot=a.useRef(!1);a.useEffect(()=>{var u,y;if(!Ot.current&&Pe.current){if(Ot.current=!0,We&&te.current.length>0){const l=ve.current;if(l){const p=l.getBoundingClientRect(),C=(xe==null?void 0:xe.padding)??.1,z=Mn(te.current),x=Ut(z,p.width,p.height,C);xe!=null&&xe.maxZoom&&(x.zoom=Math.min(x.zoom,xe.maxZoom)),xe!=null&&xe.minZoom&&(x.zoom=Math.max(x.zoom,xe.minZoom)),he.current=x,Re()}}(y=(u=J.current).onInit)==null||y.call(u,{getNodes:()=>[...te.current],getEdges:()=>[...Ne.current],getNode:l=>te.current.find(p=>p.id===l),getEdge:l=>Ne.current.find(p=>p.id===l),getViewport:()=>({...he.current}),getZoom:()=>he.current.zoom,setViewport:l=>{he.current={x:l.x??he.current.x,y:l.y??he.current.y,zoom:l.zoom??he.current.zoom},Re()},fitView:(l={})=>{const p=ve.current;if(!p||!te.current.length)return;const C=p.getBoundingClientRect(),z=l.nodes?te.current.filter(R=>l.nodes.some(H=>H.id===R.id)):te.current;if(!z.length)return;const x=Mn(z),M=Ut(x,C.width,C.height,l.padding??.1);l.maxZoom&&(M.zoom=Math.min(M.zoom,l.maxZoom)),l.minZoom&&(M.zoom=Math.max(M.zoom,l.minZoom)),he.current=M,Re()},screenToFlowPosition:l=>Be(l.x,l.y),flowToScreenPosition:l=>{const p=he.current,C=ve.current;if(!C)return{x:0,y:0};const z=C.getBoundingClientRect();return{x:l.x*p.zoom+p.x+z.left,y:l.y*p.zoom+p.y+z.top}},zoomIn:()=>{const l=he.current;l.zoom=Math.min(fe,l.zoom*1.2),Re()},zoomOut:()=>{const l=he.current;l.zoom=Math.max(se,l.zoom/1.2),Re()},zoomTo:l=>{he.current.zoom=Math.min(fe,Math.max(se,l)),Re()},setNodes:l=>{var p,C;(C=(p=J.current).onNodesChange)==null||C.call(p,[...te.current.map(z=>({id:z.id,type:"remove"})),...(typeof l=="function"?l(te.current):l).map(z=>({type:"add",item:z}))])},setEdges:l=>{var p,C;(C=(p=J.current).onEdgesChange)==null||C.call(p,[...Ne.current.map(z=>({id:z.id,type:"remove"})),...(typeof l=="function"?l(Ne.current):l).map(z=>({type:"add",item:z}))])},addNodes:l=>{var C,z;const p=Array.isArray(l)?l:[l];(z=(C=J.current).onNodesChange)==null||z.call(C,p.map(x=>({type:"add",item:x})))},addEdges:l=>{var C,z;const p=Array.isArray(l)?l:[l];(z=(C=J.current).onEdgesChange)==null||z.call(C,p.map(x=>({type:"add",item:x})))},deleteElements:({nodes:l=[],edges:p=[]})=>{var C,z,x,M;l.length&&((z=(C=J.current).onNodesChange)==null||z.call(C,l.map(R=>({id:R.id,type:"remove"})))),p.length&&((M=(x=J.current).onEdgesChange)==null||M.call(x,p.map(R=>({id:R.id,type:"remove"}))))},updateNodeData:(l,p)=>{var x,M;const C=te.current.find(R=>R.id===l);if(!C)return;const z=typeof p=="function"?p(C.data):{...C.data,...p};(M=(x=J.current).onNodesChange)==null||M.call(x,[{id:l,type:"replace",item:{...C,data:z}}])},toObject:()=>({nodes:[...te.current],edges:[...Ne.current],viewport:{...he.current}}),setCenter:(l,p,C={})=>{const z=ve.current;if(!z)return;const x=z.getBoundingClientRect(),M=C.zoom??he.current.zoom;he.current={x:x.width/2-l*M,y:x.height/2-p*M,zoom:M},Re()},fitBounds:(l,p={})=>{const C=ve.current;if(!C)return;const z=C.getBoundingClientRect(),x=Ut(l,z.width,z.height,p.padding??.1);he.current=x,Re()}})}});const Hn=a.useCallback(()=>{he.current={...be},Re()},[Re,be]),_n=a.useCallback(u=>{var y;if(u)vt.current.push(u);else{const l=he.current,p=ve.current;if(!p)return;const C=p.getBoundingClientRect(),z=Math.round(-l.x/l.zoom+C.width/2/l.zoom),x=Math.round(-l.y/l.zoom+C.height/2/l.zoom);vt.current.push({x:z-80,y:x-45,w:160,h:90,title:"Note "+(vt.current.length+1),body:"Added at viewport center"})}(y=Pe.current)==null||y.postMessage({type:"cards",data:{cards:[...vt.current]}})},[]),Wn=a.useCallback(u=>{if(u.id||(u.id="node-"+Date.now()),!u.position){const y=he.current,l=ve.current;if(!l)return;const p=l.getBoundingClientRect();u.position={x:Math.round(-y.x/y.zoom+p.width/2/y.zoom)-ft/2,y:Math.round(-y.y/y.zoom+p.height/2/y.zoom)-nt/2}}u.data||(u.data={label:u.id}),Ce.current&&Ce.current([{type:"add",item:u}])},[]),Fn=a.useCallback(()=>({...he.current}),[]),W=a.useCallback(u=>{he.current={...he.current,...u},Re()},[Re]),pe=a.useCallback(u=>Be(u.x,u.y),[Be]),ne=n,Ee=a.useMemo(()=>({wrapRef:ve,canvasRef:Tt,workerRef:Pe,cameraRef:he,nodesRef:te,edgesRef:Ne,handleRegistryRef:fn,syncNodesToWorker:pn,onNodesChangeRef:Ce,onEdgesChangeRef:_e,sendCamera:Re,screenToWorld:Be,viewportListeners:bt,selectionListeners:at,zoomMin:se,zoomMax:fe,snapToGrid:Qe,snapGrid:Je,nodeExtent:mt,defaultEdgeOptions:Pt,edgeRouting:kt,resolvedNodesRef:lt,noDragClassName:Nt,noPanClassName:It,get nodes(){return t},get edges(){return n},get routedEdges(){return ne},get viewport(){return gn},get connection(){return Zt}}),[t,n,ne,gn,Zt,Re,Be,pn,bt,at,se,fe,Qe,Je,mt,Pt,kt,Nt,It]);return{wrapRef:ve,canvasRef:Tt,canvasReady:$t,onPointerDown:Vt,onPointerMove:Kt,onPointerUp:mn,resetView:Hn,addCard:_n,addNode:Wn,getCamera:Fn,setCamera:W,screenToFlowPosition:pe,store:Ee}}function ro(e,t,n,r,i,o){const c=i-n,f=o-r,m=c*c+f*f;if(m===0)return Math.hypot(e-n,t-r);let d=((e-n)*c+(t-r)*f)/m;return d=Math.max(0,Math.min(1,d)),Math.hypot(e-(n+d*c),t-(r+d*f))}const ur=e=>{let t;const n=new Set,r=(d,h)=>{const b=typeof d=="function"?d(t):d;if(!Object.is(b,t)){const k=t;t=h??(typeof b!="object"||b===null)?b:Object.assign({},t,b),n.forEach(S=>S(t,k))}},i=()=>t,f={setState:r,getState:i,getInitialState:()=>m,subscribe:d=>(n.add(d),()=>n.delete(d))},m=t=e(r,i,f);return f},oo=(e=>e?ur(e):ur),so=e=>e;function io(e,t=so){const n=a.useSyncExternalStore(e.subscribe,a.useCallback(()=>t(e.getState()),[e,t]),a.useCallback(()=>t(e.getInitialState()),[e,t]));return a.useDebugValue(n),n}const St=a.createContext(null);function ao(e={}){return oo((t,n)=>({nodes:[],edges:[],viewport:{x:0,y:0,zoom:1},connection:null,minZoom:.1,maxZoom:5,width:0,height:0,domNode:null,nodesRef:{current:[]},edgesRef:{current:[]},cameraRef:{current:{x:0,y:0,zoom:1}},wrapRef:{current:null},workerRef:{current:null},onNodesChangeRef:{current:null},onEdgesChangeRef:{current:null},viewportListeners:new Set,selectionListeners:new Set,edgeLabelContainerRef:{current:null},viewportPortalRef:{current:null},screenToWorld:(r,i)=>{const o=n().cameraRef.current;return{x:(r-o.x)/o.zoom,y:(i-o.y)/o.zoom}},sendCamera:()=>{var i;const r=n();(i=r.workerRef.current)==null||i.postMessage({type:"camera",data:{camera:{...r.cameraRef.current}}})},...e}))}function Ie(e,t){const n=a.useContext(St);if(!n)throw new Error("useCanvasStore must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");const r=typeof n.getState=="function"&&typeof n.subscribe=="function",i=a.useRef(e),o=a.useRef(t),c=a.useRef(void 0);i.current=e,o.current=t;const f=a.useCallback(m=>{const d=i.current;if(!d)return m;const h=d(m),b=o.current||Object.is;return c.current!==void 0&&b(c.current,h)?c.current:(c.current=h,h)},[]);return r?io(n,e?f:void 0):e?f(n):n}function Rr(){const e=a.useContext(St);if(!e)throw new Error("useCanvasStoreApi must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");return typeof e.getState=="function"?e:{getState:()=>e,setState:()=>{},subscribe:()=>()=>{}}}const cn=a.createContext(null);function co(){return a.useContext(cn)}function lo({node:e,nodeType:t}){var P,F,j,A;const n=Ie(),r=a.useRef(n);r.current=n;const i=a.useRef(null),o=e._absolutePosition||e.position,c=a.useRef(null);a.useEffect(()=>{const X=i.current;if(!X)return;const B=new ResizeObserver(_=>{var O,U,Y,w;const{width:$,height:N}=_[0].contentRect;if($>0&&N>0){const g=r.current,v=g.nodesRef.current.find(D=>D.id===e.id),L=(v==null?void 0:v.width)||((O=v==null?void 0:v.measured)==null?void 0:O.width),E=(v==null?void 0:v.height)||((U=v==null?void 0:v.measured)==null?void 0:U.height);(Math.abs((L||0)-$)>1||Math.abs((E||0)-N)>1)&&((w=(Y=g.onNodesChangeRef).current)==null||w.call(Y,[{id:e.id,type:"dimensions",dimensions:{width:$,height:N},setAttributes:!0}]))}});return B.observe(X),()=>B.disconnect()},[e.id]);const f=a.useCallback(X=>{var oe,ye,we,Me;X.stopPropagation();const B=X.target.tagName;if(B==="INPUT"||B==="TEXTAREA"||B==="SELECT"||B==="BUTTON"||B==="A"||B==="LABEL"||X.target.isContentEditable)return;const _=r.current.noDragClassName||"nodrag",$=r.current.noPanClassName||"nopan";let N=X.target;for(;N&&N!==i.current;){if((oe=N.classList)!=null&&oe.contains(_)||(ye=N.classList)!=null&&ye.contains($))return;N=N.parentElement}if(r.current.onNodesChangeRef.current){const le=[];if(X.shiftKey)le.push({id:e.id,type:"select",selected:!e.selected});else for(const se of r.current.nodesRef.current)se.id===e.id&&!se.selected?le.push({id:se.id,type:"select",selected:!0}):se.id!==e.id&&se.selected&&le.push({id:se.id,type:"select",selected:!1});le.length&&r.current.onNodesChangeRef.current(le)}const O=r.current.cameraRef.current,U=r.current.wrapRef.current;if(!U)return;const Y=U.getBoundingClientRect(),w=(X.clientX-Y.left-O.x)/O.zoom,g=(X.clientY-Y.top-O.y)/O.zoom,L=e.selected?r.current.nodesRef.current.filter(le=>le.selected&&le.id!==e.id).map(le=>({id:le.id,startPos:{...le.position}})):[];c.current={startPos:{...e.position},startMouse:{x:w,y:g},selectedStarts:L};const E=[{id:e.id,type:"position",dragging:!0}];for(const le of L)E.push({id:le.id,type:"position",dragging:!0});(Me=(we=r.current.onNodesChangeRef).current)==null||Me.call(we,E);const D=i.current;D&&D.setPointerCapture(X.pointerId);let K=null;const ae=le=>{var He,Fe,rt,ht;if(!c.current)return;const Se=r.current.cameraRef.current,se=U.getBoundingClientRect(),fe=(le.clientX-se.left-Se.x)/Se.zoom,be=(le.clientY-se.top-Se.y)/Se.zoom,We=fe-c.current.startMouse.x,xe=be-c.current.startMouse.y;let ue={x:c.current.startPos.x+We,y:c.current.startPos.y+xe};if(r.current.snapToGrid&&r.current.snapGrid&&(ue={x:r.current.snapGrid[0]*Math.round(ue.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(ue.y/r.current.snapGrid[1])}),e.parentId&&e.extent==="parent"){const $e=r.current.nodesRef.current.find(Le=>Le.id===e.parentId);if($e){const Le=$e.width||160,ze=$e.height||60,Qe=e.width||((He=e.measured)==null?void 0:He.width)||160,Je=e.height||((Fe=e.measured)==null?void 0:Fe.height)||60;ue={x:Math.max(0,Math.min(ue.x,Le-Qe)),y:Math.max(0,Math.min(ue.y,ze-Je))}}}D&&(D.style.left=ue.x+"px",D.style.top=ue.y+"px");const Te=[{id:e.id,position:ue,_absolutePosition:ue,dragging:!0}];for(const $e of c.current.selectedStarts){let Le={x:$e.startPos.x+We,y:$e.startPos.y+xe};r.current.snapToGrid&&r.current.snapGrid&&(Le={x:r.current.snapGrid[0]*Math.round(Le.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Le.y/r.current.snapGrid[1])});const ze=U.querySelector(`[data-nodeid="${$e.id}"]`);ze&&(ze.style.left=Le.x+"px",ze.style.top=Le.y+"px"),Te.push({id:$e.id,position:Le,_absolutePosition:Le,dragging:!0})}(ht=(rt=r.current.workerRef)==null?void 0:rt.current)==null||ht.postMessage({type:"nodePositions",data:{updates:Te}});for(const $e of Te){const Le=r.current.nodesRef.current.find(ze=>ze.id===$e.id);Le&&(Le.position=$e.position)}K=Te},ee=le=>{var fe,be,We,xe;if(!c.current)return;const Se=[{id:e.id,position:e.position,dragging:!1}];for(const ue of c.current.selectedStarts)Se.push({id:ue.id,position:ue.startPos,dragging:!1});if(K)for(let ue=0;ue<K.length;ue++)Se[ue]={id:K[ue].id,position:K[ue].position,dragging:!1};(be=(fe=r.current.workerRef)==null?void 0:fe.current)==null||be.postMessage({type:"nodePositions",data:{updates:Se}});const se=[];for(const ue of Se)se.push({id:ue.id,type:"position",position:ue.position,dragging:!1});(xe=(We=r.current.onNodesChangeRef).current)==null||xe.call(We,se),c.current=null,K=null,D&&D.releasePointerCapture(le.pointerId),D==null||D.removeEventListener("pointermove",ae),D==null||D.removeEventListener("pointerup",ee)};D==null||D.addEventListener("pointermove",ae),D==null||D.addEventListener("pointerup",ee)},[e]),m=a.useCallback(X=>{var U,Y,w,g,v,L;if(!e.selected)return;const B=X.shiftKey?10:1;let _=0,$=0;switch(X.key){case"ArrowUp":$=-B;break;case"ArrowDown":$=B;break;case"ArrowLeft":_=-B;break;case"ArrowRight":_=B;break;case"Escape":(Y=(U=r.current.onNodesChangeRef).current)==null||Y.call(U,[{id:e.id,type:"select",selected:!1}]);return;case"Delete":case"Backspace":e.deletable!==!1&&((g=(w=r.current.onNodesChangeRef).current)==null||g.call(w,[{id:e.id,type:"remove"}]));return;default:return}X.preventDefault();const N={x:e.position.x+_,y:e.position.y+$},O=[{id:e.id,type:"position",position:N}];for(const E of r.current.nodesRef.current)E.selected&&E.id!==e.id&&O.push({id:E.id,type:"position",position:{x:E.position.x+_,y:E.position.y+$}});(L=(v=r.current.onNodesChangeRef).current)==null||L.call(v,O)},[e]),d=e.width||((P=e.measured)==null?void 0:P.width),h=e.height||((F=e.measured)==null?void 0:F.height),b=!!(d&&h),k=(j=n.pinnedNodeIds)==null?void 0:j.has(e.id),S=a.useCallback(X=>{var B,_;X.stopPropagation(),(_=(B=r.current).togglePinNode)==null||_.call(B,e.id)},[e.id]);return I.jsx(cn.Provider,{value:e.id,children:I.jsxs("div",{ref:i,className:`ric-node-wrapper ${e.selected?"selected":""} ${e.dragging?"dragging":""}`,style:{position:"absolute",left:o.x,top:o.y,zIndex:e.type==="group"?0:e.zIndex||1,pointerEvents:e.type==="group"?"none":"all",visibility:b?"visible":"hidden",outline:"none"},"data-nodeid":e.id,tabIndex:e.selectable!==!1?0:void 0,role:"button","aria-label":`Node ${((A=e.data)==null?void 0:A.label)||e.id}`,"aria-selected":!!e.selected,onPointerDown:f,onKeyDown:m,children:[I.jsx(t,{id:e.id,data:e.data,type:e.type,selected:!!e.selected,dragging:!!e.dragging,draggable:e.draggable!==!1,selectable:e.selectable!==!1,deletable:e.deletable!==!1,isConnectable:e.connectable!==!1,zIndex:e.zIndex||0,positionAbsoluteX:o.x,positionAbsoluteY:o.y,width:d,height:h,sourcePosition:e.sourcePosition,targetPosition:e.targetPosition,parentId:e.parentId,dragHandle:e.dragHandle}),n.togglePinNode&&I.jsx("button",{className:"ric-pin-btn nodrag",onClick:S,title:k?"Unpin from DOM":"Pin to DOM",style:{position:"absolute",top:-8,left:-8,width:20,height:20,borderRadius:"50%",border:"1.5px solid "+(k?"#3b82f6":"#ccc"),background:k?"#3b82f6":"#fff",color:k?"#fff":"#999",fontSize:10,lineHeight:"16px",textAlign:"center",cursor:"pointer",padding:0,zIndex:10,pointerEvents:"all",boxShadow:"0 1px 3px rgba(0,0,0,0.12)"},children:"📌"})]})})}const uo=a.memo(lo),kr=160,Cr=60;function dr(e,t,n,r){var f,m;const i=e.width||((f=e.measured)==null?void 0:f.width)||kr,o=e.height||((m=e.measured)==null?void 0:m.height)||Cr,c=e._absolutePosition||e.position;if(e.handleBounds){const d=e.handleBounds[t]||[],h=n?d.find(b=>b.id===n):d[0];if(h&&h.x!==void 0&&h.y!==void 0){const b=h.position||(t==="source"?"right":"left");return{x:c.x+h.x,y:c.y+h.y,position:b}}}if(r){const d=`${e.id}__${n||t}`,h=r.get(d);if(h&&h.x!==void 0&&h.y!==void 0)return{x:c.x+h.x,y:c.y+h.y,position:h.position||(t==="source"?"right":"left")}}if(e.handles&&e.handles.length){for(const d of e.handles)if(d.type===t&&(!n||d.id===n)){if(d.x!==void 0&&d.y!==void 0)return{x:c.x+d.x,y:c.y+d.y,position:d.position||(t==="source"?"right":"left")};const h=d.position||(t==="source"?"right":"left");switch(h){case"top":return{x:c.x+i/2,y:c.y,position:h};case"bottom":return{x:c.x+i/2,y:c.y+o,position:h};case"left":return{x:c.x,y:c.y+o/2,position:h};default:return{x:c.x+i,y:c.y+o/2,position:h}}}}return t==="source"?{x:c.x+i,y:c.y+o/2,position:"right"}:{x:c.x,y:c.y+o/2,position:"left"}}function fo(e,t,n){return n==="left"?e-t:n==="right"?e+t:e}function ho(e,t,n){return n==="top"?e-t:n==="bottom"?e+t:e}function fr({x:e,y:t,position:n,type:r,onPointerDown:i}){return I.jsx("circle",{className:`ric-edge-anchor ric-edge-anchor-${r}`,cx:fo(e,10,n),cy:ho(t,10,n),r:10,stroke:"transparent",fill:"transparent",style:{cursor:"move",pointerEvents:"stroke"},onPointerDown:i})}function go({edge:e,edgeType:t,nodes:n,reconnectable:r}){var w,g,v,L;const i=a.useContext(St),o=a.useRef(typeof i.getState=="function"?i.getState():i);o.current=typeof i.getState=="function"?i.getState():i;const[c,f]=a.useState(null),m=a.useCallback((E,D,K,ae)=>{var se;D.stopPropagation(),D.preventDefault();const ee=o.current,oe=ee.wrapRef.current;if(!oe)return;const ye=E==="source"?ae:K,we=E==="source"?e.target:e.source;(se=ee.workerRef.current)==null||se.postMessage({type:"connecting",data:{from:{x:ye.x,y:ye.y},to:{x:ye.x,y:ye.y}}});const Me=oe.getBoundingClientRect(),le=fe=>{var ue;const be=ee.cameraRef.current,We=(fe.clientX-Me.left-be.x)/be.zoom,xe=(fe.clientY-Me.top-be.y)/be.zoom;(ue=ee.workerRef.current)==null||ue.postMessage({type:"connecting",data:{from:{x:ye.x,y:ye.y},to:{x:We,y:xe}}})},Se=fe=>{var rt,ht,$e,Le;const be=ee.cameraRef.current,We=(fe.clientX-Me.left-be.x)/be.zoom,xe=(fe.clientY-Me.top-be.y)/be.zoom,ue=20/be.zoom;let Te=null,He=null;const Fe=(rt=ee.handleRegistryRef)==null?void 0:rt.current;for(const ze of ee.nodesRef.current){if(ze.hidden)continue;const Qe=ze.width||kr,Je=ze.height||Cr,Ae=ze._absolutePosition||ze.position,ot=[];if(Fe)for(const[,De]of Fe)De.nodeId===ze.id&&ot.push(De);const zt=ot.length>0?ot:ze.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const De of zt){let et,tt;if(De.x!==void 0&&De.y!==void 0)et=Ae.x+De.x,tt=Ae.y+De.y;else switch(De.position||(De.type==="source"?"right":"left")){case"top":et=Ae.x+Qe/2,tt=Ae.y;break;case"bottom":et=Ae.x+Qe/2,tt=Ae.y+Je;break;case"left":et=Ae.x,tt=Ae.y+Je/2;break;default:et=Ae.x+Qe,tt=Ae.y+Je/2;break}if(Math.abs(We-et)<ue&&Math.abs(xe-tt)<ue){Te=ze,He=De.id||null;break}}if(Te)break}if(Te){const ze=E==="source"?{source:Te.id,target:we,sourceHandle:He,targetHandle:e.targetHandle}:{source:we,target:Te.id,sourceHandle:e.sourceHandle,targetHandle:He};($e=(ht=ee.onEdgesChangeRef).current)==null||$e.call(ht,[{id:e.id,type:"remove"},{type:"add",item:{id:e.id,...ze}}])}(Le=ee.workerRef.current)==null||Le.postMessage({type:"connecting",data:null}),oe.removeEventListener("pointermove",le),oe.removeEventListener("pointerup",Se)};oe.addEventListener("pointermove",le),oe.addEventListener("pointerup",Se)},[e]),d=o.current,h=((w=d.nodesRef)==null?void 0:w.current)||n,b=h.find(E=>E.id===e.source),k=h.find(E=>E.id===e.target),[,S]=a.useReducer(E=>E+1,0),P=a.useRef(null),F=(b==null?void 0:b.dragging)||(k==null?void 0:k.dragging);a.useEffect(()=>{if(!F)return;const E=()=>{S(),P.current=requestAnimationFrame(E)};return P.current=requestAnimationFrame(E),()=>cancelAnimationFrame(P.current)},[F]);const j=b&&!!(b.width||(g=b.measured)!=null&&g.width),A=k&&!!(k.width||(v=k.measured)!=null&&v.width),X=(L=d.handleRegistryRef)==null?void 0:L.current,B=j?dr(b,"source",e.sourceHandle,X):null,_=A?dr(k,"target",e.targetHandle,X):null,$=e.type==="bezier"||e.type==="simplebezier"||e.type==="default",N=d.routedEdges||d.edges,O=N==null?void 0:N.find(E=>E.id===e.id),U=$?null:(O==null?void 0:O._routedPoints)||e._routedPoints||null,Y=r!==!1&&e.reconnectable!==!1;return!B||!_?null:I.jsxs("g",{className:`ric-edge-wrapper ${e.selected?"selected":""}`,"data-edgeid":e.id,onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),children:[I.jsx(t,{id:e.id,source:e.source,target:e.target,sourceX:B.x,sourceY:B.y,targetX:_.x,targetY:_.y,sourcePosition:B.position,targetPosition:_.position,sourceHandleId:e.sourceHandle,targetHandleId:e.targetHandle,data:e.data,type:e.type,selected:!!e.selected,animated:!!e.animated,label:e.label,style:e.style,selectable:e.selectable!==!1,deletable:e.deletable!==!1,routedPoints:U}),Y&&(c||e.selected)&&I.jsxs(I.Fragment,{children:[I.jsx(fr,{x:B.x,y:B.y,position:B.position,type:"source",onPointerDown:E=>m("source",E,B,_)}),I.jsx(fr,{x:_.x,y:_.y,position:_.position,type:"target",onPointerDown:E=>m("target",E,B,_)})]})]})}const yo=a.memo(go);function Er({selectionKeyCode:e="Shift",selectionMode:t="partial"}){var F;const n=Ie(),[r,i]=a.useState(null),o=a.useRef(null);if(a.useEffect(()=>{const j=n.wrapRef.current;if(!j)return;let A=!1,X=null,B=!1;const _=Y=>{Y.key===e&&(B=!0)},$=Y=>{Y.key===e&&(B=!1)},N=Y=>{if(!B)return;const w=Y.target;if(w.closest(".ric-node-wrapper")||w.closest(".ric-handle"))return;A=!0;const g=n.cameraRef.current,v=j.getBoundingClientRect(),L=(Y.clientX-v.left-g.x)/g.zoom,E=(Y.clientY-v.top-g.y)/g.zoom;X={x:L,y:E},i({startX:L,startY:E,endX:L,endY:E}),Y.stopPropagation()},O=Y=>{if(!A||!X)return;const w=n.cameraRef.current,g=j.getBoundingClientRect(),v=(Y.clientX-g.left-w.x)/w.zoom,L=(Y.clientY-g.top-w.y)/w.zoom;i({startX:X.x,startY:X.y,endX:v,endY:L})},U=Y=>{var K,ae;if(!A||!X)return;A=!1;const w=n.cameraRef.current,g=j.getBoundingClientRect(),v=(Y.clientX-g.left-w.x)/w.zoom,L=(Y.clientY-g.top-w.y)/w.zoom,E={x:Math.min(X.x,v),y:Math.min(X.y,L),width:Math.abs(v-X.x),height:Math.abs(L-X.y)},D=[];for(const ee of n.nodesRef.current){const oe=ee._absolutePosition||ee.position,ye=ee.width||160,we=ee.height||60;let Me;t==="full"?Me=oe.x>=E.x&&oe.y>=E.y&&oe.x+ye<=E.x+E.width&&oe.y+we<=E.y+E.height:Me=oe.x+ye>E.x&&oe.x<E.x+E.width&&oe.y+we>E.y&&oe.y<E.y+E.height,D.push({id:ee.id,type:"select",selected:Me})}D.length&&((ae=(K=n.onNodesChangeRef).current)==null||ae.call(K,D)),X=null,i(null)};return j.addEventListener("pointerdown",N,!0),j.addEventListener("pointermove",O),j.addEventListener("pointerup",U),window.addEventListener("keydown",_),window.addEventListener("keyup",$),()=>{j.removeEventListener("pointerdown",N,!0),j.removeEventListener("pointermove",O),j.removeEventListener("pointerup",U),window.removeEventListener("keydown",_),window.removeEventListener("keyup",$)}},[n,e,t]),!r)return null;const c=((F=n.cameraRef)==null?void 0:F.current)||{x:0,y:0,zoom:1},f=Math.min(r.startX,r.endX),m=Math.min(r.startY,r.endY),d=Math.abs(r.endX-r.startX),h=Math.abs(r.endY-r.startY),b=f*c.zoom+c.x,k=m*c.zoom+c.y,S=d*c.zoom,P=h*c.zoom;return I.jsx("div",{ref:o,className:"ric-selection-box",style:{position:"absolute",left:b,top:k,width:S,height:P,border:"1px dashed #3b82f6",background:"rgba(59, 130, 246, 0.08)",pointerEvents:"none",zIndex:100}})}Er.displayName="SelectionBox";const Sr=a.memo(Er);function Qn(e,t,n){switch(e){case"top":return{x:t/2,y:0};case"bottom":return{x:t/2,y:n};case"left":return{x:0,y:n/2};case"right":return{x:t,y:n/2};default:return{x:t,y:n/2}}}function xo(e,t){const n=e.closest(".ric-node-wrapper");if(!n)return null;const r=n.getBoundingClientRect(),i=e.getBoundingClientRect(),o=t||1;return{x:(i.left+i.width/2-r.left)/o,y:(i.top+i.height/2-r.top)/o}}let On=!1,Et=null;function zr(e){Et=e,!On&&(On=!0,requestAnimationFrame(()=>{var t;On=!1,(t=Et==null?void 0:Et.syncNodesToWorker)==null||t.call(Et),Et=null}))}const Jn=new WeakMap;let bn=null;function po(){return bn||(bn=new ResizeObserver(e=>{var t;for(const n of e){const r=Jn.get(n.target);if(!r)continue;const{width:i,height:o}=n.contentRect;if(!i||!o)continue;const c=r.getStore(),f=(t=c.handleRegistryRef)==null?void 0:t.current;if(f){for(const[m,d]of f)if(d.nodeId===r.nodeId){const h=Qn(d.position,i,o);d.x=h.x,d.y=h.y,f.set(m,d)}zr(c)}}}),bn)}function mo({type:e="source",position:t=e==="source"?"right":"left",id:n,isConnectable:r=!0,isConnectableStart:i=!0,isConnectableEnd:o=!0,children:c,className:f="",style:m={},onConnect:d,...h}){const b=a.useContext(cn),k=a.useContext(St),S=a.useRef(null),P=a.useCallback(()=>typeof k.getState=="function"?k.getState():k,[k]),F=a.useRef(P);F.current=P,a.useLayoutEffect(()=>{var w,g,v,L,E,D,K;if(!b)return;const B=F.current(),_=(w=B.handleRegistryRef)==null?void 0:w.current;if(!_)return;const $=`${b}__${n||e}`,N=(v=(g=B.nodesRef)==null?void 0:g.current)==null?void 0:v.find(ae=>ae.id===b),O=(N==null?void 0:N.width)||((L=N==null?void 0:N.measured)==null?void 0:L.width),U=(N==null?void 0:N.height)||((E=N==null?void 0:N.measured)==null?void 0:E.height);let Y;O&&U?Y=Qn(t,O,U):S.current?Y=xo(S.current,(K=(D=B.cameraRef)==null?void 0:D.current)==null?void 0:K.zoom):Y=Qn(t,160,60),_.set($,{nodeId:b,id:n||null,type:e,position:t,x:Y.x,y:Y.y})},[b,n,e,t]),a.useEffect(()=>{if(!b)return;const B=F.current();zr(B);const _=S.current,$=_==null?void 0:_.closest(".ric-node-wrapper");return $&&!Jn.has($)&&(Jn.set($,{nodeId:b,getStore:F.current}),po().observe($)),()=>{var Y;const O=(Y=F.current().handleRegistryRef)==null?void 0:Y.current,U=`${b}__${n||e}`;O==null||O.delete(U)}},[b,n,e,t]);const j=a.useCallback(()=>{var g;const B=F.current(),_=B.nodesRef.current.find(v=>v.id===b);if(!_)return null;const $=_._absolutePosition||_.position,N=(g=B.handleRegistryRef)==null?void 0:g.current,O=`${b}__${n||e}`,U=N==null?void 0:N.get(O);if(U&&U.x!==void 0&&U.y!==void 0)return{x:$.x+U.x,y:$.y+U.y};const Y=_.width||160,w=_.height||60;switch(t){case"top":return{x:$.x+Y/2,y:$.y};case"bottom":return{x:$.x+Y/2,y:$.y+w};case"left":return{x:$.x,y:$.y+w/2};default:return{x:$.x+Y,y:$.y+w/2}}},[b,n,e,t]),A=a.useCallback(B=>{var L;if(!r||!i)return;B.stopPropagation(),B.preventDefault();const _=F.current(),$=_.cameraRef.current,N=_.wrapRef.current;if(!N)return;const O=N.getBoundingClientRect(),U=j();if(!U)return;const Y=U.x,w=U.y;(L=_.workerRef.current)==null||L.postMessage({type:"connecting",data:{from:{x:Y,y:w},to:{x:Y,y:w}}}),N.setPointerCapture(B.pointerId);const g=E=>{var ae;const D=(E.clientX-O.left-$.x)/$.zoom,K=(E.clientY-O.top-$.y)/$.zoom;(ae=_.workerRef.current)==null||ae.postMessage({type:"connecting",data:{from:{x:Y,y:w},to:{x:D,y:K}}})},v=E=>{var we,Me,le,Se;const D=(E.clientX-O.left-$.x)/$.zoom,K=(E.clientY-O.top-$.y)/$.zoom,ae=20/$.zoom;let ee=null,oe=null;const ye=(we=_.handleRegistryRef)==null?void 0:we.current;for(const se of _.nodesRef.current){if(se.id===b||se.hidden)continue;const fe=se._absolutePosition||se.position,be=[];if(ye)for(const[,xe]of ye)xe.nodeId===se.id&&be.push(xe);const We=be.length>0?be:se.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const xe of We){let ue,Te;if(xe.x!==void 0&&xe.y!==void 0)ue=fe.x+xe.x,Te=fe.y+xe.y;else{const He=se.width||160,Fe=se.height||60;switch(xe.position||(xe.type==="source"?"right":"left")){case"top":ue=fe.x+He/2,Te=fe.y;break;case"bottom":ue=fe.x+He/2,Te=fe.y+Fe;break;case"left":ue=fe.x,Te=fe.y+Fe/2;break;default:ue=fe.x+He,Te=fe.y+Fe/2;break}}if(Math.abs(D-ue)<ae&&Math.abs(K-Te)<ae){ee=se,oe=xe.id||null;break}}if(ee)break}if(ee){const se={source:e==="source"?b:ee.id,target:e==="source"?ee.id:b,sourceHandle:e==="source"?n||null:oe,targetHandle:e==="source"?oe:n||null};(le=(Me=_.onEdgesChangeRef)==null?void 0:Me.current)==null||le.call(Me,[{type:"add",item:{id:`e-${se.source}-${se.target}`,...se}}])}(Se=_.workerRef.current)==null||Se.postMessage({type:"connecting",data:null}),N.removeEventListener("pointermove",g),N.removeEventListener("pointerup",v)};N.addEventListener("pointermove",g),N.addEventListener("pointerup",v)},[b,n,e,t,r,i,j]),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 I.jsx("div",{ref:S,className:`ric-handle ric-handle-${t} ric-handle-${e} ${f}`,"data-handleid":n||null,"data-nodeid":b,"data-handlepos":t,"data-handletype":e,onPointerDown:A,style:{position:"absolute",width:8,height:8,borderRadius:"50%",background:"#1a192b",border:"none",zIndex:10,cursor:r?"crosshair":"default",boxSizing:"border-box",...X,...m},...h,children:c})}const an=a.memo(mo);function vo({data:e,isConnectable:t,selected:n,targetPosition:r="left",sourcePosition:i="right",hideSourceHandle:o=!1,hideTargetHandle:c=!1}){return I.jsxs("div",{className:`ric-default-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!c&&I.jsx(an,{type:"target",position:r,isConnectable:t}),I.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!o&&I.jsx(an,{type:"source",position:i,isConnectable:t})]})}function Pr({data:e,isConnectable:t,selected:n,sourcePosition:r="right",hideSourceHandle:i=!1}){return I.jsxs("div",{className:`ric-input-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderBottom:"2px solid #0041d0",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[I.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!i&&I.jsx(an,{type:"source",position:r,isConnectable:t})]})}function Nr({data:e,isConnectable:t,selected:n,targetPosition:r="left",hideTargetHandle:i=!1}){return I.jsxs("div",{className:`ric-output-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderTop:"2px solid #ff0072",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!i&&I.jsx(an,{type:"target",position:r,isConnectable:t}),I.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label})]})}function Ir({data:e,selected:t,width:n,height:r}){return I.jsx("div",{className:`ric-group-node${t?" selected":""}`,style:{width:n||300,height:r||200,background:"rgba(240, 240, 240, 0.25)",border:t?"2px solid #3b82f6":"1px dashed #ccc",borderRadius:8,padding:8,boxSizing:"border-box"},children:(e==null?void 0:e.label)&&I.jsx("div",{style:{fontSize:11,fontWeight:600,color:"#888",userSelect:"none"},children:e.label})})}function Tr({x:e,y:t,label:n,labelStyle:r,labelShowBg:i=!0,labelBgStyle:o,labelBgPadding:c=[2,4],labelBgBorderRadius:f=2,children:m,className:d="",...h}){const[b,k]=a.useState({x:1,y:0,width:0,height:0}),S=a.useRef(null);return a.useEffect(()=>{if(S.current){const P=S.current.getBBox();k({x:P.x,y:P.y,width:P.width,height:P.height})}},[n]),n?I.jsxs("g",{transform:`translate(${e-b.width/2} ${t-b.height/2})`,className:`ric-edge-textwrapper ${d}`,visibility:b.width?"visible":"hidden",...h,children:[i&&I.jsx("rect",{width:b.width+2*c[0],x:-c[0],y:-c[1],height:b.height+2*c[1],className:"ric-edge-textbg",style:o,rx:f,ry:f}),I.jsx("text",{className:"ric-edge-text",y:b.height/2,dy:"0.3em",ref:S,style:r,children:n}),m]}):null}Tr.displayName="EdgeText";const Lr=a.memo(Tr);function hr(e){return e!=null&&e!==""&&!isNaN(Number(e))}function ln({id:e,path:t,labelX:n,labelY:r,label:i,labelStyle:o,labelShowBg:c,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:d,interactionWidth:h=20,style:b,markerEnd:k,markerStart:S,className:P="",...F}){return I.jsxs(I.Fragment,{children:[I.jsx("path",{id:e,d:t,fill:"none",stroke:"#b1b1b7",strokeWidth:1.5,className:`ric-edge-path ${P}`,style:b,markerEnd:k,markerStart:S,...F}),h?I.jsx("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:h,className:"ric-edge-interaction",style:{pointerEvents:"stroke"}}):null,i&&hr(n)&&hr(r)?I.jsx(Lr,{x:n,y:r,label:i,labelStyle:o,labelShowBg:c,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:d}):null]})}const rn=20;function gr(e,t,n){switch(n){case"right":return{x:e+rn,y:t};case"left":return{x:e-rn,y:t};case"bottom":return{x:e,y:t+rn};case"top":return{x:e,y:t-rn};default:return{x:e+rn,y:t}}}const er=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:c="bottom",targetPosition:f="top",label:m,labelStyle:d,labelShowBg:h,labelBgStyle:b,labelBgPadding:k,labelBgBorderRadius:S,style:P,markerEnd:F,markerStart:j,interactionWidth:A}){let X,B,_;const $=gr(n,r,c),N=gr(i,o,f),O=Math.abs(N.x-$.x),U=Math.max(50,O*.5);let Y,w,g,v;switch(c){case"left":Y=$.x-U,w=$.y;break;case"top":Y=$.x,w=$.y-U;break;case"bottom":Y=$.x,w=$.y+U;break;default:Y=$.x+U,w=$.y;break}switch(f){case"right":g=N.x+U,v=N.y;break;case"top":g=N.x,v=N.y-U;break;case"bottom":g=N.x,v=N.y+U;break;default:g=N.x-U,v=N.y;break}X=`M ${n},${r} L ${$.x},${$.y} C ${Y},${w} ${g},${v} ${N.x},${N.y} L ${i},${o}`;const L=.5,E=.5;return B=E*E*E*$.x+3*E*E*L*Y+3*E*L*L*g+L*L*L*N.x,_=E*E*E*$.y+3*E*E*L*w+3*E*L*L*v+L*L*L*N.y,I.jsx(ln,{id:t,path:X,labelX:B,labelY:_,label:m,labelStyle:d,labelShowBg:h,labelBgStyle:b,labelBgPadding:k,labelBgBorderRadius:S,style:P,markerEnd:F,markerStart:j,interactionWidth:A})});er.displayName="BezierEdge";function tr({sourceX:e,sourceY:t,targetX:n,targetY:r}){const i=`M ${e},${t}L ${n},${r}`,o=(e+n)/2,c=(t+r)/2;return[i,o,c,0,0]}function nr({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i="right",targetPosition:o="left",curvature:c=.25}){const f=Math.abs(n-e),m=Math.abs(r-t),d=Math.sqrt(f*f+m*m),h=Math.max(d*c,50);let b,k,S,P;switch(i){case"top":b=e,k=t-h;break;case"bottom":b=e,k=t+h;break;case"left":b=e-h,k=t;break;default:b=e+h,k=t;break}switch(o){case"top":S=n,P=r-h;break;case"bottom":S=n,P=r+h;break;case"right":S=n+h,P=r;break;default:S=n-h,P=r;break}const F=`M ${e},${t} C ${b},${k} ${S},${P} ${n},${r}`,j=.5,A=1-j,X=A*A*A*e+3*A*A*j*b+3*A*j*j*S+j*j*j*n,B=A*A*A*t+3*A*A*j*k+3*A*j*j*P+j*j*j*r;return[F,X,B,0,0]}function rr({sourceX:e,sourceY:t,targetX:n,targetY:r}){const i=Math.abs(n-e),o=Math.max(i*.5,50),c=e+o,f=n-o,m=`M ${e},${t} C ${c},${t} ${f},${r} ${n},${r}`,d=.5,h=.5,b=h*h*h*e+3*h*h*d*c+3*h*d*d*f+d*d*d*n,k=h*h*h*t+3*h*h*d*t+3*h*d*d*r+d*d*d*r;return[m,b,k,0,0]}function Rn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i="right",targetPosition:o="left",borderRadius:c=5,offset:f=20}){const m=i==="left"||i==="right",d=Math.min(c,Math.abs(n-e)/2,Math.abs(r-t)/2);if(m){if(Math.abs(r-t)<1)return[`M ${e},${t} L ${n},${r}`,(e+n)/2,t,0,0];const S=(e+n)/2,P=r>t?1:-1;return[`M ${e},${t} L ${S-d},${t} Q ${S},${t} ${S},${t+P*d} L ${S},${r-P*d} Q ${S},${r} ${S+(n>S?d:-d)},${r} L ${n},${r}`,S,(t+r)/2,0,0]}const h=(t+r)/2,b=n>e?1:-1;return[`M ${e},${t} L ${e},${h-d} Q ${e},${h} ${e+b*d},${h} L ${n-b*d},${h} Q ${n},${h} ${n},${h+(r>h?d:-d)} L ${n},${r}`,(e+n)/2,h,0,0]}function bo({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[,i,o]=nr({sourceX:e,sourceY:t,targetX:n,targetY:r});return[i,o,0,0]}function wo({sourceX:e,sourceY:t,targetX:n,targetY:r}){return[(e+n)/2,(t+r)/2,0,0]}function Mo(e,t,n){const r=n.filter(o=>o.id!==e.id),i={...e,id:e.id,source:t.source,target:t.target,sourceHandle:t.sourceHandle??e.sourceHandle,targetHandle:t.targetHandle??e.targetHandle};return r.push(i),r}const kn=160,Cn=60,on=20,wn=12,En=20;function yr(e,t,n){var c,f;const r=e.width||((c=e.measured)==null?void 0:c.width)||kn,i=e.height||((f=e.measured)==null?void 0:f.height)||Cn,o=e._absolutePosition||e.position;if(e.handles&&e.handles.length>0){for(const m of e.handles)if(m.type===t&&(!n||m.id===n)){if(m.x!==void 0&&m.y!==void 0)return{x:o.x+m.x,y:o.y+m.y,dir:m.position||(t==="source"?"right":"left")};switch(m.position||(t==="source"?"right":"left")){case"top":return{x:o.x+r/2,y:o.y,dir:"top"};case"bottom":return{x:o.x+r/2,y:o.y+i,dir:"bottom"};case"left":return{x:o.x,y:o.y+i/2,dir:"left"};default:return{x:o.x+r,y:o.y+i/2,dir:"right"}}}}return t==="source"?{x:o.x+r,y:o.y+i/2,dir:"right"}:{x:o.x,y:o.y+i/2,dir:"left"}}function Sn(e,t){switch(e.dir){case"right":return{x:e.x+t,y:e.y,dir:e.dir};case"left":return{x:e.x-t,y:e.y,dir:e.dir};case"bottom":return{x:e.x,y:e.y+t,dir:e.dir};case"top":return{x:e.x,y:e.y-t,dir:e.dir};default:return{x:e.x+t,y:e.y,dir:e.dir}}}function Ro(e,t,n,r,i,o,c,f){const m=Math.min(e,n),d=Math.max(e,n),h=Math.min(t,r),b=Math.max(t,r);if(d<=i||m>=i+c||b<=o||h>=o+f)return!1;const k=.5;if(e>i+k&&e<i+c-k&&t>o+k&&t<o+f-k||n>i+k&&n<i+c-k&&r>o+k&&r<o+f-k)return!0;const S=(e+n)/2,P=(t+r)/2;if(S>i+k&&S<i+c-k&&P>o+k&&P<o+f-k)return!0;const F=[[i,o],[i+c,o],[i+c,o+f],[i,o+f]];for(let j=0;j<4;j++)if(ko(e,t,n,r,F[j][0],F[j][1],F[(j+1)%4][0],F[(j+1)%4][1]))return!0;return!1}function ko(e,t,n,r,i,o,c,f){const m=(c-i)*(t-o)-(f-o)*(e-i),d=(c-i)*(r-o)-(f-o)*(n-i),h=(n-e)*(o-t)-(r-t)*(i-e),b=(n-e)*(f-t)-(r-t)*(c-e);return(m>0&&d<0||m<0&&d>0)&&(h>0&&b<0||h<0&&b>0)}function Vn(e,t,n,r,i){for(let o=0;o<i.length;o++){const c=i[o];if(Ro(e,t,n,r,c.x,c.y,c.w,c.h))return!1}return!0}function Co(e,t,n){for(let r=0;r<n.length;r++){const i=n[r];if(e>i.x&&e<i.x+i.w&&t>i.y&&t<i.y+i.h)return!0}return!1}function or(e,t){var r,i;const n=[];for(let o=0;o<e.length;o++){const c=e[o];if(c.hidden||t&&t.has(c.id)||c.type==="group")continue;const f=c._absolutePosition||c.position,m=c.width||((r=c.measured)==null?void 0:r.width)||kn,d=c.height||((i=c.measured)==null?void 0:i.height)||Cn;n.push({id:c.id,x:f.x-on,y:f.y-on,w:m+2*on,h:d+2*on})}return n}function Br(e,t,n){if(Vn(e.x,e.y,t.x,t.y,n))return null;const r=new Set,i=new Set;r.add(e.x),r.add(t.x),i.add(e.y),i.add(t.y);const o=on+5;e.dir==="right"?r.add(e.x+o):e.dir==="left"?r.add(e.x-o):e.dir==="top"?i.add(e.y-o):e.dir==="bottom"&&i.add(e.y+o),t.dir==="right"?r.add(t.x+o):t.dir==="left"?r.add(t.x-o):t.dir==="top"?i.add(t.y-o):t.dir==="bottom"&&i.add(t.y+o);for(let g=0;g<n.length;g++){const v=n[g];r.add(v.x),r.add(v.x+v.w),i.add(v.y),i.add(v.y+v.h)}const c=[...r].sort((g,v)=>g-v),f=[...i].sort((g,v)=>g-v),m=new Map,d=new Map;for(let g=0;g<c.length;g++)m.set(c[g],g);for(let g=0;g<f.length;g++)d.set(f[g],g);const h=c.length,b=f.length,k=(g,v)=>v*h+g,S=m.get(e.x),P=d.get(e.y),F=m.get(t.x),j=d.get(t.y);if(S===void 0||P===void 0||F===void 0||j===void 0)return null;const A=k(S,P),X=k(F,j),B=new Float64Array(h*b).fill(1/0),_=new Float64Array(h*b).fill(1/0),$=new Int32Array(h*b).fill(-1),N=new Int8Array(h*b).fill(-1),O=new Uint8Array(h*b);B[A]=0,_[A]=Math.abs(c[F]-e.x)+Math.abs(f[j]-e.y);const U=[A],Y=15,w=[[1,0],[-1,0],[0,1],[0,-1]];for(;U.length>0;){let g=0;for(let ee=1;ee<U.length;ee++)_[U[ee]]<_[U[g]]&&(g=ee);const v=U[g];if(U[g]=U[U.length-1],U.pop(),v===X){const ee=[];let oe=X;for(;oe!==-1&&oe!==A;){const ye=oe/h|0,we=oe%h;ee.unshift({x:c[we],y:f[ye]}),oe=$[oe]}return ee.unshift({x:e.x,y:e.y}),Eo(ee,n)}if(O[v])continue;O[v]=1;const L=v/h|0,E=v%h,D=c[E],K=f[L],ae=N[v];for(let ee=0;ee<4;ee++){const oe=E+w[ee][0],ye=L+w[ee][1];if(oe<0||oe>=h||ye<0||ye>=b)continue;const we=k(oe,ye);if(O[we])continue;const Me=c[oe],le=f[ye];if(Co(Me,le,n)||!Vn(D,K,Me,le,n))continue;const Se=Math.abs(Me-D)+Math.abs(le-K),se=ae>=0&&ae!==ee?Y:0,fe=B[v]+Se+se;fe<B[we]&&($[we]=v,N[we]=ee,B[we]=fe,_[we]=fe+Math.abs(c[F]-Me)+Math.abs(f[j]-le),U.push(we))}}return null}function Eo(e,t){if(!e||e.length<=2)return e;const n=[e[0]];for(let r=1;r<e.length-1;r++){const i=n[n.length-1],o=e[r],c=e[r+1],f=Math.abs(i.x-o.x)<.5&&Math.abs(o.x-c.x)<.5,m=Math.abs(i.y-o.y)<.5&&Math.abs(o.y-c.y)<.5;(f||m)&&Vn(i.x,i.y,c.x,c.y,t)||n.push(o)}return n.push(e[e.length-1]),n}function So(e){const t=new Map,n=new Map;for(const i of e){const o=i._routedPoints;if(!(!o||o.length<2))for(let c=0;c<o.length-1;c++){const f=o[c],m=o[c+1];if(Math.abs(f.y-m.y)<.5){const d=Math.round(f.y*10)/10;t.has(d)||t.set(d,[]),t.get(d).push({edgeId:i.id,segIdx:c,x1:Math.min(f.x,m.x),x2:Math.max(f.x,m.x)})}else if(Math.abs(f.x-m.x)<.5){const d=Math.round(f.x*10)/10;n.has(d)||n.set(d,[]),n.get(d).push({edgeId:i.id,segIdx:c,y1:Math.min(f.y,m.y),y2:Math.max(f.y,m.y)})}}}const r=new Map;for(const i of e)i._routedPoints&&r.set(i.id,i._routedPoints.map(o=>({...o})));for(const[,i]of t){if(i.length<2)continue;const o=xr(i,"x1","x2");for(const c of o){if(c.length<2)continue;const f=(c.length-1)*wn/2;for(let m=0;m<c.length;m++){const d=c[m],h=-f+m*wn,b=r.get(d.edgeId);b&&(b[d.segIdx].y+=h,b[d.segIdx+1].y+=h)}}}for(const[,i]of n){if(i.length<2)continue;const o=xr(i,"y1","y2");for(const c of o){if(c.length<2)continue;const f=(c.length-1)*wn/2;for(let m=0;m<c.length;m++){const d=c[m],h=-f+m*wn,b=r.get(d.edgeId);b&&(b[d.segIdx].x+=h,b[d.segIdx+1].x+=h)}}}return e.map(i=>{const o=r.get(i.id);return o?{...i,_routedPoints:o}:i})}function xr(e,t,n){if(e.length<2)return[];const r=[...e].sort((c,f)=>c[t]-f[t]),i=[];let o=[r[0]];for(let c=1;c<r.length;c++){const f=o[o.length-1];r[c][t]<f[n]?o.push(r[c]):(o.length>1&&i.push(o),o=[r[c]])}return o.length>1&&i.push(o),i}function zn(e,t=6,n=!1){if(!e||e.length<2)return null;if(n)return zo(e);const r=t;let i=`M ${e[0].x},${e[0].y}`;for(let o=1;o<e.length-1;o++){const c=e[o-1],f=e[o],m=e[o+1],d=Math.abs(f.x-c.x)+Math.abs(f.y-c.y),h=Math.abs(m.x-f.x)+Math.abs(m.y-f.y),b=Math.min(r,d/2,h/2);if(b>.5){const k=f.x-c.x,S=f.y-c.y,P=m.x-f.x,F=m.y-f.y,j=Math.sqrt(k*k+S*S)||1,A=Math.sqrt(P*P+F*F)||1;i+=` L ${f.x-k/j*b},${f.y-S/j*b}`,i+=` Q ${f.x},${f.y} ${f.x+P/A*b},${f.y+F/A*b}`}else i+=` L ${f.x},${f.y}`}return i+=` L ${e[e.length-1].x},${e[e.length-1].y}`,i}function zo(e){if(e.length===2)return`M ${e[0].x},${e[0].y} L ${e[1].x},${e[1].y}`;if(e.length===3)return`M ${e[0].x},${e[0].y} Q ${e[1].x},${e[1].y} ${e[2].x},${e[2].y}`;const t=.3;let n=`M ${e[0].x},${e[0].y}`;for(let r=0;r<e.length-1;r++){const i=e[r===0?0:r-1],o=e[r],c=e[r+1],f=e[r+2<e.length?r+2:e.length-1],m=o.x+(c.x-i.x)*t,d=o.y+(c.y-i.y)*t,h=c.x-(f.x-o.x)*t,b=c.y-(f.y-o.y)*t;n+=` C ${m},${d} ${h},${b} ${c.x},${c.y}`}return n}function Pn(e){if(!e||e.length<2)return{x:0,y:0};let t=0;for(let r=1;r<e.length;r++)t+=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);let n=t/2;for(let r=1;r<e.length;r++){const i=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);if(n<=i){const o=i>0?n/i:0;return{x:e[r-1].x+(e[r].x-e[r-1].x)*o,y:e[r-1].y+(e[r].y-e[r-1].y)*o}}n-=i}return{x:e[0].x,y:e[0].y}}function Po(e,t){if(!e||!t||e.length===0||t.length===0)return t;const n={};for(const o of e)n[o.id]=o;const r=or(e,null),i=t.map(o=>{var N,O,U,Y;const c=o.type||"default";if(c==="bezier"||c==="simplebezier"||c==="default")return o;const f=n[o.source],m=n[o.target];if(!f||!m||f.hidden||m.hidden)return o;const d=yr(f,"source",o.sourceHandle),h=yr(m,"target",o.targetHandle),b=Sn(d,En),k=Sn(h,En),S=5,P=r.filter(w=>w.id!==o.source&&w.id!==o.target),F=f._absolutePosition||f.position,j=f.width||((N=f.measured)==null?void 0:N.width)||kn,A=f.height||((O=f.measured)==null?void 0:O.height)||Cn;P.push({id:o.source,x:F.x-S,y:F.y-S,w:j+2*S,h:A+2*S});const X=m._absolutePosition||m.position,B=m.width||((U=m.measured)==null?void 0:U.width)||kn,_=m.height||((Y=m.measured)==null?void 0:Y.height)||Cn;if(P.push({id:o.target,x:X.x-S,y:X.y-S,w:B+2*S,h:_+2*S}),P.length===0)return o;const $=Br(b,k,P);return $&&$.length>=2?($.unshift({x:d.x,y:d.y}),$.push({x:h.x,y:h.y}),{...o,_routedPoints:$}):o});return So(i)}function No(e,t,n,r,i,o,c,f){const m=or(c,f?new Set(f):null);if(m.length===0)return null;const d={x:e,y:t,dir:i||"right"},h={x:n,y:r,dir:o||"left"},b=Sn(d,En),k=Sn(h,En),S=Br(b,k,m);return S&&S.length>=2?(S.unshift({x:d.x,y:d.y}),S.push({x:h.x,y:h.y}),S):null}const sr=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,label:c,labelStyle:f,labelShowBg:m,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:b,style:k,markerEnd:S,markerStart:P,interactionWidth:F,routedPoints:j}){let A,X,B;if(j&&j.length>=2){A=zn(j);const _=Pn(j);X=_.x,B=_.y}else[A,X,B]=tr({sourceX:n,sourceY:r,targetX:i,targetY:o});return I.jsx(ln,{id:t,path:A,labelX:X,labelY:B,label:c,labelStyle:f,labelShowBg:m,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:b,style:k,markerEnd:S,markerStart:P,interactionWidth:F})});sr.displayName="StraightEdge";const ir=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:c="bottom",targetPosition:f="top",label:m,labelStyle:d,labelShowBg:h,labelBgStyle:b,labelBgPadding:k,labelBgBorderRadius:S,style:P,markerEnd:F,markerStart:j,pathOptions:A,interactionWidth:X,routedPoints:B}){let _,$,N;if(B&&B.length>=2){_=zn(B);const O=Pn(B);$=O.x,N=O.y}else[_,$,N]=Rn({sourceX:n,sourceY:r,sourcePosition:c,targetX:i,targetY:o,targetPosition:f,borderRadius:A==null?void 0:A.borderRadius,offset:A==null?void 0:A.offset});return I.jsx(ln,{id:t,path:_,labelX:$,labelY:N,label:m,labelStyle:d,labelShowBg:h,labelBgStyle:b,labelBgPadding:k,labelBgBorderRadius:S,style:P,markerEnd:F,markerStart:j,interactionWidth:X})});ir.displayName="SmoothStepEdge";const $r=a.memo(function({id:t,...n}){var i;const r=a.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(i=n.pathOptions)==null?void 0:i.offset]);return I.jsx(ir,{...n,id:t,pathOptions:r})});$r.displayName="StepEdge";const ar=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:c,targetPosition:f,label:m,labelStyle:d,labelShowBg:h,labelBgStyle:b,labelBgPadding:k,labelBgBorderRadius:S,style:P,markerEnd:F,markerStart:j,interactionWidth:A,routedPoints:X}){let B,_,$;if(X&&X.length>=2){B=zn(X);const N=Pn(X);_=N.x,$=N.y}else[B,_,$]=rr({sourceX:n,sourceY:r,targetX:i,targetY:o});return I.jsx(ln,{id:t,path:B,labelX:_,labelY:$,label:m,labelStyle:d,labelShowBg:h,labelBgStyle:b,labelBgPadding:k,labelBgBorderRadius:S,style:P,markerEnd:F,markerStart:j,interactionWidth:A})});ar.displayName="SimpleBezierEdge";const Io={input:Pr,output:Nr,group:Ir},To={bezier:er,straight:sr,simplebezier:ar},Lo=160,Bo=60;function $o(e){let t=!1;for(let n=0;n<e.length;n++){const r=e[n];if(!r.measured||r.measured.width==null||r.measured.height==null){t=!0;break}}return t?e.map(n=>{var r,i;return((r=n.measured)==null?void 0:r.width)!=null&&((i=n.measured)==null?void 0:i.height)!=null?n:{...n,measured:{width:n.width||Lo,height:n.height||Bo}}}):e}function jo({cards:e,nodes:t=[],edges:n=[],nodeTypes:r,edgeTypes:i,canvasNodeTypes:o,domNodeLimit:c=50,dark:f,gridSize:m,width:d="100%",height:h="420px",className:b="",style:k={},zoomMin:S,zoomMax:P,initialCamera:F,fitView:j,fitViewOptions:A,onNodesChange:X,onEdgesChange:B,onConnect:_,onConnectStart:$,onConnectEnd:N,onNodeClick:O,onNodeDoubleClick:U,onNodeMouseEnter:Y,onNodeMouseMove:w,onNodeMouseLeave:g,onNodeContextMenu:v,onNodeDragStart:L,onNodeDrag:E,onNodeDragStop:D,onEdgeClick:K,onEdgeDoubleClick:ae,onEdgeMouseEnter:ee,onEdgeMouseMove:oe,onEdgeMouseLeave:ye,onEdgeContextMenu:we,onPaneClick:Me,onPaneContextMenu:le,onPaneMouseEnter:Se,onPaneMouseMove:se,onPaneMouseLeave:fe,onSelectionChange:be,onInit:We,onMoveStart:xe,onMove:ue,onMoveEnd:Te,onDelete:He,onBeforeDelete:Fe,onError:rt,onDragOver:ht,onDrop:$e,onDragEnter:Le,onDragLeave:ze,nodesDraggable:Qe,nodesConnectable:Je,elementsSelectable:Ae,multiSelectionKeyCode:ot,selectionOnDrag:zt,selectionMode:De,connectionMode:et,connectionRadius:tt,connectOnClick:un,isValidConnection:dn,defaultEdgeOptions:qt,snapToGrid:pt,snapGrid:mt,deleteKeyCode:Pt,panActivationKeyCode:Nn,panOnScroll:In,panOnScrollMode:st,panOnScrollSpeed:cr,zoomOnScroll:Tn,zoomOnDoubleClick:Ln,zoomOnPinch:Nt,preventScrolling:It,translateExtent:Bn,nodeExtent:$n,autoPanOnNodeDrag:jn,autoPanOnConnect:kt,autoPanSpeed:ve,edgesReconnectable:Tt,elevateNodesOnSelect:Pe,elevateEdgesOnSelect:he,noDragClassName:vt,noPanClassName:te,onSelectionDragStart:Ne,onSelectionDrag:fn,onSelectionDragStop:Lt,edgeRouting:Bt=!0,onHudUpdate:$t,onNodesProcessed:An,showHud:Ye=!0,showHint:Oe=!0,hintText:jt="Drag to pan · Scroll to zoom",children:it,...hn}){const[Ve,gn]=a.useState({wx:0,wy:0,zoom:"1.00"}),yn=a.useRef(null),Zt=a.useRef(null),xn=a.useCallback(W=>{gn(W),$t==null||$t(W)},[$t]),bt=a.useMemo(()=>({...Io,...r}),[r]),at=a.useMemo(()=>({...To,...i}),[i]),Ke=a.useMemo(()=>$o(t),[t]),[J,ct]=a.useState(()=>new Set),Ct=a.useRef(J);Ct.current=J;const At=a.useCallback(W=>{ct(pe=>{const ne=new Set(pe);return ne.add(W),ne})},[]),Dt=a.useCallback(W=>{ct(pe=>{const ne=new Set(pe);return ne.delete(W),ne})},[]),Ht=a.useCallback(W=>{ct(pe=>{const ne=new Set(pe);return ne.has(W)?ne.delete(W):ne.add(W),ne})},[]),wt=a.useMemo(()=>Ke.filter(W=>W.type&&bt[W.type]),[Ke,bt]),_t=a.useMemo(()=>n.filter(W=>W.type&&at[W.type]),[n,at]),[Wt,Ft]=a.useState(()=>new Set),Yt=a.useRef(new Set),Ce=a.useMemo(()=>{const W=new Set(Wt);for(const ne of J)W.add(ne);for(const ne of wt)(ne.selected||ne.dragging)&&W.add(ne.id);const pe=Yt.current;if(pe.size===W.size){let ne=!0;for(const Ee of W)if(!pe.has(Ee)){ne=!1;break}if(ne)return pe}return Yt.current=W,W},[wt,J,Wt]),gt=a.useMemo(()=>{if(c===0)return[];const W=Ke.filter(pe=>Ce.has(pe.id));return W.sort((pe,ne)=>{const Ee=pe.type==="group"||!pe.parentId&&W.some(y=>y.parentId===pe.id),u=ne.type==="group"||!ne.parentId&&W.some(y=>y.parentId===ne.id);return Ee&&!u?-1:!Ee&&u?1:0})},[Ke,Ce,c]),_e=a.useMemo(()=>t.map(W=>Ce.has(W.id)?{...W,_customRendered:!0}:W),[t,Ce]),Dn=a.useMemo(()=>n.map(W=>W.type&&at[W.type]?{...W,_customRendered:!0}:W),[n,at]),{wrapRef:yt,canvasRef:Xt,canvasReady:lt,onPointerDown:Mt,onPointerMove:pn,onPointerUp:Be,store:de}=Mr({cards:e,nodes:_e,edges:Dn,dark:f,gridSize:m,zoomMin:S,zoomMax:P,initialCamera:F,fitView:j,fitViewOptions:A,onHudUpdate:xn,onNodesProcessed:An,onNodesChange:X,onEdgesChange:B,onConnect:_,onConnectStart:$,onConnectEnd:N,onNodeClick:O,onNodeDoubleClick:U,onNodeMouseEnter:Y,onNodeMouseMove:w,onNodeMouseLeave:g,onNodeContextMenu:v,onNodeDragStart:L,onNodeDrag:E,onNodeDragStop:D,onEdgeClick:K,onEdgeDoubleClick:ae,onEdgeMouseEnter:ee,onEdgeMouseMove:oe,onEdgeMouseLeave:ye,onEdgeContextMenu:we,onPaneClick:Me,onPaneContextMenu:le,onPaneMouseEnter:Se,onPaneMouseMove:se,onPaneMouseLeave:fe,onSelectionChange:be,onInit:We,onMoveStart:xe,onMove:ue,onMoveEnd:Te,onDelete:He,onBeforeDelete:Fe,onError:rt,nodesDraggable:Qe,nodesConnectable:Je,elementsSelectable:Ae,multiSelectionKeyCode:ot,selectionOnDrag:zt,selectionMode:De,connectionMode:et,connectionRadius:tt,connectOnClick:un,isValidConnection:dn,defaultEdgeOptions:qt,snapToGrid:pt,snapGrid:mt,deleteKeyCode:Pt,panActivationKeyCode:Nn,panOnScroll:In,panOnScrollMode:st,panOnScrollSpeed:cr,zoomOnScroll:Tn,zoomOnDoubleClick:Ln,zoomOnPinch:Nt,preventScrolling:It,translateExtent:Bn,nodeExtent:$n,autoPanOnNodeDrag:jn,autoPanOnConnect:kt,autoPanSpeed:ve,edgesReconnectable:Tt,elevateNodesOnSelect:Pe,elevateEdgesOnSelect:he,noDragClassName:vt,noPanClassName:te,onSelectionDragStart:Ne,onSelectionDrag:fn,onSelectionDragStop:Lt,edgeRouting:Bt}),Gt=a.useRef(wt);Gt.current=wt;const Qt=a.useRef(c);Qt.current=c,a.useEffect(()=>{let W;const pe=()=>{const Ee=Gt.current,u=Qt.current;if(u===0||!Ee.length)return;const y=de.cameraRef.current,l=de.wrapRef.current;if(!l)return;const p=l.clientWidth,C=l.clientHeight,z=(-y.x+p/2)/y.zoom,x=(-y.y+C/2)/y.zoom,M=Ct.current;let R=M.size;for(const T of Ee)(T.selected||T.dragging)&&R++;const H=Math.max(0,u-R);if(H===0)Ft(T=>T.size===0?T:new Set);else{const T=new Set(M);for(const Z of Ee)(Z.selected||Z.dragging)&&T.add(Z.id);const q=[];for(let Z=0;Z<Ee.length;Z++){const ie=Ee[Z];if(T.has(ie.id))continue;const V=ie._absolutePosition||ie.position,ce=V.x+(ie.width||160)/2-z,ke=V.y+(ie.height||60)/2-x;q.push({id:ie.id,dist:ce*ce+ke*ke})}q.sort((Z,ie)=>Z.dist-ie.dist);const G=new Set;for(let Z=0;Z<Math.min(H,q.length);Z++)G.add(q[Z].id);Ft(Z=>{if(Z.size!==G.size)return G;for(const ie of G)if(!Z.has(ie))return G;return Z})}},ne=setTimeout(pe,100);return W=setInterval(pe,500),()=>{clearTimeout(ne),clearInterval(W)}},[de.cameraRef,de.wrapRef]);const Rt=a.useRef(new Set);a.useEffect(()=>{if(!o||!de.workerRef.current)return;let W=!1;async function pe(Ee){const u=new Blob([Ee],{type:"image/svg+xml"}),y=URL.createObjectURL(u),l=new Image;return l.src=y,await l.decode(),URL.revokeObjectURL(y),createImageBitmap(l)}async function ne(){var p,C,z;const Ee={},u=[],y={},l={};for(const[x,M]of Object.entries(o)){if(typeof M=="function"){y[x]=M;continue}if(typeof M=="object"&&M!==null&&!(M instanceof ImageBitmap)&&!(M instanceof HTMLImageElement)&&!(M instanceof HTMLCanvasElement)&&("fill"in M||"stroke"in M||"title"in M||"accent"in M)){l[x]=M;continue}try{let R;M instanceof ImageBitmap?R=M:typeof M=="string"?R=await pe(M):M instanceof HTMLImageElement?R=await createImageBitmap(M):M instanceof HTMLCanvasElement&&(R=await createImageBitmap(M)),R&&!W&&(Ee[x]=R,u.push(R))}catch(R){console.warn(`[InfiniteCanvas] Failed to convert canvasNodeType "${x}":`,R)}}if(!W&&Object.keys(Ee).length>0&&((p=de.workerRef.current)==null||p.postMessage({type:"nodeTypeBitmaps",data:{bitmaps:Ee}},u)),!W&&Object.keys(l).length>0&&((C=de.workerRef.current)==null||C.postMessage({type:"nodeTypeConfigs",data:{configs:l}})),!W&&Object.keys(y).length>0){const x=new Map,M={},R={},H=[];let T=Rt.current.size;for(const q of t){const G=y[q.type];if(G)try{const Z=G(q.data);if(!Z)continue;let ie=x.get(Z);if(!ie&&(ie="bmp_"+T++,x.set(Z,ie),!Rt.current.has(Z))){const V=await pe(Z);if(W)return;M[ie]=V,H.push(V),Rt.current.add(Z)}R[q.id]=ie}catch(Z){console.warn(`[InfiniteCanvas] canvasNodeType fn error for node "${q.id}":`,Z)}}W||(z=de.workerRef.current)==null||z.postMessage({type:"nodeBitmaps",data:{cache:M,keys:R}},H)}}return ne(),()=>{W=!0}},[o,t,de.workerRef]);const qe=a.useContext(St),Jt=qe&&typeof qe.getState=="function";a.useEffect(()=>{Jt&&queueMicrotask(()=>{qe.setState({nodes:Ke,edges:n,nodesRef:de.nodesRef,edgesRef:de.edgesRef,onNodesChangeRef:de.onNodesChangeRef,onEdgesChangeRef:de.onEdgesChangeRef,cameraRef:de.cameraRef,wrapRef:de.wrapRef,workerRef:de.workerRef})})},[Jt,Ke,n,de,qe]);const Re=a.useMemo(()=>({...de,edgeLabelContainerRef:yn,viewportPortalRef:Zt,pinNode:At,unpinNode:Dt,togglePinNode:Ht,get pinnedNodeIds(){return Ct.current},get nodes(){return Ke},get edges(){return n},get viewport(){return de.cameraRef.current},get minZoom(){return de.zoomMin||.1},get maxZoom(){return de.zoomMax||5},get domNode(){return de.wrapRef.current},get width(){var W;return((W=de.wrapRef.current)==null?void 0:W.clientWidth)||0},get height(){var W;return((W=de.wrapRef.current)==null?void 0:W.clientHeight)||0}}),[de,Ke,n,At,Dt,Ht]),ut=a.useRef(null),dt=a.useRef(null),Vt=a.useRef(null),Kt=a.useRef(null),mn=a.useRef(null);a.useEffect(()=>{let W;const pe=()=>{const ne=de.cameraRef.current,Ee=`translate(${ne.x}px, ${ne.y}px) scale(${ne.zoom})`,u=`translate(${ne.x}, ${ne.y}) scale(${ne.zoom})`;ut.current&&(ut.current.style.transform=Ee),dt.current&&dt.current.setAttribute("transform",u),Vt.current&&(Vt.current.style.transform=Ee),Kt.current&&(Kt.current.style.transform=Ee);const y=yt.current;if(y){const l=ne.zoom<.15?"lod-minimal":ne.zoom<.35?"lod-reduced":null;l!==mn.current&&(y.classList.remove("lod-minimal","lod-reduced"),l&&y.classList.add(l),mn.current=l)}W=requestAnimationFrame(pe)};return W=requestAnimationFrame(pe),()=>cancelAnimationFrame(W)},[de]);const[Ot,Hn]=a.useState(null);a.useEffect(()=>{if(!gt.length)return;let W;const pe=()=>{var M,R;const ne=de.cameraRef.current,Ee=de.wrapRef.current;if(!Ee){W=requestAnimationFrame(pe);return}const u=Ee.getBoundingClientRect(),y=200,l=-ne.x/ne.zoom-y,p=-ne.y/ne.zoom-y,C=(u.width-ne.x)/ne.zoom+y,z=(u.height-ne.y)/ne.zoom+y,x=new Set;for(const H of gt){const T=H._absolutePosition||H.position,q=H.width||((M=H.measured)==null?void 0:M.width)||200,G=H.height||((R=H.measured)==null?void 0:R.height)||100;T.x+q>=l&&T.x<=C&&T.y+G>=p&&T.y<=z&&x.add(H.id)}Hn(H=>{if(!H||H.size!==x.size)return x;for(const T of x)if(!H.has(T))return x;return H}),W=requestAnimationFrame(pe)};return W=requestAnimationFrame(pe),()=>cancelAnimationFrame(W)},[gt,de]);const _n=a.useMemo(()=>Ot?gt.filter(W=>Ot.has(W.id)):gt,[gt,Ot]),Wn=gt.length>0,Fn=_t.length>0;return I.jsx(St.Provider,{value:Re,children:I.jsxs("div",{ref:yt,className:`ric-wrap ${b}`,style:{width:d,height:h,...k},onPointerDown:Mt,onPointerMove:pn,onPointerUp:Be,onDragOver:ht,onDrop:$e,onDragEnter:Le,onDragLeave:ze,tabIndex:0,children:[I.jsx("canvas",{ref:Xt,className:"ric-canvas"}),!lt&&I.jsx("div",{className:"ric-loader",children:I.jsx("div",{className:"ric-spinner"})}),Fn&&I.jsx("svg",{className:"ric-edges-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:I.jsx("g",{ref:dt,children:_t.map(W=>I.jsx(yo,{edge:W,edgeType:at[W.type],nodes:t,reconnectable:Tt},W.id))})}),Wn&&I.jsx("div",{ref:ut,className:"ric-nodes-overlay",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:10},children:_n.map(W=>I.jsx(uo,{node:W,nodeType:bt[W.type]},W.id))}),I.jsx("div",{ref:W=>{yn.current=W,Vt.current=W},className:"ric-edge-labels",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:5}}),I.jsx("div",{ref:W=>{Zt.current=W,Kt.current=W},className:"ric-viewport-portal",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:6}}),Oe&&I.jsx("div",{className:"ric-hint",children:jt}),Ye&&I.jsxs("div",{className:"ric-info",children:["world: (",Ve.wx,", ",Ve.wy,") zoom: ",Ve.zoom,"x",Ve.nodeCount>0&&I.jsxs(I.Fragment,{children:[" nodes: ",Ve.nodeCount]}),Ve.edgeCount>0&&I.jsxs(I.Fragment,{children:[" edges: ",Ve.edgeCount]})]}),I.jsx(Sr,{selectionKeyCode:ot||"Shift",selectionMode:De||"partial"}),it]})})}function Ao({children:e}){const t=a.useRef(null);return t.current||(t.current=ao()),I.jsx(St.Provider,{value:t.current,children:e})}function jr(e,t){const n=[],r=new Map,i=[];for(const o of e)if(o.type==="add")i.push(o);else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const c=r.get(o.id);c?c.push(o):r.set(o.id,[o])}for(const o of t){const c=r.get(o.id);if(!c){n.push(o);continue}if(c[0].type==="remove")continue;if(c[0].type==="replace"){n.push({...c[0].item});continue}const f={...o};for(const m of c)Do(m,f);n.push(f)}for(const o of i)o.index!==void 0?n.splice(o.index,0,{...o.item}):n.push({...o.item});return n}function Do(e,t){switch(e.type){case"select":t.selected=e.selected;break;case"position":e.position!==void 0&&(t.position=e.position),e.dragging!==void 0&&(t.dragging=e.dragging);break;case"dimensions":e.dimensions!==void 0&&(t.measured={...e.dimensions},(e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height)),e.handleBounds!==void 0&&(t.handleBounds=e.handleBounds);break}}function Ar(e,t){return jr(e,t)}function Dr(e,t){return jr(e,t)}function Ho(e,t){return!e.source||!e.target?(console.warn("addEdge: source and target are required"),t):t.some(r=>r.source===e.source&&r.target===e.target&&(r.sourceHandle||null)===(e.sourceHandle||null)&&(r.targetHandle||null)===(e.targetHandle||null))?t:[...t,{id:e.id||`e-${e.source}-${e.target}`,...e}]}function _o(e){const[t,n]=a.useState(e),r=a.useCallback(i=>n(o=>Ar(i,o)),[]);return[t,n,r]}function Wo(e){const[t,n]=a.useState(e),r=a.useCallback(i=>n(o=>Dr(i,o)),[]);return[t,n,r]}function Hr(){const e=Rr(),t=a.useCallback(()=>typeof e.getState=="function"?e.getState():e,[e]),n=a.useCallback(()=>[...t().nodesRef.current],[t]),r=a.useCallback(()=>[...t().edgesRef.current],[t]),i=a.useCallback(w=>t().nodesRef.current.find(g=>g.id===w),[t]),o=a.useCallback(w=>t().edgesRef.current.find(g=>g.id===w),[t]),c=a.useCallback(w=>{var g,v,L,E;if(typeof w=="function"){const D=w(t().nodesRef.current);(v=(g=t().onNodesChangeRef).current)==null||v.call(g,[...t().nodesRef.current.map(K=>({id:K.id,type:"remove"})),...D.map(K=>({type:"add",item:K}))])}else(E=(L=t().onNodesChangeRef).current)==null||E.call(L,[...t().nodesRef.current.map(D=>({id:D.id,type:"remove"})),...w.map(D=>({type:"add",item:D}))])},[t]),f=a.useCallback(w=>{var g,v,L,E;if(typeof w=="function"){const D=w(t().edgesRef.current);(v=(g=t().onEdgesChangeRef).current)==null||v.call(g,[...t().edgesRef.current.map(K=>({id:K.id,type:"remove"})),...D.map(K=>({type:"add",item:K}))])}else(E=(L=t().onEdgesChangeRef).current)==null||E.call(L,[...t().edgesRef.current.map(D=>({id:D.id,type:"remove"})),...w.map(D=>({type:"add",item:D}))])},[t]),m=a.useCallback(w=>{var v,L;const g=Array.isArray(w)?w:[w];(L=(v=t().onNodesChangeRef).current)==null||L.call(v,g.map(E=>({type:"add",item:E})))},[t]),d=a.useCallback(w=>{var v,L;const g=Array.isArray(w)?w:[w];(L=(v=t().onEdgesChangeRef).current)==null||L.call(v,g.map(E=>({type:"add",item:E})))},[t]),h=a.useCallback(({nodes:w=[],edges:g=[]})=>{if(w.length&&t().onNodesChangeRef.current){t().onNodesChangeRef.current(w.map(L=>({id:L.id,type:"remove"})));const v=br(w,t().edgesRef.current);v.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(v.map(L=>({id:L.id,type:"remove"})))}g.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(g.map(v=>({id:v.id,type:"remove"})))},[t]),b=a.useCallback(()=>{const w=t().cameraRef.current;return{x:w.x,y:w.y,zoom:w.zoom}},[t]),k=a.useRef(null),S=a.useCallback((w,g)=>{if(k.current&&cancelAnimationFrame(k.current),!g||g<=0){t().cameraRef.current={...w},t().sendCamera();return}const v={...t().cameraRef.current},L=performance.now(),E=D=>{const K=D-L,ae=Math.min(K/g,1),ee=1-Math.pow(1-ae,3);t().cameraRef.current={x:v.x+(w.x-v.x)*ee,y:v.y+(w.y-v.y)*ee,zoom:v.zoom+(w.zoom-v.zoom)*ee},t().sendCamera(),ae<1&&(k.current=requestAnimationFrame(E))};k.current=requestAnimationFrame(E)},[t]),P=a.useCallback((w,g)=>{const v={x:w.x??t().cameraRef.current.x,y:w.y??t().cameraRef.current.y,zoom:w.zoom??t().cameraRef.current.zoom};S(v,g==null?void 0:g.duration)},[t,S]),F=a.useCallback(()=>t().cameraRef.current.zoom,[t]),j=a.useCallback(w=>{const g=t().cameraRef.current,v=t().wrapRef.current;if(!v)return;const L=v.getBoundingClientRect(),E=L.width/2,D=L.height/2,K=1.2,ae={x:E-(E-g.x)*K,y:D-(D-g.y)*K,zoom:Math.min(t().zoomMax,g.zoom*K)};S(ae,w==null?void 0:w.duration)},[t,S]),A=a.useCallback(w=>{const g=t().cameraRef.current,v=t().wrapRef.current;if(!v)return;const L=v.getBoundingClientRect(),E=L.width/2,D=L.height/2,K=1/1.2,ae={x:E-(E-g.x)*K,y:D-(D-g.y)*K,zoom:Math.max(t().zoomMin,g.zoom*K)};S(ae,w==null?void 0:w.duration)},[t,S]),X=a.useCallback((w,g)=>{const v=t().cameraRef.current,L=t().wrapRef.current;if(!L)return;const E=L.getBoundingClientRect(),D=E.width/2,K=E.height/2,ae=Math.min(t().zoomMax,Math.max(t().zoomMin,w)),ee=ae/v.zoom,oe={x:D-(D-v.x)*ee,y:K-(K-v.y)*ee,zoom:ae};S(oe,g==null?void 0:g.duration)},[t,S]),B=a.useCallback((w={})=>{const g=t().nodesRef.current;if(!g.length)return;const v=t().wrapRef.current;if(!v)return;const L=v.getBoundingClientRect(),E=w.padding??.1,D=w.nodes?g.filter(ee=>w.nodes.some(oe=>oe.id===ee.id)):g;if(!D.length)return;const K=Mn(D),ae=Ut(K,L.width,L.height,E);w.maxZoom&&(ae.zoom=Math.min(ae.zoom,w.maxZoom)),w.minZoom&&(ae.zoom=Math.max(ae.zoom,w.minZoom)),S(ae,w.duration)},[t,S]),_=a.useCallback((w,g={})=>{const v=t().wrapRef.current;if(!v)return;const L=v.getBoundingClientRect(),E=g.padding??.1,D=Ut(w,L.width,L.height,E);g.maxZoom&&(D.zoom=Math.min(D.zoom,g.maxZoom)),g.minZoom&&(D.zoom=Math.max(D.zoom,g.minZoom)),S(D,g.duration)},[t,S]),$=a.useCallback((w,g,v={})=>{const L=t().wrapRef.current;if(!L)return;const E=L.getBoundingClientRect(),D=v.zoom??t().cameraRef.current.zoom,K={x:E.width/2-w*D,y:E.height/2-g*D,zoom:D};S(K,v.duration)},[t,S]),N=a.useCallback(()=>({nodes:[...t().nodesRef.current],edges:[...t().edgesRef.current],viewport:{...t().cameraRef.current}}),[t]),O=a.useCallback(w=>t().screenToWorld(w.x,w.y),[t]),U=a.useCallback(w=>{const g=t().cameraRef.current,v=t().wrapRef.current;if(!v)return{x:0,y:0};const L=v.getBoundingClientRect();return{x:w.x*g.zoom+g.x+L.left,y:w.y*g.zoom+g.y+L.top}},[t]),Y=a.useCallback((w,g)=>{var E,D;const v=t().nodesRef.current.find(K=>K.id===w);if(!v)return;const L=typeof g=="function"?g(v.data):{...v.data,...g};(D=(E=t().onNodesChangeRef).current)==null||D.call(E,[{id:w,type:"replace",item:{...v,data:L}}])},[t]);return{getNodes:n,getEdges:r,getNode:i,getEdge:o,setNodes:c,setEdges:f,addNodes:m,addEdges:d,deleteElements:h,getViewport:b,setViewport:P,getZoom:F,zoomIn:j,zoomOut:A,zoomTo:X,fitView:B,fitBounds:_,setCenter:$,screenToFlowPosition:O,flowToScreenPosition:U,updateNodeData:Y,toObject:N}}function Fo(){return Ie().nodes}function Yo(){return Ie().edges}function Xo(){return Ie().viewport}function Oo(){return Ie().connection}function Uo(e){const t=Ie(),n=Array.isArray(e)?e:[e];return a.useMemo(()=>n.map(r=>{const i=t.nodes.find(o=>o.id===r);return i?{id:i.id,type:i.type,data:i.data}:null}).filter(Boolean),[t.nodes,...n])}function qo(e){const t=Ie();return a.useMemo(()=>t.edges.filter(n=>n.source===e||n.target===e),[t.edges,e])}function Zo({nodeId:e,type:t,handleId:n}){const r=Ie();return a.useMemo(()=>r.edges.filter(i=>t==="source"?i.source===e&&(n?i.sourceHandle===n:!0):i.target===e&&(n?i.targetHandle===n:!0)),[r.edges,e,t,n])}function Go({onChange:e,onStart:t,onEnd:n}){const r=Ie(),i=a.useRef(e),o=a.useRef(t),c=a.useRef(n);a.useEffect(()=>{i.current=e},[e]),a.useEffect(()=>{o.current=t},[t]),a.useEffect(()=>{c.current=n},[n]),a.useEffect(()=>{const f=m=>{var d;(d=i.current)==null||d.call(i,{x:m.x,y:m.y,zoom:m.zoom})};return r.viewportListeners.add(f),()=>r.viewportListeners.delete(f)},[s])}function Qo({onChange:e}){const t=Ie(),n=a.useRef(e);a.useEffect(()=>{n.current=e},[e]),a.useEffect(()=>{const r=i=>{var o;(o=n.current)==null||o.call(n,i)};return t.selectionListeners.add(r),()=>t.selectionListeners.delete(r)},[s])}function Jo(e){const[t,n]=a.useState(!1),r=Array.isArray(e)?e:[e];return a.useEffect(()=>{const i=c=>{r.includes(c.key)&&n(!0)},o=c=>{r.includes(c.key)&&n(!1)};return window.addEventListener("keydown",i),window.addEventListener("keyup",o),()=>{window.removeEventListener("keydown",i),window.removeEventListener("keyup",o)}},[r.join(",")]),t}function Vo(){const e=Ie();return a.useCallback(t=>{var n;(n=e.workerRef.current)==null||n.postMessage({type:"nodes",data:{nodes:[...s().nodesRef.current]}})},[s])}const Ko=e=>{var t;return((t=e.nodes)==null?void 0:t.length)>0};function es(e={}){return Ie(Ko)}function ts(e){const t=Ie();return a.useMemo(()=>t.nodes.find(n=>n.id===e)||void 0,[t.nodes,e])}function ns(e,t){return Ie(e,t)}function rs(){return Rr()}function os({maxHistorySize:e=100}={}){const t=Ie(),n=a.useRef([]),r=a.useRef([]),[,i]=a.useState(0),o=a.useRef(null),c=a.useCallback(()=>{const d={nodes:s().nodesRef.current.map(h=>({...h,data:{...h.data}})),edges:s().edgesRef.current.map(h=>({...h}))};o.current&&JSON.stringify(o.current.nodes.map(h=>h.id))===JSON.stringify(d.nodes.map(h=>h.id))&&JSON.stringify(o.current.edges.map(h=>h.id))===JSON.stringify(d.edges.map(h=>h.id))||(n.current.push(d),n.current.length>e&&n.current.shift(),r.current=[],o.current=d,i(h=>h+1))},[t,e]),f=a.useCallback(()=>{var h,b,k,S;const d=n.current.pop();d&&(r.current.push({nodes:s().nodesRef.current.map(P=>({...P,data:{...P.data}})),edges:s().edgesRef.current.map(P=>({...P}))}),(b=(h=s().onNodesChangeRef).current)==null||b.call(h,[...s().nodesRef.current.map(P=>({id:P.id,type:"remove"})),...d.nodes.map(P=>({type:"add",item:P}))]),(S=(k=s().onEdgesChangeRef).current)==null||S.call(k,[...s().edgesRef.current.map(P=>({id:P.id,type:"remove"})),...d.edges.map(P=>({type:"add",item:P}))]),o.current=d,i(P=>P+1))},[s]),m=a.useCallback(()=>{var h,b,k,S;const d=r.current.pop();d&&(n.current.push({nodes:s().nodesRef.current.map(P=>({...P,data:{...P.data}})),edges:s().edgesRef.current.map(P=>({...P}))}),(b=(h=s().onNodesChangeRef).current)==null||b.call(h,[...s().nodesRef.current.map(P=>({id:P.id,type:"remove"})),...d.nodes.map(P=>({type:"add",item:P}))]),(S=(k=s().onEdgesChangeRef).current)==null||S.call(k,[...s().edgesRef.current.map(P=>({id:P.id,type:"remove"})),...d.edges.map(P=>({type:"add",item:P}))]),o.current=d,i(P=>P+1))},[s]);return{undo:f,redo:m,takeSnapshot:c,canUndo:n.current.length>0,canRedo:r.current.length>0}}function ss(e){const t=a.useRef(e);return a.useEffect(()=>{t.current=e},[e]),a.useCallback(n=>r=>{const i=t.current(r);i!==!1&&i!=null&&n(Array.isArray(i)?i:r)},[])}function is(e){const t=a.useRef(e);return a.useEffect(()=>{t.current=e},[e]),a.useCallback(n=>r=>{const i=t.current(r);i!==!1&&i!=null&&n(Array.isArray(i)?i:r)},[])}const Un=160,qn=60;function as({width:e=200,height:t=150,nodeColor:n="#3b82f6",nodeStrokeColor:r="#fff",maskColor:i="rgba(0,0,0,0.1)",style:o={},className:c=""}){const f=Ie(),m=a.useRef(null),d=a.useRef(null),h=a.useCallback(()=>{const b=m.current;if(!b)return;const k=b.getContext("2d"),S=window.devicePixelRatio||1;b.width=e*S,b.height=t*S,k.scale(S,S),k.clearRect(0,0,e,t);const P=f.nodesRef.current;if(!P.length)return;let F=1/0,j=1/0,A=-1/0,X=-1/0;for(const g of P){const v=g.width||Un,L=g.height||qn;g.position.x<F&&(F=g.position.x),g.position.y<j&&(j=g.position.y),g.position.x+v>A&&(A=g.position.x+v),g.position.y+L>X&&(X=g.position.y+L)}const B=40;F-=B,j-=B,A+=B,X+=B;const _=A-F,$=X-j,N=Math.min(e/_,t/$),O=(e-_*N)/2,U=(t-$*N)/2;for(const g of P){if(g.hidden)continue;const v=g.width||Un,L=g.height||qn,E=(g.position.x-F)*N+O,D=(g.position.y-j)*N+U,K=v*N,ae=L*N;k.fillStyle=g.selected?"#f59e0b":typeof n=="function"?n(g):n,k.fillRect(E,D,Math.max(K,2),Math.max(ae,2))}const Y=f.cameraRef.current,w=f.wrapRef.current;if(w){const g=w.getBoundingClientRect(),v=-Y.x/Y.zoom,L=-Y.y/Y.zoom,E=g.width/Y.zoom,D=g.height/Y.zoom;k.fillStyle=i,k.fillRect(0,0,e,t);const K=(v-F)*N+O,ae=(L-j)*N+U,ee=E*N,oe=D*N;k.clearRect(K,ae,ee,oe);for(const ye of P){if(ye.hidden)continue;const we=ye.width||Un,Me=ye.height||qn,le=(ye.position.x-F)*N+O,Se=(ye.position.y-j)*N+U;k.fillStyle=ye.selected?"#f59e0b":typeof n=="function"?n(ye):n,k.fillRect(le,Se,Math.max(we*N,2),Math.max(Me*N,2))}k.strokeStyle="#3b82f6",k.lineWidth=1.5,k.strokeRect(K,ae,ee,oe)}},[f,e,t,n,r,i]);return a.useEffect(()=>{let b=!0;function k(){b&&(h(),d.current=requestAnimationFrame(k))}const S=setInterval(()=>{cancelAnimationFrame(d.current),d.current=requestAnimationFrame(k)},66);return h(),()=>{b=!1,clearInterval(S),cancelAnimationFrame(d.current)}},[h]),I.jsx("canvas",{ref:m,className:`ric-minimap ${c}`,style:{position:"absolute",bottom:30,right:10,width:e,height:t,borderRadius:4,border:"1px solid rgba(0,0,0,0.1)",background:"rgba(255,255,255,0.9)",pointerEvents:"none",...o}})}function cs(){return I.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[I.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),I.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function ls(){return I.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:I.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function us(){return I.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:I.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}function ds(){return I.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[I.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),I.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function fs(){return I.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[I.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),I.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})}function sn({children:e,className:t="",...n}){return I.jsx("button",{className:`ric-controls-button ${t}`,style:gs,...n,children:e})}function hs({showZoom:e=!0,showFitView:t=!0,showInteractive:n=!1,fitViewOptions:r,onZoomIn:i,onZoomOut:o,onFitView:c,onInteractiveChange:f,position:m="bottom-left",orientation:d="vertical",style:h={},className:b="","aria-label":k="Canvas controls",children:S}){const P=Ie(),{zoomIn:F,zoomOut:j,fitView:A,getZoom:X}=Hr(),[B,_]=a.useState(!0),$=X()<=P.zoomMin,N=X()>=P.zoomMax,O=a.useCallback(()=>{F(),i==null||i()},[F,i]),U=a.useCallback(()=>{j(),o==null||o()},[j,o]),Y=a.useCallback(()=>{A(r||{padding:.1}),c==null||c()},[A,r,c]),w=a.useCallback(()=>{const v=!B;_(v),f==null||f(v)},[B,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%)"}}[m]||{bottom:30,left:10};return I.jsxs("div",{className:`ric-controls ${b}`,style:{position:"absolute",display:"flex",flexDirection:d==="horizontal"?"row":"column",gap:2,zIndex:5,...g,...h},role:"toolbar","aria-label":k,children:[e&&I.jsxs(I.Fragment,{children:[I.jsx(sn,{onClick:O,disabled:N,title:"Zoom in","aria-label":"Zoom in",className:"ric-controls-zoomin",children:I.jsx(cs,{})}),I.jsx(sn,{onClick:U,disabled:$,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:I.jsx(ls,{})})]}),t&&I.jsx(sn,{onClick:Y,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:I.jsx(us,{})}),n&&I.jsx(sn,{onClick:w,title:B?"Lock interactivity":"Unlock interactivity","aria-label":B?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:B?I.jsx(fs,{}):I.jsx(ds,{})}),S]})}const gs={width:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid rgba(0,0,0,0.12)",borderRadius:4,background:"#fff",cursor:"pointer",fontSize:16,lineHeight:1,color:"#333",padding:0},ys=a.memo(hs);function xs({variant:e="lines",gap:t=40,size:n=1,color:r,style:i={},className:o=""}){const c=Ie();return c.workerRef.current&&c.workerRef.current.postMessage({type:"background",data:{variant:e,gap:t,size:n,color:r}}),null}function ps({position:e="top-left",style:t={},className:n="",children:r}){const i={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:10,left:10},"bottom-right":{bottom:10,right:10},"bottom-center":{bottom:10,left:"50%",transform:"translateX(-50%)"}}[e]||{top:10,left:10};return I.jsx("div",{className:`ric-panel ${n}`,style:{position:"absolute",zIndex:5,pointerEvents:"all",...i,...t},onPointerDown:o=>o.stopPropagation(),children:r})}function ms({minWidth:e=10,minHeight:t=10,maxWidth:n=1/0,maxHeight:r=1/0,isVisible:i=!0,handleStyle:o={},lineStyle:c={},color:f="#3b82f6",onResizeStart:m,onResize:d,onResizeEnd:h}){const b=a.useContext(cn),k=Ie(),S=a.useRef(null),P=a.useCallback((A,X)=>{A.stopPropagation(),A.preventDefault();const B=k.nodesRef.current.find(N=>N.id===b);if(!B)return;S.current={direction:X,startX:A.clientX,startY:A.clientY,width:B.width||160,height:B.height||60},m==null||m(A,{width:S.current.width,height:S.current.height});const _=N=>{var L,E;if(!S.current)return;const O=S.current,U=k.cameraRef.current,Y=(N.clientX-O.startX)/U.zoom,w=(N.clientY-O.startY)/U.zoom;let g=O.width,v=O.height;O.direction.includes("e")&&(g=Math.min(n,Math.max(e,O.width+Y))),O.direction.includes("w")&&(g=Math.min(n,Math.max(e,O.width-Y))),O.direction.includes("s")&&(v=Math.min(r,Math.max(t,O.height+w))),O.direction.includes("n")&&(v=Math.min(r,Math.max(t,O.height-w))),(E=(L=k.onNodesChangeRef).current)==null||E.call(L,[{id:b,type:"dimensions",dimensions:{width:g,height:v},setAttributes:!0}]),d==null||d(N,{width:g,height:v})},$=N=>{S.current=null,h==null||h(N,{}),window.removeEventListener("pointermove",_),window.removeEventListener("pointerup",$)};window.addEventListener("pointermove",_),window.addEventListener("pointerup",$)},[b,k,e,t,n,r,m,d,h]);if(!i)return null;const F=8,j={position:"absolute",width:F,height:F,background:f,border:"1px solid #fff",borderRadius:2,zIndex:20,...o};return I.jsxs(I.Fragment,{children:[I.jsx("div",{style:{...j,bottom:-F/2,right:-F/2,cursor:"nwse-resize"},onPointerDown:A=>P(A,"se")}),I.jsx("div",{style:{...j,bottom:-F/2,left:-F/2,cursor:"nesw-resize"},onPointerDown:A=>P(A,"sw")}),I.jsx("div",{style:{...j,top:-F/2,right:-F/2,cursor:"nesw-resize"},onPointerDown:A=>P(A,"ne")}),I.jsx("div",{style:{...j,top:-F/2,left:-F/2,cursor:"nwse-resize"},onPointerDown:A=>P(A,"nw")}),I.jsx("div",{style:{...j,top:"50%",right:-F/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:A=>P(A,"e")}),I.jsx("div",{style:{...j,top:"50%",left:-F/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:A=>P(A,"w")}),I.jsx("div",{style:{...j,left:"50%",top:-F/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:A=>P(A,"n")}),I.jsx("div",{style:{...j,left:"50%",bottom:-F/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:A=>P(A,"s")})]})}function vs({isVisible:e,position:t="top",offset:n=10,align:r="center",children:i,style:o={},className:c=""}){const f=a.useContext(cn),d=Ie().nodes.find(k=>k.id===f);if(!(e!==void 0?e:d==null?void 0:d.selected))return null;const b={top:{bottom:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginBottom:n},bottom:{top:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginTop:n},left:{right:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginRight:n},right:{left:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginLeft:n}}[t]||{};return I.jsx("div",{className:`ric-node-toolbar ${c}`,style:{position:"absolute",zIndex:1e3,pointerEvents:"all",...b,...o},onPointerDown:k=>k.stopPropagation(),children:i})}function bs({isVisible:e=!1,x:t=0,y:n=0,alignX:r="center",alignY:i="center",children:o,style:c={},className:f=""}){if(!e)return null;const m=r==="center"?"-50%":r==="right"?"-100%":"0",d=i==="center"?"-50%":i==="bottom"?"-100%":"0";return I.jsx("div",{className:`ric-edge-toolbar ${f}`,style:{position:"absolute",left:t,top:n,transform:`translate(${m}, ${d})`,zIndex:1e3,pointerEvents:"all",...c},children:o})}function ws({children:e}){var r;const n=(r=Ie().edgeLabelContainerRef)==null?void 0:r.current;return n?pr.createPortal(e,n):null}function Ms({children:e}){var r;const n=(r=Ie().viewportPortalRef)==null?void 0:r.current;return n?pr.createPortal(e,n):null}function _r({fromX:e,fromY:t,toX:n,toY:r,fromPosition:i="right",toPosition:o="left",connectionLineType:c="default",connectionLineStyle:f,connectionLineComponent:m}){if(m)return I.jsx(m,{fromX:e,fromY:t,toX:n,toY:r,fromPosition:i,toPosition:o});let d;switch(c){case"straight":[d]=tr({sourceX:e,sourceY:t,targetX:n,targetY:r});break;case"step":[d]=Rn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o,borderRadius:0});break;case"smoothstep":[d]=Rn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o});break;case"simplebezier":[d]=rr({sourceX:e,sourceY:t,targetX:n,targetY:r});break;default:[d]=nr({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o});break}return I.jsx("path",{d,fill:"none",className:"ric-connection-line",stroke:"#b1b1b7",strokeWidth:1.5,style:f})}_r.displayName="ConnectionLine";const Rs=a.memo(_r),ks=Object.freeze({Top:"top",Bottom:"bottom",Left:"left",Right:"right"}),Cs=Object.freeze({Arrow:"arrow",ArrowClosed:"arrowclosed"});function Es(e){const t=e.width||e.measured&&e.measured.width||0,n=e.height||e.measured&&e.measured.height||0,r=e._absolutePosition||e.position||{x:0,y:0};return{x:r.x,y:r.y,x2:r.x+t,y2:r.y+n}}exports.Background=xs;exports.BaseEdge=ln;exports.BezierEdge=er;exports.ConnectionLine=Rs;exports.ControlButton=sn;exports.Controls=ys;exports.DefaultNode=vo;exports.EdgeLabelRenderer=ws;exports.EdgeText=Lr;exports.EdgeToolbar=bs;exports.GroupNode=Ir;exports.Handle=an;exports.InfiniteCanvas=jo;exports.InfiniteCanvasProvider=Ao;exports.InputNode=Pr;exports.MarkerType=Cs;exports.MiniMap=as;exports.NodeResizer=ms;exports.NodeToolbar=vs;exports.OutputNode=Nr;exports.Panel=ps;exports.Position=ks;exports.SelectionBox=Sr;exports.SimpleBezierEdge=ar;exports.SmoothStepEdge=ir;exports.StepEdge=$r;exports.StraightEdge=sr;exports.ViewportPortal=Ms;exports.addEdge=Ho;exports.applyEdgeChanges=Dr;exports.applyNodeChanges=Ar;exports.boxToRect=Qr;exports.buildObstacles=or;exports.clampPosition=Gn;exports.computeRoutedEdges=Po;exports.getBezierEdgeCenter=bo;exports.getBezierPath=nr;exports.getBoundsOfBoxes=Jr;exports.getConnectedEdges=br;exports.getEdgeCenter=wo;exports.getIncomers=Ur;exports.getNodeDimensions=Kn;exports.getNodesBounds=Mn;exports.getNodesInside=Zr;exports.getOutgoers=qr;exports.getOverlappingArea=Vr;exports.getRoutedLabelPosition=Pn;exports.getSimpleBezierPath=rr;exports.getSmoothStepPath=Rn;exports.getStraightPath=tr;exports.getViewportForBounds=Ut;exports.isEdge=Or;exports.isNode=Xr;exports.nodeToBox=Es;exports.nodeToRect=Kr;exports.reconnectEdge=Mo;exports.rectToBox=Gr;exports.routeSinglePath=No;exports.routedPointsToPath=zn;exports.snapPosition=Zn;exports.useConnection=Oo;exports.useEdges=Yo;exports.useEdgesState=Wo;exports.useHandleConnections=Zo;exports.useInfiniteCanvas=Mr;exports.useInternalNode=ts;exports.useKeyPress=Jo;exports.useNodeConnections=qo;exports.useNodeId=co;exports.useNodes=Fo;exports.useNodesData=Uo;exports.useNodesInitialized=es;exports.useNodesState=_o;exports.useOnEdgesChangeMiddleware=is;exports.useOnNodesChangeMiddleware=ss;exports.useOnSelectionChange=Qo;exports.useOnViewportChange=Go;exports.useReactFlow=Hr;exports.useStore=ns;exports.useStoreApi=rs;exports.useUndoRedo=os;exports.useUpdateNodeInternals=Vo;exports.useViewport=Xo;
|
|
946
|
+
`,lr=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",wr],{type:"text/javascript;charset=utf-8"});function eo(e){let t;try{if(t=lr&&(self.URL||self.webkitURL).createObjectURL(lr),!t)throw"";const n=new Worker(t,{type:"module",name:e==null?void 0:e.name});return n.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),n}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(wr),{type:"module",name:e==null?void 0:e.name})}}const Xn=new WeakMap;function to(e,t){if(Xn.has(e))return Xn.get(e);const n=e.transferControlToOffscreen(),r=new eo;r.onerror=o=>console.error("[infinite-canvas] worker error:",o.message,o),r.postMessage({type:"init",data:{...t,canvas:n}},[n]);const i={worker:r};return Xn.set(e,i),i}const ut=160,tt=60,no=10;function Mr({cards:e=[],nodes:t=[],edges:n=[],onHudUpdate:r,onNodesProcessed:i,onNodesChange:o,onEdgesChange:l,onConnect:h,onNodeClick:v,onNodeDragStart:f,onNodeDrag:y,onNodeDragStop:x,onEdgeClick:R,onEdgeDoubleClick:C,onEdgeMouseEnter:z,onEdgeMouseMove:W,onEdgeMouseLeave:j,onEdgeContextMenu:D,onNodeDoubleClick:F,onNodeMouseEnter:$,onNodeMouseMove:X,onNodeMouseLeave:A,onNodeContextMenu:P,onPaneClick:Z,onPaneContextMenu:q,onPaneMouseEnter:O,onPaneMouseMove:M,onPaneMouseLeave:d,onSelectionChange:b,onConnectStart:L,onConnectEnd:T,onInit:B,onMoveStart:Q,onMove:oe,onMoveEnd:te,onDelete:ce,onBeforeDelete:me,onError:Me,isValidConnection:ke,dark:le,gridSize:xe=40,zoomMin:ie=.1,zoomMax:fe=4,initialCamera:Ce={x:0,y:0,zoom:1},fitView:je=!1,fitViewOptions:ge,nodesDraggable:de=!0,nodesConnectable:Ae=!0,elementsSelectable:_e=!0,multiSelectionKeyCode:We="Shift",selectionOnDrag:nt=!1,selectionMode:De="partial",connectionMode:$e="loose",connectionRadius:Ie=20,connectOnClick:Ee=!1,snapToGrid:Ge=!1,snapGrid:rt=[15,15],deleteKeyCode:He=["Delete","Backspace"],panActivationKeyCode:Ue=" ",panOnScroll:Ke=!1,panOnScrollMode:zt="free",panOnScrollSpeed:ln=.5,zoomOnScroll:un=!0,zoomOnDoubleClick:dn=!0,zoomOnPinch:fn=!0,preventScrolling:Ot=!0,translateExtent:ht,nodeExtent:gt,defaultEdgeOptions:Pt={},autoPanOnNodeDrag:Nn=!0,autoPanOnConnect:In=!0,autoPanSpeed:ot=5,edgesReconnectable:cr=!1,elevateNodesOnSelect:Tn=!1,elevateEdgesOnSelect:Ln=!1,noDragClassName:Nt="nodrag",noPanClassName:It="nopan",onSelectionDragStart:Bn,onSelectionDrag:$n,onSelectionDragStop:An,edgeRouting:bt=!0}={}){const be=a.useRef(null),Tt=a.useRef(null),Se=a.useRef(null),ue=a.useRef({...Ce}),yt=a.useRef([...e]),ee=a.useRef([...t]),ze=a.useRef([...n]),hn=a.useRef(new Map),Lt=a.useRef(!1),Bt=a.useRef(null),[$t,jn]=a.useState(!1),Fe=a.useRef(null),Xe=a.useRef(null),At=a.useRef(null),st=a.useRef(null),gn=a.useRef(!1),Qe=a.useRef(null),[yn,xn]=a.useState({x:Ce.x,y:Ce.y,zoom:Ce.zoom}),[Ut,pn]=a.useState(null),xt=a.useMemo(()=>new Set,[]),it=a.useMemo(()=>new Set,[]),Je=a.useRef(!1),V=a.useRef({});V.current={onHudUpdate:r,onNodesProcessed:i,onNodesChange:o,onEdgesChange:l,onConnect:h,onNodeClick:v,onNodeDragStart:f,onNodeDrag:y,onNodeDragStop:x,onEdgeClick:R,onEdgeDoubleClick:C,onEdgeMouseEnter:z,onEdgeMouseMove:W,onEdgeMouseLeave:j,onEdgeContextMenu:D,onNodeDoubleClick:F,onNodeMouseEnter:$,onNodeMouseMove:X,onNodeMouseLeave:A,onNodeContextMenu:P,onPaneClick:Z,onPaneContextMenu:q,onPaneMouseEnter:O,onPaneMouseMove:M,onPaneMouseLeave:d,onSelectionChange:b,onConnectStart:L,onConnectEnd:T,onInit:B,onMoveStart:Q,onMove:oe,onMoveEnd:te,onDelete:ce,onBeforeDelete:me,onError:Me,onSelectionDragStart:Bn,onSelectionDrag:$n,onSelectionDragStop:An,isValidConnection:ke};const at={get current(){return V.current.onConnect}},wt={get current(){return V.current.onNodeClick}},jt={get current(){return V.current.onNodeDragStart}},Dt={get current(){return V.current.onNodeDrag}},Ht={get current(){return V.current.onNodeDragStop}},dt={get current(){return V.current.onEdgeClick}},_t={get current(){return V.current.onPaneClick}},Mt={get current(){return V.current.onSelectionChange}},Wt={get current(){return V.current.onHudUpdate}},Ft={get current(){return V.current.onNodesProcessed}};a.useEffect(()=>{const u=c=>{c.key===We&&(gn.current=!0),c.key===Ue&&(Je.current=!0)},p=c=>{c.key===We&&(gn.current=!1),c.key===Ue&&(Je.current=!1)};return window.addEventListener("keydown",u),window.addEventListener("keyup",p),()=>{window.removeEventListener("keydown",u),window.removeEventListener("keyup",p)}},[We,Ue]);const Pe={get current(){return V.current.onNodesChange?Yt:null}},Yt=u=>{var c,g,k;(g=(c=V.current).onNodesChange)==null||g.call(c,u);const p=[];for(let S=0;S<u.length;S++)u[S].type==="select"&&p.push({id:u[S].id,selected:u[S].selected});p.length>0&&((k=Se.current)==null||k.postMessage({type:"nodeSelections",data:{selections:p}}))},Te={get current(){return V.current.onEdgesChange?Dn:null}},Dn=u=>{var c,g,k;(g=(c=V.current).onEdgesChange)==null||g.call(c,u);const p=[];for(let S=0;S<u.length;S++)u[S].type==="select"&&p.push({id:u[S].id,selected:u[S].selected});p.length>0&&((k=Se.current)==null||k.postMessage({type:"edgeSelections",data:{selections:p}}))},pt=a.useCallback(()=>{var g;const u=ee.current.filter(k=>k.selected),p=ze.current.filter(k=>k.selected),c={nodes:u,edges:p};(g=Mt.current)==null||g.call(Mt,c);for(const k of it)k(c)},[it]);a.useEffect(()=>{var u;yt.current=[...e],(u=Se.current)==null||u.postMessage({type:"cards",data:{cards:[...e]}})},[e]);const Rt=a.useCallback(u=>{const p={};for(const c of u)p[c.id]=c;return u.map(c=>{if(!c.parentId)return c;const g=p[c.parentId];if(!g)return c;let k=c.position.x,S=c.position.y,m=g;for(;m;)k+=m.position.x,S+=m.position.y,m=m.parentId?p[m.parentId]:null;return{...c,_absolutePosition:{x:k,y:S}}})},[]),ct=a.useRef([]),mt=a.useCallback(u=>{const p=hn.current;if(!p||p.size===0)return u;const c={};for(const[,g]of p)c[g.nodeId]||(c[g.nodeId]=[]),c[g.nodeId].push({id:g.id,type:g.type,position:g.position,x:g.x,y:g.y});return u.map(g=>{const k=c[g.id];return k&&k.length>0?{...g,handles:k}:g})},[]),mn=a.useCallback(()=>{var p;if(Fe.current)return;const u=mt(ct.current);(p=Se.current)==null||p.postMessage({type:"nodes",data:{nodes:u}})},[mt]);a.useEffect(()=>{var c,g;if(Fe.current){const k=Fe.current.id,S=new Set([k,...Fe.current.selectedStarts.map(w=>w.id)]),m={};for(const w of ee.current)S.has(w.id)&&(m[w.id]={...w.position});ee.current=[...t];for(const w of ee.current)m[w.id]&&(w.position=m[w.id]);ct.current=Rt(ee.current);const E=mt(ct.current);(c=Se.current)==null||c.postMessage({type:"nodes",data:{nodes:E}});return}ee.current=[...t];const u=Rt(t);ct.current=u;const p=mt(u);(g=Se.current)==null||g.postMessage({type:"nodes",data:{nodes:p}})},[t,Rt,mt]),a.useEffect(()=>{var u;ze.current=[...n],(u=Se.current)==null||u.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const Le=a.useCallback((u,p)=>{const c=be.current;if(!c)return{x:0,y:0};const g=c.getBoundingClientRect(),k=ue.current;return{x:(u-g.left-k.x)/k.zoom,y:(p-g.top-k.y)/k.zoom}},[]),et=a.useCallback((u,p)=>{const c=ct.current.length>0?ct.current:ee.current;let g=null;for(let k=c.length-1;k>=0;k--){const S=c[k];if(S.hidden||S._customRendered)continue;const m=S._absolutePosition||S.position,E=S.width||ut,w=S.height||tt;if(u>=m.x&&u<=m.x+E&&p>=m.y&&p<=m.y+w){if(S.type==="group"){g||(g=S);continue}return S}}return g},[]),ye=a.useCallback((u,p)=>{const c=p.width||ut,g=p.height||tt;if(u.x!==void 0&&u.y!==void 0)return{x:p.position.x+u.x,y:p.position.y+u.y};switch(u.position||(u.type==="source"?"right":"left")){case"top":return{x:p.position.x+c/2,y:p.position.y};case"bottom":return{x:p.position.x+c/2,y:p.position.y+g};case"left":return{x:p.position.x,y:p.position.y+g/2};case"right":return{x:p.position.x+c,y:p.position.y+g/2};default:return{x:p.position.x+c,y:p.position.y+g/2}}},[]),qt=a.useCallback(u=>{const p=u.width||ut,c=u.height||tt;if(u.handles&&u.handles.length>0)return u.handles.map(w=>{const H=ye(w,u);return{id:w.id||null,type:w.type,x:H.x,y:H.y}});const g=u.targetPosition||"left",k=u.sourcePosition||"right",S=w=>{switch(w){case"top":return{x:u.position.x+p/2,y:u.position.y};case"bottom":return{x:u.position.x+p/2,y:u.position.y+c};case"left":return{x:u.position.x,y:u.position.y+c/2};case"right":return{x:u.position.x+p,y:u.position.y+c/2};default:return{x:u.position.x+p,y:u.position.y+c/2}}},m=S(g),E=S(k);return[{id:null,type:"target",x:m.x,y:m.y},{id:null,type:"source",x:E.x,y:E.y}]},[ye]),kt=a.useCallback((u,p)=>{const c=ee.current,g=ue.current,k=Math.max(no,Ie)/g.zoom;for(let S=c.length-1;S>=0;S--){const m=c[S];if(m.hidden)continue;const E=qt(m);for(const w of E)if(Math.abs(u-w.x)<k&&Math.abs(p-w.y)<k)return{nodeId:m.id,handleId:w.id,type:w.type,x:w.x,y:w.y}}return null},[qt]),Ve=a.useCallback((u,p)=>{const g=8/ue.current.zoom,k=ee.current,S={};for(let m=0;m<k.length;m++)S[k[m].id]=k[m];for(let m=ze.current.length-1;m>=0;m--){const E=ze.current[m],w=S[E.source],H=S[E.target];if(!w||!H)continue;const I=w.width||ut,Y=w.height||tt,G=H.height||tt,re=w.position.x+I,K=w.position.y+Y/2,U=H.position.x,ae=H.position.y+G/2;if(ro(u,p,re,K,U,ae)<g)return E}return null},[]);a.useEffect(()=>{const u=Tt.current,p=be.current;if(!u||!p)return;const c=p.getBoundingClientRect(),g=le!==void 0?le:matchMedia("(prefers-color-scheme: dark)").matches,k=Rt(ee.current);ct.current=k;const S=mt(k),{worker:m}=to(u,{width:c.width,height:c.height,camera:ue.current,cards:yt.current,nodes:S,edges:ze.current,dark:g,gridSize:xe,edgeRouting:bt});m.onmessage=I=>{var Y,G,re,K;I.data.type==="hud"&&((Y=Wt.current)==null||Y.call(Wt,I.data.data)),I.data.type==="ready"&&jn(!0),I.data.type==="nodesProcessed"&&((G=Ft.current)==null||G.call(Ft,I.data.data)),I.data.type==="error"&&((K=(re=V.current).onError)==null||K.call(re,"worker-error",I.data.message||"Canvas worker error"))},m.onerror=I=>{var Y,G;(G=(Y=V.current).onError)==null||G.call(Y,"worker-error",I.message||"Canvas worker crashed")},Se.current=m;const E=new ResizeObserver(I=>{const{width:Y,height:G}=I[0].contentRect;m.postMessage({type:"resize",data:{width:Y,height:G}})});E.observe(p);let w,H;return le===void 0&&(w=matchMedia("(prefers-color-scheme: dark)"),H=I=>m.postMessage({type:"theme",data:{dark:I.matches}}),w.addEventListener("change",H)),()=>{E.disconnect(),w&&H&&w.removeEventListener("change",H),Se.current=null}},[]),a.useEffect(()=>{var u;le!==void 0&&((u=Se.current)==null||u.postMessage({type:"theme",data:{dark:le}}))},[le]),a.useEffect(()=>{var u;(u=Se.current)==null||u.postMessage({type:"edgeRouting",data:{enabled:bt}})},[bt]);const Ct=a.useRef(0),we=a.useCallback((u=null)=>{var g,k,S;const p=ue.current;if(ht){const m=be.current;if(m){const E=m.getBoundingClientRect(),w=-ht[1][0]*p.zoom+E.width,H=-ht[1][1]*p.zoom+E.height,I=-ht[0][0]*p.zoom,Y=-ht[0][1]*p.zoom;p.x=Math.min(I,Math.max(w,p.x)),p.y=Math.min(Y,Math.max(H,p.y))}}(g=Se.current)==null||g.postMessage({type:"camera",data:{camera:{...p}}});const c={x:p.x,y:p.y,zoom:p.zoom};(S=(k=V.current).onMove)==null||S.call(k,u,c);for(const m of xt)m(c);cancelAnimationFrame(Ct.current),Ct.current=requestAnimationFrame(()=>{xn({x:p.x,y:p.y,zoom:p.zoom})})},[xt,ht]),vt=a.useCallback(()=>{var c,g;const u=Xe.current,p=At.current;u&&p?((c=Se.current)==null||c.postMessage({type:"connecting",data:{from:u.startPos,to:p,_routedPoints:null}}),pn({source:u.sourceId,sourceHandle:u.sourceHandle,target:null,targetHandle:null})):((g=Se.current)==null||g.postMessage({type:"connecting",data:null}),pn(null))},[]),lt=a.useCallback(()=>{var p,c;const u=st.current;u?(p=Se.current)==null||p.postMessage({type:"selectionBox",data:u}):(c=Se.current)==null||c.postMessage({type:"selectionBox",data:null})},[]),Zt=a.useCallback(u=>{var m,E,w,H,I,Y,G,re,K,U,ae,Re,Be,Ye,qe,Oe,Kt,ft;const p=ee.current.length>0,c=Le(u.clientX,u.clientY),g=gn.current;if(p&&Ae&&!g){const J=kt(c.x,c.y);if(Ee&&Qe.current&&J){const se=Qe.current;if(J.nodeId!==se.nodeId){const Ze=se.handleType==="target"?{source:J.nodeId,target:se.nodeId,sourceHandle:J.handleId||null,targetHandle:se.handleId}:{source:se.nodeId,target:J.nodeId,sourceHandle:se.handleId,targetHandle:J.handleId||null};(V.current.isValidConnection?V.current.isValidConnection(Ze):!0)&&((m=at.current)==null||m.call(at,{...Ze,...Pt}))}Qe.current=null;return}if($e==="strict"?J&&J.type==="source":J!=null){if(Ee){Qe.current={nodeId:J.nodeId,handleId:J.handleId||null,handleType:J.type},(w=(E=V.current).onConnectStart)==null||w.call(E,u,{nodeId:J.nodeId,handleId:J.handleId,handleType:J.type});return}Xe.current={sourceId:J.nodeId,sourceHandle:J.handleId||null,sourceType:J.type,startPos:{x:J.x,y:J.y}},At.current={x:c.x,y:c.y},(H=be.current)==null||H.setPointerCapture(u.pointerId),(Y=(I=V.current).onConnectStart)==null||Y.call(I,u,{nodeId:J.nodeId,handleId:J.handleId,handleType:J.type}),vt();return}}const k=J=>{var se;let ve=J;for(;ve&&ve!==be.current;){if((se=ve.classList)!=null&&se.contains(Nt))return!0;ve=ve.parentElement}return!1},S=J=>{var se;let ve=J;for(;ve&&ve!==be.current;){if((se=ve.classList)!=null&&se.contains(It))return!0;ve=ve.parentElement}return!1};if(p){const J=et(c.x,c.y);if(J){if(Pe.current&&_e){const ve=[];if(g)ve.push({id:J.id,type:"select",selected:!J.selected});else if(!J.selected){for(const se of ee.current)se.id===J.id?ve.push({id:se.id,type:"select",selected:!0}):se.selected&&ve.push({id:se.id,type:"select",selected:!1});if(Te.current){const se=ze.current.filter(he=>he.selected).map(he=>({id:he.id,type:"select",selected:!1}));se.length&&Te.current(se)}}if(ve.length){if(Pe.current(ve),Tn&&!g){const se=ee.current.findIndex(he=>he.id===J.id);se>=0&&se<ee.current.length-1&&Pe.current([{id:J.id,type:"remove"},{type:"add",item:{...ee.current[se],selected:!0}}])}pt()}}if((G=wt.current)==null||G.call(wt,u,J),de&&!k(u.target)){const ve=J.selected;let se=null;if(J.parentId&&J.extent==="parent"){const he=ee.current.find(Ze=>Ze.id===J.parentId);if(he){const Ze=he.width||ut,en=he.height||tt,vn=J.width||((re=J.measured)==null?void 0:re.width)||ut,tn=J.height||((K=J.measured)==null?void 0:K.height)||tt;se={minX:0,minY:0,maxX:Ze-vn,maxY:en-tn}}}if(Fe.current={id:J.id,startPos:{...J.position},startMouse:{x:c.x,y:c.y},parentClamp:se,parentId:J.parentId||null,selectedStarts:ve?ee.current.filter(he=>he.selected&&he.id!==J.id).map(he=>{var en,vn;let Ze=null;if(he.parentId&&he.extent==="parent"){const tn=ee.current.find(Yn=>Yn.id===he.parentId);if(tn){const Yn=tn.width||ut,Wr=tn.height||tt,Fr=he.width||((en=he.measured)==null?void 0:en.width)||ut,Yr=he.height||((vn=he.measured)==null?void 0:vn.height)||tt;Ze={minX:0,minY:0,maxX:Yn-Fr,maxY:Wr-Yr}}}return{id:he.id,startPos:{...he.position},parentClamp:Ze,parentId:he.parentId||null}}):[]},(U=be.current)==null||U.setPointerCapture(u.pointerId),(ae=jt.current)==null||ae.call(jt,u,J),Fe.current.selectedStarts.length>0){const he=ee.current.filter(Ze=>Ze.selected);(Be=(Re=V.current).onSelectionDragStart)==null||Be.call(Re,u,he)}if(Pe.current){const he=[{id:J.id,type:"position",dragging:!0}];for(const Ze of Fe.current.selectedStarts)he.push({id:Ze.id,type:"position",dragging:!0});Pe.current(he)}}return}}if(ze.current.length>0&&_e){const J=Ve(c.x,c.y);if(J){if(Te.current){const ve=[];if(g)ve.push({id:J.id,type:"select",selected:!J.selected});else{for(const se of ze.current)se.id===J.id?ve.push({id:se.id,type:"select",selected:!0}):se.selected&&ve.push({id:se.id,type:"select",selected:!1});if(Pe.current){const se=ee.current.filter(he=>he.selected).map(he=>({id:he.id,type:"select",selected:!1}));se.length&&Pe.current(se)}}if(ve.length){if(Te.current(ve),Ln&&!g){const se=ze.current.findIndex(he=>he.id===J.id);se>=0&&se<ze.current.length-1&&Te.current([{id:J.id,type:"remove"},{type:"add",item:{...ze.current[se],selected:!0}}])}pt()}}(Ye=dt.current)==null||Ye.call(dt,u,J);return}}if(!g){const J=ee.current.filter(se=>se.selected).map(se=>({id:se.id,type:"select",selected:!1})),ve=ze.current.filter(se=>se.selected).map(se=>({id:se.id,type:"select",selected:!1}));J.length&&Pe.current&&Pe.current(J),ve.length&&Te.current&&Te.current(ve),(J.length||ve.length)&&pt()}if((qe=_t.current)==null||qe.call(_t,u),nt||g){st.current={startWorld:{...c},endWorld:{...c}},(Oe=be.current)==null||Oe.setPointerCapture(u.pointerId),lt();return}S(u.target)||(Lt.current=!0,Bt.current={x:u.clientX,y:u.clientY},(Kt=be.current)==null||Kt.classList.add("dragging"),(ft=be.current)==null||ft.setPointerCapture(u.pointerId))},[Le,et,kt,Ve,de,Ae,_e,nt,vt,lt,pt,Nt,It]),Gt=a.useCallback(u=>{var c,g,k,S;if(Xe.current){if(At.current=Le(u.clientX,u.clientY),vt(),In){const m=be.current;if(m){const E=m.getBoundingClientRect(),w=40,H=u.clientX-E.left,I=u.clientY-E.top;let Y=0,G=0;H<w?Y=ot:H>E.width-w&&(Y=-ot),I<w?G=ot:I>E.height-w&&(G=-ot),(Y||G)&&(ue.current.x+=Y,ue.current.y+=G,we(u))}}return}if(st.current){st.current.endWorld=Le(u.clientX,u.clientY),lt();const m=st.current,E=Math.min(m.startWorld.x,m.endWorld.x),w=Math.min(m.startWorld.y,m.endWorld.y),H=Math.max(m.startWorld.x,m.endWorld.x),I=Math.max(m.startWorld.y,m.endWorld.y);if(Pe.current){const Y=[];for(const G of ee.current){if(G.hidden)continue;const re=G.width||ut,K=G.height||tt,U=De==="full"?G.position.x>=E&&G.position.x+re<=H&&G.position.y>=w&&G.position.y+K<=I:G.position.x+re>E&&G.position.x<H&&G.position.y+K>w&&G.position.y<I;U!==!!G.selected&&Y.push({id:G.id,type:"select",selected:U})}Y.length&&Pe.current(Y)}return}if(Fe.current){const m=Le(u.clientX,u.clientY),E=Fe.current,w=m.x-E.startMouse.x,H=m.y-E.startMouse.y;let I={x:E.startPos.x+w,y:E.startPos.y+H};if(Ge&&(I=Zn(I,rt)),gt&&(I=Gn(I,gt)),E.parentClamp){const U=E.parentClamp;I={x:Math.max(U.minX,Math.min(I.x,U.maxX)),y:Math.max(U.minY,Math.min(I.y,U.maxY))}}const Y=[{id:E.id,position:I}];for(const U of E.selectedStarts){let ae={x:U.startPos.x+w,y:U.startPos.y+H};if(Ge&&(ae=Zn(ae,rt)),gt&&(ae=Gn(ae,gt)),U.parentClamp){const Re=U.parentClamp;ae={x:Math.max(Re.minX,Math.min(ae.x,Re.maxX)),y:Math.max(Re.minY,Math.min(ae.y,Re.maxY))}}Y.push({id:U.id,position:ae})}const G=[];for(const U of Y){const ae=ee.current.find(Re=>Re.id===U.id);if(ae){ae.position=U.position,ae.dragging=!0;let Re=U.position;if(ae.parentId){let Be=ee.current.find(Oe=>Oe.id===ae.parentId),Ye=U.position.x,qe=U.position.y;for(;Be;)Ye+=Be.position.x,qe+=Be.position.y,Be=Be.parentId?ee.current.find(Oe=>Oe.id===Be.parentId):null;Re={x:Ye,y:qe}}G.push({id:U.id,position:U.position,_absolutePosition:Re,width:ae.width,height:ae.height,dragging:!0,selected:ae.selected})}}const re=new Set(Y.map(U=>U.id));for(const U of ee.current)if(U.parentId&&re.has(U.parentId)&&!re.has(U.id)){let ae=ee.current.find(Ye=>Ye.id===U.parentId),Re=U.position.x,Be=U.position.y;for(;ae;)Re+=ae.position.x,Be+=ae.position.y,ae=ae.parentId?ee.current.find(Ye=>Ye.id===ae.parentId):null;G.push({id:U.id,position:U.position,_absolutePosition:{x:Re,y:Be},width:U.width,height:U.height,dragging:!1,selected:U.selected})}if((c=Se.current)==null||c.postMessage({type:"nodePositions",data:{updates:G}}),Nn){const U=be.current;if(U){const ae=U.getBoundingClientRect(),Re=40,Be=u.clientX-ae.left,Ye=u.clientY-ae.top;let qe=0,Oe=0;Be<Re?qe=ot:Be>ae.width-Re&&(qe=-ot),Ye<Re?Oe=ot:Ye>ae.height-Re&&(Oe=-ot),(qe||Oe)&&(ue.current.x+=qe,ue.current.y+=Oe,we(u))}}const K=ee.current.find(U=>U.id===E.id);if(K&&((g=Dt.current)==null||g.call(Dt,u,K)),E.selectedStarts.length>0){const U=ee.current.filter(ae=>ae.selected);(S=(k=V.current).onSelectionDrag)==null||S.call(k,u,U)}return}if(!Lt.current)return;const p=ue.current;p.x+=u.clientX-Bt.current.x,p.y+=u.clientY-Bt.current.y,Bt.current={x:u.clientX,y:u.clientY},we()},[we,Le,vt,lt]),Qt=a.useCallback(u=>{var p,c,g,k,S,m,E,w;if(Xe.current){const H=Le(u.clientX,u.clientY),I=kt(H.x,H.y);if(I&&I.nodeId!==Xe.current.sourceId&&($e==="loose"||I.type==="target")){const re=Xe.current.sourceType==="target"?{source:I.nodeId,target:Xe.current.sourceId,sourceHandle:I.handleId||null,targetHandle:Xe.current.sourceHandle}:{source:Xe.current.sourceId,target:I.nodeId,sourceHandle:Xe.current.sourceHandle,targetHandle:I.handleId||null};(V.current.isValidConnection?V.current.isValidConnection(re):!0)&&((p=at.current)==null||p.call(at,{...re,...Pt}))}(g=(c=V.current).onConnectEnd)==null||g.call(c,u.nativeEvent||u),Xe.current=null,At.current=null,vt();return}if(st.current){st.current=null,lt(),pt();return}if(Fe.current){const H=Fe.current,I=ee.current.find(re=>re.id===H.id),Y=[{id:H.id,position:I?{...I.position}:H.startPos,_absolutePosition:I?{...I.position}:H.startPos,dragging:!1}];for(const re of H.selectedStarts){const K=ee.current.find(U=>U.id===re.id);Y.push({id:re.id,position:K?{...K.position}:re.startPos,_absolutePosition:K?{...K.position}:re.startPos,dragging:!1})}if((k=Se.current)==null||k.postMessage({type:"nodePositions",data:{updates:Y}}),Pe.current){const re=Y.map(K=>({id:K.id,type:"position",position:K.position,dragging:!1}));Pe.current(re)}if(H.selectedStarts.length>0){const re=ee.current.filter(K=>K.selected);(m=(S=V.current).onSelectionDragStop)==null||m.call(S,u,re)}requestAnimationFrame(()=>{Fe.current=null});const G=ee.current.find(re=>re.id===H.id);G&&((E=Ht.current)==null||E.call(Ht,u,G));return}Lt.current=!1,(w=be.current)==null||w.classList.remove("dragging")},[Le,kt,vt,lt,pt]);a.useEffect(()=>{const u=be.current;if(!u)return;const p=c=>{Ot&&c.preventDefault();const g=ue.current;if(Ke||Je.current){const w=ln;zt==="horizontal"?g.x-=c.deltaY*w:(zt==="vertical"||(g.x-=c.deltaX*w),g.y-=c.deltaY*w),we(c);return}if(!un)return;const k=c.deltaY>0?.92:1.08,S=u.getBoundingClientRect(),m=c.clientX-S.left,E=c.clientY-S.top;g.x=m-(m-g.x)*k,g.y=E-(E-g.y)*k,g.zoom=Math.min(fe,Math.max(ie,g.zoom*k)),we(c)};return u.addEventListener("wheel",p,{passive:!Ot}),()=>u.removeEventListener("wheel",p)},[we,ie,fe,Ke,zt,ln,un,Ot]),a.useEffect(()=>{if(!fn)return;const u=be.current;if(!u)return;let p=0,c=null;const g=m=>{if(m.touches.length===2){const E=m.touches[0].clientX-m.touches[1].clientX,w=m.touches[0].clientY-m.touches[1].clientY;p=Math.hypot(E,w);const H=u.getBoundingClientRect();c={x:(m.touches[0].clientX+m.touches[1].clientX)/2-H.left,y:(m.touches[0].clientY+m.touches[1].clientY)/2-H.top},m.preventDefault()}},k=m=>{if(m.touches.length===2&&p>0){m.preventDefault();const E=m.touches[0].clientX-m.touches[1].clientX,w=m.touches[0].clientY-m.touches[1].clientY,H=Math.hypot(E,w),I=H/p;p=H;const Y=ue.current,G=c.x,re=c.y;Y.x=G-(G-Y.x)*I,Y.y=re-(re-Y.y)*I,Y.zoom=Math.min(fe,Math.max(ie,Y.zoom*I)),we(m)}},S=()=>{p=0,c=null};return u.addEventListener("touchstart",g,{passive:!1}),u.addEventListener("touchmove",k,{passive:!1}),u.addEventListener("touchend",S),()=>{u.removeEventListener("touchstart",g),u.removeEventListener("touchmove",k),u.removeEventListener("touchend",S)}},[fn,we,ie,fe]),a.useEffect(()=>{if(!dn)return;const u=be.current;if(!u)return;const p=c=>{var I,Y,G,re;const g=Le(c.clientX,c.clientY);if(et(g.x,g.y)){(Y=(I=V.current).onNodeDoubleClick)==null||Y.call(I,c,et(g.x,g.y));return}const k=Ve(g.x,g.y);if(k){(re=(G=V.current).onEdgeDoubleClick)==null||re.call(G,c,k);return}const S=1.5,m=u.getBoundingClientRect(),E=c.clientX-m.left,w=c.clientY-m.top,H=ue.current;H.x=E-(E-H.x)*S,H.y=w-(w-H.y)*S,H.zoom=Math.min(fe,Math.max(ie,H.zoom*S)),we(c)};return u.addEventListener("dblclick",p),()=>u.removeEventListener("dblclick",p)},[dn,we,ie,fe,Le,et,Ve]),a.useEffect(()=>{const u=be.current;if(!u)return;const p=c=>{var m,E,w,H,I,Y;const g=Le(c.clientX,c.clientY),k=et(g.x,g.y);if(k){(E=(m=V.current).onNodeContextMenu)==null||E.call(m,c,k);return}const S=Ve(g.x,g.y);if(S){(H=(w=V.current).onEdgeContextMenu)==null||H.call(w,c,S);return}(Y=(I=V.current).onPaneContextMenu)==null||Y.call(I,c)};return u.addEventListener("contextmenu",p),()=>u.removeEventListener("contextmenu",p)},[Le,et,Ve]),a.useEffect(()=>{const u=be.current;if(!u)return;let p=null,c=null;const g=m=>{var H,I,Y,G,re,K,U,ae,Re,Be,Ye,qe,Oe,Kt;if((I=(H=V.current).onPaneMouseMove)==null||I.call(H,m),Lt.current||Fe.current||Xe.current||st.current)return;const E=Le(m.clientX,m.clientY),w=et(E.x,E.y);if(w!==p&&(p&&((G=(Y=V.current).onNodeMouseLeave)==null||G.call(Y,m,p)),w&&((K=(re=V.current).onNodeMouseEnter)==null||K.call(re,m,w)),p=w),w&&((ae=(U=V.current).onNodeMouseMove)==null||ae.call(U,m,w)),!w){const ft=Ve(E.x,E.y);ft!==c&&(c&&((Be=(Re=V.current).onEdgeMouseLeave)==null||Be.call(Re,m,c)),ft&&((qe=(Ye=V.current).onEdgeMouseEnter)==null||qe.call(Ye,m,ft)),c=ft),ft&&((Kt=(Oe=V.current).onEdgeMouseMove)==null||Kt.call(Oe,m,ft))}},k=m=>{var E,w;return(w=(E=V.current).onPaneMouseEnter)==null?void 0:w.call(E,m)},S=m=>{var E,w,H,I,Y,G;(w=(E=V.current).onPaneMouseLeave)==null||w.call(E,m),p&&((I=(H=V.current).onNodeMouseLeave)==null||I.call(H,m,p),p=null),c&&((G=(Y=V.current).onEdgeMouseLeave)==null||G.call(Y,m,c),c=null)};return u.addEventListener("mousemove",g),u.addEventListener("mouseenter",k),u.addEventListener("mouseleave",S),()=>{u.removeEventListener("mousemove",g),u.removeEventListener("mouseenter",k),u.removeEventListener("mouseleave",S)}},[Le,et,Ve]),a.useEffect(()=>{const u=Array.isArray(He)?He:[He],p=async c=>{var g,k,S,m;if(u.includes(c.key)){if(c.target.tagName==="INPUT"||c.target.tagName==="TEXTAREA"||c.target.isContentEditable)return;const E=ee.current.filter(I=>I.selected),w=ze.current.filter(I=>I.selected);if(!E.length&&!w.length)return;if(V.current.onBeforeDelete)try{if(!await V.current.onBeforeDelete({nodes:E,edges:w}))return}catch(I){(k=(g=V.current).onError)==null||k.call(g,"before-delete-error",I.message||"onBeforeDelete threw an error");return}const H=new Set(E.map(I=>I.id));if(E.length&&Pe.current&&(Pe.current(E.map(I=>({id:I.id,type:"remove"}))),Te.current)){const I=ze.current.filter(Y=>H.has(Y.source)||H.has(Y.target));I.length&&Te.current(I.map(Y=>({id:Y.id,type:"remove"})))}w.length&&Te.current&&Te.current(w.map(I=>({id:I.id,type:"remove"}))),(m=(S=V.current).onDelete)==null||m.call(S,{nodes:E,edges:w})}if((c.ctrlKey||c.metaKey)&&c.key==="a"){if(c.target.tagName==="INPUT"||c.target.tagName==="TEXTAREA")return;if(c.preventDefault(),Pe.current){const E=ee.current.filter(w=>!w.selected).map(w=>({id:w.id,type:"select",selected:!0}));E.length&&Pe.current(E)}if(Te.current){const E=ze.current.filter(w=>!w.selected).map(w=>({id:w.id,type:"select",selected:!0}));E.length&&Te.current(E)}}};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[He]);const Jt=a.useRef(!1);a.useEffect(()=>{var u,p;if(!Jt.current&&Se.current){if(Jt.current=!0,je&&ee.current.length>0){const c=be.current;if(c){const g=c.getBoundingClientRect(),k=(ge==null?void 0:ge.padding)??.1,S=Mn(ee.current),m=Xt(S,g.width,g.height,k);ge!=null&&ge.maxZoom&&(m.zoom=Math.min(m.zoom,ge.maxZoom)),ge!=null&&ge.minZoom&&(m.zoom=Math.max(m.zoom,ge.minZoom)),ue.current=m,we()}}(p=(u=V.current).onInit)==null||p.call(u,{getNodes:()=>[...ee.current],getEdges:()=>[...ze.current],getNode:c=>ee.current.find(g=>g.id===c),getEdge:c=>ze.current.find(g=>g.id===c),getViewport:()=>({...ue.current}),getZoom:()=>ue.current.zoom,setViewport:c=>{ue.current={x:c.x??ue.current.x,y:c.y??ue.current.y,zoom:c.zoom??ue.current.zoom},we()},fitView:(c={})=>{const g=be.current;if(!g||!ee.current.length)return;const k=g.getBoundingClientRect(),S=c.nodes?ee.current.filter(w=>c.nodes.some(H=>H.id===w.id)):ee.current;if(!S.length)return;const m=Mn(S),E=Xt(m,k.width,k.height,c.padding??.1);c.maxZoom&&(E.zoom=Math.min(E.zoom,c.maxZoom)),c.minZoom&&(E.zoom=Math.max(E.zoom,c.minZoom)),ue.current=E,we()},screenToFlowPosition:c=>Le(c.x,c.y),flowToScreenPosition:c=>{const g=ue.current,k=be.current;if(!k)return{x:0,y:0};const S=k.getBoundingClientRect();return{x:c.x*g.zoom+g.x+S.left,y:c.y*g.zoom+g.y+S.top}},zoomIn:()=>{const c=ue.current;c.zoom=Math.min(fe,c.zoom*1.2),we()},zoomOut:()=>{const c=ue.current;c.zoom=Math.max(ie,c.zoom/1.2),we()},zoomTo:c=>{ue.current.zoom=Math.min(fe,Math.max(ie,c)),we()},setNodes:c=>{var g,k;(k=(g=V.current).onNodesChange)==null||k.call(g,[...ee.current.map(S=>({id:S.id,type:"remove"})),...(typeof c=="function"?c(ee.current):c).map(S=>({type:"add",item:S}))])},setEdges:c=>{var g,k;(k=(g=V.current).onEdgesChange)==null||k.call(g,[...ze.current.map(S=>({id:S.id,type:"remove"})),...(typeof c=="function"?c(ze.current):c).map(S=>({type:"add",item:S}))])},addNodes:c=>{var k,S;const g=Array.isArray(c)?c:[c];(S=(k=V.current).onNodesChange)==null||S.call(k,g.map(m=>({type:"add",item:m})))},addEdges:c=>{var k,S;const g=Array.isArray(c)?c:[c];(S=(k=V.current).onEdgesChange)==null||S.call(k,g.map(m=>({type:"add",item:m})))},deleteElements:({nodes:c=[],edges:g=[]})=>{var k,S,m,E;c.length&&((S=(k=V.current).onNodesChange)==null||S.call(k,c.map(w=>({id:w.id,type:"remove"})))),g.length&&((E=(m=V.current).onEdgesChange)==null||E.call(m,g.map(w=>({id:w.id,type:"remove"}))))},updateNodeData:(c,g)=>{var m,E;const k=ee.current.find(w=>w.id===c);if(!k)return;const S=typeof g=="function"?g(k.data):{...k.data,...g};(E=(m=V.current).onNodesChange)==null||E.call(m,[{id:c,type:"replace",item:{...k,data:S}}])},toObject:()=>({nodes:[...ee.current],edges:[...ze.current],viewport:{...ue.current}}),setCenter:(c,g,k={})=>{const S=be.current;if(!S)return;const m=S.getBoundingClientRect(),E=k.zoom??ue.current.zoom;ue.current={x:m.width/2-c*E,y:m.height/2-g*E,zoom:E},we()},fitBounds:(c,g={})=>{const k=be.current;if(!k)return;const S=k.getBoundingClientRect(),m=Xt(c,S.width,S.height,g.padding??.1);ue.current=m,we()}})}});const Vt=a.useCallback(()=>{ue.current={...Ce},we()},[we,Ce]),Hn=a.useCallback(u=>{var p;if(u)yt.current.push(u);else{const c=ue.current,g=be.current;if(!g)return;const k=g.getBoundingClientRect(),S=Math.round(-c.x/c.zoom+k.width/2/c.zoom),m=Math.round(-c.y/c.zoom+k.height/2/c.zoom);yt.current.push({x:S-80,y:m-45,w:160,h:90,title:"Note "+(yt.current.length+1),body:"Added at viewport center"})}(p=Se.current)==null||p.postMessage({type:"cards",data:{cards:[...yt.current]}})},[]),_n=a.useCallback(u=>{if(u.id||(u.id="node-"+Date.now()),!u.position){const p=ue.current,c=be.current;if(!c)return;const g=c.getBoundingClientRect();u.position={x:Math.round(-p.x/p.zoom+g.width/2/p.zoom)-ut/2,y:Math.round(-p.y/p.zoom+g.height/2/p.zoom)-tt/2}}u.data||(u.data={label:u.id}),Pe.current&&Pe.current([{type:"add",item:u}])},[]),Wn=a.useCallback(()=>({...ue.current}),[]),Fn=a.useCallback(u=>{ue.current={...ue.current,...u},we()},[we]),_=a.useCallback(u=>Le(u.x,u.y),[Le]),pe=n,ne=a.useMemo(()=>({wrapRef:be,canvasRef:Tt,workerRef:Se,cameraRef:ue,nodesRef:ee,edgesRef:ze,handleRegistryRef:hn,syncNodesToWorker:mn,onNodesChangeRef:Pe,onEdgesChangeRef:Te,sendCamera:we,screenToWorld:Le,viewportListeners:xt,selectionListeners:it,zoomMin:ie,zoomMax:fe,snapToGrid:Ge,snapGrid:rt,nodeExtent:gt,defaultEdgeOptions:Pt,edgeRouting:bt,resolvedNodesRef:ct,noDragClassName:Nt,noPanClassName:It,get nodes(){return t},get edges(){return n},get routedEdges(){return pe},get viewport(){return yn},get connection(){return Ut}}),[t,n,pe,yn,Ut,we,Le,mn,xt,it,ie,fe,Ge,rt,gt,Pt,bt,Nt,It]);return{wrapRef:be,canvasRef:Tt,canvasReady:$t,onPointerDown:Zt,onPointerMove:Gt,onPointerUp:Qt,resetView:Vt,addCard:Hn,addNode:_n,getCamera:Wn,setCamera:Fn,screenToFlowPosition:_,store:ne}}function ro(e,t,n,r,i,o){const l=i-n,h=o-r,v=l*l+h*h;if(v===0)return Math.hypot(e-n,t-r);let f=((e-n)*l+(t-r)*h)/v;return f=Math.max(0,Math.min(1,f)),Math.hypot(e-(n+f*l),t-(r+f*h))}const ur=e=>{let t;const n=new Set,r=(f,y)=>{const x=typeof f=="function"?f(t):f;if(!Object.is(x,t)){const R=t;t=y??(typeof x!="object"||x===null)?x:Object.assign({},t,x),n.forEach(C=>C(t,R))}},i=()=>t,h={setState:r,getState:i,getInitialState:()=>v,subscribe:f=>(n.add(f),()=>n.delete(f))},v=t=e(r,i,h);return h},oo=(e=>e?ur(e):ur),so=e=>e;function io(e,t=so){const n=a.useSyncExternalStore(e.subscribe,a.useCallback(()=>t(e.getState()),[e,t]),a.useCallback(()=>t(e.getInitialState()),[e,t]));return a.useDebugValue(n),n}const St=a.createContext(null);function ao(e={}){return oo((t,n)=>({nodes:[],edges:[],viewport:{x:0,y:0,zoom:1},connection:null,minZoom:.1,maxZoom:5,width:0,height:0,domNode:null,nodesRef:{current:[]},edgesRef:{current:[]},cameraRef:{current:{x:0,y:0,zoom:1}},wrapRef:{current:null},workerRef:{current:null},onNodesChangeRef:{current:null},onEdgesChangeRef:{current:null},viewportListeners:new Set,selectionListeners:new Set,edgeLabelContainerRef:{current:null},viewportPortalRef:{current:null},screenToWorld:(r,i)=>{const o=n().cameraRef.current;return{x:(r-o.x)/o.zoom,y:(i-o.y)/o.zoom}},sendCamera:()=>{var i;const r=n();(i=r.workerRef.current)==null||i.postMessage({type:"camera",data:{camera:{...r.cameraRef.current}}})},...e}))}function Ne(e,t){const n=a.useContext(St);if(!n)throw new Error("useCanvasStore must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");const r=typeof n.getState=="function"&&typeof n.subscribe=="function",i=a.useRef(e),o=a.useRef(t),l=a.useRef(void 0);i.current=e,o.current=t;const h=a.useCallback(v=>{const f=i.current;if(!f)return v;const y=f(v),x=o.current||Object.is;return l.current!==void 0&&x(l.current,y)?l.current:(l.current=y,y)},[]);return r?io(n,e?h:void 0):e?h(n):n}function Rr(){const e=a.useContext(St);if(!e)throw new Error("useCanvasStoreApi must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");return typeof e.getState=="function"?e:{getState:()=>e,setState:()=>{},subscribe:()=>()=>{}}}const an=a.createContext(null);function co(){return a.useContext(an)}function lo({node:e,nodeType:t}){var z,W,j,D;const n=Ne(),r=a.useRef(n);r.current=n;const i=a.useRef(null),o=e._absolutePosition||e.position,l=a.useRef(null);a.useEffect(()=>{const F=i.current;if(!F)return;const $=new ResizeObserver(X=>{var Z,q,O,M;const{width:A,height:P}=X[0].contentRect;if(A>0&&P>0){const d=r.current,b=d.nodesRef.current.find(B=>B.id===e.id),L=(b==null?void 0:b.width)||((Z=b==null?void 0:b.measured)==null?void 0:Z.width),T=(b==null?void 0:b.height)||((q=b==null?void 0:b.measured)==null?void 0:q.height);(Math.abs((L||0)-A)>1||Math.abs((T||0)-P)>1)&&((M=(O=d.onNodesChangeRef).current)==null||M.call(O,[{id:e.id,type:"dimensions",dimensions:{width:A,height:P},setAttributes:!0}]))}});return $.observe(F),()=>$.disconnect()},[e.id]);const h=a.useCallback(F=>{var ce,me,Me,ke;F.stopPropagation();const $=F.target.tagName;if($==="INPUT"||$==="TEXTAREA"||$==="SELECT"||$==="BUTTON"||$==="A"||$==="LABEL"||F.target.isContentEditable)return;const X=r.current.noDragClassName||"nodrag",A=r.current.noPanClassName||"nopan";let P=F.target;for(;P&&P!==i.current;){if((ce=P.classList)!=null&&ce.contains(X)||(me=P.classList)!=null&&me.contains(A))return;P=P.parentElement}if(r.current.onNodesChangeRef.current){const le=[];if(F.shiftKey)le.push({id:e.id,type:"select",selected:!e.selected});else for(const ie of r.current.nodesRef.current)ie.id===e.id&&!ie.selected?le.push({id:ie.id,type:"select",selected:!0}):ie.id!==e.id&&ie.selected&&le.push({id:ie.id,type:"select",selected:!1});le.length&&r.current.onNodesChangeRef.current(le)}const Z=r.current.cameraRef.current,q=r.current.wrapRef.current;if(!q)return;const O=q.getBoundingClientRect(),M=(F.clientX-O.left-Z.x)/Z.zoom,d=(F.clientY-O.top-Z.y)/Z.zoom,L=e.selected?r.current.nodesRef.current.filter(le=>le.selected&&le.id!==e.id).map(le=>({id:le.id,startPos:{...le.position}})):[];l.current={startPos:{...e.position},startMouse:{x:M,y:d},selectedStarts:L};const T=[{id:e.id,type:"position",dragging:!0}];for(const le of L)T.push({id:le.id,type:"position",dragging:!0});(ke=(Me=r.current.onNodesChangeRef).current)==null||ke.call(Me,T);const B=i.current;B&&B.setPointerCapture(F.pointerId);let Q=null;const oe=le=>{var _e,We,nt,De;if(!l.current)return;const xe=r.current.cameraRef.current,ie=q.getBoundingClientRect(),fe=(le.clientX-ie.left-xe.x)/xe.zoom,Ce=(le.clientY-ie.top-xe.y)/xe.zoom,je=fe-l.current.startMouse.x,ge=Ce-l.current.startMouse.y;let de={x:l.current.startPos.x+je,y:l.current.startPos.y+ge};if(r.current.snapToGrid&&r.current.snapGrid&&(de={x:r.current.snapGrid[0]*Math.round(de.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(de.y/r.current.snapGrid[1])}),e.parentId&&e.extent==="parent"){const $e=r.current.nodesRef.current.find(Ie=>Ie.id===e.parentId);if($e){const Ie=$e.width||160,Ee=$e.height||60,Ge=e.width||((_e=e.measured)==null?void 0:_e.width)||160,rt=e.height||((We=e.measured)==null?void 0:We.height)||60;de={x:Math.max(0,Math.min(de.x,Ie-Ge)),y:Math.max(0,Math.min(de.y,Ee-rt))}}}B&&(B.style.left=de.x+"px",B.style.top=de.y+"px");const Ae=[{id:e.id,position:de,_absolutePosition:de,dragging:!0}];for(const $e of l.current.selectedStarts){let Ie={x:$e.startPos.x+je,y:$e.startPos.y+ge};r.current.snapToGrid&&r.current.snapGrid&&(Ie={x:r.current.snapGrid[0]*Math.round(Ie.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Ie.y/r.current.snapGrid[1])});const Ee=q.querySelector(`[data-nodeid="${$e.id}"]`);Ee&&(Ee.style.left=Ie.x+"px",Ee.style.top=Ie.y+"px"),Ae.push({id:$e.id,position:Ie,_absolutePosition:Ie,dragging:!0})}(De=(nt=r.current.workerRef)==null?void 0:nt.current)==null||De.postMessage({type:"nodePositions",data:{updates:Ae}});for(const $e of Ae){const Ie=r.current.nodesRef.current.find(Ee=>Ee.id===$e.id);Ie&&(Ie.position=$e.position)}Q=Ae},te=le=>{var fe,Ce,je,ge;if(!l.current)return;const xe=[{id:e.id,position:e.position,dragging:!1}];for(const de of l.current.selectedStarts)xe.push({id:de.id,position:de.startPos,dragging:!1});if(Q)for(let de=0;de<Q.length;de++)xe[de]={id:Q[de].id,position:Q[de].position,dragging:!1};(Ce=(fe=r.current.workerRef)==null?void 0:fe.current)==null||Ce.postMessage({type:"nodePositions",data:{updates:xe}});const ie=[];for(const de of xe)ie.push({id:de.id,type:"position",position:de.position,dragging:!1});(ge=(je=r.current.onNodesChangeRef).current)==null||ge.call(je,ie),l.current=null,Q=null,B&&B.releasePointerCapture(le.pointerId),B==null||B.removeEventListener("pointermove",oe),B==null||B.removeEventListener("pointerup",te)};B==null||B.addEventListener("pointermove",oe),B==null||B.addEventListener("pointerup",te)},[e]),v=a.useCallback(F=>{var q,O,M,d,b,L;if(!e.selected)return;const $=F.shiftKey?10:1;let X=0,A=0;switch(F.key){case"ArrowUp":A=-$;break;case"ArrowDown":A=$;break;case"ArrowLeft":X=-$;break;case"ArrowRight":X=$;break;case"Escape":(O=(q=r.current.onNodesChangeRef).current)==null||O.call(q,[{id:e.id,type:"select",selected:!1}]);return;case"Delete":case"Backspace":e.deletable!==!1&&((d=(M=r.current.onNodesChangeRef).current)==null||d.call(M,[{id:e.id,type:"remove"}]));return;default:return}F.preventDefault();const P={x:e.position.x+X,y:e.position.y+A},Z=[{id:e.id,type:"position",position:P}];for(const T of r.current.nodesRef.current)T.selected&&T.id!==e.id&&Z.push({id:T.id,type:"position",position:{x:T.position.x+X,y:T.position.y+A}});(L=(b=r.current.onNodesChangeRef).current)==null||L.call(b,Z)},[e]),f=e.width||((z=e.measured)==null?void 0:z.width),y=e.height||((W=e.measured)==null?void 0:W.height),x=!!(f&&y),R=(j=n.pinnedNodeIds)==null?void 0:j.has(e.id),C=a.useCallback(F=>{var $,X;F.stopPropagation(),(X=($=r.current).togglePinNode)==null||X.call($,e.id)},[e.id]);return N.jsx(an.Provider,{value:e.id,children:N.jsxs("div",{ref:i,className:`ric-node-wrapper ${e.selected?"selected":""} ${e.dragging?"dragging":""}`,style:{position:"absolute",left:o.x,top:o.y,zIndex:e.type==="group"?0:e.zIndex||1,pointerEvents:e.type==="group"?"none":"all",visibility:x?"visible":"hidden",outline:"none"},"data-nodeid":e.id,tabIndex:e.selectable!==!1?0:void 0,role:"button","aria-label":`Node ${((D=e.data)==null?void 0:D.label)||e.id}`,"aria-selected":!!e.selected,onPointerDown:h,onKeyDown:v,children:[N.jsx(t,{id:e.id,data:e.data,type:e.type,selected:!!e.selected,dragging:!!e.dragging,draggable:e.draggable!==!1,selectable:e.selectable!==!1,deletable:e.deletable!==!1,isConnectable:e.connectable!==!1,zIndex:e.zIndex||0,positionAbsoluteX:o.x,positionAbsoluteY:o.y,width:f,height:y,sourcePosition:e.sourcePosition,targetPosition:e.targetPosition,parentId:e.parentId,dragHandle:e.dragHandle}),n.togglePinNode&&N.jsx("button",{className:"ric-pin-btn nodrag",onClick:C,title:R?"Unpin from DOM":"Pin to DOM",style:{position:"absolute",top:-8,left:-8,width:20,height:20,borderRadius:"50%",border:"1.5px solid "+(R?"#3b82f6":"#ccc"),background:R?"#3b82f6":"#fff",color:R?"#fff":"#999",fontSize:10,lineHeight:"16px",textAlign:"center",cursor:"pointer",padding:0,zIndex:10,pointerEvents:"all",boxShadow:"0 1px 3px rgba(0,0,0,0.12)"},children:"📌"})]})})}const uo=a.memo(lo),kr=160,Cr=60;function dr(e,t,n,r){var v,f;const i=e.width||((v=e.measured)==null?void 0:v.width)||kr,o=e.height||((f=e.measured)==null?void 0:f.height)||Cr,l=e._absolutePosition||e.position;if(e.handleBounds){const y=e.handleBounds[t]||[],x=n?y.find(R=>R.id===n):y[0];if(x&&x.x!==void 0&&x.y!==void 0){const R=x.position||(t==="source"?"right":"left");return{x:l.x+x.x,y:l.y+x.y,position:R}}}if(r){const y=`${e.id}__${n||t}`,x=r.get(y);if(x&&x.x!==void 0&&x.y!==void 0)return{x:l.x+x.x,y:l.y+x.y,position:x.position||(t==="source"?"right":"left")}}if(e.handles&&e.handles.length){for(const y of e.handles)if(y.type===t&&(!n||y.id===n)){if(y.x!==void 0&&y.y!==void 0)return{x:l.x+y.x,y:l.y+y.y,position:y.position||(t==="source"?"right":"left")};const x=y.position||(t==="source"?"right":"left");switch(x){case"top":return{x:l.x+i/2,y:l.y,position:x};case"bottom":return{x:l.x+i/2,y:l.y+o,position:x};case"left":return{x:l.x,y:l.y+o/2,position:x};default:return{x:l.x+i,y:l.y+o/2,position:x}}}}switch(t==="source"?e.sourcePosition||"right":e.targetPosition||"left"){case"top":return{x:l.x+i/2,y:l.y,position:"top"};case"bottom":return{x:l.x+i/2,y:l.y+o,position:"bottom"};case"left":return{x:l.x,y:l.y+o/2,position:"left"};default:return{x:l.x+i,y:l.y+o/2,position:"right"}}}function fo(e,t,n){return n==="left"?e-t:n==="right"?e+t:e}function ho(e,t,n){return n==="top"?e-t:n==="bottom"?e+t:e}function fr({x:e,y:t,position:n,type:r,onPointerDown:i}){return N.jsx("circle",{className:`ric-edge-anchor ric-edge-anchor-${r}`,cx:fo(e,10,n),cy:ho(t,10,n),r:10,stroke:"transparent",fill:"transparent",style:{cursor:"move",pointerEvents:"stroke"},onPointerDown:i})}function go({edge:e,edgeType:t,nodes:n,reconnectable:r}){var O,M;const i=a.useContext(St),o=a.useRef(typeof i.getState=="function"?i.getState():i);o.current=typeof i.getState=="function"?i.getState():i;const[l,h]=a.useState(null),v=a.useCallback((d,b,L,T)=>{var ke;b.stopPropagation(),b.preventDefault();const B=o.current,Q=B.wrapRef.current;if(!Q)return;const oe=d==="source"?T:L,te=d==="source"?e.target:e.source;(ke=B.workerRef.current)==null||ke.postMessage({type:"connecting",data:{from:{x:oe.x,y:oe.y},to:{x:oe.x,y:oe.y}}});const ce=Q.getBoundingClientRect(),me=le=>{var Ce;const xe=B.cameraRef.current,ie=(le.clientX-ce.left-xe.x)/xe.zoom,fe=(le.clientY-ce.top-xe.y)/xe.zoom;(Ce=B.workerRef.current)==null||Ce.postMessage({type:"connecting",data:{from:{x:oe.x,y:oe.y},to:{x:ie,y:fe}}})},Me=le=>{var Ae,_e,We,nt;const xe=B.cameraRef.current,ie=(le.clientX-ce.left-xe.x)/xe.zoom,fe=(le.clientY-ce.top-xe.y)/xe.zoom,Ce=20/xe.zoom;let je=null,ge=null;const de=(Ae=B.handleRegistryRef)==null?void 0:Ae.current;for(const De of B.nodesRef.current){if(De.hidden)continue;const $e=De.width||kr,Ie=De.height||Cr,Ee=De._absolutePosition||De.position,Ge=[];if(de)for(const[,He]of de)He.nodeId===De.id&&Ge.push(He);const rt=Ge.length>0?Ge:De.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const He of rt){let Ue,Ke;if(He.x!==void 0&&He.y!==void 0)Ue=Ee.x+He.x,Ke=Ee.y+He.y;else switch(He.position||(He.type==="source"?"right":"left")){case"top":Ue=Ee.x+$e/2,Ke=Ee.y;break;case"bottom":Ue=Ee.x+$e/2,Ke=Ee.y+Ie;break;case"left":Ue=Ee.x,Ke=Ee.y+Ie/2;break;default:Ue=Ee.x+$e,Ke=Ee.y+Ie/2;break}if(Math.abs(ie-Ue)<Ce&&Math.abs(fe-Ke)<Ce){je=De,ge=He.id||null;break}}if(je)break}if(je){const De=d==="source"?{source:je.id,target:te,sourceHandle:ge,targetHandle:e.targetHandle}:{source:te,target:je.id,sourceHandle:e.sourceHandle,targetHandle:ge};(We=(_e=B.onEdgesChangeRef).current)==null||We.call(_e,[{id:e.id,type:"remove"},{type:"add",item:{id:e.id,...De}}])}(nt=B.workerRef.current)==null||nt.postMessage({type:"connecting",data:null}),Q.removeEventListener("pointermove",me),Q.removeEventListener("pointerup",Me)};Q.addEventListener("pointermove",me),Q.addEventListener("pointerup",Me)},[e]),f=o.current,y=((O=f.nodesRef)==null?void 0:O.current)||n,x=y.find(d=>d.id===e.source),R=y.find(d=>d.id===e.target),[,C]=a.useReducer(d=>d+1,0),z=a.useRef(null),W=(x==null?void 0:x.dragging)||(R==null?void 0:R.dragging);a.useEffect(()=>{if(!W)return;const d=()=>{C(),z.current=requestAnimationFrame(d)};return z.current=requestAnimationFrame(d),()=>cancelAnimationFrame(z.current)},[W]);const j=a.useRef(!1);a.useEffect(()=>{j.current||(j.current=!0,requestAnimationFrame(()=>C()))},[]);const D=(M=f.handleRegistryRef)==null?void 0:M.current,F=x?dr(x,"source",e.sourceHandle,D):null,$=R?dr(R,"target",e.targetHandle,D):null,X=e.type==="bezier"||e.type==="simplebezier"||e.type==="default",A=f.routedEdges||f.edges,P=A==null?void 0:A.find(d=>d.id===e.id),Z=X?null:(P==null?void 0:P._routedPoints)||e._routedPoints||null,q=r!==!1&&e.reconnectable!==!1;return!F||!$?null:N.jsxs("g",{className:`ric-edge-wrapper ${e.selected?"selected":""}`,"data-edgeid":e.id,onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),children:[N.jsx(t,{id:e.id,source:e.source,target:e.target,sourceX:F.x,sourceY:F.y,targetX:$.x,targetY:$.y,sourcePosition:F.position,targetPosition:$.position,sourceHandleId:e.sourceHandle,targetHandleId:e.targetHandle,data:e.data,type:e.type,selected:!!e.selected,animated:!!e.animated,label:e.label,style:e.style,selectable:e.selectable!==!1,deletable:e.deletable!==!1,routedPoints:Z}),q&&(l||e.selected)&&N.jsxs(N.Fragment,{children:[N.jsx(fr,{x:F.x,y:F.y,position:F.position,type:"source",onPointerDown:d=>v("source",d,F,$)}),N.jsx(fr,{x:$.x,y:$.y,position:$.position,type:"target",onPointerDown:d=>v("target",d,F,$)})]})]})}const yo=a.memo(go);function Er({selectionKeyCode:e="Shift",selectionMode:t="partial"}){var W;const n=Ne(),[r,i]=a.useState(null),o=a.useRef(null);if(a.useEffect(()=>{const j=n.wrapRef.current;if(!j)return;let D=!1,F=null,$=!1;const X=O=>{O.key===e&&($=!0)},A=O=>{O.key===e&&($=!1)},P=O=>{if(!$)return;const M=O.target;if(M.closest(".ric-node-wrapper")||M.closest(".ric-handle"))return;D=!0;const d=n.cameraRef.current,b=j.getBoundingClientRect(),L=(O.clientX-b.left-d.x)/d.zoom,T=(O.clientY-b.top-d.y)/d.zoom;F={x:L,y:T},i({startX:L,startY:T,endX:L,endY:T}),O.stopPropagation()},Z=O=>{if(!D||!F)return;const M=n.cameraRef.current,d=j.getBoundingClientRect(),b=(O.clientX-d.left-M.x)/M.zoom,L=(O.clientY-d.top-M.y)/M.zoom;i({startX:F.x,startY:F.y,endX:b,endY:L})},q=O=>{var Q,oe;if(!D||!F)return;D=!1;const M=n.cameraRef.current,d=j.getBoundingClientRect(),b=(O.clientX-d.left-M.x)/M.zoom,L=(O.clientY-d.top-M.y)/M.zoom,T={x:Math.min(F.x,b),y:Math.min(F.y,L),width:Math.abs(b-F.x),height:Math.abs(L-F.y)},B=[];for(const te of n.nodesRef.current){const ce=te._absolutePosition||te.position,me=te.width||160,Me=te.height||60;let ke;t==="full"?ke=ce.x>=T.x&&ce.y>=T.y&&ce.x+me<=T.x+T.width&&ce.y+Me<=T.y+T.height:ke=ce.x+me>T.x&&ce.x<T.x+T.width&&ce.y+Me>T.y&&ce.y<T.y+T.height,B.push({id:te.id,type:"select",selected:ke})}B.length&&((oe=(Q=n.onNodesChangeRef).current)==null||oe.call(Q,B)),F=null,i(null)};return j.addEventListener("pointerdown",P,!0),j.addEventListener("pointermove",Z),j.addEventListener("pointerup",q),window.addEventListener("keydown",X),window.addEventListener("keyup",A),()=>{j.removeEventListener("pointerdown",P,!0),j.removeEventListener("pointermove",Z),j.removeEventListener("pointerup",q),window.removeEventListener("keydown",X),window.removeEventListener("keyup",A)}},[n,e,t]),!r)return null;const l=((W=n.cameraRef)==null?void 0:W.current)||{x:0,y:0,zoom:1},h=Math.min(r.startX,r.endX),v=Math.min(r.startY,r.endY),f=Math.abs(r.endX-r.startX),y=Math.abs(r.endY-r.startY),x=h*l.zoom+l.x,R=v*l.zoom+l.y,C=f*l.zoom,z=y*l.zoom;return N.jsx("div",{ref:o,className:"ric-selection-box",style:{position:"absolute",left:x,top:R,width:C,height:z,border:"1px dashed #3b82f6",background:"rgba(59, 130, 246, 0.08)",pointerEvents:"none",zIndex:100}})}Er.displayName="SelectionBox";const Sr=a.memo(Er);function Qn(e,t,n){switch(e){case"top":return{x:t/2,y:0};case"bottom":return{x:t/2,y:n};case"left":return{x:0,y:n/2};case"right":return{x:t,y:n/2};default:return{x:t,y:n/2}}}function xo(e,t){const n=e.closest(".ric-node-wrapper");if(!n)return null;const r=n.getBoundingClientRect(),i=e.getBoundingClientRect(),o=t||1;return{x:(i.left+i.width/2-r.left)/o,y:(i.top+i.height/2-r.top)/o}}let On=!1,Et=null;function zr(e){Et=e,!On&&(On=!0,requestAnimationFrame(()=>{var t;On=!1,(t=Et==null?void 0:Et.syncNodesToWorker)==null||t.call(Et),Et=null}))}const Jn=new WeakMap;let bn=null;function po(){return bn||(bn=new ResizeObserver(e=>{var t;for(const n of e){const r=Jn.get(n.target);if(!r)continue;const{width:i,height:o}=n.contentRect;if(!i||!o)continue;const l=r.getStore(),h=(t=l.handleRegistryRef)==null?void 0:t.current;if(h){for(const[v,f]of h)if(f.nodeId===r.nodeId){const y=Qn(f.position,i,o);f.x=y.x,f.y=y.y,h.set(v,f)}zr(l)}}}),bn)}function mo({type:e="source",position:t=e==="source"?"right":"left",id:n,isConnectable:r=!0,isConnectableStart:i=!0,isConnectableEnd:o=!0,children:l,className:h="",style:v={},onConnect:f,...y}){const x=a.useContext(an),R=a.useContext(St),C=a.useRef(null),z=a.useCallback(()=>typeof R.getState=="function"?R.getState():R,[R]),W=a.useRef(z);W.current=z,a.useLayoutEffect(()=>{var M,d,b,L,T,B,Q;if(!x)return;const $=W.current(),X=(M=$.handleRegistryRef)==null?void 0:M.current;if(!X)return;const A=`${x}__${n||e}`,P=(b=(d=$.nodesRef)==null?void 0:d.current)==null?void 0:b.find(oe=>oe.id===x),Z=(P==null?void 0:P.width)||((L=P==null?void 0:P.measured)==null?void 0:L.width),q=(P==null?void 0:P.height)||((T=P==null?void 0:P.measured)==null?void 0:T.height);let O;Z&&q?O=Qn(t,Z,q):C.current?O=xo(C.current,(Q=(B=$.cameraRef)==null?void 0:B.current)==null?void 0:Q.zoom):O=Qn(t,160,60),X.set(A,{nodeId:x,id:n||null,type:e,position:t,x:O.x,y:O.y}),P&&(e==="source"&&(P.sourcePosition=t),e==="target"&&(P.targetPosition=t))},[x,n,e,t]),a.useEffect(()=>{if(!x)return;const $=W.current();zr($);const X=C.current,A=X==null?void 0:X.closest(".ric-node-wrapper");return A&&!Jn.has(A)&&(Jn.set(A,{nodeId:x,getStore:W.current}),po().observe(A)),()=>{var O;const Z=(O=W.current().handleRegistryRef)==null?void 0:O.current,q=`${x}__${n||e}`;Z==null||Z.delete(q)}},[x,n,e,t]);const j=a.useCallback(()=>{var d;const $=W.current(),X=$.nodesRef.current.find(b=>b.id===x);if(!X)return null;const A=X._absolutePosition||X.position,P=(d=$.handleRegistryRef)==null?void 0:d.current,Z=`${x}__${n||e}`,q=P==null?void 0:P.get(Z);if(q&&q.x!==void 0&&q.y!==void 0)return{x:A.x+q.x,y:A.y+q.y};const O=X.width||160,M=X.height||60;switch(t){case"top":return{x:A.x+O/2,y:A.y};case"bottom":return{x:A.x+O/2,y:A.y+M};case"left":return{x:A.x,y:A.y+M/2};default:return{x:A.x+O,y:A.y+M/2}}},[x,n,e,t]),D=a.useCallback($=>{var L;if(!r||!i)return;$.stopPropagation(),$.preventDefault();const X=W.current(),A=X.cameraRef.current,P=X.wrapRef.current;if(!P)return;const Z=P.getBoundingClientRect(),q=j();if(!q)return;const O=q.x,M=q.y;(L=X.workerRef.current)==null||L.postMessage({type:"connecting",data:{from:{x:O,y:M},to:{x:O,y:M}}}),P.setPointerCapture($.pointerId);const d=T=>{var oe;const B=(T.clientX-Z.left-A.x)/A.zoom,Q=(T.clientY-Z.top-A.y)/A.zoom;(oe=X.workerRef.current)==null||oe.postMessage({type:"connecting",data:{from:{x:O,y:M},to:{x:B,y:Q}}})},b=T=>{var Me,ke,le,xe;const B=(T.clientX-Z.left-A.x)/A.zoom,Q=(T.clientY-Z.top-A.y)/A.zoom,oe=20/A.zoom;let te=null,ce=null;const me=(Me=X.handleRegistryRef)==null?void 0:Me.current;for(const ie of X.nodesRef.current){if(ie.id===x||ie.hidden)continue;const fe=ie._absolutePosition||ie.position,Ce=[];if(me)for(const[,ge]of me)ge.nodeId===ie.id&&Ce.push(ge);const je=Ce.length>0?Ce:ie.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const ge of je){let de,Ae;if(ge.x!==void 0&&ge.y!==void 0)de=fe.x+ge.x,Ae=fe.y+ge.y;else{const _e=ie.width||160,We=ie.height||60;switch(ge.position||(ge.type==="source"?"right":"left")){case"top":de=fe.x+_e/2,Ae=fe.y;break;case"bottom":de=fe.x+_e/2,Ae=fe.y+We;break;case"left":de=fe.x,Ae=fe.y+We/2;break;default:de=fe.x+_e,Ae=fe.y+We/2;break}}if(Math.abs(B-de)<oe&&Math.abs(Q-Ae)<oe){te=ie,ce=ge.id||null;break}}if(te)break}if(te){const ie={source:e==="source"?x:te.id,target:e==="source"?te.id:x,sourceHandle:e==="source"?n||null:ce,targetHandle:e==="source"?ce:n||null};(le=(ke=X.onEdgesChangeRef)==null?void 0:ke.current)==null||le.call(ke,[{type:"add",item:{id:`e-${ie.source}-${ie.target}`,...ie}}])}(xe=X.workerRef.current)==null||xe.postMessage({type:"connecting",data:null}),P.removeEventListener("pointermove",d),P.removeEventListener("pointerup",b)};P.addEventListener("pointermove",d),P.addEventListener("pointerup",b)},[x,n,e,t,r,i,j]),F={top:{top:0,left:"50%",transform:"translate(-50%, -50%)"},bottom:{bottom:0,left:"50%",transform:"translate(-50%, 50%)"},left:{top:"50%",left:0,transform:"translate(-50%, -50%)"},right:{top:"50%",right:0,transform:"translate(50%, -50%)"}}[t]||{};return N.jsx("div",{ref:C,className:`ric-handle ric-handle-${t} ric-handle-${e} ${h}`,"data-handleid":n||null,"data-nodeid":x,"data-handlepos":t,"data-handletype":e,onPointerDown:D,style:{position:"absolute",width:8,height:8,borderRadius:"50%",background:"#1a192b",border:"none",zIndex:10,cursor:r?"crosshair":"default",boxSizing:"border-box",...F,...v},...y,children:l})}const sn=a.memo(mo);function vo({data:e,isConnectable:t,selected:n,targetPosition:r="left",sourcePosition:i="right",hideSourceHandle:o=!1,hideTargetHandle:l=!1}){return N.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:[!l&&N.jsx(sn,{type:"target",position:r,isConnectable:t}),N.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!o&&N.jsx(sn,{type:"source",position:i,isConnectable:t})]})}function Pr({data:e,isConnectable:t,selected:n,sourcePosition:r="right",hideSourceHandle:i=!1}){return N.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:[N.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!i&&N.jsx(sn,{type:"source",position:r,isConnectable:t})]})}function Nr({data:e,isConnectable:t,selected:n,targetPosition:r="left",hideTargetHandle:i=!1}){return N.jsxs("div",{className:`ric-output-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderTop:"2px solid #ff0072",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!i&&N.jsx(sn,{type:"target",position:r,isConnectable:t}),N.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label})]})}function Ir({data:e,selected:t,width:n,height:r}){return N.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)&&N.jsx("div",{style:{fontSize:11,fontWeight:600,color:"#888",userSelect:"none"},children:e.label})})}function Tr({x:e,y:t,label:n,labelStyle:r,labelShowBg:i=!0,labelBgStyle:o,labelBgPadding:l=[2,4],labelBgBorderRadius:h=2,children:v,className:f="",...y}){const[x,R]=a.useState({x:1,y:0,width:0,height:0}),C=a.useRef(null);return a.useEffect(()=>{if(C.current){const z=C.current.getBBox();R({x:z.x,y:z.y,width:z.width,height:z.height})}},[n]),n?N.jsxs("g",{transform:`translate(${e-x.width/2} ${t-x.height/2})`,className:`ric-edge-textwrapper ${f}`,visibility:x.width?"visible":"hidden",...y,children:[i&&N.jsx("rect",{width:x.width+2*l[0],x:-l[0],y:-l[1],height:x.height+2*l[1],className:"ric-edge-textbg",style:o,rx:h,ry:h}),N.jsx("text",{className:"ric-edge-text",y:x.height/2,dy:"0.3em",ref:C,style:r,children:n}),v]}):null}Tr.displayName="EdgeText";const Lr=a.memo(Tr);function hr(e){return e!=null&&e!==""&&!isNaN(Number(e))}function cn({id:e,path:t,labelX:n,labelY:r,label:i,labelStyle:o,labelShowBg:l,labelBgStyle:h,labelBgPadding:v,labelBgBorderRadius:f,interactionWidth:y=20,style:x,markerEnd:R,markerStart:C,className:z="",...W}){return N.jsxs(N.Fragment,{children:[N.jsx("path",{id:e,d:t,fill:"none",stroke:"#b1b1b7",strokeWidth:1.5,className:`ric-edge-path ${z}`,style:x,markerEnd:R,markerStart:C,...W}),y?N.jsx("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:y,className:"ric-edge-interaction",style:{pointerEvents:"stroke"}}):null,i&&hr(n)&&hr(r)?N.jsx(Lr,{x:n,y:r,label:i,labelStyle:o,labelShowBg:l,labelBgStyle:h,labelBgPadding:v,labelBgBorderRadius:f}):null]})}const nn=20;function gr(e,t,n){switch(n){case"right":return{x:e+nn,y:t};case"left":return{x:e-nn,y:t};case"bottom":return{x:e,y:t+nn};case"top":return{x:e,y:t-nn};default:return{x:e+nn,y:t}}}const er=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:l="bottom",targetPosition:h="top",label:v,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:R,labelBgBorderRadius:C,style:z,markerEnd:W,markerStart:j,interactionWidth:D}){let F,$,X;const A=gr(n,r,l),P=gr(i,o,h),Z=Math.abs(P.x-A.x),q=Math.max(50,Z*.5);let O,M,d,b;switch(l){case"left":O=A.x-q,M=A.y;break;case"top":O=A.x,M=A.y-q;break;case"bottom":O=A.x,M=A.y+q;break;default:O=A.x+q,M=A.y;break}switch(h){case"right":d=P.x+q,b=P.y;break;case"top":d=P.x,b=P.y-q;break;case"bottom":d=P.x,b=P.y+q;break;default:d=P.x-q,b=P.y;break}F=`M ${n},${r} L ${A.x},${A.y} C ${O},${M} ${d},${b} ${P.x},${P.y} L ${i},${o}`;const L=.5,T=.5;return $=T*T*T*A.x+3*T*T*L*O+3*T*L*L*d+L*L*L*P.x,X=T*T*T*A.y+3*T*T*L*M+3*T*L*L*b+L*L*L*P.y,N.jsx(cn,{id:t,path:F,labelX:$,labelY:X,label:v,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:R,labelBgBorderRadius:C,style:z,markerEnd:W,markerStart:j,interactionWidth:D})});er.displayName="BezierEdge";function tr({sourceX:e,sourceY:t,targetX:n,targetY:r}){const i=`M ${e},${t}L ${n},${r}`,o=(e+n)/2,l=(t+r)/2;return[i,o,l,0,0]}function nr({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i="right",targetPosition:o="left",curvature:l=.25}){const h=Math.abs(n-e),v=Math.abs(r-t),f=Math.sqrt(h*h+v*v),y=Math.max(f*l,50);let x,R,C,z;switch(i){case"top":x=e,R=t-y;break;case"bottom":x=e,R=t+y;break;case"left":x=e-y,R=t;break;default:x=e+y,R=t;break}switch(o){case"top":C=n,z=r-y;break;case"bottom":C=n,z=r+y;break;case"right":C=n+y,z=r;break;default:C=n-y,z=r;break}const W=`M ${e},${t} C ${x},${R} ${C},${z} ${n},${r}`,j=.5,D=1-j,F=D*D*D*e+3*D*D*j*x+3*D*j*j*C+j*j*j*n,$=D*D*D*t+3*D*D*j*R+3*D*j*j*z+j*j*j*r;return[W,F,$,0,0]}function rr({sourceX:e,sourceY:t,targetX:n,targetY:r}){const i=Math.abs(n-e),o=Math.max(i*.5,50),l=e+o,h=n-o,v=`M ${e},${t} C ${l},${t} ${h},${r} ${n},${r}`,f=.5,y=.5,x=y*y*y*e+3*y*y*f*l+3*y*f*f*h+f*f*f*n,R=y*y*y*t+3*y*y*f*t+3*y*f*f*r+f*f*f*r;return[v,x,R,0,0]}function Rn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i="right",targetPosition:o="left",borderRadius:l=5,offset:h=20}){const v=i==="left"||i==="right",f=Math.min(l,Math.abs(n-e)/2,Math.abs(r-t)/2);if(v){if(Math.abs(r-t)<1)return[`M ${e},${t} L ${n},${r}`,(e+n)/2,t,0,0];const C=(e+n)/2,z=r>t?1:-1;return[`M ${e},${t} L ${C-f},${t} Q ${C},${t} ${C},${t+z*f} L ${C},${r-z*f} Q ${C},${r} ${C+(n>C?f:-f)},${r} L ${n},${r}`,C,(t+r)/2,0,0]}const y=(t+r)/2,x=n>e?1:-1;return[`M ${e},${t} L ${e},${y-f} Q ${e},${y} ${e+x*f},${y} L ${n-x*f},${y} Q ${n},${y} ${n},${y+(r>y?f:-f)} L ${n},${r}`,(e+n)/2,y,0,0]}function bo({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[,i,o]=nr({sourceX:e,sourceY:t,targetX:n,targetY:r});return[i,o,0,0]}function wo({sourceX:e,sourceY:t,targetX:n,targetY:r}){return[(e+n)/2,(t+r)/2,0,0]}function Mo(e,t,n){const r=n.filter(o=>o.id!==e.id),i={...e,id:e.id,source:t.source,target:t.target,sourceHandle:t.sourceHandle??e.sourceHandle,targetHandle:t.targetHandle??e.targetHandle};return r.push(i),r}const kn=160,Cn=60,rn=20,wn=12,En=20;function yr(e,t,n){var l,h;const r=e.width||((l=e.measured)==null?void 0:l.width)||kn,i=e.height||((h=e.measured)==null?void 0:h.height)||Cn,o=e._absolutePosition||e.position;if(e.handles&&e.handles.length>0){for(const v of e.handles)if(v.type===t&&(!n||v.id===n)){if(v.x!==void 0&&v.y!==void 0)return{x:o.x+v.x,y:o.y+v.y,dir:v.position||(t==="source"?"right":"left")};switch(v.position||(t==="source"?"right":"left")){case"top":return{x:o.x+r/2,y:o.y,dir:"top"};case"bottom":return{x:o.x+r/2,y:o.y+i,dir:"bottom"};case"left":return{x:o.x,y:o.y+i/2,dir:"left"};default:return{x:o.x+r,y:o.y+i/2,dir:"right"}}}}return t==="source"?{x:o.x+r,y:o.y+i/2,dir:"right"}:{x:o.x,y:o.y+i/2,dir:"left"}}function Sn(e,t){switch(e.dir){case"right":return{x:e.x+t,y:e.y,dir:e.dir};case"left":return{x:e.x-t,y:e.y,dir:e.dir};case"bottom":return{x:e.x,y:e.y+t,dir:e.dir};case"top":return{x:e.x,y:e.y-t,dir:e.dir};default:return{x:e.x+t,y:e.y,dir:e.dir}}}function Ro(e,t,n,r,i,o,l,h){const v=Math.min(e,n),f=Math.max(e,n),y=Math.min(t,r),x=Math.max(t,r);if(f<=i||v>=i+l||x<=o||y>=o+h)return!1;const R=.5;if(e>i+R&&e<i+l-R&&t>o+R&&t<o+h-R||n>i+R&&n<i+l-R&&r>o+R&&r<o+h-R)return!0;const C=(e+n)/2,z=(t+r)/2;if(C>i+R&&C<i+l-R&&z>o+R&&z<o+h-R)return!0;const W=[[i,o],[i+l,o],[i+l,o+h],[i,o+h]];for(let j=0;j<4;j++)if(ko(e,t,n,r,W[j][0],W[j][1],W[(j+1)%4][0],W[(j+1)%4][1]))return!0;return!1}function ko(e,t,n,r,i,o,l,h){const v=(l-i)*(t-o)-(h-o)*(e-i),f=(l-i)*(r-o)-(h-o)*(n-i),y=(n-e)*(o-t)-(r-t)*(i-e),x=(n-e)*(h-t)-(r-t)*(l-e);return(v>0&&f<0||v<0&&f>0)&&(y>0&&x<0||y<0&&x>0)}function Vn(e,t,n,r,i){for(let o=0;o<i.length;o++){const l=i[o];if(Ro(e,t,n,r,l.x,l.y,l.w,l.h))return!1}return!0}function Co(e,t,n){for(let r=0;r<n.length;r++){const i=n[r];if(e>i.x&&e<i.x+i.w&&t>i.y&&t<i.y+i.h)return!0}return!1}function or(e,t){var r,i;const n=[];for(let o=0;o<e.length;o++){const l=e[o];if(l.hidden||t&&t.has(l.id)||l.type==="group")continue;const h=l._absolutePosition||l.position,v=l.width||((r=l.measured)==null?void 0:r.width)||kn,f=l.height||((i=l.measured)==null?void 0:i.height)||Cn;n.push({id:l.id,x:h.x-rn,y:h.y-rn,w:v+2*rn,h:f+2*rn})}return n}function Br(e,t,n){if(Vn(e.x,e.y,t.x,t.y,n))return null;const r=new Set,i=new Set;r.add(e.x),r.add(t.x),i.add(e.y),i.add(t.y);const o=rn+5;e.dir==="right"?r.add(e.x+o):e.dir==="left"?r.add(e.x-o):e.dir==="top"?i.add(e.y-o):e.dir==="bottom"&&i.add(e.y+o),t.dir==="right"?r.add(t.x+o):t.dir==="left"?r.add(t.x-o):t.dir==="top"?i.add(t.y-o):t.dir==="bottom"&&i.add(t.y+o);for(let d=0;d<n.length;d++){const b=n[d];r.add(b.x),r.add(b.x+b.w),i.add(b.y),i.add(b.y+b.h)}const l=[...r].sort((d,b)=>d-b),h=[...i].sort((d,b)=>d-b),v=new Map,f=new Map;for(let d=0;d<l.length;d++)v.set(l[d],d);for(let d=0;d<h.length;d++)f.set(h[d],d);const y=l.length,x=h.length,R=(d,b)=>b*y+d,C=v.get(e.x),z=f.get(e.y),W=v.get(t.x),j=f.get(t.y);if(C===void 0||z===void 0||W===void 0||j===void 0)return null;const D=R(C,z),F=R(W,j),$=new Float64Array(y*x).fill(1/0),X=new Float64Array(y*x).fill(1/0),A=new Int32Array(y*x).fill(-1),P=new Int8Array(y*x).fill(-1),Z=new Uint8Array(y*x);$[D]=0,X[D]=Math.abs(l[W]-e.x)+Math.abs(h[j]-e.y);const q=[D],O=15,M=[[1,0],[-1,0],[0,1],[0,-1]];for(;q.length>0;){let d=0;for(let te=1;te<q.length;te++)X[q[te]]<X[q[d]]&&(d=te);const b=q[d];if(q[d]=q[q.length-1],q.pop(),b===F){const te=[];let ce=F;for(;ce!==-1&&ce!==D;){const me=ce/y|0,Me=ce%y;te.unshift({x:l[Me],y:h[me]}),ce=A[ce]}return te.unshift({x:e.x,y:e.y}),Eo(te,n)}if(Z[b])continue;Z[b]=1;const L=b/y|0,T=b%y,B=l[T],Q=h[L],oe=P[b];for(let te=0;te<4;te++){const ce=T+M[te][0],me=L+M[te][1];if(ce<0||ce>=y||me<0||me>=x)continue;const Me=R(ce,me);if(Z[Me])continue;const ke=l[ce],le=h[me];if(Co(ke,le,n)||!Vn(B,Q,ke,le,n))continue;const xe=Math.abs(ke-B)+Math.abs(le-Q),ie=oe>=0&&oe!==te?O:0,fe=$[b]+xe+ie;fe<$[Me]&&(A[Me]=b,P[Me]=te,$[Me]=fe,X[Me]=fe+Math.abs(l[W]-ke)+Math.abs(h[j]-le),q.push(Me))}}return null}function Eo(e,t){if(!e||e.length<=2)return e;const n=[e[0]];for(let r=1;r<e.length-1;r++){const i=n[n.length-1],o=e[r],l=e[r+1],h=Math.abs(i.x-o.x)<.5&&Math.abs(o.x-l.x)<.5,v=Math.abs(i.y-o.y)<.5&&Math.abs(o.y-l.y)<.5;(h||v)&&Vn(i.x,i.y,l.x,l.y,t)||n.push(o)}return n.push(e[e.length-1]),n}function So(e){const t=new Map,n=new Map;for(const i of e){const o=i._routedPoints;if(!(!o||o.length<2))for(let l=0;l<o.length-1;l++){const h=o[l],v=o[l+1];if(Math.abs(h.y-v.y)<.5){const f=Math.round(h.y*10)/10;t.has(f)||t.set(f,[]),t.get(f).push({edgeId:i.id,segIdx:l,x1:Math.min(h.x,v.x),x2:Math.max(h.x,v.x)})}else if(Math.abs(h.x-v.x)<.5){const f=Math.round(h.x*10)/10;n.has(f)||n.set(f,[]),n.get(f).push({edgeId:i.id,segIdx:l,y1:Math.min(h.y,v.y),y2:Math.max(h.y,v.y)})}}}const r=new Map;for(const i of e)i._routedPoints&&r.set(i.id,i._routedPoints.map(o=>({...o})));for(const[,i]of t){if(i.length<2)continue;const o=xr(i,"x1","x2");for(const l of o){if(l.length<2)continue;const h=(l.length-1)*wn/2;for(let v=0;v<l.length;v++){const f=l[v],y=-h+v*wn,x=r.get(f.edgeId);x&&(x[f.segIdx].y+=y,x[f.segIdx+1].y+=y)}}}for(const[,i]of n){if(i.length<2)continue;const o=xr(i,"y1","y2");for(const l of o){if(l.length<2)continue;const h=(l.length-1)*wn/2;for(let v=0;v<l.length;v++){const f=l[v],y=-h+v*wn,x=r.get(f.edgeId);x&&(x[f.segIdx].x+=y,x[f.segIdx+1].x+=y)}}}return e.map(i=>{const o=r.get(i.id);return o?{...i,_routedPoints:o}:i})}function xr(e,t,n){if(e.length<2)return[];const r=[...e].sort((l,h)=>l[t]-h[t]),i=[];let o=[r[0]];for(let l=1;l<r.length;l++){const h=o[o.length-1];r[l][t]<h[n]?o.push(r[l]):(o.length>1&&i.push(o),o=[r[l]])}return o.length>1&&i.push(o),i}function zn(e,t=6,n=!1){if(!e||e.length<2)return null;if(n)return zo(e);const r=t;let i=`M ${e[0].x},${e[0].y}`;for(let o=1;o<e.length-1;o++){const l=e[o-1],h=e[o],v=e[o+1],f=Math.abs(h.x-l.x)+Math.abs(h.y-l.y),y=Math.abs(v.x-h.x)+Math.abs(v.y-h.y),x=Math.min(r,f/2,y/2);if(x>.5){const R=h.x-l.x,C=h.y-l.y,z=v.x-h.x,W=v.y-h.y,j=Math.sqrt(R*R+C*C)||1,D=Math.sqrt(z*z+W*W)||1;i+=` L ${h.x-R/j*x},${h.y-C/j*x}`,i+=` Q ${h.x},${h.y} ${h.x+z/D*x},${h.y+W/D*x}`}else i+=` L ${h.x},${h.y}`}return i+=` L ${e[e.length-1].x},${e[e.length-1].y}`,i}function zo(e){if(e.length===2)return`M ${e[0].x},${e[0].y} L ${e[1].x},${e[1].y}`;if(e.length===3)return`M ${e[0].x},${e[0].y} Q ${e[1].x},${e[1].y} ${e[2].x},${e[2].y}`;const t=.3;let n=`M ${e[0].x},${e[0].y}`;for(let r=0;r<e.length-1;r++){const i=e[r===0?0:r-1],o=e[r],l=e[r+1],h=e[r+2<e.length?r+2:e.length-1],v=o.x+(l.x-i.x)*t,f=o.y+(l.y-i.y)*t,y=l.x-(h.x-o.x)*t,x=l.y-(h.y-o.y)*t;n+=` C ${v},${f} ${y},${x} ${l.x},${l.y}`}return n}function Pn(e){if(!e||e.length<2)return{x:0,y:0};let t=0;for(let r=1;r<e.length;r++)t+=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);let n=t/2;for(let r=1;r<e.length;r++){const i=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);if(n<=i){const o=i>0?n/i:0;return{x:e[r-1].x+(e[r].x-e[r-1].x)*o,y:e[r-1].y+(e[r].y-e[r-1].y)*o}}n-=i}return{x:e[0].x,y:e[0].y}}function Po(e,t){if(!e||!t||e.length===0||t.length===0)return t;const n={};for(const o of e)n[o.id]=o;const r=or(e,null),i=t.map(o=>{var P,Z,q,O;const l=o.type||"default";if(l==="bezier"||l==="simplebezier"||l==="default")return o;const h=n[o.source],v=n[o.target];if(!h||!v||h.hidden||v.hidden)return o;const f=yr(h,"source",o.sourceHandle),y=yr(v,"target",o.targetHandle),x=Sn(f,En),R=Sn(y,En),C=5,z=r.filter(M=>M.id!==o.source&&M.id!==o.target),W=h._absolutePosition||h.position,j=h.width||((P=h.measured)==null?void 0:P.width)||kn,D=h.height||((Z=h.measured)==null?void 0:Z.height)||Cn;z.push({id:o.source,x:W.x-C,y:W.y-C,w:j+2*C,h:D+2*C});const F=v._absolutePosition||v.position,$=v.width||((q=v.measured)==null?void 0:q.width)||kn,X=v.height||((O=v.measured)==null?void 0:O.height)||Cn;if(z.push({id:o.target,x:F.x-C,y:F.y-C,w:$+2*C,h:X+2*C}),z.length===0)return o;const A=Br(x,R,z);return A&&A.length>=2?(A.unshift({x:f.x,y:f.y}),A.push({x:y.x,y:y.y}),{...o,_routedPoints:A}):o});return So(i)}function No(e,t,n,r,i,o,l,h){const v=or(l,h?new Set(h):null);if(v.length===0)return null;const f={x:e,y:t,dir:i||"right"},y={x:n,y:r,dir:o||"left"},x=Sn(f,En),R=Sn(y,En),C=Br(x,R,v);return C&&C.length>=2?(C.unshift({x:f.x,y:f.y}),C.push({x:y.x,y:y.y}),C):null}const sr=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,label:l,labelStyle:h,labelShowBg:v,labelBgStyle:f,labelBgPadding:y,labelBgBorderRadius:x,style:R,markerEnd:C,markerStart:z,interactionWidth:W,routedPoints:j}){let D,F,$;if(j&&j.length>=2){D=zn(j);const X=Pn(j);F=X.x,$=X.y}else[D,F,$]=tr({sourceX:n,sourceY:r,targetX:i,targetY:o});return N.jsx(cn,{id:t,path:D,labelX:F,labelY:$,label:l,labelStyle:h,labelShowBg:v,labelBgStyle:f,labelBgPadding:y,labelBgBorderRadius:x,style:R,markerEnd:C,markerStart:z,interactionWidth:W})});sr.displayName="StraightEdge";const ir=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:l="bottom",targetPosition:h="top",label:v,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:R,labelBgBorderRadius:C,style:z,markerEnd:W,markerStart:j,pathOptions:D,interactionWidth:F,routedPoints:$}){let X,A,P;if($&&$.length>=2){X=zn($);const Z=Pn($);A=Z.x,P=Z.y}else[X,A,P]=Rn({sourceX:n,sourceY:r,sourcePosition:l,targetX:i,targetY:o,targetPosition:h,borderRadius:D==null?void 0:D.borderRadius,offset:D==null?void 0:D.offset});return N.jsx(cn,{id:t,path:X,labelX:A,labelY:P,label:v,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:R,labelBgBorderRadius:C,style:z,markerEnd:W,markerStart:j,interactionWidth:F})});ir.displayName="SmoothStepEdge";const $r=a.memo(function({id:t,...n}){var i;const r=a.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(i=n.pathOptions)==null?void 0:i.offset]);return N.jsx(ir,{...n,id:t,pathOptions:r})});$r.displayName="StepEdge";const ar=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:l,targetPosition:h,label:v,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:R,labelBgBorderRadius:C,style:z,markerEnd:W,markerStart:j,interactionWidth:D,routedPoints:F}){let $,X,A;if(F&&F.length>=2){$=zn(F);const P=Pn(F);X=P.x,A=P.y}else[$,X,A]=rr({sourceX:n,sourceY:r,targetX:i,targetY:o});return N.jsx(cn,{id:t,path:$,labelX:X,labelY:A,label:v,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:R,labelBgBorderRadius:C,style:z,markerEnd:W,markerStart:j,interactionWidth:D})});ar.displayName="SimpleBezierEdge";const Io={input:Pr,output:Nr,group:Ir},To={bezier:er,straight:sr,simplebezier:ar},Lo=160,Bo=60;function $o(e){let t=!1;for(let n=0;n<e.length;n++){const r=e[n];if(!r.measured||r.measured.width==null||r.measured.height==null){t=!0;break}}return t?e.map(n=>{var r,i;return((r=n.measured)==null?void 0:r.width)!=null&&((i=n.measured)==null?void 0:i.height)!=null?n:{...n,measured:{width:n.width||Lo,height:n.height||Bo}}}):e}function Ao({cards:e,nodes:t=[],edges:n=[],nodeTypes:r,edgeTypes:i,canvasNodeTypes:o,domNodeLimit:l=50,dark:h,gridSize:v,width:f="100%",height:y="420px",className:x="",style:R={},zoomMin:C,zoomMax:z,initialCamera:W,fitView:j,fitViewOptions:D,onNodesChange:F,onEdgesChange:$,onConnect:X,onConnectStart:A,onConnectEnd:P,onNodeClick:Z,onNodeDoubleClick:q,onNodeMouseEnter:O,onNodeMouseMove:M,onNodeMouseLeave:d,onNodeContextMenu:b,onNodeDragStart:L,onNodeDrag:T,onNodeDragStop:B,onEdgeClick:Q,onEdgeDoubleClick:oe,onEdgeMouseEnter:te,onEdgeMouseMove:ce,onEdgeMouseLeave:me,onEdgeContextMenu:Me,onPaneClick:ke,onPaneContextMenu:le,onPaneMouseEnter:xe,onPaneMouseMove:ie,onPaneMouseLeave:fe,onSelectionChange:Ce,onInit:je,onMoveStart:ge,onMove:de,onMoveEnd:Ae,onDelete:_e,onBeforeDelete:We,onError:nt,onDragOver:De,onDrop:$e,onDragEnter:Ie,onDragLeave:Ee,nodesDraggable:Ge,nodesConnectable:rt,elementsSelectable:He,multiSelectionKeyCode:Ue,selectionOnDrag:Ke,selectionMode:zt,connectionMode:ln,connectionRadius:un,connectOnClick:dn,isValidConnection:fn,defaultEdgeOptions:Ot,snapToGrid:ht,snapGrid:gt,deleteKeyCode:Pt,panActivationKeyCode:Nn,panOnScroll:In,panOnScrollMode:ot,panOnScrollSpeed:cr,zoomOnScroll:Tn,zoomOnDoubleClick:Ln,zoomOnPinch:Nt,preventScrolling:It,translateExtent:Bn,nodeExtent:$n,autoPanOnNodeDrag:An,autoPanOnConnect:bt,autoPanSpeed:be,edgesReconnectable:Tt,elevateNodesOnSelect:Se,elevateEdgesOnSelect:ue,noDragClassName:yt,noPanClassName:ee,onSelectionDragStart:ze,onSelectionDrag:hn,onSelectionDragStop:Lt,edgeRouting:Bt=!0,onHudUpdate:$t,onNodesProcessed:jn,showHud:Fe=!0,showHint:Xe=!0,hintText:At="Drag to pan · Scroll to zoom",children:st,...gn}){const[Qe,yn]=a.useState({wx:0,wy:0,zoom:"1.00"}),xn=a.useRef(null),Ut=a.useRef(null),pn=a.useCallback(_=>{yn(_),$t==null||$t(_)},[$t]),xt=a.useMemo(()=>({...Io,...r}),[r]),it=a.useMemo(()=>({...To,...i}),[i]),Je=a.useMemo(()=>$o(t),[t]),[V,at]=a.useState(()=>new Set),wt=a.useRef(V);wt.current=V;const jt=a.useCallback(_=>{at(pe=>{const ne=new Set(pe);return ne.add(_),ne})},[]),Dt=a.useCallback(_=>{at(pe=>{const ne=new Set(pe);return ne.delete(_),ne})},[]),Ht=a.useCallback(_=>{at(pe=>{const ne=new Set(pe);return ne.has(_)?ne.delete(_):ne.add(_),ne})},[]),dt=a.useMemo(()=>Je.filter(_=>_.type&&xt[_.type]),[Je,xt]),_t=a.useMemo(()=>n.filter(_=>_.type&&it[_.type]),[n,it]),[Mt,Wt]=a.useState(()=>new Set),Ft=a.useRef(new Set),Pe=a.useRef(!0),Yt=a.useMemo(()=>{const _=new Set(Mt);for(const ne of V)_.add(ne);if(Pe.current&&Mt.size===0)for(const ne of dt)_.add(ne.id);else Pe.current=!1;for(const ne of dt)(ne.selected||ne.dragging)&&_.add(ne.id);const pe=Ft.current;if(pe.size===_.size){let ne=!0;for(const u of _)if(!pe.has(u)){ne=!1;break}if(ne)return pe}return Ft.current=_,_},[dt,V,Mt]),Te=a.useMemo(()=>{if(l===0)return[];const _=Je.filter(pe=>Yt.has(pe.id));return _.sort((pe,ne)=>{const u=pe.type==="group"||!pe.parentId&&_.some(c=>c.parentId===pe.id),p=ne.type==="group"||!ne.parentId&&_.some(c=>c.parentId===ne.id);return u&&!p?-1:!u&&p?1:0})},[Je,Yt,l]),Dn=a.useMemo(()=>t.map(_=>Yt.has(_.id)?{..._,_customRendered:!0}:_),[t,Yt]),pt=a.useMemo(()=>n.map(_=>_.type&&it[_.type]?{..._,_customRendered:!0}:_),[n,it]),{wrapRef:Rt,canvasRef:ct,canvasReady:mt,onPointerDown:mn,onPointerMove:Le,onPointerUp:et,store:ye}=Mr({cards:e,nodes:Dn,edges:pt,dark:h,gridSize:v,zoomMin:C,zoomMax:z,initialCamera:W,fitView:j,fitViewOptions:D,onHudUpdate:pn,onNodesProcessed:jn,onNodesChange:F,onEdgesChange:$,onConnect:X,onConnectStart:A,onConnectEnd:P,onNodeClick:Z,onNodeDoubleClick:q,onNodeMouseEnter:O,onNodeMouseMove:M,onNodeMouseLeave:d,onNodeContextMenu:b,onNodeDragStart:L,onNodeDrag:T,onNodeDragStop:B,onEdgeClick:Q,onEdgeDoubleClick:oe,onEdgeMouseEnter:te,onEdgeMouseMove:ce,onEdgeMouseLeave:me,onEdgeContextMenu:Me,onPaneClick:ke,onPaneContextMenu:le,onPaneMouseEnter:xe,onPaneMouseMove:ie,onPaneMouseLeave:fe,onSelectionChange:Ce,onInit:je,onMoveStart:ge,onMove:de,onMoveEnd:Ae,onDelete:_e,onBeforeDelete:We,onError:nt,nodesDraggable:Ge,nodesConnectable:rt,elementsSelectable:He,multiSelectionKeyCode:Ue,selectionOnDrag:Ke,selectionMode:zt,connectionMode:ln,connectionRadius:un,connectOnClick:dn,isValidConnection:fn,defaultEdgeOptions:Ot,snapToGrid:ht,snapGrid:gt,deleteKeyCode:Pt,panActivationKeyCode:Nn,panOnScroll:In,panOnScrollMode:ot,panOnScrollSpeed:cr,zoomOnScroll:Tn,zoomOnDoubleClick:Ln,zoomOnPinch:Nt,preventScrolling:It,translateExtent:Bn,nodeExtent:$n,autoPanOnNodeDrag:An,autoPanOnConnect:bt,autoPanSpeed:be,edgesReconnectable:Tt,elevateNodesOnSelect:Se,elevateEdgesOnSelect:ue,noDragClassName:yt,noPanClassName:ee,onSelectionDragStart:ze,onSelectionDrag:hn,onSelectionDragStop:Lt,edgeRouting:Bt}),qt=a.useRef(dt);qt.current=dt;const kt=a.useRef(l);kt.current=l,a.useEffect(()=>{let _;const pe=()=>{const u=qt.current,p=kt.current;if(p===0||!u.length)return;const c=ye.cameraRef.current,g=ye.wrapRef.current;if(!g)return;const k=g.clientWidth,S=g.clientHeight,m=(-c.x+k/2)/c.zoom,E=(-c.y+S/2)/c.zoom,w=wt.current;let H=w.size;for(const Y of u)(Y.selected||Y.dragging)&&H++;const I=Math.max(0,p-H);if(I===0)Wt(Y=>Y.size===0?Y:new Set);else{const Y=new Set(w);for(const K of u)(K.selected||K.dragging)&&Y.add(K.id);const G=[];for(let K=0;K<u.length;K++){const U=u[K];if(Y.has(U.id))continue;const ae=U._absolutePosition||U.position,Re=ae.x+(U.width||160)/2-m,Be=ae.y+(U.height||60)/2-E;G.push({id:U.id,dist:Re*Re+Be*Be})}G.sort((K,U)=>K.dist-U.dist);const re=new Set;for(let K=0;K<Math.min(I,G.length);K++)re.add(G[K].id);Wt(K=>{if(K.size!==re.size)return re;for(const U of re)if(!K.has(U))return re;return K})}},ne=setTimeout(pe,100);return _=setInterval(pe,500),()=>{clearTimeout(ne),clearInterval(_)}},[ye.cameraRef,ye.wrapRef]);const Ve=a.useRef(new Set);a.useEffect(()=>{if(!o||!ye.workerRef.current)return;let _=!1;async function pe(u){const p=new Blob([u],{type:"image/svg+xml"}),c=URL.createObjectURL(p),g=new Image;return g.src=c,await g.decode(),URL.revokeObjectURL(c),createImageBitmap(g)}async function ne(){var k,S,m;const u={},p=[],c={},g={};for(const[E,w]of Object.entries(o)){if(typeof w=="function"){c[E]=w;continue}if(typeof w=="object"&&w!==null&&!(w instanceof ImageBitmap)&&!(w instanceof HTMLImageElement)&&!(w instanceof HTMLCanvasElement)&&("fill"in w||"stroke"in w||"title"in w||"accent"in w)){g[E]=w;continue}try{let H;w instanceof ImageBitmap?H=w:typeof w=="string"?H=await pe(w):w instanceof HTMLImageElement?H=await createImageBitmap(w):w instanceof HTMLCanvasElement&&(H=await createImageBitmap(w)),H&&!_&&(u[E]=H,p.push(H))}catch(H){console.warn(`[InfiniteCanvas] Failed to convert canvasNodeType "${E}":`,H)}}if(!_&&Object.keys(u).length>0&&((k=ye.workerRef.current)==null||k.postMessage({type:"nodeTypeBitmaps",data:{bitmaps:u}},p)),!_&&Object.keys(g).length>0&&((S=ye.workerRef.current)==null||S.postMessage({type:"nodeTypeConfigs",data:{configs:g}})),!_&&Object.keys(c).length>0){const E=new Map,w={},H={},I=[];let Y=Ve.current.size;for(const G of t){const re=c[G.type];if(re)try{const K=re(G.data);if(!K)continue;let U=E.get(K);if(!U&&(U="bmp_"+Y++,E.set(K,U),!Ve.current.has(K))){const ae=await pe(K);if(_)return;w[U]=ae,I.push(ae),Ve.current.add(K)}H[G.id]=U}catch(K){console.warn(`[InfiniteCanvas] canvasNodeType fn error for node "${G.id}":`,K)}}_||(m=ye.workerRef.current)==null||m.postMessage({type:"nodeBitmaps",data:{cache:w,keys:H}},I)}}return ne(),()=>{_=!0}},[o,t,ye.workerRef]);const Ct=a.useContext(St),we=Ct&&typeof Ct.getState=="function";a.useEffect(()=>{we&&queueMicrotask(()=>{Ct.setState({nodes:Je,edges:n,nodesRef:ye.nodesRef,edgesRef:ye.edgesRef,onNodesChangeRef:ye.onNodesChangeRef,onEdgesChangeRef:ye.onEdgesChangeRef,cameraRef:ye.cameraRef,wrapRef:ye.wrapRef,workerRef:ye.workerRef})})},[we,Je,n,ye,Ct]);const vt=a.useMemo(()=>({...ye,edgeLabelContainerRef:xn,viewportPortalRef:Ut,pinNode:jt,unpinNode:Dt,togglePinNode:Ht,get pinnedNodeIds(){return wt.current},get nodes(){return Je},get edges(){return n},get viewport(){return ye.cameraRef.current},get minZoom(){return ye.zoomMin||.1},get maxZoom(){return ye.zoomMax||5},get domNode(){return ye.wrapRef.current},get width(){var _;return((_=ye.wrapRef.current)==null?void 0:_.clientWidth)||0},get height(){var _;return((_=ye.wrapRef.current)==null?void 0:_.clientHeight)||0}}),[ye,Je,n,jt,Dt,Ht]),lt=a.useRef(null),Zt=a.useRef(null),Gt=a.useRef(null),Qt=a.useRef(null),Jt=a.useRef(null);a.useEffect(()=>{let _;const pe=()=>{const ne=ye.cameraRef.current,u=`translate(${ne.x}px, ${ne.y}px) scale(${ne.zoom})`,p=`translate(${ne.x}, ${ne.y}) scale(${ne.zoom})`;lt.current&&(lt.current.style.transform=u),Zt.current&&Zt.current.setAttribute("transform",p),Gt.current&&(Gt.current.style.transform=u),Qt.current&&(Qt.current.style.transform=u);const c=Rt.current;if(c){const g=ne.zoom<.15?"lod-minimal":ne.zoom<.35?"lod-reduced":null;g!==Jt.current&&(c.classList.remove("lod-minimal","lod-reduced"),g&&c.classList.add(g),Jt.current=g)}_=requestAnimationFrame(pe)};return _=requestAnimationFrame(pe),()=>cancelAnimationFrame(_)},[ye]);const[Vt,Hn]=a.useState(null);a.useEffect(()=>{if(!Te.length)return;let _;const pe=()=>{var w,H;const ne=ye.cameraRef.current,u=ye.wrapRef.current;if(!u){_=requestAnimationFrame(pe);return}const p=u.getBoundingClientRect(),c=200,g=-ne.x/ne.zoom-c,k=-ne.y/ne.zoom-c,S=(p.width-ne.x)/ne.zoom+c,m=(p.height-ne.y)/ne.zoom+c,E=new Set;for(const I of Te){const Y=I._absolutePosition||I.position,G=I.width||((w=I.measured)==null?void 0:w.width)||200,re=I.height||((H=I.measured)==null?void 0:H.height)||100;Y.x+G>=g&&Y.x<=S&&Y.y+re>=k&&Y.y<=m&&E.add(I.id)}Hn(I=>{if(!I||I.size!==E.size)return E;for(const Y of E)if(!I.has(Y))return E;return I}),_=requestAnimationFrame(pe)};return _=requestAnimationFrame(pe),()=>cancelAnimationFrame(_)},[Te,ye]);const _n=a.useMemo(()=>Vt?Te.filter(_=>Vt.has(_.id)):Te,[Te,Vt]),Wn=Te.length>0,Fn=_t.length>0;return N.jsx(St.Provider,{value:vt,children:N.jsxs("div",{ref:Rt,className:`ric-wrap ${x}`,style:{width:f,height:y,...R},onPointerDown:mn,onPointerMove:Le,onPointerUp:et,onDragOver:De,onDrop:$e,onDragEnter:Ie,onDragLeave:Ee,tabIndex:0,children:[N.jsx("canvas",{ref:ct,className:"ric-canvas"}),!mt&&N.jsx("div",{className:"ric-loader",children:N.jsx("div",{className:"ric-spinner"})}),Fn&&N.jsx("svg",{className:"ric-edges-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:N.jsx("g",{ref:Zt,children:_t.map(_=>N.jsx(yo,{edge:_,edgeType:it[_.type],nodes:t,reconnectable:Tt},_.id))})}),Wn&&N.jsx("div",{ref:lt,className:"ric-nodes-overlay",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:10},children:_n.map(_=>N.jsx(uo,{node:_,nodeType:xt[_.type]},_.id))}),N.jsx("div",{ref:_=>{xn.current=_,Gt.current=_},className:"ric-edge-labels",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:5}}),N.jsx("div",{ref:_=>{Ut.current=_,Qt.current=_},className:"ric-viewport-portal",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:6}}),Xe&&N.jsx("div",{className:"ric-hint",children:At}),Fe&&N.jsxs("div",{className:"ric-info",children:["world: (",Qe.wx,", ",Qe.wy,") zoom: ",Qe.zoom,"x",Qe.nodeCount>0&&N.jsxs(N.Fragment,{children:[" nodes: ",Qe.nodeCount]}),Qe.edgeCount>0&&N.jsxs(N.Fragment,{children:[" edges: ",Qe.edgeCount]})]}),N.jsx(Sr,{selectionKeyCode:Ue||"Shift",selectionMode:zt||"partial"}),st]})})}function jo({children:e}){const t=a.useRef(null);return t.current||(t.current=ao()),N.jsx(St.Provider,{value:t.current,children:e})}function Ar(e,t){const n=[],r=new Map,i=[];for(const o of e)if(o.type==="add")i.push(o);else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const l=r.get(o.id);l?l.push(o):r.set(o.id,[o])}for(const o of t){const l=r.get(o.id);if(!l){n.push(o);continue}if(l[0].type==="remove")continue;if(l[0].type==="replace"){n.push({...l[0].item});continue}const h={...o};for(const v of l)Do(v,h);n.push(h)}for(const o of i)o.index!==void 0?n.splice(o.index,0,{...o.item}):n.push({...o.item});return n}function 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 jr(e,t){return Ar(e,t)}function Dr(e,t){return Ar(e,t)}function Ho(e,t){return!e.source||!e.target?(console.warn("addEdge: source and target are required"),t):t.some(r=>r.source===e.source&&r.target===e.target&&(r.sourceHandle||null)===(e.sourceHandle||null)&&(r.targetHandle||null)===(e.targetHandle||null))?t:[...t,{id:e.id||`e-${e.source}-${e.target}`,...e}]}function _o(e){const[t,n]=a.useState(e),r=a.useCallback(i=>n(o=>jr(i,o)),[]);return[t,n,r]}function Wo(e){const[t,n]=a.useState(e),r=a.useCallback(i=>n(o=>Dr(i,o)),[]);return[t,n,r]}function Hr(){const e=Rr(),t=a.useCallback(()=>typeof e.getState=="function"?e.getState():e,[e]),n=a.useCallback(()=>[...t().nodesRef.current],[t]),r=a.useCallback(()=>[...t().edgesRef.current],[t]),i=a.useCallback(M=>t().nodesRef.current.find(d=>d.id===M),[t]),o=a.useCallback(M=>t().edgesRef.current.find(d=>d.id===M),[t]),l=a.useCallback(M=>{var d,b,L,T;if(typeof M=="function"){const B=M(t().nodesRef.current);(b=(d=t().onNodesChangeRef).current)==null||b.call(d,[...t().nodesRef.current.map(Q=>({id:Q.id,type:"remove"})),...B.map(Q=>({type:"add",item:Q}))])}else(T=(L=t().onNodesChangeRef).current)==null||T.call(L,[...t().nodesRef.current.map(B=>({id:B.id,type:"remove"})),...M.map(B=>({type:"add",item:B}))])},[t]),h=a.useCallback(M=>{var d,b,L,T;if(typeof M=="function"){const B=M(t().edgesRef.current);(b=(d=t().onEdgesChangeRef).current)==null||b.call(d,[...t().edgesRef.current.map(Q=>({id:Q.id,type:"remove"})),...B.map(Q=>({type:"add",item:Q}))])}else(T=(L=t().onEdgesChangeRef).current)==null||T.call(L,[...t().edgesRef.current.map(B=>({id:B.id,type:"remove"})),...M.map(B=>({type:"add",item:B}))])},[t]),v=a.useCallback(M=>{var b,L;const d=Array.isArray(M)?M:[M];(L=(b=t().onNodesChangeRef).current)==null||L.call(b,d.map(T=>({type:"add",item:T})))},[t]),f=a.useCallback(M=>{var b,L;const d=Array.isArray(M)?M:[M];(L=(b=t().onEdgesChangeRef).current)==null||L.call(b,d.map(T=>({type:"add",item:T})))},[t]),y=a.useCallback(({nodes:M=[],edges:d=[]})=>{if(M.length&&t().onNodesChangeRef.current){t().onNodesChangeRef.current(M.map(L=>({id:L.id,type:"remove"})));const b=br(M,t().edgesRef.current);b.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(b.map(L=>({id:L.id,type:"remove"})))}d.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(d.map(b=>({id:b.id,type:"remove"})))},[t]),x=a.useCallback(()=>{const M=t().cameraRef.current;return{x:M.x,y:M.y,zoom:M.zoom}},[t]),R=a.useRef(null),C=a.useCallback((M,d)=>{if(R.current&&cancelAnimationFrame(R.current),!d||d<=0){t().cameraRef.current={...M},t().sendCamera();return}const b={...t().cameraRef.current},L=performance.now(),T=B=>{const Q=B-L,oe=Math.min(Q/d,1),te=1-Math.pow(1-oe,3);t().cameraRef.current={x:b.x+(M.x-b.x)*te,y:b.y+(M.y-b.y)*te,zoom:b.zoom+(M.zoom-b.zoom)*te},t().sendCamera(),oe<1&&(R.current=requestAnimationFrame(T))};R.current=requestAnimationFrame(T)},[t]),z=a.useCallback((M,d)=>{const b={x:M.x??t().cameraRef.current.x,y:M.y??t().cameraRef.current.y,zoom:M.zoom??t().cameraRef.current.zoom};C(b,d==null?void 0:d.duration)},[t,C]),W=a.useCallback(()=>t().cameraRef.current.zoom,[t]),j=a.useCallback(M=>{const d=t().cameraRef.current,b=t().wrapRef.current;if(!b)return;const L=b.getBoundingClientRect(),T=L.width/2,B=L.height/2,Q=1.2,oe={x:T-(T-d.x)*Q,y:B-(B-d.y)*Q,zoom:Math.min(t().zoomMax,d.zoom*Q)};C(oe,M==null?void 0:M.duration)},[t,C]),D=a.useCallback(M=>{const d=t().cameraRef.current,b=t().wrapRef.current;if(!b)return;const L=b.getBoundingClientRect(),T=L.width/2,B=L.height/2,Q=1/1.2,oe={x:T-(T-d.x)*Q,y:B-(B-d.y)*Q,zoom:Math.max(t().zoomMin,d.zoom*Q)};C(oe,M==null?void 0:M.duration)},[t,C]),F=a.useCallback((M,d)=>{const b=t().cameraRef.current,L=t().wrapRef.current;if(!L)return;const T=L.getBoundingClientRect(),B=T.width/2,Q=T.height/2,oe=Math.min(t().zoomMax,Math.max(t().zoomMin,M)),te=oe/b.zoom,ce={x:B-(B-b.x)*te,y:Q-(Q-b.y)*te,zoom:oe};C(ce,d==null?void 0:d.duration)},[t,C]),$=a.useCallback((M={})=>{const d=t().nodesRef.current;if(!d.length)return;const b=t().wrapRef.current;if(!b)return;const L=b.getBoundingClientRect(),T=M.padding??.1,B=M.nodes?d.filter(te=>M.nodes.some(ce=>ce.id===te.id)):d;if(!B.length)return;const Q=Mn(B),oe=Xt(Q,L.width,L.height,T);M.maxZoom&&(oe.zoom=Math.min(oe.zoom,M.maxZoom)),M.minZoom&&(oe.zoom=Math.max(oe.zoom,M.minZoom)),C(oe,M.duration)},[t,C]),X=a.useCallback((M,d={})=>{const b=t().wrapRef.current;if(!b)return;const L=b.getBoundingClientRect(),T=d.padding??.1,B=Xt(M,L.width,L.height,T);d.maxZoom&&(B.zoom=Math.min(B.zoom,d.maxZoom)),d.minZoom&&(B.zoom=Math.max(B.zoom,d.minZoom)),C(B,d.duration)},[t,C]),A=a.useCallback((M,d,b={})=>{const L=t().wrapRef.current;if(!L)return;const T=L.getBoundingClientRect(),B=b.zoom??t().cameraRef.current.zoom,Q={x:T.width/2-M*B,y:T.height/2-d*B,zoom:B};C(Q,b.duration)},[t,C]),P=a.useCallback(()=>({nodes:[...t().nodesRef.current],edges:[...t().edgesRef.current],viewport:{...t().cameraRef.current}}),[t]),Z=a.useCallback(M=>t().screenToWorld(M.x,M.y),[t]),q=a.useCallback(M=>{const d=t().cameraRef.current,b=t().wrapRef.current;if(!b)return{x:0,y:0};const L=b.getBoundingClientRect();return{x:M.x*d.zoom+d.x+L.left,y:M.y*d.zoom+d.y+L.top}},[t]),O=a.useCallback((M,d)=>{var T,B;const b=t().nodesRef.current.find(Q=>Q.id===M);if(!b)return;const L=typeof d=="function"?d(b.data):{...b.data,...d};(B=(T=t().onNodesChangeRef).current)==null||B.call(T,[{id:M,type:"replace",item:{...b,data:L}}])},[t]);return{getNodes:n,getEdges:r,getNode:i,getEdge:o,setNodes:l,setEdges:h,addNodes:v,addEdges:f,deleteElements:y,getViewport:x,setViewport:z,getZoom:W,zoomIn:j,zoomOut:D,zoomTo:F,fitView:$,fitBounds:X,setCenter:A,screenToFlowPosition:Z,flowToScreenPosition:q,updateNodeData:O,toObject:P}}function Fo(){return Ne().nodes}function Yo(){return Ne().edges}function Xo(){return Ne().viewport}function Oo(){return Ne().connection}function Uo(e){const t=Ne(),n=Array.isArray(e)?e:[e];return a.useMemo(()=>n.map(r=>{const i=t.nodes.find(o=>o.id===r);return i?{id:i.id,type:i.type,data:i.data}:null}).filter(Boolean),[t.nodes,...n])}function qo(e){const t=Ne();return a.useMemo(()=>t.edges.filter(n=>n.source===e||n.target===e),[t.edges,e])}function Zo({nodeId:e,type:t,handleId:n}){const r=Ne();return a.useMemo(()=>r.edges.filter(i=>t==="source"?i.source===e&&(n?i.sourceHandle===n:!0):i.target===e&&(n?i.targetHandle===n:!0)),[r.edges,e,t,n])}function Go({onChange:e,onStart:t,onEnd:n}){const r=Ne(),i=a.useRef(e),o=a.useRef(t),l=a.useRef(n);a.useEffect(()=>{i.current=e},[e]),a.useEffect(()=>{o.current=t},[t]),a.useEffect(()=>{l.current=n},[n]),a.useEffect(()=>{const h=v=>{var f;(f=i.current)==null||f.call(i,{x:v.x,y:v.y,zoom:v.zoom})};return r.viewportListeners.add(h),()=>r.viewportListeners.delete(h)},[s])}function Qo({onChange:e}){const t=Ne(),n=a.useRef(e);a.useEffect(()=>{n.current=e},[e]),a.useEffect(()=>{const r=i=>{var o;(o=n.current)==null||o.call(n,i)};return t.selectionListeners.add(r),()=>t.selectionListeners.delete(r)},[s])}function Jo(e){const[t,n]=a.useState(!1),r=Array.isArray(e)?e:[e];return a.useEffect(()=>{const i=l=>{r.includes(l.key)&&n(!0)},o=l=>{r.includes(l.key)&&n(!1)};return window.addEventListener("keydown",i),window.addEventListener("keyup",o),()=>{window.removeEventListener("keydown",i),window.removeEventListener("keyup",o)}},[r.join(",")]),t}function Vo(){const e=Ne();return a.useCallback(t=>{var n;(n=e.workerRef.current)==null||n.postMessage({type:"nodes",data:{nodes:[...s().nodesRef.current]}})},[s])}const Ko=e=>{var t;return((t=e.nodes)==null?void 0:t.length)>0};function es(e={}){return Ne(Ko)}function ts(e){const t=Ne();return a.useMemo(()=>t.nodes.find(n=>n.id===e)||void 0,[t.nodes,e])}function ns(e,t){return Ne(e,t)}function rs(){return Rr()}function os({maxHistorySize:e=100}={}){const t=Ne(),n=a.useRef([]),r=a.useRef([]),[,i]=a.useState(0),o=a.useRef(null),l=a.useCallback(()=>{const f={nodes:s().nodesRef.current.map(y=>({...y,data:{...y.data}})),edges:s().edgesRef.current.map(y=>({...y}))};o.current&&JSON.stringify(o.current.nodes.map(y=>y.id))===JSON.stringify(f.nodes.map(y=>y.id))&&JSON.stringify(o.current.edges.map(y=>y.id))===JSON.stringify(f.edges.map(y=>y.id))||(n.current.push(f),n.current.length>e&&n.current.shift(),r.current=[],o.current=f,i(y=>y+1))},[t,e]),h=a.useCallback(()=>{var y,x,R,C;const f=n.current.pop();f&&(r.current.push({nodes:s().nodesRef.current.map(z=>({...z,data:{...z.data}})),edges:s().edgesRef.current.map(z=>({...z}))}),(x=(y=s().onNodesChangeRef).current)==null||x.call(y,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...f.nodes.map(z=>({type:"add",item:z}))]),(C=(R=s().onEdgesChangeRef).current)==null||C.call(R,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...f.edges.map(z=>({type:"add",item:z}))]),o.current=f,i(z=>z+1))},[s]),v=a.useCallback(()=>{var y,x,R,C;const f=r.current.pop();f&&(n.current.push({nodes:s().nodesRef.current.map(z=>({...z,data:{...z.data}})),edges:s().edgesRef.current.map(z=>({...z}))}),(x=(y=s().onNodesChangeRef).current)==null||x.call(y,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...f.nodes.map(z=>({type:"add",item:z}))]),(C=(R=s().onEdgesChangeRef).current)==null||C.call(R,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...f.edges.map(z=>({type:"add",item:z}))]),o.current=f,i(z=>z+1))},[s]);return{undo:h,redo:v,takeSnapshot:l,canUndo:n.current.length>0,canRedo:r.current.length>0}}function ss(e){const t=a.useRef(e);return a.useEffect(()=>{t.current=e},[e]),a.useCallback(n=>r=>{const i=t.current(r);i!==!1&&i!=null&&n(Array.isArray(i)?i:r)},[])}function is(e){const t=a.useRef(e);return a.useEffect(()=>{t.current=e},[e]),a.useCallback(n=>r=>{const i=t.current(r);i!==!1&&i!=null&&n(Array.isArray(i)?i:r)},[])}const Un=160,qn=60;function as({width:e=200,height:t=150,nodeColor:n="#3b82f6",nodeStrokeColor:r="#fff",maskColor:i="rgba(0,0,0,0.1)",style:o={},className:l=""}){const h=Ne(),v=a.useRef(null),f=a.useRef(null),y=a.useCallback(()=>{const x=v.current;if(!x)return;const R=x.getContext("2d"),C=window.devicePixelRatio||1;x.width=e*C,x.height=t*C,R.scale(C,C),R.clearRect(0,0,e,t);const z=h.nodesRef.current;if(!z.length)return;let W=1/0,j=1/0,D=-1/0,F=-1/0;for(const d of z){const b=d.width||Un,L=d.height||qn;d.position.x<W&&(W=d.position.x),d.position.y<j&&(j=d.position.y),d.position.x+b>D&&(D=d.position.x+b),d.position.y+L>F&&(F=d.position.y+L)}const $=40;W-=$,j-=$,D+=$,F+=$;const X=D-W,A=F-j,P=Math.min(e/X,t/A),Z=(e-X*P)/2,q=(t-A*P)/2;for(const d of z){if(d.hidden)continue;const b=d.width||Un,L=d.height||qn,T=(d.position.x-W)*P+Z,B=(d.position.y-j)*P+q,Q=b*P,oe=L*P;R.fillStyle=d.selected?"#f59e0b":typeof n=="function"?n(d):n,R.fillRect(T,B,Math.max(Q,2),Math.max(oe,2))}const O=h.cameraRef.current,M=h.wrapRef.current;if(M){const d=M.getBoundingClientRect(),b=-O.x/O.zoom,L=-O.y/O.zoom,T=d.width/O.zoom,B=d.height/O.zoom;R.fillStyle=i,R.fillRect(0,0,e,t);const Q=(b-W)*P+Z,oe=(L-j)*P+q,te=T*P,ce=B*P;R.clearRect(Q,oe,te,ce);for(const me of z){if(me.hidden)continue;const Me=me.width||Un,ke=me.height||qn,le=(me.position.x-W)*P+Z,xe=(me.position.y-j)*P+q;R.fillStyle=me.selected?"#f59e0b":typeof n=="function"?n(me):n,R.fillRect(le,xe,Math.max(Me*P,2),Math.max(ke*P,2))}R.strokeStyle="#3b82f6",R.lineWidth=1.5,R.strokeRect(Q,oe,te,ce)}},[h,e,t,n,r,i]);return a.useEffect(()=>{let x=!0;function R(){x&&(y(),f.current=requestAnimationFrame(R))}const C=setInterval(()=>{cancelAnimationFrame(f.current),f.current=requestAnimationFrame(R)},66);return y(),()=>{x=!1,clearInterval(C),cancelAnimationFrame(f.current)}},[y]),N.jsx("canvas",{ref:v,className:`ric-minimap ${l}`,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 N.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:[N.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),N.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function ls(){return N.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:N.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function us(){return N.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:N.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}function ds(){return N.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:[N.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),N.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function fs(){return N.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:[N.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),N.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})}function on({children:e,className:t="",...n}){return N.jsx("button",{className:`ric-controls-button ${t}`,style:gs,...n,children:e})}function hs({showZoom:e=!0,showFitView:t=!0,showInteractive:n=!1,fitViewOptions:r,onZoomIn:i,onZoomOut:o,onFitView:l,onInteractiveChange:h,position:v="bottom-left",orientation:f="vertical",style:y={},className:x="","aria-label":R="Canvas controls",children:C}){const z=Ne(),{zoomIn:W,zoomOut:j,fitView:D,getZoom:F}=Hr(),[$,X]=a.useState(!0),A=F()<=z.zoomMin,P=F()>=z.zoomMax,Z=a.useCallback(()=>{W(),i==null||i()},[W,i]),q=a.useCallback(()=>{j(),o==null||o()},[j,o]),O=a.useCallback(()=>{D(r||{padding:.1}),l==null||l()},[D,r,l]),M=a.useCallback(()=>{const b=!$;X(b),h==null||h(b)},[$,h]),d={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:30,left:10},"bottom-right":{bottom:30,right:10},"bottom-center":{bottom:30,left:"50%",transform:"translateX(-50%)"}}[v]||{bottom:30,left:10};return N.jsxs("div",{className:`ric-controls ${x}`,style:{position:"absolute",display:"flex",flexDirection:f==="horizontal"?"row":"column",gap:2,zIndex:5,...d,...y},role:"toolbar","aria-label":R,children:[e&&N.jsxs(N.Fragment,{children:[N.jsx(on,{onClick:Z,disabled:P,title:"Zoom in","aria-label":"Zoom in",className:"ric-controls-zoomin",children:N.jsx(cs,{})}),N.jsx(on,{onClick:q,disabled:A,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:N.jsx(ls,{})})]}),t&&N.jsx(on,{onClick:O,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:N.jsx(us,{})}),n&&N.jsx(on,{onClick:M,title:$?"Lock interactivity":"Unlock interactivity","aria-label":$?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:$?N.jsx(fs,{}):N.jsx(ds,{})}),C]})}const gs={width:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid rgba(0,0,0,0.12)",borderRadius:4,background:"#fff",cursor:"pointer",fontSize:16,lineHeight:1,color:"#333",padding:0},ys=a.memo(hs);function xs({variant:e="lines",gap:t=40,size:n=1,color:r,style:i={},className:o=""}){const l=Ne();return l.workerRef.current&&l.workerRef.current.postMessage({type:"background",data:{variant:e,gap:t,size:n,color:r}}),null}function ps({position:e="top-left",style:t={},className:n="",children:r}){const i={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:10,left:10},"bottom-right":{bottom:10,right:10},"bottom-center":{bottom:10,left:"50%",transform:"translateX(-50%)"}}[e]||{top:10,left:10};return N.jsx("div",{className:`ric-panel ${n}`,style:{position:"absolute",zIndex:5,pointerEvents:"all",...i,...t},onPointerDown:o=>o.stopPropagation(),children:r})}function ms({minWidth:e=10,minHeight:t=10,maxWidth:n=1/0,maxHeight:r=1/0,isVisible:i=!0,handleStyle:o={},lineStyle:l={},color:h="#3b82f6",onResizeStart:v,onResize:f,onResizeEnd:y}){const x=a.useContext(an),R=Ne(),C=a.useRef(null),z=a.useCallback((D,F)=>{D.stopPropagation(),D.preventDefault();const $=R.nodesRef.current.find(P=>P.id===x);if(!$)return;C.current={direction:F,startX:D.clientX,startY:D.clientY,width:$.width||160,height:$.height||60},v==null||v(D,{width:C.current.width,height:C.current.height});const X=P=>{var L,T;if(!C.current)return;const Z=C.current,q=R.cameraRef.current,O=(P.clientX-Z.startX)/q.zoom,M=(P.clientY-Z.startY)/q.zoom;let d=Z.width,b=Z.height;Z.direction.includes("e")&&(d=Math.min(n,Math.max(e,Z.width+O))),Z.direction.includes("w")&&(d=Math.min(n,Math.max(e,Z.width-O))),Z.direction.includes("s")&&(b=Math.min(r,Math.max(t,Z.height+M))),Z.direction.includes("n")&&(b=Math.min(r,Math.max(t,Z.height-M))),(T=(L=R.onNodesChangeRef).current)==null||T.call(L,[{id:x,type:"dimensions",dimensions:{width:d,height:b},setAttributes:!0}]),f==null||f(P,{width:d,height:b})},A=P=>{C.current=null,y==null||y(P,{}),window.removeEventListener("pointermove",X),window.removeEventListener("pointerup",A)};window.addEventListener("pointermove",X),window.addEventListener("pointerup",A)},[x,R,e,t,n,r,v,f,y]);if(!i)return null;const W=8,j={position:"absolute",width:W,height:W,background:h,border:"1px solid #fff",borderRadius:2,zIndex:20,...o};return N.jsxs(N.Fragment,{children:[N.jsx("div",{style:{...j,bottom:-W/2,right:-W/2,cursor:"nwse-resize"},onPointerDown:D=>z(D,"se")}),N.jsx("div",{style:{...j,bottom:-W/2,left:-W/2,cursor:"nesw-resize"},onPointerDown:D=>z(D,"sw")}),N.jsx("div",{style:{...j,top:-W/2,right:-W/2,cursor:"nesw-resize"},onPointerDown:D=>z(D,"ne")}),N.jsx("div",{style:{...j,top:-W/2,left:-W/2,cursor:"nwse-resize"},onPointerDown:D=>z(D,"nw")}),N.jsx("div",{style:{...j,top:"50%",right:-W/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:D=>z(D,"e")}),N.jsx("div",{style:{...j,top:"50%",left:-W/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:D=>z(D,"w")}),N.jsx("div",{style:{...j,left:"50%",top:-W/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:D=>z(D,"n")}),N.jsx("div",{style:{...j,left:"50%",bottom:-W/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:D=>z(D,"s")})]})}function vs({isVisible:e,position:t="top",offset:n=10,align:r="center",children:i,style:o={},className:l=""}){const h=a.useContext(an),f=Ne().nodes.find(R=>R.id===h);if(!(e!==void 0?e:f==null?void 0:f.selected))return null;const x={top:{bottom:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginBottom:n},bottom:{top:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginTop:n},left:{right:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginRight:n},right:{left:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginLeft:n}}[t]||{};return N.jsx("div",{className:`ric-node-toolbar ${l}`,style:{position:"absolute",zIndex:1e3,pointerEvents:"all",...x,...o},onPointerDown:R=>R.stopPropagation(),children:i})}function bs({isVisible:e=!1,x:t=0,y:n=0,alignX:r="center",alignY:i="center",children:o,style:l={},className:h=""}){if(!e)return null;const v=r==="center"?"-50%":r==="right"?"-100%":"0",f=i==="center"?"-50%":i==="bottom"?"-100%":"0";return N.jsx("div",{className:`ric-edge-toolbar ${h}`,style:{position:"absolute",left:t,top:n,transform:`translate(${v}, ${f})`,zIndex:1e3,pointerEvents:"all",...l},children:o})}function ws({children:e}){var r;const n=(r=Ne().edgeLabelContainerRef)==null?void 0:r.current;return n?pr.createPortal(e,n):null}function Ms({children:e}){var r;const n=(r=Ne().viewportPortalRef)==null?void 0:r.current;return n?pr.createPortal(e,n):null}function _r({fromX:e,fromY:t,toX:n,toY:r,fromPosition:i="right",toPosition:o="left",connectionLineType:l="default",connectionLineStyle:h,connectionLineComponent:v}){if(v)return N.jsx(v,{fromX:e,fromY:t,toX:n,toY:r,fromPosition:i,toPosition:o});let f;switch(l){case"straight":[f]=tr({sourceX:e,sourceY:t,targetX:n,targetY:r});break;case"step":[f]=Rn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o,borderRadius:0});break;case"smoothstep":[f]=Rn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o});break;case"simplebezier":[f]=rr({sourceX:e,sourceY:t,targetX:n,targetY:r});break;default:[f]=nr({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o});break}return N.jsx("path",{d:f,fill:"none",className:"ric-connection-line",stroke:"#b1b1b7",strokeWidth:1.5,style:h})}_r.displayName="ConnectionLine";const Rs=a.memo(_r),ks=Object.freeze({Top:"top",Bottom:"bottom",Left:"left",Right:"right"}),Cs=Object.freeze({Arrow:"arrow",ArrowClosed:"arrowclosed"});function Es(e){const t=e.width||e.measured&&e.measured.width||0,n=e.height||e.measured&&e.measured.height||0,r=e._absolutePosition||e.position||{x:0,y:0};return{x:r.x,y:r.y,x2:r.x+t,y2:r.y+n}}exports.Background=xs;exports.BaseEdge=cn;exports.BezierEdge=er;exports.ConnectionLine=Rs;exports.ControlButton=on;exports.Controls=ys;exports.DefaultNode=vo;exports.EdgeLabelRenderer=ws;exports.EdgeText=Lr;exports.EdgeToolbar=bs;exports.GroupNode=Ir;exports.Handle=sn;exports.InfiniteCanvas=Ao;exports.InfiniteCanvasProvider=jo;exports.InputNode=Pr;exports.MarkerType=Cs;exports.MiniMap=as;exports.NodeResizer=ms;exports.NodeToolbar=vs;exports.OutputNode=Nr;exports.Panel=ps;exports.Position=ks;exports.SelectionBox=Sr;exports.SimpleBezierEdge=ar;exports.SmoothStepEdge=ir;exports.StepEdge=$r;exports.StraightEdge=sr;exports.ViewportPortal=Ms;exports.addEdge=Ho;exports.applyEdgeChanges=Dr;exports.applyNodeChanges=jr;exports.boxToRect=Qr;exports.buildObstacles=or;exports.clampPosition=Gn;exports.computeRoutedEdges=Po;exports.getBezierEdgeCenter=bo;exports.getBezierPath=nr;exports.getBoundsOfBoxes=Jr;exports.getConnectedEdges=br;exports.getEdgeCenter=wo;exports.getIncomers=Ur;exports.getNodeDimensions=Kn;exports.getNodesBounds=Mn;exports.getNodesInside=Zr;exports.getOutgoers=qr;exports.getOverlappingArea=Vr;exports.getRoutedLabelPosition=Pn;exports.getSimpleBezierPath=rr;exports.getSmoothStepPath=Rn;exports.getStraightPath=tr;exports.getViewportForBounds=Xt;exports.isEdge=Or;exports.isNode=Xr;exports.nodeToBox=Es;exports.nodeToRect=Kr;exports.reconnectEdge=Mo;exports.rectToBox=Gr;exports.routeSinglePath=No;exports.routedPointsToPath=zn;exports.snapPosition=Zn;exports.useConnection=Oo;exports.useEdges=Yo;exports.useEdgesState=Wo;exports.useHandleConnections=Zo;exports.useInfiniteCanvas=Mr;exports.useInternalNode=ts;exports.useKeyPress=Jo;exports.useNodeConnections=qo;exports.useNodeId=co;exports.useNodes=Fo;exports.useNodesData=Uo;exports.useNodesInitialized=es;exports.useNodesState=_o;exports.useOnEdgesChangeMiddleware=is;exports.useOnNodesChangeMiddleware=ss;exports.useOnSelectionChange=Qo;exports.useOnViewportChange=Go;exports.useReactFlow=Hr;exports.useStore=ns;exports.useStoreApi=rs;exports.useUndoRedo=os;exports.useUpdateNodeInternals=Vo;exports.useViewport=Xo;
|