@infinit-canvas/react 0.1.12 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@infinit-canvas/react.svg)](https://www.npmjs.com/package/@infinit-canvas/react)
4
4
  [![license](https://img.shields.io/npm/l/@infinit-canvas/react.svg)](https://github.com/awaisshah228/infinit-canvas/blob/main/LICENSE)
5
+ [![Sponsor](https://img.shields.io/badge/Sponsor-%E2%9D%A4-pink?logo=github)](https://github.com/sponsors/awaisshah228)
5
6
 
6
7
  A high-performance infinite canvas React component powered by **OffscreenCanvas + Web Workers**. Drop-in React Flow compatible API — but renders on a canvas for **10x better performance** at scale.
7
8
 
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("react/jsx-runtime"),u=require("react"),dr=require("react-dom"),fr=160,hr=60;function Hr(e){return e&&typeof e=="object"&&"position"in e&&"data"in e}function _r(e){return e&&typeof e=="object"&&"source"in e&&"target"in e}function yr(e,t){const n=typeof e=="string"?new Set([e]):new Set(Array.isArray(e)?e.map(r=>r.id):[e.id]);return t.filter(r=>n.has(r.source)||n.has(r.target))}function Wr(e,t,n){const r=typeof e=="string"?e:e.id,a=new Set;for(const o of n)o.target===r&&a.add(o.source);return t.filter(o=>a.has(o.id))}function Fr(e,t,n){const r=typeof e=="string"?e:e.id,a=new Set;for(const o of n)o.source===r&&a.add(o.target);return t.filter(o=>a.has(o.id))}function yn(e){if(!e.length)return{x:0,y:0,width:0,height:0};let t=1/0,n=1/0,r=-1/0,a=-1/0;for(const o of e){const i=o.position.x,h=o.position.y,g=o.width||fr,d=o.height||hr;i<t&&(t=i),h<n&&(n=h),i+g>r&&(r=i+g),h+d>a&&(a=h+d)}return{x:t,y:n,width:r-t,height:a-n}}function Lt(e,t,n,r=.1){const a=e.width*(1+r*2),o=e.height*(1+r*2),i=Math.min(t/a,n/o,1),h=e.x+e.width/2,g=e.y+e.height/2;return{x:t/2-h*i,y:n/2-g*i,zoom:i}}function Fn(e,t){return{x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}}function Xn(e,t){return{x:Math.min(Math.max(e.x,t[0][0]),t[1][0]),y:Math.min(Math.max(e.y,t[0][1]),t[1][1])}}function Un(e){var t,n;return{width:e.width||((t=e.measured)==null?void 0:t.width)||fr,height:e.height||((n=e.measured)==null?void 0:n.height)||hr}}function Xr(e,t,n={x:0,y:0,zoom:1},r=!1){const a=t.x,o=t.y,i=t.x+t.width,h=t.y+t.height;return e.filter(g=>{const{width:d,height:y}=Un(g),w=g.position.x,C=g.position.y,R=w+d,b=C+y;return r?w<i&&R>a&&C<h&&b>o:w>=a&&R<=i&&C>=o&&b<=h})}function Yr(e){return{x:e.x,y:e.y,x2:e.x+e.width,y2:e.y+e.height}}function Ur(e){return{x:e.x,y:e.y,width:e.x2-e.x,height:e.y2-e.y}}function qr(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}}function Or(e,t){const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return n*r}function Zr(e){const{width:t,height:n}=Un(e);return{x:e.position.x,y:e.position.y,width:t,height:n}}const gr=`var ga = null, r = null, er = 0, or = 0, x = { x: 0, y: 0, zoom: 1 }, O = [], B = [], b = [], I = !1, Yt = 40, Ft = !1, br = "lines", Xr = 1, lt = null, Ga = null, hr = null, W = 160, _ = 60, ft = 8, ao = 5;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("react/jsx-runtime"),c=require("react"),yr=require("react-dom"),xr=160,pr=60;function Yr(e){return e&&typeof e=="object"&&"position"in e&&"data"in e}function qr(e){return e&&typeof e=="object"&&"source"in e&&"target"in e}function mr(e,t){const n=typeof e=="string"?new Set([e]):new Set(Array.isArray(e)?e.map(r=>r.id):[e.id]);return t.filter(r=>n.has(r.source)||n.has(r.target))}function Ur(e,t,n){const r=typeof e=="string"?e:e.id,a=new Set;for(const o of n)o.target===r&&a.add(o.source);return t.filter(o=>a.has(o.id))}function Or(e,t,n){const r=typeof e=="string"?e:e.id,a=new Set;for(const o of n)o.source===r&&a.add(o.target);return t.filter(o=>a.has(o.id))}function mn(e){if(!e.length)return{x:0,y:0,width:0,height:0};let t=1/0,n=1/0,r=-1/0,a=-1/0;for(const o of e){const i=o.position.x,f=o.position.y,p=o.width||xr,d=o.height||pr;i<t&&(t=i),f<n&&(n=f),i+p>r&&(r=i+p),f+d>a&&(a=f+d)}return{x:t,y:n,width:r-t,height:a-n}}function jt(e,t,n,r=.1){const a=e.width*(1+r*2),o=e.height*(1+r*2),i=Math.min(t/a,n/o,1),f=e.x+e.width/2,p=e.y+e.height/2;return{x:t/2-f*i,y:n/2-p*i,zoom:i}}function qn(e,t){return{x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}}function Un(e,t){return{x:Math.min(Math.max(e.x,t[0][0]),t[1][0]),y:Math.min(Math.max(e.y,t[0][1]),t[1][1])}}function Qn(e){var t,n;return{width:e.width||((t=e.measured)==null?void 0:t.width)||xr,height:e.height||((n=e.measured)==null?void 0:n.height)||pr}}function Zr(e,t,n={x:0,y:0,zoom:1},r=!1){const a=t.x,o=t.y,i=t.x+t.width,f=t.y+t.height;return e.filter(p=>{const{width:d,height:h}=Qn(p),v=p.position.x,E=p.position.y,M=v+d,z=E+h;return r?v<i&&M>a&&E<f&&z>o:v>=a&&M<=i&&E>=o&&z<=f})}function Gr(e){return{x:e.x,y:e.y,x2:e.x+e.width,y2:e.y+e.height}}function Qr(e){return{x:e.x,y:e.y,width:e.x2-e.x,height:e.y2-e.y}}function Vr(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}}function Jr(e,t){const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return n*r}function Kr(e){const{width:t,height:n}=Qn(e);return{x:e.position.x,y:e.position.y,width:t,height:n}}const vr=`var ga = null, r = null, er = 0, or = 0, x = { x: 0, y: 0, zoom: 1 }, O = [], B = [], b = [], I = !1, Yt = 40, Ft = !1, br = "lines", Xr = 1, lt = null, Ga = null, hr = null, W = 160, _ = 60, ft = 8, ao = 5;
2
2
  function d(a) {
3
3
  return a._absolutePosition || a.position;
4
4
  }
@@ -864,4 +864,4 @@ function st() {
864
864
  }
865
865
  }
866
866
  }
867
- `,nr=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",gr],{type:"text/javascript;charset=utf-8"});function Gr(e){let t;try{if(t=nr&&(self.URL||self.webkitURL).createObjectURL(nr),!t)throw"";const n=new Worker(t,{type:"module",name:e==null?void 0:e.name});return n.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),n}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(gr),{type:"module",name:e==null?void 0:e.name})}}const Dn=new WeakMap;function Qr(e,t){if(Dn.has(e))return Dn.get(e);const n=e.transferControlToOffscreen(),r=new Gr;r.onerror=o=>console.error("[infinite-canvas] worker error:",o.message,o),r.postMessage({type:"init",data:{...t,canvas:n}},[n]);const a={worker:r};return Dn.set(e,a),a}const ot=160,Ke=60,Vr=10;function xr({cards:e=[],nodes:t=[],edges:n=[],onHudUpdate:r,onNodesProcessed:a,onNodesChange:o,onEdgesChange:i,onConnect:h,onNodeClick:g,onNodeDragStart:d,onNodeDrag:y,onNodeDragStop:w,onEdgeClick:C,onEdgeDoubleClick:R,onEdgeMouseEnter:b,onEdgeMouseMove:B,onEdgeMouseLeave:S,onEdgeContextMenu:N,onNodeDoubleClick:X,onNodeMouseEnter:H,onNodeMouseMove:_,onNodeMouseLeave:j,onNodeContextMenu:$,onPaneClick:A,onPaneContextMenu:W,onPaneMouseEnter:F,onPaneMouseMove:m,onPaneMouseLeave:f,onSelectionChange:M,onConnectStart:L,onConnectEnd:T,onInit:Y,onMoveStart:J,onMove:oe,onMoveEnd:V,onDelete:ee,onBeforeDelete:he,onError:ne,isValidConnection:ce,dark:ue,gridSize:Ie=40,zoomMin:le=.1,zoomMax:me=4,initialCamera:Le={x:0,y:0,zoom:1},fitView:ve=!1,fitViewOptions:Re,nodesDraggable:Pe=!0,nodesConnectable:Ee=!0,elementsSelectable:xe=!0,multiSelectionKeyCode:ae="Shift",selectionOnDrag:Fe=!1,selectionMode:bt="partial",connectionMode:Ae="loose",connectionRadius:et=20,connectOnClick:Ve=!1,snapToGrid:Rt=!1,snapGrid:wt=[15,15],deleteKeyCode:kt=["Delete","Backspace"],panActivationKeyCode:Ct=" ",panOnScroll:tn=!1,panOnScrollMode:Tt="free",panOnScrollSpeed:nn=.5,zoomOnScroll:rn=!0,zoomOnDoubleClick:on=!0,zoomOnPinch:sn=!0,preventScrolling:$t=!0,translateExtent:ct,nodeExtent:ut,defaultEdgeOptions:Et={},autoPanOnNodeDrag:Mn=!0,autoPanOnConnect:Rn=!0,autoPanSpeed:tt=5,edgesReconnectable:er=!1,elevateNodesOnSelect:kn=!1,elevateEdgesOnSelect:Cn=!1,noDragClassName:zt="nodrag",noPanClassName:St="nopan",onSelectionDragStart:En,onSelectionDrag:zn,onSelectionDragStop:Sn,edgeRouting:lt=!0}={}){const ge=u.useRef(null),Bt=u.useRef(null),ze=u.useRef(null),ie=u.useRef({...Le}),dt=u.useRef([...e]),K=u.useRef([...t]),ke=u.useRef([...n]),an=u.useRef(new Map),st=u.useRef(!1),Nt=u.useRef(null),[Nn,Pn]=u.useState(!1),He=u.useRef(null),Xe=u.useRef(null),jt=u.useRef(null),De=u.useRef(null),At=u.useRef(!1),Mt=u.useRef(null),[Dt,In]=u.useState({x:Le.x,y:Le.y,zoom:Le.zoom}),[ft,ht]=u.useState(null),at=u.useMemo(()=>new Set,[]),Ze=u.useMemo(()=>new Set,[]),Pt=u.useRef(!1),Z=u.useRef({});Z.current={onHudUpdate:r,onNodesProcessed:a,onNodesChange:o,onEdgesChange:i,onConnect:h,onNodeClick:g,onNodeDragStart:d,onNodeDrag:y,onNodeDragStop:w,onEdgeClick:C,onEdgeDoubleClick:R,onEdgeMouseEnter:b,onEdgeMouseMove:B,onEdgeMouseLeave:S,onEdgeContextMenu:N,onNodeDoubleClick:X,onNodeMouseEnter:H,onNodeMouseMove:_,onNodeMouseLeave:j,onNodeContextMenu:$,onPaneClick:A,onPaneContextMenu:W,onPaneMouseEnter:F,onPaneMouseMove:m,onPaneMouseLeave:f,onSelectionChange:M,onConnectStart:L,onConnectEnd:T,onInit:Y,onMoveStart:J,onMove:oe,onMoveEnd:V,onDelete:ee,onBeforeDelete:he,onError:ne,onSelectionDragStart:En,onSelectionDrag:zn,onSelectionDragStop:Sn,isValidConnection:ce};const yt={get current(){return Z.current.onConnect}},Ht={get current(){return Z.current.onNodeClick}},_t={get current(){return Z.current.onNodeDragStart}},Wt={get current(){return Z.current.onNodeDrag}},Ft={get current(){return Z.current.onNodeDragStop}},Xt={get current(){return Z.current.onEdgeClick}},Yt={get current(){return Z.current.onPaneClick}},we={get current(){return Z.current.onSelectionChange}},gt={get current(){return Z.current.onHudUpdate}},It={get current(){return Z.current.onNodesProcessed}};u.useEffect(()=>{const l=c=>{c.key===ae&&(At.current=!0),c.key===Ct&&(Pt.current=!0)},v=c=>{c.key===ae&&(At.current=!1),c.key===Ct&&(Pt.current=!1)};return window.addEventListener("keydown",l),window.addEventListener("keyup",v),()=>{window.removeEventListener("keydown",l),window.removeEventListener("keyup",v)}},[ae,Ct]);const Se={get current(){const l=Z.current.onNodesChange;return l?v=>{var x;l(v);const c=[];for(let k=0;k<v.length;k++)v[k].type==="select"&&c.push({id:v[k].id,selected:v[k].selected});c.length>0&&((x=ze.current)==null||x.postMessage({type:"nodeSelections",data:{selections:c}}))}:null}},Te={get current(){const l=Z.current.onEdgesChange;return l?v=>{var x;l(v);const c=[];for(let k=0;k<v.length;k++)v[k].type==="select"&&c.push({id:v[k].id,selected:v[k].selected});c.length>0&&((x=ze.current)==null||x.postMessage({type:"edgeSelections",data:{selections:c}}))}:null}},nt=u.useCallback(()=>{var x;const l=K.current.filter(k=>k.selected),v=ke.current.filter(k=>k.selected),c={nodes:l,edges:v};(x=we.current)==null||x.call(we,c);for(const k of Ze)k(c)},[Ze]);u.useEffect(()=>{var l;dt.current=[...e],(l=ze.current)==null||l.postMessage({type:"cards",data:{cards:[...e]}})},[e]);const xt=u.useCallback(l=>{const v={};for(const c of l)v[c.id]=c;return l.map(c=>{if(!c.parentId)return c;const x=v[c.parentId];if(!x)return c;let k=c.position.x,I=c.position.y,p=x;for(;p;)k+=p.position.x,I+=p.position.y,p=p.parentId?v[p.parentId]:null;return{...c,_absolutePosition:{x:k,y:I}}})},[]),Ge=u.useRef([]),rt=u.useCallback(l=>{const v=an.current;if(!v||v.size===0)return l;const c={};for(const[,x]of v)c[x.nodeId]||(c[x.nodeId]=[]),c[x.nodeId].push({id:x.id,type:x.type,position:x.position,x:x.x,y:x.y});return l.map(x=>{const k=c[x.id];return k&&k.length>0?{...x,handles:k}:x})},[]),cn=u.useCallback(()=>{var v;if(He.current)return;const l=rt(Ge.current);(v=ze.current)==null||v.postMessage({type:"nodes",data:{nodes:l}})},[rt]);u.useEffect(()=>{var c;if(He.current){const x=He.current.id,k=new Set([x,...He.current.selectedStarts.map(p=>p.id)]),I={};for(const p of K.current)k.has(p.id)&&(I[p.id]={...p.position});K.current=[...t];for(const p of K.current)I[p.id]&&(p.position=I[p.id]);Ge.current=xt(K.current);return}K.current=[...t];const l=xt(t);Ge.current=l;const v=rt(l);(c=ze.current)==null||c.postMessage({type:"nodes",data:{nodes:v}})},[t,xt,rt]),u.useEffect(()=>{var l;ke.current=[...n],(l=ze.current)==null||l.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const Ne=u.useCallback((l,v)=>{const c=ge.current;if(!c)return{x:0,y:0};const x=c.getBoundingClientRect(),k=ie.current;return{x:(l-x.left-k.x)/k.zoom,y:(v-x.top-k.y)/k.zoom}},[]),Je=u.useCallback((l,v)=>{const c=Ge.current.length>0?Ge.current:K.current;let x=null;for(let k=c.length-1;k>=0;k--){const I=c[k];if(I.hidden)continue;const p=I._absolutePosition||I.position,P=I.width||ot,z=I.height||Ke;if(l>=p.x&&l<=p.x+P&&v>=p.y&&v<=p.y+z){if(I.type==="group"){x||(x=I);continue}return I}}return x},[]),un=u.useCallback((l,v)=>{const c=v.width||ot,x=v.height||Ke;if(l.x!==void 0&&l.y!==void 0)return{x:v.position.x+l.x,y:v.position.y+l.y};switch(l.position||(l.type==="source"?"right":"left")){case"top":return{x:v.position.x+c/2,y:v.position.y};case"bottom":return{x:v.position.x+c/2,y:v.position.y+x};case"left":return{x:v.position.x,y:v.position.y+x/2};case"right":return{x:v.position.x+c,y:v.position.y+x/2};default:return{x:v.position.x+c,y:v.position.y+x/2}}},[]),Q=u.useCallback(l=>{const v=l.width||ot,c=l.height||Ke;if(l.handles&&l.handles.length>0)return l.handles.map(z=>{const q=un(z,l);return{id:z.id||null,type:z.type,x:q.x,y:q.y}});const x=l.targetPosition||"left",k=l.sourcePosition||"right",I=z=>{switch(z){case"top":return{x:l.position.x+v/2,y:l.position.y};case"bottom":return{x:l.position.x+v/2,y:l.position.y+c};case"left":return{x:l.position.x,y:l.position.y+c/2};case"right":return{x:l.position.x+v,y:l.position.y+c/2};default:return{x:l.position.x+v,y:l.position.y+c/2}}},p=I(x),P=I(k);return[{id:null,type:"target",x:p.x,y:p.y},{id:null,type:"source",x:P.x,y:P.y}]},[un]),$e=u.useCallback((l,v)=>{const c=K.current,x=ie.current,k=Math.max(Vr,et)/x.zoom;for(let I=c.length-1;I>=0;I--){const p=c[I];if(p.hidden)continue;const P=Q(p);for(const z of P)if(Math.abs(l-z.x)<k&&Math.abs(v-z.y)<k)return{nodeId:p.id,handleId:z.id,type:z.type,x:z.x,y:z.y}}return null},[Q]),pe=u.useCallback((l,v)=>{const x=8/ie.current.zoom;for(let k=ke.current.length-1;k>=0;k--){const I=ke.current[k],p=K.current.find(se=>se.id===I.source),P=K.current.find(se=>se.id===I.target);if(!p||!P)continue;const z=p.width||ot,q=p.height||Ke,D=P.height||Ke,O=p.position.x+z,G=p.position.y+q/2,be=P.position.x,Be=P.position.y+D/2;if(Jr(l,v,O,G,be,Be)<x)return I}return null},[]);u.useEffect(()=>{const l=Bt.current,v=ge.current;if(!l||!v)return;const c=v.getBoundingClientRect(),x=ue!==void 0?ue:matchMedia("(prefers-color-scheme: dark)").matches,k=xt(K.current);Ge.current=k;const I=rt(k),{worker:p}=Qr(l,{width:c.width,height:c.height,camera:ie.current,cards:dt.current,nodes:I,edges:ke.current,dark:x,gridSize:Ie,edgeRouting:lt});p.onmessage=D=>{var O,G,be,Be;D.data.type==="hud"&&((O=gt.current)==null||O.call(gt,D.data.data)),D.data.type==="ready"&&Pn(!0),D.data.type==="nodesProcessed"&&((G=It.current)==null||G.call(It,D.data.data)),D.data.type==="error"&&((Be=(be=Z.current).onError)==null||Be.call(be,"worker-error",D.data.message||"Canvas worker error"))},p.onerror=D=>{var O,G;(G=(O=Z.current).onError)==null||G.call(O,"worker-error",D.message||"Canvas worker crashed")},ze.current=p;const P=new ResizeObserver(D=>{const{width:O,height:G}=D[0].contentRect;p.postMessage({type:"resize",data:{width:O,height:G}})});P.observe(v);let z,q;return ue===void 0&&(z=matchMedia("(prefers-color-scheme: dark)"),q=D=>p.postMessage({type:"theme",data:{dark:D.matches}}),z.addEventListener("change",q)),()=>{P.disconnect(),z&&q&&z.removeEventListener("change",q),ze.current=null}},[]),u.useEffect(()=>{var l;ue!==void 0&&((l=ze.current)==null||l.postMessage({type:"theme",data:{dark:ue}}))},[ue]),u.useEffect(()=>{var l;(l=ze.current)==null||l.postMessage({type:"edgeRouting",data:{enabled:lt}})},[lt]);const Qe=u.useRef(0),fe=u.useCallback((l=null)=>{var x,k,I;const v=ie.current;if(ct){const p=ge.current;if(p){const P=p.getBoundingClientRect(),z=-ct[1][0]*v.zoom+P.width,q=-ct[1][1]*v.zoom+P.height,D=-ct[0][0]*v.zoom,O=-ct[0][1]*v.zoom;v.x=Math.min(D,Math.max(z,v.x)),v.y=Math.min(O,Math.max(q,v.y))}}(x=ze.current)==null||x.postMessage({type:"camera",data:{camera:{...v}}});const c={x:v.x,y:v.y,zoom:v.zoom};(I=(k=Z.current).onMove)==null||I.call(k,l,c);for(const p of at)p(c);cancelAnimationFrame(Qe.current),Qe.current=requestAnimationFrame(()=>{In({x:v.x,y:v.y,zoom:v.zoom})})},[at,ct]),_e=u.useCallback(()=>{var c,x;const l=Xe.current,v=jt.current;l&&v?((c=ze.current)==null||c.postMessage({type:"connecting",data:{from:l.startPos,to:v,_routedPoints:null}}),ht({source:l.sourceId,sourceHandle:l.sourceHandle,target:null,targetHandle:null})):((x=ze.current)==null||x.postMessage({type:"connecting",data:null}),ht(null))},[]),pt=u.useCallback(()=>{var v,c;const l=De.current;l?(v=ze.current)==null||v.postMessage({type:"selectionBox",data:l}):(c=ze.current)==null||c.postMessage({type:"selectionBox",data:null})},[]),Ln=u.useCallback(l=>{var p,P,z,q,D,O,G,be,Be,te,se,Ce,je,We,qe,Ue,Ut,it;const v=K.current.length>0,c=Ne(l.clientX,l.clientY),x=At.current;if(v&&Ee&&!x){const U=$e(c.x,c.y);if(Ve&&Mt.current&&U){const re=Mt.current;if(U.nodeId!==re.nodeId){const Oe=re.handleType==="target"?{source:U.nodeId,target:re.nodeId,sourceHandle:U.handleId||null,targetHandle:re.handleId}:{source:re.nodeId,target:U.nodeId,sourceHandle:re.handleId,targetHandle:U.handleId||null};(Z.current.isValidConnection?Z.current.isValidConnection(Oe):!0)&&((p=yt.current)==null||p.call(yt,{...Oe,...Et}))}Mt.current=null;return}if(Ae==="strict"?U&&U.type==="source":U!=null){if(Ve){Mt.current={nodeId:U.nodeId,handleId:U.handleId||null,handleType:U.type},(z=(P=Z.current).onConnectStart)==null||z.call(P,l,{nodeId:U.nodeId,handleId:U.handleId,handleType:U.type});return}Xe.current={sourceId:U.nodeId,sourceHandle:U.handleId||null,sourceType:U.type,startPos:{x:U.x,y:U.y}},jt.current={x:c.x,y:c.y},(q=ge.current)==null||q.setPointerCapture(l.pointerId),(O=(D=Z.current).onConnectStart)==null||O.call(D,l,{nodeId:U.nodeId,handleId:U.handleId,handleType:U.type}),_e();return}}const k=U=>{var re;let ye=U;for(;ye&&ye!==ge.current;){if((re=ye.classList)!=null&&re.contains(zt))return!0;ye=ye.parentElement}return!1},I=U=>{var re;let ye=U;for(;ye&&ye!==ge.current;){if((re=ye.classList)!=null&&re.contains(St))return!0;ye=ye.parentElement}return!1};if(v){const U=Je(c.x,c.y);if(U){if(Se.current&&xe){const ye=[];if(x)ye.push({id:U.id,type:"select",selected:!U.selected});else if(!U.selected){for(const re of K.current)re.id===U.id?ye.push({id:re.id,type:"select",selected:!0}):re.selected&&ye.push({id:re.id,type:"select",selected:!1});if(Te.current){const re=ke.current.filter(de=>de.selected).map(de=>({id:de.id,type:"select",selected:!1}));re.length&&Te.current(re)}}if(ye.length){if(Se.current(ye),kn&&!x){const re=K.current.findIndex(de=>de.id===U.id);re>=0&&re<K.current.length-1&&Se.current([{id:U.id,type:"remove"},{type:"add",item:{...K.current[re],selected:!0}}])}nt()}}if((G=Ht.current)==null||G.call(Ht,l,U),Pe&&!k(l.target)){const ye=U.selected;let re=null;if(U.parentId&&U.extent==="parent"){const de=K.current.find(Oe=>Oe.id===U.parentId);if(de){const Oe=de.width||ot,qt=de.height||Ke,fn=U.width||((be=U.measured)==null?void 0:be.width)||ot,Ot=U.height||((Be=U.measured)==null?void 0:Be.height)||Ke;re={minX:0,minY:0,maxX:Oe-fn,maxY:qt-Ot}}}if(He.current={id:U.id,startPos:{...U.position},startMouse:{x:c.x,y:c.y},parentClamp:re,parentId:U.parentId||null,selectedStarts:ye?K.current.filter(de=>de.selected&&de.id!==U.id).map(de=>{var qt,fn;let Oe=null;if(de.parentId&&de.extent==="parent"){const Ot=K.current.find(An=>An.id===de.parentId);if(Ot){const An=Ot.width||ot,jr=Ot.height||Ke,Ar=de.width||((qt=de.measured)==null?void 0:qt.width)||ot,Dr=de.height||((fn=de.measured)==null?void 0:fn.height)||Ke;Oe={minX:0,minY:0,maxX:An-Ar,maxY:jr-Dr}}}return{id:de.id,startPos:{...de.position},parentClamp:Oe,parentId:de.parentId||null}}):[]},(te=ge.current)==null||te.setPointerCapture(l.pointerId),(se=_t.current)==null||se.call(_t,l,U),He.current.selectedStarts.length>0){const de=K.current.filter(Oe=>Oe.selected);(je=(Ce=Z.current).onSelectionDragStart)==null||je.call(Ce,l,de)}if(Se.current){const de=[{id:U.id,type:"position",dragging:!0}];for(const Oe of He.current.selectedStarts)de.push({id:Oe.id,type:"position",dragging:!0});Se.current(de)}}return}}if(ke.current.length>0&&xe){const U=pe(c.x,c.y);if(U){if(Te.current){const ye=[];if(x)ye.push({id:U.id,type:"select",selected:!U.selected});else{for(const re of ke.current)re.id===U.id?ye.push({id:re.id,type:"select",selected:!0}):re.selected&&ye.push({id:re.id,type:"select",selected:!1});if(Se.current){const re=K.current.filter(de=>de.selected).map(de=>({id:de.id,type:"select",selected:!1}));re.length&&Se.current(re)}}if(ye.length){if(Te.current(ye),Cn&&!x){const re=ke.current.findIndex(de=>de.id===U.id);re>=0&&re<ke.current.length-1&&Te.current([{id:U.id,type:"remove"},{type:"add",item:{...ke.current[re],selected:!0}}])}nt()}}(We=Xt.current)==null||We.call(Xt,l,U);return}}if(!x){const U=K.current.filter(re=>re.selected).map(re=>({id:re.id,type:"select",selected:!1})),ye=ke.current.filter(re=>re.selected).map(re=>({id:re.id,type:"select",selected:!1}));U.length&&Se.current&&Se.current(U),ye.length&&Te.current&&Te.current(ye),(U.length||ye.length)&&nt()}if((qe=Yt.current)==null||qe.call(Yt,l),Fe||x){De.current={startWorld:{...c},endWorld:{...c}},(Ue=ge.current)==null||Ue.setPointerCapture(l.pointerId),pt();return}I(l.target)||(st.current=!0,Nt.current={x:l.clientX,y:l.clientY},(Ut=ge.current)==null||Ut.classList.add("dragging"),(it=ge.current)==null||it.setPointerCapture(l.pointerId))},[Ne,Je,$e,pe,Pe,Ee,xe,Fe,_e,pt,nt,zt,St]),Tn=u.useCallback(l=>{var c,x,k,I;if(Xe.current){if(jt.current=Ne(l.clientX,l.clientY),_e(),Rn){const p=ge.current;if(p){const P=p.getBoundingClientRect(),z=40,q=l.clientX-P.left,D=l.clientY-P.top;let O=0,G=0;q<z?O=tt:q>P.width-z&&(O=-tt),D<z?G=tt:D>P.height-z&&(G=-tt),(O||G)&&(ie.current.x+=O,ie.current.y+=G,fe(l))}}return}if(De.current){De.current.endWorld=Ne(l.clientX,l.clientY),pt();const p=De.current,P=Math.min(p.startWorld.x,p.endWorld.x),z=Math.min(p.startWorld.y,p.endWorld.y),q=Math.max(p.startWorld.x,p.endWorld.x),D=Math.max(p.startWorld.y,p.endWorld.y);if(Se.current){const O=[];for(const G of K.current){if(G.hidden)continue;const be=G.width||ot,Be=G.height||Ke,te=bt==="full"?G.position.x>=P&&G.position.x+be<=q&&G.position.y>=z&&G.position.y+Be<=D:G.position.x+be>P&&G.position.x<q&&G.position.y+Be>z&&G.position.y<D;te!==!!G.selected&&O.push({id:G.id,type:"select",selected:te})}O.length&&Se.current(O)}return}if(He.current){const p=Ne(l.clientX,l.clientY),P=He.current,z=p.x-P.startMouse.x,q=p.y-P.startMouse.y;let D={x:P.startPos.x+z,y:P.startPos.y+q};if(Rt&&(D=Fn(D,wt)),ut&&(D=Xn(D,ut)),P.parentClamp){const te=P.parentClamp;D={x:Math.max(te.minX,Math.min(D.x,te.maxX)),y:Math.max(te.minY,Math.min(D.y,te.maxY))}}const O=[{id:P.id,position:D}];for(const te of P.selectedStarts){let se={x:te.startPos.x+z,y:te.startPos.y+q};if(Rt&&(se=Fn(se,wt)),ut&&(se=Xn(se,ut)),te.parentClamp){const Ce=te.parentClamp;se={x:Math.max(Ce.minX,Math.min(se.x,Ce.maxX)),y:Math.max(Ce.minY,Math.min(se.y,Ce.maxY))}}O.push({id:te.id,position:se})}const G=[];for(const te of O){const se=K.current.find(Ce=>Ce.id===te.id);if(se){se.position=te.position,se.dragging=!0;let Ce=te.position;if(se.parentId){let je=K.current.find(Ue=>Ue.id===se.parentId),We=te.position.x,qe=te.position.y;for(;je;)We+=je.position.x,qe+=je.position.y,je=je.parentId?K.current.find(Ue=>Ue.id===je.parentId):null;Ce={x:We,y:qe}}G.push({id:te.id,position:te.position,_absolutePosition:Ce,width:se.width,height:se.height,dragging:!0,selected:se.selected})}}const be=new Set(O.map(te=>te.id));for(const te of K.current)if(te.parentId&&be.has(te.parentId)&&!be.has(te.id)){let se=K.current.find(We=>We.id===te.parentId),Ce=te.position.x,je=te.position.y;for(;se;)Ce+=se.position.x,je+=se.position.y,se=se.parentId?K.current.find(We=>We.id===se.parentId):null;G.push({id:te.id,position:te.position,_absolutePosition:{x:Ce,y:je},width:te.width,height:te.height,dragging:!1,selected:te.selected})}if((c=ze.current)==null||c.postMessage({type:"nodePositions",data:{updates:G}}),Mn){const te=ge.current;if(te){const se=te.getBoundingClientRect(),Ce=40,je=l.clientX-se.left,We=l.clientY-se.top;let qe=0,Ue=0;je<Ce?qe=tt:je>se.width-Ce&&(qe=-tt),We<Ce?Ue=tt:We>se.height-Ce&&(Ue=-tt),(qe||Ue)&&(ie.current.x+=qe,ie.current.y+=Ue,fe(l))}}const Be=K.current.find(te=>te.id===P.id);if(Be&&((x=Wt.current)==null||x.call(Wt,l,Be)),P.selectedStarts.length>0){const te=K.current.filter(se=>se.selected);(I=(k=Z.current).onSelectionDrag)==null||I.call(k,l,te)}return}if(!st.current)return;const v=ie.current;v.x+=l.clientX-Nt.current.x,v.y+=l.clientY-Nt.current.y,Nt.current={x:l.clientX,y:l.clientY},fe()},[fe,Ne,_e,pt]),$n=u.useCallback(l=>{var v,c,x,k,I,p,P;if(Xe.current){const z=Ne(l.clientX,l.clientY),q=$e(z.x,z.y);if(q&&q.nodeId!==Xe.current.sourceId&&(Ae==="loose"||q.type==="target")){const G=Xe.current.sourceType==="target"?{source:q.nodeId,target:Xe.current.sourceId,sourceHandle:q.handleId||null,targetHandle:Xe.current.sourceHandle}:{source:Xe.current.sourceId,target:q.nodeId,sourceHandle:Xe.current.sourceHandle,targetHandle:q.handleId||null};(Z.current.isValidConnection?Z.current.isValidConnection(G):!0)&&((v=yt.current)==null||v.call(yt,{...G,...Et}))}(x=(c=Z.current).onConnectEnd)==null||x.call(c,l.nativeEvent||l),Xe.current=null,jt.current=null,_e();return}if(De.current){De.current=null,pt(),nt();return}if(He.current){const z=He.current;if(Se.current){const D=K.current.find(G=>G.id===z.id),O=[{id:z.id,type:"position",position:D?{...D.position}:void 0,dragging:!1}];for(const G of z.selectedStarts){const be=K.current.find(Be=>Be.id===G.id);O.push({id:G.id,type:"position",position:be?{...be.position}:void 0,dragging:!1})}Se.current(O)}if(z.selectedStarts.length>0){const D=K.current.filter(O=>O.selected);(I=(k=Z.current).onSelectionDragStop)==null||I.call(k,l,D)}requestAnimationFrame(()=>{var O;He.current=null;const D=rt(Ge.current);(O=ze.current)==null||O.postMessage({type:"nodes",data:{nodes:D}})});const q=K.current.find(D=>D.id===z.id);q&&((p=Ft.current)==null||p.call(Ft,l,q));return}st.current=!1,(P=ge.current)==null||P.classList.remove("dragging")},[Ne,$e,_e,pt,nt]);u.useEffect(()=>{const l=ge.current;if(!l)return;const v=c=>{$t&&c.preventDefault();const x=ie.current;if(tn||Pt.current){const z=nn;Tt==="horizontal"?x.x-=c.deltaY*z:(Tt==="vertical"||(x.x-=c.deltaX*z),x.y-=c.deltaY*z),fe(c);return}if(!rn)return;const k=c.deltaY>0?.92:1.08,I=l.getBoundingClientRect(),p=c.clientX-I.left,P=c.clientY-I.top;x.x=p-(p-x.x)*k,x.y=P-(P-x.y)*k,x.zoom=Math.min(me,Math.max(le,x.zoom*k)),fe(c)};return l.addEventListener("wheel",v,{passive:!$t}),()=>l.removeEventListener("wheel",v)},[fe,le,me,tn,Tt,nn,rn,$t]),u.useEffect(()=>{if(!sn)return;const l=ge.current;if(!l)return;let v=0,c=null;const x=p=>{if(p.touches.length===2){const P=p.touches[0].clientX-p.touches[1].clientX,z=p.touches[0].clientY-p.touches[1].clientY;v=Math.hypot(P,z);const q=l.getBoundingClientRect();c={x:(p.touches[0].clientX+p.touches[1].clientX)/2-q.left,y:(p.touches[0].clientY+p.touches[1].clientY)/2-q.top},p.preventDefault()}},k=p=>{if(p.touches.length===2&&v>0){p.preventDefault();const P=p.touches[0].clientX-p.touches[1].clientX,z=p.touches[0].clientY-p.touches[1].clientY,q=Math.hypot(P,z),D=q/v;v=q;const O=ie.current,G=c.x,be=c.y;O.x=G-(G-O.x)*D,O.y=be-(be-O.y)*D,O.zoom=Math.min(me,Math.max(le,O.zoom*D)),fe(p)}},I=()=>{v=0,c=null};return l.addEventListener("touchstart",x,{passive:!1}),l.addEventListener("touchmove",k,{passive:!1}),l.addEventListener("touchend",I),()=>{l.removeEventListener("touchstart",x),l.removeEventListener("touchmove",k),l.removeEventListener("touchend",I)}},[sn,fe,le,me]),u.useEffect(()=>{if(!on)return;const l=ge.current;if(!l)return;const v=c=>{var D,O,G,be;const x=Ne(c.clientX,c.clientY);if(Je(x.x,x.y)){(O=(D=Z.current).onNodeDoubleClick)==null||O.call(D,c,Je(x.x,x.y));return}const k=pe(x.x,x.y);if(k){(be=(G=Z.current).onEdgeDoubleClick)==null||be.call(G,c,k);return}const I=1.5,p=l.getBoundingClientRect(),P=c.clientX-p.left,z=c.clientY-p.top,q=ie.current;q.x=P-(P-q.x)*I,q.y=z-(z-q.y)*I,q.zoom=Math.min(me,Math.max(le,q.zoom*I)),fe(c)};return l.addEventListener("dblclick",v),()=>l.removeEventListener("dblclick",v)},[on,fe,le,me,Ne,Je,pe]),u.useEffect(()=>{const l=ge.current;if(!l)return;const v=c=>{var p,P,z,q,D,O;const x=Ne(c.clientX,c.clientY),k=Je(x.x,x.y);if(k){(P=(p=Z.current).onNodeContextMenu)==null||P.call(p,c,k);return}const I=pe(x.x,x.y);if(I){(q=(z=Z.current).onEdgeContextMenu)==null||q.call(z,c,I);return}(O=(D=Z.current).onPaneContextMenu)==null||O.call(D,c)};return l.addEventListener("contextmenu",v),()=>l.removeEventListener("contextmenu",v)},[Ne,Je,pe]),u.useEffect(()=>{const l=ge.current;if(!l)return;let v=null,c=null;const x=p=>{var q,D,O,G,be,Be,te,se,Ce,je,We,qe,Ue,Ut;if((D=(q=Z.current).onPaneMouseMove)==null||D.call(q,p),st.current||He.current||Xe.current||De.current)return;const P=Ne(p.clientX,p.clientY),z=Je(P.x,P.y);if(z!==v&&(v&&((G=(O=Z.current).onNodeMouseLeave)==null||G.call(O,p,v)),z&&((Be=(be=Z.current).onNodeMouseEnter)==null||Be.call(be,p,z)),v=z),z&&((se=(te=Z.current).onNodeMouseMove)==null||se.call(te,p,z)),!z){const it=pe(P.x,P.y);it!==c&&(c&&((je=(Ce=Z.current).onEdgeMouseLeave)==null||je.call(Ce,p,c)),it&&((qe=(We=Z.current).onEdgeMouseEnter)==null||qe.call(We,p,it)),c=it),it&&((Ut=(Ue=Z.current).onEdgeMouseMove)==null||Ut.call(Ue,p,it))}},k=p=>{var P,z;return(z=(P=Z.current).onPaneMouseEnter)==null?void 0:z.call(P,p)},I=p=>{var P,z,q,D,O,G;(z=(P=Z.current).onPaneMouseLeave)==null||z.call(P,p),v&&((D=(q=Z.current).onNodeMouseLeave)==null||D.call(q,p,v),v=null),c&&((G=(O=Z.current).onEdgeMouseLeave)==null||G.call(O,p,c),c=null)};return l.addEventListener("mousemove",x),l.addEventListener("mouseenter",k),l.addEventListener("mouseleave",I),()=>{l.removeEventListener("mousemove",x),l.removeEventListener("mouseenter",k),l.removeEventListener("mouseleave",I)}},[Ne,Je,pe]),u.useEffect(()=>{const l=Array.isArray(kt)?kt:[kt],v=async c=>{var x,k,I,p;if(l.includes(c.key)){if(c.target.tagName==="INPUT"||c.target.tagName==="TEXTAREA"||c.target.isContentEditable)return;const P=K.current.filter(D=>D.selected),z=ke.current.filter(D=>D.selected);if(!P.length&&!z.length)return;if(Z.current.onBeforeDelete)try{if(!await Z.current.onBeforeDelete({nodes:P,edges:z}))return}catch(D){(k=(x=Z.current).onError)==null||k.call(x,"before-delete-error",D.message||"onBeforeDelete threw an error");return}const q=new Set(P.map(D=>D.id));if(P.length&&Se.current&&(Se.current(P.map(D=>({id:D.id,type:"remove"}))),Te.current)){const D=ke.current.filter(O=>q.has(O.source)||q.has(O.target));D.length&&Te.current(D.map(O=>({id:O.id,type:"remove"})))}z.length&&Te.current&&Te.current(z.map(D=>({id:D.id,type:"remove"}))),(p=(I=Z.current).onDelete)==null||p.call(I,{nodes:P,edges:z})}if((c.ctrlKey||c.metaKey)&&c.key==="a"){if(c.target.tagName==="INPUT"||c.target.tagName==="TEXTAREA")return;if(c.preventDefault(),Se.current){const P=K.current.filter(z=>!z.selected).map(z=>({id:z.id,type:"select",selected:!0}));P.length&&Se.current(P)}if(Te.current){const P=ke.current.filter(z=>!z.selected).map(z=>({id:z.id,type:"select",selected:!0}));P.length&&Te.current(P)}}};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[kt]);const mt=u.useRef(!1);u.useEffect(()=>{var l,v;if(!mt.current&&ze.current){if(mt.current=!0,ve&&K.current.length>0){const c=ge.current;if(c){const x=c.getBoundingClientRect(),k=(Re==null?void 0:Re.padding)??.1,I=yn(K.current),p=Lt(I,x.width,x.height,k);Re!=null&&Re.maxZoom&&(p.zoom=Math.min(p.zoom,Re.maxZoom)),Re!=null&&Re.minZoom&&(p.zoom=Math.max(p.zoom,Re.minZoom)),ie.current=p,fe()}}(v=(l=Z.current).onInit)==null||v.call(l,{getNodes:()=>[...K.current],getEdges:()=>[...ke.current],getNode:c=>K.current.find(x=>x.id===c),getEdge:c=>ke.current.find(x=>x.id===c),getViewport:()=>({...ie.current}),getZoom:()=>ie.current.zoom,setViewport:c=>{ie.current={x:c.x??ie.current.x,y:c.y??ie.current.y,zoom:c.zoom??ie.current.zoom},fe()},fitView:(c={})=>{const x=ge.current;if(!x||!K.current.length)return;const k=x.getBoundingClientRect(),I=c.nodes?K.current.filter(z=>c.nodes.some(q=>q.id===z.id)):K.current;if(!I.length)return;const p=yn(I),P=Lt(p,k.width,k.height,c.padding??.1);c.maxZoom&&(P.zoom=Math.min(P.zoom,c.maxZoom)),c.minZoom&&(P.zoom=Math.max(P.zoom,c.minZoom)),ie.current=P,fe()},screenToFlowPosition:c=>Ne(c.x,c.y),flowToScreenPosition:c=>{const x=ie.current,k=ge.current;if(!k)return{x:0,y:0};const I=k.getBoundingClientRect();return{x:c.x*x.zoom+x.x+I.left,y:c.y*x.zoom+x.y+I.top}},zoomIn:()=>{const c=ie.current;c.zoom=Math.min(me,c.zoom*1.2),fe()},zoomOut:()=>{const c=ie.current;c.zoom=Math.max(le,c.zoom/1.2),fe()},zoomTo:c=>{ie.current.zoom=Math.min(me,Math.max(le,c)),fe()},setNodes:c=>{var x,k;(k=(x=Z.current).onNodesChange)==null||k.call(x,[...K.current.map(I=>({id:I.id,type:"remove"})),...(typeof c=="function"?c(K.current):c).map(I=>({type:"add",item:I}))])},setEdges:c=>{var x,k;(k=(x=Z.current).onEdgesChange)==null||k.call(x,[...ke.current.map(I=>({id:I.id,type:"remove"})),...(typeof c=="function"?c(ke.current):c).map(I=>({type:"add",item:I}))])},addNodes:c=>{var k,I;const x=Array.isArray(c)?c:[c];(I=(k=Z.current).onNodesChange)==null||I.call(k,x.map(p=>({type:"add",item:p})))},addEdges:c=>{var k,I;const x=Array.isArray(c)?c:[c];(I=(k=Z.current).onEdgesChange)==null||I.call(k,x.map(p=>({type:"add",item:p})))},deleteElements:({nodes:c=[],edges:x=[]})=>{var k,I,p,P;c.length&&((I=(k=Z.current).onNodesChange)==null||I.call(k,c.map(z=>({id:z.id,type:"remove"})))),x.length&&((P=(p=Z.current).onEdgesChange)==null||P.call(p,x.map(z=>({id:z.id,type:"remove"}))))},updateNodeData:(c,x)=>{var p,P;const k=K.current.find(z=>z.id===c);if(!k)return;const I=typeof x=="function"?x(k.data):{...k.data,...x};(P=(p=Z.current).onNodesChange)==null||P.call(p,[{id:c,type:"replace",item:{...k,data:I}}])},toObject:()=>({nodes:[...K.current],edges:[...ke.current],viewport:{...ie.current}}),setCenter:(c,x,k={})=>{const I=ge.current;if(!I)return;const p=I.getBoundingClientRect(),P=k.zoom??ie.current.zoom;ie.current={x:p.width/2-c*P,y:p.height/2-x*P,zoom:P},fe()},fitBounds:(c,x={})=>{const k=ge.current;if(!k)return;const I=k.getBoundingClientRect(),p=Lt(c,I.width,I.height,x.padding??.1);ie.current=p,fe()}})}});const ln=u.useCallback(()=>{ie.current={...Le},fe()},[fe,Le]),dn=u.useCallback(l=>{var v;if(l)dt.current.push(l);else{const c=ie.current,x=ge.current;if(!x)return;const k=x.getBoundingClientRect(),I=Math.round(-c.x/c.zoom+k.width/2/c.zoom),p=Math.round(-c.y/c.zoom+k.height/2/c.zoom);dt.current.push({x:I-80,y:p-45,w:160,h:90,title:"Note "+(dt.current.length+1),body:"Added at viewport center"})}(v=ze.current)==null||v.postMessage({type:"cards",data:{cards:[...dt.current]}})},[]),Ye=u.useCallback(l=>{if(l.id||(l.id="node-"+Date.now()),!l.position){const v=ie.current,c=ge.current;if(!c)return;const x=c.getBoundingClientRect();l.position={x:Math.round(-v.x/v.zoom+x.width/2/v.zoom)-ot/2,y:Math.round(-v.y/v.zoom+x.height/2/v.zoom)-Ke/2}}l.data||(l.data={label:l.id}),Se.current&&Se.current([{type:"add",item:l}])},[]),vt=u.useCallback(()=>({...ie.current}),[]),Bn=u.useCallback(l=>{ie.current={...ie.current,...l},fe()},[fe]),jn=u.useCallback(l=>Ne(l.x,l.y),[Ne]),tr=n,Br=u.useMemo(()=>({wrapRef:ge,canvasRef:Bt,workerRef:ze,cameraRef:ie,nodesRef:K,edgesRef:ke,handleRegistryRef:an,syncNodesToWorker:cn,onNodesChangeRef:Se,onEdgesChangeRef:Te,sendCamera:fe,screenToWorld:Ne,viewportListeners:at,selectionListeners:Ze,zoomMin:le,zoomMax:me,snapToGrid:Rt,snapGrid:wt,nodeExtent:ut,defaultEdgeOptions:Et,edgeRouting:lt,resolvedNodesRef:Ge,noDragClassName:zt,noPanClassName:St,get nodes(){return t},get edges(){return n},get routedEdges(){return tr},get viewport(){return Dt},get connection(){return ft}}),[t,n,tr,Dt,ft,fe,Ne,cn,at,Ze,le,me,Rt,wt,ut,Et,lt,zt,St]);return{wrapRef:ge,canvasRef:Bt,canvasReady:Nn,onPointerDown:Ln,onPointerMove:Tn,onPointerUp:$n,resetView:ln,addCard:dn,addNode:Ye,getCamera:vt,setCamera:Bn,screenToFlowPosition:jn,store:Br}}function Jr(e,t,n,r,a,o){const i=a-n,h=o-r,g=i*i+h*h;if(g===0)return Math.hypot(e-n,t-r);let d=((e-n)*i+(t-r)*h)/g;return d=Math.max(0,Math.min(1,d)),Math.hypot(e-(n+d*i),t-(r+d*h))}const rr=e=>{let t;const n=new Set,r=(d,y)=>{const w=typeof d=="function"?d(t):d;if(!Object.is(w,t)){const C=t;t=y??(typeof w!="object"||w===null)?w:Object.assign({},t,w),n.forEach(R=>R(t,C))}},a=()=>t,h={setState:r,getState:a,getInitialState:()=>g,subscribe:d=>(n.add(d),()=>n.delete(d))},g=t=e(r,a,h);return h},Kr=(e=>e?rr(e):rr),eo=e=>e;function to(e,t=eo){const n=u.useSyncExternalStore(e.subscribe,u.useCallback(()=>t(e.getState()),[e,t]),u.useCallback(()=>t(e.getInitialState()),[e,t]));return u.useDebugValue(n),n}const Vt=u.createContext(null);function no(e={}){return Kr((t,n)=>({nodes:[],edges:[],viewport:{x:0,y:0,zoom:1},connection:null,minZoom:.1,maxZoom:5,width:0,height:0,domNode:null,nodesRef:{current:[]},edgesRef:{current:[]},cameraRef:{current:{x:0,y:0,zoom:1}},wrapRef:{current:null},workerRef:{current:null},onNodesChangeRef:{current:null},onEdgesChangeRef:{current:null},viewportListeners:new Set,selectionListeners:new Set,edgeLabelContainerRef:{current:null},viewportPortalRef:{current:null},screenToWorld:(r,a)=>{const o=n().cameraRef.current;return{x:(r-o.x)/o.zoom,y:(a-o.y)/o.zoom}},sendCamera:()=>{var a;const r=n();(a=r.workerRef.current)==null||a.postMessage({type:"camera",data:{camera:{...r.cameraRef.current}}})},...e}))}function Me(e,t){const n=u.useContext(Vt);if(!n)throw new Error("useCanvasStore must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");const r=typeof n.getState=="function"&&typeof n.subscribe=="function",a=u.useRef(e),o=u.useRef(t),i=u.useRef(void 0);a.current=e,o.current=t;const h=u.useCallback(g=>{const d=a.current;if(!d)return g;const y=d(g),w=o.current||Object.is;return i.current!==void 0&&w(i.current,y)?i.current:(i.current=y,y)},[]);return r?to(n,e?h:void 0):e?h(n):n}function pr(){const e=u.useContext(Vt);if(!e)throw new Error("useCanvasStoreApi must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");return typeof e.getState=="function"?e:{getState:()=>e,setState:()=>{},subscribe:()=>()=>{}}}const Kt=u.createContext(null);function ro(){return u.useContext(Kt)}function oo({node:e,nodeType:t}){var w,C,R;const n=Me(),r=u.useRef(null),a=e._absolutePosition||e.position,o=u.useRef(null);u.useEffect(()=>{const b=r.current;if(!b)return;const B=new ResizeObserver(S=>{var H,_,j,$;const{width:N,height:X}=S[0].contentRect;if(N>0&&X>0){const A=n.nodesRef.current.find(m=>m.id===e.id),W=(A==null?void 0:A.width)||((H=A==null?void 0:A.measured)==null?void 0:H.width),F=(A==null?void 0:A.height)||((_=A==null?void 0:A.measured)==null?void 0:_.height);(Math.abs((W||0)-N)>1||Math.abs((F||0)-X)>1)&&(($=(j=n.onNodesChangeRef).current)==null||$.call(j,[{id:e.id,type:"dimensions",dimensions:{width:N,height:X},setAttributes:!0}]))}});return B.observe(b),()=>B.disconnect()},[e.id,n]);const i=u.useCallback(b=>{var oe,V,ee,he;b.stopPropagation();const B=b.target.tagName;if(B==="INPUT"||B==="TEXTAREA"||B==="SELECT"||B==="BUTTON"||B==="A"||B==="LABEL"||b.target.isContentEditable)return;const S=n.noDragClassName||"nodrag",N=n.noPanClassName||"nopan";let X=b.target;for(;X&&X!==r.current;){if((oe=X.classList)!=null&&oe.contains(S)||(V=X.classList)!=null&&V.contains(N))return;X=X.parentElement}if(n.onNodesChangeRef.current){const ne=[];if(b.shiftKey)ne.push({id:e.id,type:"select",selected:!e.selected});else for(const ue of n.nodesRef.current)ue.id===e.id&&!ue.selected?ne.push({id:ue.id,type:"select",selected:!0}):ue.id!==e.id&&ue.selected&&ne.push({id:ue.id,type:"select",selected:!1});ne.length&&n.onNodesChangeRef.current(ne)}const H=n.cameraRef.current,_=n.wrapRef.current;if(!_)return;const j=_.getBoundingClientRect(),$=(b.clientX-j.left-H.x)/H.zoom,A=(b.clientY-j.top-H.y)/H.zoom,F=e.selected?n.nodesRef.current.filter(ne=>ne.selected&&ne.id!==e.id).map(ne=>({id:ne.id,startPos:{...ne.position}})):[];o.current={startPos:{...e.position},startMouse:{x:$,y:A},selectedStarts:F};const m=[{id:e.id,type:"position",dragging:!0}];for(const ne of F)m.push({id:ne.id,type:"position",dragging:!0});(he=(ee=n.onNodesChangeRef).current)==null||he.call(ee,m);const f=r.current;f&&f.setPointerCapture(b.pointerId);let M=null,L=null;const T=()=>{var ne,ce;L&&((ce=(ne=n.onNodesChangeRef).current)==null||ce.call(ne,L),L=null),M=null},Y=ne=>{var Pe,Ee;if(!o.current)return;const ce=n.cameraRef.current,ue=_.getBoundingClientRect(),Ie=(ne.clientX-ue.left-ce.x)/ce.zoom,le=(ne.clientY-ue.top-ce.y)/ce.zoom,me=Ie-o.current.startMouse.x,Le=le-o.current.startMouse.y;let ve={x:o.current.startPos.x+me,y:o.current.startPos.y+Le};if(n.snapToGrid&&n.snapGrid&&(ve={x:n.snapGrid[0]*Math.round(ve.x/n.snapGrid[0]),y:n.snapGrid[1]*Math.round(ve.y/n.snapGrid[1])}),e.parentId&&e.extent==="parent"){const xe=n.nodesRef.current.find(ae=>ae.id===e.parentId);if(xe){const ae=xe.width||160,Fe=xe.height||60,bt=e.width||((Pe=e.measured)==null?void 0:Pe.width)||160,Ae=e.height||((Ee=e.measured)==null?void 0:Ee.height)||60;ve={x:Math.max(0,Math.min(ve.x,ae-bt)),y:Math.max(0,Math.min(ve.y,Fe-Ae))}}}f&&(f.style.left=ve.x+"px",f.style.top=ve.y+"px");for(const xe of o.current.selectedStarts){let ae={x:xe.startPos.x+me,y:xe.startPos.y+Le};n.snapToGrid&&n.snapGrid&&(ae={x:n.snapGrid[0]*Math.round(ae.x/n.snapGrid[0]),y:n.snapGrid[1]*Math.round(ae.y/n.snapGrid[1])});const Fe=_.querySelector(`[data-nodeid="${xe.id}"]`);Fe&&(Fe.style.left=ae.x+"px",Fe.style.top=ae.y+"px")}const Re=[{id:e.id,type:"position",position:ve,dragging:!0}];for(const xe of o.current.selectedStarts){let ae={x:xe.startPos.x+me,y:xe.startPos.y+Le};n.snapToGrid&&n.snapGrid&&(ae={x:n.snapGrid[0]*Math.round(ae.x/n.snapGrid[0]),y:n.snapGrid[1]*Math.round(ae.y/n.snapGrid[1])}),Re.push({id:xe.id,type:"position",position:ae,dragging:!0})}L=Re,M||(M=requestAnimationFrame(T))},J=ne=>{var ue,Ie;if(!o.current)return;M&&(cancelAnimationFrame(M),T());const ce=[{id:e.id,type:"position",dragging:!1}];for(const le of o.current.selectedStarts)ce.push({id:le.id,type:"position",dragging:!1});(Ie=(ue=n.onNodesChangeRef).current)==null||Ie.call(ue,ce),o.current=null,f&&f.releasePointerCapture(ne.pointerId),f==null||f.removeEventListener("pointermove",Y),f==null||f.removeEventListener("pointerup",J)};f==null||f.addEventListener("pointermove",Y),f==null||f.addEventListener("pointerup",J)},[e,n]),h=u.useCallback(b=>{var _,j,$,A,W,F;if(!e.selected)return;const B=b.shiftKey?10:1;let S=0,N=0;switch(b.key){case"ArrowUp":N=-B;break;case"ArrowDown":N=B;break;case"ArrowLeft":S=-B;break;case"ArrowRight":S=B;break;case"Escape":(j=(_=n.onNodesChangeRef).current)==null||j.call(_,[{id:e.id,type:"select",selected:!1}]);return;case"Delete":case"Backspace":e.deletable!==!1&&((A=($=n.onNodesChangeRef).current)==null||A.call($,[{id:e.id,type:"remove"}]));return;default:return}b.preventDefault();const X={x:e.position.x+S,y:e.position.y+N},H=[{id:e.id,type:"position",position:X}];for(const m of n.nodesRef.current)m.selected&&m.id!==e.id&&H.push({id:m.id,type:"position",position:{x:m.position.x+S,y:m.position.y+N}});(F=(W=n.onNodesChangeRef).current)==null||F.call(W,H)},[e,n]),g=e.width||((w=e.measured)==null?void 0:w.width),d=e.height||((C=e.measured)==null?void 0:C.height),y=!!(g&&d);return E.jsx(Kt.Provider,{value:e.id,children:E.jsx("div",{ref:r,className:`ric-node-wrapper ${e.selected?"selected":""} ${e.dragging?"dragging":""}`,style:{position:"absolute",left:a.x,top:a.y,zIndex:e.type==="group"?0:e.zIndex||1,pointerEvents:e.type==="group"?"none":"all",visibility:y?"visible":"hidden",outline:"none"},"data-nodeid":e.id,tabIndex:e.selectable!==!1?0:void 0,role:"button","aria-label":`Node ${((R=e.data)==null?void 0:R.label)||e.id}`,"aria-selected":!!e.selected,onPointerDown:i,onKeyDown:h,children:E.jsx(t,{id:e.id,data:e.data,type:e.type,selected:!!e.selected,dragging:!!e.dragging,draggable:e.draggable!==!1,selectable:e.selectable!==!1,deletable:e.deletable!==!1,isConnectable:e.connectable!==!1,zIndex:e.zIndex||0,positionAbsoluteX:a.x,positionAbsoluteY:a.y,width:g,height:d,sourcePosition:e.sourcePosition,targetPosition:e.targetPosition,parentId:e.parentId,dragHandle:e.dragHandle})})})}const so=u.memo(oo),mr=160,vr=60;function or(e,t,n,r){var h,g;const a=e.width||((h=e.measured)==null?void 0:h.width)||mr,o=e.height||((g=e.measured)==null?void 0:g.height)||vr,i=e._absolutePosition||e.position;if(e.handleBounds){const d=e.handleBounds[t]||[],y=n?d.find(w=>w.id===n):d[0];if(y&&y.x!==void 0&&y.y!==void 0){const w=y.position||(t==="source"?"right":"left");return{x:i.x+y.x,y:i.y+y.y,position:w}}}if(r){const d=`${e.id}__${n||t}`,y=r.get(d);if(y&&y.x!==void 0&&y.y!==void 0)return{x:i.x+y.x,y:i.y+y.y,position:y.position||(t==="source"?"right":"left")}}if(e.handles&&e.handles.length){for(const d of e.handles)if(d.type===t&&(!n||d.id===n)){if(d.x!==void 0&&d.y!==void 0)return{x:i.x+d.x,y:i.y+d.y,position:d.position||(t==="source"?"right":"left")};const y=d.position||(t==="source"?"right":"left");switch(y){case"top":return{x:i.x+a/2,y:i.y,position:y};case"bottom":return{x:i.x+a/2,y:i.y+o,position:y};case"left":return{x:i.x,y:i.y+o/2,position:y};default:return{x:i.x+a,y:i.y+o/2,position:y}}}}return t==="source"?{x:i.x+a,y:i.y+o/2,position:"right"}:{x:i.x,y:i.y+o/2,position:"left"}}function ao(e,t,n){return n==="left"?e-t:n==="right"?e+t:e}function io(e,t,n){return n==="top"?e-t:n==="bottom"?e+t:e}function sr({x:e,y:t,position:n,type:r,onPointerDown:a}){return E.jsx("circle",{className:`ric-edge-anchor ric-edge-anchor-${r}`,cx:ao(e,10,n),cy:io(t,10,n),r:10,stroke:"transparent",fill:"transparent",style:{cursor:"move",pointerEvents:"stroke"},onPointerDown:a})}function co({edge:e,edgeType:t,nodes:n,reconnectable:r}){var _,j,$;const a=Me(),[o,i]=u.useState(null),h=u.useCallback((A,W,F,m)=>{var oe;W.stopPropagation(),W.preventDefault();const f=a.wrapRef.current;if(!f)return;const M=A==="source"?m:F,L=A==="source"?e.target:e.source;(oe=a.workerRef.current)==null||oe.postMessage({type:"connecting",data:{from:{x:M.x,y:M.y},to:{x:M.x,y:M.y}}});const T=f.getBoundingClientRect(),Y=V=>{var ce;const ee=a.cameraRef.current,he=(V.clientX-T.left-ee.x)/ee.zoom,ne=(V.clientY-T.top-ee.y)/ee.zoom;(ce=a.workerRef.current)==null||ce.postMessage({type:"connecting",data:{from:{x:M.x,y:M.y},to:{x:he,y:ne}}})},J=V=>{var me,Le,ve,Re;const ee=a.cameraRef.current,he=(V.clientX-T.left-ee.x)/ee.zoom,ne=(V.clientY-T.top-ee.y)/ee.zoom,ce=20/ee.zoom;let ue=null,Ie=null;const le=(me=a.handleRegistryRef)==null?void 0:me.current;for(const Pe of a.nodesRef.current){if(Pe.hidden)continue;const Ee=Pe.width||mr,xe=Pe.height||vr,ae=Pe._absolutePosition||Pe.position,Fe=[];if(le)for(const[,Ae]of le)Ae.nodeId===Pe.id&&Fe.push(Ae);const bt=Fe.length>0?Fe:Pe.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const Ae of bt){let et,Ve;if(Ae.x!==void 0&&Ae.y!==void 0)et=ae.x+Ae.x,Ve=ae.y+Ae.y;else switch(Ae.position||(Ae.type==="source"?"right":"left")){case"top":et=ae.x+Ee/2,Ve=ae.y;break;case"bottom":et=ae.x+Ee/2,Ve=ae.y+xe;break;case"left":et=ae.x,Ve=ae.y+xe/2;break;default:et=ae.x+Ee,Ve=ae.y+xe/2;break}if(Math.abs(he-et)<ce&&Math.abs(ne-Ve)<ce){ue=Pe,Ie=Ae.id||null;break}}if(ue)break}if(ue){const Pe=A==="source"?{source:ue.id,target:L,sourceHandle:Ie,targetHandle:e.targetHandle}:{source:L,target:ue.id,sourceHandle:e.sourceHandle,targetHandle:Ie};(ve=(Le=a.onEdgesChangeRef).current)==null||ve.call(Le,[{id:e.id,type:"remove"},{type:"add",item:{id:e.id,...Pe}}])}(Re=a.workerRef.current)==null||Re.postMessage({type:"connecting",data:null}),f.removeEventListener("pointermove",Y),f.removeEventListener("pointerup",J)};f.addEventListener("pointermove",Y),f.addEventListener("pointerup",J)},[e,a]),g=n.find(A=>A.id===e.source),d=n.find(A=>A.id===e.target),y=g&&!!(g.width||(_=g.measured)!=null&&_.width),w=d&&!!(d.width||(j=d.measured)!=null&&j.width),C=($=a.handleRegistryRef)==null?void 0:$.current,R=y?or(g,"source",e.sourceHandle,C):null,b=w?or(d,"target",e.targetHandle,C):null,B=e.type==="bezier"||e.type==="simplebezier"||e.type==="default",S=a.routedEdges||a.edges,N=S==null?void 0:S.find(A=>A.id===e.id),X=B?null:(N==null?void 0:N._routedPoints)||e._routedPoints||null,H=r!==!1&&e.reconnectable!==!1;return!R||!b?null:E.jsxs("g",{className:`ric-edge-wrapper ${e.selected?"selected":""}`,"data-edgeid":e.id,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),children:[E.jsx(t,{id:e.id,source:e.source,target:e.target,sourceX:R.x,sourceY:R.y,targetX:b.x,targetY:b.y,sourcePosition:R.position,targetPosition:b.position,sourceHandleId:e.sourceHandle,targetHandleId:e.targetHandle,data:e.data,type:e.type,selected:!!e.selected,animated:!!e.animated,label:e.label,style:e.style,selectable:e.selectable!==!1,deletable:e.deletable!==!1,routedPoints:X}),H&&(o||e.selected)&&E.jsxs(E.Fragment,{children:[E.jsx(sr,{x:R.x,y:R.y,position:R.position,type:"source",onPointerDown:A=>h("source",A,R,b)}),E.jsx(sr,{x:b.x,y:b.y,position:b.position,type:"target",onPointerDown:A=>h("target",A,R,b)})]})]})}const uo=u.memo(co);function br({selectionKeyCode:e="Shift",selectionMode:t="partial"}){var B;const n=Me(),[r,a]=u.useState(null),o=u.useRef(null);if(u.useEffect(()=>{const S=n.wrapRef.current;if(!S)return;let N=!1,X=null,H=!1;const _=F=>{F.key===e&&(H=!0)},j=F=>{F.key===e&&(H=!1)},$=F=>{if(!H)return;const m=F.target;if(m.closest(".ric-node-wrapper")||m.closest(".ric-handle"))return;N=!0;const f=n.cameraRef.current,M=S.getBoundingClientRect(),L=(F.clientX-M.left-f.x)/f.zoom,T=(F.clientY-M.top-f.y)/f.zoom;X={x:L,y:T},a({startX:L,startY:T,endX:L,endY:T}),F.stopPropagation()},A=F=>{if(!N||!X)return;const m=n.cameraRef.current,f=S.getBoundingClientRect(),M=(F.clientX-f.left-m.x)/m.zoom,L=(F.clientY-f.top-m.y)/m.zoom;a({startX:X.x,startY:X.y,endX:M,endY:L})},W=F=>{var J,oe;if(!N||!X)return;N=!1;const m=n.cameraRef.current,f=S.getBoundingClientRect(),M=(F.clientX-f.left-m.x)/m.zoom,L=(F.clientY-f.top-m.y)/m.zoom,T={x:Math.min(X.x,M),y:Math.min(X.y,L),width:Math.abs(M-X.x),height:Math.abs(L-X.y)},Y=[];for(const V of n.nodesRef.current){const ee=V._absolutePosition||V.position,he=V.width||160,ne=V.height||60;let ce;t==="full"?ce=ee.x>=T.x&&ee.y>=T.y&&ee.x+he<=T.x+T.width&&ee.y+ne<=T.y+T.height:ce=ee.x+he>T.x&&ee.x<T.x+T.width&&ee.y+ne>T.y&&ee.y<T.y+T.height,Y.push({id:V.id,type:"select",selected:ce})}Y.length&&((oe=(J=n.onNodesChangeRef).current)==null||oe.call(J,Y)),X=null,a(null)};return S.addEventListener("pointerdown",$,!0),S.addEventListener("pointermove",A),S.addEventListener("pointerup",W),window.addEventListener("keydown",_),window.addEventListener("keyup",j),()=>{S.removeEventListener("pointerdown",$,!0),S.removeEventListener("pointermove",A),S.removeEventListener("pointerup",W),window.removeEventListener("keydown",_),window.removeEventListener("keyup",j)}},[n,e,t]),!r)return null;const i=((B=n.cameraRef)==null?void 0:B.current)||{x:0,y:0,zoom:1},h=Math.min(r.startX,r.endX),g=Math.min(r.startY,r.endY),d=Math.abs(r.endX-r.startX),y=Math.abs(r.endY-r.startY),w=h*i.zoom+i.x,C=g*i.zoom+i.y,R=d*i.zoom,b=y*i.zoom;return E.jsx("div",{ref:o,className:"ric-selection-box",style:{position:"absolute",left:w,top:C,width:R,height:b,border:"1px dashed #3b82f6",background:"rgba(59, 130, 246, 0.08)",pointerEvents:"none",zIndex:100}})}br.displayName="SelectionBox";const wr=u.memo(br);function Mr(e,t){var a,o,i,h;const n=(a=e.handleRegistryRef)==null?void 0:a.current;if(!n)return;const r={source:[],target:[]};for(const[,g]of n)if(g.nodeId===t){const d={id:g.id,type:g.type,position:g.position,x:g.x,y:g.y,width:8,height:8};g.type==="source"?r.source.push(d):r.target.push(d)}(i=(o=e.onNodesChangeRef).current)==null||i.call(o,[{id:t,type:"dimensions",handleBounds:r,setAttributes:!1}]),(h=e.syncNodesToWorker)==null||h.call(e)}const Hn=new Set;function ar(e,t){Hn.has(t)||(Hn.add(t),queueMicrotask(()=>{Hn.delete(t),Mr(e,t)}))}function lo(e,t){const n=e.closest(".ric-node-wrapper");if(!n)return null;const r=n.getBoundingClientRect(),a=e.getBoundingClientRect(),o=t||1;return{x:(a.left+a.width/2-r.left)/o,y:(a.top+a.height/2-r.top)/o}}function Jt({type:e="source",position:t=e==="source"?"right":"left",id:n,isConnectable:r=!0,isConnectableStart:a=!0,isConnectableEnd:o=!0,children:i,className:h="",style:g={},onConnect:d,...y}){const w=u.useContext(Kt),C=Me(),R=u.useRef(null),b=u.useRef(C);b.current=C;const B=u.useCallback(()=>{var F,m,f;const H=R.current;if(!H||!w)return;const _=b.current,j=(F=_.handleRegistryRef)==null?void 0:F.current;if(!j)return;const $=`${w}__${n||e}`,A=(f=(m=_.cameraRef)==null?void 0:m.current)==null?void 0:f.zoom,W=lo(H,A);if(W){const M={nodeId:w,id:n||null,type:e,position:t,x:W.x,y:W.y};j.set($,M)}},[w,n,e,t]);u.useLayoutEffect(()=>{B()},[B]),u.useEffect(()=>{if(!w)return;const H=b.current;ar(H,w);const _=R.current,j=_==null?void 0:_.closest(".ric-node-wrapper"),$=new ResizeObserver(()=>{B(),ar(b.current,w)});return j&&$.observe(j),()=>{var m;$.disconnect();const A=b.current,W=(m=A.handleRegistryRef)==null?void 0:m.current,F=`${w}__${n||e}`;W==null||W.delete(F),Mr(A,w)}},[w,n,e,t,B]);const S=u.useCallback(()=>{var f;const H=b.current,_=H.nodesRef.current.find(M=>M.id===w);if(!_)return null;const j=_._absolutePosition||_.position,$=(f=H.handleRegistryRef)==null?void 0:f.current,A=`${w}__${n||e}`,W=$==null?void 0:$.get(A);if(W&&W.x!==void 0&&W.y!==void 0)return{x:j.x+W.x,y:j.y+W.y};const F=_.width||160,m=_.height||60;switch(t){case"top":return{x:j.x+F/2,y:j.y};case"bottom":return{x:j.x+F/2,y:j.y+m};case"left":return{x:j.x,y:j.y+m/2};default:return{x:j.x+F,y:j.y+m/2}}},[w,n,e,t]),N=u.useCallback(H=>{var L;if(!r||!a)return;H.stopPropagation(),H.preventDefault();const _=b.current,j=_.cameraRef.current,$=_.wrapRef.current;if(!$)return;const A=$.getBoundingClientRect(),W=S();if(!W)return;const F=W.x,m=W.y;(L=_.workerRef.current)==null||L.postMessage({type:"connecting",data:{from:{x:F,y:m},to:{x:F,y:m}}}),$.setPointerCapture(H.pointerId);const f=T=>{var oe;const Y=(T.clientX-A.left-j.x)/j.zoom,J=(T.clientY-A.top-j.y)/j.zoom;(oe=_.workerRef.current)==null||oe.postMessage({type:"connecting",data:{from:{x:F,y:m},to:{x:Y,y:J}}})},M=T=>{var ne,ce,ue,Ie;const Y=(T.clientX-A.left-j.x)/j.zoom,J=(T.clientY-A.top-j.y)/j.zoom,oe=20/j.zoom;let V=null,ee=null;const he=(ne=_.handleRegistryRef)==null?void 0:ne.current;for(const le of _.nodesRef.current){if(le.id===w||le.hidden)continue;const me=le.width||160,Le=le.height||60,ve=le._absolutePosition||le.position,Re=[];if(he)for(const[,Ee]of he)Ee.nodeId===le.id&&Re.push(Ee);const Pe=Re.length>0?Re:le.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const Ee of Pe){let xe,ae;if(Ee.x!==void 0&&Ee.y!==void 0)xe=ve.x+Ee.x,ae=ve.y+Ee.y;else switch(Ee.position||(Ee.type==="source"?"right":"left")){case"top":xe=ve.x+me/2,ae=ve.y;break;case"bottom":xe=ve.x+me/2,ae=ve.y+Le;break;case"left":xe=ve.x,ae=ve.y+Le/2;break;default:xe=ve.x+me,ae=ve.y+Le/2;break}if(Math.abs(Y-xe)<oe&&Math.abs(J-ae)<oe){V=le,ee=Ee.id||null;break}}if(V)break}if(V){const le={source:e==="source"?w:V.id,target:e==="source"?V.id:w,sourceHandle:e==="source"?n||null:ee,targetHandle:e==="source"?ee:n||null};(ue=(ce=_.onEdgesChangeRef)==null?void 0:ce.current)==null||ue.call(ce,[{type:"add",item:{id:`e-${le.source}-${le.target}`,...le}}])}(Ie=_.workerRef.current)==null||Ie.postMessage({type:"connecting",data:null}),$.removeEventListener("pointermove",f),$.removeEventListener("pointerup",M)};$.addEventListener("pointermove",f),$.addEventListener("pointerup",M)},[w,n,e,t,r,a,S]),X={top:{top:0,left:"50%",transform:"translate(-50%, -50%)"},bottom:{bottom:0,left:"50%",transform:"translate(-50%, 50%)"},left:{top:"50%",left:0,transform:"translate(-50%, -50%)"},right:{top:"50%",right:0,transform:"translate(50%, -50%)"}}[t]||{};return E.jsx("div",{ref:R,className:`ric-handle ric-handle-${t} ric-handle-${e} ${h}`,"data-handleid":n||null,"data-nodeid":w,"data-handlepos":t,"data-handletype":e,onPointerDown:N,style:{position:"absolute",width:8,height:8,borderRadius:"50%",background:"#1a192b",border:"none",zIndex:10,cursor:r?"crosshair":"default",boxSizing:"border-box",...X,...g},...y,children:i})}function fo({data:e,isConnectable:t,selected:n,targetPosition:r="left",sourcePosition:a="right",hideSourceHandle:o=!1,hideTargetHandle:i=!1}){return E.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&&E.jsx(Jt,{type:"target",position:r,isConnectable:t}),E.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!o&&E.jsx(Jt,{type:"source",position:a,isConnectable:t})]})}function Rr({data:e,isConnectable:t,selected:n,sourcePosition:r="right",hideSourceHandle:a=!1}){return E.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:[E.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!a&&E.jsx(Jt,{type:"source",position:r,isConnectable:t})]})}function kr({data:e,isConnectable:t,selected:n,targetPosition:r="left",hideTargetHandle:a=!1}){return E.jsxs("div",{className:`ric-output-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderTop:"2px solid #ff0072",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!a&&E.jsx(Jt,{type:"target",position:r,isConnectable:t}),E.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label})]})}function Cr({data:e,selected:t,width:n,height:r}){return E.jsx("div",{className:`ric-group-node${t?" selected":""}`,style:{width:n||300,height:r||200,background:"rgba(240, 240, 240, 0.25)",border:t?"2px solid #3b82f6":"1px dashed #ccc",borderRadius:8,padding:8,boxSizing:"border-box"},children:(e==null?void 0:e.label)&&E.jsx("div",{style:{fontSize:11,fontWeight:600,color:"#888",userSelect:"none"},children:e.label})})}function Er({x:e,y:t,label:n,labelStyle:r,labelShowBg:a=!0,labelBgStyle:o,labelBgPadding:i=[2,4],labelBgBorderRadius:h=2,children:g,className:d="",...y}){const[w,C]=u.useState({x:1,y:0,width:0,height:0}),R=u.useRef(null);return u.useEffect(()=>{if(R.current){const b=R.current.getBBox();C({x:b.x,y:b.y,width:b.width,height:b.height})}},[n]),n?E.jsxs("g",{transform:`translate(${e-w.width/2} ${t-w.height/2})`,className:`ric-edge-textwrapper ${d}`,visibility:w.width?"visible":"hidden",...y,children:[a&&E.jsx("rect",{width:w.width+2*i[0],x:-i[0],y:-i[1],height:w.height+2*i[1],className:"ric-edge-textbg",style:o,rx:h,ry:h}),E.jsx("text",{className:"ric-edge-text",y:w.height/2,dy:"0.3em",ref:R,style:r,children:n}),g]}):null}Er.displayName="EdgeText";const zr=u.memo(Er);function ir(e){return e!=null&&e!==""&&!isNaN(Number(e))}function en({id:e,path:t,labelX:n,labelY:r,label:a,labelStyle:o,labelShowBg:i,labelBgStyle:h,labelBgPadding:g,labelBgBorderRadius:d,interactionWidth:y=20,style:w,markerEnd:C,markerStart:R,className:b="",...B}){return E.jsxs(E.Fragment,{children:[E.jsx("path",{id:e,d:t,fill:"none",stroke:"#b1b1b7",strokeWidth:1.5,className:`ric-edge-path ${b}`,style:w,markerEnd:C,markerStart:R,...B}),y?E.jsx("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:y,className:"ric-edge-interaction",style:{pointerEvents:"stroke"}}):null,a&&ir(n)&&ir(r)?E.jsx(zr,{x:n,y:r,label:a,labelStyle:o,labelShowBg:i,labelBgStyle:h,labelBgPadding:g,labelBgBorderRadius:d}):null]})}const Zt=20;function cr(e,t,n){switch(n){case"right":return{x:e+Zt,y:t};case"left":return{x:e-Zt,y:t};case"bottom":return{x:e,y:t+Zt};case"top":return{x:e,y:t-Zt};default:return{x:e+Zt,y:t}}}const qn=u.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:i="bottom",targetPosition:h="top",label:g,labelStyle:d,labelShowBg:y,labelBgStyle:w,labelBgPadding:C,labelBgBorderRadius:R,style:b,markerEnd:B,markerStart:S,interactionWidth:N}){let X,H,_;const j=cr(n,r,i),$=cr(a,o,h),A=Math.abs($.x-j.x),W=Math.max(50,A*.5);let F,m,f,M;switch(i){case"left":F=j.x-W,m=j.y;break;case"top":F=j.x,m=j.y-W;break;case"bottom":F=j.x,m=j.y+W;break;default:F=j.x+W,m=j.y;break}switch(h){case"right":f=$.x+W,M=$.y;break;case"top":f=$.x,M=$.y-W;break;case"bottom":f=$.x,M=$.y+W;break;default:f=$.x-W,M=$.y;break}X=`M ${n},${r} L ${j.x},${j.y} C ${F},${m} ${f},${M} ${$.x},${$.y} L ${a},${o}`;const L=.5,T=.5;return H=T*T*T*j.x+3*T*T*L*F+3*T*L*L*f+L*L*L*$.x,_=T*T*T*j.y+3*T*T*L*m+3*T*L*L*M+L*L*L*$.y,E.jsx(en,{id:t,path:X,labelX:H,labelY:_,label:g,labelStyle:d,labelShowBg:y,labelBgStyle:w,labelBgPadding:C,labelBgBorderRadius:R,style:b,markerEnd:B,markerStart:S,interactionWidth:N})});qn.displayName="BezierEdge";function On({sourceX:e,sourceY:t,targetX:n,targetY:r}){const a=`M ${e},${t}L ${n},${r}`,o=(e+n)/2,i=(t+r)/2;return[a,o,i,0,0]}function Zn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a="right",targetPosition:o="left",curvature:i=.25}){const h=Math.abs(n-e),g=Math.abs(r-t),d=Math.sqrt(h*h+g*g),y=Math.max(d*i,50);let w,C,R,b;switch(a){case"top":w=e,C=t-y;break;case"bottom":w=e,C=t+y;break;case"left":w=e-y,C=t;break;default:w=e+y,C=t;break}switch(o){case"top":R=n,b=r-y;break;case"bottom":R=n,b=r+y;break;case"right":R=n+y,b=r;break;default:R=n-y,b=r;break}const B=`M ${e},${t} C ${w},${C} ${R},${b} ${n},${r}`,S=.5,N=1-S,X=N*N*N*e+3*N*N*S*w+3*N*S*S*R+S*S*S*n,H=N*N*N*t+3*N*N*S*C+3*N*S*S*b+S*S*S*r;return[B,X,H,0,0]}function Gn({sourceX:e,sourceY:t,targetX:n,targetY:r}){const a=Math.abs(n-e),o=Math.max(a*.5,50),i=e+o,h=n-o,g=`M ${e},${t} C ${i},${t} ${h},${r} ${n},${r}`,d=.5,y=.5,w=y*y*y*e+3*y*y*d*i+3*y*d*d*h+d*d*d*n,C=y*y*y*t+3*y*y*d*t+3*y*d*d*r+d*d*d*r;return[g,w,C,0,0]}function gn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a="right",targetPosition:o="left",borderRadius:i=5,offset:h=20}){const g=a==="left"||a==="right",d=Math.min(i,Math.abs(n-e)/2,Math.abs(r-t)/2);if(g){if(Math.abs(r-t)<1)return[`M ${e},${t} L ${n},${r}`,(e+n)/2,t,0,0];const R=(e+n)/2,b=r>t?1:-1;return[`M ${e},${t} L ${R-d},${t} Q ${R},${t} ${R},${t+b*d} L ${R},${r-b*d} Q ${R},${r} ${R+(n>R?d:-d)},${r} L ${n},${r}`,R,(t+r)/2,0,0]}const y=(t+r)/2,w=n>e?1:-1;return[`M ${e},${t} L ${e},${y-d} Q ${e},${y} ${e+w*d},${y} L ${n-w*d},${y} Q ${n},${y} ${n},${y+(r>y?d:-d)} L ${n},${r}`,(e+n)/2,y,0,0]}function ho({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[,a,o]=Zn({sourceX:e,sourceY:t,targetX:n,targetY:r});return[a,o,0,0]}function yo({sourceX:e,sourceY:t,targetX:n,targetY:r}){return[(e+n)/2,(t+r)/2,0,0]}function go(e,t,n){const r=n.filter(o=>o.id!==e.id),a={...e,id:e.id,source:t.source,target:t.target,sourceHandle:t.sourceHandle??e.sourceHandle,targetHandle:t.targetHandle??e.targetHandle};return r.push(a),r}const xn=160,pn=60,Gt=20,hn=12,mn=20;function ur(e,t,n){var i,h;const r=e.width||((i=e.measured)==null?void 0:i.width)||xn,a=e.height||((h=e.measured)==null?void 0:h.height)||pn,o=e._absolutePosition||e.position;if(e.handles&&e.handles.length>0){for(const g of e.handles)if(g.type===t&&(!n||g.id===n)){if(g.x!==void 0&&g.y!==void 0)return{x:o.x+g.x,y:o.y+g.y,dir:g.position||(t==="source"?"right":"left")};switch(g.position||(t==="source"?"right":"left")){case"top":return{x:o.x+r/2,y:o.y,dir:"top"};case"bottom":return{x:o.x+r/2,y:o.y+a,dir:"bottom"};case"left":return{x:o.x,y:o.y+a/2,dir:"left"};default:return{x:o.x+r,y:o.y+a/2,dir:"right"}}}}return t==="source"?{x:o.x+r,y:o.y+a/2,dir:"right"}:{x:o.x,y:o.y+a/2,dir:"left"}}function vn(e,t){switch(e.dir){case"right":return{x:e.x+t,y:e.y,dir:e.dir};case"left":return{x:e.x-t,y:e.y,dir:e.dir};case"bottom":return{x:e.x,y:e.y+t,dir:e.dir};case"top":return{x:e.x,y:e.y-t,dir:e.dir};default:return{x:e.x+t,y:e.y,dir:e.dir}}}function xo(e,t,n,r,a,o,i,h){const g=Math.min(e,n),d=Math.max(e,n),y=Math.min(t,r),w=Math.max(t,r);if(d<=a||g>=a+i||w<=o||y>=o+h)return!1;const C=.5;if(e>a+C&&e<a+i-C&&t>o+C&&t<o+h-C||n>a+C&&n<a+i-C&&r>o+C&&r<o+h-C)return!0;const R=(e+n)/2,b=(t+r)/2;if(R>a+C&&R<a+i-C&&b>o+C&&b<o+h-C)return!0;const B=[[a,o],[a+i,o],[a+i,o+h],[a,o+h]];for(let S=0;S<4;S++)if(po(e,t,n,r,B[S][0],B[S][1],B[(S+1)%4][0],B[(S+1)%4][1]))return!0;return!1}function po(e,t,n,r,a,o,i,h){const g=(i-a)*(t-o)-(h-o)*(e-a),d=(i-a)*(r-o)-(h-o)*(n-a),y=(n-e)*(o-t)-(r-t)*(a-e),w=(n-e)*(h-t)-(r-t)*(i-e);return(g>0&&d<0||g<0&&d>0)&&(y>0&&w<0||y<0&&w>0)}function Yn(e,t,n,r,a){for(let o=0;o<a.length;o++){const i=a[o];if(xo(e,t,n,r,i.x,i.y,i.w,i.h))return!1}return!0}function mo(e,t,n){for(let r=0;r<n.length;r++){const a=n[r];if(e>a.x&&e<a.x+a.w&&t>a.y&&t<a.y+a.h)return!0}return!1}function Qn(e,t){var r,a;const n=[];for(let o=0;o<e.length;o++){const i=e[o];if(i.hidden||t&&t.has(i.id)||i.type==="group")continue;const h=i._absolutePosition||i.position,g=i.width||((r=i.measured)==null?void 0:r.width)||xn,d=i.height||((a=i.measured)==null?void 0:a.height)||pn;n.push({id:i.id,x:h.x-Gt,y:h.y-Gt,w:g+2*Gt,h:d+2*Gt})}return n}function Sr(e,t,n){if(Yn(e.x,e.y,t.x,t.y,n))return null;const r=new Set,a=new Set;r.add(e.x),r.add(t.x),a.add(e.y),a.add(t.y);const o=Gt+5;e.dir==="right"?r.add(e.x+o):e.dir==="left"?r.add(e.x-o):e.dir==="top"?a.add(e.y-o):e.dir==="bottom"&&a.add(e.y+o),t.dir==="right"?r.add(t.x+o):t.dir==="left"?r.add(t.x-o):t.dir==="top"?a.add(t.y-o):t.dir==="bottom"&&a.add(t.y+o);for(let f=0;f<n.length;f++){const M=n[f];r.add(M.x),r.add(M.x+M.w),a.add(M.y),a.add(M.y+M.h)}const i=[...r].sort((f,M)=>f-M),h=[...a].sort((f,M)=>f-M),g=new Map,d=new Map;for(let f=0;f<i.length;f++)g.set(i[f],f);for(let f=0;f<h.length;f++)d.set(h[f],f);const y=i.length,w=h.length,C=(f,M)=>M*y+f,R=g.get(e.x),b=d.get(e.y),B=g.get(t.x),S=d.get(t.y);if(R===void 0||b===void 0||B===void 0||S===void 0)return null;const N=C(R,b),X=C(B,S),H=new Float64Array(y*w).fill(1/0),_=new Float64Array(y*w).fill(1/0),j=new Int32Array(y*w).fill(-1),$=new Int8Array(y*w).fill(-1),A=new Uint8Array(y*w);H[N]=0,_[N]=Math.abs(i[B]-e.x)+Math.abs(h[S]-e.y);const W=[N],F=15,m=[[1,0],[-1,0],[0,1],[0,-1]];for(;W.length>0;){let f=0;for(let V=1;V<W.length;V++)_[W[V]]<_[W[f]]&&(f=V);const M=W[f];if(W[f]=W[W.length-1],W.pop(),M===X){const V=[];let ee=X;for(;ee!==-1&&ee!==N;){const he=ee/y|0,ne=ee%y;V.unshift({x:i[ne],y:h[he]}),ee=j[ee]}return V.unshift({x:e.x,y:e.y}),vo(V,n)}if(A[M])continue;A[M]=1;const L=M/y|0,T=M%y,Y=i[T],J=h[L],oe=$[M];for(let V=0;V<4;V++){const ee=T+m[V][0],he=L+m[V][1];if(ee<0||ee>=y||he<0||he>=w)continue;const ne=C(ee,he);if(A[ne])continue;const ce=i[ee],ue=h[he];if(mo(ce,ue,n)||!Yn(Y,J,ce,ue,n))continue;const Ie=Math.abs(ce-Y)+Math.abs(ue-J),le=oe>=0&&oe!==V?F:0,me=H[M]+Ie+le;me<H[ne]&&(j[ne]=M,$[ne]=V,H[ne]=me,_[ne]=me+Math.abs(i[B]-ce)+Math.abs(h[S]-ue),W.push(ne))}}return null}function vo(e,t){if(!e||e.length<=2)return e;const n=[e[0]];for(let r=1;r<e.length-1;r++){const a=n[n.length-1],o=e[r],i=e[r+1],h=Math.abs(a.x-o.x)<.5&&Math.abs(o.x-i.x)<.5,g=Math.abs(a.y-o.y)<.5&&Math.abs(o.y-i.y)<.5;(h||g)&&Yn(a.x,a.y,i.x,i.y,t)||n.push(o)}return n.push(e[e.length-1]),n}function bo(e){const t=new Map,n=new Map;for(const a of e){const o=a._routedPoints;if(!(!o||o.length<2))for(let i=0;i<o.length-1;i++){const h=o[i],g=o[i+1];if(Math.abs(h.y-g.y)<.5){const d=Math.round(h.y*10)/10;t.has(d)||t.set(d,[]),t.get(d).push({edgeId:a.id,segIdx:i,x1:Math.min(h.x,g.x),x2:Math.max(h.x,g.x)})}else if(Math.abs(h.x-g.x)<.5){const d=Math.round(h.x*10)/10;n.has(d)||n.set(d,[]),n.get(d).push({edgeId:a.id,segIdx:i,y1:Math.min(h.y,g.y),y2:Math.max(h.y,g.y)})}}}const r=new Map;for(const a of e)a._routedPoints&&r.set(a.id,a._routedPoints.map(o=>({...o})));for(const[,a]of t){if(a.length<2)continue;const o=lr(a,"x1","x2");for(const i of o){if(i.length<2)continue;const h=(i.length-1)*hn/2;for(let g=0;g<i.length;g++){const d=i[g],y=-h+g*hn,w=r.get(d.edgeId);w&&(w[d.segIdx].y+=y,w[d.segIdx+1].y+=y)}}}for(const[,a]of n){if(a.length<2)continue;const o=lr(a,"y1","y2");for(const i of o){if(i.length<2)continue;const h=(i.length-1)*hn/2;for(let g=0;g<i.length;g++){const d=i[g],y=-h+g*hn,w=r.get(d.edgeId);w&&(w[d.segIdx].x+=y,w[d.segIdx+1].x+=y)}}}return e.map(a=>{const o=r.get(a.id);return o?{...a,_routedPoints:o}:a})}function lr(e,t,n){if(e.length<2)return[];const r=[...e].sort((i,h)=>i[t]-h[t]),a=[];let o=[r[0]];for(let i=1;i<r.length;i++){const h=o[o.length-1];r[i][t]<h[n]?o.push(r[i]):(o.length>1&&a.push(o),o=[r[i]])}return o.length>1&&a.push(o),a}function bn(e,t=6,n=!1){if(!e||e.length<2)return null;if(n)return wo(e);const r=t;let a=`M ${e[0].x},${e[0].y}`;for(let o=1;o<e.length-1;o++){const i=e[o-1],h=e[o],g=e[o+1],d=Math.abs(h.x-i.x)+Math.abs(h.y-i.y),y=Math.abs(g.x-h.x)+Math.abs(g.y-h.y),w=Math.min(r,d/2,y/2);if(w>.5){const C=h.x-i.x,R=h.y-i.y,b=g.x-h.x,B=g.y-h.y,S=Math.sqrt(C*C+R*R)||1,N=Math.sqrt(b*b+B*B)||1;a+=` L ${h.x-C/S*w},${h.y-R/S*w}`,a+=` Q ${h.x},${h.y} ${h.x+b/N*w},${h.y+B/N*w}`}else a+=` L ${h.x},${h.y}`}return a+=` L ${e[e.length-1].x},${e[e.length-1].y}`,a}function wo(e){if(e.length===2)return`M ${e[0].x},${e[0].y} L ${e[1].x},${e[1].y}`;if(e.length===3)return`M ${e[0].x},${e[0].y} Q ${e[1].x},${e[1].y} ${e[2].x},${e[2].y}`;const t=.3;let n=`M ${e[0].x},${e[0].y}`;for(let r=0;r<e.length-1;r++){const a=e[r===0?0:r-1],o=e[r],i=e[r+1],h=e[r+2<e.length?r+2:e.length-1],g=o.x+(i.x-a.x)*t,d=o.y+(i.y-a.y)*t,y=i.x-(h.x-o.x)*t,w=i.y-(h.y-o.y)*t;n+=` C ${g},${d} ${y},${w} ${i.x},${i.y}`}return n}function wn(e){if(!e||e.length<2)return{x:0,y:0};let t=0;for(let r=1;r<e.length;r++)t+=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);let n=t/2;for(let r=1;r<e.length;r++){const a=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);if(n<=a){const o=a>0?n/a:0;return{x:e[r-1].x+(e[r].x-e[r-1].x)*o,y:e[r-1].y+(e[r].y-e[r-1].y)*o}}n-=a}return{x:e[0].x,y:e[0].y}}function Mo(e,t){if(!e||!t||e.length===0||t.length===0)return t;const n={};for(const o of e)n[o.id]=o;const r=Qn(e,null),a=t.map(o=>{var $,A,W,F;const i=o.type||"default";if(i==="bezier"||i==="simplebezier"||i==="default")return o;const h=n[o.source],g=n[o.target];if(!h||!g||h.hidden||g.hidden)return o;const d=ur(h,"source",o.sourceHandle),y=ur(g,"target",o.targetHandle),w=vn(d,mn),C=vn(y,mn),R=5,b=r.filter(m=>m.id!==o.source&&m.id!==o.target),B=h._absolutePosition||h.position,S=h.width||(($=h.measured)==null?void 0:$.width)||xn,N=h.height||((A=h.measured)==null?void 0:A.height)||pn;b.push({id:o.source,x:B.x-R,y:B.y-R,w:S+2*R,h:N+2*R});const X=g._absolutePosition||g.position,H=g.width||((W=g.measured)==null?void 0:W.width)||xn,_=g.height||((F=g.measured)==null?void 0:F.height)||pn;if(b.push({id:o.target,x:X.x-R,y:X.y-R,w:H+2*R,h:_+2*R}),b.length===0)return o;const j=Sr(w,C,b);return j&&j.length>=2?(j.unshift({x:d.x,y:d.y}),j.push({x:y.x,y:y.y}),{...o,_routedPoints:j}):o});return bo(a)}function Ro(e,t,n,r,a,o,i,h){const g=Qn(i,h?new Set(h):null);if(g.length===0)return null;const d={x:e,y:t,dir:a||"right"},y={x:n,y:r,dir:o||"left"},w=vn(d,mn),C=vn(y,mn),R=Sr(w,C,g);return R&&R.length>=2?(R.unshift({x:d.x,y:d.y}),R.push({x:y.x,y:y.y}),R):null}const Vn=u.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,label:i,labelStyle:h,labelShowBg:g,labelBgStyle:d,labelBgPadding:y,labelBgBorderRadius:w,style:C,markerEnd:R,markerStart:b,interactionWidth:B,routedPoints:S}){let N,X,H;if(S&&S.length>=2){N=bn(S);const _=wn(S);X=_.x,H=_.y}else[N,X,H]=On({sourceX:n,sourceY:r,targetX:a,targetY:o});return E.jsx(en,{id:t,path:N,labelX:X,labelY:H,label:i,labelStyle:h,labelShowBg:g,labelBgStyle:d,labelBgPadding:y,labelBgBorderRadius:w,style:C,markerEnd:R,markerStart:b,interactionWidth:B})});Vn.displayName="StraightEdge";const Jn=u.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:i="bottom",targetPosition:h="top",label:g,labelStyle:d,labelShowBg:y,labelBgStyle:w,labelBgPadding:C,labelBgBorderRadius:R,style:b,markerEnd:B,markerStart:S,pathOptions:N,interactionWidth:X,routedPoints:H}){let _,j,$;if(H&&H.length>=2){_=bn(H);const A=wn(H);j=A.x,$=A.y}else[_,j,$]=gn({sourceX:n,sourceY:r,sourcePosition:i,targetX:a,targetY:o,targetPosition:h,borderRadius:N==null?void 0:N.borderRadius,offset:N==null?void 0:N.offset});return E.jsx(en,{id:t,path:_,labelX:j,labelY:$,label:g,labelStyle:d,labelShowBg:y,labelBgStyle:w,labelBgPadding:C,labelBgBorderRadius:R,style:b,markerEnd:B,markerStart:S,interactionWidth:X})});Jn.displayName="SmoothStepEdge";const Nr=u.memo(function({id:t,...n}){var a;const r=u.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(a=n.pathOptions)==null?void 0:a.offset]);return E.jsx(Jn,{...n,id:t,pathOptions:r})});Nr.displayName="StepEdge";const Kn=u.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:i,targetPosition:h,label:g,labelStyle:d,labelShowBg:y,labelBgStyle:w,labelBgPadding:C,labelBgBorderRadius:R,style:b,markerEnd:B,markerStart:S,interactionWidth:N,routedPoints:X}){let H,_,j;if(X&&X.length>=2){H=bn(X);const $=wn(X);_=$.x,j=$.y}else[H,_,j]=Gn({sourceX:n,sourceY:r,targetX:a,targetY:o});return E.jsx(en,{id:t,path:H,labelX:_,labelY:j,label:g,labelStyle:d,labelShowBg:y,labelBgStyle:w,labelBgPadding:C,labelBgBorderRadius:R,style:b,markerEnd:B,markerStart:S,interactionWidth:N})});Kn.displayName="SimpleBezierEdge";const ko={input:Rr,output:kr,group:Cr},Co={bezier:qn,straight:Vn,simplebezier:Kn},Eo=160,zo=60;function So(e){let t=!1;for(let n=0;n<e.length;n++){const r=e[n];if(!r.measured||r.measured.width==null||r.measured.height==null){t=!0;break}}return t?e.map(n=>{var r,a;return((r=n.measured)==null?void 0:r.width)!=null&&((a=n.measured)==null?void 0:a.height)!=null?n:{...n,measured:{width:n.width||Eo,height:n.height||zo}}}):e}function No({cards:e,nodes:t=[],edges:n=[],nodeTypes:r,edgeTypes:a,dark:o,gridSize:i,width:h="100%",height:g="420px",className:d="",style:y={},zoomMin:w,zoomMax:C,initialCamera:R,fitView:b,fitViewOptions:B,onNodesChange:S,onEdgesChange:N,onConnect:X,onConnectStart:H,onConnectEnd:_,onNodeClick:j,onNodeDoubleClick:$,onNodeMouseEnter:A,onNodeMouseMove:W,onNodeMouseLeave:F,onNodeContextMenu:m,onNodeDragStart:f,onNodeDrag:M,onNodeDragStop:L,onEdgeClick:T,onEdgeDoubleClick:Y,onEdgeMouseEnter:J,onEdgeMouseMove:oe,onEdgeMouseLeave:V,onEdgeContextMenu:ee,onPaneClick:he,onPaneContextMenu:ne,onPaneMouseEnter:ce,onPaneMouseMove:ue,onPaneMouseLeave:Ie,onSelectionChange:le,onInit:me,onMoveStart:Le,onMove:ve,onMoveEnd:Re,onDelete:Pe,onBeforeDelete:Ee,onError:xe,onDragOver:ae,onDrop:Fe,onDragEnter:bt,onDragLeave:Ae,nodesDraggable:et,nodesConnectable:Ve,elementsSelectable:Rt,multiSelectionKeyCode:wt,selectionOnDrag:kt,selectionMode:Ct,connectionMode:tn,connectionRadius:Tt,connectOnClick:nn,isValidConnection:rn,defaultEdgeOptions:on,snapToGrid:sn,snapGrid:$t,deleteKeyCode:ct,panActivationKeyCode:ut,panOnScroll:Et,panOnScrollMode:Mn,panOnScrollSpeed:Rn,zoomOnScroll:tt,zoomOnDoubleClick:er,zoomOnPinch:kn,preventScrolling:Cn,translateExtent:zt,nodeExtent:St,autoPanOnNodeDrag:En,autoPanOnConnect:zn,autoPanSpeed:Sn,edgesReconnectable:lt,elevateNodesOnSelect:ge,elevateEdgesOnSelect:Bt,noDragClassName:ze,noPanClassName:ie,onSelectionDragStart:dt,onSelectionDrag:K,onSelectionDragStop:ke,edgeRouting:an=!0,onHudUpdate:st,onNodesProcessed:Nt,showHud:Nn=!0,showHint:Pn=!0,hintText:He="Drag to pan · Scroll to zoom",children:Xe,...jt}){const[De,At]=u.useState({wx:0,wy:0,zoom:"1.00"}),Mt=u.useRef(null),Dt=u.useRef(null),In=u.useCallback(Q=>{At(Q),st==null||st(Q)},[st]),ft=u.useMemo(()=>({...ko,...r}),[r]),ht=u.useMemo(()=>({...Co,...a}),[a]),at=u.useMemo(()=>So(t),[t]),Ze=u.useMemo(()=>{const Q=t.filter($e=>$e.type&&ft[$e.type]);return Q.sort(($e,pe)=>{const Qe=$e.type==="group"||!$e.parentId&&Q.some(_e=>_e.parentId===$e.id),fe=pe.type==="group"||!pe.parentId&&Q.some(_e=>_e.parentId===pe.id);return Qe&&!fe?-1:!Qe&&fe?1:0})},[t,ft]),Pt=u.useMemo(()=>n.filter(Q=>Q.type&&ht[Q.type]),[n,ht]),Z=u.useMemo(()=>t.map(Q=>Q.type&&ft[Q.type]?{...Q,_customRendered:!0}:Q),[t,ft]),yt=u.useMemo(()=>n.map(Q=>Q.type&&ht[Q.type]?{...Q,_customRendered:!0}:Q),[n,ht]),{wrapRef:Ht,canvasRef:_t,canvasReady:Wt,onPointerDown:Ft,onPointerMove:Xt,onPointerUp:Yt,store:we}=xr({cards:e,nodes:Z,edges:yt,dark:o,gridSize:i,zoomMin:w,zoomMax:C,initialCamera:R,fitView:b,fitViewOptions:B,onHudUpdate:In,onNodesProcessed:Nt,onNodesChange:S,onEdgesChange:N,onConnect:X,onConnectStart:H,onConnectEnd:_,onNodeClick:j,onNodeDoubleClick:$,onNodeMouseEnter:A,onNodeMouseMove:W,onNodeMouseLeave:F,onNodeContextMenu:m,onNodeDragStart:f,onNodeDrag:M,onNodeDragStop:L,onEdgeClick:T,onEdgeDoubleClick:Y,onEdgeMouseEnter:J,onEdgeMouseMove:oe,onEdgeMouseLeave:V,onEdgeContextMenu:ee,onPaneClick:he,onPaneContextMenu:ne,onPaneMouseEnter:ce,onPaneMouseMove:ue,onPaneMouseLeave:Ie,onSelectionChange:le,onInit:me,onMoveStart:Le,onMove:ve,onMoveEnd:Re,onDelete:Pe,onBeforeDelete:Ee,onError:xe,nodesDraggable:et,nodesConnectable:Ve,elementsSelectable:Rt,multiSelectionKeyCode:wt,selectionOnDrag:kt,selectionMode:Ct,connectionMode:tn,connectionRadius:Tt,connectOnClick:nn,isValidConnection:rn,defaultEdgeOptions:on,snapToGrid:sn,snapGrid:$t,deleteKeyCode:ct,panActivationKeyCode:ut,panOnScroll:Et,panOnScrollMode:Mn,panOnScrollSpeed:Rn,zoomOnScroll:tt,zoomOnDoubleClick:er,zoomOnPinch:kn,preventScrolling:Cn,translateExtent:zt,nodeExtent:St,autoPanOnNodeDrag:En,autoPanOnConnect:zn,autoPanSpeed:Sn,edgesReconnectable:lt,elevateNodesOnSelect:ge,elevateEdgesOnSelect:Bt,noDragClassName:ze,noPanClassName:ie,onSelectionDragStart:dt,onSelectionDrag:K,onSelectionDragStop:ke,edgeRouting:an}),gt=u.useContext(Vt),It=gt&&typeof gt.getState=="function";u.useEffect(()=>{It&&queueMicrotask(()=>{gt.setState({nodes:at,edges:n,nodesRef:we.nodesRef,edgesRef:we.edgesRef,onNodesChangeRef:we.onNodesChangeRef,onEdgesChangeRef:we.onEdgesChangeRef,cameraRef:we.cameraRef,wrapRef:we.wrapRef,workerRef:we.workerRef})})},[It,at,n,we,gt]);const Se=u.useMemo(()=>({...we,edgeLabelContainerRef:Mt,viewportPortalRef:Dt,get nodes(){return at},get edges(){return n},get viewport(){return we.cameraRef.current},get minZoom(){return we.zoomMin||.1},get maxZoom(){return we.zoomMax||5},get domNode(){return we.wrapRef.current},get width(){var Q;return((Q=we.wrapRef.current)==null?void 0:Q.clientWidth)||0},get height(){var Q;return((Q=we.wrapRef.current)==null?void 0:Q.clientHeight)||0}}),[we,at,n]),Te=u.useRef(null),nt=u.useRef(null),xt=u.useRef(null),Ge=u.useRef(null);u.useEffect(()=>{let Q;const $e=()=>{const pe=we.cameraRef.current,Qe=`translate(${pe.x}px, ${pe.y}px) scale(${pe.zoom})`,fe=`translate(${pe.x}, ${pe.y}) scale(${pe.zoom})`;Te.current&&(Te.current.style.transform=Qe),nt.current&&nt.current.setAttribute("transform",fe),xt.current&&(xt.current.style.transform=Qe),Ge.current&&(Ge.current.style.transform=Qe),Q=requestAnimationFrame($e)};return Q=requestAnimationFrame($e),()=>cancelAnimationFrame(Q)},[we]);const[rt,cn]=u.useState(null);u.useEffect(()=>{if(!Ze.length)return;let Q;const $e=()=>{var ln,dn;const pe=we.cameraRef.current,Qe=we.wrapRef.current;if(!Qe){Q=requestAnimationFrame($e);return}const fe=Qe.getBoundingClientRect(),_e=200,pt=-pe.x/pe.zoom-_e,Ln=-pe.y/pe.zoom-_e,Tn=(fe.width-pe.x)/pe.zoom+_e,$n=(fe.height-pe.y)/pe.zoom+_e,mt=new Set;for(const Ye of Ze){const vt=Ye._absolutePosition||Ye.position,Bn=Ye.width||((ln=Ye.measured)==null?void 0:ln.width)||200,jn=Ye.height||((dn=Ye.measured)==null?void 0:dn.height)||100;vt.x+Bn>=pt&&vt.x<=Tn&&vt.y+jn>=Ln&&vt.y<=$n&&mt.add(Ye.id)}cn(Ye=>{if(!Ye||Ye.size!==mt.size)return mt;for(const vt of mt)if(!Ye.has(vt))return mt;return Ye}),Q=requestAnimationFrame($e)};return Q=requestAnimationFrame($e),()=>cancelAnimationFrame(Q)},[Ze,we]);const Ne=u.useMemo(()=>rt?Ze.filter(Q=>rt.has(Q.id)):Ze,[Ze,rt]),Je=Ze.length>0,un=Pt.length>0;return E.jsx(Vt.Provider,{value:Se,children:E.jsxs("div",{ref:Ht,className:`ric-wrap ${d}`,style:{width:h,height:g,...y},onPointerDown:Ft,onPointerMove:Xt,onPointerUp:Yt,onDragOver:ae,onDrop:Fe,onDragEnter:bt,onDragLeave:Ae,tabIndex:0,children:[E.jsx("canvas",{ref:_t,className:"ric-canvas"}),!Wt&&E.jsx("div",{className:"ric-loader",children:E.jsx("div",{className:"ric-spinner"})}),un&&E.jsx("svg",{className:"ric-edges-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:E.jsx("g",{ref:nt,children:Pt.map(Q=>E.jsx(uo,{edge:Q,edgeType:ht[Q.type],nodes:t,reconnectable:lt},Q.id))})}),Je&&E.jsx("div",{ref:Te,className:"ric-nodes-overlay",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:10},children:Ne.map(Q=>E.jsx(so,{node:Q,nodeType:ft[Q.type]},Q.id))}),E.jsx("div",{ref:Q=>{Mt.current=Q,xt.current=Q},className:"ric-edge-labels",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:5}}),E.jsx("div",{ref:Q=>{Dt.current=Q,Ge.current=Q},className:"ric-viewport-portal",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:6}}),Pn&&E.jsx("div",{className:"ric-hint",children:He}),Nn&&E.jsxs("div",{className:"ric-info",children:["world: (",De.wx,", ",De.wy,")   zoom: ",De.zoom,"x",De.nodeCount>0&&E.jsxs(E.Fragment,{children:["   nodes: ",De.nodeCount]}),De.edgeCount>0&&E.jsxs(E.Fragment,{children:["   edges: ",De.edgeCount]})]}),E.jsx(wr,{selectionKeyCode:wt||"Shift",selectionMode:Ct||"partial"}),Xe]})})}function Po({children:e}){const t=u.useRef(null);return t.current||(t.current=no()),E.jsx(Vt.Provider,{value:t.current,children:e})}function Pr(e,t){const n=[],r=new Map,a=[];for(const o of e)if(o.type==="add")a.push(o);else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const i=r.get(o.id);i?i.push(o):r.set(o.id,[o])}for(const o of t){const i=r.get(o.id);if(!i){n.push(o);continue}if(i[0].type==="remove")continue;if(i[0].type==="replace"){n.push({...i[0].item});continue}const h={...o};for(const g of i)Io(g,h);n.push(h)}for(const o of a)o.index!==void 0?n.splice(o.index,0,{...o.item}):n.push({...o.item});return n}function Io(e,t){switch(e.type){case"select":t.selected=e.selected;break;case"position":e.position!==void 0&&(t.position=e.position),e.dragging!==void 0&&(t.dragging=e.dragging);break;case"dimensions":e.dimensions!==void 0&&(t.measured={...e.dimensions},(e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height)),e.handleBounds!==void 0&&(t.handleBounds=e.handleBounds);break}}function Ir(e,t){return Pr(e,t)}function Lr(e,t){return Pr(e,t)}function Lo(e,t){return!e.source||!e.target?(console.warn("addEdge: source and target are required"),t):t.some(r=>r.source===e.source&&r.target===e.target&&(r.sourceHandle||null)===(e.sourceHandle||null)&&(r.targetHandle||null)===(e.targetHandle||null))?t:[...t,{id:e.id||`e-${e.source}-${e.target}`,...e}]}function To(e){const[t,n]=u.useState(e),r=u.useCallback(a=>n(o=>Ir(a,o)),[]);return[t,n,r]}function $o(e){const[t,n]=u.useState(e),r=u.useCallback(a=>n(o=>Lr(a,o)),[]);return[t,n,r]}function Tr(){const e=pr(),t=u.useCallback(()=>typeof e.getState=="function"?e.getState():e,[e]),n=u.useCallback(()=>[...t().nodesRef.current],[t]),r=u.useCallback(()=>[...t().edgesRef.current],[t]),a=u.useCallback(m=>t().nodesRef.current.find(f=>f.id===m),[t]),o=u.useCallback(m=>t().edgesRef.current.find(f=>f.id===m),[t]),i=u.useCallback(m=>{var f,M,L,T;if(typeof m=="function"){const Y=m(t().nodesRef.current);(M=(f=t().onNodesChangeRef).current)==null||M.call(f,[...t().nodesRef.current.map(J=>({id:J.id,type:"remove"})),...Y.map(J=>({type:"add",item:J}))])}else(T=(L=t().onNodesChangeRef).current)==null||T.call(L,[...t().nodesRef.current.map(Y=>({id:Y.id,type:"remove"})),...m.map(Y=>({type:"add",item:Y}))])},[t]),h=u.useCallback(m=>{var f,M,L,T;if(typeof m=="function"){const Y=m(t().edgesRef.current);(M=(f=t().onEdgesChangeRef).current)==null||M.call(f,[...t().edgesRef.current.map(J=>({id:J.id,type:"remove"})),...Y.map(J=>({type:"add",item:J}))])}else(T=(L=t().onEdgesChangeRef).current)==null||T.call(L,[...t().edgesRef.current.map(Y=>({id:Y.id,type:"remove"})),...m.map(Y=>({type:"add",item:Y}))])},[t]),g=u.useCallback(m=>{var M,L;const f=Array.isArray(m)?m:[m];(L=(M=t().onNodesChangeRef).current)==null||L.call(M,f.map(T=>({type:"add",item:T})))},[t]),d=u.useCallback(m=>{var M,L;const f=Array.isArray(m)?m:[m];(L=(M=t().onEdgesChangeRef).current)==null||L.call(M,f.map(T=>({type:"add",item:T})))},[t]),y=u.useCallback(({nodes:m=[],edges:f=[]})=>{if(m.length&&t().onNodesChangeRef.current){t().onNodesChangeRef.current(m.map(L=>({id:L.id,type:"remove"})));const M=yr(m,t().edgesRef.current);M.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(M.map(L=>({id:L.id,type:"remove"})))}f.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(f.map(M=>({id:M.id,type:"remove"})))},[t]),w=u.useCallback(()=>{const m=t().cameraRef.current;return{x:m.x,y:m.y,zoom:m.zoom}},[t]),C=u.useRef(null),R=u.useCallback((m,f)=>{if(C.current&&cancelAnimationFrame(C.current),!f||f<=0){t().cameraRef.current={...m},t().sendCamera();return}const M={...t().cameraRef.current},L=performance.now(),T=Y=>{const J=Y-L,oe=Math.min(J/f,1),V=1-Math.pow(1-oe,3);t().cameraRef.current={x:M.x+(m.x-M.x)*V,y:M.y+(m.y-M.y)*V,zoom:M.zoom+(m.zoom-M.zoom)*V},t().sendCamera(),oe<1&&(C.current=requestAnimationFrame(T))};C.current=requestAnimationFrame(T)},[t]),b=u.useCallback((m,f)=>{const M={x:m.x??t().cameraRef.current.x,y:m.y??t().cameraRef.current.y,zoom:m.zoom??t().cameraRef.current.zoom};R(M,f==null?void 0:f.duration)},[t,R]),B=u.useCallback(()=>t().cameraRef.current.zoom,[t]),S=u.useCallback(m=>{const f=t().cameraRef.current,M=t().wrapRef.current;if(!M)return;const L=M.getBoundingClientRect(),T=L.width/2,Y=L.height/2,J=1.2,oe={x:T-(T-f.x)*J,y:Y-(Y-f.y)*J,zoom:Math.min(t().zoomMax,f.zoom*J)};R(oe,m==null?void 0:m.duration)},[t,R]),N=u.useCallback(m=>{const f=t().cameraRef.current,M=t().wrapRef.current;if(!M)return;const L=M.getBoundingClientRect(),T=L.width/2,Y=L.height/2,J=1/1.2,oe={x:T-(T-f.x)*J,y:Y-(Y-f.y)*J,zoom:Math.max(t().zoomMin,f.zoom*J)};R(oe,m==null?void 0:m.duration)},[t,R]),X=u.useCallback((m,f)=>{const M=t().cameraRef.current,L=t().wrapRef.current;if(!L)return;const T=L.getBoundingClientRect(),Y=T.width/2,J=T.height/2,oe=Math.min(t().zoomMax,Math.max(t().zoomMin,m)),V=oe/M.zoom,ee={x:Y-(Y-M.x)*V,y:J-(J-M.y)*V,zoom:oe};R(ee,f==null?void 0:f.duration)},[t,R]),H=u.useCallback((m={})=>{const f=t().nodesRef.current;if(!f.length)return;const M=t().wrapRef.current;if(!M)return;const L=M.getBoundingClientRect(),T=m.padding??.1,Y=m.nodes?f.filter(V=>m.nodes.some(ee=>ee.id===V.id)):f;if(!Y.length)return;const J=yn(Y),oe=Lt(J,L.width,L.height,T);m.maxZoom&&(oe.zoom=Math.min(oe.zoom,m.maxZoom)),m.minZoom&&(oe.zoom=Math.max(oe.zoom,m.minZoom)),R(oe,m.duration)},[t,R]),_=u.useCallback((m,f={})=>{const M=t().wrapRef.current;if(!M)return;const L=M.getBoundingClientRect(),T=f.padding??.1,Y=Lt(m,L.width,L.height,T);f.maxZoom&&(Y.zoom=Math.min(Y.zoom,f.maxZoom)),f.minZoom&&(Y.zoom=Math.max(Y.zoom,f.minZoom)),R(Y,f.duration)},[t,R]),j=u.useCallback((m,f,M={})=>{const L=t().wrapRef.current;if(!L)return;const T=L.getBoundingClientRect(),Y=M.zoom??t().cameraRef.current.zoom,J={x:T.width/2-m*Y,y:T.height/2-f*Y,zoom:Y};R(J,M.duration)},[t,R]),$=u.useCallback(()=>({nodes:[...t().nodesRef.current],edges:[...t().edgesRef.current],viewport:{...t().cameraRef.current}}),[t]),A=u.useCallback(m=>t().screenToWorld(m.x,m.y),[t]),W=u.useCallback(m=>{const f=t().cameraRef.current,M=t().wrapRef.current;if(!M)return{x:0,y:0};const L=M.getBoundingClientRect();return{x:m.x*f.zoom+f.x+L.left,y:m.y*f.zoom+f.y+L.top}},[t]),F=u.useCallback((m,f)=>{var T,Y;const M=t().nodesRef.current.find(J=>J.id===m);if(!M)return;const L=typeof f=="function"?f(M.data):{...M.data,...f};(Y=(T=t().onNodesChangeRef).current)==null||Y.call(T,[{id:m,type:"replace",item:{...M,data:L}}])},[t]);return{getNodes:n,getEdges:r,getNode:a,getEdge:o,setNodes:i,setEdges:h,addNodes:g,addEdges:d,deleteElements:y,getViewport:w,setViewport:b,getZoom:B,zoomIn:S,zoomOut:N,zoomTo:X,fitView:H,fitBounds:_,setCenter:j,screenToFlowPosition:A,flowToScreenPosition:W,updateNodeData:F,toObject:$}}function Bo(){return Me().nodes}function jo(){return Me().edges}function Ao(){return Me().viewport}function Do(){return Me().connection}function Ho(e){const t=Me(),n=Array.isArray(e)?e:[e];return u.useMemo(()=>n.map(r=>{const a=t.nodes.find(o=>o.id===r);return a?{id:a.id,type:a.type,data:a.data}:null}).filter(Boolean),[t.nodes,...n])}function _o(e){const t=Me();return u.useMemo(()=>t.edges.filter(n=>n.source===e||n.target===e),[t.edges,e])}function Wo({nodeId:e,type:t,handleId:n}){const r=Me();return u.useMemo(()=>r.edges.filter(a=>t==="source"?a.source===e&&(n?a.sourceHandle===n:!0):a.target===e&&(n?a.targetHandle===n:!0)),[r.edges,e,t,n])}function Fo({onChange:e,onStart:t,onEnd:n}){const r=Me(),a=u.useRef(e),o=u.useRef(t),i=u.useRef(n);u.useEffect(()=>{a.current=e},[e]),u.useEffect(()=>{o.current=t},[t]),u.useEffect(()=>{i.current=n},[n]),u.useEffect(()=>{const h=g=>{var d;(d=a.current)==null||d.call(a,{x:g.x,y:g.y,zoom:g.zoom})};return r.viewportListeners.add(h),()=>r.viewportListeners.delete(h)},[s])}function Xo({onChange:e}){const t=Me(),n=u.useRef(e);u.useEffect(()=>{n.current=e},[e]),u.useEffect(()=>{const r=a=>{var o;(o=n.current)==null||o.call(n,a)};return t.selectionListeners.add(r),()=>t.selectionListeners.delete(r)},[s])}function Yo(e){const[t,n]=u.useState(!1),r=Array.isArray(e)?e:[e];return u.useEffect(()=>{const a=i=>{r.includes(i.key)&&n(!0)},o=i=>{r.includes(i.key)&&n(!1)};return window.addEventListener("keydown",a),window.addEventListener("keyup",o),()=>{window.removeEventListener("keydown",a),window.removeEventListener("keyup",o)}},[r.join(",")]),t}function Uo(){const e=Me();return u.useCallback(t=>{var n;(n=e.workerRef.current)==null||n.postMessage({type:"nodes",data:{nodes:[...s().nodesRef.current]}})},[s])}const qo=e=>{var t;return((t=e.nodes)==null?void 0:t.length)>0};function Oo(e={}){return Me(qo)}function Zo(e){const t=Me();return u.useMemo(()=>t.nodes.find(n=>n.id===e)||void 0,[t.nodes,e])}function Go(e,t){return Me(e,t)}function Qo(){return pr()}function Vo({maxHistorySize:e=100}={}){const t=Me(),n=u.useRef([]),r=u.useRef([]),[,a]=u.useState(0),o=u.useRef(null),i=u.useCallback(()=>{const d={nodes:s().nodesRef.current.map(y=>({...y,data:{...y.data}})),edges:s().edgesRef.current.map(y=>({...y}))};o.current&&JSON.stringify(o.current.nodes.map(y=>y.id))===JSON.stringify(d.nodes.map(y=>y.id))&&JSON.stringify(o.current.edges.map(y=>y.id))===JSON.stringify(d.edges.map(y=>y.id))||(n.current.push(d),n.current.length>e&&n.current.shift(),r.current=[],o.current=d,a(y=>y+1))},[t,e]),h=u.useCallback(()=>{var y,w,C,R;const d=n.current.pop();d&&(r.current.push({nodes:s().nodesRef.current.map(b=>({...b,data:{...b.data}})),edges:s().edgesRef.current.map(b=>({...b}))}),(w=(y=s().onNodesChangeRef).current)==null||w.call(y,[...s().nodesRef.current.map(b=>({id:b.id,type:"remove"})),...d.nodes.map(b=>({type:"add",item:b}))]),(R=(C=s().onEdgesChangeRef).current)==null||R.call(C,[...s().edgesRef.current.map(b=>({id:b.id,type:"remove"})),...d.edges.map(b=>({type:"add",item:b}))]),o.current=d,a(b=>b+1))},[s]),g=u.useCallback(()=>{var y,w,C,R;const d=r.current.pop();d&&(n.current.push({nodes:s().nodesRef.current.map(b=>({...b,data:{...b.data}})),edges:s().edgesRef.current.map(b=>({...b}))}),(w=(y=s().onNodesChangeRef).current)==null||w.call(y,[...s().nodesRef.current.map(b=>({id:b.id,type:"remove"})),...d.nodes.map(b=>({type:"add",item:b}))]),(R=(C=s().onEdgesChangeRef).current)==null||R.call(C,[...s().edgesRef.current.map(b=>({id:b.id,type:"remove"})),...d.edges.map(b=>({type:"add",item:b}))]),o.current=d,a(b=>b+1))},[s]);return{undo:h,redo:g,takeSnapshot:i,canUndo:n.current.length>0,canRedo:r.current.length>0}}function Jo(e){const t=u.useRef(e);return u.useEffect(()=>{t.current=e},[e]),u.useCallback(n=>r=>{const a=t.current(r);a!==!1&&a!=null&&n(Array.isArray(a)?a:r)},[])}function Ko(e){const t=u.useRef(e);return u.useEffect(()=>{t.current=e},[e]),u.useCallback(n=>r=>{const a=t.current(r);a!==!1&&a!=null&&n(Array.isArray(a)?a:r)},[])}const _n=160,Wn=60;function es({width:e=200,height:t=150,nodeColor:n="#3b82f6",nodeStrokeColor:r="#fff",maskColor:a="rgba(0,0,0,0.1)",style:o={},className:i=""}){const h=Me(),g=u.useRef(null),d=u.useRef(null),y=u.useCallback(()=>{const w=g.current;if(!w)return;const C=w.getContext("2d"),R=window.devicePixelRatio||1;w.width=e*R,w.height=t*R,C.scale(R,R),C.clearRect(0,0,e,t);const b=h.nodesRef.current;if(!b.length)return;let B=1/0,S=1/0,N=-1/0,X=-1/0;for(const f of b){const M=f.width||_n,L=f.height||Wn;f.position.x<B&&(B=f.position.x),f.position.y<S&&(S=f.position.y),f.position.x+M>N&&(N=f.position.x+M),f.position.y+L>X&&(X=f.position.y+L)}const H=40;B-=H,S-=H,N+=H,X+=H;const _=N-B,j=X-S,$=Math.min(e/_,t/j),A=(e-_*$)/2,W=(t-j*$)/2;for(const f of b){if(f.hidden)continue;const M=f.width||_n,L=f.height||Wn,T=(f.position.x-B)*$+A,Y=(f.position.y-S)*$+W,J=M*$,oe=L*$;C.fillStyle=f.selected?"#f59e0b":typeof n=="function"?n(f):n,C.fillRect(T,Y,Math.max(J,2),Math.max(oe,2))}const F=h.cameraRef.current,m=h.wrapRef.current;if(m){const f=m.getBoundingClientRect(),M=-F.x/F.zoom,L=-F.y/F.zoom,T=f.width/F.zoom,Y=f.height/F.zoom;C.fillStyle=a,C.fillRect(0,0,e,t);const J=(M-B)*$+A,oe=(L-S)*$+W,V=T*$,ee=Y*$;C.clearRect(J,oe,V,ee);for(const he of b){if(he.hidden)continue;const ne=he.width||_n,ce=he.height||Wn,ue=(he.position.x-B)*$+A,Ie=(he.position.y-S)*$+W;C.fillStyle=he.selected?"#f59e0b":typeof n=="function"?n(he):n,C.fillRect(ue,Ie,Math.max(ne*$,2),Math.max(ce*$,2))}C.strokeStyle="#3b82f6",C.lineWidth=1.5,C.strokeRect(J,oe,V,ee)}},[h,e,t,n,r,a]);return u.useEffect(()=>{let w=!0;function C(){w&&(y(),d.current=requestAnimationFrame(C))}const R=setInterval(()=>{cancelAnimationFrame(d.current),d.current=requestAnimationFrame(C)},66);return y(),()=>{w=!1,clearInterval(R),cancelAnimationFrame(d.current)}},[y]),E.jsx("canvas",{ref:g,className:`ric-minimap ${i}`,style:{position:"absolute",bottom:30,right:10,width:e,height:t,borderRadius:4,border:"1px solid rgba(0,0,0,0.1)",background:"rgba(255,255,255,0.9)",pointerEvents:"none",...o}})}function ts(){return E.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:[E.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),E.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function ns(){return E.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:E.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function rs(){return E.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:E.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}function os(){return E.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:[E.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),E.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function ss(){return E.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:[E.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),E.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})}function Qt({children:e,className:t="",...n}){return E.jsx("button",{className:`ric-controls-button ${t}`,style:is,...n,children:e})}function as({showZoom:e=!0,showFitView:t=!0,showInteractive:n=!1,fitViewOptions:r,onZoomIn:a,onZoomOut:o,onFitView:i,onInteractiveChange:h,position:g="bottom-left",orientation:d="vertical",style:y={},className:w="","aria-label":C="Canvas controls",children:R}){const b=Me(),{zoomIn:B,zoomOut:S,fitView:N,getZoom:X}=Tr(),[H,_]=u.useState(!0),j=X()<=b.zoomMin,$=X()>=b.zoomMax,A=u.useCallback(()=>{B(),a==null||a()},[B,a]),W=u.useCallback(()=>{S(),o==null||o()},[S,o]),F=u.useCallback(()=>{N(r||{padding:.1}),i==null||i()},[N,r,i]),m=u.useCallback(()=>{const M=!H;_(M),h==null||h(M)},[H,h]),f={"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%)"}}[g]||{bottom:30,left:10};return E.jsxs("div",{className:`ric-controls ${w}`,style:{position:"absolute",display:"flex",flexDirection:d==="horizontal"?"row":"column",gap:2,zIndex:5,...f,...y},role:"toolbar","aria-label":C,children:[e&&E.jsxs(E.Fragment,{children:[E.jsx(Qt,{onClick:A,disabled:$,title:"Zoom in","aria-label":"Zoom in",className:"ric-controls-zoomin",children:E.jsx(ts,{})}),E.jsx(Qt,{onClick:W,disabled:j,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:E.jsx(ns,{})})]}),t&&E.jsx(Qt,{onClick:F,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:E.jsx(rs,{})}),n&&E.jsx(Qt,{onClick:m,title:H?"Lock interactivity":"Unlock interactivity","aria-label":H?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:H?E.jsx(ss,{}):E.jsx(os,{})}),R]})}const is={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},cs=u.memo(as);function us({variant:e="lines",gap:t=40,size:n=1,color:r,style:a={},className:o=""}){const i=Me();return i.workerRef.current&&i.workerRef.current.postMessage({type:"background",data:{variant:e,gap:t,size:n,color:r}}),null}function ls({position:e="top-left",style:t={},className:n="",children:r}){const a={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:10,left:10},"bottom-right":{bottom:10,right:10},"bottom-center":{bottom:10,left:"50%",transform:"translateX(-50%)"}}[e]||{top:10,left:10};return E.jsx("div",{className:`ric-panel ${n}`,style:{position:"absolute",zIndex:5,pointerEvents:"all",...a,...t},onPointerDown:o=>o.stopPropagation(),children:r})}function ds({minWidth:e=10,minHeight:t=10,maxWidth:n=1/0,maxHeight:r=1/0,isVisible:a=!0,handleStyle:o={},lineStyle:i={},color:h="#3b82f6",onResizeStart:g,onResize:d,onResizeEnd:y}){const w=u.useContext(Kt),C=Me(),R=u.useRef(null),b=u.useCallback((N,X)=>{N.stopPropagation(),N.preventDefault();const H=C.nodesRef.current.find($=>$.id===w);if(!H)return;R.current={direction:X,startX:N.clientX,startY:N.clientY,width:H.width||160,height:H.height||60},g==null||g(N,{width:R.current.width,height:R.current.height});const _=$=>{var L,T;if(!R.current)return;const A=R.current,W=C.cameraRef.current,F=($.clientX-A.startX)/W.zoom,m=($.clientY-A.startY)/W.zoom;let f=A.width,M=A.height;A.direction.includes("e")&&(f=Math.min(n,Math.max(e,A.width+F))),A.direction.includes("w")&&(f=Math.min(n,Math.max(e,A.width-F))),A.direction.includes("s")&&(M=Math.min(r,Math.max(t,A.height+m))),A.direction.includes("n")&&(M=Math.min(r,Math.max(t,A.height-m))),(T=(L=C.onNodesChangeRef).current)==null||T.call(L,[{id:w,type:"dimensions",dimensions:{width:f,height:M},setAttributes:!0}]),d==null||d($,{width:f,height:M})},j=$=>{R.current=null,y==null||y($,{}),window.removeEventListener("pointermove",_),window.removeEventListener("pointerup",j)};window.addEventListener("pointermove",_),window.addEventListener("pointerup",j)},[w,C,e,t,n,r,g,d,y]);if(!a)return null;const B=8,S={position:"absolute",width:B,height:B,background:h,border:"1px solid #fff",borderRadius:2,zIndex:20,...o};return E.jsxs(E.Fragment,{children:[E.jsx("div",{style:{...S,bottom:-B/2,right:-B/2,cursor:"nwse-resize"},onPointerDown:N=>b(N,"se")}),E.jsx("div",{style:{...S,bottom:-B/2,left:-B/2,cursor:"nesw-resize"},onPointerDown:N=>b(N,"sw")}),E.jsx("div",{style:{...S,top:-B/2,right:-B/2,cursor:"nesw-resize"},onPointerDown:N=>b(N,"ne")}),E.jsx("div",{style:{...S,top:-B/2,left:-B/2,cursor:"nwse-resize"},onPointerDown:N=>b(N,"nw")}),E.jsx("div",{style:{...S,top:"50%",right:-B/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:N=>b(N,"e")}),E.jsx("div",{style:{...S,top:"50%",left:-B/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:N=>b(N,"w")}),E.jsx("div",{style:{...S,left:"50%",top:-B/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:N=>b(N,"n")}),E.jsx("div",{style:{...S,left:"50%",bottom:-B/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:N=>b(N,"s")})]})}function fs({isVisible:e,position:t="top",offset:n=10,align:r="center",children:a,style:o={},className:i=""}){const h=u.useContext(Kt),d=Me().nodes.find(C=>C.id===h);if(!(e!==void 0?e:d==null?void 0:d.selected))return null;const w={top:{bottom:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginBottom:n},bottom:{top:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginTop:n},left:{right:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginRight:n},right:{left:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginLeft:n}}[t]||{};return E.jsx("div",{className:`ric-node-toolbar ${i}`,style:{position:"absolute",zIndex:1e3,pointerEvents:"all",...w,...o},onPointerDown:C=>C.stopPropagation(),children:a})}function hs({isVisible:e=!1,x:t=0,y:n=0,alignX:r="center",alignY:a="center",children:o,style:i={},className:h=""}){if(!e)return null;const g=r==="center"?"-50%":r==="right"?"-100%":"0",d=a==="center"?"-50%":a==="bottom"?"-100%":"0";return E.jsx("div",{className:`ric-edge-toolbar ${h}`,style:{position:"absolute",left:t,top:n,transform:`translate(${g}, ${d})`,zIndex:1e3,pointerEvents:"all",...i},children:o})}function ys({children:e}){var r;const n=(r=Me().edgeLabelContainerRef)==null?void 0:r.current;return n?dr.createPortal(e,n):null}function gs({children:e}){var r;const n=(r=Me().viewportPortalRef)==null?void 0:r.current;return n?dr.createPortal(e,n):null}function $r({fromX:e,fromY:t,toX:n,toY:r,fromPosition:a="right",toPosition:o="left",connectionLineType:i="default",connectionLineStyle:h,connectionLineComponent:g}){if(g)return E.jsx(g,{fromX:e,fromY:t,toX:n,toY:r,fromPosition:a,toPosition:o});let d;switch(i){case"straight":[d]=On({sourceX:e,sourceY:t,targetX:n,targetY:r});break;case"step":[d]=gn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o,borderRadius:0});break;case"smoothstep":[d]=gn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o});break;case"simplebezier":[d]=Gn({sourceX:e,sourceY:t,targetX:n,targetY:r});break;default:[d]=Zn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o});break}return E.jsx("path",{d,fill:"none",className:"ric-connection-line",stroke:"#b1b1b7",strokeWidth:1.5,style:h})}$r.displayName="ConnectionLine";const xs=u.memo($r),ps=Object.freeze({Top:"top",Bottom:"bottom",Left:"left",Right:"right"}),ms=Object.freeze({Arrow:"arrow",ArrowClosed:"arrowclosed"});function vs(e){const t=e.width||e.measured&&e.measured.width||0,n=e.height||e.measured&&e.measured.height||0,r=e._absolutePosition||e.position||{x:0,y:0};return{x:r.x,y:r.y,x2:r.x+t,y2:r.y+n}}exports.Background=us;exports.BaseEdge=en;exports.BezierEdge=qn;exports.ConnectionLine=xs;exports.ControlButton=Qt;exports.Controls=cs;exports.DefaultNode=fo;exports.EdgeLabelRenderer=ys;exports.EdgeText=zr;exports.EdgeToolbar=hs;exports.GroupNode=Cr;exports.Handle=Jt;exports.InfiniteCanvas=No;exports.InfiniteCanvasProvider=Po;exports.InputNode=Rr;exports.MarkerType=ms;exports.MiniMap=es;exports.NodeResizer=ds;exports.NodeToolbar=fs;exports.OutputNode=kr;exports.Panel=ls;exports.Position=ps;exports.SelectionBox=wr;exports.SimpleBezierEdge=Kn;exports.SmoothStepEdge=Jn;exports.StepEdge=Nr;exports.StraightEdge=Vn;exports.ViewportPortal=gs;exports.addEdge=Lo;exports.applyEdgeChanges=Lr;exports.applyNodeChanges=Ir;exports.boxToRect=Ur;exports.buildObstacles=Qn;exports.clampPosition=Xn;exports.computeRoutedEdges=Mo;exports.getBezierEdgeCenter=ho;exports.getBezierPath=Zn;exports.getBoundsOfBoxes=qr;exports.getConnectedEdges=yr;exports.getEdgeCenter=yo;exports.getIncomers=Wr;exports.getNodeDimensions=Un;exports.getNodesBounds=yn;exports.getNodesInside=Xr;exports.getOutgoers=Fr;exports.getOverlappingArea=Or;exports.getRoutedLabelPosition=wn;exports.getSimpleBezierPath=Gn;exports.getSmoothStepPath=gn;exports.getStraightPath=On;exports.getViewportForBounds=Lt;exports.isEdge=_r;exports.isNode=Hr;exports.nodeToBox=vs;exports.nodeToRect=Zr;exports.reconnectEdge=go;exports.rectToBox=Yr;exports.routeSinglePath=Ro;exports.routedPointsToPath=bn;exports.snapPosition=Fn;exports.useConnection=Do;exports.useEdges=jo;exports.useEdgesState=$o;exports.useHandleConnections=Wo;exports.useInfiniteCanvas=xr;exports.useInternalNode=Zo;exports.useKeyPress=Yo;exports.useNodeConnections=_o;exports.useNodeId=ro;exports.useNodes=Bo;exports.useNodesData=Ho;exports.useNodesInitialized=Oo;exports.useNodesState=To;exports.useOnEdgesChangeMiddleware=Ko;exports.useOnNodesChangeMiddleware=Jo;exports.useOnSelectionChange=Xo;exports.useOnViewportChange=Fo;exports.useReactFlow=Tr;exports.useStore=Go;exports.useStoreApi=Qo;exports.useUndoRedo=Vo;exports.useUpdateNodeInternals=Uo;exports.useViewport=Ao;
867
+ `,ir=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",vr],{type:"text/javascript;charset=utf-8"});function eo(e){let t;try{if(t=ir&&(self.URL||self.webkitURL).createObjectURL(ir),!t)throw"";const n=new Worker(t,{type:"module",name:e==null?void 0:e.name});return n.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),n}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(vr),{type:"module",name:e==null?void 0:e.name})}}const Wn=new WeakMap;function to(e,t){if(Wn.has(e))return Wn.get(e);const n=e.transferControlToOffscreen(),r=new eo;r.onerror=o=>console.error("[infinite-canvas] worker error:",o.message,o),r.postMessage({type:"init",data:{...t,canvas:n}},[n]);const a={worker:r};return Wn.set(e,a),a}const it=160,rt=60,no=10;function br({cards:e=[],nodes:t=[],edges:n=[],onHudUpdate:r,onNodesProcessed:a,onNodesChange:o,onEdgesChange:i,onConnect:f,onNodeClick:p,onNodeDragStart:d,onNodeDrag:h,onNodeDragStop:v,onEdgeClick:E,onEdgeDoubleClick:M,onEdgeMouseEnter:z,onEdgeMouseMove:I,onEdgeMouseLeave:k,onEdgeContextMenu:j,onNodeDoubleClick:X,onNodeMouseEnter:D,onNodeMouseMove:_,onNodeMouseLeave:A,onNodeContextMenu:L,onPaneClick:Y,onPaneContextMenu:F,onPaneMouseEnter:B,onPaneMouseMove:b,onPaneMouseLeave:g,onSelectionChange:x,onConnectStart:N,onConnectEnd:$,onInit:W,onMoveStart:V,onMove:re,onMoveEnd:ee,onDelete:oe,onBeforeDelete:ge,onError:ye,isValidConnection:J,dark:fe,gridSize:me=40,zoomMin:ae=.1,zoomMax:ue=4,initialCamera:Ne={x:0,y:0,zoom:1},fitView:Je=!1,fitViewOptions:le,nodesDraggable:Be=!0,nodesConnectable:je=!0,elementsSelectable:_e=!0,multiSelectionKeyCode:he="Shift",selectionOnDrag:Me=!1,selectionMode:Oe="partial",connectionMode:Ae="loose",connectionRadius:ct=20,connectOnClick:zt=!1,snapToGrid:De=!1,snapGrid:Xe=[15,15],deleteKeyCode:Ze=["Delete","Backspace"],panActivationKeyCode:St=" ",panOnScroll:an=!1,panOnScrollMode:At="free",panOnScrollSpeed:cn=.5,zoomOnScroll:un=!0,zoomOnDoubleClick:ln=!0,zoomOnPinch:dn=!0,preventScrolling:Dt=!0,translateExtent:dt,nodeExtent:ft,defaultEdgeOptions:Nt={},autoPanOnNodeDrag:En=!0,autoPanOnConnect:zn=!0,autoPanSpeed:ot=5,edgesReconnectable:sr=!1,elevateNodesOnSelect:Sn=!1,elevateEdgesOnSelect:Nn=!1,noDragClassName:Pt="nodrag",noPanClassName:It="nopan",onSelectionDragStart:Pn,onSelectionDrag:In,onSelectionDragStop:Ln,edgeRouting:ht=!0}={}){const pe=c.useRef(null),Ht=c.useRef(null),Ee=c.useRef(null),ie=c.useRef({...Ne}),gt=c.useRef([...e]),K=c.useRef([...t]),Re=c.useRef([...n]),fn=c.useRef(new Map),ut=c.useRef(!1),Lt=c.useRef(null),[Tn,$n]=c.useState(!1),We=c.useRef(null),Ye=c.useRef(null),_t=c.useRef(null),He=c.useRef(null),Wt=c.useRef(!1),Mt=c.useRef(null),[Ft,Bn]=c.useState({x:Ne.x,y:Ne.y,zoom:Ne.zoom}),[yt,xt]=c.useState(null),tt=c.useMemo(()=>new Set,[]),Ke=c.useMemo(()=>new Set,[]),Tt=c.useRef(!1),O=c.useRef({});O.current={onHudUpdate:r,onNodesProcessed:a,onNodesChange:o,onEdgesChange:i,onConnect:f,onNodeClick:p,onNodeDragStart:d,onNodeDrag:h,onNodeDragStop:v,onEdgeClick:E,onEdgeDoubleClick:M,onEdgeMouseEnter:z,onEdgeMouseMove:I,onEdgeMouseLeave:k,onEdgeContextMenu:j,onNodeDoubleClick:X,onNodeMouseEnter:D,onNodeMouseMove:_,onNodeMouseLeave:A,onNodeContextMenu:L,onPaneClick:Y,onPaneContextMenu:F,onPaneMouseEnter:B,onPaneMouseMove:b,onPaneMouseLeave:g,onSelectionChange:x,onConnectStart:N,onConnectEnd:$,onInit:W,onMoveStart:V,onMove:re,onMoveEnd:ee,onDelete:oe,onBeforeDelete:ge,onError:ye,onSelectionDragStart:Pn,onSelectionDrag:In,onSelectionDragStop:Ln,isValidConnection:J};const pt={get current(){return O.current.onConnect}},$t={get current(){return O.current.onNodeClick}},Xt={get current(){return O.current.onNodeDragStart}},Yt={get current(){return O.current.onNodeDrag}},qt={get current(){return O.current.onNodeDragStop}},Ut={get current(){return O.current.onEdgeClick}},Ot={get current(){return O.current.onPaneClick}},we={get current(){return O.current.onSelectionChange}},mt={get current(){return O.current.onHudUpdate}},Bt={get current(){return O.current.onNodesProcessed}};c.useEffect(()=>{const l=u=>{u.key===he&&(Wt.current=!0),u.key===St&&(Tt.current=!0)},w=u=>{u.key===he&&(Wt.current=!1),u.key===St&&(Tt.current=!1)};return window.addEventListener("keydown",l),window.addEventListener("keyup",w),()=>{window.removeEventListener("keydown",l),window.removeEventListener("keyup",w)}},[he,St]);const ze={get current(){return O.current.onNodesChange?Zt:null}},Zt=l=>{var u,y,R;(y=(u=O.current).onNodesChange)==null||y.call(u,l);const w=[];for(let S=0;S<l.length;S++)l[S].type==="select"&&w.push({id:l[S].id,selected:l[S].selected});w.length>0&&((R=Ee.current)==null||R.postMessage({type:"nodeSelections",data:{selections:w}}))},Pe={get current(){return O.current.onEdgesChange?Gt:null}},Gt=l=>{var u,y,R;(y=(u=O.current).onEdgesChange)==null||y.call(u,l);const w=[];for(let S=0;S<l.length;S++)l[S].type==="select"&&w.push({id:l[S].id,selected:l[S].selected});w.length>0&&((R=Ee.current)==null||R.postMessage({type:"edgeSelections",data:{selections:w}}))},st=c.useCallback(()=>{var y;const l=K.current.filter(R=>R.selected),w=Re.current.filter(R=>R.selected),u={nodes:l,edges:w};(y=we.current)==null||y.call(we,u);for(const R of Ke)R(u)},[Ke]);c.useEffect(()=>{var l;gt.current=[...e],(l=Ee.current)==null||l.postMessage({type:"cards",data:{cards:[...e]}})},[e]);const Rt=c.useCallback(l=>{const w={};for(const u of l)w[u.id]=u;return l.map(u=>{if(!u.parentId)return u;const y=w[u.parentId];if(!y)return u;let R=u.position.x,S=u.position.y,m=y;for(;m;)R+=m.position.x,S+=m.position.y,m=m.parentId?w[m.parentId]:null;return{...u,_absolutePosition:{x:R,y:S}}})},[]),et=c.useRef([]),vt=c.useCallback(l=>{const w=fn.current;if(!w||w.size===0)return l;const u={};for(const[,y]of w)u[y.nodeId]||(u[y.nodeId]=[]),u[y.nodeId].push({id:y.id,type:y.type,position:y.position,x:y.x,y:y.y});return l.map(y=>{const R=u[y.id];return R&&R.length>0?{...y,handles:R}:y})},[]),hn=c.useCallback(()=>{var w;if(We.current)return;const l=vt(et.current);(w=Ee.current)==null||w.postMessage({type:"nodes",data:{nodes:l}})},[vt]);c.useEffect(()=>{var u,y;if(We.current){const R=We.current.id,S=new Set([R,...We.current.selectedStarts.map(C=>C.id)]),m={};for(const C of K.current)S.has(C.id)&&(m[C.id]={...C.position});K.current=[...t];for(const C of K.current)m[C.id]&&(C.position=m[C.id]);et.current=Rt(K.current);const T=vt(et.current);(u=Ee.current)==null||u.postMessage({type:"nodes",data:{nodes:T}});return}K.current=[...t];const l=Rt(t);et.current=l;const w=vt(l);(y=Ee.current)==null||y.postMessage({type:"nodes",data:{nodes:w}})},[t,Rt,vt]),c.useEffect(()=>{var l;Re.current=[...n],(l=Ee.current)==null||l.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const Se=c.useCallback((l,w)=>{const u=pe.current;if(!u)return{x:0,y:0};const y=u.getBoundingClientRect(),R=ie.current;return{x:(l-y.left-R.x)/R.zoom,y:(w-y.top-R.y)/R.zoom}},[]),nt=c.useCallback((l,w)=>{const u=et.current.length>0?et.current:K.current;let y=null;for(let R=u.length-1;R>=0;R--){const S=u[R];if(S.hidden)continue;const m=S._absolutePosition||S.position,T=S.width||it,C=S.height||rt;if(l>=m.x&&l<=m.x+T&&w>=m.y&&w<=m.y+C){if(S.type==="group"){y||(y=S);continue}return S}}return y},[]),G=c.useCallback((l,w)=>{const u=w.width||it,y=w.height||rt;if(l.x!==void 0&&l.y!==void 0)return{x:w.position.x+l.x,y:w.position.y+l.y};switch(l.position||(l.type==="source"?"right":"left")){case"top":return{x:w.position.x+u/2,y:w.position.y};case"bottom":return{x:w.position.x+u/2,y:w.position.y+y};case"left":return{x:w.position.x,y:w.position.y+y/2};case"right":return{x:w.position.x+u,y:w.position.y+y/2};default:return{x:w.position.x+u,y:w.position.y+y/2}}},[]),Ie=c.useCallback(l=>{const w=l.width||it,u=l.height||rt;if(l.handles&&l.handles.length>0)return l.handles.map(C=>{const U=G(C,l);return{id:C.id||null,type:C.type,x:U.x,y:U.y}});const y=l.targetPosition||"left",R=l.sourcePosition||"right",S=C=>{switch(C){case"top":return{x:l.position.x+w/2,y:l.position.y};case"bottom":return{x:l.position.x+w/2,y:l.position.y+u};case"left":return{x:l.position.x,y:l.position.y+u/2};case"right":return{x:l.position.x+w,y:l.position.y+u/2};default:return{x:l.position.x+w,y:l.position.y+u/2}}},m=S(y),T=S(R);return[{id:null,type:"target",x:m.x,y:m.y},{id:null,type:"source",x:T.x,y:T.y}]},[G]),ve=c.useCallback((l,w)=>{const u=K.current,y=ie.current,R=Math.max(no,ct)/y.zoom;for(let S=u.length-1;S>=0;S--){const m=u[S];if(m.hidden)continue;const T=Ie(m);for(const C of T)if(Math.abs(l-C.x)<R&&Math.abs(w-C.y)<R)return{nodeId:m.id,handleId:C.id,type:C.type,x:C.x,y:C.y}}return null},[Ie]),Le=c.useCallback((l,w)=>{const y=8/ie.current.zoom;for(let R=Re.current.length-1;R>=0;R--){const S=Re.current[R],m=K.current.find(se=>se.id===S.source),T=K.current.find(se=>se.id===S.target);if(!m||!T)continue;const C=m.width||it,U=m.height||rt,H=T.height||rt,Z=m.position.x+C,Q=m.position.y+U/2,be=T.position.x,Te=T.position.y+H/2;if(ro(l,w,Z,Q,be,Te)<y)return S}return null},[]);c.useEffect(()=>{const l=Ht.current,w=pe.current;if(!l||!w)return;const u=w.getBoundingClientRect(),y=fe!==void 0?fe:matchMedia("(prefers-color-scheme: dark)").matches,R=Rt(K.current);et.current=R;const S=vt(R),{worker:m}=to(l,{width:u.width,height:u.height,camera:ie.current,cards:gt.current,nodes:S,edges:Re.current,dark:y,gridSize:me,edgeRouting:ht});m.onmessage=H=>{var Z,Q,be,Te;H.data.type==="hud"&&((Z=mt.current)==null||Z.call(mt,H.data.data)),H.data.type==="ready"&&$n(!0),H.data.type==="nodesProcessed"&&((Q=Bt.current)==null||Q.call(Bt,H.data.data)),H.data.type==="error"&&((Te=(be=O.current).onError)==null||Te.call(be,"worker-error",H.data.message||"Canvas worker error"))},m.onerror=H=>{var Z,Q;(Q=(Z=O.current).onError)==null||Q.call(Z,"worker-error",H.message||"Canvas worker crashed")},Ee.current=m;const T=new ResizeObserver(H=>{const{width:Z,height:Q}=H[0].contentRect;m.postMessage({type:"resize",data:{width:Z,height:Q}})});T.observe(w);let C,U;return fe===void 0&&(C=matchMedia("(prefers-color-scheme: dark)"),U=H=>m.postMessage({type:"theme",data:{dark:H.matches}}),C.addEventListener("change",U)),()=>{T.disconnect(),C&&U&&C.removeEventListener("change",U),Ee.current=null}},[]),c.useEffect(()=>{var l;fe!==void 0&&((l=Ee.current)==null||l.postMessage({type:"theme",data:{dark:fe}}))},[fe]),c.useEffect(()=>{var l;(l=Ee.current)==null||l.postMessage({type:"edgeRouting",data:{enabled:ht}})},[ht]);const at=c.useRef(0),ce=c.useCallback((l=null)=>{var y,R,S;const w=ie.current;if(dt){const m=pe.current;if(m){const T=m.getBoundingClientRect(),C=-dt[1][0]*w.zoom+T.width,U=-dt[1][1]*w.zoom+T.height,H=-dt[0][0]*w.zoom,Z=-dt[0][1]*w.zoom;w.x=Math.min(H,Math.max(C,w.x)),w.y=Math.min(Z,Math.max(U,w.y))}}(y=Ee.current)==null||y.postMessage({type:"camera",data:{camera:{...w}}});const u={x:w.x,y:w.y,zoom:w.zoom};(S=(R=O.current).onMove)==null||S.call(R,l,u);for(const m of tt)m(u);cancelAnimationFrame(at.current),at.current=requestAnimationFrame(()=>{Bn({x:w.x,y:w.y,zoom:w.zoom})})},[tt,dt]),Ge=c.useCallback(()=>{var u,y;const l=Ye.current,w=_t.current;l&&w?((u=Ee.current)==null||u.postMessage({type:"connecting",data:{from:l.startPos,to:w,_routedPoints:null}}),xt({source:l.sourceId,sourceHandle:l.sourceHandle,target:null,targetHandle:null})):((y=Ee.current)==null||y.postMessage({type:"connecting",data:null}),xt(null))},[]),bt=c.useCallback(()=>{var w,u;const l=He.current;l?(w=Ee.current)==null||w.postMessage({type:"selectionBox",data:l}):(u=Ee.current)==null||u.postMessage({type:"selectionBox",data:null})},[]),jn=c.useCallback(l=>{var m,T,C,U,H,Z,Q,be,Te,te,se,ke,$e,Fe,Qe,Ue,Vt,lt;const w=K.current.length>0,u=Se(l.clientX,l.clientY),y=Wt.current;if(w&&je&&!y){const q=ve(u.x,u.y);if(zt&&Mt.current&&q){const ne=Mt.current;if(q.nodeId!==ne.nodeId){const Ve=ne.handleType==="target"?{source:q.nodeId,target:ne.nodeId,sourceHandle:q.handleId||null,targetHandle:ne.handleId}:{source:ne.nodeId,target:q.nodeId,sourceHandle:ne.handleId,targetHandle:q.handleId||null};(O.current.isValidConnection?O.current.isValidConnection(Ve):!0)&&((m=pt.current)==null||m.call(pt,{...Ve,...Nt}))}Mt.current=null;return}if(Ae==="strict"?q&&q.type==="source":q!=null){if(zt){Mt.current={nodeId:q.nodeId,handleId:q.handleId||null,handleType:q.type},(C=(T=O.current).onConnectStart)==null||C.call(T,l,{nodeId:q.nodeId,handleId:q.handleId,handleType:q.type});return}Ye.current={sourceId:q.nodeId,sourceHandle:q.handleId||null,sourceType:q.type,startPos:{x:q.x,y:q.y}},_t.current={x:u.x,y:u.y},(U=pe.current)==null||U.setPointerCapture(l.pointerId),(Z=(H=O.current).onConnectStart)==null||Z.call(H,l,{nodeId:q.nodeId,handleId:q.handleId,handleType:q.type}),Ge();return}}const R=q=>{var ne;let xe=q;for(;xe&&xe!==pe.current;){if((ne=xe.classList)!=null&&ne.contains(Pt))return!0;xe=xe.parentElement}return!1},S=q=>{var ne;let xe=q;for(;xe&&xe!==pe.current;){if((ne=xe.classList)!=null&&ne.contains(It))return!0;xe=xe.parentElement}return!1};if(w){const q=nt(u.x,u.y);if(q){if(ze.current&&_e){const xe=[];if(y)xe.push({id:q.id,type:"select",selected:!q.selected});else if(!q.selected){for(const ne of K.current)ne.id===q.id?xe.push({id:ne.id,type:"select",selected:!0}):ne.selected&&xe.push({id:ne.id,type:"select",selected:!1});if(Pe.current){const ne=Re.current.filter(de=>de.selected).map(de=>({id:de.id,type:"select",selected:!1}));ne.length&&Pe.current(ne)}}if(xe.length){if(ze.current(xe),Sn&&!y){const ne=K.current.findIndex(de=>de.id===q.id);ne>=0&&ne<K.current.length-1&&ze.current([{id:q.id,type:"remove"},{type:"add",item:{...K.current[ne],selected:!0}}])}st()}}if((Q=$t.current)==null||Q.call($t,l,q),Be&&!R(l.target)){const xe=q.selected;let ne=null;if(q.parentId&&q.extent==="parent"){const de=K.current.find(Ve=>Ve.id===q.parentId);if(de){const Ve=de.width||it,Jt=de.height||rt,yn=q.width||((be=q.measured)==null?void 0:be.width)||it,Kt=q.height||((Te=q.measured)==null?void 0:Te.height)||rt;ne={minX:0,minY:0,maxX:Ve-yn,maxY:Jt-Kt}}}if(We.current={id:q.id,startPos:{...q.position},startMouse:{x:u.x,y:u.y},parentClamp:ne,parentId:q.parentId||null,selectedStarts:xe?K.current.filter(de=>de.selected&&de.id!==q.id).map(de=>{var Jt,yn;let Ve=null;if(de.parentId&&de.extent==="parent"){const Kt=K.current.find(_n=>_n.id===de.parentId);if(Kt){const _n=Kt.width||it,Wr=Kt.height||rt,Fr=de.width||((Jt=de.measured)==null?void 0:Jt.width)||it,Xr=de.height||((yn=de.measured)==null?void 0:yn.height)||rt;Ve={minX:0,minY:0,maxX:_n-Fr,maxY:Wr-Xr}}}return{id:de.id,startPos:{...de.position},parentClamp:Ve,parentId:de.parentId||null}}):[]},(te=pe.current)==null||te.setPointerCapture(l.pointerId),(se=Xt.current)==null||se.call(Xt,l,q),We.current.selectedStarts.length>0){const de=K.current.filter(Ve=>Ve.selected);($e=(ke=O.current).onSelectionDragStart)==null||$e.call(ke,l,de)}if(ze.current){const de=[{id:q.id,type:"position",dragging:!0}];for(const Ve of We.current.selectedStarts)de.push({id:Ve.id,type:"position",dragging:!0});ze.current(de)}}return}}if(Re.current.length>0&&_e){const q=Le(u.x,u.y);if(q){if(Pe.current){const xe=[];if(y)xe.push({id:q.id,type:"select",selected:!q.selected});else{for(const ne of Re.current)ne.id===q.id?xe.push({id:ne.id,type:"select",selected:!0}):ne.selected&&xe.push({id:ne.id,type:"select",selected:!1});if(ze.current){const ne=K.current.filter(de=>de.selected).map(de=>({id:de.id,type:"select",selected:!1}));ne.length&&ze.current(ne)}}if(xe.length){if(Pe.current(xe),Nn&&!y){const ne=Re.current.findIndex(de=>de.id===q.id);ne>=0&&ne<Re.current.length-1&&Pe.current([{id:q.id,type:"remove"},{type:"add",item:{...Re.current[ne],selected:!0}}])}st()}}(Fe=Ut.current)==null||Fe.call(Ut,l,q);return}}if(!y){const q=K.current.filter(ne=>ne.selected).map(ne=>({id:ne.id,type:"select",selected:!1})),xe=Re.current.filter(ne=>ne.selected).map(ne=>({id:ne.id,type:"select",selected:!1}));q.length&&ze.current&&ze.current(q),xe.length&&Pe.current&&Pe.current(xe),(q.length||xe.length)&&st()}if((Qe=Ot.current)==null||Qe.call(Ot,l),Me||y){He.current={startWorld:{...u},endWorld:{...u}},(Ue=pe.current)==null||Ue.setPointerCapture(l.pointerId),bt();return}S(l.target)||(ut.current=!0,Lt.current={x:l.clientX,y:l.clientY},(Vt=pe.current)==null||Vt.classList.add("dragging"),(lt=pe.current)==null||lt.setPointerCapture(l.pointerId))},[Se,nt,ve,Le,Be,je,_e,Me,Ge,bt,st,Pt,It]),An=c.useCallback(l=>{var u,y,R,S;if(Ye.current){if(_t.current=Se(l.clientX,l.clientY),Ge(),zn){const m=pe.current;if(m){const T=m.getBoundingClientRect(),C=40,U=l.clientX-T.left,H=l.clientY-T.top;let Z=0,Q=0;U<C?Z=ot:U>T.width-C&&(Z=-ot),H<C?Q=ot:H>T.height-C&&(Q=-ot),(Z||Q)&&(ie.current.x+=Z,ie.current.y+=Q,ce(l))}}return}if(He.current){He.current.endWorld=Se(l.clientX,l.clientY),bt();const m=He.current,T=Math.min(m.startWorld.x,m.endWorld.x),C=Math.min(m.startWorld.y,m.endWorld.y),U=Math.max(m.startWorld.x,m.endWorld.x),H=Math.max(m.startWorld.y,m.endWorld.y);if(ze.current){const Z=[];for(const Q of K.current){if(Q.hidden)continue;const be=Q.width||it,Te=Q.height||rt,te=Oe==="full"?Q.position.x>=T&&Q.position.x+be<=U&&Q.position.y>=C&&Q.position.y+Te<=H:Q.position.x+be>T&&Q.position.x<U&&Q.position.y+Te>C&&Q.position.y<H;te!==!!Q.selected&&Z.push({id:Q.id,type:"select",selected:te})}Z.length&&ze.current(Z)}return}if(We.current){const m=Se(l.clientX,l.clientY),T=We.current,C=m.x-T.startMouse.x,U=m.y-T.startMouse.y;let H={x:T.startPos.x+C,y:T.startPos.y+U};if(De&&(H=qn(H,Xe)),ft&&(H=Un(H,ft)),T.parentClamp){const te=T.parentClamp;H={x:Math.max(te.minX,Math.min(H.x,te.maxX)),y:Math.max(te.minY,Math.min(H.y,te.maxY))}}const Z=[{id:T.id,position:H}];for(const te of T.selectedStarts){let se={x:te.startPos.x+C,y:te.startPos.y+U};if(De&&(se=qn(se,Xe)),ft&&(se=Un(se,ft)),te.parentClamp){const ke=te.parentClamp;se={x:Math.max(ke.minX,Math.min(se.x,ke.maxX)),y:Math.max(ke.minY,Math.min(se.y,ke.maxY))}}Z.push({id:te.id,position:se})}const Q=[];for(const te of Z){const se=K.current.find(ke=>ke.id===te.id);if(se){se.position=te.position,se.dragging=!0;let ke=te.position;if(se.parentId){let $e=K.current.find(Ue=>Ue.id===se.parentId),Fe=te.position.x,Qe=te.position.y;for(;$e;)Fe+=$e.position.x,Qe+=$e.position.y,$e=$e.parentId?K.current.find(Ue=>Ue.id===$e.parentId):null;ke={x:Fe,y:Qe}}Q.push({id:te.id,position:te.position,_absolutePosition:ke,width:se.width,height:se.height,dragging:!0,selected:se.selected})}}const be=new Set(Z.map(te=>te.id));for(const te of K.current)if(te.parentId&&be.has(te.parentId)&&!be.has(te.id)){let se=K.current.find(Fe=>Fe.id===te.parentId),ke=te.position.x,$e=te.position.y;for(;se;)ke+=se.position.x,$e+=se.position.y,se=se.parentId?K.current.find(Fe=>Fe.id===se.parentId):null;Q.push({id:te.id,position:te.position,_absolutePosition:{x:ke,y:$e},width:te.width,height:te.height,dragging:!1,selected:te.selected})}if((u=Ee.current)==null||u.postMessage({type:"nodePositions",data:{updates:Q}}),En){const te=pe.current;if(te){const se=te.getBoundingClientRect(),ke=40,$e=l.clientX-se.left,Fe=l.clientY-se.top;let Qe=0,Ue=0;$e<ke?Qe=ot:$e>se.width-ke&&(Qe=-ot),Fe<ke?Ue=ot:Fe>se.height-ke&&(Ue=-ot),(Qe||Ue)&&(ie.current.x+=Qe,ie.current.y+=Ue,ce(l))}}const Te=K.current.find(te=>te.id===T.id);if(Te&&((y=Yt.current)==null||y.call(Yt,l,Te)),T.selectedStarts.length>0){const te=K.current.filter(se=>se.selected);(S=(R=O.current).onSelectionDrag)==null||S.call(R,l,te)}return}if(!ut.current)return;const w=ie.current;w.x+=l.clientX-Lt.current.x,w.y+=l.clientY-Lt.current.y,Lt.current={x:l.clientX,y:l.clientY},ce()},[ce,Se,Ge,bt]),kt=c.useCallback(l=>{var w,u,y,R,S,m,T;if(Ye.current){const C=Se(l.clientX,l.clientY),U=ve(C.x,C.y);if(U&&U.nodeId!==Ye.current.sourceId&&(Ae==="loose"||U.type==="target")){const Q=Ye.current.sourceType==="target"?{source:U.nodeId,target:Ye.current.sourceId,sourceHandle:U.handleId||null,targetHandle:Ye.current.sourceHandle}:{source:Ye.current.sourceId,target:U.nodeId,sourceHandle:Ye.current.sourceHandle,targetHandle:U.handleId||null};(O.current.isValidConnection?O.current.isValidConnection(Q):!0)&&((w=pt.current)==null||w.call(pt,{...Q,...Nt}))}(y=(u=O.current).onConnectEnd)==null||y.call(u,l.nativeEvent||l),Ye.current=null,_t.current=null,Ge();return}if(He.current){He.current=null,bt(),st();return}if(We.current){const C=We.current;if(ze.current){const H=K.current.find(Q=>Q.id===C.id),Z=[{id:C.id,type:"position",position:H?{...H.position}:void 0,dragging:!1}];for(const Q of C.selectedStarts){const be=K.current.find(Te=>Te.id===Q.id);Z.push({id:Q.id,type:"position",position:be?{...be.position}:void 0,dragging:!1})}ze.current(Z)}if(C.selectedStarts.length>0){const H=K.current.filter(Z=>Z.selected);(S=(R=O.current).onSelectionDragStop)==null||S.call(R,l,H)}requestAnimationFrame(()=>{We.current=null});const U=K.current.find(H=>H.id===C.id);U&&((m=qt.current)==null||m.call(qt,l,U));return}ut.current=!1,(T=pe.current)==null||T.classList.remove("dragging")},[Se,ve,Ge,bt,st]);c.useEffect(()=>{const l=pe.current;if(!l)return;const w=u=>{Dt&&u.preventDefault();const y=ie.current;if(an||Tt.current){const C=cn;At==="horizontal"?y.x-=u.deltaY*C:(At==="vertical"||(y.x-=u.deltaX*C),y.y-=u.deltaY*C),ce(u);return}if(!un)return;const R=u.deltaY>0?.92:1.08,S=l.getBoundingClientRect(),m=u.clientX-S.left,T=u.clientY-S.top;y.x=m-(m-y.x)*R,y.y=T-(T-y.y)*R,y.zoom=Math.min(ue,Math.max(ae,y.zoom*R)),ce(u)};return l.addEventListener("wheel",w,{passive:!Dt}),()=>l.removeEventListener("wheel",w)},[ce,ae,ue,an,At,cn,un,Dt]),c.useEffect(()=>{if(!dn)return;const l=pe.current;if(!l)return;let w=0,u=null;const y=m=>{if(m.touches.length===2){const T=m.touches[0].clientX-m.touches[1].clientX,C=m.touches[0].clientY-m.touches[1].clientY;w=Math.hypot(T,C);const U=l.getBoundingClientRect();u={x:(m.touches[0].clientX+m.touches[1].clientX)/2-U.left,y:(m.touches[0].clientY+m.touches[1].clientY)/2-U.top},m.preventDefault()}},R=m=>{if(m.touches.length===2&&w>0){m.preventDefault();const T=m.touches[0].clientX-m.touches[1].clientX,C=m.touches[0].clientY-m.touches[1].clientY,U=Math.hypot(T,C),H=U/w;w=U;const Z=ie.current,Q=u.x,be=u.y;Z.x=Q-(Q-Z.x)*H,Z.y=be-(be-Z.y)*H,Z.zoom=Math.min(ue,Math.max(ae,Z.zoom*H)),ce(m)}},S=()=>{w=0,u=null};return l.addEventListener("touchstart",y,{passive:!1}),l.addEventListener("touchmove",R,{passive:!1}),l.addEventListener("touchend",S),()=>{l.removeEventListener("touchstart",y),l.removeEventListener("touchmove",R),l.removeEventListener("touchend",S)}},[dn,ce,ae,ue]),c.useEffect(()=>{if(!ln)return;const l=pe.current;if(!l)return;const w=u=>{var H,Z,Q,be;const y=Se(u.clientX,u.clientY);if(nt(y.x,y.y)){(Z=(H=O.current).onNodeDoubleClick)==null||Z.call(H,u,nt(y.x,y.y));return}const R=Le(y.x,y.y);if(R){(be=(Q=O.current).onEdgeDoubleClick)==null||be.call(Q,u,R);return}const S=1.5,m=l.getBoundingClientRect(),T=u.clientX-m.left,C=u.clientY-m.top,U=ie.current;U.x=T-(T-U.x)*S,U.y=C-(C-U.y)*S,U.zoom=Math.min(ue,Math.max(ae,U.zoom*S)),ce(u)};return l.addEventListener("dblclick",w),()=>l.removeEventListener("dblclick",w)},[ln,ce,ae,ue,Se,nt,Le]),c.useEffect(()=>{const l=pe.current;if(!l)return;const w=u=>{var m,T,C,U,H,Z;const y=Se(u.clientX,u.clientY),R=nt(y.x,y.y);if(R){(T=(m=O.current).onNodeContextMenu)==null||T.call(m,u,R);return}const S=Le(y.x,y.y);if(S){(U=(C=O.current).onEdgeContextMenu)==null||U.call(C,u,S);return}(Z=(H=O.current).onPaneContextMenu)==null||Z.call(H,u)};return l.addEventListener("contextmenu",w),()=>l.removeEventListener("contextmenu",w)},[Se,nt,Le]),c.useEffect(()=>{const l=pe.current;if(!l)return;let w=null,u=null;const y=m=>{var U,H,Z,Q,be,Te,te,se,ke,$e,Fe,Qe,Ue,Vt;if((H=(U=O.current).onPaneMouseMove)==null||H.call(U,m),ut.current||We.current||Ye.current||He.current)return;const T=Se(m.clientX,m.clientY),C=nt(T.x,T.y);if(C!==w&&(w&&((Q=(Z=O.current).onNodeMouseLeave)==null||Q.call(Z,m,w)),C&&((Te=(be=O.current).onNodeMouseEnter)==null||Te.call(be,m,C)),w=C),C&&((se=(te=O.current).onNodeMouseMove)==null||se.call(te,m,C)),!C){const lt=Le(T.x,T.y);lt!==u&&(u&&(($e=(ke=O.current).onEdgeMouseLeave)==null||$e.call(ke,m,u)),lt&&((Qe=(Fe=O.current).onEdgeMouseEnter)==null||Qe.call(Fe,m,lt)),u=lt),lt&&((Vt=(Ue=O.current).onEdgeMouseMove)==null||Vt.call(Ue,m,lt))}},R=m=>{var T,C;return(C=(T=O.current).onPaneMouseEnter)==null?void 0:C.call(T,m)},S=m=>{var T,C,U,H,Z,Q;(C=(T=O.current).onPaneMouseLeave)==null||C.call(T,m),w&&((H=(U=O.current).onNodeMouseLeave)==null||H.call(U,m,w),w=null),u&&((Q=(Z=O.current).onEdgeMouseLeave)==null||Q.call(Z,m,u),u=null)};return l.addEventListener("mousemove",y),l.addEventListener("mouseenter",R),l.addEventListener("mouseleave",S),()=>{l.removeEventListener("mousemove",y),l.removeEventListener("mouseenter",R),l.removeEventListener("mouseleave",S)}},[Se,nt,Le]),c.useEffect(()=>{const l=Array.isArray(Ze)?Ze:[Ze],w=async u=>{var y,R,S,m;if(l.includes(u.key)){if(u.target.tagName==="INPUT"||u.target.tagName==="TEXTAREA"||u.target.isContentEditable)return;const T=K.current.filter(H=>H.selected),C=Re.current.filter(H=>H.selected);if(!T.length&&!C.length)return;if(O.current.onBeforeDelete)try{if(!await O.current.onBeforeDelete({nodes:T,edges:C}))return}catch(H){(R=(y=O.current).onError)==null||R.call(y,"before-delete-error",H.message||"onBeforeDelete threw an error");return}const U=new Set(T.map(H=>H.id));if(T.length&&ze.current&&(ze.current(T.map(H=>({id:H.id,type:"remove"}))),Pe.current)){const H=Re.current.filter(Z=>U.has(Z.source)||U.has(Z.target));H.length&&Pe.current(H.map(Z=>({id:Z.id,type:"remove"})))}C.length&&Pe.current&&Pe.current(C.map(H=>({id:H.id,type:"remove"}))),(m=(S=O.current).onDelete)==null||m.call(S,{nodes:T,edges:C})}if((u.ctrlKey||u.metaKey)&&u.key==="a"){if(u.target.tagName==="INPUT"||u.target.tagName==="TEXTAREA")return;if(u.preventDefault(),ze.current){const T=K.current.filter(C=>!C.selected).map(C=>({id:C.id,type:"select",selected:!0}));T.length&&ze.current(T)}if(Pe.current){const T=Re.current.filter(C=>!C.selected).map(C=>({id:C.id,type:"select",selected:!0}));T.length&&Pe.current(T)}}};return window.addEventListener("keydown",w),()=>window.removeEventListener("keydown",w)},[Ze]);const Qt=c.useRef(!1);c.useEffect(()=>{var l,w;if(!Qt.current&&Ee.current){if(Qt.current=!0,Je&&K.current.length>0){const u=pe.current;if(u){const y=u.getBoundingClientRect(),R=(le==null?void 0:le.padding)??.1,S=mn(K.current),m=jt(S,y.width,y.height,R);le!=null&&le.maxZoom&&(m.zoom=Math.min(m.zoom,le.maxZoom)),le!=null&&le.minZoom&&(m.zoom=Math.max(m.zoom,le.minZoom)),ie.current=m,ce()}}(w=(l=O.current).onInit)==null||w.call(l,{getNodes:()=>[...K.current],getEdges:()=>[...Re.current],getNode:u=>K.current.find(y=>y.id===u),getEdge:u=>Re.current.find(y=>y.id===u),getViewport:()=>({...ie.current}),getZoom:()=>ie.current.zoom,setViewport:u=>{ie.current={x:u.x??ie.current.x,y:u.y??ie.current.y,zoom:u.zoom??ie.current.zoom},ce()},fitView:(u={})=>{const y=pe.current;if(!y||!K.current.length)return;const R=y.getBoundingClientRect(),S=u.nodes?K.current.filter(C=>u.nodes.some(U=>U.id===C.id)):K.current;if(!S.length)return;const m=mn(S),T=jt(m,R.width,R.height,u.padding??.1);u.maxZoom&&(T.zoom=Math.min(T.zoom,u.maxZoom)),u.minZoom&&(T.zoom=Math.max(T.zoom,u.minZoom)),ie.current=T,ce()},screenToFlowPosition:u=>Se(u.x,u.y),flowToScreenPosition:u=>{const y=ie.current,R=pe.current;if(!R)return{x:0,y:0};const S=R.getBoundingClientRect();return{x:u.x*y.zoom+y.x+S.left,y:u.y*y.zoom+y.y+S.top}},zoomIn:()=>{const u=ie.current;u.zoom=Math.min(ue,u.zoom*1.2),ce()},zoomOut:()=>{const u=ie.current;u.zoom=Math.max(ae,u.zoom/1.2),ce()},zoomTo:u=>{ie.current.zoom=Math.min(ue,Math.max(ae,u)),ce()},setNodes:u=>{var y,R;(R=(y=O.current).onNodesChange)==null||R.call(y,[...K.current.map(S=>({id:S.id,type:"remove"})),...(typeof u=="function"?u(K.current):u).map(S=>({type:"add",item:S}))])},setEdges:u=>{var y,R;(R=(y=O.current).onEdgesChange)==null||R.call(y,[...Re.current.map(S=>({id:S.id,type:"remove"})),...(typeof u=="function"?u(Re.current):u).map(S=>({type:"add",item:S}))])},addNodes:u=>{var R,S;const y=Array.isArray(u)?u:[u];(S=(R=O.current).onNodesChange)==null||S.call(R,y.map(m=>({type:"add",item:m})))},addEdges:u=>{var R,S;const y=Array.isArray(u)?u:[u];(S=(R=O.current).onEdgesChange)==null||S.call(R,y.map(m=>({type:"add",item:m})))},deleteElements:({nodes:u=[],edges:y=[]})=>{var R,S,m,T;u.length&&((S=(R=O.current).onNodesChange)==null||S.call(R,u.map(C=>({id:C.id,type:"remove"})))),y.length&&((T=(m=O.current).onEdgesChange)==null||T.call(m,y.map(C=>({id:C.id,type:"remove"}))))},updateNodeData:(u,y)=>{var m,T;const R=K.current.find(C=>C.id===u);if(!R)return;const S=typeof y=="function"?y(R.data):{...R.data,...y};(T=(m=O.current).onNodesChange)==null||T.call(m,[{id:u,type:"replace",item:{...R,data:S}}])},toObject:()=>({nodes:[...K.current],edges:[...Re.current],viewport:{...ie.current}}),setCenter:(u,y,R={})=>{const S=pe.current;if(!S)return;const m=S.getBoundingClientRect(),T=R.zoom??ie.current.zoom;ie.current={x:m.width/2-u*T,y:m.height/2-y*T,zoom:T},ce()},fitBounds:(u,y={})=>{const R=pe.current;if(!R)return;const S=R.getBoundingClientRect(),m=jt(u,S.width,S.height,y.padding??.1);ie.current=m,ce()}})}});const gn=c.useCallback(()=>{ie.current={...Ne},ce()},[ce,Ne]),qe=c.useCallback(l=>{var w;if(l)gt.current.push(l);else{const u=ie.current,y=pe.current;if(!y)return;const R=y.getBoundingClientRect(),S=Math.round(-u.x/u.zoom+R.width/2/u.zoom),m=Math.round(-u.y/u.zoom+R.height/2/u.zoom);gt.current.push({x:S-80,y:m-45,w:160,h:90,title:"Note "+(gt.current.length+1),body:"Added at viewport center"})}(w=Ee.current)==null||w.postMessage({type:"cards",data:{cards:[...gt.current]}})},[]),wt=c.useCallback(l=>{if(l.id||(l.id="node-"+Date.now()),!l.position){const w=ie.current,u=pe.current;if(!u)return;const y=u.getBoundingClientRect();l.position={x:Math.round(-w.x/w.zoom+y.width/2/w.zoom)-it/2,y:Math.round(-w.y/w.zoom+y.height/2/w.zoom)-rt/2}}l.data||(l.data={label:l.id}),ze.current&&ze.current([{type:"add",item:l}])},[]),Dn=c.useCallback(()=>({...ie.current}),[]),Hn=c.useCallback(l=>{ie.current={...ie.current,...l},ce()},[ce]),Hr=c.useCallback(l=>Se(l.x,l.y),[Se]),ar=n,_r=c.useMemo(()=>({wrapRef:pe,canvasRef:Ht,workerRef:Ee,cameraRef:ie,nodesRef:K,edgesRef:Re,handleRegistryRef:fn,syncNodesToWorker:hn,onNodesChangeRef:ze,onEdgesChangeRef:Pe,sendCamera:ce,screenToWorld:Se,viewportListeners:tt,selectionListeners:Ke,zoomMin:ae,zoomMax:ue,snapToGrid:De,snapGrid:Xe,nodeExtent:ft,defaultEdgeOptions:Nt,edgeRouting:ht,resolvedNodesRef:et,noDragClassName:Pt,noPanClassName:It,get nodes(){return t},get edges(){return n},get routedEdges(){return ar},get viewport(){return Ft},get connection(){return yt}}),[t,n,ar,Ft,yt,ce,Se,hn,tt,Ke,ae,ue,De,Xe,ft,Nt,ht,Pt,It]);return{wrapRef:pe,canvasRef:Ht,canvasReady:Tn,onPointerDown:jn,onPointerMove:An,onPointerUp:kt,resetView:gn,addCard:qe,addNode:wt,getCamera:Dn,setCamera:Hn,screenToFlowPosition:Hr,store:_r}}function ro(e,t,n,r,a,o){const i=a-n,f=o-r,p=i*i+f*f;if(p===0)return Math.hypot(e-n,t-r);let d=((e-n)*i+(t-r)*f)/p;return d=Math.max(0,Math.min(1,d)),Math.hypot(e-(n+d*i),t-(r+d*f))}const cr=e=>{let t;const n=new Set,r=(d,h)=>{const v=typeof d=="function"?d(t):d;if(!Object.is(v,t)){const E=t;t=h??(typeof v!="object"||v===null)?v:Object.assign({},t,v),n.forEach(M=>M(t,E))}},a=()=>t,f={setState:r,getState:a,getInitialState:()=>p,subscribe:d=>(n.add(d),()=>n.delete(d))},p=t=e(r,a,f);return f},oo=(e=>e?cr(e):cr),so=e=>e;function ao(e,t=so){const n=c.useSyncExternalStore(e.subscribe,c.useCallback(()=>t(e.getState()),[e,t]),c.useCallback(()=>t(e.getInitialState()),[e,t]));return c.useDebugValue(n),n}const Et=c.createContext(null);function io(e={}){return oo((t,n)=>({nodes:[],edges:[],viewport:{x:0,y:0,zoom:1},connection:null,minZoom:.1,maxZoom:5,width:0,height:0,domNode:null,nodesRef:{current:[]},edgesRef:{current:[]},cameraRef:{current:{x:0,y:0,zoom:1}},wrapRef:{current:null},workerRef:{current:null},onNodesChangeRef:{current:null},onEdgesChangeRef:{current:null},viewportListeners:new Set,selectionListeners:new Set,edgeLabelContainerRef:{current:null},viewportPortalRef:{current:null},screenToWorld:(r,a)=>{const o=n().cameraRef.current;return{x:(r-o.x)/o.zoom,y:(a-o.y)/o.zoom}},sendCamera:()=>{var a;const r=n();(a=r.workerRef.current)==null||a.postMessage({type:"camera",data:{camera:{...r.cameraRef.current}}})},...e}))}function Ce(e,t){const n=c.useContext(Et);if(!n)throw new Error("useCanvasStore must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");const r=typeof n.getState=="function"&&typeof n.subscribe=="function",a=c.useRef(e),o=c.useRef(t),i=c.useRef(void 0);a.current=e,o.current=t;const f=c.useCallback(p=>{const d=a.current;if(!d)return p;const h=d(p),v=o.current||Object.is;return i.current!==void 0&&v(i.current,h)?i.current:(i.current=h,h)},[]);return r?ao(n,e?f:void 0):e?f(n):n}function wr(){const e=c.useContext(Et);if(!e)throw new Error("useCanvasStoreApi must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");return typeof e.getState=="function"?e:{getState:()=>e,setState:()=>{},subscribe:()=>()=>{}}}const on=c.createContext(null);function co(){return c.useContext(on)}function uo({node:e,nodeType:t}){var E,M,z;const n=Ce(),r=c.useRef(n);r.current=n;const a=c.useRef(null),o=e._absolutePosition||e.position,i=c.useRef(null);c.useEffect(()=>{const I=a.current;if(!I)return;const k=new ResizeObserver(j=>{var _,A,L,Y;const{width:X,height:D}=j[0].contentRect;if(X>0&&D>0){const F=r.current,B=F.nodesRef.current.find(x=>x.id===e.id),b=(B==null?void 0:B.width)||((_=B==null?void 0:B.measured)==null?void 0:_.width),g=(B==null?void 0:B.height)||((A=B==null?void 0:B.measured)==null?void 0:A.height);(Math.abs((b||0)-X)>1||Math.abs((g||0)-D)>1)&&((Y=(L=F.onNodesChangeRef).current)==null||Y.call(L,[{id:e.id,type:"dimensions",dimensions:{width:X,height:D},setAttributes:!0}]))}});return k.observe(I),()=>k.disconnect()},[e.id]);const f=c.useCallback(I=>{var ee,oe,ge,ye;I.stopPropagation();const k=I.target.tagName;if(k==="INPUT"||k==="TEXTAREA"||k==="SELECT"||k==="BUTTON"||k==="A"||k==="LABEL"||I.target.isContentEditable)return;const j=r.current.noDragClassName||"nodrag",X=r.current.noPanClassName||"nopan";let D=I.target;for(;D&&D!==a.current;){if((ee=D.classList)!=null&&ee.contains(j)||(oe=D.classList)!=null&&oe.contains(X))return;D=D.parentElement}if(r.current.onNodesChangeRef.current){const J=[];if(I.shiftKey)J.push({id:e.id,type:"select",selected:!e.selected});else for(const me of r.current.nodesRef.current)me.id===e.id&&!me.selected?J.push({id:me.id,type:"select",selected:!0}):me.id!==e.id&&me.selected&&J.push({id:me.id,type:"select",selected:!1});J.length&&r.current.onNodesChangeRef.current(J)}const _=r.current.cameraRef.current,A=r.current.wrapRef.current;if(!A)return;const L=A.getBoundingClientRect(),Y=(I.clientX-L.left-_.x)/_.zoom,F=(I.clientY-L.top-_.y)/_.zoom,b=e.selected?r.current.nodesRef.current.filter(J=>J.selected&&J.id!==e.id).map(J=>({id:J.id,startPos:{...J.position}})):[];i.current={startPos:{...e.position},startMouse:{x:Y,y:F},selectedStarts:b};const g=[{id:e.id,type:"position",dragging:!0}];for(const J of b)g.push({id:J.id,type:"position",dragging:!0});(ye=(ge=r.current.onNodesChangeRef).current)==null||ye.call(ge,g);const x=a.current;x&&x.setPointerCapture(I.pointerId);let N=null,$=null;const W=()=>{var J,fe;$&&((fe=(J=r.current.onNodesChangeRef).current)==null||fe.call(J,$),$=null),N=null},V=J=>{var je,_e;if(!i.current)return;const fe=r.current.cameraRef.current,me=A.getBoundingClientRect(),ae=(J.clientX-me.left-fe.x)/fe.zoom,ue=(J.clientY-me.top-fe.y)/fe.zoom,Ne=ae-i.current.startMouse.x,Je=ue-i.current.startMouse.y;let le={x:i.current.startPos.x+Ne,y:i.current.startPos.y+Je};if(r.current.snapToGrid&&r.current.snapGrid&&(le={x:r.current.snapGrid[0]*Math.round(le.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(le.y/r.current.snapGrid[1])}),e.parentId&&e.extent==="parent"){const he=r.current.nodesRef.current.find(Me=>Me.id===e.parentId);if(he){const Me=he.width||160,Oe=he.height||60,Ae=e.width||((je=e.measured)==null?void 0:je.width)||160,ct=e.height||((_e=e.measured)==null?void 0:_e.height)||60;le={x:Math.max(0,Math.min(le.x,Me-Ae)),y:Math.max(0,Math.min(le.y,Oe-ct))}}}x&&(x.style.left=le.x+"px",x.style.top=le.y+"px");for(const he of i.current.selectedStarts){let Me={x:he.startPos.x+Ne,y:he.startPos.y+Je};r.current.snapToGrid&&r.current.snapGrid&&(Me={x:r.current.snapGrid[0]*Math.round(Me.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Me.y/r.current.snapGrid[1])});const Oe=A.querySelector(`[data-nodeid="${he.id}"]`);Oe&&(Oe.style.left=Me.x+"px",Oe.style.top=Me.y+"px")}const Be=[{id:e.id,type:"position",position:le,dragging:!0}];for(const he of i.current.selectedStarts){let Me={x:he.startPos.x+Ne,y:he.startPos.y+Je};r.current.snapToGrid&&r.current.snapGrid&&(Me={x:r.current.snapGrid[0]*Math.round(Me.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Me.y/r.current.snapGrid[1])}),Be.push({id:he.id,type:"position",position:Me,dragging:!0})}$=Be,N||(N=requestAnimationFrame(W))},re=J=>{var me,ae;if(!i.current)return;N&&(cancelAnimationFrame(N),W());const fe=[{id:e.id,type:"position",dragging:!1}];for(const ue of i.current.selectedStarts)fe.push({id:ue.id,type:"position",dragging:!1});(ae=(me=r.current.onNodesChangeRef).current)==null||ae.call(me,fe),i.current=null,x&&x.releasePointerCapture(J.pointerId),x==null||x.removeEventListener("pointermove",V),x==null||x.removeEventListener("pointerup",re)};x==null||x.addEventListener("pointermove",V),x==null||x.addEventListener("pointerup",re)},[e]),p=c.useCallback(I=>{var A,L,Y,F,B,b;if(!e.selected)return;const k=I.shiftKey?10:1;let j=0,X=0;switch(I.key){case"ArrowUp":X=-k;break;case"ArrowDown":X=k;break;case"ArrowLeft":j=-k;break;case"ArrowRight":j=k;break;case"Escape":(L=(A=r.current.onNodesChangeRef).current)==null||L.call(A,[{id:e.id,type:"select",selected:!1}]);return;case"Delete":case"Backspace":e.deletable!==!1&&((F=(Y=r.current.onNodesChangeRef).current)==null||F.call(Y,[{id:e.id,type:"remove"}]));return;default:return}I.preventDefault();const D={x:e.position.x+j,y:e.position.y+X},_=[{id:e.id,type:"position",position:D}];for(const g of r.current.nodesRef.current)g.selected&&g.id!==e.id&&_.push({id:g.id,type:"position",position:{x:g.position.x+j,y:g.position.y+X}});(b=(B=r.current.onNodesChangeRef).current)==null||b.call(B,_)},[e]),d=e.width||((E=e.measured)==null?void 0:E.width),h=e.height||((M=e.measured)==null?void 0:M.height),v=!!(d&&h);return P.jsx(on.Provider,{value:e.id,children:P.jsx("div",{ref:a,className:`ric-node-wrapper ${e.selected?"selected":""} ${e.dragging?"dragging":""}`,style:{position:"absolute",left:o.x,top:o.y,zIndex:e.type==="group"?0:e.zIndex||1,pointerEvents:e.type==="group"?"none":"all",visibility:v?"visible":"hidden",outline:"none"},"data-nodeid":e.id,tabIndex:e.selectable!==!1?0:void 0,role:"button","aria-label":`Node ${((z=e.data)==null?void 0:z.label)||e.id}`,"aria-selected":!!e.selected,onPointerDown:f,onKeyDown:p,children:P.jsx(t,{id:e.id,data:e.data,type:e.type,selected:!!e.selected,dragging:!!e.dragging,draggable:e.draggable!==!1,selectable:e.selectable!==!1,deletable:e.deletable!==!1,isConnectable:e.connectable!==!1,zIndex:e.zIndex||0,positionAbsoluteX:o.x,positionAbsoluteY:o.y,width:d,height:h,sourcePosition:e.sourcePosition,targetPosition:e.targetPosition,parentId:e.parentId,dragHandle:e.dragHandle})})})}const lo=c.memo(uo),Mr=160,Rr=60;function ur(e,t,n,r){var f,p;const a=e.width||((f=e.measured)==null?void 0:f.width)||Mr,o=e.height||((p=e.measured)==null?void 0:p.height)||Rr,i=e._absolutePosition||e.position;if(e.handleBounds){const d=e.handleBounds[t]||[],h=n?d.find(v=>v.id===n):d[0];if(h&&h.x!==void 0&&h.y!==void 0){const v=h.position||(t==="source"?"right":"left");return{x:i.x+h.x,y:i.y+h.y,position:v}}}if(r){const d=`${e.id}__${n||t}`,h=r.get(d);if(h&&h.x!==void 0&&h.y!==void 0)return{x:i.x+h.x,y:i.y+h.y,position:h.position||(t==="source"?"right":"left")}}if(e.handles&&e.handles.length){for(const d of e.handles)if(d.type===t&&(!n||d.id===n)){if(d.x!==void 0&&d.y!==void 0)return{x:i.x+d.x,y:i.y+d.y,position:d.position||(t==="source"?"right":"left")};const h=d.position||(t==="source"?"right":"left");switch(h){case"top":return{x:i.x+a/2,y:i.y,position:h};case"bottom":return{x:i.x+a/2,y:i.y+o,position:h};case"left":return{x:i.x,y:i.y+o/2,position:h};default:return{x:i.x+a,y:i.y+o/2,position:h}}}}return t==="source"?{x:i.x+a,y:i.y+o/2,position:"right"}:{x:i.x,y:i.y+o/2,position:"left"}}function fo(e,t,n){return n==="left"?e-t:n==="right"?e+t:e}function ho(e,t,n){return n==="top"?e-t:n==="bottom"?e+t:e}function lr({x:e,y:t,position:n,type:r,onPointerDown:a}){return P.jsx("circle",{className:`ric-edge-anchor ric-edge-anchor-${r}`,cx:fo(e,10,n),cy:ho(t,10,n),r:10,stroke:"transparent",fill:"transparent",style:{cursor:"move",pointerEvents:"stroke"},onPointerDown:a})}function go({edge:e,edgeType:t,nodes:n,reconnectable:r}){var L,Y,F;const a=c.useContext(Et),o=c.useRef(typeof a.getState=="function"?a.getState():a);o.current=typeof a.getState=="function"?a.getState():a;const[i,f]=c.useState(null),p=c.useCallback((B,b,g,x)=>{var ge;b.stopPropagation(),b.preventDefault();const N=o.current,$=N.wrapRef.current;if(!$)return;const W=B==="source"?x:g,V=B==="source"?e.target:e.source;(ge=N.workerRef.current)==null||ge.postMessage({type:"connecting",data:{from:{x:W.x,y:W.y},to:{x:W.x,y:W.y}}});const re=$.getBoundingClientRect(),ee=ye=>{var ae;const J=N.cameraRef.current,fe=(ye.clientX-re.left-J.x)/J.zoom,me=(ye.clientY-re.top-J.y)/J.zoom;(ae=N.workerRef.current)==null||ae.postMessage({type:"connecting",data:{from:{x:W.x,y:W.y},to:{x:fe,y:me}}})},oe=ye=>{var le,Be,je,_e;const J=N.cameraRef.current,fe=(ye.clientX-re.left-J.x)/J.zoom,me=(ye.clientY-re.top-J.y)/J.zoom,ae=20/J.zoom;let ue=null,Ne=null;const Je=(le=N.handleRegistryRef)==null?void 0:le.current;for(const he of N.nodesRef.current){if(he.hidden)continue;const Me=he.width||Mr,Oe=he.height||Rr,Ae=he._absolutePosition||he.position,ct=[];if(Je)for(const[,De]of Je)De.nodeId===he.id&&ct.push(De);const zt=ct.length>0?ct:he.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const De of zt){let Xe,Ze;if(De.x!==void 0&&De.y!==void 0)Xe=Ae.x+De.x,Ze=Ae.y+De.y;else switch(De.position||(De.type==="source"?"right":"left")){case"top":Xe=Ae.x+Me/2,Ze=Ae.y;break;case"bottom":Xe=Ae.x+Me/2,Ze=Ae.y+Oe;break;case"left":Xe=Ae.x,Ze=Ae.y+Oe/2;break;default:Xe=Ae.x+Me,Ze=Ae.y+Oe/2;break}if(Math.abs(fe-Xe)<ae&&Math.abs(me-Ze)<ae){ue=he,Ne=De.id||null;break}}if(ue)break}if(ue){const he=B==="source"?{source:ue.id,target:V,sourceHandle:Ne,targetHandle:e.targetHandle}:{source:V,target:ue.id,sourceHandle:e.sourceHandle,targetHandle:Ne};(je=(Be=N.onEdgesChangeRef).current)==null||je.call(Be,[{id:e.id,type:"remove"},{type:"add",item:{id:e.id,...he}}])}(_e=N.workerRef.current)==null||_e.postMessage({type:"connecting",data:null}),$.removeEventListener("pointermove",ee),$.removeEventListener("pointerup",oe)};$.addEventListener("pointermove",ee),$.addEventListener("pointerup",oe)},[e]),d=n.find(B=>B.id===e.source),h=n.find(B=>B.id===e.target),v=d&&!!(d.width||(L=d.measured)!=null&&L.width),E=h&&!!(h.width||(Y=h.measured)!=null&&Y.width),M=o.current,z=(F=M.handleRegistryRef)==null?void 0:F.current,I=v?ur(d,"source",e.sourceHandle,z):null,k=E?ur(h,"target",e.targetHandle,z):null,j=e.type==="bezier"||e.type==="simplebezier"||e.type==="default",X=M.routedEdges||M.edges,D=X==null?void 0:X.find(B=>B.id===e.id),_=j?null:(D==null?void 0:D._routedPoints)||e._routedPoints||null,A=r!==!1&&e.reconnectable!==!1;return!I||!k?null:P.jsxs("g",{className:`ric-edge-wrapper ${e.selected?"selected":""}`,"data-edgeid":e.id,onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),children:[P.jsx(t,{id:e.id,source:e.source,target:e.target,sourceX:I.x,sourceY:I.y,targetX:k.x,targetY:k.y,sourcePosition:I.position,targetPosition:k.position,sourceHandleId:e.sourceHandle,targetHandleId:e.targetHandle,data:e.data,type:e.type,selected:!!e.selected,animated:!!e.animated,label:e.label,style:e.style,selectable:e.selectable!==!1,deletable:e.deletable!==!1,routedPoints:_}),A&&(i||e.selected)&&P.jsxs(P.Fragment,{children:[P.jsx(lr,{x:I.x,y:I.y,position:I.position,type:"source",onPointerDown:B=>p("source",B,I,k)}),P.jsx(lr,{x:k.x,y:k.y,position:k.position,type:"target",onPointerDown:B=>p("target",B,I,k)})]})]})}const yo=c.memo(go);function kr({selectionKeyCode:e="Shift",selectionMode:t="partial"}){var I;const n=Ce(),[r,a]=c.useState(null),o=c.useRef(null);if(c.useEffect(()=>{const k=n.wrapRef.current;if(!k)return;let j=!1,X=null,D=!1;const _=B=>{B.key===e&&(D=!0)},A=B=>{B.key===e&&(D=!1)},L=B=>{if(!D)return;const b=B.target;if(b.closest(".ric-node-wrapper")||b.closest(".ric-handle"))return;j=!0;const g=n.cameraRef.current,x=k.getBoundingClientRect(),N=(B.clientX-x.left-g.x)/g.zoom,$=(B.clientY-x.top-g.y)/g.zoom;X={x:N,y:$},a({startX:N,startY:$,endX:N,endY:$}),B.stopPropagation()},Y=B=>{if(!j||!X)return;const b=n.cameraRef.current,g=k.getBoundingClientRect(),x=(B.clientX-g.left-b.x)/b.zoom,N=(B.clientY-g.top-b.y)/b.zoom;a({startX:X.x,startY:X.y,endX:x,endY:N})},F=B=>{var V,re;if(!j||!X)return;j=!1;const b=n.cameraRef.current,g=k.getBoundingClientRect(),x=(B.clientX-g.left-b.x)/b.zoom,N=(B.clientY-g.top-b.y)/b.zoom,$={x:Math.min(X.x,x),y:Math.min(X.y,N),width:Math.abs(x-X.x),height:Math.abs(N-X.y)},W=[];for(const ee of n.nodesRef.current){const oe=ee._absolutePosition||ee.position,ge=ee.width||160,ye=ee.height||60;let J;t==="full"?J=oe.x>=$.x&&oe.y>=$.y&&oe.x+ge<=$.x+$.width&&oe.y+ye<=$.y+$.height:J=oe.x+ge>$.x&&oe.x<$.x+$.width&&oe.y+ye>$.y&&oe.y<$.y+$.height,W.push({id:ee.id,type:"select",selected:J})}W.length&&((re=(V=n.onNodesChangeRef).current)==null||re.call(V,W)),X=null,a(null)};return k.addEventListener("pointerdown",L,!0),k.addEventListener("pointermove",Y),k.addEventListener("pointerup",F),window.addEventListener("keydown",_),window.addEventListener("keyup",A),()=>{k.removeEventListener("pointerdown",L,!0),k.removeEventListener("pointermove",Y),k.removeEventListener("pointerup",F),window.removeEventListener("keydown",_),window.removeEventListener("keyup",A)}},[n,e,t]),!r)return null;const i=((I=n.cameraRef)==null?void 0:I.current)||{x:0,y:0,zoom:1},f=Math.min(r.startX,r.endX),p=Math.min(r.startY,r.endY),d=Math.abs(r.endX-r.startX),h=Math.abs(r.endY-r.startY),v=f*i.zoom+i.x,E=p*i.zoom+i.y,M=d*i.zoom,z=h*i.zoom;return P.jsx("div",{ref:o,className:"ric-selection-box",style:{position:"absolute",left:v,top:E,width:M,height:z,border:"1px dashed #3b82f6",background:"rgba(59, 130, 246, 0.08)",pointerEvents:"none",zIndex:100}})}kr.displayName="SelectionBox";const Cr=c.memo(kr);function On(e,t,n){switch(e){case"top":return{x:t/2,y:0};case"bottom":return{x:t/2,y:n};case"left":return{x:0,y:n/2};case"right":return{x:t,y:n/2};default:return{x:t,y:n/2}}}function xo(e,t){const n=e.closest(".ric-node-wrapper");if(!n)return null;const r=n.getBoundingClientRect(),a=e.getBoundingClientRect(),o=t||1;return{x:(a.left+a.width/2-r.left)/o,y:(a.top+a.height/2-r.top)/o}}let Fn=!1,Ct=null;function Er(e){Ct=e,!Fn&&(Fn=!0,requestAnimationFrame(()=>{var t;Fn=!1,(t=Ct==null?void 0:Ct.syncNodesToWorker)==null||t.call(Ct),Ct=null}))}const Zn=new WeakMap;let xn=null;function po(){return xn||(xn=new ResizeObserver(e=>{var t;for(const n of e){const r=Zn.get(n.target);if(!r)continue;const{width:a,height:o}=n.contentRect;if(!a||!o)continue;const i=r.getStore(),f=(t=i.handleRegistryRef)==null?void 0:t.current;if(f){for(const[p,d]of f)if(d.nodeId===r.nodeId){const h=On(d.position,a,o);d.x=h.x,d.y=h.y,f.set(p,d)}Er(i)}}}),xn)}function mo({type:e="source",position:t=e==="source"?"right":"left",id:n,isConnectable:r=!0,isConnectableStart:a=!0,isConnectableEnd:o=!0,children:i,className:f="",style:p={},onConnect:d,...h}){const v=c.useContext(on),E=c.useContext(Et),M=c.useRef(null),z=c.useCallback(()=>typeof E.getState=="function"?E.getState():E,[E]),I=c.useRef(z);I.current=z,c.useLayoutEffect(()=>{var b,g,x,N,$,W,V;if(!v)return;const D=I.current(),_=(b=D.handleRegistryRef)==null?void 0:b.current;if(!_)return;const A=`${v}__${n||e}`,L=(x=(g=D.nodesRef)==null?void 0:g.current)==null?void 0:x.find(re=>re.id===v),Y=(L==null?void 0:L.width)||((N=L==null?void 0:L.measured)==null?void 0:N.width),F=(L==null?void 0:L.height)||(($=L==null?void 0:L.measured)==null?void 0:$.height);let B;Y&&F?B=On(t,Y,F):M.current?B=xo(M.current,(V=(W=D.cameraRef)==null?void 0:W.current)==null?void 0:V.zoom):B=On(t,160,60),_.set(A,{nodeId:v,id:n||null,type:e,position:t,x:B.x,y:B.y})},[v,n,e,t]),c.useEffect(()=>{if(!v)return;const D=I.current();Er(D);const _=M.current,A=_==null?void 0:_.closest(".ric-node-wrapper");return A&&!Zn.has(A)&&(Zn.set(A,{nodeId:v,getStore:I.current}),po().observe(A)),()=>{var B;const Y=(B=I.current().handleRegistryRef)==null?void 0:B.current,F=`${v}__${n||e}`;Y==null||Y.delete(F)}},[v,n,e,t]);const k=c.useCallback(()=>{var g;const D=I.current(),_=D.nodesRef.current.find(x=>x.id===v);if(!_)return null;const A=_._absolutePosition||_.position,L=(g=D.handleRegistryRef)==null?void 0:g.current,Y=`${v}__${n||e}`,F=L==null?void 0:L.get(Y);if(F&&F.x!==void 0&&F.y!==void 0)return{x:A.x+F.x,y:A.y+F.y};const B=_.width||160,b=_.height||60;switch(t){case"top":return{x:A.x+B/2,y:A.y};case"bottom":return{x:A.x+B/2,y:A.y+b};case"left":return{x:A.x,y:A.y+b/2};default:return{x:A.x+B,y:A.y+b/2}}},[v,n,e,t]),j=c.useCallback(D=>{var N;if(!r||!a)return;D.stopPropagation(),D.preventDefault();const _=I.current(),A=_.cameraRef.current,L=_.wrapRef.current;if(!L)return;const Y=L.getBoundingClientRect(),F=k();if(!F)return;const B=F.x,b=F.y;(N=_.workerRef.current)==null||N.postMessage({type:"connecting",data:{from:{x:B,y:b},to:{x:B,y:b}}}),L.setPointerCapture(D.pointerId);const g=$=>{var re;const W=($.clientX-Y.left-A.x)/A.zoom,V=($.clientY-Y.top-A.y)/A.zoom;(re=_.workerRef.current)==null||re.postMessage({type:"connecting",data:{from:{x:B,y:b},to:{x:W,y:V}}})},x=$=>{var ye,J,fe,me;const W=($.clientX-Y.left-A.x)/A.zoom,V=($.clientY-Y.top-A.y)/A.zoom,re=20/A.zoom;let ee=null,oe=null;const ge=(ye=_.handleRegistryRef)==null?void 0:ye.current;for(const ae of _.nodesRef.current){if(ae.id===v||ae.hidden)continue;const ue=ae._absolutePosition||ae.position,Ne=[];if(ge)for(const[,le]of ge)le.nodeId===ae.id&&Ne.push(le);const Je=Ne.length>0?Ne:ae.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const le of Je){let Be,je;if(le.x!==void 0&&le.y!==void 0)Be=ue.x+le.x,je=ue.y+le.y;else{const _e=ae.width||160,he=ae.height||60;switch(le.position||(le.type==="source"?"right":"left")){case"top":Be=ue.x+_e/2,je=ue.y;break;case"bottom":Be=ue.x+_e/2,je=ue.y+he;break;case"left":Be=ue.x,je=ue.y+he/2;break;default:Be=ue.x+_e,je=ue.y+he/2;break}}if(Math.abs(W-Be)<re&&Math.abs(V-je)<re){ee=ae,oe=le.id||null;break}}if(ee)break}if(ee){const ae={source:e==="source"?v:ee.id,target:e==="source"?ee.id:v,sourceHandle:e==="source"?n||null:oe,targetHandle:e==="source"?oe:n||null};(fe=(J=_.onEdgesChangeRef)==null?void 0:J.current)==null||fe.call(J,[{type:"add",item:{id:`e-${ae.source}-${ae.target}`,...ae}}])}(me=_.workerRef.current)==null||me.postMessage({type:"connecting",data:null}),L.removeEventListener("pointermove",g),L.removeEventListener("pointerup",x)};L.addEventListener("pointermove",g),L.addEventListener("pointerup",x)},[v,n,e,t,r,a,k]),X={top:{top:0,left:"50%",transform:"translate(-50%, -50%)"},bottom:{bottom:0,left:"50%",transform:"translate(-50%, 50%)"},left:{top:"50%",left:0,transform:"translate(-50%, -50%)"},right:{top:"50%",right:0,transform:"translate(50%, -50%)"}}[t]||{};return P.jsx("div",{ref:M,className:`ric-handle ric-handle-${t} ric-handle-${e} ${f}`,"data-handleid":n||null,"data-nodeid":v,"data-handlepos":t,"data-handletype":e,onPointerDown:j,style:{position:"absolute",width:8,height:8,borderRadius:"50%",background:"#1a192b",border:"none",zIndex:10,cursor:r?"crosshair":"default",boxSizing:"border-box",...X,...p},...h,children:i})}const rn=c.memo(mo);function vo({data:e,isConnectable:t,selected:n,targetPosition:r="left",sourcePosition:a="right",hideSourceHandle:o=!1,hideTargetHandle:i=!1}){return P.jsxs("div",{className:`ric-default-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!i&&P.jsx(rn,{type:"target",position:r,isConnectable:t}),P.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!o&&P.jsx(rn,{type:"source",position:a,isConnectable:t})]})}function zr({data:e,isConnectable:t,selected:n,sourcePosition:r="right",hideSourceHandle:a=!1}){return P.jsxs("div",{className:`ric-input-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderBottom:"2px solid #0041d0",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[P.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!a&&P.jsx(rn,{type:"source",position:r,isConnectable:t})]})}function Sr({data:e,isConnectable:t,selected:n,targetPosition:r="left",hideTargetHandle:a=!1}){return P.jsxs("div",{className:`ric-output-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderTop:"2px solid #ff0072",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!a&&P.jsx(rn,{type:"target",position:r,isConnectable:t}),P.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label})]})}function Nr({data:e,selected:t,width:n,height:r}){return P.jsx("div",{className:`ric-group-node${t?" selected":""}`,style:{width:n||300,height:r||200,background:"rgba(240, 240, 240, 0.25)",border:t?"2px solid #3b82f6":"1px dashed #ccc",borderRadius:8,padding:8,boxSizing:"border-box"},children:(e==null?void 0:e.label)&&P.jsx("div",{style:{fontSize:11,fontWeight:600,color:"#888",userSelect:"none"},children:e.label})})}function Pr({x:e,y:t,label:n,labelStyle:r,labelShowBg:a=!0,labelBgStyle:o,labelBgPadding:i=[2,4],labelBgBorderRadius:f=2,children:p,className:d="",...h}){const[v,E]=c.useState({x:1,y:0,width:0,height:0}),M=c.useRef(null);return c.useEffect(()=>{if(M.current){const z=M.current.getBBox();E({x:z.x,y:z.y,width:z.width,height:z.height})}},[n]),n?P.jsxs("g",{transform:`translate(${e-v.width/2} ${t-v.height/2})`,className:`ric-edge-textwrapper ${d}`,visibility:v.width?"visible":"hidden",...h,children:[a&&P.jsx("rect",{width:v.width+2*i[0],x:-i[0],y:-i[1],height:v.height+2*i[1],className:"ric-edge-textbg",style:o,rx:f,ry:f}),P.jsx("text",{className:"ric-edge-text",y:v.height/2,dy:"0.3em",ref:M,style:r,children:n}),p]}):null}Pr.displayName="EdgeText";const Ir=c.memo(Pr);function dr(e){return e!=null&&e!==""&&!isNaN(Number(e))}function sn({id:e,path:t,labelX:n,labelY:r,label:a,labelStyle:o,labelShowBg:i,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:d,interactionWidth:h=20,style:v,markerEnd:E,markerStart:M,className:z="",...I}){return P.jsxs(P.Fragment,{children:[P.jsx("path",{id:e,d:t,fill:"none",stroke:"#b1b1b7",strokeWidth:1.5,className:`ric-edge-path ${z}`,style:v,markerEnd:E,markerStart:M,...I}),h?P.jsx("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:h,className:"ric-edge-interaction",style:{pointerEvents:"stroke"}}):null,a&&dr(n)&&dr(r)?P.jsx(Ir,{x:n,y:r,label:a,labelStyle:o,labelShowBg:i,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:d}):null]})}const en=20;function fr(e,t,n){switch(n){case"right":return{x:e+en,y:t};case"left":return{x:e-en,y:t};case"bottom":return{x:e,y:t+en};case"top":return{x:e,y:t-en};default:return{x:e+en,y:t}}}const Vn=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:i="bottom",targetPosition:f="top",label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,interactionWidth:j}){let X,D,_;const A=fr(n,r,i),L=fr(a,o,f),Y=Math.abs(L.x-A.x),F=Math.max(50,Y*.5);let B,b,g,x;switch(i){case"left":B=A.x-F,b=A.y;break;case"top":B=A.x,b=A.y-F;break;case"bottom":B=A.x,b=A.y+F;break;default:B=A.x+F,b=A.y;break}switch(f){case"right":g=L.x+F,x=L.y;break;case"top":g=L.x,x=L.y-F;break;case"bottom":g=L.x,x=L.y+F;break;default:g=L.x-F,x=L.y;break}X=`M ${n},${r} L ${A.x},${A.y} C ${B},${b} ${g},${x} ${L.x},${L.y} L ${a},${o}`;const N=.5,$=.5;return D=$*$*$*A.x+3*$*$*N*B+3*$*N*N*g+N*N*N*L.x,_=$*$*$*A.y+3*$*$*N*b+3*$*N*N*x+N*N*N*L.y,P.jsx(sn,{id:t,path:X,labelX:D,labelY:_,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,interactionWidth:j})});Vn.displayName="BezierEdge";function Jn({sourceX:e,sourceY:t,targetX:n,targetY:r}){const a=`M ${e},${t}L ${n},${r}`,o=(e+n)/2,i=(t+r)/2;return[a,o,i,0,0]}function Kn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a="right",targetPosition:o="left",curvature:i=.25}){const f=Math.abs(n-e),p=Math.abs(r-t),d=Math.sqrt(f*f+p*p),h=Math.max(d*i,50);let v,E,M,z;switch(a){case"top":v=e,E=t-h;break;case"bottom":v=e,E=t+h;break;case"left":v=e-h,E=t;break;default:v=e+h,E=t;break}switch(o){case"top":M=n,z=r-h;break;case"bottom":M=n,z=r+h;break;case"right":M=n+h,z=r;break;default:M=n-h,z=r;break}const I=`M ${e},${t} C ${v},${E} ${M},${z} ${n},${r}`,k=.5,j=1-k,X=j*j*j*e+3*j*j*k*v+3*j*k*k*M+k*k*k*n,D=j*j*j*t+3*j*j*k*E+3*j*k*k*z+k*k*k*r;return[I,X,D,0,0]}function er({sourceX:e,sourceY:t,targetX:n,targetY:r}){const a=Math.abs(n-e),o=Math.max(a*.5,50),i=e+o,f=n-o,p=`M ${e},${t} C ${i},${t} ${f},${r} ${n},${r}`,d=.5,h=.5,v=h*h*h*e+3*h*h*d*i+3*h*d*d*f+d*d*d*n,E=h*h*h*t+3*h*h*d*t+3*h*d*d*r+d*d*d*r;return[p,v,E,0,0]}function vn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a="right",targetPosition:o="left",borderRadius:i=5,offset:f=20}){const p=a==="left"||a==="right",d=Math.min(i,Math.abs(n-e)/2,Math.abs(r-t)/2);if(p){if(Math.abs(r-t)<1)return[`M ${e},${t} L ${n},${r}`,(e+n)/2,t,0,0];const M=(e+n)/2,z=r>t?1:-1;return[`M ${e},${t} L ${M-d},${t} Q ${M},${t} ${M},${t+z*d} L ${M},${r-z*d} Q ${M},${r} ${M+(n>M?d:-d)},${r} L ${n},${r}`,M,(t+r)/2,0,0]}const h=(t+r)/2,v=n>e?1:-1;return[`M ${e},${t} L ${e},${h-d} Q ${e},${h} ${e+v*d},${h} L ${n-v*d},${h} Q ${n},${h} ${n},${h+(r>h?d:-d)} L ${n},${r}`,(e+n)/2,h,0,0]}function bo({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[,a,o]=Kn({sourceX:e,sourceY:t,targetX:n,targetY:r});return[a,o,0,0]}function wo({sourceX:e,sourceY:t,targetX:n,targetY:r}){return[(e+n)/2,(t+r)/2,0,0]}function Mo(e,t,n){const r=n.filter(o=>o.id!==e.id),a={...e,id:e.id,source:t.source,target:t.target,sourceHandle:t.sourceHandle??e.sourceHandle,targetHandle:t.targetHandle??e.targetHandle};return r.push(a),r}const bn=160,wn=60,tn=20,pn=12,Mn=20;function hr(e,t,n){var i,f;const r=e.width||((i=e.measured)==null?void 0:i.width)||bn,a=e.height||((f=e.measured)==null?void 0:f.height)||wn,o=e._absolutePosition||e.position;if(e.handles&&e.handles.length>0){for(const p of e.handles)if(p.type===t&&(!n||p.id===n)){if(p.x!==void 0&&p.y!==void 0)return{x:o.x+p.x,y:o.y+p.y,dir:p.position||(t==="source"?"right":"left")};switch(p.position||(t==="source"?"right":"left")){case"top":return{x:o.x+r/2,y:o.y,dir:"top"};case"bottom":return{x:o.x+r/2,y:o.y+a,dir:"bottom"};case"left":return{x:o.x,y:o.y+a/2,dir:"left"};default:return{x:o.x+r,y:o.y+a/2,dir:"right"}}}}return t==="source"?{x:o.x+r,y:o.y+a/2,dir:"right"}:{x:o.x,y:o.y+a/2,dir:"left"}}function Rn(e,t){switch(e.dir){case"right":return{x:e.x+t,y:e.y,dir:e.dir};case"left":return{x:e.x-t,y:e.y,dir:e.dir};case"bottom":return{x:e.x,y:e.y+t,dir:e.dir};case"top":return{x:e.x,y:e.y-t,dir:e.dir};default:return{x:e.x+t,y:e.y,dir:e.dir}}}function Ro(e,t,n,r,a,o,i,f){const p=Math.min(e,n),d=Math.max(e,n),h=Math.min(t,r),v=Math.max(t,r);if(d<=a||p>=a+i||v<=o||h>=o+f)return!1;const E=.5;if(e>a+E&&e<a+i-E&&t>o+E&&t<o+f-E||n>a+E&&n<a+i-E&&r>o+E&&r<o+f-E)return!0;const M=(e+n)/2,z=(t+r)/2;if(M>a+E&&M<a+i-E&&z>o+E&&z<o+f-E)return!0;const I=[[a,o],[a+i,o],[a+i,o+f],[a,o+f]];for(let k=0;k<4;k++)if(ko(e,t,n,r,I[k][0],I[k][1],I[(k+1)%4][0],I[(k+1)%4][1]))return!0;return!1}function ko(e,t,n,r,a,o,i,f){const p=(i-a)*(t-o)-(f-o)*(e-a),d=(i-a)*(r-o)-(f-o)*(n-a),h=(n-e)*(o-t)-(r-t)*(a-e),v=(n-e)*(f-t)-(r-t)*(i-e);return(p>0&&d<0||p<0&&d>0)&&(h>0&&v<0||h<0&&v>0)}function Gn(e,t,n,r,a){for(let o=0;o<a.length;o++){const i=a[o];if(Ro(e,t,n,r,i.x,i.y,i.w,i.h))return!1}return!0}function Co(e,t,n){for(let r=0;r<n.length;r++){const a=n[r];if(e>a.x&&e<a.x+a.w&&t>a.y&&t<a.y+a.h)return!0}return!1}function tr(e,t){var r,a;const n=[];for(let o=0;o<e.length;o++){const i=e[o];if(i.hidden||t&&t.has(i.id)||i.type==="group")continue;const f=i._absolutePosition||i.position,p=i.width||((r=i.measured)==null?void 0:r.width)||bn,d=i.height||((a=i.measured)==null?void 0:a.height)||wn;n.push({id:i.id,x:f.x-tn,y:f.y-tn,w:p+2*tn,h:d+2*tn})}return n}function Lr(e,t,n){if(Gn(e.x,e.y,t.x,t.y,n))return null;const r=new Set,a=new Set;r.add(e.x),r.add(t.x),a.add(e.y),a.add(t.y);const o=tn+5;e.dir==="right"?r.add(e.x+o):e.dir==="left"?r.add(e.x-o):e.dir==="top"?a.add(e.y-o):e.dir==="bottom"&&a.add(e.y+o),t.dir==="right"?r.add(t.x+o):t.dir==="left"?r.add(t.x-o):t.dir==="top"?a.add(t.y-o):t.dir==="bottom"&&a.add(t.y+o);for(let g=0;g<n.length;g++){const x=n[g];r.add(x.x),r.add(x.x+x.w),a.add(x.y),a.add(x.y+x.h)}const i=[...r].sort((g,x)=>g-x),f=[...a].sort((g,x)=>g-x),p=new Map,d=new Map;for(let g=0;g<i.length;g++)p.set(i[g],g);for(let g=0;g<f.length;g++)d.set(f[g],g);const h=i.length,v=f.length,E=(g,x)=>x*h+g,M=p.get(e.x),z=d.get(e.y),I=p.get(t.x),k=d.get(t.y);if(M===void 0||z===void 0||I===void 0||k===void 0)return null;const j=E(M,z),X=E(I,k),D=new Float64Array(h*v).fill(1/0),_=new Float64Array(h*v).fill(1/0),A=new Int32Array(h*v).fill(-1),L=new Int8Array(h*v).fill(-1),Y=new Uint8Array(h*v);D[j]=0,_[j]=Math.abs(i[I]-e.x)+Math.abs(f[k]-e.y);const F=[j],B=15,b=[[1,0],[-1,0],[0,1],[0,-1]];for(;F.length>0;){let g=0;for(let ee=1;ee<F.length;ee++)_[F[ee]]<_[F[g]]&&(g=ee);const x=F[g];if(F[g]=F[F.length-1],F.pop(),x===X){const ee=[];let oe=X;for(;oe!==-1&&oe!==j;){const ge=oe/h|0,ye=oe%h;ee.unshift({x:i[ye],y:f[ge]}),oe=A[oe]}return ee.unshift({x:e.x,y:e.y}),Eo(ee,n)}if(Y[x])continue;Y[x]=1;const N=x/h|0,$=x%h,W=i[$],V=f[N],re=L[x];for(let ee=0;ee<4;ee++){const oe=$+b[ee][0],ge=N+b[ee][1];if(oe<0||oe>=h||ge<0||ge>=v)continue;const ye=E(oe,ge);if(Y[ye])continue;const J=i[oe],fe=f[ge];if(Co(J,fe,n)||!Gn(W,V,J,fe,n))continue;const me=Math.abs(J-W)+Math.abs(fe-V),ae=re>=0&&re!==ee?B:0,ue=D[x]+me+ae;ue<D[ye]&&(A[ye]=x,L[ye]=ee,D[ye]=ue,_[ye]=ue+Math.abs(i[I]-J)+Math.abs(f[k]-fe),F.push(ye))}}return null}function Eo(e,t){if(!e||e.length<=2)return e;const n=[e[0]];for(let r=1;r<e.length-1;r++){const a=n[n.length-1],o=e[r],i=e[r+1],f=Math.abs(a.x-o.x)<.5&&Math.abs(o.x-i.x)<.5,p=Math.abs(a.y-o.y)<.5&&Math.abs(o.y-i.y)<.5;(f||p)&&Gn(a.x,a.y,i.x,i.y,t)||n.push(o)}return n.push(e[e.length-1]),n}function zo(e){const t=new Map,n=new Map;for(const a of e){const o=a._routedPoints;if(!(!o||o.length<2))for(let i=0;i<o.length-1;i++){const f=o[i],p=o[i+1];if(Math.abs(f.y-p.y)<.5){const d=Math.round(f.y*10)/10;t.has(d)||t.set(d,[]),t.get(d).push({edgeId:a.id,segIdx:i,x1:Math.min(f.x,p.x),x2:Math.max(f.x,p.x)})}else if(Math.abs(f.x-p.x)<.5){const d=Math.round(f.x*10)/10;n.has(d)||n.set(d,[]),n.get(d).push({edgeId:a.id,segIdx:i,y1:Math.min(f.y,p.y),y2:Math.max(f.y,p.y)})}}}const r=new Map;for(const a of e)a._routedPoints&&r.set(a.id,a._routedPoints.map(o=>({...o})));for(const[,a]of t){if(a.length<2)continue;const o=gr(a,"x1","x2");for(const i of o){if(i.length<2)continue;const f=(i.length-1)*pn/2;for(let p=0;p<i.length;p++){const d=i[p],h=-f+p*pn,v=r.get(d.edgeId);v&&(v[d.segIdx].y+=h,v[d.segIdx+1].y+=h)}}}for(const[,a]of n){if(a.length<2)continue;const o=gr(a,"y1","y2");for(const i of o){if(i.length<2)continue;const f=(i.length-1)*pn/2;for(let p=0;p<i.length;p++){const d=i[p],h=-f+p*pn,v=r.get(d.edgeId);v&&(v[d.segIdx].x+=h,v[d.segIdx+1].x+=h)}}}return e.map(a=>{const o=r.get(a.id);return o?{...a,_routedPoints:o}:a})}function gr(e,t,n){if(e.length<2)return[];const r=[...e].sort((i,f)=>i[t]-f[t]),a=[];let o=[r[0]];for(let i=1;i<r.length;i++){const f=o[o.length-1];r[i][t]<f[n]?o.push(r[i]):(o.length>1&&a.push(o),o=[r[i]])}return o.length>1&&a.push(o),a}function kn(e,t=6,n=!1){if(!e||e.length<2)return null;if(n)return So(e);const r=t;let a=`M ${e[0].x},${e[0].y}`;for(let o=1;o<e.length-1;o++){const i=e[o-1],f=e[o],p=e[o+1],d=Math.abs(f.x-i.x)+Math.abs(f.y-i.y),h=Math.abs(p.x-f.x)+Math.abs(p.y-f.y),v=Math.min(r,d/2,h/2);if(v>.5){const E=f.x-i.x,M=f.y-i.y,z=p.x-f.x,I=p.y-f.y,k=Math.sqrt(E*E+M*M)||1,j=Math.sqrt(z*z+I*I)||1;a+=` L ${f.x-E/k*v},${f.y-M/k*v}`,a+=` Q ${f.x},${f.y} ${f.x+z/j*v},${f.y+I/j*v}`}else a+=` L ${f.x},${f.y}`}return a+=` L ${e[e.length-1].x},${e[e.length-1].y}`,a}function So(e){if(e.length===2)return`M ${e[0].x},${e[0].y} L ${e[1].x},${e[1].y}`;if(e.length===3)return`M ${e[0].x},${e[0].y} Q ${e[1].x},${e[1].y} ${e[2].x},${e[2].y}`;const t=.3;let n=`M ${e[0].x},${e[0].y}`;for(let r=0;r<e.length-1;r++){const a=e[r===0?0:r-1],o=e[r],i=e[r+1],f=e[r+2<e.length?r+2:e.length-1],p=o.x+(i.x-a.x)*t,d=o.y+(i.y-a.y)*t,h=i.x-(f.x-o.x)*t,v=i.y-(f.y-o.y)*t;n+=` C ${p},${d} ${h},${v} ${i.x},${i.y}`}return n}function Cn(e){if(!e||e.length<2)return{x:0,y:0};let t=0;for(let r=1;r<e.length;r++)t+=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);let n=t/2;for(let r=1;r<e.length;r++){const a=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);if(n<=a){const o=a>0?n/a:0;return{x:e[r-1].x+(e[r].x-e[r-1].x)*o,y:e[r-1].y+(e[r].y-e[r-1].y)*o}}n-=a}return{x:e[0].x,y:e[0].y}}function No(e,t){if(!e||!t||e.length===0||t.length===0)return t;const n={};for(const o of e)n[o.id]=o;const r=tr(e,null),a=t.map(o=>{var L,Y,F,B;const i=o.type||"default";if(i==="bezier"||i==="simplebezier"||i==="default")return o;const f=n[o.source],p=n[o.target];if(!f||!p||f.hidden||p.hidden)return o;const d=hr(f,"source",o.sourceHandle),h=hr(p,"target",o.targetHandle),v=Rn(d,Mn),E=Rn(h,Mn),M=5,z=r.filter(b=>b.id!==o.source&&b.id!==o.target),I=f._absolutePosition||f.position,k=f.width||((L=f.measured)==null?void 0:L.width)||bn,j=f.height||((Y=f.measured)==null?void 0:Y.height)||wn;z.push({id:o.source,x:I.x-M,y:I.y-M,w:k+2*M,h:j+2*M});const X=p._absolutePosition||p.position,D=p.width||((F=p.measured)==null?void 0:F.width)||bn,_=p.height||((B=p.measured)==null?void 0:B.height)||wn;if(z.push({id:o.target,x:X.x-M,y:X.y-M,w:D+2*M,h:_+2*M}),z.length===0)return o;const A=Lr(v,E,z);return A&&A.length>=2?(A.unshift({x:d.x,y:d.y}),A.push({x:h.x,y:h.y}),{...o,_routedPoints:A}):o});return zo(a)}function Po(e,t,n,r,a,o,i,f){const p=tr(i,f?new Set(f):null);if(p.length===0)return null;const d={x:e,y:t,dir:a||"right"},h={x:n,y:r,dir:o||"left"},v=Rn(d,Mn),E=Rn(h,Mn),M=Lr(v,E,p);return M&&M.length>=2?(M.unshift({x:d.x,y:d.y}),M.push({x:h.x,y:h.y}),M):null}const nr=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,label:i,labelStyle:f,labelShowBg:p,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:v,style:E,markerEnd:M,markerStart:z,interactionWidth:I,routedPoints:k}){let j,X,D;if(k&&k.length>=2){j=kn(k);const _=Cn(k);X=_.x,D=_.y}else[j,X,D]=Jn({sourceX:n,sourceY:r,targetX:a,targetY:o});return P.jsx(sn,{id:t,path:j,labelX:X,labelY:D,label:i,labelStyle:f,labelShowBg:p,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:v,style:E,markerEnd:M,markerStart:z,interactionWidth:I})});nr.displayName="StraightEdge";const rr=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:i="bottom",targetPosition:f="top",label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,pathOptions:j,interactionWidth:X,routedPoints:D}){let _,A,L;if(D&&D.length>=2){_=kn(D);const Y=Cn(D);A=Y.x,L=Y.y}else[_,A,L]=vn({sourceX:n,sourceY:r,sourcePosition:i,targetX:a,targetY:o,targetPosition:f,borderRadius:j==null?void 0:j.borderRadius,offset:j==null?void 0:j.offset});return P.jsx(sn,{id:t,path:_,labelX:A,labelY:L,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,interactionWidth:X})});rr.displayName="SmoothStepEdge";const Tr=c.memo(function({id:t,...n}){var a;const r=c.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(a=n.pathOptions)==null?void 0:a.offset]);return P.jsx(rr,{...n,id:t,pathOptions:r})});Tr.displayName="StepEdge";const or=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:i,targetPosition:f,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,interactionWidth:j,routedPoints:X}){let D,_,A;if(X&&X.length>=2){D=kn(X);const L=Cn(X);_=L.x,A=L.y}else[D,_,A]=er({sourceX:n,sourceY:r,targetX:a,targetY:o});return P.jsx(sn,{id:t,path:D,labelX:_,labelY:A,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,interactionWidth:j})});or.displayName="SimpleBezierEdge";const Io={input:zr,output:Sr,group:Nr},Lo={bezier:Vn,straight:nr,simplebezier:or},To=160,$o=60;function Bo(e){let t=!1;for(let n=0;n<e.length;n++){const r=e[n];if(!r.measured||r.measured.width==null||r.measured.height==null){t=!0;break}}return t?e.map(n=>{var r,a;return((r=n.measured)==null?void 0:r.width)!=null&&((a=n.measured)==null?void 0:a.height)!=null?n:{...n,measured:{width:n.width||To,height:n.height||$o}}}):e}function jo({cards:e,nodes:t=[],edges:n=[],nodeTypes:r,edgeTypes:a,dark:o,gridSize:i,width:f="100%",height:p="420px",className:d="",style:h={},zoomMin:v,zoomMax:E,initialCamera:M,fitView:z,fitViewOptions:I,onNodesChange:k,onEdgesChange:j,onConnect:X,onConnectStart:D,onConnectEnd:_,onNodeClick:A,onNodeDoubleClick:L,onNodeMouseEnter:Y,onNodeMouseMove:F,onNodeMouseLeave:B,onNodeContextMenu:b,onNodeDragStart:g,onNodeDrag:x,onNodeDragStop:N,onEdgeClick:$,onEdgeDoubleClick:W,onEdgeMouseEnter:V,onEdgeMouseMove:re,onEdgeMouseLeave:ee,onEdgeContextMenu:oe,onPaneClick:ge,onPaneContextMenu:ye,onPaneMouseEnter:J,onPaneMouseMove:fe,onPaneMouseLeave:me,onSelectionChange:ae,onInit:ue,onMoveStart:Ne,onMove:Je,onMoveEnd:le,onDelete:Be,onBeforeDelete:je,onError:_e,onDragOver:he,onDrop:Me,onDragEnter:Oe,onDragLeave:Ae,nodesDraggable:ct,nodesConnectable:zt,elementsSelectable:De,multiSelectionKeyCode:Xe,selectionOnDrag:Ze,selectionMode:St,connectionMode:an,connectionRadius:At,connectOnClick:cn,isValidConnection:un,defaultEdgeOptions:ln,snapToGrid:dn,snapGrid:Dt,deleteKeyCode:dt,panActivationKeyCode:ft,panOnScroll:Nt,panOnScrollMode:En,panOnScrollSpeed:zn,zoomOnScroll:ot,zoomOnDoubleClick:sr,zoomOnPinch:Sn,preventScrolling:Nn,translateExtent:Pt,nodeExtent:It,autoPanOnNodeDrag:Pn,autoPanOnConnect:In,autoPanSpeed:Ln,edgesReconnectable:ht,elevateNodesOnSelect:pe,elevateEdgesOnSelect:Ht,noDragClassName:Ee,noPanClassName:ie,onSelectionDragStart:gt,onSelectionDrag:K,onSelectionDragStop:Re,edgeRouting:fn=!0,onHudUpdate:ut,onNodesProcessed:Lt,showHud:Tn=!0,showHint:$n=!0,hintText:We="Drag to pan · Scroll to zoom",children:Ye,..._t}){const[He,Wt]=c.useState({wx:0,wy:0,zoom:"1.00"}),Mt=c.useRef(null),Ft=c.useRef(null),Bn=c.useCallback(G=>{Wt(G),ut==null||ut(G)},[ut]),yt=c.useMemo(()=>({...Io,...r}),[r]),xt=c.useMemo(()=>({...Lo,...a}),[a]),tt=c.useMemo(()=>Bo(t),[t]),Ke=c.useMemo(()=>{const G=tt.filter(Ie=>Ie.type&&yt[Ie.type]&&(Ie.selected||Ie.dragging));return G.sort((Ie,ve)=>{const Le=Ie.type==="group"||!Ie.parentId&&G.some(ce=>ce.parentId===Ie.id),at=ve.type==="group"||!ve.parentId&&G.some(ce=>ce.parentId===ve.id);return Le&&!at?-1:!Le&&at?1:0})},[tt,yt]),Tt=c.useMemo(()=>n.filter(G=>G.type&&xt[G.type]),[n,xt]),O=c.useMemo(()=>t.map(G=>G.type&&yt[G.type]&&(G.selected||G.dragging)?{...G,_customRendered:!0}:G),[t,yt]),pt=c.useMemo(()=>n.map(G=>G.type&&xt[G.type]?{...G,_customRendered:!0}:G),[n,xt]),{wrapRef:$t,canvasRef:Xt,canvasReady:Yt,onPointerDown:qt,onPointerMove:Ut,onPointerUp:Ot,store:we}=br({cards:e,nodes:O,edges:pt,dark:o,gridSize:i,zoomMin:v,zoomMax:E,initialCamera:M,fitView:z,fitViewOptions:I,onHudUpdate:Bn,onNodesProcessed:Lt,onNodesChange:k,onEdgesChange:j,onConnect:X,onConnectStart:D,onConnectEnd:_,onNodeClick:A,onNodeDoubleClick:L,onNodeMouseEnter:Y,onNodeMouseMove:F,onNodeMouseLeave:B,onNodeContextMenu:b,onNodeDragStart:g,onNodeDrag:x,onNodeDragStop:N,onEdgeClick:$,onEdgeDoubleClick:W,onEdgeMouseEnter:V,onEdgeMouseMove:re,onEdgeMouseLeave:ee,onEdgeContextMenu:oe,onPaneClick:ge,onPaneContextMenu:ye,onPaneMouseEnter:J,onPaneMouseMove:fe,onPaneMouseLeave:me,onSelectionChange:ae,onInit:ue,onMoveStart:Ne,onMove:Je,onMoveEnd:le,onDelete:Be,onBeforeDelete:je,onError:_e,nodesDraggable:ct,nodesConnectable:zt,elementsSelectable:De,multiSelectionKeyCode:Xe,selectionOnDrag:Ze,selectionMode:St,connectionMode:an,connectionRadius:At,connectOnClick:cn,isValidConnection:un,defaultEdgeOptions:ln,snapToGrid:dn,snapGrid:Dt,deleteKeyCode:dt,panActivationKeyCode:ft,panOnScroll:Nt,panOnScrollMode:En,panOnScrollSpeed:zn,zoomOnScroll:ot,zoomOnDoubleClick:sr,zoomOnPinch:Sn,preventScrolling:Nn,translateExtent:Pt,nodeExtent:It,autoPanOnNodeDrag:Pn,autoPanOnConnect:In,autoPanSpeed:Ln,edgesReconnectable:ht,elevateNodesOnSelect:pe,elevateEdgesOnSelect:Ht,noDragClassName:Ee,noPanClassName:ie,onSelectionDragStart:gt,onSelectionDrag:K,onSelectionDragStop:Re,edgeRouting:fn}),mt=c.useContext(Et),Bt=mt&&typeof mt.getState=="function";c.useEffect(()=>{Bt&&queueMicrotask(()=>{mt.setState({nodes:tt,edges:n,nodesRef:we.nodesRef,edgesRef:we.edgesRef,onNodesChangeRef:we.onNodesChangeRef,onEdgesChangeRef:we.onEdgesChangeRef,cameraRef:we.cameraRef,wrapRef:we.wrapRef,workerRef:we.workerRef})})},[Bt,tt,n,we,mt]);const ze=c.useMemo(()=>({...we,edgeLabelContainerRef:Mt,viewportPortalRef:Ft,get nodes(){return tt},get edges(){return n},get viewport(){return we.cameraRef.current},get minZoom(){return we.zoomMin||.1},get maxZoom(){return we.zoomMax||5},get domNode(){return we.wrapRef.current},get width(){var G;return((G=we.wrapRef.current)==null?void 0:G.clientWidth)||0},get height(){var G;return((G=we.wrapRef.current)==null?void 0:G.clientHeight)||0}}),[we,tt,n]),Zt=c.useRef(null),Pe=c.useRef(null),Gt=c.useRef(null),st=c.useRef(null),Rt=c.useRef(null);c.useEffect(()=>{let G;const Ie=()=>{const ve=we.cameraRef.current,Le=`translate(${ve.x}px, ${ve.y}px) scale(${ve.zoom})`,at=`translate(${ve.x}, ${ve.y}) scale(${ve.zoom})`;Zt.current&&(Zt.current.style.transform=Le),Pe.current&&Pe.current.setAttribute("transform",at),Gt.current&&(Gt.current.style.transform=Le),st.current&&(st.current.style.transform=Le);const ce=$t.current;if(ce){const Ge=ve.zoom<.15?"lod-minimal":ve.zoom<.35?"lod-reduced":null;Ge!==Rt.current&&(ce.classList.remove("lod-minimal","lod-reduced"),Ge&&ce.classList.add(Ge),Rt.current=Ge)}G=requestAnimationFrame(Ie)};return G=requestAnimationFrame(Ie),()=>cancelAnimationFrame(G)},[we]);const[et,vt]=c.useState(null);c.useEffect(()=>{if(!Ke.length)return;let G;const Ie=()=>{var Qt,gn;const ve=we.cameraRef.current,Le=we.wrapRef.current;if(!Le){G=requestAnimationFrame(Ie);return}const at=Le.getBoundingClientRect(),ce=200,Ge=-ve.x/ve.zoom-ce,bt=-ve.y/ve.zoom-ce,jn=(at.width-ve.x)/ve.zoom+ce,An=(at.height-ve.y)/ve.zoom+ce,kt=new Set;for(const qe of Ke){const wt=qe._absolutePosition||qe.position,Dn=qe.width||((Qt=qe.measured)==null?void 0:Qt.width)||200,Hn=qe.height||((gn=qe.measured)==null?void 0:gn.height)||100;wt.x+Dn>=Ge&&wt.x<=jn&&wt.y+Hn>=bt&&wt.y<=An&&kt.add(qe.id)}vt(qe=>{if(!qe||qe.size!==kt.size)return kt;for(const wt of kt)if(!qe.has(wt))return kt;return qe}),G=requestAnimationFrame(Ie)};return G=requestAnimationFrame(Ie),()=>cancelAnimationFrame(G)},[Ke,we]);const hn=c.useMemo(()=>et?Ke.filter(G=>et.has(G.id)):Ke,[Ke,et]),Se=Ke.length>0,nt=Tt.length>0;return P.jsx(Et.Provider,{value:ze,children:P.jsxs("div",{ref:$t,className:`ric-wrap ${d}`,style:{width:f,height:p,...h},onPointerDown:qt,onPointerMove:Ut,onPointerUp:Ot,onDragOver:he,onDrop:Me,onDragEnter:Oe,onDragLeave:Ae,tabIndex:0,children:[P.jsx("canvas",{ref:Xt,className:"ric-canvas"}),!Yt&&P.jsx("div",{className:"ric-loader",children:P.jsx("div",{className:"ric-spinner"})}),nt&&P.jsx("svg",{className:"ric-edges-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:P.jsx("g",{ref:Pe,children:Tt.map(G=>P.jsx(yo,{edge:G,edgeType:xt[G.type],nodes:t,reconnectable:ht},G.id))})}),Se&&P.jsx("div",{ref:Zt,className:"ric-nodes-overlay",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:10},children:hn.map(G=>P.jsx(lo,{node:G,nodeType:yt[G.type]},G.id))}),P.jsx("div",{ref:G=>{Mt.current=G,Gt.current=G},className:"ric-edge-labels",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:5}}),P.jsx("div",{ref:G=>{Ft.current=G,st.current=G},className:"ric-viewport-portal",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:6}}),$n&&P.jsx("div",{className:"ric-hint",children:We}),Tn&&P.jsxs("div",{className:"ric-info",children:["world: (",He.wx,", ",He.wy,")   zoom: ",He.zoom,"x",He.nodeCount>0&&P.jsxs(P.Fragment,{children:["   nodes: ",He.nodeCount]}),He.edgeCount>0&&P.jsxs(P.Fragment,{children:["   edges: ",He.edgeCount]})]}),P.jsx(Cr,{selectionKeyCode:Xe||"Shift",selectionMode:St||"partial"}),Ye]})})}function Ao({children:e}){const t=c.useRef(null);return t.current||(t.current=io()),P.jsx(Et.Provider,{value:t.current,children:e})}function $r(e,t){const n=[],r=new Map,a=[];for(const o of e)if(o.type==="add")a.push(o);else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const i=r.get(o.id);i?i.push(o):r.set(o.id,[o])}for(const o of t){const i=r.get(o.id);if(!i){n.push(o);continue}if(i[0].type==="remove")continue;if(i[0].type==="replace"){n.push({...i[0].item});continue}const f={...o};for(const p of i)Do(p,f);n.push(f)}for(const o of a)o.index!==void 0?n.splice(o.index,0,{...o.item}):n.push({...o.item});return n}function Do(e,t){switch(e.type){case"select":t.selected=e.selected;break;case"position":e.position!==void 0&&(t.position=e.position),e.dragging!==void 0&&(t.dragging=e.dragging);break;case"dimensions":e.dimensions!==void 0&&(t.measured={...e.dimensions},(e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height)),e.handleBounds!==void 0&&(t.handleBounds=e.handleBounds);break}}function Br(e,t){return $r(e,t)}function jr(e,t){return $r(e,t)}function Ho(e,t){return!e.source||!e.target?(console.warn("addEdge: source and target are required"),t):t.some(r=>r.source===e.source&&r.target===e.target&&(r.sourceHandle||null)===(e.sourceHandle||null)&&(r.targetHandle||null)===(e.targetHandle||null))?t:[...t,{id:e.id||`e-${e.source}-${e.target}`,...e}]}function _o(e){const[t,n]=c.useState(e),r=c.useCallback(a=>n(o=>Br(a,o)),[]);return[t,n,r]}function Wo(e){const[t,n]=c.useState(e),r=c.useCallback(a=>n(o=>jr(a,o)),[]);return[t,n,r]}function Ar(){const e=wr(),t=c.useCallback(()=>typeof e.getState=="function"?e.getState():e,[e]),n=c.useCallback(()=>[...t().nodesRef.current],[t]),r=c.useCallback(()=>[...t().edgesRef.current],[t]),a=c.useCallback(b=>t().nodesRef.current.find(g=>g.id===b),[t]),o=c.useCallback(b=>t().edgesRef.current.find(g=>g.id===b),[t]),i=c.useCallback(b=>{var g,x,N,$;if(typeof b=="function"){const W=b(t().nodesRef.current);(x=(g=t().onNodesChangeRef).current)==null||x.call(g,[...t().nodesRef.current.map(V=>({id:V.id,type:"remove"})),...W.map(V=>({type:"add",item:V}))])}else($=(N=t().onNodesChangeRef).current)==null||$.call(N,[...t().nodesRef.current.map(W=>({id:W.id,type:"remove"})),...b.map(W=>({type:"add",item:W}))])},[t]),f=c.useCallback(b=>{var g,x,N,$;if(typeof b=="function"){const W=b(t().edgesRef.current);(x=(g=t().onEdgesChangeRef).current)==null||x.call(g,[...t().edgesRef.current.map(V=>({id:V.id,type:"remove"})),...W.map(V=>({type:"add",item:V}))])}else($=(N=t().onEdgesChangeRef).current)==null||$.call(N,[...t().edgesRef.current.map(W=>({id:W.id,type:"remove"})),...b.map(W=>({type:"add",item:W}))])},[t]),p=c.useCallback(b=>{var x,N;const g=Array.isArray(b)?b:[b];(N=(x=t().onNodesChangeRef).current)==null||N.call(x,g.map($=>({type:"add",item:$})))},[t]),d=c.useCallback(b=>{var x,N;const g=Array.isArray(b)?b:[b];(N=(x=t().onEdgesChangeRef).current)==null||N.call(x,g.map($=>({type:"add",item:$})))},[t]),h=c.useCallback(({nodes:b=[],edges:g=[]})=>{if(b.length&&t().onNodesChangeRef.current){t().onNodesChangeRef.current(b.map(N=>({id:N.id,type:"remove"})));const x=mr(b,t().edgesRef.current);x.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(x.map(N=>({id:N.id,type:"remove"})))}g.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(g.map(x=>({id:x.id,type:"remove"})))},[t]),v=c.useCallback(()=>{const b=t().cameraRef.current;return{x:b.x,y:b.y,zoom:b.zoom}},[t]),E=c.useRef(null),M=c.useCallback((b,g)=>{if(E.current&&cancelAnimationFrame(E.current),!g||g<=0){t().cameraRef.current={...b},t().sendCamera();return}const x={...t().cameraRef.current},N=performance.now(),$=W=>{const V=W-N,re=Math.min(V/g,1),ee=1-Math.pow(1-re,3);t().cameraRef.current={x:x.x+(b.x-x.x)*ee,y:x.y+(b.y-x.y)*ee,zoom:x.zoom+(b.zoom-x.zoom)*ee},t().sendCamera(),re<1&&(E.current=requestAnimationFrame($))};E.current=requestAnimationFrame($)},[t]),z=c.useCallback((b,g)=>{const x={x:b.x??t().cameraRef.current.x,y:b.y??t().cameraRef.current.y,zoom:b.zoom??t().cameraRef.current.zoom};M(x,g==null?void 0:g.duration)},[t,M]),I=c.useCallback(()=>t().cameraRef.current.zoom,[t]),k=c.useCallback(b=>{const g=t().cameraRef.current,x=t().wrapRef.current;if(!x)return;const N=x.getBoundingClientRect(),$=N.width/2,W=N.height/2,V=1.2,re={x:$-($-g.x)*V,y:W-(W-g.y)*V,zoom:Math.min(t().zoomMax,g.zoom*V)};M(re,b==null?void 0:b.duration)},[t,M]),j=c.useCallback(b=>{const g=t().cameraRef.current,x=t().wrapRef.current;if(!x)return;const N=x.getBoundingClientRect(),$=N.width/2,W=N.height/2,V=1/1.2,re={x:$-($-g.x)*V,y:W-(W-g.y)*V,zoom:Math.max(t().zoomMin,g.zoom*V)};M(re,b==null?void 0:b.duration)},[t,M]),X=c.useCallback((b,g)=>{const x=t().cameraRef.current,N=t().wrapRef.current;if(!N)return;const $=N.getBoundingClientRect(),W=$.width/2,V=$.height/2,re=Math.min(t().zoomMax,Math.max(t().zoomMin,b)),ee=re/x.zoom,oe={x:W-(W-x.x)*ee,y:V-(V-x.y)*ee,zoom:re};M(oe,g==null?void 0:g.duration)},[t,M]),D=c.useCallback((b={})=>{const g=t().nodesRef.current;if(!g.length)return;const x=t().wrapRef.current;if(!x)return;const N=x.getBoundingClientRect(),$=b.padding??.1,W=b.nodes?g.filter(ee=>b.nodes.some(oe=>oe.id===ee.id)):g;if(!W.length)return;const V=mn(W),re=jt(V,N.width,N.height,$);b.maxZoom&&(re.zoom=Math.min(re.zoom,b.maxZoom)),b.minZoom&&(re.zoom=Math.max(re.zoom,b.minZoom)),M(re,b.duration)},[t,M]),_=c.useCallback((b,g={})=>{const x=t().wrapRef.current;if(!x)return;const N=x.getBoundingClientRect(),$=g.padding??.1,W=jt(b,N.width,N.height,$);g.maxZoom&&(W.zoom=Math.min(W.zoom,g.maxZoom)),g.minZoom&&(W.zoom=Math.max(W.zoom,g.minZoom)),M(W,g.duration)},[t,M]),A=c.useCallback((b,g,x={})=>{const N=t().wrapRef.current;if(!N)return;const $=N.getBoundingClientRect(),W=x.zoom??t().cameraRef.current.zoom,V={x:$.width/2-b*W,y:$.height/2-g*W,zoom:W};M(V,x.duration)},[t,M]),L=c.useCallback(()=>({nodes:[...t().nodesRef.current],edges:[...t().edgesRef.current],viewport:{...t().cameraRef.current}}),[t]),Y=c.useCallback(b=>t().screenToWorld(b.x,b.y),[t]),F=c.useCallback(b=>{const g=t().cameraRef.current,x=t().wrapRef.current;if(!x)return{x:0,y:0};const N=x.getBoundingClientRect();return{x:b.x*g.zoom+g.x+N.left,y:b.y*g.zoom+g.y+N.top}},[t]),B=c.useCallback((b,g)=>{var $,W;const x=t().nodesRef.current.find(V=>V.id===b);if(!x)return;const N=typeof g=="function"?g(x.data):{...x.data,...g};(W=($=t().onNodesChangeRef).current)==null||W.call($,[{id:b,type:"replace",item:{...x,data:N}}])},[t]);return{getNodes:n,getEdges:r,getNode:a,getEdge:o,setNodes:i,setEdges:f,addNodes:p,addEdges:d,deleteElements:h,getViewport:v,setViewport:z,getZoom:I,zoomIn:k,zoomOut:j,zoomTo:X,fitView:D,fitBounds:_,setCenter:A,screenToFlowPosition:Y,flowToScreenPosition:F,updateNodeData:B,toObject:L}}function Fo(){return Ce().nodes}function Xo(){return Ce().edges}function Yo(){return Ce().viewport}function qo(){return Ce().connection}function Uo(e){const t=Ce(),n=Array.isArray(e)?e:[e];return c.useMemo(()=>n.map(r=>{const a=t.nodes.find(o=>o.id===r);return a?{id:a.id,type:a.type,data:a.data}:null}).filter(Boolean),[t.nodes,...n])}function Oo(e){const t=Ce();return c.useMemo(()=>t.edges.filter(n=>n.source===e||n.target===e),[t.edges,e])}function Zo({nodeId:e,type:t,handleId:n}){const r=Ce();return c.useMemo(()=>r.edges.filter(a=>t==="source"?a.source===e&&(n?a.sourceHandle===n:!0):a.target===e&&(n?a.targetHandle===n:!0)),[r.edges,e,t,n])}function Go({onChange:e,onStart:t,onEnd:n}){const r=Ce(),a=c.useRef(e),o=c.useRef(t),i=c.useRef(n);c.useEffect(()=>{a.current=e},[e]),c.useEffect(()=>{o.current=t},[t]),c.useEffect(()=>{i.current=n},[n]),c.useEffect(()=>{const f=p=>{var d;(d=a.current)==null||d.call(a,{x:p.x,y:p.y,zoom:p.zoom})};return r.viewportListeners.add(f),()=>r.viewportListeners.delete(f)},[s])}function Qo({onChange:e}){const t=Ce(),n=c.useRef(e);c.useEffect(()=>{n.current=e},[e]),c.useEffect(()=>{const r=a=>{var o;(o=n.current)==null||o.call(n,a)};return t.selectionListeners.add(r),()=>t.selectionListeners.delete(r)},[s])}function Vo(e){const[t,n]=c.useState(!1),r=Array.isArray(e)?e:[e];return c.useEffect(()=>{const a=i=>{r.includes(i.key)&&n(!0)},o=i=>{r.includes(i.key)&&n(!1)};return window.addEventListener("keydown",a),window.addEventListener("keyup",o),()=>{window.removeEventListener("keydown",a),window.removeEventListener("keyup",o)}},[r.join(",")]),t}function Jo(){const e=Ce();return c.useCallback(t=>{var n;(n=e.workerRef.current)==null||n.postMessage({type:"nodes",data:{nodes:[...s().nodesRef.current]}})},[s])}const Ko=e=>{var t;return((t=e.nodes)==null?void 0:t.length)>0};function es(e={}){return Ce(Ko)}function ts(e){const t=Ce();return c.useMemo(()=>t.nodes.find(n=>n.id===e)||void 0,[t.nodes,e])}function ns(e,t){return Ce(e,t)}function rs(){return wr()}function os({maxHistorySize:e=100}={}){const t=Ce(),n=c.useRef([]),r=c.useRef([]),[,a]=c.useState(0),o=c.useRef(null),i=c.useCallback(()=>{const d={nodes:s().nodesRef.current.map(h=>({...h,data:{...h.data}})),edges:s().edgesRef.current.map(h=>({...h}))};o.current&&JSON.stringify(o.current.nodes.map(h=>h.id))===JSON.stringify(d.nodes.map(h=>h.id))&&JSON.stringify(o.current.edges.map(h=>h.id))===JSON.stringify(d.edges.map(h=>h.id))||(n.current.push(d),n.current.length>e&&n.current.shift(),r.current=[],o.current=d,a(h=>h+1))},[t,e]),f=c.useCallback(()=>{var h,v,E,M;const d=n.current.pop();d&&(r.current.push({nodes:s().nodesRef.current.map(z=>({...z,data:{...z.data}})),edges:s().edgesRef.current.map(z=>({...z}))}),(v=(h=s().onNodesChangeRef).current)==null||v.call(h,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...d.nodes.map(z=>({type:"add",item:z}))]),(M=(E=s().onEdgesChangeRef).current)==null||M.call(E,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...d.edges.map(z=>({type:"add",item:z}))]),o.current=d,a(z=>z+1))},[s]),p=c.useCallback(()=>{var h,v,E,M;const d=r.current.pop();d&&(n.current.push({nodes:s().nodesRef.current.map(z=>({...z,data:{...z.data}})),edges:s().edgesRef.current.map(z=>({...z}))}),(v=(h=s().onNodesChangeRef).current)==null||v.call(h,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...d.nodes.map(z=>({type:"add",item:z}))]),(M=(E=s().onEdgesChangeRef).current)==null||M.call(E,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...d.edges.map(z=>({type:"add",item:z}))]),o.current=d,a(z=>z+1))},[s]);return{undo:f,redo:p,takeSnapshot:i,canUndo:n.current.length>0,canRedo:r.current.length>0}}function ss(e){const t=c.useRef(e);return c.useEffect(()=>{t.current=e},[e]),c.useCallback(n=>r=>{const a=t.current(r);a!==!1&&a!=null&&n(Array.isArray(a)?a:r)},[])}function as(e){const t=c.useRef(e);return c.useEffect(()=>{t.current=e},[e]),c.useCallback(n=>r=>{const a=t.current(r);a!==!1&&a!=null&&n(Array.isArray(a)?a:r)},[])}const Xn=160,Yn=60;function is({width:e=200,height:t=150,nodeColor:n="#3b82f6",nodeStrokeColor:r="#fff",maskColor:a="rgba(0,0,0,0.1)",style:o={},className:i=""}){const f=Ce(),p=c.useRef(null),d=c.useRef(null),h=c.useCallback(()=>{const v=p.current;if(!v)return;const E=v.getContext("2d"),M=window.devicePixelRatio||1;v.width=e*M,v.height=t*M,E.scale(M,M),E.clearRect(0,0,e,t);const z=f.nodesRef.current;if(!z.length)return;let I=1/0,k=1/0,j=-1/0,X=-1/0;for(const g of z){const x=g.width||Xn,N=g.height||Yn;g.position.x<I&&(I=g.position.x),g.position.y<k&&(k=g.position.y),g.position.x+x>j&&(j=g.position.x+x),g.position.y+N>X&&(X=g.position.y+N)}const D=40;I-=D,k-=D,j+=D,X+=D;const _=j-I,A=X-k,L=Math.min(e/_,t/A),Y=(e-_*L)/2,F=(t-A*L)/2;for(const g of z){if(g.hidden)continue;const x=g.width||Xn,N=g.height||Yn,$=(g.position.x-I)*L+Y,W=(g.position.y-k)*L+F,V=x*L,re=N*L;E.fillStyle=g.selected?"#f59e0b":typeof n=="function"?n(g):n,E.fillRect($,W,Math.max(V,2),Math.max(re,2))}const B=f.cameraRef.current,b=f.wrapRef.current;if(b){const g=b.getBoundingClientRect(),x=-B.x/B.zoom,N=-B.y/B.zoom,$=g.width/B.zoom,W=g.height/B.zoom;E.fillStyle=a,E.fillRect(0,0,e,t);const V=(x-I)*L+Y,re=(N-k)*L+F,ee=$*L,oe=W*L;E.clearRect(V,re,ee,oe);for(const ge of z){if(ge.hidden)continue;const ye=ge.width||Xn,J=ge.height||Yn,fe=(ge.position.x-I)*L+Y,me=(ge.position.y-k)*L+F;E.fillStyle=ge.selected?"#f59e0b":typeof n=="function"?n(ge):n,E.fillRect(fe,me,Math.max(ye*L,2),Math.max(J*L,2))}E.strokeStyle="#3b82f6",E.lineWidth=1.5,E.strokeRect(V,re,ee,oe)}},[f,e,t,n,r,a]);return c.useEffect(()=>{let v=!0;function E(){v&&(h(),d.current=requestAnimationFrame(E))}const M=setInterval(()=>{cancelAnimationFrame(d.current),d.current=requestAnimationFrame(E)},66);return h(),()=>{v=!1,clearInterval(M),cancelAnimationFrame(d.current)}},[h]),P.jsx("canvas",{ref:p,className:`ric-minimap ${i}`,style:{position:"absolute",bottom:30,right:10,width:e,height:t,borderRadius:4,border:"1px solid rgba(0,0,0,0.1)",background:"rgba(255,255,255,0.9)",pointerEvents:"none",...o}})}function cs(){return P.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[P.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),P.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function us(){return P.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:P.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function ls(){return P.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:P.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}function ds(){return P.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[P.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),P.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function fs(){return P.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[P.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),P.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})}function nn({children:e,className:t="",...n}){return P.jsx("button",{className:`ric-controls-button ${t}`,style:gs,...n,children:e})}function hs({showZoom:e=!0,showFitView:t=!0,showInteractive:n=!1,fitViewOptions:r,onZoomIn:a,onZoomOut:o,onFitView:i,onInteractiveChange:f,position:p="bottom-left",orientation:d="vertical",style:h={},className:v="","aria-label":E="Canvas controls",children:M}){const z=Ce(),{zoomIn:I,zoomOut:k,fitView:j,getZoom:X}=Ar(),[D,_]=c.useState(!0),A=X()<=z.zoomMin,L=X()>=z.zoomMax,Y=c.useCallback(()=>{I(),a==null||a()},[I,a]),F=c.useCallback(()=>{k(),o==null||o()},[k,o]),B=c.useCallback(()=>{j(r||{padding:.1}),i==null||i()},[j,r,i]),b=c.useCallback(()=>{const x=!D;_(x),f==null||f(x)},[D,f]),g={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:30,left:10},"bottom-right":{bottom:30,right:10},"bottom-center":{bottom:30,left:"50%",transform:"translateX(-50%)"}}[p]||{bottom:30,left:10};return P.jsxs("div",{className:`ric-controls ${v}`,style:{position:"absolute",display:"flex",flexDirection:d==="horizontal"?"row":"column",gap:2,zIndex:5,...g,...h},role:"toolbar","aria-label":E,children:[e&&P.jsxs(P.Fragment,{children:[P.jsx(nn,{onClick:Y,disabled:L,title:"Zoom in","aria-label":"Zoom in",className:"ric-controls-zoomin",children:P.jsx(cs,{})}),P.jsx(nn,{onClick:F,disabled:A,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:P.jsx(us,{})})]}),t&&P.jsx(nn,{onClick:B,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:P.jsx(ls,{})}),n&&P.jsx(nn,{onClick:b,title:D?"Lock interactivity":"Unlock interactivity","aria-label":D?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:D?P.jsx(fs,{}):P.jsx(ds,{})}),M]})}const gs={width:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid rgba(0,0,0,0.12)",borderRadius:4,background:"#fff",cursor:"pointer",fontSize:16,lineHeight:1,color:"#333",padding:0},ys=c.memo(hs);function xs({variant:e="lines",gap:t=40,size:n=1,color:r,style:a={},className:o=""}){const i=Ce();return i.workerRef.current&&i.workerRef.current.postMessage({type:"background",data:{variant:e,gap:t,size:n,color:r}}),null}function ps({position:e="top-left",style:t={},className:n="",children:r}){const a={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:10,left:10},"bottom-right":{bottom:10,right:10},"bottom-center":{bottom:10,left:"50%",transform:"translateX(-50%)"}}[e]||{top:10,left:10};return P.jsx("div",{className:`ric-panel ${n}`,style:{position:"absolute",zIndex:5,pointerEvents:"all",...a,...t},onPointerDown:o=>o.stopPropagation(),children:r})}function ms({minWidth:e=10,minHeight:t=10,maxWidth:n=1/0,maxHeight:r=1/0,isVisible:a=!0,handleStyle:o={},lineStyle:i={},color:f="#3b82f6",onResizeStart:p,onResize:d,onResizeEnd:h}){const v=c.useContext(on),E=Ce(),M=c.useRef(null),z=c.useCallback((j,X)=>{j.stopPropagation(),j.preventDefault();const D=E.nodesRef.current.find(L=>L.id===v);if(!D)return;M.current={direction:X,startX:j.clientX,startY:j.clientY,width:D.width||160,height:D.height||60},p==null||p(j,{width:M.current.width,height:M.current.height});const _=L=>{var N,$;if(!M.current)return;const Y=M.current,F=E.cameraRef.current,B=(L.clientX-Y.startX)/F.zoom,b=(L.clientY-Y.startY)/F.zoom;let g=Y.width,x=Y.height;Y.direction.includes("e")&&(g=Math.min(n,Math.max(e,Y.width+B))),Y.direction.includes("w")&&(g=Math.min(n,Math.max(e,Y.width-B))),Y.direction.includes("s")&&(x=Math.min(r,Math.max(t,Y.height+b))),Y.direction.includes("n")&&(x=Math.min(r,Math.max(t,Y.height-b))),($=(N=E.onNodesChangeRef).current)==null||$.call(N,[{id:v,type:"dimensions",dimensions:{width:g,height:x},setAttributes:!0}]),d==null||d(L,{width:g,height:x})},A=L=>{M.current=null,h==null||h(L,{}),window.removeEventListener("pointermove",_),window.removeEventListener("pointerup",A)};window.addEventListener("pointermove",_),window.addEventListener("pointerup",A)},[v,E,e,t,n,r,p,d,h]);if(!a)return null;const I=8,k={position:"absolute",width:I,height:I,background:f,border:"1px solid #fff",borderRadius:2,zIndex:20,...o};return P.jsxs(P.Fragment,{children:[P.jsx("div",{style:{...k,bottom:-I/2,right:-I/2,cursor:"nwse-resize"},onPointerDown:j=>z(j,"se")}),P.jsx("div",{style:{...k,bottom:-I/2,left:-I/2,cursor:"nesw-resize"},onPointerDown:j=>z(j,"sw")}),P.jsx("div",{style:{...k,top:-I/2,right:-I/2,cursor:"nesw-resize"},onPointerDown:j=>z(j,"ne")}),P.jsx("div",{style:{...k,top:-I/2,left:-I/2,cursor:"nwse-resize"},onPointerDown:j=>z(j,"nw")}),P.jsx("div",{style:{...k,top:"50%",right:-I/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:j=>z(j,"e")}),P.jsx("div",{style:{...k,top:"50%",left:-I/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:j=>z(j,"w")}),P.jsx("div",{style:{...k,left:"50%",top:-I/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:j=>z(j,"n")}),P.jsx("div",{style:{...k,left:"50%",bottom:-I/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:j=>z(j,"s")})]})}function vs({isVisible:e,position:t="top",offset:n=10,align:r="center",children:a,style:o={},className:i=""}){const f=c.useContext(on),d=Ce().nodes.find(E=>E.id===f);if(!(e!==void 0?e:d==null?void 0:d.selected))return null;const v={top:{bottom:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginBottom:n},bottom:{top:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginTop:n},left:{right:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginRight:n},right:{left:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginLeft:n}}[t]||{};return P.jsx("div",{className:`ric-node-toolbar ${i}`,style:{position:"absolute",zIndex:1e3,pointerEvents:"all",...v,...o},onPointerDown:E=>E.stopPropagation(),children:a})}function bs({isVisible:e=!1,x:t=0,y:n=0,alignX:r="center",alignY:a="center",children:o,style:i={},className:f=""}){if(!e)return null;const p=r==="center"?"-50%":r==="right"?"-100%":"0",d=a==="center"?"-50%":a==="bottom"?"-100%":"0";return P.jsx("div",{className:`ric-edge-toolbar ${f}`,style:{position:"absolute",left:t,top:n,transform:`translate(${p}, ${d})`,zIndex:1e3,pointerEvents:"all",...i},children:o})}function ws({children:e}){var r;const n=(r=Ce().edgeLabelContainerRef)==null?void 0:r.current;return n?yr.createPortal(e,n):null}function Ms({children:e}){var r;const n=(r=Ce().viewportPortalRef)==null?void 0:r.current;return n?yr.createPortal(e,n):null}function Dr({fromX:e,fromY:t,toX:n,toY:r,fromPosition:a="right",toPosition:o="left",connectionLineType:i="default",connectionLineStyle:f,connectionLineComponent:p}){if(p)return P.jsx(p,{fromX:e,fromY:t,toX:n,toY:r,fromPosition:a,toPosition:o});let d;switch(i){case"straight":[d]=Jn({sourceX:e,sourceY:t,targetX:n,targetY:r});break;case"step":[d]=vn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o,borderRadius:0});break;case"smoothstep":[d]=vn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o});break;case"simplebezier":[d]=er({sourceX:e,sourceY:t,targetX:n,targetY:r});break;default:[d]=Kn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o});break}return P.jsx("path",{d,fill:"none",className:"ric-connection-line",stroke:"#b1b1b7",strokeWidth:1.5,style:f})}Dr.displayName="ConnectionLine";const Rs=c.memo(Dr),ks=Object.freeze({Top:"top",Bottom:"bottom",Left:"left",Right:"right"}),Cs=Object.freeze({Arrow:"arrow",ArrowClosed:"arrowclosed"});function Es(e){const t=e.width||e.measured&&e.measured.width||0,n=e.height||e.measured&&e.measured.height||0,r=e._absolutePosition||e.position||{x:0,y:0};return{x:r.x,y:r.y,x2:r.x+t,y2:r.y+n}}exports.Background=xs;exports.BaseEdge=sn;exports.BezierEdge=Vn;exports.ConnectionLine=Rs;exports.ControlButton=nn;exports.Controls=ys;exports.DefaultNode=vo;exports.EdgeLabelRenderer=ws;exports.EdgeText=Ir;exports.EdgeToolbar=bs;exports.GroupNode=Nr;exports.Handle=rn;exports.InfiniteCanvas=jo;exports.InfiniteCanvasProvider=Ao;exports.InputNode=zr;exports.MarkerType=Cs;exports.MiniMap=is;exports.NodeResizer=ms;exports.NodeToolbar=vs;exports.OutputNode=Sr;exports.Panel=ps;exports.Position=ks;exports.SelectionBox=Cr;exports.SimpleBezierEdge=or;exports.SmoothStepEdge=rr;exports.StepEdge=Tr;exports.StraightEdge=nr;exports.ViewportPortal=Ms;exports.addEdge=Ho;exports.applyEdgeChanges=jr;exports.applyNodeChanges=Br;exports.boxToRect=Qr;exports.buildObstacles=tr;exports.clampPosition=Un;exports.computeRoutedEdges=No;exports.getBezierEdgeCenter=bo;exports.getBezierPath=Kn;exports.getBoundsOfBoxes=Vr;exports.getConnectedEdges=mr;exports.getEdgeCenter=wo;exports.getIncomers=Ur;exports.getNodeDimensions=Qn;exports.getNodesBounds=mn;exports.getNodesInside=Zr;exports.getOutgoers=Or;exports.getOverlappingArea=Jr;exports.getRoutedLabelPosition=Cn;exports.getSimpleBezierPath=er;exports.getSmoothStepPath=vn;exports.getStraightPath=Jn;exports.getViewportForBounds=jt;exports.isEdge=qr;exports.isNode=Yr;exports.nodeToBox=Es;exports.nodeToRect=Kr;exports.reconnectEdge=Mo;exports.rectToBox=Gr;exports.routeSinglePath=Po;exports.routedPointsToPath=kn;exports.snapPosition=qn;exports.useConnection=qo;exports.useEdges=Xo;exports.useEdgesState=Wo;exports.useHandleConnections=Zo;exports.useInfiniteCanvas=br;exports.useInternalNode=ts;exports.useKeyPress=Vo;exports.useNodeConnections=Oo;exports.useNodeId=co;exports.useNodes=Fo;exports.useNodesData=Uo;exports.useNodesInitialized=es;exports.useNodesState=_o;exports.useOnEdgesChangeMiddleware=as;exports.useOnNodesChangeMiddleware=ss;exports.useOnSelectionChange=Qo;exports.useOnViewportChange=Go;exports.useReactFlow=Ar;exports.useStore=ns;exports.useStoreApi=rs;exports.useUndoRedo=os;exports.useUpdateNodeInternals=Jo;exports.useViewport=Yo;