@infinit-canvas/react 0.1.26 → 0.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("react/jsx-runtime"),a=require("react"),pr=require("react-dom"),mr=160,vr=60;function Xr(e){return e&&typeof e=="object"&&"position"in e&&"data"in e}function Or(e){return e&&typeof e=="object"&&"source"in e&&"target"in e}function br(e,t){const n=typeof e=="string"?new Set([e]):new Set(Array.isArray(e)?e.map(r=>r.id):[e.id]);return t.filter(r=>n.has(r.source)||n.has(r.target))}function Ur(e,t,n){const r=typeof e=="string"?e:e.id,i=new Set;for(const o of n)o.target===r&&i.add(o.source);return t.filter(o=>i.has(o.id))}function qr(e,t,n){const r=typeof e=="string"?e:e.id,i=new Set;for(const o of n)o.source===r&&i.add(o.target);return t.filter(o=>i.has(o.id))}function Mn(e){if(!e.length)return{x:0,y:0,width:0,height:0};let t=1/0,n=1/0,r=-1/0,i=-1/0;for(const o of e){const l=o.position.x,h=o.position.y,v=o.width||mr,f=o.height||vr;l<t&&(t=l),h<n&&(n=h),l+v>r&&(r=l+v),h+f>i&&(i=h+f)}return{x:t,y:n,width:r-t,height:i-n}}function Xt(e,t,n,r=.1){const i=e.width*(1+r*2),o=e.height*(1+r*2),l=Math.min(t/i,n/o,1),h=e.x+e.width/2,v=e.y+e.height/2;return{x:t/2-h*l,y:n/2-v*l,zoom:l}}function Zn(e,t){return{x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}}function Gn(e,t){return{x:Math.min(Math.max(e.x,t[0][0]),t[1][0]),y:Math.min(Math.max(e.y,t[0][1]),t[1][1])}}function Kn(e){var t,n;return{width:e.width||((t=e.measured)==null?void 0:t.width)||mr,height:e.height||((n=e.measured)==null?void 0:n.height)||vr}}function Zr(e,t,n={x:0,y:0,zoom:1},r=!1){const i=t.x,o=t.y,l=t.x+t.width,h=t.y+t.height;return e.filter(v=>{const{width:f,height:y}=Kn(v),x=v.position.x,R=v.position.y,C=x+f,z=R+y;return r?x<l&&C>i&&R<h&&z>o:x>=i&&C<=l&&R>=o&&z<=h})}function Gr(e){return{x:e.x,y:e.y,x2:e.x+e.width,y2:e.y+e.height}}function Qr(e){return{x:e.x,y:e.y,width:e.x2-e.x,height:e.y2-e.y}}function Jr(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}}function Vr(e,t){const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return n*r}function Kr(e){const{width:t,height:n}=Kn(e);return{x:e.position.x,y:e.position.y,width:t,height:n}}const wr=`var qa = null, r = null, fr = 0, vr = 0, M = { x: 0, y: 0, zoom: 1 }, Y = [], W = [], C = [], F = !1, Ze = 40, We = !1, Nr = "lines", da = 1, Kt = null, lt = null, Tr = null, It = {}, tl = {}, it = {}, Zt = {}, Ia = 0, L = 160, B = 60, Ga = 8, Do = 5;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("react/jsx-runtime"),i=require("react"),mr=require("react-dom"),vr=160,br=60;function Ur(e){return e&&typeof e=="object"&&"position"in e&&"data"in e}function Or(e){return e&&typeof e=="object"&&"source"in e&&"target"in e}function wr(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 qr(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 Zr(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 c=o.position.x,h=o.position.y,m=o.width||vr,f=o.height||br;c<t&&(t=c),h<n&&(n=h),c+m>r&&(r=c+m),h+f>a&&(a=h+f)}return{x:t,y:n,width:r-t,height:a-n}}function Ot(e,t,n,r=.1){const a=e.width*(1+r*2),o=e.height*(1+r*2),c=Math.min(t/a,n/o,1),h=e.x+e.width/2,m=e.y+e.height/2;return{x:t/2-h*c,y:n/2-m*c,zoom:c}}function Gn(e,t){return{x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}}function Qn(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 er(e){var t,n;return{width:e.width||((t=e.measured)==null?void 0:t.width)||vr,height:e.height||((n=e.measured)==null?void 0:n.height)||br}}function Gr(e,t,n={x:0,y:0,zoom:1},r=!1){const a=t.x,o=t.y,c=t.x+t.width,h=t.y+t.height;return e.filter(m=>{const{width:f,height:y}=er(m),x=m.position.x,k=m.position.y,S=x+f,z=k+y;return r?x<c&&S>a&&k<h&&z>o:x>=a&&S<=c&&k>=o&&z<=h})}function Qr(e){return{x:e.x,y:e.y,x2:e.x+e.width,y2:e.y+e.height}}function Jr(e){return{x:e.x,y:e.y,width:e.x2-e.x,height:e.y2-e.y}}function Kr(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}}function Vr(e,t){const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return n*r}function eo(e){const{width:t,height:n}=er(e);return{x:e.position.x,y:e.position.y,width:t,height:n}}const Mr=`var Ia = null, r = null, fr = 0, vr = 0, k = { x: 0, y: 0, zoom: 1 }, H = [], W = [], S = [], $ = !1, Ke = 40, Pe = !1, cr = "lines", xa = 1, Jt = null, lt = null, mr = null, Kt = {}, el = {}, it = {}, bt = {}, Ka = 0, C = 160, B = 60, Za = 8, Oo = 5;
2
2
  function y(a) {
3
3
  return a._absolutePosition || a.position;
4
4
  }
5
- function cl(a, t, e, l, i) {
5
+ function Nl(a, t, e, l, i) {
6
6
  if (a.x !== void 0 && a.y !== void 0)
7
7
  return { x: t + a.x, y: e + a.y };
8
8
  var o = a.position || (a.type === "source" ? "right" : "left");
@@ -19,16 +19,16 @@ function cl(a, t, e, l, i) {
19
19
  return { x: t + l, y: e + i / 2 };
20
20
  }
21
21
  }
22
- function el(a) {
23
- var t = a.width || L, e = a.height || B;
22
+ function ol(a) {
23
+ var t = a.width || C, e = a.height || B;
24
24
  if (a.handles && a.handles.length > 0)
25
- return a.handles.map(function(n) {
26
- var g = cl(n, y(a).x, y(a).y, t, e);
27
- return { id: n.id || null, type: n.type, x: g.x, y: g.y, position: n.position };
25
+ return a.handles.map(function(h) {
26
+ var x = Nl(h, y(a).x, y(a).y, t, e);
27
+ return { id: h.id || null, type: h.type, x: x.x, y: x.y, position: h.position };
28
28
  });
29
29
  var l = a.targetPosition || "left", i = a.sourcePosition || "right", o = y(a);
30
- function f(n) {
31
- switch (n) {
30
+ function f(h) {
31
+ switch (h) {
32
32
  case "top":
33
33
  return { x: o.x + t / 2, y: o.y };
34
34
  case "bottom":
@@ -41,69 +41,69 @@ function el(a) {
41
41
  return { x: o.x + t, y: o.y + e / 2 };
42
42
  }
43
43
  }
44
- var h = f(l), x = f(i);
44
+ var n = f(l), g = f(i);
45
45
  return [
46
- { id: null, type: "target", x: h.x, y: h.y, position: l },
47
- { id: null, type: "source", x: x.x, y: x.y, position: i }
46
+ { id: null, type: "target", x: n.x, y: n.y, position: l },
47
+ { id: null, type: "source", x: g.x, y: g.y, position: i }
48
48
  ];
49
49
  }
50
- var Pe = {}, nt = !0;
51
- function Vl(a) {
52
- nt && (Pe = {}, nt = !1);
53
- var t = Pe[a.id];
54
- return t || (t = el(a), Pe[a.id] = t, t);
50
+ var qe = {}, ht = !0;
51
+ function Dl(a) {
52
+ ht && (qe = {}, ht = !1);
53
+ var t = qe[a.id];
54
+ return t || (t = ol(a), qe[a.id] = t, t);
55
55
  }
56
- function bt(a, t, e) {
57
- for (var l = Vl(a), i = 0; i < l.length; i++)
56
+ function Qt(a, t, e) {
57
+ for (var l = Dl(a), i = 0; i < l.length; i++)
58
58
  if (l[i].type === t)
59
59
  if (e) {
60
60
  if (l[i].id === e) return l[i];
61
61
  } else
62
62
  return l[i];
63
- var o = a.width || L, f = a.height || B;
63
+ var o = a.width || C, f = a.height || B;
64
64
  return t === "source" ? { x: y(a).x + o, y: y(a).y + f / 2 } : { x: y(a).x, y: y(a).y + f / 2 };
65
65
  }
66
- var k = {};
67
- function Ke() {
68
- k = {
69
- grid: F ? "rgba(255,255,255,0.07)" : "rgba(0,0,0,0.07)",
70
- origin: F ? "rgba(255,255,255,0.2)" : "rgba(0,0,0,0.15)",
71
- cardBg: F ? "#2a2a28" : "#ffffff",
72
- cardBorder: F ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.1)",
73
- cardShadow: F ? "rgba(0,0,0,0.3)" : "rgba(0,0,0,0.06)",
66
+ var M = {};
67
+ function be() {
68
+ M = {
69
+ grid: $ ? "rgba(255,255,255,0.07)" : "rgba(0,0,0,0.07)",
70
+ origin: $ ? "rgba(255,255,255,0.2)" : "rgba(0,0,0,0.15)",
71
+ cardBg: $ ? "#2a2a28" : "#ffffff",
72
+ cardBorder: $ ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.1)",
73
+ cardShadow: $ ? "rgba(0,0,0,0.3)" : "rgba(0,0,0,0.06)",
74
74
  titleText: "rgba(255,255,255,0.9)",
75
- bodyText: F ? "rgba(255,255,255,0.55)" : "rgba(0,0,0,0.5)",
76
- coordText: F ? "rgba(255,255,255,0.25)" : "rgba(0,0,0,0.2)",
77
- nodeBg: F ? "#1e1e2e" : "#ffffff",
78
- nodeBorder: F ? "rgba(255,255,255,0.15)" : "rgba(0,0,0,0.15)",
75
+ bodyText: $ ? "rgba(255,255,255,0.55)" : "rgba(0,0,0,0.5)",
76
+ coordText: $ ? "rgba(255,255,255,0.25)" : "rgba(0,0,0,0.2)",
77
+ nodeBg: $ ? "#1e1e2e" : "#ffffff",
78
+ nodeBorder: $ ? "rgba(255,255,255,0.15)" : "rgba(0,0,0,0.15)",
79
79
  nodeSelectedBorder: "#3b82f6",
80
- nodeShadow: F ? "rgba(0,0,0,0.4)" : "rgba(0,0,0,0.08)",
81
- nodeText: F ? "rgba(255,255,255,0.9)" : "rgba(0,0,0,0.85)",
82
- edgeStroke: F ? "rgba(255,255,255,0.35)" : "rgba(0,0,0,0.3)",
80
+ nodeShadow: $ ? "rgba(0,0,0,0.4)" : "rgba(0,0,0,0.08)",
81
+ nodeText: $ ? "rgba(255,255,255,0.9)" : "rgba(0,0,0,0.85)",
82
+ edgeStroke: $ ? "rgba(255,255,255,0.35)" : "rgba(0,0,0,0.3)",
83
83
  edgeSelected: "#3b82f6",
84
84
  edgeAnimated: "#3b82f6",
85
85
  handleFill: "#ffffff",
86
86
  handleBorder: "#3b82f6",
87
87
  connectionLine: "#3b82f6"
88
- }, Za = !0;
88
+ }, ba = !0;
89
89
  }
90
- Ke();
91
- var Nl = ["#534AB7", "#0F6E56", "#993C1D", "#185FA5"], ot = 8, Dl = "500 11px system-ui, sans-serif", Ol = "400 11px system-ui, sans-serif", jl = "10px monospace", Oo = "500 13px system-ui, sans-serif", Yl = "400 11px system-ui, sans-serif", Dr = 400, ft = {}, Jt = !0;
92
- function Xl() {
90
+ be();
91
+ var Ol = ["#534AB7", "#0F6E56", "#993C1D", "#185FA5"], ot = 8, jl = "500 11px system-ui, sans-serif", Yl = "400 11px system-ui, sans-serif", Xl = "10px monospace", jo = "500 13px system-ui, sans-serif", Hl = "400 11px system-ui, sans-serif", Vr = 400, ft = {}, $t = !0;
92
+ function pl() {
93
93
  ft = {};
94
- for (var a = 0; a < Y.length; a++)
95
- for (var t = Y[a], e = Math.floor(t.x / Dr), l = Math.floor(t.y / Dr), i = Math.floor((t.x + t.w) / Dr), o = Math.floor((t.y + t.h) / Dr), f = e; f <= i; f++)
96
- for (var h = l; h <= o; h++) {
97
- var x = f + "," + h;
98
- ft[x] || (ft[x] = []), ft[x].push(a);
94
+ for (var a = 0; a < H.length; a++)
95
+ for (var t = H[a], e = Math.floor(t.x / Vr), l = Math.floor(t.y / Vr), i = Math.floor((t.x + t.w) / Vr), o = Math.floor((t.y + t.h) / Vr), f = e; f <= i; f++)
96
+ for (var n = l; n <= o; n++) {
97
+ var g = f + "," + n;
98
+ ft[g] || (ft[g] = []), ft[g].push(a);
99
99
  }
100
- Jt = !1;
100
+ $t = !1;
101
101
  }
102
- function jo(a, t, e, l) {
103
- Jt && Xl();
104
- for (var i = {}, o = [], f = Math.floor(a / Dr), h = Math.floor(t / Dr), x = Math.floor(e / Dr), n = Math.floor(l / Dr), g = f; g <= x; g++)
105
- for (var v = h; v <= n; v++) {
106
- var u = g + "," + v, s = ft[u];
102
+ function Yo(a, t, e, l) {
103
+ $t && pl();
104
+ for (var i = {}, o = [], f = Math.floor(a / Vr), n = Math.floor(t / Vr), g = Math.floor(e / Vr), h = Math.floor(l / Vr), x = f; x <= g; x++)
105
+ for (var v = n; v <= h; v++) {
106
+ var u = x + "," + v, s = ft[u];
107
107
  if (s)
108
108
  for (var d = 0; d < s.length; d++) {
109
109
  var T = s[d];
@@ -112,25 +112,25 @@ function jo(a, t, e, l) {
112
112
  }
113
113
  return o;
114
114
  }
115
- var Or = 500, vt = {}, jr = !0;
116
- function $e() {
115
+ var Nr = 500, vt = {}, Dr = !0;
116
+ function Fe() {
117
117
  vt = {};
118
118
  for (var a = 0; a < W.length; a++) {
119
119
  var t = W[a];
120
120
  if (!t.hidden)
121
- for (var e = y(t), l = t.width || L, i = t.height || B, o = Math.floor(e.x / Or), f = Math.floor(e.y / Or), h = Math.floor((e.x + l) / Or), x = Math.floor((e.y + i) / Or), n = o; n <= h; n++)
122
- for (var g = f; g <= x; g++) {
123
- var v = n + "," + g;
121
+ for (var e = y(t), l = t.width || C, i = t.height || B, o = Math.floor(e.x / Nr), f = Math.floor(e.y / Nr), n = Math.floor((e.x + l) / Nr), g = Math.floor((e.y + i) / Nr), h = o; h <= n; h++)
122
+ for (var x = f; x <= g; x++) {
123
+ var v = h + "," + x;
124
124
  vt[v] || (vt[v] = []), vt[v].push(a);
125
125
  }
126
126
  }
127
- jr = !1;
127
+ Dr = !1;
128
128
  }
129
- function ol(a, t, e, l) {
130
- jr && $e();
131
- for (var i = {}, o = [], f = Math.floor(a / Or), h = Math.floor(t / Or), x = Math.floor(e / Or), n = Math.floor(l / Or), g = f; g <= x; g++)
132
- for (var v = h; v <= n; v++) {
133
- var u = g + "," + v, s = vt[u];
129
+ function ll(a, t, e, l) {
130
+ Dr && Fe();
131
+ for (var i = {}, o = [], f = Math.floor(a / Nr), n = Math.floor(t / Nr), g = Math.floor(e / Nr), h = Math.floor(l / Nr), x = f; x <= g; x++)
132
+ for (var v = n; v <= h; v++) {
133
+ var u = x + "," + v, s = vt[u];
134
134
  if (s)
135
135
  for (var d = 0; d < s.length; d++) {
136
136
  var T = s[d];
@@ -139,47 +139,47 @@ function ol(a, t, e, l) {
139
139
  }
140
140
  return o;
141
141
  }
142
- var ya = {}, sa = !0;
143
- function Qt() {
144
- ya = {};
142
+ var Ma = {}, ga = !0;
143
+ function Ft() {
144
+ Ma = {};
145
145
  for (var a = 0; a < W.length; a++)
146
- ya[W[a].id] = W[a];
147
- sa = !1;
146
+ Ma[W[a].id] = W[a];
147
+ ga = !1;
148
148
  }
149
- function Yo(a) {
150
- return sa && Qt(), ya[a];
149
+ function Xo(a) {
150
+ return ga && Ft(), Ma[a];
151
151
  }
152
- var Er = {}, $t = !0;
153
- function Hl() {
154
- Er = {};
155
- for (var a = 0; a < C.length; a++) {
156
- var t = C[a];
157
- Er[t.source] || (Er[t.source] = []), Er[t.source].push(a), t.source !== t.target && (Er[t.target] || (Er[t.target] = []), Er[t.target].push(a));
152
+ var _r = {}, Ut = !0;
153
+ function ri() {
154
+ _r = {};
155
+ for (var a = 0; a < S.length; a++) {
156
+ var t = S[a];
157
+ _r[t.source] || (_r[t.source] = []), _r[t.source].push(a), t.source !== t.target && (_r[t.target] || (_r[t.target] = []), _r[t.target].push(a));
158
158
  }
159
- $t = !1;
159
+ Ut = !1;
160
160
  }
161
- var ua = null, ll = 0, il = 0, fl = "", Za = !0;
162
- function pl(a) {
163
- ua || (ua = new OffscreenCanvas(1, 1));
161
+ var ya = null, il = 0, fl = 0, vl = "", ba = !0;
162
+ function ai(a) {
163
+ ya || (ya = new OffscreenCanvas(1, 1));
164
164
  var t = Math.ceil(a), e = Math.ceil(a);
165
165
  if (t < 2 || e < 2) return !1;
166
- t > 512 && (t = 512), e > 512 && (e = 512), ua.width = t, ua.height = e, ll = t, il = a, fl = Nr, Za = !1;
167
- var l = ua.getContext("2d");
166
+ t > 512 && (t = 512), e > 512 && (e = 512), ya.width = t, ya.height = e, il = t, fl = a, vl = cr, ba = !1;
167
+ var l = ya.getContext("2d");
168
168
  l.clearRect(0, 0, t, e);
169
- var i = Kt || k.grid;
170
- if (Nr === "dots") {
169
+ var i = Jt || M.grid;
170
+ if (cr === "dots") {
171
171
  l.fillStyle = i;
172
- var o = da * M.zoom;
172
+ var o = xa * k.zoom;
173
173
  l.beginPath(), l.arc(0, 0, o, 0, 6.2832), l.fill();
174
- } else if (Nr === "cross") {
175
- l.strokeStyle = i, l.lineWidth = da;
176
- var f = 3 * M.zoom;
174
+ } else if (cr === "cross") {
175
+ l.strokeStyle = i, l.lineWidth = xa;
176
+ var f = 3 * k.zoom;
177
177
  l.beginPath(), l.moveTo(-f, 0), l.lineTo(f, 0), l.moveTo(0, -f), l.lineTo(0, f), l.stroke();
178
178
  } else
179
- l.beginPath(), l.strokeStyle = i, l.lineWidth = da * 0.5, l.moveTo(0.5, 0), l.lineTo(0.5, e), l.moveTo(0, 0.5), l.lineTo(t, 0.5), l.stroke();
179
+ l.beginPath(), l.strokeStyle = i, l.lineWidth = xa * 0.5, l.moveTo(0.5, 0), l.lineTo(0.5, e), l.moveTo(0, 0.5), l.lineTo(t, 0.5), l.stroke();
180
180
  return !0;
181
181
  }
182
- var Xo = 0, qe = 0, Ho = 0, po = 0, be = 0, ht = !1;
182
+ var Ho = 0, Ge = 0, po = 0, rl = 0, Je = 0, nt = !1;
183
183
  console.log("[worker] script loaded v2 - FRESH");
184
184
  self.postMessage({ type: "ping", data: { status: "alive" } });
185
185
  self.onmessage = function(a) {
@@ -187,128 +187,128 @@ self.onmessage = function(a) {
187
187
  var t = a.data.type, e = a.data.data;
188
188
  switch (t) {
189
189
  case "init":
190
- qa = e.canvas, r = qa.getContext("2d"), fr = e.width, vr = e.height, qa.width = fr, qa.height = vr, M = e.camera, Y = e.cards || [], W = e.nodes || [], C = e.edges || [], F = e.dark, e.gridSize && (Ze = e.gridSize), e.edgeRouting !== void 0 && (Vr = !!e.edgeRouting), Ke(), Jt = !0, sa = !0, jr = !0, nt = !0, $t = !0, ht = C.some(function(X) {
191
- return X.animated;
192
- }), console.log("[worker] init done — canvas:", fr, "x", vr, "| cards:", Y.length, "| nodes:", W.length, "| edges:", C.length, "| routing:", Vr), Ft(), self.postMessage({ type: "ready" }), ht && rl();
190
+ Ia = e.canvas, r = Ia.getContext("2d"), fr = e.width, vr = e.height, Ia.width = fr, Ia.height = vr, k = e.camera, H = e.cards || [], W = e.nodes || [], S = e.edges || [], $ = e.dark, e.gridSize && (Ke = e.gridSize), e.edgeRouting !== void 0 && (Ur = !!e.edgeRouting), be(), $t = !0, ga = !0, Dr = !0, ht = !0, Ut = !0, nt = S.some(function(nr) {
191
+ return nr.animated;
192
+ }), console.log("[worker] init done — canvas:", fr, "x", vr, "| cards:", H.length, "| nodes:", W.length, "| edges:", S.length, "| routing:", Ur), ct(), self.postMessage({ type: "ready" }), nt && al();
193
193
  break;
194
194
  case "resize":
195
- fr = e.width, vr = e.height, qa.width = fr, qa.height = vr, Za = !0, Ft();
195
+ fr = e.width, vr = e.height, Ia.width = fr, Ia.height = vr, ba = !0, ct();
196
196
  break;
197
197
  case "camera":
198
- M = e.camera, Za = !0, $();
198
+ k = e.camera, ba = !0, Q();
199
199
  break;
200
200
  case "cards":
201
- Y = e.cards, Jt = !0, $();
201
+ H = e.cards, $t = !0, Q();
202
202
  break;
203
203
  case "nodes":
204
- W = e.nodes, Ia = 0;
204
+ W = e.nodes, Ka = 0;
205
205
  for (var l = 0; l < W.length; l++)
206
- W[l].dragging && Ia++;
207
- sa = !0, jr = !0, nt = !0, $(), Gt(), self.postMessage({ type: "nodesProcessed", data: { nodeCount: W.length } });
206
+ W[l].dragging && Ka++;
207
+ ga = !0, Dr = !0, ht = !0, Q(), Zt(), self.postMessage({ type: "nodesProcessed", data: { nodeCount: W.length } });
208
208
  break;
209
209
  case "nodePositions":
210
- sa && Qt();
210
+ ga && Ft();
211
211
  for (var i = e.updates, o = 0, f = 0; f < i.length; f++) {
212
- var h = i[f], x = ya[h.id];
213
- x && (x.position = h.position, h._absolutePosition && (x._absolutePosition = h._absolutePosition), h.width !== void 0 && (x.width = h.width), h.height !== void 0 && (x.height = h.height), h.dragging && !x.dragging ? o++ : !h.dragging && x.dragging && o--, x.dragging = h.dragging, x.selected = h.selected);
214
- }
215
- if (Ia = Math.max(0, Ia + o), nt = !0, Vr)
216
- for (var n = 0; n < i.length; n++)
217
- for (var g = i[n].id, v = 0; v < C.length; v++)
218
- (C[v].source === g || C[v].target === g) && (C[v]._routedPoints = null);
219
- i.length > 10 && (jr = !0), Vr && Ia === 0 && o < 0 && (jr = !0, Gt()), $();
212
+ var n = i[f], g = Ma[n.id];
213
+ g && (g.position = n.position, n._absolutePosition && (g._absolutePosition = n._absolutePosition), n.width !== void 0 && (g.width = n.width), n.height !== void 0 && (g.height = n.height), n.dragging && !g.dragging ? o++ : !n.dragging && g.dragging && o--, g.dragging = n.dragging, g.selected = n.selected);
214
+ }
215
+ if (Ka = Math.max(0, Ka + o), ht = !0, Ur)
216
+ for (var h = 0; h < i.length; h++)
217
+ for (var x = i[h].id, v = 0; v < S.length; v++)
218
+ (S[v].source === x || S[v].target === x) && (S[v]._routedPoints = null);
219
+ i.length > 10 && (Dr = !0), Ur && Ka === 0 && o < 0 && (Dr = !0, Zt()), Q();
220
220
  break;
221
221
  case "nodeSelections":
222
- sa && Qt();
222
+ ga && Ft();
223
223
  for (var u = e.selections, s = 0; s < u.length; s++) {
224
- var d = u[s], T = ya[d.id];
224
+ var d = u[s], T = Ma[d.id];
225
225
  T && (T.selected = d.selected);
226
226
  }
227
- $();
227
+ Q();
228
228
  break;
229
229
  case "edgeSelections":
230
230
  for (var Z = e.selections, _ = 0; _ < Z.length; _++) {
231
- for (var K = Z[_], ar = null, tr = 0; tr < C.length; tr++)
232
- if (C[tr].id === K.id) {
233
- ar = C[tr];
231
+ for (var K = Z[_], rr = null, ar = 0; ar < S.length; ar++)
232
+ if (S[ar].id === K.id) {
233
+ rr = S[ar];
234
234
  break;
235
235
  }
236
- ar && (ar.selected = K.selected);
236
+ rr && (rr.selected = K.selected);
237
237
  }
238
- $();
238
+ Q();
239
239
  break;
240
240
  case "edges":
241
- C = e.edges, $t = !0, ht = C.some(function(X) {
242
- return X.animated;
243
- }), ht && rl(), $(), Gt();
241
+ S = e.edges, Ut = !0, nt = S.some(function(nr) {
242
+ return nr.animated;
243
+ }), nt && al(), Q(), Zt();
244
244
  break;
245
245
  case "theme":
246
- F = e.dark, Ke(), $();
246
+ $ = e.dark, be(), Q();
247
247
  break;
248
248
  case "connecting":
249
- lt = e, $();
249
+ lt = e, Q();
250
250
  break;
251
251
  case "selectionBox":
252
- Tr = e, $();
252
+ mr = e, Q();
253
253
  break;
254
254
  case "background":
255
- e.variant && (Nr = e.variant), e.gap && (Ze = e.gap), e.size && (da = e.size), Kt = e.color || null, Za = !0, $();
255
+ e.variant && (cr = e.variant), e.gap && (Ke = e.gap), e.size && (xa = e.size), Jt = e.color || null, ba = !0, Q();
256
256
  break;
257
257
  case "nodeTypeBitmaps":
258
- It = e.bitmaps || {}, $();
258
+ Kt = e.bitmaps || {}, Q();
259
259
  break;
260
260
  case "nodeBitmaps":
261
- tl = e.cache || {}, it = e.keys || {}, $();
261
+ el = e.cache || {}, it = e.keys || {}, Q();
262
262
  break;
263
263
  case "nodeTypeConfigs":
264
- Zt = e.configs || {}, $();
264
+ bt = e.configs || {}, Q();
265
265
  break;
266
266
  case "edgeRouting":
267
- if (Vr = !!e.enabled, Vr)
268
- Gt();
267
+ if (Ur = !!e.enabled, Ur)
268
+ Zt();
269
269
  else {
270
- for (var hr = 0; hr < C.length; hr++)
271
- C[hr]._routedPoints = null;
272
- $();
270
+ for (var Tr = 0; Tr < S.length; Tr++)
271
+ S[Tr]._routedPoints = null;
272
+ Q();
273
273
  }
274
274
  break;
275
275
  }
276
- } catch (X) {
277
- console.error("[worker] error:", X);
276
+ } catch (nr) {
277
+ console.error("[worker] error:", nr);
278
278
  }
279
279
  };
280
- function $() {
281
- We || (We = !0, requestAnimationFrame(function() {
282
- We = !1, Ft();
280
+ function Q() {
281
+ Pe || (Pe = !0, requestAnimationFrame(function() {
282
+ Pe = !1, ct();
283
283
  }));
284
284
  }
285
- var Ge = !1;
286
- function rl() {
287
- if (Ge) return;
288
- Ge = !0;
285
+ var Ie = !1;
286
+ function al() {
287
+ if (Ie) return;
288
+ Ie = !0;
289
289
  function a() {
290
- if (!ht) {
291
- Ge = !1;
290
+ if (!nt) {
291
+ Ie = !1;
292
292
  return;
293
293
  }
294
- be = (be + 0.5) % 20, Ft(), requestAnimationFrame(a);
294
+ Je = (Je + 0.5) % 20, ct(), requestAnimationFrame(a);
295
295
  }
296
296
  requestAnimationFrame(a);
297
297
  }
298
- function al(a, t) {
298
+ function tl(a, t) {
299
299
  var e = 6;
300
300
  a.moveTo(t[0].x, t[0].y);
301
301
  for (var l = 1; l < t.length - 1; l++) {
302
- var i = t[l - 1], o = t[l], f = t[l + 1], h = Math.abs(o.x - i.x) + Math.abs(o.y - i.y), x = Math.abs(f.x - o.x) + Math.abs(f.y - o.y), n = Math.min(e, h / 2, x / 2);
303
- if (n > 0.5) {
304
- var g = o.x - i.x, v = o.y - i.y, u = f.x - o.x, s = f.y - o.y, d = Math.sqrt(g * g + v * v) || 1, T = Math.sqrt(u * u + s * s) || 1;
305
- a.lineTo(o.x - g / d * n, o.y - v / d * n), a.quadraticCurveTo(o.x, o.y, o.x + u / T * n, o.y + s / T * n);
302
+ var i = t[l - 1], o = t[l], f = t[l + 1], n = Math.abs(o.x - i.x) + Math.abs(o.y - i.y), g = Math.abs(f.x - o.x) + Math.abs(f.y - o.y), h = Math.min(e, n / 2, g / 2);
303
+ if (h > 0.5) {
304
+ var x = o.x - i.x, v = o.y - i.y, u = f.x - o.x, s = f.y - o.y, d = Math.sqrt(x * x + v * v) || 1, T = Math.sqrt(u * u + s * s) || 1;
305
+ a.lineTo(o.x - x / d * h, o.y - v / d * h), a.quadraticCurveTo(o.x, o.y, o.x + u / T * h, o.y + s / T * h);
306
306
  } else
307
307
  a.lineTo(o.x, o.y);
308
308
  }
309
309
  a.lineTo(t[t.length - 1].x, t[t.length - 1].y);
310
310
  }
311
- function ri(a) {
311
+ function ti(a) {
312
312
  for (var t = 0, e = 1; e < a.length; e++)
313
313
  t += Math.abs(a[e].x - a[e - 1].x) + Math.abs(a[e].y - a[e - 1].y);
314
314
  for (var l = t / 2, i = 1; i < a.length; i++) {
@@ -324,166 +324,166 @@ function ri(a) {
324
324
  }
325
325
  return { x: a[0].x, y: a[0].y };
326
326
  }
327
- function Je(a, t, e, l) {
328
- var i = Math.abs(e - a), o = Math.max(50, i * 0.5), f = a + o, h = t, x = e - o, n = l;
329
- return { cp1x: f, cp1y: h, cp2x: x, cp2y: n };
327
+ function Qe(a, t, e, l) {
328
+ var i = Math.abs(e - a), o = Math.max(50, i * 0.5), f = a + o, n = t, g = e - o, h = l;
329
+ return { cp1x: f, cp1y: n, cp2x: g, cp2y: h };
330
330
  }
331
- function ai(a, t, e, l) {
332
- var i = Je(a, t, e, l), o = 0.5, f = 1 - o, h = f * f * f * a + 3 * f * f * o * i.cp1x + 3 * f * o * o * i.cp2x + o * o * o * e, x = f * f * f * t + 3 * f * f * o * i.cp1y + 3 * f * o * o * i.cp2y + o * o * o * l;
333
- return { x: h, y: x };
331
+ function ei(a, t, e, l) {
332
+ var i = Qe(a, t, e, l), o = 0.5, f = 1 - o, n = f * f * f * a + 3 * f * f * o * i.cp1x + 3 * f * o * o * i.cp2x + o * o * o * e, g = f * f * f * t + 3 * f * f * o * i.cp1y + 3 * f * o * o * i.cp2y + o * o * o * l;
333
+ return { x: n, y: g };
334
334
  }
335
- var Vr = !0, Qe = !1, Ie = !1;
336
- function vl(a, t, e, l, i) {
337
- jr && $e();
338
- for (var o = Math.min(a, e) - 20, f = Math.min(t, l) - 20, h = Math.max(a, e) + 20, x = Math.max(t, l) + 20, n = ol(o, f, h, x), g = [], v = 0; v < n.length; v++) {
339
- var u = W[n[v]];
340
- u.hidden || i[u.id] || u.type !== "group" && g.push(u);
335
+ var Ur = !0, $e = !1, Ze = !1;
336
+ function nl(a, t, e, l, i) {
337
+ Dr && Fe();
338
+ for (var o = Math.min(a, e) - 20, f = Math.min(t, l) - 20, n = Math.max(a, e) + 20, g = Math.max(t, l) + 20, h = ll(o, f, n, g), x = [], v = 0; v < h.length; v++) {
339
+ var u = W[h[v]];
340
+ u.hidden || i[u.id] || u.type !== "group" && x.push(u);
341
341
  }
342
- return g;
342
+ return x;
343
343
  }
344
- function Lr(a, t, e, l) {
344
+ function Er(a, t, e, l) {
345
345
  for (var i = Math.min(a, t), o = Math.max(a, t), f = 0; f < l.length; f++) {
346
- var h = l[f], x = y(h), n = h.width || L, g = h.height || B;
347
- if (e > x.y && e < x.y + g && o > x.x && i < x.x + n) return h;
346
+ var n = l[f], g = y(n), h = n.width || C, x = n.height || B;
347
+ if (e > g.y && e < g.y + x && o > g.x && i < g.x + h) return n;
348
348
  }
349
349
  return null;
350
350
  }
351
- function Sr(a, t, e, l) {
351
+ function Cr(a, t, e, l) {
352
352
  for (var i = Math.min(t, e), o = Math.max(t, e), f = 0; f < l.length; f++) {
353
- var h = l[f], x = y(h), n = h.width || L, g = h.height || B;
354
- if (a > x.x && a < x.x + n && o > x.y && i < x.y + g) return h;
353
+ var n = l[f], g = y(n), h = n.width || C, x = n.height || B;
354
+ if (a > g.x && a < g.x + h && o > g.y && i < g.y + x) return n;
355
355
  }
356
356
  return null;
357
357
  }
358
- function ti() {
359
- if (Vr && !(!Qe || C.length === 0 || W.length === 0)) {
360
- Qe = !1, sa && Qt(), jr && $e();
361
- for (var a = 20, t = !1, e = 0; e < C.length; e++) {
362
- var l = C[e];
358
+ function oi() {
359
+ if (Ur && !(!$e || S.length === 0 || W.length === 0)) {
360
+ $e = !1, ga && Ft(), Dr && Fe();
361
+ for (var a = 20, t = !1, e = 0; e < S.length; e++) {
362
+ var l = S[e];
363
363
  if (!l._customRendered) {
364
364
  var i = l.type || "default";
365
365
  if (!(i === "bezier" || i === "simplebezier" || i === "default")) {
366
- var o = ya[l.source], f = ya[l.target];
366
+ var o = Ma[l.source], f = Ma[l.target];
367
367
  if (!(!o || !f || o.hidden || f.hidden)) {
368
- var h = bt(o, "source", l.sourceHandle), x = bt(f, "target", l.targetHandle), n = h.position || "right", g = x.position || "left", v = h.x, u = h.y, s = x.x, d = x.y, T = v, Z = u, _ = s, K = d;
369
- n === "right" ? T += a : n === "left" ? T -= a : n === "bottom" ? Z += a : n === "top" && (Z -= a), g === "right" ? _ += a : g === "left" ? _ -= a : g === "bottom" ? K += a : g === "top" && (K -= a);
370
- var ar = y(o), tr = y(f), hr = o.width || L, X = o.height || B, Yr = f.width || L, xa = f.height || B, Xr = {};
371
- Xr[l.source] = !0, Xr[l.target] = !0;
372
- var H = vl(
373
- Math.min(v, s) - hr,
374
- Math.min(u, d) - X,
375
- Math.max(v, s) + Yr,
376
- Math.max(u, d) + xa,
377
- Xr
368
+ var n = Qt(o, "source", l.sourceHandle), g = Qt(f, "target", l.targetHandle), h = n.position || "right", x = g.position || "left", v = n.x, u = n.y, s = g.x, d = g.y, T = v, Z = u, _ = s, K = d;
369
+ h === "right" ? T += a : h === "left" ? T -= a : h === "bottom" ? Z += a : h === "top" && (Z -= a), x === "right" ? _ += a : x === "left" ? _ -= a : x === "bottom" ? K += a : x === "top" && (K -= a);
370
+ var rr = y(o), ar = y(f), Tr = o.width || C, nr = o.height || B, Or = f.width || C, jr = f.height || B, Lr = {};
371
+ Lr[l.source] = !0, Lr[l.target] = !0;
372
+ var D = nl(
373
+ Math.min(v, s) - Tr,
374
+ Math.min(u, d) - nr,
375
+ Math.max(v, s) + Or,
376
+ Math.max(u, d) + jr,
377
+ Lr
378
378
  );
379
- H.push(o), H.push(f);
380
- var ga = n === "left" || n === "right", Ka = g === "left" || g === "right", q = null;
381
- if (ga && Ka) {
382
- var P, sr = n === "right" && T < _, Ut = n === "left" && T > _;
383
- if (sr || Ut) {
384
- P = (T + _) / 2;
385
- var ba = Sr(P, u, d, H);
386
- if (ba) {
387
- var Ma = y(ba), ka = ba.width || L;
388
- P = P < Ma.x + ka / 2 ? Ma.x - a : Ma.x + ka + a;
379
+ D.push(o), D.push(f);
380
+ var Yr = h === "left" || h === "right", Ja = x === "left" || x === "right", P = null;
381
+ if (Yr && Ja) {
382
+ var O, ut = h === "right" && T < _, sr = h === "left" && T > _;
383
+ if (ut || sr) {
384
+ O = (T + _) / 2;
385
+ var tr = Cr(O, u, d, D);
386
+ if (tr) {
387
+ var Qa = y(tr), st = tr.width || C;
388
+ O = O < Qa.x + st / 2 ? Qa.x - a : Qa.x + st + a;
389
389
  }
390
390
  } else
391
- n === "right" ? P = Math.max(ar.x + hr, tr.x + Yr) + a : P = Math.min(ar.x, tr.x) - a;
392
- q = [{ x: v, y: u }, { x: T, y: u }, { x: P, y: u }, { x: P, y: d }, { x: _, y: d }, { x: s, y: d }];
393
- var Cr = Lr(P, _, d, H);
394
- if (Cr) {
395
- var ma = y(Cr), Ta = Cr.height || B, Ra = ma.y - a, Hr = ma.y + Ta + a, pr = Math.abs(u - Ra) <= Math.abs(u - Hr) ? Ra : Hr;
396
- q = [{ x: v, y: u }, { x: T, y: u }, { x: P, y: u }, { x: P, y: pr }, { x: _, y: pr }, { x: _, y: d }, { x: s, y: d }];
391
+ h === "right" ? O = Math.max(rr.x + Tr, ar.x + Or) + a : O = Math.min(rr.x, ar.x) - a;
392
+ P = [{ x: v, y: u }, { x: T, y: u }, { x: O, y: u }, { x: O, y: d }, { x: _, y: d }, { x: s, y: d }];
393
+ var ka = Er(O, _, d, D);
394
+ if (ka) {
395
+ var ma = y(ka), Ta = ka.height || B, Ra = ma.y - a, Xr = ma.y + Ta + a, za = Math.abs(u - Ra) <= Math.abs(u - Xr) ? Ra : Xr;
396
+ P = [{ x: v, y: u }, { x: T, y: u }, { x: O, y: u }, { x: O, y: za }, { x: _, y: za }, { x: _, y: d }, { x: s, y: d }];
397
397
  }
398
- } else if (!ga && !Ka) {
399
- var b, ut = n === "bottom" && Z < K, Ja = n === "top" && Z > K;
400
- if (ut || Ja) {
401
- b = (Z + K) / 2;
402
- var Wr = Lr(v, s, b, H);
403
- if (Wr) {
404
- var Pr = y(Wr), za = Wr.height || B;
405
- b = b < Pr.y + za / 2 ? Pr.y - a : Pr.y + za + a;
398
+ } else if (!Yr && !Ja) {
399
+ var G, wa = h === "bottom" && Z < K, $a = h === "top" && Z > K;
400
+ if (wa || $a) {
401
+ G = (Z + K) / 2;
402
+ var Ba = Er(v, s, G, D);
403
+ if (Ba) {
404
+ var Hr = y(Ba), pr = Ba.height || B;
405
+ G = G < Hr.y + pr / 2 ? Hr.y - a : Hr.y + pr + a;
406
406
  }
407
407
  } else
408
- n === "bottom" ? b = Math.max(ar.y + X, tr.y + xa) + a : b = Math.min(ar.y, tr.y) - a;
409
- q = [{ x: v, y: u }, { x: v, y: Z }, { x: v, y: b }, { x: s, y: b }, { x: s, y: K }, { x: s, y: d }];
410
- var ra = Sr(s, b, K, H);
411
- if (ra) {
412
- var wa = y(ra), Qa = ra.height || B, Ba = wa.y - a, Aa = wa.y + Qa + a, _a = Math.abs(b - Ba) <= Math.abs(b - Aa) ? Ba : Aa;
413
- q = [{ x: v, y: u }, { x: v, y: Z }, { x: v, y: b }, { x: s, y: b }, { x: s, y: _a }, { x: _, y: _a }, { x: _, y: d }, { x: s, y: d }];
408
+ h === "bottom" ? G = Math.max(rr.y + nr, ar.y + jr) + a : G = Math.min(rr.y, ar.y) - a;
409
+ P = [{ x: v, y: u }, { x: v, y: Z }, { x: v, y: G }, { x: s, y: G }, { x: s, y: K }, { x: s, y: d }];
410
+ var Sr = Cr(s, G, K, D);
411
+ if (Sr) {
412
+ var Aa = y(Sr), Fa = Sr.height || B, _a = Aa.y - a, Ea = Aa.y + Fa + a, Ca = Math.abs(G - _a) <= Math.abs(G - Ea) ? _a : Ea;
413
+ P = [{ x: v, y: u }, { x: v, y: Z }, { x: v, y: G }, { x: s, y: G }, { x: s, y: Ca }, { x: _, y: Ca }, { x: _, y: d }, { x: s, y: d }];
414
414
  }
415
- } else if (ga) {
416
- q = [{ x: v, y: u }, { x: T, y: u }, { x: s, y: u }, { x: s, y: K }, { x: s, y: d }];
417
- var qr = Sr(s, u, K, H);
418
- if (qr) {
419
- var nr = y(qr), Rr = qr.width || L, $a = Math.abs(v - nr.x + a) <= Math.abs(v - nr.x - Rr - a) ? nr.x - a : nr.x + Rr + a;
420
- q = [{ x: v, y: u }, { x: T, y: u }, { x: $a, y: u }, { x: $a, y: d }, { x: s, y: d }, { x: s, y: K }, { x: s, y: d }];
415
+ } else if (Yr) {
416
+ P = [{ x: v, y: u }, { x: T, y: u }, { x: s, y: u }, { x: s, y: K }, { x: s, y: d }];
417
+ var ra = Cr(s, u, K, D);
418
+ if (ra) {
419
+ var Wr = y(ra), aa = ra.width || C, Rr = Math.abs(v - Wr.x + a) <= Math.abs(v - Wr.x - aa - a) ? Wr.x - a : Wr.x + aa + a;
420
+ P = [{ x: v, y: u }, { x: T, y: u }, { x: Rr, y: u }, { x: Rr, y: d }, { x: s, y: d }, { x: s, y: K }, { x: s, y: d }];
421
421
  }
422
- var aa = Lr(T, s, u, H);
423
- if (aa) {
424
- var Gr = y(aa), Ea = aa.height || B, p = Math.abs(d - Gr.y + a) <= Math.abs(d - Gr.y - Ea - a) ? Gr.y - a : Gr.y + Ea + a;
425
- q = [{ x: v, y: u }, { x: T, y: u }, { x: T, y: p }, { x: s, y: p }, { x: s, y: K }, { x: s, y: d }];
422
+ var dr = Er(T, s, u, D);
423
+ if (dr) {
424
+ var ta = y(dr), La = dr.height || B, Sa = Math.abs(d - ta.y + a) <= Math.abs(d - ta.y - La - a) ? ta.y - a : ta.y + La + a;
425
+ P = [{ x: v, y: u }, { x: T, y: u }, { x: T, y: Sa }, { x: s, y: Sa }, { x: s, y: K }, { x: s, y: d }];
426
426
  }
427
427
  } else {
428
- q = [{ x: v, y: u }, { x: v, y: Z }, { x: v, y: d }, { x: _, y: d }, { x: s, y: d }];
429
- var Ir = Lr(v, _, d, H);
430
- if (Ir) {
431
- var La = y(Ir), dr = Ir.height || B, Zr = Math.abs(u - La.y + a) <= Math.abs(u - La.y - dr - a) ? La.y - a : La.y + dr + a;
432
- q = [{ x: v, y: u }, { x: v, y: Z }, { x: v, y: Zr }, { x: _, y: Zr }, { x: _, y: d }, { x: s, y: d }];
428
+ P = [{ x: v, y: u }, { x: v, y: Z }, { x: v, y: d }, { x: _, y: d }, { x: s, y: d }];
429
+ var ea = Er(v, _, d, D);
430
+ if (ea) {
431
+ var F = y(ea), oa = ea.height || B, dt = Math.abs(u - F.y + a) <= Math.abs(u - F.y - oa - a) ? F.y - a : F.y + oa + a;
432
+ P = [{ x: v, y: u }, { x: v, y: Z }, { x: v, y: dt }, { x: _, y: dt }, { x: _, y: d }, { x: s, y: d }];
433
433
  }
434
- var zr = Sr(v, Z, d, H);
435
- if (zr) {
436
- var yr = y(zr), Fa = zr.width || L, Ua = Math.abs(s - yr.x + a) <= Math.abs(s - yr.x - Fa - a) ? yr.x - a : yr.x + Fa + a;
437
- q = [{ x: v, y: u }, { x: v, y: Z }, { x: Ua, y: Z }, { x: Ua, y: d }, { x: _, y: d }, { x: s, y: d }];
434
+ var hr = Cr(v, Z, d, D);
435
+ if (hr) {
436
+ var yr = y(hr), Pr = hr.width || C, qr = Math.abs(s - yr.x + a) <= Math.abs(s - yr.x - Pr - a) ? yr.x - a : yr.x + Pr + a;
437
+ P = [{ x: v, y: u }, { x: v, y: Z }, { x: qr, y: Z }, { x: qr, y: d }, { x: _, y: d }, { x: s, y: d }];
438
438
  }
439
439
  }
440
- if (q) {
441
- for (var ta = [q[0]], xr = 1; xr < q.length; xr++) {
442
- var st = ta[ta.length - 1];
443
- (Math.abs(q[xr].x - st.x) > 0.1 || Math.abs(q[xr].y - st.y) > 0.1) && ta.push(q[xr]);
440
+ if (P) {
441
+ for (var la = [P[0]], Gr = 1; Gr < P.length; Gr++) {
442
+ var Ua = la[la.length - 1];
443
+ (Math.abs(P[Gr].x - Ua.x) > 0.1 || Math.abs(P[Gr].y - Ua.y) > 0.1) && la.push(P[Gr]);
444
444
  }
445
- l._routedPoints = ta, t = !0;
445
+ l._routedPoints = la, t = !0;
446
446
  }
447
447
  }
448
448
  }
449
449
  }
450
450
  }
451
- t && $();
451
+ t && Q();
452
452
  }
453
453
  }
454
- function Gt() {
455
- Vr && (Ie || (Ie = !0, Qe = !0, requestAnimationFrame(function() {
456
- Ie = !1;
454
+ function Zt() {
455
+ Ur && (Ze || (Ze = !0, $e = !0, requestAnimationFrame(function() {
456
+ Ze = !1;
457
457
  try {
458
- ti();
458
+ oi();
459
459
  } catch (a) {
460
460
  console.error("[worker] async routing error:", a);
461
461
  }
462
462
  })));
463
463
  }
464
- function Ft() {
464
+ function ct() {
465
465
  if (r) {
466
466
  var a = performance.now();
467
467
  r.clearRect(0, 0, fr, vr);
468
- var t = Ze * M.zoom;
468
+ var t = Ke * k.zoom;
469
469
  if (t > 2)
470
- if (Nr === "lines" && t >= 4 && t <= 512) {
471
- if ((Za || il !== t || fl !== Nr) && pl(t), ua && ll > 0) {
472
- var e = (M.x % t + t) % t, l = (M.y % t + t) % t;
470
+ if (cr === "lines" && t >= 4 && t <= 512) {
471
+ if ((ba || fl !== t || vl !== cr) && ai(t), ya && il > 0) {
472
+ var e = (k.x % t + t) % t, l = (k.y % t + t) % t;
473
473
  r.save(), r.translate(e, l);
474
- var i = r.createPattern(ua, "repeat");
474
+ var i = r.createPattern(ya, "repeat");
475
475
  i && (r.fillStyle = i, r.fillRect(-e, -l, fr, vr)), r.restore();
476
476
  }
477
477
  } else {
478
- var o = (M.x % t + t) % t, f = (M.y % t + t) % t, h = Kt || k.grid;
479
- if (Nr === "dots") {
480
- r.fillStyle = h;
481
- for (var x = da * M.zoom, n = o; n < fr; n += t)
482
- for (var g = f; g < vr; g += t)
483
- r.beginPath(), r.arc(Math.round(n), Math.round(g), x, 0, 6.2832), r.fill();
484
- } else if (Nr === "cross") {
485
- r.strokeStyle = h, r.lineWidth = da;
486
- var v = 3 * M.zoom;
478
+ var o = (k.x % t + t) % t, f = (k.y % t + t) % t, n = Jt || M.grid;
479
+ if (cr === "dots") {
480
+ r.fillStyle = n;
481
+ for (var g = xa * k.zoom, h = o; h < fr; h += t)
482
+ for (var x = f; x < vr; x += t)
483
+ r.beginPath(), r.arc(Math.round(h), Math.round(x), g, 0, 6.2832), r.fill();
484
+ } else if (cr === "cross") {
485
+ r.strokeStyle = n, r.lineWidth = xa;
486
+ var v = 3 * k.zoom;
487
487
  r.beginPath();
488
488
  for (var u = o; u < fr; u += t)
489
489
  for (var s = f; s < vr; s += t) {
@@ -492,455 +492,457 @@ function Ft() {
492
492
  }
493
493
  r.stroke();
494
494
  } else {
495
- var Z = Kt || k.grid;
496
- r.beginPath(), r.strokeStyle = Z, r.lineWidth = da * 0.5;
495
+ var Z = Jt || M.grid;
496
+ r.beginPath(), r.strokeStyle = Z, r.lineWidth = xa * 0.5;
497
497
  for (var _ = o; _ < fr; _ += t) {
498
498
  var K = Math.round(_) + 0.5;
499
499
  r.moveTo(K, 0), r.lineTo(K, vr);
500
500
  }
501
- for (var ar = f; ar < vr; ar += t) {
502
- var tr = Math.round(ar) + 0.5;
503
- r.moveTo(0, tr), r.lineTo(fr, tr);
501
+ for (var rr = f; rr < vr; rr += t) {
502
+ var ar = Math.round(rr) + 0.5;
503
+ r.moveTo(0, ar), r.lineTo(fr, ar);
504
504
  }
505
505
  r.stroke();
506
506
  }
507
507
  }
508
- r.beginPath(), r.arc(M.x, M.y, 4 * M.zoom, 0, 6.2832), r.fillStyle = k.origin, r.fill(), r.save(), r.translate(M.x, M.y), r.scale(M.zoom, M.zoom);
509
- var hr = 100, X = -M.x / M.zoom, Yr = -M.y / M.zoom, xa = X + fr / M.zoom, Xr = Yr + vr / M.zoom, H = X - hr, ga = Yr - hr, Ka = xa + hr, q = Xr + hr;
510
- if (Y.length > 0) {
511
- var P = jo(X, Yr, xa, Xr), sr = P.length, Ut = M.zoom > 0.15, ba = M.zoom > 0.3, Ma = M.zoom > 0.08 && sr < 200;
512
- if (Ma) {
513
- r.shadowColor = k.cardShadow, r.shadowBlur = 6, r.shadowOffsetY = 2, r.fillStyle = k.cardBg, r.beginPath();
514
- for (var ka = 0; ka < sr; ka++) {
515
- var Cr = Y[P[ka]];
516
- r.roundRect(Cr.x, Cr.y, Cr.w, Cr.h, ot);
508
+ r.beginPath(), r.arc(Math.round(k.x), Math.round(k.y), 4 * k.zoom, 0, 6.2832), r.fillStyle = M.origin, r.fill();
509
+ var Tr = Math.round(k.x), nr = Math.round(k.y);
510
+ r.save(), r.translate(Tr, nr), r.scale(k.zoom, k.zoom);
511
+ var Or = 100, jr = -Tr / k.zoom, Lr = -nr / k.zoom, D = jr + fr / k.zoom, Yr = Lr + vr / k.zoom, Ja = jr - Or, P = Lr - Or, O = D + Or, ut = Yr + Or;
512
+ if (H.length > 0) {
513
+ var sr = Yo(jr, Lr, D, Yr), tr = sr.length, Qa = k.zoom > 0.15, st = k.zoom > 0.3, ka = k.zoom > 0.08 && tr < 200;
514
+ if (ka) {
515
+ r.shadowColor = M.cardShadow, r.shadowBlur = 6, r.shadowOffsetY = 2, r.fillStyle = M.cardBg, r.beginPath();
516
+ for (var ma = 0; ma < tr; ma++) {
517
+ var Ta = H[sr[ma]];
518
+ r.roundRect(Ta.x, Ta.y, Ta.w, Ta.h, ot);
517
519
  }
518
520
  r.fill(), r.shadowColor = "transparent", r.shadowBlur = 0, r.shadowOffsetY = 0;
519
521
  }
520
- if (!Ma) {
521
- r.fillStyle = k.cardBg, r.beginPath();
522
- for (var ma = 0; ma < sr; ma++) {
523
- var Ta = Y[P[ma]];
524
- r.roundRect(Ta.x, Ta.y, Ta.w, Ta.h, ot);
522
+ if (!ka) {
523
+ r.fillStyle = M.cardBg, r.beginPath();
524
+ for (var Ra = 0; Ra < tr; Ra++) {
525
+ var Xr = H[sr[Ra]];
526
+ r.roundRect(Xr.x, Xr.y, Xr.w, Xr.h, ot);
525
527
  }
526
528
  r.fill();
527
529
  }
528
- r.strokeStyle = k.cardBorder, r.lineWidth = 0.5, r.beginPath();
529
- for (var Ra = 0; Ra < sr; Ra++) {
530
- var Hr = Y[P[Ra]];
531
- r.roundRect(Hr.x, Hr.y, Hr.w, Hr.h, ot);
530
+ r.strokeStyle = M.cardBorder, r.lineWidth = 0.5, r.beginPath();
531
+ for (var za = 0; za < tr; za++) {
532
+ var G = H[sr[za]];
533
+ r.roundRect(G.x, G.y, G.w, G.h, ot);
532
534
  }
533
535
  r.stroke();
534
- for (var pr = [{}, {}, {}, {}], b = 0; b < sr; b++) {
535
- var ut = P[b], Ja = ut % 4;
536
- pr[Ja].items || (pr[Ja].items = []), pr[Ja].items.push(Y[ut]);
536
+ for (var wa = [{}, {}, {}, {}], $a = 0; $a < tr; $a++) {
537
+ var Ba = sr[$a], Hr = Ba % 4;
538
+ wa[Hr].items || (wa[Hr].items = []), wa[Hr].items.push(H[Ba]);
537
539
  }
538
- for (var Wr = 0; Wr < 4; Wr++) {
539
- var Pr = pr[Wr].items;
540
- if (!(!Pr || Pr.length === 0)) {
541
- r.fillStyle = Nl[Wr], r.beginPath();
542
- for (var za = 0; za < Pr.length; za++) {
543
- var ra = Pr[za];
544
- r.roundRect(ra.x, ra.y, ra.w, 30, [ot, ot, 0, 0]);
540
+ for (var pr = 0; pr < 4; pr++) {
541
+ var Sr = wa[pr].items;
542
+ if (!(!Sr || Sr.length === 0)) {
543
+ r.fillStyle = Ol[pr], r.beginPath();
544
+ for (var Aa = 0; Aa < Sr.length; Aa++) {
545
+ var Fa = Sr[Aa];
546
+ r.roundRect(Fa.x, Fa.y, Fa.w, 30, [ot, ot, 0, 0]);
545
547
  }
546
548
  r.fill();
547
549
  }
548
550
  }
549
- if (Ut) {
550
- r.fillStyle = k.titleText, r.font = Dl;
551
- for (var wa = 0; wa < sr; wa++) {
552
- var Qa = Y[P[wa]];
553
- r.fillText(Qa.title, Qa.x + 12, Qa.y + 19);
554
- }
555
- r.fillStyle = k.bodyText, r.font = Ol;
556
- for (var Ba = 0; Ba < sr; Ba++) {
557
- var Aa = Y[P[Ba]];
558
- r.fillText(Aa.body, Aa.x + 12, Aa.y + 52);
559
- }
560
- if (ba) {
561
- r.fillStyle = k.coordText, r.font = jl;
562
- for (var _a = 0; _a < sr; _a++) {
563
- var qr = Y[P[_a]];
564
- r.fillText("(" + qr.x + ", " + qr.y + ")", qr.x + 12, qr.y + 75);
551
+ if (Qa) {
552
+ r.fillStyle = M.titleText, r.font = jl;
553
+ for (var _a = 0; _a < tr; _a++) {
554
+ var Ea = H[sr[_a]];
555
+ r.fillText(Ea.title, Ea.x + 12, Ea.y + 19);
556
+ }
557
+ r.fillStyle = M.bodyText, r.font = Yl;
558
+ for (var Ca = 0; Ca < tr; Ca++) {
559
+ var ra = H[sr[Ca]];
560
+ r.fillText(ra.body, ra.x + 12, ra.y + 52);
561
+ }
562
+ if (st) {
563
+ r.fillStyle = M.coordText, r.font = Xl;
564
+ for (var Wr = 0; Wr < tr; Wr++) {
565
+ var aa = H[sr[Wr]];
566
+ r.fillText("(" + aa.x + ", " + aa.y + ")", aa.x + 12, aa.y + 75);
565
567
  }
566
568
  }
567
569
  }
568
570
  }
569
- var nr = [], Rr = null;
571
+ var Rr = [], dr = null;
570
572
  if (W.length > 0)
571
- if (Rr = {}, W.length > 100)
572
- for (var $a = ol(H, ga, Ka, q), aa = 0; aa < $a.length; aa++) {
573
- var Gr = W[$a[aa]];
574
- Rr[Gr.id] = !0, Gr._customRendered || nr.push(Gr);
573
+ if (dr = {}, W.length > 100)
574
+ for (var ta = ll(Ja, P, O, ut), La = 0; La < ta.length; La++) {
575
+ var Sa = W[ta[La]];
576
+ dr[Sa.id] = !0, Sa._customRendered || Rr.push(Sa);
575
577
  }
576
578
  else
577
- for (var Ea = 0; Ea < W.length; Ea++) {
578
- var p = W[Ea];
579
- if (!p.hidden) {
580
- var Ir = p.width || L, La = p.height || B;
581
- y(p).x + Ir < H || y(p).x > Ka || y(p).y + La < ga || y(p).y > q || (Rr[p.id] = !0, p._customRendered || nr.push(p));
579
+ for (var ea = 0; ea < W.length; ea++) {
580
+ var F = W[ea];
581
+ if (!F.hidden) {
582
+ var oa = F.width || C, dt = F.height || B;
583
+ y(F).x + oa < Ja || y(F).x > O || y(F).y + dt < P || y(F).y > ut || (dr[F.id] = !0, F._customRendered || Rr.push(F));
582
584
  }
583
585
  }
584
- var dr = nr.length;
585
- if (C.length > 0 && W.length > 0) {
586
- let qt = function(cr, No) {
587
- if (cr.length) {
588
- r.fillStyle = No, r.beginPath();
589
- for (var Ce = 0; Ce < cr.length; Ce++) {
590
- var j = cr[Ce];
591
- r.moveTo(j.x, j.y), r.lineTo(j.x - j.size * Math.cos(j.angle - 0.5236), j.y - j.size * Math.sin(j.angle - 0.5236)), r.lineTo(j.x - j.size * Math.cos(j.angle + 0.5236), j.y - j.size * Math.sin(j.angle + 0.5236)), r.closePath();
586
+ var hr = Rr.length;
587
+ if (S.length > 0 && W.length > 0) {
588
+ let It = function(Fr, Do) {
589
+ if (Fr.length) {
590
+ r.fillStyle = Do, r.beginPath();
591
+ for (var We = 0; We < Fr.length; We++) {
592
+ var X = Fr[We];
593
+ r.moveTo(X.x, X.y), r.lineTo(X.x - X.size * Math.cos(X.angle - 0.5236), X.y - X.size * Math.sin(X.angle - 0.5236)), r.lineTo(X.x - X.size * Math.cos(X.angle + 0.5236), X.y - X.size * Math.sin(X.angle + 0.5236)), r.closePath();
592
594
  }
593
595
  r.fill();
594
596
  }
595
597
  };
596
- var ei = qt;
597
- $t && Hl();
598
- var Zr = null, zr = null, yr = null, Fa = [], Ua = [], ta = [], xr = [], st = M.zoom > 0.3, hl = M.zoom > 0.05, ea;
599
- if (Rr && W.length > 100) {
600
- var dt = {};
601
- ea = [];
602
- for (var nl in Rr) {
603
- var ct = Er[nl];
604
- if (ct)
605
- for (var Vt = 0; Vt < ct.length; Vt++) {
606
- var Nt = ct[Vt];
607
- dt[Nt] || (dt[Nt] = !0, ea.push(Nt));
598
+ var li = It;
599
+ Ut && ri();
600
+ var yr = null, Pr = null, qr = null, la = [], Gr = [], Ua = [], yt = [], hl = k.zoom > 0.3, ul = k.zoom > 0.05, ia;
601
+ if (dr && W.length > 100) {
602
+ var gt = {};
603
+ ia = [];
604
+ for (var sl in dr) {
605
+ var Vt = _r[sl];
606
+ if (Vt)
607
+ for (var Nt = 0; Nt < Vt.length; Nt++) {
608
+ var Dt = Vt[Nt];
609
+ gt[Dt] || (gt[Dt] = !0, ia.push(Dt));
608
610
  }
609
611
  }
610
- for (var rr = 0; rr < W.length; rr++) {
611
- var yt = W[rr];
612
- if ((yt.dragging || yt.selected) && !Rr[yt.id]) {
613
- var ca = Er[yt.id];
612
+ for (var p = 0; p < W.length; p++) {
613
+ var xt = W[p];
614
+ if ((xt.dragging || xt.selected) && !dr[xt.id]) {
615
+ var ca = _r[xt.id];
614
616
  if (ca)
615
617
  for (var Va = 0; Va < ca.length; Va++)
616
- dt[ca[Va]] || (dt[ca[Va]] = !0, ea.push(ca[Va]));
618
+ gt[ca[Va]] || (gt[ca[Va]] = !0, ia.push(ca[Va]));
617
619
  }
618
620
  }
619
621
  } else {
620
- ea = [];
621
- for (var Dt = 0; Dt < C.length; Dt++) ea.push(Dt);
622
+ ia = [];
623
+ for (var Ot = 0; Ot < S.length; Ot++) ia.push(Ot);
622
624
  }
623
- for (var Ot = 0; Ot < ea.length; Ot++) {
624
- var D = C[ea[Ot]], oa = Yo(D.source), la = Yo(D.target);
625
- if (!(!oa || !la) && !(oa.hidden || la.hidden) && !D._customRendered) {
626
- var xt = bt(oa, "source", D.sourceHandle), gt = bt(la, "target", D.targetHandle), A = xt.x, w = xt.y, R = gt.x, z = gt.y, gr = D.type || "default", Fe = D.selected, Ue = D.animated, J;
627
- Fe ? (zr || (zr = new Path2D()), J = zr) : Ue ? (yr || (yr = new Path2D()), J = yr) : (Zr || (Zr = new Path2D()), J = Zr);
628
- var Q = D._routedPoints;
629
- if (Q && Q.length >= 2)
630
- al(J, Q);
625
+ for (var jt = 0; jt < ia.length; jt++) {
626
+ var j = S[ia[jt]], fa = Xo(j.source), va = Xo(j.target);
627
+ if (!(!fa || !va) && !(fa.hidden || va.hidden) && !j._customRendered) {
628
+ var Mt = Qt(fa, "source", j.sourceHandle), kt = Qt(va, "target", j.targetHandle), A = Mt.x, w = Mt.y, R = kt.x, z = kt.y, gr = j.type || "default", Ue = j.selected, ce = j.animated, b;
629
+ Ue ? (Pr || (Pr = new Path2D()), b = Pr) : ce ? (qr || (qr = new Path2D()), b = qr) : (yr || (yr = new Path2D()), b = yr);
630
+ var J = j._routedPoints;
631
+ if (J && J.length >= 2)
632
+ tl(b, J);
631
633
  else if (gr === "straight")
632
- J.moveTo(A, w), J.lineTo(R, z);
634
+ b.moveTo(A, w), b.lineTo(R, z);
633
635
  else if (gr === "step" || gr === "smoothstep")
634
636
  try {
635
- var er = xt.position || "right", Sa = gt.position || "left", m = 20, U = A, O = w, c = R, or = z;
636
- er === "right" ? U += m : er === "left" ? U -= m : er === "bottom" ? O += m : er === "top" && (O -= m), Sa === "right" ? c += m : Sa === "left" ? c -= m : Sa === "bottom" ? or += m : Sa === "top" && (or -= m);
637
- var Mt = y(oa), kt = y(la), Na = oa.width || L, Da = oa.height || B, ce = la.width || L, Ve = la.height || B, jt = er === "left" || er === "right", Ne = Sa === "left" || Sa === "right", Yt = {};
638
- Yt[D.source] = !0, Yt[D.target] = !0;
639
- var lr = vl(
637
+ var er = Mt.position || "right", Wa = kt.position || "left", m = 20, U = A, Y = w, c = R, or = z;
638
+ er === "right" ? U += m : er === "left" ? U -= m : er === "bottom" ? Y += m : er === "top" && (Y -= m), Wa === "right" ? c += m : Wa === "left" ? c -= m : Wa === "bottom" ? or += m : Wa === "top" && (or -= m);
639
+ var mt = y(fa), Tt = y(va), Na = fa.width || C, Da = fa.height || B, Ve = va.width || C, Ne = va.height || B, Yt = er === "left" || er === "right", De = Wa === "left" || Wa === "right", Xt = {};
640
+ Xt[j.source] = !0, Xt[j.target] = !0;
641
+ var lr = nl(
640
642
  Math.min(A, R) - Na,
641
643
  Math.min(w, z) - Da,
642
- Math.max(A, R) + ce,
643
- Math.max(w, z) + Ve,
644
- Yt
644
+ Math.max(A, R) + Ve,
645
+ Math.max(w, z) + Ne,
646
+ Xt
645
647
  );
646
- lr.push(oa), lr.push(la);
648
+ lr.push(fa), lr.push(va);
647
649
  var I = [];
648
- if (jt && Ne) {
649
- var V, ul = er === "right" && U < c, sl = er === "left" && U > c;
650
- if (ul || sl) {
650
+ if (Yt && De) {
651
+ var V, dl = er === "right" && U < c, yl = er === "left" && U > c;
652
+ if (dl || yl) {
651
653
  V = (U + c) / 2;
652
- var Xt = Sr(V, w, z, lr);
653
- if (Xt) {
654
- var Ht = y(Xt), Ir = Xt.width || L;
655
- V < Ht.x + Ir / 2 ? V = Ht.x - m : V = Ht.x + Ir + m;
654
+ var Ht = Cr(V, w, z, lr);
655
+ if (Ht) {
656
+ var pt = y(Ht), oa = Ht.width || C;
657
+ V < pt.x + oa / 2 ? V = pt.x - m : V = pt.x + oa + m;
656
658
  }
657
659
  } else
658
- er === "right" ? V = Math.max(Mt.x + Na, kt.x + ce) + m : V = Math.min(Mt.x, kt.x) - m;
660
+ er === "right" ? V = Math.max(mt.x + Na, Tt.x + Ve) + m : V = Math.min(mt.x, Tt.x) - m;
659
661
  I = [{ x: U, y: w }, { x: V, y: w }, { x: V, y: z }, { x: c, y: z }];
660
- var pt = Lr(V, c, z, lr);
661
- if (pt) {
662
- var De = y(pt), dl = pt.height || B, Oe = De.y - m, je = De.y + dl + m, Ye = Math.abs(w - Oe) <= Math.abs(w - je) ? Oe : je;
662
+ var re = Er(V, c, z, lr);
663
+ if (re) {
664
+ var Oe = y(re), gl = re.height || B, je = Oe.y - m, Ye = Oe.y + gl + m, Xe = Math.abs(w - je) <= Math.abs(w - Ye) ? je : Ye;
663
665
  I = [
664
666
  { x: U, y: w },
665
667
  { x: V, y: w },
666
- { x: V, y: Ye },
667
- { x: c, y: Ye },
668
+ { x: V, y: Xe },
669
+ { x: c, y: Xe },
668
670
  { x: c, y: z }
669
671
  ];
670
672
  }
671
- var re = Lr(U, V, w, lr);
672
- if (re) {
673
- var Xe = y(re), yl = re.height || B, He = Xe.y - m, pe = Xe.y + yl + m, ro = Math.abs(z - He) <= Math.abs(z - pe) ? He : pe;
673
+ var ae = Er(U, V, w, lr);
674
+ if (ae) {
675
+ var He = y(ae), xl = ae.height || B, pe = He.y - m, ro = He.y + xl + m, ao = Math.abs(z - pe) <= Math.abs(z - ro) ? pe : ro;
674
676
  I.splice(
675
677
  1,
676
678
  0,
677
- { x: U, y: ro },
678
- { x: V, y: ro }
679
- ), I = I.filter(function(cr, No) {
680
- return !(Math.abs(cr.x - V) < 1 && Math.abs(cr.y - w) < 1);
679
+ { x: U, y: ao },
680
+ { x: V, y: ao }
681
+ ), I = I.filter(function(Fr, Do) {
682
+ return !(Math.abs(Fr.x - V) < 1 && Math.abs(Fr.y - w) < 1);
681
683
  }), I.splice(0, 0, { x: U, y: w });
682
684
  }
683
- } else if (!jt && !Ne) {
684
- var N, xl = er === "bottom" && O < or, gl = er === "top" && O > or;
685
- if (xl || gl) {
686
- N = (O + or) / 2;
687
- var ae = Lr(A, R, N, lr);
688
- if (ae) {
689
- var te = y(ae), ao = ae.height || B;
690
- N < te.y + ao / 2 ? N = te.y - m : N = te.y + ao + m;
685
+ } else if (!Yt && !De) {
686
+ var N, Ml = er === "bottom" && Y < or, kl = er === "top" && Y > or;
687
+ if (Ml || kl) {
688
+ N = (Y + or) / 2;
689
+ var te = Er(A, R, N, lr);
690
+ if (te) {
691
+ var ee = y(te), to = te.height || B;
692
+ N < ee.y + to / 2 ? N = ee.y - m : N = ee.y + to + m;
691
693
  }
692
694
  } else
693
- er === "bottom" ? N = Math.max(Mt.y + Da, kt.y + Ve) + m : N = Math.min(Mt.y, kt.y) - m;
694
- I = [{ x: A, y: O }, { x: A, y: N }, { x: R, y: N }, { x: R, y: or }];
695
- var ee = Sr(A, O, N, lr);
696
- if (ee) {
697
- var to = y(ee), Ml = ee.width || L, eo = to.x - m, oo = to.x + Ml + m, lo = Math.abs(R - eo) <= Math.abs(R - oo) ? eo : oo;
695
+ er === "bottom" ? N = Math.max(mt.y + Da, Tt.y + Ne) + m : N = Math.min(mt.y, Tt.y) - m;
696
+ I = [{ x: A, y: Y }, { x: A, y: N }, { x: R, y: N }, { x: R, y: or }];
697
+ var oe = Cr(A, Y, N, lr);
698
+ if (oe) {
699
+ var eo = y(oe), ml = oe.width || C, oo = eo.x - m, lo = eo.x + ml + m, io = Math.abs(R - oo) <= Math.abs(R - lo) ? oo : lo;
698
700
  I = [
699
- { x: A, y: O },
700
- { x: lo, y: O },
701
- { x: lo, y: N },
701
+ { x: A, y: Y },
702
+ { x: io, y: Y },
703
+ { x: io, y: N },
702
704
  { x: R, y: N },
703
705
  { x: R, y: or }
704
706
  ];
705
707
  }
706
- var oe = Sr(R, N, or, lr);
707
- if (oe) {
708
- var io = y(oe), kl = oe.height || B, fo = io.y - m, vo = io.y + kl + m, ml = Math.abs(N - fo) <= Math.abs(N - vo) ? fo : vo;
708
+ var le = Cr(R, N, or, lr);
709
+ if (le) {
710
+ var fo = y(le), Tl = le.height || B, vo = fo.y - m, no = fo.y + Tl + m, Rl = Math.abs(N - vo) <= Math.abs(N - no) ? vo : no;
709
711
  I.splice(
710
712
  I.length - 1,
711
713
  0,
712
- { x: c, y: ml }
714
+ { x: c, y: Rl }
713
715
  );
714
716
  }
715
- } else if (jt) {
717
+ } else if (Yt) {
716
718
  I = [{ x: U, y: w }, { x: R, y: w }, { x: R, y: or }];
717
- var le = Sr(R, w, or, lr);
718
- if (le) {
719
- var ho = y(le), Tl = le.width || L, no = ho.x - m, uo = ho.x + Tl + m, so = Math.abs(A - no) <= Math.abs(A - uo) ? no : uo;
720
- I = [{ x: U, y: w }, { x: so, y: w }, { x: so, y: z }, { x: R, y: z }, { x: R, y: or }];
721
- }
722
- var ie = Lr(U, R, w, lr);
719
+ var ie = Cr(R, w, or, lr);
723
720
  if (ie) {
724
- var yo = y(ie), Rl = ie.height || B, xo = yo.y - m, go = yo.y + Rl + m, Mo = Math.abs(z - xo) <= Math.abs(z - go) ? xo : go;
725
- I = [{ x: U, y: w }, { x: U, y: Mo }, { x: R, y: Mo }, { x: R, y: or }];
721
+ var ho = y(ie), zl = ie.width || C, uo = ho.x - m, so = ho.x + zl + m, yo = Math.abs(A - uo) <= Math.abs(A - so) ? uo : so;
722
+ I = [{ x: U, y: w }, { x: yo, y: w }, { x: yo, y: z }, { x: R, y: z }, { x: R, y: or }];
726
723
  }
727
- } else {
728
- I = [{ x: A, y: O }, { x: A, y: z }, { x: c, y: z }];
729
- var fe = Lr(A, c, z, lr);
724
+ var fe = Er(U, R, w, lr);
730
725
  if (fe) {
731
- var ko = y(fe), zl = fe.height || B, mo = ko.y - m, To = ko.y + zl + m, Ro = Math.abs(w - mo) <= Math.abs(w - To) ? mo : To;
732
- I = [{ x: A, y: O }, { x: A, y: Ro }, { x: c, y: Ro }, { x: c, y: z }];
726
+ var go = y(fe), wl = fe.height || B, xo = go.y - m, Mo = go.y + wl + m, ko = Math.abs(z - xo) <= Math.abs(z - Mo) ? xo : Mo;
727
+ I = [{ x: U, y: w }, { x: U, y: ko }, { x: R, y: ko }, { x: R, y: or }];
733
728
  }
734
- var ve = Sr(A, O, z, lr);
729
+ } else {
730
+ I = [{ x: A, y: Y }, { x: A, y: z }, { x: c, y: z }];
731
+ var ve = Er(A, c, z, lr);
735
732
  if (ve) {
736
- var zo = y(ve), wl = ve.width || L, wo = zo.x - m, Bo = zo.x + wl + m, Ao = Math.abs(R - wo) <= Math.abs(R - Bo) ? wo : Bo;
737
- I = [{ x: A, y: O }, { x: Ao, y: O }, { x: Ao, y: z }, { x: c, y: z }];
733
+ var mo = y(ve), Bl = ve.height || B, To = mo.y - m, Ro = mo.y + Bl + m, zo = Math.abs(w - To) <= Math.abs(w - Ro) ? To : Ro;
734
+ I = [{ x: A, y: Y }, { x: A, y: zo }, { x: c, y: zo }, { x: c, y: z }];
735
+ }
736
+ var ne = Cr(A, Y, z, lr);
737
+ if (ne) {
738
+ var wo = y(ne), Al = ne.width || C, Bo = wo.x - m, Ao = wo.x + Al + m, _o = Math.abs(R - Bo) <= Math.abs(R - Ao) ? Bo : Ao;
739
+ I = [{ x: A, y: Y }, { x: _o, y: Y }, { x: _o, y: z }, { x: c, y: z }];
738
740
  }
739
741
  }
740
- for (var ia = [{ x: A, y: w }], he = 0; he < I.length; he++) ia.push(I[he]);
741
- ia.push({ x: R, y: z });
742
- for (var ir = [ia[0]], Oa = 1; Oa < ia.length; Oa++) {
742
+ for (var na = [{ x: A, y: w }], he = 0; he < I.length; he++) na.push(I[he]);
743
+ na.push({ x: R, y: z });
744
+ for (var ir = [na[0]], Oa = 1; Oa < na.length; Oa++) {
743
745
  var ja = ir[ir.length - 1];
744
- (Math.abs(ia[Oa].x - ja.x) > 0.1 || Math.abs(ia[Oa].y - ja.y) > 0.1) && ir.push(ia[Oa]);
746
+ (Math.abs(na[Oa].x - ja.x) > 0.1 || Math.abs(na[Oa].y - ja.y) > 0.1) && ir.push(na[Oa]);
745
747
  }
746
- var _o = gr === "smoothstep" ? 8 : 0;
747
- J.moveTo(ir[0].x, ir[0].y);
748
- for (var rr = 1; rr < ir.length; rr++)
749
- if (_o > 0 && rr > 0 && rr < ir.length - 1) {
750
- var wr = ir[rr - 1], S = ir[rr], Kr = ir[rr + 1];
751
- if (Math.abs(wr.x - S.x) < 0.5 && Math.abs(S.x - Kr.x) < 0.5 || Math.abs(wr.y - S.y) < 0.5 && Math.abs(S.y - Kr.y) < 0.5)
752
- J.lineTo(S.x, S.y);
748
+ var Eo = gr === "smoothstep" ? 8 : 0;
749
+ b.moveTo(ir[0].x, ir[0].y);
750
+ for (var p = 1; p < ir.length; p++)
751
+ if (Eo > 0 && p > 0 && p < ir.length - 1) {
752
+ var zr = ir[p - 1], L = ir[p], Ir = ir[p + 1];
753
+ if (Math.abs(zr.x - L.x) < 0.5 && Math.abs(L.x - Ir.x) < 0.5 || Math.abs(zr.y - L.y) < 0.5 && Math.abs(L.y - Ir.y) < 0.5)
754
+ b.lineTo(L.x, L.y);
753
755
  else {
754
- var mt = Math.min(Math.hypot(wr.x - S.x, wr.y - S.y) / 2, Math.hypot(S.x - Kr.x, S.y - Kr.y) / 2, _o);
755
- Math.abs(wr.y - S.y) < 0.5 ? (J.lineTo(S.x + (wr.x < Kr.x ? -1 : 1) * mt, S.y), J.quadraticCurveTo(S.x, S.y, S.x, S.y + (wr.y < Kr.y ? 1 : -1) * mt)) : (J.lineTo(S.x, S.y + (wr.y < Kr.y ? -1 : 1) * mt), J.quadraticCurveTo(S.x, S.y, S.x + (wr.x < Kr.x ? 1 : -1) * mt, S.y));
756
+ var Rt = Math.min(Math.hypot(zr.x - L.x, zr.y - L.y) / 2, Math.hypot(L.x - Ir.x, L.y - Ir.y) / 2, Eo);
757
+ Math.abs(zr.y - L.y) < 0.5 ? (b.lineTo(L.x + (zr.x < Ir.x ? -1 : 1) * Rt, L.y), b.quadraticCurveTo(L.x, L.y, L.x, L.y + (zr.y < Ir.y ? 1 : -1) * Rt)) : (b.lineTo(L.x, L.y + (zr.y < Ir.y ? -1 : 1) * Rt), b.quadraticCurveTo(L.x, L.y, L.x + (zr.x < Ir.x ? 1 : -1) * Rt, L.y));
756
758
  }
757
759
  } else
758
- J.lineTo(ir[rr].x, ir[rr].y);
759
- } catch (cr) {
760
- console.error("[worker] smoothstep error:", cr, "edge:", D.id);
760
+ b.lineTo(ir[p].x, ir[p].y);
761
+ } catch (Fr) {
762
+ console.error("[worker] smoothstep error:", Fr, "edge:", j.id);
761
763
  }
762
764
  else {
763
- var br = xt.position || "right", Jr = gt.position || "left", Qr = 20, Ya = A, Tt = w, Xa = R, Rt = z;
764
- br === "right" ? Ya += Qr : br === "left" ? Ya -= Qr : br === "bottom" ? Tt += Qr : br === "top" && (Tt -= Qr), Jr === "right" ? Xa += Qr : Jr === "left" ? Xa -= Qr : Jr === "bottom" ? Rt += Qr : Jr === "top" && (Rt -= Qr);
765
- var Bl = Math.abs(Xa - Ya), $r = Math.max(50, Bl * 0.5), Al = Ya + (br === "left" ? -$r : br === "right" ? $r : 0), _l = Tt + (br === "top" ? -$r : br === "bottom" ? $r : 0), El = Xa + (Jr === "left" ? -$r : Jr === "right" ? $r : 0), Ll = Rt + (Jr === "top" ? -$r : Jr === "bottom" ? $r : 0);
766
- J.moveTo(A, w), J.lineTo(Ya, Tt), J.bezierCurveTo(Al, _l, El, Ll, Xa, Rt), J.lineTo(R, z);
765
+ var Zr = Mt.position || "right", Kr = kt.position || "left", br = 20, Ya = A, zt = w, Xa = R, wt = z;
766
+ Zr === "right" ? Ya += br : Zr === "left" ? Ya -= br : Zr === "bottom" ? zt += br : Zr === "top" && (zt -= br), Kr === "right" ? Xa += br : Kr === "left" ? Xa -= br : Kr === "bottom" ? wt += br : Kr === "top" && (wt -= br);
767
+ var _l = Math.abs(Xa - Ya), Jr = Math.max(50, _l * 0.5), El = Ya + (Zr === "left" ? -Jr : Zr === "right" ? Jr : 0), Cl = zt + (Zr === "top" ? -Jr : Zr === "bottom" ? Jr : 0), Ll = Xa + (Kr === "left" ? -Jr : Kr === "right" ? Jr : 0), Sl = wt + (Kr === "top" ? -Jr : Kr === "bottom" ? Jr : 0);
768
+ b.moveTo(A, w), b.lineTo(Ya, zt), b.bezierCurveTo(El, Cl, Ll, Sl, Xa, wt), b.lineTo(R, z);
767
769
  }
768
- if (hl) {
769
- var Sl = 8, Ha;
770
- if (Q && Q.length >= 2) {
771
- var ja = Q[Q.length - 1], Eo = Q[Q.length - 2];
772
- Ha = Math.atan2(ja.y - Eo.y, ja.x - Eo.x);
770
+ if (ul) {
771
+ var Wl = 8, Ha;
772
+ if (J && J.length >= 2) {
773
+ var ja = J[J.length - 1], Co = J[J.length - 2];
774
+ Ha = Math.atan2(ja.y - Co.y, ja.x - Co.x);
773
775
  } else if (gr === "straight")
774
776
  Ha = Math.atan2(z - w, R - A);
775
777
  else if (gr === "step" || gr === "smoothstep")
776
778
  Ha = 0;
777
779
  else {
778
- var Lo = Je(A, w, R, z);
780
+ var Lo = Qe(A, w, R, z);
779
781
  Ha = Math.atan2(z - Lo.cp2y, R - Lo.cp2x);
780
782
  }
781
- var So = Q && Q.length >= 2 ? Q[Q.length - 1] : { x: R, y: z }, ne = { x: So.x, y: So.y, angle: Ha, size: Sl };
782
- Fe ? Ua.push(ne) : Ue ? ta.push(ne) : Fa.push(ne);
783
+ var So = J && J.length >= 2 ? J[J.length - 1] : { x: R, y: z }, ue = { x: So.x, y: So.y, angle: Ha, size: Wl };
784
+ Ue ? Gr.push(ue) : ce ? Ua.push(ue) : la.push(ue);
783
785
  }
784
- if (st && D.label) {
786
+ if (hl && j.label) {
785
787
  var pa;
786
- Q && Q.length >= 2 ? pa = ri(Q) : gr === "straight" || gr === "step" || gr === "smoothstep" ? pa = { x: (A + R) / 2, y: (w + z) / 2 } : pa = ai(A, w, R, z), xr.push({ text: D.label, x: pa.x, y: pa.y });
788
+ J && J.length >= 2 ? pa = ti(J) : gr === "straight" || gr === "step" || gr === "smoothstep" ? pa = { x: (A + R) / 2, y: (w + z) / 2 } : pa = ei(A, w, R, z), yt.push({ text: j.label, x: pa.x, y: pa.y });
787
789
  }
788
790
  }
789
791
  }
790
- if (Zr && (r.strokeStyle = k.edgeStroke, r.lineWidth = 1.5, r.setLineDash([]), r.stroke(Zr)), yr && (r.strokeStyle = k.edgeAnimated, r.lineWidth = 1.5, r.setLineDash([5, 5]), r.lineDashOffset = -be, r.stroke(yr), r.setLineDash([])), zr && (r.strokeStyle = k.edgeSelected, r.lineWidth = 2.5, r.setLineDash([]), r.stroke(zr)), qt(Fa, k.edgeStroke), qt(ta, k.edgeAnimated), qt(Ua, k.edgeSelected), xr.length > 0) {
791
- r.font = Yl, r.textAlign = "center", r.textBaseline = "middle";
792
- for (var ue = 0; ue < xr.length; ue++) {
793
- var Ca = xr[ue], Cl = r.measureText(Ca.text), Co = Cl.width + 12;
794
- r.fillStyle = F ? "#2a2a2a" : "#ffffff", r.fillRect(Ca.x - Co / 2, Ca.y - 9, Co, 18), r.fillStyle = k.nodeText, r.fillText(Ca.text, Ca.x, Ca.y);
792
+ if (yr && (r.strokeStyle = M.edgeStroke, r.lineWidth = 1.5, r.setLineDash([]), r.stroke(yr)), qr && (r.strokeStyle = M.edgeAnimated, r.lineWidth = 1.5, r.setLineDash([5, 5]), r.lineDashOffset = -Je, r.stroke(qr), r.setLineDash([])), Pr && (r.strokeStyle = M.edgeSelected, r.lineWidth = 2.5, r.setLineDash([]), r.stroke(Pr)), It(la, M.edgeStroke), It(Ua, M.edgeAnimated), It(Gr, M.edgeSelected), yt.length > 0) {
793
+ r.font = Hl, r.textAlign = "center", r.textBaseline = "middle";
794
+ for (var se = 0; se < yt.length; se++) {
795
+ var Pa = yt[se], Pl = r.measureText(Pa.text), Wo = Pl.width + 12;
796
+ r.fillStyle = $ ? "#2a2a2a" : "#ffffff", r.fillRect(Pa.x - Wo / 2, Pa.y - 9, Wo, 18), r.fillStyle = M.nodeText, r.fillText(Pa.text, Pa.x, Pa.y);
795
797
  }
796
798
  r.textAlign = "start", r.textBaseline = "alphabetic";
797
799
  }
798
800
  }
799
801
  if (lt) {
800
- r.beginPath(), r.strokeStyle = k.connectionLine, r.lineWidth = 2, r.setLineDash([6, 4]);
801
- var se = lt._routedPoints;
802
- if (se && se.length >= 2) {
803
- var Wo = new Path2D();
804
- al(Wo, se), r.stroke(Wo);
802
+ r.beginPath(), r.strokeStyle = M.connectionLine, r.lineWidth = 2, r.setLineDash([6, 4]);
803
+ var de = lt._routedPoints;
804
+ if (de && de.length >= 2) {
805
+ var Po = new Path2D();
806
+ tl(Po, de), r.stroke(Po);
805
807
  } else {
806
- var zt = lt.from, wt = lt.to, Bt = Je(zt.x, zt.y, wt.x, wt.y);
807
- r.moveTo(zt.x, zt.y), r.bezierCurveTo(Bt.cp1x, Bt.cp1y, Bt.cp2x, Bt.cp2y, wt.x, wt.y), r.stroke();
808
+ var Bt = lt.from, At = lt.to, _t = Qe(Bt.x, Bt.y, At.x, At.y);
809
+ r.moveTo(Bt.x, Bt.y), r.bezierCurveTo(_t.cp1x, _t.cp1y, _t.cp2x, _t.cp2y, At.x, At.y), r.stroke();
808
810
  }
809
811
  r.setLineDash([]);
810
812
  }
811
- if (Tr) {
812
- var Po = Math.min(Tr.startWorld.x, Tr.endWorld.x), qo = Math.min(Tr.startWorld.y, Tr.endWorld.y), Na = Math.abs(Tr.endWorld.x - Tr.startWorld.x), Da = Math.abs(Tr.endWorld.y - Tr.startWorld.y);
813
- r.fillStyle = F ? "rgba(59,130,246,0.08)" : "rgba(59,130,246,0.06)", r.fillRect(Po, qo, Na, Da), r.strokeStyle = "#3b82f6", r.lineWidth = 1 / M.zoom, r.setLineDash([]), r.strokeRect(Po, qo, Na, Da);
813
+ if (mr) {
814
+ var qo = Math.min(mr.startWorld.x, mr.endWorld.x), Go = Math.min(mr.startWorld.y, mr.endWorld.y), Na = Math.abs(mr.endWorld.x - mr.startWorld.x), Da = Math.abs(mr.endWorld.y - mr.startWorld.y);
815
+ r.fillStyle = $ ? "rgba(59,130,246,0.08)" : "rgba(59,130,246,0.06)", r.fillRect(qo, Go, Na, Da), r.strokeStyle = "#3b82f6", r.lineWidth = 1 / k.zoom, r.setLineDash([]), r.strokeRect(qo, Go, Na, Da);
814
816
  }
815
- if (dr > 0) {
816
- var Go = Ia > 0, fa = M.zoom > 0.12 && (M.zoom > 0.25 || dr < 500), de = !Go && M.zoom > 0.08 && dr < 200, Wl = !Go && M.zoom > 0.2 && dr < 300, Pl = Object.keys(It).length > 0 || Object.keys(it).length > 0 || Object.keys(Zt).length > 0, Fr = nr, At = [], _t = [];
817
- if (Pl) {
818
- Fr = [];
819
- for (var ye = 0; ye < dr; ye++) {
820
- var Ur = nr[ye];
821
- it[Ur.id] || Ur.type && It[Ur.type] ? At.push(Ur) : Ur.type && Zt[Ur.type] ? _t.push(Ur) : Fr.push(Ur);
817
+ if (hr > 0) {
818
+ var Io = Ka > 0, ha = k.zoom > 0.12 && (k.zoom > 0.25 || hr < 500), ye = !Io && k.zoom > 0.08 && hr < 200, ql = !Io && k.zoom > 0.2 && hr < 300, Gl = Object.keys(Kt).length > 0 || Object.keys(it).length > 0 || Object.keys(bt).length > 0, Qr = Rr, Et = [], Ct = [];
819
+ if (Gl) {
820
+ Qr = [];
821
+ for (var ge = 0; ge < hr; ge++) {
822
+ var $r = Rr[ge];
823
+ it[$r.id] || $r.type && Kt[$r.type] ? Et.push($r) : $r.type && bt[$r.type] ? Ct.push($r) : Qr.push($r);
822
824
  }
823
825
  }
824
- var rt = Fr.length;
825
- if (de) {
826
- r.shadowColor = k.nodeShadow, r.shadowBlur = 6, r.shadowOffsetY = 2, r.fillStyle = k.nodeBg, r.beginPath();
826
+ var rt = Qr.length;
827
+ if (ye) {
828
+ r.shadowColor = M.nodeShadow, r.shadowBlur = 6, r.shadowOffsetY = 2, r.fillStyle = M.nodeBg, r.beginPath();
827
829
  for (var xe = 0; xe < rt; xe++) {
828
- var Et = Fr[xe];
829
- r.roundRect(y(Et).x, y(Et).y, Et.width || L, Et.height || B, Ga);
830
+ var Lt = Qr[xe];
831
+ r.roundRect(y(Lt).x, y(Lt).y, Lt.width || C, Lt.height || B, Za);
830
832
  }
831
833
  r.fill(), r.shadowColor = "transparent", r.shadowBlur = 0, r.shadowOffsetY = 0;
832
834
  }
833
- if (!de) {
834
- r.fillStyle = k.nodeBg, r.beginPath();
835
- for (var ge = 0; ge < rt; ge++) {
836
- var Lt = Fr[ge];
837
- r.roundRect(y(Lt).x, y(Lt).y, Lt.width || L, Lt.height || B, Ga);
835
+ if (!ye) {
836
+ r.fillStyle = M.nodeBg, r.beginPath();
837
+ for (var Me = 0; Me < rt; Me++) {
838
+ var St = Qr[Me];
839
+ r.roundRect(y(St).x, y(St).y, St.width || C, St.height || B, Za);
838
840
  }
839
841
  r.fill();
840
842
  }
841
- r.strokeStyle = k.nodeBorder, r.lineWidth = 1, r.beginPath();
842
- for (var Me = 0; Me < rt; Me++) {
843
- var at = Fr[Me];
844
- at.selected || r.roundRect(y(at).x, y(at).y, at.width || L, at.height || B, Ga);
843
+ r.strokeStyle = M.nodeBorder, r.lineWidth = 1, r.beginPath();
844
+ for (var ke = 0; ke < rt; ke++) {
845
+ var at = Qr[ke];
846
+ at.selected || r.roundRect(y(at).x, y(at).y, at.width || C, at.height || B, Za);
845
847
  }
846
848
  r.stroke();
847
- var Io = !1;
848
- r.strokeStyle = k.nodeSelectedBorder, r.lineWidth = 2, r.beginPath();
849
- for (var ke = 0; ke < rt; ke++) {
850
- var tt = Fr[ke];
851
- tt.selected && (Io = !0, r.roundRect(y(tt).x, y(tt).y, tt.width || L, tt.height || B, Ga));
849
+ var Zo = !1;
850
+ r.strokeStyle = M.nodeSelectedBorder, r.lineWidth = 2, r.beginPath();
851
+ for (var me = 0; me < rt; me++) {
852
+ var tt = Qr[me];
853
+ tt.selected && (Zo = !0, r.roundRect(y(tt).x, y(tt).y, tt.width || C, tt.height || B, Za));
852
854
  }
853
- if (Io && r.stroke(), fa) {
854
- r.fillStyle = k.nodeText, r.font = Oo, r.textAlign = "center", r.textBaseline = "middle";
855
- for (var me = 0; me < rt; me++) {
856
- var va = Fr[me];
857
- if (!(!va.data || !va.data.label)) {
858
- var Zo = va.width || L, ql = va.height || B;
859
- r.fillText(va.data.label, y(va).x + Zo / 2, y(va).y + ql / 2, Zo - 24);
855
+ if (Zo && r.stroke(), ha) {
856
+ r.fillStyle = M.nodeText, r.font = jo, r.textAlign = "center", r.textBaseline = "middle";
857
+ for (var Te = 0; Te < rt; Te++) {
858
+ var ua = Qr[Te];
859
+ if (!(!ua.data || !ua.data.label)) {
860
+ var Ko = ua.width || C, Il = ua.height || B;
861
+ r.fillText(ua.data.label, y(ua).x + Ko / 2, y(ua).y + Il / 2, Ko - 24);
860
862
  }
861
863
  }
862
864
  r.textAlign = "start", r.textBaseline = "alphabetic";
863
865
  }
864
- for (var Te = 0; Te < At.length; Te++) {
865
- var Mr = At[Te], Wa = y(Mr), St = Mr.width || L, Re = Mr.height || B, Ko = it[Mr.id] && tl[it[Mr.id]] || It[Mr.type];
866
- Ko && r.drawImage(Ko, Wa.x, Wa.y, St, Re), fa && Mr.data && Mr.data.label && (r.fillStyle = k.nodeText, r.font = Oo, r.textAlign = "center", r.textBaseline = "middle", r.fillText(Mr.data.label, Wa.x + St / 2, Wa.y + Re / 2, St - 24)), Mr.selected && (r.strokeStyle = k.nodeSelectedBorder, r.lineWidth = 2, r.beginPath(), r.roundRect(Wa.x, Wa.y, St, Re, Ga), r.stroke());
866
+ for (var Re = 0; Re < Et.length; Re++) {
867
+ var xr = Et[Re], qa = y(xr), Wt = xr.width || C, ze = xr.height || B, bo = it[xr.id] && el[it[xr.id]] || Kt[xr.type];
868
+ bo && r.drawImage(bo, qa.x, qa.y, Wt, ze), ha && xr.data && xr.data.label && (r.fillStyle = M.nodeText, r.font = jo, r.textAlign = "center", r.textBaseline = "middle", r.fillText(xr.data.label, qa.x + Wt / 2, qa.y + ze / 2, Wt - 24)), xr.selected && (r.strokeStyle = M.nodeSelectedBorder, r.lineWidth = 2, r.beginPath(), r.roundRect(qa.x, qa.y, Wt, ze, Za), r.stroke());
867
869
  }
868
- At.length > 0 && fa && (r.textAlign = "start", r.textBaseline = "alphabetic");
869
- for (var ze = 0; ze < _t.length; ze++) {
870
- var ha = _t[ze], G = Zt[ha.type], E = y(ha), Br = ha.width || L, na = ha.height || B, ur = G.radius || Ga, Ct = ha.data || {};
871
- if (de && G.shadow !== !1 && (r.save(), r.shadowColor = G.shadowColor || k.nodeShadow, r.shadowBlur = G.shadowBlur || 6, r.shadowOffsetY = G.shadowOffsetY || 2, r.fillStyle = G.fill || k.nodeBg, r.beginPath(), r.roundRect(E.x, E.y, Br, na, ur), r.fill(), r.restore()), r.fillStyle = G.fill || k.nodeBg, r.beginPath(), r.roundRect(E.x, E.y, Br, na, ur), r.fill(), r.strokeStyle = ha.selected ? k.nodeSelectedBorder : G.stroke || k.nodeBorder, r.lineWidth = ha.selected ? 2 : G.strokeWidth || 1, r.beginPath(), r.roundRect(E.x, E.y, Br, na, ur), r.stroke(), G.accent) {
872
- var et = G.accent;
870
+ Et.length > 0 && ha && (r.textAlign = "start", r.textBaseline = "alphabetic");
871
+ for (var we = 0; we < Ct.length; we++) {
872
+ var sa = Ct[we], q = bt[sa.type], E = y(sa), wr = sa.width || C, da = sa.height || B, ur = q.radius || Za, Pt = sa.data || {};
873
+ if (ye && q.shadow !== !1 && (r.save(), r.shadowColor = q.shadowColor || M.nodeShadow, r.shadowBlur = q.shadowBlur || 6, r.shadowOffsetY = q.shadowOffsetY || 2, r.fillStyle = q.fill || M.nodeBg, r.beginPath(), r.roundRect(E.x, E.y, wr, da, ur), r.fill(), r.restore()), r.fillStyle = q.fill || M.nodeBg, r.beginPath(), r.roundRect(E.x, E.y, wr, da, ur), r.fill(), r.strokeStyle = sa.selected ? M.nodeSelectedBorder : q.stroke || M.nodeBorder, r.lineWidth = sa.selected ? 2 : q.strokeWidth || 1, r.beginPath(), r.roundRect(E.x, E.y, wr, da, ur), r.stroke(), q.accent) {
874
+ var et = q.accent;
873
875
  r.fillStyle = et.color || "#3b82f6";
874
- var Pa = et.width || 5;
875
- r.beginPath(), et.side === "right" ? r.roundRect(E.x + Br - Pa, E.y, Pa, na, [0, ur, ur, 0]) : et.side === "top" ? r.roundRect(E.x, E.y, Br, Pa, [ur, ur, 0, 0]) : et.side === "bottom" ? r.roundRect(E.x, E.y + na - Pa, Br, Pa, [0, 0, ur, ur]) : r.roundRect(E.x, E.y, Pa, na, [ur, 0, 0, ur]), r.fill();
876
- }
877
- if (G.icon && fa) {
878
- var Ar = G.icon, bo = Ar.dataField ? Ct[Ar.dataField] : Ar.text;
879
- if (bo) {
880
- r.font = (Ar.size || 18) + "px system-ui, sans-serif", r.textAlign = "center", r.textBaseline = "middle", r.fillStyle = Ar.color || k.nodeText;
881
- var Gl = E.x + (Ar.x !== void 0 ? Ar.x : 20), Il = E.y + (Ar.y !== void 0 ? Ar.y : na / 2);
882
- r.fillText(bo, Gl, Il);
883
- }
876
+ var Ga = et.width || 5;
877
+ r.beginPath(), et.side === "right" ? r.roundRect(E.x + wr - Ga, E.y, Ga, da, [0, ur, ur, 0]) : et.side === "top" ? r.roundRect(E.x, E.y, wr, Ga, [ur, ur, 0, 0]) : et.side === "bottom" ? r.roundRect(E.x, E.y + da - Ga, wr, Ga, [0, 0, ur, ur]) : r.roundRect(E.x, E.y, Ga, da, [ur, 0, 0, ur]), r.fill();
884
878
  }
885
- if (G.title && fa) {
886
- var kr = G.title, Jo = kr.dataField ? Ct[kr.dataField] : kr.text;
879
+ if (q.icon && ha) {
880
+ var Br = q.icon, Jo = Br.dataField ? Pt[Br.dataField] : Br.text;
887
881
  if (Jo) {
888
- r.font = kr.font || "600 13px system-ui, sans-serif", r.textAlign = kr.align || "left", r.textBaseline = "top", r.fillStyle = kr.color || k.nodeText;
889
- var Qo = E.x + (kr.x !== void 0 ? kr.x : 12), Zl = E.y + (kr.y !== void 0 ? kr.y : 12);
890
- r.fillText(Jo, Qo, Zl, Br - Qo + E.x - 12);
882
+ r.font = (Br.size || 18) + "px system-ui, sans-serif", r.textAlign = "center", r.textBaseline = "middle", r.fillStyle = Br.color || M.nodeText;
883
+ var Zl = E.x + (Br.x !== void 0 ? Br.x : 20), Kl = E.y + (Br.y !== void 0 ? Br.y : da / 2);
884
+ r.fillText(Jo, Zl, Kl);
885
+ }
886
+ }
887
+ if (q.title && ha) {
888
+ var Mr = q.title, Qo = Mr.dataField ? Pt[Mr.dataField] : Mr.text;
889
+ if (Qo) {
890
+ r.font = Mr.font || "600 13px system-ui, sans-serif", r.textAlign = Mr.align || "left", r.textBaseline = "top", r.fillStyle = Mr.color || M.nodeText;
891
+ var $o = E.x + (Mr.x !== void 0 ? Mr.x : 12), bl = E.y + (Mr.y !== void 0 ? Mr.y : 12);
892
+ r.fillText(Qo, $o, bl, wr - $o + E.x - 12);
891
893
  }
892
894
  }
893
- if (G.subtitle && fa) {
894
- var mr = G.subtitle, $o = mr.dataField ? Ct[mr.dataField] : mr.text;
895
- if ($o) {
896
- r.font = mr.font || "11px system-ui, sans-serif", r.textAlign = mr.align || "left", r.textBaseline = "top", r.fillStyle = mr.color || "#64748b";
897
- var Fo = E.x + (mr.x !== void 0 ? mr.x : 12), Kl = E.y + (mr.y !== void 0 ? mr.y : 32);
898
- r.fillText($o, Fo, Kl, Br - Fo + E.x - 12);
895
+ if (q.subtitle && ha) {
896
+ var kr = q.subtitle, Fo = kr.dataField ? Pt[kr.dataField] : kr.text;
897
+ if (Fo) {
898
+ r.font = kr.font || "11px system-ui, sans-serif", r.textAlign = kr.align || "left", r.textBaseline = "top", r.fillStyle = kr.color || "#64748b";
899
+ var Uo = E.x + (kr.x !== void 0 ? kr.x : 12), Jl = E.y + (kr.y !== void 0 ? kr.y : 32);
900
+ r.fillText(Fo, Uo, Jl, wr - Uo + E.x - 12);
899
901
  }
900
902
  }
901
- if (G.badge && fa) {
902
- var _r = G.badge, we = _r.dataField ? Ct[_r.dataField] : _r.text;
903
- if (we) {
904
- r.font = _r.font || "700 9px system-ui, sans-serif";
905
- var bl = r.measureText(we), Jl = _r.paddingX || 6, Ql = _r.paddingY || 3, Be = bl.width + Jl * 2, Ae = 14 + Ql, Uo = E.x + Br - Be / 2 - 4, co = E.y - Ae / 2;
906
- r.fillStyle = _r.bg || "#3b82f6", r.beginPath(), r.roundRect(Uo, co, Be, Ae, _r.radius || 7), r.fill(), r.fillStyle = _r.color || "#fff", r.textAlign = "center", r.textBaseline = "middle", r.fillText(we, Uo + Be / 2, co + Ae / 2);
903
+ if (q.badge && ha) {
904
+ var Ar = q.badge, Be = Ar.dataField ? Pt[Ar.dataField] : Ar.text;
905
+ if (Be) {
906
+ r.font = Ar.font || "700 9px system-ui, sans-serif";
907
+ var Ql = r.measureText(Be), $l = Ar.paddingX || 6, Fl = Ar.paddingY || 3, Ae = Ql.width + $l * 2, _e = 14 + Fl, co = E.x + wr - Ae / 2 - 4, Vo = E.y - _e / 2;
908
+ r.fillStyle = Ar.bg || "#3b82f6", r.beginPath(), r.roundRect(co, Vo, Ae, _e, Ar.radius || 7), r.fill(), r.fillStyle = Ar.color || "#fff", r.textAlign = "center", r.textBaseline = "middle", r.fillText(Be, co + Ae / 2, Vo + _e / 2);
907
909
  }
908
910
  }
909
911
  }
910
- if (_t.length > 0 && (r.textAlign = "start", r.textBaseline = "alphabetic"), Wl) {
911
- for (var _e = [], Ee = 0; Ee < dr; Ee++)
912
- for (var Vo = el(nr[Ee]), Le = 0; Le < Vo.length; Le++)
913
- _e.push(Vo[Le]);
914
- r.fillStyle = k.handleFill, r.beginPath();
915
- for (var Se = 0; Se < _e.length; Se++) {
916
- var Wt = _e[Se];
917
- r.moveTo(Wt.x + Do, Wt.y), r.arc(Wt.x, Wt.y, Do, 0, 6.2832);
918
- }
919
- r.fill(), r.strokeStyle = k.handleBorder, r.lineWidth = 1.5, r.stroke();
912
+ if (Ct.length > 0 && (r.textAlign = "start", r.textBaseline = "alphabetic"), ql) {
913
+ for (var Ee = [], Ce = 0; Ce < hr; Ce++)
914
+ for (var No = ol(Rr[Ce]), Le = 0; Le < No.length; Le++)
915
+ Ee.push(No[Le]);
916
+ r.fillStyle = M.handleFill, r.beginPath();
917
+ for (var Se = 0; Se < Ee.length; Se++) {
918
+ var qt = Ee[Se];
919
+ r.moveTo(qt.x + Oo, qt.y), r.arc(qt.x, qt.y, Oo, 0, 6.2832);
920
+ }
921
+ r.fill(), r.strokeStyle = M.handleBorder, r.lineWidth = 1.5, r.stroke();
920
922
  }
921
923
  }
922
924
  r.restore();
923
- var $l = (performance.now() - a).toFixed(1);
924
- qe++;
925
- var Pt = performance.now();
926
- if (Pt - Xo >= 1e3 && (Ho = qe, qe = 0, Xo = Pt), Pt - po >= 100) {
927
- po = Pt;
928
- var Fl = Math.round(-M.x / M.zoom), Ul = Math.round(-M.y / M.zoom);
925
+ var Ul = (performance.now() - a).toFixed(1);
926
+ Ge++;
927
+ var Gt = performance.now();
928
+ if (Gt - Ho >= 1e3 && (po = Ge, Ge = 0, Ho = Gt), Gt - rl >= 100) {
929
+ rl = Gt;
930
+ var cl = Math.round(-k.x / k.zoom), Vl = Math.round(-k.y / k.zoom);
929
931
  self.postMessage({
930
932
  type: "hud",
931
933
  data: {
932
- wx: Fl,
933
- wy: Ul,
934
- zoom: M.zoom.toFixed(2),
935
- renderMs: $l,
936
- fps: Ho,
937
- visible: Y.length > 0 ? jo(X, Yr, xa, Xr).length : 0,
934
+ wx: cl,
935
+ wy: Vl,
936
+ zoom: k.zoom.toFixed(2),
937
+ renderMs: Ul,
938
+ fps: po,
939
+ visible: H.length > 0 ? Yo(jr, Lr, D, Yr).length : 0,
938
940
  nodeCount: W.length,
939
- visibleNodes: dr,
940
- edgeCount: C.length
941
+ visibleNodes: hr,
942
+ edgeCount: S.length
941
943
  }
942
944
  });
943
945
  }
944
946
  }
945
947
  }
946
- `,lr=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",wr],{type:"text/javascript;charset=utf-8"});function eo(e){let t;try{if(t=lr&&(self.URL||self.webkitURL).createObjectURL(lr),!t)throw"";const n=new Worker(t,{type:"module",name:e==null?void 0:e.name});return n.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),n}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(wr),{type:"module",name:e==null?void 0:e.name})}}const Xn=new WeakMap;function to(e,t){if(Xn.has(e))return Xn.get(e);const n=e.transferControlToOffscreen(),r=new eo;r.onerror=o=>console.error("[infinite-canvas] worker error:",o.message,o),r.postMessage({type:"init",data:{...t,canvas:n}},[n]);const i={worker:r};return Xn.set(e,i),i}const ut=160,tt=60,no=10;function Mr({cards:e=[],nodes:t=[],edges:n=[],onHudUpdate:r,onNodesProcessed:i,onNodesChange:o,onEdgesChange:l,onConnect:h,onNodeClick:v,onNodeDragStart:f,onNodeDrag:y,onNodeDragStop:x,onEdgeClick:R,onEdgeDoubleClick:C,onEdgeMouseEnter:z,onEdgeMouseMove:W,onEdgeMouseLeave:j,onEdgeContextMenu:D,onNodeDoubleClick:F,onNodeMouseEnter:$,onNodeMouseMove:X,onNodeMouseLeave:A,onNodeContextMenu:P,onPaneClick:Z,onPaneContextMenu:q,onPaneMouseEnter:O,onPaneMouseMove:M,onPaneMouseLeave:d,onSelectionChange:b,onConnectStart:L,onConnectEnd:T,onInit:B,onMoveStart:Q,onMove:oe,onMoveEnd:te,onDelete:ce,onBeforeDelete:me,onError:Me,isValidConnection:ke,dark:le,gridSize:xe=40,zoomMin:ie=.1,zoomMax:fe=4,initialCamera:Ce={x:0,y:0,zoom:1},fitView:je=!1,fitViewOptions:ge,nodesDraggable:de=!0,nodesConnectable:Ae=!0,elementsSelectable:_e=!0,multiSelectionKeyCode:We="Shift",selectionOnDrag:nt=!1,selectionMode:De="partial",connectionMode:$e="loose",connectionRadius:Ie=20,connectOnClick:Ee=!1,snapToGrid:Ge=!1,snapGrid:rt=[15,15],deleteKeyCode:He=["Delete","Backspace"],panActivationKeyCode:Ue=" ",panOnScroll:Ke=!1,panOnScrollMode:zt="free",panOnScrollSpeed:ln=.5,zoomOnScroll:un=!0,zoomOnDoubleClick:dn=!0,zoomOnPinch:fn=!0,preventScrolling:Ot=!0,translateExtent:ht,nodeExtent:gt,defaultEdgeOptions:Pt={},autoPanOnNodeDrag:Nn=!0,autoPanOnConnect:In=!0,autoPanSpeed:ot=5,edgesReconnectable:cr=!1,elevateNodesOnSelect:Tn=!1,elevateEdgesOnSelect:Ln=!1,noDragClassName:Nt="nodrag",noPanClassName:It="nopan",onSelectionDragStart:Bn,onSelectionDrag:$n,onSelectionDragStop:An,edgeRouting:bt=!0}={}){const be=a.useRef(null),Tt=a.useRef(null),Se=a.useRef(null),ue=a.useRef({...Ce}),yt=a.useRef([...e]),ee=a.useRef([...t]),ze=a.useRef([...n]),hn=a.useRef(new Map),Lt=a.useRef(!1),Bt=a.useRef(null),[$t,jn]=a.useState(!1),Fe=a.useRef(null),Xe=a.useRef(null),At=a.useRef(null),st=a.useRef(null),gn=a.useRef(!1),Qe=a.useRef(null),[yn,xn]=a.useState({x:Ce.x,y:Ce.y,zoom:Ce.zoom}),[Ut,pn]=a.useState(null),xt=a.useMemo(()=>new Set,[]),it=a.useMemo(()=>new Set,[]),Je=a.useRef(!1),V=a.useRef({});V.current={onHudUpdate:r,onNodesProcessed:i,onNodesChange:o,onEdgesChange:l,onConnect:h,onNodeClick:v,onNodeDragStart:f,onNodeDrag:y,onNodeDragStop:x,onEdgeClick:R,onEdgeDoubleClick:C,onEdgeMouseEnter:z,onEdgeMouseMove:W,onEdgeMouseLeave:j,onEdgeContextMenu:D,onNodeDoubleClick:F,onNodeMouseEnter:$,onNodeMouseMove:X,onNodeMouseLeave:A,onNodeContextMenu:P,onPaneClick:Z,onPaneContextMenu:q,onPaneMouseEnter:O,onPaneMouseMove:M,onPaneMouseLeave:d,onSelectionChange:b,onConnectStart:L,onConnectEnd:T,onInit:B,onMoveStart:Q,onMove:oe,onMoveEnd:te,onDelete:ce,onBeforeDelete:me,onError:Me,onSelectionDragStart:Bn,onSelectionDrag:$n,onSelectionDragStop:An,isValidConnection:ke};const at={get current(){return V.current.onConnect}},wt={get current(){return V.current.onNodeClick}},jt={get current(){return V.current.onNodeDragStart}},Dt={get current(){return V.current.onNodeDrag}},Ht={get current(){return V.current.onNodeDragStop}},dt={get current(){return V.current.onEdgeClick}},_t={get current(){return V.current.onPaneClick}},Mt={get current(){return V.current.onSelectionChange}},Wt={get current(){return V.current.onHudUpdate}},Ft={get current(){return V.current.onNodesProcessed}};a.useEffect(()=>{const u=c=>{c.key===We&&(gn.current=!0),c.key===Ue&&(Je.current=!0)},p=c=>{c.key===We&&(gn.current=!1),c.key===Ue&&(Je.current=!1)};return window.addEventListener("keydown",u),window.addEventListener("keyup",p),()=>{window.removeEventListener("keydown",u),window.removeEventListener("keyup",p)}},[We,Ue]);const Pe={get current(){return V.current.onNodesChange?Yt:null}},Yt=u=>{var c,g,k;(g=(c=V.current).onNodesChange)==null||g.call(c,u);const p=[];for(let S=0;S<u.length;S++)u[S].type==="select"&&p.push({id:u[S].id,selected:u[S].selected});p.length>0&&((k=Se.current)==null||k.postMessage({type:"nodeSelections",data:{selections:p}}))},Te={get current(){return V.current.onEdgesChange?Dn:null}},Dn=u=>{var c,g,k;(g=(c=V.current).onEdgesChange)==null||g.call(c,u);const p=[];for(let S=0;S<u.length;S++)u[S].type==="select"&&p.push({id:u[S].id,selected:u[S].selected});p.length>0&&((k=Se.current)==null||k.postMessage({type:"edgeSelections",data:{selections:p}}))},pt=a.useCallback(()=>{var g;const u=ee.current.filter(k=>k.selected),p=ze.current.filter(k=>k.selected),c={nodes:u,edges:p};(g=Mt.current)==null||g.call(Mt,c);for(const k of it)k(c)},[it]);a.useEffect(()=>{var u;yt.current=[...e],(u=Se.current)==null||u.postMessage({type:"cards",data:{cards:[...e]}})},[e]);const Rt=a.useCallback(u=>{const p={};for(const c of u)p[c.id]=c;return u.map(c=>{if(!c.parentId)return c;const g=p[c.parentId];if(!g)return c;let k=c.position.x,S=c.position.y,m=g;for(;m;)k+=m.position.x,S+=m.position.y,m=m.parentId?p[m.parentId]:null;return{...c,_absolutePosition:{x:k,y:S}}})},[]),ct=a.useRef([]),mt=a.useCallback(u=>{const p=hn.current;if(!p||p.size===0)return u;const c={};for(const[,g]of p)c[g.nodeId]||(c[g.nodeId]=[]),c[g.nodeId].push({id:g.id,type:g.type,position:g.position,x:g.x,y:g.y});return u.map(g=>{const k=c[g.id];return k&&k.length>0?{...g,handles:k}:g})},[]),mn=a.useCallback(()=>{var p;if(Fe.current)return;const u=mt(ct.current);(p=Se.current)==null||p.postMessage({type:"nodes",data:{nodes:u}})},[mt]);a.useEffect(()=>{var c,g;if(Fe.current){const k=Fe.current.id,S=new Set([k,...Fe.current.selectedStarts.map(w=>w.id)]),m={};for(const w of ee.current)S.has(w.id)&&(m[w.id]={...w.position});ee.current=[...t];for(const w of ee.current)m[w.id]&&(w.position=m[w.id]);ct.current=Rt(ee.current);const E=mt(ct.current);(c=Se.current)==null||c.postMessage({type:"nodes",data:{nodes:E}});return}ee.current=[...t];const u=Rt(t);ct.current=u;const p=mt(u);(g=Se.current)==null||g.postMessage({type:"nodes",data:{nodes:p}})},[t,Rt,mt]),a.useEffect(()=>{var u;ze.current=[...n],(u=Se.current)==null||u.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const Le=a.useCallback((u,p)=>{const c=be.current;if(!c)return{x:0,y:0};const g=c.getBoundingClientRect(),k=ue.current;return{x:(u-g.left-k.x)/k.zoom,y:(p-g.top-k.y)/k.zoom}},[]),et=a.useCallback((u,p)=>{const c=ct.current.length>0?ct.current:ee.current;let g=null;for(let k=c.length-1;k>=0;k--){const S=c[k];if(S.hidden||S._customRendered)continue;const m=S._absolutePosition||S.position,E=S.width||ut,w=S.height||tt;if(u>=m.x&&u<=m.x+E&&p>=m.y&&p<=m.y+w){if(S.type==="group"){g||(g=S);continue}return S}}return g},[]),ye=a.useCallback((u,p)=>{const c=p.width||ut,g=p.height||tt;if(u.x!==void 0&&u.y!==void 0)return{x:p.position.x+u.x,y:p.position.y+u.y};switch(u.position||(u.type==="source"?"right":"left")){case"top":return{x:p.position.x+c/2,y:p.position.y};case"bottom":return{x:p.position.x+c/2,y:p.position.y+g};case"left":return{x:p.position.x,y:p.position.y+g/2};case"right":return{x:p.position.x+c,y:p.position.y+g/2};default:return{x:p.position.x+c,y:p.position.y+g/2}}},[]),qt=a.useCallback(u=>{const p=u.width||ut,c=u.height||tt;if(u.handles&&u.handles.length>0)return u.handles.map(w=>{const H=ye(w,u);return{id:w.id||null,type:w.type,x:H.x,y:H.y}});const g=u.targetPosition||"left",k=u.sourcePosition||"right",S=w=>{switch(w){case"top":return{x:u.position.x+p/2,y:u.position.y};case"bottom":return{x:u.position.x+p/2,y:u.position.y+c};case"left":return{x:u.position.x,y:u.position.y+c/2};case"right":return{x:u.position.x+p,y:u.position.y+c/2};default:return{x:u.position.x+p,y:u.position.y+c/2}}},m=S(g),E=S(k);return[{id:null,type:"target",x:m.x,y:m.y},{id:null,type:"source",x:E.x,y:E.y}]},[ye]),kt=a.useCallback((u,p)=>{const c=ee.current,g=ue.current,k=Math.max(no,Ie)/g.zoom;for(let S=c.length-1;S>=0;S--){const m=c[S];if(m.hidden)continue;const E=qt(m);for(const w of E)if(Math.abs(u-w.x)<k&&Math.abs(p-w.y)<k)return{nodeId:m.id,handleId:w.id,type:w.type,x:w.x,y:w.y}}return null},[qt]),Ve=a.useCallback((u,p)=>{const g=8/ue.current.zoom,k=ee.current,S={};for(let m=0;m<k.length;m++)S[k[m].id]=k[m];for(let m=ze.current.length-1;m>=0;m--){const E=ze.current[m],w=S[E.source],H=S[E.target];if(!w||!H)continue;const I=w.width||ut,Y=w.height||tt,G=H.height||tt,re=w.position.x+I,K=w.position.y+Y/2,U=H.position.x,ae=H.position.y+G/2;if(ro(u,p,re,K,U,ae)<g)return E}return null},[]);a.useEffect(()=>{const u=Tt.current,p=be.current;if(!u||!p)return;const c=p.getBoundingClientRect(),g=le!==void 0?le:matchMedia("(prefers-color-scheme: dark)").matches,k=Rt(ee.current);ct.current=k;const S=mt(k),{worker:m}=to(u,{width:c.width,height:c.height,camera:ue.current,cards:yt.current,nodes:S,edges:ze.current,dark:g,gridSize:xe,edgeRouting:bt});m.onmessage=I=>{var Y,G,re,K;I.data.type==="hud"&&((Y=Wt.current)==null||Y.call(Wt,I.data.data)),I.data.type==="ready"&&jn(!0),I.data.type==="nodesProcessed"&&((G=Ft.current)==null||G.call(Ft,I.data.data)),I.data.type==="error"&&((K=(re=V.current).onError)==null||K.call(re,"worker-error",I.data.message||"Canvas worker error"))},m.onerror=I=>{var Y,G;(G=(Y=V.current).onError)==null||G.call(Y,"worker-error",I.message||"Canvas worker crashed")},Se.current=m;const E=new ResizeObserver(I=>{const{width:Y,height:G}=I[0].contentRect;m.postMessage({type:"resize",data:{width:Y,height:G}})});E.observe(p);let w,H;return le===void 0&&(w=matchMedia("(prefers-color-scheme: dark)"),H=I=>m.postMessage({type:"theme",data:{dark:I.matches}}),w.addEventListener("change",H)),()=>{E.disconnect(),w&&H&&w.removeEventListener("change",H),Se.current=null}},[]),a.useEffect(()=>{var u;le!==void 0&&((u=Se.current)==null||u.postMessage({type:"theme",data:{dark:le}}))},[le]),a.useEffect(()=>{var u;(u=Se.current)==null||u.postMessage({type:"edgeRouting",data:{enabled:bt}})},[bt]);const Ct=a.useRef(0),we=a.useCallback((u=null)=>{var g,k,S;const p=ue.current;if(ht){const m=be.current;if(m){const E=m.getBoundingClientRect(),w=-ht[1][0]*p.zoom+E.width,H=-ht[1][1]*p.zoom+E.height,I=-ht[0][0]*p.zoom,Y=-ht[0][1]*p.zoom;p.x=Math.min(I,Math.max(w,p.x)),p.y=Math.min(Y,Math.max(H,p.y))}}(g=Se.current)==null||g.postMessage({type:"camera",data:{camera:{...p}}});const c={x:p.x,y:p.y,zoom:p.zoom};(S=(k=V.current).onMove)==null||S.call(k,u,c);for(const m of xt)m(c);cancelAnimationFrame(Ct.current),Ct.current=requestAnimationFrame(()=>{xn({x:p.x,y:p.y,zoom:p.zoom})})},[xt,ht]),vt=a.useCallback(()=>{var c,g;const u=Xe.current,p=At.current;u&&p?((c=Se.current)==null||c.postMessage({type:"connecting",data:{from:u.startPos,to:p,_routedPoints:null}}),pn({source:u.sourceId,sourceHandle:u.sourceHandle,target:null,targetHandle:null})):((g=Se.current)==null||g.postMessage({type:"connecting",data:null}),pn(null))},[]),lt=a.useCallback(()=>{var p,c;const u=st.current;u?(p=Se.current)==null||p.postMessage({type:"selectionBox",data:u}):(c=Se.current)==null||c.postMessage({type:"selectionBox",data:null})},[]),Zt=a.useCallback(u=>{var m,E,w,H,I,Y,G,re,K,U,ae,Re,Be,Ye,qe,Oe,Kt,ft;const p=ee.current.length>0,c=Le(u.clientX,u.clientY),g=gn.current;if(p&&Ae&&!g){const J=kt(c.x,c.y);if(Ee&&Qe.current&&J){const se=Qe.current;if(J.nodeId!==se.nodeId){const Ze=se.handleType==="target"?{source:J.nodeId,target:se.nodeId,sourceHandle:J.handleId||null,targetHandle:se.handleId}:{source:se.nodeId,target:J.nodeId,sourceHandle:se.handleId,targetHandle:J.handleId||null};(V.current.isValidConnection?V.current.isValidConnection(Ze):!0)&&((m=at.current)==null||m.call(at,{...Ze,...Pt}))}Qe.current=null;return}if($e==="strict"?J&&J.type==="source":J!=null){if(Ee){Qe.current={nodeId:J.nodeId,handleId:J.handleId||null,handleType:J.type},(w=(E=V.current).onConnectStart)==null||w.call(E,u,{nodeId:J.nodeId,handleId:J.handleId,handleType:J.type});return}Xe.current={sourceId:J.nodeId,sourceHandle:J.handleId||null,sourceType:J.type,startPos:{x:J.x,y:J.y}},At.current={x:c.x,y:c.y},(H=be.current)==null||H.setPointerCapture(u.pointerId),(Y=(I=V.current).onConnectStart)==null||Y.call(I,u,{nodeId:J.nodeId,handleId:J.handleId,handleType:J.type}),vt();return}}const k=J=>{var se;let ve=J;for(;ve&&ve!==be.current;){if((se=ve.classList)!=null&&se.contains(Nt))return!0;ve=ve.parentElement}return!1},S=J=>{var se;let ve=J;for(;ve&&ve!==be.current;){if((se=ve.classList)!=null&&se.contains(It))return!0;ve=ve.parentElement}return!1};if(p){const J=et(c.x,c.y);if(J){if(Pe.current&&_e){const ve=[];if(g)ve.push({id:J.id,type:"select",selected:!J.selected});else if(!J.selected){for(const se of ee.current)se.id===J.id?ve.push({id:se.id,type:"select",selected:!0}):se.selected&&ve.push({id:se.id,type:"select",selected:!1});if(Te.current){const se=ze.current.filter(he=>he.selected).map(he=>({id:he.id,type:"select",selected:!1}));se.length&&Te.current(se)}}if(ve.length){if(Pe.current(ve),Tn&&!g){const se=ee.current.findIndex(he=>he.id===J.id);se>=0&&se<ee.current.length-1&&Pe.current([{id:J.id,type:"remove"},{type:"add",item:{...ee.current[se],selected:!0}}])}pt()}}if((G=wt.current)==null||G.call(wt,u,J),de&&!k(u.target)){const ve=J.selected;let se=null;if(J.parentId&&J.extent==="parent"){const he=ee.current.find(Ze=>Ze.id===J.parentId);if(he){const Ze=he.width||ut,en=he.height||tt,vn=J.width||((re=J.measured)==null?void 0:re.width)||ut,tn=J.height||((K=J.measured)==null?void 0:K.height)||tt;se={minX:0,minY:0,maxX:Ze-vn,maxY:en-tn}}}if(Fe.current={id:J.id,startPos:{...J.position},startMouse:{x:c.x,y:c.y},parentClamp:se,parentId:J.parentId||null,selectedStarts:ve?ee.current.filter(he=>he.selected&&he.id!==J.id).map(he=>{var en,vn;let Ze=null;if(he.parentId&&he.extent==="parent"){const tn=ee.current.find(Yn=>Yn.id===he.parentId);if(tn){const Yn=tn.width||ut,Wr=tn.height||tt,Fr=he.width||((en=he.measured)==null?void 0:en.width)||ut,Yr=he.height||((vn=he.measured)==null?void 0:vn.height)||tt;Ze={minX:0,minY:0,maxX:Yn-Fr,maxY:Wr-Yr}}}return{id:he.id,startPos:{...he.position},parentClamp:Ze,parentId:he.parentId||null}}):[]},(U=be.current)==null||U.setPointerCapture(u.pointerId),(ae=jt.current)==null||ae.call(jt,u,J),Fe.current.selectedStarts.length>0){const he=ee.current.filter(Ze=>Ze.selected);(Be=(Re=V.current).onSelectionDragStart)==null||Be.call(Re,u,he)}if(Pe.current){const he=[{id:J.id,type:"position",dragging:!0}];for(const Ze of Fe.current.selectedStarts)he.push({id:Ze.id,type:"position",dragging:!0});Pe.current(he)}}return}}if(ze.current.length>0&&_e){const J=Ve(c.x,c.y);if(J){if(Te.current){const ve=[];if(g)ve.push({id:J.id,type:"select",selected:!J.selected});else{for(const se of ze.current)se.id===J.id?ve.push({id:se.id,type:"select",selected:!0}):se.selected&&ve.push({id:se.id,type:"select",selected:!1});if(Pe.current){const se=ee.current.filter(he=>he.selected).map(he=>({id:he.id,type:"select",selected:!1}));se.length&&Pe.current(se)}}if(ve.length){if(Te.current(ve),Ln&&!g){const se=ze.current.findIndex(he=>he.id===J.id);se>=0&&se<ze.current.length-1&&Te.current([{id:J.id,type:"remove"},{type:"add",item:{...ze.current[se],selected:!0}}])}pt()}}(Ye=dt.current)==null||Ye.call(dt,u,J);return}}if(!g){const J=ee.current.filter(se=>se.selected).map(se=>({id:se.id,type:"select",selected:!1})),ve=ze.current.filter(se=>se.selected).map(se=>({id:se.id,type:"select",selected:!1}));J.length&&Pe.current&&Pe.current(J),ve.length&&Te.current&&Te.current(ve),(J.length||ve.length)&&pt()}if((qe=_t.current)==null||qe.call(_t,u),nt||g){st.current={startWorld:{...c},endWorld:{...c}},(Oe=be.current)==null||Oe.setPointerCapture(u.pointerId),lt();return}S(u.target)||(Lt.current=!0,Bt.current={x:u.clientX,y:u.clientY},(Kt=be.current)==null||Kt.classList.add("dragging"),(ft=be.current)==null||ft.setPointerCapture(u.pointerId))},[Le,et,kt,Ve,de,Ae,_e,nt,vt,lt,pt,Nt,It]),Gt=a.useCallback(u=>{var c,g,k,S;if(Xe.current){if(At.current=Le(u.clientX,u.clientY),vt(),In){const m=be.current;if(m){const E=m.getBoundingClientRect(),w=40,H=u.clientX-E.left,I=u.clientY-E.top;let Y=0,G=0;H<w?Y=ot:H>E.width-w&&(Y=-ot),I<w?G=ot:I>E.height-w&&(G=-ot),(Y||G)&&(ue.current.x+=Y,ue.current.y+=G,we(u))}}return}if(st.current){st.current.endWorld=Le(u.clientX,u.clientY),lt();const m=st.current,E=Math.min(m.startWorld.x,m.endWorld.x),w=Math.min(m.startWorld.y,m.endWorld.y),H=Math.max(m.startWorld.x,m.endWorld.x),I=Math.max(m.startWorld.y,m.endWorld.y);if(Pe.current){const Y=[];for(const G of ee.current){if(G.hidden)continue;const re=G.width||ut,K=G.height||tt,U=De==="full"?G.position.x>=E&&G.position.x+re<=H&&G.position.y>=w&&G.position.y+K<=I:G.position.x+re>E&&G.position.x<H&&G.position.y+K>w&&G.position.y<I;U!==!!G.selected&&Y.push({id:G.id,type:"select",selected:U})}Y.length&&Pe.current(Y)}return}if(Fe.current){const m=Le(u.clientX,u.clientY),E=Fe.current,w=m.x-E.startMouse.x,H=m.y-E.startMouse.y;let I={x:E.startPos.x+w,y:E.startPos.y+H};if(Ge&&(I=Zn(I,rt)),gt&&(I=Gn(I,gt)),E.parentClamp){const U=E.parentClamp;I={x:Math.max(U.minX,Math.min(I.x,U.maxX)),y:Math.max(U.minY,Math.min(I.y,U.maxY))}}const Y=[{id:E.id,position:I}];for(const U of E.selectedStarts){let ae={x:U.startPos.x+w,y:U.startPos.y+H};if(Ge&&(ae=Zn(ae,rt)),gt&&(ae=Gn(ae,gt)),U.parentClamp){const Re=U.parentClamp;ae={x:Math.max(Re.minX,Math.min(ae.x,Re.maxX)),y:Math.max(Re.minY,Math.min(ae.y,Re.maxY))}}Y.push({id:U.id,position:ae})}const G=[];for(const U of Y){const ae=ee.current.find(Re=>Re.id===U.id);if(ae){ae.position=U.position,ae.dragging=!0;let Re=U.position;if(ae.parentId){let Be=ee.current.find(Oe=>Oe.id===ae.parentId),Ye=U.position.x,qe=U.position.y;for(;Be;)Ye+=Be.position.x,qe+=Be.position.y,Be=Be.parentId?ee.current.find(Oe=>Oe.id===Be.parentId):null;Re={x:Ye,y:qe}}G.push({id:U.id,position:U.position,_absolutePosition:Re,width:ae.width,height:ae.height,dragging:!0,selected:ae.selected})}}const re=new Set(Y.map(U=>U.id));for(const U of ee.current)if(U.parentId&&re.has(U.parentId)&&!re.has(U.id)){let ae=ee.current.find(Ye=>Ye.id===U.parentId),Re=U.position.x,Be=U.position.y;for(;ae;)Re+=ae.position.x,Be+=ae.position.y,ae=ae.parentId?ee.current.find(Ye=>Ye.id===ae.parentId):null;G.push({id:U.id,position:U.position,_absolutePosition:{x:Re,y:Be},width:U.width,height:U.height,dragging:!1,selected:U.selected})}if((c=Se.current)==null||c.postMessage({type:"nodePositions",data:{updates:G}}),Nn){const U=be.current;if(U){const ae=U.getBoundingClientRect(),Re=40,Be=u.clientX-ae.left,Ye=u.clientY-ae.top;let qe=0,Oe=0;Be<Re?qe=ot:Be>ae.width-Re&&(qe=-ot),Ye<Re?Oe=ot:Ye>ae.height-Re&&(Oe=-ot),(qe||Oe)&&(ue.current.x+=qe,ue.current.y+=Oe,we(u))}}const K=ee.current.find(U=>U.id===E.id);if(K&&((g=Dt.current)==null||g.call(Dt,u,K)),E.selectedStarts.length>0){const U=ee.current.filter(ae=>ae.selected);(S=(k=V.current).onSelectionDrag)==null||S.call(k,u,U)}return}if(!Lt.current)return;const p=ue.current;p.x+=u.clientX-Bt.current.x,p.y+=u.clientY-Bt.current.y,Bt.current={x:u.clientX,y:u.clientY},we()},[we,Le,vt,lt]),Qt=a.useCallback(u=>{var p,c,g,k,S,m,E,w;if(Xe.current){const H=Le(u.clientX,u.clientY),I=kt(H.x,H.y);if(I&&I.nodeId!==Xe.current.sourceId&&($e==="loose"||I.type==="target")){const re=Xe.current.sourceType==="target"?{source:I.nodeId,target:Xe.current.sourceId,sourceHandle:I.handleId||null,targetHandle:Xe.current.sourceHandle}:{source:Xe.current.sourceId,target:I.nodeId,sourceHandle:Xe.current.sourceHandle,targetHandle:I.handleId||null};(V.current.isValidConnection?V.current.isValidConnection(re):!0)&&((p=at.current)==null||p.call(at,{...re,...Pt}))}(g=(c=V.current).onConnectEnd)==null||g.call(c,u.nativeEvent||u),Xe.current=null,At.current=null,vt();return}if(st.current){st.current=null,lt(),pt();return}if(Fe.current){const H=Fe.current,I=ee.current.find(re=>re.id===H.id),Y=[{id:H.id,position:I?{...I.position}:H.startPos,_absolutePosition:I?{...I.position}:H.startPos,dragging:!1}];for(const re of H.selectedStarts){const K=ee.current.find(U=>U.id===re.id);Y.push({id:re.id,position:K?{...K.position}:re.startPos,_absolutePosition:K?{...K.position}:re.startPos,dragging:!1})}if((k=Se.current)==null||k.postMessage({type:"nodePositions",data:{updates:Y}}),Pe.current){const re=Y.map(K=>({id:K.id,type:"position",position:K.position,dragging:!1}));Pe.current(re)}if(H.selectedStarts.length>0){const re=ee.current.filter(K=>K.selected);(m=(S=V.current).onSelectionDragStop)==null||m.call(S,u,re)}requestAnimationFrame(()=>{Fe.current=null});const G=ee.current.find(re=>re.id===H.id);G&&((E=Ht.current)==null||E.call(Ht,u,G));return}Lt.current=!1,(w=be.current)==null||w.classList.remove("dragging")},[Le,kt,vt,lt,pt]);a.useEffect(()=>{const u=be.current;if(!u)return;const p=c=>{Ot&&c.preventDefault();const g=ue.current;if(Ke||Je.current){const w=ln;zt==="horizontal"?g.x-=c.deltaY*w:(zt==="vertical"||(g.x-=c.deltaX*w),g.y-=c.deltaY*w),we(c);return}if(!un)return;const k=c.deltaY>0?.92:1.08,S=u.getBoundingClientRect(),m=c.clientX-S.left,E=c.clientY-S.top;g.x=m-(m-g.x)*k,g.y=E-(E-g.y)*k,g.zoom=Math.min(fe,Math.max(ie,g.zoom*k)),we(c)};return u.addEventListener("wheel",p,{passive:!Ot}),()=>u.removeEventListener("wheel",p)},[we,ie,fe,Ke,zt,ln,un,Ot]),a.useEffect(()=>{if(!fn)return;const u=be.current;if(!u)return;let p=0,c=null;const g=m=>{if(m.touches.length===2){const E=m.touches[0].clientX-m.touches[1].clientX,w=m.touches[0].clientY-m.touches[1].clientY;p=Math.hypot(E,w);const H=u.getBoundingClientRect();c={x:(m.touches[0].clientX+m.touches[1].clientX)/2-H.left,y:(m.touches[0].clientY+m.touches[1].clientY)/2-H.top},m.preventDefault()}},k=m=>{if(m.touches.length===2&&p>0){m.preventDefault();const E=m.touches[0].clientX-m.touches[1].clientX,w=m.touches[0].clientY-m.touches[1].clientY,H=Math.hypot(E,w),I=H/p;p=H;const Y=ue.current,G=c.x,re=c.y;Y.x=G-(G-Y.x)*I,Y.y=re-(re-Y.y)*I,Y.zoom=Math.min(fe,Math.max(ie,Y.zoom*I)),we(m)}},S=()=>{p=0,c=null};return u.addEventListener("touchstart",g,{passive:!1}),u.addEventListener("touchmove",k,{passive:!1}),u.addEventListener("touchend",S),()=>{u.removeEventListener("touchstart",g),u.removeEventListener("touchmove",k),u.removeEventListener("touchend",S)}},[fn,we,ie,fe]),a.useEffect(()=>{if(!dn)return;const u=be.current;if(!u)return;const p=c=>{var I,Y,G,re;const g=Le(c.clientX,c.clientY);if(et(g.x,g.y)){(Y=(I=V.current).onNodeDoubleClick)==null||Y.call(I,c,et(g.x,g.y));return}const k=Ve(g.x,g.y);if(k){(re=(G=V.current).onEdgeDoubleClick)==null||re.call(G,c,k);return}const S=1.5,m=u.getBoundingClientRect(),E=c.clientX-m.left,w=c.clientY-m.top,H=ue.current;H.x=E-(E-H.x)*S,H.y=w-(w-H.y)*S,H.zoom=Math.min(fe,Math.max(ie,H.zoom*S)),we(c)};return u.addEventListener("dblclick",p),()=>u.removeEventListener("dblclick",p)},[dn,we,ie,fe,Le,et,Ve]),a.useEffect(()=>{const u=be.current;if(!u)return;const p=c=>{var m,E,w,H,I,Y;const g=Le(c.clientX,c.clientY),k=et(g.x,g.y);if(k){(E=(m=V.current).onNodeContextMenu)==null||E.call(m,c,k);return}const S=Ve(g.x,g.y);if(S){(H=(w=V.current).onEdgeContextMenu)==null||H.call(w,c,S);return}(Y=(I=V.current).onPaneContextMenu)==null||Y.call(I,c)};return u.addEventListener("contextmenu",p),()=>u.removeEventListener("contextmenu",p)},[Le,et,Ve]),a.useEffect(()=>{const u=be.current;if(!u)return;let p=null,c=null;const g=m=>{var H,I,Y,G,re,K,U,ae,Re,Be,Ye,qe,Oe,Kt;if((I=(H=V.current).onPaneMouseMove)==null||I.call(H,m),Lt.current||Fe.current||Xe.current||st.current)return;const E=Le(m.clientX,m.clientY),w=et(E.x,E.y);if(w!==p&&(p&&((G=(Y=V.current).onNodeMouseLeave)==null||G.call(Y,m,p)),w&&((K=(re=V.current).onNodeMouseEnter)==null||K.call(re,m,w)),p=w),w&&((ae=(U=V.current).onNodeMouseMove)==null||ae.call(U,m,w)),!w){const ft=Ve(E.x,E.y);ft!==c&&(c&&((Be=(Re=V.current).onEdgeMouseLeave)==null||Be.call(Re,m,c)),ft&&((qe=(Ye=V.current).onEdgeMouseEnter)==null||qe.call(Ye,m,ft)),c=ft),ft&&((Kt=(Oe=V.current).onEdgeMouseMove)==null||Kt.call(Oe,m,ft))}},k=m=>{var E,w;return(w=(E=V.current).onPaneMouseEnter)==null?void 0:w.call(E,m)},S=m=>{var E,w,H,I,Y,G;(w=(E=V.current).onPaneMouseLeave)==null||w.call(E,m),p&&((I=(H=V.current).onNodeMouseLeave)==null||I.call(H,m,p),p=null),c&&((G=(Y=V.current).onEdgeMouseLeave)==null||G.call(Y,m,c),c=null)};return u.addEventListener("mousemove",g),u.addEventListener("mouseenter",k),u.addEventListener("mouseleave",S),()=>{u.removeEventListener("mousemove",g),u.removeEventListener("mouseenter",k),u.removeEventListener("mouseleave",S)}},[Le,et,Ve]),a.useEffect(()=>{const u=Array.isArray(He)?He:[He],p=async c=>{var g,k,S,m;if(u.includes(c.key)){if(c.target.tagName==="INPUT"||c.target.tagName==="TEXTAREA"||c.target.isContentEditable)return;const E=ee.current.filter(I=>I.selected),w=ze.current.filter(I=>I.selected);if(!E.length&&!w.length)return;if(V.current.onBeforeDelete)try{if(!await V.current.onBeforeDelete({nodes:E,edges:w}))return}catch(I){(k=(g=V.current).onError)==null||k.call(g,"before-delete-error",I.message||"onBeforeDelete threw an error");return}const H=new Set(E.map(I=>I.id));if(E.length&&Pe.current&&(Pe.current(E.map(I=>({id:I.id,type:"remove"}))),Te.current)){const I=ze.current.filter(Y=>H.has(Y.source)||H.has(Y.target));I.length&&Te.current(I.map(Y=>({id:Y.id,type:"remove"})))}w.length&&Te.current&&Te.current(w.map(I=>({id:I.id,type:"remove"}))),(m=(S=V.current).onDelete)==null||m.call(S,{nodes:E,edges:w})}if((c.ctrlKey||c.metaKey)&&c.key==="a"){if(c.target.tagName==="INPUT"||c.target.tagName==="TEXTAREA")return;if(c.preventDefault(),Pe.current){const E=ee.current.filter(w=>!w.selected).map(w=>({id:w.id,type:"select",selected:!0}));E.length&&Pe.current(E)}if(Te.current){const E=ze.current.filter(w=>!w.selected).map(w=>({id:w.id,type:"select",selected:!0}));E.length&&Te.current(E)}}};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[He]);const Jt=a.useRef(!1);a.useEffect(()=>{var u,p;if(!Jt.current&&Se.current){if(Jt.current=!0,je&&ee.current.length>0){const c=be.current;if(c){const g=c.getBoundingClientRect(),k=(ge==null?void 0:ge.padding)??.1,S=Mn(ee.current),m=Xt(S,g.width,g.height,k);ge!=null&&ge.maxZoom&&(m.zoom=Math.min(m.zoom,ge.maxZoom)),ge!=null&&ge.minZoom&&(m.zoom=Math.max(m.zoom,ge.minZoom)),ue.current=m,we()}}(p=(u=V.current).onInit)==null||p.call(u,{getNodes:()=>[...ee.current],getEdges:()=>[...ze.current],getNode:c=>ee.current.find(g=>g.id===c),getEdge:c=>ze.current.find(g=>g.id===c),getViewport:()=>({...ue.current}),getZoom:()=>ue.current.zoom,setViewport:c=>{ue.current={x:c.x??ue.current.x,y:c.y??ue.current.y,zoom:c.zoom??ue.current.zoom},we()},fitView:(c={})=>{const g=be.current;if(!g||!ee.current.length)return;const k=g.getBoundingClientRect(),S=c.nodes?ee.current.filter(w=>c.nodes.some(H=>H.id===w.id)):ee.current;if(!S.length)return;const m=Mn(S),E=Xt(m,k.width,k.height,c.padding??.1);c.maxZoom&&(E.zoom=Math.min(E.zoom,c.maxZoom)),c.minZoom&&(E.zoom=Math.max(E.zoom,c.minZoom)),ue.current=E,we()},screenToFlowPosition:c=>Le(c.x,c.y),flowToScreenPosition:c=>{const g=ue.current,k=be.current;if(!k)return{x:0,y:0};const S=k.getBoundingClientRect();return{x:c.x*g.zoom+g.x+S.left,y:c.y*g.zoom+g.y+S.top}},zoomIn:()=>{const c=ue.current;c.zoom=Math.min(fe,c.zoom*1.2),we()},zoomOut:()=>{const c=ue.current;c.zoom=Math.max(ie,c.zoom/1.2),we()},zoomTo:c=>{ue.current.zoom=Math.min(fe,Math.max(ie,c)),we()},setNodes:c=>{var g,k;(k=(g=V.current).onNodesChange)==null||k.call(g,[...ee.current.map(S=>({id:S.id,type:"remove"})),...(typeof c=="function"?c(ee.current):c).map(S=>({type:"add",item:S}))])},setEdges:c=>{var g,k;(k=(g=V.current).onEdgesChange)==null||k.call(g,[...ze.current.map(S=>({id:S.id,type:"remove"})),...(typeof c=="function"?c(ze.current):c).map(S=>({type:"add",item:S}))])},addNodes:c=>{var k,S;const g=Array.isArray(c)?c:[c];(S=(k=V.current).onNodesChange)==null||S.call(k,g.map(m=>({type:"add",item:m})))},addEdges:c=>{var k,S;const g=Array.isArray(c)?c:[c];(S=(k=V.current).onEdgesChange)==null||S.call(k,g.map(m=>({type:"add",item:m})))},deleteElements:({nodes:c=[],edges:g=[]})=>{var k,S,m,E;c.length&&((S=(k=V.current).onNodesChange)==null||S.call(k,c.map(w=>({id:w.id,type:"remove"})))),g.length&&((E=(m=V.current).onEdgesChange)==null||E.call(m,g.map(w=>({id:w.id,type:"remove"}))))},updateNodeData:(c,g)=>{var m,E;const k=ee.current.find(w=>w.id===c);if(!k)return;const S=typeof g=="function"?g(k.data):{...k.data,...g};(E=(m=V.current).onNodesChange)==null||E.call(m,[{id:c,type:"replace",item:{...k,data:S}}])},toObject:()=>({nodes:[...ee.current],edges:[...ze.current],viewport:{...ue.current}}),setCenter:(c,g,k={})=>{const S=be.current;if(!S)return;const m=S.getBoundingClientRect(),E=k.zoom??ue.current.zoom;ue.current={x:m.width/2-c*E,y:m.height/2-g*E,zoom:E},we()},fitBounds:(c,g={})=>{const k=be.current;if(!k)return;const S=k.getBoundingClientRect(),m=Xt(c,S.width,S.height,g.padding??.1);ue.current=m,we()}})}});const Vt=a.useCallback(()=>{ue.current={...Ce},we()},[we,Ce]),Hn=a.useCallback(u=>{var p;if(u)yt.current.push(u);else{const c=ue.current,g=be.current;if(!g)return;const k=g.getBoundingClientRect(),S=Math.round(-c.x/c.zoom+k.width/2/c.zoom),m=Math.round(-c.y/c.zoom+k.height/2/c.zoom);yt.current.push({x:S-80,y:m-45,w:160,h:90,title:"Note "+(yt.current.length+1),body:"Added at viewport center"})}(p=Se.current)==null||p.postMessage({type:"cards",data:{cards:[...yt.current]}})},[]),_n=a.useCallback(u=>{if(u.id||(u.id="node-"+Date.now()),!u.position){const p=ue.current,c=be.current;if(!c)return;const g=c.getBoundingClientRect();u.position={x:Math.round(-p.x/p.zoom+g.width/2/p.zoom)-ut/2,y:Math.round(-p.y/p.zoom+g.height/2/p.zoom)-tt/2}}u.data||(u.data={label:u.id}),Pe.current&&Pe.current([{type:"add",item:u}])},[]),Wn=a.useCallback(()=>({...ue.current}),[]),Fn=a.useCallback(u=>{ue.current={...ue.current,...u},we()},[we]),_=a.useCallback(u=>Le(u.x,u.y),[Le]),pe=n,ne=a.useMemo(()=>({wrapRef:be,canvasRef:Tt,workerRef:Se,cameraRef:ue,nodesRef:ee,edgesRef:ze,handleRegistryRef:hn,syncNodesToWorker:mn,onNodesChangeRef:Pe,onEdgesChangeRef:Te,sendCamera:we,screenToWorld:Le,viewportListeners:xt,selectionListeners:it,zoomMin:ie,zoomMax:fe,snapToGrid:Ge,snapGrid:rt,nodeExtent:gt,defaultEdgeOptions:Pt,edgeRouting:bt,resolvedNodesRef:ct,noDragClassName:Nt,noPanClassName:It,get nodes(){return t},get edges(){return n},get routedEdges(){return pe},get viewport(){return yn},get connection(){return Ut}}),[t,n,pe,yn,Ut,we,Le,mn,xt,it,ie,fe,Ge,rt,gt,Pt,bt,Nt,It]);return{wrapRef:be,canvasRef:Tt,canvasReady:$t,onPointerDown:Zt,onPointerMove:Gt,onPointerUp:Qt,resetView:Vt,addCard:Hn,addNode:_n,getCamera:Wn,setCamera:Fn,screenToFlowPosition:_,store:ne}}function ro(e,t,n,r,i,o){const l=i-n,h=o-r,v=l*l+h*h;if(v===0)return Math.hypot(e-n,t-r);let f=((e-n)*l+(t-r)*h)/v;return f=Math.max(0,Math.min(1,f)),Math.hypot(e-(n+f*l),t-(r+f*h))}const ur=e=>{let t;const n=new Set,r=(f,y)=>{const x=typeof f=="function"?f(t):f;if(!Object.is(x,t)){const R=t;t=y??(typeof x!="object"||x===null)?x:Object.assign({},t,x),n.forEach(C=>C(t,R))}},i=()=>t,h={setState:r,getState:i,getInitialState:()=>v,subscribe:f=>(n.add(f),()=>n.delete(f))},v=t=e(r,i,h);return h},oo=(e=>e?ur(e):ur),so=e=>e;function io(e,t=so){const n=a.useSyncExternalStore(e.subscribe,a.useCallback(()=>t(e.getState()),[e,t]),a.useCallback(()=>t(e.getInitialState()),[e,t]));return a.useDebugValue(n),n}const St=a.createContext(null);function ao(e={}){return oo((t,n)=>({nodes:[],edges:[],viewport:{x:0,y:0,zoom:1},connection:null,minZoom:.1,maxZoom:5,width:0,height:0,domNode:null,nodesRef:{current:[]},edgesRef:{current:[]},cameraRef:{current:{x:0,y:0,zoom:1}},wrapRef:{current:null},workerRef:{current:null},onNodesChangeRef:{current:null},onEdgesChangeRef:{current:null},viewportListeners:new Set,selectionListeners:new Set,edgeLabelContainerRef:{current:null},viewportPortalRef:{current:null},screenToWorld:(r,i)=>{const o=n().cameraRef.current;return{x:(r-o.x)/o.zoom,y:(i-o.y)/o.zoom}},sendCamera:()=>{var i;const r=n();(i=r.workerRef.current)==null||i.postMessage({type:"camera",data:{camera:{...r.cameraRef.current}}})},...e}))}function Ne(e,t){const n=a.useContext(St);if(!n)throw new Error("useCanvasStore must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");const r=typeof n.getState=="function"&&typeof n.subscribe=="function",i=a.useRef(e),o=a.useRef(t),l=a.useRef(void 0);i.current=e,o.current=t;const h=a.useCallback(v=>{const f=i.current;if(!f)return v;const y=f(v),x=o.current||Object.is;return l.current!==void 0&&x(l.current,y)?l.current:(l.current=y,y)},[]);return r?io(n,e?h:void 0):e?h(n):n}function Rr(){const e=a.useContext(St);if(!e)throw new Error("useCanvasStoreApi must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");return typeof e.getState=="function"?e:{getState:()=>e,setState:()=>{},subscribe:()=>()=>{}}}const an=a.createContext(null);function co(){return a.useContext(an)}function lo({node:e,nodeType:t}){var z,W,j,D;const n=Ne(),r=a.useRef(n);r.current=n;const i=a.useRef(null),o=e._absolutePosition||e.position,l=a.useRef(null);a.useEffect(()=>{const F=i.current;if(!F)return;const $=new ResizeObserver(X=>{var Z,q,O,M;const{width:A,height:P}=X[0].contentRect;if(A>0&&P>0){const d=r.current,b=d.nodesRef.current.find(B=>B.id===e.id),L=(b==null?void 0:b.width)||((Z=b==null?void 0:b.measured)==null?void 0:Z.width),T=(b==null?void 0:b.height)||((q=b==null?void 0:b.measured)==null?void 0:q.height);(Math.abs((L||0)-A)>1||Math.abs((T||0)-P)>1)&&((M=(O=d.onNodesChangeRef).current)==null||M.call(O,[{id:e.id,type:"dimensions",dimensions:{width:A,height:P},setAttributes:!0}]))}});return $.observe(F),()=>$.disconnect()},[e.id]);const h=a.useCallback(F=>{var ce,me,Me,ke;F.stopPropagation();const $=F.target.tagName;if($==="INPUT"||$==="TEXTAREA"||$==="SELECT"||$==="BUTTON"||$==="A"||$==="LABEL"||F.target.isContentEditable)return;const X=r.current.noDragClassName||"nodrag",A=r.current.noPanClassName||"nopan";let P=F.target;for(;P&&P!==i.current;){if((ce=P.classList)!=null&&ce.contains(X)||(me=P.classList)!=null&&me.contains(A))return;P=P.parentElement}if(r.current.onNodesChangeRef.current){const le=[];if(F.shiftKey)le.push({id:e.id,type:"select",selected:!e.selected});else for(const ie of r.current.nodesRef.current)ie.id===e.id&&!ie.selected?le.push({id:ie.id,type:"select",selected:!0}):ie.id!==e.id&&ie.selected&&le.push({id:ie.id,type:"select",selected:!1});le.length&&r.current.onNodesChangeRef.current(le)}const Z=r.current.cameraRef.current,q=r.current.wrapRef.current;if(!q)return;const O=q.getBoundingClientRect(),M=(F.clientX-O.left-Z.x)/Z.zoom,d=(F.clientY-O.top-Z.y)/Z.zoom,L=e.selected?r.current.nodesRef.current.filter(le=>le.selected&&le.id!==e.id).map(le=>({id:le.id,startPos:{...le.position}})):[];l.current={startPos:{...e.position},startMouse:{x:M,y:d},selectedStarts:L};const T=[{id:e.id,type:"position",dragging:!0}];for(const le of L)T.push({id:le.id,type:"position",dragging:!0});(ke=(Me=r.current.onNodesChangeRef).current)==null||ke.call(Me,T);const B=i.current;B&&B.setPointerCapture(F.pointerId);let Q=null;const oe=le=>{var _e,We,nt,De;if(!l.current)return;const xe=r.current.cameraRef.current,ie=q.getBoundingClientRect(),fe=(le.clientX-ie.left-xe.x)/xe.zoom,Ce=(le.clientY-ie.top-xe.y)/xe.zoom,je=fe-l.current.startMouse.x,ge=Ce-l.current.startMouse.y;let de={x:l.current.startPos.x+je,y:l.current.startPos.y+ge};if(r.current.snapToGrid&&r.current.snapGrid&&(de={x:r.current.snapGrid[0]*Math.round(de.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(de.y/r.current.snapGrid[1])}),e.parentId&&e.extent==="parent"){const $e=r.current.nodesRef.current.find(Ie=>Ie.id===e.parentId);if($e){const Ie=$e.width||160,Ee=$e.height||60,Ge=e.width||((_e=e.measured)==null?void 0:_e.width)||160,rt=e.height||((We=e.measured)==null?void 0:We.height)||60;de={x:Math.max(0,Math.min(de.x,Ie-Ge)),y:Math.max(0,Math.min(de.y,Ee-rt))}}}B&&(B.style.left=de.x+"px",B.style.top=de.y+"px");const Ae=[{id:e.id,position:de,_absolutePosition:de,dragging:!0}];for(const $e of l.current.selectedStarts){let Ie={x:$e.startPos.x+je,y:$e.startPos.y+ge};r.current.snapToGrid&&r.current.snapGrid&&(Ie={x:r.current.snapGrid[0]*Math.round(Ie.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Ie.y/r.current.snapGrid[1])});const Ee=q.querySelector(`[data-nodeid="${$e.id}"]`);Ee&&(Ee.style.left=Ie.x+"px",Ee.style.top=Ie.y+"px"),Ae.push({id:$e.id,position:Ie,_absolutePosition:Ie,dragging:!0})}(De=(nt=r.current.workerRef)==null?void 0:nt.current)==null||De.postMessage({type:"nodePositions",data:{updates:Ae}});for(const $e of Ae){const Ie=r.current.nodesRef.current.find(Ee=>Ee.id===$e.id);Ie&&(Ie.position=$e.position)}Q=Ae},te=le=>{var fe,Ce,je,ge;if(!l.current)return;const xe=[{id:e.id,position:e.position,dragging:!1}];for(const de of l.current.selectedStarts)xe.push({id:de.id,position:de.startPos,dragging:!1});if(Q)for(let de=0;de<Q.length;de++)xe[de]={id:Q[de].id,position:Q[de].position,dragging:!1};(Ce=(fe=r.current.workerRef)==null?void 0:fe.current)==null||Ce.postMessage({type:"nodePositions",data:{updates:xe}});const ie=[];for(const de of xe)ie.push({id:de.id,type:"position",position:de.position,dragging:!1});(ge=(je=r.current.onNodesChangeRef).current)==null||ge.call(je,ie),l.current=null,Q=null,B&&B.releasePointerCapture(le.pointerId),B==null||B.removeEventListener("pointermove",oe),B==null||B.removeEventListener("pointerup",te)};B==null||B.addEventListener("pointermove",oe),B==null||B.addEventListener("pointerup",te)},[e]),v=a.useCallback(F=>{var q,O,M,d,b,L;if(!e.selected)return;const $=F.shiftKey?10:1;let X=0,A=0;switch(F.key){case"ArrowUp":A=-$;break;case"ArrowDown":A=$;break;case"ArrowLeft":X=-$;break;case"ArrowRight":X=$;break;case"Escape":(O=(q=r.current.onNodesChangeRef).current)==null||O.call(q,[{id:e.id,type:"select",selected:!1}]);return;case"Delete":case"Backspace":e.deletable!==!1&&((d=(M=r.current.onNodesChangeRef).current)==null||d.call(M,[{id:e.id,type:"remove"}]));return;default:return}F.preventDefault();const P={x:e.position.x+X,y:e.position.y+A},Z=[{id:e.id,type:"position",position:P}];for(const T of r.current.nodesRef.current)T.selected&&T.id!==e.id&&Z.push({id:T.id,type:"position",position:{x:T.position.x+X,y:T.position.y+A}});(L=(b=r.current.onNodesChangeRef).current)==null||L.call(b,Z)},[e]),f=e.width||((z=e.measured)==null?void 0:z.width),y=e.height||((W=e.measured)==null?void 0:W.height),x=!!(f&&y),R=(j=n.pinnedNodeIds)==null?void 0:j.has(e.id),C=a.useCallback(F=>{var $,X;F.stopPropagation(),(X=($=r.current).togglePinNode)==null||X.call($,e.id)},[e.id]);return N.jsx(an.Provider,{value:e.id,children:N.jsxs("div",{ref:i,className:`ric-node-wrapper ${e.selected?"selected":""} ${e.dragging?"dragging":""}`,style:{position:"absolute",left:o.x,top:o.y,zIndex:e.type==="group"?0:e.zIndex||1,pointerEvents:e.type==="group"?"none":"all",visibility:x?"visible":"hidden",outline:"none"},"data-nodeid":e.id,tabIndex:e.selectable!==!1?0:void 0,role:"button","aria-label":`Node ${((D=e.data)==null?void 0:D.label)||e.id}`,"aria-selected":!!e.selected,onPointerDown:h,onKeyDown:v,children:[N.jsx(t,{id:e.id,data:e.data,type:e.type,selected:!!e.selected,dragging:!!e.dragging,draggable:e.draggable!==!1,selectable:e.selectable!==!1,deletable:e.deletable!==!1,isConnectable:e.connectable!==!1,zIndex:e.zIndex||0,positionAbsoluteX:o.x,positionAbsoluteY:o.y,width:f,height:y,sourcePosition:e.sourcePosition,targetPosition:e.targetPosition,parentId:e.parentId,dragHandle:e.dragHandle}),n.togglePinNode&&N.jsx("button",{className:"ric-pin-btn nodrag",onClick:C,title:R?"Unpin from DOM":"Pin to DOM",style:{position:"absolute",top:-8,left:-8,width:20,height:20,borderRadius:"50%",border:"1.5px solid "+(R?"#3b82f6":"#ccc"),background:R?"#3b82f6":"#fff",color:R?"#fff":"#999",fontSize:10,lineHeight:"16px",textAlign:"center",cursor:"pointer",padding:0,zIndex:10,pointerEvents:"all",boxShadow:"0 1px 3px rgba(0,0,0,0.12)"},children:"📌"})]})})}const uo=a.memo(lo),kr=160,Cr=60;function dr(e,t,n,r){var v,f;const i=e.width||((v=e.measured)==null?void 0:v.width)||kr,o=e.height||((f=e.measured)==null?void 0:f.height)||Cr,l=e._absolutePosition||e.position;if(e.handleBounds){const y=e.handleBounds[t]||[],x=n?y.find(R=>R.id===n):y[0];if(x&&x.x!==void 0&&x.y!==void 0){const R=x.position||(t==="source"?"right":"left");return{x:l.x+x.x,y:l.y+x.y,position:R}}}if(r){const y=`${e.id}__${n||t}`,x=r.get(y);if(x&&x.x!==void 0&&x.y!==void 0)return{x:l.x+x.x,y:l.y+x.y,position:x.position||(t==="source"?"right":"left")}}if(e.handles&&e.handles.length){for(const y of e.handles)if(y.type===t&&(!n||y.id===n)){if(y.x!==void 0&&y.y!==void 0)return{x:l.x+y.x,y:l.y+y.y,position:y.position||(t==="source"?"right":"left")};const x=y.position||(t==="source"?"right":"left");switch(x){case"top":return{x:l.x+i/2,y:l.y,position:x};case"bottom":return{x:l.x+i/2,y:l.y+o,position:x};case"left":return{x:l.x,y:l.y+o/2,position:x};default:return{x:l.x+i,y:l.y+o/2,position:x}}}}switch(t==="source"?e.sourcePosition||"right":e.targetPosition||"left"){case"top":return{x:l.x+i/2,y:l.y,position:"top"};case"bottom":return{x:l.x+i/2,y:l.y+o,position:"bottom"};case"left":return{x:l.x,y:l.y+o/2,position:"left"};default:return{x:l.x+i,y:l.y+o/2,position:"right"}}}function fo(e,t,n){return n==="left"?e-t:n==="right"?e+t:e}function ho(e,t,n){return n==="top"?e-t:n==="bottom"?e+t:e}function fr({x:e,y:t,position:n,type:r,onPointerDown:i}){return N.jsx("circle",{className:`ric-edge-anchor ric-edge-anchor-${r}`,cx:fo(e,10,n),cy:ho(t,10,n),r:10,stroke:"transparent",fill:"transparent",style:{cursor:"move",pointerEvents:"stroke"},onPointerDown:i})}function go({edge:e,edgeType:t,nodes:n,reconnectable:r}){var O,M;const i=a.useContext(St),o=a.useRef(typeof i.getState=="function"?i.getState():i);o.current=typeof i.getState=="function"?i.getState():i;const[l,h]=a.useState(null),v=a.useCallback((d,b,L,T)=>{var ke;b.stopPropagation(),b.preventDefault();const B=o.current,Q=B.wrapRef.current;if(!Q)return;const oe=d==="source"?T:L,te=d==="source"?e.target:e.source;(ke=B.workerRef.current)==null||ke.postMessage({type:"connecting",data:{from:{x:oe.x,y:oe.y},to:{x:oe.x,y:oe.y}}});const ce=Q.getBoundingClientRect(),me=le=>{var Ce;const xe=B.cameraRef.current,ie=(le.clientX-ce.left-xe.x)/xe.zoom,fe=(le.clientY-ce.top-xe.y)/xe.zoom;(Ce=B.workerRef.current)==null||Ce.postMessage({type:"connecting",data:{from:{x:oe.x,y:oe.y},to:{x:ie,y:fe}}})},Me=le=>{var Ae,_e,We,nt;const xe=B.cameraRef.current,ie=(le.clientX-ce.left-xe.x)/xe.zoom,fe=(le.clientY-ce.top-xe.y)/xe.zoom,Ce=20/xe.zoom;let je=null,ge=null;const de=(Ae=B.handleRegistryRef)==null?void 0:Ae.current;for(const De of B.nodesRef.current){if(De.hidden)continue;const $e=De.width||kr,Ie=De.height||Cr,Ee=De._absolutePosition||De.position,Ge=[];if(de)for(const[,He]of de)He.nodeId===De.id&&Ge.push(He);const rt=Ge.length>0?Ge:De.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const He of rt){let Ue,Ke;if(He.x!==void 0&&He.y!==void 0)Ue=Ee.x+He.x,Ke=Ee.y+He.y;else switch(He.position||(He.type==="source"?"right":"left")){case"top":Ue=Ee.x+$e/2,Ke=Ee.y;break;case"bottom":Ue=Ee.x+$e/2,Ke=Ee.y+Ie;break;case"left":Ue=Ee.x,Ke=Ee.y+Ie/2;break;default:Ue=Ee.x+$e,Ke=Ee.y+Ie/2;break}if(Math.abs(ie-Ue)<Ce&&Math.abs(fe-Ke)<Ce){je=De,ge=He.id||null;break}}if(je)break}if(je){const De=d==="source"?{source:je.id,target:te,sourceHandle:ge,targetHandle:e.targetHandle}:{source:te,target:je.id,sourceHandle:e.sourceHandle,targetHandle:ge};(We=(_e=B.onEdgesChangeRef).current)==null||We.call(_e,[{id:e.id,type:"remove"},{type:"add",item:{id:e.id,...De}}])}(nt=B.workerRef.current)==null||nt.postMessage({type:"connecting",data:null}),Q.removeEventListener("pointermove",me),Q.removeEventListener("pointerup",Me)};Q.addEventListener("pointermove",me),Q.addEventListener("pointerup",Me)},[e]),f=o.current,y=((O=f.nodesRef)==null?void 0:O.current)||n,x=y.find(d=>d.id===e.source),R=y.find(d=>d.id===e.target),[,C]=a.useReducer(d=>d+1,0),z=a.useRef(null),W=(x==null?void 0:x.dragging)||(R==null?void 0:R.dragging);a.useEffect(()=>{if(!W)return;const d=()=>{C(),z.current=requestAnimationFrame(d)};return z.current=requestAnimationFrame(d),()=>cancelAnimationFrame(z.current)},[W]);const j=a.useRef(!1);a.useEffect(()=>{j.current||(j.current=!0,requestAnimationFrame(()=>C()))},[]);const D=(M=f.handleRegistryRef)==null?void 0:M.current,F=x?dr(x,"source",e.sourceHandle,D):null,$=R?dr(R,"target",e.targetHandle,D):null,X=e.type==="bezier"||e.type==="simplebezier"||e.type==="default",A=f.routedEdges||f.edges,P=A==null?void 0:A.find(d=>d.id===e.id),Z=X?null:(P==null?void 0:P._routedPoints)||e._routedPoints||null,q=r!==!1&&e.reconnectable!==!1;return!F||!$?null:N.jsxs("g",{className:`ric-edge-wrapper ${e.selected?"selected":""}`,"data-edgeid":e.id,onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),children:[N.jsx(t,{id:e.id,source:e.source,target:e.target,sourceX:F.x,sourceY:F.y,targetX:$.x,targetY:$.y,sourcePosition:F.position,targetPosition:$.position,sourceHandleId:e.sourceHandle,targetHandleId:e.targetHandle,data:e.data,type:e.type,selected:!!e.selected,animated:!!e.animated,label:e.label,style:e.style,selectable:e.selectable!==!1,deletable:e.deletable!==!1,routedPoints:Z}),q&&(l||e.selected)&&N.jsxs(N.Fragment,{children:[N.jsx(fr,{x:F.x,y:F.y,position:F.position,type:"source",onPointerDown:d=>v("source",d,F,$)}),N.jsx(fr,{x:$.x,y:$.y,position:$.position,type:"target",onPointerDown:d=>v("target",d,F,$)})]})]})}const yo=a.memo(go);function Er({selectionKeyCode:e="Shift",selectionMode:t="partial"}){var W;const n=Ne(),[r,i]=a.useState(null),o=a.useRef(null);if(a.useEffect(()=>{const j=n.wrapRef.current;if(!j)return;let D=!1,F=null,$=!1;const X=O=>{O.key===e&&($=!0)},A=O=>{O.key===e&&($=!1)},P=O=>{if(!$)return;const M=O.target;if(M.closest(".ric-node-wrapper")||M.closest(".ric-handle"))return;D=!0;const d=n.cameraRef.current,b=j.getBoundingClientRect(),L=(O.clientX-b.left-d.x)/d.zoom,T=(O.clientY-b.top-d.y)/d.zoom;F={x:L,y:T},i({startX:L,startY:T,endX:L,endY:T}),O.stopPropagation()},Z=O=>{if(!D||!F)return;const M=n.cameraRef.current,d=j.getBoundingClientRect(),b=(O.clientX-d.left-M.x)/M.zoom,L=(O.clientY-d.top-M.y)/M.zoom;i({startX:F.x,startY:F.y,endX:b,endY:L})},q=O=>{var Q,oe;if(!D||!F)return;D=!1;const M=n.cameraRef.current,d=j.getBoundingClientRect(),b=(O.clientX-d.left-M.x)/M.zoom,L=(O.clientY-d.top-M.y)/M.zoom,T={x:Math.min(F.x,b),y:Math.min(F.y,L),width:Math.abs(b-F.x),height:Math.abs(L-F.y)},B=[];for(const te of n.nodesRef.current){const ce=te._absolutePosition||te.position,me=te.width||160,Me=te.height||60;let ke;t==="full"?ke=ce.x>=T.x&&ce.y>=T.y&&ce.x+me<=T.x+T.width&&ce.y+Me<=T.y+T.height:ke=ce.x+me>T.x&&ce.x<T.x+T.width&&ce.y+Me>T.y&&ce.y<T.y+T.height,B.push({id:te.id,type:"select",selected:ke})}B.length&&((oe=(Q=n.onNodesChangeRef).current)==null||oe.call(Q,B)),F=null,i(null)};return j.addEventListener("pointerdown",P,!0),j.addEventListener("pointermove",Z),j.addEventListener("pointerup",q),window.addEventListener("keydown",X),window.addEventListener("keyup",A),()=>{j.removeEventListener("pointerdown",P,!0),j.removeEventListener("pointermove",Z),j.removeEventListener("pointerup",q),window.removeEventListener("keydown",X),window.removeEventListener("keyup",A)}},[n,e,t]),!r)return null;const l=((W=n.cameraRef)==null?void 0:W.current)||{x:0,y:0,zoom:1},h=Math.min(r.startX,r.endX),v=Math.min(r.startY,r.endY),f=Math.abs(r.endX-r.startX),y=Math.abs(r.endY-r.startY),x=h*l.zoom+l.x,R=v*l.zoom+l.y,C=f*l.zoom,z=y*l.zoom;return N.jsx("div",{ref:o,className:"ric-selection-box",style:{position:"absolute",left:x,top:R,width:C,height:z,border:"1px dashed #3b82f6",background:"rgba(59, 130, 246, 0.08)",pointerEvents:"none",zIndex:100}})}Er.displayName="SelectionBox";const Sr=a.memo(Er);function Qn(e,t,n){switch(e){case"top":return{x:t/2,y:0};case"bottom":return{x:t/2,y:n};case"left":return{x:0,y:n/2};case"right":return{x:t,y:n/2};default:return{x:t,y:n/2}}}function xo(e,t){const n=e.closest(".ric-node-wrapper");if(!n)return null;const r=n.getBoundingClientRect(),i=e.getBoundingClientRect(),o=t||1;return{x:(i.left+i.width/2-r.left)/o,y:(i.top+i.height/2-r.top)/o}}let On=!1,Et=null;function zr(e){Et=e,!On&&(On=!0,requestAnimationFrame(()=>{var t;On=!1,(t=Et==null?void 0:Et.syncNodesToWorker)==null||t.call(Et),Et=null}))}const Jn=new WeakMap;let bn=null;function po(){return bn||(bn=new ResizeObserver(e=>{var t;for(const n of e){const r=Jn.get(n.target);if(!r)continue;const{width:i,height:o}=n.contentRect;if(!i||!o)continue;const l=r.getStore(),h=(t=l.handleRegistryRef)==null?void 0:t.current;if(h){for(const[v,f]of h)if(f.nodeId===r.nodeId){const y=Qn(f.position,i,o);f.x=y.x,f.y=y.y,h.set(v,f)}zr(l)}}}),bn)}function mo({type:e="source",position:t=e==="source"?"right":"left",id:n,isConnectable:r=!0,isConnectableStart:i=!0,isConnectableEnd:o=!0,children:l,className:h="",style:v={},onConnect:f,...y}){const x=a.useContext(an),R=a.useContext(St),C=a.useRef(null),z=a.useCallback(()=>typeof R.getState=="function"?R.getState():R,[R]),W=a.useRef(z);W.current=z,a.useLayoutEffect(()=>{var M,d,b,L,T,B,Q;if(!x)return;const $=W.current(),X=(M=$.handleRegistryRef)==null?void 0:M.current;if(!X)return;const A=`${x}__${n||e}`,P=(b=(d=$.nodesRef)==null?void 0:d.current)==null?void 0:b.find(oe=>oe.id===x),Z=(P==null?void 0:P.width)||((L=P==null?void 0:P.measured)==null?void 0:L.width),q=(P==null?void 0:P.height)||((T=P==null?void 0:P.measured)==null?void 0:T.height);let O;Z&&q?O=Qn(t,Z,q):C.current?O=xo(C.current,(Q=(B=$.cameraRef)==null?void 0:B.current)==null?void 0:Q.zoom):O=Qn(t,160,60),X.set(A,{nodeId:x,id:n||null,type:e,position:t,x:O.x,y:O.y}),P&&(e==="source"&&(P.sourcePosition=t),e==="target"&&(P.targetPosition=t))},[x,n,e,t]),a.useEffect(()=>{if(!x)return;const $=W.current();zr($);const X=C.current,A=X==null?void 0:X.closest(".ric-node-wrapper");return A&&!Jn.has(A)&&(Jn.set(A,{nodeId:x,getStore:W.current}),po().observe(A)),()=>{var O;const Z=(O=W.current().handleRegistryRef)==null?void 0:O.current,q=`${x}__${n||e}`;Z==null||Z.delete(q)}},[x,n,e,t]);const j=a.useCallback(()=>{var d;const $=W.current(),X=$.nodesRef.current.find(b=>b.id===x);if(!X)return null;const A=X._absolutePosition||X.position,P=(d=$.handleRegistryRef)==null?void 0:d.current,Z=`${x}__${n||e}`,q=P==null?void 0:P.get(Z);if(q&&q.x!==void 0&&q.y!==void 0)return{x:A.x+q.x,y:A.y+q.y};const O=X.width||160,M=X.height||60;switch(t){case"top":return{x:A.x+O/2,y:A.y};case"bottom":return{x:A.x+O/2,y:A.y+M};case"left":return{x:A.x,y:A.y+M/2};default:return{x:A.x+O,y:A.y+M/2}}},[x,n,e,t]),D=a.useCallback($=>{var L;if(!r||!i)return;$.stopPropagation(),$.preventDefault();const X=W.current(),A=X.cameraRef.current,P=X.wrapRef.current;if(!P)return;const Z=P.getBoundingClientRect(),q=j();if(!q)return;const O=q.x,M=q.y;(L=X.workerRef.current)==null||L.postMessage({type:"connecting",data:{from:{x:O,y:M},to:{x:O,y:M}}}),P.setPointerCapture($.pointerId);const d=T=>{var oe;const B=(T.clientX-Z.left-A.x)/A.zoom,Q=(T.clientY-Z.top-A.y)/A.zoom;(oe=X.workerRef.current)==null||oe.postMessage({type:"connecting",data:{from:{x:O,y:M},to:{x:B,y:Q}}})},b=T=>{var Me,ke,le,xe;const B=(T.clientX-Z.left-A.x)/A.zoom,Q=(T.clientY-Z.top-A.y)/A.zoom,oe=20/A.zoom;let te=null,ce=null;const me=(Me=X.handleRegistryRef)==null?void 0:Me.current;for(const ie of X.nodesRef.current){if(ie.id===x||ie.hidden)continue;const fe=ie._absolutePosition||ie.position,Ce=[];if(me)for(const[,ge]of me)ge.nodeId===ie.id&&Ce.push(ge);const je=Ce.length>0?Ce:ie.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const ge of je){let de,Ae;if(ge.x!==void 0&&ge.y!==void 0)de=fe.x+ge.x,Ae=fe.y+ge.y;else{const _e=ie.width||160,We=ie.height||60;switch(ge.position||(ge.type==="source"?"right":"left")){case"top":de=fe.x+_e/2,Ae=fe.y;break;case"bottom":de=fe.x+_e/2,Ae=fe.y+We;break;case"left":de=fe.x,Ae=fe.y+We/2;break;default:de=fe.x+_e,Ae=fe.y+We/2;break}}if(Math.abs(B-de)<oe&&Math.abs(Q-Ae)<oe){te=ie,ce=ge.id||null;break}}if(te)break}if(te){const ie={source:e==="source"?x:te.id,target:e==="source"?te.id:x,sourceHandle:e==="source"?n||null:ce,targetHandle:e==="source"?ce:n||null};(le=(ke=X.onEdgesChangeRef)==null?void 0:ke.current)==null||le.call(ke,[{type:"add",item:{id:`e-${ie.source}-${ie.target}`,...ie}}])}(xe=X.workerRef.current)==null||xe.postMessage({type:"connecting",data:null}),P.removeEventListener("pointermove",d),P.removeEventListener("pointerup",b)};P.addEventListener("pointermove",d),P.addEventListener("pointerup",b)},[x,n,e,t,r,i,j]),F={top:{top:0,left:"50%",transform:"translate(-50%, -50%)"},bottom:{bottom:0,left:"50%",transform:"translate(-50%, 50%)"},left:{top:"50%",left:0,transform:"translate(-50%, -50%)"},right:{top:"50%",right:0,transform:"translate(50%, -50%)"}}[t]||{};return N.jsx("div",{ref:C,className:`ric-handle ric-handle-${t} ric-handle-${e} ${h}`,"data-handleid":n||null,"data-nodeid":x,"data-handlepos":t,"data-handletype":e,onPointerDown:D,style:{position:"absolute",width:8,height:8,borderRadius:"50%",background:"#1a192b",border:"none",zIndex:10,cursor:r?"crosshair":"default",boxSizing:"border-box",...F,...v},...y,children:l})}const sn=a.memo(mo);function vo({data:e,isConnectable:t,selected:n,targetPosition:r="left",sourcePosition:i="right",hideSourceHandle:o=!1,hideTargetHandle:l=!1}){return N.jsxs("div",{className:`ric-default-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!l&&N.jsx(sn,{type:"target",position:r,isConnectable:t}),N.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!o&&N.jsx(sn,{type:"source",position:i,isConnectable:t})]})}function Pr({data:e,isConnectable:t,selected:n,sourcePosition:r="right",hideSourceHandle:i=!1}){return N.jsxs("div",{className:`ric-input-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderBottom:"2px solid #0041d0",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[N.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!i&&N.jsx(sn,{type:"source",position:r,isConnectable:t})]})}function Nr({data:e,isConnectable:t,selected:n,targetPosition:r="left",hideTargetHandle:i=!1}){return N.jsxs("div",{className:`ric-output-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderTop:"2px solid #ff0072",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!i&&N.jsx(sn,{type:"target",position:r,isConnectable:t}),N.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label})]})}function Ir({data:e,selected:t,width:n,height:r}){return N.jsx("div",{className:`ric-group-node${t?" selected":""}`,style:{width:n||300,height:r||200,background:"rgba(240, 240, 240, 0.25)",border:t?"2px solid #3b82f6":"1px dashed #ccc",borderRadius:8,padding:8,boxSizing:"border-box"},children:(e==null?void 0:e.label)&&N.jsx("div",{style:{fontSize:11,fontWeight:600,color:"#888",userSelect:"none"},children:e.label})})}function Tr({x:e,y:t,label:n,labelStyle:r,labelShowBg:i=!0,labelBgStyle:o,labelBgPadding:l=[2,4],labelBgBorderRadius:h=2,children:v,className:f="",...y}){const[x,R]=a.useState({x:1,y:0,width:0,height:0}),C=a.useRef(null);return a.useEffect(()=>{if(C.current){const z=C.current.getBBox();R({x:z.x,y:z.y,width:z.width,height:z.height})}},[n]),n?N.jsxs("g",{transform:`translate(${e-x.width/2} ${t-x.height/2})`,className:`ric-edge-textwrapper ${f}`,visibility:x.width?"visible":"hidden",...y,children:[i&&N.jsx("rect",{width:x.width+2*l[0],x:-l[0],y:-l[1],height:x.height+2*l[1],className:"ric-edge-textbg",style:o,rx:h,ry:h}),N.jsx("text",{className:"ric-edge-text",y:x.height/2,dy:"0.3em",ref:C,style:r,children:n}),v]}):null}Tr.displayName="EdgeText";const Lr=a.memo(Tr);function hr(e){return e!=null&&e!==""&&!isNaN(Number(e))}function cn({id:e,path:t,labelX:n,labelY:r,label:i,labelStyle:o,labelShowBg:l,labelBgStyle:h,labelBgPadding:v,labelBgBorderRadius:f,interactionWidth:y=20,style:x,markerEnd:R,markerStart:C,className:z="",...W}){return N.jsxs(N.Fragment,{children:[N.jsx("path",{id:e,d:t,fill:"none",stroke:"#b1b1b7",strokeWidth:1.5,className:`ric-edge-path ${z}`,style:x,markerEnd:R,markerStart:C,...W}),y?N.jsx("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:y,className:"ric-edge-interaction",style:{pointerEvents:"stroke"}}):null,i&&hr(n)&&hr(r)?N.jsx(Lr,{x:n,y:r,label:i,labelStyle:o,labelShowBg:l,labelBgStyle:h,labelBgPadding:v,labelBgBorderRadius:f}):null]})}const nn=20;function gr(e,t,n){switch(n){case"right":return{x:e+nn,y:t};case"left":return{x:e-nn,y:t};case"bottom":return{x:e,y:t+nn};case"top":return{x:e,y:t-nn};default:return{x:e+nn,y:t}}}const er=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:l="bottom",targetPosition:h="top",label:v,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:R,labelBgBorderRadius:C,style:z,markerEnd:W,markerStart:j,interactionWidth:D}){let F,$,X;const A=gr(n,r,l),P=gr(i,o,h),Z=Math.abs(P.x-A.x),q=Math.max(50,Z*.5);let O,M,d,b;switch(l){case"left":O=A.x-q,M=A.y;break;case"top":O=A.x,M=A.y-q;break;case"bottom":O=A.x,M=A.y+q;break;default:O=A.x+q,M=A.y;break}switch(h){case"right":d=P.x+q,b=P.y;break;case"top":d=P.x,b=P.y-q;break;case"bottom":d=P.x,b=P.y+q;break;default:d=P.x-q,b=P.y;break}F=`M ${n},${r} L ${A.x},${A.y} C ${O},${M} ${d},${b} ${P.x},${P.y} L ${i},${o}`;const L=.5,T=.5;return $=T*T*T*A.x+3*T*T*L*O+3*T*L*L*d+L*L*L*P.x,X=T*T*T*A.y+3*T*T*L*M+3*T*L*L*b+L*L*L*P.y,N.jsx(cn,{id:t,path:F,labelX:$,labelY:X,label:v,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:R,labelBgBorderRadius:C,style:z,markerEnd:W,markerStart:j,interactionWidth:D})});er.displayName="BezierEdge";function tr({sourceX:e,sourceY:t,targetX:n,targetY:r}){const i=`M ${e},${t}L ${n},${r}`,o=(e+n)/2,l=(t+r)/2;return[i,o,l,0,0]}function nr({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i="right",targetPosition:o="left",curvature:l=.25}){const h=Math.abs(n-e),v=Math.abs(r-t),f=Math.sqrt(h*h+v*v),y=Math.max(f*l,50);let x,R,C,z;switch(i){case"top":x=e,R=t-y;break;case"bottom":x=e,R=t+y;break;case"left":x=e-y,R=t;break;default:x=e+y,R=t;break}switch(o){case"top":C=n,z=r-y;break;case"bottom":C=n,z=r+y;break;case"right":C=n+y,z=r;break;default:C=n-y,z=r;break}const W=`M ${e},${t} C ${x},${R} ${C},${z} ${n},${r}`,j=.5,D=1-j,F=D*D*D*e+3*D*D*j*x+3*D*j*j*C+j*j*j*n,$=D*D*D*t+3*D*D*j*R+3*D*j*j*z+j*j*j*r;return[W,F,$,0,0]}function rr({sourceX:e,sourceY:t,targetX:n,targetY:r}){const i=Math.abs(n-e),o=Math.max(i*.5,50),l=e+o,h=n-o,v=`M ${e},${t} C ${l},${t} ${h},${r} ${n},${r}`,f=.5,y=.5,x=y*y*y*e+3*y*y*f*l+3*y*f*f*h+f*f*f*n,R=y*y*y*t+3*y*y*f*t+3*y*f*f*r+f*f*f*r;return[v,x,R,0,0]}function Rn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i="right",targetPosition:o="left",borderRadius:l=5,offset:h=20}){const v=i==="left"||i==="right",f=Math.min(l,Math.abs(n-e)/2,Math.abs(r-t)/2);if(v){if(Math.abs(r-t)<1)return[`M ${e},${t} L ${n},${r}`,(e+n)/2,t,0,0];const C=(e+n)/2,z=r>t?1:-1;return[`M ${e},${t} L ${C-f},${t} Q ${C},${t} ${C},${t+z*f} L ${C},${r-z*f} Q ${C},${r} ${C+(n>C?f:-f)},${r} L ${n},${r}`,C,(t+r)/2,0,0]}const y=(t+r)/2,x=n>e?1:-1;return[`M ${e},${t} L ${e},${y-f} Q ${e},${y} ${e+x*f},${y} L ${n-x*f},${y} Q ${n},${y} ${n},${y+(r>y?f:-f)} L ${n},${r}`,(e+n)/2,y,0,0]}function bo({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[,i,o]=nr({sourceX:e,sourceY:t,targetX:n,targetY:r});return[i,o,0,0]}function wo({sourceX:e,sourceY:t,targetX:n,targetY:r}){return[(e+n)/2,(t+r)/2,0,0]}function Mo(e,t,n){const r=n.filter(o=>o.id!==e.id),i={...e,id:e.id,source:t.source,target:t.target,sourceHandle:t.sourceHandle??e.sourceHandle,targetHandle:t.targetHandle??e.targetHandle};return r.push(i),r}const kn=160,Cn=60,rn=20,wn=12,En=20;function yr(e,t,n){var l,h;const r=e.width||((l=e.measured)==null?void 0:l.width)||kn,i=e.height||((h=e.measured)==null?void 0:h.height)||Cn,o=e._absolutePosition||e.position;if(e.handles&&e.handles.length>0){for(const v of e.handles)if(v.type===t&&(!n||v.id===n)){if(v.x!==void 0&&v.y!==void 0)return{x:o.x+v.x,y:o.y+v.y,dir:v.position||(t==="source"?"right":"left")};switch(v.position||(t==="source"?"right":"left")){case"top":return{x:o.x+r/2,y:o.y,dir:"top"};case"bottom":return{x:o.x+r/2,y:o.y+i,dir:"bottom"};case"left":return{x:o.x,y:o.y+i/2,dir:"left"};default:return{x:o.x+r,y:o.y+i/2,dir:"right"}}}}return t==="source"?{x:o.x+r,y:o.y+i/2,dir:"right"}:{x:o.x,y:o.y+i/2,dir:"left"}}function Sn(e,t){switch(e.dir){case"right":return{x:e.x+t,y:e.y,dir:e.dir};case"left":return{x:e.x-t,y:e.y,dir:e.dir};case"bottom":return{x:e.x,y:e.y+t,dir:e.dir};case"top":return{x:e.x,y:e.y-t,dir:e.dir};default:return{x:e.x+t,y:e.y,dir:e.dir}}}function Ro(e,t,n,r,i,o,l,h){const v=Math.min(e,n),f=Math.max(e,n),y=Math.min(t,r),x=Math.max(t,r);if(f<=i||v>=i+l||x<=o||y>=o+h)return!1;const R=.5;if(e>i+R&&e<i+l-R&&t>o+R&&t<o+h-R||n>i+R&&n<i+l-R&&r>o+R&&r<o+h-R)return!0;const C=(e+n)/2,z=(t+r)/2;if(C>i+R&&C<i+l-R&&z>o+R&&z<o+h-R)return!0;const W=[[i,o],[i+l,o],[i+l,o+h],[i,o+h]];for(let j=0;j<4;j++)if(ko(e,t,n,r,W[j][0],W[j][1],W[(j+1)%4][0],W[(j+1)%4][1]))return!0;return!1}function ko(e,t,n,r,i,o,l,h){const v=(l-i)*(t-o)-(h-o)*(e-i),f=(l-i)*(r-o)-(h-o)*(n-i),y=(n-e)*(o-t)-(r-t)*(i-e),x=(n-e)*(h-t)-(r-t)*(l-e);return(v>0&&f<0||v<0&&f>0)&&(y>0&&x<0||y<0&&x>0)}function Vn(e,t,n,r,i){for(let o=0;o<i.length;o++){const l=i[o];if(Ro(e,t,n,r,l.x,l.y,l.w,l.h))return!1}return!0}function Co(e,t,n){for(let r=0;r<n.length;r++){const i=n[r];if(e>i.x&&e<i.x+i.w&&t>i.y&&t<i.y+i.h)return!0}return!1}function or(e,t){var r,i;const n=[];for(let o=0;o<e.length;o++){const l=e[o];if(l.hidden||t&&t.has(l.id)||l.type==="group")continue;const h=l._absolutePosition||l.position,v=l.width||((r=l.measured)==null?void 0:r.width)||kn,f=l.height||((i=l.measured)==null?void 0:i.height)||Cn;n.push({id:l.id,x:h.x-rn,y:h.y-rn,w:v+2*rn,h:f+2*rn})}return n}function Br(e,t,n){if(Vn(e.x,e.y,t.x,t.y,n))return null;const r=new Set,i=new Set;r.add(e.x),r.add(t.x),i.add(e.y),i.add(t.y);const o=rn+5;e.dir==="right"?r.add(e.x+o):e.dir==="left"?r.add(e.x-o):e.dir==="top"?i.add(e.y-o):e.dir==="bottom"&&i.add(e.y+o),t.dir==="right"?r.add(t.x+o):t.dir==="left"?r.add(t.x-o):t.dir==="top"?i.add(t.y-o):t.dir==="bottom"&&i.add(t.y+o);for(let d=0;d<n.length;d++){const b=n[d];r.add(b.x),r.add(b.x+b.w),i.add(b.y),i.add(b.y+b.h)}const l=[...r].sort((d,b)=>d-b),h=[...i].sort((d,b)=>d-b),v=new Map,f=new Map;for(let d=0;d<l.length;d++)v.set(l[d],d);for(let d=0;d<h.length;d++)f.set(h[d],d);const y=l.length,x=h.length,R=(d,b)=>b*y+d,C=v.get(e.x),z=f.get(e.y),W=v.get(t.x),j=f.get(t.y);if(C===void 0||z===void 0||W===void 0||j===void 0)return null;const D=R(C,z),F=R(W,j),$=new Float64Array(y*x).fill(1/0),X=new Float64Array(y*x).fill(1/0),A=new Int32Array(y*x).fill(-1),P=new Int8Array(y*x).fill(-1),Z=new Uint8Array(y*x);$[D]=0,X[D]=Math.abs(l[W]-e.x)+Math.abs(h[j]-e.y);const q=[D],O=15,M=[[1,0],[-1,0],[0,1],[0,-1]];for(;q.length>0;){let d=0;for(let te=1;te<q.length;te++)X[q[te]]<X[q[d]]&&(d=te);const b=q[d];if(q[d]=q[q.length-1],q.pop(),b===F){const te=[];let ce=F;for(;ce!==-1&&ce!==D;){const me=ce/y|0,Me=ce%y;te.unshift({x:l[Me],y:h[me]}),ce=A[ce]}return te.unshift({x:e.x,y:e.y}),Eo(te,n)}if(Z[b])continue;Z[b]=1;const L=b/y|0,T=b%y,B=l[T],Q=h[L],oe=P[b];for(let te=0;te<4;te++){const ce=T+M[te][0],me=L+M[te][1];if(ce<0||ce>=y||me<0||me>=x)continue;const Me=R(ce,me);if(Z[Me])continue;const ke=l[ce],le=h[me];if(Co(ke,le,n)||!Vn(B,Q,ke,le,n))continue;const xe=Math.abs(ke-B)+Math.abs(le-Q),ie=oe>=0&&oe!==te?O:0,fe=$[b]+xe+ie;fe<$[Me]&&(A[Me]=b,P[Me]=te,$[Me]=fe,X[Me]=fe+Math.abs(l[W]-ke)+Math.abs(h[j]-le),q.push(Me))}}return null}function Eo(e,t){if(!e||e.length<=2)return e;const n=[e[0]];for(let r=1;r<e.length-1;r++){const i=n[n.length-1],o=e[r],l=e[r+1],h=Math.abs(i.x-o.x)<.5&&Math.abs(o.x-l.x)<.5,v=Math.abs(i.y-o.y)<.5&&Math.abs(o.y-l.y)<.5;(h||v)&&Vn(i.x,i.y,l.x,l.y,t)||n.push(o)}return n.push(e[e.length-1]),n}function So(e){const t=new Map,n=new Map;for(const i of e){const o=i._routedPoints;if(!(!o||o.length<2))for(let l=0;l<o.length-1;l++){const h=o[l],v=o[l+1];if(Math.abs(h.y-v.y)<.5){const f=Math.round(h.y*10)/10;t.has(f)||t.set(f,[]),t.get(f).push({edgeId:i.id,segIdx:l,x1:Math.min(h.x,v.x),x2:Math.max(h.x,v.x)})}else if(Math.abs(h.x-v.x)<.5){const f=Math.round(h.x*10)/10;n.has(f)||n.set(f,[]),n.get(f).push({edgeId:i.id,segIdx:l,y1:Math.min(h.y,v.y),y2:Math.max(h.y,v.y)})}}}const r=new Map;for(const i of e)i._routedPoints&&r.set(i.id,i._routedPoints.map(o=>({...o})));for(const[,i]of t){if(i.length<2)continue;const o=xr(i,"x1","x2");for(const l of o){if(l.length<2)continue;const h=(l.length-1)*wn/2;for(let v=0;v<l.length;v++){const f=l[v],y=-h+v*wn,x=r.get(f.edgeId);x&&(x[f.segIdx].y+=y,x[f.segIdx+1].y+=y)}}}for(const[,i]of n){if(i.length<2)continue;const o=xr(i,"y1","y2");for(const l of o){if(l.length<2)continue;const h=(l.length-1)*wn/2;for(let v=0;v<l.length;v++){const f=l[v],y=-h+v*wn,x=r.get(f.edgeId);x&&(x[f.segIdx].x+=y,x[f.segIdx+1].x+=y)}}}return e.map(i=>{const o=r.get(i.id);return o?{...i,_routedPoints:o}:i})}function xr(e,t,n){if(e.length<2)return[];const r=[...e].sort((l,h)=>l[t]-h[t]),i=[];let o=[r[0]];for(let l=1;l<r.length;l++){const h=o[o.length-1];r[l][t]<h[n]?o.push(r[l]):(o.length>1&&i.push(o),o=[r[l]])}return o.length>1&&i.push(o),i}function zn(e,t=6,n=!1){if(!e||e.length<2)return null;if(n)return zo(e);const r=t;let i=`M ${e[0].x},${e[0].y}`;for(let o=1;o<e.length-1;o++){const l=e[o-1],h=e[o],v=e[o+1],f=Math.abs(h.x-l.x)+Math.abs(h.y-l.y),y=Math.abs(v.x-h.x)+Math.abs(v.y-h.y),x=Math.min(r,f/2,y/2);if(x>.5){const R=h.x-l.x,C=h.y-l.y,z=v.x-h.x,W=v.y-h.y,j=Math.sqrt(R*R+C*C)||1,D=Math.sqrt(z*z+W*W)||1;i+=` L ${h.x-R/j*x},${h.y-C/j*x}`,i+=` Q ${h.x},${h.y} ${h.x+z/D*x},${h.y+W/D*x}`}else i+=` L ${h.x},${h.y}`}return i+=` L ${e[e.length-1].x},${e[e.length-1].y}`,i}function zo(e){if(e.length===2)return`M ${e[0].x},${e[0].y} L ${e[1].x},${e[1].y}`;if(e.length===3)return`M ${e[0].x},${e[0].y} Q ${e[1].x},${e[1].y} ${e[2].x},${e[2].y}`;const t=.3;let n=`M ${e[0].x},${e[0].y}`;for(let r=0;r<e.length-1;r++){const i=e[r===0?0:r-1],o=e[r],l=e[r+1],h=e[r+2<e.length?r+2:e.length-1],v=o.x+(l.x-i.x)*t,f=o.y+(l.y-i.y)*t,y=l.x-(h.x-o.x)*t,x=l.y-(h.y-o.y)*t;n+=` C ${v},${f} ${y},${x} ${l.x},${l.y}`}return n}function Pn(e){if(!e||e.length<2)return{x:0,y:0};let t=0;for(let r=1;r<e.length;r++)t+=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);let n=t/2;for(let r=1;r<e.length;r++){const i=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);if(n<=i){const o=i>0?n/i:0;return{x:e[r-1].x+(e[r].x-e[r-1].x)*o,y:e[r-1].y+(e[r].y-e[r-1].y)*o}}n-=i}return{x:e[0].x,y:e[0].y}}function Po(e,t){if(!e||!t||e.length===0||t.length===0)return t;const n={};for(const o of e)n[o.id]=o;const r=or(e,null),i=t.map(o=>{var P,Z,q,O;const l=o.type||"default";if(l==="bezier"||l==="simplebezier"||l==="default")return o;const h=n[o.source],v=n[o.target];if(!h||!v||h.hidden||v.hidden)return o;const f=yr(h,"source",o.sourceHandle),y=yr(v,"target",o.targetHandle),x=Sn(f,En),R=Sn(y,En),C=5,z=r.filter(M=>M.id!==o.source&&M.id!==o.target),W=h._absolutePosition||h.position,j=h.width||((P=h.measured)==null?void 0:P.width)||kn,D=h.height||((Z=h.measured)==null?void 0:Z.height)||Cn;z.push({id:o.source,x:W.x-C,y:W.y-C,w:j+2*C,h:D+2*C});const F=v._absolutePosition||v.position,$=v.width||((q=v.measured)==null?void 0:q.width)||kn,X=v.height||((O=v.measured)==null?void 0:O.height)||Cn;if(z.push({id:o.target,x:F.x-C,y:F.y-C,w:$+2*C,h:X+2*C}),z.length===0)return o;const A=Br(x,R,z);return A&&A.length>=2?(A.unshift({x:f.x,y:f.y}),A.push({x:y.x,y:y.y}),{...o,_routedPoints:A}):o});return So(i)}function No(e,t,n,r,i,o,l,h){const v=or(l,h?new Set(h):null);if(v.length===0)return null;const f={x:e,y:t,dir:i||"right"},y={x:n,y:r,dir:o||"left"},x=Sn(f,En),R=Sn(y,En),C=Br(x,R,v);return C&&C.length>=2?(C.unshift({x:f.x,y:f.y}),C.push({x:y.x,y:y.y}),C):null}const sr=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,label:l,labelStyle:h,labelShowBg:v,labelBgStyle:f,labelBgPadding:y,labelBgBorderRadius:x,style:R,markerEnd:C,markerStart:z,interactionWidth:W,routedPoints:j}){let D,F,$;if(j&&j.length>=2){D=zn(j);const X=Pn(j);F=X.x,$=X.y}else[D,F,$]=tr({sourceX:n,sourceY:r,targetX:i,targetY:o});return N.jsx(cn,{id:t,path:D,labelX:F,labelY:$,label:l,labelStyle:h,labelShowBg:v,labelBgStyle:f,labelBgPadding:y,labelBgBorderRadius:x,style:R,markerEnd:C,markerStart:z,interactionWidth:W})});sr.displayName="StraightEdge";const ir=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:l="bottom",targetPosition:h="top",label:v,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:R,labelBgBorderRadius:C,style:z,markerEnd:W,markerStart:j,pathOptions:D,interactionWidth:F,routedPoints:$}){let X,A,P;if($&&$.length>=2){X=zn($);const Z=Pn($);A=Z.x,P=Z.y}else[X,A,P]=Rn({sourceX:n,sourceY:r,sourcePosition:l,targetX:i,targetY:o,targetPosition:h,borderRadius:D==null?void 0:D.borderRadius,offset:D==null?void 0:D.offset});return N.jsx(cn,{id:t,path:X,labelX:A,labelY:P,label:v,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:R,labelBgBorderRadius:C,style:z,markerEnd:W,markerStart:j,interactionWidth:F})});ir.displayName="SmoothStepEdge";const $r=a.memo(function({id:t,...n}){var i;const r=a.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(i=n.pathOptions)==null?void 0:i.offset]);return N.jsx(ir,{...n,id:t,pathOptions:r})});$r.displayName="StepEdge";const ar=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:l,targetPosition:h,label:v,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:R,labelBgBorderRadius:C,style:z,markerEnd:W,markerStart:j,interactionWidth:D,routedPoints:F}){let $,X,A;if(F&&F.length>=2){$=zn(F);const P=Pn(F);X=P.x,A=P.y}else[$,X,A]=rr({sourceX:n,sourceY:r,targetX:i,targetY:o});return N.jsx(cn,{id:t,path:$,labelX:X,labelY:A,label:v,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:R,labelBgBorderRadius:C,style:z,markerEnd:W,markerStart:j,interactionWidth:D})});ar.displayName="SimpleBezierEdge";const Io={input:Pr,output:Nr,group:Ir},To={bezier:er,straight:sr,simplebezier:ar},Lo=160,Bo=60;function $o(e){let t=!1;for(let n=0;n<e.length;n++){const r=e[n];if(!r.measured||r.measured.width==null||r.measured.height==null){t=!0;break}}return t?e.map(n=>{var r,i;return((r=n.measured)==null?void 0:r.width)!=null&&((i=n.measured)==null?void 0:i.height)!=null?n:{...n,measured:{width:n.width||Lo,height:n.height||Bo}}}):e}function Ao({cards:e,nodes:t=[],edges:n=[],nodeTypes:r,edgeTypes:i,canvasNodeTypes:o,domNodeLimit:l=50,dark:h,gridSize:v,width:f="100%",height:y="420px",className:x="",style:R={},zoomMin:C,zoomMax:z,initialCamera:W,fitView:j,fitViewOptions:D,onNodesChange:F,onEdgesChange:$,onConnect:X,onConnectStart:A,onConnectEnd:P,onNodeClick:Z,onNodeDoubleClick:q,onNodeMouseEnter:O,onNodeMouseMove:M,onNodeMouseLeave:d,onNodeContextMenu:b,onNodeDragStart:L,onNodeDrag:T,onNodeDragStop:B,onEdgeClick:Q,onEdgeDoubleClick:oe,onEdgeMouseEnter:te,onEdgeMouseMove:ce,onEdgeMouseLeave:me,onEdgeContextMenu:Me,onPaneClick:ke,onPaneContextMenu:le,onPaneMouseEnter:xe,onPaneMouseMove:ie,onPaneMouseLeave:fe,onSelectionChange:Ce,onInit:je,onMoveStart:ge,onMove:de,onMoveEnd:Ae,onDelete:_e,onBeforeDelete:We,onError:nt,onDragOver:De,onDrop:$e,onDragEnter:Ie,onDragLeave:Ee,nodesDraggable:Ge,nodesConnectable:rt,elementsSelectable:He,multiSelectionKeyCode:Ue,selectionOnDrag:Ke,selectionMode:zt,connectionMode:ln,connectionRadius:un,connectOnClick:dn,isValidConnection:fn,defaultEdgeOptions:Ot,snapToGrid:ht,snapGrid:gt,deleteKeyCode:Pt,panActivationKeyCode:Nn,panOnScroll:In,panOnScrollMode:ot,panOnScrollSpeed:cr,zoomOnScroll:Tn,zoomOnDoubleClick:Ln,zoomOnPinch:Nt,preventScrolling:It,translateExtent:Bn,nodeExtent:$n,autoPanOnNodeDrag:An,autoPanOnConnect:bt,autoPanSpeed:be,edgesReconnectable:Tt,elevateNodesOnSelect:Se,elevateEdgesOnSelect:ue,noDragClassName:yt,noPanClassName:ee,onSelectionDragStart:ze,onSelectionDrag:hn,onSelectionDragStop:Lt,edgeRouting:Bt=!0,onHudUpdate:$t,onNodesProcessed:jn,showHud:Fe=!0,showHint:Xe=!0,hintText:At="Drag to pan · Scroll to zoom",children:st,...gn}){const[Qe,yn]=a.useState({wx:0,wy:0,zoom:"1.00"}),xn=a.useRef(null),Ut=a.useRef(null),pn=a.useCallback(_=>{yn(_),$t==null||$t(_)},[$t]),xt=a.useMemo(()=>({...Io,...r}),[r]),it=a.useMemo(()=>({...To,...i}),[i]),Je=a.useMemo(()=>$o(t),[t]),[V,at]=a.useState(()=>new Set),wt=a.useRef(V);wt.current=V;const jt=a.useCallback(_=>{at(pe=>{const ne=new Set(pe);return ne.add(_),ne})},[]),Dt=a.useCallback(_=>{at(pe=>{const ne=new Set(pe);return ne.delete(_),ne})},[]),Ht=a.useCallback(_=>{at(pe=>{const ne=new Set(pe);return ne.has(_)?ne.delete(_):ne.add(_),ne})},[]),dt=a.useMemo(()=>Je.filter(_=>_.type&&xt[_.type]),[Je,xt]),_t=a.useMemo(()=>n.filter(_=>_.type&&it[_.type]),[n,it]),[Mt,Wt]=a.useState(()=>new Set),Ft=a.useRef(new Set),Pe=a.useRef(!0),Yt=a.useMemo(()=>{const _=new Set(Mt);for(const ne of V)_.add(ne);if(Pe.current&&Mt.size===0)for(const ne of dt)_.add(ne.id);else Pe.current=!1;for(const ne of dt)(ne.selected||ne.dragging)&&_.add(ne.id);const pe=Ft.current;if(pe.size===_.size){let ne=!0;for(const u of _)if(!pe.has(u)){ne=!1;break}if(ne)return pe}return Ft.current=_,_},[dt,V,Mt]),Te=a.useMemo(()=>{if(l===0)return[];const _=Je.filter(pe=>Yt.has(pe.id));return _.sort((pe,ne)=>{const u=pe.type==="group"||!pe.parentId&&_.some(c=>c.parentId===pe.id),p=ne.type==="group"||!ne.parentId&&_.some(c=>c.parentId===ne.id);return u&&!p?-1:!u&&p?1:0})},[Je,Yt,l]),Dn=a.useMemo(()=>t.map(_=>Yt.has(_.id)?{..._,_customRendered:!0}:_),[t,Yt]),pt=a.useMemo(()=>n.map(_=>_.type&&it[_.type]?{..._,_customRendered:!0}:_),[n,it]),{wrapRef:Rt,canvasRef:ct,canvasReady:mt,onPointerDown:mn,onPointerMove:Le,onPointerUp:et,store:ye}=Mr({cards:e,nodes:Dn,edges:pt,dark:h,gridSize:v,zoomMin:C,zoomMax:z,initialCamera:W,fitView:j,fitViewOptions:D,onHudUpdate:pn,onNodesProcessed:jn,onNodesChange:F,onEdgesChange:$,onConnect:X,onConnectStart:A,onConnectEnd:P,onNodeClick:Z,onNodeDoubleClick:q,onNodeMouseEnter:O,onNodeMouseMove:M,onNodeMouseLeave:d,onNodeContextMenu:b,onNodeDragStart:L,onNodeDrag:T,onNodeDragStop:B,onEdgeClick:Q,onEdgeDoubleClick:oe,onEdgeMouseEnter:te,onEdgeMouseMove:ce,onEdgeMouseLeave:me,onEdgeContextMenu:Me,onPaneClick:ke,onPaneContextMenu:le,onPaneMouseEnter:xe,onPaneMouseMove:ie,onPaneMouseLeave:fe,onSelectionChange:Ce,onInit:je,onMoveStart:ge,onMove:de,onMoveEnd:Ae,onDelete:_e,onBeforeDelete:We,onError:nt,nodesDraggable:Ge,nodesConnectable:rt,elementsSelectable:He,multiSelectionKeyCode:Ue,selectionOnDrag:Ke,selectionMode:zt,connectionMode:ln,connectionRadius:un,connectOnClick:dn,isValidConnection:fn,defaultEdgeOptions:Ot,snapToGrid:ht,snapGrid:gt,deleteKeyCode:Pt,panActivationKeyCode:Nn,panOnScroll:In,panOnScrollMode:ot,panOnScrollSpeed:cr,zoomOnScroll:Tn,zoomOnDoubleClick:Ln,zoomOnPinch:Nt,preventScrolling:It,translateExtent:Bn,nodeExtent:$n,autoPanOnNodeDrag:An,autoPanOnConnect:bt,autoPanSpeed:be,edgesReconnectable:Tt,elevateNodesOnSelect:Se,elevateEdgesOnSelect:ue,noDragClassName:yt,noPanClassName:ee,onSelectionDragStart:ze,onSelectionDrag:hn,onSelectionDragStop:Lt,edgeRouting:Bt}),qt=a.useRef(dt);qt.current=dt;const kt=a.useRef(l);kt.current=l,a.useEffect(()=>{let _;const pe=()=>{const u=qt.current,p=kt.current;if(p===0||!u.length)return;const c=ye.cameraRef.current,g=ye.wrapRef.current;if(!g)return;const k=g.clientWidth,S=g.clientHeight,m=(-c.x+k/2)/c.zoom,E=(-c.y+S/2)/c.zoom,w=wt.current;let H=w.size;for(const Y of u)(Y.selected||Y.dragging)&&H++;const I=Math.max(0,p-H);if(I===0)Wt(Y=>Y.size===0?Y:new Set);else{const Y=new Set(w);for(const K of u)(K.selected||K.dragging)&&Y.add(K.id);const G=[];for(let K=0;K<u.length;K++){const U=u[K];if(Y.has(U.id))continue;const ae=U._absolutePosition||U.position,Re=ae.x+(U.width||160)/2-m,Be=ae.y+(U.height||60)/2-E;G.push({id:U.id,dist:Re*Re+Be*Be})}G.sort((K,U)=>K.dist-U.dist);const re=new Set;for(let K=0;K<Math.min(I,G.length);K++)re.add(G[K].id);Wt(K=>{if(K.size!==re.size)return re;for(const U of re)if(!K.has(U))return re;return K})}},ne=setTimeout(pe,100);return _=setInterval(pe,500),()=>{clearTimeout(ne),clearInterval(_)}},[ye.cameraRef,ye.wrapRef]);const Ve=a.useRef(new Set);a.useEffect(()=>{if(!o||!ye.workerRef.current)return;let _=!1;async function pe(u){const p=new Blob([u],{type:"image/svg+xml"}),c=URL.createObjectURL(p),g=new Image;return g.src=c,await g.decode(),URL.revokeObjectURL(c),createImageBitmap(g)}async function ne(){var k,S,m;const u={},p=[],c={},g={};for(const[E,w]of Object.entries(o)){if(typeof w=="function"){c[E]=w;continue}if(typeof w=="object"&&w!==null&&!(w instanceof ImageBitmap)&&!(w instanceof HTMLImageElement)&&!(w instanceof HTMLCanvasElement)&&("fill"in w||"stroke"in w||"title"in w||"accent"in w)){g[E]=w;continue}try{let H;w instanceof ImageBitmap?H=w:typeof w=="string"?H=await pe(w):w instanceof HTMLImageElement?H=await createImageBitmap(w):w instanceof HTMLCanvasElement&&(H=await createImageBitmap(w)),H&&!_&&(u[E]=H,p.push(H))}catch(H){console.warn(`[InfiniteCanvas] Failed to convert canvasNodeType "${E}":`,H)}}if(!_&&Object.keys(u).length>0&&((k=ye.workerRef.current)==null||k.postMessage({type:"nodeTypeBitmaps",data:{bitmaps:u}},p)),!_&&Object.keys(g).length>0&&((S=ye.workerRef.current)==null||S.postMessage({type:"nodeTypeConfigs",data:{configs:g}})),!_&&Object.keys(c).length>0){const E=new Map,w={},H={},I=[];let Y=Ve.current.size;for(const G of t){const re=c[G.type];if(re)try{const K=re(G.data);if(!K)continue;let U=E.get(K);if(!U&&(U="bmp_"+Y++,E.set(K,U),!Ve.current.has(K))){const ae=await pe(K);if(_)return;w[U]=ae,I.push(ae),Ve.current.add(K)}H[G.id]=U}catch(K){console.warn(`[InfiniteCanvas] canvasNodeType fn error for node "${G.id}":`,K)}}_||(m=ye.workerRef.current)==null||m.postMessage({type:"nodeBitmaps",data:{cache:w,keys:H}},I)}}return ne(),()=>{_=!0}},[o,t,ye.workerRef]);const Ct=a.useContext(St),we=Ct&&typeof Ct.getState=="function";a.useEffect(()=>{we&&queueMicrotask(()=>{Ct.setState({nodes:Je,edges:n,nodesRef:ye.nodesRef,edgesRef:ye.edgesRef,onNodesChangeRef:ye.onNodesChangeRef,onEdgesChangeRef:ye.onEdgesChangeRef,cameraRef:ye.cameraRef,wrapRef:ye.wrapRef,workerRef:ye.workerRef})})},[we,Je,n,ye,Ct]);const vt=a.useMemo(()=>({...ye,edgeLabelContainerRef:xn,viewportPortalRef:Ut,pinNode:jt,unpinNode:Dt,togglePinNode:Ht,get pinnedNodeIds(){return wt.current},get nodes(){return Je},get edges(){return n},get viewport(){return ye.cameraRef.current},get minZoom(){return ye.zoomMin||.1},get maxZoom(){return ye.zoomMax||5},get domNode(){return ye.wrapRef.current},get width(){var _;return((_=ye.wrapRef.current)==null?void 0:_.clientWidth)||0},get height(){var _;return((_=ye.wrapRef.current)==null?void 0:_.clientHeight)||0}}),[ye,Je,n,jt,Dt,Ht]),lt=a.useRef(null),Zt=a.useRef(null),Gt=a.useRef(null),Qt=a.useRef(null),Jt=a.useRef(null);a.useEffect(()=>{let _;const pe=()=>{const ne=ye.cameraRef.current,u=`translate(${ne.x}px, ${ne.y}px) scale(${ne.zoom})`,p=`translate(${ne.x}, ${ne.y}) scale(${ne.zoom})`;lt.current&&(lt.current.style.transform=u),Zt.current&&Zt.current.setAttribute("transform",p),Gt.current&&(Gt.current.style.transform=u),Qt.current&&(Qt.current.style.transform=u);const c=Rt.current;if(c){const g=ne.zoom<.15?"lod-minimal":ne.zoom<.35?"lod-reduced":null;g!==Jt.current&&(c.classList.remove("lod-minimal","lod-reduced"),g&&c.classList.add(g),Jt.current=g)}_=requestAnimationFrame(pe)};return _=requestAnimationFrame(pe),()=>cancelAnimationFrame(_)},[ye]);const[Vt,Hn]=a.useState(null);a.useEffect(()=>{if(!Te.length)return;let _;const pe=()=>{var w,H;const ne=ye.cameraRef.current,u=ye.wrapRef.current;if(!u){_=requestAnimationFrame(pe);return}const p=u.getBoundingClientRect(),c=200,g=-ne.x/ne.zoom-c,k=-ne.y/ne.zoom-c,S=(p.width-ne.x)/ne.zoom+c,m=(p.height-ne.y)/ne.zoom+c,E=new Set;for(const I of Te){const Y=I._absolutePosition||I.position,G=I.width||((w=I.measured)==null?void 0:w.width)||200,re=I.height||((H=I.measured)==null?void 0:H.height)||100;Y.x+G>=g&&Y.x<=S&&Y.y+re>=k&&Y.y<=m&&E.add(I.id)}Hn(I=>{if(!I||I.size!==E.size)return E;for(const Y of E)if(!I.has(Y))return E;return I}),_=requestAnimationFrame(pe)};return _=requestAnimationFrame(pe),()=>cancelAnimationFrame(_)},[Te,ye]);const _n=a.useMemo(()=>Vt?Te.filter(_=>Vt.has(_.id)):Te,[Te,Vt]),Wn=Te.length>0,Fn=_t.length>0;return N.jsx(St.Provider,{value:vt,children:N.jsxs("div",{ref:Rt,className:`ric-wrap ${x}`,style:{width:f,height:y,...R},onPointerDown:mn,onPointerMove:Le,onPointerUp:et,onDragOver:De,onDrop:$e,onDragEnter:Ie,onDragLeave:Ee,tabIndex:0,children:[N.jsx("canvas",{ref:ct,className:"ric-canvas"}),!mt&&N.jsx("div",{className:"ric-loader",children:N.jsx("div",{className:"ric-spinner"})}),Fn&&N.jsx("svg",{className:"ric-edges-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:N.jsx("g",{ref:Zt,children:_t.map(_=>N.jsx(yo,{edge:_,edgeType:it[_.type],nodes:t,reconnectable:Tt},_.id))})}),Wn&&N.jsx("div",{ref:lt,className:"ric-nodes-overlay",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:10},children:_n.map(_=>N.jsx(uo,{node:_,nodeType:xt[_.type]},_.id))}),N.jsx("div",{ref:_=>{xn.current=_,Gt.current=_},className:"ric-edge-labels",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:5}}),N.jsx("div",{ref:_=>{Ut.current=_,Qt.current=_},className:"ric-viewport-portal",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:6}}),Xe&&N.jsx("div",{className:"ric-hint",children:At}),Fe&&N.jsxs("div",{className:"ric-info",children:["world: (",Qe.wx,", ",Qe.wy,")   zoom: ",Qe.zoom,"x",Qe.nodeCount>0&&N.jsxs(N.Fragment,{children:["   nodes: ",Qe.nodeCount]}),Qe.edgeCount>0&&N.jsxs(N.Fragment,{children:["   edges: ",Qe.edgeCount]})]}),N.jsx(Sr,{selectionKeyCode:Ue||"Shift",selectionMode:zt||"partial"}),st]})})}function jo({children:e}){const t=a.useRef(null);return t.current||(t.current=ao()),N.jsx(St.Provider,{value:t.current,children:e})}function Ar(e,t){const n=[],r=new Map,i=[];for(const o of e)if(o.type==="add")i.push(o);else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const l=r.get(o.id);l?l.push(o):r.set(o.id,[o])}for(const o of t){const l=r.get(o.id);if(!l){n.push(o);continue}if(l[0].type==="remove")continue;if(l[0].type==="replace"){n.push({...l[0].item});continue}const h={...o};for(const v of l)Do(v,h);n.push(h)}for(const o of i)o.index!==void 0?n.splice(o.index,0,{...o.item}):n.push({...o.item});return n}function Do(e,t){switch(e.type){case"select":t.selected=e.selected;break;case"position":e.position!==void 0&&(t.position=e.position),e.dragging!==void 0&&(t.dragging=e.dragging);break;case"dimensions":e.dimensions!==void 0&&(t.measured={...e.dimensions},(e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height)),e.handleBounds!==void 0&&(t.handleBounds=e.handleBounds);break}}function jr(e,t){return Ar(e,t)}function Dr(e,t){return Ar(e,t)}function Ho(e,t){return!e.source||!e.target?(console.warn("addEdge: source and target are required"),t):t.some(r=>r.source===e.source&&r.target===e.target&&(r.sourceHandle||null)===(e.sourceHandle||null)&&(r.targetHandle||null)===(e.targetHandle||null))?t:[...t,{id:e.id||`e-${e.source}-${e.target}`,...e}]}function _o(e){const[t,n]=a.useState(e),r=a.useCallback(i=>n(o=>jr(i,o)),[]);return[t,n,r]}function Wo(e){const[t,n]=a.useState(e),r=a.useCallback(i=>n(o=>Dr(i,o)),[]);return[t,n,r]}function Hr(){const e=Rr(),t=a.useCallback(()=>typeof e.getState=="function"?e.getState():e,[e]),n=a.useCallback(()=>[...t().nodesRef.current],[t]),r=a.useCallback(()=>[...t().edgesRef.current],[t]),i=a.useCallback(M=>t().nodesRef.current.find(d=>d.id===M),[t]),o=a.useCallback(M=>t().edgesRef.current.find(d=>d.id===M),[t]),l=a.useCallback(M=>{var d,b,L,T;if(typeof M=="function"){const B=M(t().nodesRef.current);(b=(d=t().onNodesChangeRef).current)==null||b.call(d,[...t().nodesRef.current.map(Q=>({id:Q.id,type:"remove"})),...B.map(Q=>({type:"add",item:Q}))])}else(T=(L=t().onNodesChangeRef).current)==null||T.call(L,[...t().nodesRef.current.map(B=>({id:B.id,type:"remove"})),...M.map(B=>({type:"add",item:B}))])},[t]),h=a.useCallback(M=>{var d,b,L,T;if(typeof M=="function"){const B=M(t().edgesRef.current);(b=(d=t().onEdgesChangeRef).current)==null||b.call(d,[...t().edgesRef.current.map(Q=>({id:Q.id,type:"remove"})),...B.map(Q=>({type:"add",item:Q}))])}else(T=(L=t().onEdgesChangeRef).current)==null||T.call(L,[...t().edgesRef.current.map(B=>({id:B.id,type:"remove"})),...M.map(B=>({type:"add",item:B}))])},[t]),v=a.useCallback(M=>{var b,L;const d=Array.isArray(M)?M:[M];(L=(b=t().onNodesChangeRef).current)==null||L.call(b,d.map(T=>({type:"add",item:T})))},[t]),f=a.useCallback(M=>{var b,L;const d=Array.isArray(M)?M:[M];(L=(b=t().onEdgesChangeRef).current)==null||L.call(b,d.map(T=>({type:"add",item:T})))},[t]),y=a.useCallback(({nodes:M=[],edges:d=[]})=>{if(M.length&&t().onNodesChangeRef.current){t().onNodesChangeRef.current(M.map(L=>({id:L.id,type:"remove"})));const b=br(M,t().edgesRef.current);b.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(b.map(L=>({id:L.id,type:"remove"})))}d.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(d.map(b=>({id:b.id,type:"remove"})))},[t]),x=a.useCallback(()=>{const M=t().cameraRef.current;return{x:M.x,y:M.y,zoom:M.zoom}},[t]),R=a.useRef(null),C=a.useCallback((M,d)=>{if(R.current&&cancelAnimationFrame(R.current),!d||d<=0){t().cameraRef.current={...M},t().sendCamera();return}const b={...t().cameraRef.current},L=performance.now(),T=B=>{const Q=B-L,oe=Math.min(Q/d,1),te=1-Math.pow(1-oe,3);t().cameraRef.current={x:b.x+(M.x-b.x)*te,y:b.y+(M.y-b.y)*te,zoom:b.zoom+(M.zoom-b.zoom)*te},t().sendCamera(),oe<1&&(R.current=requestAnimationFrame(T))};R.current=requestAnimationFrame(T)},[t]),z=a.useCallback((M,d)=>{const b={x:M.x??t().cameraRef.current.x,y:M.y??t().cameraRef.current.y,zoom:M.zoom??t().cameraRef.current.zoom};C(b,d==null?void 0:d.duration)},[t,C]),W=a.useCallback(()=>t().cameraRef.current.zoom,[t]),j=a.useCallback(M=>{const d=t().cameraRef.current,b=t().wrapRef.current;if(!b)return;const L=b.getBoundingClientRect(),T=L.width/2,B=L.height/2,Q=1.2,oe={x:T-(T-d.x)*Q,y:B-(B-d.y)*Q,zoom:Math.min(t().zoomMax,d.zoom*Q)};C(oe,M==null?void 0:M.duration)},[t,C]),D=a.useCallback(M=>{const d=t().cameraRef.current,b=t().wrapRef.current;if(!b)return;const L=b.getBoundingClientRect(),T=L.width/2,B=L.height/2,Q=1/1.2,oe={x:T-(T-d.x)*Q,y:B-(B-d.y)*Q,zoom:Math.max(t().zoomMin,d.zoom*Q)};C(oe,M==null?void 0:M.duration)},[t,C]),F=a.useCallback((M,d)=>{const b=t().cameraRef.current,L=t().wrapRef.current;if(!L)return;const T=L.getBoundingClientRect(),B=T.width/2,Q=T.height/2,oe=Math.min(t().zoomMax,Math.max(t().zoomMin,M)),te=oe/b.zoom,ce={x:B-(B-b.x)*te,y:Q-(Q-b.y)*te,zoom:oe};C(ce,d==null?void 0:d.duration)},[t,C]),$=a.useCallback((M={})=>{const d=t().nodesRef.current;if(!d.length)return;const b=t().wrapRef.current;if(!b)return;const L=b.getBoundingClientRect(),T=M.padding??.1,B=M.nodes?d.filter(te=>M.nodes.some(ce=>ce.id===te.id)):d;if(!B.length)return;const Q=Mn(B),oe=Xt(Q,L.width,L.height,T);M.maxZoom&&(oe.zoom=Math.min(oe.zoom,M.maxZoom)),M.minZoom&&(oe.zoom=Math.max(oe.zoom,M.minZoom)),C(oe,M.duration)},[t,C]),X=a.useCallback((M,d={})=>{const b=t().wrapRef.current;if(!b)return;const L=b.getBoundingClientRect(),T=d.padding??.1,B=Xt(M,L.width,L.height,T);d.maxZoom&&(B.zoom=Math.min(B.zoom,d.maxZoom)),d.minZoom&&(B.zoom=Math.max(B.zoom,d.minZoom)),C(B,d.duration)},[t,C]),A=a.useCallback((M,d,b={})=>{const L=t().wrapRef.current;if(!L)return;const T=L.getBoundingClientRect(),B=b.zoom??t().cameraRef.current.zoom,Q={x:T.width/2-M*B,y:T.height/2-d*B,zoom:B};C(Q,b.duration)},[t,C]),P=a.useCallback(()=>({nodes:[...t().nodesRef.current],edges:[...t().edgesRef.current],viewport:{...t().cameraRef.current}}),[t]),Z=a.useCallback(M=>t().screenToWorld(M.x,M.y),[t]),q=a.useCallback(M=>{const d=t().cameraRef.current,b=t().wrapRef.current;if(!b)return{x:0,y:0};const L=b.getBoundingClientRect();return{x:M.x*d.zoom+d.x+L.left,y:M.y*d.zoom+d.y+L.top}},[t]),O=a.useCallback((M,d)=>{var T,B;const b=t().nodesRef.current.find(Q=>Q.id===M);if(!b)return;const L=typeof d=="function"?d(b.data):{...b.data,...d};(B=(T=t().onNodesChangeRef).current)==null||B.call(T,[{id:M,type:"replace",item:{...b,data:L}}])},[t]);return{getNodes:n,getEdges:r,getNode:i,getEdge:o,setNodes:l,setEdges:h,addNodes:v,addEdges:f,deleteElements:y,getViewport:x,setViewport:z,getZoom:W,zoomIn:j,zoomOut:D,zoomTo:F,fitView:$,fitBounds:X,setCenter:A,screenToFlowPosition:Z,flowToScreenPosition:q,updateNodeData:O,toObject:P}}function Fo(){return Ne().nodes}function Yo(){return Ne().edges}function Xo(){return Ne().viewport}function Oo(){return Ne().connection}function Uo(e){const t=Ne(),n=Array.isArray(e)?e:[e];return a.useMemo(()=>n.map(r=>{const i=t.nodes.find(o=>o.id===r);return i?{id:i.id,type:i.type,data:i.data}:null}).filter(Boolean),[t.nodes,...n])}function qo(e){const t=Ne();return a.useMemo(()=>t.edges.filter(n=>n.source===e||n.target===e),[t.edges,e])}function Zo({nodeId:e,type:t,handleId:n}){const r=Ne();return a.useMemo(()=>r.edges.filter(i=>t==="source"?i.source===e&&(n?i.sourceHandle===n:!0):i.target===e&&(n?i.targetHandle===n:!0)),[r.edges,e,t,n])}function Go({onChange:e,onStart:t,onEnd:n}){const r=Ne(),i=a.useRef(e),o=a.useRef(t),l=a.useRef(n);a.useEffect(()=>{i.current=e},[e]),a.useEffect(()=>{o.current=t},[t]),a.useEffect(()=>{l.current=n},[n]),a.useEffect(()=>{const h=v=>{var f;(f=i.current)==null||f.call(i,{x:v.x,y:v.y,zoom:v.zoom})};return r.viewportListeners.add(h),()=>r.viewportListeners.delete(h)},[s])}function Qo({onChange:e}){const t=Ne(),n=a.useRef(e);a.useEffect(()=>{n.current=e},[e]),a.useEffect(()=>{const r=i=>{var o;(o=n.current)==null||o.call(n,i)};return t.selectionListeners.add(r),()=>t.selectionListeners.delete(r)},[s])}function Jo(e){const[t,n]=a.useState(!1),r=Array.isArray(e)?e:[e];return a.useEffect(()=>{const i=l=>{r.includes(l.key)&&n(!0)},o=l=>{r.includes(l.key)&&n(!1)};return window.addEventListener("keydown",i),window.addEventListener("keyup",o),()=>{window.removeEventListener("keydown",i),window.removeEventListener("keyup",o)}},[r.join(",")]),t}function Vo(){const e=Ne();return a.useCallback(t=>{var n;(n=e.workerRef.current)==null||n.postMessage({type:"nodes",data:{nodes:[...s().nodesRef.current]}})},[s])}const Ko=e=>{var t;return((t=e.nodes)==null?void 0:t.length)>0};function es(e={}){return Ne(Ko)}function ts(e){const t=Ne();return a.useMemo(()=>t.nodes.find(n=>n.id===e)||void 0,[t.nodes,e])}function ns(e,t){return Ne(e,t)}function rs(){return Rr()}function os({maxHistorySize:e=100}={}){const t=Ne(),n=a.useRef([]),r=a.useRef([]),[,i]=a.useState(0),o=a.useRef(null),l=a.useCallback(()=>{const f={nodes:s().nodesRef.current.map(y=>({...y,data:{...y.data}})),edges:s().edgesRef.current.map(y=>({...y}))};o.current&&JSON.stringify(o.current.nodes.map(y=>y.id))===JSON.stringify(f.nodes.map(y=>y.id))&&JSON.stringify(o.current.edges.map(y=>y.id))===JSON.stringify(f.edges.map(y=>y.id))||(n.current.push(f),n.current.length>e&&n.current.shift(),r.current=[],o.current=f,i(y=>y+1))},[t,e]),h=a.useCallback(()=>{var y,x,R,C;const f=n.current.pop();f&&(r.current.push({nodes:s().nodesRef.current.map(z=>({...z,data:{...z.data}})),edges:s().edgesRef.current.map(z=>({...z}))}),(x=(y=s().onNodesChangeRef).current)==null||x.call(y,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...f.nodes.map(z=>({type:"add",item:z}))]),(C=(R=s().onEdgesChangeRef).current)==null||C.call(R,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...f.edges.map(z=>({type:"add",item:z}))]),o.current=f,i(z=>z+1))},[s]),v=a.useCallback(()=>{var y,x,R,C;const f=r.current.pop();f&&(n.current.push({nodes:s().nodesRef.current.map(z=>({...z,data:{...z.data}})),edges:s().edgesRef.current.map(z=>({...z}))}),(x=(y=s().onNodesChangeRef).current)==null||x.call(y,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...f.nodes.map(z=>({type:"add",item:z}))]),(C=(R=s().onEdgesChangeRef).current)==null||C.call(R,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...f.edges.map(z=>({type:"add",item:z}))]),o.current=f,i(z=>z+1))},[s]);return{undo:h,redo:v,takeSnapshot:l,canUndo:n.current.length>0,canRedo:r.current.length>0}}function ss(e){const t=a.useRef(e);return a.useEffect(()=>{t.current=e},[e]),a.useCallback(n=>r=>{const i=t.current(r);i!==!1&&i!=null&&n(Array.isArray(i)?i:r)},[])}function is(e){const t=a.useRef(e);return a.useEffect(()=>{t.current=e},[e]),a.useCallback(n=>r=>{const i=t.current(r);i!==!1&&i!=null&&n(Array.isArray(i)?i:r)},[])}const Un=160,qn=60;function as({width:e=200,height:t=150,nodeColor:n="#3b82f6",nodeStrokeColor:r="#fff",maskColor:i="rgba(0,0,0,0.1)",style:o={},className:l=""}){const h=Ne(),v=a.useRef(null),f=a.useRef(null),y=a.useCallback(()=>{const x=v.current;if(!x)return;const R=x.getContext("2d"),C=window.devicePixelRatio||1;x.width=e*C,x.height=t*C,R.scale(C,C),R.clearRect(0,0,e,t);const z=h.nodesRef.current;if(!z.length)return;let W=1/0,j=1/0,D=-1/0,F=-1/0;for(const d of z){const b=d.width||Un,L=d.height||qn;d.position.x<W&&(W=d.position.x),d.position.y<j&&(j=d.position.y),d.position.x+b>D&&(D=d.position.x+b),d.position.y+L>F&&(F=d.position.y+L)}const $=40;W-=$,j-=$,D+=$,F+=$;const X=D-W,A=F-j,P=Math.min(e/X,t/A),Z=(e-X*P)/2,q=(t-A*P)/2;for(const d of z){if(d.hidden)continue;const b=d.width||Un,L=d.height||qn,T=(d.position.x-W)*P+Z,B=(d.position.y-j)*P+q,Q=b*P,oe=L*P;R.fillStyle=d.selected?"#f59e0b":typeof n=="function"?n(d):n,R.fillRect(T,B,Math.max(Q,2),Math.max(oe,2))}const O=h.cameraRef.current,M=h.wrapRef.current;if(M){const d=M.getBoundingClientRect(),b=-O.x/O.zoom,L=-O.y/O.zoom,T=d.width/O.zoom,B=d.height/O.zoom;R.fillStyle=i,R.fillRect(0,0,e,t);const Q=(b-W)*P+Z,oe=(L-j)*P+q,te=T*P,ce=B*P;R.clearRect(Q,oe,te,ce);for(const me of z){if(me.hidden)continue;const Me=me.width||Un,ke=me.height||qn,le=(me.position.x-W)*P+Z,xe=(me.position.y-j)*P+q;R.fillStyle=me.selected?"#f59e0b":typeof n=="function"?n(me):n,R.fillRect(le,xe,Math.max(Me*P,2),Math.max(ke*P,2))}R.strokeStyle="#3b82f6",R.lineWidth=1.5,R.strokeRect(Q,oe,te,ce)}},[h,e,t,n,r,i]);return a.useEffect(()=>{let x=!0;function R(){x&&(y(),f.current=requestAnimationFrame(R))}const C=setInterval(()=>{cancelAnimationFrame(f.current),f.current=requestAnimationFrame(R)},66);return y(),()=>{x=!1,clearInterval(C),cancelAnimationFrame(f.current)}},[y]),N.jsx("canvas",{ref:v,className:`ric-minimap ${l}`,style:{position:"absolute",bottom:30,right:10,width:e,height:t,borderRadius:4,border:"1px solid rgba(0,0,0,0.1)",background:"rgba(255,255,255,0.9)",pointerEvents:"none",...o}})}function cs(){return N.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),N.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function ls(){return N.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:N.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function us(){return N.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:N.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}function ds(){return N.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),N.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function fs(){return N.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),N.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})}function on({children:e,className:t="",...n}){return N.jsx("button",{className:`ric-controls-button ${t}`,style:gs,...n,children:e})}function hs({showZoom:e=!0,showFitView:t=!0,showInteractive:n=!1,fitViewOptions:r,onZoomIn:i,onZoomOut:o,onFitView:l,onInteractiveChange:h,position:v="bottom-left",orientation:f="vertical",style:y={},className:x="","aria-label":R="Canvas controls",children:C}){const z=Ne(),{zoomIn:W,zoomOut:j,fitView:D,getZoom:F}=Hr(),[$,X]=a.useState(!0),A=F()<=z.zoomMin,P=F()>=z.zoomMax,Z=a.useCallback(()=>{W(),i==null||i()},[W,i]),q=a.useCallback(()=>{j(),o==null||o()},[j,o]),O=a.useCallback(()=>{D(r||{padding:.1}),l==null||l()},[D,r,l]),M=a.useCallback(()=>{const b=!$;X(b),h==null||h(b)},[$,h]),d={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:30,left:10},"bottom-right":{bottom:30,right:10},"bottom-center":{bottom:30,left:"50%",transform:"translateX(-50%)"}}[v]||{bottom:30,left:10};return N.jsxs("div",{className:`ric-controls ${x}`,style:{position:"absolute",display:"flex",flexDirection:f==="horizontal"?"row":"column",gap:2,zIndex:5,...d,...y},role:"toolbar","aria-label":R,children:[e&&N.jsxs(N.Fragment,{children:[N.jsx(on,{onClick:Z,disabled:P,title:"Zoom in","aria-label":"Zoom in",className:"ric-controls-zoomin",children:N.jsx(cs,{})}),N.jsx(on,{onClick:q,disabled:A,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:N.jsx(ls,{})})]}),t&&N.jsx(on,{onClick:O,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:N.jsx(us,{})}),n&&N.jsx(on,{onClick:M,title:$?"Lock interactivity":"Unlock interactivity","aria-label":$?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:$?N.jsx(fs,{}):N.jsx(ds,{})}),C]})}const gs={width:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid rgba(0,0,0,0.12)",borderRadius:4,background:"#fff",cursor:"pointer",fontSize:16,lineHeight:1,color:"#333",padding:0},ys=a.memo(hs);function xs({variant:e="lines",gap:t=40,size:n=1,color:r,style:i={},className:o=""}){const l=Ne();return l.workerRef.current&&l.workerRef.current.postMessage({type:"background",data:{variant:e,gap:t,size:n,color:r}}),null}function ps({position:e="top-left",style:t={},className:n="",children:r}){const i={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:10,left:10},"bottom-right":{bottom:10,right:10},"bottom-center":{bottom:10,left:"50%",transform:"translateX(-50%)"}}[e]||{top:10,left:10};return N.jsx("div",{className:`ric-panel ${n}`,style:{position:"absolute",zIndex:5,pointerEvents:"all",...i,...t},onPointerDown:o=>o.stopPropagation(),children:r})}function ms({minWidth:e=10,minHeight:t=10,maxWidth:n=1/0,maxHeight:r=1/0,isVisible:i=!0,handleStyle:o={},lineStyle:l={},color:h="#3b82f6",onResizeStart:v,onResize:f,onResizeEnd:y}){const x=a.useContext(an),R=Ne(),C=a.useRef(null),z=a.useCallback((D,F)=>{D.stopPropagation(),D.preventDefault();const $=R.nodesRef.current.find(P=>P.id===x);if(!$)return;C.current={direction:F,startX:D.clientX,startY:D.clientY,width:$.width||160,height:$.height||60},v==null||v(D,{width:C.current.width,height:C.current.height});const X=P=>{var L,T;if(!C.current)return;const Z=C.current,q=R.cameraRef.current,O=(P.clientX-Z.startX)/q.zoom,M=(P.clientY-Z.startY)/q.zoom;let d=Z.width,b=Z.height;Z.direction.includes("e")&&(d=Math.min(n,Math.max(e,Z.width+O))),Z.direction.includes("w")&&(d=Math.min(n,Math.max(e,Z.width-O))),Z.direction.includes("s")&&(b=Math.min(r,Math.max(t,Z.height+M))),Z.direction.includes("n")&&(b=Math.min(r,Math.max(t,Z.height-M))),(T=(L=R.onNodesChangeRef).current)==null||T.call(L,[{id:x,type:"dimensions",dimensions:{width:d,height:b},setAttributes:!0}]),f==null||f(P,{width:d,height:b})},A=P=>{C.current=null,y==null||y(P,{}),window.removeEventListener("pointermove",X),window.removeEventListener("pointerup",A)};window.addEventListener("pointermove",X),window.addEventListener("pointerup",A)},[x,R,e,t,n,r,v,f,y]);if(!i)return null;const W=8,j={position:"absolute",width:W,height:W,background:h,border:"1px solid #fff",borderRadius:2,zIndex:20,...o};return N.jsxs(N.Fragment,{children:[N.jsx("div",{style:{...j,bottom:-W/2,right:-W/2,cursor:"nwse-resize"},onPointerDown:D=>z(D,"se")}),N.jsx("div",{style:{...j,bottom:-W/2,left:-W/2,cursor:"nesw-resize"},onPointerDown:D=>z(D,"sw")}),N.jsx("div",{style:{...j,top:-W/2,right:-W/2,cursor:"nesw-resize"},onPointerDown:D=>z(D,"ne")}),N.jsx("div",{style:{...j,top:-W/2,left:-W/2,cursor:"nwse-resize"},onPointerDown:D=>z(D,"nw")}),N.jsx("div",{style:{...j,top:"50%",right:-W/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:D=>z(D,"e")}),N.jsx("div",{style:{...j,top:"50%",left:-W/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:D=>z(D,"w")}),N.jsx("div",{style:{...j,left:"50%",top:-W/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:D=>z(D,"n")}),N.jsx("div",{style:{...j,left:"50%",bottom:-W/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:D=>z(D,"s")})]})}function vs({isVisible:e,position:t="top",offset:n=10,align:r="center",children:i,style:o={},className:l=""}){const h=a.useContext(an),f=Ne().nodes.find(R=>R.id===h);if(!(e!==void 0?e:f==null?void 0:f.selected))return null;const x={top:{bottom:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginBottom:n},bottom:{top:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginTop:n},left:{right:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginRight:n},right:{left:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginLeft:n}}[t]||{};return N.jsx("div",{className:`ric-node-toolbar ${l}`,style:{position:"absolute",zIndex:1e3,pointerEvents:"all",...x,...o},onPointerDown:R=>R.stopPropagation(),children:i})}function bs({isVisible:e=!1,x:t=0,y:n=0,alignX:r="center",alignY:i="center",children:o,style:l={},className:h=""}){if(!e)return null;const v=r==="center"?"-50%":r==="right"?"-100%":"0",f=i==="center"?"-50%":i==="bottom"?"-100%":"0";return N.jsx("div",{className:`ric-edge-toolbar ${h}`,style:{position:"absolute",left:t,top:n,transform:`translate(${v}, ${f})`,zIndex:1e3,pointerEvents:"all",...l},children:o})}function ws({children:e}){var r;const n=(r=Ne().edgeLabelContainerRef)==null?void 0:r.current;return n?pr.createPortal(e,n):null}function Ms({children:e}){var r;const n=(r=Ne().viewportPortalRef)==null?void 0:r.current;return n?pr.createPortal(e,n):null}function _r({fromX:e,fromY:t,toX:n,toY:r,fromPosition:i="right",toPosition:o="left",connectionLineType:l="default",connectionLineStyle:h,connectionLineComponent:v}){if(v)return N.jsx(v,{fromX:e,fromY:t,toX:n,toY:r,fromPosition:i,toPosition:o});let f;switch(l){case"straight":[f]=tr({sourceX:e,sourceY:t,targetX:n,targetY:r});break;case"step":[f]=Rn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o,borderRadius:0});break;case"smoothstep":[f]=Rn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o});break;case"simplebezier":[f]=rr({sourceX:e,sourceY:t,targetX:n,targetY:r});break;default:[f]=nr({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o});break}return N.jsx("path",{d:f,fill:"none",className:"ric-connection-line",stroke:"#b1b1b7",strokeWidth:1.5,style:h})}_r.displayName="ConnectionLine";const Rs=a.memo(_r),ks=Object.freeze({Top:"top",Bottom:"bottom",Left:"left",Right:"right"}),Cs=Object.freeze({Arrow:"arrow",ArrowClosed:"arrowclosed"});function Es(e){const t=e.width||e.measured&&e.measured.width||0,n=e.height||e.measured&&e.measured.height||0,r=e._absolutePosition||e.position||{x:0,y:0};return{x:r.x,y:r.y,x2:r.x+t,y2:r.y+n}}exports.Background=xs;exports.BaseEdge=cn;exports.BezierEdge=er;exports.ConnectionLine=Rs;exports.ControlButton=on;exports.Controls=ys;exports.DefaultNode=vo;exports.EdgeLabelRenderer=ws;exports.EdgeText=Lr;exports.EdgeToolbar=bs;exports.GroupNode=Ir;exports.Handle=sn;exports.InfiniteCanvas=Ao;exports.InfiniteCanvasProvider=jo;exports.InputNode=Pr;exports.MarkerType=Cs;exports.MiniMap=as;exports.NodeResizer=ms;exports.NodeToolbar=vs;exports.OutputNode=Nr;exports.Panel=ps;exports.Position=ks;exports.SelectionBox=Sr;exports.SimpleBezierEdge=ar;exports.SmoothStepEdge=ir;exports.StepEdge=$r;exports.StraightEdge=sr;exports.ViewportPortal=Ms;exports.addEdge=Ho;exports.applyEdgeChanges=Dr;exports.applyNodeChanges=jr;exports.boxToRect=Qr;exports.buildObstacles=or;exports.clampPosition=Gn;exports.computeRoutedEdges=Po;exports.getBezierEdgeCenter=bo;exports.getBezierPath=nr;exports.getBoundsOfBoxes=Jr;exports.getConnectedEdges=br;exports.getEdgeCenter=wo;exports.getIncomers=Ur;exports.getNodeDimensions=Kn;exports.getNodesBounds=Mn;exports.getNodesInside=Zr;exports.getOutgoers=qr;exports.getOverlappingArea=Vr;exports.getRoutedLabelPosition=Pn;exports.getSimpleBezierPath=rr;exports.getSmoothStepPath=Rn;exports.getStraightPath=tr;exports.getViewportForBounds=Xt;exports.isEdge=Or;exports.isNode=Xr;exports.nodeToBox=Es;exports.nodeToRect=Kr;exports.reconnectEdge=Mo;exports.rectToBox=Gr;exports.routeSinglePath=No;exports.routedPointsToPath=zn;exports.snapPosition=Zn;exports.useConnection=Oo;exports.useEdges=Yo;exports.useEdgesState=Wo;exports.useHandleConnections=Zo;exports.useInfiniteCanvas=Mr;exports.useInternalNode=ts;exports.useKeyPress=Jo;exports.useNodeConnections=qo;exports.useNodeId=co;exports.useNodes=Fo;exports.useNodesData=Uo;exports.useNodesInitialized=es;exports.useNodesState=_o;exports.useOnEdgesChangeMiddleware=is;exports.useOnNodesChangeMiddleware=ss;exports.useOnSelectionChange=Qo;exports.useOnViewportChange=Go;exports.useReactFlow=Hr;exports.useStore=ns;exports.useStoreApi=rs;exports.useUndoRedo=os;exports.useUpdateNodeInternals=Vo;exports.useViewport=Xo;
948
+ `,ur=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",Mr],{type:"text/javascript;charset=utf-8"});function to(e){let t;try{if(t=ur&&(self.URL||self.webkitURL).createObjectURL(ur),!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(Mr),{type:"module",name:e==null?void 0:e.name})}}const Un=new WeakMap;function no(e,t){if(Un.has(e))return Un.get(e);const n=e.transferControlToOffscreen(),r=new to;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 Un.set(e,a),a}const dt=160,tt=60,ro=10;function Rr({cards:e=[],nodes:t=[],edges:n=[],onHudUpdate:r,onNodesProcessed:a,onNodesChange:o,onEdgesChange:c,onConnect:h,onNodeClick:m,onNodeDragStart:f,onNodeDrag:y,onNodeDragStop:x,onEdgeClick:k,onEdgeDoubleClick:S,onEdgeMouseEnter:z,onEdgeMouseMove:W,onEdgeMouseLeave:j,onEdgeContextMenu:H,onNodeDoubleClick:F,onNodeMouseEnter:$,onNodeMouseMove:Y,onNodeMouseLeave:A,onNodeContextMenu:P,onPaneClick:Z,onPaneContextMenu:O,onPaneMouseEnter:X,onPaneMouseMove:M,onPaneMouseLeave:d,onSelectionChange:v,onConnectStart:L,onConnectEnd:T,onInit:B,onMoveStart:Q,onMove:ne,onMoveEnd:ee,onDelete:ie,onBeforeDelete:me,onError:we,isValidConnection:Re,dark:ce,gridSize:pe=40,zoomMin:oe=.1,zoomMax:ge=4,initialCamera:Se={x:0,y:0,zoom:1},fitView:De=!1,fitViewOptions:xe,nodesDraggable:fe=!0,nodesConnectable:Ae=!0,elementsSelectable:Fe=!0,multiSelectionKeyCode:Ye="Shift",selectionOnDrag:nt=!1,selectionMode:He="partial",connectionMode:$e="loose",connectionRadius:Le=20,connectOnClick:ze=!1,snapToGrid:Je=!1,snapGrid:rt=[15,15],deleteKeyCode:_e=["Delete","Backspace"],panActivationKeyCode:Oe=" ",panOnScroll:Ke=!1,panOnScrollMode:zt="free",panOnScrollSpeed:un=.5,zoomOnScroll:dn=!0,zoomOnDoubleClick:fn=!0,zoomOnPinch:hn=!0,preventScrolling:qt=!0,translateExtent:mt,nodeExtent:vt,defaultEdgeOptions:Pt={},autoPanOnNodeDrag:Nn=!0,autoPanOnConnect:In=!0,autoPanSpeed:ot=5,edgesReconnectable:lr=!1,elevateNodesOnSelect:Tn=!1,elevateEdgesOnSelect:Ln=!1,noDragClassName:Nt="nodrag",noPanClassName:It="nopan",onSelectionDragStart:Bn,onSelectionDrag:$n,onSelectionDragStop:An,edgeRouting:kt=!0}={}){const be=i.useRef(null),Tt=i.useRef(null),Pe=i.useRef(null),de=i.useRef({...Se}),bt=i.useRef([...e]),se=i.useRef([...t]),Ne=i.useRef([...n]),ft=i.useRef(null);if(!ft.current){const u=new Map;for(const g of se.current)u.set(g.id,g);ft.current=u}const gn=i.useRef(new Map),Lt=i.useRef(!1),ht=i.useRef(null),[jn,Dn]=i.useState(!1),Xe=i.useRef(null),Ue=i.useRef(null),Bt=i.useRef(null),gt=i.useRef(null),Ve=i.useRef(!1),$t=i.useRef(null),[Zt,yn]=i.useState({x:Se.x,y:Se.y,zoom:Se.zoom}),[xn,At]=i.useState(null),st=i.useMemo(()=>new Set,[]),qe=i.useMemo(()=>new Set,[]),wt=i.useRef(!1),K=i.useRef({});K.current={onHudUpdate:r,onNodesProcessed:a,onNodesChange:o,onEdgesChange:c,onConnect:h,onNodeClick:m,onNodeDragStart:f,onNodeDrag:y,onNodeDragStop:x,onEdgeClick:k,onEdgeDoubleClick:S,onEdgeMouseEnter:z,onEdgeMouseMove:W,onEdgeMouseLeave:j,onEdgeContextMenu:H,onNodeDoubleClick:F,onNodeMouseEnter:$,onNodeMouseMove:Y,onNodeMouseLeave:A,onNodeContextMenu:P,onPaneClick:Z,onPaneContextMenu:O,onPaneMouseEnter:X,onPaneMouseMove:M,onPaneMouseLeave:d,onSelectionChange:v,onConnectStart:L,onConnectEnd:T,onInit:B,onMoveStart:Q,onMove:ne,onMoveEnd:ee,onDelete:ie,onBeforeDelete:me,onError:we,onSelectionDragStart:Bn,onSelectionDrag:$n,onSelectionDragStop:An,isValidConnection:Re};const at={get current(){return K.current.onConnect}},jt={get current(){return K.current.onNodeClick}},Dt={get current(){return K.current.onNodeDragStart}},Ht={get current(){return K.current.onNodeDrag}},yt={get current(){return K.current.onNodeDragStop}},_t={get current(){return K.current.onEdgeClick}},Ct={get current(){return K.current.onPaneClick}},Wt={get current(){return K.current.onSelectionChange}},Ft={get current(){return K.current.onHudUpdate}},Yt={get current(){return K.current.onNodesProcessed}};i.useEffect(()=>{const u=l=>{l.key===Ye&&(Ve.current=!0),l.key===Oe&&(wt.current=!0)},g=l=>{l.key===Ye&&(Ve.current=!1),l.key===Oe&&(wt.current=!1)};return window.addEventListener("keydown",u),window.addEventListener("keyup",g),()=>{window.removeEventListener("keydown",u),window.removeEventListener("keyup",g)}},[Ye,Oe]);const ke={get current(){return K.current.onNodesChange?xt:null}},xt=u=>{var l,p,C;(p=(l=K.current).onNodesChange)==null||p.call(l,u);const g=[];for(let E=0;E<u.length;E++)u[E].type==="select"&&g.push({id:u[E].id,selected:u[E].selected});g.length>0&&((C=Pe.current)==null||C.postMessage({type:"nodeSelections",data:{selections:g}}))},We={get current(){return K.current.onEdgesChange?Hn:null}},Hn=u=>{var l,p,C;(p=(l=K.current).onEdgesChange)==null||p.call(l,u);const g=[];for(let E=0;E<u.length;E++)u[E].type==="select"&&g.push({id:u[E].id,selected:u[E].selected});g.length>0&&((C=Pe.current)==null||C.postMessage({type:"edgeSelections",data:{selections:g}}))},pt=i.useCallback(()=>{var p;const u=se.current.filter(C=>C.selected),g=Ne.current.filter(C=>C.selected),l={nodes:u,edges:g};(p=Wt.current)==null||p.call(Wt,l);for(const C of qe)C(l)},[qe]);i.useEffect(()=>{var u;bt.current=[...e],(u=Pe.current)==null||u.postMessage({type:"cards",data:{cards:[...e]}})},[e]);const Xt=i.useCallback(u=>{const g={};for(const l of u)g[l.id]=l;return u.map(l=>{if(!l.parentId)return l;const p=g[l.parentId];if(!p)return l;let C=l.position.x,E=l.position.y,w=p;for(;w;)C+=w.position.x,E+=w.position.y,w=w.parentId?g[w.parentId]:null;return{...l,_absolutePosition:{x:C,y:E}}})},[]),it=i.useRef([]),Mt=i.useCallback(u=>{const g=gn.current;if(!g||g.size===0)return u;const l={};for(const[,p]of g)l[p.nodeId]||(l[p.nodeId]=[]),l[p.nodeId].push({id:p.id,type:p.type,position:p.position,x:p.x,y:p.y});return u.map(p=>{const C=l[p.id];return C&&C.length>0?{...p,handles:C}:p})},[]),pn=i.useCallback(()=>{var g;if(Xe.current)return;const u=Mt(it.current);(g=Pe.current)==null||g.postMessage({type:"nodes",data:{nodes:u}})},[Mt]);i.useEffect(()=>{var l,p;if(Xe.current){const C=Xe.current.id,E=new Set([C,...Xe.current.selectedStarts.map(R=>R.id)]),w={};for(const R of se.current)E.has(R.id)&&(w[R.id]={...R.position});se.current=[...t];for(const R of se.current)w[R.id]&&(R.position=w[R.id]);{const R=ft.current;R.clear();for(const D of se.current)R.set(D.id,D)}it.current=Xt(se.current);const b=Mt(it.current);(l=Pe.current)==null||l.postMessage({type:"nodes",data:{nodes:b}});return}se.current=[...t];{const C=ft.current;C.clear();for(const E of se.current)C.set(E.id,E)}const u=Xt(t);it.current=u;const g=Mt(u);(p=Pe.current)==null||p.postMessage({type:"nodes",data:{nodes:g}})},[t,Xt,Mt]),i.useEffect(()=>{var u;Ne.current=[...n],(u=Pe.current)==null||u.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const Be=i.useCallback((u,g)=>{const l=be.current;if(!l)return{x:0,y:0};const p=l.getBoundingClientRect(),C=de.current;return{x:(u-p.left-C.x)/C.zoom,y:(g-p.top-C.y)/C.zoom}},[]),le=i.useCallback((u,g)=>{const l=it.current.length>0?it.current:se.current;let p=null;for(let C=l.length-1;C>=0;C--){const E=l[C];if(E.hidden||E._customRendered)continue;const w=E._absolutePosition||E.position,b=E.width||dt,R=E.height||tt;if(u>=w.x&&u<=w.x+b&&g>=w.y&&g<=w.y+R){if(E.type==="group"){p||(p=E);continue}return E}}return p},[]),Gt=i.useCallback((u,g)=>{const l=g.width||dt,p=g.height||tt;if(u.x!==void 0&&u.y!==void 0)return{x:g.position.x+u.x,y:g.position.y+u.y};switch(u.position||(u.type==="source"?"right":"left")){case"top":return{x:g.position.x+l/2,y:g.position.y};case"bottom":return{x:g.position.x+l/2,y:g.position.y+p};case"left":return{x:g.position.x,y:g.position.y+p/2};case"right":return{x:g.position.x+l,y:g.position.y+p/2};default:return{x:g.position.x+l,y:g.position.y+p/2}}},[]),Qt=i.useCallback(u=>{const g=u.width||dt,l=u.height||tt;if(u.handles&&u.handles.length>0)return u.handles.map(R=>{const D=Gt(R,u);return{id:R.id||null,type:R.type,x:D.x,y:D.y}});const p=u.targetPosition||"left",C=u.sourcePosition||"right",E=R=>{switch(R){case"top":return{x:u.position.x+g/2,y:u.position.y};case"bottom":return{x:u.position.x+g/2,y:u.position.y+l};case"left":return{x:u.position.x,y:u.position.y+l/2};case"right":return{x:u.position.x+g,y:u.position.y+l/2};default:return{x:u.position.x+g,y:u.position.y+l/2}}},w=E(p),b=E(C);return[{id:null,type:"target",x:w.x,y:w.y},{id:null,type:"source",x:b.x,y:b.y}]},[Gt]),Rt=i.useCallback((u,g)=>{const l=se.current,p=de.current,C=Math.max(ro,Le)/p.zoom;for(let E=l.length-1;E>=0;E--){const w=l[E];if(w.hidden)continue;const b=Qt(w);for(const R of b)if(Math.abs(u-R.x)<C&&Math.abs(g-R.y)<C)return{nodeId:w.id,handleId:R.id,type:R.type,x:R.x,y:R.y}}return null},[Qt]),Ze=i.useCallback((u,g)=>{const p=8/de.current.zoom,C=ft.current;for(let E=Ne.current.length-1;E>=0;E--){const w=Ne.current[E],b=C.get(w.source),R=C.get(w.target);if(!b||!R)continue;const D=b.width||dt,N=b.height||tt,q=R.height||tt,J=b.position.x+D,U=b.position.y+N/2,ae=R.position.x,Ie=R.position.y+q/2;if(oo(u,g,J,U,ae,Ie)<p)return w}return null},[]);i.useEffect(()=>{const u=Tt.current,g=be.current;if(!u||!g)return;const l=g.getBoundingClientRect(),p=ce!==void 0?ce:matchMedia("(prefers-color-scheme: dark)").matches,C=Xt(se.current);it.current=C;const E=Mt(C),{worker:w}=no(u,{width:l.width,height:l.height,camera:de.current,cards:bt.current,nodes:E,edges:Ne.current,dark:p,gridSize:pe,edgeRouting:kt});w.onmessage=N=>{var q,J,U,ae;N.data.type==="hud"&&((q=Ft.current)==null||q.call(Ft,N.data.data)),N.data.type==="ready"&&Dn(!0),N.data.type==="nodesProcessed"&&((J=Yt.current)==null||J.call(Yt,N.data.data)),N.data.type==="error"&&((ae=(U=K.current).onError)==null||ae.call(U,"worker-error",N.data.message||"Canvas worker error"))},w.onerror=N=>{var q,J;(J=(q=K.current).onError)==null||J.call(q,"worker-error",N.message||"Canvas worker crashed")},Pe.current=w;const b=new ResizeObserver(N=>{const{width:q,height:J}=N[0].contentRect;w.postMessage({type:"resize",data:{width:q,height:J}})});b.observe(g);let R,D;return ce===void 0&&(R=matchMedia("(prefers-color-scheme: dark)"),D=N=>w.postMessage({type:"theme",data:{dark:N.matches}}),R.addEventListener("change",D)),()=>{b.disconnect(),R&&D&&R.removeEventListener("change",D),Pe.current=null}},[]),i.useEffect(()=>{var u;ce!==void 0&&((u=Pe.current)==null||u.postMessage({type:"theme",data:{dark:ce}}))},[ce]),i.useEffect(()=>{var u;(u=Pe.current)==null||u.postMessage({type:"edgeRouting",data:{enabled:kt}})},[kt]);const Jt=i.useRef(0),Me=i.useCallback((u=null)=>{var p,C,E;const g=de.current;if(mt){const w=be.current;if(w){const b=w.getBoundingClientRect(),R=-mt[1][0]*g.zoom+b.width,D=-mt[1][1]*g.zoom+b.height,N=-mt[0][0]*g.zoom,q=-mt[0][1]*g.zoom;g.x=Math.min(N,Math.max(R,g.x)),g.y=Math.min(q,Math.max(D,g.y))}}(p=Pe.current)==null||p.postMessage({type:"camera",data:{camera:{...g}}});const l={x:g.x,y:g.y,zoom:g.zoom};(E=(C=K.current).onMove)==null||E.call(C,u,l);for(const w of st)w(l);cancelAnimationFrame(Jt.current),Jt.current=requestAnimationFrame(()=>{yn({x:g.x,y:g.y,zoom:g.zoom})})},[st,mt]),ct=i.useCallback(()=>{var l,p;const u=Ue.current,g=Bt.current;u&&g?((l=Pe.current)==null||l.postMessage({type:"connecting",data:{from:u.startPos,to:g,_routedPoints:null}}),At({source:u.sourceId,sourceHandle:u.sourceHandle,target:null,targetHandle:null})):((p=Pe.current)==null||p.postMessage({type:"connecting",data:null}),At(null))},[]),lt=i.useCallback(()=>{var g,l;const u=gt.current;u?(g=Pe.current)==null||g.postMessage({type:"selectionBox",data:u}):(l=Pe.current)==null||l.postMessage({type:"selectionBox",data:null})},[]),Kt=i.useCallback(u=>{var w,b,R,D,N,q,J,U,ae,Ie,te,ue,Ee,je,et,Ge,ut,en;const g=se.current.length>0,l=Be(u.clientX,u.clientY),p=Ve.current;if(g&&Ae&&!p){const G=Rt(l.x,l.y);if(ze&&$t.current&&G){const re=$t.current;if(G.nodeId!==re.nodeId){const Qe=re.handleType==="target"?{source:G.nodeId,target:re.nodeId,sourceHandle:G.handleId||null,targetHandle:re.handleId}:{source:re.nodeId,target:G.nodeId,sourceHandle:re.handleId,targetHandle:G.handleId||null};(K.current.isValidConnection?K.current.isValidConnection(Qe):!0)&&((w=at.current)==null||w.call(at,{...Qe,...Pt}))}$t.current=null;return}if($e==="strict"?G&&G.type==="source":G!=null){if(ze){$t.current={nodeId:G.nodeId,handleId:G.handleId||null,handleType:G.type},(R=(b=K.current).onConnectStart)==null||R.call(b,u,{nodeId:G.nodeId,handleId:G.handleId,handleType:G.type});return}Ue.current={sourceId:G.nodeId,sourceHandle:G.handleId||null,sourceType:G.type,startPos:{x:G.x,y:G.y}},Bt.current={x:l.x,y:l.y},(D=be.current)==null||D.setPointerCapture(u.pointerId),(q=(N=K.current).onConnectStart)==null||q.call(N,u,{nodeId:G.nodeId,handleId:G.handleId,handleType:G.type}),ct();return}}const C=G=>{var re;let he=G;for(;he&&he!==be.current;){if((re=he.classList)!=null&&re.contains(Nt))return!0;he=he.parentElement}return!1},E=G=>{var re;let he=G;for(;he&&he!==be.current;){if((re=he.classList)!=null&&re.contains(It))return!0;he=he.parentElement}return!1};if(g){const G=le(l.x,l.y);if(G){if(ke.current&&Fe){const he=[];if(p)he.push({id:G.id,type:"select",selected:!G.selected});else if(!G.selected){for(const re of se.current)re.id===G.id?he.push({id:re.id,type:"select",selected:!0}):re.selected&&he.push({id:re.id,type:"select",selected:!1});if(We.current){const re=Ne.current.filter(ye=>ye.selected).map(ye=>({id:ye.id,type:"select",selected:!1}));re.length&&We.current(re)}}if(he.length){if(ke.current(he),Tn&&!p){const re=se.current.findIndex(ye=>ye.id===G.id);re>=0&&re<se.current.length-1&&ke.current([{id:G.id,type:"remove"},{type:"add",item:{...se.current[re],selected:!0}}])}pt()}}if((J=jt.current)==null||J.call(jt,u,G),fe&&!C(u.target)){const he=G.selected;let re=null;if(G.parentId&&G.extent==="parent"){const ye=se.current.find(Qe=>Qe.id===G.parentId);if(ye){const Qe=ye.width||dt,tn=ye.height||tt,vn=G.width||((U=G.measured)==null?void 0:U.width)||dt,nn=G.height||((ae=G.measured)==null?void 0:ae.height)||tt;re={minX:0,minY:0,maxX:Qe-vn,maxY:tn-nn}}}if(Xe.current={id:G.id,startPos:{...G.position},startMouse:{x:l.x,y:l.y},parentClamp:re,parentId:G.parentId||null,selectedStarts:he?se.current.filter(ye=>ye.selected&&ye.id!==G.id).map(ye=>{var tn,vn;let Qe=null;if(ye.parentId&&ye.extent==="parent"){const nn=se.current.find(Xn=>Xn.id===ye.parentId);if(nn){const Xn=nn.width||dt,Fr=nn.height||tt,Yr=ye.width||((tn=ye.measured)==null?void 0:tn.width)||dt,Xr=ye.height||((vn=ye.measured)==null?void 0:vn.height)||tt;Qe={minX:0,minY:0,maxX:Xn-Yr,maxY:Fr-Xr}}}return{id:ye.id,startPos:{...ye.position},parentClamp:Qe,parentId:ye.parentId||null}}):[]},(Ie=be.current)==null||Ie.setPointerCapture(u.pointerId),(te=Dt.current)==null||te.call(Dt,u,G),Xe.current.selectedStarts.length>0){const ye=se.current.filter(Qe=>Qe.selected);(Ee=(ue=K.current).onSelectionDragStart)==null||Ee.call(ue,u,ye)}if(ke.current){const ye=[{id:G.id,type:"position",dragging:!0}];for(const Qe of Xe.current.selectedStarts)ye.push({id:Qe.id,type:"position",dragging:!0});ke.current(ye)}}return}}if(Ne.current.length>0&&Fe){const G=Ze(l.x,l.y);if(G){if(We.current){const he=[];if(p)he.push({id:G.id,type:"select",selected:!G.selected});else{for(const re of Ne.current)re.id===G.id?he.push({id:re.id,type:"select",selected:!0}):re.selected&&he.push({id:re.id,type:"select",selected:!1});if(ke.current){const re=se.current.filter(ye=>ye.selected).map(ye=>({id:ye.id,type:"select",selected:!1}));re.length&&ke.current(re)}}if(he.length){if(We.current(he),Ln&&!p){const re=Ne.current.findIndex(ye=>ye.id===G.id);re>=0&&re<Ne.current.length-1&&We.current([{id:G.id,type:"remove"},{type:"add",item:{...Ne.current[re],selected:!0}}])}pt()}}(je=_t.current)==null||je.call(_t,u,G);return}}if(!p){const G=se.current.filter(re=>re.selected).map(re=>({id:re.id,type:"select",selected:!1})),he=Ne.current.filter(re=>re.selected).map(re=>({id:re.id,type:"select",selected:!1}));G.length&&ke.current&&ke.current(G),he.length&&We.current&&We.current(he),(G.length||he.length)&&pt()}if((et=Ct.current)==null||et.call(Ct,u),nt||p){gt.current={startWorld:{...l},endWorld:{...l}},(Ge=be.current)==null||Ge.setPointerCapture(u.pointerId),lt();return}E(u.target)||(Lt.current=!0,ht.current={x:u.clientX,y:u.clientY},(ut=be.current)==null||ut.classList.add("dragging"),(en=be.current)==null||en.setPointerCapture(u.pointerId))},[Be,le,Rt,Ze,fe,Ae,Fe,nt,ct,lt,pt,Nt,It]),Vt=i.useCallback(u=>{var l,p,C,E;if(Ue.current){if(Bt.current=Be(u.clientX,u.clientY),ct(),In){const w=be.current;if(w){const b=w.getBoundingClientRect(),R=40,D=u.clientX-b.left,N=u.clientY-b.top;let q=0,J=0;D<R?q=ot:D>b.width-R&&(q=-ot),N<R?J=ot:N>b.height-R&&(J=-ot),(q||J)&&(de.current.x+=q,de.current.y+=J,Me(u))}}return}if(gt.current){gt.current.endWorld=Be(u.clientX,u.clientY),lt();const w=gt.current,b=Math.min(w.startWorld.x,w.endWorld.x),R=Math.min(w.startWorld.y,w.endWorld.y),D=Math.max(w.startWorld.x,w.endWorld.x),N=Math.max(w.startWorld.y,w.endWorld.y);if(ke.current){const q=[];for(const J of se.current){if(J.hidden)continue;const U=J.width||dt,ae=J.height||tt,Ie=He==="full"?J.position.x>=b&&J.position.x+U<=D&&J.position.y>=R&&J.position.y+ae<=N:J.position.x+U>b&&J.position.x<D&&J.position.y+ae>R&&J.position.y<N;Ie!==!!J.selected&&q.push({id:J.id,type:"select",selected:Ie})}q.length&&ke.current(q)}return}if(Xe.current){const w=Be(u.clientX,u.clientY),b=Xe.current,R=w.x-b.startMouse.x,D=w.y-b.startMouse.y;let N={x:b.startPos.x+R,y:b.startPos.y+D};if(Je&&(N=Gn(N,rt)),vt&&(N=Qn(N,vt)),b.parentClamp){const te=b.parentClamp;N={x:Math.max(te.minX,Math.min(N.x,te.maxX)),y:Math.max(te.minY,Math.min(N.y,te.maxY))}}const q=[{id:b.id,position:N}];for(const te of b.selectedStarts){let ue={x:te.startPos.x+R,y:te.startPos.y+D};if(Je&&(ue=Gn(ue,rt)),vt&&(ue=Qn(ue,vt)),te.parentClamp){const Ee=te.parentClamp;ue={x:Math.max(Ee.minX,Math.min(ue.x,Ee.maxX)),y:Math.max(Ee.minY,Math.min(ue.y,Ee.maxY))}}q.push({id:te.id,position:ue})}const J=[],U=ft.current;for(const te of q){const ue=U.get(te.id);if(ue){ue.position=te.position,ue.dragging=!0;let Ee=te.position;if(ue.parentId){let je=U.get(ue.parentId),et=te.position.x,Ge=te.position.y;for(;je;)et+=je.position.x,Ge+=je.position.y,je=je.parentId?U.get(je.parentId):null;Ee={x:et,y:Ge}}J.push({id:te.id,position:te.position,_absolutePosition:Ee,width:ue.width,height:ue.height,dragging:!0,selected:ue.selected})}}const ae=new Set(q.map(te=>te.id));for(const te of se.current)if(te.parentId&&ae.has(te.parentId)&&!ae.has(te.id)){let ue=U.get(te.parentId),Ee=te.position.x,je=te.position.y;for(;ue;)Ee+=ue.position.x,je+=ue.position.y,ue=ue.parentId?U.get(ue.parentId):null;J.push({id:te.id,position:te.position,_absolutePosition:{x:Ee,y:je},width:te.width,height:te.height,dragging:!1,selected:te.selected})}if((l=Pe.current)==null||l.postMessage({type:"nodePositions",data:{updates:J}}),Nn){const te=be.current;if(te){const ue=te.getBoundingClientRect(),Ee=40,je=u.clientX-ue.left,et=u.clientY-ue.top;let Ge=0,ut=0;je<Ee?Ge=ot:je>ue.width-Ee&&(Ge=-ot),et<Ee?ut=ot:et>ue.height-Ee&&(ut=-ot),(Ge||ut)&&(de.current.x+=Ge,de.current.y+=ut,Me(u))}}const Ie=U.get(b.id);if(Ie&&((p=Ht.current)==null||p.call(Ht,u,Ie)),b.selectedStarts.length>0){const te=[];for(const ue of b.selectedStarts){const Ee=U.get(ue.id);Ee&&te.push(Ee)}Ie&&te.push(Ie),(E=(C=K.current).onSelectionDrag)==null||E.call(C,u,te)}return}if(!Lt.current)return;const g=de.current;g.x+=u.clientX-ht.current.x,g.y+=u.clientY-ht.current.y,ht.current={x:u.clientX,y:u.clientY},Me()},[Me,Be,ct,lt]),mn=i.useCallback(u=>{var g,l,p,C,E,w,b,R;if(Ue.current){const D=Be(u.clientX,u.clientY),N=Rt(D.x,D.y);if(N&&N.nodeId!==Ue.current.sourceId&&($e==="loose"||N.type==="target")){const U=Ue.current.sourceType==="target"?{source:N.nodeId,target:Ue.current.sourceId,sourceHandle:N.handleId||null,targetHandle:Ue.current.sourceHandle}:{source:Ue.current.sourceId,target:N.nodeId,sourceHandle:Ue.current.sourceHandle,targetHandle:N.handleId||null};(K.current.isValidConnection?K.current.isValidConnection(U):!0)&&((g=at.current)==null||g.call(at,{...U,...Pt}))}(p=(l=K.current).onConnectEnd)==null||p.call(l,u.nativeEvent||u),Ue.current=null,Bt.current=null,ct();return}if(gt.current){gt.current=null,lt(),pt();return}if(Xe.current){const D=Xe.current,N=se.current.find(U=>U.id===D.id),q=[{id:D.id,position:N?{...N.position}:D.startPos,_absolutePosition:N?{...N.position}:D.startPos,dragging:!1}];for(const U of D.selectedStarts){const ae=se.current.find(Ie=>Ie.id===U.id);q.push({id:U.id,position:ae?{...ae.position}:U.startPos,_absolutePosition:ae?{...ae.position}:U.startPos,dragging:!1})}if((C=Pe.current)==null||C.postMessage({type:"nodePositions",data:{updates:q}}),ke.current){const U=q.map(ae=>({id:ae.id,type:"position",position:ae.position,dragging:!1}));ke.current(U)}if(D.selectedStarts.length>0){const U=se.current.filter(ae=>ae.selected);(w=(E=K.current).onSelectionDragStop)==null||w.call(E,u,U)}requestAnimationFrame(()=>{Xe.current=null});const J=se.current.find(U=>U.id===D.id);J&&((b=yt.current)==null||b.call(yt,u,J));return}Lt.current=!1,(R=be.current)==null||R.classList.remove("dragging")},[Be,Rt,ct,lt,pt]);i.useEffect(()=>{const u=be.current;if(!u)return;const g=l=>{qt&&l.preventDefault();const p=de.current;if(Ke||wt.current){const R=un;zt==="horizontal"?p.x-=l.deltaY*R:(zt==="vertical"||(p.x-=l.deltaX*R),p.y-=l.deltaY*R),Me(l);return}if(!dn)return;const C=l.deltaY>0?.92:1.08,E=u.getBoundingClientRect(),w=l.clientX-E.left,b=l.clientY-E.top;p.x=w-(w-p.x)*C,p.y=b-(b-p.y)*C,p.zoom=Math.min(ge,Math.max(oe,p.zoom*C)),Me(l)};return u.addEventListener("wheel",g,{passive:!qt}),()=>u.removeEventListener("wheel",g)},[Me,oe,ge,Ke,zt,un,dn,qt]),i.useEffect(()=>{if(!hn)return;const u=be.current;if(!u)return;let g=0,l=null;const p=w=>{if(w.touches.length===2){const b=w.touches[0].clientX-w.touches[1].clientX,R=w.touches[0].clientY-w.touches[1].clientY;g=Math.hypot(b,R);const D=u.getBoundingClientRect();l={x:(w.touches[0].clientX+w.touches[1].clientX)/2-D.left,y:(w.touches[0].clientY+w.touches[1].clientY)/2-D.top},w.preventDefault()}},C=w=>{if(w.touches.length===2&&g>0){w.preventDefault();const b=w.touches[0].clientX-w.touches[1].clientX,R=w.touches[0].clientY-w.touches[1].clientY,D=Math.hypot(b,R),N=D/g;g=D;const q=de.current,J=l.x,U=l.y;q.x=J-(J-q.x)*N,q.y=U-(U-q.y)*N,q.zoom=Math.min(ge,Math.max(oe,q.zoom*N)),Me(w)}},E=()=>{g=0,l=null};return u.addEventListener("touchstart",p,{passive:!1}),u.addEventListener("touchmove",C,{passive:!1}),u.addEventListener("touchend",E),()=>{u.removeEventListener("touchstart",p),u.removeEventListener("touchmove",C),u.removeEventListener("touchend",E)}},[hn,Me,oe,ge]),i.useEffect(()=>{if(!fn)return;const u=be.current;if(!u)return;const g=l=>{var N,q,J,U;const p=Be(l.clientX,l.clientY);if(le(p.x,p.y)){(q=(N=K.current).onNodeDoubleClick)==null||q.call(N,l,le(p.x,p.y));return}const C=Ze(p.x,p.y);if(C){(U=(J=K.current).onEdgeDoubleClick)==null||U.call(J,l,C);return}const E=1.5,w=u.getBoundingClientRect(),b=l.clientX-w.left,R=l.clientY-w.top,D=de.current;D.x=b-(b-D.x)*E,D.y=R-(R-D.y)*E,D.zoom=Math.min(ge,Math.max(oe,D.zoom*E)),Me(l)};return u.addEventListener("dblclick",g),()=>u.removeEventListener("dblclick",g)},[fn,Me,oe,ge,Be,le,Ze]),i.useEffect(()=>{const u=be.current;if(!u)return;const g=l=>{var w,b,R,D,N,q;const p=Be(l.clientX,l.clientY),C=le(p.x,p.y);if(C){(b=(w=K.current).onNodeContextMenu)==null||b.call(w,l,C);return}const E=Ze(p.x,p.y);if(E){(D=(R=K.current).onEdgeContextMenu)==null||D.call(R,l,E);return}(q=(N=K.current).onPaneContextMenu)==null||q.call(N,l)};return u.addEventListener("contextmenu",g),()=>u.removeEventListener("contextmenu",g)},[Be,le,Ze]),i.useEffect(()=>{const u=be.current;if(!u)return;let g=null,l=null,p=0;const C=b=>{var q,J,U,ae,Ie,te,ue,Ee,je,et,Ge,ut,en,G;if((J=(q=K.current).onPaneMouseMove)==null||J.call(q,b),Lt.current||Xe.current||Ue.current||gt.current)return;const R=performance.now();if(R-p<32)return;p=R;const D=Be(b.clientX,b.clientY),N=le(D.x,D.y);if(N!==g&&(g&&((ae=(U=K.current).onNodeMouseLeave)==null||ae.call(U,b,g)),N&&((te=(Ie=K.current).onNodeMouseEnter)==null||te.call(Ie,b,N)),g=N),N&&((Ee=(ue=K.current).onNodeMouseMove)==null||Ee.call(ue,b,N)),!N){const he=Ze(D.x,D.y);he!==l&&(l&&((et=(je=K.current).onEdgeMouseLeave)==null||et.call(je,b,l)),he&&((ut=(Ge=K.current).onEdgeMouseEnter)==null||ut.call(Ge,b,he)),l=he),he&&((G=(en=K.current).onEdgeMouseMove)==null||G.call(en,b,he))}},E=b=>{var R,D;return(D=(R=K.current).onPaneMouseEnter)==null?void 0:D.call(R,b)},w=b=>{var R,D,N,q,J,U;(D=(R=K.current).onPaneMouseLeave)==null||D.call(R,b),g&&((q=(N=K.current).onNodeMouseLeave)==null||q.call(N,b,g),g=null),l&&((U=(J=K.current).onEdgeMouseLeave)==null||U.call(J,b,l),l=null)};return u.addEventListener("mousemove",C),u.addEventListener("mouseenter",E),u.addEventListener("mouseleave",w),()=>{u.removeEventListener("mousemove",C),u.removeEventListener("mouseenter",E),u.removeEventListener("mouseleave",w)}},[Be,le,Ze]),i.useEffect(()=>{const u=Array.isArray(_e)?_e:[_e],g=async l=>{var p,C,E,w;if(u.includes(l.key)){if(l.target.tagName==="INPUT"||l.target.tagName==="TEXTAREA"||l.target.isContentEditable)return;const b=se.current.filter(N=>N.selected),R=Ne.current.filter(N=>N.selected);if(!b.length&&!R.length)return;if(K.current.onBeforeDelete)try{if(!await K.current.onBeforeDelete({nodes:b,edges:R}))return}catch(N){(C=(p=K.current).onError)==null||C.call(p,"before-delete-error",N.message||"onBeforeDelete threw an error");return}const D=new Set(b.map(N=>N.id));if(b.length&&ke.current&&(ke.current(b.map(N=>({id:N.id,type:"remove"}))),We.current)){const N=Ne.current.filter(q=>D.has(q.source)||D.has(q.target));N.length&&We.current(N.map(q=>({id:q.id,type:"remove"})))}R.length&&We.current&&We.current(R.map(N=>({id:N.id,type:"remove"}))),(w=(E=K.current).onDelete)==null||w.call(E,{nodes:b,edges:R})}if((l.ctrlKey||l.metaKey)&&l.key==="a"){if(l.target.tagName==="INPUT"||l.target.tagName==="TEXTAREA")return;if(l.preventDefault(),ke.current){const b=se.current.filter(R=>!R.selected).map(R=>({id:R.id,type:"select",selected:!0}));b.length&&ke.current(b)}if(We.current){const b=Ne.current.filter(R=>!R.selected).map(R=>({id:R.id,type:"select",selected:!0}));b.length&&We.current(b)}}};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[_e]);const Ut=i.useRef(!1);i.useEffect(()=>{var u,g;if(!Ut.current&&Pe.current){if(Ut.current=!0,De&&se.current.length>0){const l=be.current;if(l){const p=l.getBoundingClientRect(),C=(xe==null?void 0:xe.padding)??.1,E=Mn(se.current),w=Ot(E,p.width,p.height,C);xe!=null&&xe.maxZoom&&(w.zoom=Math.min(w.zoom,xe.maxZoom)),xe!=null&&xe.minZoom&&(w.zoom=Math.max(w.zoom,xe.minZoom)),de.current=w,Me()}}(g=(u=K.current).onInit)==null||g.call(u,{getNodes:()=>[...se.current],getEdges:()=>[...Ne.current],getNode:l=>ft.current.get(l),getEdge:l=>Ne.current.find(p=>p.id===l),getViewport:()=>({...de.current}),getZoom:()=>de.current.zoom,setViewport:l=>{de.current={x:l.x??de.current.x,y:l.y??de.current.y,zoom:l.zoom??de.current.zoom},Me()},fitView:(l={})=>{const p=be.current;if(!p||!se.current.length)return;const C=p.getBoundingClientRect(),E=l.nodes?se.current.filter(R=>l.nodes.some(D=>D.id===R.id)):se.current;if(!E.length)return;const w=Mn(E),b=Ot(w,C.width,C.height,l.padding??.1);l.maxZoom&&(b.zoom=Math.min(b.zoom,l.maxZoom)),l.minZoom&&(b.zoom=Math.max(b.zoom,l.minZoom)),de.current=b,Me()},screenToFlowPosition:l=>Be(l.x,l.y),flowToScreenPosition:l=>{const p=de.current,C=be.current;if(!C)return{x:0,y:0};const E=C.getBoundingClientRect();return{x:l.x*p.zoom+p.x+E.left,y:l.y*p.zoom+p.y+E.top}},zoomIn:()=>{const l=de.current;l.zoom=Math.min(ge,l.zoom*1.2),Me()},zoomOut:()=>{const l=de.current;l.zoom=Math.max(oe,l.zoom/1.2),Me()},zoomTo:l=>{de.current.zoom=Math.min(ge,Math.max(oe,l)),Me()},setNodes:l=>{var p,C;(C=(p=K.current).onNodesChange)==null||C.call(p,[...se.current.map(E=>({id:E.id,type:"remove"})),...(typeof l=="function"?l(se.current):l).map(E=>({type:"add",item:E}))])},setEdges:l=>{var p,C;(C=(p=K.current).onEdgesChange)==null||C.call(p,[...Ne.current.map(E=>({id:E.id,type:"remove"})),...(typeof l=="function"?l(Ne.current):l).map(E=>({type:"add",item:E}))])},addNodes:l=>{var C,E;const p=Array.isArray(l)?l:[l];(E=(C=K.current).onNodesChange)==null||E.call(C,p.map(w=>({type:"add",item:w})))},addEdges:l=>{var C,E;const p=Array.isArray(l)?l:[l];(E=(C=K.current).onEdgesChange)==null||E.call(C,p.map(w=>({type:"add",item:w})))},deleteElements:({nodes:l=[],edges:p=[]})=>{var C,E,w,b;l.length&&((E=(C=K.current).onNodesChange)==null||E.call(C,l.map(R=>({id:R.id,type:"remove"})))),p.length&&((b=(w=K.current).onEdgesChange)==null||b.call(w,p.map(R=>({id:R.id,type:"remove"}))))},updateNodeData:(l,p)=>{var w,b;const C=se.current.find(R=>R.id===l);if(!C)return;const E=typeof p=="function"?p(C.data):{...C.data,...p};(b=(w=K.current).onNodesChange)==null||b.call(w,[{id:l,type:"replace",item:{...C,data:E}}])},toObject:()=>({nodes:[...se.current],edges:[...Ne.current],viewport:{...de.current}}),setCenter:(l,p,C={})=>{const E=be.current;if(!E)return;const w=E.getBoundingClientRect(),b=C.zoom??de.current.zoom;de.current={x:w.width/2-l*b,y:w.height/2-p*b,zoom:b},Me()},fitBounds:(l,p={})=>{const C=be.current;if(!C)return;const E=C.getBoundingClientRect(),w=Ot(l,E.width,E.height,p.padding??.1);de.current=w,Me()}})}});const _n=i.useCallback(()=>{de.current={...Se},Me()},[Me,Se]),Wn=i.useCallback(u=>{var g;if(u)bt.current.push(u);else{const l=de.current,p=be.current;if(!p)return;const C=p.getBoundingClientRect(),E=Math.round(-l.x/l.zoom+C.width/2/l.zoom),w=Math.round(-l.y/l.zoom+C.height/2/l.zoom);bt.current.push({x:E-80,y:w-45,w:160,h:90,title:"Note "+(bt.current.length+1),body:"Added at viewport center"})}(g=Pe.current)==null||g.postMessage({type:"cards",data:{cards:[...bt.current]}})},[]),Fn=i.useCallback(u=>{if(u.id||(u.id="node-"+Date.now()),!u.position){const g=de.current,l=be.current;if(!l)return;const p=l.getBoundingClientRect();u.position={x:Math.round(-g.x/g.zoom+p.width/2/g.zoom)-dt/2,y:Math.round(-g.y/g.zoom+p.height/2/g.zoom)-tt/2}}u.data||(u.data={label:u.id}),ke.current&&ke.current([{type:"add",item:u}])},[]),Yn=i.useCallback(()=>({...de.current}),[]),_=i.useCallback(u=>{de.current={...de.current,...u},Me()},[Me]),ve=i.useCallback(u=>Be(u.x,u.y),[Be]),V=n,Ce=i.useMemo(()=>({wrapRef:be,canvasRef:Tt,workerRef:Pe,cameraRef:de,nodesRef:se,edgesRef:Ne,handleRegistryRef:gn,syncNodesToWorker:pn,onNodesChangeRef:ke,onEdgesChangeRef:We,sendCamera:Me,screenToWorld:Be,viewportListeners:st,selectionListeners:qe,zoomMin:oe,zoomMax:ge,snapToGrid:Je,snapGrid:rt,nodeExtent:vt,defaultEdgeOptions:Pt,edgeRouting:kt,resolvedNodesRef:it,noDragClassName:Nt,noPanClassName:It,get nodes(){return t},get edges(){return n},get routedEdges(){return V},get viewport(){return Zt},get connection(){return xn}}),[t,n,V,Zt,xn,Me,Be,pn,st,qe,oe,ge,Je,rt,vt,Pt,kt,Nt,It]);return{wrapRef:be,canvasRef:Tt,canvasReady:jn,onPointerDown:Kt,onPointerMove:Vt,onPointerUp:mn,resetView:_n,addCard:Wn,addNode:Fn,getCamera:Yn,setCamera:_,screenToFlowPosition:ve,store:Ce}}function oo(e,t,n,r,a,o){const c=a-n,h=o-r,m=c*c+h*h;if(m===0)return Math.hypot(e-n,t-r);let f=((e-n)*c+(t-r)*h)/m;return f=Math.max(0,Math.min(1,f)),Math.hypot(e-(n+f*c),t-(r+f*h))}const dr=e=>{let t;const n=new Set,r=(f,y)=>{const x=typeof f=="function"?f(t):f;if(!Object.is(x,t)){const k=t;t=y??(typeof x!="object"||x===null)?x:Object.assign({},t,x),n.forEach(S=>S(t,k))}},a=()=>t,h={setState:r,getState:a,getInitialState:()=>m,subscribe:f=>(n.add(f),()=>n.delete(f))},m=t=e(r,a,h);return h},so=(e=>e?dr(e):dr),ao=e=>e;function io(e,t=ao){const n=i.useSyncExternalStore(e.subscribe,i.useCallback(()=>t(e.getState()),[e,t]),i.useCallback(()=>t(e.getInitialState()),[e,t]));return i.useDebugValue(n),n}const St=i.createContext(null);function co(e={}){return so((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 Te(e,t){const n=i.useContext(St);if(!n)throw new Error("useCanvasStore must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");const r=typeof n.getState=="function"&&typeof n.subscribe=="function",a=i.useRef(e),o=i.useRef(t),c=i.useRef(void 0);a.current=e,o.current=t;const h=i.useCallback(m=>{const f=a.current;if(!f)return m;const y=f(m),x=o.current||Object.is;return c.current!==void 0&&x(c.current,y)?c.current:(c.current=y,y)},[]);return r?io(n,e?h:void 0):e?h(n):n}function kr(){const e=i.useContext(St);if(!e)throw new Error("useCanvasStoreApi must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");return typeof e.getState=="function"?e:{getState:()=>e,setState:()=>{},subscribe:()=>()=>{}}}const cn=i.createContext(null);function lo(){return i.useContext(cn)}function uo({node:e,nodeType:t}){var z,W,j,H;const n=Te(),r=i.useRef(n);r.current=n;const a=i.useRef(null),o=e._absolutePosition||e.position,c=i.useRef(null);i.useEffect(()=>{const F=a.current;if(!F)return;const $=new ResizeObserver(Y=>{var Z,O,X,M;const{width:A,height:P}=Y[0].contentRect;if(A>0&&P>0){const d=r.current,v=d.nodesRef.current.find(B=>B.id===e.id),L=(v==null?void 0:v.width)||((Z=v==null?void 0:v.measured)==null?void 0:Z.width),T=(v==null?void 0:v.height)||((O=v==null?void 0:v.measured)==null?void 0:O.height);(Math.abs((L||0)-A)>1||Math.abs((T||0)-P)>1)&&((M=(X=d.onNodesChangeRef).current)==null||M.call(X,[{id:e.id,type:"dimensions",dimensions:{width:A,height:P},setAttributes:!0}]))}});return $.observe(F),()=>$.disconnect()},[e.id]);const h=i.useCallback(F=>{var ie,me,we,Re;F.stopPropagation();const $=F.target.tagName;if($==="INPUT"||$==="TEXTAREA"||$==="SELECT"||$==="BUTTON"||$==="A"||$==="LABEL"||F.target.isContentEditable)return;const Y=r.current.noDragClassName||"nodrag",A=r.current.noPanClassName||"nopan";let P=F.target;for(;P&&P!==a.current;){if((ie=P.classList)!=null&&ie.contains(Y)||(me=P.classList)!=null&&me.contains(A))return;P=P.parentElement}if(r.current.onNodesChangeRef.current){const ce=[];if(F.shiftKey)ce.push({id:e.id,type:"select",selected:!e.selected});else for(const oe of r.current.nodesRef.current)oe.id===e.id&&!oe.selected?ce.push({id:oe.id,type:"select",selected:!0}):oe.id!==e.id&&oe.selected&&ce.push({id:oe.id,type:"select",selected:!1});ce.length&&r.current.onNodesChangeRef.current(ce)}const Z=r.current.cameraRef.current,O=r.current.wrapRef.current;if(!O)return;const X=O.getBoundingClientRect(),M=(F.clientX-X.left-Z.x)/Z.zoom,d=(F.clientY-X.top-Z.y)/Z.zoom,L=e.selected?r.current.nodesRef.current.filter(ce=>ce.selected&&ce.id!==e.id).map(ce=>({id:ce.id,startPos:{...ce.position}})):[];c.current={startPos:{...e.position},startMouse:{x:M,y:d},selectedStarts:L};const T=[{id:e.id,type:"position",dragging:!0}];for(const ce of L)T.push({id:ce.id,type:"position",dragging:!0});(Re=(we=r.current.onNodesChangeRef).current)==null||Re.call(we,T);const B=a.current;B&&B.setPointerCapture(F.pointerId);let Q=null;const ne=ce=>{var Fe,Ye,nt,He;if(!c.current)return;const pe=r.current.cameraRef.current,oe=O.getBoundingClientRect(),ge=(ce.clientX-oe.left-pe.x)/pe.zoom,Se=(ce.clientY-oe.top-pe.y)/pe.zoom,De=ge-c.current.startMouse.x,xe=Se-c.current.startMouse.y;let fe={x:c.current.startPos.x+De,y:c.current.startPos.y+xe};if(r.current.snapToGrid&&r.current.snapGrid&&(fe={x:r.current.snapGrid[0]*Math.round(fe.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(fe.y/r.current.snapGrid[1])}),e.parentId&&e.extent==="parent"){const $e=r.current.nodesRef.current.find(Le=>Le.id===e.parentId);if($e){const Le=$e.width||160,ze=$e.height||60,Je=e.width||((Fe=e.measured)==null?void 0:Fe.width)||160,rt=e.height||((Ye=e.measured)==null?void 0:Ye.height)||60;fe={x:Math.max(0,Math.min(fe.x,Le-Je)),y:Math.max(0,Math.min(fe.y,ze-rt))}}}B&&(B.style.left=fe.x+"px",B.style.top=fe.y+"px");const Ae=[{id:e.id,position:fe,_absolutePosition:fe,dragging:!0}];for(const $e of c.current.selectedStarts){let Le={x:$e.startPos.x+De,y:$e.startPos.y+xe};r.current.snapToGrid&&r.current.snapGrid&&(Le={x:r.current.snapGrid[0]*Math.round(Le.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Le.y/r.current.snapGrid[1])});const ze=O.querySelector(`[data-nodeid="${$e.id}"]`);ze&&(ze.style.left=Le.x+"px",ze.style.top=Le.y+"px"),Ae.push({id:$e.id,position:Le,_absolutePosition:Le,dragging:!0})}(He=(nt=r.current.workerRef)==null?void 0:nt.current)==null||He.postMessage({type:"nodePositions",data:{updates:Ae}});for(const $e of Ae){const Le=r.current.nodesRef.current.find(ze=>ze.id===$e.id);Le&&(Le.position=$e.position)}Q=Ae},ee=ce=>{var ge,Se,De,xe;if(!c.current)return;const pe=[{id:e.id,position:e.position,dragging:!1}];for(const fe of c.current.selectedStarts)pe.push({id:fe.id,position:fe.startPos,dragging:!1});if(Q)for(let fe=0;fe<Q.length;fe++)pe[fe]={id:Q[fe].id,position:Q[fe].position,dragging:!1};(Se=(ge=r.current.workerRef)==null?void 0:ge.current)==null||Se.postMessage({type:"nodePositions",data:{updates:pe}});const oe=[];for(const fe of pe)oe.push({id:fe.id,type:"position",position:fe.position,dragging:!1});(xe=(De=r.current.onNodesChangeRef).current)==null||xe.call(De,oe),c.current=null,Q=null,B&&B.releasePointerCapture(ce.pointerId),B==null||B.removeEventListener("pointermove",ne),B==null||B.removeEventListener("pointerup",ee)};B==null||B.addEventListener("pointermove",ne),B==null||B.addEventListener("pointerup",ee)},[e]),m=i.useCallback(F=>{var O,X,M,d,v,L;if(!e.selected)return;const $=F.shiftKey?10:1;let Y=0,A=0;switch(F.key){case"ArrowUp":A=-$;break;case"ArrowDown":A=$;break;case"ArrowLeft":Y=-$;break;case"ArrowRight":Y=$;break;case"Escape":(X=(O=r.current.onNodesChangeRef).current)==null||X.call(O,[{id:e.id,type:"select",selected:!1}]);return;case"Delete":case"Backspace":e.deletable!==!1&&((d=(M=r.current.onNodesChangeRef).current)==null||d.call(M,[{id:e.id,type:"remove"}]));return;default:return}F.preventDefault();const P={x:e.position.x+Y,y:e.position.y+A},Z=[{id:e.id,type:"position",position:P}];for(const T of r.current.nodesRef.current)T.selected&&T.id!==e.id&&Z.push({id:T.id,type:"position",position:{x:T.position.x+Y,y:T.position.y+A}});(L=(v=r.current.onNodesChangeRef).current)==null||L.call(v,Z)},[e]),f=e.width||((z=e.measured)==null?void 0:z.width),y=e.height||((W=e.measured)==null?void 0:W.height),x=!!(f&&y),k=(j=n.pinnedNodeIds)==null?void 0:j.has(e.id),S=i.useCallback(F=>{var $,Y;F.stopPropagation(),(Y=($=r.current).togglePinNode)==null||Y.call($,e.id)},[e.id]);return I.jsx(cn.Provider,{value:e.id,children:I.jsxs("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:x?"visible":"hidden",outline:"none"},"data-nodeid":e.id,tabIndex:e.selectable!==!1?0:void 0,role:"button","aria-label":`Node ${((H=e.data)==null?void 0:H.label)||e.id}`,"aria-selected":!!e.selected,onPointerDown:h,onKeyDown:m,children:[I.jsx(t,{id:e.id,data:e.data,type:e.type,selected:!!e.selected,dragging:!!e.dragging,draggable:e.draggable!==!1,selectable:e.selectable!==!1,deletable:e.deletable!==!1,isConnectable:e.connectable!==!1,zIndex:e.zIndex||0,positionAbsoluteX:o.x,positionAbsoluteY:o.y,width:f,height:y,sourcePosition:e.sourcePosition,targetPosition:e.targetPosition,parentId:e.parentId,dragHandle:e.dragHandle}),n.togglePinNode&&I.jsx("button",{className:"ric-pin-btn nodrag",onClick:S,title:k?"Unpin from DOM":"Pin to DOM",style:{position:"absolute",top:-8,left:-8,width:20,height:20,borderRadius:"50%",border:"1.5px solid "+(k?"#3b82f6":"#ccc"),background:k?"#3b82f6":"#fff",color:k?"#fff":"#999",fontSize:10,lineHeight:"16px",textAlign:"center",cursor:"pointer",padding:0,zIndex:10,pointerEvents:"all",boxShadow:"0 1px 3px rgba(0,0,0,0.12)"},children:"📌"})]})})}const fo=i.memo(uo),Cr=160,Er=60;function fr(e,t,n,r){var m,f;const a=e.width||((m=e.measured)==null?void 0:m.width)||Cr,o=e.height||((f=e.measured)==null?void 0:f.height)||Er,c=e._absolutePosition||e.position;if(e.handleBounds){const y=e.handleBounds[t]||[],x=n?y.find(k=>k.id===n):y[0];if(x&&x.x!==void 0&&x.y!==void 0){const k=x.position||(t==="source"?"right":"left");return{x:c.x+x.x,y:c.y+x.y,position:k}}}if(r){const y=`${e.id}__${n||t}`,x=r.get(y);if(x&&x.x!==void 0&&x.y!==void 0)return{x:c.x+x.x,y:c.y+x.y,position:x.position||(t==="source"?"right":"left")}}if(e.handles&&e.handles.length){for(const y of e.handles)if(y.type===t&&(!n||y.id===n)){if(y.x!==void 0&&y.y!==void 0)return{x:c.x+y.x,y:c.y+y.y,position:y.position||(t==="source"?"right":"left")};const x=y.position||(t==="source"?"right":"left");switch(x){case"top":return{x:c.x+a/2,y:c.y,position:x};case"bottom":return{x:c.x+a/2,y:c.y+o,position:x};case"left":return{x:c.x,y:c.y+o/2,position:x};default:return{x:c.x+a,y:c.y+o/2,position:x}}}}switch(t==="source"?e.sourcePosition||"right":e.targetPosition||"left"){case"top":return{x:c.x+a/2,y:c.y,position:"top"};case"bottom":return{x:c.x+a/2,y:c.y+o,position:"bottom"};case"left":return{x:c.x,y:c.y+o/2,position:"left"};default:return{x:c.x+a,y:c.y+o/2,position:"right"}}}function ho(e,t,n){return n==="left"?e-t:n==="right"?e+t:e}function go(e,t,n){return n==="top"?e-t:n==="bottom"?e+t:e}function hr({x:e,y:t,position:n,type:r,onPointerDown:a}){return I.jsx("circle",{className:`ric-edge-anchor ric-edge-anchor-${r}`,cx:ho(e,10,n),cy:go(t,10,n),r:10,stroke:"transparent",fill:"transparent",style:{cursor:"move",pointerEvents:"stroke"},onPointerDown:a})}function yo({edge:e,edgeType:t,nodes:n,reconnectable:r}){var X,M;const a=i.useContext(St),o=i.useRef(typeof a.getState=="function"?a.getState():a);o.current=typeof a.getState=="function"?a.getState():a;const[c,h]=i.useState(null),m=i.useCallback((d,v,L,T)=>{var Re;v.stopPropagation(),v.preventDefault();const B=o.current,Q=B.wrapRef.current;if(!Q)return;const ne=d==="source"?T:L,ee=d==="source"?e.target:e.source;(Re=B.workerRef.current)==null||Re.postMessage({type:"connecting",data:{from:{x:ne.x,y:ne.y},to:{x:ne.x,y:ne.y}}});const ie=Q.getBoundingClientRect(),me=ce=>{var Se;const pe=B.cameraRef.current,oe=(ce.clientX-ie.left-pe.x)/pe.zoom,ge=(ce.clientY-ie.top-pe.y)/pe.zoom;(Se=B.workerRef.current)==null||Se.postMessage({type:"connecting",data:{from:{x:ne.x,y:ne.y},to:{x:oe,y:ge}}})},we=ce=>{var Ae,Fe,Ye,nt;const pe=B.cameraRef.current,oe=(ce.clientX-ie.left-pe.x)/pe.zoom,ge=(ce.clientY-ie.top-pe.y)/pe.zoom,Se=20/pe.zoom;let De=null,xe=null;const fe=(Ae=B.handleRegistryRef)==null?void 0:Ae.current;for(const He of B.nodesRef.current){if(He.hidden)continue;const $e=He.width||Cr,Le=He.height||Er,ze=He._absolutePosition||He.position,Je=[];if(fe)for(const[,_e]of fe)_e.nodeId===He.id&&Je.push(_e);const rt=Je.length>0?Je:He.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const _e of rt){let Oe,Ke;if(_e.x!==void 0&&_e.y!==void 0)Oe=ze.x+_e.x,Ke=ze.y+_e.y;else switch(_e.position||(_e.type==="source"?"right":"left")){case"top":Oe=ze.x+$e/2,Ke=ze.y;break;case"bottom":Oe=ze.x+$e/2,Ke=ze.y+Le;break;case"left":Oe=ze.x,Ke=ze.y+Le/2;break;default:Oe=ze.x+$e,Ke=ze.y+Le/2;break}if(Math.abs(oe-Oe)<Se&&Math.abs(ge-Ke)<Se){De=He,xe=_e.id||null;break}}if(De)break}if(De){const He=d==="source"?{source:De.id,target:ee,sourceHandle:xe,targetHandle:e.targetHandle}:{source:ee,target:De.id,sourceHandle:e.sourceHandle,targetHandle:xe};(Ye=(Fe=B.onEdgesChangeRef).current)==null||Ye.call(Fe,[{id:e.id,type:"remove"},{type:"add",item:{id:e.id,...He}}])}(nt=B.workerRef.current)==null||nt.postMessage({type:"connecting",data:null}),Q.removeEventListener("pointermove",me),Q.removeEventListener("pointerup",we)};Q.addEventListener("pointermove",me),Q.addEventListener("pointerup",we)},[e]),f=o.current,y=((X=f.nodesRef)==null?void 0:X.current)||n,x=y.find(d=>d.id===e.source),k=y.find(d=>d.id===e.target),[,S]=i.useReducer(d=>d+1,0),z=i.useRef(null),W=(x==null?void 0:x.dragging)||(k==null?void 0:k.dragging);i.useEffect(()=>{if(!W)return;const d=()=>{S(),z.current=requestAnimationFrame(d)};return z.current=requestAnimationFrame(d),()=>cancelAnimationFrame(z.current)},[W]);const j=i.useRef(!1);i.useEffect(()=>{j.current||(j.current=!0,requestAnimationFrame(()=>S()))},[]);const H=(M=f.handleRegistryRef)==null?void 0:M.current,F=x?fr(x,"source",e.sourceHandle,H):null,$=k?fr(k,"target",e.targetHandle,H):null,Y=e.type==="bezier"||e.type==="simplebezier"||e.type==="default",A=f.routedEdges||f.edges,P=A==null?void 0:A.find(d=>d.id===e.id),Z=Y?null:(P==null?void 0:P._routedPoints)||e._routedPoints||null,O=r!==!1&&e.reconnectable!==!1;return!F||!$?null:I.jsxs("g",{className:`ric-edge-wrapper ${e.selected?"selected":""}`,"data-edgeid":e.id,onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),children:[I.jsx(t,{id:e.id,source:e.source,target:e.target,sourceX:F.x,sourceY:F.y,targetX:$.x,targetY:$.y,sourcePosition:F.position,targetPosition:$.position,sourceHandleId:e.sourceHandle,targetHandleId:e.targetHandle,data:e.data,type:e.type,selected:!!e.selected,animated:!!e.animated,label:e.label,style:e.style,selectable:e.selectable!==!1,deletable:e.deletable!==!1,routedPoints:Z}),O&&(c||e.selected)&&I.jsxs(I.Fragment,{children:[I.jsx(hr,{x:F.x,y:F.y,position:F.position,type:"source",onPointerDown:d=>m("source",d,F,$)}),I.jsx(hr,{x:$.x,y:$.y,position:$.position,type:"target",onPointerDown:d=>m("target",d,F,$)})]})]})}const xo=i.memo(yo);function Sr({selectionKeyCode:e="Shift",selectionMode:t="partial"}){var W;const n=Te(),[r,a]=i.useState(null),o=i.useRef(null);if(i.useEffect(()=>{const j=n.wrapRef.current;if(!j)return;let H=!1,F=null,$=!1;const Y=X=>{X.key===e&&($=!0)},A=X=>{X.key===e&&($=!1)},P=X=>{if(!$)return;const M=X.target;if(M.closest(".ric-node-wrapper")||M.closest(".ric-handle"))return;H=!0;const d=n.cameraRef.current,v=j.getBoundingClientRect(),L=(X.clientX-v.left-d.x)/d.zoom,T=(X.clientY-v.top-d.y)/d.zoom;F={x:L,y:T},a({startX:L,startY:T,endX:L,endY:T}),X.stopPropagation()},Z=X=>{if(!H||!F)return;const M=n.cameraRef.current,d=j.getBoundingClientRect(),v=(X.clientX-d.left-M.x)/M.zoom,L=(X.clientY-d.top-M.y)/M.zoom;a({startX:F.x,startY:F.y,endX:v,endY:L})},O=X=>{var Q,ne;if(!H||!F)return;H=!1;const M=n.cameraRef.current,d=j.getBoundingClientRect(),v=(X.clientX-d.left-M.x)/M.zoom,L=(X.clientY-d.top-M.y)/M.zoom,T={x:Math.min(F.x,v),y:Math.min(F.y,L),width:Math.abs(v-F.x),height:Math.abs(L-F.y)},B=[];for(const ee of n.nodesRef.current){const ie=ee._absolutePosition||ee.position,me=ee.width||160,we=ee.height||60;let Re;t==="full"?Re=ie.x>=T.x&&ie.y>=T.y&&ie.x+me<=T.x+T.width&&ie.y+we<=T.y+T.height:Re=ie.x+me>T.x&&ie.x<T.x+T.width&&ie.y+we>T.y&&ie.y<T.y+T.height,B.push({id:ee.id,type:"select",selected:Re})}B.length&&((ne=(Q=n.onNodesChangeRef).current)==null||ne.call(Q,B)),F=null,a(null)};return j.addEventListener("pointerdown",P,!0),j.addEventListener("pointermove",Z),j.addEventListener("pointerup",O),window.addEventListener("keydown",Y),window.addEventListener("keyup",A),()=>{j.removeEventListener("pointerdown",P,!0),j.removeEventListener("pointermove",Z),j.removeEventListener("pointerup",O),window.removeEventListener("keydown",Y),window.removeEventListener("keyup",A)}},[n,e,t]),!r)return null;const c=((W=n.cameraRef)==null?void 0:W.current)||{x:0,y:0,zoom:1},h=Math.min(r.startX,r.endX),m=Math.min(r.startY,r.endY),f=Math.abs(r.endX-r.startX),y=Math.abs(r.endY-r.startY),x=h*c.zoom+c.x,k=m*c.zoom+c.y,S=f*c.zoom,z=y*c.zoom;return I.jsx("div",{ref:o,className:"ric-selection-box",style:{position:"absolute",left:x,top:k,width:S,height:z,border:"1px dashed #3b82f6",background:"rgba(59, 130, 246, 0.08)",pointerEvents:"none",zIndex:100}})}Sr.displayName="SelectionBox";const zr=i.memo(Sr);function Jn(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 po(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 On=!1,Et=null;function Pr(e){Et=e,!On&&(On=!0,requestAnimationFrame(()=>{var t;On=!1,(t=Et==null?void 0:Et.syncNodesToWorker)==null||t.call(Et),Et=null}))}const Kn=new WeakMap;let bn=null;function mo(){return bn||(bn=new ResizeObserver(e=>{var t;for(const n of e){const r=Kn.get(n.target);if(!r)continue;const{width:a,height:o}=n.contentRect;if(!a||!o)continue;const c=r.getStore(),h=(t=c.handleRegistryRef)==null?void 0:t.current;if(h){for(const[m,f]of h)if(f.nodeId===r.nodeId){const y=Jn(f.position,a,o);f.x=y.x,f.y=y.y,h.set(m,f)}Pr(c)}}}),bn)}function vo({type:e="source",position:t=e==="source"?"right":"left",id:n,isConnectable:r=!0,isConnectableStart:a=!0,isConnectableEnd:o=!0,children:c,className:h="",style:m={},onConnect:f,...y}){const x=i.useContext(cn),k=i.useContext(St),S=i.useRef(null),z=i.useCallback(()=>typeof k.getState=="function"?k.getState():k,[k]),W=i.useRef(z);W.current=z,i.useLayoutEffect(()=>{var M,d,v,L,T,B,Q;if(!x)return;const $=W.current(),Y=(M=$.handleRegistryRef)==null?void 0:M.current;if(!Y)return;const A=`${x}__${n||e}`,P=(v=(d=$.nodesRef)==null?void 0:d.current)==null?void 0:v.find(ne=>ne.id===x),Z=(P==null?void 0:P.width)||((L=P==null?void 0:P.measured)==null?void 0:L.width),O=(P==null?void 0:P.height)||((T=P==null?void 0:P.measured)==null?void 0:T.height);let X;Z&&O?X=Jn(t,Z,O):S.current?X=po(S.current,(Q=(B=$.cameraRef)==null?void 0:B.current)==null?void 0:Q.zoom):X=Jn(t,160,60),Y.set(A,{nodeId:x,id:n||null,type:e,position:t,x:X.x,y:X.y}),P&&(e==="source"&&(P.sourcePosition=t),e==="target"&&(P.targetPosition=t))},[x,n,e,t]),i.useEffect(()=>{if(!x)return;const $=W.current();Pr($);const Y=S.current,A=Y==null?void 0:Y.closest(".ric-node-wrapper");return A&&!Kn.has(A)&&(Kn.set(A,{nodeId:x,getStore:W.current}),mo().observe(A)),()=>{var X;const Z=(X=W.current().handleRegistryRef)==null?void 0:X.current,O=`${x}__${n||e}`;Z==null||Z.delete(O)}},[x,n,e,t]);const j=i.useCallback(()=>{var d;const $=W.current(),Y=$.nodesRef.current.find(v=>v.id===x);if(!Y)return null;const A=Y._absolutePosition||Y.position,P=(d=$.handleRegistryRef)==null?void 0:d.current,Z=`${x}__${n||e}`,O=P==null?void 0:P.get(Z);if(O&&O.x!==void 0&&O.y!==void 0)return{x:A.x+O.x,y:A.y+O.y};const X=Y.width||160,M=Y.height||60;switch(t){case"top":return{x:A.x+X/2,y:A.y};case"bottom":return{x:A.x+X/2,y:A.y+M};case"left":return{x:A.x,y:A.y+M/2};default:return{x:A.x+X,y:A.y+M/2}}},[x,n,e,t]),H=i.useCallback($=>{var L;if(!r||!a)return;$.stopPropagation(),$.preventDefault();const Y=W.current(),A=Y.cameraRef.current,P=Y.wrapRef.current;if(!P)return;const Z=P.getBoundingClientRect(),O=j();if(!O)return;const X=O.x,M=O.y;(L=Y.workerRef.current)==null||L.postMessage({type:"connecting",data:{from:{x:X,y:M},to:{x:X,y:M}}}),P.setPointerCapture($.pointerId);const d=T=>{var ne;const B=(T.clientX-Z.left-A.x)/A.zoom,Q=(T.clientY-Z.top-A.y)/A.zoom;(ne=Y.workerRef.current)==null||ne.postMessage({type:"connecting",data:{from:{x:X,y:M},to:{x:B,y:Q}}})},v=T=>{var we,Re,ce,pe;const B=(T.clientX-Z.left-A.x)/A.zoom,Q=(T.clientY-Z.top-A.y)/A.zoom,ne=20/A.zoom;let ee=null,ie=null;const me=(we=Y.handleRegistryRef)==null?void 0:we.current;for(const oe of Y.nodesRef.current){if(oe.id===x||oe.hidden)continue;const ge=oe._absolutePosition||oe.position,Se=[];if(me)for(const[,xe]of me)xe.nodeId===oe.id&&Se.push(xe);const De=Se.length>0?Se:oe.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const xe of De){let fe,Ae;if(xe.x!==void 0&&xe.y!==void 0)fe=ge.x+xe.x,Ae=ge.y+xe.y;else{const Fe=oe.width||160,Ye=oe.height||60;switch(xe.position||(xe.type==="source"?"right":"left")){case"top":fe=ge.x+Fe/2,Ae=ge.y;break;case"bottom":fe=ge.x+Fe/2,Ae=ge.y+Ye;break;case"left":fe=ge.x,Ae=ge.y+Ye/2;break;default:fe=ge.x+Fe,Ae=ge.y+Ye/2;break}}if(Math.abs(B-fe)<ne&&Math.abs(Q-Ae)<ne){ee=oe,ie=xe.id||null;break}}if(ee)break}if(ee){const oe={source:e==="source"?x:ee.id,target:e==="source"?ee.id:x,sourceHandle:e==="source"?n||null:ie,targetHandle:e==="source"?ie:n||null};(ce=(Re=Y.onEdgesChangeRef)==null?void 0:Re.current)==null||ce.call(Re,[{type:"add",item:{id:`e-${oe.source}-${oe.target}`,...oe}}])}(pe=Y.workerRef.current)==null||pe.postMessage({type:"connecting",data:null}),P.removeEventListener("pointermove",d),P.removeEventListener("pointerup",v)};P.addEventListener("pointermove",d),P.addEventListener("pointerup",v)},[x,n,e,t,r,a,j]),F={top:{top:0,left:"50%",transform:"translate(-50%, -50%)"},bottom:{bottom:0,left:"50%",transform:"translate(-50%, 50%)"},left:{top:"50%",left:0,transform:"translate(-50%, -50%)"},right:{top:"50%",right:0,transform:"translate(50%, -50%)"}}[t]||{};return I.jsx("div",{ref:S,className:`ric-handle ric-handle-${t} ric-handle-${e} ${h}`,"data-handleid":n||null,"data-nodeid":x,"data-handlepos":t,"data-handletype":e,onPointerDown:H,style:{position:"absolute",width:8,height:8,borderRadius:"50%",background:"#1a192b",border:"none",zIndex:10,cursor:r?"crosshair":"default",boxSizing:"border-box",...F,...m},...y,children:c})}const an=i.memo(vo);function bo({data:e,isConnectable:t,selected:n,targetPosition:r="left",sourcePosition:a="right",hideSourceHandle:o=!1,hideTargetHandle:c=!1}){return I.jsxs("div",{className:`ric-default-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!c&&I.jsx(an,{type:"target",position:r,isConnectable:t}),I.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!o&&I.jsx(an,{type:"source",position:a,isConnectable:t})]})}function Nr({data:e,isConnectable:t,selected:n,sourcePosition:r="right",hideSourceHandle:a=!1}){return I.jsxs("div",{className:`ric-input-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderBottom:"2px solid #0041d0",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[I.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!a&&I.jsx(an,{type:"source",position:r,isConnectable:t})]})}function Ir({data:e,isConnectable:t,selected:n,targetPosition:r="left",hideTargetHandle:a=!1}){return I.jsxs("div",{className:`ric-output-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderTop:"2px solid #ff0072",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!a&&I.jsx(an,{type:"target",position:r,isConnectable:t}),I.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label})]})}function Tr({data:e,selected:t,width:n,height:r}){return I.jsx("div",{className:`ric-group-node${t?" selected":""}`,style:{width:n||300,height:r||200,background:"rgba(240, 240, 240, 0.25)",border:t?"2px solid #3b82f6":"1px dashed #ccc",borderRadius:8,padding:8,boxSizing:"border-box"},children:(e==null?void 0:e.label)&&I.jsx("div",{style:{fontSize:11,fontWeight:600,color:"#888",userSelect:"none"},children:e.label})})}function Lr({x:e,y:t,label:n,labelStyle:r,labelShowBg:a=!0,labelBgStyle:o,labelBgPadding:c=[2,4],labelBgBorderRadius:h=2,children:m,className:f="",...y}){const[x,k]=i.useState({x:1,y:0,width:0,height:0}),S=i.useRef(null);return i.useEffect(()=>{if(S.current){const z=S.current.getBBox();k({x:z.x,y:z.y,width:z.width,height:z.height})}},[n]),n?I.jsxs("g",{transform:`translate(${e-x.width/2} ${t-x.height/2})`,className:`ric-edge-textwrapper ${f}`,visibility:x.width?"visible":"hidden",...y,children:[a&&I.jsx("rect",{width:x.width+2*c[0],x:-c[0],y:-c[1],height:x.height+2*c[1],className:"ric-edge-textbg",style:o,rx:h,ry:h}),I.jsx("text",{className:"ric-edge-text",y:x.height/2,dy:"0.3em",ref:S,style:r,children:n}),m]}):null}Lr.displayName="EdgeText";const Br=i.memo(Lr);function gr(e){return e!=null&&e!==""&&!isNaN(Number(e))}function ln({id:e,path:t,labelX:n,labelY:r,label:a,labelStyle:o,labelShowBg:c,labelBgStyle:h,labelBgPadding:m,labelBgBorderRadius:f,interactionWidth:y=20,style:x,markerEnd:k,markerStart:S,className:z="",...W}){return I.jsxs(I.Fragment,{children:[I.jsx("path",{id:e,d:t,fill:"none",stroke:"#b1b1b7",strokeWidth:1.5,className:`ric-edge-path ${z}`,style:x,markerEnd:k,markerStart:S,...W}),y?I.jsx("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:y,className:"ric-edge-interaction",style:{pointerEvents:"stroke"}}):null,a&&gr(n)&&gr(r)?I.jsx(Br,{x:n,y:r,label:a,labelStyle:o,labelShowBg:c,labelBgStyle:h,labelBgPadding:m,labelBgBorderRadius:f}):null]})}const rn=20;function yr(e,t,n){switch(n){case"right":return{x:e+rn,y:t};case"left":return{x:e-rn,y:t};case"bottom":return{x:e,y:t+rn};case"top":return{x:e,y:t-rn};default:return{x:e+rn,y:t}}}const tr=i.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:c="bottom",targetPosition:h="top",label:m,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:k,labelBgBorderRadius:S,style:z,markerEnd:W,markerStart:j,interactionWidth:H}){let F,$,Y;const A=yr(n,r,c),P=yr(a,o,h),Z=Math.abs(P.x-A.x),O=Math.max(50,Z*.5);let X,M,d,v;switch(c){case"left":X=A.x-O,M=A.y;break;case"top":X=A.x,M=A.y-O;break;case"bottom":X=A.x,M=A.y+O;break;default:X=A.x+O,M=A.y;break}switch(h){case"right":d=P.x+O,v=P.y;break;case"top":d=P.x,v=P.y-O;break;case"bottom":d=P.x,v=P.y+O;break;default:d=P.x-O,v=P.y;break}F=`M ${n},${r} L ${A.x},${A.y} C ${X},${M} ${d},${v} ${P.x},${P.y} L ${a},${o}`;const L=.5,T=.5;return $=T*T*T*A.x+3*T*T*L*X+3*T*L*L*d+L*L*L*P.x,Y=T*T*T*A.y+3*T*T*L*M+3*T*L*L*v+L*L*L*P.y,I.jsx(ln,{id:t,path:F,labelX:$,labelY:Y,label:m,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:k,labelBgBorderRadius:S,style:z,markerEnd:W,markerStart:j,interactionWidth:H})});tr.displayName="BezierEdge";function nr({sourceX:e,sourceY:t,targetX:n,targetY:r}){const a=`M ${e},${t}L ${n},${r}`,o=(e+n)/2,c=(t+r)/2;return[a,o,c,0,0]}function rr({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a="right",targetPosition:o="left",curvature:c=.25}){const h=Math.abs(n-e),m=Math.abs(r-t),f=Math.sqrt(h*h+m*m),y=Math.max(f*c,50);let x,k,S,z;switch(a){case"top":x=e,k=t-y;break;case"bottom":x=e,k=t+y;break;case"left":x=e-y,k=t;break;default:x=e+y,k=t;break}switch(o){case"top":S=n,z=r-y;break;case"bottom":S=n,z=r+y;break;case"right":S=n+y,z=r;break;default:S=n-y,z=r;break}const W=`M ${e},${t} C ${x},${k} ${S},${z} ${n},${r}`,j=.5,H=1-j,F=H*H*H*e+3*H*H*j*x+3*H*j*j*S+j*j*j*n,$=H*H*H*t+3*H*H*j*k+3*H*j*j*z+j*j*j*r;return[W,F,$,0,0]}function or({sourceX:e,sourceY:t,targetX:n,targetY:r}){const a=Math.abs(n-e),o=Math.max(a*.5,50),c=e+o,h=n-o,m=`M ${e},${t} C ${c},${t} ${h},${r} ${n},${r}`,f=.5,y=.5,x=y*y*y*e+3*y*y*f*c+3*y*f*f*h+f*f*f*n,k=y*y*y*t+3*y*y*f*t+3*y*f*f*r+f*f*f*r;return[m,x,k,0,0]}function Rn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a="right",targetPosition:o="left",borderRadius:c=5,offset:h=20}){const m=a==="left"||a==="right",f=Math.min(c,Math.abs(n-e)/2,Math.abs(r-t)/2);if(m){if(Math.abs(r-t)<1)return[`M ${e},${t} L ${n},${r}`,(e+n)/2,t,0,0];const S=(e+n)/2,z=r>t?1:-1;return[`M ${e},${t} L ${S-f},${t} Q ${S},${t} ${S},${t+z*f} L ${S},${r-z*f} Q ${S},${r} ${S+(n>S?f:-f)},${r} L ${n},${r}`,S,(t+r)/2,0,0]}const y=(t+r)/2,x=n>e?1:-1;return[`M ${e},${t} L ${e},${y-f} Q ${e},${y} ${e+x*f},${y} L ${n-x*f},${y} Q ${n},${y} ${n},${y+(r>y?f:-f)} L ${n},${r}`,(e+n)/2,y,0,0]}function wo({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[,a,o]=rr({sourceX:e,sourceY:t,targetX:n,targetY:r});return[a,o,0,0]}function Mo({sourceX:e,sourceY:t,targetX:n,targetY:r}){return[(e+n)/2,(t+r)/2,0,0]}function Ro(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 kn=160,Cn=60,on=20,wn=12,En=20;function xr(e,t,n){var c,h;const r=e.width||((c=e.measured)==null?void 0:c.width)||kn,a=e.height||((h=e.measured)==null?void 0:h.height)||Cn,o=e._absolutePosition||e.position;if(e.handles&&e.handles.length>0){for(const m of e.handles)if(m.type===t&&(!n||m.id===n)){if(m.x!==void 0&&m.y!==void 0)return{x:o.x+m.x,y:o.y+m.y,dir:m.position||(t==="source"?"right":"left")};switch(m.position||(t==="source"?"right":"left")){case"top":return{x:o.x+r/2,y:o.y,dir:"top"};case"bottom":return{x:o.x+r/2,y:o.y+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 Sn(e,t){switch(e.dir){case"right":return{x:e.x+t,y:e.y,dir:e.dir};case"left":return{x:e.x-t,y:e.y,dir:e.dir};case"bottom":return{x:e.x,y:e.y+t,dir:e.dir};case"top":return{x:e.x,y:e.y-t,dir:e.dir};default:return{x:e.x+t,y:e.y,dir:e.dir}}}function ko(e,t,n,r,a,o,c,h){const m=Math.min(e,n),f=Math.max(e,n),y=Math.min(t,r),x=Math.max(t,r);if(f<=a||m>=a+c||x<=o||y>=o+h)return!1;const k=.5;if(e>a+k&&e<a+c-k&&t>o+k&&t<o+h-k||n>a+k&&n<a+c-k&&r>o+k&&r<o+h-k)return!0;const S=(e+n)/2,z=(t+r)/2;if(S>a+k&&S<a+c-k&&z>o+k&&z<o+h-k)return!0;const W=[[a,o],[a+c,o],[a+c,o+h],[a,o+h]];for(let j=0;j<4;j++)if(Co(e,t,n,r,W[j][0],W[j][1],W[(j+1)%4][0],W[(j+1)%4][1]))return!0;return!1}function Co(e,t,n,r,a,o,c,h){const m=(c-a)*(t-o)-(h-o)*(e-a),f=(c-a)*(r-o)-(h-o)*(n-a),y=(n-e)*(o-t)-(r-t)*(a-e),x=(n-e)*(h-t)-(r-t)*(c-e);return(m>0&&f<0||m<0&&f>0)&&(y>0&&x<0||y<0&&x>0)}function Vn(e,t,n,r,a){for(let o=0;o<a.length;o++){const c=a[o];if(ko(e,t,n,r,c.x,c.y,c.w,c.h))return!1}return!0}function Eo(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 sr(e,t){var r,a;const n=[];for(let o=0;o<e.length;o++){const c=e[o];if(c.hidden||t&&t.has(c.id)||c.type==="group")continue;const h=c._absolutePosition||c.position,m=c.width||((r=c.measured)==null?void 0:r.width)||kn,f=c.height||((a=c.measured)==null?void 0:a.height)||Cn;n.push({id:c.id,x:h.x-on,y:h.y-on,w:m+2*on,h:f+2*on})}return n}function $r(e,t,n){if(Vn(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=on+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 d=0;d<n.length;d++){const v=n[d];r.add(v.x),r.add(v.x+v.w),a.add(v.y),a.add(v.y+v.h)}const c=[...r].sort((d,v)=>d-v),h=[...a].sort((d,v)=>d-v),m=new Map,f=new Map;for(let d=0;d<c.length;d++)m.set(c[d],d);for(let d=0;d<h.length;d++)f.set(h[d],d);const y=c.length,x=h.length,k=(d,v)=>v*y+d,S=m.get(e.x),z=f.get(e.y),W=m.get(t.x),j=f.get(t.y);if(S===void 0||z===void 0||W===void 0||j===void 0)return null;const H=k(S,z),F=k(W,j),$=new Float64Array(y*x).fill(1/0),Y=new Float64Array(y*x).fill(1/0),A=new Int32Array(y*x).fill(-1),P=new Int8Array(y*x).fill(-1),Z=new Uint8Array(y*x);$[H]=0,Y[H]=Math.abs(c[W]-e.x)+Math.abs(h[j]-e.y);const O=[H],X=15,M=[[1,0],[-1,0],[0,1],[0,-1]];for(;O.length>0;){let d=0;for(let ee=1;ee<O.length;ee++)Y[O[ee]]<Y[O[d]]&&(d=ee);const v=O[d];if(O[d]=O[O.length-1],O.pop(),v===F){const ee=[];let ie=F;for(;ie!==-1&&ie!==H;){const me=ie/y|0,we=ie%y;ee.unshift({x:c[we],y:h[me]}),ie=A[ie]}return ee.unshift({x:e.x,y:e.y}),So(ee,n)}if(Z[v])continue;Z[v]=1;const L=v/y|0,T=v%y,B=c[T],Q=h[L],ne=P[v];for(let ee=0;ee<4;ee++){const ie=T+M[ee][0],me=L+M[ee][1];if(ie<0||ie>=y||me<0||me>=x)continue;const we=k(ie,me);if(Z[we])continue;const Re=c[ie],ce=h[me];if(Eo(Re,ce,n)||!Vn(B,Q,Re,ce,n))continue;const pe=Math.abs(Re-B)+Math.abs(ce-Q),oe=ne>=0&&ne!==ee?X:0,ge=$[v]+pe+oe;ge<$[we]&&(A[we]=v,P[we]=ee,$[we]=ge,Y[we]=ge+Math.abs(c[W]-Re)+Math.abs(h[j]-ce),O.push(we))}}return null}function So(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],c=e[r+1],h=Math.abs(a.x-o.x)<.5&&Math.abs(o.x-c.x)<.5,m=Math.abs(a.y-o.y)<.5&&Math.abs(o.y-c.y)<.5;(h||m)&&Vn(a.x,a.y,c.x,c.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 c=0;c<o.length-1;c++){const h=o[c],m=o[c+1];if(Math.abs(h.y-m.y)<.5){const f=Math.round(h.y*10)/10;t.has(f)||t.set(f,[]),t.get(f).push({edgeId:a.id,segIdx:c,x1:Math.min(h.x,m.x),x2:Math.max(h.x,m.x)})}else if(Math.abs(h.x-m.x)<.5){const f=Math.round(h.x*10)/10;n.has(f)||n.set(f,[]),n.get(f).push({edgeId:a.id,segIdx:c,y1:Math.min(h.y,m.y),y2:Math.max(h.y,m.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=pr(a,"x1","x2");for(const c of o){if(c.length<2)continue;const h=(c.length-1)*wn/2;for(let m=0;m<c.length;m++){const f=c[m],y=-h+m*wn,x=r.get(f.edgeId);x&&(x[f.segIdx].y+=y,x[f.segIdx+1].y+=y)}}}for(const[,a]of n){if(a.length<2)continue;const o=pr(a,"y1","y2");for(const c of o){if(c.length<2)continue;const h=(c.length-1)*wn/2;for(let m=0;m<c.length;m++){const f=c[m],y=-h+m*wn,x=r.get(f.edgeId);x&&(x[f.segIdx].x+=y,x[f.segIdx+1].x+=y)}}}return e.map(a=>{const o=r.get(a.id);return o?{...a,_routedPoints:o}:a})}function pr(e,t,n){if(e.length<2)return[];const r=[...e].sort((c,h)=>c[t]-h[t]),a=[];let o=[r[0]];for(let c=1;c<r.length;c++){const h=o[o.length-1];r[c][t]<h[n]?o.push(r[c]):(o.length>1&&a.push(o),o=[r[c]])}return o.length>1&&a.push(o),a}function zn(e,t=6,n=!1){if(!e||e.length<2)return null;if(n)return Po(e);const r=t;let a=`M ${e[0].x},${e[0].y}`;for(let o=1;o<e.length-1;o++){const c=e[o-1],h=e[o],m=e[o+1],f=Math.abs(h.x-c.x)+Math.abs(h.y-c.y),y=Math.abs(m.x-h.x)+Math.abs(m.y-h.y),x=Math.min(r,f/2,y/2);if(x>.5){const k=h.x-c.x,S=h.y-c.y,z=m.x-h.x,W=m.y-h.y,j=Math.sqrt(k*k+S*S)||1,H=Math.sqrt(z*z+W*W)||1;a+=` L ${h.x-k/j*x},${h.y-S/j*x}`,a+=` Q ${h.x},${h.y} ${h.x+z/H*x},${h.y+W/H*x}`}else a+=` L ${h.x},${h.y}`}return a+=` L ${e[e.length-1].x},${e[e.length-1].y}`,a}function Po(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],c=e[r+1],h=e[r+2<e.length?r+2:e.length-1],m=o.x+(c.x-a.x)*t,f=o.y+(c.y-a.y)*t,y=c.x-(h.x-o.x)*t,x=c.y-(h.y-o.y)*t;n+=` C ${m},${f} ${y},${x} ${c.x},${c.y}`}return n}function Pn(e){if(!e||e.length<2)return{x:0,y:0};let t=0;for(let r=1;r<e.length;r++)t+=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);let n=t/2;for(let r=1;r<e.length;r++){const 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=sr(e,null),a=t.map(o=>{var P,Z,O,X;const c=o.type||"default";if(c==="bezier"||c==="simplebezier"||c==="default")return o;const h=n[o.source],m=n[o.target];if(!h||!m||h.hidden||m.hidden)return o;const f=xr(h,"source",o.sourceHandle),y=xr(m,"target",o.targetHandle),x=Sn(f,En),k=Sn(y,En),S=5,z=r.filter(M=>M.id!==o.source&&M.id!==o.target),W=h._absolutePosition||h.position,j=h.width||((P=h.measured)==null?void 0:P.width)||kn,H=h.height||((Z=h.measured)==null?void 0:Z.height)||Cn;z.push({id:o.source,x:W.x-S,y:W.y-S,w:j+2*S,h:H+2*S});const F=m._absolutePosition||m.position,$=m.width||((O=m.measured)==null?void 0:O.width)||kn,Y=m.height||((X=m.measured)==null?void 0:X.height)||Cn;if(z.push({id:o.target,x:F.x-S,y:F.y-S,w:$+2*S,h:Y+2*S}),z.length===0)return o;const A=$r(x,k,z);return A&&A.length>=2?(A.unshift({x:f.x,y:f.y}),A.push({x:y.x,y:y.y}),{...o,_routedPoints:A}):o});return zo(a)}function Io(e,t,n,r,a,o,c,h){const m=sr(c,h?new Set(h):null);if(m.length===0)return null;const f={x:e,y:t,dir:a||"right"},y={x:n,y:r,dir:o||"left"},x=Sn(f,En),k=Sn(y,En),S=$r(x,k,m);return S&&S.length>=2?(S.unshift({x:f.x,y:f.y}),S.push({x:y.x,y:y.y}),S):null}const ar=i.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,label:c,labelStyle:h,labelShowBg:m,labelBgStyle:f,labelBgPadding:y,labelBgBorderRadius:x,style:k,markerEnd:S,markerStart:z,interactionWidth:W,routedPoints:j}){let H,F,$;if(j&&j.length>=2){H=zn(j);const Y=Pn(j);F=Y.x,$=Y.y}else[H,F,$]=nr({sourceX:n,sourceY:r,targetX:a,targetY:o});return I.jsx(ln,{id:t,path:H,labelX:F,labelY:$,label:c,labelStyle:h,labelShowBg:m,labelBgStyle:f,labelBgPadding:y,labelBgBorderRadius:x,style:k,markerEnd:S,markerStart:z,interactionWidth:W})});ar.displayName="StraightEdge";const ir=i.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:c="bottom",targetPosition:h="top",label:m,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:k,labelBgBorderRadius:S,style:z,markerEnd:W,markerStart:j,pathOptions:H,interactionWidth:F,routedPoints:$}){let Y,A,P;if($&&$.length>=2){Y=zn($);const Z=Pn($);A=Z.x,P=Z.y}else[Y,A,P]=Rn({sourceX:n,sourceY:r,sourcePosition:c,targetX:a,targetY:o,targetPosition:h,borderRadius:H==null?void 0:H.borderRadius,offset:H==null?void 0:H.offset});return I.jsx(ln,{id:t,path:Y,labelX:A,labelY:P,label:m,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:k,labelBgBorderRadius:S,style:z,markerEnd:W,markerStart:j,interactionWidth:F})});ir.displayName="SmoothStepEdge";const Ar=i.memo(function({id:t,...n}){var a;const r=i.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(a=n.pathOptions)==null?void 0:a.offset]);return I.jsx(ir,{...n,id:t,pathOptions:r})});Ar.displayName="StepEdge";const cr=i.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:c,targetPosition:h,label:m,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:k,labelBgBorderRadius:S,style:z,markerEnd:W,markerStart:j,interactionWidth:H,routedPoints:F}){let $,Y,A;if(F&&F.length>=2){$=zn(F);const P=Pn(F);Y=P.x,A=P.y}else[$,Y,A]=or({sourceX:n,sourceY:r,targetX:a,targetY:o});return I.jsx(ln,{id:t,path:$,labelX:Y,labelY:A,label:m,labelStyle:f,labelShowBg:y,labelBgStyle:x,labelBgPadding:k,labelBgBorderRadius:S,style:z,markerEnd:W,markerStart:j,interactionWidth:H})});cr.displayName="SimpleBezierEdge";const To={input:Nr,output:Ir,group:Tr},Lo={bezier:tr,straight:ar,simplebezier:cr},Bo=160,$o=60;function Ao(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||Bo,height:n.height||$o}}}):e}function jo({cards:e,nodes:t=[],edges:n=[],nodeTypes:r,edgeTypes:a,canvasNodeTypes:o,domNodeLimit:c=50,dark:h,gridSize:m,width:f="100%",height:y="420px",className:x="",style:k={},zoomMin:S,zoomMax:z,initialCamera:W,fitView:j,fitViewOptions:H,onNodesChange:F,onEdgesChange:$,onConnect:Y,onConnectStart:A,onConnectEnd:P,onNodeClick:Z,onNodeDoubleClick:O,onNodeMouseEnter:X,onNodeMouseMove:M,onNodeMouseLeave:d,onNodeContextMenu:v,onNodeDragStart:L,onNodeDrag:T,onNodeDragStop:B,onEdgeClick:Q,onEdgeDoubleClick:ne,onEdgeMouseEnter:ee,onEdgeMouseMove:ie,onEdgeMouseLeave:me,onEdgeContextMenu:we,onPaneClick:Re,onPaneContextMenu:ce,onPaneMouseEnter:pe,onPaneMouseMove:oe,onPaneMouseLeave:ge,onSelectionChange:Se,onInit:De,onMoveStart:xe,onMove:fe,onMoveEnd:Ae,onDelete:Fe,onBeforeDelete:Ye,onError:nt,onDragOver:He,onDrop:$e,onDragEnter:Le,onDragLeave:ze,nodesDraggable:Je,nodesConnectable:rt,elementsSelectable:_e,multiSelectionKeyCode:Oe,selectionOnDrag:Ke,selectionMode:zt,connectionMode:un,connectionRadius:dn,connectOnClick:fn,isValidConnection:hn,defaultEdgeOptions:qt,snapToGrid:mt,snapGrid:vt,deleteKeyCode:Pt,panActivationKeyCode:Nn,panOnScroll:In,panOnScrollMode:ot,panOnScrollSpeed:lr,zoomOnScroll:Tn,zoomOnDoubleClick:Ln,zoomOnPinch:Nt,preventScrolling:It,translateExtent:Bn,nodeExtent:$n,autoPanOnNodeDrag:An,autoPanOnConnect:kt,autoPanSpeed:be,edgesReconnectable:Tt,elevateNodesOnSelect:Pe,elevateEdgesOnSelect:de,noDragClassName:bt,noPanClassName:se,onSelectionDragStart:Ne,onSelectionDrag:ft,onSelectionDragStop:gn,edgeRouting:Lt=!0,onHudUpdate:ht,onNodesProcessed:jn,showHud:Dn=!0,showHint:Xe=!0,hintText:Ue="Drag to pan · Scroll to zoom",children:Bt,...gt}){const[Ve,$t]=i.useState({wx:0,wy:0,zoom:"1.00"}),Zt=i.useRef(null),yn=i.useRef(null),xn=i.useCallback(_=>{$t(_),ht==null||ht(_)},[ht]),At=i.useMemo(()=>({...To,...r}),[r]),st=i.useMemo(()=>({...Lo,...a}),[a]),qe=i.useMemo(()=>Ao(t),[t]),[wt,K]=i.useState(()=>new Set),at=i.useRef(wt);at.current=wt;const jt=i.useCallback(_=>{K(ve=>{const V=new Set(ve);return V.add(_),V})},[]),Dt=i.useCallback(_=>{K(ve=>{const V=new Set(ve);return V.delete(_),V})},[]),Ht=i.useCallback(_=>{K(ve=>{const V=new Set(ve);return V.has(_)?V.delete(_):V.add(_),V})},[]),yt=i.useMemo(()=>qe.filter(_=>_.type&&At[_.type]),[qe,At]),_t=i.useMemo(()=>n.filter(_=>_.type&&st[_.type]),[n,st]),[Ct,Wt]=i.useState(()=>new Set),Ft=i.useRef(new Set),Yt=i.useRef(!0),ke=i.useMemo(()=>{const _=new Set(Ct);for(const V of wt)_.add(V);if(Yt.current&&Ct.size===0)for(const V of yt)_.add(V.id);else Yt.current=!1;for(const V of yt)(V.selected||V.dragging)&&_.add(V.id);const ve=Ft.current;if(ve.size===_.size){let V=!0;for(const Ce of _)if(!ve.has(Ce)){V=!1;break}if(V)return ve}return Ft.current=_,_},[yt,wt,Ct]),xt=i.useMemo(()=>{if(c===0)return[];const _=qe.filter(ve=>ke.has(ve.id));return _.sort((ve,V)=>{const Ce=ve.type==="group"||!ve.parentId&&_.some(g=>g.parentId===ve.id),u=V.type==="group"||!V.parentId&&_.some(g=>g.parentId===V.id);return Ce&&!u?-1:!Ce&&u?1:0})},[qe,ke,c]),We=i.useMemo(()=>t.map(_=>ke.has(_.id)?{..._,_customRendered:!0}:_),[t,ke]),Hn=i.useMemo(()=>n.map(_=>_.type&&st[_.type]?{..._,_customRendered:!0}:_),[n,st]),{wrapRef:pt,canvasRef:Xt,canvasReady:it,onPointerDown:Mt,onPointerMove:pn,onPointerUp:Be,store:le}=Rr({cards:e,nodes:We,edges:Hn,dark:h,gridSize:m,zoomMin:S,zoomMax:z,initialCamera:W,fitView:j,fitViewOptions:H,onHudUpdate:xn,onNodesProcessed:jn,onNodesChange:F,onEdgesChange:$,onConnect:Y,onConnectStart:A,onConnectEnd:P,onNodeClick:Z,onNodeDoubleClick:O,onNodeMouseEnter:X,onNodeMouseMove:M,onNodeMouseLeave:d,onNodeContextMenu:v,onNodeDragStart:L,onNodeDrag:T,onNodeDragStop:B,onEdgeClick:Q,onEdgeDoubleClick:ne,onEdgeMouseEnter:ee,onEdgeMouseMove:ie,onEdgeMouseLeave:me,onEdgeContextMenu:we,onPaneClick:Re,onPaneContextMenu:ce,onPaneMouseEnter:pe,onPaneMouseMove:oe,onPaneMouseLeave:ge,onSelectionChange:Se,onInit:De,onMoveStart:xe,onMove:fe,onMoveEnd:Ae,onDelete:Fe,onBeforeDelete:Ye,onError:nt,nodesDraggable:Je,nodesConnectable:rt,elementsSelectable:_e,multiSelectionKeyCode:Oe,selectionOnDrag:Ke,selectionMode:zt,connectionMode:un,connectionRadius:dn,connectOnClick:fn,isValidConnection:hn,defaultEdgeOptions:qt,snapToGrid:mt,snapGrid:vt,deleteKeyCode:Pt,panActivationKeyCode:Nn,panOnScroll:In,panOnScrollMode:ot,panOnScrollSpeed:lr,zoomOnScroll:Tn,zoomOnDoubleClick:Ln,zoomOnPinch:Nt,preventScrolling:It,translateExtent:Bn,nodeExtent:$n,autoPanOnNodeDrag:An,autoPanOnConnect:kt,autoPanSpeed:be,edgesReconnectable:Tt,elevateNodesOnSelect:Pe,elevateEdgesOnSelect:de,noDragClassName:bt,noPanClassName:se,onSelectionDragStart:Ne,onSelectionDrag:ft,onSelectionDragStop:gn,edgeRouting:Lt}),Gt=i.useRef(yt);Gt.current=yt;const Qt=i.useRef(c);Qt.current=c,i.useEffect(()=>{let _;const ve=()=>{const Ce=Gt.current,u=Qt.current;if(u===0||!Ce.length)return;const g=le.cameraRef.current,l=le.wrapRef.current;if(!l)return;const p=l.clientWidth,C=l.clientHeight,E=(-g.x+p/2)/g.zoom,w=(-g.y+C/2)/g.zoom,b=at.current;let R=b.size;for(const N of Ce)(N.selected||N.dragging)&&R++;const D=Math.max(0,u-R);if(D===0)Wt(N=>N.size===0?N:new Set);else{const N=new Set(b);for(const U of Ce)(U.selected||U.dragging)&&N.add(U.id);const q=[];for(let U=0;U<Ce.length;U++){const ae=Ce[U];if(N.has(ae.id))continue;const Ie=ae._absolutePosition||ae.position,te=Ie.x+(ae.width||160)/2-E,ue=Ie.y+(ae.height||60)/2-w;q.push({id:ae.id,dist:te*te+ue*ue})}q.sort((U,ae)=>U.dist-ae.dist);const J=new Set;for(let U=0;U<Math.min(D,q.length);U++)J.add(q[U].id);Wt(U=>{if(U.size!==J.size)return J;for(const ae of J)if(!U.has(ae))return J;return U})}},V=setTimeout(ve,100);return _=setInterval(ve,500),()=>{clearTimeout(V),clearInterval(_)}},[le.cameraRef,le.wrapRef]);const Rt=i.useRef(new Set);i.useEffect(()=>{if(!o||!le.workerRef.current)return;let _=!1;async function ve(Ce){const u=new Blob([Ce],{type:"image/svg+xml"}),g=URL.createObjectURL(u),l=new Image;return l.src=g,await l.decode(),URL.revokeObjectURL(g),createImageBitmap(l)}async function V(){var p,C,E;const Ce={},u=[],g={},l={};for(const[w,b]of Object.entries(o)){if(typeof b=="function"){g[w]=b;continue}if(typeof b=="object"&&b!==null&&!(b instanceof ImageBitmap)&&!(b instanceof HTMLImageElement)&&!(b instanceof HTMLCanvasElement)&&("fill"in b||"stroke"in b||"title"in b||"accent"in b)){l[w]=b;continue}try{let R;b instanceof ImageBitmap?R=b:typeof b=="string"?R=await ve(b):b instanceof HTMLImageElement?R=await createImageBitmap(b):b instanceof HTMLCanvasElement&&(R=await createImageBitmap(b)),R&&!_&&(Ce[w]=R,u.push(R))}catch(R){console.warn(`[InfiniteCanvas] Failed to convert canvasNodeType "${w}":`,R)}}if(!_&&Object.keys(Ce).length>0&&((p=le.workerRef.current)==null||p.postMessage({type:"nodeTypeBitmaps",data:{bitmaps:Ce}},u)),!_&&Object.keys(l).length>0&&((C=le.workerRef.current)==null||C.postMessage({type:"nodeTypeConfigs",data:{configs:l}})),!_&&Object.keys(g).length>0){const w=new Map,b={},R={},D=[];let N=Rt.current.size;for(const q of t){const J=g[q.type];if(J)try{const U=J(q.data);if(!U)continue;let ae=w.get(U);if(!ae&&(ae="bmp_"+N++,w.set(U,ae),!Rt.current.has(U))){const Ie=await ve(U);if(_)return;b[ae]=Ie,D.push(Ie),Rt.current.add(U)}R[q.id]=ae}catch(U){console.warn(`[InfiniteCanvas] canvasNodeType fn error for node "${q.id}":`,U)}}_||(E=le.workerRef.current)==null||E.postMessage({type:"nodeBitmaps",data:{cache:b,keys:R}},D)}}return V(),()=>{_=!0}},[o,t,le.workerRef]);const Ze=i.useContext(St),Jt=Ze&&typeof Ze.getState=="function";i.useEffect(()=>{Jt&&queueMicrotask(()=>{Ze.setState({nodes:qe,edges:n,nodesRef:le.nodesRef,edgesRef:le.edgesRef,onNodesChangeRef:le.onNodesChangeRef,onEdgesChangeRef:le.onEdgesChangeRef,cameraRef:le.cameraRef,wrapRef:le.wrapRef,workerRef:le.workerRef})})},[Jt,qe,n,le,Ze]);const Me=i.useMemo(()=>({...le,edgeLabelContainerRef:Zt,viewportPortalRef:yn,pinNode:jt,unpinNode:Dt,togglePinNode:Ht,get pinnedNodeIds(){return at.current},get nodes(){return qe},get edges(){return n},get viewport(){return le.cameraRef.current},get minZoom(){return le.zoomMin||.1},get maxZoom(){return le.zoomMax||5},get domNode(){return le.wrapRef.current},get width(){var _;return((_=le.wrapRef.current)==null?void 0:_.clientWidth)||0},get height(){var _;return((_=le.wrapRef.current)==null?void 0:_.clientHeight)||0}}),[le,qe,n,jt,Dt,Ht]),ct=i.useRef(null),lt=i.useRef(null),Kt=i.useRef(null),Vt=i.useRef(null),mn=i.useRef(null);i.useEffect(()=>{let _;const ve=()=>{const V=le.cameraRef.current,Ce=`translate(${V.x}px, ${V.y}px) scale(${V.zoom})`,u=`translate(${V.x}, ${V.y}) scale(${V.zoom})`;ct.current&&(ct.current.style.transform=Ce),lt.current&&lt.current.setAttribute("transform",u),Kt.current&&(Kt.current.style.transform=Ce),Vt.current&&(Vt.current.style.transform=Ce);const g=pt.current;if(g){const l=V.zoom<.15?"lod-minimal":V.zoom<.35?"lod-reduced":null;l!==mn.current&&(g.classList.remove("lod-minimal","lod-reduced"),l&&g.classList.add(l),mn.current=l)}_=requestAnimationFrame(ve)};return _=requestAnimationFrame(ve),()=>cancelAnimationFrame(_)},[le]);const[Ut,_n]=i.useState(null);i.useEffect(()=>{if(!xt.length)return;let _;const ve=()=>{var b,R;const V=le.cameraRef.current,Ce=le.wrapRef.current;if(!Ce){_=requestAnimationFrame(ve);return}const u=Ce.getBoundingClientRect(),g=200,l=-V.x/V.zoom-g,p=-V.y/V.zoom-g,C=(u.width-V.x)/V.zoom+g,E=(u.height-V.y)/V.zoom+g,w=new Set;for(const D of xt){const N=D._absolutePosition||D.position,q=D.width||((b=D.measured)==null?void 0:b.width)||200,J=D.height||((R=D.measured)==null?void 0:R.height)||100;N.x+q>=l&&N.x<=C&&N.y+J>=p&&N.y<=E&&w.add(D.id)}_n(D=>{if(!D||D.size!==w.size)return w;for(const N of w)if(!D.has(N))return w;return D}),_=requestAnimationFrame(ve)};return _=requestAnimationFrame(ve),()=>cancelAnimationFrame(_)},[xt,le]);const Wn=i.useMemo(()=>Ut?xt.filter(_=>Ut.has(_.id)):xt,[xt,Ut]),Fn=xt.length>0,Yn=_t.length>0;return I.jsx(St.Provider,{value:Me,children:I.jsxs("div",{ref:pt,className:`ric-wrap ${x}`,style:{width:f,height:y,...k},onPointerDown:Mt,onPointerMove:pn,onPointerUp:Be,onDragOver:He,onDrop:$e,onDragEnter:Le,onDragLeave:ze,tabIndex:0,children:[I.jsx("canvas",{ref:Xt,className:"ric-canvas"}),!it&&I.jsx("div",{className:"ric-loader",children:I.jsx("div",{className:"ric-spinner"})}),Yn&&I.jsx("svg",{className:"ric-edges-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:I.jsx("g",{ref:lt,children:_t.map(_=>I.jsx(xo,{edge:_,edgeType:st[_.type],nodes:t,reconnectable:Tt},_.id))})}),Fn&&I.jsx("div",{ref:ct,className:"ric-nodes-overlay",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:10},children:Wn.map(_=>I.jsx(fo,{node:_,nodeType:At[_.type]},_.id))}),I.jsx("div",{ref:_=>{Zt.current=_,Kt.current=_},className:"ric-edge-labels",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:5}}),I.jsx("div",{ref:_=>{yn.current=_,Vt.current=_},className:"ric-viewport-portal",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:6}}),Xe&&I.jsx("div",{className:"ric-hint",children:Ue}),Dn&&I.jsxs("div",{className:"ric-info",children:["world: (",Ve.wx,", ",Ve.wy,")   zoom: ",Ve.zoom,"x",Ve.nodeCount>0&&I.jsxs(I.Fragment,{children:["   nodes: ",Ve.nodeCount]}),Ve.edgeCount>0&&I.jsxs(I.Fragment,{children:["   edges: ",Ve.edgeCount]})]}),I.jsx(zr,{selectionKeyCode:Oe||"Shift",selectionMode:zt||"partial"}),Bt]})})}function Do({children:e}){const t=i.useRef(null);return t.current||(t.current=co()),I.jsx(St.Provider,{value:t.current,children:e})}function jr(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 c=r.get(o.id);c?c.push(o):r.set(o.id,[o])}for(const o of t){const c=r.get(o.id);if(!c){n.push(o);continue}if(c[0].type==="remove")continue;if(c[0].type==="replace"){n.push({...c[0].item});continue}const h={...o};for(const m of c)Ho(m,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 Ho(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 Dr(e,t){return jr(e,t)}function Hr(e,t){return jr(e,t)}function _o(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 Wo(e){const[t,n]=i.useState(e),r=i.useCallback(a=>n(o=>Dr(a,o)),[]);return[t,n,r]}function Fo(e){const[t,n]=i.useState(e),r=i.useCallback(a=>n(o=>Hr(a,o)),[]);return[t,n,r]}function _r(){const e=kr(),t=i.useCallback(()=>typeof e.getState=="function"?e.getState():e,[e]),n=i.useCallback(()=>[...t().nodesRef.current],[t]),r=i.useCallback(()=>[...t().edgesRef.current],[t]),a=i.useCallback(M=>t().nodesRef.current.find(d=>d.id===M),[t]),o=i.useCallback(M=>t().edgesRef.current.find(d=>d.id===M),[t]),c=i.useCallback(M=>{var d,v,L,T;if(typeof M=="function"){const B=M(t().nodesRef.current);(v=(d=t().onNodesChangeRef).current)==null||v.call(d,[...t().nodesRef.current.map(Q=>({id:Q.id,type:"remove"})),...B.map(Q=>({type:"add",item:Q}))])}else(T=(L=t().onNodesChangeRef).current)==null||T.call(L,[...t().nodesRef.current.map(B=>({id:B.id,type:"remove"})),...M.map(B=>({type:"add",item:B}))])},[t]),h=i.useCallback(M=>{var d,v,L,T;if(typeof M=="function"){const B=M(t().edgesRef.current);(v=(d=t().onEdgesChangeRef).current)==null||v.call(d,[...t().edgesRef.current.map(Q=>({id:Q.id,type:"remove"})),...B.map(Q=>({type:"add",item:Q}))])}else(T=(L=t().onEdgesChangeRef).current)==null||T.call(L,[...t().edgesRef.current.map(B=>({id:B.id,type:"remove"})),...M.map(B=>({type:"add",item:B}))])},[t]),m=i.useCallback(M=>{var v,L;const d=Array.isArray(M)?M:[M];(L=(v=t().onNodesChangeRef).current)==null||L.call(v,d.map(T=>({type:"add",item:T})))},[t]),f=i.useCallback(M=>{var v,L;const d=Array.isArray(M)?M:[M];(L=(v=t().onEdgesChangeRef).current)==null||L.call(v,d.map(T=>({type:"add",item:T})))},[t]),y=i.useCallback(({nodes:M=[],edges:d=[]})=>{if(M.length&&t().onNodesChangeRef.current){t().onNodesChangeRef.current(M.map(L=>({id:L.id,type:"remove"})));const v=wr(M,t().edgesRef.current);v.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(v.map(L=>({id:L.id,type:"remove"})))}d.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(d.map(v=>({id:v.id,type:"remove"})))},[t]),x=i.useCallback(()=>{const M=t().cameraRef.current;return{x:M.x,y:M.y,zoom:M.zoom}},[t]),k=i.useRef(null),S=i.useCallback((M,d)=>{if(k.current&&cancelAnimationFrame(k.current),!d||d<=0){t().cameraRef.current={...M},t().sendCamera();return}const v={...t().cameraRef.current},L=performance.now(),T=B=>{const Q=B-L,ne=Math.min(Q/d,1),ee=1-Math.pow(1-ne,3);t().cameraRef.current={x:v.x+(M.x-v.x)*ee,y:v.y+(M.y-v.y)*ee,zoom:v.zoom+(M.zoom-v.zoom)*ee},t().sendCamera(),ne<1&&(k.current=requestAnimationFrame(T))};k.current=requestAnimationFrame(T)},[t]),z=i.useCallback((M,d)=>{const v={x:M.x??t().cameraRef.current.x,y:M.y??t().cameraRef.current.y,zoom:M.zoom??t().cameraRef.current.zoom};S(v,d==null?void 0:d.duration)},[t,S]),W=i.useCallback(()=>t().cameraRef.current.zoom,[t]),j=i.useCallback(M=>{const d=t().cameraRef.current,v=t().wrapRef.current;if(!v)return;const L=v.getBoundingClientRect(),T=L.width/2,B=L.height/2,Q=1.2,ne={x:T-(T-d.x)*Q,y:B-(B-d.y)*Q,zoom:Math.min(t().zoomMax,d.zoom*Q)};S(ne,M==null?void 0:M.duration)},[t,S]),H=i.useCallback(M=>{const d=t().cameraRef.current,v=t().wrapRef.current;if(!v)return;const L=v.getBoundingClientRect(),T=L.width/2,B=L.height/2,Q=1/1.2,ne={x:T-(T-d.x)*Q,y:B-(B-d.y)*Q,zoom:Math.max(t().zoomMin,d.zoom*Q)};S(ne,M==null?void 0:M.duration)},[t,S]),F=i.useCallback((M,d)=>{const v=t().cameraRef.current,L=t().wrapRef.current;if(!L)return;const T=L.getBoundingClientRect(),B=T.width/2,Q=T.height/2,ne=Math.min(t().zoomMax,Math.max(t().zoomMin,M)),ee=ne/v.zoom,ie={x:B-(B-v.x)*ee,y:Q-(Q-v.y)*ee,zoom:ne};S(ie,d==null?void 0:d.duration)},[t,S]),$=i.useCallback((M={})=>{const d=t().nodesRef.current;if(!d.length)return;const v=t().wrapRef.current;if(!v)return;const L=v.getBoundingClientRect(),T=M.padding??.1,B=M.nodes?d.filter(ee=>M.nodes.some(ie=>ie.id===ee.id)):d;if(!B.length)return;const Q=Mn(B),ne=Ot(Q,L.width,L.height,T);M.maxZoom&&(ne.zoom=Math.min(ne.zoom,M.maxZoom)),M.minZoom&&(ne.zoom=Math.max(ne.zoom,M.minZoom)),S(ne,M.duration)},[t,S]),Y=i.useCallback((M,d={})=>{const v=t().wrapRef.current;if(!v)return;const L=v.getBoundingClientRect(),T=d.padding??.1,B=Ot(M,L.width,L.height,T);d.maxZoom&&(B.zoom=Math.min(B.zoom,d.maxZoom)),d.minZoom&&(B.zoom=Math.max(B.zoom,d.minZoom)),S(B,d.duration)},[t,S]),A=i.useCallback((M,d,v={})=>{const L=t().wrapRef.current;if(!L)return;const T=L.getBoundingClientRect(),B=v.zoom??t().cameraRef.current.zoom,Q={x:T.width/2-M*B,y:T.height/2-d*B,zoom:B};S(Q,v.duration)},[t,S]),P=i.useCallback(()=>({nodes:[...t().nodesRef.current],edges:[...t().edgesRef.current],viewport:{...t().cameraRef.current}}),[t]),Z=i.useCallback(M=>t().screenToWorld(M.x,M.y),[t]),O=i.useCallback(M=>{const d=t().cameraRef.current,v=t().wrapRef.current;if(!v)return{x:0,y:0};const L=v.getBoundingClientRect();return{x:M.x*d.zoom+d.x+L.left,y:M.y*d.zoom+d.y+L.top}},[t]),X=i.useCallback((M,d)=>{var T,B;const v=t().nodesRef.current.find(Q=>Q.id===M);if(!v)return;const L=typeof d=="function"?d(v.data):{...v.data,...d};(B=(T=t().onNodesChangeRef).current)==null||B.call(T,[{id:M,type:"replace",item:{...v,data:L}}])},[t]);return{getNodes:n,getEdges:r,getNode:a,getEdge:o,setNodes:c,setEdges:h,addNodes:m,addEdges:f,deleteElements:y,getViewport:x,setViewport:z,getZoom:W,zoomIn:j,zoomOut:H,zoomTo:F,fitView:$,fitBounds:Y,setCenter:A,screenToFlowPosition:Z,flowToScreenPosition:O,updateNodeData:X,toObject:P}}function Yo(){return Te().nodes}function Xo(){return Te().edges}function Uo(){return Te().viewport}function Oo(){return Te().connection}function qo(e){const t=Te(),n=Array.isArray(e)?e:[e];return i.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 Zo(e){const t=Te();return i.useMemo(()=>t.edges.filter(n=>n.source===e||n.target===e),[t.edges,e])}function Go({nodeId:e,type:t,handleId:n}){const r=Te();return i.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 Qo({onChange:e,onStart:t,onEnd:n}){const r=Te(),a=i.useRef(e),o=i.useRef(t),c=i.useRef(n);i.useEffect(()=>{a.current=e},[e]),i.useEffect(()=>{o.current=t},[t]),i.useEffect(()=>{c.current=n},[n]),i.useEffect(()=>{const h=m=>{var f;(f=a.current)==null||f.call(a,{x:m.x,y:m.y,zoom:m.zoom})};return r.viewportListeners.add(h),()=>r.viewportListeners.delete(h)},[s])}function Jo({onChange:e}){const t=Te(),n=i.useRef(e);i.useEffect(()=>{n.current=e},[e]),i.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 Ko(e){const[t,n]=i.useState(!1),r=Array.isArray(e)?e:[e];return i.useEffect(()=>{const a=c=>{r.includes(c.key)&&n(!0)},o=c=>{r.includes(c.key)&&n(!1)};return window.addEventListener("keydown",a),window.addEventListener("keyup",o),()=>{window.removeEventListener("keydown",a),window.removeEventListener("keyup",o)}},[r.join(",")]),t}function Vo(){const e=Te();return i.useCallback(t=>{var n;(n=e.workerRef.current)==null||n.postMessage({type:"nodes",data:{nodes:[...s().nodesRef.current]}})},[s])}const es=e=>{var t;return((t=e.nodes)==null?void 0:t.length)>0};function ts(e={}){return Te(es)}function ns(e){const t=Te();return i.useMemo(()=>t.nodes.find(n=>n.id===e)||void 0,[t.nodes,e])}function rs(e,t){return Te(e,t)}function os(){return kr()}function ss({maxHistorySize:e=100}={}){const t=Te(),n=i.useRef([]),r=i.useRef([]),[,a]=i.useState(0),o=i.useRef(null),c=i.useCallback(()=>{const f={nodes:s().nodesRef.current.map(y=>({...y,data:{...y.data}})),edges:s().edgesRef.current.map(y=>({...y}))};o.current&&JSON.stringify(o.current.nodes.map(y=>y.id))===JSON.stringify(f.nodes.map(y=>y.id))&&JSON.stringify(o.current.edges.map(y=>y.id))===JSON.stringify(f.edges.map(y=>y.id))||(n.current.push(f),n.current.length>e&&n.current.shift(),r.current=[],o.current=f,a(y=>y+1))},[t,e]),h=i.useCallback(()=>{var y,x,k,S;const f=n.current.pop();f&&(r.current.push({nodes:s().nodesRef.current.map(z=>({...z,data:{...z.data}})),edges:s().edgesRef.current.map(z=>({...z}))}),(x=(y=s().onNodesChangeRef).current)==null||x.call(y,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...f.nodes.map(z=>({type:"add",item:z}))]),(S=(k=s().onEdgesChangeRef).current)==null||S.call(k,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...f.edges.map(z=>({type:"add",item:z}))]),o.current=f,a(z=>z+1))},[s]),m=i.useCallback(()=>{var y,x,k,S;const f=r.current.pop();f&&(n.current.push({nodes:s().nodesRef.current.map(z=>({...z,data:{...z.data}})),edges:s().edgesRef.current.map(z=>({...z}))}),(x=(y=s().onNodesChangeRef).current)==null||x.call(y,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...f.nodes.map(z=>({type:"add",item:z}))]),(S=(k=s().onEdgesChangeRef).current)==null||S.call(k,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...f.edges.map(z=>({type:"add",item:z}))]),o.current=f,a(z=>z+1))},[s]);return{undo:h,redo:m,takeSnapshot:c,canUndo:n.current.length>0,canRedo:r.current.length>0}}function as(e){const t=i.useRef(e);return i.useEffect(()=>{t.current=e},[e]),i.useCallback(n=>r=>{const a=t.current(r);a!==!1&&a!=null&&n(Array.isArray(a)?a:r)},[])}function is(e){const t=i.useRef(e);return i.useEffect(()=>{t.current=e},[e]),i.useCallback(n=>r=>{const a=t.current(r);a!==!1&&a!=null&&n(Array.isArray(a)?a:r)},[])}const qn=160,Zn=60;function cs({width:e=200,height:t=150,nodeColor:n="#3b82f6",nodeStrokeColor:r="#fff",maskColor:a="rgba(0,0,0,0.1)",style:o={},className:c=""}){const h=Te(),m=i.useRef(null),f=i.useRef(null),y=i.useCallback(()=>{const x=m.current;if(!x)return;const k=x.getContext("2d"),S=window.devicePixelRatio||1;x.width=e*S,x.height=t*S,k.scale(S,S),k.clearRect(0,0,e,t);const z=h.nodesRef.current;if(!z.length)return;let W=1/0,j=1/0,H=-1/0,F=-1/0;for(const d of z){const v=d.width||qn,L=d.height||Zn;d.position.x<W&&(W=d.position.x),d.position.y<j&&(j=d.position.y),d.position.x+v>H&&(H=d.position.x+v),d.position.y+L>F&&(F=d.position.y+L)}const $=40;W-=$,j-=$,H+=$,F+=$;const Y=H-W,A=F-j,P=Math.min(e/Y,t/A),Z=(e-Y*P)/2,O=(t-A*P)/2;for(const d of z){if(d.hidden)continue;const v=d.width||qn,L=d.height||Zn,T=(d.position.x-W)*P+Z,B=(d.position.y-j)*P+O,Q=v*P,ne=L*P;k.fillStyle=d.selected?"#f59e0b":typeof n=="function"?n(d):n,k.fillRect(T,B,Math.max(Q,2),Math.max(ne,2))}const X=h.cameraRef.current,M=h.wrapRef.current;if(M){const d=M.getBoundingClientRect(),v=-X.x/X.zoom,L=-X.y/X.zoom,T=d.width/X.zoom,B=d.height/X.zoom;k.fillStyle=a,k.fillRect(0,0,e,t);const Q=(v-W)*P+Z,ne=(L-j)*P+O,ee=T*P,ie=B*P;k.clearRect(Q,ne,ee,ie);for(const me of z){if(me.hidden)continue;const we=me.width||qn,Re=me.height||Zn,ce=(me.position.x-W)*P+Z,pe=(me.position.y-j)*P+O;k.fillStyle=me.selected?"#f59e0b":typeof n=="function"?n(me):n,k.fillRect(ce,pe,Math.max(we*P,2),Math.max(Re*P,2))}k.strokeStyle="#3b82f6",k.lineWidth=1.5,k.strokeRect(Q,ne,ee,ie)}},[h,e,t,n,r,a]);return i.useEffect(()=>{let x=!0;function k(){x&&(y(),f.current=requestAnimationFrame(k))}const S=setInterval(()=>{cancelAnimationFrame(f.current),f.current=requestAnimationFrame(k)},66);return y(),()=>{x=!1,clearInterval(S),cancelAnimationFrame(f.current)}},[y]),I.jsx("canvas",{ref:m,className:`ric-minimap ${c}`,style:{position:"absolute",bottom:30,right:10,width:e,height:t,borderRadius:4,border:"1px solid rgba(0,0,0,0.1)",background:"rgba(255,255,255,0.9)",pointerEvents:"none",...o}})}function ls(){return I.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[I.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),I.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function us(){return I.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:I.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function ds(){return I.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:I.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}function fs(){return I.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[I.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),I.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function hs(){return I.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[I.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),I.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})}function sn({children:e,className:t="",...n}){return I.jsx("button",{className:`ric-controls-button ${t}`,style:ys,...n,children:e})}function gs({showZoom:e=!0,showFitView:t=!0,showInteractive:n=!1,fitViewOptions:r,onZoomIn:a,onZoomOut:o,onFitView:c,onInteractiveChange:h,position:m="bottom-left",orientation:f="vertical",style:y={},className:x="","aria-label":k="Canvas controls",children:S}){const z=Te(),{zoomIn:W,zoomOut:j,fitView:H,getZoom:F}=_r(),[$,Y]=i.useState(!0),A=F()<=z.zoomMin,P=F()>=z.zoomMax,Z=i.useCallback(()=>{W(),a==null||a()},[W,a]),O=i.useCallback(()=>{j(),o==null||o()},[j,o]),X=i.useCallback(()=>{H(r||{padding:.1}),c==null||c()},[H,r,c]),M=i.useCallback(()=>{const v=!$;Y(v),h==null||h(v)},[$,h]),d={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:30,left:10},"bottom-right":{bottom:30,right:10},"bottom-center":{bottom:30,left:"50%",transform:"translateX(-50%)"}}[m]||{bottom:30,left:10};return I.jsxs("div",{className:`ric-controls ${x}`,style:{position:"absolute",display:"flex",flexDirection:f==="horizontal"?"row":"column",gap:2,zIndex:5,...d,...y},role:"toolbar","aria-label":k,children:[e&&I.jsxs(I.Fragment,{children:[I.jsx(sn,{onClick:Z,disabled:P,title:"Zoom in","aria-label":"Zoom in",className:"ric-controls-zoomin",children:I.jsx(ls,{})}),I.jsx(sn,{onClick:O,disabled:A,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:I.jsx(us,{})})]}),t&&I.jsx(sn,{onClick:X,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:I.jsx(ds,{})}),n&&I.jsx(sn,{onClick:M,title:$?"Lock interactivity":"Unlock interactivity","aria-label":$?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:$?I.jsx(hs,{}):I.jsx(fs,{})}),S]})}const ys={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},xs=i.memo(gs);function ps({variant:e="lines",gap:t=40,size:n=1,color:r,style:a={},className:o=""}){const c=Te();return c.workerRef.current&&c.workerRef.current.postMessage({type:"background",data:{variant:e,gap:t,size:n,color:r}}),null}function ms({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 I.jsx("div",{className:`ric-panel ${n}`,style:{position:"absolute",zIndex:5,pointerEvents:"all",...a,...t},onPointerDown:o=>o.stopPropagation(),children:r})}function vs({minWidth:e=10,minHeight:t=10,maxWidth:n=1/0,maxHeight:r=1/0,isVisible:a=!0,handleStyle:o={},lineStyle:c={},color:h="#3b82f6",onResizeStart:m,onResize:f,onResizeEnd:y}){const x=i.useContext(cn),k=Te(),S=i.useRef(null),z=i.useCallback((H,F)=>{H.stopPropagation(),H.preventDefault();const $=k.nodesRef.current.find(P=>P.id===x);if(!$)return;S.current={direction:F,startX:H.clientX,startY:H.clientY,width:$.width||160,height:$.height||60},m==null||m(H,{width:S.current.width,height:S.current.height});const Y=P=>{var L,T;if(!S.current)return;const Z=S.current,O=k.cameraRef.current,X=(P.clientX-Z.startX)/O.zoom,M=(P.clientY-Z.startY)/O.zoom;let d=Z.width,v=Z.height;Z.direction.includes("e")&&(d=Math.min(n,Math.max(e,Z.width+X))),Z.direction.includes("w")&&(d=Math.min(n,Math.max(e,Z.width-X))),Z.direction.includes("s")&&(v=Math.min(r,Math.max(t,Z.height+M))),Z.direction.includes("n")&&(v=Math.min(r,Math.max(t,Z.height-M))),(T=(L=k.onNodesChangeRef).current)==null||T.call(L,[{id:x,type:"dimensions",dimensions:{width:d,height:v},setAttributes:!0}]),f==null||f(P,{width:d,height:v})},A=P=>{S.current=null,y==null||y(P,{}),window.removeEventListener("pointermove",Y),window.removeEventListener("pointerup",A)};window.addEventListener("pointermove",Y),window.addEventListener("pointerup",A)},[x,k,e,t,n,r,m,f,y]);if(!a)return null;const W=8,j={position:"absolute",width:W,height:W,background:h,border:"1px solid #fff",borderRadius:2,zIndex:20,...o};return I.jsxs(I.Fragment,{children:[I.jsx("div",{style:{...j,bottom:-W/2,right:-W/2,cursor:"nwse-resize"},onPointerDown:H=>z(H,"se")}),I.jsx("div",{style:{...j,bottom:-W/2,left:-W/2,cursor:"nesw-resize"},onPointerDown:H=>z(H,"sw")}),I.jsx("div",{style:{...j,top:-W/2,right:-W/2,cursor:"nesw-resize"},onPointerDown:H=>z(H,"ne")}),I.jsx("div",{style:{...j,top:-W/2,left:-W/2,cursor:"nwse-resize"},onPointerDown:H=>z(H,"nw")}),I.jsx("div",{style:{...j,top:"50%",right:-W/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:H=>z(H,"e")}),I.jsx("div",{style:{...j,top:"50%",left:-W/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:H=>z(H,"w")}),I.jsx("div",{style:{...j,left:"50%",top:-W/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:H=>z(H,"n")}),I.jsx("div",{style:{...j,left:"50%",bottom:-W/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:H=>z(H,"s")})]})}function bs({isVisible:e,position:t="top",offset:n=10,align:r="center",children:a,style:o={},className:c=""}){const h=i.useContext(cn),f=Te().nodes.find(k=>k.id===h);if(!(e!==void 0?e:f==null?void 0:f.selected))return null;const x={top:{bottom:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginBottom:n},bottom:{top:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginTop:n},left:{right:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginRight:n},right:{left:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginLeft:n}}[t]||{};return I.jsx("div",{className:`ric-node-toolbar ${c}`,style:{position:"absolute",zIndex:1e3,pointerEvents:"all",...x,...o},onPointerDown:k=>k.stopPropagation(),children:a})}function ws({isVisible:e=!1,x:t=0,y:n=0,alignX:r="center",alignY:a="center",children:o,style:c={},className:h=""}){if(!e)return null;const m=r==="center"?"-50%":r==="right"?"-100%":"0",f=a==="center"?"-50%":a==="bottom"?"-100%":"0";return I.jsx("div",{className:`ric-edge-toolbar ${h}`,style:{position:"absolute",left:t,top:n,transform:`translate(${m}, ${f})`,zIndex:1e3,pointerEvents:"all",...c},children:o})}function Ms({children:e}){var r;const n=(r=Te().edgeLabelContainerRef)==null?void 0:r.current;return n?mr.createPortal(e,n):null}function Rs({children:e}){var r;const n=(r=Te().viewportPortalRef)==null?void 0:r.current;return n?mr.createPortal(e,n):null}function Wr({fromX:e,fromY:t,toX:n,toY:r,fromPosition:a="right",toPosition:o="left",connectionLineType:c="default",connectionLineStyle:h,connectionLineComponent:m}){if(m)return I.jsx(m,{fromX:e,fromY:t,toX:n,toY:r,fromPosition:a,toPosition:o});let f;switch(c){case"straight":[f]=nr({sourceX:e,sourceY:t,targetX:n,targetY:r});break;case"step":[f]=Rn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o,borderRadius:0});break;case"smoothstep":[f]=Rn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o});break;case"simplebezier":[f]=or({sourceX:e,sourceY:t,targetX:n,targetY:r});break;default:[f]=rr({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o});break}return I.jsx("path",{d:f,fill:"none",className:"ric-connection-line",stroke:"#b1b1b7",strokeWidth:1.5,style:h})}Wr.displayName="ConnectionLine";const ks=i.memo(Wr),Cs=Object.freeze({Top:"top",Bottom:"bottom",Left:"left",Right:"right"}),Es=Object.freeze({Arrow:"arrow",ArrowClosed:"arrowclosed"});function Ss(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=ps;exports.BaseEdge=ln;exports.BezierEdge=tr;exports.ConnectionLine=ks;exports.ControlButton=sn;exports.Controls=xs;exports.DefaultNode=bo;exports.EdgeLabelRenderer=Ms;exports.EdgeText=Br;exports.EdgeToolbar=ws;exports.GroupNode=Tr;exports.Handle=an;exports.InfiniteCanvas=jo;exports.InfiniteCanvasProvider=Do;exports.InputNode=Nr;exports.MarkerType=Es;exports.MiniMap=cs;exports.NodeResizer=vs;exports.NodeToolbar=bs;exports.OutputNode=Ir;exports.Panel=ms;exports.Position=Cs;exports.SelectionBox=zr;exports.SimpleBezierEdge=cr;exports.SmoothStepEdge=ir;exports.StepEdge=Ar;exports.StraightEdge=ar;exports.ViewportPortal=Rs;exports.addEdge=_o;exports.applyEdgeChanges=Hr;exports.applyNodeChanges=Dr;exports.boxToRect=Jr;exports.buildObstacles=sr;exports.clampPosition=Qn;exports.computeRoutedEdges=No;exports.getBezierEdgeCenter=wo;exports.getBezierPath=rr;exports.getBoundsOfBoxes=Kr;exports.getConnectedEdges=wr;exports.getEdgeCenter=Mo;exports.getIncomers=qr;exports.getNodeDimensions=er;exports.getNodesBounds=Mn;exports.getNodesInside=Gr;exports.getOutgoers=Zr;exports.getOverlappingArea=Vr;exports.getRoutedLabelPosition=Pn;exports.getSimpleBezierPath=or;exports.getSmoothStepPath=Rn;exports.getStraightPath=nr;exports.getViewportForBounds=Ot;exports.isEdge=Or;exports.isNode=Ur;exports.nodeToBox=Ss;exports.nodeToRect=eo;exports.reconnectEdge=Ro;exports.rectToBox=Qr;exports.routeSinglePath=Io;exports.routedPointsToPath=zn;exports.snapPosition=Gn;exports.useConnection=Oo;exports.useEdges=Xo;exports.useEdgesState=Fo;exports.useHandleConnections=Go;exports.useInfiniteCanvas=Rr;exports.useInternalNode=ns;exports.useKeyPress=Ko;exports.useNodeConnections=Zo;exports.useNodeId=lo;exports.useNodes=Yo;exports.useNodesData=qo;exports.useNodesInitialized=ts;exports.useNodesState=Wo;exports.useOnEdgesChangeMiddleware=is;exports.useOnNodesChangeMiddleware=as;exports.useOnSelectionChange=Jo;exports.useOnViewportChange=Qo;exports.useReactFlow=_r;exports.useStore=rs;exports.useStoreApi=os;exports.useUndoRedo=ss;exports.useUpdateNodeInternals=Vo;exports.useViewport=Uo;