@infinit-canvas/react 0.1.0 → 0.1.2

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 Ir(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 Sr(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 Pr(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 $r(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 Tr(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 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;
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 Zn({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:S,onPaneMouseEnter:I,onPaneMouseMove:T,onPaneMouseLeave:M,onSelectionChange:P,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:Pt="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:Pn=!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]),Z=a.useRef([...e]),It=a.useRef([...n]),dn=a.useRef(new Map),ze=a.useRef(!1),Zt=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}),[Ze,ee]=a.useState(null),Ut=a.useMemo(()=>new Set,[]),ae=a.useMemo(()=>new Set,[]),me=a.useRef(!1),O=a.useRef({});O.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:S,onPaneMouseEnter:I,onPaneMouseMove:T,onPaneMouseLeave:M,onSelectionChange:P,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 O.current.onNodesChange}},Lt={get current(){return O.current.onEdgesChange}},ne={get current(){return O.current.onConnect}},Ie={get current(){return O.current.onNodeClick}},Se={get current(){return O.current.onNodeDragStart}},Pe={get current(){return O.current.onNodeDrag}},Le={get current(){return O.current.onNodeDragStop}},re={get current(){return O.current.onEdgeClick}},$e={get current(){return O.current.onPaneClick}},ce={get current(){return O.current.onSelectionChange}},le={get current(){return O.current.onHudUpdate}},ue={get current(){return O.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=Z.current.filter(L=>L.selected),v=It.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,$=f.position.y,y=w;for(;y;)L+=y.position.x,$+=y.position.y,y=y.parentId?v[y.parentId]:null;return{...f,_absolutePosition:{x:L,y:$}}})},[]),Ot=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(Ot.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)]),$={};for(const y of Z.current)L.has(y.id)&&($[y.id]={...y.position});Z.current=[...e];for(const y of Z.current)$[y.id]&&(y.position=$[y.id]);Ot.current=ve(Z.current);return}Z.current=[...e];const c=ve(e);Ot.current=c;const v=Q(c);(f=Rt.current)==null||f.postMessage({type:"nodes",data:{nodes:v}})},[e,ve,Q]),a.useEffect(()=>{var c;It.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}},[]),St=a.useCallback((c,v)=>{const f=Ot.current.length>0?Ot.current:Z.current;let w=null;for(let L=f.length-1;L>=0;L--){const $=f[L];if($.hidden)continue;const y=$._absolutePosition||$.position,A=$.width||Gt,j=$.height||Ft;if(c>=y.x&&c<=y.x+A&&v>=y.y&&v<=y.y+j){if($.type==="group"){w||(w=$);continue}return $}}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]),Oe=a.useCallback((c,v)=>{const f=Z.current,w=ht.current,L=Math.max(Hr,Xt)/w.zoom;for(let $=f.length-1;$>=0;$--){const y=f[$];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=It.current.length-1;L>=0;L--){const $=It.current[L],y=Z.current.find(vt=>vt.id===$.source),A=Z.current.find(vt=>vt.id===$.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 $}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(Z.current);Ot.current=L;const $=Q(L),{worker:y}=Dr(c,{width:f.width,height:f.height,camera:ht.current,cards:Jt.current,nodes:$,edges:It.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,$;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};($=(L=O.current).onMove)==null||$.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,$,y,A,j,Y,_,K,st,U,et,gt,vt,$t,Dt,Tt;const v=Z.current.length>0,f=ot(c.clientX,c.clientY),w=_t.current;if(v&&Mt){const F=Oe(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};(O.current.isValidConnection?O.current.isValidConnection(Wt):!0)&&((L=ne.current)==null||L.call(ne,{...Wt,...ge}))}pe.current=null;return}if(Pt==="strict"?F&&F.type==="source":F!=null){if(At){pe.current={nodeId:F.nodeId,handleId:F.handleId||null,handleType:F.type},(y=($=O.current).onConnectStart)==null||y.call($,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=O.current).onConnectStart)==null||Y.call(j,c,{nodeId:F.nodeId,handleId:F.handleId,handleType:F.type}),we();return}}if(v){const F=St(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 Z.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=It.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=Z.current.findIndex(J=>J.id===F.id);V>=0&&V<Z.current.length-1&&mt.current([{id:F.id,type:"remove"},{type:"add",item:{...Z.current[V],selected:!0}}])}qt()}}if((_=Ie.current)==null||_.call(Ie,c,F),zt){const bt=w&&F.selected;let V=null;if(F.parentId&&F.extent==="parent"){const J=Z.current.find(Wt=>Wt.id===F.parentId);if(J){const Wt=J.width||Gt,Te=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:Te-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?Z.current.filter(J=>J.selected&&J.id!==F.id).map(J=>{var Te,Qe;let Wt=null;if(J.parentId&&J.extent==="parent"){const Be=Z.current.find(yn=>yn.id===J.parentId);if(Be){const yn=Be.width||Gt,Rr=Be.height||Ft,kr=J.width||((Te=J.measured)==null?void 0:Te.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=Se.current)==null||et.call(Se,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(It.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 It.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=Z.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=Z.current.filter(V=>V.selected).map(V=>({id:V.id,type:"select",selected:!1})),bt=It.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=$e.current)==null||vt.call($e,c),Qt||w){te.current={startWorld:{...f},endWorld:{...f}},($t=yt.current)==null||$t.setPointerCapture(c.pointerId),Me();return}ze.current=!0,Zt.current={x:c.clientX,y:c.clientY},(Dt=yt.current)==null||Dt.classList.add("dragging"),(Tt=yt.current)==null||Tt.setPointerCapture(c.pointerId)},[ot,St,Oe,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 $=L.getBoundingClientRect(),y=40,A=c.clientX-$.left,j=c.clientY-$.top;let Y=0,_=0;A<y?Y=Yt:A>$.width-y&&(Y=-Yt),j<y?_=Yt:j>$.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,$=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 Z.current){if(_.hidden)continue;const K=_.width||Gt,st=_.height||Ft,U=Re==="full"?_.position.x>=$&&_.position.x+K<=A&&_.position.y>=y&&_.position.y+st<=j:_.position.x+K>$&&_.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),$=Bt.current,y=L.x-$.startMouse.x,A=L.y-$.startMouse.y;let j={x:$.startPos.x+y,y:$.startPos.y+A};if(fe&&(j=vn(j,se)),Vt&&(j=bn(j,Vt)),$.parentClamp){const U=$.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:$.id,position:j}];for(const U of $.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=Z.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=Z.current.find(Tt=>Tt.id===et.parentId),$t=U.position.x,Dt=U.position.y;for(;vt;)$t+=vt.position.x,Dt+=vt.position.y,vt=vt.parentId?Z.current.find(Tt=>Tt.id===vt.parentId):null;gt={x:$t,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 Z.current)if(U.parentId&&K.has(U.parentId)&&!K.has(U.id)){let et=Z.current.find($t=>$t.id===U.parentId),gt=U.position.x,vt=U.position.y;for(;et;)gt+=et.position.x,vt+=et.position.y,et=et.parentId?Z.current.find($t=>$t.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,$t=c.clientY-et.top;let Dt=0,Tt=0;vt<gt?Dt=Yt:vt>et.width-gt&&(Dt=-Yt),$t<gt?Tt=Yt:$t>et.height-gt&&(Tt=-Yt),(Dt||Tt)&&(ht.current.x+=Dt,ht.current.y+=Tt,kt(c))}}const st=Z.current.find(U=>U.id===$.id);st&&((w=Pe.current)==null||w.call(Pe,c,st));return}if(!ze.current)return;const v=ht.current;v.x+=c.clientX-Zt.current.x,v.y+=c.clientY-Zt.current.y,Zt.current={x:c.clientX,y:c.clientY},kt()},[kt,ot,we,Me]),gr=a.useCallback(c=>{var v,f,w,L,$;if(jt.current){const y=ot(c.clientX,c.clientY),A=Oe(y.x,y.y);if(A&&A.nodeId!==jt.current.sourceId&&(Pt==="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};(O.current.isValidConnection?O.current.isValidConnection(_):!0)&&((v=ne.current)==null||v.call(ne,{..._,...ge}))}(w=(f=O.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=Z.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=Z.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=Z.current.find(j=>j.id===y.id);A&&((L=Le.current)==null||L.call(Le,c,A));return}ze.current=!1,($=yt.current)==null||$.classList.remove("dragging")},[ot,Oe,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,$=c.getBoundingClientRect(),y=f.clientX-$.left,A=f.clientY-$.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)}},$=()=>{v=0,f=null};return c.addEventListener("touchstart",w,{passive:!1}),c.addEventListener("touchmove",L,{passive:!1}),c.addEventListener("touchend",$),()=>{c.removeEventListener("touchstart",w),c.removeEventListener("touchmove",L),c.removeEventListener("touchend",$)}},[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(St(w.x,w.y)){(K=(_=O.current).onNodeDoubleClick)==null||K.call(_,f,St(w.x,w.y));return}const L=oe(w.x,w.y);if(L){(U=(st=O.current).onEdgeDoubleClick)==null||U.call(st,f,L);return}const $=1.5,y=c.getBoundingClientRect(),A=f.clientX-y.left,j=f.clientY-y.top,Y=ht.current;Y.x=A-(A-Y.x)*$,Y.y=j-(j-Y.y)*$,Y.zoom=Math.min(rt,Math.max(tt,Y.zoom*$)),kt(f)};return c.addEventListener("dblclick",v),()=>c.removeEventListener("dblclick",v)},[Ue,kt,tt,rt,ot,St,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=St(w.x,w.y);if(L){(A=(y=O.current).onNodeContextMenu)==null||A.call(y,f,L);return}const $=oe(w.x,w.y);if($){(Y=(j=O.current).onEdgeContextMenu)==null||Y.call(j,f,$);return}(K=(_=O.current).onPaneContextMenu)==null||K.call(_,f)};return c.addEventListener("contextmenu",v),()=>c.removeEventListener("contextmenu",v)},[ot,St,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,$t,Dt,Tt,F,bt,V;(_=(Y=O.current).onPaneMouseMove)==null||_.call(Y,y);const A=ot(y.clientX,y.clientY),j=St(A.x,A.y);if(j!==v&&(v&&((st=(K=O.current).onNodeMouseLeave)==null||st.call(K,y,v)),j&&((et=(U=O.current).onNodeMouseEnter)==null||et.call(U,y,j)),v=j),j&&((vt=(gt=O.current).onNodeMouseMove)==null||vt.call(gt,y,j)),!j){const J=oe(A.x,A.y);J!==f&&(f&&((Dt=($t=O.current).onEdgeMouseLeave)==null||Dt.call($t,y,f)),J&&((F=(Tt=O.current).onEdgeMouseEnter)==null||F.call(Tt,y,J)),f=J),J&&((V=(bt=O.current).onEdgeMouseMove)==null||V.call(bt,y,J))}},L=y=>{var A,j;return(j=(A=O.current).onPaneMouseEnter)==null?void 0:j.call(A,y)},$=y=>{var A,j,Y,_,K,st;(j=(A=O.current).onPaneMouseLeave)==null||j.call(A,y),v&&((_=(Y=O.current).onNodeMouseLeave)==null||_.call(Y,y,v),v=null),f&&((st=(K=O.current).onEdgeMouseLeave)==null||st.call(K,y,f),f=null)};return c.addEventListener("mousemove",w),c.addEventListener("mouseenter",L),c.addEventListener("mouseleave",$),()=>{c.removeEventListener("mousemove",w),c.removeEventListener("mouseenter",L),c.removeEventListener("mouseleave",$)}},[ot,St,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 $=Z.current.filter(j=>j.selected),y=It.current.filter(j=>j.selected);if(!$.length&&!y.length||O.current.onBeforeDelete&&!await O.current.onBeforeDelete({nodes:$,edges:y}))return;const A=new Set($.map(j=>j.id));if($.length&&mt.current&&(mt.current($.map(j=>({id:j.id,type:"remove"}))),Lt.current)){const j=It.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=O.current).onDelete)==null||L.call(w,{nodes:$,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 $=Z.current.filter(y=>!y.selected).map(y=>({id:y.id,type:"select",selected:!0}));$.length&&mt.current($)}if(Lt.current){const $=It.current.filter(y=>!y.selected).map(y=>({id:y.id,type:"select",selected:!0}));$.length&&Lt.current($)}}};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[he]);const $n=a.useRef(!1);a.useEffect(()=>{var c,v;if(!$n.current&&Rt.current){if($n.current=!0,wt&&Z.current.length>0){const f=yt.current;if(f){const w=f.getBoundingClientRect(),L=(pt==null?void 0:pt.padding)??.1,$=Ve(Z.current),y=Je($,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=O.current).onInit)==null||v.call(c,{getNodes:()=>[...Z.current],getEdges:()=>[...It.current],getViewport:()=>({...ht.current}),fitView:(f={})=>{const w=yt.current;if(!w||!Z.current.length)return;const L=w.getBoundingClientRect(),$=Ve(Z.current),y=Je($,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(),$=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:$-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]),Tn=n,Mr=a.useMemo(()=>({wrapRef:yt,canvasRef:Ee,workerRef:Rt,cameraRef:ht,nodesRef:Z,edgesRef:It,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:Ot,get nodes(){return e},get edges(){return n},get routedEdges(){return Tn},get viewport(){return Ne},get connection(){return Ze}}),[e,n,Tn,Ne,Ze,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 On=a.createContext(null);function dt(){const t=a.useContext(On);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(T=>T.id===t.id),S=(g==null?void 0:g.width)||((D=g==null?void 0:g.measured)==null?void 0:D.width),I=(g==null?void 0:g.height)||((m=g==null?void 0:g.measured)==null?void 0:m.height);(Math.abs((S||0)-z)>1||Math.abs((I||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 T,M;if(R.stopPropagation(),n.onNodesChangeRef.current){const P=[];if(R.shiftKey)P.push({id:t.id,type:"select",selected:!t.selected});else for(const H of n.nodesRef.current)H.id===t.id&&!H.selected?P.push({id:H.id,type:"select",selected:!0}):H.id!==t.id&&H.selected&&P.push({id:H.id,type:"select",selected:!1});P.length&&n.onNodesChangeRef.current(P)}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(P=>P.selected&&P.id!==t.id).map(P=>({id:P.id,startPos:{...P.position}})):[];o.current={startPos:{...t.position},startMouse:{x:W,y:D},selectedStarts:h};const p=[{id:t.id,type:"position",dragging:!0}];for(const P of h)p.push({id:P.id,type:"position",dragging:!0});(M=(T=n.onNodesChangeRef).current)==null||M.call(T,p);const g=r.current;g&&g.setPointerCapture(R.pointerId);const S=P=>{var it,at,ct,Ct;if(!o.current)return;const X=n.cameraRef.current,H=E.getBoundingClientRect(),lt=(P.clientX-H.left-X.x)/X.zoom,ft=(P.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)},I=P=>{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(P.pointerId),g==null||g.removeEventListener("pointermove",S),g==null||g.removeEventListener("pointerup",I)};g==null||g.addEventListener("pointermove",S),g==null||g.addEventListener("pointerup",I)},[t,n]),l=a.useCallback(R=>{var m,h,p,g,S,I;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 T of n.nodesRef.current)T.selected&&T.id!==t.id&&D.push({id:T.id,type:"position",position:{x:T.position.x+E,y:T.position.y+z}});(I=(S=n.onNodesChangeRef).current)==null||I.call(S,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,S,I,T)=>{var ut;S.stopPropagation(),S.preventDefault();const M=s.wrapRef.current;if(!M)return;const P=g==="source"?T:I,X=g==="source"?t.target:t.source;(ut=s.workerRef.current)==null||ut.postMessage({type:"connecting",data:{from:{x:P.x,y:P.y},to:{x:P.x,y:P.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:P.x,y:P.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[,Pt]of tt)Pt.nodeId===zt.id&&Qt.push(Pt);const Re=Qt.length>0?Qt:zt.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const Pt of Re){let Xt,At;if(Pt.x!==void 0&&Pt.y!==void 0)Xt=xt.x+Pt.x,At=xt.y+Pt.y;else switch(Pt.position||(Pt.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=Pt.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=I=>{I.key===t&&(D=!0)},h=I=>{I.key===t&&(D=!1)},p=I=>{if(!D)return;const T=I.target;if(T.closest(".ric-node-wrapper")||T.closest(".ric-handle"))return;z=!0;const M=n.cameraRef.current,P=E.getBoundingClientRect(),X=(I.clientX-P.left-M.x)/M.zoom,H=(I.clientY-P.top-M.y)/M.zoom;W={x:X,y:H},s({startX:X,startY:H,endX:X,endY:H}),I.stopPropagation()},g=I=>{if(!z||!W)return;const T=n.cameraRef.current,M=E.getBoundingClientRect(),P=(I.clientX-M.left-T.x)/T.zoom,X=(I.clientY-M.top-T.y)/T.zoom;s({startX:W.x,startY:W.y,endX:P,endY:X})},S=I=>{var ft,ut;if(!z||!W)return;z=!1;const T=n.cameraRef.current,M=E.getBoundingClientRect(),P=(I.clientX-M.left-T.x)/T.zoom,X=(I.clientY-M.top-T.y)/T.zoom,H={x:Math.min(W.x,P),y:Math.min(W.y,X),width:Math.abs(P-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",S),window.addEventListener("keydown",m),window.addEventListener("keyup",h),()=>{E.removeEventListener("pointerdown",p,!0),E.removeEventListener("pointermove",g),E.removeEventListener("pointerup",S),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 I,T,M;const D=k.current;if(!D||!b)return;const m=R.current,h=(I=m.handleRegistryRef)==null?void 0:I.current;if(!h)return;const p=`${b}__${n||t}`,g=(M=(T=m.cameraRef)==null?void 0:T.current)==null?void 0:M.zoom,S=Gr(D,g);if(S){const P={nodeId:b,id:n||null,type:t,position:e,x:S.x,y:S.y};h.set(p,P)}},[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 T;p.disconnect();const g=R.current,S=(T=g.handleRegistryRef)==null?void 0:T.current,I=`${b}__${n||t}`;S==null||S.delete(I),tr(g,b)}},[b,n,t,e,B]);const E=a.useCallback(()=>{var M;const D=R.current,m=D.nodesRef.current.find(P=>P.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}`,S=p==null?void 0:p.get(g);if(S&&S.x!==void 0&&S.y!==void 0)return{x:h.x+S.x,y:h.y+S.y};const I=m.width||160,T=m.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+T};case"left":return{x:h.x,y:h.y+T/2};default:return{x:h.x+I,y:h.y+T/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(),S=E();if(!S)return;const I=S.x,T=S.y;(X=m.workerRef.current)==null||X.postMessage({type:"connecting",data:{from:{x:I,y:T},to:{x:I,y:T}}}),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:I,y:T},to:{x:lt,y:ft}}})},P=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",P)};p.addEventListener("pointermove",M),p.addEventListener("pointerup",P)},[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 Zr({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),S=Math.max(50,g*.5);let I,T,M,P;switch(i){case"left":I=h.x-S,T=h.y;break;case"top":I=h.x,T=h.y-S;break;case"bottom":I=h.x,T=h.y+S;break;default:I=h.x+S,T=h.y;break}switch(l){case"right":M=p.x+S,P=p.y;break;case"top":M=p.x,P=p.y-S;break;case"bottom":M=p.x,P=p.y+S;break;default:M=p.x-S,P=p.y;break}W=`M ${n},${r} L ${h.x},${h.y} C ${I},${T} ${M},${P} ${p.x},${p.y} L ${s},${o}`;const X=.5,H=.5;return D=H*H*H*h.x+3*H*H*X*I+3*H*X*X*M+X*X*X*p.x,m=H*H*H*h.y+3*H*H*X*T+3*H*X*X*P+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 Or({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 P=n[M];r.add(P.x),r.add(P.x+P.w),s.add(P.y),s.add(P.y+P.h)}const i=[...r].sort((M,P)=>M-P),l=[...s].sort((M,P)=>M-P),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,P)=>P*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 S=[z],I=15,T=[[1,0],[-1,0],[0,1],[0,-1]];for(;S.length>0;){let M=0;for(let G=1;G<S.length;G++)m[S[G]]<m[S[M]]&&(M=G);const P=S[M];if(S[M]=S[S.length-1],S.pop(),P===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[P])continue;g[P]=1;const X=P/x|0,H=P%x,lt=i[H],ft=l[X],ut=p[P];for(let G=0;G<4;G++){const q=H+T[G][0],nt=X+T[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?I:0,rt=D[P]+Ct+tt;rt<D[it]&&(h[it]=P,p[it]=G,D[it]=rt,m[it]=rt+Math.abs(i[B]-at)+Math.abs(l[E]-ct),S.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,S,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),x=Wn(d,"target",o.targetHandle),b=on(u,rn),N=on(x,rn),k=5,R=r.filter(T=>T.id!==o.source&&T.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||((S=d.measured)==null?void 0:S.width)||en,m=d.height||((I=d.measured)==null?void 0:I.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 In=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})});In.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(In,{...n,id:e,pathOptions:r})});ar.displayName="StepEdge";const Sn=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})});Sn.displayName="SimpleBezierEdge";const io={input:er,output:nr,group:rr},ao={bezier:Rn,straight:Nn,simplebezier:Sn};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:S,onNodeMouseLeave:I,onNodeContextMenu:T,onNodeDragStart:M,onNodeDrag:P,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:Pt,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:Pn,zoomOnPinch:un,preventScrolling:ie,translateExtent:yt,nodeExtent:Ee,autoPanOnNodeDrag:Rt,autoPanOnConnect:ht,autoPanSpeed:Jt,edgesReconnectable:Z,elevateNodesOnSelect:It,elevateEdgesOnSelect:dn,edgeRouting:ze=!0,onHudUpdate:Zt,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),Ze=a.useCallback(Q=>{pe(Q),Zt==null||Zt(Q)},[Zt]),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 St=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 St&&!de?-1:!St&&de?1:0})},[e,ee]),me=a.useMemo(()=>n.filter(Q=>Q.type&&Ut[Q.type]),[n,Ut]),O=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:Ie,onPointerDown:Se,onPointerMove:Pe,onPointerUp:Le,store:re}=Zn({cards:t,nodes:O,edges:mt,dark:o,gridSize:i,zoomMin:b,zoomMax:N,initialCamera:k,fitView:R,fitViewOptions:B,onHudUpdate:Ze,onNodesProcessed:fn,onNodesChange:E,onEdgesChange:z,onConnect:W,onConnectStart:D,onConnectEnd:m,onNodeClick:h,onNodeDoubleClick:p,onNodeMouseEnter:g,onNodeMouseMove:S,onNodeMouseLeave:I,onNodeContextMenu:T,onNodeDragStart:M,onNodeDrag:P,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:Pn,zoomOnPinch:un,preventScrolling:ie,translateExtent:yt,nodeExtent:Ee,autoPanOnNodeDrag:Rt,autoPanOnConnect:ht,autoPanSpeed:Jt,edgesReconnectable:Z,elevateNodesOnSelect:It,edgeRouting:ze}),$e=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,St=`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=St),le.current&&le.current.setAttribute("transform",de),ue.current&&(ue.current.style.transform=St),qt.current&&(qt.current.style.transform=St),Q=requestAnimationFrame(Ht)};return Q=requestAnimationFrame(Ht),()=>cancelAnimationFrame(Q)},[re]);const ve=ae.length>0,Ot=me.length>0;return C.jsx(On.Provider,{value:$e,children:C.jsxs("div",{ref:Lt,className:`ric-wrap ${u}`,style:{width:l,height:d,...x},onPointerDown:Se,onPointerMove:Pe,onPointerUp:Le,onDragOver:xt,onDrop:Qt,onDragEnter:Re,onDragLeave:Pt,tabIndex:0,children:[C.jsx("canvas",{ref:ne,className:"ric-canvas"}),!Ie&&C.jsx("div",{className:"ric-loader",children:C.jsx("div",{className:"ric-spinner"})}),Ot&&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:Z},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,S;if(typeof m=="function"){const I=m(t.nodesRef.current);(p=(h=t.onNodesChangeRef).current)==null||p.call(h,[...t.nodesRef.current.map(T=>({id:T.id,type:"remove"})),...I.map(T=>({type:"add",item:T}))])}else(S=(g=t.onNodesChangeRef).current)==null||S.call(g,[...t.nodesRef.current.map(I=>({id:I.id,type:"remove"})),...m.map(I=>({type:"add",item:I}))])},[t]),i=a.useCallback(m=>{var h,p,g,S;if(typeof m=="function"){const I=m(t.edgesRef.current);(p=(h=t.onEdgesChangeRef).current)==null||p.call(h,[...t.edgesRef.current.map(T=>({id:T.id,type:"remove"})),...I.map(T=>({type:"add",item:T}))])}else(S=(g=t.onEdgesChangeRef).current)==null||S.call(g,[...t.edgesRef.current.map(I=>({id:I.id,type:"remove"})),...m.map(I=>({type:"add",item:I}))])},[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(S=>({type:"add",item:S})))},[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(S=>({type:"add",item:S})))},[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(),S=g.width/2,I=g.height/2,T=1.2;h.x=S-(S-h.x)*T,h.y=I-(I-h.y)*T,h.zoom=Math.min(t.zoomMax,h.zoom*T),t.sendCamera()},[t]),R=a.useCallback(m=>{const h=t.cameraRef.current,p=t.wrapRef.current;if(!p)return;const g=p.getBoundingClientRect(),S=g.width/2,I=g.height/2,T=1/1.2;h.x=S-(S-h.x)*T,h.y=I-(I-h.y)*T,h.zoom=Math.max(t.zoomMin,h.zoom*T),t.sendCamera()},[t]),B=a.useCallback(m=>{const h=t.cameraRef.current,p=t.wrapRef.current;if(!p)return;const g=p.getBoundingClientRect(),S=g.width/2,I=g.height/2,T=m/h.zoom;h.x=S-(S-h.x)*T,h.y=I-(I-h.y)*T,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(),S=m.padding??.1,I=m.nodes?h.filter(P=>m.nodes.some(X=>X.id===P.id)):h;if(!I.length)return;const T=Ve(I),M=Je(T,g.width,g.height,S);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 S=g.getBoundingClientRect(),I=p.zoom??t.cameraRef.current.zoom;t.cameraRef.current={x:S.width/2-m*I,y:S.height/2-h*I,zoom:I},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 Io(){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 So({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 P=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+P>z&&(z=M.position.x+P),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,S=(e-h*p)/2;for(const M of R){if(M.hidden)continue;const P=M.width||pn,X=M.height||mn,H=(M.position.x-B)*p+g,lt=(M.position.y-E)*p+S,ft=P*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 I=l.cameraRef.current,T=l.wrapRef.current;if(T){const M=T.getBoundingClientRect(),P=-I.x/I.zoom,X=-I.y/I.zoom,H=M.width/I.zoom,lt=M.height/I.zoom;N.fillStyle=s,N.fillRect(0,0,t,e);const ft=(P-B)*p+g,ut=(X-E)*p+S,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+S;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 Po(){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 $o(){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 To(){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]),S=a.useCallback(()=>{E(),o==null||o()},[E,o]),I=a.useCallback(()=>{z(r||{padding:.1}),i==null||i()},[z,r,i]),T=a.useCallback(()=>{const P=!D;m(P),l==null||l(P)},[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(Po,{})}),C.jsx(He,{onClick:S,disabled:h,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:C.jsx(Lo,{})})]}),e&&C.jsx(He,{onClick:I,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:C.jsx($o,{})}),n&&C.jsx(He,{onClick:T,title:D?"Lock interactivity":"Unlock interactivity","aria-label":D?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:D?C.jsx(Bo,{}):C.jsx(To,{})}),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,S=N.cameraRef.current,I=(p.clientX-g.startX)/S.zoom,T=(p.clientY-g.startY)/S.zoom;let M=g.width,P=g.height;g.direction.includes("e")&&(M=Math.min(n,Math.max(t,g.width+I))),g.direction.includes("w")&&(M=Math.min(n,Math.max(t,g.width-I))),g.direction.includes("s")&&(P=Math.min(r,Math.max(e,g.height+T))),g.direction.includes("n")&&(P=Math.min(r,Math.max(e,g.height-T))),(H=(X=N.onNodesChangeRef).current)==null||H.call(X,[{id:b,type:"dimensions",dimensions:{width:M,height:P},setAttributes:!0}]),u==null||u(p,{width:M,height:P})},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);exports.Background=Ao;exports.BaseEdge=We;exports.BezierEdge=Rn;exports.ConnectionLine=qo;exports.ControlButton=He;exports.Controls=Ho;exports.DefaultNode=Zr;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.MiniMap=So;exports.NodeResizer=Wo;exports.NodeToolbar=Fo;exports.OutputNode=nr;exports.Panel=_o;exports.SelectionBox=Jn;exports.SimpleBezierEdge=Sn;exports.SmoothStepEdge=In;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=Or;exports.getBezierPath=Cn;exports.getBoundsOfBoxes=$r;exports.getConnectedEdges=qn;exports.getEdgeCenter=Qr;exports.getIncomers=Nr;exports.getNodeDimensions=Mn;exports.getNodesBounds=Ve;exports.getNodesInside=Sr;exports.getOutgoers=Ir;exports.getOverlappingArea=Tr;exports.getRoutedLabelPosition=an;exports.getSimpleBezierPath=En;exports.getSmoothStepPath=tn;exports.getStraightPath=kn;exports.getViewportForBounds=Je;exports.isEdge=zr;exports.isNode=Er;exports.nodeToRect=Br;exports.reconnectEdge=Kr;exports.rectToBox=Pr;exports.routeSinglePath=so;exports.routedPointsToPath=sn;exports.snapPosition=vn;exports.useConnection=mo;exports.useEdges=xo;exports.useEdgesState=yo;exports.useHandleConnections=wo;exports.useInfiniteCanvas=Zn;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=Io;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: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;