@infinit-canvas/react 0.1.20 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/react-infinite-canvas.cjs +459 -456
- package/dist/react-infinite-canvas.js +2535 -2518
- package/package.json +1 -1
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("react/jsx-runtime"),
|
|
2
|
-
function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("react/jsx-runtime"),a=require("react"),pr=require("react-dom"),mr=160,vr=60;function Xr(e){return e&&typeof e=="object"&&"position"in e&&"data"in e}function Ur(e){return e&&typeof e=="object"&&"source"in e&&"target"in e}function br(e,t){const n=typeof e=="string"?new Set([e]):new Set(Array.isArray(e)?e.map(r=>r.id):[e.id]);return t.filter(r=>n.has(r.source)||n.has(r.target))}function Or(e,t,n){const r=typeof e=="string"?e:e.id,i=new Set;for(const o of n)o.target===r&&i.add(o.source);return t.filter(o=>i.has(o.id))}function qr(e,t,n){const r=typeof e=="string"?e:e.id,i=new Set;for(const o of n)o.source===r&&i.add(o.target);return t.filter(o=>i.has(o.id))}function Mn(e){if(!e.length)return{x:0,y:0,width:0,height:0};let t=1/0,n=1/0,r=-1/0,i=-1/0;for(const o of e){const c=o.position.x,f=o.position.y,m=o.width||mr,d=o.height||vr;c<t&&(t=c),f<n&&(n=f),c+m>r&&(r=c+m),f+d>i&&(i=f+d)}return{x:t,y:n,width:r-t,height:i-n}}function Yt(e,t,n,r=.1){const i=e.width*(1+r*2),o=e.height*(1+r*2),c=Math.min(t/i,n/o,1),f=e.x+e.width/2,m=e.y+e.height/2;return{x:t/2-f*c,y:n/2-m*c,zoom:c}}function Zn(e,t){return{x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}}function Gn(e,t){return{x:Math.min(Math.max(e.x,t[0][0]),t[1][0]),y:Math.min(Math.max(e.y,t[0][1]),t[1][1])}}function Vn(e){var t,n;return{width:e.width||((t=e.measured)==null?void 0:t.width)||mr,height:e.height||((n=e.measured)==null?void 0:n.height)||vr}}function Zr(e,t,n={x:0,y:0,zoom:1},r=!1){const i=t.x,o=t.y,c=t.x+t.width,f=t.y+t.height;return e.filter(m=>{const{width:d,height:h}=Vn(m),b=m.position.x,S=m.position.y,C=b+d,z=S+h;return r?b<c&&C>i&&S<f&&z>o:b>=i&&C<=c&&S>=o&&z<=f})}function Gr(e){return{x:e.x,y:e.y,x2:e.x+e.width,y2:e.y+e.height}}function Qr(e){return{x:e.x,y:e.y,width:e.x2-e.x,height:e.y2-e.y}}function Jr(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}}function Kr(e,t){const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return n*r}function Vr(e){const{width:t,height:n}=Vn(e);return{x:e.position.x,y:e.position.y,width:t,height:n}}const wr=`var Pa = null, r = null, ir = 0, lr = 0, M = { x: 0, y: 0, zoom: 1 }, X = [], C = [], G = [], F = !1, Zt = 40, Ct = !1, Fr = "lines", ua = 1, Ze = null, oe = null, Mr = null, Ge = {}, ei = {}, ie = {}, Ie = {}, le = 0, L = 160, B = 60, qa = 8, Do = 5;
|
|
2
|
+
function y(a) {
|
|
3
3
|
return a._absolutePosition || a.position;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
5
|
+
function ci(a, e, t, i, l) {
|
|
6
6
|
if (a.x !== void 0 && a.y !== void 0)
|
|
7
7
|
return { x: e + a.x, y: t + a.y };
|
|
8
8
|
var o = a.position || (a.type === "source" ? "right" : "left");
|
|
9
9
|
switch (o) {
|
|
10
10
|
case "top":
|
|
11
|
-
return { x: e +
|
|
11
|
+
return { x: e + i / 2, y: t };
|
|
12
12
|
case "bottom":
|
|
13
|
-
return { x: e +
|
|
13
|
+
return { x: e + i / 2, y: t + l };
|
|
14
14
|
case "left":
|
|
15
|
-
return { x: e, y: t +
|
|
15
|
+
return { x: e, y: t + l / 2 };
|
|
16
16
|
case "right":
|
|
17
|
-
return { x: e +
|
|
17
|
+
return { x: e + i, y: t + l / 2 };
|
|
18
18
|
default:
|
|
19
|
-
return { x: e +
|
|
19
|
+
return { x: e + i, y: t + l / 2 };
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
function
|
|
22
|
+
function ti(a) {
|
|
23
23
|
var e = a.width || L, t = a.height || B;
|
|
24
24
|
if (a.handles && a.handles.length > 0)
|
|
25
|
-
return a.handles.map(function(
|
|
26
|
-
var g =
|
|
27
|
-
return { id:
|
|
25
|
+
return a.handles.map(function(u) {
|
|
26
|
+
var g = ci(u, y(a).x, y(a).y, e, t);
|
|
27
|
+
return { id: u.id || null, type: u.type, x: g.x, y: g.y, position: u.position };
|
|
28
28
|
});
|
|
29
|
-
var
|
|
30
|
-
function
|
|
31
|
-
switch (
|
|
29
|
+
var i = a.targetPosition || "left", l = a.sourcePosition || "right", o = y(a);
|
|
30
|
+
function f(u) {
|
|
31
|
+
switch (u) {
|
|
32
32
|
case "top":
|
|
33
33
|
return { x: o.x + e / 2, y: o.y };
|
|
34
34
|
case "bottom":
|
|
@@ -41,30 +41,30 @@ function tl(a) {
|
|
|
41
41
|
return { x: o.x + e, y: o.y + t / 2 };
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
var
|
|
44
|
+
var h = f(i), x = f(l);
|
|
45
45
|
return [
|
|
46
|
-
{ id: null, type: "target", x:
|
|
47
|
-
{ id: null, type: "source", x: x.x, y: x.y, position:
|
|
46
|
+
{ id: null, type: "target", x: h.x, y: h.y, position: i },
|
|
47
|
+
{ id: null, type: "source", x: x.x, y: x.y, position: l }
|
|
48
48
|
];
|
|
49
49
|
}
|
|
50
|
-
var Wt = {},
|
|
51
|
-
function
|
|
52
|
-
|
|
50
|
+
var Wt = {}, ne = !0;
|
|
51
|
+
function Vi(a) {
|
|
52
|
+
ne && (Wt = {}, ne = !1);
|
|
53
53
|
var e = Wt[a.id];
|
|
54
|
-
return e || (e =
|
|
54
|
+
return e || (e = ti(a), Wt[a.id] = e, e);
|
|
55
55
|
}
|
|
56
56
|
function Ke(a, e, t) {
|
|
57
|
-
for (var
|
|
58
|
-
if (l
|
|
57
|
+
for (var i = Vi(a), l = 0; l < i.length; l++)
|
|
58
|
+
if (i[l].type === e)
|
|
59
59
|
if (t) {
|
|
60
|
-
if (l
|
|
60
|
+
if (i[l].id === t) return i[l];
|
|
61
61
|
} else
|
|
62
|
-
return l
|
|
63
|
-
var o = a.width || L,
|
|
64
|
-
return e === "source" ? { x:
|
|
62
|
+
return i[l];
|
|
63
|
+
var o = a.width || L, f = a.height || B;
|
|
64
|
+
return e === "source" ? { x: y(a).x + o, y: y(a).y + f / 2 } : { x: y(a).x, y: y(a).y + f / 2 };
|
|
65
65
|
}
|
|
66
66
|
var k = {};
|
|
67
|
-
function
|
|
67
|
+
function Kt() {
|
|
68
68
|
k = {
|
|
69
69
|
grid: F ? "rgba(255,255,255,0.07)" : "rgba(0,0,0,0.07)",
|
|
70
70
|
origin: F ? "rgba(255,255,255,0.2)" : "rgba(0,0,0,0.15)",
|
|
@@ -87,54 +87,54 @@ function bt() {
|
|
|
87
87
|
connectionLine: "#3b82f6"
|
|
88
88
|
}, Ia = !0;
|
|
89
89
|
}
|
|
90
|
-
|
|
91
|
-
var
|
|
92
|
-
function
|
|
93
|
-
|
|
94
|
-
for (var a = 0; a <
|
|
95
|
-
for (var e =
|
|
96
|
-
for (var
|
|
97
|
-
var x =
|
|
98
|
-
|
|
90
|
+
Kt();
|
|
91
|
+
var Ni = ["#534AB7", "#0F6E56", "#993C1D", "#185FA5"], te = 8, Di = "500 11px system-ui, sans-serif", Oi = "400 11px system-ui, sans-serif", ji = "10px monospace", Oo = "500 13px system-ui, sans-serif", Yi = "400 11px system-ui, sans-serif", Ur = 400, fe = {}, be = !0;
|
|
92
|
+
function Xi() {
|
|
93
|
+
fe = {};
|
|
94
|
+
for (var a = 0; a < X.length; a++)
|
|
95
|
+
for (var e = X[a], t = Math.floor(e.x / Ur), i = Math.floor(e.y / Ur), l = Math.floor((e.x + e.w) / Ur), o = Math.floor((e.y + e.h) / Ur), f = t; f <= l; f++)
|
|
96
|
+
for (var h = i; h <= o; h++) {
|
|
97
|
+
var x = f + "," + h;
|
|
98
|
+
fe[x] || (fe[x] = []), fe[x].push(a);
|
|
99
99
|
}
|
|
100
100
|
be = !1;
|
|
101
101
|
}
|
|
102
|
-
function jo(a, e, t,
|
|
103
|
-
be &&
|
|
104
|
-
for (var
|
|
105
|
-
for (var v =
|
|
106
|
-
var
|
|
107
|
-
if (
|
|
108
|
-
for (var
|
|
109
|
-
var
|
|
110
|
-
|
|
102
|
+
function jo(a, e, t, i) {
|
|
103
|
+
be && Xi();
|
|
104
|
+
for (var l = {}, o = [], f = Math.floor(a / Ur), h = Math.floor(e / Ur), x = Math.floor(t / Ur), u = Math.floor(i / Ur), g = f; g <= x; g++)
|
|
105
|
+
for (var v = h; v <= u; v++) {
|
|
106
|
+
var s = g + "," + v, d = fe[s];
|
|
107
|
+
if (d)
|
|
108
|
+
for (var n = 0; n < d.length; n++) {
|
|
109
|
+
var T = d[n];
|
|
110
|
+
l[T] || (l[T] = !0, o.push(T));
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
return o;
|
|
114
114
|
}
|
|
115
|
-
var
|
|
116
|
-
function
|
|
117
|
-
|
|
115
|
+
var cr = 500, ve = {}, sa = !0;
|
|
116
|
+
function $t() {
|
|
117
|
+
ve = {};
|
|
118
118
|
for (var a = 0; a < C.length; a++) {
|
|
119
119
|
var e = C[a];
|
|
120
120
|
if (!e.hidden)
|
|
121
|
-
for (var t =
|
|
122
|
-
for (var g =
|
|
123
|
-
var v =
|
|
124
|
-
|
|
121
|
+
for (var t = y(e), i = e.width || L, l = e.height || B, o = Math.floor(t.x / cr), f = Math.floor(t.y / cr), h = Math.floor((t.x + i) / cr), x = Math.floor((t.y + l) / cr), u = o; u <= h; u++)
|
|
122
|
+
for (var g = f; g <= x; g++) {
|
|
123
|
+
var v = u + "," + g;
|
|
124
|
+
ve[v] || (ve[v] = []), ve[v].push(a);
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
sa = !1;
|
|
128
128
|
}
|
|
129
|
-
function
|
|
130
|
-
sa &&
|
|
131
|
-
for (var
|
|
132
|
-
for (var v =
|
|
133
|
-
var
|
|
134
|
-
if (
|
|
135
|
-
for (var
|
|
136
|
-
var
|
|
137
|
-
|
|
129
|
+
function oi(a, e, t, i) {
|
|
130
|
+
sa && $t();
|
|
131
|
+
for (var l = {}, o = [], f = Math.floor(a / cr), h = Math.floor(e / cr), x = Math.floor(t / cr), u = Math.floor(i / cr), g = f; g <= x; g++)
|
|
132
|
+
for (var v = h; v <= u; v++) {
|
|
133
|
+
var s = g + "," + v, d = ve[s];
|
|
134
|
+
if (d)
|
|
135
|
+
for (var n = 0; n < d.length; n++) {
|
|
136
|
+
var T = d[n];
|
|
137
|
+
l[T] || (l[T] = !0, o.push(T));
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
return o;
|
|
@@ -149,37 +149,37 @@ function Je() {
|
|
|
149
149
|
function Yo(a) {
|
|
150
150
|
return na && Je(), da[a];
|
|
151
151
|
}
|
|
152
|
-
var
|
|
153
|
-
function
|
|
154
|
-
|
|
155
|
-
for (var a = 0; a <
|
|
156
|
-
var e =
|
|
157
|
-
|
|
152
|
+
var Br = {}, Qe = !0;
|
|
153
|
+
function Hi() {
|
|
154
|
+
Br = {};
|
|
155
|
+
for (var a = 0; a < G.length; a++) {
|
|
156
|
+
var e = G[a];
|
|
157
|
+
Br[e.source] || (Br[e.source] = []), Br[e.source].push(a), e.source !== e.target && (Br[e.target] || (Br[e.target] = []), Br[e.target].push(a));
|
|
158
158
|
}
|
|
159
159
|
Qe = !1;
|
|
160
160
|
}
|
|
161
|
-
var ha = null,
|
|
162
|
-
function
|
|
161
|
+
var ha = null, ii = 0, li = 0, fi = "", Ia = !0;
|
|
162
|
+
function pi(a) {
|
|
163
163
|
ha || (ha = new OffscreenCanvas(1, 1));
|
|
164
164
|
var e = Math.ceil(a), t = Math.ceil(a);
|
|
165
165
|
if (e < 2 || t < 2) return !1;
|
|
166
|
-
e > 512 && (e = 512), t > 512 && (t = 512), ha.width = e, ha.height = t,
|
|
167
|
-
var
|
|
168
|
-
|
|
169
|
-
var
|
|
166
|
+
e > 512 && (e = 512), t > 512 && (t = 512), ha.width = e, ha.height = t, ii = e, li = a, fi = Fr, Ia = !1;
|
|
167
|
+
var i = ha.getContext("2d");
|
|
168
|
+
i.clearRect(0, 0, e, t);
|
|
169
|
+
var l = Ze || k.grid;
|
|
170
170
|
if (Fr === "dots") {
|
|
171
|
-
|
|
171
|
+
i.fillStyle = l;
|
|
172
172
|
var o = ua * M.zoom;
|
|
173
|
-
|
|
173
|
+
i.beginPath(), i.arc(0, 0, o, 0, 6.2832), i.fill();
|
|
174
174
|
} else if (Fr === "cross") {
|
|
175
|
-
|
|
176
|
-
var
|
|
177
|
-
|
|
175
|
+
i.strokeStyle = l, i.lineWidth = ua;
|
|
176
|
+
var f = 3 * M.zoom;
|
|
177
|
+
i.beginPath(), i.moveTo(-f, 0), i.lineTo(f, 0), i.moveTo(0, -f), i.lineTo(0, f), i.stroke();
|
|
178
178
|
} else
|
|
179
|
-
|
|
179
|
+
i.beginPath(), i.strokeStyle = l, i.lineWidth = ua * 0.5, i.moveTo(0.5, 0), i.lineTo(0.5, t), i.moveTo(0, 0.5), i.lineTo(e, 0.5), i.stroke();
|
|
180
180
|
return !0;
|
|
181
181
|
}
|
|
182
|
-
var Xo = 0, Pt = 0, Ho = 0, po = 0,
|
|
182
|
+
var Xo = 0, Pt = 0, Ho = 0, po = 0, bt = 0, he = !1;
|
|
183
183
|
console.log("[worker] script loaded v2 - FRESH");
|
|
184
184
|
self.postMessage({ type: "ping", data: { status: "alive" } });
|
|
185
185
|
self.onmessage = function(a) {
|
|
@@ -187,62 +187,65 @@ self.onmessage = function(a) {
|
|
|
187
187
|
var e = a.data.type, t = a.data.data;
|
|
188
188
|
switch (e) {
|
|
189
189
|
case "init":
|
|
190
|
-
Pa = t.canvas, r = Pa.getContext("2d"),
|
|
191
|
-
return
|
|
192
|
-
}), console.log("[worker] init done — canvas:",
|
|
190
|
+
Pa = t.canvas, r = Pa.getContext("2d"), ir = t.width, lr = t.height, Pa.width = ir, Pa.height = lr, M = t.camera, X = t.cards || [], C = t.nodes || [], G = t.edges || [], F = t.dark, t.gridSize && (Zt = t.gridSize), t.edgeRouting !== void 0 && (Ga = !!t.edgeRouting), Kt(), be = !0, na = !0, sa = !0, ne = !0, Qe = !0, he = G.some(function(D) {
|
|
191
|
+
return D.animated;
|
|
192
|
+
}), console.log("[worker] init done — canvas:", ir, "x", lr, "| cards:", X.length, "| nodes:", C.length, "| edges:", G.length, "| routing:", Ga), $e(), self.postMessage({ type: "ready" }), he && ri();
|
|
193
193
|
break;
|
|
194
194
|
case "resize":
|
|
195
|
-
|
|
195
|
+
ir = t.width, lr = t.height, Pa.width = ir, Pa.height = lr, Ia = !0, $e();
|
|
196
196
|
break;
|
|
197
197
|
case "camera":
|
|
198
198
|
M = t.camera, Ia = !0, $();
|
|
199
199
|
break;
|
|
200
200
|
case "cards":
|
|
201
|
-
|
|
201
|
+
X = t.cards, be = !0, $();
|
|
202
202
|
break;
|
|
203
203
|
case "nodes":
|
|
204
|
-
C = t.nodes,
|
|
204
|
+
C = t.nodes, le = 0;
|
|
205
|
+
for (var i = 0; i < C.length; i++)
|
|
206
|
+
C[i].dragging && le++;
|
|
207
|
+
na = !0, sa = !0, ne = !0, $(), It(), self.postMessage({ type: "nodesProcessed", data: { nodeCount: C.length } });
|
|
205
208
|
break;
|
|
206
209
|
case "nodePositions":
|
|
207
210
|
na && Je();
|
|
208
|
-
for (var l = t.updates,
|
|
209
|
-
var
|
|
210
|
-
|
|
211
|
+
for (var l = t.updates, o = 0, f = 0; f < l.length; f++) {
|
|
212
|
+
var h = l[f], x = da[h.id];
|
|
213
|
+
x && (x.position = h.position, h._absolutePosition && (x._absolutePosition = h._absolutePosition), h.width !== void 0 && (x.width = h.width), h.height !== void 0 && (x.height = h.height), h.dragging && !x.dragging ? o++ : !h.dragging && x.dragging && o--, x.dragging = h.dragging, x.selected = h.selected);
|
|
211
214
|
}
|
|
212
|
-
|
|
215
|
+
le = Math.max(0, le + o), ne = !0, l.length > 10 && (sa = !0), $();
|
|
213
216
|
break;
|
|
214
217
|
case "nodeSelections":
|
|
215
218
|
na && Je();
|
|
216
|
-
for (var
|
|
217
|
-
var
|
|
218
|
-
|
|
219
|
+
for (var u = t.selections, g = 0; g < u.length; g++) {
|
|
220
|
+
var v = u[g], s = da[v.id];
|
|
221
|
+
s && (s.selected = v.selected);
|
|
219
222
|
}
|
|
220
223
|
$();
|
|
221
224
|
break;
|
|
222
225
|
case "edgeSelections":
|
|
223
|
-
for (var
|
|
224
|
-
for (var
|
|
225
|
-
if (
|
|
226
|
-
|
|
226
|
+
for (var d = t.selections, n = 0; n < d.length; n++) {
|
|
227
|
+
for (var T = d[n], I = null, A = 0; A < G.length; A++)
|
|
228
|
+
if (G[A].id === T.id) {
|
|
229
|
+
I = G[A];
|
|
227
230
|
break;
|
|
228
231
|
}
|
|
229
|
-
|
|
232
|
+
I && (I.selected = T.selected);
|
|
230
233
|
}
|
|
231
234
|
$();
|
|
232
235
|
break;
|
|
233
236
|
case "edges":
|
|
234
|
-
|
|
235
|
-
return
|
|
236
|
-
}),
|
|
237
|
+
G = t.edges, Qe = !0, he = G.some(function(D) {
|
|
238
|
+
return D.animated;
|
|
239
|
+
}), he && ri(), $(), It();
|
|
237
240
|
break;
|
|
238
241
|
case "theme":
|
|
239
|
-
F = t.dark,
|
|
242
|
+
F = t.dark, Kt(), $();
|
|
240
243
|
break;
|
|
241
244
|
case "connecting":
|
|
242
245
|
oe = t, $();
|
|
243
246
|
break;
|
|
244
247
|
case "selectionBox":
|
|
245
|
-
|
|
248
|
+
Mr = t, $();
|
|
246
249
|
break;
|
|
247
250
|
case "background":
|
|
248
251
|
t.variant && (Fr = t.variant), t.gap && (Zt = t.gap), t.size && (ua = t.size), Ze = t.color || null, Ia = !0, $();
|
|
@@ -251,7 +254,7 @@ self.onmessage = function(a) {
|
|
|
251
254
|
Ge = t.bitmaps || {}, $();
|
|
252
255
|
break;
|
|
253
256
|
case "nodeBitmaps":
|
|
254
|
-
|
|
257
|
+
ei = t.cache || {}, ie = t.keys || {}, $();
|
|
255
258
|
break;
|
|
256
259
|
case "nodeTypeConfigs":
|
|
257
260
|
Ie = t.configs || {}, $();
|
|
@@ -260,14 +263,14 @@ self.onmessage = function(a) {
|
|
|
260
263
|
if (Ga = !!t.enabled, Ga)
|
|
261
264
|
It();
|
|
262
265
|
else {
|
|
263
|
-
for (var
|
|
264
|
-
Z
|
|
266
|
+
for (var Z = 0; Z < G.length; Z++)
|
|
267
|
+
G[Z]._routedPoints = null;
|
|
265
268
|
$();
|
|
266
269
|
}
|
|
267
270
|
break;
|
|
268
271
|
}
|
|
269
|
-
} catch (
|
|
270
|
-
console.error("[worker] error:",
|
|
272
|
+
} catch (D) {
|
|
273
|
+
console.error("[worker] error:", D);
|
|
271
274
|
}
|
|
272
275
|
};
|
|
273
276
|
function $() {
|
|
@@ -276,166 +279,166 @@ function $() {
|
|
|
276
279
|
}));
|
|
277
280
|
}
|
|
278
281
|
var qt = !1;
|
|
279
|
-
function
|
|
282
|
+
function ri() {
|
|
280
283
|
if (qt) return;
|
|
281
284
|
qt = !0;
|
|
282
285
|
function a() {
|
|
283
|
-
if (!
|
|
286
|
+
if (!he) {
|
|
284
287
|
qt = !1;
|
|
285
288
|
return;
|
|
286
289
|
}
|
|
287
|
-
|
|
290
|
+
bt = (bt + 0.5) % 20, $e(), requestAnimationFrame(a);
|
|
288
291
|
}
|
|
289
292
|
requestAnimationFrame(a);
|
|
290
293
|
}
|
|
291
|
-
function
|
|
294
|
+
function ai(a, e) {
|
|
292
295
|
var t = 6;
|
|
293
296
|
a.moveTo(e[0].x, e[0].y);
|
|
294
|
-
for (var
|
|
295
|
-
var
|
|
296
|
-
if (
|
|
297
|
-
var g = o.x -
|
|
298
|
-
a.lineTo(o.x - g /
|
|
297
|
+
for (var i = 1; i < e.length - 1; i++) {
|
|
298
|
+
var l = e[i - 1], o = e[i], f = e[i + 1], h = Math.abs(o.x - l.x) + Math.abs(o.y - l.y), x = Math.abs(f.x - o.x) + Math.abs(f.y - o.y), u = Math.min(t, h / 2, x / 2);
|
|
299
|
+
if (u > 0.5) {
|
|
300
|
+
var g = o.x - l.x, v = o.y - l.y, s = f.x - o.x, d = f.y - o.y, n = Math.sqrt(g * g + v * v) || 1, T = Math.sqrt(s * s + d * d) || 1;
|
|
301
|
+
a.lineTo(o.x - g / n * u, o.y - v / n * u), a.quadraticCurveTo(o.x, o.y, o.x + s / T * u, o.y + d / T * u);
|
|
299
302
|
} else
|
|
300
303
|
a.lineTo(o.x, o.y);
|
|
301
304
|
}
|
|
302
305
|
a.lineTo(e[e.length - 1].x, e[e.length - 1].y);
|
|
303
306
|
}
|
|
304
|
-
function
|
|
307
|
+
function rl(a) {
|
|
305
308
|
for (var e = 0, t = 1; t < a.length; t++)
|
|
306
309
|
e += Math.abs(a[t].x - a[t - 1].x) + Math.abs(a[t].y - a[t - 1].y);
|
|
307
|
-
for (var
|
|
308
|
-
var o = Math.abs(a[
|
|
309
|
-
if (
|
|
310
|
-
var
|
|
310
|
+
for (var i = e / 2, l = 1; l < a.length; l++) {
|
|
311
|
+
var o = Math.abs(a[l].x - a[l - 1].x) + Math.abs(a[l].y - a[l - 1].y);
|
|
312
|
+
if (i <= o) {
|
|
313
|
+
var f = o > 0 ? i / o : 0;
|
|
311
314
|
return {
|
|
312
|
-
x: a[
|
|
313
|
-
y: a[
|
|
315
|
+
x: a[l - 1].x + (a[l].x - a[l - 1].x) * f,
|
|
316
|
+
y: a[l - 1].y + (a[l].y - a[l - 1].y) * f
|
|
314
317
|
};
|
|
315
318
|
}
|
|
316
|
-
|
|
319
|
+
i -= o;
|
|
317
320
|
}
|
|
318
321
|
return { x: a[0].x, y: a[0].y };
|
|
319
322
|
}
|
|
320
|
-
function
|
|
321
|
-
var
|
|
322
|
-
return { cp1x:
|
|
323
|
+
function Jt(a, e, t, i) {
|
|
324
|
+
var l = Math.abs(t - a), o = Math.max(50, l * 0.5), f = a + o, h = e, x = t - o, u = i;
|
|
325
|
+
return { cp1x: f, cp1y: h, cp2x: x, cp2y: u };
|
|
323
326
|
}
|
|
324
|
-
function
|
|
325
|
-
var
|
|
326
|
-
return { x:
|
|
327
|
+
function al(a, e, t, i) {
|
|
328
|
+
var l = Jt(a, e, t, i), o = 0.5, f = 1 - o, h = f * f * f * a + 3 * f * f * o * l.cp1x + 3 * f * o * o * l.cp2x + o * o * o * t, x = f * f * f * e + 3 * f * f * o * l.cp1y + 3 * f * o * o * l.cp2y + o * o * o * i;
|
|
329
|
+
return { x: h, y: x };
|
|
327
330
|
}
|
|
328
|
-
var Ga = !0,
|
|
329
|
-
function
|
|
330
|
-
sa &&
|
|
331
|
-
for (var o = Math.min(a, t) - 20,
|
|
332
|
-
var
|
|
333
|
-
|
|
331
|
+
var Ga = !0, Qt = !1, Gt = !1;
|
|
332
|
+
function vi(a, e, t, i, l) {
|
|
333
|
+
sa && $t();
|
|
334
|
+
for (var o = Math.min(a, t) - 20, f = Math.min(e, i) - 20, h = Math.max(a, t) + 20, x = Math.max(e, i) + 20, u = oi(o, f, h, x), g = [], v = 0; v < u.length; v++) {
|
|
335
|
+
var s = C[u[v]];
|
|
336
|
+
s.hidden || l[s.id] || s.type !== "group" && g.push(s);
|
|
334
337
|
}
|
|
335
338
|
return g;
|
|
336
339
|
}
|
|
337
|
-
function
|
|
338
|
-
for (var
|
|
339
|
-
var
|
|
340
|
-
if (t > x.y && t < x.y + g && o > x.x &&
|
|
340
|
+
function Ar(a, e, t, i) {
|
|
341
|
+
for (var l = Math.min(a, e), o = Math.max(a, e), f = 0; f < i.length; f++) {
|
|
342
|
+
var h = i[f], x = y(h), u = h.width || L, g = h.height || B;
|
|
343
|
+
if (t > x.y && t < x.y + g && o > x.x && l < x.x + u) return h;
|
|
341
344
|
}
|
|
342
345
|
return null;
|
|
343
346
|
}
|
|
344
|
-
function
|
|
345
|
-
for (var
|
|
346
|
-
var
|
|
347
|
-
if (a > x.x && a < x.x +
|
|
347
|
+
function _r(a, e, t, i) {
|
|
348
|
+
for (var l = Math.min(e, t), o = Math.max(e, t), f = 0; f < i.length; f++) {
|
|
349
|
+
var h = i[f], x = y(h), u = h.width || L, g = h.height || B;
|
|
350
|
+
if (a > x.x && a < x.x + u && o > x.y && l < x.y + g) return h;
|
|
348
351
|
}
|
|
349
352
|
return null;
|
|
350
353
|
}
|
|
351
|
-
function
|
|
352
|
-
if (Ga && !(
|
|
353
|
-
|
|
354
|
-
for (var a = 20, e = !1, t = 0; t <
|
|
355
|
-
var
|
|
356
|
-
if (!
|
|
357
|
-
var
|
|
358
|
-
if (!(
|
|
359
|
-
var o = da[
|
|
360
|
-
if (!(!o || !
|
|
361
|
-
var
|
|
362
|
-
|
|
363
|
-
var
|
|
364
|
-
jr[
|
|
365
|
-
var
|
|
366
|
-
Math.min(v,
|
|
367
|
-
Math.min(
|
|
368
|
-
Math.max(v,
|
|
369
|
-
Math.max(
|
|
354
|
+
function el() {
|
|
355
|
+
if (Ga && !(!Qt || G.length === 0 || C.length === 0)) {
|
|
356
|
+
Qt = !1, na && Je(), sa && $t();
|
|
357
|
+
for (var a = 20, e = !1, t = 0; t < G.length; t++) {
|
|
358
|
+
var i = G[t];
|
|
359
|
+
if (!i._customRendered) {
|
|
360
|
+
var l = i.type || "default";
|
|
361
|
+
if (!(l === "bezier" || l === "simplebezier" || l === "default")) {
|
|
362
|
+
var o = da[i.source], f = da[i.target];
|
|
363
|
+
if (!(!o || !f || o.hidden || f.hidden)) {
|
|
364
|
+
var h = Ke(o, "source", i.sourceHandle), x = Ke(f, "target", i.targetHandle), u = h.position || "right", g = x.position || "left", v = h.x, s = h.y, d = x.x, n = x.y, T = v, I = s, A = d, Z = n;
|
|
365
|
+
u === "right" ? T += a : u === "left" ? T -= a : u === "bottom" ? I += a : u === "top" && (I -= a), g === "right" ? A += a : g === "left" ? A -= a : g === "bottom" ? Z += a : g === "top" && (Z -= a);
|
|
366
|
+
var D = y(o), Vr = y(f), Nr = o.width || L, Dr = o.height || B, Or = f.width || L, ya = f.height || B, jr = {};
|
|
367
|
+
jr[i.source] = !0, jr[i.target] = !0;
|
|
368
|
+
var H = vi(
|
|
369
|
+
Math.min(v, d) - Nr,
|
|
370
|
+
Math.min(s, n) - Dr,
|
|
371
|
+
Math.max(v, d) + Or,
|
|
372
|
+
Math.max(s, n) + ya,
|
|
370
373
|
jr
|
|
371
374
|
);
|
|
372
|
-
|
|
373
|
-
var xa =
|
|
375
|
+
H.push(o), H.push(f);
|
|
376
|
+
var xa = u === "left" || u === "right", Za = g === "left" || g === "right", P = null;
|
|
374
377
|
if (xa && Za) {
|
|
375
|
-
var
|
|
376
|
-
if (
|
|
377
|
-
|
|
378
|
-
var Ka =
|
|
378
|
+
var W, hr = u === "right" && T < A, Fe = u === "left" && T > A;
|
|
379
|
+
if (hr || Fe) {
|
|
380
|
+
W = (T + A) / 2;
|
|
381
|
+
var Ka = _r(W, s, n, H);
|
|
379
382
|
if (Ka) {
|
|
380
|
-
var ga =
|
|
381
|
-
|
|
383
|
+
var ga = y(Ka), Ma = Ka.width || L;
|
|
384
|
+
W = W < ga.x + Ma / 2 ? ga.x - a : ga.x + Ma + a;
|
|
382
385
|
}
|
|
383
386
|
} else
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
var Er =
|
|
387
|
+
u === "right" ? W = Math.max(D.x + Nr, Vr.x + Or) + a : W = Math.min(D.x, Vr.x) - a;
|
|
388
|
+
P = [{ x: v, y: s }, { x: T, y: s }, { x: W, y: s }, { x: W, y: n }, { x: A, y: n }, { x: d, y: n }];
|
|
389
|
+
var Er = Ar(W, A, n, H);
|
|
387
390
|
if (Er) {
|
|
388
|
-
var ka =
|
|
389
|
-
|
|
391
|
+
var ka = y(Er), ma = Er.height || B, Ta = ka.y - a, Yr = ka.y + ma + a, Xr = Math.abs(s - Ta) <= Math.abs(s - Yr) ? Ta : Yr;
|
|
392
|
+
P = [{ x: v, y: s }, { x: T, y: s }, { x: W, y: s }, { x: W, y: Xr }, { x: A, y: Xr }, { x: A, y: n }, { x: d, y: n }];
|
|
390
393
|
}
|
|
391
394
|
} else if (!xa && !Za) {
|
|
392
|
-
var b,
|
|
393
|
-
if (
|
|
394
|
-
b = (
|
|
395
|
-
var Lr =
|
|
395
|
+
var b, ue = u === "bottom" && I < Z, ba = u === "top" && I > Z;
|
|
396
|
+
if (ue || ba) {
|
|
397
|
+
b = (I + Z) / 2;
|
|
398
|
+
var Lr = Ar(v, d, b, H);
|
|
396
399
|
if (Lr) {
|
|
397
|
-
var Sr =
|
|
400
|
+
var Sr = y(Lr), Ra = Lr.height || B;
|
|
398
401
|
b = b < Sr.y + Ra / 2 ? Sr.y - a : Sr.y + Ra + a;
|
|
399
402
|
}
|
|
400
403
|
} else
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
var Hr =
|
|
404
|
+
u === "bottom" ? b = Math.max(D.y + Dr, Vr.y + ya) + a : b = Math.min(D.y, Vr.y) - a;
|
|
405
|
+
P = [{ x: v, y: s }, { x: v, y: I }, { x: v, y: b }, { x: d, y: b }, { x: d, y: Z }, { x: d, y: n }];
|
|
406
|
+
var Hr = _r(d, b, Z, H);
|
|
404
407
|
if (Hr) {
|
|
405
|
-
var za =
|
|
406
|
-
|
|
408
|
+
var za = y(Hr), Ja = Hr.height || B, wa = za.y - a, Ba = za.y + Ja + a, Aa = Math.abs(b - wa) <= Math.abs(b - Ba) ? wa : Ba;
|
|
409
|
+
P = [{ x: v, y: s }, { x: v, y: I }, { x: v, y: b }, { x: d, y: b }, { x: d, y: Aa }, { x: A, y: Aa }, { x: A, y: n }, { x: d, y: n }];
|
|
407
410
|
}
|
|
408
411
|
} else if (xa) {
|
|
409
|
-
|
|
410
|
-
var Cr =
|
|
412
|
+
P = [{ x: v, y: s }, { x: T, y: s }, { x: d, y: s }, { x: d, y: Z }, { x: d, y: n }];
|
|
413
|
+
var Cr = _r(d, s, Z, H);
|
|
411
414
|
if (Cr) {
|
|
412
|
-
var
|
|
413
|
-
|
|
415
|
+
var fr = y(Cr), kr = Cr.width || L, Qa = Math.abs(v - fr.x + a) <= Math.abs(v - fr.x - kr - a) ? fr.x - a : fr.x + kr + a;
|
|
416
|
+
P = [{ x: v, y: s }, { x: T, y: s }, { x: Qa, y: s }, { x: Qa, y: n }, { x: d, y: n }, { x: d, y: Z }, { x: d, y: n }];
|
|
414
417
|
}
|
|
415
|
-
var pr =
|
|
418
|
+
var pr = Ar(T, d, s, H);
|
|
416
419
|
if (pr) {
|
|
417
|
-
var Wr =
|
|
418
|
-
|
|
420
|
+
var Wr = y(pr), _a = pr.height || B, p = Math.abs(n - Wr.y + a) <= Math.abs(n - Wr.y - _a - a) ? Wr.y - a : Wr.y + _a + a;
|
|
421
|
+
P = [{ x: v, y: s }, { x: T, y: s }, { x: T, y: p }, { x: d, y: p }, { x: d, y: Z }, { x: d, y: n }];
|
|
419
422
|
}
|
|
420
423
|
} else {
|
|
421
|
-
|
|
422
|
-
var Pr =
|
|
424
|
+
P = [{ x: v, y: s }, { x: v, y: I }, { x: v, y: n }, { x: A, y: n }, { x: d, y: n }];
|
|
425
|
+
var Pr = Ar(v, A, n, H);
|
|
423
426
|
if (Pr) {
|
|
424
|
-
var Ea =
|
|
425
|
-
|
|
427
|
+
var Ea = y(Pr), nr = Pr.height || B, qr = Math.abs(s - Ea.y + a) <= Math.abs(s - Ea.y - nr - a) ? Ea.y - a : Ea.y + nr + a;
|
|
428
|
+
P = [{ x: v, y: s }, { x: v, y: I }, { x: v, y: qr }, { x: A, y: qr }, { x: A, y: n }, { x: d, y: n }];
|
|
426
429
|
}
|
|
427
|
-
var
|
|
428
|
-
if (
|
|
429
|
-
var
|
|
430
|
-
|
|
430
|
+
var mr = _r(v, I, n, H);
|
|
431
|
+
if (mr) {
|
|
432
|
+
var ur = y(mr), $a = mr.width || L, Fa = Math.abs(d - ur.x + a) <= Math.abs(d - ur.x - $a - a) ? ur.x - a : ur.x + $a + a;
|
|
433
|
+
P = [{ x: v, y: s }, { x: v, y: I }, { x: Fa, y: I }, { x: Fa, y: n }, { x: A, y: n }, { x: d, y: n }];
|
|
431
434
|
}
|
|
432
435
|
}
|
|
433
|
-
if (
|
|
434
|
-
for (var ra = [
|
|
435
|
-
var
|
|
436
|
-
(Math.abs(
|
|
436
|
+
if (P) {
|
|
437
|
+
for (var ra = [P[0]], sr = 1; sr < P.length; sr++) {
|
|
438
|
+
var se = ra[ra.length - 1];
|
|
439
|
+
(Math.abs(P[sr].x - se.x) > 0.1 || Math.abs(P[sr].y - se.y) > 0.1) && ra.push(P[sr]);
|
|
437
440
|
}
|
|
438
|
-
|
|
441
|
+
i._routedPoints = ra, e = !0;
|
|
439
442
|
}
|
|
440
443
|
}
|
|
441
444
|
}
|
|
@@ -445,10 +448,10 @@ function ei() {
|
|
|
445
448
|
}
|
|
446
449
|
}
|
|
447
450
|
function It() {
|
|
448
|
-
Ga && (Gt || (Gt = !0,
|
|
451
|
+
Ga && (Gt || (Gt = !0, Qt = !0, requestAnimationFrame(function() {
|
|
449
452
|
Gt = !1;
|
|
450
453
|
try {
|
|
451
|
-
|
|
454
|
+
el();
|
|
452
455
|
} catch (a) {
|
|
453
456
|
console.error("[worker] async routing error:", a);
|
|
454
457
|
}
|
|
@@ -457,81 +460,81 @@ function It() {
|
|
|
457
460
|
function $e() {
|
|
458
461
|
if (r) {
|
|
459
462
|
var a = performance.now();
|
|
460
|
-
r.clearRect(0, 0,
|
|
463
|
+
r.clearRect(0, 0, ir, lr);
|
|
461
464
|
var e = Zt * M.zoom;
|
|
462
465
|
if (e > 2)
|
|
463
466
|
if (Fr === "lines" && e >= 4 && e <= 512) {
|
|
464
|
-
if ((Ia ||
|
|
465
|
-
var t = (M.x % e + e) % e,
|
|
466
|
-
r.save(), r.translate(t,
|
|
467
|
-
var
|
|
468
|
-
|
|
467
|
+
if ((Ia || li !== e || fi !== Fr) && pi(e), ha && ii > 0) {
|
|
468
|
+
var t = (M.x % e + e) % e, i = (M.y % e + e) % e;
|
|
469
|
+
r.save(), r.translate(t, i);
|
|
470
|
+
var l = r.createPattern(ha, "repeat");
|
|
471
|
+
l && (r.fillStyle = l, r.fillRect(-t, -i, ir, lr)), r.restore();
|
|
469
472
|
}
|
|
470
473
|
} else {
|
|
471
|
-
var o = (M.x % e + e) % e,
|
|
474
|
+
var o = (M.x % e + e) % e, f = (M.y % e + e) % e, h = Ze || k.grid;
|
|
472
475
|
if (Fr === "dots") {
|
|
473
|
-
r.fillStyle =
|
|
474
|
-
for (var x = ua * M.zoom,
|
|
475
|
-
for (var g =
|
|
476
|
-
r.beginPath(), r.arc(Math.round(
|
|
476
|
+
r.fillStyle = h;
|
|
477
|
+
for (var x = ua * M.zoom, u = o; u < ir; u += e)
|
|
478
|
+
for (var g = f; g < lr; g += e)
|
|
479
|
+
r.beginPath(), r.arc(Math.round(u), Math.round(g), x, 0, 6.2832), r.fill();
|
|
477
480
|
} else if (Fr === "cross") {
|
|
478
|
-
r.strokeStyle =
|
|
481
|
+
r.strokeStyle = h, r.lineWidth = ua;
|
|
479
482
|
var v = 3 * M.zoom;
|
|
480
483
|
r.beginPath();
|
|
481
|
-
for (var
|
|
482
|
-
for (var
|
|
483
|
-
var
|
|
484
|
-
r.moveTo(
|
|
484
|
+
for (var s = o; s < ir; s += e)
|
|
485
|
+
for (var d = f; d < lr; d += e) {
|
|
486
|
+
var n = Math.round(s), T = Math.round(d);
|
|
487
|
+
r.moveTo(n - v, T), r.lineTo(n + v, T), r.moveTo(n, T - v), r.lineTo(n, T + v);
|
|
485
488
|
}
|
|
486
489
|
r.stroke();
|
|
487
490
|
} else {
|
|
488
|
-
var
|
|
489
|
-
r.beginPath(), r.strokeStyle =
|
|
490
|
-
for (var
|
|
491
|
-
var
|
|
492
|
-
r.moveTo(
|
|
491
|
+
var I = Ze || k.grid;
|
|
492
|
+
r.beginPath(), r.strokeStyle = I, r.lineWidth = ua * 0.5;
|
|
493
|
+
for (var A = o; A < ir; A += e) {
|
|
494
|
+
var Z = Math.round(A) + 0.5;
|
|
495
|
+
r.moveTo(Z, 0), r.lineTo(Z, lr);
|
|
493
496
|
}
|
|
494
|
-
for (var
|
|
495
|
-
var Vr = Math.round(
|
|
496
|
-
r.moveTo(0, Vr), r.lineTo(
|
|
497
|
+
for (var D = f; D < lr; D += e) {
|
|
498
|
+
var Vr = Math.round(D) + 0.5;
|
|
499
|
+
r.moveTo(0, Vr), r.lineTo(ir, Vr);
|
|
497
500
|
}
|
|
498
501
|
r.stroke();
|
|
499
502
|
}
|
|
500
503
|
}
|
|
501
504
|
r.beginPath(), r.arc(M.x, M.y, 4 * M.zoom, 0, 6.2832), r.fillStyle = k.origin, r.fill(), r.save(), r.translate(M.x, M.y), r.scale(M.zoom, M.zoom);
|
|
502
|
-
var Nr = 100,
|
|
503
|
-
if (
|
|
504
|
-
var
|
|
505
|
+
var Nr = 100, Dr = -M.x / M.zoom, Or = -M.y / M.zoom, ya = Dr + ir / M.zoom, jr = Or + lr / M.zoom, H = Dr - Nr, xa = Or - Nr, Za = ya + Nr, P = jr + Nr;
|
|
506
|
+
if (X.length > 0) {
|
|
507
|
+
var W = jo(Dr, Or, ya, jr), hr = W.length, Fe = M.zoom > 0.15, Ka = M.zoom > 0.3, ga = M.zoom > 0.08 && hr < 200;
|
|
505
508
|
if (ga) {
|
|
506
509
|
r.shadowColor = k.cardShadow, r.shadowBlur = 6, r.shadowOffsetY = 2, r.fillStyle = k.cardBg, r.beginPath();
|
|
507
|
-
for (var Ma = 0; Ma <
|
|
508
|
-
var Er =
|
|
510
|
+
for (var Ma = 0; Ma < hr; Ma++) {
|
|
511
|
+
var Er = X[W[Ma]];
|
|
509
512
|
r.roundRect(Er.x, Er.y, Er.w, Er.h, te);
|
|
510
513
|
}
|
|
511
514
|
r.fill(), r.shadowColor = "transparent", r.shadowBlur = 0, r.shadowOffsetY = 0;
|
|
512
515
|
}
|
|
513
516
|
if (!ga) {
|
|
514
517
|
r.fillStyle = k.cardBg, r.beginPath();
|
|
515
|
-
for (var ka = 0; ka <
|
|
516
|
-
var ma =
|
|
518
|
+
for (var ka = 0; ka < hr; ka++) {
|
|
519
|
+
var ma = X[W[ka]];
|
|
517
520
|
r.roundRect(ma.x, ma.y, ma.w, ma.h, te);
|
|
518
521
|
}
|
|
519
522
|
r.fill();
|
|
520
523
|
}
|
|
521
524
|
r.strokeStyle = k.cardBorder, r.lineWidth = 0.5, r.beginPath();
|
|
522
|
-
for (var Ta = 0; Ta <
|
|
523
|
-
var Yr =
|
|
525
|
+
for (var Ta = 0; Ta < hr; Ta++) {
|
|
526
|
+
var Yr = X[W[Ta]];
|
|
524
527
|
r.roundRect(Yr.x, Yr.y, Yr.w, Yr.h, te);
|
|
525
528
|
}
|
|
526
529
|
r.stroke();
|
|
527
|
-
for (var Xr = [{}, {}, {}, {}], b = 0; b <
|
|
528
|
-
var
|
|
529
|
-
Xr[ba].items || (Xr[ba].items = []), Xr[ba].items.push(
|
|
530
|
+
for (var Xr = [{}, {}, {}, {}], b = 0; b < hr; b++) {
|
|
531
|
+
var ue = W[b], ba = ue % 4;
|
|
532
|
+
Xr[ba].items || (Xr[ba].items = []), Xr[ba].items.push(X[ue]);
|
|
530
533
|
}
|
|
531
534
|
for (var Lr = 0; Lr < 4; Lr++) {
|
|
532
535
|
var Sr = Xr[Lr].items;
|
|
533
536
|
if (!(!Sr || Sr.length === 0)) {
|
|
534
|
-
r.fillStyle =
|
|
537
|
+
r.fillStyle = Ni[Lr], r.beginPath();
|
|
535
538
|
for (var Ra = 0; Ra < Sr.length; Ra++) {
|
|
536
539
|
var Hr = Sr[Ra];
|
|
537
540
|
r.roundRect(Hr.x, Hr.y, Hr.w, 30, [te, te, 0, 0]);
|
|
@@ -540,251 +543,251 @@ function $e() {
|
|
|
540
543
|
}
|
|
541
544
|
}
|
|
542
545
|
if (Fe) {
|
|
543
|
-
r.fillStyle = k.titleText, r.font =
|
|
544
|
-
for (var za = 0; za <
|
|
545
|
-
var Ja =
|
|
546
|
+
r.fillStyle = k.titleText, r.font = Di;
|
|
547
|
+
for (var za = 0; za < hr; za++) {
|
|
548
|
+
var Ja = X[W[za]];
|
|
546
549
|
r.fillText(Ja.title, Ja.x + 12, Ja.y + 19);
|
|
547
550
|
}
|
|
548
|
-
r.fillStyle = k.bodyText, r.font =
|
|
549
|
-
for (var wa = 0; wa <
|
|
550
|
-
var Ba =
|
|
551
|
+
r.fillStyle = k.bodyText, r.font = Oi;
|
|
552
|
+
for (var wa = 0; wa < hr; wa++) {
|
|
553
|
+
var Ba = X[W[wa]];
|
|
551
554
|
r.fillText(Ba.body, Ba.x + 12, Ba.y + 52);
|
|
552
555
|
}
|
|
553
556
|
if (Ka) {
|
|
554
|
-
r.fillStyle = k.coordText, r.font =
|
|
555
|
-
for (var Aa = 0; Aa <
|
|
556
|
-
var Cr =
|
|
557
|
+
r.fillStyle = k.coordText, r.font = ji;
|
|
558
|
+
for (var Aa = 0; Aa < hr; Aa++) {
|
|
559
|
+
var Cr = X[W[Aa]];
|
|
557
560
|
r.fillText("(" + Cr.x + ", " + Cr.y + ")", Cr.x + 12, Cr.y + 75);
|
|
558
561
|
}
|
|
559
562
|
}
|
|
560
563
|
}
|
|
561
564
|
}
|
|
562
|
-
var
|
|
565
|
+
var fr = [], kr = null;
|
|
563
566
|
if (C.length > 0)
|
|
564
|
-
if (
|
|
565
|
-
for (var Qa =
|
|
567
|
+
if (kr = {}, C.length > 100)
|
|
568
|
+
for (var Qa = oi(H, xa, Za, P), pr = 0; pr < Qa.length; pr++) {
|
|
566
569
|
var Wr = C[Qa[pr]];
|
|
567
|
-
|
|
570
|
+
kr[Wr.id] = !0, Wr._customRendered || fr.push(Wr);
|
|
568
571
|
}
|
|
569
572
|
else
|
|
570
573
|
for (var _a = 0; _a < C.length; _a++) {
|
|
571
|
-
var
|
|
572
|
-
if (!
|
|
573
|
-
var Pr =
|
|
574
|
-
|
|
574
|
+
var p = C[_a];
|
|
575
|
+
if (!p.hidden) {
|
|
576
|
+
var Pr = p.width || L, Ea = p.height || B;
|
|
577
|
+
y(p).x + Pr < H || y(p).x > Za || y(p).y + Ea < xa || y(p).y > P || (kr[p.id] = !0, p._customRendered || fr.push(p));
|
|
575
578
|
}
|
|
576
579
|
}
|
|
577
|
-
var
|
|
578
|
-
if (
|
|
580
|
+
var nr = fr.length;
|
|
581
|
+
if (G.length > 0 && C.length > 0) {
|
|
579
582
|
let qe = function($r, No) {
|
|
580
583
|
if ($r.length) {
|
|
581
584
|
r.fillStyle = No, r.beginPath();
|
|
582
585
|
for (var St = 0; St < $r.length; St++) {
|
|
583
|
-
var
|
|
584
|
-
r.moveTo(
|
|
586
|
+
var Y = $r[St];
|
|
587
|
+
r.moveTo(Y.x, Y.y), r.lineTo(Y.x - Y.size * Math.cos(Y.angle - 0.5236), Y.y - Y.size * Math.sin(Y.angle - 0.5236)), r.lineTo(Y.x - Y.size * Math.cos(Y.angle + 0.5236), Y.y - Y.size * Math.sin(Y.angle + 0.5236)), r.closePath();
|
|
585
588
|
}
|
|
586
589
|
r.fill();
|
|
587
590
|
}
|
|
588
591
|
};
|
|
589
|
-
var
|
|
590
|
-
Qe &&
|
|
591
|
-
var qr = null,
|
|
592
|
-
if (
|
|
593
|
-
var
|
|
592
|
+
var tl = qe;
|
|
593
|
+
Qe && Hi();
|
|
594
|
+
var qr = null, mr = null, ur = null, $a = [], Fa = [], ra = [], sr = [], se = M.zoom > 0.3, hi = M.zoom > 0.05, aa;
|
|
595
|
+
if (kr && C.length > 100) {
|
|
596
|
+
var de = {};
|
|
594
597
|
aa = [];
|
|
595
|
-
for (var
|
|
596
|
-
var
|
|
597
|
-
if (
|
|
598
|
-
for (var
|
|
599
|
-
var Ve = ce
|
|
600
|
-
|
|
598
|
+
for (var ni in kr) {
|
|
599
|
+
var Ue = Br[ni];
|
|
600
|
+
if (Ue)
|
|
601
|
+
for (var ce = 0; ce < Ue.length; ce++) {
|
|
602
|
+
var Ve = Ue[ce];
|
|
603
|
+
de[Ve] || (de[Ve] = !0, aa.push(Ve));
|
|
601
604
|
}
|
|
602
605
|
}
|
|
603
|
-
for (var
|
|
604
|
-
var
|
|
605
|
-
if ((
|
|
606
|
-
var
|
|
607
|
-
if (
|
|
608
|
-
for (var
|
|
609
|
-
|
|
606
|
+
for (var rr = 0; rr < C.length; rr++) {
|
|
607
|
+
var ye = C[rr];
|
|
608
|
+
if ((ye.dragging || ye.selected) && !kr[ye.id]) {
|
|
609
|
+
var Ua = Br[ye.id];
|
|
610
|
+
if (Ua)
|
|
611
|
+
for (var ca = 0; ca < Ua.length; ca++)
|
|
612
|
+
de[Ua[ca]] || (de[Ua[ca]] = !0, aa.push(Ua[ca]));
|
|
610
613
|
}
|
|
611
614
|
}
|
|
612
615
|
} else {
|
|
613
616
|
aa = [];
|
|
614
|
-
for (var Ne = 0; Ne <
|
|
617
|
+
for (var Ne = 0; Ne < G.length; Ne++) aa.push(Ne);
|
|
615
618
|
}
|
|
616
|
-
for (var
|
|
617
|
-
var O =
|
|
619
|
+
for (var De = 0; De < aa.length; De++) {
|
|
620
|
+
var O = G[aa[De]], ea = Yo(O.source), ta = Yo(O.target);
|
|
618
621
|
if (!(!ea || !ta) && !(ea.hidden || ta.hidden) && !O._customRendered) {
|
|
619
|
-
var
|
|
620
|
-
|
|
622
|
+
var xe = Ke(ea, "source", O.sourceHandle), ge = Ke(ta, "target", O.targetHandle), _ = xe.x, w = xe.y, R = ge.x, z = ge.y, dr = O.type || "default", Ft = O.selected, Ut = O.animated, J;
|
|
623
|
+
Ft ? (mr || (mr = new Path2D()), J = mr) : Ut ? (ur || (ur = new Path2D()), J = ur) : (qr || (qr = new Path2D()), J = qr);
|
|
621
624
|
var Q = O._routedPoints;
|
|
622
625
|
if (Q && Q.length >= 2)
|
|
623
|
-
|
|
624
|
-
else if (
|
|
625
|
-
J.moveTo(
|
|
626
|
-
else if (
|
|
626
|
+
ai(J, Q);
|
|
627
|
+
else if (dr === "straight")
|
|
628
|
+
J.moveTo(_, w), J.lineTo(R, z);
|
|
629
|
+
else if (dr === "step" || dr === "smoothstep")
|
|
627
630
|
try {
|
|
628
|
-
var
|
|
629
|
-
|
|
630
|
-
var
|
|
631
|
+
var ar = xe.position || "right", La = ge.position || "left", m = 20, U = _, j = w, c = R, er = z;
|
|
632
|
+
ar === "right" ? U += m : ar === "left" ? U -= m : ar === "bottom" ? j += m : ar === "top" && (j -= m), La === "right" ? c += m : La === "left" ? c -= m : La === "bottom" ? er += m : La === "top" && (er -= m);
|
|
633
|
+
var Me = y(ea), ke = y(ta), Va = ea.width || L, Na = ea.height || B, ct = ta.width || L, Vt = ta.height || B, Oe = ar === "left" || ar === "right", Nt = La === "left" || La === "right", je = {};
|
|
631
634
|
je[O.source] = !0, je[O.target] = !0;
|
|
632
|
-
var
|
|
633
|
-
Math.min(
|
|
635
|
+
var tr = vi(
|
|
636
|
+
Math.min(_, R) - Va,
|
|
634
637
|
Math.min(w, z) - Na,
|
|
635
|
-
Math.max(
|
|
636
|
-
Math.max(w, z) +
|
|
638
|
+
Math.max(_, R) + ct,
|
|
639
|
+
Math.max(w, z) + Vt,
|
|
637
640
|
je
|
|
638
641
|
);
|
|
639
|
-
|
|
642
|
+
tr.push(ea), tr.push(ta);
|
|
640
643
|
var K = [];
|
|
641
|
-
if (
|
|
642
|
-
var V,
|
|
643
|
-
if (
|
|
644
|
-
V = (
|
|
645
|
-
var Ye =
|
|
644
|
+
if (Oe && Nt) {
|
|
645
|
+
var V, ui = ar === "right" && U < c, si = ar === "left" && U > c;
|
|
646
|
+
if (ui || si) {
|
|
647
|
+
V = (U + c) / 2;
|
|
648
|
+
var Ye = _r(V, w, z, tr);
|
|
646
649
|
if (Ye) {
|
|
647
|
-
var Xe =
|
|
648
|
-
V < Xe.x + Pr / 2 ? V = Xe.x -
|
|
650
|
+
var Xe = y(Ye), Pr = Ye.width || L;
|
|
651
|
+
V < Xe.x + Pr / 2 ? V = Xe.x - m : V = Xe.x + Pr + m;
|
|
649
652
|
}
|
|
650
653
|
} else
|
|
651
|
-
|
|
652
|
-
K = [{ x:
|
|
653
|
-
var He =
|
|
654
|
+
ar === "right" ? V = Math.max(Me.x + Va, ke.x + ct) + m : V = Math.min(Me.x, ke.x) - m;
|
|
655
|
+
K = [{ x: U, y: w }, { x: V, y: w }, { x: V, y: z }, { x: c, y: z }];
|
|
656
|
+
var He = Ar(V, c, z, tr);
|
|
654
657
|
if (He) {
|
|
655
|
-
var Dt =
|
|
658
|
+
var Dt = y(He), di = He.height || B, Ot = Dt.y - m, jt = Dt.y + di + m, Yt = Math.abs(w - Ot) <= Math.abs(w - jt) ? Ot : jt;
|
|
656
659
|
K = [
|
|
657
|
-
{ x:
|
|
660
|
+
{ x: U, y: w },
|
|
658
661
|
{ x: V, y: w },
|
|
659
|
-
{ x: V, y:
|
|
660
|
-
{ x:
|
|
661
|
-
{ x:
|
|
662
|
+
{ x: V, y: Yt },
|
|
663
|
+
{ x: c, y: Yt },
|
|
664
|
+
{ x: c, y: z }
|
|
662
665
|
];
|
|
663
666
|
}
|
|
664
|
-
var pe =
|
|
667
|
+
var pe = Ar(U, V, w, tr);
|
|
665
668
|
if (pe) {
|
|
666
|
-
var
|
|
669
|
+
var Xt = y(pe), yi = pe.height || B, Ht = Xt.y - m, pt = Xt.y + yi + m, ro = Math.abs(z - Ht) <= Math.abs(z - pt) ? Ht : pt;
|
|
667
670
|
K.splice(
|
|
668
671
|
1,
|
|
669
672
|
0,
|
|
670
|
-
{ x:
|
|
671
|
-
{ x: V, y:
|
|
673
|
+
{ x: U, y: ro },
|
|
674
|
+
{ x: V, y: ro }
|
|
672
675
|
), K = K.filter(function($r, No) {
|
|
673
676
|
return !(Math.abs($r.x - V) < 1 && Math.abs($r.y - w) < 1);
|
|
674
|
-
}), K.splice(0, 0, { x:
|
|
677
|
+
}), K.splice(0, 0, { x: U, y: w });
|
|
675
678
|
}
|
|
676
|
-
} else if (!
|
|
677
|
-
var N,
|
|
678
|
-
if (
|
|
679
|
-
N = (
|
|
680
|
-
var rt =
|
|
679
|
+
} else if (!Oe && !Nt) {
|
|
680
|
+
var N, xi = ar === "bottom" && j < er, gi = ar === "top" && j > er;
|
|
681
|
+
if (xi || gi) {
|
|
682
|
+
N = (j + er) / 2;
|
|
683
|
+
var rt = Ar(_, R, N, tr);
|
|
681
684
|
if (rt) {
|
|
682
|
-
var at =
|
|
683
|
-
N < at.y +
|
|
685
|
+
var at = y(rt), ao = rt.height || B;
|
|
686
|
+
N < at.y + ao / 2 ? N = at.y - m : N = at.y + ao + m;
|
|
684
687
|
}
|
|
685
688
|
} else
|
|
686
|
-
|
|
687
|
-
K = [{ x:
|
|
688
|
-
var et =
|
|
689
|
+
ar === "bottom" ? N = Math.max(Me.y + Na, ke.y + Vt) + m : N = Math.min(Me.y, ke.y) - m;
|
|
690
|
+
K = [{ x: _, y: j }, { x: _, y: N }, { x: R, y: N }, { x: R, y: er }];
|
|
691
|
+
var et = _r(_, j, N, tr);
|
|
689
692
|
if (et) {
|
|
690
|
-
var
|
|
693
|
+
var eo = y(et), Mi = et.width || L, to = eo.x - m, oo = eo.x + Mi + m, io = Math.abs(R - to) <= Math.abs(R - oo) ? to : oo;
|
|
691
694
|
K = [
|
|
692
|
-
{ x:
|
|
693
|
-
{ x: io, y:
|
|
695
|
+
{ x: _, y: j },
|
|
696
|
+
{ x: io, y: j },
|
|
694
697
|
{ x: io, y: N },
|
|
695
698
|
{ x: R, y: N },
|
|
696
|
-
{ x: R, y:
|
|
699
|
+
{ x: R, y: er }
|
|
697
700
|
];
|
|
698
701
|
}
|
|
699
|
-
var tt =
|
|
702
|
+
var tt = _r(R, N, er, tr);
|
|
700
703
|
if (tt) {
|
|
701
|
-
var
|
|
704
|
+
var lo = y(tt), ki = tt.height || B, fo = lo.y - m, vo = lo.y + ki + m, mi = Math.abs(N - fo) <= Math.abs(N - vo) ? fo : vo;
|
|
702
705
|
K.splice(
|
|
703
706
|
K.length - 1,
|
|
704
707
|
0,
|
|
705
|
-
{ x:
|
|
708
|
+
{ x: c, y: mi }
|
|
706
709
|
);
|
|
707
710
|
}
|
|
708
|
-
} else if (
|
|
709
|
-
K = [{ x:
|
|
710
|
-
var ot =
|
|
711
|
+
} else if (Oe) {
|
|
712
|
+
K = [{ x: U, y: w }, { x: R, y: w }, { x: R, y: er }];
|
|
713
|
+
var ot = _r(R, w, er, tr);
|
|
711
714
|
if (ot) {
|
|
712
|
-
var
|
|
713
|
-
K = [{ x:
|
|
715
|
+
var ho = y(ot), Ti = ot.width || L, no = ho.x - m, uo = ho.x + Ti + m, so = Math.abs(_ - no) <= Math.abs(_ - uo) ? no : uo;
|
|
716
|
+
K = [{ x: U, y: w }, { x: so, y: w }, { x: so, y: z }, { x: R, y: z }, { x: R, y: er }];
|
|
714
717
|
}
|
|
715
|
-
var
|
|
716
|
-
if (
|
|
717
|
-
var
|
|
718
|
-
K = [{ x:
|
|
718
|
+
var it = Ar(U, R, w, tr);
|
|
719
|
+
if (it) {
|
|
720
|
+
var yo = y(it), Ri = it.height || B, xo = yo.y - m, go = yo.y + Ri + m, Mo = Math.abs(z - xo) <= Math.abs(z - go) ? xo : go;
|
|
721
|
+
K = [{ x: U, y: w }, { x: U, y: Mo }, { x: R, y: Mo }, { x: R, y: er }];
|
|
719
722
|
}
|
|
720
723
|
} else {
|
|
721
|
-
K = [{ x:
|
|
722
|
-
var
|
|
723
|
-
if (
|
|
724
|
-
var
|
|
725
|
-
K = [{ x:
|
|
724
|
+
K = [{ x: _, y: j }, { x: _, y: z }, { x: c, y: z }];
|
|
725
|
+
var lt = Ar(_, c, z, tr);
|
|
726
|
+
if (lt) {
|
|
727
|
+
var ko = y(lt), zi = lt.height || B, mo = ko.y - m, To = ko.y + zi + m, Ro = Math.abs(w - mo) <= Math.abs(w - To) ? mo : To;
|
|
728
|
+
K = [{ x: _, y: j }, { x: _, y: Ro }, { x: c, y: Ro }, { x: c, y: z }];
|
|
726
729
|
}
|
|
727
|
-
var ft =
|
|
730
|
+
var ft = _r(_, j, z, tr);
|
|
728
731
|
if (ft) {
|
|
729
|
-
var
|
|
730
|
-
K = [{ x:
|
|
732
|
+
var zo = y(ft), wi = ft.width || L, wo = zo.x - m, Bo = zo.x + wi + m, Ao = Math.abs(R - wo) <= Math.abs(R - Bo) ? wo : Bo;
|
|
733
|
+
K = [{ x: _, y: j }, { x: Ao, y: j }, { x: Ao, y: z }, { x: c, y: z }];
|
|
731
734
|
}
|
|
732
735
|
}
|
|
733
|
-
for (var oa = [{ x:
|
|
736
|
+
for (var oa = [{ x: _, y: w }], vt = 0; vt < K.length; vt++) oa.push(K[vt]);
|
|
734
737
|
oa.push({ x: R, y: z });
|
|
735
|
-
for (var
|
|
736
|
-
var
|
|
737
|
-
(Math.abs(oa[
|
|
738
|
+
for (var or = [oa[0]], Da = 1; Da < oa.length; Da++) {
|
|
739
|
+
var Oa = or[or.length - 1];
|
|
740
|
+
(Math.abs(oa[Da].x - Oa.x) > 0.1 || Math.abs(oa[Da].y - Oa.y) > 0.1) && or.push(oa[Da]);
|
|
738
741
|
}
|
|
739
|
-
var
|
|
740
|
-
J.moveTo(
|
|
741
|
-
for (var
|
|
742
|
-
if (
|
|
743
|
-
var
|
|
744
|
-
if (Math.abs(
|
|
742
|
+
var _o = dr === "smoothstep" ? 8 : 0;
|
|
743
|
+
J.moveTo(or[0].x, or[0].y);
|
|
744
|
+
for (var rr = 1; rr < or.length; rr++)
|
|
745
|
+
if (_o > 0 && rr > 0 && rr < or.length - 1) {
|
|
746
|
+
var Tr = or[rr - 1], S = or[rr], Gr = or[rr + 1];
|
|
747
|
+
if (Math.abs(Tr.x - S.x) < 0.5 && Math.abs(S.x - Gr.x) < 0.5 || Math.abs(Tr.y - S.y) < 0.5 && Math.abs(S.y - Gr.y) < 0.5)
|
|
745
748
|
J.lineTo(S.x, S.y);
|
|
746
749
|
else {
|
|
747
|
-
var
|
|
748
|
-
Math.abs(
|
|
750
|
+
var me = Math.min(Math.hypot(Tr.x - S.x, Tr.y - S.y) / 2, Math.hypot(S.x - Gr.x, S.y - Gr.y) / 2, _o);
|
|
751
|
+
Math.abs(Tr.y - S.y) < 0.5 ? (J.lineTo(S.x + (Tr.x < Gr.x ? -1 : 1) * me, S.y), J.quadraticCurveTo(S.x, S.y, S.x, S.y + (Tr.y < Gr.y ? 1 : -1) * me)) : (J.lineTo(S.x, S.y + (Tr.y < Gr.y ? -1 : 1) * me), J.quadraticCurveTo(S.x, S.y, S.x + (Tr.x < Gr.x ? 1 : -1) * me, S.y));
|
|
749
752
|
}
|
|
750
753
|
} else
|
|
751
|
-
J.lineTo(
|
|
754
|
+
J.lineTo(or[rr].x, or[rr].y);
|
|
752
755
|
} catch ($r) {
|
|
753
756
|
console.error("[worker] smoothstep error:", $r, "edge:", O.id);
|
|
754
757
|
}
|
|
755
758
|
else {
|
|
756
|
-
var Ir =
|
|
757
|
-
Ir === "right" ? ja += Kr : Ir === "left" ? ja -= Kr : Ir === "bottom" ?
|
|
758
|
-
var
|
|
759
|
-
J.moveTo(
|
|
759
|
+
var Ir = xe.position || "right", Zr = ge.position || "left", Kr = 20, ja = _, Te = w, Ya = R, Re = z;
|
|
760
|
+
Ir === "right" ? ja += Kr : Ir === "left" ? ja -= Kr : Ir === "bottom" ? Te += Kr : Ir === "top" && (Te -= Kr), Zr === "right" ? Ya += Kr : Zr === "left" ? Ya -= Kr : Zr === "bottom" ? Re += Kr : Zr === "top" && (Re -= Kr);
|
|
761
|
+
var Bi = Math.abs(Ya - ja), br = Math.max(50, Bi * 0.5), Ai = ja + (Ir === "left" ? -br : Ir === "right" ? br : 0), _i = Te + (Ir === "top" ? -br : Ir === "bottom" ? br : 0), Ei = Ya + (Zr === "left" ? -br : Zr === "right" ? br : 0), Li = Re + (Zr === "top" ? -br : Zr === "bottom" ? br : 0);
|
|
762
|
+
J.moveTo(_, w), J.lineTo(ja, Te), J.bezierCurveTo(Ai, _i, Ei, Li, Ya, Re), J.lineTo(R, z);
|
|
760
763
|
}
|
|
761
|
-
if (
|
|
762
|
-
var
|
|
764
|
+
if (hi) {
|
|
765
|
+
var Si = 8, Xa;
|
|
763
766
|
if (Q && Q.length >= 2) {
|
|
764
|
-
var
|
|
765
|
-
Xa = Math.atan2(
|
|
766
|
-
} else if (
|
|
767
|
-
Xa = Math.atan2(z - w, R -
|
|
768
|
-
else if (
|
|
767
|
+
var Oa = Q[Q.length - 1], Eo = Q[Q.length - 2];
|
|
768
|
+
Xa = Math.atan2(Oa.y - Eo.y, Oa.x - Eo.x);
|
|
769
|
+
} else if (dr === "straight")
|
|
770
|
+
Xa = Math.atan2(z - w, R - _);
|
|
771
|
+
else if (dr === "step" || dr === "smoothstep")
|
|
769
772
|
Xa = 0;
|
|
770
773
|
else {
|
|
771
|
-
var
|
|
772
|
-
Xa = Math.atan2(z -
|
|
774
|
+
var Lo = Jt(_, w, R, z);
|
|
775
|
+
Xa = Math.atan2(z - Lo.cp2y, R - Lo.cp2x);
|
|
773
776
|
}
|
|
774
|
-
var
|
|
775
|
-
|
|
777
|
+
var So = Q && Q.length >= 2 ? Q[Q.length - 1] : { x: R, y: z }, ht = { x: So.x, y: So.y, angle: Xa, size: Si };
|
|
778
|
+
Ft ? Fa.push(ht) : Ut ? ra.push(ht) : $a.push(ht);
|
|
776
779
|
}
|
|
777
|
-
if (
|
|
780
|
+
if (se && O.label) {
|
|
778
781
|
var Ha;
|
|
779
|
-
Q && Q.length >= 2 ? Ha =
|
|
782
|
+
Q && Q.length >= 2 ? Ha = rl(Q) : dr === "straight" || dr === "step" || dr === "smoothstep" ? Ha = { x: (_ + R) / 2, y: (w + z) / 2 } : Ha = al(_, w, R, z), sr.push({ text: O.label, x: Ha.x, y: Ha.y });
|
|
780
783
|
}
|
|
781
784
|
}
|
|
782
785
|
}
|
|
783
|
-
if (qr && (r.strokeStyle = k.edgeStroke, r.lineWidth = 1.5, r.setLineDash([]), r.stroke(qr)),
|
|
784
|
-
r.font =
|
|
785
|
-
for (var nt = 0; nt <
|
|
786
|
-
var Sa =
|
|
787
|
-
r.fillStyle = F ? "#2a2a2a" : "#ffffff", r.fillRect(Sa.x -
|
|
786
|
+
if (qr && (r.strokeStyle = k.edgeStroke, r.lineWidth = 1.5, r.setLineDash([]), r.stroke(qr)), ur && (r.strokeStyle = k.edgeAnimated, r.lineWidth = 1.5, r.setLineDash([5, 5]), r.lineDashOffset = -bt, r.stroke(ur), r.setLineDash([])), mr && (r.strokeStyle = k.edgeSelected, r.lineWidth = 2.5, r.setLineDash([]), r.stroke(mr)), qe($a, k.edgeStroke), qe(ra, k.edgeAnimated), qe(Fa, k.edgeSelected), sr.length > 0) {
|
|
787
|
+
r.font = Yi, r.textAlign = "center", r.textBaseline = "middle";
|
|
788
|
+
for (var nt = 0; nt < sr.length; nt++) {
|
|
789
|
+
var Sa = sr[nt], Ci = r.measureText(Sa.text), Co = Ci.width + 12;
|
|
790
|
+
r.fillStyle = F ? "#2a2a2a" : "#ffffff", r.fillRect(Sa.x - Co / 2, Sa.y - 9, Co, 18), r.fillStyle = k.nodeText, r.fillText(Sa.text, Sa.x, Sa.y);
|
|
788
791
|
}
|
|
789
792
|
r.textAlign = "start", r.textBaseline = "alphabetic";
|
|
790
793
|
}
|
|
@@ -793,25 +796,25 @@ function $e() {
|
|
|
793
796
|
r.beginPath(), r.strokeStyle = k.connectionLine, r.lineWidth = 2, r.setLineDash([6, 4]);
|
|
794
797
|
var ut = oe._routedPoints;
|
|
795
798
|
if (ut && ut.length >= 2) {
|
|
796
|
-
var
|
|
797
|
-
|
|
799
|
+
var Wo = new Path2D();
|
|
800
|
+
ai(Wo, ut), r.stroke(Wo);
|
|
798
801
|
} else {
|
|
799
|
-
var
|
|
800
|
-
r.moveTo(
|
|
802
|
+
var ze = oe.from, we = oe.to, Be = Jt(ze.x, ze.y, we.x, we.y);
|
|
803
|
+
r.moveTo(ze.x, ze.y), r.bezierCurveTo(Be.cp1x, Be.cp1y, Be.cp2x, Be.cp2y, we.x, we.y), r.stroke();
|
|
801
804
|
}
|
|
802
805
|
r.setLineDash([]);
|
|
803
806
|
}
|
|
804
|
-
if (
|
|
805
|
-
var
|
|
806
|
-
r.fillStyle = F ? "rgba(59,130,246,0.08)" : "rgba(59,130,246,0.06)", r.fillRect(
|
|
807
|
+
if (Mr) {
|
|
808
|
+
var Po = Math.min(Mr.startWorld.x, Mr.endWorld.x), qo = Math.min(Mr.startWorld.y, Mr.endWorld.y), Va = Math.abs(Mr.endWorld.x - Mr.startWorld.x), Na = Math.abs(Mr.endWorld.y - Mr.startWorld.y);
|
|
809
|
+
r.fillStyle = F ? "rgba(59,130,246,0.08)" : "rgba(59,130,246,0.06)", r.fillRect(Po, qo, Va, Na), r.strokeStyle = "#3b82f6", r.lineWidth = 1 / M.zoom, r.setLineDash([]), r.strokeRect(Po, qo, Va, Na);
|
|
807
810
|
}
|
|
808
|
-
if (
|
|
809
|
-
var
|
|
810
|
-
if (
|
|
811
|
+
if (nr > 0) {
|
|
812
|
+
var Go = le > 0, ia = M.zoom > 0.12 && (M.zoom > 0.25 || nr < 500), st = !Go && M.zoom > 0.08 && nr < 200, Wi = !Go && M.zoom > 0.2 && nr < 300, Pi = Object.keys(Ge).length > 0 || Object.keys(ie).length > 0 || Object.keys(Ie).length > 0, Jr = fr, Ae = [], _e = [];
|
|
813
|
+
if (Pi) {
|
|
811
814
|
Jr = [];
|
|
812
|
-
for (var dt = 0; dt <
|
|
813
|
-
var Qr =
|
|
814
|
-
|
|
815
|
+
for (var dt = 0; dt < nr; dt++) {
|
|
816
|
+
var Qr = fr[dt];
|
|
817
|
+
ie[Qr.id] || Qr.type && Ge[Qr.type] ? Ae.push(Qr) : Qr.type && Ie[Qr.type] ? _e.push(Qr) : Jr.push(Qr);
|
|
815
818
|
}
|
|
816
819
|
}
|
|
817
820
|
var pa = Jr.length;
|
|
@@ -819,7 +822,7 @@ function $e() {
|
|
|
819
822
|
r.shadowColor = k.nodeShadow, r.shadowBlur = 6, r.shadowOffsetY = 2, r.fillStyle = k.nodeBg, r.beginPath();
|
|
820
823
|
for (var yt = 0; yt < pa; yt++) {
|
|
821
824
|
var Ee = Jr[yt];
|
|
822
|
-
r.roundRect(
|
|
825
|
+
r.roundRect(y(Ee).x, y(Ee).y, Ee.width || L, Ee.height || B, qa);
|
|
823
826
|
}
|
|
824
827
|
r.fill(), r.shadowColor = "transparent", r.shadowBlur = 0, r.shadowOffsetY = 0;
|
|
825
828
|
}
|
|
@@ -827,113 +830,113 @@ function $e() {
|
|
|
827
830
|
r.fillStyle = k.nodeBg, r.beginPath();
|
|
828
831
|
for (var xt = 0; xt < pa; xt++) {
|
|
829
832
|
var Le = Jr[xt];
|
|
830
|
-
r.roundRect(
|
|
833
|
+
r.roundRect(y(Le).x, y(Le).y, Le.width || L, Le.height || B, qa);
|
|
831
834
|
}
|
|
832
835
|
r.fill();
|
|
833
836
|
}
|
|
834
837
|
r.strokeStyle = k.nodeBorder, r.lineWidth = 1, r.beginPath();
|
|
835
838
|
for (var gt = 0; gt < pa; gt++) {
|
|
836
839
|
var re = Jr[gt];
|
|
837
|
-
re.selected || r.roundRect(
|
|
840
|
+
re.selected || r.roundRect(y(re).x, y(re).y, re.width || L, re.height || B, qa);
|
|
838
841
|
}
|
|
839
842
|
r.stroke();
|
|
840
843
|
var Io = !1;
|
|
841
844
|
r.strokeStyle = k.nodeSelectedBorder, r.lineWidth = 2, r.beginPath();
|
|
842
845
|
for (var Mt = 0; Mt < pa; Mt++) {
|
|
843
846
|
var ae = Jr[Mt];
|
|
844
|
-
ae.selected && (Io = !0, r.roundRect(
|
|
847
|
+
ae.selected && (Io = !0, r.roundRect(y(ae).x, y(ae).y, ae.width || L, ae.height || B, qa));
|
|
845
848
|
}
|
|
846
|
-
if (Io && r.stroke(),
|
|
847
|
-
r.fillStyle = k.nodeText, r.font =
|
|
849
|
+
if (Io && r.stroke(), ia) {
|
|
850
|
+
r.fillStyle = k.nodeText, r.font = Oo, r.textAlign = "center", r.textBaseline = "middle";
|
|
848
851
|
for (var kt = 0; kt < pa; kt++) {
|
|
849
|
-
var
|
|
850
|
-
if (!(!
|
|
851
|
-
var Zo =
|
|
852
|
-
r.fillText(
|
|
852
|
+
var la = Jr[kt];
|
|
853
|
+
if (!(!la.data || !la.data.label)) {
|
|
854
|
+
var Zo = la.width || L, qi = la.height || B;
|
|
855
|
+
r.fillText(la.data.label, y(la).x + Zo / 2, y(la).y + qi / 2, Zo - 24);
|
|
853
856
|
}
|
|
854
857
|
}
|
|
855
858
|
r.textAlign = "start", r.textBaseline = "alphabetic";
|
|
856
859
|
}
|
|
857
860
|
for (var mt = 0; mt < Ae.length; mt++) {
|
|
858
|
-
var
|
|
859
|
-
Ko && r.drawImage(Ko, Ca.x, Ca.y, Se, Tt),
|
|
861
|
+
var yr = Ae[mt], Ca = y(yr), Se = yr.width || L, Tt = yr.height || B, Ko = ie[yr.id] && ei[ie[yr.id]] || Ge[yr.type];
|
|
862
|
+
Ko && r.drawImage(Ko, Ca.x, Ca.y, Se, Tt), ia && yr.data && yr.data.label && (r.fillStyle = k.nodeText, r.font = Oo, r.textAlign = "center", r.textBaseline = "middle", r.fillText(yr.data.label, Ca.x + Se / 2, Ca.y + Tt / 2, Se - 24)), yr.selected && (r.strokeStyle = k.nodeSelectedBorder, r.lineWidth = 2, r.beginPath(), r.roundRect(Ca.x, Ca.y, Se, Tt, qa), r.stroke());
|
|
860
863
|
}
|
|
861
|
-
Ae.length > 0 &&
|
|
864
|
+
Ae.length > 0 && ia && (r.textAlign = "start", r.textBaseline = "alphabetic");
|
|
862
865
|
for (var Rt = 0; Rt < _e.length; Rt++) {
|
|
863
|
-
var fa = _e[Rt],
|
|
864
|
-
if (st &&
|
|
865
|
-
var ee =
|
|
866
|
+
var fa = _e[Rt], q = Ie[fa.type], E = y(fa), Rr = fa.width || L, va = fa.height || B, vr = q.radius || qa, Ce = fa.data || {};
|
|
867
|
+
if (st && q.shadow !== !1 && (r.save(), r.shadowColor = q.shadowColor || k.nodeShadow, r.shadowBlur = q.shadowBlur || 6, r.shadowOffsetY = q.shadowOffsetY || 2, r.fillStyle = q.fill || k.nodeBg, r.beginPath(), r.roundRect(E.x, E.y, Rr, va, vr), r.fill(), r.restore()), r.fillStyle = q.fill || k.nodeBg, r.beginPath(), r.roundRect(E.x, E.y, Rr, va, vr), r.fill(), r.strokeStyle = fa.selected ? k.nodeSelectedBorder : q.stroke || k.nodeBorder, r.lineWidth = fa.selected ? 2 : q.strokeWidth || 1, r.beginPath(), r.roundRect(E.x, E.y, Rr, va, vr), r.stroke(), q.accent) {
|
|
868
|
+
var ee = q.accent;
|
|
866
869
|
r.fillStyle = ee.color || "#3b82f6";
|
|
867
870
|
var Wa = ee.width || 5;
|
|
868
|
-
r.beginPath(), ee.side === "right" ? r.roundRect(E.x +
|
|
871
|
+
r.beginPath(), ee.side === "right" ? r.roundRect(E.x + Rr - Wa, E.y, Wa, va, [0, vr, vr, 0]) : ee.side === "top" ? r.roundRect(E.x, E.y, Rr, Wa, [vr, vr, 0, 0]) : ee.side === "bottom" ? r.roundRect(E.x, E.y + va - Wa, Rr, Wa, [0, 0, vr, vr]) : r.roundRect(E.x, E.y, Wa, va, [vr, 0, 0, vr]), r.fill();
|
|
869
872
|
}
|
|
870
|
-
if (
|
|
871
|
-
var
|
|
873
|
+
if (q.icon && ia) {
|
|
874
|
+
var zr = q.icon, bo = zr.dataField ? Ce[zr.dataField] : zr.text;
|
|
872
875
|
if (bo) {
|
|
873
|
-
r.font = (
|
|
874
|
-
var
|
|
875
|
-
r.fillText(bo,
|
|
876
|
+
r.font = (zr.size || 18) + "px system-ui, sans-serif", r.textAlign = "center", r.textBaseline = "middle", r.fillStyle = zr.color || k.nodeText;
|
|
877
|
+
var Gi = E.x + (zr.x !== void 0 ? zr.x : 20), Ii = E.y + (zr.y !== void 0 ? zr.y : va / 2);
|
|
878
|
+
r.fillText(bo, Gi, Ii);
|
|
876
879
|
}
|
|
877
880
|
}
|
|
878
|
-
if (
|
|
879
|
-
var
|
|
881
|
+
if (q.title && ia) {
|
|
882
|
+
var xr = q.title, Jo = xr.dataField ? Ce[xr.dataField] : xr.text;
|
|
880
883
|
if (Jo) {
|
|
881
|
-
r.font =
|
|
882
|
-
var Qo = E.x + (
|
|
883
|
-
r.fillText(Jo, Qo,
|
|
884
|
+
r.font = xr.font || "600 13px system-ui, sans-serif", r.textAlign = xr.align || "left", r.textBaseline = "top", r.fillStyle = xr.color || k.nodeText;
|
|
885
|
+
var Qo = E.x + (xr.x !== void 0 ? xr.x : 12), Zi = E.y + (xr.y !== void 0 ? xr.y : 12);
|
|
886
|
+
r.fillText(Jo, Qo, Zi, Rr - Qo + E.x - 12);
|
|
884
887
|
}
|
|
885
888
|
}
|
|
886
|
-
if (
|
|
887
|
-
var
|
|
889
|
+
if (q.subtitle && ia) {
|
|
890
|
+
var gr = q.subtitle, $o = gr.dataField ? Ce[gr.dataField] : gr.text;
|
|
888
891
|
if ($o) {
|
|
889
|
-
r.font =
|
|
890
|
-
var Fo = E.x + (
|
|
891
|
-
r.fillText($o, Fo,
|
|
892
|
+
r.font = gr.font || "11px system-ui, sans-serif", r.textAlign = gr.align || "left", r.textBaseline = "top", r.fillStyle = gr.color || "#64748b";
|
|
893
|
+
var Fo = E.x + (gr.x !== void 0 ? gr.x : 12), Ki = E.y + (gr.y !== void 0 ? gr.y : 32);
|
|
894
|
+
r.fillText($o, Fo, Ki, Rr - Fo + E.x - 12);
|
|
892
895
|
}
|
|
893
896
|
}
|
|
894
|
-
if (
|
|
895
|
-
var
|
|
897
|
+
if (q.badge && ia) {
|
|
898
|
+
var wr = q.badge, zt = wr.dataField ? Ce[wr.dataField] : wr.text;
|
|
896
899
|
if (zt) {
|
|
897
|
-
r.font =
|
|
898
|
-
var
|
|
899
|
-
r.fillStyle =
|
|
900
|
+
r.font = wr.font || "700 9px system-ui, sans-serif";
|
|
901
|
+
var bi = r.measureText(zt), Ji = wr.paddingX || 6, Qi = wr.paddingY || 3, wt = bi.width + Ji * 2, Bt = 14 + Qi, Uo = E.x + Rr - wt / 2 - 4, co = E.y - Bt / 2;
|
|
902
|
+
r.fillStyle = wr.bg || "#3b82f6", r.beginPath(), r.roundRect(Uo, co, wt, Bt, wr.radius || 7), r.fill(), r.fillStyle = wr.color || "#fff", r.textAlign = "center", r.textBaseline = "middle", r.fillText(zt, Uo + wt / 2, co + Bt / 2);
|
|
900
903
|
}
|
|
901
904
|
}
|
|
902
905
|
}
|
|
903
|
-
if (_e.length > 0 && (r.textAlign = "start", r.textBaseline = "alphabetic"),
|
|
904
|
-
for (var At = [], _t = 0; _t <
|
|
905
|
-
for (var Vo =
|
|
906
|
+
if (_e.length > 0 && (r.textAlign = "start", r.textBaseline = "alphabetic"), Wi) {
|
|
907
|
+
for (var At = [], _t = 0; _t < nr; _t++)
|
|
908
|
+
for (var Vo = ti(fr[_t]), Et = 0; Et < Vo.length; Et++)
|
|
906
909
|
At.push(Vo[Et]);
|
|
907
910
|
r.fillStyle = k.handleFill, r.beginPath();
|
|
908
911
|
for (var Lt = 0; Lt < At.length; Lt++) {
|
|
909
912
|
var We = At[Lt];
|
|
910
|
-
r.moveTo(We.x +
|
|
913
|
+
r.moveTo(We.x + Do, We.y), r.arc(We.x, We.y, Do, 0, 6.2832);
|
|
911
914
|
}
|
|
912
915
|
r.fill(), r.strokeStyle = k.handleBorder, r.lineWidth = 1.5, r.stroke();
|
|
913
916
|
}
|
|
914
917
|
}
|
|
915
918
|
r.restore();
|
|
916
|
-
var $
|
|
919
|
+
var $i = (performance.now() - a).toFixed(1);
|
|
917
920
|
Pt++;
|
|
918
921
|
var Pe = performance.now();
|
|
919
922
|
if (Pe - Xo >= 1e3 && (Ho = Pt, Pt = 0, Xo = Pe), Pe - po >= 100) {
|
|
920
923
|
po = Pe;
|
|
921
|
-
var
|
|
924
|
+
var Fi = Math.round(-M.x / M.zoom), Ui = Math.round(-M.y / M.zoom);
|
|
922
925
|
self.postMessage({
|
|
923
926
|
type: "hud",
|
|
924
927
|
data: {
|
|
925
|
-
wx:
|
|
926
|
-
wy:
|
|
928
|
+
wx: Fi,
|
|
929
|
+
wy: Ui,
|
|
927
930
|
zoom: M.zoom.toFixed(2),
|
|
928
|
-
renderMs: $
|
|
931
|
+
renderMs: $i,
|
|
929
932
|
fps: Ho,
|
|
930
|
-
visible:
|
|
933
|
+
visible: X.length > 0 ? jo(Dr, Or, ya, jr).length : 0,
|
|
931
934
|
nodeCount: C.length,
|
|
932
|
-
visibleNodes:
|
|
933
|
-
edgeCount:
|
|
935
|
+
visibleNodes: nr,
|
|
936
|
+
edgeCount: G.length
|
|
934
937
|
}
|
|
935
938
|
});
|
|
936
939
|
}
|
|
937
940
|
}
|
|
938
941
|
}
|
|
939
|
-
`,lr=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",wr],{type:"text/javascript;charset=utf-8"});function eo(e){let t;try{if(t=lr&&(self.URL||self.webkitURL).createObjectURL(lr),!t)throw"";const n=new Worker(t,{type:"module",name:e==null?void 0:e.name});return n.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),n}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(wr),{type:"module",name:e==null?void 0:e.name})}}const Xn=new WeakMap;function to(e,t){if(Xn.has(e))return Xn.get(e);const n=e.transferControlToOffscreen(),r=new eo;r.onerror=o=>console.error("[infinite-canvas] worker error:",o.message,o),r.postMessage({type:"init",data:{...t,canvas:n}},[n]);const i={worker:r};return Xn.set(e,i),i}const ft=160,nt=60,no=10;function Mr({cards:e=[],nodes:t=[],edges:n=[],onHudUpdate:r,onNodesProcessed:i,onNodesChange:o,onEdgesChange:a,onConnect:f,onNodeClick:p,onNodeDragStart:d,onNodeDrag:h,onNodeDragStop:k,onEdgeClick:S,onEdgeDoubleClick:E,onEdgeMouseEnter:z,onEdgeMouseMove:j,onEdgeMouseLeave:L,onEdgeContextMenu:A,onNodeDoubleClick:X,onNodeMouseEnter:D,onNodeMouseMove:Y,onNodeMouseLeave:$,onNodeContextMenu:I,onPaneClick:q,onPaneContextMenu:O,onPaneMouseEnter:H,onPaneMouseMove:C,onPaneMouseLeave:y,onSelectionChange:v,onConnectStart:N,onConnectEnd:P,onInit:B,onMoveStart:J,onMove:oe,onMoveEnd:te,onDelete:se,onBeforeDelete:he,onError:ge,isValidConnection:fe,dark:ie,gridSize:Me=40,zoomMin:ne=.1,zoomMax:le=4,initialCamera:Ee={x:0,y:0,zoom:1},fitView:et=!1,fitViewOptions:ye,nodesDraggable:Re=!0,nodesConnectable:$e=!0,elementsSelectable:We=!0,multiSelectionKeyCode:Se="Shift",selectionOnDrag:tt=!1,selectionMode:rt="partial",connectionMode:we="loose",connectionRadius:Te=20,connectOnClick:Oe=!1,snapToGrid:je=!1,snapGrid:Fe=[15,15],deleteKeyCode:Ze=["Delete","Backspace"],panActivationKeyCode:Et=" ",panOnScroll:an=!1,panOnScrollMode:St="free",panOnScrollSpeed:cn=.5,zoomOnScroll:ln=!0,zoomOnDoubleClick:un=!0,zoomOnPinch:dn=!0,preventScrolling:Zt=!0,translateExtent:xt,nodeExtent:pt,defaultEdgeOptions:zt={},autoPanOnNodeDrag:Pn=!0,autoPanOnConnect:Tn=!0,autoPanSpeed:ot=5,edgesReconnectable:cr=!1,elevateNodesOnSelect:Ln=!1,elevateEdgesOnSelect:Bn=!1,noDragClassName:Nt="nodrag",noPanClassName:It="nopan",onSelectionDragStart:$n,onSelectionDrag:jn,onSelectionDragStop:An,edgeRouting:wt=!0}={}){const me=c.useRef(null),Pt=c.useRef(null),Le=c.useRef(null),ue=c.useRef({...Ee}),mt=c.useRef([...e]),K=c.useRef([...t]),ze=c.useRef([...n]),fn=c.useRef(new Map),Tt=c.useRef(!1),Lt=c.useRef(null),[Bt,Dn]=c.useState(!1),Ye=c.useRef(null),Ue=c.useRef(null),$t=c.useRef(null),st=c.useRef(null),hn=c.useRef(!1),Je=c.useRef(null),[gn,yn]=c.useState({x:Ee.x,y:Ee.y,zoom:Ee.zoom}),[Gt,xn]=c.useState(null),vt=c.useMemo(()=>new Set,[]),it=c.useMemo(()=>new Set,[]),Ke=c.useRef(!1),Z=c.useRef({});Z.current={onHudUpdate:r,onNodesProcessed:i,onNodesChange:o,onEdgesChange:a,onConnect:f,onNodeClick:p,onNodeDragStart:d,onNodeDrag:h,onNodeDragStop:k,onEdgeClick:S,onEdgeDoubleClick:E,onEdgeMouseEnter:z,onEdgeMouseMove:j,onEdgeMouseLeave:L,onEdgeContextMenu:A,onNodeDoubleClick:X,onNodeMouseEnter:D,onNodeMouseMove:Y,onNodeMouseLeave:$,onNodeContextMenu:I,onPaneClick:q,onPaneContextMenu:O,onPaneMouseEnter:H,onPaneMouseMove:C,onPaneMouseLeave:y,onSelectionChange:v,onConnectStart:N,onConnectEnd:P,onInit:B,onMoveStart:J,onMove:oe,onMoveEnd:te,onDelete:se,onBeforeDelete:he,onError:ge,onSelectionDragStart:$n,onSelectionDrag:jn,onSelectionDragStop:An,isValidConnection:fe};const at={get current(){return Z.current.onConnect}},jt={get current(){return Z.current.onNodeClick}},At={get current(){return Z.current.onNodeDragStart}},Dt={get current(){return Z.current.onNodeDrag}},Ht={get current(){return Z.current.onNodeDragStop}},Ve={get current(){return Z.current.onEdgeClick}},_t={get current(){return Z.current.onPaneClick}},Wt={get current(){return Z.current.onSelectionChange}},Ft={get current(){return Z.current.onHudUpdate}},Yt={get current(){return Z.current.onNodesProcessed}};c.useEffect(()=>{const u=l=>{l.key===Se&&(hn.current=!0),l.key===Et&&(Ke.current=!0)},b=l=>{l.key===Se&&(hn.current=!1),l.key===Et&&(Ke.current=!1)};return window.addEventListener("keydown",u),window.addEventListener("keyup",b),()=>{window.removeEventListener("keydown",u),window.removeEventListener("keyup",b)}},[Se,Et]);const ke={get current(){return Z.current.onNodesChange?ht:null}},ht=u=>{var l,x,w;(x=(l=Z.current).onNodesChange)==null||x.call(l,u);const b=[];for(let m=0;m<u.length;m++)u[m].type==="select"&&b.push({id:u[m].id,selected:u[m].selected});b.length>0&&((w=Le.current)==null||w.postMessage({type:"nodeSelections",data:{selections:b}}))},_e={get current(){return Z.current.onEdgesChange?Hn:null}},Hn=u=>{var l,x,w;(x=(l=Z.current).onEdgesChange)==null||x.call(l,u);const b=[];for(let m=0;m<u.length;m++)u[m].type==="select"&&b.push({id:u[m].id,selected:u[m].selected});b.length>0&&((w=Le.current)==null||w.postMessage({type:"edgeSelections",data:{selections:b}}))},gt=c.useCallback(()=>{var x;const u=K.current.filter(w=>w.selected),b=ze.current.filter(w=>w.selected),l={nodes:u,edges:b};(x=Wt.current)==null||x.call(Wt,l);for(const w of it)w(l)},[it]);c.useEffect(()=>{var u;mt.current=[...e],(u=Le.current)==null||u.postMessage({type:"cards",data:{cards:[...e]}})},[e]);const Xt=c.useCallback(u=>{const b={};for(const l of u)b[l.id]=l;return u.map(l=>{if(!l.parentId)return l;const x=b[l.parentId];if(!x)return l;let w=l.position.x,m=l.position.y,g=x;for(;g;)w+=g.position.x,m+=g.position.y,g=g.parentId?b[g.parentId]:null;return{...l,_absolutePosition:{x:w,y:m}}})},[]),ct=c.useRef([]),bt=c.useCallback(u=>{const b=fn.current;if(!b||b.size===0)return u;const l={};for(const[,x]of b)l[x.nodeId]||(l[x.nodeId]=[]),l[x.nodeId].push({id:x.id,type:x.type,position:x.position,x:x.x,y:x.y});return u.map(x=>{const w=l[x.id];return w&&w.length>0?{...x,handles:w}:x})},[]),pn=c.useCallback(()=>{var b;if(Ye.current)return;const u=bt(ct.current);(b=Le.current)==null||b.postMessage({type:"nodes",data:{nodes:u}})},[bt]);c.useEffect(()=>{var l,x;if(Ye.current){const w=Ye.current.id,m=new Set([w,...Ye.current.selectedStarts.map(M=>M.id)]),g={};for(const M of K.current)m.has(M.id)&&(g[M.id]={...M.position});K.current=[...t];for(const M of K.current)g[M.id]&&(M.position=g[M.id]);ct.current=Xt(K.current);const R=bt(ct.current);(l=Le.current)==null||l.postMessage({type:"nodes",data:{nodes:R}});return}K.current=[...t];const u=Xt(t);ct.current=u;const b=bt(u);(x=Le.current)==null||x.postMessage({type:"nodes",data:{nodes:b}})},[t,Xt,bt]),c.useEffect(()=>{var u;ze.current=[...n],(u=Le.current)==null||u.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const Be=c.useCallback((u,b)=>{const l=me.current;if(!l)return{x:0,y:0};const x=l.getBoundingClientRect(),w=ue.current;return{x:(u-x.left-w.x)/w.zoom,y:(b-x.top-w.y)/w.zoom}},[]),ae=c.useCallback((u,b)=>{const l=ct.current.length>0?ct.current:K.current;let x=null;for(let w=l.length-1;w>=0;w--){const m=l[w];if(m.hidden||m._customRendered)continue;const g=m._absolutePosition||m.position,R=m.width||ft,M=m.height||nt;if(u>=g.x&&u<=g.x+R&&b>=g.y&&b<=g.y+M){if(m.type==="group"){x||(x=m);continue}return m}}return x},[]),Ot=c.useCallback((u,b)=>{const l=b.width||ft,x=b.height||nt;if(u.x!==void 0&&u.y!==void 0)return{x:b.position.x+u.x,y:b.position.y+u.y};switch(u.position||(u.type==="source"?"right":"left")){case"top":return{x:b.position.x+l/2,y:b.position.y};case"bottom":return{x:b.position.x+l/2,y:b.position.y+x};case"left":return{x:b.position.x,y:b.position.y+x/2};case"right":return{x:b.position.x+l,y:b.position.y+x/2};default:return{x:b.position.x+l,y:b.position.y+x/2}}},[]),Mt=c.useCallback(u=>{const b=u.width||ft,l=u.height||nt;if(u.handles&&u.handles.length>0)return u.handles.map(M=>{const F=Ot(M,u);return{id:M.id||null,type:M.type,x:F.x,y:F.y}});const x=u.targetPosition||"left",w=u.sourcePosition||"right",m=M=>{switch(M){case"top":return{x:u.position.x+b/2,y:u.position.y};case"bottom":return{x:u.position.x+b/2,y:u.position.y+l};case"left":return{x:u.position.x,y:u.position.y+l/2};case"right":return{x:u.position.x+b,y:u.position.y+l/2};default:return{x:u.position.x+b,y:u.position.y+l/2}}},g=m(x),R=m(w);return[{id:null,type:"target",x:g.x,y:g.y},{id:null,type:"source",x:R.x,y:R.y}]},[Ot]),Rt=c.useCallback((u,b)=>{const l=K.current,x=ue.current,w=Math.max(no,Te)/x.zoom;for(let m=l.length-1;m>=0;m--){const g=l[m];if(g.hidden)continue;const R=Mt(g);for(const M of R)if(Math.abs(u-M.x)<w&&Math.abs(b-M.y)<w)return{nodeId:g.id,handleId:M.id,type:M.type,x:M.x,y:M.y}}return null},[Mt]),lt=c.useCallback((u,b)=>{const x=8/ue.current.zoom,w=K.current,m={};for(let g=0;g<w.length;g++)m[w[g].id]=w[g];for(let g=ze.current.length-1;g>=0;g--){const R=ze.current[g],M=m[R.source],F=m[R.target];if(!M||!F)continue;const _=M.width||ft,U=M.height||nt,Q=F.height||nt,be=M.position.x+_,Ae=M.position.y+U/2,ee=F.position.x,ce=F.position.y+Q/2;if(ro(u,b,be,Ae,ee,ce)<x)return R}return null},[]);c.useEffect(()=>{const u=Pt.current,b=me.current;if(!u||!b)return;const l=b.getBoundingClientRect(),x=ie!==void 0?ie:matchMedia("(prefers-color-scheme: dark)").matches,w=Xt(K.current);ct.current=w;const m=bt(w),{worker:g}=to(u,{width:l.width,height:l.height,camera:ue.current,cards:mt.current,nodes:m,edges:ze.current,dark:x,gridSize:Me,edgeRouting:wt});g.onmessage=_=>{var U,Q,be,Ae;_.data.type==="hud"&&((U=Ft.current)==null||U.call(Ft,_.data.data)),_.data.type==="ready"&&Dn(!0),_.data.type==="nodesProcessed"&&((Q=Yt.current)==null||Q.call(Yt,_.data.data)),_.data.type==="error"&&((Ae=(be=Z.current).onError)==null||Ae.call(be,"worker-error",_.data.message||"Canvas worker error"))},g.onerror=_=>{var U,Q;(Q=(U=Z.current).onError)==null||Q.call(U,"worker-error",_.message||"Canvas worker crashed")},Le.current=g;const R=new ResizeObserver(_=>{const{width:U,height:Q}=_[0].contentRect;g.postMessage({type:"resize",data:{width:U,height:Q}})});R.observe(b);let M,F;return ie===void 0&&(M=matchMedia("(prefers-color-scheme: dark)"),F=_=>g.postMessage({type:"theme",data:{dark:_.matches}}),M.addEventListener("change",F)),()=>{R.disconnect(),M&&F&&M.removeEventListener("change",F),Le.current=null}},[]),c.useEffect(()=>{var u;ie!==void 0&&((u=Le.current)==null||u.postMessage({type:"theme",data:{dark:ie}}))},[ie]),c.useEffect(()=>{var u;(u=Le.current)==null||u.postMessage({type:"edgeRouting",data:{enabled:wt}})},[wt]);const Ut=c.useRef(0),ve=c.useCallback((u=null)=>{var x,w,m;const b=ue.current;if(xt){const g=me.current;if(g){const R=g.getBoundingClientRect(),M=-xt[1][0]*b.zoom+R.width,F=-xt[1][1]*b.zoom+R.height,_=-xt[0][0]*b.zoom,U=-xt[0][1]*b.zoom;b.x=Math.min(_,Math.max(M,b.x)),b.y=Math.min(U,Math.max(F,b.y))}}(x=Le.current)==null||x.postMessage({type:"camera",data:{camera:{...b}}});const l={x:b.x,y:b.y,zoom:b.zoom};(m=(w=Z.current).onMove)==null||m.call(w,u,l);for(const g of vt)g(l);cancelAnimationFrame(Ut.current),Ut.current=requestAnimationFrame(()=>{yn({x:b.x,y:b.y,zoom:b.zoom})})},[vt,xt]),ut=c.useCallback(()=>{var l,x;const u=Ue.current,b=$t.current;u&&b?((l=Le.current)==null||l.postMessage({type:"connecting",data:{from:u.startPos,to:b,_routedPoints:null}}),xn({source:u.sourceId,sourceHandle:u.sourceHandle,target:null,targetHandle:null})):((x=Le.current)==null||x.postMessage({type:"connecting",data:null}),xn(null))},[]),dt=c.useCallback(()=>{var b,l;const u=st.current;u?(b=Le.current)==null||b.postMessage({type:"selectionBox",data:u}):(l=Le.current)==null||l.postMessage({type:"selectionBox",data:null})},[]),mn=c.useCallback(u=>{var g,R,M,F,_,U,Q,be,Ae,ee,ce,Ce,De,Xe,Ge,qe,Jt,yt;const b=K.current.length>0,l=Be(u.clientX,u.clientY),x=hn.current;if(b&&$e&&!x){const G=Rt(l.x,l.y);if(Oe&&Je.current&&G){const re=Je.current;if(G.nodeId!==re.nodeId){const Qe=re.handleType==="target"?{source:G.nodeId,target:re.nodeId,sourceHandle:G.handleId||null,targetHandle:re.handleId}:{source:re.nodeId,target:G.nodeId,sourceHandle:re.handleId,targetHandle:G.handleId||null};(Z.current.isValidConnection?Z.current.isValidConnection(Qe):!0)&&((g=at.current)==null||g.call(at,{...Qe,...zt}))}Je.current=null;return}if(we==="strict"?G&&G.type==="source":G!=null){if(Oe){Je.current={nodeId:G.nodeId,handleId:G.handleId||null,handleType:G.type},(M=(R=Z.current).onConnectStart)==null||M.call(R,u,{nodeId:G.nodeId,handleId:G.handleId,handleType:G.type});return}Ue.current={sourceId:G.nodeId,sourceHandle:G.handleId||null,sourceType:G.type,startPos:{x:G.x,y:G.y}},$t.current={x:l.x,y:l.y},(F=me.current)==null||F.setPointerCapture(u.pointerId),(U=(_=Z.current).onConnectStart)==null||U.call(_,u,{nodeId:G.nodeId,handleId:G.handleId,handleType:G.type}),ut();return}}const w=G=>{var re;let pe=G;for(;pe&&pe!==me.current;){if((re=pe.classList)!=null&&re.contains(Nt))return!0;pe=pe.parentElement}return!1},m=G=>{var re;let pe=G;for(;pe&&pe!==me.current;){if((re=pe.classList)!=null&&re.contains(It))return!0;pe=pe.parentElement}return!1};if(b){const G=ae(l.x,l.y);if(G){if(ke.current&&We){const pe=[];if(x)pe.push({id:G.id,type:"select",selected:!G.selected});else if(!G.selected){for(const re of K.current)re.id===G.id?pe.push({id:re.id,type:"select",selected:!0}):re.selected&&pe.push({id:re.id,type:"select",selected:!1});if(_e.current){const re=ze.current.filter(de=>de.selected).map(de=>({id:de.id,type:"select",selected:!1}));re.length&&_e.current(re)}}if(pe.length){if(ke.current(pe),Ln&&!x){const re=K.current.findIndex(de=>de.id===G.id);re>=0&&re<K.current.length-1&&ke.current([{id:G.id,type:"remove"},{type:"add",item:{...K.current[re],selected:!0}}])}gt()}}if((Q=jt.current)==null||Q.call(jt,u,G),Re&&!w(u.target)){const pe=G.selected;let re=null;if(G.parentId&&G.extent==="parent"){const de=K.current.find(Qe=>Qe.id===G.parentId);if(de){const Qe=de.width||ft,Kt=de.height||nt,bn=G.width||((be=G.measured)==null?void 0:be.width)||ft,Vt=G.height||((Ae=G.measured)==null?void 0:Ae.height)||nt;re={minX:0,minY:0,maxX:Qe-bn,maxY:Kt-Vt}}}if(Ye.current={id:G.id,startPos:{...G.position},startMouse:{x:l.x,y:l.y},parentClamp:re,parentId:G.parentId||null,selectedStarts:pe?K.current.filter(de=>de.selected&&de.id!==G.id).map(de=>{var Kt,bn;let Qe=null;if(de.parentId&&de.extent==="parent"){const Vt=K.current.find(Yn=>Yn.id===de.parentId);if(Vt){const Yn=Vt.width||ft,Wr=Vt.height||nt,Fr=de.width||((Kt=de.measured)==null?void 0:Kt.width)||ft,Yr=de.height||((bn=de.measured)==null?void 0:bn.height)||nt;Qe={minX:0,minY:0,maxX:Yn-Fr,maxY:Wr-Yr}}}return{id:de.id,startPos:{...de.position},parentClamp:Qe,parentId:de.parentId||null}}):[]},(ee=me.current)==null||ee.setPointerCapture(u.pointerId),(ce=At.current)==null||ce.call(At,u,G),Ye.current.selectedStarts.length>0){const de=K.current.filter(Qe=>Qe.selected);(De=(Ce=Z.current).onSelectionDragStart)==null||De.call(Ce,u,de)}if(ke.current){const de=[{id:G.id,type:"position",dragging:!0}];for(const Qe of Ye.current.selectedStarts)de.push({id:Qe.id,type:"position",dragging:!0});ke.current(de)}}return}}if(ze.current.length>0&&We){const G=lt(l.x,l.y);if(G){if(_e.current){const pe=[];if(x)pe.push({id:G.id,type:"select",selected:!G.selected});else{for(const re of ze.current)re.id===G.id?pe.push({id:re.id,type:"select",selected:!0}):re.selected&&pe.push({id:re.id,type:"select",selected:!1});if(ke.current){const re=K.current.filter(de=>de.selected).map(de=>({id:de.id,type:"select",selected:!1}));re.length&&ke.current(re)}}if(pe.length){if(_e.current(pe),Bn&&!x){const re=ze.current.findIndex(de=>de.id===G.id);re>=0&&re<ze.current.length-1&&_e.current([{id:G.id,type:"remove"},{type:"add",item:{...ze.current[re],selected:!0}}])}gt()}}(Xe=Ve.current)==null||Xe.call(Ve,u,G);return}}if(!x){const G=K.current.filter(re=>re.selected).map(re=>({id:re.id,type:"select",selected:!1})),pe=ze.current.filter(re=>re.selected).map(re=>({id:re.id,type:"select",selected:!1}));G.length&&ke.current&&ke.current(G),pe.length&&_e.current&&_e.current(pe),(G.length||pe.length)&>()}if((Ge=_t.current)==null||Ge.call(_t,u),tt||x){st.current={startWorld:{...l},endWorld:{...l}},(qe=me.current)==null||qe.setPointerCapture(u.pointerId),dt();return}m(u.target)||(Tt.current=!0,Lt.current={x:u.clientX,y:u.clientY},(Jt=me.current)==null||Jt.classList.add("dragging"),(yt=me.current)==null||yt.setPointerCapture(u.pointerId))},[Be,ae,Rt,lt,Re,$e,We,tt,ut,dt,gt,Nt,It]),Qt=c.useCallback(u=>{var l,x,w,m;if(Ue.current){if($t.current=Be(u.clientX,u.clientY),ut(),Tn){const g=me.current;if(g){const R=g.getBoundingClientRect(),M=40,F=u.clientX-R.left,_=u.clientY-R.top;let U=0,Q=0;F<M?U=ot:F>R.width-M&&(U=-ot),_<M?Q=ot:_>R.height-M&&(Q=-ot),(U||Q)&&(ue.current.x+=U,ue.current.y+=Q,ve(u))}}return}if(st.current){st.current.endWorld=Be(u.clientX,u.clientY),dt();const g=st.current,R=Math.min(g.startWorld.x,g.endWorld.x),M=Math.min(g.startWorld.y,g.endWorld.y),F=Math.max(g.startWorld.x,g.endWorld.x),_=Math.max(g.startWorld.y,g.endWorld.y);if(ke.current){const U=[];for(const Q of K.current){if(Q.hidden)continue;const be=Q.width||ft,Ae=Q.height||nt,ee=rt==="full"?Q.position.x>=R&&Q.position.x+be<=F&&Q.position.y>=M&&Q.position.y+Ae<=_:Q.position.x+be>R&&Q.position.x<F&&Q.position.y+Ae>M&&Q.position.y<_;ee!==!!Q.selected&&U.push({id:Q.id,type:"select",selected:ee})}U.length&&ke.current(U)}return}if(Ye.current){const g=Be(u.clientX,u.clientY),R=Ye.current,M=g.x-R.startMouse.x,F=g.y-R.startMouse.y;let _={x:R.startPos.x+M,y:R.startPos.y+F};if(je&&(_=Zn(_,Fe)),pt&&(_=Gn(_,pt)),R.parentClamp){const ee=R.parentClamp;_={x:Math.max(ee.minX,Math.min(_.x,ee.maxX)),y:Math.max(ee.minY,Math.min(_.y,ee.maxY))}}const U=[{id:R.id,position:_}];for(const ee of R.selectedStarts){let ce={x:ee.startPos.x+M,y:ee.startPos.y+F};if(je&&(ce=Zn(ce,Fe)),pt&&(ce=Gn(ce,pt)),ee.parentClamp){const Ce=ee.parentClamp;ce={x:Math.max(Ce.minX,Math.min(ce.x,Ce.maxX)),y:Math.max(Ce.minY,Math.min(ce.y,Ce.maxY))}}U.push({id:ee.id,position:ce})}const Q=[];for(const ee of U){const ce=K.current.find(Ce=>Ce.id===ee.id);if(ce){ce.position=ee.position,ce.dragging=!0;let Ce=ee.position;if(ce.parentId){let De=K.current.find(qe=>qe.id===ce.parentId),Xe=ee.position.x,Ge=ee.position.y;for(;De;)Xe+=De.position.x,Ge+=De.position.y,De=De.parentId?K.current.find(qe=>qe.id===De.parentId):null;Ce={x:Xe,y:Ge}}Q.push({id:ee.id,position:ee.position,_absolutePosition:Ce,width:ce.width,height:ce.height,dragging:!0,selected:ce.selected})}}const be=new Set(U.map(ee=>ee.id));for(const ee of K.current)if(ee.parentId&&be.has(ee.parentId)&&!be.has(ee.id)){let ce=K.current.find(Xe=>Xe.id===ee.parentId),Ce=ee.position.x,De=ee.position.y;for(;ce;)Ce+=ce.position.x,De+=ce.position.y,ce=ce.parentId?K.current.find(Xe=>Xe.id===ce.parentId):null;Q.push({id:ee.id,position:ee.position,_absolutePosition:{x:Ce,y:De},width:ee.width,height:ee.height,dragging:!1,selected:ee.selected})}if((l=Le.current)==null||l.postMessage({type:"nodePositions",data:{updates:Q}}),Pn){const ee=me.current;if(ee){const ce=ee.getBoundingClientRect(),Ce=40,De=u.clientX-ce.left,Xe=u.clientY-ce.top;let Ge=0,qe=0;De<Ce?Ge=ot:De>ce.width-Ce&&(Ge=-ot),Xe<Ce?qe=ot:Xe>ce.height-Ce&&(qe=-ot),(Ge||qe)&&(ue.current.x+=Ge,ue.current.y+=qe,ve(u))}}const Ae=K.current.find(ee=>ee.id===R.id);if(Ae&&((x=Dt.current)==null||x.call(Dt,u,Ae)),R.selectedStarts.length>0){const ee=K.current.filter(ce=>ce.selected);(m=(w=Z.current).onSelectionDrag)==null||m.call(w,u,ee)}return}if(!Tt.current)return;const b=ue.current;b.x+=u.clientX-Lt.current.x,b.y+=u.clientY-Lt.current.y,Lt.current={x:u.clientX,y:u.clientY},ve()},[ve,Be,ut,dt]),_n=c.useCallback(u=>{var b,l,x,w,m,g,R;if(Ue.current){const M=Be(u.clientX,u.clientY),F=Rt(M.x,M.y);if(F&&F.nodeId!==Ue.current.sourceId&&(we==="loose"||F.type==="target")){const Q=Ue.current.sourceType==="target"?{source:F.nodeId,target:Ue.current.sourceId,sourceHandle:F.handleId||null,targetHandle:Ue.current.sourceHandle}:{source:Ue.current.sourceId,target:F.nodeId,sourceHandle:Ue.current.sourceHandle,targetHandle:F.handleId||null};(Z.current.isValidConnection?Z.current.isValidConnection(Q):!0)&&((b=at.current)==null||b.call(at,{...Q,...zt}))}(x=(l=Z.current).onConnectEnd)==null||x.call(l,u.nativeEvent||u),Ue.current=null,$t.current=null,ut();return}if(st.current){st.current=null,dt(),gt();return}if(Ye.current){const M=Ye.current;if(ke.current){const _=K.current.find(Q=>Q.id===M.id),U=[{id:M.id,type:"position",position:_?{..._.position}:void 0,dragging:!1}];for(const Q of M.selectedStarts){const be=K.current.find(Ae=>Ae.id===Q.id);U.push({id:Q.id,type:"position",position:be?{...be.position}:void 0,dragging:!1})}ke.current(U)}if(M.selectedStarts.length>0){const _=K.current.filter(U=>U.selected);(m=(w=Z.current).onSelectionDragStop)==null||m.call(w,u,_)}requestAnimationFrame(()=>{Ye.current=null});const F=K.current.find(_=>_.id===M.id);F&&((g=Ht.current)==null||g.call(Ht,u,F));return}Tt.current=!1,(R=me.current)==null||R.classList.remove("dragging")},[Be,Rt,ut,dt,gt]);c.useEffect(()=>{const u=me.current;if(!u)return;const b=l=>{Zt&&l.preventDefault();const x=ue.current;if(an||Ke.current){const M=cn;St==="horizontal"?x.x-=l.deltaY*M:(St==="vertical"||(x.x-=l.deltaX*M),x.y-=l.deltaY*M),ve(l);return}if(!ln)return;const w=l.deltaY>0?.92:1.08,m=u.getBoundingClientRect(),g=l.clientX-m.left,R=l.clientY-m.top;x.x=g-(g-x.x)*w,x.y=R-(R-x.y)*w,x.zoom=Math.min(le,Math.max(ne,x.zoom*w)),ve(l)};return u.addEventListener("wheel",b,{passive:!Zt}),()=>u.removeEventListener("wheel",b)},[ve,ne,le,an,St,cn,ln,Zt]),c.useEffect(()=>{if(!dn)return;const u=me.current;if(!u)return;let b=0,l=null;const x=g=>{if(g.touches.length===2){const R=g.touches[0].clientX-g.touches[1].clientX,M=g.touches[0].clientY-g.touches[1].clientY;b=Math.hypot(R,M);const F=u.getBoundingClientRect();l={x:(g.touches[0].clientX+g.touches[1].clientX)/2-F.left,y:(g.touches[0].clientY+g.touches[1].clientY)/2-F.top},g.preventDefault()}},w=g=>{if(g.touches.length===2&&b>0){g.preventDefault();const R=g.touches[0].clientX-g.touches[1].clientX,M=g.touches[0].clientY-g.touches[1].clientY,F=Math.hypot(R,M),_=F/b;b=F;const U=ue.current,Q=l.x,be=l.y;U.x=Q-(Q-U.x)*_,U.y=be-(be-U.y)*_,U.zoom=Math.min(le,Math.max(ne,U.zoom*_)),ve(g)}},m=()=>{b=0,l=null};return u.addEventListener("touchstart",x,{passive:!1}),u.addEventListener("touchmove",w,{passive:!1}),u.addEventListener("touchend",m),()=>{u.removeEventListener("touchstart",x),u.removeEventListener("touchmove",w),u.removeEventListener("touchend",m)}},[dn,ve,ne,le]),c.useEffect(()=>{if(!un)return;const u=me.current;if(!u)return;const b=l=>{var _,U,Q,be;const x=Be(l.clientX,l.clientY);if(ae(x.x,x.y)){(U=(_=Z.current).onNodeDoubleClick)==null||U.call(_,l,ae(x.x,x.y));return}const w=lt(x.x,x.y);if(w){(be=(Q=Z.current).onEdgeDoubleClick)==null||be.call(Q,l,w);return}const m=1.5,g=u.getBoundingClientRect(),R=l.clientX-g.left,M=l.clientY-g.top,F=ue.current;F.x=R-(R-F.x)*m,F.y=M-(M-F.y)*m,F.zoom=Math.min(le,Math.max(ne,F.zoom*m)),ve(l)};return u.addEventListener("dblclick",b),()=>u.removeEventListener("dblclick",b)},[un,ve,ne,le,Be,ae,lt]),c.useEffect(()=>{const u=me.current;if(!u)return;const b=l=>{var g,R,M,F,_,U;const x=Be(l.clientX,l.clientY),w=ae(x.x,x.y);if(w){(R=(g=Z.current).onNodeContextMenu)==null||R.call(g,l,w);return}const m=lt(x.x,x.y);if(m){(F=(M=Z.current).onEdgeContextMenu)==null||F.call(M,l,m);return}(U=(_=Z.current).onPaneContextMenu)==null||U.call(_,l)};return u.addEventListener("contextmenu",b),()=>u.removeEventListener("contextmenu",b)},[Be,ae,lt]),c.useEffect(()=>{const u=me.current;if(!u)return;let b=null,l=null;const x=g=>{var F,_,U,Q,be,Ae,ee,ce,Ce,De,Xe,Ge,qe,Jt;if((_=(F=Z.current).onPaneMouseMove)==null||_.call(F,g),Tt.current||Ye.current||Ue.current||st.current)return;const R=Be(g.clientX,g.clientY),M=ae(R.x,R.y);if(M!==b&&(b&&((Q=(U=Z.current).onNodeMouseLeave)==null||Q.call(U,g,b)),M&&((Ae=(be=Z.current).onNodeMouseEnter)==null||Ae.call(be,g,M)),b=M),M&&((ce=(ee=Z.current).onNodeMouseMove)==null||ce.call(ee,g,M)),!M){const yt=lt(R.x,R.y);yt!==l&&(l&&((De=(Ce=Z.current).onEdgeMouseLeave)==null||De.call(Ce,g,l)),yt&&((Ge=(Xe=Z.current).onEdgeMouseEnter)==null||Ge.call(Xe,g,yt)),l=yt),yt&&((Jt=(qe=Z.current).onEdgeMouseMove)==null||Jt.call(qe,g,yt))}},w=g=>{var R,M;return(M=(R=Z.current).onPaneMouseEnter)==null?void 0:M.call(R,g)},m=g=>{var R,M,F,_,U,Q;(M=(R=Z.current).onPaneMouseLeave)==null||M.call(R,g),b&&((_=(F=Z.current).onNodeMouseLeave)==null||_.call(F,g,b),b=null),l&&((Q=(U=Z.current).onEdgeMouseLeave)==null||Q.call(U,g,l),l=null)};return u.addEventListener("mousemove",x),u.addEventListener("mouseenter",w),u.addEventListener("mouseleave",m),()=>{u.removeEventListener("mousemove",x),u.removeEventListener("mouseenter",w),u.removeEventListener("mouseleave",m)}},[Be,ae,lt]),c.useEffect(()=>{const u=Array.isArray(Ze)?Ze:[Ze],b=async l=>{var x,w,m,g;if(u.includes(l.key)){if(l.target.tagName==="INPUT"||l.target.tagName==="TEXTAREA"||l.target.isContentEditable)return;const R=K.current.filter(_=>_.selected),M=ze.current.filter(_=>_.selected);if(!R.length&&!M.length)return;if(Z.current.onBeforeDelete)try{if(!await Z.current.onBeforeDelete({nodes:R,edges:M}))return}catch(_){(w=(x=Z.current).onError)==null||w.call(x,"before-delete-error",_.message||"onBeforeDelete threw an error");return}const F=new Set(R.map(_=>_.id));if(R.length&&ke.current&&(ke.current(R.map(_=>({id:_.id,type:"remove"}))),_e.current)){const _=ze.current.filter(U=>F.has(U.source)||F.has(U.target));_.length&&_e.current(_.map(U=>({id:U.id,type:"remove"})))}M.length&&_e.current&&_e.current(M.map(_=>({id:_.id,type:"remove"}))),(g=(m=Z.current).onDelete)==null||g.call(m,{nodes:R,edges:M})}if((l.ctrlKey||l.metaKey)&&l.key==="a"){if(l.target.tagName==="INPUT"||l.target.tagName==="TEXTAREA")return;if(l.preventDefault(),ke.current){const R=K.current.filter(M=>!M.selected).map(M=>({id:M.id,type:"select",selected:!0}));R.length&&ke.current(R)}if(_e.current){const R=ze.current.filter(M=>!M.selected).map(M=>({id:M.id,type:"select",selected:!0}));R.length&&_e.current(R)}}};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[Ze]);const vn=c.useRef(!1);c.useEffect(()=>{var u,b;if(!vn.current&&Le.current){if(vn.current=!0,et&&K.current.length>0){const l=me.current;if(l){const x=l.getBoundingClientRect(),w=(ye==null?void 0:ye.padding)??.1,m=Rn(K.current),g=qt(m,x.width,x.height,w);ye!=null&&ye.maxZoom&&(g.zoom=Math.min(g.zoom,ye.maxZoom)),ye!=null&&ye.minZoom&&(g.zoom=Math.max(g.zoom,ye.minZoom)),ue.current=g,ve()}}(b=(u=Z.current).onInit)==null||b.call(u,{getNodes:()=>[...K.current],getEdges:()=>[...ze.current],getNode:l=>K.current.find(x=>x.id===l),getEdge:l=>ze.current.find(x=>x.id===l),getViewport:()=>({...ue.current}),getZoom:()=>ue.current.zoom,setViewport:l=>{ue.current={x:l.x??ue.current.x,y:l.y??ue.current.y,zoom:l.zoom??ue.current.zoom},ve()},fitView:(l={})=>{const x=me.current;if(!x||!K.current.length)return;const w=x.getBoundingClientRect(),m=l.nodes?K.current.filter(M=>l.nodes.some(F=>F.id===M.id)):K.current;if(!m.length)return;const g=Rn(m),R=qt(g,w.width,w.height,l.padding??.1);l.maxZoom&&(R.zoom=Math.min(R.zoom,l.maxZoom)),l.minZoom&&(R.zoom=Math.max(R.zoom,l.minZoom)),ue.current=R,ve()},screenToFlowPosition:l=>Be(l.x,l.y),flowToScreenPosition:l=>{const x=ue.current,w=me.current;if(!w)return{x:0,y:0};const m=w.getBoundingClientRect();return{x:l.x*x.zoom+x.x+m.left,y:l.y*x.zoom+x.y+m.top}},zoomIn:()=>{const l=ue.current;l.zoom=Math.min(le,l.zoom*1.2),ve()},zoomOut:()=>{const l=ue.current;l.zoom=Math.max(ne,l.zoom/1.2),ve()},zoomTo:l=>{ue.current.zoom=Math.min(le,Math.max(ne,l)),ve()},setNodes:l=>{var x,w;(w=(x=Z.current).onNodesChange)==null||w.call(x,[...K.current.map(m=>({id:m.id,type:"remove"})),...(typeof l=="function"?l(K.current):l).map(m=>({type:"add",item:m}))])},setEdges:l=>{var x,w;(w=(x=Z.current).onEdgesChange)==null||w.call(x,[...ze.current.map(m=>({id:m.id,type:"remove"})),...(typeof l=="function"?l(ze.current):l).map(m=>({type:"add",item:m}))])},addNodes:l=>{var w,m;const x=Array.isArray(l)?l:[l];(m=(w=Z.current).onNodesChange)==null||m.call(w,x.map(g=>({type:"add",item:g})))},addEdges:l=>{var w,m;const x=Array.isArray(l)?l:[l];(m=(w=Z.current).onEdgesChange)==null||m.call(w,x.map(g=>({type:"add",item:g})))},deleteElements:({nodes:l=[],edges:x=[]})=>{var w,m,g,R;l.length&&((m=(w=Z.current).onNodesChange)==null||m.call(w,l.map(M=>({id:M.id,type:"remove"})))),x.length&&((R=(g=Z.current).onEdgesChange)==null||R.call(g,x.map(M=>({id:M.id,type:"remove"}))))},updateNodeData:(l,x)=>{var g,R;const w=K.current.find(M=>M.id===l);if(!w)return;const m=typeof x=="function"?x(w.data):{...w.data,...x};(R=(g=Z.current).onNodesChange)==null||R.call(g,[{id:l,type:"replace",item:{...w,data:m}}])},toObject:()=>({nodes:[...K.current],edges:[...ze.current],viewport:{...ue.current}}),setCenter:(l,x,w={})=>{const m=me.current;if(!m)return;const g=m.getBoundingClientRect(),R=w.zoom??ue.current.zoom;ue.current={x:g.width/2-l*R,y:g.height/2-x*R,zoom:R},ve()},fitBounds:(l,x={})=>{const w=me.current;if(!w)return;const m=w.getBoundingClientRect(),g=qt(l,m.width,m.height,x.padding??.1);ue.current=g,ve()}})}});const Wn=c.useCallback(()=>{ue.current={...Ee},ve()},[ve,Ee]),Fn=c.useCallback(u=>{var b;if(u)mt.current.push(u);else{const l=ue.current,x=me.current;if(!x)return;const w=x.getBoundingClientRect(),m=Math.round(-l.x/l.zoom+w.width/2/l.zoom),g=Math.round(-l.y/l.zoom+w.height/2/l.zoom);mt.current.push({x:m-80,y:g-45,w:160,h:90,title:"Note "+(mt.current.length+1),body:"Added at viewport center"})}(b=Le.current)==null||b.postMessage({type:"cards",data:{cards:[...mt.current]}})},[]),W=c.useCallback(u=>{if(u.id||(u.id="node-"+Date.now()),!u.position){const b=ue.current,l=me.current;if(!l)return;const x=l.getBoundingClientRect();u.position={x:Math.round(-b.x/b.zoom+x.width/2/b.zoom)-ft/2,y:Math.round(-b.y/b.zoom+x.height/2/b.zoom)-nt/2}}u.data||(u.data={label:u.id}),ke.current&&ke.current([{type:"add",item:u}])},[]),xe=c.useCallback(()=>({...ue.current}),[]),V=c.useCallback(u=>{ue.current={...ue.current,...u},ve()},[ve]),Ne=c.useCallback(u=>Be(u.x,u.y),[Be]),He=n,Ie=c.useMemo(()=>({wrapRef:me,canvasRef:Pt,workerRef:Le,cameraRef:ue,nodesRef:K,edgesRef:ze,handleRegistryRef:fn,syncNodesToWorker:pn,onNodesChangeRef:ke,onEdgesChangeRef:_e,sendCamera:ve,screenToWorld:Be,viewportListeners:vt,selectionListeners:it,zoomMin:ne,zoomMax:le,snapToGrid:je,snapGrid:Fe,nodeExtent:pt,defaultEdgeOptions:zt,edgeRouting:wt,resolvedNodesRef:ct,noDragClassName:Nt,noPanClassName:It,get nodes(){return t},get edges(){return n},get routedEdges(){return He},get viewport(){return gn},get connection(){return Gt}}),[t,n,He,gn,Gt,ve,Be,pn,vt,it,ne,le,je,Fe,pt,zt,wt,Nt,It]);return{wrapRef:me,canvasRef:Pt,canvasReady:Bt,onPointerDown:mn,onPointerMove:Qt,onPointerUp:_n,resetView:Wn,addCard:Fn,addNode:W,getCamera:xe,setCamera:V,screenToFlowPosition:Ne,store:Ie}}function ro(e,t,n,r,i,o){const a=i-n,f=o-r,p=a*a+f*f;if(p===0)return Math.hypot(e-n,t-r);let d=((e-n)*a+(t-r)*f)/p;return d=Math.max(0,Math.min(1,d)),Math.hypot(e-(n+d*a),t-(r+d*f))}const ur=e=>{let t;const n=new Set,r=(d,h)=>{const k=typeof d=="function"?d(t):d;if(!Object.is(k,t)){const S=t;t=h??(typeof k!="object"||k===null)?k:Object.assign({},t,k),n.forEach(E=>E(t,S))}},i=()=>t,f={setState:r,getState:i,getInitialState:()=>p,subscribe:d=>(n.add(d),()=>n.delete(d))},p=t=e(r,i,f);return f},oo=(e=>e?ur(e):ur),so=e=>e;function io(e,t=so){const n=c.useSyncExternalStore(e.subscribe,c.useCallback(()=>t(e.getState()),[e,t]),c.useCallback(()=>t(e.getInitialState()),[e,t]));return c.useDebugValue(n),n}const Ct=c.createContext(null);function ao(e={}){return oo((t,n)=>({nodes:[],edges:[],viewport:{x:0,y:0,zoom:1},connection:null,minZoom:.1,maxZoom:5,width:0,height:0,domNode:null,nodesRef:{current:[]},edgesRef:{current:[]},cameraRef:{current:{x:0,y:0,zoom:1}},wrapRef:{current:null},workerRef:{current:null},onNodesChangeRef:{current:null},onEdgesChangeRef:{current:null},viewportListeners:new Set,selectionListeners:new Set,edgeLabelContainerRef:{current:null},viewportPortalRef:{current:null},screenToWorld:(r,i)=>{const o=n().cameraRef.current;return{x:(r-o.x)/o.zoom,y:(i-o.y)/o.zoom}},sendCamera:()=>{var i;const r=n();(i=r.workerRef.current)==null||i.postMessage({type:"camera",data:{camera:{...r.cameraRef.current}}})},...e}))}function Pe(e,t){const n=c.useContext(Ct);if(!n)throw new Error("useCanvasStore must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");const r=typeof n.getState=="function"&&typeof n.subscribe=="function",i=c.useRef(e),o=c.useRef(t),a=c.useRef(void 0);i.current=e,o.current=t;const f=c.useCallback(p=>{const d=i.current;if(!d)return p;const h=d(p),k=o.current||Object.is;return a.current!==void 0&&k(a.current,h)?a.current:(a.current=h,h)},[]);return r?io(n,e?f:void 0):e?f(n):n}function Rr(){const e=c.useContext(Ct);if(!e)throw new Error("useCanvasStoreApi must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");return typeof e.getState=="function"?e:{getState:()=>e,setState:()=>{},subscribe:()=>()=>{}}}const on=c.createContext(null);function co(){return c.useContext(on)}function lo({node:e,nodeType:t}){var z,j,L,A;const n=Pe(),r=c.useRef(n);r.current=n;const i=c.useRef(null),o=e._absolutePosition||e.position,a=c.useRef(null);c.useEffect(()=>{const X=i.current;if(!X)return;const D=new ResizeObserver(Y=>{var q,O,H,C;const{width:$,height:I}=Y[0].contentRect;if($>0&&I>0){const y=r.current,v=y.nodesRef.current.find(B=>B.id===e.id),N=(v==null?void 0:v.width)||((q=v==null?void 0:v.measured)==null?void 0:q.width),P=(v==null?void 0:v.height)||((O=v==null?void 0:v.measured)==null?void 0:O.height);(Math.abs((N||0)-$)>1||Math.abs((P||0)-I)>1)&&((C=(H=y.onNodesChangeRef).current)==null||C.call(H,[{id:e.id,type:"dimensions",dimensions:{width:$,height:I},setAttributes:!0}]))}});return D.observe(X),()=>D.disconnect()},[e.id]);const f=c.useCallback(X=>{var se,he,ge,fe;X.stopPropagation();const D=X.target.tagName;if(D==="INPUT"||D==="TEXTAREA"||D==="SELECT"||D==="BUTTON"||D==="A"||D==="LABEL"||X.target.isContentEditable)return;const Y=r.current.noDragClassName||"nodrag",$=r.current.noPanClassName||"nopan";let I=X.target;for(;I&&I!==i.current;){if((se=I.classList)!=null&&se.contains(Y)||(he=I.classList)!=null&&he.contains($))return;I=I.parentElement}if(r.current.onNodesChangeRef.current){const ie=[];if(X.shiftKey)ie.push({id:e.id,type:"select",selected:!e.selected});else for(const ne of r.current.nodesRef.current)ne.id===e.id&&!ne.selected?ie.push({id:ne.id,type:"select",selected:!0}):ne.id!==e.id&&ne.selected&&ie.push({id:ne.id,type:"select",selected:!1});ie.length&&r.current.onNodesChangeRef.current(ie)}const q=r.current.cameraRef.current,O=r.current.wrapRef.current;if(!O)return;const H=O.getBoundingClientRect(),C=(X.clientX-H.left-q.x)/q.zoom,y=(X.clientY-H.top-q.y)/q.zoom,N=e.selected?r.current.nodesRef.current.filter(ie=>ie.selected&&ie.id!==e.id).map(ie=>({id:ie.id,startPos:{...ie.position}})):[];a.current={startPos:{...e.position},startMouse:{x:C,y},selectedStarts:N};const P=[{id:e.id,type:"position",dragging:!0}];for(const ie of N)P.push({id:ie.id,type:"position",dragging:!0});(fe=(ge=r.current.onNodesChangeRef).current)==null||fe.call(ge,P);const B=i.current;B&&B.setPointerCapture(X.pointerId);let J=null;const oe=ie=>{var We,Se,tt,rt;if(!a.current)return;const Me=r.current.cameraRef.current,ne=O.getBoundingClientRect(),le=(ie.clientX-ne.left-Me.x)/Me.zoom,Ee=(ie.clientY-ne.top-Me.y)/Me.zoom,et=le-a.current.startMouse.x,ye=Ee-a.current.startMouse.y;let Re={x:a.current.startPos.x+et,y:a.current.startPos.y+ye};if(r.current.snapToGrid&&r.current.snapGrid&&(Re={x:r.current.snapGrid[0]*Math.round(Re.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Re.y/r.current.snapGrid[1])}),e.parentId&&e.extent==="parent"){const we=r.current.nodesRef.current.find(Te=>Te.id===e.parentId);if(we){const Te=we.width||160,Oe=we.height||60,je=e.width||((We=e.measured)==null?void 0:We.width)||160,Fe=e.height||((Se=e.measured)==null?void 0:Se.height)||60;Re={x:Math.max(0,Math.min(Re.x,Te-je)),y:Math.max(0,Math.min(Re.y,Oe-Fe))}}}B&&(B.style.left=Re.x+"px",B.style.top=Re.y+"px");const $e=[{id:e.id,position:Re,_absolutePosition:Re,dragging:!0}];for(const we of a.current.selectedStarts){let Te={x:we.startPos.x+et,y:we.startPos.y+ye};r.current.snapToGrid&&r.current.snapGrid&&(Te={x:r.current.snapGrid[0]*Math.round(Te.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Te.y/r.current.snapGrid[1])});const Oe=O.querySelector(`[data-nodeid="${we.id}"]`);Oe&&(Oe.style.left=Te.x+"px",Oe.style.top=Te.y+"px"),$e.push({id:we.id,position:Te,_absolutePosition:Te,dragging:!0})}(rt=(tt=r.current.workerRef)==null?void 0:tt.current)==null||rt.postMessage({type:"nodePositions",data:{updates:$e}});for(const we of $e){const Te=r.current.nodesRef.current.find(Oe=>Oe.id===we.id);Te&&(Te.position=we.position)}J=$e},te=ie=>{var ne,le;if(!a.current)return;const Me=[];if(J)for(const Ee of J)Me.push({id:Ee.id,type:"position",position:Ee.position,dragging:!1});else{Me.push({id:e.id,type:"position",dragging:!1});for(const Ee of a.current.selectedStarts)Me.push({id:Ee.id,type:"position",dragging:!1})}(le=(ne=r.current.onNodesChangeRef).current)==null||le.call(ne,Me),a.current=null,J=null,B&&B.releasePointerCapture(ie.pointerId),B==null||B.removeEventListener("pointermove",oe),B==null||B.removeEventListener("pointerup",te)};B==null||B.addEventListener("pointermove",oe),B==null||B.addEventListener("pointerup",te)},[e]),p=c.useCallback(X=>{var O,H,C,y,v,N;if(!e.selected)return;const D=X.shiftKey?10:1;let Y=0,$=0;switch(X.key){case"ArrowUp":$=-D;break;case"ArrowDown":$=D;break;case"ArrowLeft":Y=-D;break;case"ArrowRight":Y=D;break;case"Escape":(H=(O=r.current.onNodesChangeRef).current)==null||H.call(O,[{id:e.id,type:"select",selected:!1}]);return;case"Delete":case"Backspace":e.deletable!==!1&&((y=(C=r.current.onNodesChangeRef).current)==null||y.call(C,[{id:e.id,type:"remove"}]));return;default:return}X.preventDefault();const I={x:e.position.x+Y,y:e.position.y+$},q=[{id:e.id,type:"position",position:I}];for(const P of r.current.nodesRef.current)P.selected&&P.id!==e.id&&q.push({id:P.id,type:"position",position:{x:P.position.x+Y,y:P.position.y+$}});(N=(v=r.current.onNodesChangeRef).current)==null||N.call(v,q)},[e]),d=e.width||((z=e.measured)==null?void 0:z.width),h=e.height||((j=e.measured)==null?void 0:j.height),k=!!(d&&h),S=(L=n.pinnedNodeIds)==null?void 0:L.has(e.id),E=c.useCallback(X=>{var D,Y;X.stopPropagation(),(Y=(D=r.current).togglePinNode)==null||Y.call(D,e.id)},[e.id]);return T.jsx(on.Provider,{value:e.id,children:T.jsxs("div",{ref:i,className:`ric-node-wrapper ${e.selected?"selected":""} ${e.dragging?"dragging":""}`,style:{position:"absolute",left:o.x,top:o.y,zIndex:e.type==="group"?0:e.zIndex||1,pointerEvents:e.type==="group"?"none":"all",visibility:k?"visible":"hidden",outline:"none"},"data-nodeid":e.id,tabIndex:e.selectable!==!1?0:void 0,role:"button","aria-label":`Node ${((A=e.data)==null?void 0:A.label)||e.id}`,"aria-selected":!!e.selected,onPointerDown:f,onKeyDown:p,children:[T.jsx(t,{id:e.id,data:e.data,type:e.type,selected:!!e.selected,dragging:!!e.dragging,draggable:e.draggable!==!1,selectable:e.selectable!==!1,deletable:e.deletable!==!1,isConnectable:e.connectable!==!1,zIndex:e.zIndex||0,positionAbsoluteX:o.x,positionAbsoluteY:o.y,width:d,height:h,sourcePosition:e.sourcePosition,targetPosition:e.targetPosition,parentId:e.parentId,dragHandle:e.dragHandle}),n.togglePinNode&&T.jsx("button",{className:"ric-pin-btn nodrag",onClick:E,title:S?"Unpin from DOM":"Pin to DOM",style:{position:"absolute",top:-8,left:-8,width:20,height:20,borderRadius:"50%",border:"1.5px solid "+(S?"#3b82f6":"#ccc"),background:S?"#3b82f6":"#fff",color:S?"#fff":"#999",fontSize:10,lineHeight:"16px",textAlign:"center",cursor:"pointer",padding:0,zIndex:10,pointerEvents:"all",boxShadow:"0 1px 3px rgba(0,0,0,0.12)"},children:"📌"})]})})}const uo=c.memo(lo),kr=160,Cr=60;function dr(e,t,n,r){var f,p;const i=e.width||((f=e.measured)==null?void 0:f.width)||kr,o=e.height||((p=e.measured)==null?void 0:p.height)||Cr,a=e._absolutePosition||e.position;if(e.handleBounds){const d=e.handleBounds[t]||[],h=n?d.find(k=>k.id===n):d[0];if(h&&h.x!==void 0&&h.y!==void 0){const k=h.position||(t==="source"?"right":"left");return{x:a.x+h.x,y:a.y+h.y,position:k}}}if(r){const d=`${e.id}__${n||t}`,h=r.get(d);if(h&&h.x!==void 0&&h.y!==void 0)return{x:a.x+h.x,y:a.y+h.y,position:h.position||(t==="source"?"right":"left")}}if(e.handles&&e.handles.length){for(const d of e.handles)if(d.type===t&&(!n||d.id===n)){if(d.x!==void 0&&d.y!==void 0)return{x:a.x+d.x,y:a.y+d.y,position:d.position||(t==="source"?"right":"left")};const h=d.position||(t==="source"?"right":"left");switch(h){case"top":return{x:a.x+i/2,y:a.y,position:h};case"bottom":return{x:a.x+i/2,y:a.y+o,position:h};case"left":return{x:a.x,y:a.y+o/2,position:h};default:return{x:a.x+i,y:a.y+o/2,position:h}}}}return t==="source"?{x:a.x+i,y:a.y+o/2,position:"right"}:{x:a.x,y:a.y+o/2,position:"left"}}function fo(e,t,n){return n==="left"?e-t:n==="right"?e+t:e}function ho(e,t,n){return n==="top"?e-t:n==="bottom"?e+t:e}function fr({x:e,y:t,position:n,type:r,onPointerDown:i}){return T.jsx("circle",{className:`ric-edge-anchor ric-edge-anchor-${r}`,cx:fo(e,10,n),cy:ho(t,10,n),r:10,stroke:"transparent",fill:"transparent",style:{cursor:"move",pointerEvents:"stroke"},onPointerDown:i})}function go({edge:e,edgeType:t,nodes:n,reconnectable:r}){var I,q,O;const i=c.useContext(Ct),o=c.useRef(typeof i.getState=="function"?i.getState():i);o.current=typeof i.getState=="function"?i.getState():i;const[a,f]=c.useState(null),p=c.useCallback((H,C,y,v)=>{var he;C.stopPropagation(),C.preventDefault();const N=o.current,P=N.wrapRef.current;if(!P)return;const B=H==="source"?v:y,J=H==="source"?e.target:e.source;(he=N.workerRef.current)==null||he.postMessage({type:"connecting",data:{from:{x:B.x,y:B.y},to:{x:B.x,y:B.y}}});const oe=P.getBoundingClientRect(),te=ge=>{var ne;const fe=N.cameraRef.current,ie=(ge.clientX-oe.left-fe.x)/fe.zoom,Me=(ge.clientY-oe.top-fe.y)/fe.zoom;(ne=N.workerRef.current)==null||ne.postMessage({type:"connecting",data:{from:{x:B.x,y:B.y},to:{x:ie,y:Me}}})},se=ge=>{var ye,Re,$e,We;const fe=N.cameraRef.current,ie=(ge.clientX-oe.left-fe.x)/fe.zoom,Me=(ge.clientY-oe.top-fe.y)/fe.zoom,ne=20/fe.zoom;let le=null,Ee=null;const et=(ye=N.handleRegistryRef)==null?void 0:ye.current;for(const Se of N.nodesRef.current){if(Se.hidden)continue;const tt=Se.width||kr,rt=Se.height||Cr,we=Se._absolutePosition||Se.position,Te=[];if(et)for(const[,je]of et)je.nodeId===Se.id&&Te.push(je);const Oe=Te.length>0?Te:Se.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const je of Oe){let Fe,Ze;if(je.x!==void 0&&je.y!==void 0)Fe=we.x+je.x,Ze=we.y+je.y;else switch(je.position||(je.type==="source"?"right":"left")){case"top":Fe=we.x+tt/2,Ze=we.y;break;case"bottom":Fe=we.x+tt/2,Ze=we.y+rt;break;case"left":Fe=we.x,Ze=we.y+rt/2;break;default:Fe=we.x+tt,Ze=we.y+rt/2;break}if(Math.abs(ie-Fe)<ne&&Math.abs(Me-Ze)<ne){le=Se,Ee=je.id||null;break}}if(le)break}if(le){const Se=H==="source"?{source:le.id,target:J,sourceHandle:Ee,targetHandle:e.targetHandle}:{source:J,target:le.id,sourceHandle:e.sourceHandle,targetHandle:Ee};($e=(Re=N.onEdgesChangeRef).current)==null||$e.call(Re,[{id:e.id,type:"remove"},{type:"add",item:{id:e.id,...Se}}])}(We=N.workerRef.current)==null||We.postMessage({type:"connecting",data:null}),P.removeEventListener("pointermove",te),P.removeEventListener("pointerup",se)};P.addEventListener("pointermove",te),P.addEventListener("pointerup",se)},[e]),d=n.find(H=>H.id===e.source),h=n.find(H=>H.id===e.target),k=d&&!!(d.width||(I=d.measured)!=null&&I.width),S=h&&!!(h.width||(q=h.measured)!=null&&q.width),E=o.current,z=(O=E.handleRegistryRef)==null?void 0:O.current,j=k?dr(d,"source",e.sourceHandle,z):null,L=S?dr(h,"target",e.targetHandle,z):null,A=e.type==="bezier"||e.type==="simplebezier"||e.type==="default",X=E.routedEdges||E.edges,D=X==null?void 0:X.find(H=>H.id===e.id),Y=A?null:(D==null?void 0:D._routedPoints)||e._routedPoints||null,$=r!==!1&&e.reconnectable!==!1;return!j||!L?null:T.jsxs("g",{className:`ric-edge-wrapper ${e.selected?"selected":""}`,"data-edgeid":e.id,onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),children:[T.jsx(t,{id:e.id,source:e.source,target:e.target,sourceX:j.x,sourceY:j.y,targetX:L.x,targetY:L.y,sourcePosition:j.position,targetPosition:L.position,sourceHandleId:e.sourceHandle,targetHandleId:e.targetHandle,data:e.data,type:e.type,selected:!!e.selected,animated:!!e.animated,label:e.label,style:e.style,selectable:e.selectable!==!1,deletable:e.deletable!==!1,routedPoints:Y}),$&&(a||e.selected)&&T.jsxs(T.Fragment,{children:[T.jsx(fr,{x:j.x,y:j.y,position:j.position,type:"source",onPointerDown:H=>p("source",H,j,L)}),T.jsx(fr,{x:L.x,y:L.y,position:L.position,type:"target",onPointerDown:H=>p("target",H,j,L)})]})]})}const yo=c.memo(go);function Er({selectionKeyCode:e="Shift",selectionMode:t="partial"}){var j;const n=Pe(),[r,i]=c.useState(null),o=c.useRef(null);if(c.useEffect(()=>{const L=n.wrapRef.current;if(!L)return;let A=!1,X=null,D=!1;const Y=H=>{H.key===e&&(D=!0)},$=H=>{H.key===e&&(D=!1)},I=H=>{if(!D)return;const C=H.target;if(C.closest(".ric-node-wrapper")||C.closest(".ric-handle"))return;A=!0;const y=n.cameraRef.current,v=L.getBoundingClientRect(),N=(H.clientX-v.left-y.x)/y.zoom,P=(H.clientY-v.top-y.y)/y.zoom;X={x:N,y:P},i({startX:N,startY:P,endX:N,endY:P}),H.stopPropagation()},q=H=>{if(!A||!X)return;const C=n.cameraRef.current,y=L.getBoundingClientRect(),v=(H.clientX-y.left-C.x)/C.zoom,N=(H.clientY-y.top-C.y)/C.zoom;i({startX:X.x,startY:X.y,endX:v,endY:N})},O=H=>{var J,oe;if(!A||!X)return;A=!1;const C=n.cameraRef.current,y=L.getBoundingClientRect(),v=(H.clientX-y.left-C.x)/C.zoom,N=(H.clientY-y.top-C.y)/C.zoom,P={x:Math.min(X.x,v),y:Math.min(X.y,N),width:Math.abs(v-X.x),height:Math.abs(N-X.y)},B=[];for(const te of n.nodesRef.current){const se=te._absolutePosition||te.position,he=te.width||160,ge=te.height||60;let fe;t==="full"?fe=se.x>=P.x&&se.y>=P.y&&se.x+he<=P.x+P.width&&se.y+ge<=P.y+P.height:fe=se.x+he>P.x&&se.x<P.x+P.width&&se.y+ge>P.y&&se.y<P.y+P.height,B.push({id:te.id,type:"select",selected:fe})}B.length&&((oe=(J=n.onNodesChangeRef).current)==null||oe.call(J,B)),X=null,i(null)};return L.addEventListener("pointerdown",I,!0),L.addEventListener("pointermove",q),L.addEventListener("pointerup",O),window.addEventListener("keydown",Y),window.addEventListener("keyup",$),()=>{L.removeEventListener("pointerdown",I,!0),L.removeEventListener("pointermove",q),L.removeEventListener("pointerup",O),window.removeEventListener("keydown",Y),window.removeEventListener("keyup",$)}},[n,e,t]),!r)return null;const a=((j=n.cameraRef)==null?void 0:j.current)||{x:0,y:0,zoom:1},f=Math.min(r.startX,r.endX),p=Math.min(r.startY,r.endY),d=Math.abs(r.endX-r.startX),h=Math.abs(r.endY-r.startY),k=f*a.zoom+a.x,S=p*a.zoom+a.y,E=d*a.zoom,z=h*a.zoom;return T.jsx("div",{ref:o,className:"ric-selection-box",style:{position:"absolute",left:k,top:S,width:E,height:z,border:"1px dashed #3b82f6",background:"rgba(59, 130, 246, 0.08)",pointerEvents:"none",zIndex:100}})}Er.displayName="SelectionBox";const Sr=c.memo(Er);function Qn(e,t,n){switch(e){case"top":return{x:t/2,y:0};case"bottom":return{x:t/2,y:n};case"left":return{x:0,y:n/2};case"right":return{x:t,y:n/2};default:return{x:t,y:n/2}}}function xo(e,t){const n=e.closest(".ric-node-wrapper");if(!n)return null;const r=n.getBoundingClientRect(),i=e.getBoundingClientRect(),o=t||1;return{x:(i.left+i.width/2-r.left)/o,y:(i.top+i.height/2-r.top)/o}}let On=!1,kt=null;function zr(e){kt=e,!On&&(On=!0,requestAnimationFrame(()=>{var t;On=!1,(t=kt==null?void 0:kt.syncNodesToWorker)==null||t.call(kt),kt=null}))}const Jn=new WeakMap;let wn=null;function po(){return wn||(wn=new ResizeObserver(e=>{var t;for(const n of e){const r=Jn.get(n.target);if(!r)continue;const{width:i,height:o}=n.contentRect;if(!i||!o)continue;const a=r.getStore(),f=(t=a.handleRegistryRef)==null?void 0:t.current;if(f){for(const[p,d]of f)if(d.nodeId===r.nodeId){const h=Qn(d.position,i,o);d.x=h.x,d.y=h.y,f.set(p,d)}zr(a)}}}),wn)}function mo({type:e="source",position:t=e==="source"?"right":"left",id:n,isConnectable:r=!0,isConnectableStart:i=!0,isConnectableEnd:o=!0,children:a,className:f="",style:p={},onConnect:d,...h}){const k=c.useContext(on),S=c.useContext(Ct),E=c.useRef(null),z=c.useCallback(()=>typeof S.getState=="function"?S.getState():S,[S]),j=c.useRef(z);j.current=z,c.useLayoutEffect(()=>{var C,y,v,N,P,B,J;if(!k)return;const D=j.current(),Y=(C=D.handleRegistryRef)==null?void 0:C.current;if(!Y)return;const $=`${k}__${n||e}`,I=(v=(y=D.nodesRef)==null?void 0:y.current)==null?void 0:v.find(oe=>oe.id===k),q=(I==null?void 0:I.width)||((N=I==null?void 0:I.measured)==null?void 0:N.width),O=(I==null?void 0:I.height)||((P=I==null?void 0:I.measured)==null?void 0:P.height);let H;q&&O?H=Qn(t,q,O):E.current?H=xo(E.current,(J=(B=D.cameraRef)==null?void 0:B.current)==null?void 0:J.zoom):H=Qn(t,160,60),Y.set($,{nodeId:k,id:n||null,type:e,position:t,x:H.x,y:H.y})},[k,n,e,t]),c.useEffect(()=>{if(!k)return;const D=j.current();zr(D);const Y=E.current,$=Y==null?void 0:Y.closest(".ric-node-wrapper");return $&&!Jn.has($)&&(Jn.set($,{nodeId:k,getStore:j.current}),po().observe($)),()=>{var H;const q=(H=j.current().handleRegistryRef)==null?void 0:H.current,O=`${k}__${n||e}`;q==null||q.delete(O)}},[k,n,e,t]);const L=c.useCallback(()=>{var y;const D=j.current(),Y=D.nodesRef.current.find(v=>v.id===k);if(!Y)return null;const $=Y._absolutePosition||Y.position,I=(y=D.handleRegistryRef)==null?void 0:y.current,q=`${k}__${n||e}`,O=I==null?void 0:I.get(q);if(O&&O.x!==void 0&&O.y!==void 0)return{x:$.x+O.x,y:$.y+O.y};const H=Y.width||160,C=Y.height||60;switch(t){case"top":return{x:$.x+H/2,y:$.y};case"bottom":return{x:$.x+H/2,y:$.y+C};case"left":return{x:$.x,y:$.y+C/2};default:return{x:$.x+H,y:$.y+C/2}}},[k,n,e,t]),A=c.useCallback(D=>{var N;if(!r||!i)return;D.stopPropagation(),D.preventDefault();const Y=j.current(),$=Y.cameraRef.current,I=Y.wrapRef.current;if(!I)return;const q=I.getBoundingClientRect(),O=L();if(!O)return;const H=O.x,C=O.y;(N=Y.workerRef.current)==null||N.postMessage({type:"connecting",data:{from:{x:H,y:C},to:{x:H,y:C}}}),I.setPointerCapture(D.pointerId);const y=P=>{var oe;const B=(P.clientX-q.left-$.x)/$.zoom,J=(P.clientY-q.top-$.y)/$.zoom;(oe=Y.workerRef.current)==null||oe.postMessage({type:"connecting",data:{from:{x:H,y:C},to:{x:B,y:J}}})},v=P=>{var ge,fe,ie,Me;const B=(P.clientX-q.left-$.x)/$.zoom,J=(P.clientY-q.top-$.y)/$.zoom,oe=20/$.zoom;let te=null,se=null;const he=(ge=Y.handleRegistryRef)==null?void 0:ge.current;for(const ne of Y.nodesRef.current){if(ne.id===k||ne.hidden)continue;const le=ne._absolutePosition||ne.position,Ee=[];if(he)for(const[,ye]of he)ye.nodeId===ne.id&&Ee.push(ye);const et=Ee.length>0?Ee:ne.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const ye of et){let Re,$e;if(ye.x!==void 0&&ye.y!==void 0)Re=le.x+ye.x,$e=le.y+ye.y;else{const We=ne.width||160,Se=ne.height||60;switch(ye.position||(ye.type==="source"?"right":"left")){case"top":Re=le.x+We/2,$e=le.y;break;case"bottom":Re=le.x+We/2,$e=le.y+Se;break;case"left":Re=le.x,$e=le.y+Se/2;break;default:Re=le.x+We,$e=le.y+Se/2;break}}if(Math.abs(B-Re)<oe&&Math.abs(J-$e)<oe){te=ne,se=ye.id||null;break}}if(te)break}if(te){const ne={source:e==="source"?k:te.id,target:e==="source"?te.id:k,sourceHandle:e==="source"?n||null:se,targetHandle:e==="source"?se:n||null};(ie=(fe=Y.onEdgesChangeRef)==null?void 0:fe.current)==null||ie.call(fe,[{type:"add",item:{id:`e-${ne.source}-${ne.target}`,...ne}}])}(Me=Y.workerRef.current)==null||Me.postMessage({type:"connecting",data:null}),I.removeEventListener("pointermove",y),I.removeEventListener("pointerup",v)};I.addEventListener("pointermove",y),I.addEventListener("pointerup",v)},[k,n,e,t,r,i,L]),X={top:{top:0,left:"50%",transform:"translate(-50%, -50%)"},bottom:{bottom:0,left:"50%",transform:"translate(-50%, 50%)"},left:{top:"50%",left:0,transform:"translate(-50%, -50%)"},right:{top:"50%",right:0,transform:"translate(50%, -50%)"}}[t]||{};return T.jsx("div",{ref:E,className:`ric-handle ric-handle-${t} ric-handle-${e} ${f}`,"data-handleid":n||null,"data-nodeid":k,"data-handlepos":t,"data-handletype":e,onPointerDown:A,style:{position:"absolute",width:8,height:8,borderRadius:"50%",background:"#1a192b",border:"none",zIndex:10,cursor:r?"crosshair":"default",boxSizing:"border-box",...X,...p},...h,children:a})}const rn=c.memo(mo);function vo({data:e,isConnectable:t,selected:n,targetPosition:r="left",sourcePosition:i="right",hideSourceHandle:o=!1,hideTargetHandle:a=!1}){return T.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:[!a&&T.jsx(rn,{type:"target",position:r,isConnectable:t}),T.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!o&&T.jsx(rn,{type:"source",position:i,isConnectable:t})]})}function Nr({data:e,isConnectable:t,selected:n,sourcePosition:r="right",hideSourceHandle:i=!1}){return T.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:[T.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!i&&T.jsx(rn,{type:"source",position:r,isConnectable:t})]})}function Ir({data:e,isConnectable:t,selected:n,targetPosition:r="left",hideTargetHandle:i=!1}){return T.jsxs("div",{className:`ric-output-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderTop:"2px solid #ff0072",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!i&&T.jsx(rn,{type:"target",position:r,isConnectable:t}),T.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label})]})}function Pr({data:e,selected:t,width:n,height:r}){return T.jsx("div",{className:`ric-group-node${t?" selected":""}`,style:{width:n||300,height:r||200,background:"rgba(240, 240, 240, 0.25)",border:t?"2px solid #3b82f6":"1px dashed #ccc",borderRadius:8,padding:8,boxSizing:"border-box"},children:(e==null?void 0:e.label)&&T.jsx("div",{style:{fontSize:11,fontWeight:600,color:"#888",userSelect:"none"},children:e.label})})}function Tr({x:e,y:t,label:n,labelStyle:r,labelShowBg:i=!0,labelBgStyle:o,labelBgPadding:a=[2,4],labelBgBorderRadius:f=2,children:p,className:d="",...h}){const[k,S]=c.useState({x:1,y:0,width:0,height:0}),E=c.useRef(null);return c.useEffect(()=>{if(E.current){const z=E.current.getBBox();S({x:z.x,y:z.y,width:z.width,height:z.height})}},[n]),n?T.jsxs("g",{transform:`translate(${e-k.width/2} ${t-k.height/2})`,className:`ric-edge-textwrapper ${d}`,visibility:k.width?"visible":"hidden",...h,children:[i&&T.jsx("rect",{width:k.width+2*a[0],x:-a[0],y:-a[1],height:k.height+2*a[1],className:"ric-edge-textbg",style:o,rx:f,ry:f}),T.jsx("text",{className:"ric-edge-text",y:k.height/2,dy:"0.3em",ref:E,style:r,children:n}),p]}):null}Tr.displayName="EdgeText";const Lr=c.memo(Tr);function hr(e){return e!=null&&e!==""&&!isNaN(Number(e))}function sn({id:e,path:t,labelX:n,labelY:r,label:i,labelStyle:o,labelShowBg:a,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:d,interactionWidth:h=20,style:k,markerEnd:S,markerStart:E,className:z="",...j}){return T.jsxs(T.Fragment,{children:[T.jsx("path",{id:e,d:t,fill:"none",stroke:"#b1b1b7",strokeWidth:1.5,className:`ric-edge-path ${z}`,style:k,markerEnd:S,markerStart:E,...j}),h?T.jsx("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:h,className:"ric-edge-interaction",style:{pointerEvents:"stroke"}}):null,i&&hr(n)&&hr(r)?T.jsx(Lr,{x:n,y:r,label:i,labelStyle:o,labelShowBg:a,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:d}):null]})}const en=20;function gr(e,t,n){switch(n){case"right":return{x:e+en,y:t};case"left":return{x:e-en,y:t};case"bottom":return{x:e,y:t+en};case"top":return{x:e,y:t-en};default:return{x:e+en,y:t}}}const er=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:a="bottom",targetPosition:f="top",label:p,labelStyle:d,labelShowBg:h,labelBgStyle:k,labelBgPadding:S,labelBgBorderRadius:E,style:z,markerEnd:j,markerStart:L,interactionWidth:A}){let X,D,Y;const $=gr(n,r,a),I=gr(i,o,f),q=Math.abs(I.x-$.x),O=Math.max(50,q*.5);let H,C,y,v;switch(a){case"left":H=$.x-O,C=$.y;break;case"top":H=$.x,C=$.y-O;break;case"bottom":H=$.x,C=$.y+O;break;default:H=$.x+O,C=$.y;break}switch(f){case"right":y=I.x+O,v=I.y;break;case"top":y=I.x,v=I.y-O;break;case"bottom":y=I.x,v=I.y+O;break;default:y=I.x-O,v=I.y;break}X=`M ${n},${r} L ${$.x},${$.y} C ${H},${C} ${y},${v} ${I.x},${I.y} L ${i},${o}`;const N=.5,P=.5;return D=P*P*P*$.x+3*P*P*N*H+3*P*N*N*y+N*N*N*I.x,Y=P*P*P*$.y+3*P*P*N*C+3*P*N*N*v+N*N*N*I.y,T.jsx(sn,{id:t,path:X,labelX:D,labelY:Y,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:k,labelBgPadding:S,labelBgBorderRadius:E,style:z,markerEnd:j,markerStart:L,interactionWidth:A})});er.displayName="BezierEdge";function tr({sourceX:e,sourceY:t,targetX:n,targetY:r}){const i=`M ${e},${t}L ${n},${r}`,o=(e+n)/2,a=(t+r)/2;return[i,o,a,0,0]}function nr({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i="right",targetPosition:o="left",curvature:a=.25}){const f=Math.abs(n-e),p=Math.abs(r-t),d=Math.sqrt(f*f+p*p),h=Math.max(d*a,50);let k,S,E,z;switch(i){case"top":k=e,S=t-h;break;case"bottom":k=e,S=t+h;break;case"left":k=e-h,S=t;break;default:k=e+h,S=t;break}switch(o){case"top":E=n,z=r-h;break;case"bottom":E=n,z=r+h;break;case"right":E=n+h,z=r;break;default:E=n-h,z=r;break}const j=`M ${e},${t} C ${k},${S} ${E},${z} ${n},${r}`,L=.5,A=1-L,X=A*A*A*e+3*A*A*L*k+3*A*L*L*E+L*L*L*n,D=A*A*A*t+3*A*A*L*S+3*A*L*L*z+L*L*L*r;return[j,X,D,0,0]}function rr({sourceX:e,sourceY:t,targetX:n,targetY:r}){const i=Math.abs(n-e),o=Math.max(i*.5,50),a=e+o,f=n-o,p=`M ${e},${t} C ${a},${t} ${f},${r} ${n},${r}`,d=.5,h=.5,k=h*h*h*e+3*h*h*d*a+3*h*d*d*f+d*d*d*n,S=h*h*h*t+3*h*h*d*t+3*h*d*d*r+d*d*d*r;return[p,k,S,0,0]}function kn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i="right",targetPosition:o="left",borderRadius:a=5,offset:f=20}){const p=i==="left"||i==="right",d=Math.min(a,Math.abs(n-e)/2,Math.abs(r-t)/2);if(p){if(Math.abs(r-t)<1)return[`M ${e},${t} L ${n},${r}`,(e+n)/2,t,0,0];const E=(e+n)/2,z=r>t?1:-1;return[`M ${e},${t} L ${E-d},${t} Q ${E},${t} ${E},${t+z*d} L ${E},${r-z*d} Q ${E},${r} ${E+(n>E?d:-d)},${r} L ${n},${r}`,E,(t+r)/2,0,0]}const h=(t+r)/2,k=n>e?1:-1;return[`M ${e},${t} L ${e},${h-d} Q ${e},${h} ${e+k*d},${h} L ${n-k*d},${h} Q ${n},${h} ${n},${h+(r>h?d:-d)} L ${n},${r}`,(e+n)/2,h,0,0]}function bo({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[,i,o]=nr({sourceX:e,sourceY:t,targetX:n,targetY:r});return[i,o,0,0]}function wo({sourceX:e,sourceY:t,targetX:n,targetY:r}){return[(e+n)/2,(t+r)/2,0,0]}function Mo(e,t,n){const r=n.filter(o=>o.id!==e.id),i={...e,id:e.id,source:t.source,target:t.target,sourceHandle:t.sourceHandle??e.sourceHandle,targetHandle:t.targetHandle??e.targetHandle};return r.push(i),r}const Cn=160,En=60,tn=20,Mn=12,Sn=20;function yr(e,t,n){var a,f;const r=e.width||((a=e.measured)==null?void 0:a.width)||Cn,i=e.height||((f=e.measured)==null?void 0:f.height)||En,o=e._absolutePosition||e.position;if(e.handles&&e.handles.length>0){for(const p of e.handles)if(p.type===t&&(!n||p.id===n)){if(p.x!==void 0&&p.y!==void 0)return{x:o.x+p.x,y:o.y+p.y,dir:p.position||(t==="source"?"right":"left")};switch(p.position||(t==="source"?"right":"left")){case"top":return{x:o.x+r/2,y:o.y,dir:"top"};case"bottom":return{x:o.x+r/2,y:o.y+i,dir:"bottom"};case"left":return{x:o.x,y:o.y+i/2,dir:"left"};default:return{x:o.x+r,y:o.y+i/2,dir:"right"}}}}return t==="source"?{x:o.x+r,y:o.y+i/2,dir:"right"}:{x:o.x,y:o.y+i/2,dir:"left"}}function zn(e,t){switch(e.dir){case"right":return{x:e.x+t,y:e.y,dir:e.dir};case"left":return{x:e.x-t,y:e.y,dir:e.dir};case"bottom":return{x:e.x,y:e.y+t,dir:e.dir};case"top":return{x:e.x,y:e.y-t,dir:e.dir};default:return{x:e.x+t,y:e.y,dir:e.dir}}}function Ro(e,t,n,r,i,o,a,f){const p=Math.min(e,n),d=Math.max(e,n),h=Math.min(t,r),k=Math.max(t,r);if(d<=i||p>=i+a||k<=o||h>=o+f)return!1;const S=.5;if(e>i+S&&e<i+a-S&&t>o+S&&t<o+f-S||n>i+S&&n<i+a-S&&r>o+S&&r<o+f-S)return!0;const E=(e+n)/2,z=(t+r)/2;if(E>i+S&&E<i+a-S&&z>o+S&&z<o+f-S)return!0;const j=[[i,o],[i+a,o],[i+a,o+f],[i,o+f]];for(let L=0;L<4;L++)if(ko(e,t,n,r,j[L][0],j[L][1],j[(L+1)%4][0],j[(L+1)%4][1]))return!0;return!1}function ko(e,t,n,r,i,o,a,f){const p=(a-i)*(t-o)-(f-o)*(e-i),d=(a-i)*(r-o)-(f-o)*(n-i),h=(n-e)*(o-t)-(r-t)*(i-e),k=(n-e)*(f-t)-(r-t)*(a-e);return(p>0&&d<0||p<0&&d>0)&&(h>0&&k<0||h<0&&k>0)}function Kn(e,t,n,r,i){for(let o=0;o<i.length;o++){const a=i[o];if(Ro(e,t,n,r,a.x,a.y,a.w,a.h))return!1}return!0}function Co(e,t,n){for(let r=0;r<n.length;r++){const i=n[r];if(e>i.x&&e<i.x+i.w&&t>i.y&&t<i.y+i.h)return!0}return!1}function or(e,t){var r,i;const n=[];for(let o=0;o<e.length;o++){const a=e[o];if(a.hidden||t&&t.has(a.id)||a.type==="group")continue;const f=a._absolutePosition||a.position,p=a.width||((r=a.measured)==null?void 0:r.width)||Cn,d=a.height||((i=a.measured)==null?void 0:i.height)||En;n.push({id:a.id,x:f.x-tn,y:f.y-tn,w:p+2*tn,h:d+2*tn})}return n}function Br(e,t,n){if(Kn(e.x,e.y,t.x,t.y,n))return null;const r=new Set,i=new Set;r.add(e.x),r.add(t.x),i.add(e.y),i.add(t.y);const o=tn+5;e.dir==="right"?r.add(e.x+o):e.dir==="left"?r.add(e.x-o):e.dir==="top"?i.add(e.y-o):e.dir==="bottom"&&i.add(e.y+o),t.dir==="right"?r.add(t.x+o):t.dir==="left"?r.add(t.x-o):t.dir==="top"?i.add(t.y-o):t.dir==="bottom"&&i.add(t.y+o);for(let y=0;y<n.length;y++){const v=n[y];r.add(v.x),r.add(v.x+v.w),i.add(v.y),i.add(v.y+v.h)}const a=[...r].sort((y,v)=>y-v),f=[...i].sort((y,v)=>y-v),p=new Map,d=new Map;for(let y=0;y<a.length;y++)p.set(a[y],y);for(let y=0;y<f.length;y++)d.set(f[y],y);const h=a.length,k=f.length,S=(y,v)=>v*h+y,E=p.get(e.x),z=d.get(e.y),j=p.get(t.x),L=d.get(t.y);if(E===void 0||z===void 0||j===void 0||L===void 0)return null;const A=S(E,z),X=S(j,L),D=new Float64Array(h*k).fill(1/0),Y=new Float64Array(h*k).fill(1/0),$=new Int32Array(h*k).fill(-1),I=new Int8Array(h*k).fill(-1),q=new Uint8Array(h*k);D[A]=0,Y[A]=Math.abs(a[j]-e.x)+Math.abs(f[L]-e.y);const O=[A],H=15,C=[[1,0],[-1,0],[0,1],[0,-1]];for(;O.length>0;){let y=0;for(let te=1;te<O.length;te++)Y[O[te]]<Y[O[y]]&&(y=te);const v=O[y];if(O[y]=O[O.length-1],O.pop(),v===X){const te=[];let se=X;for(;se!==-1&&se!==A;){const he=se/h|0,ge=se%h;te.unshift({x:a[ge],y:f[he]}),se=$[se]}return te.unshift({x:e.x,y:e.y}),Eo(te,n)}if(q[v])continue;q[v]=1;const N=v/h|0,P=v%h,B=a[P],J=f[N],oe=I[v];for(let te=0;te<4;te++){const se=P+C[te][0],he=N+C[te][1];if(se<0||se>=h||he<0||he>=k)continue;const ge=S(se,he);if(q[ge])continue;const fe=a[se],ie=f[he];if(Co(fe,ie,n)||!Kn(B,J,fe,ie,n))continue;const Me=Math.abs(fe-B)+Math.abs(ie-J),ne=oe>=0&&oe!==te?H:0,le=D[v]+Me+ne;le<D[ge]&&($[ge]=v,I[ge]=te,D[ge]=le,Y[ge]=le+Math.abs(a[j]-fe)+Math.abs(f[L]-ie),O.push(ge))}}return null}function Eo(e,t){if(!e||e.length<=2)return e;const n=[e[0]];for(let r=1;r<e.length-1;r++){const i=n[n.length-1],o=e[r],a=e[r+1],f=Math.abs(i.x-o.x)<.5&&Math.abs(o.x-a.x)<.5,p=Math.abs(i.y-o.y)<.5&&Math.abs(o.y-a.y)<.5;(f||p)&&Kn(i.x,i.y,a.x,a.y,t)||n.push(o)}return n.push(e[e.length-1]),n}function So(e){const t=new Map,n=new Map;for(const i of e){const o=i._routedPoints;if(!(!o||o.length<2))for(let a=0;a<o.length-1;a++){const f=o[a],p=o[a+1];if(Math.abs(f.y-p.y)<.5){const d=Math.round(f.y*10)/10;t.has(d)||t.set(d,[]),t.get(d).push({edgeId:i.id,segIdx:a,x1:Math.min(f.x,p.x),x2:Math.max(f.x,p.x)})}else if(Math.abs(f.x-p.x)<.5){const d=Math.round(f.x*10)/10;n.has(d)||n.set(d,[]),n.get(d).push({edgeId:i.id,segIdx:a,y1:Math.min(f.y,p.y),y2:Math.max(f.y,p.y)})}}}const r=new Map;for(const i of e)i._routedPoints&&r.set(i.id,i._routedPoints.map(o=>({...o})));for(const[,i]of t){if(i.length<2)continue;const o=xr(i,"x1","x2");for(const a of o){if(a.length<2)continue;const f=(a.length-1)*Mn/2;for(let p=0;p<a.length;p++){const d=a[p],h=-f+p*Mn,k=r.get(d.edgeId);k&&(k[d.segIdx].y+=h,k[d.segIdx+1].y+=h)}}}for(const[,i]of n){if(i.length<2)continue;const o=xr(i,"y1","y2");for(const a of o){if(a.length<2)continue;const f=(a.length-1)*Mn/2;for(let p=0;p<a.length;p++){const d=a[p],h=-f+p*Mn,k=r.get(d.edgeId);k&&(k[d.segIdx].x+=h,k[d.segIdx+1].x+=h)}}}return e.map(i=>{const o=r.get(i.id);return o?{...i,_routedPoints:o}:i})}function xr(e,t,n){if(e.length<2)return[];const r=[...e].sort((a,f)=>a[t]-f[t]),i=[];let o=[r[0]];for(let a=1;a<r.length;a++){const f=o[o.length-1];r[a][t]<f[n]?o.push(r[a]):(o.length>1&&i.push(o),o=[r[a]])}return o.length>1&&i.push(o),i}function Nn(e,t=6,n=!1){if(!e||e.length<2)return null;if(n)return zo(e);const r=t;let i=`M ${e[0].x},${e[0].y}`;for(let o=1;o<e.length-1;o++){const a=e[o-1],f=e[o],p=e[o+1],d=Math.abs(f.x-a.x)+Math.abs(f.y-a.y),h=Math.abs(p.x-f.x)+Math.abs(p.y-f.y),k=Math.min(r,d/2,h/2);if(k>.5){const S=f.x-a.x,E=f.y-a.y,z=p.x-f.x,j=p.y-f.y,L=Math.sqrt(S*S+E*E)||1,A=Math.sqrt(z*z+j*j)||1;i+=` L ${f.x-S/L*k},${f.y-E/L*k}`,i+=` Q ${f.x},${f.y} ${f.x+z/A*k},${f.y+j/A*k}`}else i+=` L ${f.x},${f.y}`}return i+=` L ${e[e.length-1].x},${e[e.length-1].y}`,i}function zo(e){if(e.length===2)return`M ${e[0].x},${e[0].y} L ${e[1].x},${e[1].y}`;if(e.length===3)return`M ${e[0].x},${e[0].y} Q ${e[1].x},${e[1].y} ${e[2].x},${e[2].y}`;const t=.3;let n=`M ${e[0].x},${e[0].y}`;for(let r=0;r<e.length-1;r++){const i=e[r===0?0:r-1],o=e[r],a=e[r+1],f=e[r+2<e.length?r+2:e.length-1],p=o.x+(a.x-i.x)*t,d=o.y+(a.y-i.y)*t,h=a.x-(f.x-o.x)*t,k=a.y-(f.y-o.y)*t;n+=` C ${p},${d} ${h},${k} ${a.x},${a.y}`}return n}function In(e){if(!e||e.length<2)return{x:0,y:0};let t=0;for(let r=1;r<e.length;r++)t+=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);let n=t/2;for(let r=1;r<e.length;r++){const i=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);if(n<=i){const o=i>0?n/i:0;return{x:e[r-1].x+(e[r].x-e[r-1].x)*o,y:e[r-1].y+(e[r].y-e[r-1].y)*o}}n-=i}return{x:e[0].x,y:e[0].y}}function No(e,t){if(!e||!t||e.length===0||t.length===0)return t;const n={};for(const o of e)n[o.id]=o;const r=or(e,null),i=t.map(o=>{var I,q,O,H;const a=o.type||"default";if(a==="bezier"||a==="simplebezier"||a==="default")return o;const f=n[o.source],p=n[o.target];if(!f||!p||f.hidden||p.hidden)return o;const d=yr(f,"source",o.sourceHandle),h=yr(p,"target",o.targetHandle),k=zn(d,Sn),S=zn(h,Sn),E=5,z=r.filter(C=>C.id!==o.source&&C.id!==o.target),j=f._absolutePosition||f.position,L=f.width||((I=f.measured)==null?void 0:I.width)||Cn,A=f.height||((q=f.measured)==null?void 0:q.height)||En;z.push({id:o.source,x:j.x-E,y:j.y-E,w:L+2*E,h:A+2*E});const X=p._absolutePosition||p.position,D=p.width||((O=p.measured)==null?void 0:O.width)||Cn,Y=p.height||((H=p.measured)==null?void 0:H.height)||En;if(z.push({id:o.target,x:X.x-E,y:X.y-E,w:D+2*E,h:Y+2*E}),z.length===0)return o;const $=Br(k,S,z);return $&&$.length>=2?($.unshift({x:d.x,y:d.y}),$.push({x:h.x,y:h.y}),{...o,_routedPoints:$}):o});return So(i)}function Io(e,t,n,r,i,o,a,f){const p=or(a,f?new Set(f):null);if(p.length===0)return null;const d={x:e,y:t,dir:i||"right"},h={x:n,y:r,dir:o||"left"},k=zn(d,Sn),S=zn(h,Sn),E=Br(k,S,p);return E&&E.length>=2?(E.unshift({x:d.x,y:d.y}),E.push({x:h.x,y:h.y}),E):null}const sr=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,label:a,labelStyle:f,labelShowBg:p,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:k,style:S,markerEnd:E,markerStart:z,interactionWidth:j,routedPoints:L}){let A,X,D;if(L&&L.length>=2){A=Nn(L);const Y=In(L);X=Y.x,D=Y.y}else[A,X,D]=tr({sourceX:n,sourceY:r,targetX:i,targetY:o});return T.jsx(sn,{id:t,path:A,labelX:X,labelY:D,label:a,labelStyle:f,labelShowBg:p,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:k,style:S,markerEnd:E,markerStart:z,interactionWidth:j})});sr.displayName="StraightEdge";const ir=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:a="bottom",targetPosition:f="top",label:p,labelStyle:d,labelShowBg:h,labelBgStyle:k,labelBgPadding:S,labelBgBorderRadius:E,style:z,markerEnd:j,markerStart:L,pathOptions:A,interactionWidth:X,routedPoints:D}){let Y,$,I;if(D&&D.length>=2){Y=Nn(D);const q=In(D);$=q.x,I=q.y}else[Y,$,I]=kn({sourceX:n,sourceY:r,sourcePosition:a,targetX:i,targetY:o,targetPosition:f,borderRadius:A==null?void 0:A.borderRadius,offset:A==null?void 0:A.offset});return T.jsx(sn,{id:t,path:Y,labelX:$,labelY:I,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:k,labelBgPadding:S,labelBgBorderRadius:E,style:z,markerEnd:j,markerStart:L,interactionWidth:X})});ir.displayName="SmoothStepEdge";const $r=c.memo(function({id:t,...n}){var i;const r=c.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(i=n.pathOptions)==null?void 0:i.offset]);return T.jsx(ir,{...n,id:t,pathOptions:r})});$r.displayName="StepEdge";const ar=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:a,targetPosition:f,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:k,labelBgPadding:S,labelBgBorderRadius:E,style:z,markerEnd:j,markerStart:L,interactionWidth:A,routedPoints:X}){let D,Y,$;if(X&&X.length>=2){D=Nn(X);const I=In(X);Y=I.x,$=I.y}else[D,Y,$]=rr({sourceX:n,sourceY:r,targetX:i,targetY:o});return T.jsx(sn,{id:t,path:D,labelX:Y,labelY:$,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:k,labelBgPadding:S,labelBgBorderRadius:E,style:z,markerEnd:j,markerStart:L,interactionWidth:A})});ar.displayName="SimpleBezierEdge";const Po={input:Nr,output:Ir,group:Pr},To={bezier:er,straight:sr,simplebezier:ar},Lo=160,Bo=60;function $o(e){let t=!1;for(let n=0;n<e.length;n++){const r=e[n];if(!r.measured||r.measured.width==null||r.measured.height==null){t=!0;break}}return t?e.map(n=>{var r,i;return((r=n.measured)==null?void 0:r.width)!=null&&((i=n.measured)==null?void 0:i.height)!=null?n:{...n,measured:{width:n.width||Lo,height:n.height||Bo}}}):e}function jo({cards:e,nodes:t=[],edges:n=[],nodeTypes:r,edgeTypes:i,canvasNodeTypes:o,domNodeLimit:a=50,dark:f,gridSize:p,width:d="100%",height:h="420px",className:k="",style:S={},zoomMin:E,zoomMax:z,initialCamera:j,fitView:L,fitViewOptions:A,onNodesChange:X,onEdgesChange:D,onConnect:Y,onConnectStart:$,onConnectEnd:I,onNodeClick:q,onNodeDoubleClick:O,onNodeMouseEnter:H,onNodeMouseMove:C,onNodeMouseLeave:y,onNodeContextMenu:v,onNodeDragStart:N,onNodeDrag:P,onNodeDragStop:B,onEdgeClick:J,onEdgeDoubleClick:oe,onEdgeMouseEnter:te,onEdgeMouseMove:se,onEdgeMouseLeave:he,onEdgeContextMenu:ge,onPaneClick:fe,onPaneContextMenu:ie,onPaneMouseEnter:Me,onPaneMouseMove:ne,onPaneMouseLeave:le,onSelectionChange:Ee,onInit:et,onMoveStart:ye,onMove:Re,onMoveEnd:$e,onDelete:We,onBeforeDelete:Se,onError:tt,onDragOver:rt,onDrop:we,onDragEnter:Te,onDragLeave:Oe,nodesDraggable:je,nodesConnectable:Fe,elementsSelectable:Ze,multiSelectionKeyCode:Et,selectionOnDrag:an,selectionMode:St,connectionMode:cn,connectionRadius:ln,connectOnClick:un,isValidConnection:dn,defaultEdgeOptions:Zt,snapToGrid:xt,snapGrid:pt,deleteKeyCode:zt,panActivationKeyCode:Pn,panOnScroll:Tn,panOnScrollMode:ot,panOnScrollSpeed:cr,zoomOnScroll:Ln,zoomOnDoubleClick:Bn,zoomOnPinch:Nt,preventScrolling:It,translateExtent:$n,nodeExtent:jn,autoPanOnNodeDrag:An,autoPanOnConnect:wt,autoPanSpeed:me,edgesReconnectable:Pt,elevateNodesOnSelect:Le,elevateEdgesOnSelect:ue,noDragClassName:mt,noPanClassName:K,onSelectionDragStart:ze,onSelectionDrag:fn,onSelectionDragStop:Tt,edgeRouting:Lt=!0,onHudUpdate:Bt,onNodesProcessed:Dn,showHud:Ye=!0,showHint:Ue=!0,hintText:$t="Drag to pan · Scroll to zoom",children:st,...hn}){const[Je,gn]=c.useState({wx:0,wy:0,zoom:"1.00"}),yn=c.useRef(null),Gt=c.useRef(null),xn=c.useCallback(W=>{gn(W),Bt==null||Bt(W)},[Bt]),vt=c.useMemo(()=>({...Po,...r}),[r]),it=c.useMemo(()=>({...To,...i}),[i]),Ke=c.useMemo(()=>$o(t),[t]),[Z,at]=c.useState(()=>new Set),jt=c.useRef(Z);jt.current=Z;const At=c.useCallback(W=>{at(xe=>{const V=new Set(xe);return V.add(W),V})},[]),Dt=c.useCallback(W=>{at(xe=>{const V=new Set(xe);return V.delete(W),V})},[]),Ht=c.useCallback(W=>{at(xe=>{const V=new Set(xe);return V.has(W)?V.delete(W):V.add(W),V})},[]),Ve=c.useMemo(()=>Ke.filter(W=>W.type&&vt[W.type]),[Ke,vt]),_t=c.useMemo(()=>n.filter(W=>W.type&&it[W.type]),[n,it]),[Wt,Ft]=c.useState(()=>new Set),Yt=c.useRef(new Set),ke=c.useMemo(()=>{const W=new Set(Wt);for(const V of Z)W.add(V);for(const V of Ve)(V.selected||V.dragging)&&W.add(V.id);const xe=Yt.current;if(xe.size===W.size){let V=!0;for(const Ne of W)if(!xe.has(Ne)){V=!1;break}if(V)return xe}return Yt.current=W,W},[Ve,Z,Wt]),ht=c.useMemo(()=>{if(a===0)return[];const W=Ke.filter(xe=>ke.has(xe.id));return W.sort((xe,V)=>{const Ne=xe.type==="group"||!xe.parentId&&W.some(Ie=>Ie.parentId===xe.id),He=V.type==="group"||!V.parentId&&W.some(Ie=>Ie.parentId===V.id);return Ne&&!He?-1:!Ne&&He?1:0})},[Ke,ke,a]),_e=c.useMemo(()=>t.map(W=>ke.has(W.id)?{...W,_customRendered:!0}:W),[t,ke]),Hn=c.useMemo(()=>n.map(W=>W.type&&it[W.type]?{...W,_customRendered:!0}:W),[n,it]),{wrapRef:gt,canvasRef:Xt,canvasReady:ct,onPointerDown:bt,onPointerMove:pn,onPointerUp:Be,store:ae}=Mr({cards:e,nodes:_e,edges:Hn,dark:f,gridSize:p,zoomMin:E,zoomMax:z,initialCamera:j,fitView:L,fitViewOptions:A,onHudUpdate:xn,onNodesProcessed:Dn,onNodesChange:X,onEdgesChange:D,onConnect:Y,onConnectStart:$,onConnectEnd:I,onNodeClick:q,onNodeDoubleClick:O,onNodeMouseEnter:H,onNodeMouseMove:C,onNodeMouseLeave:y,onNodeContextMenu:v,onNodeDragStart:N,onNodeDrag:P,onNodeDragStop:B,onEdgeClick:J,onEdgeDoubleClick:oe,onEdgeMouseEnter:te,onEdgeMouseMove:se,onEdgeMouseLeave:he,onEdgeContextMenu:ge,onPaneClick:fe,onPaneContextMenu:ie,onPaneMouseEnter:Me,onPaneMouseMove:ne,onPaneMouseLeave:le,onSelectionChange:Ee,onInit:et,onMoveStart:ye,onMove:Re,onMoveEnd:$e,onDelete:We,onBeforeDelete:Se,onError:tt,nodesDraggable:je,nodesConnectable:Fe,elementsSelectable:Ze,multiSelectionKeyCode:Et,selectionOnDrag:an,selectionMode:St,connectionMode:cn,connectionRadius:ln,connectOnClick:un,isValidConnection:dn,defaultEdgeOptions:Zt,snapToGrid:xt,snapGrid:pt,deleteKeyCode:zt,panActivationKeyCode:Pn,panOnScroll:Tn,panOnScrollMode:ot,panOnScrollSpeed:cr,zoomOnScroll:Ln,zoomOnDoubleClick:Bn,zoomOnPinch:Nt,preventScrolling:It,translateExtent:$n,nodeExtent:jn,autoPanOnNodeDrag:An,autoPanOnConnect:wt,autoPanSpeed:me,edgesReconnectable:Pt,elevateNodesOnSelect:Le,elevateEdgesOnSelect:ue,noDragClassName:mt,noPanClassName:K,onSelectionDragStart:ze,onSelectionDrag:fn,onSelectionDragStop:Tt,edgeRouting:Lt});c.useEffect(()=>{if(a===0||!Ve.length)return;let W;const xe=()=>{const V=ae.cameraRef.current,Ne=ae.wrapRef.current;if(!Ne)return;const He=Ne.clientWidth,Ie=Ne.clientHeight,u=(-V.x+He/2)/V.zoom,b=(-V.y+Ie/2)/V.zoom;let l=Z.size;for(const w of Ve)(w.selected||w.dragging)&&l++;const x=Math.max(0,a-l);if(x===0)Ft(w=>w.size===0?w:new Set);else{const w=new Set(Z);for(const R of Ve)(R.selected||R.dragging)&&w.add(R.id);const m=[];for(let R=0;R<Ve.length;R++){const M=Ve[R];if(w.has(M.id))continue;const F=M._absolutePosition||M.position,_=F.x+(M.width||160)/2-u,U=F.y+(M.height||60)/2-b;m.push({id:M.id,dist:_*_+U*U})}m.sort((R,M)=>R.dist-M.dist);const g=new Set;for(let R=0;R<Math.min(x,m.length);R++)g.add(m[R].id);Ft(R=>{if(R.size!==g.size)return g;for(const M of g)if(!R.has(M))return g;return R})}};return xe(),W=setInterval(xe,500),()=>clearInterval(W)},[Ve,Z,a,ae]);const Ot=c.useRef(new Set);c.useEffect(()=>{if(!o||!ae.workerRef.current)return;let W=!1;async function xe(Ne){const He=new Blob([Ne],{type:"image/svg+xml"}),Ie=URL.createObjectURL(He),u=new Image;return u.src=Ie,await u.decode(),URL.revokeObjectURL(Ie),createImageBitmap(u)}async function V(){var b,l,x;const Ne={},He=[],Ie={},u={};for(const[w,m]of Object.entries(o)){if(typeof m=="function"){Ie[w]=m;continue}if(typeof m=="object"&&m!==null&&!(m instanceof ImageBitmap)&&!(m instanceof HTMLImageElement)&&!(m instanceof HTMLCanvasElement)&&("fill"in m||"stroke"in m||"title"in m||"accent"in m)){u[w]=m;continue}try{let g;m instanceof ImageBitmap?g=m:typeof m=="string"?g=await xe(m):m instanceof HTMLImageElement?g=await createImageBitmap(m):m instanceof HTMLCanvasElement&&(g=await createImageBitmap(m)),g&&!W&&(Ne[w]=g,He.push(g))}catch(g){console.warn(`[InfiniteCanvas] Failed to convert canvasNodeType "${w}":`,g)}}if(!W&&Object.keys(Ne).length>0&&((b=ae.workerRef.current)==null||b.postMessage({type:"nodeTypeBitmaps",data:{bitmaps:Ne}},He)),!W&&Object.keys(u).length>0&&((l=ae.workerRef.current)==null||l.postMessage({type:"nodeTypeConfigs",data:{configs:u}})),!W&&Object.keys(Ie).length>0){const w=new Map,m={},g={},R=[];let M=Ot.current.size;for(const F of t){const _=Ie[F.type];if(_)try{const U=_(F.data);if(!U)continue;let Q=w.get(U);if(!Q&&(Q="bmp_"+M++,w.set(U,Q),!Ot.current.has(U))){const be=await xe(U);if(W)return;m[Q]=be,R.push(be),Ot.current.add(U)}g[F.id]=Q}catch(U){console.warn(`[InfiniteCanvas] canvasNodeType fn error for node "${F.id}":`,U)}}W||(x=ae.workerRef.current)==null||x.postMessage({type:"nodeBitmaps",data:{cache:m,keys:g}},R)}}return V(),()=>{W=!0}},[o,t,ae.workerRef]);const Mt=c.useContext(Ct),Rt=Mt&&typeof Mt.getState=="function";c.useEffect(()=>{Rt&&queueMicrotask(()=>{Mt.setState({nodes:Ke,edges:n,nodesRef:ae.nodesRef,edgesRef:ae.edgesRef,onNodesChangeRef:ae.onNodesChangeRef,onEdgesChangeRef:ae.onEdgesChangeRef,cameraRef:ae.cameraRef,wrapRef:ae.wrapRef,workerRef:ae.workerRef})})},[Rt,Ke,n,ae,Mt]);const lt=c.useMemo(()=>({...ae,edgeLabelContainerRef:yn,viewportPortalRef:Gt,pinNode:At,unpinNode:Dt,togglePinNode:Ht,get pinnedNodeIds(){return jt.current},get nodes(){return Ke},get edges(){return n},get viewport(){return ae.cameraRef.current},get minZoom(){return ae.zoomMin||.1},get maxZoom(){return ae.zoomMax||5},get domNode(){return ae.wrapRef.current},get width(){var W;return((W=ae.wrapRef.current)==null?void 0:W.clientWidth)||0},get height(){var W;return((W=ae.wrapRef.current)==null?void 0:W.clientHeight)||0}}),[ae,Ke,n,At,Dt,Ht]),Ut=c.useRef(null),ve=c.useRef(null),ut=c.useRef(null),dt=c.useRef(null),mn=c.useRef(null);c.useEffect(()=>{let W;const xe=()=>{const V=ae.cameraRef.current,Ne=`translate(${V.x}px, ${V.y}px) scale(${V.zoom})`,He=`translate(${V.x}, ${V.y}) scale(${V.zoom})`;Ut.current&&(Ut.current.style.transform=Ne),ve.current&&ve.current.setAttribute("transform",He),ut.current&&(ut.current.style.transform=Ne),dt.current&&(dt.current.style.transform=Ne);const Ie=gt.current;if(Ie){const u=V.zoom<.15?"lod-minimal":V.zoom<.35?"lod-reduced":null;u!==mn.current&&(Ie.classList.remove("lod-minimal","lod-reduced"),u&&Ie.classList.add(u),mn.current=u)}W=requestAnimationFrame(xe)};return W=requestAnimationFrame(xe),()=>cancelAnimationFrame(W)},[ae]);const[Qt,_n]=c.useState(null);c.useEffect(()=>{if(!ht.length)return;let W;const xe=()=>{var m,g;const V=ae.cameraRef.current,Ne=ae.wrapRef.current;if(!Ne){W=requestAnimationFrame(xe);return}const He=Ne.getBoundingClientRect(),Ie=200,u=-V.x/V.zoom-Ie,b=-V.y/V.zoom-Ie,l=(He.width-V.x)/V.zoom+Ie,x=(He.height-V.y)/V.zoom+Ie,w=new Set;for(const R of ht){const M=R._absolutePosition||R.position,F=R.width||((m=R.measured)==null?void 0:m.width)||200,_=R.height||((g=R.measured)==null?void 0:g.height)||100;M.x+F>=u&&M.x<=l&&M.y+_>=b&&M.y<=x&&w.add(R.id)}_n(R=>{if(!R||R.size!==w.size)return w;for(const M of w)if(!R.has(M))return w;return R}),W=requestAnimationFrame(xe)};return W=requestAnimationFrame(xe),()=>cancelAnimationFrame(W)},[ht,ae]);const vn=c.useMemo(()=>Qt?ht.filter(W=>Qt.has(W.id)):ht,[ht,Qt]),Wn=ht.length>0,Fn=_t.length>0;return T.jsx(Ct.Provider,{value:lt,children:T.jsxs("div",{ref:gt,className:`ric-wrap ${k}`,style:{width:d,height:h,...S},onPointerDown:bt,onPointerMove:pn,onPointerUp:Be,onDragOver:rt,onDrop:we,onDragEnter:Te,onDragLeave:Oe,tabIndex:0,children:[T.jsx("canvas",{ref:Xt,className:"ric-canvas"}),!ct&&T.jsx("div",{className:"ric-loader",children:T.jsx("div",{className:"ric-spinner"})}),Fn&&T.jsx("svg",{className:"ric-edges-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:T.jsx("g",{ref:ve,children:_t.map(W=>T.jsx(yo,{edge:W,edgeType:it[W.type],nodes:t,reconnectable:Pt},W.id))})}),Wn&&T.jsx("div",{ref:Ut,className:"ric-nodes-overlay",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:10},children:vn.map(W=>T.jsx(uo,{node:W,nodeType:vt[W.type]},W.id))}),T.jsx("div",{ref:W=>{yn.current=W,ut.current=W},className:"ric-edge-labels",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:5}}),T.jsx("div",{ref:W=>{Gt.current=W,dt.current=W},className:"ric-viewport-portal",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:6}}),Ue&&T.jsx("div",{className:"ric-hint",children:$t}),Ye&&T.jsxs("div",{className:"ric-info",children:["world: (",Je.wx,", ",Je.wy,") zoom: ",Je.zoom,"x",Je.nodeCount>0&&T.jsxs(T.Fragment,{children:[" nodes: ",Je.nodeCount]}),Je.edgeCount>0&&T.jsxs(T.Fragment,{children:[" edges: ",Je.edgeCount]})]}),T.jsx(Sr,{selectionKeyCode:Et||"Shift",selectionMode:St||"partial"}),st]})})}function Ao({children:e}){const t=c.useRef(null);return t.current||(t.current=ao()),T.jsx(Ct.Provider,{value:t.current,children:e})}function jr(e,t){const n=[],r=new Map,i=[];for(const o of e)if(o.type==="add")i.push(o);else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const a=r.get(o.id);a?a.push(o):r.set(o.id,[o])}for(const o of t){const a=r.get(o.id);if(!a){n.push(o);continue}if(a[0].type==="remove")continue;if(a[0].type==="replace"){n.push({...a[0].item});continue}const f={...o};for(const p of a)Do(p,f);n.push(f)}for(const o of i)o.index!==void 0?n.splice(o.index,0,{...o.item}):n.push({...o.item});return n}function Do(e,t){switch(e.type){case"select":t.selected=e.selected;break;case"position":e.position!==void 0&&(t.position=e.position),e.dragging!==void 0&&(t.dragging=e.dragging);break;case"dimensions":e.dimensions!==void 0&&(t.measured={...e.dimensions},(e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height)),e.handleBounds!==void 0&&(t.handleBounds=e.handleBounds);break}}function Ar(e,t){return jr(e,t)}function Dr(e,t){return jr(e,t)}function Ho(e,t){return!e.source||!e.target?(console.warn("addEdge: source and target are required"),t):t.some(r=>r.source===e.source&&r.target===e.target&&(r.sourceHandle||null)===(e.sourceHandle||null)&&(r.targetHandle||null)===(e.targetHandle||null))?t:[...t,{id:e.id||`e-${e.source}-${e.target}`,...e}]}function _o(e){const[t,n]=c.useState(e),r=c.useCallback(i=>n(o=>Ar(i,o)),[]);return[t,n,r]}function Wo(e){const[t,n]=c.useState(e),r=c.useCallback(i=>n(o=>Dr(i,o)),[]);return[t,n,r]}function Hr(){const e=Rr(),t=c.useCallback(()=>typeof e.getState=="function"?e.getState():e,[e]),n=c.useCallback(()=>[...t().nodesRef.current],[t]),r=c.useCallback(()=>[...t().edgesRef.current],[t]),i=c.useCallback(C=>t().nodesRef.current.find(y=>y.id===C),[t]),o=c.useCallback(C=>t().edgesRef.current.find(y=>y.id===C),[t]),a=c.useCallback(C=>{var y,v,N,P;if(typeof C=="function"){const B=C(t().nodesRef.current);(v=(y=t().onNodesChangeRef).current)==null||v.call(y,[...t().nodesRef.current.map(J=>({id:J.id,type:"remove"})),...B.map(J=>({type:"add",item:J}))])}else(P=(N=t().onNodesChangeRef).current)==null||P.call(N,[...t().nodesRef.current.map(B=>({id:B.id,type:"remove"})),...C.map(B=>({type:"add",item:B}))])},[t]),f=c.useCallback(C=>{var y,v,N,P;if(typeof C=="function"){const B=C(t().edgesRef.current);(v=(y=t().onEdgesChangeRef).current)==null||v.call(y,[...t().edgesRef.current.map(J=>({id:J.id,type:"remove"})),...B.map(J=>({type:"add",item:J}))])}else(P=(N=t().onEdgesChangeRef).current)==null||P.call(N,[...t().edgesRef.current.map(B=>({id:B.id,type:"remove"})),...C.map(B=>({type:"add",item:B}))])},[t]),p=c.useCallback(C=>{var v,N;const y=Array.isArray(C)?C:[C];(N=(v=t().onNodesChangeRef).current)==null||N.call(v,y.map(P=>({type:"add",item:P})))},[t]),d=c.useCallback(C=>{var v,N;const y=Array.isArray(C)?C:[C];(N=(v=t().onEdgesChangeRef).current)==null||N.call(v,y.map(P=>({type:"add",item:P})))},[t]),h=c.useCallback(({nodes:C=[],edges:y=[]})=>{if(C.length&&t().onNodesChangeRef.current){t().onNodesChangeRef.current(C.map(N=>({id:N.id,type:"remove"})));const v=br(C,t().edgesRef.current);v.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(v.map(N=>({id:N.id,type:"remove"})))}y.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(y.map(v=>({id:v.id,type:"remove"})))},[t]),k=c.useCallback(()=>{const C=t().cameraRef.current;return{x:C.x,y:C.y,zoom:C.zoom}},[t]),S=c.useRef(null),E=c.useCallback((C,y)=>{if(S.current&&cancelAnimationFrame(S.current),!y||y<=0){t().cameraRef.current={...C},t().sendCamera();return}const v={...t().cameraRef.current},N=performance.now(),P=B=>{const J=B-N,oe=Math.min(J/y,1),te=1-Math.pow(1-oe,3);t().cameraRef.current={x:v.x+(C.x-v.x)*te,y:v.y+(C.y-v.y)*te,zoom:v.zoom+(C.zoom-v.zoom)*te},t().sendCamera(),oe<1&&(S.current=requestAnimationFrame(P))};S.current=requestAnimationFrame(P)},[t]),z=c.useCallback((C,y)=>{const v={x:C.x??t().cameraRef.current.x,y:C.y??t().cameraRef.current.y,zoom:C.zoom??t().cameraRef.current.zoom};E(v,y==null?void 0:y.duration)},[t,E]),j=c.useCallback(()=>t().cameraRef.current.zoom,[t]),L=c.useCallback(C=>{const y=t().cameraRef.current,v=t().wrapRef.current;if(!v)return;const N=v.getBoundingClientRect(),P=N.width/2,B=N.height/2,J=1.2,oe={x:P-(P-y.x)*J,y:B-(B-y.y)*J,zoom:Math.min(t().zoomMax,y.zoom*J)};E(oe,C==null?void 0:C.duration)},[t,E]),A=c.useCallback(C=>{const y=t().cameraRef.current,v=t().wrapRef.current;if(!v)return;const N=v.getBoundingClientRect(),P=N.width/2,B=N.height/2,J=1/1.2,oe={x:P-(P-y.x)*J,y:B-(B-y.y)*J,zoom:Math.max(t().zoomMin,y.zoom*J)};E(oe,C==null?void 0:C.duration)},[t,E]),X=c.useCallback((C,y)=>{const v=t().cameraRef.current,N=t().wrapRef.current;if(!N)return;const P=N.getBoundingClientRect(),B=P.width/2,J=P.height/2,oe=Math.min(t().zoomMax,Math.max(t().zoomMin,C)),te=oe/v.zoom,se={x:B-(B-v.x)*te,y:J-(J-v.y)*te,zoom:oe};E(se,y==null?void 0:y.duration)},[t,E]),D=c.useCallback((C={})=>{const y=t().nodesRef.current;if(!y.length)return;const v=t().wrapRef.current;if(!v)return;const N=v.getBoundingClientRect(),P=C.padding??.1,B=C.nodes?y.filter(te=>C.nodes.some(se=>se.id===te.id)):y;if(!B.length)return;const J=Rn(B),oe=qt(J,N.width,N.height,P);C.maxZoom&&(oe.zoom=Math.min(oe.zoom,C.maxZoom)),C.minZoom&&(oe.zoom=Math.max(oe.zoom,C.minZoom)),E(oe,C.duration)},[t,E]),Y=c.useCallback((C,y={})=>{const v=t().wrapRef.current;if(!v)return;const N=v.getBoundingClientRect(),P=y.padding??.1,B=qt(C,N.width,N.height,P);y.maxZoom&&(B.zoom=Math.min(B.zoom,y.maxZoom)),y.minZoom&&(B.zoom=Math.max(B.zoom,y.minZoom)),E(B,y.duration)},[t,E]),$=c.useCallback((C,y,v={})=>{const N=t().wrapRef.current;if(!N)return;const P=N.getBoundingClientRect(),B=v.zoom??t().cameraRef.current.zoom,J={x:P.width/2-C*B,y:P.height/2-y*B,zoom:B};E(J,v.duration)},[t,E]),I=c.useCallback(()=>({nodes:[...t().nodesRef.current],edges:[...t().edgesRef.current],viewport:{...t().cameraRef.current}}),[t]),q=c.useCallback(C=>t().screenToWorld(C.x,C.y),[t]),O=c.useCallback(C=>{const y=t().cameraRef.current,v=t().wrapRef.current;if(!v)return{x:0,y:0};const N=v.getBoundingClientRect();return{x:C.x*y.zoom+y.x+N.left,y:C.y*y.zoom+y.y+N.top}},[t]),H=c.useCallback((C,y)=>{var P,B;const v=t().nodesRef.current.find(J=>J.id===C);if(!v)return;const N=typeof y=="function"?y(v.data):{...v.data,...y};(B=(P=t().onNodesChangeRef).current)==null||B.call(P,[{id:C,type:"replace",item:{...v,data:N}}])},[t]);return{getNodes:n,getEdges:r,getNode:i,getEdge:o,setNodes:a,setEdges:f,addNodes:p,addEdges:d,deleteElements:h,getViewport:k,setViewport:z,getZoom:j,zoomIn:L,zoomOut:A,zoomTo:X,fitView:D,fitBounds:Y,setCenter:$,screenToFlowPosition:q,flowToScreenPosition:O,updateNodeData:H,toObject:I}}function Fo(){return Pe().nodes}function Yo(){return Pe().edges}function Xo(){return Pe().viewport}function Oo(){return Pe().connection}function Uo(e){const t=Pe(),n=Array.isArray(e)?e:[e];return c.useMemo(()=>n.map(r=>{const i=t.nodes.find(o=>o.id===r);return i?{id:i.id,type:i.type,data:i.data}:null}).filter(Boolean),[t.nodes,...n])}function qo(e){const t=Pe();return c.useMemo(()=>t.edges.filter(n=>n.source===e||n.target===e),[t.edges,e])}function Zo({nodeId:e,type:t,handleId:n}){const r=Pe();return c.useMemo(()=>r.edges.filter(i=>t==="source"?i.source===e&&(n?i.sourceHandle===n:!0):i.target===e&&(n?i.targetHandle===n:!0)),[r.edges,e,t,n])}function Go({onChange:e,onStart:t,onEnd:n}){const r=Pe(),i=c.useRef(e),o=c.useRef(t),a=c.useRef(n);c.useEffect(()=>{i.current=e},[e]),c.useEffect(()=>{o.current=t},[t]),c.useEffect(()=>{a.current=n},[n]),c.useEffect(()=>{const f=p=>{var d;(d=i.current)==null||d.call(i,{x:p.x,y:p.y,zoom:p.zoom})};return r.viewportListeners.add(f),()=>r.viewportListeners.delete(f)},[s])}function Qo({onChange:e}){const t=Pe(),n=c.useRef(e);c.useEffect(()=>{n.current=e},[e]),c.useEffect(()=>{const r=i=>{var o;(o=n.current)==null||o.call(n,i)};return t.selectionListeners.add(r),()=>t.selectionListeners.delete(r)},[s])}function Jo(e){const[t,n]=c.useState(!1),r=Array.isArray(e)?e:[e];return c.useEffect(()=>{const i=a=>{r.includes(a.key)&&n(!0)},o=a=>{r.includes(a.key)&&n(!1)};return window.addEventListener("keydown",i),window.addEventListener("keyup",o),()=>{window.removeEventListener("keydown",i),window.removeEventListener("keyup",o)}},[r.join(",")]),t}function Ko(){const e=Pe();return c.useCallback(t=>{var n;(n=e.workerRef.current)==null||n.postMessage({type:"nodes",data:{nodes:[...s().nodesRef.current]}})},[s])}const Vo=e=>{var t;return((t=e.nodes)==null?void 0:t.length)>0};function es(e={}){return Pe(Vo)}function ts(e){const t=Pe();return c.useMemo(()=>t.nodes.find(n=>n.id===e)||void 0,[t.nodes,e])}function ns(e,t){return Pe(e,t)}function rs(){return Rr()}function os({maxHistorySize:e=100}={}){const t=Pe(),n=c.useRef([]),r=c.useRef([]),[,i]=c.useState(0),o=c.useRef(null),a=c.useCallback(()=>{const d={nodes:s().nodesRef.current.map(h=>({...h,data:{...h.data}})),edges:s().edgesRef.current.map(h=>({...h}))};o.current&&JSON.stringify(o.current.nodes.map(h=>h.id))===JSON.stringify(d.nodes.map(h=>h.id))&&JSON.stringify(o.current.edges.map(h=>h.id))===JSON.stringify(d.edges.map(h=>h.id))||(n.current.push(d),n.current.length>e&&n.current.shift(),r.current=[],o.current=d,i(h=>h+1))},[t,e]),f=c.useCallback(()=>{var h,k,S,E;const d=n.current.pop();d&&(r.current.push({nodes:s().nodesRef.current.map(z=>({...z,data:{...z.data}})),edges:s().edgesRef.current.map(z=>({...z}))}),(k=(h=s().onNodesChangeRef).current)==null||k.call(h,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...d.nodes.map(z=>({type:"add",item:z}))]),(E=(S=s().onEdgesChangeRef).current)==null||E.call(S,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...d.edges.map(z=>({type:"add",item:z}))]),o.current=d,i(z=>z+1))},[s]),p=c.useCallback(()=>{var h,k,S,E;const d=r.current.pop();d&&(n.current.push({nodes:s().nodesRef.current.map(z=>({...z,data:{...z.data}})),edges:s().edgesRef.current.map(z=>({...z}))}),(k=(h=s().onNodesChangeRef).current)==null||k.call(h,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...d.nodes.map(z=>({type:"add",item:z}))]),(E=(S=s().onEdgesChangeRef).current)==null||E.call(S,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...d.edges.map(z=>({type:"add",item:z}))]),o.current=d,i(z=>z+1))},[s]);return{undo:f,redo:p,takeSnapshot:a,canUndo:n.current.length>0,canRedo:r.current.length>0}}function ss(e){const t=c.useRef(e);return c.useEffect(()=>{t.current=e},[e]),c.useCallback(n=>r=>{const i=t.current(r);i!==!1&&i!=null&&n(Array.isArray(i)?i:r)},[])}function is(e){const t=c.useRef(e);return c.useEffect(()=>{t.current=e},[e]),c.useCallback(n=>r=>{const i=t.current(r);i!==!1&&i!=null&&n(Array.isArray(i)?i:r)},[])}const Un=160,qn=60;function as({width:e=200,height:t=150,nodeColor:n="#3b82f6",nodeStrokeColor:r="#fff",maskColor:i="rgba(0,0,0,0.1)",style:o={},className:a=""}){const f=Pe(),p=c.useRef(null),d=c.useRef(null),h=c.useCallback(()=>{const k=p.current;if(!k)return;const S=k.getContext("2d"),E=window.devicePixelRatio||1;k.width=e*E,k.height=t*E,S.scale(E,E),S.clearRect(0,0,e,t);const z=f.nodesRef.current;if(!z.length)return;let j=1/0,L=1/0,A=-1/0,X=-1/0;for(const y of z){const v=y.width||Un,N=y.height||qn;y.position.x<j&&(j=y.position.x),y.position.y<L&&(L=y.position.y),y.position.x+v>A&&(A=y.position.x+v),y.position.y+N>X&&(X=y.position.y+N)}const D=40;j-=D,L-=D,A+=D,X+=D;const Y=A-j,$=X-L,I=Math.min(e/Y,t/$),q=(e-Y*I)/2,O=(t-$*I)/2;for(const y of z){if(y.hidden)continue;const v=y.width||Un,N=y.height||qn,P=(y.position.x-j)*I+q,B=(y.position.y-L)*I+O,J=v*I,oe=N*I;S.fillStyle=y.selected?"#f59e0b":typeof n=="function"?n(y):n,S.fillRect(P,B,Math.max(J,2),Math.max(oe,2))}const H=f.cameraRef.current,C=f.wrapRef.current;if(C){const y=C.getBoundingClientRect(),v=-H.x/H.zoom,N=-H.y/H.zoom,P=y.width/H.zoom,B=y.height/H.zoom;S.fillStyle=i,S.fillRect(0,0,e,t);const J=(v-j)*I+q,oe=(N-L)*I+O,te=P*I,se=B*I;S.clearRect(J,oe,te,se);for(const he of z){if(he.hidden)continue;const ge=he.width||Un,fe=he.height||qn,ie=(he.position.x-j)*I+q,Me=(he.position.y-L)*I+O;S.fillStyle=he.selected?"#f59e0b":typeof n=="function"?n(he):n,S.fillRect(ie,Me,Math.max(ge*I,2),Math.max(fe*I,2))}S.strokeStyle="#3b82f6",S.lineWidth=1.5,S.strokeRect(J,oe,te,se)}},[f,e,t,n,r,i]);return c.useEffect(()=>{let k=!0;function S(){k&&(h(),d.current=requestAnimationFrame(S))}const E=setInterval(()=>{cancelAnimationFrame(d.current),d.current=requestAnimationFrame(S)},66);return h(),()=>{k=!1,clearInterval(E),cancelAnimationFrame(d.current)}},[h]),T.jsx("canvas",{ref:p,className:`ric-minimap ${a}`,style:{position:"absolute",bottom:30,right:10,width:e,height:t,borderRadius:4,border:"1px solid rgba(0,0,0,0.1)",background:"rgba(255,255,255,0.9)",pointerEvents:"none",...o}})}function cs(){return T.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:[T.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),T.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function ls(){return T.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:T.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function us(){return T.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:T.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}function ds(){return T.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:[T.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),T.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function fs(){return T.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:[T.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),T.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})}function nn({children:e,className:t="",...n}){return T.jsx("button",{className:`ric-controls-button ${t}`,style:gs,...n,children:e})}function hs({showZoom:e=!0,showFitView:t=!0,showInteractive:n=!1,fitViewOptions:r,onZoomIn:i,onZoomOut:o,onFitView:a,onInteractiveChange:f,position:p="bottom-left",orientation:d="vertical",style:h={},className:k="","aria-label":S="Canvas controls",children:E}){const z=Pe(),{zoomIn:j,zoomOut:L,fitView:A,getZoom:X}=Hr(),[D,Y]=c.useState(!0),$=X()<=z.zoomMin,I=X()>=z.zoomMax,q=c.useCallback(()=>{j(),i==null||i()},[j,i]),O=c.useCallback(()=>{L(),o==null||o()},[L,o]),H=c.useCallback(()=>{A(r||{padding:.1}),a==null||a()},[A,r,a]),C=c.useCallback(()=>{const v=!D;Y(v),f==null||f(v)},[D,f]),y={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:30,left:10},"bottom-right":{bottom:30,right:10},"bottom-center":{bottom:30,left:"50%",transform:"translateX(-50%)"}}[p]||{bottom:30,left:10};return T.jsxs("div",{className:`ric-controls ${k}`,style:{position:"absolute",display:"flex",flexDirection:d==="horizontal"?"row":"column",gap:2,zIndex:5,...y,...h},role:"toolbar","aria-label":S,children:[e&&T.jsxs(T.Fragment,{children:[T.jsx(nn,{onClick:q,disabled:I,title:"Zoom in","aria-label":"Zoom in",className:"ric-controls-zoomin",children:T.jsx(cs,{})}),T.jsx(nn,{onClick:O,disabled:$,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:T.jsx(ls,{})})]}),t&&T.jsx(nn,{onClick:H,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:T.jsx(us,{})}),n&&T.jsx(nn,{onClick:C,title:D?"Lock interactivity":"Unlock interactivity","aria-label":D?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:D?T.jsx(fs,{}):T.jsx(ds,{})}),E]})}const gs={width:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid rgba(0,0,0,0.12)",borderRadius:4,background:"#fff",cursor:"pointer",fontSize:16,lineHeight:1,color:"#333",padding:0},ys=c.memo(hs);function xs({variant:e="lines",gap:t=40,size:n=1,color:r,style:i={},className:o=""}){const a=Pe();return a.workerRef.current&&a.workerRef.current.postMessage({type:"background",data:{variant:e,gap:t,size:n,color:r}}),null}function ps({position:e="top-left",style:t={},className:n="",children:r}){const i={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:10,left:10},"bottom-right":{bottom:10,right:10},"bottom-center":{bottom:10,left:"50%",transform:"translateX(-50%)"}}[e]||{top:10,left:10};return T.jsx("div",{className:`ric-panel ${n}`,style:{position:"absolute",zIndex:5,pointerEvents:"all",...i,...t},onPointerDown:o=>o.stopPropagation(),children:r})}function ms({minWidth:e=10,minHeight:t=10,maxWidth:n=1/0,maxHeight:r=1/0,isVisible:i=!0,handleStyle:o={},lineStyle:a={},color:f="#3b82f6",onResizeStart:p,onResize:d,onResizeEnd:h}){const k=c.useContext(on),S=Pe(),E=c.useRef(null),z=c.useCallback((A,X)=>{A.stopPropagation(),A.preventDefault();const D=S.nodesRef.current.find(I=>I.id===k);if(!D)return;E.current={direction:X,startX:A.clientX,startY:A.clientY,width:D.width||160,height:D.height||60},p==null||p(A,{width:E.current.width,height:E.current.height});const Y=I=>{var N,P;if(!E.current)return;const q=E.current,O=S.cameraRef.current,H=(I.clientX-q.startX)/O.zoom,C=(I.clientY-q.startY)/O.zoom;let y=q.width,v=q.height;q.direction.includes("e")&&(y=Math.min(n,Math.max(e,q.width+H))),q.direction.includes("w")&&(y=Math.min(n,Math.max(e,q.width-H))),q.direction.includes("s")&&(v=Math.min(r,Math.max(t,q.height+C))),q.direction.includes("n")&&(v=Math.min(r,Math.max(t,q.height-C))),(P=(N=S.onNodesChangeRef).current)==null||P.call(N,[{id:k,type:"dimensions",dimensions:{width:y,height:v},setAttributes:!0}]),d==null||d(I,{width:y,height:v})},$=I=>{E.current=null,h==null||h(I,{}),window.removeEventListener("pointermove",Y),window.removeEventListener("pointerup",$)};window.addEventListener("pointermove",Y),window.addEventListener("pointerup",$)},[k,S,e,t,n,r,p,d,h]);if(!i)return null;const j=8,L={position:"absolute",width:j,height:j,background:f,border:"1px solid #fff",borderRadius:2,zIndex:20,...o};return T.jsxs(T.Fragment,{children:[T.jsx("div",{style:{...L,bottom:-j/2,right:-j/2,cursor:"nwse-resize"},onPointerDown:A=>z(A,"se")}),T.jsx("div",{style:{...L,bottom:-j/2,left:-j/2,cursor:"nesw-resize"},onPointerDown:A=>z(A,"sw")}),T.jsx("div",{style:{...L,top:-j/2,right:-j/2,cursor:"nesw-resize"},onPointerDown:A=>z(A,"ne")}),T.jsx("div",{style:{...L,top:-j/2,left:-j/2,cursor:"nwse-resize"},onPointerDown:A=>z(A,"nw")}),T.jsx("div",{style:{...L,top:"50%",right:-j/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:A=>z(A,"e")}),T.jsx("div",{style:{...L,top:"50%",left:-j/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:A=>z(A,"w")}),T.jsx("div",{style:{...L,left:"50%",top:-j/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:A=>z(A,"n")}),T.jsx("div",{style:{...L,left:"50%",bottom:-j/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:A=>z(A,"s")})]})}function vs({isVisible:e,position:t="top",offset:n=10,align:r="center",children:i,style:o={},className:a=""}){const f=c.useContext(on),d=Pe().nodes.find(S=>S.id===f);if(!(e!==void 0?e:d==null?void 0:d.selected))return null;const k={top:{bottom:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginBottom:n},bottom:{top:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginTop:n},left:{right:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginRight:n},right:{left:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginLeft:n}}[t]||{};return T.jsx("div",{className:`ric-node-toolbar ${a}`,style:{position:"absolute",zIndex:1e3,pointerEvents:"all",...k,...o},onPointerDown:S=>S.stopPropagation(),children:i})}function bs({isVisible:e=!1,x:t=0,y:n=0,alignX:r="center",alignY:i="center",children:o,style:a={},className:f=""}){if(!e)return null;const p=r==="center"?"-50%":r==="right"?"-100%":"0",d=i==="center"?"-50%":i==="bottom"?"-100%":"0";return T.jsx("div",{className:`ric-edge-toolbar ${f}`,style:{position:"absolute",left:t,top:n,transform:`translate(${p}, ${d})`,zIndex:1e3,pointerEvents:"all",...a},children:o})}function ws({children:e}){var r;const n=(r=Pe().edgeLabelContainerRef)==null?void 0:r.current;return n?pr.createPortal(e,n):null}function Ms({children:e}){var r;const n=(r=Pe().viewportPortalRef)==null?void 0:r.current;return n?pr.createPortal(e,n):null}function _r({fromX:e,fromY:t,toX:n,toY:r,fromPosition:i="right",toPosition:o="left",connectionLineType:a="default",connectionLineStyle:f,connectionLineComponent:p}){if(p)return T.jsx(p,{fromX:e,fromY:t,toX:n,toY:r,fromPosition:i,toPosition:o});let d;switch(a){case"straight":[d]=tr({sourceX:e,sourceY:t,targetX:n,targetY:r});break;case"step":[d]=kn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o,borderRadius:0});break;case"smoothstep":[d]=kn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o});break;case"simplebezier":[d]=rr({sourceX:e,sourceY:t,targetX:n,targetY:r});break;default:[d]=nr({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o});break}return T.jsx("path",{d,fill:"none",className:"ric-connection-line",stroke:"#b1b1b7",strokeWidth:1.5,style:f})}_r.displayName="ConnectionLine";const Rs=c.memo(_r),ks=Object.freeze({Top:"top",Bottom:"bottom",Left:"left",Right:"right"}),Cs=Object.freeze({Arrow:"arrow",ArrowClosed:"arrowclosed"});function Es(e){const t=e.width||e.measured&&e.measured.width||0,n=e.height||e.measured&&e.measured.height||0,r=e._absolutePosition||e.position||{x:0,y:0};return{x:r.x,y:r.y,x2:r.x+t,y2:r.y+n}}exports.Background=xs;exports.BaseEdge=sn;exports.BezierEdge=er;exports.ConnectionLine=Rs;exports.ControlButton=nn;exports.Controls=ys;exports.DefaultNode=vo;exports.EdgeLabelRenderer=ws;exports.EdgeText=Lr;exports.EdgeToolbar=bs;exports.GroupNode=Pr;exports.Handle=rn;exports.InfiniteCanvas=jo;exports.InfiniteCanvasProvider=Ao;exports.InputNode=Nr;exports.MarkerType=Cs;exports.MiniMap=as;exports.NodeResizer=ms;exports.NodeToolbar=vs;exports.OutputNode=Ir;exports.Panel=ps;exports.Position=ks;exports.SelectionBox=Sr;exports.SimpleBezierEdge=ar;exports.SmoothStepEdge=ir;exports.StepEdge=$r;exports.StraightEdge=sr;exports.ViewportPortal=Ms;exports.addEdge=Ho;exports.applyEdgeChanges=Dr;exports.applyNodeChanges=Ar;exports.boxToRect=Qr;exports.buildObstacles=or;exports.clampPosition=Gn;exports.computeRoutedEdges=No;exports.getBezierEdgeCenter=bo;exports.getBezierPath=nr;exports.getBoundsOfBoxes=Jr;exports.getConnectedEdges=br;exports.getEdgeCenter=wo;exports.getIncomers=Ur;exports.getNodeDimensions=Vn;exports.getNodesBounds=Rn;exports.getNodesInside=Zr;exports.getOutgoers=qr;exports.getOverlappingArea=Kr;exports.getRoutedLabelPosition=In;exports.getSimpleBezierPath=rr;exports.getSmoothStepPath=kn;exports.getStraightPath=tr;exports.getViewportForBounds=qt;exports.isEdge=Or;exports.isNode=Xr;exports.nodeToBox=Es;exports.nodeToRect=Vr;exports.reconnectEdge=Mo;exports.rectToBox=Gr;exports.routeSinglePath=Io;exports.routedPointsToPath=Nn;exports.snapPosition=Zn;exports.useConnection=Oo;exports.useEdges=Yo;exports.useEdgesState=Wo;exports.useHandleConnections=Zo;exports.useInfiniteCanvas=Mr;exports.useInternalNode=ts;exports.useKeyPress=Jo;exports.useNodeConnections=qo;exports.useNodeId=co;exports.useNodes=Fo;exports.useNodesData=Uo;exports.useNodesInitialized=es;exports.useNodesState=_o;exports.useOnEdgesChangeMiddleware=is;exports.useOnNodesChangeMiddleware=ss;exports.useOnSelectionChange=Qo;exports.useOnViewportChange=Go;exports.useReactFlow=Hr;exports.useStore=ns;exports.useStoreApi=rs;exports.useUndoRedo=os;exports.useUpdateNodeInternals=Ko;exports.useViewport=Xo;
|
|
942
|
+
`,ur=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",wr],{type:"text/javascript;charset=utf-8"});function eo(e){let t;try{if(t=ur&&(self.URL||self.webkitURL).createObjectURL(ur),!t)throw"";const n=new Worker(t,{type:"module",name:e==null?void 0:e.name});return n.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),n}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(wr),{type:"module",name:e==null?void 0:e.name})}}const Xn=new WeakMap;function to(e,t){if(Xn.has(e))return Xn.get(e);const n=e.transferControlToOffscreen(),r=new eo;r.onerror=o=>console.error("[infinite-canvas] worker error:",o.message,o),r.postMessage({type:"init",data:{...t,canvas:n}},[n]);const i={worker:r};return Xn.set(e,i),i}const ut=160,et=60,no=10;function Mr({cards:e=[],nodes:t=[],edges:n=[],onHudUpdate:r,onNodesProcessed:i,onNodesChange:o,onEdgesChange:c,onConnect:f,onNodeClick:m,onNodeDragStart:d,onNodeDrag:h,onNodeDragStop:b,onEdgeClick:S,onEdgeDoubleClick:C,onEdgeMouseEnter:z,onEdgeMouseMove:A,onEdgeMouseLeave:B,onEdgeContextMenu:D,onNodeDoubleClick:X,onNodeMouseEnter:H,onNodeMouseMove:Y,onNodeMouseLeave:j,onNodeContextMenu:P,onPaneClick:q,onPaneContextMenu:U,onPaneMouseEnter:_,onPaneMouseMove:w,onPaneMouseLeave:g,onSelectionChange:v,onConnectStart:N,onConnectEnd:I,onInit:$,onMoveStart:K,onMove:se,onMoveEnd:te,onDelete:ce,onBeforeDelete:pe,onError:me,isValidConnection:ye,dark:ue,gridSize:Ce=40,zoomMin:re=.1,zoomMax:de=4,initialCamera:Le={x:0,y:0,zoom:1},fitView:Ye=!1,fitViewOptions:xe,nodesDraggable:he=!0,nodesConnectable:$e=!0,elementsSelectable:He=!0,multiSelectionKeyCode:ze="Shift",selectionOnDrag:Ve=!1,selectionMode:tt="partial",connectionMode:Me="loose",connectionRadius:Te=20,connectOnClick:Xe=!1,snapToGrid:je=!1,snapGrid:_e=[15,15],deleteKeyCode:qe=["Delete","Backspace"],panActivationKeyCode:kt=" ",panOnScroll:an=!1,panOnScrollMode:Ct="free",panOnScrollSpeed:cn=.5,zoomOnScroll:un=!0,zoomOnDoubleClick:ln=!0,zoomOnPinch:dn=!0,preventScrolling:Xt=!0,translateExtent:ht,nodeExtent:gt,defaultEdgeOptions:Et={},autoPanOnNodeDrag:Pn=!0,autoPanOnConnect:In=!0,autoPanSpeed:nt=5,edgesReconnectable:cr=!1,elevateNodesOnSelect:Tn=!1,elevateEdgesOnSelect:Ln=!1,noDragClassName:St="nodrag",noPanClassName:zt="nopan",onSelectionDragStart:Bn,onSelectionDrag:$n,onSelectionDragStop:jn,edgeRouting:bt=!0}={}){const we=a.useRef(null),Nt=a.useRef(null),Ne=a.useRef(null),fe=a.useRef({...Le}),yt=a.useRef([...e]),ee=a.useRef([...t]),Pe=a.useRef([...n]),fn=a.useRef(new Map),Pt=a.useRef(!1),It=a.useRef(null),[Tt,An]=a.useState(!1),We=a.useRef(null),Ue=a.useRef(null),Lt=a.useRef(null),rt=a.useRef(null),hn=a.useRef(!1),Je=a.useRef(null),[gn,yn]=a.useState({x:Le.x,y:Le.y,zoom:Le.zoom}),[Ut,xn]=a.useState(null),xt=a.useMemo(()=>new Set,[]),ot=a.useMemo(()=>new Set,[]),Ke=a.useRef(!1),J=a.useRef({});J.current={onHudUpdate:r,onNodesProcessed:i,onNodesChange:o,onEdgesChange:c,onConnect:f,onNodeClick:m,onNodeDragStart:d,onNodeDrag:h,onNodeDragStop:b,onEdgeClick:S,onEdgeDoubleClick:C,onEdgeMouseEnter:z,onEdgeMouseMove:A,onEdgeMouseLeave:B,onEdgeContextMenu:D,onNodeDoubleClick:X,onNodeMouseEnter:H,onNodeMouseMove:Y,onNodeMouseLeave:j,onNodeContextMenu:P,onPaneClick:q,onPaneContextMenu:U,onPaneMouseEnter:_,onPaneMouseMove:w,onPaneMouseLeave:g,onSelectionChange:v,onConnectStart:N,onConnectEnd:I,onInit:$,onMoveStart:K,onMove:se,onMoveEnd:te,onDelete:ce,onBeforeDelete:pe,onError:me,onSelectionDragStart:Bn,onSelectionDrag:$n,onSelectionDragStop:jn,isValidConnection:ye};const st={get current(){return J.current.onConnect}},wt={get current(){return J.current.onNodeClick}},Bt={get current(){return J.current.onNodeDragStart}},$t={get current(){return J.current.onNodeDrag}},jt={get current(){return J.current.onNodeDragStop}},pt={get current(){return J.current.onEdgeClick}},At={get current(){return J.current.onPaneClick}},Dt={get current(){return J.current.onSelectionChange}},Ht={get current(){return J.current.onHudUpdate}},_t={get current(){return J.current.onNodesProcessed}};a.useEffect(()=>{const l=u=>{u.key===ze&&(hn.current=!0),u.key===kt&&(Ke.current=!0)},y=u=>{u.key===ze&&(hn.current=!1),u.key===kt&&(Ke.current=!1)};return window.addEventListener("keydown",l),window.addEventListener("keyup",y),()=>{window.removeEventListener("keydown",l),window.removeEventListener("keyup",y)}},[ze,kt]);const Ee={get current(){return J.current.onNodesChange?lt:null}},lt=l=>{var u,p,k;(p=(u=J.current).onNodesChange)==null||p.call(u,l);const y=[];for(let E=0;E<l.length;E++)l[E].type==="select"&&y.push({id:l[E].id,selected:l[E].selected});y.length>0&&((k=Ne.current)==null||k.postMessage({type:"nodeSelections",data:{selections:y}}))},De={get current(){return J.current.onEdgesChange?Dn:null}},Dn=l=>{var u,p,k;(p=(u=J.current).onEdgesChange)==null||p.call(u,l);const y=[];for(let E=0;E<l.length;E++)l[E].type==="select"&&y.push({id:l[E].id,selected:l[E].selected});y.length>0&&((k=Ne.current)==null||k.postMessage({type:"edgeSelections",data:{selections:y}}))},dt=a.useCallback(()=>{var p;const l=ee.current.filter(k=>k.selected),y=Pe.current.filter(k=>k.selected),u={nodes:l,edges:y};(p=Dt.current)==null||p.call(Dt,u);for(const k of ot)k(u)},[ot]);a.useEffect(()=>{var l;yt.current=[...e],(l=Ne.current)==null||l.postMessage({type:"cards",data:{cards:[...e]}})},[e]);const Wt=a.useCallback(l=>{const y={};for(const u of l)y[u.id]=u;return l.map(u=>{if(!u.parentId)return u;const p=y[u.parentId];if(!p)return u;let k=u.position.x,E=u.position.y,x=p;for(;x;)k+=x.position.x,E+=x.position.y,x=x.parentId?y[x.parentId]:null;return{...u,_absolutePosition:{x:k,y:E}}})},[]),it=a.useRef([]),mt=a.useCallback(l=>{const y=fn.current;if(!y||y.size===0)return l;const u={};for(const[,p]of y)u[p.nodeId]||(u[p.nodeId]=[]),u[p.nodeId].push({id:p.id,type:p.type,position:p.position,x:p.x,y:p.y});return l.map(p=>{const k=u[p.id];return k&&k.length>0?{...p,handles:k}:p})},[]),pn=a.useCallback(()=>{var y;if(We.current)return;const l=mt(it.current);(y=Ne.current)==null||y.postMessage({type:"nodes",data:{nodes:l}})},[mt]);a.useEffect(()=>{var u,p;if(We.current){const k=We.current.id,E=new Set([k,...We.current.selectedStarts.map(R=>R.id)]),x={};for(const R of ee.current)E.has(R.id)&&(x[R.id]={...R.position});ee.current=[...t];for(const R of ee.current)x[R.id]&&(R.position=x[R.id]);it.current=Wt(ee.current);const M=mt(it.current);(u=Ne.current)==null||u.postMessage({type:"nodes",data:{nodes:M}});return}ee.current=[...t];const l=Wt(t);it.current=l;const y=mt(l);(p=Ne.current)==null||p.postMessage({type:"nodes",data:{nodes:y}})},[t,Wt,mt]),a.useEffect(()=>{var l;Pe.current=[...n],(l=Ne.current)==null||l.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const Be=a.useCallback((l,y)=>{const u=we.current;if(!u)return{x:0,y:0};const p=u.getBoundingClientRect(),k=fe.current;return{x:(l-p.left-k.x)/k.zoom,y:(y-p.top-k.y)/k.zoom}},[]),le=a.useCallback((l,y)=>{const u=it.current.length>0?it.current:ee.current;let p=null;for(let k=u.length-1;k>=0;k--){const E=u[k];if(E.hidden||E._customRendered)continue;const x=E._absolutePosition||E.position,M=E.width||ut,R=E.height||et;if(l>=x.x&&l<=x.x+M&&y>=x.y&&y<=x.y+R){if(E.type==="group"){p||(p=E);continue}return E}}return p},[]),Ot=a.useCallback((l,y)=>{const u=y.width||ut,p=y.height||et;if(l.x!==void 0&&l.y!==void 0)return{x:y.position.x+l.x,y:y.position.y+l.y};switch(l.position||(l.type==="source"?"right":"left")){case"top":return{x:y.position.x+u/2,y:y.position.y};case"bottom":return{x:y.position.x+u/2,y:y.position.y+p};case"left":return{x:y.position.x,y:y.position.y+p/2};case"right":return{x:y.position.x+u,y:y.position.y+p/2};default:return{x:y.position.x+u,y:y.position.y+p/2}}},[]),qt=a.useCallback(l=>{const y=l.width||ut,u=l.height||et;if(l.handles&&l.handles.length>0)return l.handles.map(R=>{const W=Ot(R,l);return{id:R.id||null,type:R.type,x:W.x,y:W.y}});const p=l.targetPosition||"left",k=l.sourcePosition||"right",E=R=>{switch(R){case"top":return{x:l.position.x+y/2,y:l.position.y};case"bottom":return{x:l.position.x+y/2,y:l.position.y+u};case"left":return{x:l.position.x,y:l.position.y+u/2};case"right":return{x:l.position.x+y,y:l.position.y+u/2};default:return{x:l.position.x+y,y:l.position.y+u/2}}},x=E(p),M=E(k);return[{id:null,type:"target",x:x.x,y:x.y},{id:null,type:"source",x:M.x,y:M.y}]},[Ot]),vt=a.useCallback((l,y)=>{const u=ee.current,p=fe.current,k=Math.max(no,Te)/p.zoom;for(let E=u.length-1;E>=0;E--){const x=u[E];if(x.hidden)continue;const M=qt(x);for(const R of M)if(Math.abs(l-R.x)<k&&Math.abs(y-R.y)<k)return{nodeId:x.id,handleId:R.id,type:R.type,x:R.x,y:R.y}}return null},[qt]),Ze=a.useCallback((l,y)=>{const p=8/fe.current.zoom,k=ee.current,E={};for(let x=0;x<k.length;x++)E[k[x].id]=k[x];for(let x=Pe.current.length-1;x>=0;x--){const M=Pe.current[x],R=E[M.source],W=E[M.target];if(!R||!W)continue;const L=R.width||ut,O=R.height||et,G=W.height||et,Z=R.position.x+L,ie=R.position.y+O/2,V=W.position.x,ae=W.position.y+G/2;if(ro(l,y,Z,ie,V,ae)<p)return M}return null},[]);a.useEffect(()=>{const l=Nt.current,y=we.current;if(!l||!y)return;const u=y.getBoundingClientRect(),p=ue!==void 0?ue:matchMedia("(prefers-color-scheme: dark)").matches,k=Wt(ee.current);it.current=k;const E=mt(k),{worker:x}=to(l,{width:u.width,height:u.height,camera:fe.current,cards:yt.current,nodes:E,edges:Pe.current,dark:p,gridSize:Ce,edgeRouting:bt});x.onmessage=L=>{var O,G,Z,ie;L.data.type==="hud"&&((O=Ht.current)==null||O.call(Ht,L.data.data)),L.data.type==="ready"&&An(!0),L.data.type==="nodesProcessed"&&((G=_t.current)==null||G.call(_t,L.data.data)),L.data.type==="error"&&((ie=(Z=J.current).onError)==null||ie.call(Z,"worker-error",L.data.message||"Canvas worker error"))},x.onerror=L=>{var O,G;(G=(O=J.current).onError)==null||G.call(O,"worker-error",L.message||"Canvas worker crashed")},Ne.current=x;const M=new ResizeObserver(L=>{const{width:O,height:G}=L[0].contentRect;x.postMessage({type:"resize",data:{width:O,height:G}})});M.observe(y);let R,W;return ue===void 0&&(R=matchMedia("(prefers-color-scheme: dark)"),W=L=>x.postMessage({type:"theme",data:{dark:L.matches}}),R.addEventListener("change",W)),()=>{M.disconnect(),R&&W&&R.removeEventListener("change",W),Ne.current=null}},[]),a.useEffect(()=>{var l;ue!==void 0&&((l=Ne.current)==null||l.postMessage({type:"theme",data:{dark:ue}}))},[ue]),a.useEffect(()=>{var l;(l=Ne.current)==null||l.postMessage({type:"edgeRouting",data:{enabled:bt}})},[bt]);const Zt=a.useRef(0),Re=a.useCallback((l=null)=>{var p,k,E;const y=fe.current;if(ht){const x=we.current;if(x){const M=x.getBoundingClientRect(),R=-ht[1][0]*y.zoom+M.width,W=-ht[1][1]*y.zoom+M.height,L=-ht[0][0]*y.zoom,O=-ht[0][1]*y.zoom;y.x=Math.min(L,Math.max(R,y.x)),y.y=Math.min(O,Math.max(W,y.y))}}(p=Ne.current)==null||p.postMessage({type:"camera",data:{camera:{...y}}});const u={x:y.x,y:y.y,zoom:y.zoom};(E=(k=J.current).onMove)==null||E.call(k,l,u);for(const x of xt)x(u);cancelAnimationFrame(Zt.current),Zt.current=requestAnimationFrame(()=>{yn({x:y.x,y:y.y,zoom:y.zoom})})},[xt,ht]),at=a.useCallback(()=>{var u,p;const l=Ue.current,y=Lt.current;l&&y?((u=Ne.current)==null||u.postMessage({type:"connecting",data:{from:l.startPos,to:y,_routedPoints:null}}),xn({source:l.sourceId,sourceHandle:l.sourceHandle,target:null,targetHandle:null})):((p=Ne.current)==null||p.postMessage({type:"connecting",data:null}),xn(null))},[]),ct=a.useCallback(()=>{var y,u;const l=rt.current;l?(y=Ne.current)==null||y.postMessage({type:"selectionBox",data:l}):(u=Ne.current)==null||u.postMessage({type:"selectionBox",data:null})},[]),Gt=a.useCallback(l=>{var x,M,R,W,L,O,G,Z,ie,V,ae,ke,Ae,Fe,Ge,Oe,Jt,ft;const y=ee.current.length>0,u=Be(l.clientX,l.clientY),p=hn.current;if(y&&$e&&!p){const Q=vt(u.x,u.y);if(Xe&&Je.current&&Q){const oe=Je.current;if(Q.nodeId!==oe.nodeId){const Qe=oe.handleType==="target"?{source:Q.nodeId,target:oe.nodeId,sourceHandle:Q.handleId||null,targetHandle:oe.handleId}:{source:oe.nodeId,target:Q.nodeId,sourceHandle:oe.handleId,targetHandle:Q.handleId||null};(J.current.isValidConnection?J.current.isValidConnection(Qe):!0)&&((x=st.current)==null||x.call(st,{...Qe,...Et}))}Je.current=null;return}if(Me==="strict"?Q&&Q.type==="source":Q!=null){if(Xe){Je.current={nodeId:Q.nodeId,handleId:Q.handleId||null,handleType:Q.type},(R=(M=J.current).onConnectStart)==null||R.call(M,l,{nodeId:Q.nodeId,handleId:Q.handleId,handleType:Q.type});return}Ue.current={sourceId:Q.nodeId,sourceHandle:Q.handleId||null,sourceType:Q.type,startPos:{x:Q.x,y:Q.y}},Lt.current={x:u.x,y:u.y},(W=we.current)==null||W.setPointerCapture(l.pointerId),(O=(L=J.current).onConnectStart)==null||O.call(L,l,{nodeId:Q.nodeId,handleId:Q.handleId,handleType:Q.type}),at();return}}const k=Q=>{var oe;let be=Q;for(;be&&be!==we.current;){if((oe=be.classList)!=null&&oe.contains(St))return!0;be=be.parentElement}return!1},E=Q=>{var oe;let be=Q;for(;be&&be!==we.current;){if((oe=be.classList)!=null&&oe.contains(zt))return!0;be=be.parentElement}return!1};if(y){const Q=le(u.x,u.y);if(Q){if(Ee.current&&He){const be=[];if(p)be.push({id:Q.id,type:"select",selected:!Q.selected});else if(!Q.selected){for(const oe of ee.current)oe.id===Q.id?be.push({id:oe.id,type:"select",selected:!0}):oe.selected&&be.push({id:oe.id,type:"select",selected:!1});if(De.current){const oe=Pe.current.filter(ge=>ge.selected).map(ge=>({id:ge.id,type:"select",selected:!1}));oe.length&&De.current(oe)}}if(be.length){if(Ee.current(be),Tn&&!p){const oe=ee.current.findIndex(ge=>ge.id===Q.id);oe>=0&&oe<ee.current.length-1&&Ee.current([{id:Q.id,type:"remove"},{type:"add",item:{...ee.current[oe],selected:!0}}])}dt()}}if((G=wt.current)==null||G.call(wt,l,Q),he&&!k(l.target)){const be=Q.selected;let oe=null;if(Q.parentId&&Q.extent==="parent"){const ge=ee.current.find(Qe=>Qe.id===Q.parentId);if(ge){const Qe=ge.width||ut,Kt=ge.height||et,vn=Q.width||((Z=Q.measured)==null?void 0:Z.width)||ut,Vt=Q.height||((ie=Q.measured)==null?void 0:ie.height)||et;oe={minX:0,minY:0,maxX:Qe-vn,maxY:Kt-Vt}}}if(We.current={id:Q.id,startPos:{...Q.position},startMouse:{x:u.x,y:u.y},parentClamp:oe,parentId:Q.parentId||null,selectedStarts:be?ee.current.filter(ge=>ge.selected&&ge.id!==Q.id).map(ge=>{var Kt,vn;let Qe=null;if(ge.parentId&&ge.extent==="parent"){const Vt=ee.current.find(Yn=>Yn.id===ge.parentId);if(Vt){const Yn=Vt.width||ut,Wr=Vt.height||et,Fr=ge.width||((Kt=ge.measured)==null?void 0:Kt.width)||ut,Yr=ge.height||((vn=ge.measured)==null?void 0:vn.height)||et;Qe={minX:0,minY:0,maxX:Yn-Fr,maxY:Wr-Yr}}}return{id:ge.id,startPos:{...ge.position},parentClamp:Qe,parentId:ge.parentId||null}}):[]},(V=we.current)==null||V.setPointerCapture(l.pointerId),(ae=Bt.current)==null||ae.call(Bt,l,Q),We.current.selectedStarts.length>0){const ge=ee.current.filter(Qe=>Qe.selected);(Ae=(ke=J.current).onSelectionDragStart)==null||Ae.call(ke,l,ge)}if(Ee.current){const ge=[{id:Q.id,type:"position",dragging:!0}];for(const Qe of We.current.selectedStarts)ge.push({id:Qe.id,type:"position",dragging:!0});Ee.current(ge)}}return}}if(Pe.current.length>0&&He){const Q=Ze(u.x,u.y);if(Q){if(De.current){const be=[];if(p)be.push({id:Q.id,type:"select",selected:!Q.selected});else{for(const oe of Pe.current)oe.id===Q.id?be.push({id:oe.id,type:"select",selected:!0}):oe.selected&&be.push({id:oe.id,type:"select",selected:!1});if(Ee.current){const oe=ee.current.filter(ge=>ge.selected).map(ge=>({id:ge.id,type:"select",selected:!1}));oe.length&&Ee.current(oe)}}if(be.length){if(De.current(be),Ln&&!p){const oe=Pe.current.findIndex(ge=>ge.id===Q.id);oe>=0&&oe<Pe.current.length-1&&De.current([{id:Q.id,type:"remove"},{type:"add",item:{...Pe.current[oe],selected:!0}}])}dt()}}(Fe=pt.current)==null||Fe.call(pt,l,Q);return}}if(!p){const Q=ee.current.filter(oe=>oe.selected).map(oe=>({id:oe.id,type:"select",selected:!1})),be=Pe.current.filter(oe=>oe.selected).map(oe=>({id:oe.id,type:"select",selected:!1}));Q.length&&Ee.current&&Ee.current(Q),be.length&&De.current&&De.current(be),(Q.length||be.length)&&dt()}if((Ge=At.current)==null||Ge.call(At,l),Ve||p){rt.current={startWorld:{...u},endWorld:{...u}},(Oe=we.current)==null||Oe.setPointerCapture(l.pointerId),ct();return}E(l.target)||(Pt.current=!0,It.current={x:l.clientX,y:l.clientY},(Jt=we.current)==null||Jt.classList.add("dragging"),(ft=we.current)==null||ft.setPointerCapture(l.pointerId))},[Be,le,vt,Ze,he,$e,He,Ve,at,ct,dt,St,zt]),Qt=a.useCallback(l=>{var u,p,k,E;if(Ue.current){if(Lt.current=Be(l.clientX,l.clientY),at(),In){const x=we.current;if(x){const M=x.getBoundingClientRect(),R=40,W=l.clientX-M.left,L=l.clientY-M.top;let O=0,G=0;W<R?O=nt:W>M.width-R&&(O=-nt),L<R?G=nt:L>M.height-R&&(G=-nt),(O||G)&&(fe.current.x+=O,fe.current.y+=G,Re(l))}}return}if(rt.current){rt.current.endWorld=Be(l.clientX,l.clientY),ct();const x=rt.current,M=Math.min(x.startWorld.x,x.endWorld.x),R=Math.min(x.startWorld.y,x.endWorld.y),W=Math.max(x.startWorld.x,x.endWorld.x),L=Math.max(x.startWorld.y,x.endWorld.y);if(Ee.current){const O=[];for(const G of ee.current){if(G.hidden)continue;const Z=G.width||ut,ie=G.height||et,V=tt==="full"?G.position.x>=M&&G.position.x+Z<=W&&G.position.y>=R&&G.position.y+ie<=L:G.position.x+Z>M&&G.position.x<W&&G.position.y+ie>R&&G.position.y<L;V!==!!G.selected&&O.push({id:G.id,type:"select",selected:V})}O.length&&Ee.current(O)}return}if(We.current){const x=Be(l.clientX,l.clientY),M=We.current,R=x.x-M.startMouse.x,W=x.y-M.startMouse.y;let L={x:M.startPos.x+R,y:M.startPos.y+W};if(je&&(L=Zn(L,_e)),gt&&(L=Gn(L,gt)),M.parentClamp){const V=M.parentClamp;L={x:Math.max(V.minX,Math.min(L.x,V.maxX)),y:Math.max(V.minY,Math.min(L.y,V.maxY))}}const O=[{id:M.id,position:L}];for(const V of M.selectedStarts){let ae={x:V.startPos.x+R,y:V.startPos.y+W};if(je&&(ae=Zn(ae,_e)),gt&&(ae=Gn(ae,gt)),V.parentClamp){const ke=V.parentClamp;ae={x:Math.max(ke.minX,Math.min(ae.x,ke.maxX)),y:Math.max(ke.minY,Math.min(ae.y,ke.maxY))}}O.push({id:V.id,position:ae})}const G=[];for(const V of O){const ae=ee.current.find(ke=>ke.id===V.id);if(ae){ae.position=V.position,ae.dragging=!0;let ke=V.position;if(ae.parentId){let Ae=ee.current.find(Oe=>Oe.id===ae.parentId),Fe=V.position.x,Ge=V.position.y;for(;Ae;)Fe+=Ae.position.x,Ge+=Ae.position.y,Ae=Ae.parentId?ee.current.find(Oe=>Oe.id===Ae.parentId):null;ke={x:Fe,y:Ge}}G.push({id:V.id,position:V.position,_absolutePosition:ke,width:ae.width,height:ae.height,dragging:!0,selected:ae.selected})}}const Z=new Set(O.map(V=>V.id));for(const V of ee.current)if(V.parentId&&Z.has(V.parentId)&&!Z.has(V.id)){let ae=ee.current.find(Fe=>Fe.id===V.parentId),ke=V.position.x,Ae=V.position.y;for(;ae;)ke+=ae.position.x,Ae+=ae.position.y,ae=ae.parentId?ee.current.find(Fe=>Fe.id===ae.parentId):null;G.push({id:V.id,position:V.position,_absolutePosition:{x:ke,y:Ae},width:V.width,height:V.height,dragging:!1,selected:V.selected})}if((u=Ne.current)==null||u.postMessage({type:"nodePositions",data:{updates:G}}),Pn){const V=we.current;if(V){const ae=V.getBoundingClientRect(),ke=40,Ae=l.clientX-ae.left,Fe=l.clientY-ae.top;let Ge=0,Oe=0;Ae<ke?Ge=nt:Ae>ae.width-ke&&(Ge=-nt),Fe<ke?Oe=nt:Fe>ae.height-ke&&(Oe=-nt),(Ge||Oe)&&(fe.current.x+=Ge,fe.current.y+=Oe,Re(l))}}const ie=ee.current.find(V=>V.id===M.id);if(ie&&((p=$t.current)==null||p.call($t,l,ie)),M.selectedStarts.length>0){const V=ee.current.filter(ae=>ae.selected);(E=(k=J.current).onSelectionDrag)==null||E.call(k,l,V)}return}if(!Pt.current)return;const y=fe.current;y.x+=l.clientX-It.current.x,y.y+=l.clientY-It.current.y,It.current={x:l.clientX,y:l.clientY},Re()},[Re,Be,at,ct]),mn=a.useCallback(l=>{var y,u,p,k,E,x,M,R;if(Ue.current){const W=Be(l.clientX,l.clientY),L=vt(W.x,W.y);if(L&&L.nodeId!==Ue.current.sourceId&&(Me==="loose"||L.type==="target")){const Z=Ue.current.sourceType==="target"?{source:L.nodeId,target:Ue.current.sourceId,sourceHandle:L.handleId||null,targetHandle:Ue.current.sourceHandle}:{source:Ue.current.sourceId,target:L.nodeId,sourceHandle:Ue.current.sourceHandle,targetHandle:L.handleId||null};(J.current.isValidConnection?J.current.isValidConnection(Z):!0)&&((y=st.current)==null||y.call(st,{...Z,...Et}))}(p=(u=J.current).onConnectEnd)==null||p.call(u,l.nativeEvent||l),Ue.current=null,Lt.current=null,at();return}if(rt.current){rt.current=null,ct(),dt();return}if(We.current){const W=We.current,L=ee.current.find(Z=>Z.id===W.id),O=[{id:W.id,position:L?{...L.position}:W.startPos,_absolutePosition:L?{...L.position}:W.startPos,dragging:!1}];for(const Z of W.selectedStarts){const ie=ee.current.find(V=>V.id===Z.id);O.push({id:Z.id,position:ie?{...ie.position}:Z.startPos,_absolutePosition:ie?{...ie.position}:Z.startPos,dragging:!1})}if((k=Ne.current)==null||k.postMessage({type:"nodePositions",data:{updates:O}}),Ee.current){const Z=O.map(ie=>({id:ie.id,type:"position",position:ie.position,dragging:!1}));Ee.current(Z)}if(W.selectedStarts.length>0){const Z=ee.current.filter(ie=>ie.selected);(x=(E=J.current).onSelectionDragStop)==null||x.call(E,l,Z)}requestAnimationFrame(()=>{We.current=null});const G=ee.current.find(Z=>Z.id===W.id);G&&((M=jt.current)==null||M.call(jt,l,G));return}Pt.current=!1,(R=we.current)==null||R.classList.remove("dragging")},[Be,vt,at,ct,dt]);a.useEffect(()=>{const l=we.current;if(!l)return;const y=u=>{Xt&&u.preventDefault();const p=fe.current;if(an||Ke.current){const R=cn;Ct==="horizontal"?p.x-=u.deltaY*R:(Ct==="vertical"||(p.x-=u.deltaX*R),p.y-=u.deltaY*R),Re(u);return}if(!un)return;const k=u.deltaY>0?.92:1.08,E=l.getBoundingClientRect(),x=u.clientX-E.left,M=u.clientY-E.top;p.x=x-(x-p.x)*k,p.y=M-(M-p.y)*k,p.zoom=Math.min(de,Math.max(re,p.zoom*k)),Re(u)};return l.addEventListener("wheel",y,{passive:!Xt}),()=>l.removeEventListener("wheel",y)},[Re,re,de,an,Ct,cn,un,Xt]),a.useEffect(()=>{if(!dn)return;const l=we.current;if(!l)return;let y=0,u=null;const p=x=>{if(x.touches.length===2){const M=x.touches[0].clientX-x.touches[1].clientX,R=x.touches[0].clientY-x.touches[1].clientY;y=Math.hypot(M,R);const W=l.getBoundingClientRect();u={x:(x.touches[0].clientX+x.touches[1].clientX)/2-W.left,y:(x.touches[0].clientY+x.touches[1].clientY)/2-W.top},x.preventDefault()}},k=x=>{if(x.touches.length===2&&y>0){x.preventDefault();const M=x.touches[0].clientX-x.touches[1].clientX,R=x.touches[0].clientY-x.touches[1].clientY,W=Math.hypot(M,R),L=W/y;y=W;const O=fe.current,G=u.x,Z=u.y;O.x=G-(G-O.x)*L,O.y=Z-(Z-O.y)*L,O.zoom=Math.min(de,Math.max(re,O.zoom*L)),Re(x)}},E=()=>{y=0,u=null};return l.addEventListener("touchstart",p,{passive:!1}),l.addEventListener("touchmove",k,{passive:!1}),l.addEventListener("touchend",E),()=>{l.removeEventListener("touchstart",p),l.removeEventListener("touchmove",k),l.removeEventListener("touchend",E)}},[dn,Re,re,de]),a.useEffect(()=>{if(!ln)return;const l=we.current;if(!l)return;const y=u=>{var L,O,G,Z;const p=Be(u.clientX,u.clientY);if(le(p.x,p.y)){(O=(L=J.current).onNodeDoubleClick)==null||O.call(L,u,le(p.x,p.y));return}const k=Ze(p.x,p.y);if(k){(Z=(G=J.current).onEdgeDoubleClick)==null||Z.call(G,u,k);return}const E=1.5,x=l.getBoundingClientRect(),M=u.clientX-x.left,R=u.clientY-x.top,W=fe.current;W.x=M-(M-W.x)*E,W.y=R-(R-W.y)*E,W.zoom=Math.min(de,Math.max(re,W.zoom*E)),Re(u)};return l.addEventListener("dblclick",y),()=>l.removeEventListener("dblclick",y)},[ln,Re,re,de,Be,le,Ze]),a.useEffect(()=>{const l=we.current;if(!l)return;const y=u=>{var x,M,R,W,L,O;const p=Be(u.clientX,u.clientY),k=le(p.x,p.y);if(k){(M=(x=J.current).onNodeContextMenu)==null||M.call(x,u,k);return}const E=Ze(p.x,p.y);if(E){(W=(R=J.current).onEdgeContextMenu)==null||W.call(R,u,E);return}(O=(L=J.current).onPaneContextMenu)==null||O.call(L,u)};return l.addEventListener("contextmenu",y),()=>l.removeEventListener("contextmenu",y)},[Be,le,Ze]),a.useEffect(()=>{const l=we.current;if(!l)return;let y=null,u=null;const p=x=>{var W,L,O,G,Z,ie,V,ae,ke,Ae,Fe,Ge,Oe,Jt;if((L=(W=J.current).onPaneMouseMove)==null||L.call(W,x),Pt.current||We.current||Ue.current||rt.current)return;const M=Be(x.clientX,x.clientY),R=le(M.x,M.y);if(R!==y&&(y&&((G=(O=J.current).onNodeMouseLeave)==null||G.call(O,x,y)),R&&((ie=(Z=J.current).onNodeMouseEnter)==null||ie.call(Z,x,R)),y=R),R&&((ae=(V=J.current).onNodeMouseMove)==null||ae.call(V,x,R)),!R){const ft=Ze(M.x,M.y);ft!==u&&(u&&((Ae=(ke=J.current).onEdgeMouseLeave)==null||Ae.call(ke,x,u)),ft&&((Ge=(Fe=J.current).onEdgeMouseEnter)==null||Ge.call(Fe,x,ft)),u=ft),ft&&((Jt=(Oe=J.current).onEdgeMouseMove)==null||Jt.call(Oe,x,ft))}},k=x=>{var M,R;return(R=(M=J.current).onPaneMouseEnter)==null?void 0:R.call(M,x)},E=x=>{var M,R,W,L,O,G;(R=(M=J.current).onPaneMouseLeave)==null||R.call(M,x),y&&((L=(W=J.current).onNodeMouseLeave)==null||L.call(W,x,y),y=null),u&&((G=(O=J.current).onEdgeMouseLeave)==null||G.call(O,x,u),u=null)};return l.addEventListener("mousemove",p),l.addEventListener("mouseenter",k),l.addEventListener("mouseleave",E),()=>{l.removeEventListener("mousemove",p),l.removeEventListener("mouseenter",k),l.removeEventListener("mouseleave",E)}},[Be,le,Ze]),a.useEffect(()=>{const l=Array.isArray(qe)?qe:[qe],y=async u=>{var p,k,E,x;if(l.includes(u.key)){if(u.target.tagName==="INPUT"||u.target.tagName==="TEXTAREA"||u.target.isContentEditable)return;const M=ee.current.filter(L=>L.selected),R=Pe.current.filter(L=>L.selected);if(!M.length&&!R.length)return;if(J.current.onBeforeDelete)try{if(!await J.current.onBeforeDelete({nodes:M,edges:R}))return}catch(L){(k=(p=J.current).onError)==null||k.call(p,"before-delete-error",L.message||"onBeforeDelete threw an error");return}const W=new Set(M.map(L=>L.id));if(M.length&&Ee.current&&(Ee.current(M.map(L=>({id:L.id,type:"remove"}))),De.current)){const L=Pe.current.filter(O=>W.has(O.source)||W.has(O.target));L.length&&De.current(L.map(O=>({id:O.id,type:"remove"})))}R.length&&De.current&&De.current(R.map(L=>({id:L.id,type:"remove"}))),(x=(E=J.current).onDelete)==null||x.call(E,{nodes:M,edges:R})}if((u.ctrlKey||u.metaKey)&&u.key==="a"){if(u.target.tagName==="INPUT"||u.target.tagName==="TEXTAREA")return;if(u.preventDefault(),Ee.current){const M=ee.current.filter(R=>!R.selected).map(R=>({id:R.id,type:"select",selected:!0}));M.length&&Ee.current(M)}if(De.current){const M=Pe.current.filter(R=>!R.selected).map(R=>({id:R.id,type:"select",selected:!0}));M.length&&De.current(M)}}};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[qe]);const Ft=a.useRef(!1);a.useEffect(()=>{var l,y;if(!Ft.current&&Ne.current){if(Ft.current=!0,Ye&&ee.current.length>0){const u=we.current;if(u){const p=u.getBoundingClientRect(),k=(xe==null?void 0:xe.padding)??.1,E=Mn(ee.current),x=Yt(E,p.width,p.height,k);xe!=null&&xe.maxZoom&&(x.zoom=Math.min(x.zoom,xe.maxZoom)),xe!=null&&xe.minZoom&&(x.zoom=Math.max(x.zoom,xe.minZoom)),fe.current=x,Re()}}(y=(l=J.current).onInit)==null||y.call(l,{getNodes:()=>[...ee.current],getEdges:()=>[...Pe.current],getNode:u=>ee.current.find(p=>p.id===u),getEdge:u=>Pe.current.find(p=>p.id===u),getViewport:()=>({...fe.current}),getZoom:()=>fe.current.zoom,setViewport:u=>{fe.current={x:u.x??fe.current.x,y:u.y??fe.current.y,zoom:u.zoom??fe.current.zoom},Re()},fitView:(u={})=>{const p=we.current;if(!p||!ee.current.length)return;const k=p.getBoundingClientRect(),E=u.nodes?ee.current.filter(R=>u.nodes.some(W=>W.id===R.id)):ee.current;if(!E.length)return;const x=Mn(E),M=Yt(x,k.width,k.height,u.padding??.1);u.maxZoom&&(M.zoom=Math.min(M.zoom,u.maxZoom)),u.minZoom&&(M.zoom=Math.max(M.zoom,u.minZoom)),fe.current=M,Re()},screenToFlowPosition:u=>Be(u.x,u.y),flowToScreenPosition:u=>{const p=fe.current,k=we.current;if(!k)return{x:0,y:0};const E=k.getBoundingClientRect();return{x:u.x*p.zoom+p.x+E.left,y:u.y*p.zoom+p.y+E.top}},zoomIn:()=>{const u=fe.current;u.zoom=Math.min(de,u.zoom*1.2),Re()},zoomOut:()=>{const u=fe.current;u.zoom=Math.max(re,u.zoom/1.2),Re()},zoomTo:u=>{fe.current.zoom=Math.min(de,Math.max(re,u)),Re()},setNodes:u=>{var p,k;(k=(p=J.current).onNodesChange)==null||k.call(p,[...ee.current.map(E=>({id:E.id,type:"remove"})),...(typeof u=="function"?u(ee.current):u).map(E=>({type:"add",item:E}))])},setEdges:u=>{var p,k;(k=(p=J.current).onEdgesChange)==null||k.call(p,[...Pe.current.map(E=>({id:E.id,type:"remove"})),...(typeof u=="function"?u(Pe.current):u).map(E=>({type:"add",item:E}))])},addNodes:u=>{var k,E;const p=Array.isArray(u)?u:[u];(E=(k=J.current).onNodesChange)==null||E.call(k,p.map(x=>({type:"add",item:x})))},addEdges:u=>{var k,E;const p=Array.isArray(u)?u:[u];(E=(k=J.current).onEdgesChange)==null||E.call(k,p.map(x=>({type:"add",item:x})))},deleteElements:({nodes:u=[],edges:p=[]})=>{var k,E,x,M;u.length&&((E=(k=J.current).onNodesChange)==null||E.call(k,u.map(R=>({id:R.id,type:"remove"})))),p.length&&((M=(x=J.current).onEdgesChange)==null||M.call(x,p.map(R=>({id:R.id,type:"remove"}))))},updateNodeData:(u,p)=>{var x,M;const k=ee.current.find(R=>R.id===u);if(!k)return;const E=typeof p=="function"?p(k.data):{...k.data,...p};(M=(x=J.current).onNodesChange)==null||M.call(x,[{id:u,type:"replace",item:{...k,data:E}}])},toObject:()=>({nodes:[...ee.current],edges:[...Pe.current],viewport:{...fe.current}}),setCenter:(u,p,k={})=>{const E=we.current;if(!E)return;const x=E.getBoundingClientRect(),M=k.zoom??fe.current.zoom;fe.current={x:x.width/2-u*M,y:x.height/2-p*M,zoom:M},Re()},fitBounds:(u,p={})=>{const k=we.current;if(!k)return;const E=k.getBoundingClientRect(),x=Yt(u,E.width,E.height,p.padding??.1);fe.current=x,Re()}})}});const Hn=a.useCallback(()=>{fe.current={...Le},Re()},[Re,Le]),_n=a.useCallback(l=>{var y;if(l)yt.current.push(l);else{const u=fe.current,p=we.current;if(!p)return;const k=p.getBoundingClientRect(),E=Math.round(-u.x/u.zoom+k.width/2/u.zoom),x=Math.round(-u.y/u.zoom+k.height/2/u.zoom);yt.current.push({x:E-80,y:x-45,w:160,h:90,title:"Note "+(yt.current.length+1),body:"Added at viewport center"})}(y=Ne.current)==null||y.postMessage({type:"cards",data:{cards:[...yt.current]}})},[]),Wn=a.useCallback(l=>{if(l.id||(l.id="node-"+Date.now()),!l.position){const y=fe.current,u=we.current;if(!u)return;const p=u.getBoundingClientRect();l.position={x:Math.round(-y.x/y.zoom+p.width/2/y.zoom)-ut/2,y:Math.round(-y.y/y.zoom+p.height/2/y.zoom)-et/2}}l.data||(l.data={label:l.id}),Ee.current&&Ee.current([{type:"add",item:l}])},[]),Fn=a.useCallback(()=>({...fe.current}),[]),F=a.useCallback(l=>{fe.current={...fe.current,...l},Re()},[Re]),ve=a.useCallback(l=>Be(l.x,l.y),[Be]),ne=n,Se=a.useMemo(()=>({wrapRef:we,canvasRef:Nt,workerRef:Ne,cameraRef:fe,nodesRef:ee,edgesRef:Pe,handleRegistryRef:fn,syncNodesToWorker:pn,onNodesChangeRef:Ee,onEdgesChangeRef:De,sendCamera:Re,screenToWorld:Be,viewportListeners:xt,selectionListeners:ot,zoomMin:re,zoomMax:de,snapToGrid:je,snapGrid:_e,nodeExtent:gt,defaultEdgeOptions:Et,edgeRouting:bt,resolvedNodesRef:it,noDragClassName:St,noPanClassName:zt,get nodes(){return t},get edges(){return n},get routedEdges(){return ne},get viewport(){return gn},get connection(){return Ut}}),[t,n,ne,gn,Ut,Re,Be,pn,xt,ot,re,de,je,_e,gt,Et,bt,St,zt]);return{wrapRef:we,canvasRef:Nt,canvasReady:Tt,onPointerDown:Gt,onPointerMove:Qt,onPointerUp:mn,resetView:Hn,addCard:_n,addNode:Wn,getCamera:Fn,setCamera:F,screenToFlowPosition:ve,store:Se}}function ro(e,t,n,r,i,o){const c=i-n,f=o-r,m=c*c+f*f;if(m===0)return Math.hypot(e-n,t-r);let d=((e-n)*c+(t-r)*f)/m;return d=Math.max(0,Math.min(1,d)),Math.hypot(e-(n+d*c),t-(r+d*f))}const lr=e=>{let t;const n=new Set,r=(d,h)=>{const b=typeof d=="function"?d(t):d;if(!Object.is(b,t)){const S=t;t=h??(typeof b!="object"||b===null)?b:Object.assign({},t,b),n.forEach(C=>C(t,S))}},i=()=>t,f={setState:r,getState:i,getInitialState:()=>m,subscribe:d=>(n.add(d),()=>n.delete(d))},m=t=e(r,i,f);return f},oo=(e=>e?lr(e):lr),so=e=>e;function io(e,t=so){const n=a.useSyncExternalStore(e.subscribe,a.useCallback(()=>t(e.getState()),[e,t]),a.useCallback(()=>t(e.getInitialState()),[e,t]));return a.useDebugValue(n),n}const Rt=a.createContext(null);function ao(e={}){return oo((t,n)=>({nodes:[],edges:[],viewport:{x:0,y:0,zoom:1},connection:null,minZoom:.1,maxZoom:5,width:0,height:0,domNode:null,nodesRef:{current:[]},edgesRef:{current:[]},cameraRef:{current:{x:0,y:0,zoom:1}},wrapRef:{current:null},workerRef:{current:null},onNodesChangeRef:{current:null},onEdgesChangeRef:{current:null},viewportListeners:new Set,selectionListeners:new Set,edgeLabelContainerRef:{current:null},viewportPortalRef:{current:null},screenToWorld:(r,i)=>{const o=n().cameraRef.current;return{x:(r-o.x)/o.zoom,y:(i-o.y)/o.zoom}},sendCamera:()=>{var i;const r=n();(i=r.workerRef.current)==null||i.postMessage({type:"camera",data:{camera:{...r.cameraRef.current}}})},...e}))}function Ie(e,t){const n=a.useContext(Rt);if(!n)throw new Error("useCanvasStore must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");const r=typeof n.getState=="function"&&typeof n.subscribe=="function",i=a.useRef(e),o=a.useRef(t),c=a.useRef(void 0);i.current=e,o.current=t;const f=a.useCallback(m=>{const d=i.current;if(!d)return m;const h=d(m),b=o.current||Object.is;return c.current!==void 0&&b(c.current,h)?c.current:(c.current=h,h)},[]);return r?io(n,e?f:void 0):e?f(n):n}function Rr(){const e=a.useContext(Rt);if(!e)throw new Error("useCanvasStoreApi must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");return typeof e.getState=="function"?e:{getState:()=>e,setState:()=>{},subscribe:()=>()=>{}}}const on=a.createContext(null);function co(){return a.useContext(on)}function uo({node:e,nodeType:t}){var z,A,B,D;const n=Ie(),r=a.useRef(n);r.current=n;const i=a.useRef(null),o=e._absolutePosition||e.position,c=a.useRef(null);a.useEffect(()=>{const X=i.current;if(!X)return;const H=new ResizeObserver(Y=>{var q,U,_,w;const{width:j,height:P}=Y[0].contentRect;if(j>0&&P>0){const g=r.current,v=g.nodesRef.current.find($=>$.id===e.id),N=(v==null?void 0:v.width)||((q=v==null?void 0:v.measured)==null?void 0:q.width),I=(v==null?void 0:v.height)||((U=v==null?void 0:v.measured)==null?void 0:U.height);(Math.abs((N||0)-j)>1||Math.abs((I||0)-P)>1)&&((w=(_=g.onNodesChangeRef).current)==null||w.call(_,[{id:e.id,type:"dimensions",dimensions:{width:j,height:P},setAttributes:!0}]))}});return H.observe(X),()=>H.disconnect()},[e.id]);const f=a.useCallback(X=>{var ce,pe,me,ye;X.stopPropagation();const H=X.target.tagName;if(H==="INPUT"||H==="TEXTAREA"||H==="SELECT"||H==="BUTTON"||H==="A"||H==="LABEL"||X.target.isContentEditable)return;const Y=r.current.noDragClassName||"nodrag",j=r.current.noPanClassName||"nopan";let P=X.target;for(;P&&P!==i.current;){if((ce=P.classList)!=null&&ce.contains(Y)||(pe=P.classList)!=null&&pe.contains(j))return;P=P.parentElement}if(r.current.onNodesChangeRef.current){const ue=[];if(X.shiftKey)ue.push({id:e.id,type:"select",selected:!e.selected});else for(const re of r.current.nodesRef.current)re.id===e.id&&!re.selected?ue.push({id:re.id,type:"select",selected:!0}):re.id!==e.id&&re.selected&&ue.push({id:re.id,type:"select",selected:!1});ue.length&&r.current.onNodesChangeRef.current(ue)}const q=r.current.cameraRef.current,U=r.current.wrapRef.current;if(!U)return;const _=U.getBoundingClientRect(),w=(X.clientX-_.left-q.x)/q.zoom,g=(X.clientY-_.top-q.y)/q.zoom,N=e.selected?r.current.nodesRef.current.filter(ue=>ue.selected&&ue.id!==e.id).map(ue=>({id:ue.id,startPos:{...ue.position}})):[];c.current={startPos:{...e.position},startMouse:{x:w,y:g},selectedStarts:N};const I=[{id:e.id,type:"position",dragging:!0}];for(const ue of N)I.push({id:ue.id,type:"position",dragging:!0});(ye=(me=r.current.onNodesChangeRef).current)==null||ye.call(me,I);const $=i.current;$&&$.setPointerCapture(X.pointerId);let K=null;const se=ue=>{var He,ze,Ve,tt;if(!c.current)return;const Ce=r.current.cameraRef.current,re=U.getBoundingClientRect(),de=(ue.clientX-re.left-Ce.x)/Ce.zoom,Le=(ue.clientY-re.top-Ce.y)/Ce.zoom,Ye=de-c.current.startMouse.x,xe=Le-c.current.startMouse.y;let he={x:c.current.startPos.x+Ye,y:c.current.startPos.y+xe};if(r.current.snapToGrid&&r.current.snapGrid&&(he={x:r.current.snapGrid[0]*Math.round(he.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(he.y/r.current.snapGrid[1])}),e.parentId&&e.extent==="parent"){const Me=r.current.nodesRef.current.find(Te=>Te.id===e.parentId);if(Me){const Te=Me.width||160,Xe=Me.height||60,je=e.width||((He=e.measured)==null?void 0:He.width)||160,_e=e.height||((ze=e.measured)==null?void 0:ze.height)||60;he={x:Math.max(0,Math.min(he.x,Te-je)),y:Math.max(0,Math.min(he.y,Xe-_e))}}}$&&($.style.left=he.x+"px",$.style.top=he.y+"px");const $e=[{id:e.id,position:he,_absolutePosition:he,dragging:!0}];for(const Me of c.current.selectedStarts){let Te={x:Me.startPos.x+Ye,y:Me.startPos.y+xe};r.current.snapToGrid&&r.current.snapGrid&&(Te={x:r.current.snapGrid[0]*Math.round(Te.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Te.y/r.current.snapGrid[1])});const Xe=U.querySelector(`[data-nodeid="${Me.id}"]`);Xe&&(Xe.style.left=Te.x+"px",Xe.style.top=Te.y+"px"),$e.push({id:Me.id,position:Te,_absolutePosition:Te,dragging:!0})}(tt=(Ve=r.current.workerRef)==null?void 0:Ve.current)==null||tt.postMessage({type:"nodePositions",data:{updates:$e}});for(const Me of $e){const Te=r.current.nodesRef.current.find(Xe=>Xe.id===Me.id);Te&&(Te.position=Me.position)}K=$e},te=ue=>{var de,Le,Ye,xe;if(!c.current)return;const Ce=[{id:e.id,position:e.position,dragging:!1}];for(const he of c.current.selectedStarts)Ce.push({id:he.id,position:he.startPos,dragging:!1});if(K)for(let he=0;he<K.length;he++)Ce[he]={id:K[he].id,position:K[he].position,dragging:!1};(Le=(de=r.current.workerRef)==null?void 0:de.current)==null||Le.postMessage({type:"nodePositions",data:{updates:Ce}});const re=[];for(const he of Ce)re.push({id:he.id,type:"position",position:he.position,dragging:!1});(xe=(Ye=r.current.onNodesChangeRef).current)==null||xe.call(Ye,re),c.current=null,K=null,$&&$.releasePointerCapture(ue.pointerId),$==null||$.removeEventListener("pointermove",se),$==null||$.removeEventListener("pointerup",te)};$==null||$.addEventListener("pointermove",se),$==null||$.addEventListener("pointerup",te)},[e]),m=a.useCallback(X=>{var U,_,w,g,v,N;if(!e.selected)return;const H=X.shiftKey?10:1;let Y=0,j=0;switch(X.key){case"ArrowUp":j=-H;break;case"ArrowDown":j=H;break;case"ArrowLeft":Y=-H;break;case"ArrowRight":Y=H;break;case"Escape":(_=(U=r.current.onNodesChangeRef).current)==null||_.call(U,[{id:e.id,type:"select",selected:!1}]);return;case"Delete":case"Backspace":e.deletable!==!1&&((g=(w=r.current.onNodesChangeRef).current)==null||g.call(w,[{id:e.id,type:"remove"}]));return;default:return}X.preventDefault();const P={x:e.position.x+Y,y:e.position.y+j},q=[{id:e.id,type:"position",position:P}];for(const I of r.current.nodesRef.current)I.selected&&I.id!==e.id&&q.push({id:I.id,type:"position",position:{x:I.position.x+Y,y:I.position.y+j}});(N=(v=r.current.onNodesChangeRef).current)==null||N.call(v,q)},[e]),d=e.width||((z=e.measured)==null?void 0:z.width),h=e.height||((A=e.measured)==null?void 0:A.height),b=!!(d&&h),S=(B=n.pinnedNodeIds)==null?void 0:B.has(e.id),C=a.useCallback(X=>{var H,Y;X.stopPropagation(),(Y=(H=r.current).togglePinNode)==null||Y.call(H,e.id)},[e.id]);return T.jsx(on.Provider,{value:e.id,children:T.jsxs("div",{ref:i,className:`ric-node-wrapper ${e.selected?"selected":""} ${e.dragging?"dragging":""}`,style:{position:"absolute",left:o.x,top:o.y,zIndex:e.type==="group"?0:e.zIndex||1,pointerEvents:e.type==="group"?"none":"all",visibility:b?"visible":"hidden",outline:"none"},"data-nodeid":e.id,tabIndex:e.selectable!==!1?0:void 0,role:"button","aria-label":`Node ${((D=e.data)==null?void 0:D.label)||e.id}`,"aria-selected":!!e.selected,onPointerDown:f,onKeyDown:m,children:[T.jsx(t,{id:e.id,data:e.data,type:e.type,selected:!!e.selected,dragging:!!e.dragging,draggable:e.draggable!==!1,selectable:e.selectable!==!1,deletable:e.deletable!==!1,isConnectable:e.connectable!==!1,zIndex:e.zIndex||0,positionAbsoluteX:o.x,positionAbsoluteY:o.y,width:d,height:h,sourcePosition:e.sourcePosition,targetPosition:e.targetPosition,parentId:e.parentId,dragHandle:e.dragHandle}),n.togglePinNode&&T.jsx("button",{className:"ric-pin-btn nodrag",onClick:C,title:S?"Unpin from DOM":"Pin to DOM",style:{position:"absolute",top:-8,left:-8,width:20,height:20,borderRadius:"50%",border:"1.5px solid "+(S?"#3b82f6":"#ccc"),background:S?"#3b82f6":"#fff",color:S?"#fff":"#999",fontSize:10,lineHeight:"16px",textAlign:"center",cursor:"pointer",padding:0,zIndex:10,pointerEvents:"all",boxShadow:"0 1px 3px rgba(0,0,0,0.12)"},children:"📌"})]})})}const lo=a.memo(uo),kr=160,Cr=60;function dr(e,t,n,r){var f,m;const i=e.width||((f=e.measured)==null?void 0:f.width)||kr,o=e.height||((m=e.measured)==null?void 0:m.height)||Cr,c=e._absolutePosition||e.position;if(e.handleBounds){const d=e.handleBounds[t]||[],h=n?d.find(b=>b.id===n):d[0];if(h&&h.x!==void 0&&h.y!==void 0){const b=h.position||(t==="source"?"right":"left");return{x:c.x+h.x,y:c.y+h.y,position:b}}}if(r){const d=`${e.id}__${n||t}`,h=r.get(d);if(h&&h.x!==void 0&&h.y!==void 0)return{x:c.x+h.x,y:c.y+h.y,position:h.position||(t==="source"?"right":"left")}}if(e.handles&&e.handles.length){for(const d of e.handles)if(d.type===t&&(!n||d.id===n)){if(d.x!==void 0&&d.y!==void 0)return{x:c.x+d.x,y:c.y+d.y,position:d.position||(t==="source"?"right":"left")};const h=d.position||(t==="source"?"right":"left");switch(h){case"top":return{x:c.x+i/2,y:c.y,position:h};case"bottom":return{x:c.x+i/2,y:c.y+o,position:h};case"left":return{x:c.x,y:c.y+o/2,position:h};default:return{x:c.x+i,y:c.y+o/2,position:h}}}}return t==="source"?{x:c.x+i,y:c.y+o/2,position:"right"}:{x:c.x,y:c.y+o/2,position:"left"}}function fo(e,t,n){return n==="left"?e-t:n==="right"?e+t:e}function ho(e,t,n){return n==="top"?e-t:n==="bottom"?e+t:e}function fr({x:e,y:t,position:n,type:r,onPointerDown:i}){return T.jsx("circle",{className:`ric-edge-anchor ric-edge-anchor-${r}`,cx:fo(e,10,n),cy:ho(t,10,n),r:10,stroke:"transparent",fill:"transparent",style:{cursor:"move",pointerEvents:"stroke"},onPointerDown:i})}function go({edge:e,edgeType:t,nodes:n,reconnectable:r}){var P,q,U;const i=a.useContext(Rt),o=a.useRef(typeof i.getState=="function"?i.getState():i);o.current=typeof i.getState=="function"?i.getState():i;const[c,f]=a.useState(null),m=a.useCallback((_,w,g,v)=>{var pe;w.stopPropagation(),w.preventDefault();const N=o.current,I=N.wrapRef.current;if(!I)return;const $=_==="source"?v:g,K=_==="source"?e.target:e.source;(pe=N.workerRef.current)==null||pe.postMessage({type:"connecting",data:{from:{x:$.x,y:$.y},to:{x:$.x,y:$.y}}});const se=I.getBoundingClientRect(),te=me=>{var re;const ye=N.cameraRef.current,ue=(me.clientX-se.left-ye.x)/ye.zoom,Ce=(me.clientY-se.top-ye.y)/ye.zoom;(re=N.workerRef.current)==null||re.postMessage({type:"connecting",data:{from:{x:$.x,y:$.y},to:{x:ue,y:Ce}}})},ce=me=>{var xe,he,$e,He;const ye=N.cameraRef.current,ue=(me.clientX-se.left-ye.x)/ye.zoom,Ce=(me.clientY-se.top-ye.y)/ye.zoom,re=20/ye.zoom;let de=null,Le=null;const Ye=(xe=N.handleRegistryRef)==null?void 0:xe.current;for(const ze of N.nodesRef.current){if(ze.hidden)continue;const Ve=ze.width||kr,tt=ze.height||Cr,Me=ze._absolutePosition||ze.position,Te=[];if(Ye)for(const[,je]of Ye)je.nodeId===ze.id&&Te.push(je);const Xe=Te.length>0?Te:ze.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const je of Xe){let _e,qe;if(je.x!==void 0&&je.y!==void 0)_e=Me.x+je.x,qe=Me.y+je.y;else switch(je.position||(je.type==="source"?"right":"left")){case"top":_e=Me.x+Ve/2,qe=Me.y;break;case"bottom":_e=Me.x+Ve/2,qe=Me.y+tt;break;case"left":_e=Me.x,qe=Me.y+tt/2;break;default:_e=Me.x+Ve,qe=Me.y+tt/2;break}if(Math.abs(ue-_e)<re&&Math.abs(Ce-qe)<re){de=ze,Le=je.id||null;break}}if(de)break}if(de){const ze=_==="source"?{source:de.id,target:K,sourceHandle:Le,targetHandle:e.targetHandle}:{source:K,target:de.id,sourceHandle:e.sourceHandle,targetHandle:Le};($e=(he=N.onEdgesChangeRef).current)==null||$e.call(he,[{id:e.id,type:"remove"},{type:"add",item:{id:e.id,...ze}}])}(He=N.workerRef.current)==null||He.postMessage({type:"connecting",data:null}),I.removeEventListener("pointermove",te),I.removeEventListener("pointerup",ce)};I.addEventListener("pointermove",te),I.addEventListener("pointerup",ce)},[e]),d=n.find(_=>_.id===e.source),h=n.find(_=>_.id===e.target),b=d&&!!(d.width||(P=d.measured)!=null&&P.width),S=h&&!!(h.width||(q=h.measured)!=null&&q.width),C=o.current,z=(U=C.handleRegistryRef)==null?void 0:U.current,A=b?dr(d,"source",e.sourceHandle,z):null,B=S?dr(h,"target",e.targetHandle,z):null,D=e.type==="bezier"||e.type==="simplebezier"||e.type==="default",X=C.routedEdges||C.edges,H=X==null?void 0:X.find(_=>_.id===e.id),Y=D?null:(H==null?void 0:H._routedPoints)||e._routedPoints||null,j=r!==!1&&e.reconnectable!==!1;return!A||!B?null:T.jsxs("g",{className:`ric-edge-wrapper ${e.selected?"selected":""}`,"data-edgeid":e.id,onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),children:[T.jsx(t,{id:e.id,source:e.source,target:e.target,sourceX:A.x,sourceY:A.y,targetX:B.x,targetY:B.y,sourcePosition:A.position,targetPosition:B.position,sourceHandleId:e.sourceHandle,targetHandleId:e.targetHandle,data:e.data,type:e.type,selected:!!e.selected,animated:!!e.animated,label:e.label,style:e.style,selectable:e.selectable!==!1,deletable:e.deletable!==!1,routedPoints:Y}),j&&(c||e.selected)&&T.jsxs(T.Fragment,{children:[T.jsx(fr,{x:A.x,y:A.y,position:A.position,type:"source",onPointerDown:_=>m("source",_,A,B)}),T.jsx(fr,{x:B.x,y:B.y,position:B.position,type:"target",onPointerDown:_=>m("target",_,A,B)})]})]})}const yo=a.memo(go);function Er({selectionKeyCode:e="Shift",selectionMode:t="partial"}){var A;const n=Ie(),[r,i]=a.useState(null),o=a.useRef(null);if(a.useEffect(()=>{const B=n.wrapRef.current;if(!B)return;let D=!1,X=null,H=!1;const Y=_=>{_.key===e&&(H=!0)},j=_=>{_.key===e&&(H=!1)},P=_=>{if(!H)return;const w=_.target;if(w.closest(".ric-node-wrapper")||w.closest(".ric-handle"))return;D=!0;const g=n.cameraRef.current,v=B.getBoundingClientRect(),N=(_.clientX-v.left-g.x)/g.zoom,I=(_.clientY-v.top-g.y)/g.zoom;X={x:N,y:I},i({startX:N,startY:I,endX:N,endY:I}),_.stopPropagation()},q=_=>{if(!D||!X)return;const w=n.cameraRef.current,g=B.getBoundingClientRect(),v=(_.clientX-g.left-w.x)/w.zoom,N=(_.clientY-g.top-w.y)/w.zoom;i({startX:X.x,startY:X.y,endX:v,endY:N})},U=_=>{var K,se;if(!D||!X)return;D=!1;const w=n.cameraRef.current,g=B.getBoundingClientRect(),v=(_.clientX-g.left-w.x)/w.zoom,N=(_.clientY-g.top-w.y)/w.zoom,I={x:Math.min(X.x,v),y:Math.min(X.y,N),width:Math.abs(v-X.x),height:Math.abs(N-X.y)},$=[];for(const te of n.nodesRef.current){const ce=te._absolutePosition||te.position,pe=te.width||160,me=te.height||60;let ye;t==="full"?ye=ce.x>=I.x&&ce.y>=I.y&&ce.x+pe<=I.x+I.width&&ce.y+me<=I.y+I.height:ye=ce.x+pe>I.x&&ce.x<I.x+I.width&&ce.y+me>I.y&&ce.y<I.y+I.height,$.push({id:te.id,type:"select",selected:ye})}$.length&&((se=(K=n.onNodesChangeRef).current)==null||se.call(K,$)),X=null,i(null)};return B.addEventListener("pointerdown",P,!0),B.addEventListener("pointermove",q),B.addEventListener("pointerup",U),window.addEventListener("keydown",Y),window.addEventListener("keyup",j),()=>{B.removeEventListener("pointerdown",P,!0),B.removeEventListener("pointermove",q),B.removeEventListener("pointerup",U),window.removeEventListener("keydown",Y),window.removeEventListener("keyup",j)}},[n,e,t]),!r)return null;const c=((A=n.cameraRef)==null?void 0:A.current)||{x:0,y:0,zoom:1},f=Math.min(r.startX,r.endX),m=Math.min(r.startY,r.endY),d=Math.abs(r.endX-r.startX),h=Math.abs(r.endY-r.startY),b=f*c.zoom+c.x,S=m*c.zoom+c.y,C=d*c.zoom,z=h*c.zoom;return T.jsx("div",{ref:o,className:"ric-selection-box",style:{position:"absolute",left:b,top:S,width:C,height:z,border:"1px dashed #3b82f6",background:"rgba(59, 130, 246, 0.08)",pointerEvents:"none",zIndex:100}})}Er.displayName="SelectionBox";const Sr=a.memo(Er);function Qn(e,t,n){switch(e){case"top":return{x:t/2,y:0};case"bottom":return{x:t/2,y:n};case"left":return{x:0,y:n/2};case"right":return{x:t,y:n/2};default:return{x:t,y:n/2}}}function xo(e,t){const n=e.closest(".ric-node-wrapper");if(!n)return null;const r=n.getBoundingClientRect(),i=e.getBoundingClientRect(),o=t||1;return{x:(i.left+i.width/2-r.left)/o,y:(i.top+i.height/2-r.top)/o}}let Un=!1,Mt=null;function zr(e){Mt=e,!Un&&(Un=!0,requestAnimationFrame(()=>{var t;Un=!1,(t=Mt==null?void 0:Mt.syncNodesToWorker)==null||t.call(Mt),Mt=null}))}const Jn=new WeakMap;let bn=null;function po(){return bn||(bn=new ResizeObserver(e=>{var t;for(const n of e){const r=Jn.get(n.target);if(!r)continue;const{width:i,height:o}=n.contentRect;if(!i||!o)continue;const c=r.getStore(),f=(t=c.handleRegistryRef)==null?void 0:t.current;if(f){for(const[m,d]of f)if(d.nodeId===r.nodeId){const h=Qn(d.position,i,o);d.x=h.x,d.y=h.y,f.set(m,d)}zr(c)}}}),bn)}function mo({type:e="source",position:t=e==="source"?"right":"left",id:n,isConnectable:r=!0,isConnectableStart:i=!0,isConnectableEnd:o=!0,children:c,className:f="",style:m={},onConnect:d,...h}){const b=a.useContext(on),S=a.useContext(Rt),C=a.useRef(null),z=a.useCallback(()=>typeof S.getState=="function"?S.getState():S,[S]),A=a.useRef(z);A.current=z,a.useLayoutEffect(()=>{var w,g,v,N,I,$,K;if(!b)return;const H=A.current(),Y=(w=H.handleRegistryRef)==null?void 0:w.current;if(!Y)return;const j=`${b}__${n||e}`,P=(v=(g=H.nodesRef)==null?void 0:g.current)==null?void 0:v.find(se=>se.id===b),q=(P==null?void 0:P.width)||((N=P==null?void 0:P.measured)==null?void 0:N.width),U=(P==null?void 0:P.height)||((I=P==null?void 0:P.measured)==null?void 0:I.height);let _;q&&U?_=Qn(t,q,U):C.current?_=xo(C.current,(K=($=H.cameraRef)==null?void 0:$.current)==null?void 0:K.zoom):_=Qn(t,160,60),Y.set(j,{nodeId:b,id:n||null,type:e,position:t,x:_.x,y:_.y})},[b,n,e,t]),a.useEffect(()=>{if(!b)return;const H=A.current();zr(H);const Y=C.current,j=Y==null?void 0:Y.closest(".ric-node-wrapper");return j&&!Jn.has(j)&&(Jn.set(j,{nodeId:b,getStore:A.current}),po().observe(j)),()=>{var _;const q=(_=A.current().handleRegistryRef)==null?void 0:_.current,U=`${b}__${n||e}`;q==null||q.delete(U)}},[b,n,e,t]);const B=a.useCallback(()=>{var g;const H=A.current(),Y=H.nodesRef.current.find(v=>v.id===b);if(!Y)return null;const j=Y._absolutePosition||Y.position,P=(g=H.handleRegistryRef)==null?void 0:g.current,q=`${b}__${n||e}`,U=P==null?void 0:P.get(q);if(U&&U.x!==void 0&&U.y!==void 0)return{x:j.x+U.x,y:j.y+U.y};const _=Y.width||160,w=Y.height||60;switch(t){case"top":return{x:j.x+_/2,y:j.y};case"bottom":return{x:j.x+_/2,y:j.y+w};case"left":return{x:j.x,y:j.y+w/2};default:return{x:j.x+_,y:j.y+w/2}}},[b,n,e,t]),D=a.useCallback(H=>{var N;if(!r||!i)return;H.stopPropagation(),H.preventDefault();const Y=A.current(),j=Y.cameraRef.current,P=Y.wrapRef.current;if(!P)return;const q=P.getBoundingClientRect(),U=B();if(!U)return;const _=U.x,w=U.y;(N=Y.workerRef.current)==null||N.postMessage({type:"connecting",data:{from:{x:_,y:w},to:{x:_,y:w}}}),P.setPointerCapture(H.pointerId);const g=I=>{var se;const $=(I.clientX-q.left-j.x)/j.zoom,K=(I.clientY-q.top-j.y)/j.zoom;(se=Y.workerRef.current)==null||se.postMessage({type:"connecting",data:{from:{x:_,y:w},to:{x:$,y:K}}})},v=I=>{var me,ye,ue,Ce;const $=(I.clientX-q.left-j.x)/j.zoom,K=(I.clientY-q.top-j.y)/j.zoom,se=20/j.zoom;let te=null,ce=null;const pe=(me=Y.handleRegistryRef)==null?void 0:me.current;for(const re of Y.nodesRef.current){if(re.id===b||re.hidden)continue;const de=re._absolutePosition||re.position,Le=[];if(pe)for(const[,xe]of pe)xe.nodeId===re.id&&Le.push(xe);const Ye=Le.length>0?Le:re.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const xe of Ye){let he,$e;if(xe.x!==void 0&&xe.y!==void 0)he=de.x+xe.x,$e=de.y+xe.y;else{const He=re.width||160,ze=re.height||60;switch(xe.position||(xe.type==="source"?"right":"left")){case"top":he=de.x+He/2,$e=de.y;break;case"bottom":he=de.x+He/2,$e=de.y+ze;break;case"left":he=de.x,$e=de.y+ze/2;break;default:he=de.x+He,$e=de.y+ze/2;break}}if(Math.abs($-he)<se&&Math.abs(K-$e)<se){te=re,ce=xe.id||null;break}}if(te)break}if(te){const re={source:e==="source"?b:te.id,target:e==="source"?te.id:b,sourceHandle:e==="source"?n||null:ce,targetHandle:e==="source"?ce:n||null};(ue=(ye=Y.onEdgesChangeRef)==null?void 0:ye.current)==null||ue.call(ye,[{type:"add",item:{id:`e-${re.source}-${re.target}`,...re}}])}(Ce=Y.workerRef.current)==null||Ce.postMessage({type:"connecting",data:null}),P.removeEventListener("pointermove",g),P.removeEventListener("pointerup",v)};P.addEventListener("pointermove",g),P.addEventListener("pointerup",v)},[b,n,e,t,r,i,B]),X={top:{top:0,left:"50%",transform:"translate(-50%, -50%)"},bottom:{bottom:0,left:"50%",transform:"translate(-50%, 50%)"},left:{top:"50%",left:0,transform:"translate(-50%, -50%)"},right:{top:"50%",right:0,transform:"translate(50%, -50%)"}}[t]||{};return T.jsx("div",{ref:C,className:`ric-handle ric-handle-${t} ric-handle-${e} ${f}`,"data-handleid":n||null,"data-nodeid":b,"data-handlepos":t,"data-handletype":e,onPointerDown:D,style:{position:"absolute",width:8,height:8,borderRadius:"50%",background:"#1a192b",border:"none",zIndex:10,cursor:r?"crosshair":"default",boxSizing:"border-box",...X,...m},...h,children:c})}const rn=a.memo(mo);function vo({data:e,isConnectable:t,selected:n,targetPosition:r="left",sourcePosition:i="right",hideSourceHandle:o=!1,hideTargetHandle:c=!1}){return T.jsxs("div",{className:`ric-default-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!c&&T.jsx(rn,{type:"target",position:r,isConnectable:t}),T.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!o&&T.jsx(rn,{type:"source",position:i,isConnectable:t})]})}function Nr({data:e,isConnectable:t,selected:n,sourcePosition:r="right",hideSourceHandle:i=!1}){return T.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:[T.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!i&&T.jsx(rn,{type:"source",position:r,isConnectable:t})]})}function Pr({data:e,isConnectable:t,selected:n,targetPosition:r="left",hideTargetHandle:i=!1}){return T.jsxs("div",{className:`ric-output-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderTop:"2px solid #ff0072",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!i&&T.jsx(rn,{type:"target",position:r,isConnectable:t}),T.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label})]})}function Ir({data:e,selected:t,width:n,height:r}){return T.jsx("div",{className:`ric-group-node${t?" selected":""}`,style:{width:n||300,height:r||200,background:"rgba(240, 240, 240, 0.25)",border:t?"2px solid #3b82f6":"1px dashed #ccc",borderRadius:8,padding:8,boxSizing:"border-box"},children:(e==null?void 0:e.label)&&T.jsx("div",{style:{fontSize:11,fontWeight:600,color:"#888",userSelect:"none"},children:e.label})})}function Tr({x:e,y:t,label:n,labelStyle:r,labelShowBg:i=!0,labelBgStyle:o,labelBgPadding:c=[2,4],labelBgBorderRadius:f=2,children:m,className:d="",...h}){const[b,S]=a.useState({x:1,y:0,width:0,height:0}),C=a.useRef(null);return a.useEffect(()=>{if(C.current){const z=C.current.getBBox();S({x:z.x,y:z.y,width:z.width,height:z.height})}},[n]),n?T.jsxs("g",{transform:`translate(${e-b.width/2} ${t-b.height/2})`,className:`ric-edge-textwrapper ${d}`,visibility:b.width?"visible":"hidden",...h,children:[i&&T.jsx("rect",{width:b.width+2*c[0],x:-c[0],y:-c[1],height:b.height+2*c[1],className:"ric-edge-textbg",style:o,rx:f,ry:f}),T.jsx("text",{className:"ric-edge-text",y:b.height/2,dy:"0.3em",ref:C,style:r,children:n}),m]}):null}Tr.displayName="EdgeText";const Lr=a.memo(Tr);function hr(e){return e!=null&&e!==""&&!isNaN(Number(e))}function sn({id:e,path:t,labelX:n,labelY:r,label:i,labelStyle:o,labelShowBg:c,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:d,interactionWidth:h=20,style:b,markerEnd:S,markerStart:C,className:z="",...A}){return T.jsxs(T.Fragment,{children:[T.jsx("path",{id:e,d:t,fill:"none",stroke:"#b1b1b7",strokeWidth:1.5,className:`ric-edge-path ${z}`,style:b,markerEnd:S,markerStart:C,...A}),h?T.jsx("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:h,className:"ric-edge-interaction",style:{pointerEvents:"stroke"}}):null,i&&hr(n)&&hr(r)?T.jsx(Lr,{x:n,y:r,label:i,labelStyle:o,labelShowBg:c,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:d}):null]})}const en=20;function gr(e,t,n){switch(n){case"right":return{x:e+en,y:t};case"left":return{x:e-en,y:t};case"bottom":return{x:e,y:t+en};case"top":return{x:e,y:t-en};default:return{x:e+en,y:t}}}const er=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:c="bottom",targetPosition:f="top",label:m,labelStyle:d,labelShowBg:h,labelBgStyle:b,labelBgPadding:S,labelBgBorderRadius:C,style:z,markerEnd:A,markerStart:B,interactionWidth:D}){let X,H,Y;const j=gr(n,r,c),P=gr(i,o,f),q=Math.abs(P.x-j.x),U=Math.max(50,q*.5);let _,w,g,v;switch(c){case"left":_=j.x-U,w=j.y;break;case"top":_=j.x,w=j.y-U;break;case"bottom":_=j.x,w=j.y+U;break;default:_=j.x+U,w=j.y;break}switch(f){case"right":g=P.x+U,v=P.y;break;case"top":g=P.x,v=P.y-U;break;case"bottom":g=P.x,v=P.y+U;break;default:g=P.x-U,v=P.y;break}X=`M ${n},${r} L ${j.x},${j.y} C ${_},${w} ${g},${v} ${P.x},${P.y} L ${i},${o}`;const N=.5,I=.5;return H=I*I*I*j.x+3*I*I*N*_+3*I*N*N*g+N*N*N*P.x,Y=I*I*I*j.y+3*I*I*N*w+3*I*N*N*v+N*N*N*P.y,T.jsx(sn,{id:t,path:X,labelX:H,labelY:Y,label:m,labelStyle:d,labelShowBg:h,labelBgStyle:b,labelBgPadding:S,labelBgBorderRadius:C,style:z,markerEnd:A,markerStart:B,interactionWidth:D})});er.displayName="BezierEdge";function tr({sourceX:e,sourceY:t,targetX:n,targetY:r}){const i=`M ${e},${t}L ${n},${r}`,o=(e+n)/2,c=(t+r)/2;return[i,o,c,0,0]}function nr({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i="right",targetPosition:o="left",curvature:c=.25}){const f=Math.abs(n-e),m=Math.abs(r-t),d=Math.sqrt(f*f+m*m),h=Math.max(d*c,50);let b,S,C,z;switch(i){case"top":b=e,S=t-h;break;case"bottom":b=e,S=t+h;break;case"left":b=e-h,S=t;break;default:b=e+h,S=t;break}switch(o){case"top":C=n,z=r-h;break;case"bottom":C=n,z=r+h;break;case"right":C=n+h,z=r;break;default:C=n-h,z=r;break}const A=`M ${e},${t} C ${b},${S} ${C},${z} ${n},${r}`,B=.5,D=1-B,X=D*D*D*e+3*D*D*B*b+3*D*B*B*C+B*B*B*n,H=D*D*D*t+3*D*D*B*S+3*D*B*B*z+B*B*B*r;return[A,X,H,0,0]}function rr({sourceX:e,sourceY:t,targetX:n,targetY:r}){const i=Math.abs(n-e),o=Math.max(i*.5,50),c=e+o,f=n-o,m=`M ${e},${t} C ${c},${t} ${f},${r} ${n},${r}`,d=.5,h=.5,b=h*h*h*e+3*h*h*d*c+3*h*d*d*f+d*d*d*n,S=h*h*h*t+3*h*h*d*t+3*h*d*d*r+d*d*d*r;return[m,b,S,0,0]}function Rn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i="right",targetPosition:o="left",borderRadius:c=5,offset:f=20}){const m=i==="left"||i==="right",d=Math.min(c,Math.abs(n-e)/2,Math.abs(r-t)/2);if(m){if(Math.abs(r-t)<1)return[`M ${e},${t} L ${n},${r}`,(e+n)/2,t,0,0];const C=(e+n)/2,z=r>t?1:-1;return[`M ${e},${t} L ${C-d},${t} Q ${C},${t} ${C},${t+z*d} L ${C},${r-z*d} Q ${C},${r} ${C+(n>C?d:-d)},${r} L ${n},${r}`,C,(t+r)/2,0,0]}const h=(t+r)/2,b=n>e?1:-1;return[`M ${e},${t} L ${e},${h-d} Q ${e},${h} ${e+b*d},${h} L ${n-b*d},${h} Q ${n},${h} ${n},${h+(r>h?d:-d)} L ${n},${r}`,(e+n)/2,h,0,0]}function bo({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[,i,o]=nr({sourceX:e,sourceY:t,targetX:n,targetY:r});return[i,o,0,0]}function wo({sourceX:e,sourceY:t,targetX:n,targetY:r}){return[(e+n)/2,(t+r)/2,0,0]}function Mo(e,t,n){const r=n.filter(o=>o.id!==e.id),i={...e,id:e.id,source:t.source,target:t.target,sourceHandle:t.sourceHandle??e.sourceHandle,targetHandle:t.targetHandle??e.targetHandle};return r.push(i),r}const kn=160,Cn=60,tn=20,wn=12,En=20;function yr(e,t,n){var c,f;const r=e.width||((c=e.measured)==null?void 0:c.width)||kn,i=e.height||((f=e.measured)==null?void 0:f.height)||Cn,o=e._absolutePosition||e.position;if(e.handles&&e.handles.length>0){for(const m of e.handles)if(m.type===t&&(!n||m.id===n)){if(m.x!==void 0&&m.y!==void 0)return{x:o.x+m.x,y:o.y+m.y,dir:m.position||(t==="source"?"right":"left")};switch(m.position||(t==="source"?"right":"left")){case"top":return{x:o.x+r/2,y:o.y,dir:"top"};case"bottom":return{x:o.x+r/2,y:o.y+i,dir:"bottom"};case"left":return{x:o.x,y:o.y+i/2,dir:"left"};default:return{x:o.x+r,y:o.y+i/2,dir:"right"}}}}return t==="source"?{x:o.x+r,y:o.y+i/2,dir:"right"}:{x:o.x,y:o.y+i/2,dir:"left"}}function Sn(e,t){switch(e.dir){case"right":return{x:e.x+t,y:e.y,dir:e.dir};case"left":return{x:e.x-t,y:e.y,dir:e.dir};case"bottom":return{x:e.x,y:e.y+t,dir:e.dir};case"top":return{x:e.x,y:e.y-t,dir:e.dir};default:return{x:e.x+t,y:e.y,dir:e.dir}}}function Ro(e,t,n,r,i,o,c,f){const m=Math.min(e,n),d=Math.max(e,n),h=Math.min(t,r),b=Math.max(t,r);if(d<=i||m>=i+c||b<=o||h>=o+f)return!1;const S=.5;if(e>i+S&&e<i+c-S&&t>o+S&&t<o+f-S||n>i+S&&n<i+c-S&&r>o+S&&r<o+f-S)return!0;const C=(e+n)/2,z=(t+r)/2;if(C>i+S&&C<i+c-S&&z>o+S&&z<o+f-S)return!0;const A=[[i,o],[i+c,o],[i+c,o+f],[i,o+f]];for(let B=0;B<4;B++)if(ko(e,t,n,r,A[B][0],A[B][1],A[(B+1)%4][0],A[(B+1)%4][1]))return!0;return!1}function ko(e,t,n,r,i,o,c,f){const m=(c-i)*(t-o)-(f-o)*(e-i),d=(c-i)*(r-o)-(f-o)*(n-i),h=(n-e)*(o-t)-(r-t)*(i-e),b=(n-e)*(f-t)-(r-t)*(c-e);return(m>0&&d<0||m<0&&d>0)&&(h>0&&b<0||h<0&&b>0)}function Kn(e,t,n,r,i){for(let o=0;o<i.length;o++){const c=i[o];if(Ro(e,t,n,r,c.x,c.y,c.w,c.h))return!1}return!0}function Co(e,t,n){for(let r=0;r<n.length;r++){const i=n[r];if(e>i.x&&e<i.x+i.w&&t>i.y&&t<i.y+i.h)return!0}return!1}function or(e,t){var r,i;const n=[];for(let o=0;o<e.length;o++){const c=e[o];if(c.hidden||t&&t.has(c.id)||c.type==="group")continue;const f=c._absolutePosition||c.position,m=c.width||((r=c.measured)==null?void 0:r.width)||kn,d=c.height||((i=c.measured)==null?void 0:i.height)||Cn;n.push({id:c.id,x:f.x-tn,y:f.y-tn,w:m+2*tn,h:d+2*tn})}return n}function Br(e,t,n){if(Kn(e.x,e.y,t.x,t.y,n))return null;const r=new Set,i=new Set;r.add(e.x),r.add(t.x),i.add(e.y),i.add(t.y);const o=tn+5;e.dir==="right"?r.add(e.x+o):e.dir==="left"?r.add(e.x-o):e.dir==="top"?i.add(e.y-o):e.dir==="bottom"&&i.add(e.y+o),t.dir==="right"?r.add(t.x+o):t.dir==="left"?r.add(t.x-o):t.dir==="top"?i.add(t.y-o):t.dir==="bottom"&&i.add(t.y+o);for(let g=0;g<n.length;g++){const v=n[g];r.add(v.x),r.add(v.x+v.w),i.add(v.y),i.add(v.y+v.h)}const c=[...r].sort((g,v)=>g-v),f=[...i].sort((g,v)=>g-v),m=new Map,d=new Map;for(let g=0;g<c.length;g++)m.set(c[g],g);for(let g=0;g<f.length;g++)d.set(f[g],g);const h=c.length,b=f.length,S=(g,v)=>v*h+g,C=m.get(e.x),z=d.get(e.y),A=m.get(t.x),B=d.get(t.y);if(C===void 0||z===void 0||A===void 0||B===void 0)return null;const D=S(C,z),X=S(A,B),H=new Float64Array(h*b).fill(1/0),Y=new Float64Array(h*b).fill(1/0),j=new Int32Array(h*b).fill(-1),P=new Int8Array(h*b).fill(-1),q=new Uint8Array(h*b);H[D]=0,Y[D]=Math.abs(c[A]-e.x)+Math.abs(f[B]-e.y);const U=[D],_=15,w=[[1,0],[-1,0],[0,1],[0,-1]];for(;U.length>0;){let g=0;for(let te=1;te<U.length;te++)Y[U[te]]<Y[U[g]]&&(g=te);const v=U[g];if(U[g]=U[U.length-1],U.pop(),v===X){const te=[];let ce=X;for(;ce!==-1&&ce!==D;){const pe=ce/h|0,me=ce%h;te.unshift({x:c[me],y:f[pe]}),ce=j[ce]}return te.unshift({x:e.x,y:e.y}),Eo(te,n)}if(q[v])continue;q[v]=1;const N=v/h|0,I=v%h,$=c[I],K=f[N],se=P[v];for(let te=0;te<4;te++){const ce=I+w[te][0],pe=N+w[te][1];if(ce<0||ce>=h||pe<0||pe>=b)continue;const me=S(ce,pe);if(q[me])continue;const ye=c[ce],ue=f[pe];if(Co(ye,ue,n)||!Kn($,K,ye,ue,n))continue;const Ce=Math.abs(ye-$)+Math.abs(ue-K),re=se>=0&&se!==te?_:0,de=H[v]+Ce+re;de<H[me]&&(j[me]=v,P[me]=te,H[me]=de,Y[me]=de+Math.abs(c[A]-ye)+Math.abs(f[B]-ue),U.push(me))}}return null}function Eo(e,t){if(!e||e.length<=2)return e;const n=[e[0]];for(let r=1;r<e.length-1;r++){const i=n[n.length-1],o=e[r],c=e[r+1],f=Math.abs(i.x-o.x)<.5&&Math.abs(o.x-c.x)<.5,m=Math.abs(i.y-o.y)<.5&&Math.abs(o.y-c.y)<.5;(f||m)&&Kn(i.x,i.y,c.x,c.y,t)||n.push(o)}return n.push(e[e.length-1]),n}function So(e){const t=new Map,n=new Map;for(const i of e){const o=i._routedPoints;if(!(!o||o.length<2))for(let c=0;c<o.length-1;c++){const f=o[c],m=o[c+1];if(Math.abs(f.y-m.y)<.5){const d=Math.round(f.y*10)/10;t.has(d)||t.set(d,[]),t.get(d).push({edgeId:i.id,segIdx:c,x1:Math.min(f.x,m.x),x2:Math.max(f.x,m.x)})}else if(Math.abs(f.x-m.x)<.5){const d=Math.round(f.x*10)/10;n.has(d)||n.set(d,[]),n.get(d).push({edgeId:i.id,segIdx:c,y1:Math.min(f.y,m.y),y2:Math.max(f.y,m.y)})}}}const r=new Map;for(const i of e)i._routedPoints&&r.set(i.id,i._routedPoints.map(o=>({...o})));for(const[,i]of t){if(i.length<2)continue;const o=xr(i,"x1","x2");for(const c of o){if(c.length<2)continue;const f=(c.length-1)*wn/2;for(let m=0;m<c.length;m++){const d=c[m],h=-f+m*wn,b=r.get(d.edgeId);b&&(b[d.segIdx].y+=h,b[d.segIdx+1].y+=h)}}}for(const[,i]of n){if(i.length<2)continue;const o=xr(i,"y1","y2");for(const c of o){if(c.length<2)continue;const f=(c.length-1)*wn/2;for(let m=0;m<c.length;m++){const d=c[m],h=-f+m*wn,b=r.get(d.edgeId);b&&(b[d.segIdx].x+=h,b[d.segIdx+1].x+=h)}}}return e.map(i=>{const o=r.get(i.id);return o?{...i,_routedPoints:o}:i})}function xr(e,t,n){if(e.length<2)return[];const r=[...e].sort((c,f)=>c[t]-f[t]),i=[];let o=[r[0]];for(let c=1;c<r.length;c++){const f=o[o.length-1];r[c][t]<f[n]?o.push(r[c]):(o.length>1&&i.push(o),o=[r[c]])}return o.length>1&&i.push(o),i}function zn(e,t=6,n=!1){if(!e||e.length<2)return null;if(n)return zo(e);const r=t;let i=`M ${e[0].x},${e[0].y}`;for(let o=1;o<e.length-1;o++){const c=e[o-1],f=e[o],m=e[o+1],d=Math.abs(f.x-c.x)+Math.abs(f.y-c.y),h=Math.abs(m.x-f.x)+Math.abs(m.y-f.y),b=Math.min(r,d/2,h/2);if(b>.5){const S=f.x-c.x,C=f.y-c.y,z=m.x-f.x,A=m.y-f.y,B=Math.sqrt(S*S+C*C)||1,D=Math.sqrt(z*z+A*A)||1;i+=` L ${f.x-S/B*b},${f.y-C/B*b}`,i+=` Q ${f.x},${f.y} ${f.x+z/D*b},${f.y+A/D*b}`}else i+=` L ${f.x},${f.y}`}return i+=` L ${e[e.length-1].x},${e[e.length-1].y}`,i}function zo(e){if(e.length===2)return`M ${e[0].x},${e[0].y} L ${e[1].x},${e[1].y}`;if(e.length===3)return`M ${e[0].x},${e[0].y} Q ${e[1].x},${e[1].y} ${e[2].x},${e[2].y}`;const t=.3;let n=`M ${e[0].x},${e[0].y}`;for(let r=0;r<e.length-1;r++){const i=e[r===0?0:r-1],o=e[r],c=e[r+1],f=e[r+2<e.length?r+2:e.length-1],m=o.x+(c.x-i.x)*t,d=o.y+(c.y-i.y)*t,h=c.x-(f.x-o.x)*t,b=c.y-(f.y-o.y)*t;n+=` C ${m},${d} ${h},${b} ${c.x},${c.y}`}return n}function Nn(e){if(!e||e.length<2)return{x:0,y:0};let t=0;for(let r=1;r<e.length;r++)t+=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);let n=t/2;for(let r=1;r<e.length;r++){const i=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);if(n<=i){const o=i>0?n/i:0;return{x:e[r-1].x+(e[r].x-e[r-1].x)*o,y:e[r-1].y+(e[r].y-e[r-1].y)*o}}n-=i}return{x:e[0].x,y:e[0].y}}function No(e,t){if(!e||!t||e.length===0||t.length===0)return t;const n={};for(const o of e)n[o.id]=o;const r=or(e,null),i=t.map(o=>{var P,q,U,_;const c=o.type||"default";if(c==="bezier"||c==="simplebezier"||c==="default")return o;const f=n[o.source],m=n[o.target];if(!f||!m||f.hidden||m.hidden)return o;const d=yr(f,"source",o.sourceHandle),h=yr(m,"target",o.targetHandle),b=Sn(d,En),S=Sn(h,En),C=5,z=r.filter(w=>w.id!==o.source&&w.id!==o.target),A=f._absolutePosition||f.position,B=f.width||((P=f.measured)==null?void 0:P.width)||kn,D=f.height||((q=f.measured)==null?void 0:q.height)||Cn;z.push({id:o.source,x:A.x-C,y:A.y-C,w:B+2*C,h:D+2*C});const X=m._absolutePosition||m.position,H=m.width||((U=m.measured)==null?void 0:U.width)||kn,Y=m.height||((_=m.measured)==null?void 0:_.height)||Cn;if(z.push({id:o.target,x:X.x-C,y:X.y-C,w:H+2*C,h:Y+2*C}),z.length===0)return o;const j=Br(b,S,z);return j&&j.length>=2?(j.unshift({x:d.x,y:d.y}),j.push({x:h.x,y:h.y}),{...o,_routedPoints:j}):o});return So(i)}function Po(e,t,n,r,i,o,c,f){const m=or(c,f?new Set(f):null);if(m.length===0)return null;const d={x:e,y:t,dir:i||"right"},h={x:n,y:r,dir:o||"left"},b=Sn(d,En),S=Sn(h,En),C=Br(b,S,m);return C&&C.length>=2?(C.unshift({x:d.x,y:d.y}),C.push({x:h.x,y:h.y}),C):null}const sr=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,label:c,labelStyle:f,labelShowBg:m,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:b,style:S,markerEnd:C,markerStart:z,interactionWidth:A,routedPoints:B}){let D,X,H;if(B&&B.length>=2){D=zn(B);const Y=Nn(B);X=Y.x,H=Y.y}else[D,X,H]=tr({sourceX:n,sourceY:r,targetX:i,targetY:o});return T.jsx(sn,{id:t,path:D,labelX:X,labelY:H,label:c,labelStyle:f,labelShowBg:m,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:b,style:S,markerEnd:C,markerStart:z,interactionWidth:A})});sr.displayName="StraightEdge";const ir=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:c="bottom",targetPosition:f="top",label:m,labelStyle:d,labelShowBg:h,labelBgStyle:b,labelBgPadding:S,labelBgBorderRadius:C,style:z,markerEnd:A,markerStart:B,pathOptions:D,interactionWidth:X,routedPoints:H}){let Y,j,P;if(H&&H.length>=2){Y=zn(H);const q=Nn(H);j=q.x,P=q.y}else[Y,j,P]=Rn({sourceX:n,sourceY:r,sourcePosition:c,targetX:i,targetY:o,targetPosition:f,borderRadius:D==null?void 0:D.borderRadius,offset:D==null?void 0:D.offset});return T.jsx(sn,{id:t,path:Y,labelX:j,labelY:P,label:m,labelStyle:d,labelShowBg:h,labelBgStyle:b,labelBgPadding:S,labelBgBorderRadius:C,style:z,markerEnd:A,markerStart:B,interactionWidth:X})});ir.displayName="SmoothStepEdge";const $r=a.memo(function({id:t,...n}){var i;const r=a.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(i=n.pathOptions)==null?void 0:i.offset]);return T.jsx(ir,{...n,id:t,pathOptions:r})});$r.displayName="StepEdge";const ar=a.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:c,targetPosition:f,label:m,labelStyle:d,labelShowBg:h,labelBgStyle:b,labelBgPadding:S,labelBgBorderRadius:C,style:z,markerEnd:A,markerStart:B,interactionWidth:D,routedPoints:X}){let H,Y,j;if(X&&X.length>=2){H=zn(X);const P=Nn(X);Y=P.x,j=P.y}else[H,Y,j]=rr({sourceX:n,sourceY:r,targetX:i,targetY:o});return T.jsx(sn,{id:t,path:H,labelX:Y,labelY:j,label:m,labelStyle:d,labelShowBg:h,labelBgStyle:b,labelBgPadding:S,labelBgBorderRadius:C,style:z,markerEnd:A,markerStart:B,interactionWidth:D})});ar.displayName="SimpleBezierEdge";const Io={input:Nr,output:Pr,group:Ir},To={bezier:er,straight:sr,simplebezier:ar},Lo=160,Bo=60;function $o(e){let t=!1;for(let n=0;n<e.length;n++){const r=e[n];if(!r.measured||r.measured.width==null||r.measured.height==null){t=!0;break}}return t?e.map(n=>{var r,i;return((r=n.measured)==null?void 0:r.width)!=null&&((i=n.measured)==null?void 0:i.height)!=null?n:{...n,measured:{width:n.width||Lo,height:n.height||Bo}}}):e}function jo({cards:e,nodes:t=[],edges:n=[],nodeTypes:r,edgeTypes:i,canvasNodeTypes:o,domNodeLimit:c=50,dark:f,gridSize:m,width:d="100%",height:h="420px",className:b="",style:S={},zoomMin:C,zoomMax:z,initialCamera:A,fitView:B,fitViewOptions:D,onNodesChange:X,onEdgesChange:H,onConnect:Y,onConnectStart:j,onConnectEnd:P,onNodeClick:q,onNodeDoubleClick:U,onNodeMouseEnter:_,onNodeMouseMove:w,onNodeMouseLeave:g,onNodeContextMenu:v,onNodeDragStart:N,onNodeDrag:I,onNodeDragStop:$,onEdgeClick:K,onEdgeDoubleClick:se,onEdgeMouseEnter:te,onEdgeMouseMove:ce,onEdgeMouseLeave:pe,onEdgeContextMenu:me,onPaneClick:ye,onPaneContextMenu:ue,onPaneMouseEnter:Ce,onPaneMouseMove:re,onPaneMouseLeave:de,onSelectionChange:Le,onInit:Ye,onMoveStart:xe,onMove:he,onMoveEnd:$e,onDelete:He,onBeforeDelete:ze,onError:Ve,onDragOver:tt,onDrop:Me,onDragEnter:Te,onDragLeave:Xe,nodesDraggable:je,nodesConnectable:_e,elementsSelectable:qe,multiSelectionKeyCode:kt,selectionOnDrag:an,selectionMode:Ct,connectionMode:cn,connectionRadius:un,connectOnClick:ln,isValidConnection:dn,defaultEdgeOptions:Xt,snapToGrid:ht,snapGrid:gt,deleteKeyCode:Et,panActivationKeyCode:Pn,panOnScroll:In,panOnScrollMode:nt,panOnScrollSpeed:cr,zoomOnScroll:Tn,zoomOnDoubleClick:Ln,zoomOnPinch:St,preventScrolling:zt,translateExtent:Bn,nodeExtent:$n,autoPanOnNodeDrag:jn,autoPanOnConnect:bt,autoPanSpeed:we,edgesReconnectable:Nt,elevateNodesOnSelect:Ne,elevateEdgesOnSelect:fe,noDragClassName:yt,noPanClassName:ee,onSelectionDragStart:Pe,onSelectionDrag:fn,onSelectionDragStop:Pt,edgeRouting:It=!0,onHudUpdate:Tt,onNodesProcessed:An,showHud:We=!0,showHint:Ue=!0,hintText:Lt="Drag to pan · Scroll to zoom",children:rt,...hn}){const[Je,gn]=a.useState({wx:0,wy:0,zoom:"1.00"}),yn=a.useRef(null),Ut=a.useRef(null),xn=a.useCallback(F=>{gn(F),Tt==null||Tt(F)},[Tt]),xt=a.useMemo(()=>({...Io,...r}),[r]),ot=a.useMemo(()=>({...To,...i}),[i]),Ke=a.useMemo(()=>$o(t),[t]),[J,st]=a.useState(()=>new Set),wt=a.useRef(J);wt.current=J;const Bt=a.useCallback(F=>{st(ve=>{const ne=new Set(ve);return ne.add(F),ne})},[]),$t=a.useCallback(F=>{st(ve=>{const ne=new Set(ve);return ne.delete(F),ne})},[]),jt=a.useCallback(F=>{st(ve=>{const ne=new Set(ve);return ne.has(F)?ne.delete(F):ne.add(F),ne})},[]),pt=a.useMemo(()=>Ke.filter(F=>F.type&&xt[F.type]),[Ke,xt]),At=a.useMemo(()=>n.filter(F=>F.type&&ot[F.type]),[n,ot]),[Dt,Ht]=a.useState(()=>new Set),_t=a.useRef(new Set),Ee=a.useMemo(()=>{const F=new Set(Dt);for(const ne of J)F.add(ne);for(const ne of pt)(ne.selected||ne.dragging)&&F.add(ne.id);const ve=_t.current;if(ve.size===F.size){let ne=!0;for(const Se of F)if(!ve.has(Se)){ne=!1;break}if(ne)return ve}return _t.current=F,F},[pt,J,Dt]),lt=a.useMemo(()=>{if(c===0)return[];const F=Ke.filter(ve=>Ee.has(ve.id));return F.sort((ve,ne)=>{const Se=ve.type==="group"||!ve.parentId&&F.some(y=>y.parentId===ve.id),l=ne.type==="group"||!ne.parentId&&F.some(y=>y.parentId===ne.id);return Se&&!l?-1:!Se&&l?1:0})},[Ke,Ee,c]),De=a.useMemo(()=>t.map(F=>Ee.has(F.id)?{...F,_customRendered:!0}:F),[t,Ee]),Dn=a.useMemo(()=>n.map(F=>F.type&&ot[F.type]?{...F,_customRendered:!0}:F),[n,ot]),{wrapRef:dt,canvasRef:Wt,canvasReady:it,onPointerDown:mt,onPointerMove:pn,onPointerUp:Be,store:le}=Mr({cards:e,nodes:De,edges:Dn,dark:f,gridSize:m,zoomMin:C,zoomMax:z,initialCamera:A,fitView:B,fitViewOptions:D,onHudUpdate:xn,onNodesProcessed:An,onNodesChange:X,onEdgesChange:H,onConnect:Y,onConnectStart:j,onConnectEnd:P,onNodeClick:q,onNodeDoubleClick:U,onNodeMouseEnter:_,onNodeMouseMove:w,onNodeMouseLeave:g,onNodeContextMenu:v,onNodeDragStart:N,onNodeDrag:I,onNodeDragStop:$,onEdgeClick:K,onEdgeDoubleClick:se,onEdgeMouseEnter:te,onEdgeMouseMove:ce,onEdgeMouseLeave:pe,onEdgeContextMenu:me,onPaneClick:ye,onPaneContextMenu:ue,onPaneMouseEnter:Ce,onPaneMouseMove:re,onPaneMouseLeave:de,onSelectionChange:Le,onInit:Ye,onMoveStart:xe,onMove:he,onMoveEnd:$e,onDelete:He,onBeforeDelete:ze,onError:Ve,nodesDraggable:je,nodesConnectable:_e,elementsSelectable:qe,multiSelectionKeyCode:kt,selectionOnDrag:an,selectionMode:Ct,connectionMode:cn,connectionRadius:un,connectOnClick:ln,isValidConnection:dn,defaultEdgeOptions:Xt,snapToGrid:ht,snapGrid:gt,deleteKeyCode:Et,panActivationKeyCode:Pn,panOnScroll:In,panOnScrollMode:nt,panOnScrollSpeed:cr,zoomOnScroll:Tn,zoomOnDoubleClick:Ln,zoomOnPinch:St,preventScrolling:zt,translateExtent:Bn,nodeExtent:$n,autoPanOnNodeDrag:jn,autoPanOnConnect:bt,autoPanSpeed:we,edgesReconnectable:Nt,elevateNodesOnSelect:Ne,elevateEdgesOnSelect:fe,noDragClassName:yt,noPanClassName:ee,onSelectionDragStart:Pe,onSelectionDrag:fn,onSelectionDragStop:Pt,edgeRouting:It}),Ot=a.useRef(pt);Ot.current=pt;const qt=a.useRef(c);qt.current=c,a.useEffect(()=>{let F;const ve=()=>{const Se=Ot.current,l=qt.current;if(l===0||!Se.length)return;const y=le.cameraRef.current,u=le.wrapRef.current;if(!u)return;const p=u.clientWidth,k=u.clientHeight,E=(-y.x+p/2)/y.zoom,x=(-y.y+k/2)/y.zoom,M=wt.current;let R=M.size;for(const L of Se)(L.selected||L.dragging)&&R++;const W=Math.max(0,l-R);if(W===0)Ht(L=>L.size===0?L:new Set);else{const L=new Set(M);for(const Z of Se)(Z.selected||Z.dragging)&&L.add(Z.id);const O=[];for(let Z=0;Z<Se.length;Z++){const ie=Se[Z];if(L.has(ie.id))continue;const V=ie._absolutePosition||ie.position,ae=V.x+(ie.width||160)/2-E,ke=V.y+(ie.height||60)/2-x;O.push({id:ie.id,dist:ae*ae+ke*ke})}O.sort((Z,ie)=>Z.dist-ie.dist);const G=new Set;for(let Z=0;Z<Math.min(W,O.length);Z++)G.add(O[Z].id);Ht(Z=>{if(Z.size!==G.size)return G;for(const ie of G)if(!Z.has(ie))return G;return Z})}},ne=setTimeout(ve,100);return F=setInterval(ve,500),()=>{clearTimeout(ne),clearInterval(F)}},[le.cameraRef,le.wrapRef]);const vt=a.useRef(new Set);a.useEffect(()=>{if(!o||!le.workerRef.current)return;let F=!1;async function ve(Se){const l=new Blob([Se],{type:"image/svg+xml"}),y=URL.createObjectURL(l),u=new Image;return u.src=y,await u.decode(),URL.revokeObjectURL(y),createImageBitmap(u)}async function ne(){var p,k,E;const Se={},l=[],y={},u={};for(const[x,M]of Object.entries(o)){if(typeof M=="function"){y[x]=M;continue}if(typeof M=="object"&&M!==null&&!(M instanceof ImageBitmap)&&!(M instanceof HTMLImageElement)&&!(M instanceof HTMLCanvasElement)&&("fill"in M||"stroke"in M||"title"in M||"accent"in M)){u[x]=M;continue}try{let R;M instanceof ImageBitmap?R=M:typeof M=="string"?R=await ve(M):M instanceof HTMLImageElement?R=await createImageBitmap(M):M instanceof HTMLCanvasElement&&(R=await createImageBitmap(M)),R&&!F&&(Se[x]=R,l.push(R))}catch(R){console.warn(`[InfiniteCanvas] Failed to convert canvasNodeType "${x}":`,R)}}if(!F&&Object.keys(Se).length>0&&((p=le.workerRef.current)==null||p.postMessage({type:"nodeTypeBitmaps",data:{bitmaps:Se}},l)),!F&&Object.keys(u).length>0&&((k=le.workerRef.current)==null||k.postMessage({type:"nodeTypeConfigs",data:{configs:u}})),!F&&Object.keys(y).length>0){const x=new Map,M={},R={},W=[];let L=vt.current.size;for(const O of t){const G=y[O.type];if(G)try{const Z=G(O.data);if(!Z)continue;let ie=x.get(Z);if(!ie&&(ie="bmp_"+L++,x.set(Z,ie),!vt.current.has(Z))){const V=await ve(Z);if(F)return;M[ie]=V,W.push(V),vt.current.add(Z)}R[O.id]=ie}catch(Z){console.warn(`[InfiniteCanvas] canvasNodeType fn error for node "${O.id}":`,Z)}}F||(E=le.workerRef.current)==null||E.postMessage({type:"nodeBitmaps",data:{cache:M,keys:R}},W)}}return ne(),()=>{F=!0}},[o,t,le.workerRef]);const Ze=a.useContext(Rt),Zt=Ze&&typeof Ze.getState=="function";a.useEffect(()=>{Zt&&queueMicrotask(()=>{Ze.setState({nodes:Ke,edges:n,nodesRef:le.nodesRef,edgesRef:le.edgesRef,onNodesChangeRef:le.onNodesChangeRef,onEdgesChangeRef:le.onEdgesChangeRef,cameraRef:le.cameraRef,wrapRef:le.wrapRef,workerRef:le.workerRef})})},[Zt,Ke,n,le,Ze]);const Re=a.useMemo(()=>({...le,edgeLabelContainerRef:yn,viewportPortalRef:Ut,pinNode:Bt,unpinNode:$t,togglePinNode:jt,get pinnedNodeIds(){return wt.current},get nodes(){return Ke},get edges(){return n},get viewport(){return le.cameraRef.current},get minZoom(){return le.zoomMin||.1},get maxZoom(){return le.zoomMax||5},get domNode(){return le.wrapRef.current},get width(){var F;return((F=le.wrapRef.current)==null?void 0:F.clientWidth)||0},get height(){var F;return((F=le.wrapRef.current)==null?void 0:F.clientHeight)||0}}),[le,Ke,n,Bt,$t,jt]),at=a.useRef(null),ct=a.useRef(null),Gt=a.useRef(null),Qt=a.useRef(null),mn=a.useRef(null);a.useEffect(()=>{let F;const ve=()=>{const ne=le.cameraRef.current,Se=`translate(${ne.x}px, ${ne.y}px) scale(${ne.zoom})`,l=`translate(${ne.x}, ${ne.y}) scale(${ne.zoom})`;at.current&&(at.current.style.transform=Se),ct.current&&ct.current.setAttribute("transform",l),Gt.current&&(Gt.current.style.transform=Se),Qt.current&&(Qt.current.style.transform=Se);const y=dt.current;if(y){const u=ne.zoom<.15?"lod-minimal":ne.zoom<.35?"lod-reduced":null;u!==mn.current&&(y.classList.remove("lod-minimal","lod-reduced"),u&&y.classList.add(u),mn.current=u)}F=requestAnimationFrame(ve)};return F=requestAnimationFrame(ve),()=>cancelAnimationFrame(F)},[le]);const[Ft,Hn]=a.useState(null);a.useEffect(()=>{if(!lt.length)return;let F;const ve=()=>{var M,R;const ne=le.cameraRef.current,Se=le.wrapRef.current;if(!Se){F=requestAnimationFrame(ve);return}const l=Se.getBoundingClientRect(),y=200,u=-ne.x/ne.zoom-y,p=-ne.y/ne.zoom-y,k=(l.width-ne.x)/ne.zoom+y,E=(l.height-ne.y)/ne.zoom+y,x=new Set;for(const W of lt){const L=W._absolutePosition||W.position,O=W.width||((M=W.measured)==null?void 0:M.width)||200,G=W.height||((R=W.measured)==null?void 0:R.height)||100;L.x+O>=u&&L.x<=k&&L.y+G>=p&&L.y<=E&&x.add(W.id)}Hn(W=>{if(!W||W.size!==x.size)return x;for(const L of x)if(!W.has(L))return x;return W}),F=requestAnimationFrame(ve)};return F=requestAnimationFrame(ve),()=>cancelAnimationFrame(F)},[lt,le]);const _n=a.useMemo(()=>Ft?lt.filter(F=>Ft.has(F.id)):lt,[lt,Ft]),Wn=lt.length>0,Fn=At.length>0;return T.jsx(Rt.Provider,{value:Re,children:T.jsxs("div",{ref:dt,className:`ric-wrap ${b}`,style:{width:d,height:h,...S},onPointerDown:mt,onPointerMove:pn,onPointerUp:Be,onDragOver:tt,onDrop:Me,onDragEnter:Te,onDragLeave:Xe,tabIndex:0,children:[T.jsx("canvas",{ref:Wt,className:"ric-canvas"}),!it&&T.jsx("div",{className:"ric-loader",children:T.jsx("div",{className:"ric-spinner"})}),Fn&&T.jsx("svg",{className:"ric-edges-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:T.jsx("g",{ref:ct,children:At.map(F=>T.jsx(yo,{edge:F,edgeType:ot[F.type],nodes:t,reconnectable:Nt},F.id))})}),Wn&&T.jsx("div",{ref:at,className:"ric-nodes-overlay",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:10},children:_n.map(F=>T.jsx(lo,{node:F,nodeType:xt[F.type]},F.id))}),T.jsx("div",{ref:F=>{yn.current=F,Gt.current=F},className:"ric-edge-labels",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:5}}),T.jsx("div",{ref:F=>{Ut.current=F,Qt.current=F},className:"ric-viewport-portal",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:6}}),Ue&&T.jsx("div",{className:"ric-hint",children:Lt}),We&&T.jsxs("div",{className:"ric-info",children:["world: (",Je.wx,", ",Je.wy,") zoom: ",Je.zoom,"x",Je.nodeCount>0&&T.jsxs(T.Fragment,{children:[" nodes: ",Je.nodeCount]}),Je.edgeCount>0&&T.jsxs(T.Fragment,{children:[" edges: ",Je.edgeCount]})]}),T.jsx(Sr,{selectionKeyCode:kt||"Shift",selectionMode:Ct||"partial"}),rt]})})}function Ao({children:e}){const t=a.useRef(null);return t.current||(t.current=ao()),T.jsx(Rt.Provider,{value:t.current,children:e})}function jr(e,t){const n=[],r=new Map,i=[];for(const o of e)if(o.type==="add")i.push(o);else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const c=r.get(o.id);c?c.push(o):r.set(o.id,[o])}for(const o of t){const c=r.get(o.id);if(!c){n.push(o);continue}if(c[0].type==="remove")continue;if(c[0].type==="replace"){n.push({...c[0].item});continue}const f={...o};for(const m of c)Do(m,f);n.push(f)}for(const o of i)o.index!==void 0?n.splice(o.index,0,{...o.item}):n.push({...o.item});return n}function Do(e,t){switch(e.type){case"select":t.selected=e.selected;break;case"position":e.position!==void 0&&(t.position=e.position),e.dragging!==void 0&&(t.dragging=e.dragging);break;case"dimensions":e.dimensions!==void 0&&(t.measured={...e.dimensions},(e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height)),e.handleBounds!==void 0&&(t.handleBounds=e.handleBounds);break}}function Ar(e,t){return jr(e,t)}function Dr(e,t){return jr(e,t)}function Ho(e,t){return!e.source||!e.target?(console.warn("addEdge: source and target are required"),t):t.some(r=>r.source===e.source&&r.target===e.target&&(r.sourceHandle||null)===(e.sourceHandle||null)&&(r.targetHandle||null)===(e.targetHandle||null))?t:[...t,{id:e.id||`e-${e.source}-${e.target}`,...e}]}function _o(e){const[t,n]=a.useState(e),r=a.useCallback(i=>n(o=>Ar(i,o)),[]);return[t,n,r]}function Wo(e){const[t,n]=a.useState(e),r=a.useCallback(i=>n(o=>Dr(i,o)),[]);return[t,n,r]}function Hr(){const e=Rr(),t=a.useCallback(()=>typeof e.getState=="function"?e.getState():e,[e]),n=a.useCallback(()=>[...t().nodesRef.current],[t]),r=a.useCallback(()=>[...t().edgesRef.current],[t]),i=a.useCallback(w=>t().nodesRef.current.find(g=>g.id===w),[t]),o=a.useCallback(w=>t().edgesRef.current.find(g=>g.id===w),[t]),c=a.useCallback(w=>{var g,v,N,I;if(typeof w=="function"){const $=w(t().nodesRef.current);(v=(g=t().onNodesChangeRef).current)==null||v.call(g,[...t().nodesRef.current.map(K=>({id:K.id,type:"remove"})),...$.map(K=>({type:"add",item:K}))])}else(I=(N=t().onNodesChangeRef).current)==null||I.call(N,[...t().nodesRef.current.map($=>({id:$.id,type:"remove"})),...w.map($=>({type:"add",item:$}))])},[t]),f=a.useCallback(w=>{var g,v,N,I;if(typeof w=="function"){const $=w(t().edgesRef.current);(v=(g=t().onEdgesChangeRef).current)==null||v.call(g,[...t().edgesRef.current.map(K=>({id:K.id,type:"remove"})),...$.map(K=>({type:"add",item:K}))])}else(I=(N=t().onEdgesChangeRef).current)==null||I.call(N,[...t().edgesRef.current.map($=>({id:$.id,type:"remove"})),...w.map($=>({type:"add",item:$}))])},[t]),m=a.useCallback(w=>{var v,N;const g=Array.isArray(w)?w:[w];(N=(v=t().onNodesChangeRef).current)==null||N.call(v,g.map(I=>({type:"add",item:I})))},[t]),d=a.useCallback(w=>{var v,N;const g=Array.isArray(w)?w:[w];(N=(v=t().onEdgesChangeRef).current)==null||N.call(v,g.map(I=>({type:"add",item:I})))},[t]),h=a.useCallback(({nodes:w=[],edges:g=[]})=>{if(w.length&&t().onNodesChangeRef.current){t().onNodesChangeRef.current(w.map(N=>({id:N.id,type:"remove"})));const v=br(w,t().edgesRef.current);v.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(v.map(N=>({id:N.id,type:"remove"})))}g.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(g.map(v=>({id:v.id,type:"remove"})))},[t]),b=a.useCallback(()=>{const w=t().cameraRef.current;return{x:w.x,y:w.y,zoom:w.zoom}},[t]),S=a.useRef(null),C=a.useCallback((w,g)=>{if(S.current&&cancelAnimationFrame(S.current),!g||g<=0){t().cameraRef.current={...w},t().sendCamera();return}const v={...t().cameraRef.current},N=performance.now(),I=$=>{const K=$-N,se=Math.min(K/g,1),te=1-Math.pow(1-se,3);t().cameraRef.current={x:v.x+(w.x-v.x)*te,y:v.y+(w.y-v.y)*te,zoom:v.zoom+(w.zoom-v.zoom)*te},t().sendCamera(),se<1&&(S.current=requestAnimationFrame(I))};S.current=requestAnimationFrame(I)},[t]),z=a.useCallback((w,g)=>{const v={x:w.x??t().cameraRef.current.x,y:w.y??t().cameraRef.current.y,zoom:w.zoom??t().cameraRef.current.zoom};C(v,g==null?void 0:g.duration)},[t,C]),A=a.useCallback(()=>t().cameraRef.current.zoom,[t]),B=a.useCallback(w=>{const g=t().cameraRef.current,v=t().wrapRef.current;if(!v)return;const N=v.getBoundingClientRect(),I=N.width/2,$=N.height/2,K=1.2,se={x:I-(I-g.x)*K,y:$-($-g.y)*K,zoom:Math.min(t().zoomMax,g.zoom*K)};C(se,w==null?void 0:w.duration)},[t,C]),D=a.useCallback(w=>{const g=t().cameraRef.current,v=t().wrapRef.current;if(!v)return;const N=v.getBoundingClientRect(),I=N.width/2,$=N.height/2,K=1/1.2,se={x:I-(I-g.x)*K,y:$-($-g.y)*K,zoom:Math.max(t().zoomMin,g.zoom*K)};C(se,w==null?void 0:w.duration)},[t,C]),X=a.useCallback((w,g)=>{const v=t().cameraRef.current,N=t().wrapRef.current;if(!N)return;const I=N.getBoundingClientRect(),$=I.width/2,K=I.height/2,se=Math.min(t().zoomMax,Math.max(t().zoomMin,w)),te=se/v.zoom,ce={x:$-($-v.x)*te,y:K-(K-v.y)*te,zoom:se};C(ce,g==null?void 0:g.duration)},[t,C]),H=a.useCallback((w={})=>{const g=t().nodesRef.current;if(!g.length)return;const v=t().wrapRef.current;if(!v)return;const N=v.getBoundingClientRect(),I=w.padding??.1,$=w.nodes?g.filter(te=>w.nodes.some(ce=>ce.id===te.id)):g;if(!$.length)return;const K=Mn($),se=Yt(K,N.width,N.height,I);w.maxZoom&&(se.zoom=Math.min(se.zoom,w.maxZoom)),w.minZoom&&(se.zoom=Math.max(se.zoom,w.minZoom)),C(se,w.duration)},[t,C]),Y=a.useCallback((w,g={})=>{const v=t().wrapRef.current;if(!v)return;const N=v.getBoundingClientRect(),I=g.padding??.1,$=Yt(w,N.width,N.height,I);g.maxZoom&&($.zoom=Math.min($.zoom,g.maxZoom)),g.minZoom&&($.zoom=Math.max($.zoom,g.minZoom)),C($,g.duration)},[t,C]),j=a.useCallback((w,g,v={})=>{const N=t().wrapRef.current;if(!N)return;const I=N.getBoundingClientRect(),$=v.zoom??t().cameraRef.current.zoom,K={x:I.width/2-w*$,y:I.height/2-g*$,zoom:$};C(K,v.duration)},[t,C]),P=a.useCallback(()=>({nodes:[...t().nodesRef.current],edges:[...t().edgesRef.current],viewport:{...t().cameraRef.current}}),[t]),q=a.useCallback(w=>t().screenToWorld(w.x,w.y),[t]),U=a.useCallback(w=>{const g=t().cameraRef.current,v=t().wrapRef.current;if(!v)return{x:0,y:0};const N=v.getBoundingClientRect();return{x:w.x*g.zoom+g.x+N.left,y:w.y*g.zoom+g.y+N.top}},[t]),_=a.useCallback((w,g)=>{var I,$;const v=t().nodesRef.current.find(K=>K.id===w);if(!v)return;const N=typeof g=="function"?g(v.data):{...v.data,...g};($=(I=t().onNodesChangeRef).current)==null||$.call(I,[{id:w,type:"replace",item:{...v,data:N}}])},[t]);return{getNodes:n,getEdges:r,getNode:i,getEdge:o,setNodes:c,setEdges:f,addNodes:m,addEdges:d,deleteElements:h,getViewport:b,setViewport:z,getZoom:A,zoomIn:B,zoomOut:D,zoomTo:X,fitView:H,fitBounds:Y,setCenter:j,screenToFlowPosition:q,flowToScreenPosition:U,updateNodeData:_,toObject:P}}function Fo(){return Ie().nodes}function Yo(){return Ie().edges}function Xo(){return Ie().viewport}function Uo(){return Ie().connection}function Oo(e){const t=Ie(),n=Array.isArray(e)?e:[e];return a.useMemo(()=>n.map(r=>{const i=t.nodes.find(o=>o.id===r);return i?{id:i.id,type:i.type,data:i.data}:null}).filter(Boolean),[t.nodes,...n])}function qo(e){const t=Ie();return a.useMemo(()=>t.edges.filter(n=>n.source===e||n.target===e),[t.edges,e])}function Zo({nodeId:e,type:t,handleId:n}){const r=Ie();return a.useMemo(()=>r.edges.filter(i=>t==="source"?i.source===e&&(n?i.sourceHandle===n:!0):i.target===e&&(n?i.targetHandle===n:!0)),[r.edges,e,t,n])}function Go({onChange:e,onStart:t,onEnd:n}){const r=Ie(),i=a.useRef(e),o=a.useRef(t),c=a.useRef(n);a.useEffect(()=>{i.current=e},[e]),a.useEffect(()=>{o.current=t},[t]),a.useEffect(()=>{c.current=n},[n]),a.useEffect(()=>{const f=m=>{var d;(d=i.current)==null||d.call(i,{x:m.x,y:m.y,zoom:m.zoom})};return r.viewportListeners.add(f),()=>r.viewportListeners.delete(f)},[s])}function Qo({onChange:e}){const t=Ie(),n=a.useRef(e);a.useEffect(()=>{n.current=e},[e]),a.useEffect(()=>{const r=i=>{var o;(o=n.current)==null||o.call(n,i)};return t.selectionListeners.add(r),()=>t.selectionListeners.delete(r)},[s])}function Jo(e){const[t,n]=a.useState(!1),r=Array.isArray(e)?e:[e];return a.useEffect(()=>{const i=c=>{r.includes(c.key)&&n(!0)},o=c=>{r.includes(c.key)&&n(!1)};return window.addEventListener("keydown",i),window.addEventListener("keyup",o),()=>{window.removeEventListener("keydown",i),window.removeEventListener("keyup",o)}},[r.join(",")]),t}function Ko(){const e=Ie();return a.useCallback(t=>{var n;(n=e.workerRef.current)==null||n.postMessage({type:"nodes",data:{nodes:[...s().nodesRef.current]}})},[s])}const Vo=e=>{var t;return((t=e.nodes)==null?void 0:t.length)>0};function es(e={}){return Ie(Vo)}function ts(e){const t=Ie();return a.useMemo(()=>t.nodes.find(n=>n.id===e)||void 0,[t.nodes,e])}function ns(e,t){return Ie(e,t)}function rs(){return Rr()}function os({maxHistorySize:e=100}={}){const t=Ie(),n=a.useRef([]),r=a.useRef([]),[,i]=a.useState(0),o=a.useRef(null),c=a.useCallback(()=>{const d={nodes:s().nodesRef.current.map(h=>({...h,data:{...h.data}})),edges:s().edgesRef.current.map(h=>({...h}))};o.current&&JSON.stringify(o.current.nodes.map(h=>h.id))===JSON.stringify(d.nodes.map(h=>h.id))&&JSON.stringify(o.current.edges.map(h=>h.id))===JSON.stringify(d.edges.map(h=>h.id))||(n.current.push(d),n.current.length>e&&n.current.shift(),r.current=[],o.current=d,i(h=>h+1))},[t,e]),f=a.useCallback(()=>{var h,b,S,C;const d=n.current.pop();d&&(r.current.push({nodes:s().nodesRef.current.map(z=>({...z,data:{...z.data}})),edges:s().edgesRef.current.map(z=>({...z}))}),(b=(h=s().onNodesChangeRef).current)==null||b.call(h,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...d.nodes.map(z=>({type:"add",item:z}))]),(C=(S=s().onEdgesChangeRef).current)==null||C.call(S,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...d.edges.map(z=>({type:"add",item:z}))]),o.current=d,i(z=>z+1))},[s]),m=a.useCallback(()=>{var h,b,S,C;const d=r.current.pop();d&&(n.current.push({nodes:s().nodesRef.current.map(z=>({...z,data:{...z.data}})),edges:s().edgesRef.current.map(z=>({...z}))}),(b=(h=s().onNodesChangeRef).current)==null||b.call(h,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...d.nodes.map(z=>({type:"add",item:z}))]),(C=(S=s().onEdgesChangeRef).current)==null||C.call(S,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...d.edges.map(z=>({type:"add",item:z}))]),o.current=d,i(z=>z+1))},[s]);return{undo:f,redo:m,takeSnapshot:c,canUndo:n.current.length>0,canRedo:r.current.length>0}}function ss(e){const t=a.useRef(e);return a.useEffect(()=>{t.current=e},[e]),a.useCallback(n=>r=>{const i=t.current(r);i!==!1&&i!=null&&n(Array.isArray(i)?i:r)},[])}function is(e){const t=a.useRef(e);return a.useEffect(()=>{t.current=e},[e]),a.useCallback(n=>r=>{const i=t.current(r);i!==!1&&i!=null&&n(Array.isArray(i)?i:r)},[])}const On=160,qn=60;function as({width:e=200,height:t=150,nodeColor:n="#3b82f6",nodeStrokeColor:r="#fff",maskColor:i="rgba(0,0,0,0.1)",style:o={},className:c=""}){const f=Ie(),m=a.useRef(null),d=a.useRef(null),h=a.useCallback(()=>{const b=m.current;if(!b)return;const S=b.getContext("2d"),C=window.devicePixelRatio||1;b.width=e*C,b.height=t*C,S.scale(C,C),S.clearRect(0,0,e,t);const z=f.nodesRef.current;if(!z.length)return;let A=1/0,B=1/0,D=-1/0,X=-1/0;for(const g of z){const v=g.width||On,N=g.height||qn;g.position.x<A&&(A=g.position.x),g.position.y<B&&(B=g.position.y),g.position.x+v>D&&(D=g.position.x+v),g.position.y+N>X&&(X=g.position.y+N)}const H=40;A-=H,B-=H,D+=H,X+=H;const Y=D-A,j=X-B,P=Math.min(e/Y,t/j),q=(e-Y*P)/2,U=(t-j*P)/2;for(const g of z){if(g.hidden)continue;const v=g.width||On,N=g.height||qn,I=(g.position.x-A)*P+q,$=(g.position.y-B)*P+U,K=v*P,se=N*P;S.fillStyle=g.selected?"#f59e0b":typeof n=="function"?n(g):n,S.fillRect(I,$,Math.max(K,2),Math.max(se,2))}const _=f.cameraRef.current,w=f.wrapRef.current;if(w){const g=w.getBoundingClientRect(),v=-_.x/_.zoom,N=-_.y/_.zoom,I=g.width/_.zoom,$=g.height/_.zoom;S.fillStyle=i,S.fillRect(0,0,e,t);const K=(v-A)*P+q,se=(N-B)*P+U,te=I*P,ce=$*P;S.clearRect(K,se,te,ce);for(const pe of z){if(pe.hidden)continue;const me=pe.width||On,ye=pe.height||qn,ue=(pe.position.x-A)*P+q,Ce=(pe.position.y-B)*P+U;S.fillStyle=pe.selected?"#f59e0b":typeof n=="function"?n(pe):n,S.fillRect(ue,Ce,Math.max(me*P,2),Math.max(ye*P,2))}S.strokeStyle="#3b82f6",S.lineWidth=1.5,S.strokeRect(K,se,te,ce)}},[f,e,t,n,r,i]);return a.useEffect(()=>{let b=!0;function S(){b&&(h(),d.current=requestAnimationFrame(S))}const C=setInterval(()=>{cancelAnimationFrame(d.current),d.current=requestAnimationFrame(S)},66);return h(),()=>{b=!1,clearInterval(C),cancelAnimationFrame(d.current)}},[h]),T.jsx("canvas",{ref:m,className:`ric-minimap ${c}`,style:{position:"absolute",bottom:30,right:10,width:e,height:t,borderRadius:4,border:"1px solid rgba(0,0,0,0.1)",background:"rgba(255,255,255,0.9)",pointerEvents:"none",...o}})}function cs(){return T.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:[T.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),T.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function us(){return T.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:T.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function ls(){return T.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:T.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}function ds(){return T.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:[T.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),T.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function fs(){return T.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:[T.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),T.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})}function nn({children:e,className:t="",...n}){return T.jsx("button",{className:`ric-controls-button ${t}`,style:gs,...n,children:e})}function hs({showZoom:e=!0,showFitView:t=!0,showInteractive:n=!1,fitViewOptions:r,onZoomIn:i,onZoomOut:o,onFitView:c,onInteractiveChange:f,position:m="bottom-left",orientation:d="vertical",style:h={},className:b="","aria-label":S="Canvas controls",children:C}){const z=Ie(),{zoomIn:A,zoomOut:B,fitView:D,getZoom:X}=Hr(),[H,Y]=a.useState(!0),j=X()<=z.zoomMin,P=X()>=z.zoomMax,q=a.useCallback(()=>{A(),i==null||i()},[A,i]),U=a.useCallback(()=>{B(),o==null||o()},[B,o]),_=a.useCallback(()=>{D(r||{padding:.1}),c==null||c()},[D,r,c]),w=a.useCallback(()=>{const v=!H;Y(v),f==null||f(v)},[H,f]),g={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:30,left:10},"bottom-right":{bottom:30,right:10},"bottom-center":{bottom:30,left:"50%",transform:"translateX(-50%)"}}[m]||{bottom:30,left:10};return T.jsxs("div",{className:`ric-controls ${b}`,style:{position:"absolute",display:"flex",flexDirection:d==="horizontal"?"row":"column",gap:2,zIndex:5,...g,...h},role:"toolbar","aria-label":S,children:[e&&T.jsxs(T.Fragment,{children:[T.jsx(nn,{onClick:q,disabled:P,title:"Zoom in","aria-label":"Zoom in",className:"ric-controls-zoomin",children:T.jsx(cs,{})}),T.jsx(nn,{onClick:U,disabled:j,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:T.jsx(us,{})})]}),t&&T.jsx(nn,{onClick:_,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:T.jsx(ls,{})}),n&&T.jsx(nn,{onClick:w,title:H?"Lock interactivity":"Unlock interactivity","aria-label":H?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:H?T.jsx(fs,{}):T.jsx(ds,{})}),C]})}const gs={width:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid rgba(0,0,0,0.12)",borderRadius:4,background:"#fff",cursor:"pointer",fontSize:16,lineHeight:1,color:"#333",padding:0},ys=a.memo(hs);function xs({variant:e="lines",gap:t=40,size:n=1,color:r,style:i={},className:o=""}){const c=Ie();return c.workerRef.current&&c.workerRef.current.postMessage({type:"background",data:{variant:e,gap:t,size:n,color:r}}),null}function ps({position:e="top-left",style:t={},className:n="",children:r}){const i={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:10,left:10},"bottom-right":{bottom:10,right:10},"bottom-center":{bottom:10,left:"50%",transform:"translateX(-50%)"}}[e]||{top:10,left:10};return T.jsx("div",{className:`ric-panel ${n}`,style:{position:"absolute",zIndex:5,pointerEvents:"all",...i,...t},onPointerDown:o=>o.stopPropagation(),children:r})}function ms({minWidth:e=10,minHeight:t=10,maxWidth:n=1/0,maxHeight:r=1/0,isVisible:i=!0,handleStyle:o={},lineStyle:c={},color:f="#3b82f6",onResizeStart:m,onResize:d,onResizeEnd:h}){const b=a.useContext(on),S=Ie(),C=a.useRef(null),z=a.useCallback((D,X)=>{D.stopPropagation(),D.preventDefault();const H=S.nodesRef.current.find(P=>P.id===b);if(!H)return;C.current={direction:X,startX:D.clientX,startY:D.clientY,width:H.width||160,height:H.height||60},m==null||m(D,{width:C.current.width,height:C.current.height});const Y=P=>{var N,I;if(!C.current)return;const q=C.current,U=S.cameraRef.current,_=(P.clientX-q.startX)/U.zoom,w=(P.clientY-q.startY)/U.zoom;let g=q.width,v=q.height;q.direction.includes("e")&&(g=Math.min(n,Math.max(e,q.width+_))),q.direction.includes("w")&&(g=Math.min(n,Math.max(e,q.width-_))),q.direction.includes("s")&&(v=Math.min(r,Math.max(t,q.height+w))),q.direction.includes("n")&&(v=Math.min(r,Math.max(t,q.height-w))),(I=(N=S.onNodesChangeRef).current)==null||I.call(N,[{id:b,type:"dimensions",dimensions:{width:g,height:v},setAttributes:!0}]),d==null||d(P,{width:g,height:v})},j=P=>{C.current=null,h==null||h(P,{}),window.removeEventListener("pointermove",Y),window.removeEventListener("pointerup",j)};window.addEventListener("pointermove",Y),window.addEventListener("pointerup",j)},[b,S,e,t,n,r,m,d,h]);if(!i)return null;const A=8,B={position:"absolute",width:A,height:A,background:f,border:"1px solid #fff",borderRadius:2,zIndex:20,...o};return T.jsxs(T.Fragment,{children:[T.jsx("div",{style:{...B,bottom:-A/2,right:-A/2,cursor:"nwse-resize"},onPointerDown:D=>z(D,"se")}),T.jsx("div",{style:{...B,bottom:-A/2,left:-A/2,cursor:"nesw-resize"},onPointerDown:D=>z(D,"sw")}),T.jsx("div",{style:{...B,top:-A/2,right:-A/2,cursor:"nesw-resize"},onPointerDown:D=>z(D,"ne")}),T.jsx("div",{style:{...B,top:-A/2,left:-A/2,cursor:"nwse-resize"},onPointerDown:D=>z(D,"nw")}),T.jsx("div",{style:{...B,top:"50%",right:-A/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:D=>z(D,"e")}),T.jsx("div",{style:{...B,top:"50%",left:-A/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:D=>z(D,"w")}),T.jsx("div",{style:{...B,left:"50%",top:-A/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:D=>z(D,"n")}),T.jsx("div",{style:{...B,left:"50%",bottom:-A/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:D=>z(D,"s")})]})}function vs({isVisible:e,position:t="top",offset:n=10,align:r="center",children:i,style:o={},className:c=""}){const f=a.useContext(on),d=Ie().nodes.find(S=>S.id===f);if(!(e!==void 0?e:d==null?void 0:d.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}}[t]||{};return T.jsx("div",{className:`ric-node-toolbar ${c}`,style:{position:"absolute",zIndex:1e3,pointerEvents:"all",...b,...o},onPointerDown:S=>S.stopPropagation(),children:i})}function bs({isVisible:e=!1,x:t=0,y:n=0,alignX:r="center",alignY:i="center",children:o,style:c={},className:f=""}){if(!e)return null;const m=r==="center"?"-50%":r==="right"?"-100%":"0",d=i==="center"?"-50%":i==="bottom"?"-100%":"0";return T.jsx("div",{className:`ric-edge-toolbar ${f}`,style:{position:"absolute",left:t,top:n,transform:`translate(${m}, ${d})`,zIndex:1e3,pointerEvents:"all",...c},children:o})}function ws({children:e}){var r;const n=(r=Ie().edgeLabelContainerRef)==null?void 0:r.current;return n?pr.createPortal(e,n):null}function Ms({children:e}){var r;const n=(r=Ie().viewportPortalRef)==null?void 0:r.current;return n?pr.createPortal(e,n):null}function _r({fromX:e,fromY:t,toX:n,toY:r,fromPosition:i="right",toPosition:o="left",connectionLineType:c="default",connectionLineStyle:f,connectionLineComponent:m}){if(m)return T.jsx(m,{fromX:e,fromY:t,toX:n,toY:r,fromPosition:i,toPosition:o});let d;switch(c){case"straight":[d]=tr({sourceX:e,sourceY:t,targetX:n,targetY:r});break;case"step":[d]=Rn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o,borderRadius:0});break;case"smoothstep":[d]=Rn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o});break;case"simplebezier":[d]=rr({sourceX:e,sourceY:t,targetX:n,targetY:r});break;default:[d]=nr({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o});break}return T.jsx("path",{d,fill:"none",className:"ric-connection-line",stroke:"#b1b1b7",strokeWidth:1.5,style:f})}_r.displayName="ConnectionLine";const Rs=a.memo(_r),ks=Object.freeze({Top:"top",Bottom:"bottom",Left:"left",Right:"right"}),Cs=Object.freeze({Arrow:"arrow",ArrowClosed:"arrowclosed"});function Es(e){const t=e.width||e.measured&&e.measured.width||0,n=e.height||e.measured&&e.measured.height||0,r=e._absolutePosition||e.position||{x:0,y:0};return{x:r.x,y:r.y,x2:r.x+t,y2:r.y+n}}exports.Background=xs;exports.BaseEdge=sn;exports.BezierEdge=er;exports.ConnectionLine=Rs;exports.ControlButton=nn;exports.Controls=ys;exports.DefaultNode=vo;exports.EdgeLabelRenderer=ws;exports.EdgeText=Lr;exports.EdgeToolbar=bs;exports.GroupNode=Ir;exports.Handle=rn;exports.InfiniteCanvas=jo;exports.InfiniteCanvasProvider=Ao;exports.InputNode=Nr;exports.MarkerType=Cs;exports.MiniMap=as;exports.NodeResizer=ms;exports.NodeToolbar=vs;exports.OutputNode=Pr;exports.Panel=ps;exports.Position=ks;exports.SelectionBox=Sr;exports.SimpleBezierEdge=ar;exports.SmoothStepEdge=ir;exports.StepEdge=$r;exports.StraightEdge=sr;exports.ViewportPortal=Ms;exports.addEdge=Ho;exports.applyEdgeChanges=Dr;exports.applyNodeChanges=Ar;exports.boxToRect=Qr;exports.buildObstacles=or;exports.clampPosition=Gn;exports.computeRoutedEdges=No;exports.getBezierEdgeCenter=bo;exports.getBezierPath=nr;exports.getBoundsOfBoxes=Jr;exports.getConnectedEdges=br;exports.getEdgeCenter=wo;exports.getIncomers=Or;exports.getNodeDimensions=Vn;exports.getNodesBounds=Mn;exports.getNodesInside=Zr;exports.getOutgoers=qr;exports.getOverlappingArea=Kr;exports.getRoutedLabelPosition=Nn;exports.getSimpleBezierPath=rr;exports.getSmoothStepPath=Rn;exports.getStraightPath=tr;exports.getViewportForBounds=Yt;exports.isEdge=Ur;exports.isNode=Xr;exports.nodeToBox=Es;exports.nodeToRect=Vr;exports.reconnectEdge=Mo;exports.rectToBox=Gr;exports.routeSinglePath=Po;exports.routedPointsToPath=zn;exports.snapPosition=Zn;exports.useConnection=Uo;exports.useEdges=Yo;exports.useEdgesState=Wo;exports.useHandleConnections=Zo;exports.useInfiniteCanvas=Mr;exports.useInternalNode=ts;exports.useKeyPress=Jo;exports.useNodeConnections=qo;exports.useNodeId=co;exports.useNodes=Fo;exports.useNodesData=Oo;exports.useNodesInitialized=es;exports.useNodesState=_o;exports.useOnEdgesChangeMiddleware=is;exports.useOnNodesChangeMiddleware=ss;exports.useOnSelectionChange=Qo;exports.useOnViewportChange=Go;exports.useReactFlow=Hr;exports.useStore=ns;exports.useStoreApi=rs;exports.useUndoRedo=os;exports.useUpdateNodeInternals=Ko;exports.useViewport=Xo;
|