@infinit-canvas/react 0.1.0

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.
@@ -0,0 +1,830 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("react/jsx-runtime"),a=require("react"),Xn=require("react-dom"),Yn=160,Un=60;function Er(t){return t&&typeof t=="object"&&"position"in t&&"data"in t}function zr(t){return t&&typeof t=="object"&&"source"in t&&"target"in t}function qn(t,e){const n=typeof t=="string"?new Set([t]):new Set(Array.isArray(t)?t.map(r=>r.id):[t.id]);return e.filter(r=>n.has(r.source)||n.has(r.target))}function Nr(t,e,n){const r=typeof t=="string"?t:t.id,s=new Set;for(const o of n)o.target===r&&s.add(o.source);return e.filter(o=>s.has(o.id))}function Ir(t,e,n){const r=typeof t=="string"?t:t.id,s=new Set;for(const o of n)o.source===r&&s.add(o.target);return e.filter(o=>s.has(o.id))}function Ve(t){if(!t.length)return{x:0,y:0,width:0,height:0};let e=1/0,n=1/0,r=-1/0,s=-1/0;for(const o of t){const i=o.position.x,l=o.position.y,d=o.width||Yn,u=o.height||Un;i<e&&(e=i),l<n&&(n=l),i+d>r&&(r=i+d),l+u>s&&(s=l+u)}return{x:e,y:n,width:r-e,height:s-n}}function Je(t,e,n,r=.1){const s=t.width*(1+r*2),o=t.height*(1+r*2),i=Math.min(e/s,n/o,1),l=t.x+t.width/2,d=t.y+t.height/2;return{x:e/2-l*i,y:n/2-d*i,zoom:i}}function vn(t,e){return{x:e[0]*Math.round(t.x/e[0]),y:e[1]*Math.round(t.y/e[1])}}function bn(t,e){return{x:Math.min(Math.max(t.x,e[0][0]),e[1][0]),y:Math.min(Math.max(t.y,e[0][1]),e[1][1])}}function Mn(t){var e,n;return{width:t.width||((e=t.measured)==null?void 0:e.width)||Yn,height:t.height||((n=t.measured)==null?void 0:n.height)||Un}}function Sr(t,e,n={x:0,y:0,zoom:1},r=!1){const s=e.x,o=e.y,i=e.x+e.width,l=e.y+e.height;return t.filter(d=>{const{width:u,height:x}=Mn(d),b=d.position.x,N=d.position.y,k=b+u,R=N+x;return r?b<i&&k>s&&N<l&&R>o:b>=s&&k<=i&&N>=o&&R<=l})}function Pr(t){return{x:t.x,y:t.y,x2:t.x+t.width,y2:t.y+t.height}}function Lr(t){return{x:t.x,y:t.y,width:t.x2-t.x,height:t.y2-t.y}}function $r(t,e){return{x:Math.min(t.x,e.x),y:Math.min(t.y,e.y),x2:Math.max(t.x2,e.x2),y2:Math.max(t.y2,e.y2)}}function Tr(t,e){const n=Math.max(0,Math.min(t.x+t.width,e.x+e.width)-Math.max(t.x,e.x)),r=Math.max(0,Math.min(t.y+t.height,e.y+e.height)-Math.max(t.y,e.y));return n*r}function Br(t){const{width:e,height:n}=Mn(t);return{x:t.position.x,y:t.position.y,width:e,height:n}}const Gn=`var Ma = null, r = null, tr = 0, er = 0, g = { x: 0, y: 0, zoom: 1 }, O = [], B = [], P = [], G = !1, Ht = 40, Dt = !1, Br = "lines", Or = 1, lt = null, Pa = null, hr = null, E = 160, c = 60, ft = 8, ao = 5;
2
+ function h(a) {
3
+ return a._absolutePosition || a.position;
4
+ }
5
+ function Vo(a, t, e, o, v) {
6
+ if (a.x !== void 0 && a.y !== void 0)
7
+ return { x: t + a.x, y: e + a.y };
8
+ var f = a.position || (a.type === "source" ? "right" : "left");
9
+ switch (f) {
10
+ case "top":
11
+ return { x: t + o / 2, y: e };
12
+ case "bottom":
13
+ return { x: t + o / 2, y: e + v };
14
+ case "left":
15
+ return { x: t, y: e + v / 2 };
16
+ case "right":
17
+ return { x: t + o, y: e + v / 2 };
18
+ default:
19
+ return { x: t + o, y: e + v / 2 };
20
+ }
21
+ }
22
+ function ho(a) {
23
+ var t = a.width || E, e = a.height || c;
24
+ return a.handles && a.handles.length > 0 ? a.handles.map(function(o) {
25
+ var v = Vo(o, h(a).x, h(a).y, t, e);
26
+ return { id: o.id || null, type: o.type, x: v.x, y: v.y, position: o.position };
27
+ }) : [
28
+ { id: null, type: "target", x: h(a).x, y: h(a).y + e / 2, position: "left" },
29
+ { id: null, type: "source", x: h(a).x + t, y: h(a).y + e / 2, position: "right" }
30
+ ];
31
+ }
32
+ var Ft = {}, Ka = !0;
33
+ function Uo(a) {
34
+ Ka && (Ft = {}, Ka = !1);
35
+ var t = Ft[a.id];
36
+ return t || (t = ho(a), Ft[a.id] = t, t);
37
+ }
38
+ function it(a, t, e) {
39
+ for (var o = Uo(a), v = 0; v < o.length; v++)
40
+ if (o[v].type === t)
41
+ if (e) {
42
+ if (o[v].id === e) return o[v];
43
+ } else
44
+ return o[v];
45
+ var f = a.width || E, l = a.height || c;
46
+ return t === "source" ? { x: h(a).x + f, y: h(a).y + l / 2 } : { x: h(a).x, y: h(a).y + l / 2 };
47
+ }
48
+ var z = {};
49
+ function Yt() {
50
+ z = {
51
+ grid: G ? "rgba(255,255,255,0.07)" : "rgba(0,0,0,0.07)",
52
+ origin: G ? "rgba(255,255,255,0.2)" : "rgba(0,0,0,0.15)",
53
+ cardBg: G ? "#2a2a28" : "#ffffff",
54
+ cardBorder: G ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.1)",
55
+ cardShadow: G ? "rgba(0,0,0,0.3)" : "rgba(0,0,0,0.06)",
56
+ titleText: "rgba(255,255,255,0.9)",
57
+ bodyText: G ? "rgba(255,255,255,0.55)" : "rgba(0,0,0,0.5)",
58
+ coordText: G ? "rgba(255,255,255,0.25)" : "rgba(0,0,0,0.2)",
59
+ nodeBg: G ? "#1e1e2e" : "#ffffff",
60
+ nodeBorder: G ? "rgba(255,255,255,0.15)" : "rgba(0,0,0,0.15)",
61
+ nodeSelectedBorder: "#3b82f6",
62
+ nodeShadow: G ? "rgba(0,0,0,0.4)" : "rgba(0,0,0,0.08)",
63
+ nodeText: G ? "rgba(255,255,255,0.9)" : "rgba(0,0,0,0.85)",
64
+ edgeStroke: G ? "rgba(255,255,255,0.35)" : "rgba(0,0,0,0.3)",
65
+ edgeSelected: "#3b82f6",
66
+ edgeAnimated: "#3b82f6",
67
+ handleFill: "#ffffff",
68
+ handleBorder: "#3b82f6",
69
+ connectionLine: "#3b82f6"
70
+ }, xa = !0;
71
+ }
72
+ Yt();
73
+ var Do = ["#534AB7", "#0F6E56", "#993C1D", "#185FA5"], Ga = 8, Fo = "500 11px system-ui, sans-serif", jo = "400 11px system-ui, sans-serif", Oo = "10px monospace", Xo = "500 13px system-ui, sans-serif", Ho = "400 11px system-ui, sans-serif", br = 400, Ia = {}, ht = !0;
74
+ function Yo() {
75
+ Ia = {};
76
+ for (var a = 0; a < O.length; a++)
77
+ for (var t = O[a], e = Math.floor(t.x / br), o = Math.floor(t.y / br), v = Math.floor((t.x + t.w) / br), f = Math.floor((t.y + t.h) / br), l = e; l <= v; l++)
78
+ for (var y = o; y <= f; y++) {
79
+ var d = l + "," + y;
80
+ Ia[d] || (Ia[d] = []), Ia[d].push(a);
81
+ }
82
+ ht = !1;
83
+ }
84
+ function to(a, t, e, o) {
85
+ ht && Yo();
86
+ for (var v = {}, f = [], l = Math.floor(a / br), y = Math.floor(t / br), d = Math.floor(e / br), M = Math.floor(o / br), x = l; x <= d; x++)
87
+ for (var i = y; i <= M; i++) {
88
+ var n = x + "," + i, s = Ia[n];
89
+ if (s)
90
+ for (var u = 0; u < s.length; u++) {
91
+ var w = s[u];
92
+ v[w] || (v[w] = !0, f.push(w));
93
+ }
94
+ }
95
+ return f;
96
+ }
97
+ var Nr = 500, Za = {}, Xr = !0;
98
+ function te() {
99
+ Za = {};
100
+ for (var a = 0; a < B.length; a++) {
101
+ var t = B[a];
102
+ if (!t.hidden)
103
+ for (var e = h(t), o = t.width || E, v = t.height || c, f = Math.floor(e.x / Nr), l = Math.floor(e.y / Nr), y = Math.floor((e.x + o) / Nr), d = Math.floor((e.y + v) / Nr), M = f; M <= y; M++)
104
+ for (var x = l; x <= d; x++) {
105
+ var i = M + "," + x;
106
+ Za[i] || (Za[i] = []), Za[i].push(a);
107
+ }
108
+ }
109
+ Xr = !1;
110
+ }
111
+ function no(a, t, e, o) {
112
+ Xr && te();
113
+ for (var v = {}, f = [], l = Math.floor(a / Nr), y = Math.floor(t / Nr), d = Math.floor(e / Nr), M = Math.floor(o / Nr), x = l; x <= d; x++)
114
+ for (var i = y; i <= M; i++) {
115
+ var n = x + "," + i, s = Za[n];
116
+ if (s)
117
+ for (var u = 0; u < s.length; u++) {
118
+ var w = s[u];
119
+ v[w] || (v[w] = !0, f.push(w));
120
+ }
121
+ }
122
+ return f;
123
+ }
124
+ var ka = {}, ya = !0;
125
+ function ee() {
126
+ ka = {};
127
+ for (var a = 0; a < B.length; a++)
128
+ ka[B[a].id] = B[a];
129
+ ya = !1;
130
+ }
131
+ function eo(a) {
132
+ return ya && ee(), ka[a];
133
+ }
134
+ var Cr = {}, nt = !0;
135
+ function po() {
136
+ Cr = {};
137
+ for (var a = 0; a < P.length; a++) {
138
+ var t = P[a];
139
+ Cr[t.source] || (Cr[t.source] = []), Cr[t.source].push(a), t.source !== t.target && (Cr[t.target] || (Cr[t.target] = []), Cr[t.target].push(a));
140
+ }
141
+ nt = !1;
142
+ }
143
+ var jr = null, uo = 0, so = 0, Mo = "", xa = !0;
144
+ function rf(a) {
145
+ jr || (jr = new OffscreenCanvas(1, 1));
146
+ var t = Math.ceil(a), e = Math.ceil(a);
147
+ if (t < 2 || e < 2) return !1;
148
+ t > 512 && (t = 512), e > 512 && (e = 512), jr.width = t, jr.height = e, uo = t, so = a, Mo = Br, xa = !1;
149
+ var o = jr.getContext("2d");
150
+ o.clearRect(0, 0, t, e);
151
+ var v = lt || z.grid;
152
+ if (Br === "dots") {
153
+ o.fillStyle = v;
154
+ var f = Or * g.zoom;
155
+ o.beginPath(), o.arc(0, 0, f, 0, 6.2832), o.fill();
156
+ } else if (Br === "cross") {
157
+ o.strokeStyle = v, o.lineWidth = Or;
158
+ var l = 3 * g.zoom;
159
+ o.beginPath(), o.moveTo(-l, 0), o.lineTo(l, 0), o.moveTo(0, -l), o.lineTo(0, l), o.stroke();
160
+ } else
161
+ o.beginPath(), o.strokeStyle = v, o.lineWidth = Or * 0.5, o.moveTo(0.5, 0), o.lineTo(0.5, e), o.moveTo(0, 0.5), o.lineTo(t, 0.5), o.stroke();
162
+ return !0;
163
+ }
164
+ var oo = 0, jt = 0, fo = 0, vo = 0, pt = 0, Ja = !1;
165
+ console.log("[worker] script loaded v2 - FRESH");
166
+ self.postMessage({ type: "ping", data: { status: "alive" } });
167
+ self.onmessage = function(a) {
168
+ try {
169
+ var t = a.data.type, e = a.data.data;
170
+ switch (t) {
171
+ case "init":
172
+ Ma = e.canvas, r = Ma.getContext("2d"), tr = e.width, er = e.height, Ma.width = tr, Ma.height = er, g = e.camera, O = e.cards || [], B = e.nodes || [], P = e.edges || [], G = e.dark, e.gridSize && (Ht = e.gridSize), e.edgeRouting !== void 0 && (ga = !!e.edgeRouting), Yt(), ht = !0, ya = !0, Xr = !0, Ka = !0, nt = !0, Ja = P.some(function(d) {
173
+ return d.animated;
174
+ }), console.log("[worker] init done — canvas:", tr, "x", er, "| cards:", O.length, "| nodes:", B.length, "| edges:", P.length, "| routing:", ga), ut(), self.postMessage({ type: "ready" }), Ja && lo();
175
+ break;
176
+ case "resize":
177
+ tr = e.width, er = e.height, Ma.width = tr, Ma.height = er, xa = !0, ut();
178
+ break;
179
+ case "camera":
180
+ g = e.camera, xa = !0, or();
181
+ break;
182
+ case "cards":
183
+ O = e.cards, ht = !0, or();
184
+ break;
185
+ case "nodes":
186
+ B = e.nodes, ya = !0, Xr = !0, Ka = !0, or(), vt(), self.postMessage({ type: "nodesProcessed", data: { nodeCount: B.length } });
187
+ break;
188
+ case "nodePositions":
189
+ ya && ee();
190
+ for (var o = e.updates, v = 0; v < o.length; v++) {
191
+ var f = o[v], l = ka[f.id];
192
+ l && (l.position = f.position, f._absolutePosition && (l._absolutePosition = f._absolutePosition), f.width !== void 0 && (l.width = f.width), f.height !== void 0 && (l.height = f.height), l.dragging = f.dragging, l.selected = f.selected);
193
+ }
194
+ Ka = !0, Xr = !0, or(), vt();
195
+ break;
196
+ case "edges":
197
+ P = e.edges, nt = !0, Ja = P.some(function(d) {
198
+ return d.animated;
199
+ }), Ja && lo(), or(), vt();
200
+ break;
201
+ case "theme":
202
+ G = e.dark, Yt(), or();
203
+ break;
204
+ case "connecting":
205
+ Pa = e, or();
206
+ break;
207
+ case "selectionBox":
208
+ hr = e, or();
209
+ break;
210
+ case "background":
211
+ e.variant && (Br = e.variant), e.gap && (Ht = e.gap), e.size && (Or = e.size), lt = e.color || null, xa = !0, or();
212
+ break;
213
+ case "edgeRouting":
214
+ if (ga = !!e.enabled, ga)
215
+ vt();
216
+ else {
217
+ for (var y = 0; y < P.length; y++)
218
+ P[y]._routedPoints = null;
219
+ or();
220
+ }
221
+ break;
222
+ }
223
+ } catch (d) {
224
+ console.error("[worker] error:", d);
225
+ }
226
+ };
227
+ function or() {
228
+ Dt || (Dt = !0, requestAnimationFrame(function() {
229
+ Dt = !1, ut();
230
+ }));
231
+ }
232
+ var Ot = !1;
233
+ function lo() {
234
+ if (Ot) return;
235
+ Ot = !0;
236
+ function a() {
237
+ if (!Ja) {
238
+ Ot = !1;
239
+ return;
240
+ }
241
+ pt = (pt + 0.5) % 20, ut(), requestAnimationFrame(a);
242
+ }
243
+ requestAnimationFrame(a);
244
+ }
245
+ function io(a, t) {
246
+ var e = 6;
247
+ a.moveTo(t[0].x, t[0].y);
248
+ for (var o = 1; o < t.length - 1; o++) {
249
+ var v = t[o - 1], f = t[o], l = t[o + 1], y = Math.abs(f.x - v.x) + Math.abs(f.y - v.y), d = Math.abs(l.x - f.x) + Math.abs(l.y - f.y), M = Math.min(e, y / 2, d / 2);
250
+ if (M > 0.5) {
251
+ var x = f.x - v.x, i = f.y - v.y, n = l.x - f.x, s = l.y - f.y, u = Math.sqrt(x * x + i * i) || 1, w = Math.sqrt(n * n + s * s) || 1;
252
+ a.lineTo(f.x - x / u * M, f.y - i / u * M), a.quadraticCurveTo(f.x, f.y, f.x + n / w * M, f.y + s / w * M);
253
+ } else
254
+ a.lineTo(f.x, f.y);
255
+ }
256
+ a.lineTo(t[t.length - 1].x, t[t.length - 1].y);
257
+ }
258
+ function af(a) {
259
+ for (var t = 0, e = 1; e < a.length; e++)
260
+ t += Math.abs(a[e].x - a[e - 1].x) + Math.abs(a[e].y - a[e - 1].y);
261
+ for (var o = t / 2, v = 1; v < a.length; v++) {
262
+ var f = Math.abs(a[v].x - a[v - 1].x) + Math.abs(a[v].y - a[v - 1].y);
263
+ if (o <= f) {
264
+ var l = f > 0 ? o / f : 0;
265
+ return {
266
+ x: a[v - 1].x + (a[v].x - a[v - 1].x) * l,
267
+ y: a[v - 1].y + (a[v].y - a[v - 1].y) * l
268
+ };
269
+ }
270
+ o -= f;
271
+ }
272
+ return { x: a[0].x, y: a[0].y };
273
+ }
274
+ function re(a, t, e, o) {
275
+ var v = Math.abs(e - a), f = Math.max(50, v * 0.5), l = a + f, y = t, d = e - f, M = o;
276
+ return { cp1x: l, cp1y: y, cp2x: d, cp2y: M };
277
+ }
278
+ function tf(a, t, e, o) {
279
+ var v = re(a, t, e, o), f = 0.5, l = 1 - f, y = l * l * l * a + 3 * l * l * f * v.cp1x + 3 * l * f * f * v.cp2x + f * f * f * e, d = l * l * l * t + 3 * l * l * f * v.cp1y + 3 * l * f * f * v.cp2y + f * f * f * o;
280
+ return { x: y, y: d };
281
+ }
282
+ var ga = !0, ae = !1, Xt = !1;
283
+ function go(a, t, e, o, v) {
284
+ Xr && te();
285
+ for (var f = Math.min(a, e) - 20, l = Math.min(t, o) - 20, y = Math.max(a, e) + 20, d = Math.max(t, o) + 20, M = no(f, l, y, d), x = [], i = 0; i < M.length; i++) {
286
+ var n = B[M[i]];
287
+ n.hidden || v[n.id] || n.type !== "group" && x.push(n);
288
+ }
289
+ return x;
290
+ }
291
+ function dr(a, t, e, o) {
292
+ for (var v = Math.min(a, t), f = Math.max(a, t), l = 0; l < o.length; l++) {
293
+ var y = o[l], d = h(y), M = y.width || E, x = y.height || c;
294
+ if (e > d.y && e < d.y + x && f > d.x && v < d.x + M) return y;
295
+ }
296
+ return null;
297
+ }
298
+ function Mr(a, t, e, o) {
299
+ for (var v = Math.min(t, e), f = Math.max(t, e), l = 0; l < o.length; l++) {
300
+ var y = o[l], d = h(y), M = y.width || E, x = y.height || c;
301
+ if (a > d.x && a < d.x + M && f > d.y && v < d.y + x) return y;
302
+ }
303
+ return null;
304
+ }
305
+ function ef() {
306
+ if (ga && !(!ae || P.length === 0 || B.length === 0)) {
307
+ ae = !1, ya && ee(), Xr && te();
308
+ for (var a = 20, t = !1, e = 0; e < P.length; e++) {
309
+ var o = P[e];
310
+ if (!o._customRendered) {
311
+ var v = o.type || "default";
312
+ if (!(v === "bezier" || v === "simplebezier" || v === "default")) {
313
+ var f = ka[o.source], l = ka[o.target];
314
+ if (!(!f || !l || f.hidden || l.hidden)) {
315
+ var y = it(f, "source", o.sourceHandle), d = it(l, "target", o.targetHandle), M = y.position || "right", x = d.position || "left", i = y.x, n = y.y, s = d.x, u = d.y, w = i, Q = n, W = s, $ = u;
316
+ M === "right" ? w += a : M === "left" ? w -= a : M === "bottom" ? Q += a : M === "top" && (Q -= a), x === "right" ? W += a : x === "left" ? W -= a : x === "bottom" ? $ += a : x === "top" && ($ -= a);
317
+ var gr = h(f), qr = h(l), Sr = f.width || E, Gr = f.height || c, Pr = l.width || E, Hr = l.height || c, Ir = {};
318
+ Ir[o.source] = !0, Ir[o.target] = !0;
319
+ var X = go(
320
+ Math.min(i, s) - Sr,
321
+ Math.min(n, u) - Gr,
322
+ Math.max(i, s) + Pr,
323
+ Math.max(n, u) + Hr,
324
+ Ir
325
+ );
326
+ X.push(f), X.push(l);
327
+ var Yr = M === "left" || M === "right", Ta = x === "left" || x === "right", C = null;
328
+ if (Yr && Ta) {
329
+ var L, fr = M === "right" && w < W, st = M === "left" && w > W;
330
+ if (fr || st) {
331
+ L = (w + W) / 2;
332
+ var ma = Mr(L, n, u, X);
333
+ if (ma) {
334
+ var pr = h(ma), ra = ma.width || E;
335
+ L = L < pr.x + ra / 2 ? pr.x - a : pr.x + ra + a;
336
+ }
337
+ } else
338
+ M === "right" ? L = Math.max(gr.x + Sr, qr.x + Pr) + a : L = Math.min(gr.x, qr.x) - a;
339
+ C = [{ x: i, y: n }, { x: w, y: n }, { x: L, y: n }, { x: L, y: u }, { x: W, y: u }, { x: s, y: u }];
340
+ var yr = dr(L, W, u, X);
341
+ if (yr) {
342
+ var aa = h(yr), ta = yr.height || c, ea = aa.y - a, Zr = aa.y + ta + a, Jr = Math.abs(n - ea) <= Math.abs(n - Zr) ? ea : Zr;
343
+ C = [{ x: i, y: n }, { x: w, y: n }, { x: L, y: n }, { x: L, y: Jr }, { x: W, y: Jr }, { x: W, y: u }, { x: s, y: u }];
344
+ }
345
+ } else if (!Yr && !Ta) {
346
+ var N, Qa = M === "bottom" && Q < $, Ra = M === "top" && Q > $;
347
+ if (Qa || Ra) {
348
+ N = (Q + $) / 2;
349
+ var xr = dr(i, s, N, X);
350
+ if (xr) {
351
+ var kr = h(xr), oa = xr.height || c;
352
+ N = N < kr.y + oa / 2 ? kr.y - a : kr.y + oa + a;
353
+ }
354
+ } else
355
+ M === "bottom" ? N = Math.max(gr.y + Gr, qr.y + Hr) + a : N = Math.min(gr.y, qr.y) - a;
356
+ C = [{ x: i, y: n }, { x: i, y: Q }, { x: i, y: N }, { x: s, y: N }, { x: s, y: $ }, { x: s, y: u }];
357
+ var Kr = Mr(s, N, $, X);
358
+ if (Kr) {
359
+ var fa = h(Kr), wa = Kr.height || c, va = fa.y - a, la = fa.y + wa + a, ia = Math.abs(N - va) <= Math.abs(N - la) ? va : la;
360
+ C = [{ x: i, y: n }, { x: i, y: Q }, { x: i, y: N }, { x: s, y: N }, { x: s, y: ia }, { x: W, y: ia }, { x: W, y: u }, { x: s, y: u }];
361
+ }
362
+ } else if (Yr) {
363
+ C = [{ x: i, y: n }, { x: w, y: n }, { x: s, y: n }, { x: s, y: $ }, { x: s, y: u }];
364
+ var Tr = Mr(s, n, $, X);
365
+ if (Tr) {
366
+ var V = h(Tr), mr = Tr.width || E, za = Math.abs(i - V.x + a) <= Math.abs(i - V.x - mr - a) ? V.x - a : V.x + mr + a;
367
+ C = [{ x: i, y: n }, { x: w, y: n }, { x: za, y: n }, { x: za, y: u }, { x: s, y: u }, { x: s, y: $ }, { x: s, y: u }];
368
+ }
369
+ var Qr = dr(w, s, n, X);
370
+ if (Qr) {
371
+ var Rr = h(Qr), ha = Qr.height || c, H = Math.abs(u - Rr.y + a) <= Math.abs(u - Rr.y - ha - a) ? Rr.y - a : Rr.y + ha + a;
372
+ C = [{ x: i, y: n }, { x: w, y: n }, { x: w, y: H }, { x: s, y: H }, { x: s, y: $ }, { x: s, y: u }];
373
+ }
374
+ } else {
375
+ C = [{ x: i, y: n }, { x: i, y: Q }, { x: i, y: u }, { x: W, y: u }, { x: s, y: u }];
376
+ var wr = dr(i, W, u, X);
377
+ if (wr) {
378
+ var na = h(wr), U = wr.height || c, zr = Math.abs(n - na.y + a) <= Math.abs(n - na.y - U - a) ? na.y - a : na.y + U + a;
379
+ C = [{ x: i, y: n }, { x: i, y: Q }, { x: i, y: zr }, { x: W, y: zr }, { x: W, y: u }, { x: s, y: u }];
380
+ }
381
+ var nr = Mr(i, Q, u, X);
382
+ if (nr) {
383
+ var vr = h(nr), ca = nr.width || E, _a = Math.abs(s - vr.x + a) <= Math.abs(s - vr.x - ca - a) ? vr.x - a : vr.x + ca + a;
384
+ C = [{ x: i, y: n }, { x: i, y: Q }, { x: _a, y: Q }, { x: _a, y: u }, { x: W, y: u }, { x: s, y: u }];
385
+ }
386
+ }
387
+ if (C) {
388
+ for (var $r = [C[0]], lr = 1; lr < C.length; lr++) {
389
+ var $a = $r[$r.length - 1];
390
+ (Math.abs(C[lr].x - $a.x) > 0.1 || Math.abs(C[lr].y - $a.y) > 0.1) && $r.push(C[lr]);
391
+ }
392
+ o._routedPoints = $r, t = !0;
393
+ }
394
+ }
395
+ }
396
+ }
397
+ }
398
+ t && or();
399
+ }
400
+ }
401
+ function vt() {
402
+ ga && (Xt || (Xt = !0, ae = !0, requestAnimationFrame(function() {
403
+ Xt = !1;
404
+ try {
405
+ ef();
406
+ } catch (a) {
407
+ console.error("[worker] async routing error:", a);
408
+ }
409
+ })));
410
+ }
411
+ function ut() {
412
+ if (r) {
413
+ var a = performance.now();
414
+ r.clearRect(0, 0, tr, er);
415
+ var t = Ht * g.zoom;
416
+ if (t > 2)
417
+ if (Br === "lines" && t >= 4 && t <= 512) {
418
+ if ((xa || so !== t || Mo !== Br) && rf(t), jr && uo > 0) {
419
+ var e = (g.x % t + t) % t, o = (g.y % t + t) % t;
420
+ r.save(), r.translate(e, o);
421
+ var v = r.createPattern(jr, "repeat");
422
+ v && (r.fillStyle = v, r.fillRect(-e, -o, tr, er)), r.restore();
423
+ }
424
+ } else {
425
+ var f = (g.x % t + t) % t, l = (g.y % t + t) % t, y = lt || z.grid;
426
+ if (Br === "dots") {
427
+ r.fillStyle = y;
428
+ for (var d = Or * g.zoom, M = f; M < tr; M += t)
429
+ for (var x = l; x < er; x += t)
430
+ r.beginPath(), r.arc(Math.round(M), Math.round(x), d, 0, 6.2832), r.fill();
431
+ } else if (Br === "cross") {
432
+ r.strokeStyle = y, r.lineWidth = Or;
433
+ var i = 3 * g.zoom;
434
+ r.beginPath();
435
+ for (var n = f; n < tr; n += t)
436
+ for (var s = l; s < er; s += t) {
437
+ var u = Math.round(n), w = Math.round(s);
438
+ r.moveTo(u - i, w), r.lineTo(u + i, w), r.moveTo(u, w - i), r.lineTo(u, w + i);
439
+ }
440
+ r.stroke();
441
+ } else {
442
+ var Q = lt || z.grid;
443
+ r.beginPath(), r.strokeStyle = Q, r.lineWidth = Or * 0.5;
444
+ for (var W = f; W < tr; W += t) {
445
+ var $ = Math.round(W) + 0.5;
446
+ r.moveTo($, 0), r.lineTo($, er);
447
+ }
448
+ for (var gr = l; gr < er; gr += t) {
449
+ var qr = Math.round(gr) + 0.5;
450
+ r.moveTo(0, qr), r.lineTo(tr, qr);
451
+ }
452
+ r.stroke();
453
+ }
454
+ }
455
+ r.beginPath(), r.arc(g.x, g.y, 4 * g.zoom, 0, 6.2832), r.fillStyle = z.origin, r.fill(), r.save(), r.translate(g.x, g.y), r.scale(g.zoom, g.zoom);
456
+ var Sr = 100, Gr = -g.x / g.zoom, Pr = -g.y / g.zoom, Hr = Gr + tr / g.zoom, Ir = Pr + er / g.zoom, X = Gr - Sr, Yr = Pr - Sr, Ta = Hr + Sr, C = Ir + Sr;
457
+ if (O.length > 0) {
458
+ var L = to(Gr, Pr, Hr, Ir), fr = L.length, st = g.zoom > 0.15, ma = g.zoom > 0.3, pr = g.zoom > 0.08 && fr < 200;
459
+ if (pr) {
460
+ r.shadowColor = z.cardShadow, r.shadowBlur = 6, r.shadowOffsetY = 2, r.fillStyle = z.cardBg, r.beginPath();
461
+ for (var ra = 0; ra < fr; ra++) {
462
+ var yr = O[L[ra]];
463
+ r.roundRect(yr.x, yr.y, yr.w, yr.h, Ga);
464
+ }
465
+ r.fill(), r.shadowColor = "transparent", r.shadowBlur = 0, r.shadowOffsetY = 0;
466
+ }
467
+ if (!pr) {
468
+ r.fillStyle = z.cardBg, r.beginPath();
469
+ for (var aa = 0; aa < fr; aa++) {
470
+ var ta = O[L[aa]];
471
+ r.roundRect(ta.x, ta.y, ta.w, ta.h, Ga);
472
+ }
473
+ r.fill();
474
+ }
475
+ r.strokeStyle = z.cardBorder, r.lineWidth = 0.5, r.beginPath();
476
+ for (var ea = 0; ea < fr; ea++) {
477
+ var Zr = O[L[ea]];
478
+ r.roundRect(Zr.x, Zr.y, Zr.w, Zr.h, Ga);
479
+ }
480
+ r.stroke();
481
+ for (var Jr = [{}, {}, {}, {}], N = 0; N < fr; N++) {
482
+ var Qa = L[N], Ra = Qa % 4;
483
+ Jr[Ra].items || (Jr[Ra].items = []), Jr[Ra].items.push(O[Qa]);
484
+ }
485
+ for (var xr = 0; xr < 4; xr++) {
486
+ var kr = Jr[xr].items;
487
+ if (!(!kr || kr.length === 0)) {
488
+ r.fillStyle = Do[xr], r.beginPath();
489
+ for (var oa = 0; oa < kr.length; oa++) {
490
+ var Kr = kr[oa];
491
+ r.roundRect(Kr.x, Kr.y, Kr.w, 30, [Ga, Ga, 0, 0]);
492
+ }
493
+ r.fill();
494
+ }
495
+ }
496
+ if (st) {
497
+ r.fillStyle = z.titleText, r.font = Fo;
498
+ for (var fa = 0; fa < fr; fa++) {
499
+ var wa = O[L[fa]];
500
+ r.fillText(wa.title, wa.x + 12, wa.y + 19);
501
+ }
502
+ r.fillStyle = z.bodyText, r.font = jo;
503
+ for (var va = 0; va < fr; va++) {
504
+ var la = O[L[va]];
505
+ r.fillText(la.body, la.x + 12, la.y + 52);
506
+ }
507
+ if (ma) {
508
+ r.fillStyle = z.coordText, r.font = Oo;
509
+ for (var ia = 0; ia < fr; ia++) {
510
+ var Tr = O[L[ia]];
511
+ r.fillText("(" + Tr.x + ", " + Tr.y + ")", Tr.x + 12, Tr.y + 75);
512
+ }
513
+ }
514
+ }
515
+ }
516
+ var V = [], mr = null;
517
+ if (B.length > 0)
518
+ if (mr = {}, B.length > 100)
519
+ for (var za = no(X, Yr, Ta, C), Qr = 0; Qr < za.length; Qr++) {
520
+ var Rr = B[za[Qr]];
521
+ mr[Rr.id] = !0, Rr._customRendered || V.push(Rr);
522
+ }
523
+ else
524
+ for (var ha = 0; ha < B.length; ha++) {
525
+ var H = B[ha];
526
+ if (!H.hidden) {
527
+ var wr = H.width || E, na = H.height || c;
528
+ h(H).x + wr < X || h(H).x > Ta || h(H).y + na < Yr || h(H).y > C || (mr[H.id] = !0, H._customRendered || V.push(H));
529
+ }
530
+ }
531
+ var U = V.length;
532
+ if (P.length > 0 && B.length > 0) {
533
+ let ot = function(Lr, ro) {
534
+ if (Lr.length) {
535
+ r.fillStyle = ro, r.beginPath();
536
+ for (var Ut = 0; Ut < Lr.length; Ut++) {
537
+ var j = Lr[Ut];
538
+ 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();
539
+ }
540
+ r.fill();
541
+ }
542
+ };
543
+ var of = ot;
544
+ nt && po();
545
+ var zr = null, nr = null, vr = null, ca = [], _a = [], $r = [], lr = [], $a = g.zoom > 0.3, yo = g.zoom > 0.05, ua;
546
+ if (mr && B.length > 100) {
547
+ var oe = {};
548
+ ua = [];
549
+ for (var xo in mr) {
550
+ var dt = Cr[xo];
551
+ if (dt)
552
+ for (var Mt = 0; Mt < dt.length; Mt++) {
553
+ var gt = dt[Mt];
554
+ oe[gt] || (oe[gt] = !0, ua.push(gt));
555
+ }
556
+ }
557
+ } else {
558
+ ua = [];
559
+ for (var yt = 0; yt < P.length; yt++) ua.push(yt);
560
+ }
561
+ for (var xt = 0; xt < ua.length; xt++) {
562
+ var D = P[ua[xt]], Vr = eo(D.source), Ur = eo(D.target);
563
+ if (!(!Vr || !Ur) && !(Vr.hidden || Ur.hidden) && !D._customRendered) {
564
+ var Va = it(Vr, "source", D.sourceHandle), Ua = it(Ur, "target", D.targetHandle), _ = Va.x, R = Va.y, T = Ua.x, m = Ua.y, ir = D.type || "default", fe = D.selected, ve = D.animated, q;
565
+ fe ? (nr || (nr = new Path2D()), q = nr) : ve ? (vr || (vr = new Path2D()), q = vr) : (zr || (zr = new Path2D()), q = zr);
566
+ var S = D._routedPoints;
567
+ if (S && S.length >= 2)
568
+ io(q, S);
569
+ else if (ir === "straight")
570
+ q.moveTo(_, R), q.lineTo(T, m);
571
+ else if (ir === "step" || ir === "smoothstep")
572
+ try {
573
+ var Y = Va.position || "right", sa = Ua.position || "left", k = 20, I = _, F = R, Z = T, p = m;
574
+ Y === "right" ? I += k : Y === "left" ? I -= k : Y === "bottom" ? F += k : Y === "top" && (F -= k), sa === "right" ? Z += k : sa === "left" ? Z -= k : sa === "bottom" ? p += k : sa === "top" && (p -= k);
575
+ var Da = h(Vr), Fa = h(Ur), Aa = Vr.width || E, Ea = Vr.height || c, le = Ur.width || E, ie = Ur.height || c, kt = Y === "left" || Y === "right", he = sa === "left" || sa === "right", Tt = {};
576
+ Tt[D.source] = !0, Tt[D.target] = !0;
577
+ var rr = go(
578
+ Math.min(_, T) - Aa,
579
+ Math.min(R, m) - Ea,
580
+ Math.max(_, T) + le,
581
+ Math.max(R, m) + ie,
582
+ Tt
583
+ );
584
+ rr.push(Vr), rr.push(Ur);
585
+ var b = [];
586
+ if (kt && he) {
587
+ var J, ko = Y === "right" && I < Z, To = Y === "left" && I > Z;
588
+ if (ko || To) {
589
+ J = (I + Z) / 2;
590
+ var mt = Mr(J, R, m, rr);
591
+ if (mt) {
592
+ var Rt = h(mt), wr = mt.width || E;
593
+ J < Rt.x + wr / 2 ? J = Rt.x - k : J = Rt.x + wr + k;
594
+ }
595
+ } else
596
+ Y === "right" ? J = Math.max(Da.x + Aa, Fa.x + le) + k : J = Math.min(Da.x, Fa.x) - k;
597
+ b = [{ x: I, y: R }, { x: J, y: R }, { x: J, y: m }, { x: Z, y: m }];
598
+ var wt = dr(J, Z, m, rr);
599
+ if (wt) {
600
+ var ne = h(wt), mo = wt.height || c, ue = ne.y - k, se = ne.y + mo + k, de = Math.abs(R - ue) <= Math.abs(R - se) ? ue : se;
601
+ b = [
602
+ { x: I, y: R },
603
+ { x: J, y: R },
604
+ { x: J, y: de },
605
+ { x: Z, y: de },
606
+ { x: Z, y: m }
607
+ ];
608
+ }
609
+ var zt = dr(I, J, R, rr);
610
+ if (zt) {
611
+ var Me = h(zt), Ro = zt.height || c, ge = Me.y - k, ye = Me.y + Ro + k, xe = Math.abs(m - ge) <= Math.abs(m - ye) ? ge : ye;
612
+ b.splice(
613
+ 1,
614
+ 0,
615
+ { x: I, y: xe },
616
+ { x: J, y: xe }
617
+ ), b = b.filter(function(Lr, ro) {
618
+ return !(Math.abs(Lr.x - J) < 1 && Math.abs(Lr.y - R) < 1);
619
+ }), b.splice(0, 0, { x: I, y: R });
620
+ }
621
+ } else if (!kt && !he) {
622
+ var K, wo = Y === "bottom" && F < p, zo = Y === "top" && F > p;
623
+ if (wo || zo) {
624
+ K = (F + p) / 2;
625
+ var ct = dr(_, T, K, rr);
626
+ if (ct) {
627
+ var _t = h(ct), ke = ct.height || c;
628
+ K < _t.y + ke / 2 ? K = _t.y - k : K = _t.y + ke + k;
629
+ }
630
+ } else
631
+ Y === "bottom" ? K = Math.max(Da.y + Ea, Fa.y + ie) + k : K = Math.min(Da.y, Fa.y) - k;
632
+ b = [{ x: _, y: F }, { x: _, y: K }, { x: T, y: K }, { x: T, y: p }];
633
+ var At = Mr(_, F, K, rr);
634
+ if (At) {
635
+ var Te = h(At), co = At.width || E, me = Te.x - k, Re = Te.x + co + k, we = Math.abs(T - me) <= Math.abs(T - Re) ? me : Re;
636
+ b = [
637
+ { x: _, y: F },
638
+ { x: we, y: F },
639
+ { x: we, y: K },
640
+ { x: T, y: K },
641
+ { x: T, y: p }
642
+ ];
643
+ }
644
+ var Et = Mr(T, K, p, rr);
645
+ if (Et) {
646
+ var ze = h(Et), _o = Et.height || c, ce = ze.y - k, _e = ze.y + _o + k, Ao = Math.abs(K - ce) <= Math.abs(K - _e) ? ce : _e;
647
+ b.splice(
648
+ b.length - 1,
649
+ 0,
650
+ { x: Z, y: Ao }
651
+ );
652
+ }
653
+ } else if (kt) {
654
+ b = [{ x: I, y: R }, { x: T, y: R }, { x: T, y: p }];
655
+ var Wt = Mr(T, R, p, rr);
656
+ if (Wt) {
657
+ var Ae = h(Wt), Eo = Wt.width || E, Ee = Ae.x - k, We = Ae.x + Eo + k, Le = Math.abs(_ - Ee) <= Math.abs(_ - We) ? Ee : We;
658
+ b = [{ x: I, y: R }, { x: Le, y: R }, { x: Le, y: m }, { x: T, y: m }, { x: T, y: p }];
659
+ }
660
+ var Lt = dr(I, T, R, rr);
661
+ if (Lt) {
662
+ var Ce = h(Lt), Wo = Lt.height || c, Be = Ce.y - k, be = Ce.y + Wo + k, Ne = Math.abs(m - Be) <= Math.abs(m - be) ? Be : be;
663
+ b = [{ x: I, y: R }, { x: I, y: Ne }, { x: T, y: Ne }, { x: T, y: p }];
664
+ }
665
+ } else {
666
+ b = [{ x: _, y: F }, { x: _, y: m }, { x: Z, y: m }];
667
+ var Ct = dr(_, Z, m, rr);
668
+ if (Ct) {
669
+ var qe = h(Ct), Lo = Ct.height || c, Se = qe.y - k, Ge = qe.y + Lo + k, Pe = Math.abs(R - Se) <= Math.abs(R - Ge) ? Se : Ge;
670
+ b = [{ x: _, y: F }, { x: _, y: Pe }, { x: Z, y: Pe }, { x: Z, y: m }];
671
+ }
672
+ var Bt = Mr(_, F, m, rr);
673
+ if (Bt) {
674
+ var Ie = h(Bt), Co = Bt.width || E, Ze = Ie.x - k, Je = Ie.x + Co + k, Ke = Math.abs(T - Ze) <= Math.abs(T - Je) ? Ze : Je;
675
+ b = [{ x: _, y: F }, { x: Ke, y: F }, { x: Ke, y: m }, { x: Z, y: m }];
676
+ }
677
+ }
678
+ for (var Dr = [{ x: _, y: R }], bt = 0; bt < b.length; bt++) Dr.push(b[bt]);
679
+ Dr.push({ x: T, y: m });
680
+ for (var ar = [Dr[0]], Wa = 1; Wa < Dr.length; Wa++) {
681
+ var La = ar[ar.length - 1];
682
+ (Math.abs(Dr[Wa].x - La.x) > 0.1 || Math.abs(Dr[Wa].y - La.y) > 0.1) && ar.push(Dr[Wa]);
683
+ }
684
+ var Qe = ir === "smoothstep" ? 8 : 0;
685
+ q.moveTo(ar[0].x, ar[0].y);
686
+ for (var ur = 1; ur < ar.length; ur++)
687
+ if (Qe > 0 && ur > 0 && ur < ar.length - 1) {
688
+ var sr = ar[ur - 1], A = ar[ur], cr = ar[ur + 1];
689
+ if (Math.abs(sr.x - A.x) < 0.5 && Math.abs(A.x - cr.x) < 0.5 || Math.abs(sr.y - A.y) < 0.5 && Math.abs(A.y - cr.y) < 0.5)
690
+ q.lineTo(A.x, A.y);
691
+ else {
692
+ var ja = Math.min(Math.hypot(sr.x - A.x, sr.y - A.y) / 2, Math.hypot(A.x - cr.x, A.y - cr.y) / 2, Qe);
693
+ Math.abs(sr.y - A.y) < 0.5 ? (q.lineTo(A.x + (sr.x < cr.x ? -1 : 1) * ja, A.y), q.quadraticCurveTo(A.x, A.y, A.x, A.y + (sr.y < cr.y ? 1 : -1) * ja)) : (q.lineTo(A.x, A.y + (sr.y < cr.y ? -1 : 1) * ja), q.quadraticCurveTo(A.x, A.y, A.x + (sr.x < cr.x ? 1 : -1) * ja, A.y));
694
+ }
695
+ } else
696
+ q.lineTo(ar[ur].x, ar[ur].y);
697
+ } catch (Lr) {
698
+ console.error("[worker] smoothstep error:", Lr, "edge:", D.id);
699
+ }
700
+ else {
701
+ var _r = Va.position || "right", Ar = Ua.position || "left", Er = 20, Ca = _, Oa = R, Ba = T, Xa = m;
702
+ _r === "right" ? Ca += Er : _r === "left" ? Ca -= Er : _r === "bottom" ? Oa += Er : _r === "top" && (Oa -= Er), Ar === "right" ? Ba += Er : Ar === "left" ? Ba -= Er : Ar === "bottom" ? Xa += Er : Ar === "top" && (Xa -= Er);
703
+ var Bo = Math.abs(Ba - Ca), Wr = Math.max(50, Bo * 0.5), bo = Ca + (_r === "left" ? -Wr : _r === "right" ? Wr : 0), No = Oa + (_r === "top" ? -Wr : _r === "bottom" ? Wr : 0), qo = Ba + (Ar === "left" ? -Wr : Ar === "right" ? Wr : 0), So = Xa + (Ar === "top" ? -Wr : Ar === "bottom" ? Wr : 0);
704
+ q.moveTo(_, R), q.lineTo(Ca, Oa), q.bezierCurveTo(bo, No, qo, So, Ba, Xa), q.lineTo(T, m);
705
+ }
706
+ if (yo) {
707
+ var Go = 8, ba;
708
+ if (S && S.length >= 2) {
709
+ var La = S[S.length - 1], $e = S[S.length - 2];
710
+ ba = Math.atan2(La.y - $e.y, La.x - $e.x);
711
+ } else if (ir === "straight")
712
+ ba = Math.atan2(m - R, T - _);
713
+ else if (ir === "step" || ir === "smoothstep")
714
+ ba = 0;
715
+ else {
716
+ var Ve = re(_, R, T, m);
717
+ ba = Math.atan2(m - Ve.cp2y, T - Ve.cp2x);
718
+ }
719
+ var Ue = S && S.length >= 2 ? S[S.length - 1] : { x: T, y: m }, Nt = { x: Ue.x, y: Ue.y, angle: ba, size: Go };
720
+ fe ? _a.push(Nt) : ve ? $r.push(Nt) : ca.push(Nt);
721
+ }
722
+ if ($a && D.label) {
723
+ var Na;
724
+ S && S.length >= 2 ? Na = af(S) : ir === "straight" || ir === "step" || ir === "smoothstep" ? Na = { x: (_ + T) / 2, y: (R + m) / 2 } : Na = tf(_, R, T, m), lr.push({ text: D.label, x: Na.x, y: Na.y });
725
+ }
726
+ }
727
+ }
728
+ if (zr && (r.strokeStyle = z.edgeStroke, r.lineWidth = 1.5, r.setLineDash([]), r.stroke(zr)), vr && (r.strokeStyle = z.edgeAnimated, r.lineWidth = 1.5, r.setLineDash([5, 5]), r.lineDashOffset = -pt, r.stroke(vr), r.setLineDash([])), nr && (r.strokeStyle = z.edgeSelected, r.lineWidth = 2.5, r.setLineDash([]), r.stroke(nr)), ot(ca, z.edgeStroke), ot($r, z.edgeAnimated), ot(_a, z.edgeSelected), lr.length > 0) {
729
+ r.font = Ho, r.textAlign = "center", r.textBaseline = "middle";
730
+ for (var qt = 0; qt < lr.length; qt++) {
731
+ var da = lr[qt], Po = r.measureText(da.text), De = Po.width + 12;
732
+ r.fillStyle = G ? "#2a2a2a" : "#ffffff", r.fillRect(da.x - De / 2, da.y - 9, De, 18), r.fillStyle = z.nodeText, r.fillText(da.text, da.x, da.y);
733
+ }
734
+ r.textAlign = "start", r.textBaseline = "alphabetic";
735
+ }
736
+ }
737
+ if (Pa) {
738
+ r.beginPath(), r.strokeStyle = z.connectionLine, r.lineWidth = 2, r.setLineDash([6, 4]);
739
+ var St = Pa._routedPoints;
740
+ if (St && St.length >= 2) {
741
+ var Fe = new Path2D();
742
+ io(Fe, St), r.stroke(Fe);
743
+ } else {
744
+ var Ha = Pa.from, Ya = Pa.to, pa = re(Ha.x, Ha.y, Ya.x, Ya.y);
745
+ r.moveTo(Ha.x, Ha.y), r.bezierCurveTo(pa.cp1x, pa.cp1y, pa.cp2x, pa.cp2y, Ya.x, Ya.y), r.stroke();
746
+ }
747
+ r.setLineDash([]);
748
+ }
749
+ if (hr) {
750
+ var je = Math.min(hr.startWorld.x, hr.endWorld.x), Oe = Math.min(hr.startWorld.y, hr.endWorld.y), Aa = Math.abs(hr.endWorld.x - hr.startWorld.x), Ea = Math.abs(hr.endWorld.y - hr.startWorld.y);
751
+ r.fillStyle = G ? "rgba(59,130,246,0.08)" : "rgba(59,130,246,0.06)", r.fillRect(je, Oe, Aa, Ea), r.strokeStyle = "#3b82f6", r.lineWidth = 1 / g.zoom, r.setLineDash([]), r.strokeRect(je, Oe, Aa, Ea);
752
+ }
753
+ if (U > 0) {
754
+ var Io = g.zoom > 0.12 && (g.zoom > 0.25 || U < 500), Xe = g.zoom > 0.08 && U < 200, Zo = g.zoom > 0.2 && U < 300;
755
+ if (Xe) {
756
+ r.shadowColor = z.nodeShadow, r.shadowBlur = 6, r.shadowOffsetY = 2, r.fillStyle = z.nodeBg, r.beginPath();
757
+ for (var Gt = 0; Gt < U; Gt++) {
758
+ var rt = V[Gt];
759
+ r.roundRect(h(rt).x, h(rt).y, rt.width || E, rt.height || c, ft);
760
+ }
761
+ r.fill(), r.shadowColor = "transparent", r.shadowBlur = 0, r.shadowOffsetY = 0;
762
+ }
763
+ if (!Xe) {
764
+ r.fillStyle = z.nodeBg, r.beginPath();
765
+ for (var Pt = 0; Pt < U; Pt++) {
766
+ var at = V[Pt];
767
+ r.roundRect(h(at).x, h(at).y, at.width || E, at.height || c, ft);
768
+ }
769
+ r.fill();
770
+ }
771
+ r.strokeStyle = z.nodeBorder, r.lineWidth = 1, r.beginPath();
772
+ for (var It = 0; It < U; It++) {
773
+ var qa = V[It];
774
+ qa.selected || r.roundRect(h(qa).x, h(qa).y, qa.width || E, qa.height || c, ft);
775
+ }
776
+ r.stroke();
777
+ var He = !1;
778
+ r.strokeStyle = z.nodeSelectedBorder, r.lineWidth = 2, r.beginPath();
779
+ for (var Zt = 0; Zt < U; Zt++) {
780
+ var Sa = V[Zt];
781
+ Sa.selected && (He = !0, r.roundRect(h(Sa).x, h(Sa).y, Sa.width || E, Sa.height || c, ft));
782
+ }
783
+ if (He && r.stroke(), Io) {
784
+ r.fillStyle = z.nodeText, r.font = Xo, r.textAlign = "center", r.textBaseline = "middle";
785
+ for (var Jt = 0; Jt < U; Jt++) {
786
+ var Fr = V[Jt];
787
+ if (!(!Fr.data || !Fr.data.label)) {
788
+ var Ye = Fr.width || E, Jo = Fr.height || c;
789
+ r.fillText(Fr.data.label, h(Fr).x + Ye / 2, h(Fr).y + Jo / 2, Ye - 24);
790
+ }
791
+ }
792
+ r.textAlign = "start", r.textBaseline = "alphabetic";
793
+ }
794
+ if (Zo) {
795
+ for (var Kt = [], Qt = 0; Qt < U; Qt++)
796
+ for (var pe = ho(V[Qt]), $t = 0; $t < pe.length; $t++)
797
+ Kt.push(pe[$t]);
798
+ r.fillStyle = z.handleFill, r.beginPath();
799
+ for (var Vt = 0; Vt < Kt.length; Vt++) {
800
+ var tt = Kt[Vt];
801
+ r.moveTo(tt.x + ao, tt.y), r.arc(tt.x, tt.y, ao, 0, 6.2832);
802
+ }
803
+ r.fill(), r.strokeStyle = z.handleBorder, r.lineWidth = 1.5, r.stroke();
804
+ }
805
+ }
806
+ r.restore();
807
+ var Ko = (performance.now() - a).toFixed(1);
808
+ jt++;
809
+ var et = performance.now();
810
+ if (et - oo >= 1e3 && (fo = jt, jt = 0, oo = et), et - vo >= 100) {
811
+ vo = et;
812
+ var Qo = Math.round(-g.x / g.zoom), $o = Math.round(-g.y / g.zoom);
813
+ self.postMessage({
814
+ type: "hud",
815
+ data: {
816
+ wx: Qo,
817
+ wy: $o,
818
+ zoom: g.zoom.toFixed(2),
819
+ renderMs: Ko,
820
+ fps: fo,
821
+ visible: O.length > 0 ? to(Gr, Pr, Hr, Ir).length : 0,
822
+ nodeCount: B.length,
823
+ visibleNodes: U,
824
+ edgeCount: P.length
825
+ }
826
+ });
827
+ }
828
+ }
829
+ }
830
+ `,Bn=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",Gn],{type:"text/javascript;charset=utf-8"});function jr(t){let e;try{if(e=Bn&&(self.URL||self.webkitURL).createObjectURL(Bn),!e)throw"";const n=new Worker(e,{type:"module",name:t==null?void 0:t.name});return n.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),n}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(Gn),{type:"module",name:t==null?void 0:t.name})}}const gn=new WeakMap;function Dr(t,e){if(gn.has(t))return gn.get(t);const n=t.transferControlToOffscreen(),r=new jr;r.onerror=o=>console.error("[infinite-canvas] worker error:",o.message,o),r.postMessage({type:"init",data:{...e,canvas:n}},[n]);const s={worker:r};return gn.set(t,s),s}const Gt=160,Ft=60,Hr=10;function Zn({cards:t=[],nodes:e=[],edges:n=[],onHudUpdate:r,onNodesProcessed:s,onNodesChange:o,onEdgesChange:i,onConnect:l,onNodeClick:d,onNodeDragStart:u,onNodeDrag:x,onNodeDragStop:b,onEdgeClick:N,onEdgeDoubleClick:k,onEdgeMouseEnter:R,onEdgeMouseMove:B,onEdgeMouseLeave:E,onEdgeContextMenu:z,onNodeDoubleClick:W,onNodeMouseEnter:D,onNodeMouseMove:m,onNodeMouseLeave:h,onNodeContextMenu:p,onPaneClick:g,onPaneContextMenu:S,onPaneMouseEnter:I,onPaneMouseMove:T,onPaneMouseLeave:M,onSelectionChange:P,onConnectStart:X,onConnectEnd:H,onInit:lt,onMoveStart:ft,onMove:ut,onMoveEnd:G,onDelete:q,onBeforeDelete:nt,onError:it,isValidConnection:at,dark:ct,gridSize:Ct=40,zoomMin:tt=.1,zoomMax:rt=4,initialCamera:Et={x:0,y:0,zoom:1},fitView:wt=!1,fitViewOptions:pt,nodesDraggable:zt=!0,nodesConnectable:Mt=!0,elementsSelectable:Nt=!0,multiSelectionKeyCode:xt="Shift",selectionOnDrag:Qt=!1,selectionMode:Re="partial",connectionMode:Pt="loose",connectionRadius:Xt=20,connectOnClick:At=!1,snapToGrid:fe=!1,snapGrid:se=[15,15],deleteKeyCode:he=["Delete","Backspace"],panActivationKeyCode:ye=" ",panOnScroll:Fe=!1,panOnScrollMode:ke="free",panOnScrollSpeed:Xe=.5,zoomOnScroll:Ye=!0,zoomOnDoubleClick:Ue=!0,zoomOnPinch:qe=!0,preventScrolling:Ce=!0,translateExtent:Kt,nodeExtent:Vt,defaultEdgeOptions:ge={},autoPanOnNodeDrag:cn=!0,autoPanOnConnect:ln=!0,autoPanSpeed:Yt=5,edgesReconnectable:Pn=!1,elevateNodesOnSelect:un=!1,edgeRouting:ie=!0}={}){const yt=a.useRef(null),Ee=a.useRef(null),Rt=a.useRef(null),ht=a.useRef({...Et}),Jt=a.useRef([...t]),Z=a.useRef([...e]),It=a.useRef([...n]),dn=a.useRef(new Map),ze=a.useRef(!1),Zt=a.useRef(null),[fn,hn]=a.useState(!1),Bt=a.useRef(null),jt=a.useRef(null),xe=a.useRef(null),te=a.useRef(null),_t=a.useRef(!1),pe=a.useRef(null),[Ne,Ge]=a.useState({x:Et.x,y:Et.y,zoom:Et.zoom}),[Ze,ee]=a.useState(null),Ut=a.useMemo(()=>new Set,[]),ae=a.useMemo(()=>new Set,[]),me=a.useRef(!1),O=a.useRef({});O.current={onHudUpdate:r,onNodesProcessed:s,onNodesChange:o,onEdgesChange:i,onConnect:l,onNodeClick:d,onNodeDragStart:u,onNodeDrag:x,onNodeDragStop:b,onEdgeClick:N,onEdgeDoubleClick:k,onEdgeMouseEnter:R,onEdgeMouseMove:B,onEdgeMouseLeave:E,onEdgeContextMenu:z,onNodeDoubleClick:W,onNodeMouseEnter:D,onNodeMouseMove:m,onNodeMouseLeave:h,onNodeContextMenu:p,onPaneClick:g,onPaneContextMenu:S,onPaneMouseEnter:I,onPaneMouseMove:T,onPaneMouseLeave:M,onSelectionChange:P,onConnectStart:X,onConnectEnd:H,onInit:lt,onMoveStart:ft,onMove:ut,onMoveEnd:G,onDelete:q,onBeforeDelete:nt,onError:it,isValidConnection:at};const mt={get current(){return O.current.onNodesChange}},Lt={get current(){return O.current.onEdgesChange}},ne={get current(){return O.current.onConnect}},Ie={get current(){return O.current.onNodeClick}},Se={get current(){return O.current.onNodeDragStart}},Pe={get current(){return O.current.onNodeDrag}},Le={get current(){return O.current.onNodeDragStop}},re={get current(){return O.current.onEdgeClick}},$e={get current(){return O.current.onPaneClick}},ce={get current(){return O.current.onSelectionChange}},le={get current(){return O.current.onHudUpdate}},ue={get current(){return O.current.onNodesProcessed}};a.useEffect(()=>{const c=f=>{f.key===xt&&(_t.current=!0),f.key===ye&&(me.current=!0)},v=f=>{f.key===xt&&(_t.current=!1),f.key===ye&&(me.current=!1)};return window.addEventListener("keydown",c),window.addEventListener("keyup",v),()=>{window.removeEventListener("keydown",c),window.removeEventListener("keyup",v)}},[xt,ye]);const qt=a.useCallback(()=>{var w;const c=Z.current.filter(L=>L.selected),v=It.current.filter(L=>L.selected),f={nodes:c,edges:v};(w=ce.current)==null||w.call(ce,f);for(const L of ae)L(f)},[ae]);a.useEffect(()=>{var c;Jt.current=[...t],(c=Rt.current)==null||c.postMessage({type:"cards",data:{cards:[...t]}})},[t]);const ve=a.useCallback(c=>{const v={};for(const f of c)v[f.id]=f;return c.map(f=>{if(!f.parentId)return f;const w=v[f.parentId];if(!w)return f;let L=f.position.x,$=f.position.y,y=w;for(;y;)L+=y.position.x,$+=y.position.y,y=y.parentId?v[y.parentId]:null;return{...f,_absolutePosition:{x:L,y:$}}})},[]),Ot=a.useRef([]),Q=a.useCallback(c=>{const v=dn.current;if(!v||v.size===0)return c;const f={};for(const[,w]of v)f[w.nodeId]||(f[w.nodeId]=[]),f[w.nodeId].push({id:w.id,type:w.type,position:w.position,x:w.x,y:w.y});return c.map(w=>{const L=f[w.id];return L&&L.length>0?{...w,handles:L}:w})},[]),Ht=a.useCallback(()=>{var v;if(Bt.current)return;const c=Q(Ot.current);(v=Rt.current)==null||v.postMessage({type:"nodes",data:{nodes:c}})},[Q]);a.useEffect(()=>{var f;if(Bt.current){const w=Bt.current.id,L=new Set([w,...Bt.current.selectedStarts.map(y=>y.id)]),$={};for(const y of Z.current)L.has(y.id)&&($[y.id]={...y.position});Z.current=[...e];for(const y of Z.current)$[y.id]&&(y.position=$[y.id]);Ot.current=ve(Z.current);return}Z.current=[...e];const c=ve(e);Ot.current=c;const v=Q(c);(f=Rt.current)==null||f.postMessage({type:"nodes",data:{nodes:v}})},[e,ve,Q]),a.useEffect(()=>{var c;It.current=[...n],(c=Rt.current)==null||c.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const ot=a.useCallback((c,v)=>{const f=yt.current;if(!f)return{x:0,y:0};const w=f.getBoundingClientRect(),L=ht.current;return{x:(c-w.left-L.x)/L.zoom,y:(v-w.top-L.y)/L.zoom}},[]),St=a.useCallback((c,v)=>{const f=Ot.current.length>0?Ot.current:Z.current;let w=null;for(let L=f.length-1;L>=0;L--){const $=f[L];if($.hidden)continue;const y=$._absolutePosition||$.position,A=$.width||Gt,j=$.height||Ft;if(c>=y.x&&c<=y.x+A&&v>=y.y&&v<=y.y+j){if($.type==="group"){w||(w=$);continue}return $}}return w},[]),de=a.useCallback((c,v)=>{const f=v.width||Gt,w=v.height||Ft;if(c.x!==void 0&&c.y!==void 0)return{x:v.position.x+c.x,y:v.position.y+c.y};switch(c.position||(c.type==="source"?"right":"left")){case"top":return{x:v.position.x+f/2,y:v.position.y};case"bottom":return{x:v.position.x+f/2,y:v.position.y+w};case"left":return{x:v.position.x,y:v.position.y+w/2};case"right":return{x:v.position.x+f,y:v.position.y+w/2};default:return{x:v.position.x+f,y:v.position.y+w/2}}},[]),be=a.useCallback(c=>{const v=c.width||Gt,f=c.height||Ft;return c.handles&&c.handles.length>0?c.handles.map(w=>{const L=de(w,c);return{id:w.id||null,type:w.type,x:L.x,y:L.y}}):[{id:null,type:"target",x:c.position.x,y:c.position.y+f/2},{id:null,type:"source",x:c.position.x+v,y:c.position.y+f/2}]},[de]),Oe=a.useCallback((c,v)=>{const f=Z.current,w=ht.current,L=Math.max(Hr,Xt)/w.zoom;for(let $=f.length-1;$>=0;$--){const y=f[$];if(y.hidden)continue;const A=be(y);for(const j of A)if(Math.abs(c-j.x)<L&&Math.abs(v-j.y)<L)return{nodeId:y.id,handleId:j.id,type:j.type,x:j.x,y:j.y}}return null},[be]),oe=a.useCallback((c,v)=>{const w=8/ht.current.zoom;for(let L=It.current.length-1;L>=0;L--){const $=It.current[L],y=Z.current.find(vt=>vt.id===$.source),A=Z.current.find(vt=>vt.id===$.target);if(!y||!A)continue;const j=y.width||Gt,Y=y.height||Ft,_=A.height||Ft,K=y.position.x+j,st=y.position.y+Y/2,U=A.position.x,et=A.position.y+_/2;if(Ar(c,v,K,st,U,et)<w)return $}return null},[]);a.useEffect(()=>{const c=Ee.current,v=yt.current;if(!c||!v)return;const f=v.getBoundingClientRect(),w=ct!==void 0?ct:matchMedia("(prefers-color-scheme: dark)").matches,L=ve(Z.current);Ot.current=L;const $=Q(L),{worker:y}=Dr(c,{width:f.width,height:f.height,camera:ht.current,cards:Jt.current,nodes:$,edges:It.current,dark:w,gridSize:Ct,edgeRouting:ie});y.onmessage=_=>{var K,st;_.data.type==="hud"&&((K=le.current)==null||K.call(le,_.data.data)),_.data.type==="ready"&&hn(!0),_.data.type==="nodesProcessed"&&((st=ue.current)==null||st.call(ue,_.data.data))},Rt.current=y;const A=new ResizeObserver(_=>{const{width:K,height:st}=_[0].contentRect;y.postMessage({type:"resize",data:{width:K,height:st}})});A.observe(v);let j,Y;return ct===void 0&&(j=matchMedia("(prefers-color-scheme: dark)"),Y=_=>y.postMessage({type:"theme",data:{dark:_.matches}}),j.addEventListener("change",Y)),()=>{A.disconnect(),j&&Y&&j.removeEventListener("change",Y),Rt.current=null}},[]),a.useEffect(()=>{var c;ct!==void 0&&((c=Rt.current)==null||c.postMessage({type:"theme",data:{dark:ct}}))},[ct]),a.useEffect(()=>{var c;(c=Rt.current)==null||c.postMessage({type:"edgeRouting",data:{enabled:ie}})},[ie]);const Ln=a.useRef(0),kt=a.useCallback((c=null)=>{var w,L,$;const v=ht.current;if(Kt){const y=yt.current;if(y){const A=y.getBoundingClientRect(),j=-Kt[1][0]*v.zoom+A.width,Y=-Kt[1][1]*v.zoom+A.height,_=-Kt[0][0]*v.zoom,K=-Kt[0][1]*v.zoom;v.x=Math.min(_,Math.max(j,v.x)),v.y=Math.min(K,Math.max(Y,v.y))}}(w=Rt.current)==null||w.postMessage({type:"camera",data:{camera:{...v}}});const f={x:v.x,y:v.y,zoom:v.zoom};($=(L=O.current).onMove)==null||$.call(L,c,f);for(const y of Ut)y(f);cancelAnimationFrame(Ln.current),Ln.current=requestAnimationFrame(()=>{Ge({x:v.x,y:v.y,zoom:v.zoom})})},[Ut,Kt]),we=a.useCallback(()=>{var f,w;const c=jt.current,v=xe.current;c&&v?((f=Rt.current)==null||f.postMessage({type:"connecting",data:{from:c.startPos,to:v,_routedPoints:null}}),ee({source:c.sourceId,sourceHandle:c.sourceHandle,target:null,targetHandle:null})):((w=Rt.current)==null||w.postMessage({type:"connecting",data:null}),ee(null))},[]),Me=a.useCallback(()=>{var v,f;const c=te.current;c?(v=Rt.current)==null||v.postMessage({type:"selectionBox",data:c}):(f=Rt.current)==null||f.postMessage({type:"selectionBox",data:null})},[]),hr=a.useCallback(c=>{var L,$,y,A,j,Y,_,K,st,U,et,gt,vt,$t,Dt,Tt;const v=Z.current.length>0,f=ot(c.clientX,c.clientY),w=_t.current;if(v&&Mt){const F=Oe(f.x,f.y);if(At&&pe.current&&F){const V=pe.current;if(F.nodeId!==V.nodeId){const Wt=V.handleType==="target"?{source:F.nodeId,target:V.nodeId,sourceHandle:F.handleId||null,targetHandle:V.handleId}:{source:V.nodeId,target:F.nodeId,sourceHandle:V.handleId,targetHandle:F.handleId||null};(O.current.isValidConnection?O.current.isValidConnection(Wt):!0)&&((L=ne.current)==null||L.call(ne,{...Wt,...ge}))}pe.current=null;return}if(Pt==="strict"?F&&F.type==="source":F!=null){if(At){pe.current={nodeId:F.nodeId,handleId:F.handleId||null,handleType:F.type},(y=($=O.current).onConnectStart)==null||y.call($,c,{nodeId:F.nodeId,handleId:F.handleId,handleType:F.type});return}jt.current={sourceId:F.nodeId,sourceHandle:F.handleId||null,sourceType:F.type,startPos:{x:F.x,y:F.y}},xe.current={x:f.x,y:f.y},(A=yt.current)==null||A.setPointerCapture(c.pointerId),(Y=(j=O.current).onConnectStart)==null||Y.call(j,c,{nodeId:F.nodeId,handleId:F.handleId,handleType:F.type}),we();return}}if(v){const F=St(f.x,f.y);if(F){if(mt.current&&Nt){const bt=[];if(w)bt.push({id:F.id,type:"select",selected:!F.selected});else if(!F.selected){for(const V of Z.current)V.id===F.id?bt.push({id:V.id,type:"select",selected:!0}):V.selected&&bt.push({id:V.id,type:"select",selected:!1});if(Lt.current){const V=It.current.filter(J=>J.selected).map(J=>({id:J.id,type:"select",selected:!1}));V.length&&Lt.current(V)}}if(bt.length){if(mt.current(bt),un&&!w){const V=Z.current.findIndex(J=>J.id===F.id);V>=0&&V<Z.current.length-1&&mt.current([{id:F.id,type:"remove"},{type:"add",item:{...Z.current[V],selected:!0}}])}qt()}}if((_=Ie.current)==null||_.call(Ie,c,F),zt){const bt=w&&F.selected;let V=null;if(F.parentId&&F.extent==="parent"){const J=Z.current.find(Wt=>Wt.id===F.parentId);if(J){const Wt=J.width||Gt,Te=J.height||Ft,Qe=F.width||((K=F.measured)==null?void 0:K.width)||Gt,Be=F.height||((st=F.measured)==null?void 0:st.height)||Ft;V={minX:0,minY:0,maxX:Wt-Qe,maxY:Te-Be}}}if(Bt.current={id:F.id,startPos:{...F.position},startMouse:{x:f.x,y:f.y},parentClamp:V,parentId:F.parentId||null,selectedStarts:bt?Z.current.filter(J=>J.selected&&J.id!==F.id).map(J=>{var Te,Qe;let Wt=null;if(J.parentId&&J.extent==="parent"){const Be=Z.current.find(yn=>yn.id===J.parentId);if(Be){const yn=Be.width||Gt,Rr=Be.height||Ft,kr=J.width||((Te=J.measured)==null?void 0:Te.width)||Gt,Cr=J.height||((Qe=J.measured)==null?void 0:Qe.height)||Ft;Wt={minX:0,minY:0,maxX:yn-kr,maxY:Rr-Cr}}}return{id:J.id,startPos:{...J.position},parentClamp:Wt,parentId:J.parentId||null}}):[]},(U=yt.current)==null||U.setPointerCapture(c.pointerId),(et=Se.current)==null||et.call(Se,c,F),mt.current){const J=[{id:F.id,type:"position",dragging:!0}];for(const Wt of Bt.current.selectedStarts)J.push({id:Wt.id,type:"position",dragging:!0});mt.current(J)}}return}}if(It.current.length>0&&Nt){const F=oe(f.x,f.y);if(F){if(Lt.current){const bt=[];if(w)bt.push({id:F.id,type:"select",selected:!F.selected});else{for(const V of It.current)V.id===F.id?bt.push({id:V.id,type:"select",selected:!0}):V.selected&&bt.push({id:V.id,type:"select",selected:!1});if(mt.current){const V=Z.current.filter(J=>J.selected).map(J=>({id:J.id,type:"select",selected:!1}));V.length&&mt.current(V)}}bt.length&&(Lt.current(bt),qt())}(gt=re.current)==null||gt.call(re,c,F);return}}if(!w){const F=Z.current.filter(V=>V.selected).map(V=>({id:V.id,type:"select",selected:!1})),bt=It.current.filter(V=>V.selected).map(V=>({id:V.id,type:"select",selected:!1}));F.length&&mt.current&&mt.current(F),bt.length&&Lt.current&&Lt.current(bt),(F.length||bt.length)&&qt()}if((vt=$e.current)==null||vt.call($e,c),Qt||w){te.current={startWorld:{...f},endWorld:{...f}},($t=yt.current)==null||$t.setPointerCapture(c.pointerId),Me();return}ze.current=!0,Zt.current={x:c.clientX,y:c.clientY},(Dt=yt.current)==null||Dt.classList.add("dragging"),(Tt=yt.current)==null||Tt.setPointerCapture(c.pointerId)},[ot,St,Oe,oe,zt,Mt,Nt,Qt,we,Me,qt]),yr=a.useCallback(c=>{var f,w;if(jt.current){if(xe.current=ot(c.clientX,c.clientY),we(),ln){const L=yt.current;if(L){const $=L.getBoundingClientRect(),y=40,A=c.clientX-$.left,j=c.clientY-$.top;let Y=0,_=0;A<y?Y=Yt:A>$.width-y&&(Y=-Yt),j<y?_=Yt:j>$.height-y&&(_=-Yt),(Y||_)&&(ht.current.x+=Y,ht.current.y+=_,kt(c))}}return}if(te.current){te.current.endWorld=ot(c.clientX,c.clientY),Me();const L=te.current,$=Math.min(L.startWorld.x,L.endWorld.x),y=Math.min(L.startWorld.y,L.endWorld.y),A=Math.max(L.startWorld.x,L.endWorld.x),j=Math.max(L.startWorld.y,L.endWorld.y);if(mt.current){const Y=[];for(const _ of Z.current){if(_.hidden)continue;const K=_.width||Gt,st=_.height||Ft,U=Re==="full"?_.position.x>=$&&_.position.x+K<=A&&_.position.y>=y&&_.position.y+st<=j:_.position.x+K>$&&_.position.x<A&&_.position.y+st>y&&_.position.y<j;U!==!!_.selected&&Y.push({id:_.id,type:"select",selected:U})}Y.length&&mt.current(Y)}return}if(Bt.current){const L=ot(c.clientX,c.clientY),$=Bt.current,y=L.x-$.startMouse.x,A=L.y-$.startMouse.y;let j={x:$.startPos.x+y,y:$.startPos.y+A};if(fe&&(j=vn(j,se)),Vt&&(j=bn(j,Vt)),$.parentClamp){const U=$.parentClamp;j={x:Math.max(U.minX,Math.min(j.x,U.maxX)),y:Math.max(U.minY,Math.min(j.y,U.maxY))}}const Y=[{id:$.id,position:j}];for(const U of $.selectedStarts){let et={x:U.startPos.x+y,y:U.startPos.y+A};if(fe&&(et=vn(et,se)),Vt&&(et=bn(et,Vt)),U.parentClamp){const gt=U.parentClamp;et={x:Math.max(gt.minX,Math.min(et.x,gt.maxX)),y:Math.max(gt.minY,Math.min(et.y,gt.maxY))}}Y.push({id:U.id,position:et})}const _=[];for(const U of Y){const et=Z.current.find(gt=>gt.id===U.id);if(et){et.position=U.position,et.dragging=!0;let gt=U.position;if(et.parentId){let vt=Z.current.find(Tt=>Tt.id===et.parentId),$t=U.position.x,Dt=U.position.y;for(;vt;)$t+=vt.position.x,Dt+=vt.position.y,vt=vt.parentId?Z.current.find(Tt=>Tt.id===vt.parentId):null;gt={x:$t,y:Dt}}_.push({id:U.id,position:U.position,_absolutePosition:gt,width:et.width,height:et.height,dragging:!0,selected:et.selected})}}const K=new Set(Y.map(U=>U.id));for(const U of Z.current)if(U.parentId&&K.has(U.parentId)&&!K.has(U.id)){let et=Z.current.find($t=>$t.id===U.parentId),gt=U.position.x,vt=U.position.y;for(;et;)gt+=et.position.x,vt+=et.position.y,et=et.parentId?Z.current.find($t=>$t.id===et.parentId):null;_.push({id:U.id,position:U.position,_absolutePosition:{x:gt,y:vt},width:U.width,height:U.height,dragging:!1,selected:U.selected})}if((f=Rt.current)==null||f.postMessage({type:"nodePositions",data:{updates:_}}),cn){const U=yt.current;if(U){const et=U.getBoundingClientRect(),gt=40,vt=c.clientX-et.left,$t=c.clientY-et.top;let Dt=0,Tt=0;vt<gt?Dt=Yt:vt>et.width-gt&&(Dt=-Yt),$t<gt?Tt=Yt:$t>et.height-gt&&(Tt=-Yt),(Dt||Tt)&&(ht.current.x+=Dt,ht.current.y+=Tt,kt(c))}}const st=Z.current.find(U=>U.id===$.id);st&&((w=Pe.current)==null||w.call(Pe,c,st));return}if(!ze.current)return;const v=ht.current;v.x+=c.clientX-Zt.current.x,v.y+=c.clientY-Zt.current.y,Zt.current={x:c.clientX,y:c.clientY},kt()},[kt,ot,we,Me]),gr=a.useCallback(c=>{var v,f,w,L,$;if(jt.current){const y=ot(c.clientX,c.clientY),A=Oe(y.x,y.y);if(A&&A.nodeId!==jt.current.sourceId&&(Pt==="loose"||A.type==="target")){const _=jt.current.sourceType==="target"?{source:A.nodeId,target:jt.current.sourceId,sourceHandle:A.handleId||null,targetHandle:jt.current.sourceHandle}:{source:jt.current.sourceId,target:A.nodeId,sourceHandle:jt.current.sourceHandle,targetHandle:A.handleId||null};(O.current.isValidConnection?O.current.isValidConnection(_):!0)&&((v=ne.current)==null||v.call(ne,{..._,...ge}))}(w=(f=O.current).onConnectEnd)==null||w.call(f,c.nativeEvent||c),jt.current=null,xe.current=null,we();return}if(te.current){te.current=null,Me(),qt();return}if(Bt.current){const y=Bt.current;if(mt.current){const j=Z.current.find(_=>_.id===y.id),Y=[{id:y.id,type:"position",position:j?{...j.position}:void 0,dragging:!1}];for(const _ of y.selectedStarts){const K=Z.current.find(st=>st.id===_.id);Y.push({id:_.id,type:"position",position:K?{...K.position}:void 0,dragging:!1})}mt.current(Y)}requestAnimationFrame(()=>{Bt.current=null});const A=Z.current.find(j=>j.id===y.id);A&&((L=Le.current)==null||L.call(Le,c,A));return}ze.current=!1,($=yt.current)==null||$.classList.remove("dragging")},[ot,Oe,we,Me,qt]);a.useEffect(()=>{const c=yt.current;if(!c)return;const v=f=>{Ce&&f.preventDefault();const w=ht.current;if(Fe||me.current){const j=Xe;ke==="horizontal"?w.x-=f.deltaY*j:(ke==="vertical"||(w.x-=f.deltaX*j),w.y-=f.deltaY*j),kt(f);return}if(!Ye)return;const L=f.deltaY>0?.92:1.08,$=c.getBoundingClientRect(),y=f.clientX-$.left,A=f.clientY-$.top;w.x=y-(y-w.x)*L,w.y=A-(A-w.y)*L,w.zoom=Math.min(rt,Math.max(tt,w.zoom*L)),kt(f)};return c.addEventListener("wheel",v,{passive:!Ce}),()=>c.removeEventListener("wheel",v)},[kt,tt,rt,Fe,ke,Xe,Ye,Ce]),a.useEffect(()=>{if(!qe)return;const c=yt.current;if(!c)return;let v=0,f=null;const w=y=>{if(y.touches.length===2){const A=y.touches[0].clientX-y.touches[1].clientX,j=y.touches[0].clientY-y.touches[1].clientY;v=Math.hypot(A,j);const Y=c.getBoundingClientRect();f={x:(y.touches[0].clientX+y.touches[1].clientX)/2-Y.left,y:(y.touches[0].clientY+y.touches[1].clientY)/2-Y.top},y.preventDefault()}},L=y=>{if(y.touches.length===2&&v>0){y.preventDefault();const A=y.touches[0].clientX-y.touches[1].clientX,j=y.touches[0].clientY-y.touches[1].clientY,Y=Math.hypot(A,j),_=Y/v;v=Y;const K=ht.current,st=f.x,U=f.y;K.x=st-(st-K.x)*_,K.y=U-(U-K.y)*_,K.zoom=Math.min(rt,Math.max(tt,K.zoom*_)),kt(y)}},$=()=>{v=0,f=null};return c.addEventListener("touchstart",w,{passive:!1}),c.addEventListener("touchmove",L,{passive:!1}),c.addEventListener("touchend",$),()=>{c.removeEventListener("touchstart",w),c.removeEventListener("touchmove",L),c.removeEventListener("touchend",$)}},[qe,kt,tt,rt]),a.useEffect(()=>{if(!Ue)return;const c=yt.current;if(!c)return;const v=f=>{var _,K,st,U;const w=ot(f.clientX,f.clientY);if(St(w.x,w.y)){(K=(_=O.current).onNodeDoubleClick)==null||K.call(_,f,St(w.x,w.y));return}const L=oe(w.x,w.y);if(L){(U=(st=O.current).onEdgeDoubleClick)==null||U.call(st,f,L);return}const $=1.5,y=c.getBoundingClientRect(),A=f.clientX-y.left,j=f.clientY-y.top,Y=ht.current;Y.x=A-(A-Y.x)*$,Y.y=j-(j-Y.y)*$,Y.zoom=Math.min(rt,Math.max(tt,Y.zoom*$)),kt(f)};return c.addEventListener("dblclick",v),()=>c.removeEventListener("dblclick",v)},[Ue,kt,tt,rt,ot,St,oe]),a.useEffect(()=>{const c=yt.current;if(!c)return;const v=f=>{var y,A,j,Y,_,K;const w=ot(f.clientX,f.clientY),L=St(w.x,w.y);if(L){(A=(y=O.current).onNodeContextMenu)==null||A.call(y,f,L);return}const $=oe(w.x,w.y);if($){(Y=(j=O.current).onEdgeContextMenu)==null||Y.call(j,f,$);return}(K=(_=O.current).onPaneContextMenu)==null||K.call(_,f)};return c.addEventListener("contextmenu",v),()=>c.removeEventListener("contextmenu",v)},[ot,St,oe]),a.useEffect(()=>{const c=yt.current;if(!c)return;let v=null,f=null;const w=y=>{var Y,_,K,st,U,et,gt,vt,$t,Dt,Tt,F,bt,V;(_=(Y=O.current).onPaneMouseMove)==null||_.call(Y,y);const A=ot(y.clientX,y.clientY),j=St(A.x,A.y);if(j!==v&&(v&&((st=(K=O.current).onNodeMouseLeave)==null||st.call(K,y,v)),j&&((et=(U=O.current).onNodeMouseEnter)==null||et.call(U,y,j)),v=j),j&&((vt=(gt=O.current).onNodeMouseMove)==null||vt.call(gt,y,j)),!j){const J=oe(A.x,A.y);J!==f&&(f&&((Dt=($t=O.current).onEdgeMouseLeave)==null||Dt.call($t,y,f)),J&&((F=(Tt=O.current).onEdgeMouseEnter)==null||F.call(Tt,y,J)),f=J),J&&((V=(bt=O.current).onEdgeMouseMove)==null||V.call(bt,y,J))}},L=y=>{var A,j;return(j=(A=O.current).onPaneMouseEnter)==null?void 0:j.call(A,y)},$=y=>{var A,j,Y,_,K,st;(j=(A=O.current).onPaneMouseLeave)==null||j.call(A,y),v&&((_=(Y=O.current).onNodeMouseLeave)==null||_.call(Y,y,v),v=null),f&&((st=(K=O.current).onEdgeMouseLeave)==null||st.call(K,y,f),f=null)};return c.addEventListener("mousemove",w),c.addEventListener("mouseenter",L),c.addEventListener("mouseleave",$),()=>{c.removeEventListener("mousemove",w),c.removeEventListener("mouseenter",L),c.removeEventListener("mouseleave",$)}},[ot,St,oe]),a.useEffect(()=>{const c=Array.isArray(he)?he:[he],v=async f=>{var w,L;if(c.includes(f.key)){if(f.target.tagName==="INPUT"||f.target.tagName==="TEXTAREA"||f.target.isContentEditable)return;const $=Z.current.filter(j=>j.selected),y=It.current.filter(j=>j.selected);if(!$.length&&!y.length||O.current.onBeforeDelete&&!await O.current.onBeforeDelete({nodes:$,edges:y}))return;const A=new Set($.map(j=>j.id));if($.length&&mt.current&&(mt.current($.map(j=>({id:j.id,type:"remove"}))),Lt.current)){const j=It.current.filter(Y=>A.has(Y.source)||A.has(Y.target));j.length&&Lt.current(j.map(Y=>({id:Y.id,type:"remove"})))}y.length&&Lt.current&&Lt.current(y.map(j=>({id:j.id,type:"remove"}))),(L=(w=O.current).onDelete)==null||L.call(w,{nodes:$,edges:y})}if((f.ctrlKey||f.metaKey)&&f.key==="a"){if(f.target.tagName==="INPUT"||f.target.tagName==="TEXTAREA")return;if(f.preventDefault(),mt.current){const $=Z.current.filter(y=>!y.selected).map(y=>({id:y.id,type:"select",selected:!0}));$.length&&mt.current($)}if(Lt.current){const $=It.current.filter(y=>!y.selected).map(y=>({id:y.id,type:"select",selected:!0}));$.length&&Lt.current($)}}};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[he]);const $n=a.useRef(!1);a.useEffect(()=>{var c,v;if(!$n.current&&Rt.current){if($n.current=!0,wt&&Z.current.length>0){const f=yt.current;if(f){const w=f.getBoundingClientRect(),L=(pt==null?void 0:pt.padding)??.1,$=Ve(Z.current),y=Je($,w.width,w.height,L);pt!=null&&pt.maxZoom&&(y.zoom=Math.min(y.zoom,pt.maxZoom)),pt!=null&&pt.minZoom&&(y.zoom=Math.max(y.zoom,pt.minZoom)),ht.current=y,kt()}}(v=(c=O.current).onInit)==null||v.call(c,{getNodes:()=>[...Z.current],getEdges:()=>[...It.current],getViewport:()=>({...ht.current}),fitView:(f={})=>{const w=yt.current;if(!w||!Z.current.length)return;const L=w.getBoundingClientRect(),$=Ve(Z.current),y=Je($,L.width,L.height,f.padding??.1);ht.current=y,kt()}})}});const xr=a.useCallback(()=>{ht.current={...Et},kt()},[kt,Et]),pr=a.useCallback(c=>{var v;if(c)Jt.current.push(c);else{const f=ht.current,w=yt.current;if(!w)return;const L=w.getBoundingClientRect(),$=Math.round(-f.x/f.zoom+L.width/2/f.zoom),y=Math.round(-f.y/f.zoom+L.height/2/f.zoom);Jt.current.push({x:$-80,y:y-45,w:160,h:90,title:"Note "+(Jt.current.length+1),body:"Added at viewport center"})}(v=Rt.current)==null||v.postMessage({type:"cards",data:{cards:[...Jt.current]}})},[]),mr=a.useCallback(c=>{if(c.id||(c.id="node-"+Date.now()),!c.position){const v=ht.current,f=yt.current;if(!f)return;const w=f.getBoundingClientRect();c.position={x:Math.round(-v.x/v.zoom+w.width/2/v.zoom)-Gt/2,y:Math.round(-v.y/v.zoom+w.height/2/v.zoom)-Ft/2}}c.data||(c.data={label:c.id}),mt.current&&mt.current([{type:"add",item:c}])},[]),vr=a.useCallback(()=>({...ht.current}),[]),br=a.useCallback(c=>{ht.current={...ht.current,...c},kt()},[kt]),wr=a.useCallback(c=>ot(c.x,c.y),[ot]),Tn=n,Mr=a.useMemo(()=>({wrapRef:yt,canvasRef:Ee,workerRef:Rt,cameraRef:ht,nodesRef:Z,edgesRef:It,handleRegistryRef:dn,syncNodesToWorker:Ht,onNodesChangeRef:mt,onEdgesChangeRef:Lt,sendCamera:kt,screenToWorld:ot,viewportListeners:Ut,selectionListeners:ae,zoomMin:tt,zoomMax:rt,snapToGrid:fe,snapGrid:se,nodeExtent:Vt,defaultEdgeOptions:ge,edgeRouting:ie,resolvedNodesRef:Ot,get nodes(){return e},get edges(){return n},get routedEdges(){return Tn},get viewport(){return Ne},get connection(){return Ze}}),[e,n,Tn,Ne,Ze,kt,ot,Ht,Ut,ae,tt,rt,fe,se,Vt,ge,ie]);return{wrapRef:yt,canvasRef:Ee,canvasReady:fn,onPointerDown:hr,onPointerMove:yr,onPointerUp:gr,resetView:xr,addCard:pr,addNode:mr,getCamera:vr,setCamera:br,screenToFlowPosition:wr,store:Mr}}function Ar(t,e,n,r,s,o){const i=s-n,l=o-r,d=i*i+l*l;if(d===0)return Math.hypot(t-n,e-r);let u=((t-n)*i+(e-r)*l)/d;return u=Math.max(0,Math.min(1,u)),Math.hypot(t-(n+u*i),e-(r+u*l))}const On=a.createContext(null);function dt(){const t=a.useContext(On);if(!t)throw new Error("useCanvasStore must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");return t}const _e=a.createContext(null);function _r(){return a.useContext(_e)}function Wr({node:t,nodeType:e}){var b,N,k;const n=dt(),r=a.useRef(null),s=t._absolutePosition||t.position,o=a.useRef(null);a.useEffect(()=>{const R=r.current;if(!R)return;const B=new ResizeObserver(E=>{var D,m,h,p;const{width:z,height:W}=E[0].contentRect;if(z>0&&W>0){const g=n.nodesRef.current.find(T=>T.id===t.id),S=(g==null?void 0:g.width)||((D=g==null?void 0:g.measured)==null?void 0:D.width),I=(g==null?void 0:g.height)||((m=g==null?void 0:g.measured)==null?void 0:m.height);(Math.abs((S||0)-z)>1||Math.abs((I||0)-W)>1)&&((p=(h=n.onNodesChangeRef).current)==null||p.call(h,[{id:t.id,type:"dimensions",dimensions:{width:z,height:W},setAttributes:!0}]))}});return B.observe(R),()=>B.disconnect()},[t.id,n]);const i=a.useCallback(R=>{var T,M;if(R.stopPropagation(),n.onNodesChangeRef.current){const P=[];if(R.shiftKey)P.push({id:t.id,type:"select",selected:!t.selected});else for(const H of n.nodesRef.current)H.id===t.id&&!H.selected?P.push({id:H.id,type:"select",selected:!0}):H.id!==t.id&&H.selected&&P.push({id:H.id,type:"select",selected:!1});P.length&&n.onNodesChangeRef.current(P)}const B=n.cameraRef.current,E=n.wrapRef.current;if(!E)return;const z=E.getBoundingClientRect(),W=(R.clientX-z.left-B.x)/B.zoom,D=(R.clientY-z.top-B.y)/B.zoom,h=R.shiftKey&&t.selected?n.nodesRef.current.filter(P=>P.selected&&P.id!==t.id).map(P=>({id:P.id,startPos:{...P.position}})):[];o.current={startPos:{...t.position},startMouse:{x:W,y:D},selectedStarts:h};const p=[{id:t.id,type:"position",dragging:!0}];for(const P of h)p.push({id:P.id,type:"position",dragging:!0});(M=(T=n.onNodesChangeRef).current)==null||M.call(T,p);const g=r.current;g&&g.setPointerCapture(R.pointerId);const S=P=>{var it,at,ct,Ct;if(!o.current)return;const X=n.cameraRef.current,H=E.getBoundingClientRect(),lt=(P.clientX-H.left-X.x)/X.zoom,ft=(P.clientY-H.top-X.y)/X.zoom,ut=lt-o.current.startMouse.x,G=ft-o.current.startMouse.y;let q={x:o.current.startPos.x+ut,y:o.current.startPos.y+G};if(n.snapToGrid&&n.snapGrid&&(q={x:n.snapGrid[0]*Math.round(q.x/n.snapGrid[0]),y:n.snapGrid[1]*Math.round(q.y/n.snapGrid[1])}),t.parentId&&t.extent==="parent"){const tt=n.nodesRef.current.find(rt=>rt.id===t.parentId);if(tt){const rt=tt.width||160,Et=tt.height||60,wt=t.width||((it=t.measured)==null?void 0:it.width)||160,pt=t.height||((at=t.measured)==null?void 0:at.height)||60;q={x:Math.max(0,Math.min(q.x,rt-wt)),y:Math.max(0,Math.min(q.y,Et-pt))}}}const nt=[{id:t.id,type:"position",position:q,dragging:!0}];for(const tt of o.current.selectedStarts){let rt={x:tt.startPos.x+ut,y:tt.startPos.y+G};n.snapToGrid&&n.snapGrid&&(rt={x:n.snapGrid[0]*Math.round(rt.x/n.snapGrid[0]),y:n.snapGrid[1]*Math.round(rt.y/n.snapGrid[1])}),nt.push({id:tt.id,type:"position",position:rt,dragging:!0})}(Ct=(ct=n.onNodesChangeRef).current)==null||Ct.call(ct,nt)},I=P=>{var H,lt;if(!o.current)return;const X=[{id:t.id,type:"position",dragging:!1}];for(const ft of o.current.selectedStarts)X.push({id:ft.id,type:"position",dragging:!1});(lt=(H=n.onNodesChangeRef).current)==null||lt.call(H,X),o.current=null,g&&g.releasePointerCapture(P.pointerId),g==null||g.removeEventListener("pointermove",S),g==null||g.removeEventListener("pointerup",I)};g==null||g.addEventListener("pointermove",S),g==null||g.addEventListener("pointerup",I)},[t,n]),l=a.useCallback(R=>{var m,h,p,g,S,I;if(!t.selected)return;const B=R.shiftKey?10:1;let E=0,z=0;switch(R.key){case"ArrowUp":z=-B;break;case"ArrowDown":z=B;break;case"ArrowLeft":E=-B;break;case"ArrowRight":E=B;break;case"Escape":(h=(m=n.onNodesChangeRef).current)==null||h.call(m,[{id:t.id,type:"select",selected:!1}]);return;case"Delete":case"Backspace":t.deletable!==!1&&((g=(p=n.onNodesChangeRef).current)==null||g.call(p,[{id:t.id,type:"remove"}]));return;default:return}R.preventDefault();const W={x:t.position.x+E,y:t.position.y+z},D=[{id:t.id,type:"position",position:W}];for(const T of n.nodesRef.current)T.selected&&T.id!==t.id&&D.push({id:T.id,type:"position",position:{x:T.position.x+E,y:T.position.y+z}});(I=(S=n.onNodesChangeRef).current)==null||I.call(S,D)},[t,n]),d=t.width||((b=t.measured)==null?void 0:b.width),u=t.height||((N=t.measured)==null?void 0:N.height),x=!!(d&&u);return C.jsx(_e.Provider,{value:t.id,children:C.jsx("div",{ref:r,className:`ric-node-wrapper ${t.selected?"selected":""} ${t.dragging?"dragging":""}`,style:{position:"absolute",left:s.x,top:s.y,zIndex:t.type==="group"?0:t.zIndex||1,pointerEvents:t.type==="group"?"none":"all",cursor:t.dragging?"grabbing":"grab",visibility:x?"visible":"hidden",userSelect:"none",outline:"none"},"data-nodeid":t.id,tabIndex:t.selectable!==!1?0:void 0,role:"button","aria-label":`Node ${((k=t.data)==null?void 0:k.label)||t.id}`,"aria-selected":!!t.selected,onPointerDown:i,onKeyDown:l,children:C.jsx(e,{id:t.id,data:t.data,type:t.type,selected:!!t.selected,dragging:!!t.dragging,draggable:t.draggable!==!1,selectable:t.selectable!==!1,deletable:t.deletable!==!1,isConnectable:t.connectable!==!1,zIndex:t.zIndex||0,positionAbsoluteX:s.x,positionAbsoluteY:s.y,width:d,height:u,sourcePosition:t.sourcePosition,targetPosition:t.targetPosition,parentId:t.parentId,dragHandle:t.dragHandle})})})}const Fr=a.memo(Wr),Qn=160,Kn=60;function jn(t,e,n,r){var l,d;const s=t.width||((l=t.measured)==null?void 0:l.width)||Qn,o=t.height||((d=t.measured)==null?void 0:d.height)||Kn,i=t._absolutePosition||t.position;if(t.handleBounds){const u=t.handleBounds[e]||[],x=n?u.find(b=>b.id===n):u[0];if(x&&x.x!==void 0&&x.y!==void 0){const b=x.position||(e==="source"?"right":"left");return{x:i.x+x.x,y:i.y+x.y,position:b}}}if(r){const u=`${t.id}__${n||e}`,x=r.get(u);if(x&&x.x!==void 0&&x.y!==void 0)return{x:i.x+x.x,y:i.y+x.y,position:x.position||(e==="source"?"right":"left")}}if(t.handles&&t.handles.length){for(const u of t.handles)if(u.type===e&&(!n||u.id===n)){if(u.x!==void 0&&u.y!==void 0)return{x:i.x+u.x,y:i.y+u.y,position:u.position||(e==="source"?"right":"left")};const x=u.position||(e==="source"?"right":"left");switch(x){case"top":return{x:i.x+s/2,y:i.y,position:x};case"bottom":return{x:i.x+s/2,y:i.y+o,position:x};case"left":return{x:i.x,y:i.y+o/2,position:x};default:return{x:i.x+s,y:i.y+o/2,position:x}}}}return e==="source"?{x:i.x+s,y:i.y+o/2,position:"right"}:{x:i.x,y:i.y+o/2,position:"left"}}function Xr(t,e,n){return n==="left"?t-e:n==="right"?t+e:t}function Yr(t,e,n){return n==="top"?t-e:n==="bottom"?t+e:t}function Dn({x:t,y:e,position:n,type:r,onPointerDown:s}){return C.jsx("circle",{className:`ric-edge-anchor ric-edge-anchor-${r}`,cx:Xr(t,10,n),cy:Yr(e,10,n),r:10,stroke:"transparent",fill:"transparent",style:{cursor:"move",pointerEvents:"stroke"},onPointerDown:s})}function Ur({edge:t,edgeType:e,nodes:n,reconnectable:r}){var m,h,p;const s=dt(),[o,i]=a.useState(null),l=a.useCallback((g,S,I,T)=>{var ut;S.stopPropagation(),S.preventDefault();const M=s.wrapRef.current;if(!M)return;const P=g==="source"?T:I,X=g==="source"?t.target:t.source;(ut=s.workerRef.current)==null||ut.postMessage({type:"connecting",data:{from:{x:P.x,y:P.y},to:{x:P.x,y:P.y}}});const H=M.getBoundingClientRect(),lt=G=>{var at;const q=s.cameraRef.current,nt=(G.clientX-H.left-q.x)/q.zoom,it=(G.clientY-H.top-q.y)/q.zoom;(at=s.workerRef.current)==null||at.postMessage({type:"connecting",data:{from:{x:P.x,y:P.y},to:{x:nt,y:it}}})},ft=G=>{var rt,Et,wt,pt;const q=s.cameraRef.current,nt=(G.clientX-H.left-q.x)/q.zoom,it=(G.clientY-H.top-q.y)/q.zoom,at=20/q.zoom;let ct=null,Ct=null;const tt=(rt=s.handleRegistryRef)==null?void 0:rt.current;for(const zt of s.nodesRef.current){if(zt.hidden)continue;const Mt=zt.width||Qn,Nt=zt.height||Kn,xt=zt._absolutePosition||zt.position,Qt=[];if(tt)for(const[,Pt]of tt)Pt.nodeId===zt.id&&Qt.push(Pt);const Re=Qt.length>0?Qt:zt.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const Pt of Re){let Xt,At;if(Pt.x!==void 0&&Pt.y!==void 0)Xt=xt.x+Pt.x,At=xt.y+Pt.y;else switch(Pt.position||(Pt.type==="source"?"right":"left")){case"top":Xt=xt.x+Mt/2,At=xt.y;break;case"bottom":Xt=xt.x+Mt/2,At=xt.y+Nt;break;case"left":Xt=xt.x,At=xt.y+Nt/2;break;default:Xt=xt.x+Mt,At=xt.y+Nt/2;break}if(Math.abs(nt-Xt)<at&&Math.abs(it-At)<at){ct=zt,Ct=Pt.id||null;break}}if(ct)break}if(ct){const zt=g==="source"?{source:ct.id,target:X,sourceHandle:Ct,targetHandle:t.targetHandle}:{source:X,target:ct.id,sourceHandle:t.sourceHandle,targetHandle:Ct};(wt=(Et=s.onEdgesChangeRef).current)==null||wt.call(Et,[{id:t.id,type:"remove"},{type:"add",item:{id:t.id,...zt}}])}(pt=s.workerRef.current)==null||pt.postMessage({type:"connecting",data:null}),M.removeEventListener("pointermove",lt),M.removeEventListener("pointerup",ft)};M.addEventListener("pointermove",lt),M.addEventListener("pointerup",ft)},[t,s]),d=n.find(g=>g.id===t.source),u=n.find(g=>g.id===t.target),x=d&&!!(d.width||(m=d.measured)!=null&&m.width),b=u&&!!(u.width||(h=u.measured)!=null&&h.width),N=(p=s.handleRegistryRef)==null?void 0:p.current,k=x?jn(d,"source",t.sourceHandle,N):null,R=b?jn(u,"target",t.targetHandle,N):null,B=t.type==="bezier"||t.type==="simplebezier"||t.type==="default",E=s.routedEdges||s.edges,z=E==null?void 0:E.find(g=>g.id===t.id),W=B?null:(z==null?void 0:z._routedPoints)||t._routedPoints||null,D=r!==!1&&t.reconnectable!==!1;return!k||!R?null:C.jsxs("g",{className:`ric-edge-wrapper ${t.selected?"selected":""}`,"data-edgeid":t.id,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),children:[C.jsx(e,{id:t.id,source:t.source,target:t.target,sourceX:k.x,sourceY:k.y,targetX:R.x,targetY:R.y,sourcePosition:k.position,targetPosition:R.position,sourceHandleId:t.sourceHandle,targetHandleId:t.targetHandle,data:t.data,type:t.type,selected:!!t.selected,animated:!!t.animated,label:t.label,style:t.style,selectable:t.selectable!==!1,deletable:t.deletable!==!1,routedPoints:W}),D&&(o||t.selected)&&C.jsxs(C.Fragment,{children:[C.jsx(Dn,{x:k.x,y:k.y,position:k.position,type:"source",onPointerDown:g=>l("source",g,k,R)}),C.jsx(Dn,{x:R.x,y:R.y,position:R.position,type:"target",onPointerDown:g=>l("target",g,k,R)})]})]})}const qr=a.memo(Ur);function Vn({selectionKeyCode:t="Shift",selectionMode:e="partial"}){var B;const n=dt(),[r,s]=a.useState(null),o=a.useRef(null);if(a.useEffect(()=>{const E=n.wrapRef.current;if(!E)return;let z=!1,W=null,D=!1;const m=I=>{I.key===t&&(D=!0)},h=I=>{I.key===t&&(D=!1)},p=I=>{if(!D)return;const T=I.target;if(T.closest(".ric-node-wrapper")||T.closest(".ric-handle"))return;z=!0;const M=n.cameraRef.current,P=E.getBoundingClientRect(),X=(I.clientX-P.left-M.x)/M.zoom,H=(I.clientY-P.top-M.y)/M.zoom;W={x:X,y:H},s({startX:X,startY:H,endX:X,endY:H}),I.stopPropagation()},g=I=>{if(!z||!W)return;const T=n.cameraRef.current,M=E.getBoundingClientRect(),P=(I.clientX-M.left-T.x)/T.zoom,X=(I.clientY-M.top-T.y)/T.zoom;s({startX:W.x,startY:W.y,endX:P,endY:X})},S=I=>{var ft,ut;if(!z||!W)return;z=!1;const T=n.cameraRef.current,M=E.getBoundingClientRect(),P=(I.clientX-M.left-T.x)/T.zoom,X=(I.clientY-M.top-T.y)/T.zoom,H={x:Math.min(W.x,P),y:Math.min(W.y,X),width:Math.abs(P-W.x),height:Math.abs(X-W.y)},lt=[];for(const G of n.nodesRef.current){const q=G._absolutePosition||G.position,nt=G.width||160,it=G.height||60;let at;e==="full"?at=q.x>=H.x&&q.y>=H.y&&q.x+nt<=H.x+H.width&&q.y+it<=H.y+H.height:at=q.x+nt>H.x&&q.x<H.x+H.width&&q.y+it>H.y&&q.y<H.y+H.height,lt.push({id:G.id,type:"select",selected:at})}lt.length&&((ut=(ft=n.onNodesChangeRef).current)==null||ut.call(ft,lt)),W=null,s(null)};return E.addEventListener("pointerdown",p,!0),E.addEventListener("pointermove",g),E.addEventListener("pointerup",S),window.addEventListener("keydown",m),window.addEventListener("keyup",h),()=>{E.removeEventListener("pointerdown",p,!0),E.removeEventListener("pointermove",g),E.removeEventListener("pointerup",S),window.removeEventListener("keydown",m),window.removeEventListener("keyup",h)}},[n,t,e]),!r)return null;const i=((B=n.cameraRef)==null?void 0:B.current)||{x:0,y:0,zoom:1},l=Math.min(r.startX,r.endX),d=Math.min(r.startY,r.endY),u=Math.abs(r.endX-r.startX),x=Math.abs(r.endY-r.startY),b=l*i.zoom+i.x,N=d*i.zoom+i.y,k=u*i.zoom,R=x*i.zoom;return C.jsx("div",{ref:o,className:"ric-selection-box",style:{position:"absolute",left:b,top:N,width:k,height:R,border:"1px dashed #3b82f6",background:"rgba(59, 130, 246, 0.08)",pointerEvents:"none",zIndex:100}})}Vn.displayName="SelectionBox";const Jn=a.memo(Vn);function tr(t,e){var s,o,i,l;const n=(s=t.handleRegistryRef)==null?void 0:s.current;if(!n)return;const r={source:[],target:[]};for(const[,d]of n)if(d.nodeId===e){const u={id:d.id,type:d.type,position:d.position,x:d.x,y:d.y,width:8,height:8};d.type==="source"?r.source.push(u):r.target.push(u)}(i=(o=t.onNodesChangeRef).current)==null||i.call(o,[{id:e,type:"dimensions",handleBounds:r,setAttributes:!1}]),(l=t.syncNodesToWorker)==null||l.call(t)}const xn=new Set;function Hn(t,e){xn.has(e)||(xn.add(e),queueMicrotask(()=>{xn.delete(e),tr(t,e)}))}function Gr(t,e){const n=t.closest(".ric-node-wrapper");if(!n)return null;const r=n.getBoundingClientRect(),s=t.getBoundingClientRect(),o=e||1;return{x:(s.left+s.width/2-r.left)/o,y:(s.top+s.height/2-r.top)/o}}function Ae({type:t="source",position:e=t==="source"?"right":"left",id:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:o=!0,children:i,className:l="",style:d={},onConnect:u,...x}){const b=a.useContext(_e),N=dt(),k=a.useRef(null),R=a.useRef(N);R.current=N;const B=a.useCallback(()=>{var I,T,M;const D=k.current;if(!D||!b)return;const m=R.current,h=(I=m.handleRegistryRef)==null?void 0:I.current;if(!h)return;const p=`${b}__${n||t}`,g=(M=(T=m.cameraRef)==null?void 0:T.current)==null?void 0:M.zoom,S=Gr(D,g);if(S){const P={nodeId:b,id:n||null,type:t,position:e,x:S.x,y:S.y};h.set(p,P)}},[b,n,t,e]);a.useLayoutEffect(()=>{B()},[B]),a.useEffect(()=>{if(!b)return;const D=R.current;Hn(D,b);const m=k.current,h=m==null?void 0:m.closest(".ric-node-wrapper"),p=new ResizeObserver(()=>{B(),Hn(R.current,b)});return h&&p.observe(h),()=>{var T;p.disconnect();const g=R.current,S=(T=g.handleRegistryRef)==null?void 0:T.current,I=`${b}__${n||t}`;S==null||S.delete(I),tr(g,b)}},[b,n,t,e,B]);const E=a.useCallback(()=>{var M;const D=R.current,m=D.nodesRef.current.find(P=>P.id===b);if(!m)return null;const h=m._absolutePosition||m.position,p=(M=D.handleRegistryRef)==null?void 0:M.current,g=`${b}__${n||t}`,S=p==null?void 0:p.get(g);if(S&&S.x!==void 0&&S.y!==void 0)return{x:h.x+S.x,y:h.y+S.y};const I=m.width||160,T=m.height||60;switch(e){case"top":return{x:h.x+I/2,y:h.y};case"bottom":return{x:h.x+I/2,y:h.y+T};case"left":return{x:h.x,y:h.y+T/2};default:return{x:h.x+I,y:h.y+T/2}}},[b,n,t,e]),z=a.useCallback(D=>{var X;if(!r||!s)return;D.stopPropagation(),D.preventDefault();const m=R.current,h=m.cameraRef.current,p=m.wrapRef.current;if(!p)return;const g=p.getBoundingClientRect(),S=E();if(!S)return;const I=S.x,T=S.y;(X=m.workerRef.current)==null||X.postMessage({type:"connecting",data:{from:{x:I,y:T},to:{x:I,y:T}}}),p.setPointerCapture(D.pointerId);const M=H=>{var ut;const lt=(H.clientX-g.left-h.x)/h.zoom,ft=(H.clientY-g.top-h.y)/h.zoom;(ut=m.workerRef.current)==null||ut.postMessage({type:"connecting",data:{from:{x:I,y:T},to:{x:lt,y:ft}}})},P=H=>{var it,at,ct,Ct;const lt=(H.clientX-g.left-h.x)/h.zoom,ft=(H.clientY-g.top-h.y)/h.zoom,ut=20/h.zoom;let G=null,q=null;const nt=(it=m.handleRegistryRef)==null?void 0:it.current;for(const tt of m.nodesRef.current){if(tt.id===b||tt.hidden)continue;const rt=tt.width||160,Et=tt.height||60,wt=tt._absolutePosition||tt.position,pt=[];if(nt)for(const[,Mt]of nt)Mt.nodeId===tt.id&&pt.push(Mt);const zt=pt.length>0?pt:tt.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const Mt of zt){let Nt,xt;if(Mt.x!==void 0&&Mt.y!==void 0)Nt=wt.x+Mt.x,xt=wt.y+Mt.y;else switch(Mt.position||(Mt.type==="source"?"right":"left")){case"top":Nt=wt.x+rt/2,xt=wt.y;break;case"bottom":Nt=wt.x+rt/2,xt=wt.y+Et;break;case"left":Nt=wt.x,xt=wt.y+Et/2;break;default:Nt=wt.x+rt,xt=wt.y+Et/2;break}if(Math.abs(lt-Nt)<ut&&Math.abs(ft-xt)<ut){G=tt,q=Mt.id||null;break}}if(G)break}if(G){const tt={source:t==="source"?b:G.id,target:t==="source"?G.id:b,sourceHandle:t==="source"?n||null:q,targetHandle:t==="source"?q:n||null};(ct=(at=m.onEdgesChangeRef)==null?void 0:at.current)==null||ct.call(at,[{type:"add",item:{id:`e-${tt.source}-${tt.target}`,...tt}}])}(Ct=m.workerRef.current)==null||Ct.postMessage({type:"connecting",data:null}),p.removeEventListener("pointermove",M),p.removeEventListener("pointerup",P)};p.addEventListener("pointermove",M),p.addEventListener("pointerup",P)},[b,n,t,e,r,s,E]),W={top:{top:0,left:"50%",transform:"translate(-50%, -50%)"},bottom:{bottom:0,left:"50%",transform:"translate(-50%, 50%)"},left:{top:"50%",left:0,transform:"translate(-50%, -50%)"},right:{top:"50%",right:0,transform:"translate(50%, -50%)"}}[e]||{};return C.jsx("div",{ref:k,className:`ric-handle ric-handle-${e} ric-handle-${t} ${l}`,"data-handleid":n||null,"data-nodeid":b,"data-handlepos":e,"data-handletype":t,onPointerDown:z,style:{position:"absolute",width:8,height:8,borderRadius:"50%",background:"#1a192b",border:"none",zIndex:10,cursor:r?"crosshair":"default",boxSizing:"border-box",...W,...d},...x,children:i})}function Zr({data:t,isConnectable:e,selected:n,targetPosition:r="left",sourcePosition:s="right",hideSourceHandle:o=!1,hideTargetHandle:i=!1}){return C.jsxs("div",{className:`ric-default-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!i&&C.jsx(Ae,{type:"target",position:r,isConnectable:e}),C.jsx("div",{className:"ric-node-content",children:t==null?void 0:t.label}),!o&&C.jsx(Ae,{type:"source",position:s,isConnectable:e})]})}function er({data:t,isConnectable:e,selected:n,sourcePosition:r="right",hideSourceHandle:s=!1}){return C.jsxs("div",{className:`ric-input-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderBottom:"2px solid #0041d0",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[C.jsx("div",{className:"ric-node-content",children:t==null?void 0:t.label}),!s&&C.jsx(Ae,{type:"source",position:r,isConnectable:e})]})}function nr({data:t,isConnectable:e,selected:n,targetPosition:r="left",hideTargetHandle:s=!1}){return C.jsxs("div",{className:`ric-output-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderTop:"2px solid #ff0072",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!s&&C.jsx(Ae,{type:"target",position:r,isConnectable:e}),C.jsx("div",{className:"ric-node-content",children:t==null?void 0:t.label})]})}function rr({data:t,selected:e,width:n,height:r}){return C.jsx("div",{className:`ric-group-node${e?" selected":""}`,style:{width:n||300,height:r||200,background:"rgba(240, 240, 240, 0.25)",border:e?"2px solid #3b82f6":"1px dashed #ccc",borderRadius:8,padding:8,boxSizing:"border-box"},children:(t==null?void 0:t.label)&&C.jsx("div",{style:{fontSize:11,fontWeight:600,color:"#888",userSelect:"none"},children:t.label})})}function or({x:t,y:e,label:n,labelStyle:r,labelShowBg:s=!0,labelBgStyle:o,labelBgPadding:i=[2,4],labelBgBorderRadius:l=2,children:d,className:u="",...x}){const[b,N]=a.useState({x:1,y:0,width:0,height:0}),k=a.useRef(null);return a.useEffect(()=>{if(k.current){const R=k.current.getBBox();N({x:R.x,y:R.y,width:R.width,height:R.height})}},[n]),n?C.jsxs("g",{transform:`translate(${t-b.width/2} ${e-b.height/2})`,className:`ric-edge-textwrapper ${u}`,visibility:b.width?"visible":"hidden",...x,children:[s&&C.jsx("rect",{width:b.width+2*i[0],x:-i[0],y:-i[1],height:b.height+2*i[1],className:"ric-edge-textbg",style:o,rx:l,ry:l}),C.jsx("text",{className:"ric-edge-text",y:b.height/2,dy:"0.3em",ref:k,style:r,children:n}),d]}):null}or.displayName="EdgeText";const sr=a.memo(or);function An(t){return t!=null&&t!==""&&!isNaN(Number(t))}function We({id:t,path:e,labelX:n,labelY:r,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:l,labelBgPadding:d,labelBgBorderRadius:u,interactionWidth:x=20,style:b,markerEnd:N,markerStart:k,className:R="",...B}){return C.jsxs(C.Fragment,{children:[C.jsx("path",{id:t,d:e,fill:"none",stroke:"#b1b1b7",strokeWidth:1.5,className:`ric-edge-path ${R}`,style:b,markerEnd:N,markerStart:k,...B}),x?C.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:x,className:"ric-edge-interaction",style:{pointerEvents:"stroke"}}):null,s&&An(n)&&An(r)?C.jsx(sr,{x:n,y:r,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:l,labelBgPadding:d,labelBgBorderRadius:u}):null]})}const je=20;function _n(t,e,n){switch(n){case"right":return{x:t+je,y:e};case"left":return{x:t-je,y:e};case"bottom":return{x:t,y:e+je};case"top":return{x:t,y:e-je};default:return{x:t+je,y:e}}}const Rn=a.memo(function({id:e,sourceX:n,sourceY:r,targetX:s,targetY:o,sourcePosition:i="bottom",targetPosition:l="top",label:d,labelStyle:u,labelShowBg:x,labelBgStyle:b,labelBgPadding:N,labelBgBorderRadius:k,style:R,markerEnd:B,markerStart:E,interactionWidth:z}){let W,D,m;const h=_n(n,r,i),p=_n(s,o,l),g=Math.abs(p.x-h.x),S=Math.max(50,g*.5);let I,T,M,P;switch(i){case"left":I=h.x-S,T=h.y;break;case"top":I=h.x,T=h.y-S;break;case"bottom":I=h.x,T=h.y+S;break;default:I=h.x+S,T=h.y;break}switch(l){case"right":M=p.x+S,P=p.y;break;case"top":M=p.x,P=p.y-S;break;case"bottom":M=p.x,P=p.y+S;break;default:M=p.x-S,P=p.y;break}W=`M ${n},${r} L ${h.x},${h.y} C ${I},${T} ${M},${P} ${p.x},${p.y} L ${s},${o}`;const X=.5,H=.5;return D=H*H*H*h.x+3*H*H*X*I+3*H*X*X*M+X*X*X*p.x,m=H*H*H*h.y+3*H*H*X*T+3*H*X*X*P+X*X*X*p.y,C.jsx(We,{id:e,path:W,labelX:D,labelY:m,label:d,labelStyle:u,labelShowBg:x,labelBgStyle:b,labelBgPadding:N,labelBgBorderRadius:k,style:R,markerEnd:B,markerStart:E,interactionWidth:z})});Rn.displayName="BezierEdge";function kn({sourceX:t,sourceY:e,targetX:n,targetY:r}){const s=`M ${t},${e}L ${n},${r}`,o=(t+n)/2,i=(e+r)/2;return[s,o,i,0,0]}function Cn({sourceX:t,sourceY:e,targetX:n,targetY:r,sourcePosition:s="right",targetPosition:o="left",curvature:i=.25}){const l=Math.abs(n-t),d=Math.abs(r-e),u=Math.sqrt(l*l+d*d),x=Math.max(u*i,50);let b,N,k,R;switch(s){case"top":b=t,N=e-x;break;case"bottom":b=t,N=e+x;break;case"left":b=t-x,N=e;break;default:b=t+x,N=e;break}switch(o){case"top":k=n,R=r-x;break;case"bottom":k=n,R=r+x;break;case"right":k=n+x,R=r;break;default:k=n-x,R=r;break}const B=`M ${t},${e} C ${b},${N} ${k},${R} ${n},${r}`,E=.5,z=1-E,W=z*z*z*t+3*z*z*E*b+3*z*E*E*k+E*E*E*n,D=z*z*z*e+3*z*z*E*N+3*z*E*E*R+E*E*E*r;return[B,W,D,0,0]}function En({sourceX:t,sourceY:e,targetX:n,targetY:r}){const s=Math.abs(n-t),o=Math.max(s*.5,50),i=t+o,l=n-o,d=`M ${t},${e} C ${i},${e} ${l},${r} ${n},${r}`,u=.5,x=.5,b=x*x*x*t+3*x*x*u*i+3*x*u*u*l+u*u*u*n,N=x*x*x*e+3*x*x*u*e+3*x*u*u*r+u*u*u*r;return[d,b,N,0,0]}function tn({sourceX:t,sourceY:e,targetX:n,targetY:r,sourcePosition:s="right",targetPosition:o="left",borderRadius:i=5,offset:l=20}){const d=s==="left"||s==="right",u=Math.min(i,Math.abs(n-t)/2,Math.abs(r-e)/2);if(d){if(Math.abs(r-e)<1)return[`M ${t},${e} L ${n},${r}`,(t+n)/2,e,0,0];const k=(t+n)/2,R=r>e?1:-1;return[`M ${t},${e} L ${k-u},${e} Q ${k},${e} ${k},${e+R*u} L ${k},${r-R*u} Q ${k},${r} ${k+(n>k?u:-u)},${r} L ${n},${r}`,k,(e+r)/2,0,0]}const x=(e+r)/2,b=n>t?1:-1;return[`M ${t},${e} L ${t},${x-u} Q ${t},${x} ${t+b*u},${x} L ${n-b*u},${x} Q ${n},${x} ${n},${x+(r>x?u:-u)} L ${n},${r}`,(t+n)/2,x,0,0]}function Or({sourceX:t,sourceY:e,targetX:n,targetY:r}){const[,s,o]=Cn({sourceX:t,sourceY:e,targetX:n,targetY:r});return[s,o,0,0]}function Qr({sourceX:t,sourceY:e,targetX:n,targetY:r}){return[(t+n)/2,(e+r)/2,0,0]}function Kr(t,e,n){const r=n.filter(o=>o.id!==t.id),s={...t,id:t.id,source:e.source,target:e.target,sourceHandle:e.sourceHandle??t.sourceHandle,targetHandle:e.targetHandle??t.targetHandle};return r.push(s),r}const en=160,nn=60,De=20,Ke=12,rn=20;function Wn(t,e,n){var i,l;const r=t.width||((i=t.measured)==null?void 0:i.width)||en,s=t.height||((l=t.measured)==null?void 0:l.height)||nn,o=t._absolutePosition||t.position;if(t.handles&&t.handles.length>0){for(const d of t.handles)if(d.type===e&&(!n||d.id===n)){if(d.x!==void 0&&d.y!==void 0)return{x:o.x+d.x,y:o.y+d.y,dir:d.position||(e==="source"?"right":"left")};switch(d.position||(e==="source"?"right":"left")){case"top":return{x:o.x+r/2,y:o.y,dir:"top"};case"bottom":return{x:o.x+r/2,y:o.y+s,dir:"bottom"};case"left":return{x:o.x,y:o.y+s/2,dir:"left"};default:return{x:o.x+r,y:o.y+s/2,dir:"right"}}}}return e==="source"?{x:o.x+r,y:o.y+s/2,dir:"right"}:{x:o.x,y:o.y+s/2,dir:"left"}}function on(t,e){switch(t.dir){case"right":return{x:t.x+e,y:t.y,dir:t.dir};case"left":return{x:t.x-e,y:t.y,dir:t.dir};case"bottom":return{x:t.x,y:t.y+e,dir:t.dir};case"top":return{x:t.x,y:t.y-e,dir:t.dir};default:return{x:t.x+e,y:t.y,dir:t.dir}}}function Vr(t,e,n,r,s,o,i,l){const d=Math.min(t,n),u=Math.max(t,n),x=Math.min(e,r),b=Math.max(e,r);if(u<=s||d>=s+i||b<=o||x>=o+l)return!1;const N=.5;if(t>s+N&&t<s+i-N&&e>o+N&&e<o+l-N||n>s+N&&n<s+i-N&&r>o+N&&r<o+l-N)return!0;const k=(t+n)/2,R=(e+r)/2;if(k>s+N&&k<s+i-N&&R>o+N&&R<o+l-N)return!0;const B=[[s,o],[s+i,o],[s+i,o+l],[s,o+l]];for(let E=0;E<4;E++)if(Jr(t,e,n,r,B[E][0],B[E][1],B[(E+1)%4][0],B[(E+1)%4][1]))return!0;return!1}function Jr(t,e,n,r,s,o,i,l){const d=(i-s)*(e-o)-(l-o)*(t-s),u=(i-s)*(r-o)-(l-o)*(n-s),x=(n-t)*(o-e)-(r-e)*(s-t),b=(n-t)*(l-e)-(r-e)*(i-t);return(d>0&&u<0||d<0&&u>0)&&(x>0&&b<0||x<0&&b>0)}function wn(t,e,n,r,s){for(let o=0;o<s.length;o++){const i=s[o];if(Vr(t,e,n,r,i.x,i.y,i.w,i.h))return!1}return!0}function to(t,e,n){for(let r=0;r<n.length;r++){const s=n[r];if(t>s.x&&t<s.x+s.w&&e>s.y&&e<s.y+s.h)return!0}return!1}function zn(t,e){var r,s;const n=[];for(let o=0;o<t.length;o++){const i=t[o];if(i.hidden||e&&e.has(i.id)||i.type==="group")continue;const l=i._absolutePosition||i.position,d=i.width||((r=i.measured)==null?void 0:r.width)||en,u=i.height||((s=i.measured)==null?void 0:s.height)||nn;n.push({id:i.id,x:l.x-De,y:l.y-De,w:d+2*De,h:u+2*De})}return n}function ir(t,e,n){if(wn(t.x,t.y,e.x,e.y,n))return null;const r=new Set,s=new Set;r.add(t.x),r.add(e.x),s.add(t.y),s.add(e.y);const o=De+5;t.dir==="right"?r.add(t.x+o):t.dir==="left"?r.add(t.x-o):t.dir==="top"?s.add(t.y-o):t.dir==="bottom"&&s.add(t.y+o),e.dir==="right"?r.add(e.x+o):e.dir==="left"?r.add(e.x-o):e.dir==="top"?s.add(e.y-o):e.dir==="bottom"&&s.add(e.y+o);for(let M=0;M<n.length;M++){const P=n[M];r.add(P.x),r.add(P.x+P.w),s.add(P.y),s.add(P.y+P.h)}const i=[...r].sort((M,P)=>M-P),l=[...s].sort((M,P)=>M-P),d=new Map,u=new Map;for(let M=0;M<i.length;M++)d.set(i[M],M);for(let M=0;M<l.length;M++)u.set(l[M],M);const x=i.length,b=l.length,N=(M,P)=>P*x+M,k=d.get(t.x),R=u.get(t.y),B=d.get(e.x),E=u.get(e.y);if(k===void 0||R===void 0||B===void 0||E===void 0)return null;const z=N(k,R),W=N(B,E),D=new Float64Array(x*b).fill(1/0),m=new Float64Array(x*b).fill(1/0),h=new Int32Array(x*b).fill(-1),p=new Int8Array(x*b).fill(-1),g=new Uint8Array(x*b);D[z]=0,m[z]=Math.abs(i[B]-t.x)+Math.abs(l[E]-t.y);const S=[z],I=15,T=[[1,0],[-1,0],[0,1],[0,-1]];for(;S.length>0;){let M=0;for(let G=1;G<S.length;G++)m[S[G]]<m[S[M]]&&(M=G);const P=S[M];if(S[M]=S[S.length-1],S.pop(),P===W){const G=[];let q=W;for(;q!==-1&&q!==z;){const nt=q/x|0,it=q%x;G.unshift({x:i[it],y:l[nt]}),q=h[q]}return G.unshift({x:t.x,y:t.y}),eo(G,n)}if(g[P])continue;g[P]=1;const X=P/x|0,H=P%x,lt=i[H],ft=l[X],ut=p[P];for(let G=0;G<4;G++){const q=H+T[G][0],nt=X+T[G][1];if(q<0||q>=x||nt<0||nt>=b)continue;const it=N(q,nt);if(g[it])continue;const at=i[q],ct=l[nt];if(to(at,ct,n)||!wn(lt,ft,at,ct,n))continue;const Ct=Math.abs(at-lt)+Math.abs(ct-ft),tt=ut>=0&&ut!==G?I:0,rt=D[P]+Ct+tt;rt<D[it]&&(h[it]=P,p[it]=G,D[it]=rt,m[it]=rt+Math.abs(i[B]-at)+Math.abs(l[E]-ct),S.push(it))}}return null}function eo(t,e){if(!t||t.length<=2)return t;const n=[t[0]];for(let r=1;r<t.length-1;r++){const s=n[n.length-1],o=t[r],i=t[r+1],l=Math.abs(s.x-o.x)<.5&&Math.abs(o.x-i.x)<.5,d=Math.abs(s.y-o.y)<.5&&Math.abs(o.y-i.y)<.5;(l||d)&&wn(s.x,s.y,i.x,i.y,e)||n.push(o)}return n.push(t[t.length-1]),n}function no(t){const e=new Map,n=new Map;for(const s of t){const o=s._routedPoints;if(!(!o||o.length<2))for(let i=0;i<o.length-1;i++){const l=o[i],d=o[i+1];if(Math.abs(l.y-d.y)<.5){const u=Math.round(l.y*10)/10;e.has(u)||e.set(u,[]),e.get(u).push({edgeId:s.id,segIdx:i,x1:Math.min(l.x,d.x),x2:Math.max(l.x,d.x)})}else if(Math.abs(l.x-d.x)<.5){const u=Math.round(l.x*10)/10;n.has(u)||n.set(u,[]),n.get(u).push({edgeId:s.id,segIdx:i,y1:Math.min(l.y,d.y),y2:Math.max(l.y,d.y)})}}}const r=new Map;for(const s of t)s._routedPoints&&r.set(s.id,s._routedPoints.map(o=>({...o})));for(const[,s]of e){if(s.length<2)continue;const o=Fn(s,"x1","x2");for(const i of o){if(i.length<2)continue;const l=(i.length-1)*Ke/2;for(let d=0;d<i.length;d++){const u=i[d],x=-l+d*Ke,b=r.get(u.edgeId);b&&(b[u.segIdx].y+=x,b[u.segIdx+1].y+=x)}}}for(const[,s]of n){if(s.length<2)continue;const o=Fn(s,"y1","y2");for(const i of o){if(i.length<2)continue;const l=(i.length-1)*Ke/2;for(let d=0;d<i.length;d++){const u=i[d],x=-l+d*Ke,b=r.get(u.edgeId);b&&(b[u.segIdx].x+=x,b[u.segIdx+1].x+=x)}}}return t.map(s=>{const o=r.get(s.id);return o?{...s,_routedPoints:o}:s})}function Fn(t,e,n){if(t.length<2)return[];const r=[...t].sort((i,l)=>i[e]-l[e]),s=[];let o=[r[0]];for(let i=1;i<r.length;i++){const l=o[o.length-1];r[i][e]<l[n]?o.push(r[i]):(o.length>1&&s.push(o),o=[r[i]])}return o.length>1&&s.push(o),s}function sn(t,e=6,n=!1){if(!t||t.length<2)return null;if(n)return ro(t);const r=e;let s=`M ${t[0].x},${t[0].y}`;for(let o=1;o<t.length-1;o++){const i=t[o-1],l=t[o],d=t[o+1],u=Math.abs(l.x-i.x)+Math.abs(l.y-i.y),x=Math.abs(d.x-l.x)+Math.abs(d.y-l.y),b=Math.min(r,u/2,x/2);if(b>.5){const N=l.x-i.x,k=l.y-i.y,R=d.x-l.x,B=d.y-l.y,E=Math.sqrt(N*N+k*k)||1,z=Math.sqrt(R*R+B*B)||1;s+=` L ${l.x-N/E*b},${l.y-k/E*b}`,s+=` Q ${l.x},${l.y} ${l.x+R/z*b},${l.y+B/z*b}`}else s+=` L ${l.x},${l.y}`}return s+=` L ${t[t.length-1].x},${t[t.length-1].y}`,s}function ro(t){if(t.length===2)return`M ${t[0].x},${t[0].y} L ${t[1].x},${t[1].y}`;if(t.length===3)return`M ${t[0].x},${t[0].y} Q ${t[1].x},${t[1].y} ${t[2].x},${t[2].y}`;const e=.3;let n=`M ${t[0].x},${t[0].y}`;for(let r=0;r<t.length-1;r++){const s=t[r===0?0:r-1],o=t[r],i=t[r+1],l=t[r+2<t.length?r+2:t.length-1],d=o.x+(i.x-s.x)*e,u=o.y+(i.y-s.y)*e,x=i.x-(l.x-o.x)*e,b=i.y-(l.y-o.y)*e;n+=` C ${d},${u} ${x},${b} ${i.x},${i.y}`}return n}function an(t){if(!t||t.length<2)return{x:0,y:0};let e=0;for(let r=1;r<t.length;r++)e+=Math.abs(t[r].x-t[r-1].x)+Math.abs(t[r].y-t[r-1].y);let n=e/2;for(let r=1;r<t.length;r++){const s=Math.abs(t[r].x-t[r-1].x)+Math.abs(t[r].y-t[r-1].y);if(n<=s){const o=s>0?n/s:0;return{x:t[r-1].x+(t[r].x-t[r-1].x)*o,y:t[r-1].y+(t[r].y-t[r-1].y)*o}}n-=s}return{x:t[0].x,y:t[0].y}}function oo(t,e){if(!t||!e||t.length===0||e.length===0)return e;const n={};for(const o of t)n[o.id]=o;const r=zn(t,null),s=e.map(o=>{var p,g,S,I;const i=o.type||"default";if(i==="bezier"||i==="simplebezier"||i==="default")return o;const l=n[o.source],d=n[o.target];if(!l||!d||l.hidden||d.hidden)return o;const u=Wn(l,"source",o.sourceHandle),x=Wn(d,"target",o.targetHandle),b=on(u,rn),N=on(x,rn),k=5,R=r.filter(T=>T.id!==o.source&&T.id!==o.target),B=l._absolutePosition||l.position,E=l.width||((p=l.measured)==null?void 0:p.width)||en,z=l.height||((g=l.measured)==null?void 0:g.height)||nn;R.push({id:o.source,x:B.x-k,y:B.y-k,w:E+2*k,h:z+2*k});const W=d._absolutePosition||d.position,D=d.width||((S=d.measured)==null?void 0:S.width)||en,m=d.height||((I=d.measured)==null?void 0:I.height)||nn;if(R.push({id:o.target,x:W.x-k,y:W.y-k,w:D+2*k,h:m+2*k}),R.length===0)return o;const h=ir(b,N,R);return h&&h.length>=2?(h.unshift({x:u.x,y:u.y}),h.push({x:x.x,y:x.y}),{...o,_routedPoints:h}):o});return no(s)}function so(t,e,n,r,s,o,i,l){const d=zn(i,l?new Set(l):null);if(d.length===0)return null;const u={x:t,y:e,dir:s||"right"},x={x:n,y:r,dir:o||"left"},b=on(u,rn),N=on(x,rn),k=ir(b,N,d);return k&&k.length>=2?(k.unshift({x:u.x,y:u.y}),k.push({x:x.x,y:x.y}),k):null}const Nn=a.memo(function({id:e,sourceX:n,sourceY:r,targetX:s,targetY:o,label:i,labelStyle:l,labelShowBg:d,labelBgStyle:u,labelBgPadding:x,labelBgBorderRadius:b,style:N,markerEnd:k,markerStart:R,interactionWidth:B,routedPoints:E}){let z,W,D;if(E&&E.length>=2){z=sn(E);const m=an(E);W=m.x,D=m.y}else[z,W,D]=kn({sourceX:n,sourceY:r,targetX:s,targetY:o});return C.jsx(We,{id:e,path:z,labelX:W,labelY:D,label:i,labelStyle:l,labelShowBg:d,labelBgStyle:u,labelBgPadding:x,labelBgBorderRadius:b,style:N,markerEnd:k,markerStart:R,interactionWidth:B})});Nn.displayName="StraightEdge";const In=a.memo(function({id:e,sourceX:n,sourceY:r,targetX:s,targetY:o,sourcePosition:i="bottom",targetPosition:l="top",label:d,labelStyle:u,labelShowBg:x,labelBgStyle:b,labelBgPadding:N,labelBgBorderRadius:k,style:R,markerEnd:B,markerStart:E,pathOptions:z,interactionWidth:W,routedPoints:D}){let m,h,p;if(D&&D.length>=2){m=sn(D);const g=an(D);h=g.x,p=g.y}else[m,h,p]=tn({sourceX:n,sourceY:r,sourcePosition:i,targetX:s,targetY:o,targetPosition:l,borderRadius:z==null?void 0:z.borderRadius,offset:z==null?void 0:z.offset});return C.jsx(We,{id:e,path:m,labelX:h,labelY:p,label:d,labelStyle:u,labelShowBg:x,labelBgStyle:b,labelBgPadding:N,labelBgBorderRadius:k,style:R,markerEnd:B,markerStart:E,interactionWidth:W})});In.displayName="SmoothStepEdge";const ar=a.memo(function({id:e,...n}){var s;const r=a.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(s=n.pathOptions)==null?void 0:s.offset]);return C.jsx(In,{...n,id:e,pathOptions:r})});ar.displayName="StepEdge";const Sn=a.memo(function({id:e,sourceX:n,sourceY:r,targetX:s,targetY:o,sourcePosition:i,targetPosition:l,label:d,labelStyle:u,labelShowBg:x,labelBgStyle:b,labelBgPadding:N,labelBgBorderRadius:k,style:R,markerEnd:B,markerStart:E,interactionWidth:z,routedPoints:W}){let D,m,h;if(W&&W.length>=2){D=sn(W);const p=an(W);m=p.x,h=p.y}else[D,m,h]=En({sourceX:n,sourceY:r,targetX:s,targetY:o});return C.jsx(We,{id:e,path:D,labelX:m,labelY:h,label:d,labelStyle:u,labelShowBg:x,labelBgStyle:b,labelBgPadding:N,labelBgBorderRadius:k,style:R,markerEnd:B,markerStart:E,interactionWidth:z})});Sn.displayName="SimpleBezierEdge";const io={input:er,output:nr,group:rr},ao={bezier:Rn,straight:Nn,simplebezier:Sn};function co({cards:t,nodes:e=[],edges:n=[],nodeTypes:r,edgeTypes:s,dark:o,gridSize:i,width:l="100%",height:d="420px",className:u="",style:x={},zoomMin:b,zoomMax:N,initialCamera:k,fitView:R,fitViewOptions:B,onNodesChange:E,onEdgesChange:z,onConnect:W,onConnectStart:D,onConnectEnd:m,onNodeClick:h,onNodeDoubleClick:p,onNodeMouseEnter:g,onNodeMouseMove:S,onNodeMouseLeave:I,onNodeContextMenu:T,onNodeDragStart:M,onNodeDrag:P,onNodeDragStop:X,onEdgeClick:H,onEdgeDoubleClick:lt,onEdgeMouseEnter:ft,onEdgeMouseMove:ut,onEdgeMouseLeave:G,onEdgeContextMenu:q,onPaneClick:nt,onPaneContextMenu:it,onPaneMouseEnter:at,onPaneMouseMove:ct,onPaneMouseLeave:Ct,onSelectionChange:tt,onInit:rt,onMoveStart:Et,onMove:wt,onMoveEnd:pt,onDelete:zt,onBeforeDelete:Mt,onError:Nt,onDragOver:xt,onDrop:Qt,onDragEnter:Re,onDragLeave:Pt,nodesDraggable:Xt,nodesConnectable:At,elementsSelectable:fe,multiSelectionKeyCode:se,selectionOnDrag:he,selectionMode:ye,connectionMode:Fe,connectionRadius:ke,connectOnClick:Xe,isValidConnection:Ye,defaultEdgeOptions:Ue,snapToGrid:qe,snapGrid:Ce,deleteKeyCode:Kt,panActivationKeyCode:Vt,panOnScroll:ge,panOnScrollMode:cn,panOnScrollSpeed:ln,zoomOnScroll:Yt,zoomOnDoubleClick:Pn,zoomOnPinch:un,preventScrolling:ie,translateExtent:yt,nodeExtent:Ee,autoPanOnNodeDrag:Rt,autoPanOnConnect:ht,autoPanSpeed:Jt,edgesReconnectable:Z,elevateNodesOnSelect:It,elevateEdgesOnSelect:dn,edgeRouting:ze=!0,onHudUpdate:Zt,onNodesProcessed:fn,showHud:hn=!0,showHint:Bt=!0,hintText:jt="Drag to pan · Scroll to zoom",children:xe,...te}){const[_t,pe]=a.useState({wx:0,wy:0,zoom:"1.00"}),Ne=a.useRef(null),Ge=a.useRef(null),Ze=a.useCallback(Q=>{pe(Q),Zt==null||Zt(Q)},[Zt]),ee=a.useMemo(()=>({...io,...r}),[r]),Ut=a.useMemo(()=>({...ao,...s}),[s]),ae=a.useMemo(()=>{const Q=e.filter(Ht=>Ht.type&&ee[Ht.type]);return Q.sort((Ht,ot)=>{const St=Ht.type==="group"||!Ht.parentId&&Q.some(be=>be.parentId===Ht.id),de=ot.type==="group"||!ot.parentId&&Q.some(be=>be.parentId===ot.id);return St&&!de?-1:!St&&de?1:0})},[e,ee]),me=a.useMemo(()=>n.filter(Q=>Q.type&&Ut[Q.type]),[n,Ut]),O=a.useMemo(()=>e.map(Q=>Q.type&&ee[Q.type]?{...Q,_customRendered:!0}:Q),[e,ee]),mt=a.useMemo(()=>n.map(Q=>Q.type&&Ut[Q.type]?{...Q,_customRendered:!0}:Q),[n,Ut]),{wrapRef:Lt,canvasRef:ne,canvasReady:Ie,onPointerDown:Se,onPointerMove:Pe,onPointerUp:Le,store:re}=Zn({cards:t,nodes:O,edges:mt,dark:o,gridSize:i,zoomMin:b,zoomMax:N,initialCamera:k,fitView:R,fitViewOptions:B,onHudUpdate:Ze,onNodesProcessed:fn,onNodesChange:E,onEdgesChange:z,onConnect:W,onConnectStart:D,onConnectEnd:m,onNodeClick:h,onNodeDoubleClick:p,onNodeMouseEnter:g,onNodeMouseMove:S,onNodeMouseLeave:I,onNodeContextMenu:T,onNodeDragStart:M,onNodeDrag:P,onNodeDragStop:X,onEdgeClick:H,onEdgeDoubleClick:lt,onEdgeMouseEnter:ft,onEdgeMouseMove:ut,onEdgeMouseLeave:G,onEdgeContextMenu:q,onPaneClick:nt,onPaneContextMenu:it,onPaneMouseEnter:at,onPaneMouseMove:ct,onPaneMouseLeave:Ct,onSelectionChange:tt,onInit:rt,onMoveStart:Et,onMove:wt,onMoveEnd:pt,onDelete:zt,onBeforeDelete:Mt,onError:Nt,nodesDraggable:Xt,nodesConnectable:At,elementsSelectable:fe,multiSelectionKeyCode:se,selectionOnDrag:he,selectionMode:ye,connectionMode:Fe,connectionRadius:ke,connectOnClick:Xe,isValidConnection:Ye,defaultEdgeOptions:Ue,snapToGrid:qe,snapGrid:Ce,deleteKeyCode:Kt,panActivationKeyCode:Vt,panOnScroll:ge,panOnScrollMode:cn,panOnScrollSpeed:ln,zoomOnScroll:Yt,zoomOnDoubleClick:Pn,zoomOnPinch:un,preventScrolling:ie,translateExtent:yt,nodeExtent:Ee,autoPanOnNodeDrag:Rt,autoPanOnConnect:ht,autoPanSpeed:Jt,edgesReconnectable:Z,elevateNodesOnSelect:It,edgeRouting:ze}),$e=a.useMemo(()=>({...re,edgeLabelContainerRef:Ne,viewportPortalRef:Ge,get nodes(){return e},get edges(){return n}}),[re,e,n]),ce=a.useRef(null),le=a.useRef(null),ue=a.useRef(null),qt=a.useRef(null);a.useEffect(()=>{let Q;const Ht=()=>{const ot=re.cameraRef.current,St=`translate(${ot.x}px, ${ot.y}px) scale(${ot.zoom})`,de=`translate(${ot.x}, ${ot.y}) scale(${ot.zoom})`;ce.current&&(ce.current.style.transform=St),le.current&&le.current.setAttribute("transform",de),ue.current&&(ue.current.style.transform=St),qt.current&&(qt.current.style.transform=St),Q=requestAnimationFrame(Ht)};return Q=requestAnimationFrame(Ht),()=>cancelAnimationFrame(Q)},[re]);const ve=ae.length>0,Ot=me.length>0;return C.jsx(On.Provider,{value:$e,children:C.jsxs("div",{ref:Lt,className:`ric-wrap ${u}`,style:{width:l,height:d,...x},onPointerDown:Se,onPointerMove:Pe,onPointerUp:Le,onDragOver:xt,onDrop:Qt,onDragEnter:Re,onDragLeave:Pt,tabIndex:0,children:[C.jsx("canvas",{ref:ne,className:"ric-canvas"}),!Ie&&C.jsx("div",{className:"ric-loader",children:C.jsx("div",{className:"ric-spinner"})}),Ot&&C.jsx("svg",{className:"ric-edges-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:C.jsx("g",{ref:le,children:me.map(Q=>C.jsx(qr,{edge:Q,edgeType:Ut[Q.type],nodes:e,reconnectable:Z},Q.id))})}),ve&&C.jsx("div",{ref:ce,className:"ric-nodes-overlay",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:10},children:ae.map(Q=>C.jsx(Fr,{node:Q,nodeType:ee[Q.type]},Q.id))}),C.jsx("div",{ref:Q=>{Ne.current=Q,ue.current=Q},className:"ric-edge-labels",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:5}}),C.jsx("div",{ref:Q=>{Ge.current=Q,qt.current=Q},className:"ric-viewport-portal",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:6}}),Bt&&C.jsx("div",{className:"ric-hint",children:jt}),hn&&C.jsxs("div",{className:"ric-info",children:["world: (",_t.wx,", ",_t.wy,")   zoom: ",_t.zoom,"x",_t.nodeCount>0&&C.jsxs(C.Fragment,{children:["   nodes: ",_t.nodeCount]}),_t.edgeCount>0&&C.jsxs(C.Fragment,{children:["   edges: ",_t.edgeCount]})]}),C.jsx(Jn,{selectionKeyCode:se||"Shift",selectionMode:ye||"partial"}),xe]})})}function lo({children:t}){return t}function cr(t,e){const n=[],r=new Map,s=[];for(const o of t)if(o.type==="add")s.push(o);else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const i=r.get(o.id);i?i.push(o):r.set(o.id,[o])}for(const o of e){const i=r.get(o.id);if(!i){n.push(o);continue}if(i[0].type==="remove")continue;if(i[0].type==="replace"){n.push({...i[0].item});continue}const l={...o};for(const d of i)uo(d,l);n.push(l)}for(const o of s)o.index!==void 0?n.splice(o.index,0,{...o.item}):n.push({...o.item});return n}function uo(t,e){switch(t.type){case"select":e.selected=t.selected;break;case"position":t.position!==void 0&&(e.position=t.position),t.dragging!==void 0&&(e.dragging=t.dragging);break;case"dimensions":t.dimensions!==void 0&&(e.measured={...t.dimensions},(t.setAttributes===!0||t.setAttributes==="width")&&(e.width=t.dimensions.width),(t.setAttributes===!0||t.setAttributes==="height")&&(e.height=t.dimensions.height)),t.handleBounds!==void 0&&(e.handleBounds=t.handleBounds);break}}function lr(t,e){return cr(t,e)}function ur(t,e){return cr(t,e)}function fo(t,e){return!t.source||!t.target?(console.warn("addEdge: source and target are required"),e):e.some(r=>r.source===t.source&&r.target===t.target&&(r.sourceHandle||null)===(t.sourceHandle||null)&&(r.targetHandle||null)===(t.targetHandle||null))?e:[...e,{id:t.id||`e-${t.source}-${t.target}`,...t}]}function ho(t){const[e,n]=a.useState(t),r=a.useCallback(s=>n(o=>lr(s,o)),[]);return[e,n,r]}function yo(t){const[e,n]=a.useState(t),r=a.useCallback(s=>n(o=>ur(s,o)),[]);return[e,n,r]}function dr(){const t=dt(),e=a.useCallback(()=>[...t.nodesRef.current],[t]),n=a.useCallback(()=>[...t.edgesRef.current],[t]),r=a.useCallback(m=>t.nodesRef.current.find(h=>h.id===m),[t]),s=a.useCallback(m=>t.edgesRef.current.find(h=>h.id===m),[t]),o=a.useCallback(m=>{var h,p,g,S;if(typeof m=="function"){const I=m(t.nodesRef.current);(p=(h=t.onNodesChangeRef).current)==null||p.call(h,[...t.nodesRef.current.map(T=>({id:T.id,type:"remove"})),...I.map(T=>({type:"add",item:T}))])}else(S=(g=t.onNodesChangeRef).current)==null||S.call(g,[...t.nodesRef.current.map(I=>({id:I.id,type:"remove"})),...m.map(I=>({type:"add",item:I}))])},[t]),i=a.useCallback(m=>{var h,p,g,S;if(typeof m=="function"){const I=m(t.edgesRef.current);(p=(h=t.onEdgesChangeRef).current)==null||p.call(h,[...t.edgesRef.current.map(T=>({id:T.id,type:"remove"})),...I.map(T=>({type:"add",item:T}))])}else(S=(g=t.onEdgesChangeRef).current)==null||S.call(g,[...t.edgesRef.current.map(I=>({id:I.id,type:"remove"})),...m.map(I=>({type:"add",item:I}))])},[t]),l=a.useCallback(m=>{var p,g;const h=Array.isArray(m)?m:[m];(g=(p=t.onNodesChangeRef).current)==null||g.call(p,h.map(S=>({type:"add",item:S})))},[t]),d=a.useCallback(m=>{var p,g;const h=Array.isArray(m)?m:[m];(g=(p=t.onEdgesChangeRef).current)==null||g.call(p,h.map(S=>({type:"add",item:S})))},[t]),u=a.useCallback(({nodes:m=[],edges:h=[]})=>{if(m.length&&t.onNodesChangeRef.current){t.onNodesChangeRef.current(m.map(g=>({id:g.id,type:"remove"})));const p=qn(m,t.edgesRef.current);p.length&&t.onEdgesChangeRef.current&&t.onEdgesChangeRef.current(p.map(g=>({id:g.id,type:"remove"})))}h.length&&t.onEdgesChangeRef.current&&t.onEdgesChangeRef.current(h.map(p=>({id:p.id,type:"remove"})))},[t]),x=a.useCallback(()=>{const m=t.cameraRef.current;return{x:m.x,y:m.y,zoom:m.zoom}},[t]),b=a.useCallback((m,h)=>{t.cameraRef.current={x:m.x??t.cameraRef.current.x,y:m.y??t.cameraRef.current.y,zoom:m.zoom??t.cameraRef.current.zoom},t.sendCamera()},[t]),N=a.useCallback(()=>t.cameraRef.current.zoom,[t]),k=a.useCallback(m=>{const h=t.cameraRef.current,p=t.wrapRef.current;if(!p)return;const g=p.getBoundingClientRect(),S=g.width/2,I=g.height/2,T=1.2;h.x=S-(S-h.x)*T,h.y=I-(I-h.y)*T,h.zoom=Math.min(t.zoomMax,h.zoom*T),t.sendCamera()},[t]),R=a.useCallback(m=>{const h=t.cameraRef.current,p=t.wrapRef.current;if(!p)return;const g=p.getBoundingClientRect(),S=g.width/2,I=g.height/2,T=1/1.2;h.x=S-(S-h.x)*T,h.y=I-(I-h.y)*T,h.zoom=Math.max(t.zoomMin,h.zoom*T),t.sendCamera()},[t]),B=a.useCallback(m=>{const h=t.cameraRef.current,p=t.wrapRef.current;if(!p)return;const g=p.getBoundingClientRect(),S=g.width/2,I=g.height/2,T=m/h.zoom;h.x=S-(S-h.x)*T,h.y=I-(I-h.y)*T,h.zoom=Math.min(t.zoomMax,Math.max(t.zoomMin,m)),t.sendCamera()},[t]),E=a.useCallback((m={})=>{const h=t.nodesRef.current;if(!h.length)return;const p=t.wrapRef.current;if(!p)return;const g=p.getBoundingClientRect(),S=m.padding??.1,I=m.nodes?h.filter(P=>m.nodes.some(X=>X.id===P.id)):h;if(!I.length)return;const T=Ve(I),M=Je(T,g.width,g.height,S);m.maxZoom&&(M.zoom=Math.min(M.zoom,m.maxZoom)),m.minZoom&&(M.zoom=Math.max(M.zoom,m.minZoom)),t.cameraRef.current=M,t.sendCamera()},[t]),z=a.useCallback((m,h,p={})=>{const g=t.wrapRef.current;if(!g)return;const S=g.getBoundingClientRect(),I=p.zoom??t.cameraRef.current.zoom;t.cameraRef.current={x:S.width/2-m*I,y:S.height/2-h*I,zoom:I},t.sendCamera()},[t]),W=a.useCallback(m=>t.screenToWorld(m.x,m.y),[t]),D=a.useCallback(m=>{const h=t.cameraRef.current,p=t.wrapRef.current;if(!p)return{x:0,y:0};const g=p.getBoundingClientRect();return{x:m.x*h.zoom+h.x+g.left,y:m.y*h.zoom+h.y+g.top}},[t]);return{getNodes:e,getEdges:n,getNode:r,getEdge:s,setNodes:o,setEdges:i,addNodes:l,addEdges:d,deleteElements:u,getViewport:x,setViewport:b,getZoom:N,zoomIn:k,zoomOut:R,zoomTo:B,fitView:E,setCenter:z,screenToFlowPosition:W,flowToScreenPosition:D}}function go(){return dt().nodes}function xo(){return dt().edges}function po(){return dt().viewport}function mo(){return dt().connection}function vo(t){const e=dt(),n=Array.isArray(t)?t:[t];return a.useMemo(()=>n.map(r=>{const s=e.nodes.find(o=>o.id===r);return s?{id:s.id,type:s.type,data:s.data}:null}).filter(Boolean),[e.nodes,...n])}function bo(t){const e=dt();return a.useMemo(()=>e.edges.filter(n=>n.source===t||n.target===t),[e.edges,t])}function wo({nodeId:t,type:e,handleId:n}){const r=dt();return a.useMemo(()=>r.edges.filter(s=>e==="source"?s.source===t&&(n?s.sourceHandle===n:!0):s.target===t&&(n?s.targetHandle===n:!0)),[r.edges,t,e,n])}function Mo({onChange:t,onStart:e,onEnd:n}){const r=dt(),s=a.useRef(t),o=a.useRef(e),i=a.useRef(n);a.useEffect(()=>{s.current=t},[t]),a.useEffect(()=>{o.current=e},[e]),a.useEffect(()=>{i.current=n},[n]),a.useEffect(()=>{const l=d=>{var u;(u=s.current)==null||u.call(s,{x:d.x,y:d.y,zoom:d.zoom})};return r.viewportListeners.add(l),()=>r.viewportListeners.delete(l)},[r])}function Ro({onChange:t}){const e=dt(),n=a.useRef(t);a.useEffect(()=>{n.current=t},[t]),a.useEffect(()=>{const r=s=>{var o;(o=n.current)==null||o.call(n,s)};return e.selectionListeners.add(r),()=>e.selectionListeners.delete(r)},[e])}function ko(t){const[e,n]=a.useState(!1),r=Array.isArray(t)?t:[t];return a.useEffect(()=>{const s=i=>{r.includes(i.key)&&n(!0)},o=i=>{r.includes(i.key)&&n(!1)};return window.addEventListener("keydown",s),window.addEventListener("keyup",o),()=>{window.removeEventListener("keydown",s),window.removeEventListener("keyup",o)}},[r.join(",")]),e}function Co(){const t=dt();return a.useCallback(e=>{var n;(n=t.workerRef.current)==null||n.postMessage({type:"nodes",data:{nodes:[...t.nodesRef.current]}})},[t])}function Eo(t={}){return dt().nodes.length>0}function zo(t){const e=dt();return a.useMemo(()=>e.nodes.find(n=>n.id===t)||void 0,[e.nodes,t])}function No(t){const e=dt();return typeof t=="function"?t(e):e}function Io(){const t=dt();return a.useMemo(()=>({getState:()=>t,setState:()=>{console.warn("[infinite-canvas] setState on storeApi is not supported. Use onNodesChange/onEdgesChange instead.")}}),[t])}const pn=160,mn=60;function So({width:t=200,height:e=150,nodeColor:n="#3b82f6",nodeStrokeColor:r="#fff",maskColor:s="rgba(0,0,0,0.1)",style:o={},className:i=""}){const l=dt(),d=a.useRef(null),u=a.useRef(null),x=a.useCallback(()=>{const b=d.current;if(!b)return;const N=b.getContext("2d"),k=window.devicePixelRatio||1;b.width=t*k,b.height=e*k,N.scale(k,k),N.clearRect(0,0,t,e);const R=l.nodesRef.current;if(!R.length)return;let B=1/0,E=1/0,z=-1/0,W=-1/0;for(const M of R){const P=M.width||pn,X=M.height||mn;M.position.x<B&&(B=M.position.x),M.position.y<E&&(E=M.position.y),M.position.x+P>z&&(z=M.position.x+P),M.position.y+X>W&&(W=M.position.y+X)}const D=40;B-=D,E-=D,z+=D,W+=D;const m=z-B,h=W-E,p=Math.min(t/m,e/h),g=(t-m*p)/2,S=(e-h*p)/2;for(const M of R){if(M.hidden)continue;const P=M.width||pn,X=M.height||mn,H=(M.position.x-B)*p+g,lt=(M.position.y-E)*p+S,ft=P*p,ut=X*p;N.fillStyle=M.selected?"#f59e0b":typeof n=="function"?n(M):n,N.fillRect(H,lt,Math.max(ft,2),Math.max(ut,2))}const I=l.cameraRef.current,T=l.wrapRef.current;if(T){const M=T.getBoundingClientRect(),P=-I.x/I.zoom,X=-I.y/I.zoom,H=M.width/I.zoom,lt=M.height/I.zoom;N.fillStyle=s,N.fillRect(0,0,t,e);const ft=(P-B)*p+g,ut=(X-E)*p+S,G=H*p,q=lt*p;N.clearRect(ft,ut,G,q);for(const nt of R){if(nt.hidden)continue;const it=nt.width||pn,at=nt.height||mn,ct=(nt.position.x-B)*p+g,Ct=(nt.position.y-E)*p+S;N.fillStyle=nt.selected?"#f59e0b":typeof n=="function"?n(nt):n,N.fillRect(ct,Ct,Math.max(it*p,2),Math.max(at*p,2))}N.strokeStyle="#3b82f6",N.lineWidth=1.5,N.strokeRect(ft,ut,G,q)}},[l,t,e,n,r,s]);return a.useEffect(()=>{let b=!0;function N(){b&&(x(),u.current=requestAnimationFrame(N))}const k=setInterval(()=>{cancelAnimationFrame(u.current),u.current=requestAnimationFrame(N)},66);return x(),()=>{b=!1,clearInterval(k),cancelAnimationFrame(u.current)}},[x]),C.jsx("canvas",{ref:d,className:`ric-minimap ${i}`,style:{position:"absolute",bottom:30,right:10,width:t,height:e,borderRadius:4,border:"1px solid rgba(0,0,0,0.1)",background:"rgba(255,255,255,0.9)",pointerEvents:"none",...o}})}function Po(){return C.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[C.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),C.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function Lo(){return C.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:C.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function $o(){return C.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:C.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}function To(){return C.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[C.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),C.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function Bo(){return C.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[C.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),C.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})}function He({children:t,className:e="",...n}){return C.jsx("button",{className:`ric-controls-button ${e}`,style:Do,...n,children:t})}function jo({showZoom:t=!0,showFitView:e=!0,showInteractive:n=!1,fitViewOptions:r,onZoomIn:s,onZoomOut:o,onFitView:i,onInteractiveChange:l,position:d="bottom-left",orientation:u="vertical",style:x={},className:b="","aria-label":N="Canvas controls",children:k}){const R=dt(),{zoomIn:B,zoomOut:E,fitView:z,getZoom:W}=dr(),[D,m]=a.useState(!0),h=W()<=R.zoomMin,p=W()>=R.zoomMax,g=a.useCallback(()=>{B(),s==null||s()},[B,s]),S=a.useCallback(()=>{E(),o==null||o()},[E,o]),I=a.useCallback(()=>{z(r||{padding:.1}),i==null||i()},[z,r,i]),T=a.useCallback(()=>{const P=!D;m(P),l==null||l(P)},[D,l]),M={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:30,left:10},"bottom-right":{bottom:30,right:10},"bottom-center":{bottom:30,left:"50%",transform:"translateX(-50%)"}}[d]||{bottom:30,left:10};return C.jsxs("div",{className:`ric-controls ${b}`,style:{position:"absolute",display:"flex",flexDirection:u==="horizontal"?"row":"column",gap:2,zIndex:5,...M,...x},role:"toolbar","aria-label":N,children:[t&&C.jsxs(C.Fragment,{children:[C.jsx(He,{onClick:g,disabled:p,title:"Zoom in","aria-label":"Zoom in",className:"ric-controls-zoomin",children:C.jsx(Po,{})}),C.jsx(He,{onClick:S,disabled:h,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:C.jsx(Lo,{})})]}),e&&C.jsx(He,{onClick:I,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:C.jsx($o,{})}),n&&C.jsx(He,{onClick:T,title:D?"Lock interactivity":"Unlock interactivity","aria-label":D?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:D?C.jsx(Bo,{}):C.jsx(To,{})}),k]})}const Do={width:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid rgba(0,0,0,0.12)",borderRadius:4,background:"#fff",cursor:"pointer",fontSize:16,lineHeight:1,color:"#333",padding:0},Ho=a.memo(jo);function Ao({variant:t="lines",gap:e=40,size:n=1,color:r,style:s={},className:o=""}){const i=dt();return i.workerRef.current&&i.workerRef.current.postMessage({type:"background",data:{variant:t,gap:e,size:n,color:r}}),null}function _o({position:t="top-left",style:e={},className:n="",children:r}){const s={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:10,left:10},"bottom-right":{bottom:10,right:10},"bottom-center":{bottom:10,left:"50%",transform:"translateX(-50%)"}}[t]||{top:10,left:10};return C.jsx("div",{className:`ric-panel ${n}`,style:{position:"absolute",zIndex:5,pointerEvents:"all",...s,...e},onPointerDown:o=>o.stopPropagation(),children:r})}function Wo({minWidth:t=10,minHeight:e=10,maxWidth:n=1/0,maxHeight:r=1/0,isVisible:s=!0,handleStyle:o={},lineStyle:i={},color:l="#3b82f6",onResizeStart:d,onResize:u,onResizeEnd:x}){const b=a.useContext(_e),N=dt(),k=a.useRef(null),R=a.useCallback((z,W)=>{z.stopPropagation(),z.preventDefault();const D=N.nodesRef.current.find(p=>p.id===b);if(!D)return;k.current={direction:W,startX:z.clientX,startY:z.clientY,width:D.width||160,height:D.height||60},d==null||d(z,{width:k.current.width,height:k.current.height});const m=p=>{var X,H;if(!k.current)return;const g=k.current,S=N.cameraRef.current,I=(p.clientX-g.startX)/S.zoom,T=(p.clientY-g.startY)/S.zoom;let M=g.width,P=g.height;g.direction.includes("e")&&(M=Math.min(n,Math.max(t,g.width+I))),g.direction.includes("w")&&(M=Math.min(n,Math.max(t,g.width-I))),g.direction.includes("s")&&(P=Math.min(r,Math.max(e,g.height+T))),g.direction.includes("n")&&(P=Math.min(r,Math.max(e,g.height-T))),(H=(X=N.onNodesChangeRef).current)==null||H.call(X,[{id:b,type:"dimensions",dimensions:{width:M,height:P},setAttributes:!0}]),u==null||u(p,{width:M,height:P})},h=p=>{k.current=null,x==null||x(p,{}),window.removeEventListener("pointermove",m),window.removeEventListener("pointerup",h)};window.addEventListener("pointermove",m),window.addEventListener("pointerup",h)},[b,N,t,e,n,r,d,u,x]);if(!s)return null;const B=8,E={position:"absolute",width:B,height:B,background:l,border:"1px solid #fff",borderRadius:2,zIndex:20,...o};return C.jsxs(C.Fragment,{children:[C.jsx("div",{style:{...E,bottom:-B/2,right:-B/2,cursor:"nwse-resize"},onPointerDown:z=>R(z,"se")}),C.jsx("div",{style:{...E,bottom:-B/2,left:-B/2,cursor:"nesw-resize"},onPointerDown:z=>R(z,"sw")}),C.jsx("div",{style:{...E,top:-B/2,right:-B/2,cursor:"nesw-resize"},onPointerDown:z=>R(z,"ne")}),C.jsx("div",{style:{...E,top:-B/2,left:-B/2,cursor:"nwse-resize"},onPointerDown:z=>R(z,"nw")}),C.jsx("div",{style:{...E,top:"50%",right:-B/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:z=>R(z,"e")}),C.jsx("div",{style:{...E,top:"50%",left:-B/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:z=>R(z,"w")}),C.jsx("div",{style:{...E,left:"50%",top:-B/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:z=>R(z,"n")}),C.jsx("div",{style:{...E,left:"50%",bottom:-B/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:z=>R(z,"s")})]})}function Fo({isVisible:t,position:e="top",offset:n=10,align:r="center",children:s,style:o={},className:i=""}){const l=a.useContext(_e),u=dt().nodes.find(N=>N.id===l);if(!(t!==void 0?t:u==null?void 0:u.selected))return null;const b={top:{bottom:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginBottom:n},bottom:{top:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginTop:n},left:{right:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginRight:n},right:{left:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginLeft:n}}[e]||{};return C.jsx("div",{className:`ric-node-toolbar ${i}`,style:{position:"absolute",zIndex:1e3,pointerEvents:"all",...b,...o},onPointerDown:N=>N.stopPropagation(),children:s})}function Xo({isVisible:t=!1,x:e=0,y:n=0,alignX:r="center",alignY:s="center",children:o,style:i={},className:l=""}){if(!t)return null;const d=r==="center"?"-50%":r==="right"?"-100%":"0",u=s==="center"?"-50%":s==="bottom"?"-100%":"0";return C.jsx("div",{className:`ric-edge-toolbar ${l}`,style:{position:"absolute",left:e,top:n,transform:`translate(${d}, ${u})`,zIndex:1e3,pointerEvents:"all",...i},children:o})}function Yo({children:t}){var r;const n=(r=dt().edgeLabelContainerRef)==null?void 0:r.current;return n?Xn.createPortal(t,n):null}function Uo({children:t}){var r;const n=(r=dt().viewportPortalRef)==null?void 0:r.current;return n?Xn.createPortal(t,n):null}function fr({fromX:t,fromY:e,toX:n,toY:r,fromPosition:s="right",toPosition:o="left",connectionLineType:i="default",connectionLineStyle:l,connectionLineComponent:d}){if(d)return C.jsx(d,{fromX:t,fromY:e,toX:n,toY:r,fromPosition:s,toPosition:o});let u;switch(i){case"straight":[u]=kn({sourceX:t,sourceY:e,targetX:n,targetY:r});break;case"step":[u]=tn({sourceX:t,sourceY:e,targetX:n,targetY:r,sourcePosition:s,targetPosition:o,borderRadius:0});break;case"smoothstep":[u]=tn({sourceX:t,sourceY:e,targetX:n,targetY:r,sourcePosition:s,targetPosition:o});break;case"simplebezier":[u]=En({sourceX:t,sourceY:e,targetX:n,targetY:r});break;default:[u]=Cn({sourceX:t,sourceY:e,targetX:n,targetY:r,sourcePosition:s,targetPosition:o});break}return C.jsx("path",{d:u,fill:"none",className:"ric-connection-line",stroke:"#b1b1b7",strokeWidth:1.5,style:l})}fr.displayName="ConnectionLine";const qo=a.memo(fr);exports.Background=Ao;exports.BaseEdge=We;exports.BezierEdge=Rn;exports.ConnectionLine=qo;exports.ControlButton=He;exports.Controls=Ho;exports.DefaultNode=Zr;exports.EdgeLabelRenderer=Yo;exports.EdgeText=sr;exports.EdgeToolbar=Xo;exports.GroupNode=rr;exports.Handle=Ae;exports.InfiniteCanvas=co;exports.InfiniteCanvasProvider=lo;exports.InputNode=er;exports.MiniMap=So;exports.NodeResizer=Wo;exports.NodeToolbar=Fo;exports.OutputNode=nr;exports.Panel=_o;exports.SelectionBox=Jn;exports.SimpleBezierEdge=Sn;exports.SmoothStepEdge=In;exports.StepEdge=ar;exports.StraightEdge=Nn;exports.ViewportPortal=Uo;exports.addEdge=fo;exports.applyEdgeChanges=ur;exports.applyNodeChanges=lr;exports.boxToRect=Lr;exports.buildObstacles=zn;exports.clampPosition=bn;exports.computeRoutedEdges=oo;exports.getBezierEdgeCenter=Or;exports.getBezierPath=Cn;exports.getBoundsOfBoxes=$r;exports.getConnectedEdges=qn;exports.getEdgeCenter=Qr;exports.getIncomers=Nr;exports.getNodeDimensions=Mn;exports.getNodesBounds=Ve;exports.getNodesInside=Sr;exports.getOutgoers=Ir;exports.getOverlappingArea=Tr;exports.getRoutedLabelPosition=an;exports.getSimpleBezierPath=En;exports.getSmoothStepPath=tn;exports.getStraightPath=kn;exports.getViewportForBounds=Je;exports.isEdge=zr;exports.isNode=Er;exports.nodeToRect=Br;exports.reconnectEdge=Kr;exports.rectToBox=Pr;exports.routeSinglePath=so;exports.routedPointsToPath=sn;exports.snapPosition=vn;exports.useConnection=mo;exports.useEdges=xo;exports.useEdgesState=yo;exports.useHandleConnections=wo;exports.useInfiniteCanvas=Zn;exports.useInternalNode=zo;exports.useKeyPress=ko;exports.useNodeConnections=bo;exports.useNodeId=_r;exports.useNodes=go;exports.useNodesData=vo;exports.useNodesInitialized=Eo;exports.useNodesState=ho;exports.useOnSelectionChange=Ro;exports.useOnViewportChange=Mo;exports.useReactFlow=dr;exports.useStore=No;exports.useStoreApi=Io;exports.useUpdateNodeInternals=Co;exports.useViewport=po;