@infinit-canvas/react 0.1.1 → 0.1.3

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 C=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:x}=Mn(d),b=d.position.x,N=d.position.y,k=b+u,R=N+x;return r?b<i&&k>s&&N<l&&R>o:b>=s&&k<=i&&N>=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 z=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,C=v+u,R=P+g;return r?v<i&&C>s&&P<l&&R>o:v>=s&&C<=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;
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,Hr=10;function On({cards:t=[],nodes:e=[],edges:n=[],onHudUpdate:r,onNodesProcessed:s,onNodesChange:o,onEdgesChange:i,onConnect:l,onNodeClick:d,onNodeDragStart:u,onNodeDrag:x,onNodeDragStop:b,onEdgeClick:N,onEdgeDoubleClick:k,onEdgeMouseEnter:R,onEdgeMouseMove:B,onEdgeMouseLeave:E,onEdgeContextMenu:z,onNodeDoubleClick:W,onNodeMouseEnter:D,onNodeMouseMove:m,onNodeMouseLeave:h,onNodeContextMenu:p,onPaneClick:g,onPaneContextMenu:I,onPaneMouseEnter:P,onPaneMouseMove:$,onPaneMouseLeave:M,onSelectionChange:S,onConnectStart:X,onConnectEnd:H,onInit:lt,onMoveStart:ft,onMove:ut,onMoveEnd:G,onDelete:q,onBeforeDelete:nt,onError:it,isValidConnection:at,dark:ct,gridSize:Ct=40,zoomMin:tt=.1,zoomMax:rt=4,initialCamera:Et={x:0,y:0,zoom:1},fitView:wt=!1,fitViewOptions:pt,nodesDraggable:zt=!0,nodesConnectable:Mt=!0,elementsSelectable:Nt=!0,multiSelectionKeyCode:xt="Shift",selectionOnDrag:Qt=!1,selectionMode:Re="partial",connectionMode:St="loose",connectionRadius:Xt=20,connectOnClick:At=!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 yt=a.useRef(null),Ee=a.useRef(null),Rt=a.useRef(null),ht=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:x,onNodeDragStop:b,onEdgeClick:N,onEdgeDoubleClick:k,onEdgeMouseEnter:R,onEdgeMouseMove:B,onEdgeMouseLeave:E,onEdgeContextMenu:z,onNodeDoubleClick:W,onNodeMouseEnter:D,onNodeMouseMove:m,onNodeMouseLeave:h,onNodeContextMenu:p,onPaneClick:g,onPaneContextMenu:I,onPaneMouseEnter:P,onPaneMouseMove:$,onPaneMouseLeave:M,onSelectionChange:S,onConnectStart:X,onConnectEnd:H,onInit:lt,onMoveStart:ft,onMove:ut,onMoveEnd:G,onDelete:q,onBeforeDelete:nt,onError:it,isValidConnection:at};const mt={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===xt&&(_t.current=!0),f.key===ye&&(me.current=!0)},v=f=>{f.key===xt&&(_t.current=!1),f.key===ye&&(me.current=!1)};return window.addEventListener("keydown",c),window.addEventListener("keyup",v),()=>{window.removeEventListener("keydown",c),window.removeEventListener("keyup",v)}},[xt,ye]);const qt=a.useCallback(()=>{var w;const c=O.current.filter(L=>L.selected),v=Pt.current.filter(L=>L.selected),f={nodes:c,edges:v};(w=ce.current)==null||w.call(ce,f);for(const L of ae)L(f)},[ae]);a.useEffect(()=>{var c;Jt.current=[...t],(c=Rt.current)==null||c.postMessage({type:"cards",data:{cards:[...t]}})},[t]);const ve=a.useCallback(c=>{const v={};for(const f of c)v[f.id]=f;return c.map(f=>{if(!f.parentId)return f;const w=v[f.parentId];if(!w)return f;let L=f.position.x,T=f.position.y,y=w;for(;y;)L+=y.position.x,T+=y.position.y,y=y.parentId?v[y.parentId]:null;return{...f,_absolutePosition:{x:L,y:T}}})},[]),Zt=a.useRef([]),Q=a.useCallback(c=>{const v=dn.current;if(!v||v.size===0)return c;const f={};for(const[,w]of v)f[w.nodeId]||(f[w.nodeId]=[]),f[w.nodeId].push({id:w.id,type:w.type,position:w.position,x:w.x,y:w.y});return c.map(w=>{const L=f[w.id];return L&&L.length>0?{...w,handles:L}:w})},[]),Ht=a.useCallback(()=>{var v;if(Bt.current)return;const c=Q(Zt.current);(v=Rt.current)==null||v.postMessage({type:"nodes",data:{nodes:c}})},[Q]);a.useEffect(()=>{var f;if(Bt.current){const w=Bt.current.id,L=new Set([w,...Bt.current.selectedStarts.map(y=>y.id)]),T={};for(const y of O.current)L.has(y.id)&&(T[y.id]={...y.position});O.current=[...e];for(const y of O.current)T[y.id]&&(y.position=T[y.id]);Zt.current=ve(O.current);return}O.current=[...e];const c=ve(e);Zt.current=c;const v=Q(c);(f=Rt.current)==null||f.postMessage({type:"nodes",data:{nodes:v}})},[e,ve,Q]),a.useEffect(()=>{var c;Pt.current=[...n],(c=Rt.current)==null||c.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const ot=a.useCallback((c,v)=>{const f=yt.current;if(!f)return{x:0,y:0};const w=f.getBoundingClientRect(),L=ht.current;return{x:(c-w.left-L.x)/L.zoom,y:(v-w.top-L.y)/L.zoom}},[]),It=a.useCallback((c,v)=>{const f=Zt.current.length>0?Zt.current:O.current;let w=null;for(let L=f.length-1;L>=0;L--){const T=f[L];if(T.hidden)continue;const y=T._absolutePosition||T.position,A=T.width||Gt,j=T.height||Ft;if(c>=y.x&&c<=y.x+A&&v>=y.y&&v<=y.y+j){if(T.type==="group"){w||(w=T);continue}return T}}return w},[]),de=a.useCallback((c,v)=>{const f=v.width||Gt,w=v.height||Ft;if(c.x!==void 0&&c.y!==void 0)return{x:v.position.x+c.x,y:v.position.y+c.y};switch(c.position||(c.type==="source"?"right":"left")){case"top":return{x:v.position.x+f/2,y:v.position.y};case"bottom":return{x:v.position.x+f/2,y:v.position.y+w};case"left":return{x:v.position.x,y:v.position.y+w/2};case"right":return{x:v.position.x+f,y:v.position.y+w/2};default:return{x:v.position.x+f,y:v.position.y+w/2}}},[]),be=a.useCallback(c=>{const v=c.width||Gt,f=c.height||Ft;return c.handles&&c.handles.length>0?c.handles.map(w=>{const L=de(w,c);return{id:w.id||null,type:w.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+v,y:c.position.y+f/2}]},[de]),Ze=a.useCallback((c,v)=>{const f=O.current,w=ht.current,L=Math.max(Hr,Xt)/w.zoom;for(let T=f.length-1;T>=0;T--){const y=f[T];if(y.hidden)continue;const A=be(y);for(const j of A)if(Math.abs(c-j.x)<L&&Math.abs(v-j.y)<L)return{nodeId:y.id,handleId:j.id,type:j.type,x:j.x,y:j.y}}return null},[be]),oe=a.useCallback((c,v)=>{const w=8/ht.current.zoom;for(let L=Pt.current.length-1;L>=0;L--){const T=Pt.current[L],y=O.current.find(vt=>vt.id===T.source),A=O.current.find(vt=>vt.id===T.target);if(!y||!A)continue;const j=y.width||Gt,Y=y.height||Ft,_=A.height||Ft,K=y.position.x+j,st=y.position.y+Y/2,U=A.position.x,et=A.position.y+_/2;if(Ar(c,v,K,st,U,et)<w)return T}return null},[]);a.useEffect(()=>{const c=Ee.current,v=yt.current;if(!c||!v)return;const f=v.getBoundingClientRect(),w=ct!==void 0?ct:matchMedia("(prefers-color-scheme: dark)").matches,L=ve(O.current);Zt.current=L;const T=Q(L),{worker:y}=Dr(c,{width:f.width,height:f.height,camera:ht.current,cards:Jt.current,nodes:T,edges:Pt.current,dark:w,gridSize:Ct,edgeRouting:ie});y.onmessage=_=>{var K,st;_.data.type==="hud"&&((K=le.current)==null||K.call(le,_.data.data)),_.data.type==="ready"&&hn(!0),_.data.type==="nodesProcessed"&&((st=ue.current)==null||st.call(ue,_.data.data))},Rt.current=y;const A=new ResizeObserver(_=>{const{width:K,height:st}=_[0].contentRect;y.postMessage({type:"resize",data:{width:K,height:st}})});A.observe(v);let j,Y;return ct===void 0&&(j=matchMedia("(prefers-color-scheme: dark)"),Y=_=>y.postMessage({type:"theme",data:{dark:_.matches}}),j.addEventListener("change",Y)),()=>{A.disconnect(),j&&Y&&j.removeEventListener("change",Y),Rt.current=null}},[]),a.useEffect(()=>{var c;ct!==void 0&&((c=Rt.current)==null||c.postMessage({type:"theme",data:{dark:ct}}))},[ct]),a.useEffect(()=>{var c;(c=Rt.current)==null||c.postMessage({type:"edgeRouting",data:{enabled:ie}})},[ie]);const Ln=a.useRef(0),kt=a.useCallback((c=null)=>{var w,L,T;const v=ht.current;if(Kt){const y=yt.current;if(y){const A=y.getBoundingClientRect(),j=-Kt[1][0]*v.zoom+A.width,Y=-Kt[1][1]*v.zoom+A.height,_=-Kt[0][0]*v.zoom,K=-Kt[0][1]*v.zoom;v.x=Math.min(_,Math.max(j,v.x)),v.y=Math.min(K,Math.max(Y,v.y))}}(w=Rt.current)==null||w.postMessage({type:"camera",data:{camera:{...v}}});const f={x:v.x,y:v.y,zoom:v.zoom};(T=(L=Z.current).onMove)==null||T.call(L,c,f);for(const y of Ut)y(f);cancelAnimationFrame(Ln.current),Ln.current=requestAnimationFrame(()=>{Ge({x:v.x,y:v.y,zoom:v.zoom})})},[Ut,Kt]),we=a.useCallback(()=>{var f,w;const c=jt.current,v=xe.current;c&&v?((f=Rt.current)==null||f.postMessage({type:"connecting",data:{from:c.startPos,to:v,_routedPoints:null}}),ee({source:c.sourceId,sourceHandle:c.sourceHandle,target:null,targetHandle:null})):((w=Rt.current)==null||w.postMessage({type:"connecting",data:null}),ee(null))},[]),Me=a.useCallback(()=>{var v,f;const c=te.current;c?(v=Rt.current)==null||v.postMessage({type:"selectionBox",data:c}):(f=Rt.current)==null||f.postMessage({type:"selectionBox",data:null})},[]),hr=a.useCallback(c=>{var L,T,y,A,j,Y,_,K,st,U,et,gt,vt,Tt,Dt,$t;const v=O.current.length>0,f=ot(c.clientX,c.clientY),w=_t.current;if(v&&Mt){const F=Ze(f.x,f.y);if(At&&pe.current&&F){const V=pe.current;if(F.nodeId!==V.nodeId){const Wt=V.handleType==="target"?{source:F.nodeId,target:V.nodeId,sourceHandle:F.handleId||null,targetHandle:V.handleId}:{source:V.nodeId,target:F.nodeId,sourceHandle:V.handleId,targetHandle:F.handleId||null};(Z.current.isValidConnection?Z.current.isValidConnection(Wt):!0)&&((L=ne.current)==null||L.call(ne,{...Wt,...ge}))}pe.current=null;return}if(St==="strict"?F&&F.type==="source":F!=null){if(At){pe.current={nodeId:F.nodeId,handleId:F.handleId||null,handleType:F.type},(y=(T=Z.current).onConnectStart)==null||y.call(T,c,{nodeId:F.nodeId,handleId:F.handleId,handleType:F.type});return}jt.current={sourceId:F.nodeId,sourceHandle:F.handleId||null,sourceType:F.type,startPos:{x:F.x,y:F.y}},xe.current={x:f.x,y:f.y},(A=yt.current)==null||A.setPointerCapture(c.pointerId),(Y=(j=Z.current).onConnectStart)==null||Y.call(j,c,{nodeId:F.nodeId,handleId:F.handleId,handleType:F.type}),we();return}}if(v){const F=It(f.x,f.y);if(F){if(mt.current&&Nt){const bt=[];if(w)bt.push({id:F.id,type:"select",selected:!F.selected});else if(!F.selected){for(const V of O.current)V.id===F.id?bt.push({id:V.id,type:"select",selected:!0}):V.selected&&bt.push({id:V.id,type:"select",selected:!1});if(Lt.current){const V=Pt.current.filter(J=>J.selected).map(J=>({id:J.id,type:"select",selected:!1}));V.length&&Lt.current(V)}}if(bt.length){if(mt.current(bt),un&&!w){const V=O.current.findIndex(J=>J.id===F.id);V>=0&&V<O.current.length-1&&mt.current([{id:F.id,type:"remove"},{type:"add",item:{...O.current[V],selected:!0}}])}qt()}}if((_=Pe.current)==null||_.call(Pe,c,F),zt){const bt=w&&F.selected;let V=null;if(F.parentId&&F.extent==="parent"){const J=O.current.find(Wt=>Wt.id===F.parentId);if(J){const Wt=J.width||Gt,$e=J.height||Ft,Qe=F.width||((K=F.measured)==null?void 0:K.width)||Gt,Be=F.height||((st=F.measured)==null?void 0:st.height)||Ft;V={minX:0,minY:0,maxX:Wt-Qe,maxY:$e-Be}}}if(Bt.current={id:F.id,startPos:{...F.position},startMouse:{x:f.x,y:f.y},parentClamp:V,parentId:F.parentId||null,selectedStarts:bt?O.current.filter(J=>J.selected&&J.id!==F.id).map(J=>{var $e,Qe;let Wt=null;if(J.parentId&&J.extent==="parent"){const Be=O.current.find(yn=>yn.id===J.parentId);if(Be){const yn=Be.width||Gt,Rr=Be.height||Ft,kr=J.width||(($e=J.measured)==null?void 0:$e.width)||Gt,Cr=J.height||((Qe=J.measured)==null?void 0:Qe.height)||Ft;Wt={minX:0,minY:0,maxX:yn-kr,maxY:Rr-Cr}}}return{id:J.id,startPos:{...J.position},parentClamp:Wt,parentId:J.parentId||null}}):[]},(U=yt.current)==null||U.setPointerCapture(c.pointerId),(et=Ie.current)==null||et.call(Ie,c,F),mt.current){const J=[{id:F.id,type:"position",dragging:!0}];for(const Wt of Bt.current.selectedStarts)J.push({id:Wt.id,type:"position",dragging:!0});mt.current(J)}}return}}if(Pt.current.length>0&&Nt){const F=oe(f.x,f.y);if(F){if(Lt.current){const bt=[];if(w)bt.push({id:F.id,type:"select",selected:!F.selected});else{for(const V of Pt.current)V.id===F.id?bt.push({id:V.id,type:"select",selected:!0}):V.selected&&bt.push({id:V.id,type:"select",selected:!1});if(mt.current){const V=O.current.filter(J=>J.selected).map(J=>({id:J.id,type:"select",selected:!1}));V.length&&mt.current(V)}}bt.length&&(Lt.current(bt),qt())}(gt=re.current)==null||gt.call(re,c,F);return}}if(!w){const F=O.current.filter(V=>V.selected).map(V=>({id:V.id,type:"select",selected:!1})),bt=Pt.current.filter(V=>V.selected).map(V=>({id:V.id,type:"select",selected:!1}));F.length&&mt.current&&mt.current(F),bt.length&&Lt.current&&Lt.current(bt),(F.length||bt.length)&&qt()}if((vt=Te.current)==null||vt.call(Te,c),Qt||w){te.current={startWorld:{...f},endWorld:{...f}},(Tt=yt.current)==null||Tt.setPointerCapture(c.pointerId),Me();return}ze.current=!0,Ot.current={x:c.clientX,y:c.clientY},(Dt=yt.current)==null||Dt.classList.add("dragging"),($t=yt.current)==null||$t.setPointerCapture(c.pointerId)},[ot,It,Ze,oe,zt,Mt,Nt,Qt,we,Me,qt]),yr=a.useCallback(c=>{var f,w;if(jt.current){if(xe.current=ot(c.clientX,c.clientY),we(),ln){const L=yt.current;if(L){const T=L.getBoundingClientRect(),y=40,A=c.clientX-T.left,j=c.clientY-T.top;let Y=0,_=0;A<y?Y=Yt:A>T.width-y&&(Y=-Yt),j<y?_=Yt:j>T.height-y&&(_=-Yt),(Y||_)&&(ht.current.x+=Y,ht.current.y+=_,kt(c))}}return}if(te.current){te.current.endWorld=ot(c.clientX,c.clientY),Me();const L=te.current,T=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),j=Math.max(L.startWorld.y,L.endWorld.y);if(mt.current){const Y=[];for(const _ of O.current){if(_.hidden)continue;const K=_.width||Gt,st=_.height||Ft,U=Re==="full"?_.position.x>=T&&_.position.x+K<=A&&_.position.y>=y&&_.position.y+st<=j:_.position.x+K>T&&_.position.x<A&&_.position.y+st>y&&_.position.y<j;U!==!!_.selected&&Y.push({id:_.id,type:"select",selected:U})}Y.length&&mt.current(Y)}return}if(Bt.current){const L=ot(c.clientX,c.clientY),T=Bt.current,y=L.x-T.startMouse.x,A=L.y-T.startMouse.y;let j={x:T.startPos.x+y,y:T.startPos.y+A};if(fe&&(j=vn(j,se)),Vt&&(j=bn(j,Vt)),T.parentClamp){const U=T.parentClamp;j={x:Math.max(U.minX,Math.min(j.x,U.maxX)),y:Math.max(U.minY,Math.min(j.y,U.maxY))}}const Y=[{id:T.id,position:j}];for(const U of T.selectedStarts){let et={x:U.startPos.x+y,y:U.startPos.y+A};if(fe&&(et=vn(et,se)),Vt&&(et=bn(et,Vt)),U.parentClamp){const gt=U.parentClamp;et={x:Math.max(gt.minX,Math.min(et.x,gt.maxX)),y:Math.max(gt.minY,Math.min(et.y,gt.maxY))}}Y.push({id:U.id,position:et})}const _=[];for(const U of Y){const et=O.current.find(gt=>gt.id===U.id);if(et){et.position=U.position,et.dragging=!0;let gt=U.position;if(et.parentId){let vt=O.current.find($t=>$t.id===et.parentId),Tt=U.position.x,Dt=U.position.y;for(;vt;)Tt+=vt.position.x,Dt+=vt.position.y,vt=vt.parentId?O.current.find($t=>$t.id===vt.parentId):null;gt={x:Tt,y:Dt}}_.push({id:U.id,position:U.position,_absolutePosition:gt,width:et.width,height:et.height,dragging:!0,selected:et.selected})}}const K=new Set(Y.map(U=>U.id));for(const U of O.current)if(U.parentId&&K.has(U.parentId)&&!K.has(U.id)){let et=O.current.find(Tt=>Tt.id===U.parentId),gt=U.position.x,vt=U.position.y;for(;et;)gt+=et.position.x,vt+=et.position.y,et=et.parentId?O.current.find(Tt=>Tt.id===et.parentId):null;_.push({id:U.id,position:U.position,_absolutePosition:{x:gt,y:vt},width:U.width,height:U.height,dragging:!1,selected:U.selected})}if((f=Rt.current)==null||f.postMessage({type:"nodePositions",data:{updates:_}}),cn){const U=yt.current;if(U){const et=U.getBoundingClientRect(),gt=40,vt=c.clientX-et.left,Tt=c.clientY-et.top;let Dt=0,$t=0;vt<gt?Dt=Yt:vt>et.width-gt&&(Dt=-Yt),Tt<gt?$t=Yt:Tt>et.height-gt&&($t=-Yt),(Dt||$t)&&(ht.current.x+=Dt,ht.current.y+=$t,kt(c))}}const st=O.current.find(U=>U.id===T.id);st&&((w=Se.current)==null||w.call(Se,c,st));return}if(!ze.current)return;const v=ht.current;v.x+=c.clientX-Ot.current.x,v.y+=c.clientY-Ot.current.y,Ot.current={x:c.clientX,y:c.clientY},kt()},[kt,ot,we,Me]),gr=a.useCallback(c=>{var v,f,w,L,T;if(jt.current){const y=ot(c.clientX,c.clientY),A=Ze(y.x,y.y);if(A&&A.nodeId!==jt.current.sourceId&&(St==="loose"||A.type==="target")){const _=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(_):!0)&&((v=ne.current)==null||v.call(ne,{..._,...ge}))}(w=(f=Z.current).onConnectEnd)==null||w.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(mt.current){const j=O.current.find(_=>_.id===y.id),Y=[{id:y.id,type:"position",position:j?{...j.position}:void 0,dragging:!1}];for(const _ of y.selectedStarts){const K=O.current.find(st=>st.id===_.id);Y.push({id:_.id,type:"position",position:K?{...K.position}:void 0,dragging:!1})}mt.current(Y)}requestAnimationFrame(()=>{Bt.current=null});const A=O.current.find(j=>j.id===y.id);A&&((L=Le.current)==null||L.call(Le,c,A));return}ze.current=!1,(T=yt.current)==null||T.classList.remove("dragging")},[ot,Ze,we,Me,qt]);a.useEffect(()=>{const c=yt.current;if(!c)return;const v=f=>{Ce&&f.preventDefault();const w=ht.current;if(Fe||me.current){const j=Xe;ke==="horizontal"?w.x-=f.deltaY*j:(ke==="vertical"||(w.x-=f.deltaX*j),w.y-=f.deltaY*j),kt(f);return}if(!Ye)return;const L=f.deltaY>0?.92:1.08,T=c.getBoundingClientRect(),y=f.clientX-T.left,A=f.clientY-T.top;w.x=y-(y-w.x)*L,w.y=A-(A-w.y)*L,w.zoom=Math.min(rt,Math.max(tt,w.zoom*L)),kt(f)};return c.addEventListener("wheel",v,{passive:!Ce}),()=>c.removeEventListener("wheel",v)},[kt,tt,rt,Fe,ke,Xe,Ye,Ce]),a.useEffect(()=>{if(!qe)return;const c=yt.current;if(!c)return;let v=0,f=null;const w=y=>{if(y.touches.length===2){const A=y.touches[0].clientX-y.touches[1].clientX,j=y.touches[0].clientY-y.touches[1].clientY;v=Math.hypot(A,j);const Y=c.getBoundingClientRect();f={x:(y.touches[0].clientX+y.touches[1].clientX)/2-Y.left,y:(y.touches[0].clientY+y.touches[1].clientY)/2-Y.top},y.preventDefault()}},L=y=>{if(y.touches.length===2&&v>0){y.preventDefault();const A=y.touches[0].clientX-y.touches[1].clientX,j=y.touches[0].clientY-y.touches[1].clientY,Y=Math.hypot(A,j),_=Y/v;v=Y;const K=ht.current,st=f.x,U=f.y;K.x=st-(st-K.x)*_,K.y=U-(U-K.y)*_,K.zoom=Math.min(rt,Math.max(tt,K.zoom*_)),kt(y)}},T=()=>{v=0,f=null};return c.addEventListener("touchstart",w,{passive:!1}),c.addEventListener("touchmove",L,{passive:!1}),c.addEventListener("touchend",T),()=>{c.removeEventListener("touchstart",w),c.removeEventListener("touchmove",L),c.removeEventListener("touchend",T)}},[qe,kt,tt,rt]),a.useEffect(()=>{if(!Ue)return;const c=yt.current;if(!c)return;const v=f=>{var _,K,st,U;const w=ot(f.clientX,f.clientY);if(It(w.x,w.y)){(K=(_=Z.current).onNodeDoubleClick)==null||K.call(_,f,It(w.x,w.y));return}const L=oe(w.x,w.y);if(L){(U=(st=Z.current).onEdgeDoubleClick)==null||U.call(st,f,L);return}const T=1.5,y=c.getBoundingClientRect(),A=f.clientX-y.left,j=f.clientY-y.top,Y=ht.current;Y.x=A-(A-Y.x)*T,Y.y=j-(j-Y.y)*T,Y.zoom=Math.min(rt,Math.max(tt,Y.zoom*T)),kt(f)};return c.addEventListener("dblclick",v),()=>c.removeEventListener("dblclick",v)},[Ue,kt,tt,rt,ot,It,oe]),a.useEffect(()=>{const c=yt.current;if(!c)return;const v=f=>{var y,A,j,Y,_,K;const w=ot(f.clientX,f.clientY),L=It(w.x,w.y);if(L){(A=(y=Z.current).onNodeContextMenu)==null||A.call(y,f,L);return}const T=oe(w.x,w.y);if(T){(Y=(j=Z.current).onEdgeContextMenu)==null||Y.call(j,f,T);return}(K=(_=Z.current).onPaneContextMenu)==null||K.call(_,f)};return c.addEventListener("contextmenu",v),()=>c.removeEventListener("contextmenu",v)},[ot,It,oe]),a.useEffect(()=>{const c=yt.current;if(!c)return;let v=null,f=null;const w=y=>{var Y,_,K,st,U,et,gt,vt,Tt,Dt,$t,F,bt,V;(_=(Y=Z.current).onPaneMouseMove)==null||_.call(Y,y);const A=ot(y.clientX,y.clientY),j=It(A.x,A.y);if(j!==v&&(v&&((st=(K=Z.current).onNodeMouseLeave)==null||st.call(K,y,v)),j&&((et=(U=Z.current).onNodeMouseEnter)==null||et.call(U,y,j)),v=j),j&&((vt=(gt=Z.current).onNodeMouseMove)==null||vt.call(gt,y,j)),!j){const J=oe(A.x,A.y);J!==f&&(f&&((Dt=(Tt=Z.current).onEdgeMouseLeave)==null||Dt.call(Tt,y,f)),J&&((F=($t=Z.current).onEdgeMouseEnter)==null||F.call($t,y,J)),f=J),J&&((V=(bt=Z.current).onEdgeMouseMove)==null||V.call(bt,y,J))}},L=y=>{var A,j;return(j=(A=Z.current).onPaneMouseEnter)==null?void 0:j.call(A,y)},T=y=>{var A,j,Y,_,K,st;(j=(A=Z.current).onPaneMouseLeave)==null||j.call(A,y),v&&((_=(Y=Z.current).onNodeMouseLeave)==null||_.call(Y,y,v),v=null),f&&((st=(K=Z.current).onEdgeMouseLeave)==null||st.call(K,y,f),f=null)};return c.addEventListener("mousemove",w),c.addEventListener("mouseenter",L),c.addEventListener("mouseleave",T),()=>{c.removeEventListener("mousemove",w),c.removeEventListener("mouseenter",L),c.removeEventListener("mouseleave",T)}},[ot,It,oe]),a.useEffect(()=>{const c=Array.isArray(he)?he:[he],v=async f=>{var w,L;if(c.includes(f.key)){if(f.target.tagName==="INPUT"||f.target.tagName==="TEXTAREA"||f.target.isContentEditable)return;const T=O.current.filter(j=>j.selected),y=Pt.current.filter(j=>j.selected);if(!T.length&&!y.length||Z.current.onBeforeDelete&&!await Z.current.onBeforeDelete({nodes:T,edges:y}))return;const A=new Set(T.map(j=>j.id));if(T.length&&mt.current&&(mt.current(T.map(j=>({id:j.id,type:"remove"}))),Lt.current)){const j=Pt.current.filter(Y=>A.has(Y.source)||A.has(Y.target));j.length&&Lt.current(j.map(Y=>({id:Y.id,type:"remove"})))}y.length&&Lt.current&&Lt.current(y.map(j=>({id:j.id,type:"remove"}))),(L=(w=Z.current).onDelete)==null||L.call(w,{nodes:T,edges:y})}if((f.ctrlKey||f.metaKey)&&f.key==="a"){if(f.target.tagName==="INPUT"||f.target.tagName==="TEXTAREA")return;if(f.preventDefault(),mt.current){const T=O.current.filter(y=>!y.selected).map(y=>({id:y.id,type:"select",selected:!0}));T.length&&mt.current(T)}if(Lt.current){const T=Pt.current.filter(y=>!y.selected).map(y=>({id:y.id,type:"select",selected:!0}));T.length&&Lt.current(T)}}};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[he]);const Tn=a.useRef(!1);a.useEffect(()=>{var c,v;if(!Tn.current&&Rt.current){if(Tn.current=!0,wt&&O.current.length>0){const f=yt.current;if(f){const w=f.getBoundingClientRect(),L=(pt==null?void 0:pt.padding)??.1,T=Ve(O.current),y=Je(T,w.width,w.height,L);pt!=null&&pt.maxZoom&&(y.zoom=Math.min(y.zoom,pt.maxZoom)),pt!=null&&pt.minZoom&&(y.zoom=Math.max(y.zoom,pt.minZoom)),ht.current=y,kt()}}(v=(c=Z.current).onInit)==null||v.call(c,{getNodes:()=>[...O.current],getEdges:()=>[...Pt.current],getViewport:()=>({...ht.current}),fitView:(f={})=>{const w=yt.current;if(!w||!O.current.length)return;const L=w.getBoundingClientRect(),T=Ve(O.current),y=Je(T,L.width,L.height,f.padding??.1);ht.current=y,kt()}})}});const xr=a.useCallback(()=>{ht.current={...Et},kt()},[kt,Et]),pr=a.useCallback(c=>{var v;if(c)Jt.current.push(c);else{const f=ht.current,w=yt.current;if(!w)return;const L=w.getBoundingClientRect(),T=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:T-80,y:y-45,w:160,h:90,title:"Note "+(Jt.current.length+1),body:"Added at viewport center"})}(v=Rt.current)==null||v.postMessage({type:"cards",data:{cards:[...Jt.current]}})},[]),mr=a.useCallback(c=>{if(c.id||(c.id="node-"+Date.now()),!c.position){const v=ht.current,f=yt.current;if(!f)return;const w=f.getBoundingClientRect();c.position={x:Math.round(-v.x/v.zoom+w.width/2/v.zoom)-Gt/2,y:Math.round(-v.y/v.zoom+w.height/2/v.zoom)-Ft/2}}c.data||(c.data={label:c.id}),mt.current&&mt.current([{type:"add",item:c}])},[]),vr=a.useCallback(()=>({...ht.current}),[]),br=a.useCallback(c=>{ht.current={...ht.current,...c},kt()},[kt]),wr=a.useCallback(c=>ot(c.x,c.y),[ot]),$n=n,Mr=a.useMemo(()=>({wrapRef:yt,canvasRef:Ee,workerRef:Rt,cameraRef:ht,nodesRef:O,edgesRef:Pt,handleRegistryRef:dn,syncNodesToWorker:Ht,onNodesChangeRef:mt,onEdgesChangeRef:Lt,sendCamera:kt,screenToWorld:ot,viewportListeners:Ut,selectionListeners:ae,zoomMin:tt,zoomMax:rt,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,kt,ot,Ht,Ut,ae,tt,rt,fe,se,Vt,ge,ie]);return{wrapRef:yt,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 Ar(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 dt(){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 b,N,k;const n=dt(),r=a.useRef(null),s=t._absolutePosition||t.position,o=a.useRef(null);a.useEffect(()=>{const R=r.current;if(!R)return;const B=new ResizeObserver(E=>{var D,m,h,p;const{width:z,height:W}=E[0].contentRect;if(z>0&&W>0){const g=n.nodesRef.current.find($=>$.id===t.id),I=(g==null?void 0:g.width)||((D=g==null?void 0:g.measured)==null?void 0:D.width),P=(g==null?void 0:g.height)||((m=g==null?void 0:g.measured)==null?void 0:m.height);(Math.abs((I||0)-z)>1||Math.abs((P||0)-W)>1)&&((p=(h=n.onNodesChangeRef).current)==null||p.call(h,[{id:t.id,type:"dimensions",dimensions:{width:z,height:W},setAttributes:!0}]))}});return B.observe(R),()=>B.disconnect()},[t.id,n]);const i=a.useCallback(R=>{var $,M;if(R.stopPropagation(),n.onNodesChangeRef.current){const S=[];if(R.shiftKey)S.push({id:t.id,type:"select",selected:!t.selected});else for(const H of n.nodesRef.current)H.id===t.id&&!H.selected?S.push({id:H.id,type:"select",selected:!0}):H.id!==t.id&&H.selected&&S.push({id:H.id,type:"select",selected:!1});S.length&&n.onNodesChangeRef.current(S)}const B=n.cameraRef.current,E=n.wrapRef.current;if(!E)return;const z=E.getBoundingClientRect(),W=(R.clientX-z.left-B.x)/B.zoom,D=(R.clientY-z.top-B.y)/B.zoom,h=R.shiftKey&&t.selected?n.nodesRef.current.filter(S=>S.selected&&S.id!==t.id).map(S=>({id:S.id,startPos:{...S.position}})):[];o.current={startPos:{...t.position},startMouse:{x:W,y:D},selectedStarts:h};const p=[{id:t.id,type:"position",dragging:!0}];for(const S of h)p.push({id:S.id,type:"position",dragging:!0});(M=($=n.onNodesChangeRef).current)==null||M.call($,p);const g=r.current;g&&g.setPointerCapture(R.pointerId);const I=S=>{var it,at,ct,Ct;if(!o.current)return;const X=n.cameraRef.current,H=E.getBoundingClientRect(),lt=(S.clientX-H.left-X.x)/X.zoom,ft=(S.clientY-H.top-X.y)/X.zoom,ut=lt-o.current.startMouse.x,G=ft-o.current.startMouse.y;let q={x:o.current.startPos.x+ut,y:o.current.startPos.y+G};if(n.snapToGrid&&n.snapGrid&&(q={x:n.snapGrid[0]*Math.round(q.x/n.snapGrid[0]),y:n.snapGrid[1]*Math.round(q.y/n.snapGrid[1])}),t.parentId&&t.extent==="parent"){const tt=n.nodesRef.current.find(rt=>rt.id===t.parentId);if(tt){const rt=tt.width||160,Et=tt.height||60,wt=t.width||((it=t.measured)==null?void 0:it.width)||160,pt=t.height||((at=t.measured)==null?void 0:at.height)||60;q={x:Math.max(0,Math.min(q.x,rt-wt)),y:Math.max(0,Math.min(q.y,Et-pt))}}}const nt=[{id:t.id,type:"position",position:q,dragging:!0}];for(const tt of o.current.selectedStarts){let rt={x:tt.startPos.x+ut,y:tt.startPos.y+G};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])}),nt.push({id:tt.id,type:"position",position:rt,dragging:!0})}(Ct=(ct=n.onNodesChangeRef).current)==null||Ct.call(ct,nt)},P=S=>{var H,lt;if(!o.current)return;const X=[{id:t.id,type:"position",dragging:!1}];for(const ft of o.current.selectedStarts)X.push({id:ft.id,type:"position",dragging:!1});(lt=(H=n.onNodesChangeRef).current)==null||lt.call(H,X),o.current=null,g&&g.releasePointerCapture(S.pointerId),g==null||g.removeEventListener("pointermove",I),g==null||g.removeEventListener("pointerup",P)};g==null||g.addEventListener("pointermove",I),g==null||g.addEventListener("pointerup",P)},[t,n]),l=a.useCallback(R=>{var m,h,p,g,I,P;if(!t.selected)return;const B=R.shiftKey?10:1;let E=0,z=0;switch(R.key){case"ArrowUp":z=-B;break;case"ArrowDown":z=B;break;case"ArrowLeft":E=-B;break;case"ArrowRight":E=B;break;case"Escape":(h=(m=n.onNodesChangeRef).current)==null||h.call(m,[{id:t.id,type:"select",selected:!1}]);return;case"Delete":case"Backspace":t.deletable!==!1&&((g=(p=n.onNodesChangeRef).current)==null||g.call(p,[{id:t.id,type:"remove"}]));return;default:return}R.preventDefault();const W={x:t.position.x+E,y:t.position.y+z},D=[{id:t.id,type:"position",position:W}];for(const $ of n.nodesRef.current)$.selected&&$.id!==t.id&&D.push({id:$.id,type:"position",position:{x:$.position.x+E,y:$.position.y+z}});(P=(I=n.onNodesChangeRef).current)==null||P.call(I,D)},[t,n]),d=t.width||((b=t.measured)==null?void 0:b.width),u=t.height||((N=t.measured)==null?void 0:N.height),x=!!(d&&u);return C.jsx(_e.Provider,{value:t.id,children:C.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:x?"visible":"hidden",userSelect:"none",outline:"none"},"data-nodeid":t.id,tabIndex:t.selectable!==!1?0:void 0,role:"button","aria-label":`Node ${((k=t.data)==null?void 0:k.label)||t.id}`,"aria-selected":!!t.selected,onPointerDown:i,onKeyDown:l,children:C.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]||[],x=n?u.find(b=>b.id===n):u[0];if(x&&x.x!==void 0&&x.y!==void 0){const b=x.position||(e==="source"?"right":"left");return{x:i.x+x.x,y:i.y+x.y,position:b}}}if(r){const u=`${t.id}__${n||e}`,x=r.get(u);if(x&&x.x!==void 0&&x.y!==void 0)return{x:i.x+x.x,y:i.y+x.y,position:x.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 x=u.position||(e==="source"?"right":"left");switch(x){case"top":return{x:i.x+s/2,y:i.y,position:x};case"bottom":return{x:i.x+s/2,y:i.y+o,position:x};case"left":return{x:i.x,y:i.y+o/2,position:x};default:return{x:i.x+s,y:i.y+o/2,position:x}}}}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 C.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 m,h,p;const s=dt(),[o,i]=a.useState(null),l=a.useCallback((g,I,P,$)=>{var ut;I.stopPropagation(),I.preventDefault();const M=s.wrapRef.current;if(!M)return;const S=g==="source"?$:P,X=g==="source"?t.target:t.source;(ut=s.workerRef.current)==null||ut.postMessage({type:"connecting",data:{from:{x:S.x,y:S.y},to:{x:S.x,y:S.y}}});const H=M.getBoundingClientRect(),lt=G=>{var at;const q=s.cameraRef.current,nt=(G.clientX-H.left-q.x)/q.zoom,it=(G.clientY-H.top-q.y)/q.zoom;(at=s.workerRef.current)==null||at.postMessage({type:"connecting",data:{from:{x:S.x,y:S.y},to:{x:nt,y:it}}})},ft=G=>{var rt,Et,wt,pt;const q=s.cameraRef.current,nt=(G.clientX-H.left-q.x)/q.zoom,it=(G.clientY-H.top-q.y)/q.zoom,at=20/q.zoom;let ct=null,Ct=null;const tt=(rt=s.handleRegistryRef)==null?void 0:rt.current;for(const zt of s.nodesRef.current){if(zt.hidden)continue;const Mt=zt.width||Qn,Nt=zt.height||Kn,xt=zt._absolutePosition||zt.position,Qt=[];if(tt)for(const[,St]of tt)St.nodeId===zt.id&&Qt.push(St);const Re=Qt.length>0?Qt:zt.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const St of Re){let Xt,At;if(St.x!==void 0&&St.y!==void 0)Xt=xt.x+St.x,At=xt.y+St.y;else switch(St.position||(St.type==="source"?"right":"left")){case"top":Xt=xt.x+Mt/2,At=xt.y;break;case"bottom":Xt=xt.x+Mt/2,At=xt.y+Nt;break;case"left":Xt=xt.x,At=xt.y+Nt/2;break;default:Xt=xt.x+Mt,At=xt.y+Nt/2;break}if(Math.abs(nt-Xt)<at&&Math.abs(it-At)<at){ct=zt,Ct=St.id||null;break}}if(ct)break}if(ct){const zt=g==="source"?{source:ct.id,target:X,sourceHandle:Ct,targetHandle:t.targetHandle}:{source:X,target:ct.id,sourceHandle:t.sourceHandle,targetHandle:Ct};(wt=(Et=s.onEdgesChangeRef).current)==null||wt.call(Et,[{id:t.id,type:"remove"},{type:"add",item:{id:t.id,...zt}}])}(pt=s.workerRef.current)==null||pt.postMessage({type:"connecting",data:null}),M.removeEventListener("pointermove",lt),M.removeEventListener("pointerup",ft)};M.addEventListener("pointermove",lt),M.addEventListener("pointerup",ft)},[t,s]),d=n.find(g=>g.id===t.source),u=n.find(g=>g.id===t.target),x=d&&!!(d.width||(m=d.measured)!=null&&m.width),b=u&&!!(u.width||(h=u.measured)!=null&&h.width),N=(p=s.handleRegistryRef)==null?void 0:p.current,k=x?jn(d,"source",t.sourceHandle,N):null,R=b?jn(u,"target",t.targetHandle,N):null,B=t.type==="bezier"||t.type==="simplebezier"||t.type==="default",E=s.routedEdges||s.edges,z=E==null?void 0:E.find(g=>g.id===t.id),W=B?null:(z==null?void 0:z._routedPoints)||t._routedPoints||null,D=r!==!1&&t.reconnectable!==!1;return!k||!R?null:C.jsxs("g",{className:`ric-edge-wrapper ${t.selected?"selected":""}`,"data-edgeid":t.id,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),children:[C.jsx(e,{id:t.id,source:t.source,target:t.target,sourceX:k.x,sourceY:k.y,targetX:R.x,targetY:R.y,sourcePosition:k.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:W}),D&&(o||t.selected)&&C.jsxs(C.Fragment,{children:[C.jsx(Dn,{x:k.x,y:k.y,position:k.position,type:"source",onPointerDown:g=>l("source",g,k,R)}),C.jsx(Dn,{x:R.x,y:R.y,position:R.position,type:"target",onPointerDown:g=>l("target",g,k,R)})]})]})}const qr=a.memo(Ur);function Vn({selectionKeyCode:t="Shift",selectionMode:e="partial"}){var B;const n=dt(),[r,s]=a.useState(null),o=a.useRef(null);if(a.useEffect(()=>{const E=n.wrapRef.current;if(!E)return;let z=!1,W=null,D=!1;const m=P=>{P.key===t&&(D=!0)},h=P=>{P.key===t&&(D=!1)},p=P=>{if(!D)return;const $=P.target;if($.closest(".ric-node-wrapper")||$.closest(".ric-handle"))return;z=!0;const M=n.cameraRef.current,S=E.getBoundingClientRect(),X=(P.clientX-S.left-M.x)/M.zoom,H=(P.clientY-S.top-M.y)/M.zoom;W={x:X,y:H},s({startX:X,startY:H,endX:X,endY:H}),P.stopPropagation()},g=P=>{if(!z||!W)return;const $=n.cameraRef.current,M=E.getBoundingClientRect(),S=(P.clientX-M.left-$.x)/$.zoom,X=(P.clientY-M.top-$.y)/$.zoom;s({startX:W.x,startY:W.y,endX:S,endY:X})},I=P=>{var ft,ut;if(!z||!W)return;z=!1;const $=n.cameraRef.current,M=E.getBoundingClientRect(),S=(P.clientX-M.left-$.x)/$.zoom,X=(P.clientY-M.top-$.y)/$.zoom,H={x:Math.min(W.x,S),y:Math.min(W.y,X),width:Math.abs(S-W.x),height:Math.abs(X-W.y)},lt=[];for(const G of n.nodesRef.current){const q=G._absolutePosition||G.position,nt=G.width||160,it=G.height||60;let at;e==="full"?at=q.x>=H.x&&q.y>=H.y&&q.x+nt<=H.x+H.width&&q.y+it<=H.y+H.height:at=q.x+nt>H.x&&q.x<H.x+H.width&&q.y+it>H.y&&q.y<H.y+H.height,lt.push({id:G.id,type:"select",selected:at})}lt.length&&((ut=(ft=n.onNodesChangeRef).current)==null||ut.call(ft,lt)),W=null,s(null)};return E.addEventListener("pointerdown",p,!0),E.addEventListener("pointermove",g),E.addEventListener("pointerup",I),window.addEventListener("keydown",m),window.addEventListener("keyup",h),()=>{E.removeEventListener("pointerdown",p,!0),E.removeEventListener("pointermove",g),E.removeEventListener("pointerup",I),window.removeEventListener("keydown",m),window.removeEventListener("keyup",h)}},[n,t,e]),!r)return null;const i=((B=n.cameraRef)==null?void 0:B.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),x=Math.abs(r.endY-r.startY),b=l*i.zoom+i.x,N=d*i.zoom+i.y,k=u*i.zoom,R=x*i.zoom;return C.jsx("div",{ref:o,className:"ric-selection-box",style:{position:"absolute",left:b,top:N,width:k,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 Hn(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 Ae({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,...x}){const b=a.useContext(_e),N=dt(),k=a.useRef(null),R=a.useRef(N);R.current=N;const B=a.useCallback(()=>{var P,$,M;const D=k.current;if(!D||!b)return;const m=R.current,h=(P=m.handleRegistryRef)==null?void 0:P.current;if(!h)return;const p=`${b}__${n||t}`,g=(M=($=m.cameraRef)==null?void 0:$.current)==null?void 0:M.zoom,I=Gr(D,g);if(I){const S={nodeId:b,id:n||null,type:t,position:e,x:I.x,y:I.y};h.set(p,S)}},[b,n,t,e]);a.useLayoutEffect(()=>{B()},[B]),a.useEffect(()=>{if(!b)return;const D=R.current;Hn(D,b);const m=k.current,h=m==null?void 0:m.closest(".ric-node-wrapper"),p=new ResizeObserver(()=>{B(),Hn(R.current,b)});return h&&p.observe(h),()=>{var $;p.disconnect();const g=R.current,I=($=g.handleRegistryRef)==null?void 0:$.current,P=`${b}__${n||t}`;I==null||I.delete(P),tr(g,b)}},[b,n,t,e,B]);const E=a.useCallback(()=>{var M;const D=R.current,m=D.nodesRef.current.find(S=>S.id===b);if(!m)return null;const h=m._absolutePosition||m.position,p=(M=D.handleRegistryRef)==null?void 0:M.current,g=`${b}__${n||t}`,I=p==null?void 0:p.get(g);if(I&&I.x!==void 0&&I.y!==void 0)return{x:h.x+I.x,y:h.y+I.y};const P=m.width||160,$=m.height||60;switch(e){case"top":return{x:h.x+P/2,y:h.y};case"bottom":return{x:h.x+P/2,y:h.y+$};case"left":return{x:h.x,y:h.y+$/2};default:return{x:h.x+P,y:h.y+$/2}}},[b,n,t,e]),z=a.useCallback(D=>{var X;if(!r||!s)return;D.stopPropagation(),D.preventDefault();const m=R.current,h=m.cameraRef.current,p=m.wrapRef.current;if(!p)return;const g=p.getBoundingClientRect(),I=E();if(!I)return;const P=I.x,$=I.y;(X=m.workerRef.current)==null||X.postMessage({type:"connecting",data:{from:{x:P,y:$},to:{x:P,y:$}}}),p.setPointerCapture(D.pointerId);const M=H=>{var ut;const lt=(H.clientX-g.left-h.x)/h.zoom,ft=(H.clientY-g.top-h.y)/h.zoom;(ut=m.workerRef.current)==null||ut.postMessage({type:"connecting",data:{from:{x:P,y:$},to:{x:lt,y:ft}}})},S=H=>{var it,at,ct,Ct;const lt=(H.clientX-g.left-h.x)/h.zoom,ft=(H.clientY-g.top-h.y)/h.zoom,ut=20/h.zoom;let G=null,q=null;const nt=(it=m.handleRegistryRef)==null?void 0:it.current;for(const tt of m.nodesRef.current){if(tt.id===b||tt.hidden)continue;const rt=tt.width||160,Et=tt.height||60,wt=tt._absolutePosition||tt.position,pt=[];if(nt)for(const[,Mt]of nt)Mt.nodeId===tt.id&&pt.push(Mt);const zt=pt.length>0?pt:tt.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const Mt of zt){let Nt,xt;if(Mt.x!==void 0&&Mt.y!==void 0)Nt=wt.x+Mt.x,xt=wt.y+Mt.y;else switch(Mt.position||(Mt.type==="source"?"right":"left")){case"top":Nt=wt.x+rt/2,xt=wt.y;break;case"bottom":Nt=wt.x+rt/2,xt=wt.y+Et;break;case"left":Nt=wt.x,xt=wt.y+Et/2;break;default:Nt=wt.x+rt,xt=wt.y+Et/2;break}if(Math.abs(lt-Nt)<ut&&Math.abs(ft-xt)<ut){G=tt,q=Mt.id||null;break}}if(G)break}if(G){const tt={source:t==="source"?b:G.id,target:t==="source"?G.id:b,sourceHandle:t==="source"?n||null:q,targetHandle:t==="source"?q:n||null};(ct=(at=m.onEdgesChangeRef)==null?void 0:at.current)==null||ct.call(at,[{type:"add",item:{id:`e-${tt.source}-${tt.target}`,...tt}}])}(Ct=m.workerRef.current)==null||Ct.postMessage({type:"connecting",data:null}),p.removeEventListener("pointermove",M),p.removeEventListener("pointerup",S)};p.addEventListener("pointermove",M),p.addEventListener("pointerup",S)},[b,n,t,e,r,s,E]),W={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 C.jsx("div",{ref:k,className:`ric-handle ric-handle-${e} ric-handle-${t} ${l}`,"data-handleid":n||null,"data-nodeid":b,"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",...W,...d},...x,children:i})}function Or({data:t,isConnectable:e,selected:n,targetPosition:r="left",sourcePosition:s="right",hideSourceHandle:o=!1,hideTargetHandle:i=!1}){return C.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&&C.jsx(Ae,{type:"target",position:r,isConnectable:e}),C.jsx("div",{className:"ric-node-content",children:t==null?void 0:t.label}),!o&&C.jsx(Ae,{type:"source",position:s,isConnectable:e})]})}function er({data:t,isConnectable:e,selected:n,sourcePosition:r="right",hideSourceHandle:s=!1}){return C.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:[C.jsx("div",{className:"ric-node-content",children:t==null?void 0:t.label}),!s&&C.jsx(Ae,{type:"source",position:r,isConnectable:e})]})}function nr({data:t,isConnectable:e,selected:n,targetPosition:r="left",hideTargetHandle:s=!1}){return C.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&&C.jsx(Ae,{type:"target",position:r,isConnectable:e}),C.jsx("div",{className:"ric-node-content",children:t==null?void 0:t.label})]})}function rr({data:t,selected:e,width:n,height:r}){return C.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)&&C.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="",...x}){const[b,N]=a.useState({x:1,y:0,width:0,height:0}),k=a.useRef(null);return a.useEffect(()=>{if(k.current){const R=k.current.getBBox();N({x:R.x,y:R.y,width:R.width,height:R.height})}},[n]),n?C.jsxs("g",{transform:`translate(${t-b.width/2} ${e-b.height/2})`,className:`ric-edge-textwrapper ${u}`,visibility:b.width?"visible":"hidden",...x,children:[s&&C.jsx("rect",{width:b.width+2*i[0],x:-i[0],y:-i[1],height:b.height+2*i[1],className:"ric-edge-textbg",style:o,rx:l,ry:l}),C.jsx("text",{className:"ric-edge-text",y:b.height/2,dy:"0.3em",ref:k,style:r,children:n}),d]}):null}or.displayName="EdgeText";const sr=a.memo(or);function An(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:x=20,style:b,markerEnd:N,markerStart:k,className:R="",...B}){return C.jsxs(C.Fragment,{children:[C.jsx("path",{id:t,d:e,fill:"none",stroke:"#b1b1b7",strokeWidth:1.5,className:`ric-edge-path ${R}`,style:b,markerEnd:N,markerStart:k,...B}),x?C.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:x,className:"ric-edge-interaction",style:{pointerEvents:"stroke"}}):null,s&&An(n)&&An(r)?C.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:x,labelBgStyle:b,labelBgPadding:N,labelBgBorderRadius:k,style:R,markerEnd:B,markerStart:E,interactionWidth:z}){let W,D,m;const h=_n(n,r,i),p=_n(s,o,l),g=Math.abs(p.x-h.x),I=Math.max(50,g*.5);let P,$,M,S;switch(i){case"left":P=h.x-I,$=h.y;break;case"top":P=h.x,$=h.y-I;break;case"bottom":P=h.x,$=h.y+I;break;default:P=h.x+I,$=h.y;break}switch(l){case"right":M=p.x+I,S=p.y;break;case"top":M=p.x,S=p.y-I;break;case"bottom":M=p.x,S=p.y+I;break;default:M=p.x-I,S=p.y;break}W=`M ${n},${r} L ${h.x},${h.y} C ${P},${$} ${M},${S} ${p.x},${p.y} L ${s},${o}`;const X=.5,H=.5;return D=H*H*H*h.x+3*H*H*X*P+3*H*X*X*M+X*X*X*p.x,m=H*H*H*h.y+3*H*H*X*$+3*H*X*X*S+X*X*X*p.y,C.jsx(We,{id:e,path:W,labelX:D,labelY:m,label:d,labelStyle:u,labelShowBg:x,labelBgStyle:b,labelBgPadding:N,labelBgBorderRadius:k,style:R,markerEnd:B,markerStart:E,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),x=Math.max(u*i,50);let b,N,k,R;switch(s){case"top":b=t,N=e-x;break;case"bottom":b=t,N=e+x;break;case"left":b=t-x,N=e;break;default:b=t+x,N=e;break}switch(o){case"top":k=n,R=r-x;break;case"bottom":k=n,R=r+x;break;case"right":k=n+x,R=r;break;default:k=n-x,R=r;break}const B=`M ${t},${e} C ${b},${N} ${k},${R} ${n},${r}`,E=.5,z=1-E,W=z*z*z*t+3*z*z*E*b+3*z*E*E*k+E*E*E*n,D=z*z*z*e+3*z*z*E*N+3*z*E*E*R+E*E*E*r;return[B,W,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,x=.5,b=x*x*x*t+3*x*x*u*i+3*x*u*u*l+u*u*u*n,N=x*x*x*e+3*x*x*u*e+3*x*u*u*r+u*u*u*r;return[d,b,N,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 k=(t+n)/2,R=r>e?1:-1;return[`M ${t},${e} L ${k-u},${e} Q ${k},${e} ${k},${e+R*u} L ${k},${r-R*u} Q ${k},${r} ${k+(n>k?u:-u)},${r} L ${n},${r}`,k,(e+r)/2,0,0]}const x=(e+r)/2,b=n>t?1:-1;return[`M ${t},${e} L ${t},${x-u} Q ${t},${x} ${t+b*u},${x} L ${n-b*u},${x} Q ${n},${x} ${n},${x+(r>x?u:-u)} L ${n},${r}`,(t+n)/2,x,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),x=Math.min(e,r),b=Math.max(e,r);if(u<=s||d>=s+i||b<=o||x>=o+l)return!1;const N=.5;if(t>s+N&&t<s+i-N&&e>o+N&&e<o+l-N||n>s+N&&n<s+i-N&&r>o+N&&r<o+l-N)return!0;const k=(t+n)/2,R=(e+r)/2;if(k>s+N&&k<s+i-N&&R>o+N&&R<o+l-N)return!0;const B=[[s,o],[s+i,o],[s+i,o+l],[s,o+l]];for(let E=0;E<4;E++)if(Jr(t,e,n,r,B[E][0],B[E][1],B[(E+1)%4][0],B[(E+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),x=(n-t)*(o-e)-(r-e)*(s-t),b=(n-t)*(l-e)-(r-e)*(i-t);return(d>0&&u<0||d<0&&u>0)&&(x>0&&b<0||x<0&&b>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 M=0;M<n.length;M++){const S=n[M];r.add(S.x),r.add(S.x+S.w),s.add(S.y),s.add(S.y+S.h)}const i=[...r].sort((M,S)=>M-S),l=[...s].sort((M,S)=>M-S),d=new Map,u=new Map;for(let M=0;M<i.length;M++)d.set(i[M],M);for(let M=0;M<l.length;M++)u.set(l[M],M);const x=i.length,b=l.length,N=(M,S)=>S*x+M,k=d.get(t.x),R=u.get(t.y),B=d.get(e.x),E=u.get(e.y);if(k===void 0||R===void 0||B===void 0||E===void 0)return null;const z=N(k,R),W=N(B,E),D=new Float64Array(x*b).fill(1/0),m=new Float64Array(x*b).fill(1/0),h=new Int32Array(x*b).fill(-1),p=new Int8Array(x*b).fill(-1),g=new Uint8Array(x*b);D[z]=0,m[z]=Math.abs(i[B]-t.x)+Math.abs(l[E]-t.y);const I=[z],P=15,$=[[1,0],[-1,0],[0,1],[0,-1]];for(;I.length>0;){let M=0;for(let G=1;G<I.length;G++)m[I[G]]<m[I[M]]&&(M=G);const S=I[M];if(I[M]=I[I.length-1],I.pop(),S===W){const G=[];let q=W;for(;q!==-1&&q!==z;){const nt=q/x|0,it=q%x;G.unshift({x:i[it],y:l[nt]}),q=h[q]}return G.unshift({x:t.x,y:t.y}),eo(G,n)}if(g[S])continue;g[S]=1;const X=S/x|0,H=S%x,lt=i[H],ft=l[X],ut=p[S];for(let G=0;G<4;G++){const q=H+$[G][0],nt=X+$[G][1];if(q<0||q>=x||nt<0||nt>=b)continue;const it=N(q,nt);if(g[it])continue;const at=i[q],ct=l[nt];if(to(at,ct,n)||!wn(lt,ft,at,ct,n))continue;const Ct=Math.abs(at-lt)+Math.abs(ct-ft),tt=ut>=0&&ut!==G?P:0,rt=D[S]+Ct+tt;rt<D[it]&&(h[it]=S,p[it]=G,D[it]=rt,m[it]=rt+Math.abs(i[B]-at)+Math.abs(l[E]-ct),I.push(it))}}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],x=-l+d*Ke,b=r.get(u.edgeId);b&&(b[u.segIdx].y+=x,b[u.segIdx+1].y+=x)}}}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],x=-l+d*Ke,b=r.get(u.edgeId);b&&(b[u.segIdx].x+=x,b[u.segIdx+1].x+=x)}}}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),x=Math.abs(d.x-l.x)+Math.abs(d.y-l.y),b=Math.min(r,u/2,x/2);if(b>.5){const N=l.x-i.x,k=l.y-i.y,R=d.x-l.x,B=d.y-l.y,E=Math.sqrt(N*N+k*k)||1,z=Math.sqrt(R*R+B*B)||1;s+=` L ${l.x-N/E*b},${l.y-k/E*b}`,s+=` Q ${l.x},${l.y} ${l.x+R/z*b},${l.y+B/z*b}`}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,x=i.x-(l.x-o.x)*e,b=i.y-(l.y-o.y)*e;n+=` C ${d},${u} ${x},${b} ${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,g,I,P;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),x=Wn(d,"target",o.targetHandle),b=on(u,rn),N=on(x,rn),k=5,R=r.filter($=>$.id!==o.source&&$.id!==o.target),B=l._absolutePosition||l.position,E=l.width||((p=l.measured)==null?void 0:p.width)||en,z=l.height||((g=l.measured)==null?void 0:g.height)||nn;R.push({id:o.source,x:B.x-k,y:B.y-k,w:E+2*k,h:z+2*k});const W=d._absolutePosition||d.position,D=d.width||((I=d.measured)==null?void 0:I.width)||en,m=d.height||((P=d.measured)==null?void 0:P.height)||nn;if(R.push({id:o.target,x:W.x-k,y:W.y-k,w:D+2*k,h:m+2*k}),R.length===0)return o;const h=ir(b,N,R);return h&&h.length>=2?(h.unshift({x:u.x,y:u.y}),h.push({x:x.x,y:x.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"},x={x:n,y:r,dir:o||"left"},b=on(u,rn),N=on(x,rn),k=ir(b,N,d);return k&&k.length>=2?(k.unshift({x:u.x,y:u.y}),k.push({x:x.x,y:x.y}),k):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:x,labelBgBorderRadius:b,style:N,markerEnd:k,markerStart:R,interactionWidth:B,routedPoints:E}){let z,W,D;if(E&&E.length>=2){z=sn(E);const m=an(E);W=m.x,D=m.y}else[z,W,D]=kn({sourceX:n,sourceY:r,targetX:s,targetY:o});return C.jsx(We,{id:e,path:z,labelX:W,labelY:D,label:i,labelStyle:l,labelShowBg:d,labelBgStyle:u,labelBgPadding:x,labelBgBorderRadius:b,style:N,markerEnd:k,markerStart:R,interactionWidth:B})});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:x,labelBgStyle:b,labelBgPadding:N,labelBgBorderRadius:k,style:R,markerEnd:B,markerStart:E,pathOptions:z,interactionWidth:W,routedPoints:D}){let m,h,p;if(D&&D.length>=2){m=sn(D);const g=an(D);h=g.x,p=g.y}else[m,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 C.jsx(We,{id:e,path:m,labelX:h,labelY:p,label:d,labelStyle:u,labelShowBg:x,labelBgStyle:b,labelBgPadding:N,labelBgBorderRadius:k,style:R,markerEnd:B,markerStart:E,interactionWidth:W})});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 C.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:x,labelBgStyle:b,labelBgPadding:N,labelBgBorderRadius:k,style:R,markerEnd:B,markerStart:E,interactionWidth:z,routedPoints:W}){let D,m,h;if(W&&W.length>=2){D=sn(W);const p=an(W);m=p.x,h=p.y}else[D,m,h]=En({sourceX:n,sourceY:r,targetX:s,targetY:o});return C.jsx(We,{id:e,path:D,labelX:m,labelY:h,label:d,labelStyle:u,labelShowBg:x,labelBgStyle:b,labelBgPadding:N,labelBgBorderRadius:k,style:R,markerEnd:B,markerStart:E,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:x={},zoomMin:b,zoomMax:N,initialCamera:k,fitView:R,fitViewOptions:B,onNodesChange:E,onEdgesChange:z,onConnect:W,onConnectStart:D,onConnectEnd:m,onNodeClick:h,onNodeDoubleClick:p,onNodeMouseEnter:g,onNodeMouseMove:I,onNodeMouseLeave:P,onNodeContextMenu:$,onNodeDragStart:M,onNodeDrag:S,onNodeDragStop:X,onEdgeClick:H,onEdgeDoubleClick:lt,onEdgeMouseEnter:ft,onEdgeMouseMove:ut,onEdgeMouseLeave:G,onEdgeContextMenu:q,onPaneClick:nt,onPaneContextMenu:it,onPaneMouseEnter:at,onPaneMouseMove:ct,onPaneMouseLeave:Ct,onSelectionChange:tt,onInit:rt,onMoveStart:Et,onMove:wt,onMoveEnd:pt,onDelete:zt,onBeforeDelete:Mt,onError:Nt,onDragOver:xt,onDrop:Qt,onDragEnter:Re,onDragLeave:St,nodesDraggable:Xt,nodesConnectable:At,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:yt,nodeExtent:Ee,autoPanOnNodeDrag:Rt,autoPanOnConnect:ht,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(Ht=>Ht.type&&ee[Ht.type]);return Q.sort((Ht,ot)=>{const It=Ht.type==="group"||!Ht.parentId&&Q.some(be=>be.parentId===Ht.id),de=ot.type==="group"||!ot.parentId&&Q.some(be=>be.parentId===ot.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]),mt=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:mt,dark:o,gridSize:i,zoomMin:b,zoomMax:N,initialCamera:k,fitView:R,fitViewOptions:B,onHudUpdate:Oe,onNodesProcessed:fn,onNodesChange:E,onEdgesChange:z,onConnect:W,onConnectStart:D,onConnectEnd:m,onNodeClick:h,onNodeDoubleClick:p,onNodeMouseEnter:g,onNodeMouseMove:I,onNodeMouseLeave:P,onNodeContextMenu:$,onNodeDragStart:M,onNodeDrag:S,onNodeDragStop:X,onEdgeClick:H,onEdgeDoubleClick:lt,onEdgeMouseEnter:ft,onEdgeMouseMove:ut,onEdgeMouseLeave:G,onEdgeContextMenu:q,onPaneClick:nt,onPaneContextMenu:it,onPaneMouseEnter:at,onPaneMouseMove:ct,onPaneMouseLeave:Ct,onSelectionChange:tt,onInit:rt,onMoveStart:Et,onMove:wt,onMoveEnd:pt,onDelete:zt,onBeforeDelete:Mt,onError:Nt,nodesDraggable:Xt,nodesConnectable:At,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:yt,nodeExtent:Ee,autoPanOnNodeDrag:Rt,autoPanOnConnect:ht,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 Ht=()=>{const ot=re.cameraRef.current,It=`translate(${ot.x}px, ${ot.y}px) scale(${ot.zoom})`,de=`translate(${ot.x}, ${ot.y}) scale(${ot.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(Ht)};return Q=requestAnimationFrame(Ht),()=>cancelAnimationFrame(Q)},[re]);const ve=ae.length>0,Zt=me.length>0;return C.jsx(Zn.Provider,{value:Te,children:C.jsxs("div",{ref:Lt,className:`ric-wrap ${u}`,style:{width:l,height:d,...x},onPointerDown:Ie,onPointerMove:Se,onPointerUp:Le,onDragOver:xt,onDrop:Qt,onDragEnter:Re,onDragLeave:St,tabIndex:0,children:[C.jsx("canvas",{ref:ne,className:"ric-canvas"}),!Pe&&C.jsx("div",{className:"ric-loader",children:C.jsx("div",{className:"ric-spinner"})}),Zt&&C.jsx("svg",{className:"ric-edges-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:C.jsx("g",{ref:le,children:me.map(Q=>C.jsx(qr,{edge:Q,edgeType:Ut[Q.type],nodes:e,reconnectable:O},Q.id))})}),ve&&C.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=>C.jsx(Fr,{node:Q,nodeType:ee[Q.type]},Q.id))}),C.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}}),C.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&&C.jsx("div",{className:"ric-hint",children:jt}),hn&&C.jsxs("div",{className:"ric-info",children:["world: (",_t.wx,", ",_t.wy,")   zoom: ",_t.zoom,"x",_t.nodeCount>0&&C.jsxs(C.Fragment,{children:["   nodes: ",_t.nodeCount]}),_t.edgeCount>0&&C.jsxs(C.Fragment,{children:["   edges: ",_t.edgeCount]})]}),C.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=dt(),e=a.useCallback(()=>[...t.nodesRef.current],[t]),n=a.useCallback(()=>[...t.edgesRef.current],[t]),r=a.useCallback(m=>t.nodesRef.current.find(h=>h.id===m),[t]),s=a.useCallback(m=>t.edgesRef.current.find(h=>h.id===m),[t]),o=a.useCallback(m=>{var h,p,g,I;if(typeof m=="function"){const P=m(t.nodesRef.current);(p=(h=t.onNodesChangeRef).current)==null||p.call(h,[...t.nodesRef.current.map($=>({id:$.id,type:"remove"})),...P.map($=>({type:"add",item:$}))])}else(I=(g=t.onNodesChangeRef).current)==null||I.call(g,[...t.nodesRef.current.map(P=>({id:P.id,type:"remove"})),...m.map(P=>({type:"add",item:P}))])},[t]),i=a.useCallback(m=>{var h,p,g,I;if(typeof m=="function"){const P=m(t.edgesRef.current);(p=(h=t.onEdgesChangeRef).current)==null||p.call(h,[...t.edgesRef.current.map($=>({id:$.id,type:"remove"})),...P.map($=>({type:"add",item:$}))])}else(I=(g=t.onEdgesChangeRef).current)==null||I.call(g,[...t.edgesRef.current.map(P=>({id:P.id,type:"remove"})),...m.map(P=>({type:"add",item:P}))])},[t]),l=a.useCallback(m=>{var p,g;const h=Array.isArray(m)?m:[m];(g=(p=t.onNodesChangeRef).current)==null||g.call(p,h.map(I=>({type:"add",item:I})))},[t]),d=a.useCallback(m=>{var p,g;const h=Array.isArray(m)?m:[m];(g=(p=t.onEdgesChangeRef).current)==null||g.call(p,h.map(I=>({type:"add",item:I})))},[t]),u=a.useCallback(({nodes:m=[],edges:h=[]})=>{if(m.length&&t.onNodesChangeRef.current){t.onNodesChangeRef.current(m.map(g=>({id:g.id,type:"remove"})));const p=qn(m,t.edgesRef.current);p.length&&t.onEdgesChangeRef.current&&t.onEdgesChangeRef.current(p.map(g=>({id:g.id,type:"remove"})))}h.length&&t.onEdgesChangeRef.current&&t.onEdgesChangeRef.current(h.map(p=>({id:p.id,type:"remove"})))},[t]),x=a.useCallback(()=>{const m=t.cameraRef.current;return{x:m.x,y:m.y,zoom:m.zoom}},[t]),b=a.useCallback((m,h)=>{t.cameraRef.current={x:m.x??t.cameraRef.current.x,y:m.y??t.cameraRef.current.y,zoom:m.zoom??t.cameraRef.current.zoom},t.sendCamera()},[t]),N=a.useCallback(()=>t.cameraRef.current.zoom,[t]),k=a.useCallback(m=>{const h=t.cameraRef.current,p=t.wrapRef.current;if(!p)return;const g=p.getBoundingClientRect(),I=g.width/2,P=g.height/2,$=1.2;h.x=I-(I-h.x)*$,h.y=P-(P-h.y)*$,h.zoom=Math.min(t.zoomMax,h.zoom*$),t.sendCamera()},[t]),R=a.useCallback(m=>{const h=t.cameraRef.current,p=t.wrapRef.current;if(!p)return;const g=p.getBoundingClientRect(),I=g.width/2,P=g.height/2,$=1/1.2;h.x=I-(I-h.x)*$,h.y=P-(P-h.y)*$,h.zoom=Math.max(t.zoomMin,h.zoom*$),t.sendCamera()},[t]),B=a.useCallback(m=>{const h=t.cameraRef.current,p=t.wrapRef.current;if(!p)return;const g=p.getBoundingClientRect(),I=g.width/2,P=g.height/2,$=m/h.zoom;h.x=I-(I-h.x)*$,h.y=P-(P-h.y)*$,h.zoom=Math.min(t.zoomMax,Math.max(t.zoomMin,m)),t.sendCamera()},[t]),E=a.useCallback((m={})=>{const h=t.nodesRef.current;if(!h.length)return;const p=t.wrapRef.current;if(!p)return;const g=p.getBoundingClientRect(),I=m.padding??.1,P=m.nodes?h.filter(S=>m.nodes.some(X=>X.id===S.id)):h;if(!P.length)return;const $=Ve(P),M=Je($,g.width,g.height,I);m.maxZoom&&(M.zoom=Math.min(M.zoom,m.maxZoom)),m.minZoom&&(M.zoom=Math.max(M.zoom,m.minZoom)),t.cameraRef.current=M,t.sendCamera()},[t]),z=a.useCallback((m,h,p={})=>{const g=t.wrapRef.current;if(!g)return;const I=g.getBoundingClientRect(),P=p.zoom??t.cameraRef.current.zoom;t.cameraRef.current={x:I.width/2-m*P,y:I.height/2-h*P,zoom:P},t.sendCamera()},[t]),W=a.useCallback(m=>t.screenToWorld(m.x,m.y),[t]),D=a.useCallback(m=>{const h=t.cameraRef.current,p=t.wrapRef.current;if(!p)return{x:0,y:0};const g=p.getBoundingClientRect();return{x:m.x*h.zoom+h.x+g.left,y:m.y*h.zoom+h.y+g.top}},[t]);return{getNodes:e,getEdges:n,getNode:r,getEdge:s,setNodes:o,setEdges:i,addNodes:l,addEdges:d,deleteElements:u,getViewport:x,setViewport:b,getZoom:N,zoomIn:k,zoomOut:R,zoomTo:B,fitView:E,setCenter:z,screenToFlowPosition:W,flowToScreenPosition:D}}function go(){return dt().nodes}function xo(){return dt().edges}function po(){return dt().viewport}function mo(){return dt().connection}function vo(t){const e=dt(),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=dt();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=dt();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=dt(),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=dt(),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=dt();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 dt().nodes.length>0}function zo(t){const e=dt();return a.useMemo(()=>e.nodes.find(n=>n.id===t)||void 0,[e.nodes,t])}function No(t){const e=dt();return typeof t=="function"?t(e):e}function Po(){const t=dt();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=dt(),d=a.useRef(null),u=a.useRef(null),x=a.useCallback(()=>{const b=d.current;if(!b)return;const N=b.getContext("2d"),k=window.devicePixelRatio||1;b.width=t*k,b.height=e*k,N.scale(k,k),N.clearRect(0,0,t,e);const R=l.nodesRef.current;if(!R.length)return;let B=1/0,E=1/0,z=-1/0,W=-1/0;for(const M of R){const S=M.width||pn,X=M.height||mn;M.position.x<B&&(B=M.position.x),M.position.y<E&&(E=M.position.y),M.position.x+S>z&&(z=M.position.x+S),M.position.y+X>W&&(W=M.position.y+X)}const D=40;B-=D,E-=D,z+=D,W+=D;const m=z-B,h=W-E,p=Math.min(t/m,e/h),g=(t-m*p)/2,I=(e-h*p)/2;for(const M of R){if(M.hidden)continue;const S=M.width||pn,X=M.height||mn,H=(M.position.x-B)*p+g,lt=(M.position.y-E)*p+I,ft=S*p,ut=X*p;N.fillStyle=M.selected?"#f59e0b":typeof n=="function"?n(M):n,N.fillRect(H,lt,Math.max(ft,2),Math.max(ut,2))}const P=l.cameraRef.current,$=l.wrapRef.current;if($){const M=$.getBoundingClientRect(),S=-P.x/P.zoom,X=-P.y/P.zoom,H=M.width/P.zoom,lt=M.height/P.zoom;N.fillStyle=s,N.fillRect(0,0,t,e);const ft=(S-B)*p+g,ut=(X-E)*p+I,G=H*p,q=lt*p;N.clearRect(ft,ut,G,q);for(const nt of R){if(nt.hidden)continue;const it=nt.width||pn,at=nt.height||mn,ct=(nt.position.x-B)*p+g,Ct=(nt.position.y-E)*p+I;N.fillStyle=nt.selected?"#f59e0b":typeof n=="function"?n(nt):n,N.fillRect(ct,Ct,Math.max(it*p,2),Math.max(at*p,2))}N.strokeStyle="#3b82f6",N.lineWidth=1.5,N.strokeRect(ft,ut,G,q)}},[l,t,e,n,r,s]);return a.useEffect(()=>{let b=!0;function N(){b&&(x(),u.current=requestAnimationFrame(N))}const k=setInterval(()=>{cancelAnimationFrame(u.current),u.current=requestAnimationFrame(N)},66);return x(),()=>{b=!1,clearInterval(k),cancelAnimationFrame(u.current)}},[x]),C.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 C.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:[C.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),C.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function Lo(){return C.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:C.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function To(){return C.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:C.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}function $o(){return C.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:[C.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),C.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function Bo(){return C.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:[C.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),C.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})}function He({children:t,className:e="",...n}){return C.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:x={},className:b="","aria-label":N="Canvas controls",children:k}){const R=dt(),{zoomIn:B,zoomOut:E,fitView:z,getZoom:W}=dr(),[D,m]=a.useState(!0),h=W()<=R.zoomMin,p=W()>=R.zoomMax,g=a.useCallback(()=>{B(),s==null||s()},[B,s]),I=a.useCallback(()=>{E(),o==null||o()},[E,o]),P=a.useCallback(()=>{z(r||{padding:.1}),i==null||i()},[z,r,i]),$=a.useCallback(()=>{const S=!D;m(S),l==null||l(S)},[D,l]),M={"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 C.jsxs("div",{className:`ric-controls ${b}`,style:{position:"absolute",display:"flex",flexDirection:u==="horizontal"?"row":"column",gap:2,zIndex:5,...M,...x},role:"toolbar","aria-label":N,children:[t&&C.jsxs(C.Fragment,{children:[C.jsx(He,{onClick:g,disabled:p,title:"Zoom in","aria-label":"Zoom in",className:"ric-controls-zoomin",children:C.jsx(So,{})}),C.jsx(He,{onClick:I,disabled:h,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:C.jsx(Lo,{})})]}),e&&C.jsx(He,{onClick:P,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:C.jsx(To,{})}),n&&C.jsx(He,{onClick:$,title:D?"Lock interactivity":"Unlock interactivity","aria-label":D?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:D?C.jsx(Bo,{}):C.jsx($o,{})}),k]})}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},Ho=a.memo(jo);function Ao({variant:t="lines",gap:e=40,size:n=1,color:r,style:s={},className:o=""}){const i=dt();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 C.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:x}){const b=a.useContext(_e),N=dt(),k=a.useRef(null),R=a.useCallback((z,W)=>{z.stopPropagation(),z.preventDefault();const D=N.nodesRef.current.find(p=>p.id===b);if(!D)return;k.current={direction:W,startX:z.clientX,startY:z.clientY,width:D.width||160,height:D.height||60},d==null||d(z,{width:k.current.width,height:k.current.height});const m=p=>{var X,H;if(!k.current)return;const g=k.current,I=N.cameraRef.current,P=(p.clientX-g.startX)/I.zoom,$=(p.clientY-g.startY)/I.zoom;let M=g.width,S=g.height;g.direction.includes("e")&&(M=Math.min(n,Math.max(t,g.width+P))),g.direction.includes("w")&&(M=Math.min(n,Math.max(t,g.width-P))),g.direction.includes("s")&&(S=Math.min(r,Math.max(e,g.height+$))),g.direction.includes("n")&&(S=Math.min(r,Math.max(e,g.height-$))),(H=(X=N.onNodesChangeRef).current)==null||H.call(X,[{id:b,type:"dimensions",dimensions:{width:M,height:S},setAttributes:!0}]),u==null||u(p,{width:M,height:S})},h=p=>{k.current=null,x==null||x(p,{}),window.removeEventListener("pointermove",m),window.removeEventListener("pointerup",h)};window.addEventListener("pointermove",m),window.addEventListener("pointerup",h)},[b,N,t,e,n,r,d,u,x]);if(!s)return null;const B=8,E={position:"absolute",width:B,height:B,background:l,border:"1px solid #fff",borderRadius:2,zIndex:20,...o};return C.jsxs(C.Fragment,{children:[C.jsx("div",{style:{...E,bottom:-B/2,right:-B/2,cursor:"nwse-resize"},onPointerDown:z=>R(z,"se")}),C.jsx("div",{style:{...E,bottom:-B/2,left:-B/2,cursor:"nesw-resize"},onPointerDown:z=>R(z,"sw")}),C.jsx("div",{style:{...E,top:-B/2,right:-B/2,cursor:"nesw-resize"},onPointerDown:z=>R(z,"ne")}),C.jsx("div",{style:{...E,top:-B/2,left:-B/2,cursor:"nwse-resize"},onPointerDown:z=>R(z,"nw")}),C.jsx("div",{style:{...E,top:"50%",right:-B/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:z=>R(z,"e")}),C.jsx("div",{style:{...E,top:"50%",left:-B/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:z=>R(z,"w")}),C.jsx("div",{style:{...E,left:"50%",top:-B/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:z=>R(z,"n")}),C.jsx("div",{style:{...E,left:"50%",bottom:-B/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=dt().nodes.find(N=>N.id===l);if(!(t!==void 0?t:u==null?void 0:u.selected))return null;const b={top:{bottom:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginBottom:n},bottom:{top:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginTop:n},left:{right:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginRight:n},right:{left:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginLeft:n}}[e]||{};return C.jsx("div",{className:`ric-node-toolbar ${i}`,style:{position:"absolute",zIndex:1e3,pointerEvents:"all",...b,...o},onPointerDown:N=>N.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 C.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=dt().edgeLabelContainerRef)==null?void 0:r.current;return n?Xn.createPortal(t,n):null}function Uo({children:t}){var r;const n=(r=dt().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 C.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 C.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=Ao;exports.BaseEdge=We;exports.BezierEdge=Rn;exports.ConnectionLine=qo;exports.ControlButton=He;exports.Controls=Ho;exports.DefaultNode=Or;exports.EdgeLabelRenderer=Yo;exports.EdgeText=sr;exports.EdgeToolbar=Xo;exports.GroupNode=rr;exports.Handle=Ae;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,Hr=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:C,onEdgeMouseEnter:R,onEdgeMouseMove:T,onEdgeMouseLeave:E,onEdgeContextMenu:N,onNodeDoubleClick:W,onNodeMouseEnter:H,onNodeMouseMove:x,onNodeMouseLeave:h,onNodeContextMenu:p,onPaneClick:b,onPaneContextMenu:w,onPaneMouseEnter:I,onPaneMouseMove:$,onPaneMouseLeave:k,onSelectionChange:j,onConnectStart:U,onConnectEnd:D,onInit:st,onMoveStart:et,onMove:ct,onMoveEnd:G,onDelete:q,onBeforeDelete:ot,onError:nt,isValidConnection:lt,dark:ut,gridSize:zt=40,zoomMin:rt=.1,zoomMax:yt=4,initialCamera:pt={x:0,y:0,zoom:1},fitView:dt=!1,fitViewOptions:vt,nodesDraggable:kt=!0,nodesConnectable:Mt=!0,elementsSelectable:Nt=!0,multiSelectionKeyCode:mt="Shift",selectionOnDrag:Qt=!1,selectionMode:Re="partial",connectionMode:St="loose",connectionRadius:Xt=20,connectOnClick:At=!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 gt=a.useRef(null),Ee=a.useRef(null),Ct=a.useRef(null),ht=a.useRef({...pt}),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:pt.x,y:pt.y,zoom:pt.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:C,onEdgeMouseEnter:R,onEdgeMouseMove:T,onEdgeMouseLeave:E,onEdgeContextMenu:N,onNodeDoubleClick:W,onNodeMouseEnter:H,onNodeMouseMove:x,onNodeMouseLeave:h,onNodeContextMenu:p,onPaneClick:b,onPaneContextMenu:w,onPaneMouseEnter:I,onPaneMouseMove:$,onPaneMouseLeave:k,onSelectionChange:j,onConnectStart:U,onConnectEnd:D,onInit:st,onMoveStart:et,onMove:ct,onMoveEnd:G,onDelete:q,onBeforeDelete:ot,onError:nt,isValidConnection:lt};const bt={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=Ct.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})},[]),Ht=a.useCallback(()=>{var m;if(Bt.current)return;const c=Q(Zt.current);(m=Ct.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=Ct.current)==null||f.postMessage({type:"nodes",data:{nodes:m}})},[e,ve,Q]),a.useEffect(()=>{var c;Pt.current=[...n],(c=Ct.current)==null||c.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const it=a.useCallback((c,m)=>{const f=gt.current;if(!f)return{x:0,y:0};const M=f.getBoundingClientRect(),S=ht.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=ht.current,S=Math.max(Hr,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/ht.current.zoom;for(let S=Pt.current.length-1;S>=0;S--){const L=Pt.current[S],y=O.current.find(wt=>wt.id===L.source),A=O.current.find(wt=>wt.id===L.target);if(!y||!A)continue;const B=y.width||Gt,X=y.height||Ft,_=A.height||Ft,K=y.position.x+B,at=y.position.y+X/2,Y=A.position.x,tt=A.position.y+_/2;if(Ar(c,m,K,at,Y,tt)<M)return L}return null},[]);a.useEffect(()=>{const c=Ee.current,m=gt.current;if(!c||!m)return;const f=m.getBoundingClientRect(),M=ut!==void 0?ut: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:ht.current,cards:Jt.current,nodes:L,edges:Pt.current,dark:M,gridSize:zt,edgeRouting:ie});y.onmessage=_=>{var K,at;_.data.type==="hud"&&((K=le.current)==null||K.call(le,_.data.data)),_.data.type==="ready"&&hn(!0),_.data.type==="nodesProcessed"&&((at=ue.current)==null||at.call(ue,_.data.data))},Ct.current=y;const A=new ResizeObserver(_=>{const{width:K,height:at}=_[0].contentRect;y.postMessage({type:"resize",data:{width:K,height:at}})});A.observe(m);let B,X;return ut===void 0&&(B=matchMedia("(prefers-color-scheme: dark)"),X=_=>y.postMessage({type:"theme",data:{dark:_.matches}}),B.addEventListener("change",X)),()=>{A.disconnect(),B&&X&&B.removeEventListener("change",X),Ct.current=null}},[]),a.useEffect(()=>{var c;ut!==void 0&&((c=Ct.current)==null||c.postMessage({type:"theme",data:{dark:ut}}))},[ut]),a.useEffect(()=>{var c;(c=Ct.current)==null||c.postMessage({type:"edgeRouting",data:{enabled:ie}})},[ie]);const Ln=a.useRef(0),Et=a.useCallback((c=null)=>{var M,S,L;const m=ht.current;if(Kt){const y=gt.current;if(y){const A=y.getBoundingClientRect(),B=-Kt[1][0]*m.zoom+A.width,X=-Kt[1][1]*m.zoom+A.height,_=-Kt[0][0]*m.zoom,K=-Kt[0][1]*m.zoom;m.x=Math.min(_,Math.max(B,m.x)),m.y=Math.min(K,Math.max(X,m.y))}}(M=Ct.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=Ct.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=Ct.current)==null||M.postMessage({type:"connecting",data:null}),ee(null))},[]),Me=a.useCallback(()=>{var m,f;const c=te.current;c?(m=Ct.current)==null||m.postMessage({type:"selectionBox",data:c}):(f=Ct.current)==null||f.postMessage({type:"selectionBox",data:null})},[]),hr=a.useCallback(c=>{var S,L,y,A,B,X,_,K,at,Y,tt,xt,wt,Tt,Dt,$t;const m=O.current.length>0,f=it(c.clientX,c.clientY),M=_t.current;if(m&&Mt){const F=Ze(f.x,f.y);if(At&&pe.current&&F){const V=pe.current;if(F.nodeId!==V.nodeId){const Wt=V.handleType==="target"?{source:F.nodeId,target:V.nodeId,sourceHandle:F.handleId||null,targetHandle:V.handleId}:{source:V.nodeId,target:F.nodeId,sourceHandle:V.handleId,targetHandle:F.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"?F&&F.type==="source":F!=null){if(At){pe.current={nodeId:F.nodeId,handleId:F.handleId||null,handleType:F.type},(y=(L=Z.current).onConnectStart)==null||y.call(L,c,{nodeId:F.nodeId,handleId:F.handleId,handleType:F.type});return}jt.current={sourceId:F.nodeId,sourceHandle:F.handleId||null,sourceType:F.type,startPos:{x:F.x,y:F.y}},xe.current={x:f.x,y:f.y},(A=gt.current)==null||A.setPointerCapture(c.pointerId),(X=(B=Z.current).onConnectStart)==null||X.call(B,c,{nodeId:F.nodeId,handleId:F.handleId,handleType:F.type}),we();return}}if(m){const F=It(f.x,f.y);if(F){if(bt.current&&Nt){const Rt=[];if(M)Rt.push({id:F.id,type:"select",selected:!F.selected});else if(!F.selected){for(const V of O.current)V.id===F.id?Rt.push({id:V.id,type:"select",selected:!0}):V.selected&&Rt.push({id:V.id,type:"select",selected:!1});if(Lt.current){const V=Pt.current.filter(J=>J.selected).map(J=>({id:J.id,type:"select",selected:!1}));V.length&&Lt.current(V)}}if(Rt.length){if(bt.current(Rt),un&&!M){const V=O.current.findIndex(J=>J.id===F.id);V>=0&&V<O.current.length-1&&bt.current([{id:F.id,type:"remove"},{type:"add",item:{...O.current[V],selected:!0}}])}qt()}}if((_=Pe.current)==null||_.call(Pe,c,F),kt){const Rt=M&&F.selected;let V=null;if(F.parentId&&F.extent==="parent"){const J=O.current.find(Wt=>Wt.id===F.parentId);if(J){const Wt=J.width||Gt,$e=J.height||Ft,Qe=F.width||((K=F.measured)==null?void 0:K.width)||Gt,Be=F.height||((at=F.measured)==null?void 0:at.height)||Ft;V={minX:0,minY:0,maxX:Wt-Qe,maxY:$e-Be}}}if(Bt.current={id:F.id,startPos:{...F.position},startMouse:{x:f.x,y:f.y},parentClamp:V,parentId:F.parentId||null,selectedStarts:Rt?O.current.filter(J=>J.selected&&J.id!==F.id).map(J=>{var $e,Qe;let Wt=null;if(J.parentId&&J.extent==="parent"){const Be=O.current.find(yn=>yn.id===J.parentId);if(Be){const yn=Be.width||Gt,Rr=Be.height||Ft,kr=J.width||(($e=J.measured)==null?void 0:$e.width)||Gt,Cr=J.height||((Qe=J.measured)==null?void 0:Qe.height)||Ft;Wt={minX:0,minY:0,maxX:yn-kr,maxY:Rr-Cr}}}return{id:J.id,startPos:{...J.position},parentClamp:Wt,parentId:J.parentId||null}}):[]},(Y=gt.current)==null||Y.setPointerCapture(c.pointerId),(tt=Ie.current)==null||tt.call(Ie,c,F),bt.current){const J=[{id:F.id,type:"position",dragging:!0}];for(const Wt of Bt.current.selectedStarts)J.push({id:Wt.id,type:"position",dragging:!0});bt.current(J)}}return}}if(Pt.current.length>0&&Nt){const F=oe(f.x,f.y);if(F){if(Lt.current){const Rt=[];if(M)Rt.push({id:F.id,type:"select",selected:!F.selected});else{for(const V of Pt.current)V.id===F.id?Rt.push({id:V.id,type:"select",selected:!0}):V.selected&&Rt.push({id:V.id,type:"select",selected:!1});if(bt.current){const V=O.current.filter(J=>J.selected).map(J=>({id:J.id,type:"select",selected:!1}));V.length&&bt.current(V)}}Rt.length&&(Lt.current(Rt),qt())}(xt=re.current)==null||xt.call(re,c,F);return}}if(!M){const F=O.current.filter(V=>V.selected).map(V=>({id:V.id,type:"select",selected:!1})),Rt=Pt.current.filter(V=>V.selected).map(V=>({id:V.id,type:"select",selected:!1}));F.length&&bt.current&&bt.current(F),Rt.length&&Lt.current&&Lt.current(Rt),(F.length||Rt.length)&&qt()}if((wt=Te.current)==null||wt.call(Te,c),Qt||M){te.current={startWorld:{...f},endWorld:{...f}},(Tt=gt.current)==null||Tt.setPointerCapture(c.pointerId),Me();return}ze.current=!0,Ot.current={x:c.clientX,y:c.clientY},(Dt=gt.current)==null||Dt.classList.add("dragging"),($t=gt.current)==null||$t.setPointerCapture(c.pointerId)},[it,It,Ze,oe,kt,Mt,Nt,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 S=gt.current;if(S){const L=S.getBoundingClientRect(),y=40,A=c.clientX-L.left,B=c.clientY-L.top;let X=0,_=0;A<y?X=Yt:A>L.width-y&&(X=-Yt),B<y?_=Yt:B>L.height-y&&(_=-Yt),(X||_)&&(ht.current.x+=X,ht.current.y+=_,Et(c))}}return}if(te.current){te.current.endWorld=it(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(bt.current){const X=[];for(const _ of O.current){if(_.hidden)continue;const K=_.width||Gt,at=_.height||Ft,Y=Re==="full"?_.position.x>=L&&_.position.x+K<=A&&_.position.y>=y&&_.position.y+at<=B:_.position.x+K>L&&_.position.x<A&&_.position.y+at>y&&_.position.y<B;Y!==!!_.selected&&X.push({id:_.id,type:"select",selected:Y})}X.length&&bt.current(X)}return}if(Bt.current){const S=it(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 tt={x:Y.startPos.x+y,y:Y.startPos.y+A};if(fe&&(tt=vn(tt,se)),Vt&&(tt=bn(tt,Vt)),Y.parentClamp){const xt=Y.parentClamp;tt={x:Math.max(xt.minX,Math.min(tt.x,xt.maxX)),y:Math.max(xt.minY,Math.min(tt.y,xt.maxY))}}X.push({id:Y.id,position:tt})}const _=[];for(const Y of X){const tt=O.current.find(xt=>xt.id===Y.id);if(tt){tt.position=Y.position,tt.dragging=!0;let xt=Y.position;if(tt.parentId){let wt=O.current.find($t=>$t.id===tt.parentId),Tt=Y.position.x,Dt=Y.position.y;for(;wt;)Tt+=wt.position.x,Dt+=wt.position.y,wt=wt.parentId?O.current.find($t=>$t.id===wt.parentId):null;xt={x:Tt,y:Dt}}_.push({id:Y.id,position:Y.position,_absolutePosition:xt,width:tt.width,height:tt.height,dragging:!0,selected:tt.selected})}}const K=new Set(X.map(Y=>Y.id));for(const Y of O.current)if(Y.parentId&&K.has(Y.parentId)&&!K.has(Y.id)){let tt=O.current.find(Tt=>Tt.id===Y.parentId),xt=Y.position.x,wt=Y.position.y;for(;tt;)xt+=tt.position.x,wt+=tt.position.y,tt=tt.parentId?O.current.find(Tt=>Tt.id===tt.parentId):null;_.push({id:Y.id,position:Y.position,_absolutePosition:{x:xt,y:wt},width:Y.width,height:Y.height,dragging:!1,selected:Y.selected})}if((f=Ct.current)==null||f.postMessage({type:"nodePositions",data:{updates:_}}),cn){const Y=gt.current;if(Y){const tt=Y.getBoundingClientRect(),xt=40,wt=c.clientX-tt.left,Tt=c.clientY-tt.top;let Dt=0,$t=0;wt<xt?Dt=Yt:wt>tt.width-xt&&(Dt=-Yt),Tt<xt?$t=Yt:Tt>tt.height-xt&&($t=-Yt),(Dt||$t)&&(ht.current.x+=Dt,ht.current.y+=$t,Et(c))}}const at=O.current.find(Y=>Y.id===L.id);at&&((M=Se.current)==null||M.call(Se,c,at));return}if(!ze.current)return;const m=ht.current;m.x+=c.clientX-Ot.current.x,m.y+=c.clientY-Ot.current.y,Ot.current={x:c.clientX,y:c.clientY},Et()},[Et,it,we,Me]),gr=a.useCallback(c=>{var m,f,M,S,L;if(jt.current){const y=it(c.clientX,c.clientY),A=Ze(y.x,y.y);if(A&&A.nodeId!==jt.current.sourceId&&(St==="loose"||A.type==="target")){const _=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(_):!0)&&((m=ne.current)==null||m.call(ne,{..._,...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(bt.current){const B=O.current.find(_=>_.id===y.id),X=[{id:y.id,type:"position",position:B?{...B.position}:void 0,dragging:!1}];for(const _ of y.selectedStarts){const K=O.current.find(at=>at.id===_.id);X.push({id:_.id,type:"position",position:K?{...K.position}:void 0,dragging:!1})}bt.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=gt.current)==null||L.classList.remove("dragging")},[it,Ze,we,Me,qt]);a.useEffect(()=>{const c=gt.current;if(!c)return;const m=f=>{Ce&&f.preventDefault();const M=ht.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),Et(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(yt,Math.max(rt,M.zoom*S)),Et(f)};return c.addEventListener("wheel",m,{passive:!Ce}),()=>c.removeEventListener("wheel",m)},[Et,rt,yt,Fe,ke,Xe,Ye,Ce]),a.useEffect(()=>{if(!qe)return;const c=gt.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),_=X/m;m=X;const K=ht.current,at=f.x,Y=f.y;K.x=at-(at-K.x)*_,K.y=Y-(Y-K.y)*_,K.zoom=Math.min(yt,Math.max(rt,K.zoom*_)),Et(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,Et,rt,yt]),a.useEffect(()=>{if(!Ue)return;const c=gt.current;if(!c)return;const m=f=>{var _,K,at,Y;const M=it(f.clientX,f.clientY);if(It(M.x,M.y)){(K=(_=Z.current).onNodeDoubleClick)==null||K.call(_,f,It(M.x,M.y));return}const S=oe(M.x,M.y);if(S){(Y=(at=Z.current).onEdgeDoubleClick)==null||Y.call(at,f,S);return}const L=1.5,y=c.getBoundingClientRect(),A=f.clientX-y.left,B=f.clientY-y.top,X=ht.current;X.x=A-(A-X.x)*L,X.y=B-(B-X.y)*L,X.zoom=Math.min(yt,Math.max(rt,X.zoom*L)),Et(f)};return c.addEventListener("dblclick",m),()=>c.removeEventListener("dblclick",m)},[Ue,Et,rt,yt,it,It,oe]),a.useEffect(()=>{const c=gt.current;if(!c)return;const m=f=>{var y,A,B,X,_,K;const M=it(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}(K=(_=Z.current).onPaneContextMenu)==null||K.call(_,f)};return c.addEventListener("contextmenu",m),()=>c.removeEventListener("contextmenu",m)},[it,It,oe]),a.useEffect(()=>{const c=gt.current;if(!c)return;let m=null,f=null;const M=y=>{var X,_,K,at,Y,tt,xt,wt,Tt,Dt,$t,F,Rt,V;(_=(X=Z.current).onPaneMouseMove)==null||_.call(X,y);const A=it(y.clientX,y.clientY),B=It(A.x,A.y);if(B!==m&&(m&&((at=(K=Z.current).onNodeMouseLeave)==null||at.call(K,y,m)),B&&((tt=(Y=Z.current).onNodeMouseEnter)==null||tt.call(Y,y,B)),m=B),B&&((wt=(xt=Z.current).onNodeMouseMove)==null||wt.call(xt,y,B)),!B){const J=oe(A.x,A.y);J!==f&&(f&&((Dt=(Tt=Z.current).onEdgeMouseLeave)==null||Dt.call(Tt,y,f)),J&&((F=($t=Z.current).onEdgeMouseEnter)==null||F.call($t,y,J)),f=J),J&&((V=(Rt=Z.current).onEdgeMouseMove)==null||V.call(Rt,y,J))}},S=y=>{var A,B;return(B=(A=Z.current).onPaneMouseEnter)==null?void 0:B.call(A,y)},L=y=>{var A,B,X,_,K,at;(B=(A=Z.current).onPaneMouseLeave)==null||B.call(A,y),m&&((_=(X=Z.current).onNodeMouseLeave)==null||_.call(X,y,m),m=null),f&&((at=(K=Z.current).onEdgeMouseLeave)==null||at.call(K,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)}},[it,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&&bt.current&&(bt.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(),bt.current){const L=O.current.filter(y=>!y.selected).map(y=>({id:y.id,type:"select",selected:!0}));L.length&&bt.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&&Ct.current){if(Tn.current=!0,dt&&O.current.length>0){const f=gt.current;if(f){const M=f.getBoundingClientRect(),S=(vt==null?void 0:vt.padding)??.1,L=Ve(O.current),y=Je(L,M.width,M.height,S);vt!=null&&vt.maxZoom&&(y.zoom=Math.min(y.zoom,vt.maxZoom)),vt!=null&&vt.minZoom&&(y.zoom=Math.max(y.zoom,vt.minZoom)),ht.current=y,Et()}}(m=(c=Z.current).onInit)==null||m.call(c,{getNodes:()=>[...O.current],getEdges:()=>[...Pt.current],getViewport:()=>({...ht.current}),fitView:(f={})=>{const M=gt.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);ht.current=y,Et()}})}});const xr=a.useCallback(()=>{ht.current={...pt},Et()},[Et,pt]),pr=a.useCallback(c=>{var m;if(c)Jt.current.push(c);else{const f=ht.current,M=gt.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=Ct.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=ht.current,f=gt.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}),bt.current&&bt.current([{type:"add",item:c}])},[]),vr=a.useCallback(()=>({...ht.current}),[]),br=a.useCallback(c=>{ht.current={...ht.current,...c},Et()},[Et]),wr=a.useCallback(c=>it(c.x,c.y),[it]),$n=n,Mr=a.useMemo(()=>({wrapRef:gt,canvasRef:Ee,workerRef:Ct,cameraRef:ht,nodesRef:O,edgesRef:Pt,handleRegistryRef:dn,syncNodesToWorker:Ht,onNodesChangeRef:bt,onEdgesChangeRef:Lt,sendCamera:Et,screenToWorld:it,viewportListeners:Ut,selectionListeners:ae,zoomMin:rt,zoomMax:yt,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,Et,it,Ht,Ut,ae,rt,yt,fe,se,Vt,ge,ie]);return{wrapRef:gt,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 Ar(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,C;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(E=>{var H,x,h,p;const{width:N,height:W}=E[0].contentRect;if(N>0&&W>0){const b=n.nodesRef.current.find($=>$.id===t.id),w=(b==null?void 0:b.width)||((H=b==null?void 0:b.measured)==null?void 0:H.width),I=(b==null?void 0:b.height)||((x=b==null?void 0:b.measured)==null?void 0:x.height);(Math.abs((w||0)-N)>1||Math.abs((I||0)-W)>1)&&((p=(h=n.onNodesChangeRef).current)==null||p.call(h,[{id:t.id,type:"dimensions",dimensions:{width:N,height:W},setAttributes:!0}]))}});return T.observe(R),()=>T.disconnect()},[t.id,n]);const i=a.useCallback(R=>{var k,j,U;R.stopPropagation();let T=R.target;for(;T&&T!==r.current;){if((k=T.classList)!=null&&k.contains("nodrag"))return;T=T.parentElement}if(n.onNodesChangeRef.current){const D=[];if(R.shiftKey)D.push({id:t.id,type:"select",selected:!t.selected});else for(const et of n.nodesRef.current)et.id===t.id&&!et.selected?D.push({id:et.id,type:"select",selected:!0}):et.id!==t.id&&et.selected&&D.push({id:et.id,type:"select",selected:!1});D.length&&n.onNodesChangeRef.current(D)}const E=n.cameraRef.current,N=n.wrapRef.current;if(!N)return;const W=N.getBoundingClientRect(),H=(R.clientX-W.left-E.x)/E.zoom,x=(R.clientY-W.top-E.y)/E.zoom,p=R.shiftKey&&t.selected?n.nodesRef.current.filter(D=>D.selected&&D.id!==t.id).map(D=>({id:D.id,startPos:{...D.position}})):[];o.current={startPos:{...t.position},startMouse:{x:H,y:x},selectedStarts:p};const b=[{id:t.id,type:"position",dragging:!0}];for(const D of p)b.push({id:D.id,type:"position",dragging:!0});(U=(j=n.onNodesChangeRef).current)==null||U.call(j,b);const w=r.current;w&&w.setPointerCapture(R.pointerId);const I=D=>{var ut,zt,rt,yt;if(!o.current)return;const st=n.cameraRef.current,et=N.getBoundingClientRect(),ct=(D.clientX-et.left-st.x)/st.zoom,G=(D.clientY-et.top-st.y)/st.zoom,q=ct-o.current.startMouse.x,ot=G-o.current.startMouse.y;let nt={x:o.current.startPos.x+q,y:o.current.startPos.y+ot};if(n.snapToGrid&&n.snapGrid&&(nt={x:n.snapGrid[0]*Math.round(nt.x/n.snapGrid[0]),y:n.snapGrid[1]*Math.round(nt.y/n.snapGrid[1])}),t.parentId&&t.extent==="parent"){const pt=n.nodesRef.current.find(dt=>dt.id===t.parentId);if(pt){const dt=pt.width||160,vt=pt.height||60,kt=t.width||((ut=t.measured)==null?void 0:ut.width)||160,Mt=t.height||((zt=t.measured)==null?void 0:zt.height)||60;nt={x:Math.max(0,Math.min(nt.x,dt-kt)),y:Math.max(0,Math.min(nt.y,vt-Mt))}}}const lt=[{id:t.id,type:"position",position:nt,dragging:!0}];for(const pt of o.current.selectedStarts){let dt={x:pt.startPos.x+q,y:pt.startPos.y+ot};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])}),lt.push({id:pt.id,type:"position",position:dt,dragging:!0})}(yt=(rt=n.onNodesChangeRef).current)==null||yt.call(rt,lt)},$=D=>{var et,ct;if(!o.current)return;const st=[{id:t.id,type:"position",dragging:!1}];for(const G of o.current.selectedStarts)st.push({id:G.id,type:"position",dragging:!1});(ct=(et=n.onNodesChangeRef).current)==null||ct.call(et,st),o.current=null,w&&w.releasePointerCapture(D.pointerId),w==null||w.removeEventListener("pointermove",I),w==null||w.removeEventListener("pointerup",$)};w==null||w.addEventListener("pointermove",I),w==null||w.addEventListener("pointerup",$)},[t,n]),l=a.useCallback(R=>{var x,h,p,b,w,I;if(!t.selected)return;const T=R.shiftKey?10:1;let E=0,N=0;switch(R.key){case"ArrowUp":N=-T;break;case"ArrowDown":N=T;break;case"ArrowLeft":E=-T;break;case"ArrowRight":E=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 W={x:t.position.x+E,y:t.position.y+N},H=[{id:t.id,type:"position",position:W}];for(const $ of n.nodesRef.current)$.selected&&$.id!==t.id&&H.push({id:$.id,type:"position",position:{x:$.position.x+E,y:$.position.y+N}});(I=(w=n.onNodesChangeRef).current)==null||I.call(w,H)},[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 z.jsx(_e.Provider,{value:t.id,children:z.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 ${((C=t.data)==null?void 0:C.label)||t.id}`,"aria-selected":!!t.selected,onPointerDown:i,onKeyDown:l,children:z.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 z.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,w,I,$)=>{var ct;w.stopPropagation(),w.preventDefault();const k=s.wrapRef.current;if(!k)return;const j=b==="source"?$:I,U=b==="source"?t.target:t.source;(ct=s.workerRef.current)==null||ct.postMessage({type:"connecting",data:{from:{x:j.x,y:j.y},to:{x:j.x,y:j.y}}});const D=k.getBoundingClientRect(),st=G=>{var lt;const q=s.cameraRef.current,ot=(G.clientX-D.left-q.x)/q.zoom,nt=(G.clientY-D.top-q.y)/q.zoom;(lt=s.workerRef.current)==null||lt.postMessage({type:"connecting",data:{from:{x:j.x,y:j.y},to:{x:ot,y:nt}}})},et=G=>{var yt,pt,dt,vt;const q=s.cameraRef.current,ot=(G.clientX-D.left-q.x)/q.zoom,nt=(G.clientY-D.top-q.y)/q.zoom,lt=20/q.zoom;let ut=null,zt=null;const rt=(yt=s.handleRegistryRef)==null?void 0:yt.current;for(const kt of s.nodesRef.current){if(kt.hidden)continue;const Mt=kt.width||Qn,Nt=kt.height||Kn,mt=kt._absolutePosition||kt.position,Qt=[];if(rt)for(const[,St]of rt)St.nodeId===kt.id&&Qt.push(St);const Re=Qt.length>0?Qt:kt.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const St of Re){let Xt,At;if(St.x!==void 0&&St.y!==void 0)Xt=mt.x+St.x,At=mt.y+St.y;else switch(St.position||(St.type==="source"?"right":"left")){case"top":Xt=mt.x+Mt/2,At=mt.y;break;case"bottom":Xt=mt.x+Mt/2,At=mt.y+Nt;break;case"left":Xt=mt.x,At=mt.y+Nt/2;break;default:Xt=mt.x+Mt,At=mt.y+Nt/2;break}if(Math.abs(ot-Xt)<lt&&Math.abs(nt-At)<lt){ut=kt,zt=St.id||null;break}}if(ut)break}if(ut){const kt=b==="source"?{source:ut.id,target:U,sourceHandle:zt,targetHandle:t.targetHandle}:{source:U,target:ut.id,sourceHandle:t.sourceHandle,targetHandle:zt};(dt=(pt=s.onEdgesChangeRef).current)==null||dt.call(pt,[{id:t.id,type:"remove"},{type:"add",item:{id:t.id,...kt}}])}(vt=s.workerRef.current)==null||vt.postMessage({type:"connecting",data:null}),k.removeEventListener("pointermove",st),k.removeEventListener("pointerup",et)};k.addEventListener("pointermove",st),k.addEventListener("pointerup",et)},[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,C=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",E=s.routedEdges||s.edges,N=E==null?void 0:E.find(b=>b.id===t.id),W=T?null:(N==null?void 0:N._routedPoints)||t._routedPoints||null,H=r!==!1&&t.reconnectable!==!1;return!C||!R?null:z.jsxs("g",{className:`ric-edge-wrapper ${t.selected?"selected":""}`,"data-edgeid":t.id,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),children:[z.jsx(e,{id:t.id,source:t.source,target:t.target,sourceX:C.x,sourceY:C.y,targetX:R.x,targetY:R.y,sourcePosition:C.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:W}),H&&(o||t.selected)&&z.jsxs(z.Fragment,{children:[z.jsx(Dn,{x:C.x,y:C.y,position:C.position,type:"source",onPointerDown:b=>l("source",b,C,R)}),z.jsx(Dn,{x:R.x,y:R.y,position:R.position,type:"target",onPointerDown:b=>l("target",b,C,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 E=n.wrapRef.current;if(!E)return;let N=!1,W=null,H=!1;const x=I=>{I.key===t&&(H=!0)},h=I=>{I.key===t&&(H=!1)},p=I=>{if(!H)return;const $=I.target;if($.closest(".ric-node-wrapper")||$.closest(".ric-handle"))return;N=!0;const k=n.cameraRef.current,j=E.getBoundingClientRect(),U=(I.clientX-j.left-k.x)/k.zoom,D=(I.clientY-j.top-k.y)/k.zoom;W={x:U,y:D},s({startX:U,startY:D,endX:U,endY:D}),I.stopPropagation()},b=I=>{if(!N||!W)return;const $=n.cameraRef.current,k=E.getBoundingClientRect(),j=(I.clientX-k.left-$.x)/$.zoom,U=(I.clientY-k.top-$.y)/$.zoom;s({startX:W.x,startY:W.y,endX:j,endY:U})},w=I=>{var et,ct;if(!N||!W)return;N=!1;const $=n.cameraRef.current,k=E.getBoundingClientRect(),j=(I.clientX-k.left-$.x)/$.zoom,U=(I.clientY-k.top-$.y)/$.zoom,D={x:Math.min(W.x,j),y:Math.min(W.y,U),width:Math.abs(j-W.x),height:Math.abs(U-W.y)},st=[];for(const G of n.nodesRef.current){const q=G._absolutePosition||G.position,ot=G.width||160,nt=G.height||60;let lt;e==="full"?lt=q.x>=D.x&&q.y>=D.y&&q.x+ot<=D.x+D.width&&q.y+nt<=D.y+D.height:lt=q.x+ot>D.x&&q.x<D.x+D.width&&q.y+nt>D.y&&q.y<D.y+D.height,st.push({id:G.id,type:"select",selected:lt})}st.length&&((ct=(et=n.onNodesChangeRef).current)==null||ct.call(et,st)),W=null,s(null)};return E.addEventListener("pointerdown",p,!0),E.addEventListener("pointermove",b),E.addEventListener("pointerup",w),window.addEventListener("keydown",x),window.addEventListener("keyup",h),()=>{E.removeEventListener("pointerdown",p,!0),E.removeEventListener("pointermove",b),E.removeEventListener("pointerup",w),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,C=u*i.zoom,R=g*i.zoom;return z.jsx("div",{ref:o,className:"ric-selection-box",style:{position:"absolute",left:v,top:P,width:C,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 Hn(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 Ae({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(),C=a.useRef(null),R=a.useRef(P);R.current=P;const T=a.useCallback(()=>{var I,$,k;const H=C.current;if(!H||!v)return;const x=R.current,h=(I=x.handleRegistryRef)==null?void 0:I.current;if(!h)return;const p=`${v}__${n||t}`,b=(k=($=x.cameraRef)==null?void 0:$.current)==null?void 0:k.zoom,w=Gr(H,b);if(w){const j={nodeId:v,id:n||null,type:t,position:e,x:w.x,y:w.y};h.set(p,j)}},[v,n,t,e]);a.useLayoutEffect(()=>{T()},[T]),a.useEffect(()=>{if(!v)return;const H=R.current;Hn(H,v);const x=C.current,h=x==null?void 0:x.closest(".ric-node-wrapper"),p=new ResizeObserver(()=>{T(),Hn(R.current,v)});return h&&p.observe(h),()=>{var $;p.disconnect();const b=R.current,w=($=b.handleRegistryRef)==null?void 0:$.current,I=`${v}__${n||t}`;w==null||w.delete(I),tr(b,v)}},[v,n,t,e,T]);const E=a.useCallback(()=>{var k;const H=R.current,x=H.nodesRef.current.find(j=>j.id===v);if(!x)return null;const h=x._absolutePosition||x.position,p=(k=H.handleRegistryRef)==null?void 0:k.current,b=`${v}__${n||t}`,w=p==null?void 0:p.get(b);if(w&&w.x!==void 0&&w.y!==void 0)return{x:h.x+w.x,y:h.y+w.y};const I=x.width||160,$=x.height||60;switch(e){case"top":return{x:h.x+I/2,y:h.y};case"bottom":return{x:h.x+I/2,y:h.y+$};case"left":return{x:h.x,y:h.y+$/2};default:return{x:h.x+I,y:h.y+$/2}}},[v,n,t,e]),N=a.useCallback(H=>{var U;if(!r||!s)return;H.stopPropagation(),H.preventDefault();const x=R.current,h=x.cameraRef.current,p=x.wrapRef.current;if(!p)return;const b=p.getBoundingClientRect(),w=E();if(!w)return;const I=w.x,$=w.y;(U=x.workerRef.current)==null||U.postMessage({type:"connecting",data:{from:{x:I,y:$},to:{x:I,y:$}}}),p.setPointerCapture(H.pointerId);const k=D=>{var ct;const st=(D.clientX-b.left-h.x)/h.zoom,et=(D.clientY-b.top-h.y)/h.zoom;(ct=x.workerRef.current)==null||ct.postMessage({type:"connecting",data:{from:{x:I,y:$},to:{x:st,y:et}}})},j=D=>{var nt,lt,ut,zt;const st=(D.clientX-b.left-h.x)/h.zoom,et=(D.clientY-b.top-h.y)/h.zoom,ct=20/h.zoom;let G=null,q=null;const ot=(nt=x.handleRegistryRef)==null?void 0:nt.current;for(const rt of x.nodesRef.current){if(rt.id===v||rt.hidden)continue;const yt=rt.width||160,pt=rt.height||60,dt=rt._absolutePosition||rt.position,vt=[];if(ot)for(const[,Mt]of ot)Mt.nodeId===rt.id&&vt.push(Mt);const kt=vt.length>0?vt:rt.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const Mt of kt){let Nt,mt;if(Mt.x!==void 0&&Mt.y!==void 0)Nt=dt.x+Mt.x,mt=dt.y+Mt.y;else switch(Mt.position||(Mt.type==="source"?"right":"left")){case"top":Nt=dt.x+yt/2,mt=dt.y;break;case"bottom":Nt=dt.x+yt/2,mt=dt.y+pt;break;case"left":Nt=dt.x,mt=dt.y+pt/2;break;default:Nt=dt.x+yt,mt=dt.y+pt/2;break}if(Math.abs(st-Nt)<ct&&Math.abs(et-mt)<ct){G=rt,q=Mt.id||null;break}}if(G)break}if(G){const rt={source:t==="source"?v:G.id,target:t==="source"?G.id:v,sourceHandle:t==="source"?n||null:q,targetHandle:t==="source"?q:n||null};(ut=(lt=x.onEdgesChangeRef)==null?void 0:lt.current)==null||ut.call(lt,[{type:"add",item:{id:`e-${rt.source}-${rt.target}`,...rt}}])}(zt=x.workerRef.current)==null||zt.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,E]),W={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 z.jsx("div",{ref:C,className:`ric-handle ric-handle-${e} ric-handle-${t} ${l}`,"data-handleid":n||null,"data-nodeid":v,"data-handlepos":e,"data-handletype":t,onPointerDown:N,style:{position:"absolute",width:8,height:8,borderRadius:"50%",background:"#1a192b",border:"none",zIndex:10,cursor:r?"crosshair":"default",boxSizing:"border-box",...W,...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 z.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&&z.jsx(Ae,{type:"target",position:r,isConnectable:e}),z.jsx("div",{className:"ric-node-content",children:t==null?void 0:t.label}),!o&&z.jsx(Ae,{type:"source",position:s,isConnectable:e})]})}function er({data:t,isConnectable:e,selected:n,sourcePosition:r="right",hideSourceHandle:s=!1}){return z.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:[z.jsx("div",{className:"ric-node-content",children:t==null?void 0:t.label}),!s&&z.jsx(Ae,{type:"source",position:r,isConnectable:e})]})}function nr({data:t,isConnectable:e,selected:n,targetPosition:r="left",hideTargetHandle:s=!1}){return z.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&&z.jsx(Ae,{type:"target",position:r,isConnectable:e}),z.jsx("div",{className:"ric-node-content",children:t==null?void 0:t.label})]})}function rr({data:t,selected:e,width:n,height:r}){return z.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)&&z.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}),C=a.useRef(null);return a.useEffect(()=>{if(C.current){const R=C.current.getBBox();P({x:R.x,y:R.y,width:R.width,height:R.height})}},[n]),n?z.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&&z.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}),z.jsx("text",{className:"ric-edge-text",y:v.height/2,dy:"0.3em",ref:C,style:r,children:n}),d]}):null}or.displayName="EdgeText";const sr=a.memo(or);function An(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:C,className:R="",...T}){return z.jsxs(z.Fragment,{children:[z.jsx("path",{id:t,d:e,fill:"none",stroke:"#b1b1b7",strokeWidth:1.5,className:`ric-edge-path ${R}`,style:v,markerEnd:P,markerStart:C,...T}),g?z.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:g,className:"ric-edge-interaction",style:{pointerEvents:"stroke"}}):null,s&&An(n)&&An(r)?z.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:C,style:R,markerEnd:T,markerStart:E,interactionWidth:N}){let W,H,x;const h=_n(n,r,i),p=_n(s,o,l),b=Math.abs(p.x-h.x),w=Math.max(50,b*.5);let I,$,k,j;switch(i){case"left":I=h.x-w,$=h.y;break;case"top":I=h.x,$=h.y-w;break;case"bottom":I=h.x,$=h.y+w;break;default:I=h.x+w,$=h.y;break}switch(l){case"right":k=p.x+w,j=p.y;break;case"top":k=p.x,j=p.y-w;break;case"bottom":k=p.x,j=p.y+w;break;default:k=p.x-w,j=p.y;break}W=`M ${n},${r} L ${h.x},${h.y} C ${I},${$} ${k},${j} ${p.x},${p.y} L ${s},${o}`;const U=.5,D=.5;return H=D*D*D*h.x+3*D*D*U*I+3*D*U*U*k+U*U*U*p.x,x=D*D*D*h.y+3*D*D*U*$+3*D*U*U*j+U*U*U*p.y,z.jsx(We,{id:e,path:W,labelX:H,labelY:x,label:d,labelStyle:u,labelShowBg:g,labelBgStyle:v,labelBgPadding:P,labelBgBorderRadius:C,style:R,markerEnd:T,markerStart:E,interactionWidth:N})});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,C,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":C=n,R=r-g;break;case"bottom":C=n,R=r+g;break;case"right":C=n+g,R=r;break;default:C=n-g,R=r;break}const T=`M ${t},${e} C ${v},${P} ${C},${R} ${n},${r}`,E=.5,N=1-E,W=N*N*N*t+3*N*N*E*v+3*N*E*E*C+E*E*E*n,H=N*N*N*e+3*N*N*E*P+3*N*E*E*R+E*E*E*r;return[T,W,H,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 C=(t+n)/2,R=r>e?1:-1;return[`M ${t},${e} L ${C-u},${e} Q ${C},${e} ${C},${e+R*u} L ${C},${r-R*u} Q ${C},${r} ${C+(n>C?u:-u)},${r} L ${n},${r}`,C,(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 C=(t+n)/2,R=(e+r)/2;if(C>s+P&&C<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 E=0;E<4;E++)if(Jr(t,e,n,r,T[E][0],T[E][1],T[(E+1)%4][0],T[(E+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,C=d.get(t.x),R=u.get(t.y),T=d.get(e.x),E=u.get(e.y);if(C===void 0||R===void 0||T===void 0||E===void 0)return null;const N=P(C,R),W=P(T,E),H=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);H[N]=0,x[N]=Math.abs(i[T]-t.x)+Math.abs(l[E]-t.y);const w=[N],I=15,$=[[1,0],[-1,0],[0,1],[0,-1]];for(;w.length>0;){let k=0;for(let G=1;G<w.length;G++)x[w[G]]<x[w[k]]&&(k=G);const j=w[k];if(w[k]=w[w.length-1],w.pop(),j===W){const G=[];let q=W;for(;q!==-1&&q!==N;){const ot=q/g|0,nt=q%g;G.unshift({x:i[nt],y:l[ot]}),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,D=j%g,st=i[D],et=l[U],ct=p[j];for(let G=0;G<4;G++){const q=D+$[G][0],ot=U+$[G][1];if(q<0||q>=g||ot<0||ot>=v)continue;const nt=P(q,ot);if(b[nt])continue;const lt=i[q],ut=l[ot];if(to(lt,ut,n)||!wn(st,et,lt,ut,n))continue;const zt=Math.abs(lt-st)+Math.abs(ut-et),rt=ct>=0&&ct!==G?I:0,yt=H[j]+zt+rt;yt<H[nt]&&(h[nt]=j,p[nt]=G,H[nt]=yt,x[nt]=yt+Math.abs(i[T]-lt)+Math.abs(l[E]-ut),w.push(nt))}}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,C=l.y-i.y,R=d.x-l.x,T=d.y-l.y,E=Math.sqrt(P*P+C*C)||1,N=Math.sqrt(R*R+T*T)||1;s+=` L ${l.x-P/E*v},${l.y-C/E*v}`,s+=` Q ${l.x},${l.y} ${l.x+R/N*v},${l.y+T/N*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,w,I;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),C=5,R=r.filter($=>$.id!==o.source&&$.id!==o.target),T=l._absolutePosition||l.position,E=l.width||((p=l.measured)==null?void 0:p.width)||en,N=l.height||((b=l.measured)==null?void 0:b.height)||nn;R.push({id:o.source,x:T.x-C,y:T.y-C,w:E+2*C,h:N+2*C});const W=d._absolutePosition||d.position,H=d.width||((w=d.measured)==null?void 0:w.width)||en,x=d.height||((I=d.measured)==null?void 0:I.height)||nn;if(R.push({id:o.target,x:W.x-C,y:W.y-C,w:H+2*C,h:x+2*C}),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),C=ir(v,P,d);return C&&C.length>=2?(C.unshift({x:u.x,y:u.y}),C.push({x:g.x,y:g.y}),C):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:C,markerStart:R,interactionWidth:T,routedPoints:E}){let N,W,H;if(E&&E.length>=2){N=sn(E);const x=an(E);W=x.x,H=x.y}else[N,W,H]=kn({sourceX:n,sourceY:r,targetX:s,targetY:o});return z.jsx(We,{id:e,path:N,labelX:W,labelY:H,label:i,labelStyle:l,labelShowBg:d,labelBgStyle:u,labelBgPadding:g,labelBgBorderRadius:v,style:P,markerEnd:C,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:C,style:R,markerEnd:T,markerStart:E,pathOptions:N,interactionWidth:W,routedPoints:H}){let x,h,p;if(H&&H.length>=2){x=sn(H);const b=an(H);h=b.x,p=b.y}else[x,h,p]=tn({sourceX:n,sourceY:r,sourcePosition:i,targetX:s,targetY:o,targetPosition:l,borderRadius:N==null?void 0:N.borderRadius,offset:N==null?void 0:N.offset});return z.jsx(We,{id:e,path:x,labelX:h,labelY:p,label:d,labelStyle:u,labelShowBg:g,labelBgStyle:v,labelBgPadding:P,labelBgBorderRadius:C,style:R,markerEnd:T,markerStart:E,interactionWidth:W})});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 z.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:C,style:R,markerEnd:T,markerStart:E,interactionWidth:N,routedPoints:W}){let H,x,h;if(W&&W.length>=2){H=sn(W);const p=an(W);x=p.x,h=p.y}else[H,x,h]=En({sourceX:n,sourceY:r,targetX:s,targetY:o});return z.jsx(We,{id:e,path:H,labelX:x,labelY:h,label:d,labelStyle:u,labelShowBg:g,labelBgStyle:v,labelBgPadding:P,labelBgBorderRadius:C,style:R,markerEnd:T,markerStart:E,interactionWidth:N})});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:C,fitView:R,fitViewOptions:T,onNodesChange:E,onEdgesChange:N,onConnect:W,onConnectStart:H,onConnectEnd:x,onNodeClick:h,onNodeDoubleClick:p,onNodeMouseEnter:b,onNodeMouseMove:w,onNodeMouseLeave:I,onNodeContextMenu:$,onNodeDragStart:k,onNodeDrag:j,onNodeDragStop:U,onEdgeClick:D,onEdgeDoubleClick:st,onEdgeMouseEnter:et,onEdgeMouseMove:ct,onEdgeMouseLeave:G,onEdgeContextMenu:q,onPaneClick:ot,onPaneContextMenu:nt,onPaneMouseEnter:lt,onPaneMouseMove:ut,onPaneMouseLeave:zt,onSelectionChange:rt,onInit:yt,onMoveStart:pt,onMove:dt,onMoveEnd:vt,onDelete:kt,onBeforeDelete:Mt,onError:Nt,onDragOver:mt,onDrop:Qt,onDragEnter:Re,onDragLeave:St,nodesDraggable:Xt,nodesConnectable:At,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:gt,nodeExtent:Ee,autoPanOnNodeDrag:Ct,autoPanOnConnect:ht,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(Ht=>Ht.type&&ee[Ht.type]);return Q.sort((Ht,it)=>{const It=Ht.type==="group"||!Ht.parentId&&Q.some(be=>be.parentId===Ht.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]),bt=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:bt,dark:o,gridSize:i,zoomMin:v,zoomMax:P,initialCamera:C,fitView:R,fitViewOptions:T,onHudUpdate:Oe,onNodesProcessed:fn,onNodesChange:E,onEdgesChange:N,onConnect:W,onConnectStart:H,onConnectEnd:x,onNodeClick:h,onNodeDoubleClick:p,onNodeMouseEnter:b,onNodeMouseMove:w,onNodeMouseLeave:I,onNodeContextMenu:$,onNodeDragStart:k,onNodeDrag:j,onNodeDragStop:U,onEdgeClick:D,onEdgeDoubleClick:st,onEdgeMouseEnter:et,onEdgeMouseMove:ct,onEdgeMouseLeave:G,onEdgeContextMenu:q,onPaneClick:ot,onPaneContextMenu:nt,onPaneMouseEnter:lt,onPaneMouseMove:ut,onPaneMouseLeave:zt,onSelectionChange:rt,onInit:yt,onMoveStart:pt,onMove:dt,onMoveEnd:vt,onDelete:kt,onBeforeDelete:Mt,onError:Nt,nodesDraggable:Xt,nodesConnectable:At,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:gt,nodeExtent:Ee,autoPanOnNodeDrag:Ct,autoPanOnConnect:ht,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 Ht=()=>{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(Ht)};return Q=requestAnimationFrame(Ht),()=>cancelAnimationFrame(Q)},[re]);const ve=ae.length>0,Zt=me.length>0;return z.jsx(Zn.Provider,{value:Te,children:z.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:[z.jsx("canvas",{ref:ne,className:"ric-canvas"}),!Pe&&z.jsx("div",{className:"ric-loader",children:z.jsx("div",{className:"ric-spinner"})}),Zt&&z.jsx("svg",{className:"ric-edges-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:z.jsx("g",{ref:le,children:me.map(Q=>z.jsx(qr,{edge:Q,edgeType:Ut[Q.type],nodes:e,reconnectable:O},Q.id))})}),ve&&z.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=>z.jsx(Fr,{node:Q,nodeType:ee[Q.type]},Q.id))}),z.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}}),z.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&&z.jsx("div",{className:"ric-hint",children:jt}),hn&&z.jsxs("div",{className:"ric-info",children:["world: (",_t.wx,", ",_t.wy,")   zoom: ",_t.zoom,"x",_t.nodeCount>0&&z.jsxs(z.Fragment,{children:["   nodes: ",_t.nodeCount]}),_t.edgeCount>0&&z.jsxs(z.Fragment,{children:["   edges: ",_t.edgeCount]})]}),z.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,w;if(typeof x=="function"){const I=x(t.nodesRef.current);(p=(h=t.onNodesChangeRef).current)==null||p.call(h,[...t.nodesRef.current.map($=>({id:$.id,type:"remove"})),...I.map($=>({type:"add",item:$}))])}else(w=(b=t.onNodesChangeRef).current)==null||w.call(b,[...t.nodesRef.current.map(I=>({id:I.id,type:"remove"})),...x.map(I=>({type:"add",item:I}))])},[t]),i=a.useCallback(x=>{var h,p,b,w;if(typeof x=="function"){const I=x(t.edgesRef.current);(p=(h=t.onEdgesChangeRef).current)==null||p.call(h,[...t.edgesRef.current.map($=>({id:$.id,type:"remove"})),...I.map($=>({type:"add",item:$}))])}else(w=(b=t.onEdgesChangeRef).current)==null||w.call(b,[...t.edgesRef.current.map(I=>({id:I.id,type:"remove"})),...x.map(I=>({type:"add",item:I}))])},[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(w=>({type:"add",item:w})))},[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(w=>({type:"add",item:w})))},[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]),C=a.useCallback(x=>{const h=t.cameraRef.current,p=t.wrapRef.current;if(!p)return;const b=p.getBoundingClientRect(),w=b.width/2,I=b.height/2,$=1.2;h.x=w-(w-h.x)*$,h.y=I-(I-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(),w=b.width/2,I=b.height/2,$=1/1.2;h.x=w-(w-h.x)*$,h.y=I-(I-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(),w=b.width/2,I=b.height/2,$=x/h.zoom;h.x=w-(w-h.x)*$,h.y=I-(I-h.y)*$,h.zoom=Math.min(t.zoomMax,Math.max(t.zoomMin,x)),t.sendCamera()},[t]),E=a.useCallback((x={})=>{const h=t.nodesRef.current;if(!h.length)return;const p=t.wrapRef.current;if(!p)return;const b=p.getBoundingClientRect(),w=x.padding??.1,I=x.nodes?h.filter(j=>x.nodes.some(U=>U.id===j.id)):h;if(!I.length)return;const $=Ve(I),k=Je($,b.width,b.height,w);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]),N=a.useCallback((x,h,p={})=>{const b=t.wrapRef.current;if(!b)return;const w=b.getBoundingClientRect(),I=p.zoom??t.cameraRef.current.zoom;t.cameraRef.current={x:w.width/2-x*I,y:w.height/2-h*I,zoom:I},t.sendCamera()},[t]),W=a.useCallback(x=>t.screenToWorld(x.x,x.y),[t]),H=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:C,zoomOut:R,zoomTo:T,fitView:E,setCenter:N,screenToFlowPosition:W,flowToScreenPosition:H}}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"),C=window.devicePixelRatio||1;v.width=t*C,v.height=e*C,P.scale(C,C),P.clearRect(0,0,t,e);const R=l.nodesRef.current;if(!R.length)return;let T=1/0,E=1/0,N=-1/0,W=-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<E&&(E=k.position.y),k.position.x+j>N&&(N=k.position.x+j),k.position.y+U>W&&(W=k.position.y+U)}const H=40;T-=H,E-=H,N+=H,W+=H;const x=N-T,h=W-E,p=Math.min(t/x,e/h),b=(t-x*p)/2,w=(e-h*p)/2;for(const k of R){if(k.hidden)continue;const j=k.width||pn,U=k.height||mn,D=(k.position.x-T)*p+b,st=(k.position.y-E)*p+w,et=j*p,ct=U*p;P.fillStyle=k.selected?"#f59e0b":typeof n=="function"?n(k):n,P.fillRect(D,st,Math.max(et,2),Math.max(ct,2))}const I=l.cameraRef.current,$=l.wrapRef.current;if($){const k=$.getBoundingClientRect(),j=-I.x/I.zoom,U=-I.y/I.zoom,D=k.width/I.zoom,st=k.height/I.zoom;P.fillStyle=s,P.fillRect(0,0,t,e);const et=(j-T)*p+b,ct=(U-E)*p+w,G=D*p,q=st*p;P.clearRect(et,ct,G,q);for(const ot of R){if(ot.hidden)continue;const nt=ot.width||pn,lt=ot.height||mn,ut=(ot.position.x-T)*p+b,zt=(ot.position.y-E)*p+w;P.fillStyle=ot.selected?"#f59e0b":typeof n=="function"?n(ot):n,P.fillRect(ut,zt,Math.max(nt*p,2),Math.max(lt*p,2))}P.strokeStyle="#3b82f6",P.lineWidth=1.5,P.strokeRect(et,ct,G,q)}},[l,t,e,n,r,s]);return a.useEffect(()=>{let v=!0;function P(){v&&(g(),u.current=requestAnimationFrame(P))}const C=setInterval(()=>{cancelAnimationFrame(u.current),u.current=requestAnimationFrame(P)},66);return g(),()=>{v=!1,clearInterval(C),cancelAnimationFrame(u.current)}},[g]),z.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 z.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:[z.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),z.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function Lo(){return z.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:z.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function To(){return z.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:z.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}function $o(){return z.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:[z.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),z.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function Bo(){return z.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:[z.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),z.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})}function He({children:t,className:e="",...n}){return z.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:C}){const R=ft(),{zoomIn:T,zoomOut:E,fitView:N,getZoom:W}=dr(),[H,x]=a.useState(!0),h=W()<=R.zoomMin,p=W()>=R.zoomMax,b=a.useCallback(()=>{T(),s==null||s()},[T,s]),w=a.useCallback(()=>{E(),o==null||o()},[E,o]),I=a.useCallback(()=>{N(r||{padding:.1}),i==null||i()},[N,r,i]),$=a.useCallback(()=>{const j=!H;x(j),l==null||l(j)},[H,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 z.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&&z.jsxs(z.Fragment,{children:[z.jsx(He,{onClick:b,disabled:p,title:"Zoom in","aria-label":"Zoom in",className:"ric-controls-zoomin",children:z.jsx(So,{})}),z.jsx(He,{onClick:w,disabled:h,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:z.jsx(Lo,{})})]}),e&&z.jsx(He,{onClick:I,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:z.jsx(To,{})}),n&&z.jsx(He,{onClick:$,title:H?"Lock interactivity":"Unlock interactivity","aria-label":H?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:H?z.jsx(Bo,{}):z.jsx($o,{})}),C]})}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},Ho=a.memo(jo);function Ao({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 z.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(),C=a.useRef(null),R=a.useCallback((N,W)=>{N.stopPropagation(),N.preventDefault();const H=P.nodesRef.current.find(p=>p.id===v);if(!H)return;C.current={direction:W,startX:N.clientX,startY:N.clientY,width:H.width||160,height:H.height||60},d==null||d(N,{width:C.current.width,height:C.current.height});const x=p=>{var U,D;if(!C.current)return;const b=C.current,w=P.cameraRef.current,I=(p.clientX-b.startX)/w.zoom,$=(p.clientY-b.startY)/w.zoom;let k=b.width,j=b.height;b.direction.includes("e")&&(k=Math.min(n,Math.max(t,b.width+I))),b.direction.includes("w")&&(k=Math.min(n,Math.max(t,b.width-I))),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-$))),(D=(U=P.onNodesChangeRef).current)==null||D.call(U,[{id:v,type:"dimensions",dimensions:{width:k,height:j},setAttributes:!0}]),u==null||u(p,{width:k,height:j})},h=p=>{C.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,E={position:"absolute",width:T,height:T,background:l,border:"1px solid #fff",borderRadius:2,zIndex:20,...o};return z.jsxs(z.Fragment,{children:[z.jsx("div",{style:{...E,bottom:-T/2,right:-T/2,cursor:"nwse-resize"},onPointerDown:N=>R(N,"se")}),z.jsx("div",{style:{...E,bottom:-T/2,left:-T/2,cursor:"nesw-resize"},onPointerDown:N=>R(N,"sw")}),z.jsx("div",{style:{...E,top:-T/2,right:-T/2,cursor:"nesw-resize"},onPointerDown:N=>R(N,"ne")}),z.jsx("div",{style:{...E,top:-T/2,left:-T/2,cursor:"nwse-resize"},onPointerDown:N=>R(N,"nw")}),z.jsx("div",{style:{...E,top:"50%",right:-T/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:N=>R(N,"e")}),z.jsx("div",{style:{...E,top:"50%",left:-T/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:N=>R(N,"w")}),z.jsx("div",{style:{...E,left:"50%",top:-T/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:N=>R(N,"n")}),z.jsx("div",{style:{...E,left:"50%",bottom:-T/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:N=>R(N,"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 z.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 z.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 z.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 z.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=Ao;exports.BaseEdge=We;exports.BezierEdge=Rn;exports.ConnectionLine=qo;exports.ControlButton=He;exports.Controls=Ho;exports.DefaultNode=Or;exports.EdgeLabelRenderer=Yo;exports.EdgeText=sr;exports.EdgeToolbar=Xo;exports.GroupNode=rr;exports.Handle=Ae;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;