@infinit-canvas/react 0.1.5 → 0.1.6

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