@infinit-canvas/react 0.1.22 → 0.1.23
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 +601 -597
- package/dist/react-infinite-canvas.js +796 -792
- package/package.json +1 -1
|
@@ -1,70 +1,70 @@
|
|
|
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
|
|
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 Or(e){return e&&typeof e=="object"&&"source"in e&&"target"in e}function br(e,t){const n=typeof e=="string"?new Set([e]):new Set(Array.isArray(e)?e.map(r=>r.id):[e.id]);return t.filter(r=>n.has(r.source)||n.has(r.target))}function Ur(e,t,n){const r=typeof e=="string"?e:e.id,i=new Set;for(const o of n)o.target===r&&i.add(o.source);return t.filter(o=>i.has(o.id))}function qr(e,t,n){const r=typeof e=="string"?e:e.id,i=new Set;for(const o of n)o.source===r&&i.add(o.target);return t.filter(o=>i.has(o.id))}function Mn(e){if(!e.length)return{x:0,y:0,width:0,height:0};let t=1/0,n=1/0,r=-1/0,i=-1/0;for(const o of e){const 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 Kn(e){var t,n;return{width:e.width||((t=e.measured)==null?void 0:t.width)||mr,height:e.height||((n=e.measured)==null?void 0:n.height)||vr}}function Zr(e,t,n={x:0,y:0,zoom:1},r=!1){const i=t.x,o=t.y,c=t.x+t.width,f=t.y+t.height;return e.filter(m=>{const{width:d,height:h}=Kn(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 Vr(e,t){const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return n*r}function Kr(e){const{width:t,height:n}=Kn(e);return{x:e.position.x,y:e.position.y,width:t,height:n}}const wr=`var qa = null, r = null, fr = 0, vr = 0, M = { x: 0, y: 0, zoom: 1 }, Y = [], W = [], C = [], F = !1, Ze = 40, We = !1, Nr = "lines", da = 1, Kt = null, lt = null, Tr = null, It = {}, tl = {}, it = {}, Zt = {}, Ia = 0, L = 160, B = 60, Ga = 8, Do = 5;
|
|
2
2
|
function y(a) {
|
|
3
3
|
return a._absolutePosition || a.position;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
5
|
+
function cl(a, t, e, l, i) {
|
|
6
6
|
if (a.x !== void 0 && a.y !== void 0)
|
|
7
|
-
return { x:
|
|
7
|
+
return { x: t + a.x, y: e + a.y };
|
|
8
8
|
var o = a.position || (a.type === "source" ? "right" : "left");
|
|
9
9
|
switch (o) {
|
|
10
10
|
case "top":
|
|
11
|
-
return { x:
|
|
11
|
+
return { x: t + l / 2, y: e };
|
|
12
12
|
case "bottom":
|
|
13
|
-
return { x:
|
|
13
|
+
return { x: t + l / 2, y: e + i };
|
|
14
14
|
case "left":
|
|
15
|
-
return { x:
|
|
15
|
+
return { x: t, y: e + i / 2 };
|
|
16
16
|
case "right":
|
|
17
|
-
return { x:
|
|
17
|
+
return { x: t + l, y: e + i / 2 };
|
|
18
18
|
default:
|
|
19
|
-
return { x:
|
|
19
|
+
return { x: t + l, y: e + i / 2 };
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
function
|
|
23
|
-
var
|
|
22
|
+
function el(a) {
|
|
23
|
+
var t = a.width || L, e = 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(n) {
|
|
26
|
+
var g = cl(n, y(a).x, y(a).y, t, e);
|
|
27
|
+
return { id: n.id || null, type: n.type, x: g.x, y: g.y, position: n.position };
|
|
28
28
|
});
|
|
29
|
-
var
|
|
30
|
-
function f(
|
|
31
|
-
switch (
|
|
29
|
+
var l = a.targetPosition || "left", i = a.sourcePosition || "right", o = y(a);
|
|
30
|
+
function f(n) {
|
|
31
|
+
switch (n) {
|
|
32
32
|
case "top":
|
|
33
|
-
return { x: o.x +
|
|
33
|
+
return { x: o.x + t / 2, y: o.y };
|
|
34
34
|
case "bottom":
|
|
35
|
-
return { x: o.x +
|
|
35
|
+
return { x: o.x + t / 2, y: o.y + e };
|
|
36
36
|
case "left":
|
|
37
|
-
return { x: o.x, y: o.y +
|
|
37
|
+
return { x: o.x, y: o.y + e / 2 };
|
|
38
38
|
case "right":
|
|
39
|
-
return { x: o.x +
|
|
39
|
+
return { x: o.x + t, y: o.y + e / 2 };
|
|
40
40
|
default:
|
|
41
|
-
return { x: o.x +
|
|
41
|
+
return { x: o.x + t, y: o.y + e / 2 };
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
var h = f(
|
|
44
|
+
var h = f(l), x = f(i);
|
|
45
45
|
return [
|
|
46
|
-
{ id: null, type: "target", x: h.x, y: h.y, position:
|
|
47
|
-
{ id: null, type: "source", x: x.x, y: x.y, position:
|
|
46
|
+
{ id: null, type: "target", x: h.x, y: h.y, position: l },
|
|
47
|
+
{ id: null, type: "source", x: x.x, y: x.y, position: i }
|
|
48
48
|
];
|
|
49
49
|
}
|
|
50
|
-
var
|
|
51
|
-
function
|
|
52
|
-
|
|
53
|
-
var
|
|
54
|
-
return
|
|
50
|
+
var Pe = {}, nt = !0;
|
|
51
|
+
function Vl(a) {
|
|
52
|
+
nt && (Pe = {}, nt = !1);
|
|
53
|
+
var t = Pe[a.id];
|
|
54
|
+
return t || (t = el(a), Pe[a.id] = t, t);
|
|
55
55
|
}
|
|
56
|
-
function
|
|
57
|
-
for (var
|
|
58
|
-
if (i
|
|
59
|
-
if (
|
|
60
|
-
if (i
|
|
56
|
+
function bt(a, t, e) {
|
|
57
|
+
for (var l = Vl(a), i = 0; i < l.length; i++)
|
|
58
|
+
if (l[i].type === t)
|
|
59
|
+
if (e) {
|
|
60
|
+
if (l[i].id === e) return l[i];
|
|
61
61
|
} else
|
|
62
|
-
return i
|
|
62
|
+
return l[i];
|
|
63
63
|
var o = a.width || L, f = a.height || B;
|
|
64
|
-
return
|
|
64
|
+
return t === "source" ? { x: y(a).x + o, y: y(a).y + f / 2 } : { x: y(a).x, y: y(a).y + f / 2 };
|
|
65
65
|
}
|
|
66
66
|
var k = {};
|
|
67
|
-
function
|
|
67
|
+
function Ke() {
|
|
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)",
|
|
@@ -85,858 +85,862 @@ function Kt() {
|
|
|
85
85
|
handleFill: "#ffffff",
|
|
86
86
|
handleBorder: "#3b82f6",
|
|
87
87
|
connectionLine: "#3b82f6"
|
|
88
|
-
},
|
|
88
|
+
}, Za = !0;
|
|
89
89
|
}
|
|
90
|
-
|
|
91
|
-
var
|
|
92
|
-
function
|
|
93
|
-
|
|
94
|
-
for (var a = 0; a <
|
|
95
|
-
for (var
|
|
96
|
-
for (var h =
|
|
90
|
+
Ke();
|
|
91
|
+
var Nl = ["#534AB7", "#0F6E56", "#993C1D", "#185FA5"], ot = 8, Dl = "500 11px system-ui, sans-serif", Ol = "400 11px system-ui, sans-serif", jl = "10px monospace", Oo = "500 13px system-ui, sans-serif", Yl = "400 11px system-ui, sans-serif", Dr = 400, ft = {}, Jt = !0;
|
|
92
|
+
function Xl() {
|
|
93
|
+
ft = {};
|
|
94
|
+
for (var a = 0; a < Y.length; a++)
|
|
95
|
+
for (var t = Y[a], e = Math.floor(t.x / Dr), l = Math.floor(t.y / Dr), i = Math.floor((t.x + t.w) / Dr), o = Math.floor((t.y + t.h) / Dr), f = e; f <= i; f++)
|
|
96
|
+
for (var h = l; h <= o; h++) {
|
|
97
97
|
var x = f + "," + h;
|
|
98
|
-
|
|
98
|
+
ft[x] || (ft[x] = []), ft[x].push(a);
|
|
99
99
|
}
|
|
100
|
-
|
|
100
|
+
Jt = !1;
|
|
101
101
|
}
|
|
102
|
-
function jo(a,
|
|
103
|
-
|
|
104
|
-
for (var
|
|
105
|
-
for (var v = h; v <=
|
|
106
|
-
var
|
|
107
|
-
if (
|
|
108
|
-
for (var
|
|
109
|
-
var T = d
|
|
110
|
-
|
|
102
|
+
function jo(a, t, e, l) {
|
|
103
|
+
Jt && Xl();
|
|
104
|
+
for (var i = {}, o = [], f = Math.floor(a / Dr), h = Math.floor(t / Dr), x = Math.floor(e / Dr), n = Math.floor(l / Dr), g = f; g <= x; g++)
|
|
105
|
+
for (var v = h; v <= n; v++) {
|
|
106
|
+
var u = g + "," + v, s = ft[u];
|
|
107
|
+
if (s)
|
|
108
|
+
for (var d = 0; d < s.length; d++) {
|
|
109
|
+
var T = s[d];
|
|
110
|
+
i[T] || (i[T] = !0, o.push(T));
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
return o;
|
|
114
114
|
}
|
|
115
|
-
var
|
|
116
|
-
function $
|
|
117
|
-
|
|
118
|
-
for (var a = 0; a <
|
|
119
|
-
var
|
|
120
|
-
if (!
|
|
121
|
-
for (var
|
|
115
|
+
var Or = 500, vt = {}, jr = !0;
|
|
116
|
+
function $e() {
|
|
117
|
+
vt = {};
|
|
118
|
+
for (var a = 0; a < W.length; a++) {
|
|
119
|
+
var t = W[a];
|
|
120
|
+
if (!t.hidden)
|
|
121
|
+
for (var e = y(t), l = t.width || L, i = t.height || B, o = Math.floor(e.x / Or), f = Math.floor(e.y / Or), h = Math.floor((e.x + l) / Or), x = Math.floor((e.y + i) / Or), n = o; n <= h; n++)
|
|
122
122
|
for (var g = f; g <= x; g++) {
|
|
123
|
-
var v =
|
|
124
|
-
|
|
123
|
+
var v = n + "," + g;
|
|
124
|
+
vt[v] || (vt[v] = []), vt[v].push(a);
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
|
|
127
|
+
jr = !1;
|
|
128
128
|
}
|
|
129
|
-
function
|
|
130
|
-
|
|
131
|
-
for (var
|
|
132
|
-
for (var v = h; v <=
|
|
133
|
-
var
|
|
134
|
-
if (
|
|
135
|
-
for (var
|
|
136
|
-
var T = d
|
|
137
|
-
|
|
129
|
+
function ol(a, t, e, l) {
|
|
130
|
+
jr && $e();
|
|
131
|
+
for (var i = {}, o = [], f = Math.floor(a / Or), h = Math.floor(t / Or), x = Math.floor(e / Or), n = Math.floor(l / Or), g = f; g <= x; g++)
|
|
132
|
+
for (var v = h; v <= n; v++) {
|
|
133
|
+
var u = g + "," + v, s = vt[u];
|
|
134
|
+
if (s)
|
|
135
|
+
for (var d = 0; d < s.length; d++) {
|
|
136
|
+
var T = s[d];
|
|
137
|
+
i[T] || (i[T] = !0, o.push(T));
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
return o;
|
|
141
141
|
}
|
|
142
|
-
var
|
|
143
|
-
function
|
|
144
|
-
|
|
145
|
-
for (var a = 0; a <
|
|
146
|
-
|
|
147
|
-
|
|
142
|
+
var ya = {}, sa = !0;
|
|
143
|
+
function Qt() {
|
|
144
|
+
ya = {};
|
|
145
|
+
for (var a = 0; a < W.length; a++)
|
|
146
|
+
ya[W[a].id] = W[a];
|
|
147
|
+
sa = !1;
|
|
148
148
|
}
|
|
149
149
|
function Yo(a) {
|
|
150
|
-
return
|
|
150
|
+
return sa && Qt(), ya[a];
|
|
151
151
|
}
|
|
152
|
-
var
|
|
153
|
-
function
|
|
154
|
-
|
|
155
|
-
for (var a = 0; a <
|
|
156
|
-
var
|
|
157
|
-
|
|
152
|
+
var Er = {}, $t = !0;
|
|
153
|
+
function Hl() {
|
|
154
|
+
Er = {};
|
|
155
|
+
for (var a = 0; a < C.length; a++) {
|
|
156
|
+
var t = C[a];
|
|
157
|
+
Er[t.source] || (Er[t.source] = []), Er[t.source].push(a), t.source !== t.target && (Er[t.target] || (Er[t.target] = []), Er[t.target].push(a));
|
|
158
158
|
}
|
|
159
|
-
|
|
159
|
+
$t = !1;
|
|
160
160
|
}
|
|
161
|
-
var
|
|
162
|
-
function
|
|
163
|
-
|
|
164
|
-
var
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
var
|
|
168
|
-
|
|
169
|
-
var
|
|
170
|
-
if (
|
|
171
|
-
|
|
172
|
-
var o =
|
|
173
|
-
|
|
174
|
-
} else if (
|
|
175
|
-
|
|
161
|
+
var ua = null, ll = 0, il = 0, fl = "", Za = !0;
|
|
162
|
+
function pl(a) {
|
|
163
|
+
ua || (ua = new OffscreenCanvas(1, 1));
|
|
164
|
+
var t = Math.ceil(a), e = Math.ceil(a);
|
|
165
|
+
if (t < 2 || e < 2) return !1;
|
|
166
|
+
t > 512 && (t = 512), e > 512 && (e = 512), ua.width = t, ua.height = e, ll = t, il = a, fl = Nr, Za = !1;
|
|
167
|
+
var l = ua.getContext("2d");
|
|
168
|
+
l.clearRect(0, 0, t, e);
|
|
169
|
+
var i = Kt || k.grid;
|
|
170
|
+
if (Nr === "dots") {
|
|
171
|
+
l.fillStyle = i;
|
|
172
|
+
var o = da * M.zoom;
|
|
173
|
+
l.beginPath(), l.arc(0, 0, o, 0, 6.2832), l.fill();
|
|
174
|
+
} else if (Nr === "cross") {
|
|
175
|
+
l.strokeStyle = i, l.lineWidth = da;
|
|
176
176
|
var f = 3 * M.zoom;
|
|
177
|
-
|
|
177
|
+
l.beginPath(), l.moveTo(-f, 0), l.lineTo(f, 0), l.moveTo(0, -f), l.lineTo(0, f), l.stroke();
|
|
178
178
|
} else
|
|
179
|
-
|
|
179
|
+
l.beginPath(), l.strokeStyle = i, l.lineWidth = da * 0.5, l.moveTo(0.5, 0), l.lineTo(0.5, e), l.moveTo(0, 0.5), l.lineTo(t, 0.5), l.stroke();
|
|
180
180
|
return !0;
|
|
181
181
|
}
|
|
182
|
-
var Xo = 0,
|
|
182
|
+
var Xo = 0, qe = 0, Ho = 0, po = 0, be = 0, ht = !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) {
|
|
186
186
|
try {
|
|
187
|
-
var
|
|
188
|
-
switch (
|
|
187
|
+
var t = a.data.type, e = a.data.data;
|
|
188
|
+
switch (t) {
|
|
189
189
|
case "init":
|
|
190
|
-
|
|
191
|
-
return
|
|
192
|
-
}), console.log("[worker] init done — canvas:",
|
|
190
|
+
qa = e.canvas, r = qa.getContext("2d"), fr = e.width, vr = e.height, qa.width = fr, qa.height = vr, M = e.camera, Y = e.cards || [], W = e.nodes || [], C = e.edges || [], F = e.dark, e.gridSize && (Ze = e.gridSize), e.edgeRouting !== void 0 && (Vr = !!e.edgeRouting), Ke(), Jt = !0, sa = !0, jr = !0, nt = !0, $t = !0, ht = C.some(function(X) {
|
|
191
|
+
return X.animated;
|
|
192
|
+
}), console.log("[worker] init done — canvas:", fr, "x", vr, "| cards:", Y.length, "| nodes:", W.length, "| edges:", C.length, "| routing:", Vr), Ft(), self.postMessage({ type: "ready" }), ht && rl();
|
|
193
193
|
break;
|
|
194
194
|
case "resize":
|
|
195
|
-
|
|
195
|
+
fr = e.width, vr = e.height, qa.width = fr, qa.height = vr, Za = !0, Ft();
|
|
196
196
|
break;
|
|
197
197
|
case "camera":
|
|
198
|
-
M =
|
|
198
|
+
M = e.camera, Za = !0, $();
|
|
199
199
|
break;
|
|
200
200
|
case "cards":
|
|
201
|
-
|
|
201
|
+
Y = e.cards, Jt = !0, $();
|
|
202
202
|
break;
|
|
203
203
|
case "nodes":
|
|
204
|
-
|
|
205
|
-
for (var
|
|
206
|
-
|
|
207
|
-
|
|
204
|
+
W = e.nodes, Ia = 0;
|
|
205
|
+
for (var l = 0; l < W.length; l++)
|
|
206
|
+
W[l].dragging && Ia++;
|
|
207
|
+
sa = !0, jr = !0, nt = !0, $(), Gt(), self.postMessage({ type: "nodesProcessed", data: { nodeCount: W.length } });
|
|
208
208
|
break;
|
|
209
209
|
case "nodePositions":
|
|
210
|
-
|
|
211
|
-
for (var
|
|
212
|
-
var h =
|
|
210
|
+
sa && Qt();
|
|
211
|
+
for (var i = e.updates, o = 0, f = 0; f < i.length; f++) {
|
|
212
|
+
var h = i[f], x = ya[h.id];
|
|
213
213
|
x && (x.position = h.position, h._absolutePosition && (x._absolutePosition = h._absolutePosition), h.width !== void 0 && (x.width = h.width), h.height !== void 0 && (x.height = h.height), h.dragging && !x.dragging ? o++ : !h.dragging && x.dragging && o--, x.dragging = h.dragging, x.selected = h.selected);
|
|
214
214
|
}
|
|
215
|
-
|
|
215
|
+
if (Ia = Math.max(0, Ia + o), nt = !0, Vr)
|
|
216
|
+
for (var n = 0; n < i.length; n++)
|
|
217
|
+
for (var g = i[n].id, v = 0; v < C.length; v++)
|
|
218
|
+
(C[v].source === g || C[v].target === g) && (C[v]._routedPoints = null);
|
|
219
|
+
i.length > 10 && (jr = !0), Vr && Ia === 0 && o < 0 && (jr = !0, Gt()), $();
|
|
216
220
|
break;
|
|
217
221
|
case "nodeSelections":
|
|
218
|
-
|
|
219
|
-
for (var u =
|
|
220
|
-
var
|
|
221
|
-
|
|
222
|
+
sa && Qt();
|
|
223
|
+
for (var u = e.selections, s = 0; s < u.length; s++) {
|
|
224
|
+
var d = u[s], T = ya[d.id];
|
|
225
|
+
T && (T.selected = d.selected);
|
|
222
226
|
}
|
|
223
227
|
$();
|
|
224
228
|
break;
|
|
225
229
|
case "edgeSelections":
|
|
226
|
-
for (var
|
|
227
|
-
for (var
|
|
228
|
-
if (
|
|
229
|
-
|
|
230
|
+
for (var Z = e.selections, _ = 0; _ < Z.length; _++) {
|
|
231
|
+
for (var K = Z[_], ar = null, tr = 0; tr < C.length; tr++)
|
|
232
|
+
if (C[tr].id === K.id) {
|
|
233
|
+
ar = C[tr];
|
|
230
234
|
break;
|
|
231
235
|
}
|
|
232
|
-
|
|
236
|
+
ar && (ar.selected = K.selected);
|
|
233
237
|
}
|
|
234
238
|
$();
|
|
235
239
|
break;
|
|
236
240
|
case "edges":
|
|
237
|
-
|
|
238
|
-
return
|
|
239
|
-
}),
|
|
241
|
+
C = e.edges, $t = !0, ht = C.some(function(X) {
|
|
242
|
+
return X.animated;
|
|
243
|
+
}), ht && rl(), $(), Gt();
|
|
240
244
|
break;
|
|
241
245
|
case "theme":
|
|
242
|
-
F =
|
|
246
|
+
F = e.dark, Ke(), $();
|
|
243
247
|
break;
|
|
244
248
|
case "connecting":
|
|
245
|
-
|
|
249
|
+
lt = e, $();
|
|
246
250
|
break;
|
|
247
251
|
case "selectionBox":
|
|
248
|
-
|
|
252
|
+
Tr = e, $();
|
|
249
253
|
break;
|
|
250
254
|
case "background":
|
|
251
|
-
|
|
255
|
+
e.variant && (Nr = e.variant), e.gap && (Ze = e.gap), e.size && (da = e.size), Kt = e.color || null, Za = !0, $();
|
|
252
256
|
break;
|
|
253
257
|
case "nodeTypeBitmaps":
|
|
254
|
-
|
|
258
|
+
It = e.bitmaps || {}, $();
|
|
255
259
|
break;
|
|
256
260
|
case "nodeBitmaps":
|
|
257
|
-
|
|
261
|
+
tl = e.cache || {}, it = e.keys || {}, $();
|
|
258
262
|
break;
|
|
259
263
|
case "nodeTypeConfigs":
|
|
260
|
-
|
|
264
|
+
Zt = e.configs || {}, $();
|
|
261
265
|
break;
|
|
262
266
|
case "edgeRouting":
|
|
263
|
-
if (
|
|
264
|
-
|
|
267
|
+
if (Vr = !!e.enabled, Vr)
|
|
268
|
+
Gt();
|
|
265
269
|
else {
|
|
266
|
-
for (var
|
|
267
|
-
|
|
270
|
+
for (var hr = 0; hr < C.length; hr++)
|
|
271
|
+
C[hr]._routedPoints = null;
|
|
268
272
|
$();
|
|
269
273
|
}
|
|
270
274
|
break;
|
|
271
275
|
}
|
|
272
|
-
} catch (
|
|
273
|
-
console.error("[worker] error:",
|
|
276
|
+
} catch (X) {
|
|
277
|
+
console.error("[worker] error:", X);
|
|
274
278
|
}
|
|
275
279
|
};
|
|
276
280
|
function $() {
|
|
277
|
-
|
|
278
|
-
|
|
281
|
+
We || (We = !0, requestAnimationFrame(function() {
|
|
282
|
+
We = !1, Ft();
|
|
279
283
|
}));
|
|
280
284
|
}
|
|
281
|
-
var
|
|
282
|
-
function
|
|
283
|
-
if (
|
|
284
|
-
|
|
285
|
+
var Ge = !1;
|
|
286
|
+
function rl() {
|
|
287
|
+
if (Ge) return;
|
|
288
|
+
Ge = !0;
|
|
285
289
|
function a() {
|
|
286
|
-
if (!
|
|
287
|
-
|
|
290
|
+
if (!ht) {
|
|
291
|
+
Ge = !1;
|
|
288
292
|
return;
|
|
289
293
|
}
|
|
290
|
-
|
|
294
|
+
be = (be + 0.5) % 20, Ft(), requestAnimationFrame(a);
|
|
291
295
|
}
|
|
292
296
|
requestAnimationFrame(a);
|
|
293
297
|
}
|
|
294
|
-
function
|
|
295
|
-
var
|
|
296
|
-
a.moveTo(
|
|
297
|
-
for (var
|
|
298
|
-
var
|
|
299
|
-
if (
|
|
300
|
-
var g = o.x -
|
|
301
|
-
a.lineTo(o.x - g /
|
|
298
|
+
function al(a, t) {
|
|
299
|
+
var e = 6;
|
|
300
|
+
a.moveTo(t[0].x, t[0].y);
|
|
301
|
+
for (var l = 1; l < t.length - 1; l++) {
|
|
302
|
+
var i = t[l - 1], o = t[l], f = t[l + 1], h = Math.abs(o.x - i.x) + Math.abs(o.y - i.y), x = Math.abs(f.x - o.x) + Math.abs(f.y - o.y), n = Math.min(e, h / 2, x / 2);
|
|
303
|
+
if (n > 0.5) {
|
|
304
|
+
var g = o.x - i.x, v = o.y - i.y, u = f.x - o.x, s = f.y - o.y, d = Math.sqrt(g * g + v * v) || 1, T = Math.sqrt(u * u + s * s) || 1;
|
|
305
|
+
a.lineTo(o.x - g / d * n, o.y - v / d * n), a.quadraticCurveTo(o.x, o.y, o.x + u / T * n, o.y + s / T * n);
|
|
302
306
|
} else
|
|
303
307
|
a.lineTo(o.x, o.y);
|
|
304
308
|
}
|
|
305
|
-
a.lineTo(
|
|
309
|
+
a.lineTo(t[t.length - 1].x, t[t.length - 1].y);
|
|
306
310
|
}
|
|
307
|
-
function
|
|
308
|
-
for (var
|
|
309
|
-
|
|
310
|
-
for (var
|
|
311
|
-
var o = Math.abs(a[
|
|
312
|
-
if (
|
|
313
|
-
var f = o > 0 ?
|
|
311
|
+
function ri(a) {
|
|
312
|
+
for (var t = 0, e = 1; e < a.length; e++)
|
|
313
|
+
t += Math.abs(a[e].x - a[e - 1].x) + Math.abs(a[e].y - a[e - 1].y);
|
|
314
|
+
for (var l = t / 2, i = 1; i < a.length; i++) {
|
|
315
|
+
var o = Math.abs(a[i].x - a[i - 1].x) + Math.abs(a[i].y - a[i - 1].y);
|
|
316
|
+
if (l <= o) {
|
|
317
|
+
var f = o > 0 ? l / o : 0;
|
|
314
318
|
return {
|
|
315
|
-
x: a[
|
|
316
|
-
y: a[
|
|
319
|
+
x: a[i - 1].x + (a[i].x - a[i - 1].x) * f,
|
|
320
|
+
y: a[i - 1].y + (a[i].y - a[i - 1].y) * f
|
|
317
321
|
};
|
|
318
322
|
}
|
|
319
|
-
|
|
323
|
+
l -= o;
|
|
320
324
|
}
|
|
321
325
|
return { x: a[0].x, y: a[0].y };
|
|
322
326
|
}
|
|
323
|
-
function
|
|
324
|
-
var
|
|
325
|
-
return { cp1x: f, cp1y: h, cp2x: x, cp2y:
|
|
327
|
+
function Je(a, t, e, l) {
|
|
328
|
+
var i = Math.abs(e - a), o = Math.max(50, i * 0.5), f = a + o, h = t, x = e - o, n = l;
|
|
329
|
+
return { cp1x: f, cp1y: h, cp2x: x, cp2y: n };
|
|
326
330
|
}
|
|
327
|
-
function
|
|
328
|
-
var
|
|
331
|
+
function ai(a, t, e, l) {
|
|
332
|
+
var i = Je(a, t, e, l), o = 0.5, f = 1 - o, h = f * f * f * a + 3 * f * f * o * i.cp1x + 3 * f * o * o * i.cp2x + o * o * o * e, x = f * f * f * t + 3 * f * f * o * i.cp1y + 3 * f * o * o * i.cp2y + o * o * o * l;
|
|
329
333
|
return { x: h, y: x };
|
|
330
334
|
}
|
|
331
|
-
var
|
|
332
|
-
function
|
|
333
|
-
|
|
334
|
-
for (var o = Math.min(a,
|
|
335
|
-
var
|
|
336
|
-
|
|
335
|
+
var Vr = !0, Qe = !1, Ie = !1;
|
|
336
|
+
function vl(a, t, e, l, i) {
|
|
337
|
+
jr && $e();
|
|
338
|
+
for (var o = Math.min(a, e) - 20, f = Math.min(t, l) - 20, h = Math.max(a, e) + 20, x = Math.max(t, l) + 20, n = ol(o, f, h, x), g = [], v = 0; v < n.length; v++) {
|
|
339
|
+
var u = W[n[v]];
|
|
340
|
+
u.hidden || i[u.id] || u.type !== "group" && g.push(u);
|
|
337
341
|
}
|
|
338
342
|
return g;
|
|
339
343
|
}
|
|
340
|
-
function
|
|
341
|
-
for (var
|
|
342
|
-
var h =
|
|
343
|
-
if (
|
|
344
|
+
function Lr(a, t, e, l) {
|
|
345
|
+
for (var i = Math.min(a, t), o = Math.max(a, t), f = 0; f < l.length; f++) {
|
|
346
|
+
var h = l[f], x = y(h), n = h.width || L, g = h.height || B;
|
|
347
|
+
if (e > x.y && e < x.y + g && o > x.x && i < x.x + n) return h;
|
|
344
348
|
}
|
|
345
349
|
return null;
|
|
346
350
|
}
|
|
347
|
-
function
|
|
348
|
-
for (var
|
|
349
|
-
var h =
|
|
350
|
-
if (a > x.x && a < x.x +
|
|
351
|
+
function Sr(a, t, e, l) {
|
|
352
|
+
for (var i = Math.min(t, e), o = Math.max(t, e), f = 0; f < l.length; f++) {
|
|
353
|
+
var h = l[f], x = y(h), n = h.width || L, g = h.height || B;
|
|
354
|
+
if (a > x.x && a < x.x + n && o > x.y && i < x.y + g) return h;
|
|
351
355
|
}
|
|
352
356
|
return null;
|
|
353
357
|
}
|
|
354
|
-
function
|
|
355
|
-
if (
|
|
356
|
-
|
|
357
|
-
for (var a = 20,
|
|
358
|
-
var
|
|
359
|
-
if (!
|
|
360
|
-
var
|
|
361
|
-
if (!(
|
|
362
|
-
var o =
|
|
358
|
+
function ti() {
|
|
359
|
+
if (Vr && !(!Qe || C.length === 0 || W.length === 0)) {
|
|
360
|
+
Qe = !1, sa && Qt(), jr && $e();
|
|
361
|
+
for (var a = 20, t = !1, e = 0; e < C.length; e++) {
|
|
362
|
+
var l = C[e];
|
|
363
|
+
if (!l._customRendered) {
|
|
364
|
+
var i = l.type || "default";
|
|
365
|
+
if (!(i === "bezier" || i === "simplebezier" || i === "default")) {
|
|
366
|
+
var o = ya[l.source], f = ya[l.target];
|
|
363
367
|
if (!(!o || !f || o.hidden || f.hidden)) {
|
|
364
|
-
var h =
|
|
365
|
-
|
|
366
|
-
var
|
|
367
|
-
|
|
368
|
-
var H =
|
|
369
|
-
Math.min(v,
|
|
370
|
-
Math.min(
|
|
371
|
-
Math.max(v,
|
|
372
|
-
Math.max(
|
|
373
|
-
|
|
368
|
+
var h = bt(o, "source", l.sourceHandle), x = bt(f, "target", l.targetHandle), n = h.position || "right", g = x.position || "left", v = h.x, u = h.y, s = x.x, d = x.y, T = v, Z = u, _ = s, K = d;
|
|
369
|
+
n === "right" ? T += a : n === "left" ? T -= a : n === "bottom" ? Z += a : n === "top" && (Z -= a), g === "right" ? _ += a : g === "left" ? _ -= a : g === "bottom" ? K += a : g === "top" && (K -= a);
|
|
370
|
+
var ar = y(o), tr = y(f), hr = o.width || L, X = o.height || B, Yr = f.width || L, xa = f.height || B, Xr = {};
|
|
371
|
+
Xr[l.source] = !0, Xr[l.target] = !0;
|
|
372
|
+
var H = vl(
|
|
373
|
+
Math.min(v, s) - hr,
|
|
374
|
+
Math.min(u, d) - X,
|
|
375
|
+
Math.max(v, s) + Yr,
|
|
376
|
+
Math.max(u, d) + xa,
|
|
377
|
+
Xr
|
|
374
378
|
);
|
|
375
379
|
H.push(o), H.push(f);
|
|
376
|
-
var
|
|
377
|
-
if (
|
|
378
|
-
var
|
|
379
|
-
if (
|
|
380
|
-
|
|
381
|
-
var
|
|
382
|
-
if (
|
|
383
|
-
var
|
|
384
|
-
|
|
380
|
+
var ga = n === "left" || n === "right", Ka = g === "left" || g === "right", q = null;
|
|
381
|
+
if (ga && Ka) {
|
|
382
|
+
var P, sr = n === "right" && T < _, Ut = n === "left" && T > _;
|
|
383
|
+
if (sr || Ut) {
|
|
384
|
+
P = (T + _) / 2;
|
|
385
|
+
var ba = Sr(P, u, d, H);
|
|
386
|
+
if (ba) {
|
|
387
|
+
var Ma = y(ba), ka = ba.width || L;
|
|
388
|
+
P = P < Ma.x + ka / 2 ? Ma.x - a : Ma.x + ka + a;
|
|
385
389
|
}
|
|
386
390
|
} else
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
var
|
|
390
|
-
if (
|
|
391
|
-
var
|
|
392
|
-
|
|
391
|
+
n === "right" ? P = Math.max(ar.x + hr, tr.x + Yr) + a : P = Math.min(ar.x, tr.x) - a;
|
|
392
|
+
q = [{ x: v, y: u }, { x: T, y: u }, { x: P, y: u }, { x: P, y: d }, { x: _, y: d }, { x: s, y: d }];
|
|
393
|
+
var Cr = Lr(P, _, d, H);
|
|
394
|
+
if (Cr) {
|
|
395
|
+
var ma = y(Cr), Ta = Cr.height || B, Ra = ma.y - a, Hr = ma.y + Ta + a, pr = Math.abs(u - Ra) <= Math.abs(u - Hr) ? Ra : Hr;
|
|
396
|
+
q = [{ x: v, y: u }, { x: T, y: u }, { x: P, y: u }, { x: P, y: pr }, { x: _, y: pr }, { x: _, y: d }, { x: s, y: d }];
|
|
393
397
|
}
|
|
394
|
-
} else if (!
|
|
395
|
-
var b,
|
|
396
|
-
if (
|
|
397
|
-
b = (
|
|
398
|
-
var
|
|
399
|
-
if (
|
|
400
|
-
var
|
|
401
|
-
b = b <
|
|
398
|
+
} else if (!ga && !Ka) {
|
|
399
|
+
var b, ut = n === "bottom" && Z < K, Ja = n === "top" && Z > K;
|
|
400
|
+
if (ut || Ja) {
|
|
401
|
+
b = (Z + K) / 2;
|
|
402
|
+
var Wr = Lr(v, s, b, H);
|
|
403
|
+
if (Wr) {
|
|
404
|
+
var Pr = y(Wr), za = Wr.height || B;
|
|
405
|
+
b = b < Pr.y + za / 2 ? Pr.y - a : Pr.y + za + a;
|
|
402
406
|
}
|
|
403
407
|
} else
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
var
|
|
407
|
-
if (
|
|
408
|
-
var
|
|
409
|
-
|
|
408
|
+
n === "bottom" ? b = Math.max(ar.y + X, tr.y + xa) + a : b = Math.min(ar.y, tr.y) - a;
|
|
409
|
+
q = [{ x: v, y: u }, { x: v, y: Z }, { x: v, y: b }, { x: s, y: b }, { x: s, y: K }, { x: s, y: d }];
|
|
410
|
+
var ra = Sr(s, b, K, H);
|
|
411
|
+
if (ra) {
|
|
412
|
+
var wa = y(ra), Qa = ra.height || B, Ba = wa.y - a, Aa = wa.y + Qa + a, _a = Math.abs(b - Ba) <= Math.abs(b - Aa) ? Ba : Aa;
|
|
413
|
+
q = [{ x: v, y: u }, { x: v, y: Z }, { x: v, y: b }, { x: s, y: b }, { x: s, y: _a }, { x: _, y: _a }, { x: _, y: d }, { x: s, y: d }];
|
|
410
414
|
}
|
|
411
|
-
} else if (
|
|
412
|
-
|
|
413
|
-
var
|
|
414
|
-
if (
|
|
415
|
-
var
|
|
416
|
-
|
|
415
|
+
} else if (ga) {
|
|
416
|
+
q = [{ x: v, y: u }, { x: T, y: u }, { x: s, y: u }, { x: s, y: K }, { x: s, y: d }];
|
|
417
|
+
var qr = Sr(s, u, K, H);
|
|
418
|
+
if (qr) {
|
|
419
|
+
var nr = y(qr), Rr = qr.width || L, $a = Math.abs(v - nr.x + a) <= Math.abs(v - nr.x - Rr - a) ? nr.x - a : nr.x + Rr + a;
|
|
420
|
+
q = [{ x: v, y: u }, { x: T, y: u }, { x: $a, y: u }, { x: $a, y: d }, { x: s, y: d }, { x: s, y: K }, { x: s, y: d }];
|
|
417
421
|
}
|
|
418
|
-
var
|
|
419
|
-
if (
|
|
420
|
-
var
|
|
421
|
-
|
|
422
|
+
var aa = Lr(T, s, u, H);
|
|
423
|
+
if (aa) {
|
|
424
|
+
var Gr = y(aa), Ea = aa.height || B, p = Math.abs(d - Gr.y + a) <= Math.abs(d - Gr.y - Ea - a) ? Gr.y - a : Gr.y + Ea + a;
|
|
425
|
+
q = [{ x: v, y: u }, { x: T, y: u }, { x: T, y: p }, { x: s, y: p }, { x: s, y: K }, { x: s, y: d }];
|
|
422
426
|
}
|
|
423
427
|
} else {
|
|
424
|
-
|
|
425
|
-
var
|
|
426
|
-
if (
|
|
427
|
-
var
|
|
428
|
-
|
|
428
|
+
q = [{ x: v, y: u }, { x: v, y: Z }, { x: v, y: d }, { x: _, y: d }, { x: s, y: d }];
|
|
429
|
+
var Ir = Lr(v, _, d, H);
|
|
430
|
+
if (Ir) {
|
|
431
|
+
var La = y(Ir), dr = Ir.height || B, Zr = Math.abs(u - La.y + a) <= Math.abs(u - La.y - dr - a) ? La.y - a : La.y + dr + a;
|
|
432
|
+
q = [{ x: v, y: u }, { x: v, y: Z }, { x: v, y: Zr }, { x: _, y: Zr }, { x: _, y: d }, { x: s, y: d }];
|
|
429
433
|
}
|
|
430
|
-
var
|
|
431
|
-
if (
|
|
432
|
-
var
|
|
433
|
-
|
|
434
|
+
var zr = Sr(v, Z, d, H);
|
|
435
|
+
if (zr) {
|
|
436
|
+
var yr = y(zr), Fa = zr.width || L, Ua = Math.abs(s - yr.x + a) <= Math.abs(s - yr.x - Fa - a) ? yr.x - a : yr.x + Fa + a;
|
|
437
|
+
q = [{ x: v, y: u }, { x: v, y: Z }, { x: Ua, y: Z }, { x: Ua, y: d }, { x: _, y: d }, { x: s, y: d }];
|
|
434
438
|
}
|
|
435
439
|
}
|
|
436
|
-
if (
|
|
437
|
-
for (var
|
|
438
|
-
var
|
|
439
|
-
(Math.abs(
|
|
440
|
+
if (q) {
|
|
441
|
+
for (var ta = [q[0]], xr = 1; xr < q.length; xr++) {
|
|
442
|
+
var st = ta[ta.length - 1];
|
|
443
|
+
(Math.abs(q[xr].x - st.x) > 0.1 || Math.abs(q[xr].y - st.y) > 0.1) && ta.push(q[xr]);
|
|
440
444
|
}
|
|
441
|
-
|
|
445
|
+
l._routedPoints = ta, t = !0;
|
|
442
446
|
}
|
|
443
447
|
}
|
|
444
448
|
}
|
|
445
449
|
}
|
|
446
450
|
}
|
|
447
|
-
|
|
451
|
+
t && $();
|
|
448
452
|
}
|
|
449
453
|
}
|
|
450
|
-
function
|
|
451
|
-
|
|
452
|
-
|
|
454
|
+
function Gt() {
|
|
455
|
+
Vr && (Ie || (Ie = !0, Qe = !0, requestAnimationFrame(function() {
|
|
456
|
+
Ie = !1;
|
|
453
457
|
try {
|
|
454
|
-
|
|
458
|
+
ti();
|
|
455
459
|
} catch (a) {
|
|
456
460
|
console.error("[worker] async routing error:", a);
|
|
457
461
|
}
|
|
458
462
|
})));
|
|
459
463
|
}
|
|
460
|
-
function
|
|
464
|
+
function Ft() {
|
|
461
465
|
if (r) {
|
|
462
466
|
var a = performance.now();
|
|
463
|
-
r.clearRect(0, 0,
|
|
464
|
-
var
|
|
465
|
-
if (
|
|
466
|
-
if (
|
|
467
|
-
if ((
|
|
468
|
-
var
|
|
469
|
-
r.save(), r.translate(
|
|
470
|
-
var
|
|
471
|
-
|
|
467
|
+
r.clearRect(0, 0, fr, vr);
|
|
468
|
+
var t = Ze * M.zoom;
|
|
469
|
+
if (t > 2)
|
|
470
|
+
if (Nr === "lines" && t >= 4 && t <= 512) {
|
|
471
|
+
if ((Za || il !== t || fl !== Nr) && pl(t), ua && ll > 0) {
|
|
472
|
+
var e = (M.x % t + t) % t, l = (M.y % t + t) % t;
|
|
473
|
+
r.save(), r.translate(e, l);
|
|
474
|
+
var i = r.createPattern(ua, "repeat");
|
|
475
|
+
i && (r.fillStyle = i, r.fillRect(-e, -l, fr, vr)), r.restore();
|
|
472
476
|
}
|
|
473
477
|
} else {
|
|
474
|
-
var o = (M.x %
|
|
475
|
-
if (
|
|
478
|
+
var o = (M.x % t + t) % t, f = (M.y % t + t) % t, h = Kt || k.grid;
|
|
479
|
+
if (Nr === "dots") {
|
|
476
480
|
r.fillStyle = h;
|
|
477
|
-
for (var x =
|
|
478
|
-
for (var g = f; g <
|
|
479
|
-
r.beginPath(), r.arc(Math.round(
|
|
480
|
-
} else if (
|
|
481
|
-
r.strokeStyle = h, r.lineWidth =
|
|
481
|
+
for (var x = da * M.zoom, n = o; n < fr; n += t)
|
|
482
|
+
for (var g = f; g < vr; g += t)
|
|
483
|
+
r.beginPath(), r.arc(Math.round(n), Math.round(g), x, 0, 6.2832), r.fill();
|
|
484
|
+
} else if (Nr === "cross") {
|
|
485
|
+
r.strokeStyle = h, r.lineWidth = da;
|
|
482
486
|
var v = 3 * M.zoom;
|
|
483
487
|
r.beginPath();
|
|
484
|
-
for (var
|
|
485
|
-
for (var
|
|
486
|
-
var
|
|
487
|
-
r.moveTo(
|
|
488
|
+
for (var u = o; u < fr; u += t)
|
|
489
|
+
for (var s = f; s < vr; s += t) {
|
|
490
|
+
var d = Math.round(u), T = Math.round(s);
|
|
491
|
+
r.moveTo(d - v, T), r.lineTo(d + v, T), r.moveTo(d, T - v), r.lineTo(d, T + v);
|
|
488
492
|
}
|
|
489
493
|
r.stroke();
|
|
490
494
|
} else {
|
|
491
|
-
var
|
|
492
|
-
r.beginPath(), r.strokeStyle =
|
|
493
|
-
for (var
|
|
494
|
-
var
|
|
495
|
-
r.moveTo(
|
|
495
|
+
var Z = Kt || k.grid;
|
|
496
|
+
r.beginPath(), r.strokeStyle = Z, r.lineWidth = da * 0.5;
|
|
497
|
+
for (var _ = o; _ < fr; _ += t) {
|
|
498
|
+
var K = Math.round(_) + 0.5;
|
|
499
|
+
r.moveTo(K, 0), r.lineTo(K, vr);
|
|
496
500
|
}
|
|
497
|
-
for (var
|
|
498
|
-
var
|
|
499
|
-
r.moveTo(0,
|
|
501
|
+
for (var ar = f; ar < vr; ar += t) {
|
|
502
|
+
var tr = Math.round(ar) + 0.5;
|
|
503
|
+
r.moveTo(0, tr), r.lineTo(fr, tr);
|
|
500
504
|
}
|
|
501
505
|
r.stroke();
|
|
502
506
|
}
|
|
503
507
|
}
|
|
504
508
|
r.beginPath(), r.arc(M.x, M.y, 4 * M.zoom, 0, 6.2832), r.fillStyle = k.origin, r.fill(), r.save(), r.translate(M.x, M.y), r.scale(M.zoom, M.zoom);
|
|
505
|
-
var
|
|
506
|
-
if (
|
|
507
|
-
var
|
|
508
|
-
if (
|
|
509
|
+
var hr = 100, X = -M.x / M.zoom, Yr = -M.y / M.zoom, xa = X + fr / M.zoom, Xr = Yr + vr / M.zoom, H = X - hr, ga = Yr - hr, Ka = xa + hr, q = Xr + hr;
|
|
510
|
+
if (Y.length > 0) {
|
|
511
|
+
var P = jo(X, Yr, xa, Xr), sr = P.length, Ut = M.zoom > 0.15, ba = M.zoom > 0.3, Ma = M.zoom > 0.08 && sr < 200;
|
|
512
|
+
if (Ma) {
|
|
509
513
|
r.shadowColor = k.cardShadow, r.shadowBlur = 6, r.shadowOffsetY = 2, r.fillStyle = k.cardBg, r.beginPath();
|
|
510
|
-
for (var
|
|
511
|
-
var
|
|
512
|
-
r.roundRect(
|
|
514
|
+
for (var ka = 0; ka < sr; ka++) {
|
|
515
|
+
var Cr = Y[P[ka]];
|
|
516
|
+
r.roundRect(Cr.x, Cr.y, Cr.w, Cr.h, ot);
|
|
513
517
|
}
|
|
514
518
|
r.fill(), r.shadowColor = "transparent", r.shadowBlur = 0, r.shadowOffsetY = 0;
|
|
515
519
|
}
|
|
516
|
-
if (!
|
|
520
|
+
if (!Ma) {
|
|
517
521
|
r.fillStyle = k.cardBg, r.beginPath();
|
|
518
|
-
for (var
|
|
519
|
-
var
|
|
520
|
-
r.roundRect(
|
|
522
|
+
for (var ma = 0; ma < sr; ma++) {
|
|
523
|
+
var Ta = Y[P[ma]];
|
|
524
|
+
r.roundRect(Ta.x, Ta.y, Ta.w, Ta.h, ot);
|
|
521
525
|
}
|
|
522
526
|
r.fill();
|
|
523
527
|
}
|
|
524
528
|
r.strokeStyle = k.cardBorder, r.lineWidth = 0.5, r.beginPath();
|
|
525
|
-
for (var
|
|
526
|
-
var
|
|
527
|
-
r.roundRect(
|
|
529
|
+
for (var Ra = 0; Ra < sr; Ra++) {
|
|
530
|
+
var Hr = Y[P[Ra]];
|
|
531
|
+
r.roundRect(Hr.x, Hr.y, Hr.w, Hr.h, ot);
|
|
528
532
|
}
|
|
529
533
|
r.stroke();
|
|
530
|
-
for (var
|
|
531
|
-
var
|
|
532
|
-
|
|
534
|
+
for (var pr = [{}, {}, {}, {}], b = 0; b < sr; b++) {
|
|
535
|
+
var ut = P[b], Ja = ut % 4;
|
|
536
|
+
pr[Ja].items || (pr[Ja].items = []), pr[Ja].items.push(Y[ut]);
|
|
533
537
|
}
|
|
534
|
-
for (var
|
|
535
|
-
var
|
|
536
|
-
if (!(!
|
|
537
|
-
r.fillStyle =
|
|
538
|
-
for (var
|
|
539
|
-
var
|
|
540
|
-
r.roundRect(
|
|
538
|
+
for (var Wr = 0; Wr < 4; Wr++) {
|
|
539
|
+
var Pr = pr[Wr].items;
|
|
540
|
+
if (!(!Pr || Pr.length === 0)) {
|
|
541
|
+
r.fillStyle = Nl[Wr], r.beginPath();
|
|
542
|
+
for (var za = 0; za < Pr.length; za++) {
|
|
543
|
+
var ra = Pr[za];
|
|
544
|
+
r.roundRect(ra.x, ra.y, ra.w, 30, [ot, ot, 0, 0]);
|
|
541
545
|
}
|
|
542
546
|
r.fill();
|
|
543
547
|
}
|
|
544
548
|
}
|
|
545
|
-
if (
|
|
546
|
-
r.fillStyle = k.titleText, r.font =
|
|
547
|
-
for (var
|
|
548
|
-
var
|
|
549
|
-
r.fillText(
|
|
550
|
-
}
|
|
551
|
-
r.fillStyle = k.bodyText, r.font =
|
|
552
|
-
for (var
|
|
553
|
-
var
|
|
554
|
-
r.fillText(
|
|
555
|
-
}
|
|
556
|
-
if (
|
|
557
|
-
r.fillStyle = k.coordText, r.font =
|
|
558
|
-
for (var
|
|
559
|
-
var
|
|
560
|
-
r.fillText("(" +
|
|
549
|
+
if (Ut) {
|
|
550
|
+
r.fillStyle = k.titleText, r.font = Dl;
|
|
551
|
+
for (var wa = 0; wa < sr; wa++) {
|
|
552
|
+
var Qa = Y[P[wa]];
|
|
553
|
+
r.fillText(Qa.title, Qa.x + 12, Qa.y + 19);
|
|
554
|
+
}
|
|
555
|
+
r.fillStyle = k.bodyText, r.font = Ol;
|
|
556
|
+
for (var Ba = 0; Ba < sr; Ba++) {
|
|
557
|
+
var Aa = Y[P[Ba]];
|
|
558
|
+
r.fillText(Aa.body, Aa.x + 12, Aa.y + 52);
|
|
559
|
+
}
|
|
560
|
+
if (ba) {
|
|
561
|
+
r.fillStyle = k.coordText, r.font = jl;
|
|
562
|
+
for (var _a = 0; _a < sr; _a++) {
|
|
563
|
+
var qr = Y[P[_a]];
|
|
564
|
+
r.fillText("(" + qr.x + ", " + qr.y + ")", qr.x + 12, qr.y + 75);
|
|
561
565
|
}
|
|
562
566
|
}
|
|
563
567
|
}
|
|
564
568
|
}
|
|
565
|
-
var
|
|
566
|
-
if (
|
|
567
|
-
if (
|
|
568
|
-
for (var
|
|
569
|
-
var
|
|
570
|
-
|
|
569
|
+
var nr = [], Rr = null;
|
|
570
|
+
if (W.length > 0)
|
|
571
|
+
if (Rr = {}, W.length > 100)
|
|
572
|
+
for (var $a = ol(H, ga, Ka, q), aa = 0; aa < $a.length; aa++) {
|
|
573
|
+
var Gr = W[$a[aa]];
|
|
574
|
+
Rr[Gr.id] = !0, Gr._customRendered || nr.push(Gr);
|
|
571
575
|
}
|
|
572
576
|
else
|
|
573
|
-
for (var
|
|
574
|
-
var p =
|
|
577
|
+
for (var Ea = 0; Ea < W.length; Ea++) {
|
|
578
|
+
var p = W[Ea];
|
|
575
579
|
if (!p.hidden) {
|
|
576
|
-
var
|
|
577
|
-
y(p).x +
|
|
580
|
+
var Ir = p.width || L, La = p.height || B;
|
|
581
|
+
y(p).x + Ir < H || y(p).x > Ka || y(p).y + La < ga || y(p).y > q || (Rr[p.id] = !0, p._customRendered || nr.push(p));
|
|
578
582
|
}
|
|
579
583
|
}
|
|
580
|
-
var
|
|
581
|
-
if (
|
|
582
|
-
let
|
|
583
|
-
if (
|
|
584
|
+
var dr = nr.length;
|
|
585
|
+
if (C.length > 0 && W.length > 0) {
|
|
586
|
+
let qt = function(cr, No) {
|
|
587
|
+
if (cr.length) {
|
|
584
588
|
r.fillStyle = No, r.beginPath();
|
|
585
|
-
for (var
|
|
586
|
-
var
|
|
587
|
-
r.moveTo(
|
|
589
|
+
for (var Ce = 0; Ce < cr.length; Ce++) {
|
|
590
|
+
var j = cr[Ce];
|
|
591
|
+
r.moveTo(j.x, j.y), r.lineTo(j.x - j.size * Math.cos(j.angle - 0.5236), j.y - j.size * Math.sin(j.angle - 0.5236)), r.lineTo(j.x - j.size * Math.cos(j.angle + 0.5236), j.y - j.size * Math.sin(j.angle + 0.5236)), r.closePath();
|
|
588
592
|
}
|
|
589
593
|
r.fill();
|
|
590
594
|
}
|
|
591
595
|
};
|
|
592
|
-
var
|
|
593
|
-
|
|
594
|
-
var
|
|
595
|
-
if (
|
|
596
|
-
var
|
|
597
|
-
|
|
598
|
-
for (var
|
|
599
|
-
var
|
|
600
|
-
if (
|
|
601
|
-
for (var
|
|
602
|
-
var
|
|
603
|
-
|
|
596
|
+
var ei = qt;
|
|
597
|
+
$t && Hl();
|
|
598
|
+
var Zr = null, zr = null, yr = null, Fa = [], Ua = [], ta = [], xr = [], st = M.zoom > 0.3, hl = M.zoom > 0.05, ea;
|
|
599
|
+
if (Rr && W.length > 100) {
|
|
600
|
+
var dt = {};
|
|
601
|
+
ea = [];
|
|
602
|
+
for (var nl in Rr) {
|
|
603
|
+
var ct = Er[nl];
|
|
604
|
+
if (ct)
|
|
605
|
+
for (var Vt = 0; Vt < ct.length; Vt++) {
|
|
606
|
+
var Nt = ct[Vt];
|
|
607
|
+
dt[Nt] || (dt[Nt] = !0, ea.push(Nt));
|
|
604
608
|
}
|
|
605
609
|
}
|
|
606
|
-
for (var rr = 0; rr <
|
|
607
|
-
var
|
|
608
|
-
if ((
|
|
609
|
-
var
|
|
610
|
-
if (
|
|
611
|
-
for (var
|
|
612
|
-
|
|
610
|
+
for (var rr = 0; rr < W.length; rr++) {
|
|
611
|
+
var yt = W[rr];
|
|
612
|
+
if ((yt.dragging || yt.selected) && !Rr[yt.id]) {
|
|
613
|
+
var ca = Er[yt.id];
|
|
614
|
+
if (ca)
|
|
615
|
+
for (var Va = 0; Va < ca.length; Va++)
|
|
616
|
+
dt[ca[Va]] || (dt[ca[Va]] = !0, ea.push(ca[Va]));
|
|
613
617
|
}
|
|
614
618
|
}
|
|
615
619
|
} else {
|
|
616
|
-
|
|
617
|
-
for (var
|
|
620
|
+
ea = [];
|
|
621
|
+
for (var Dt = 0; Dt < C.length; Dt++) ea.push(Dt);
|
|
618
622
|
}
|
|
619
|
-
for (var
|
|
620
|
-
var
|
|
621
|
-
if (!(!
|
|
622
|
-
var
|
|
623
|
-
|
|
624
|
-
var Q =
|
|
623
|
+
for (var Ot = 0; Ot < ea.length; Ot++) {
|
|
624
|
+
var D = C[ea[Ot]], oa = Yo(D.source), la = Yo(D.target);
|
|
625
|
+
if (!(!oa || !la) && !(oa.hidden || la.hidden) && !D._customRendered) {
|
|
626
|
+
var xt = bt(oa, "source", D.sourceHandle), gt = bt(la, "target", D.targetHandle), A = xt.x, w = xt.y, R = gt.x, z = gt.y, gr = D.type || "default", Fe = D.selected, Ue = D.animated, J;
|
|
627
|
+
Fe ? (zr || (zr = new Path2D()), J = zr) : Ue ? (yr || (yr = new Path2D()), J = yr) : (Zr || (Zr = new Path2D()), J = Zr);
|
|
628
|
+
var Q = D._routedPoints;
|
|
625
629
|
if (Q && Q.length >= 2)
|
|
626
|
-
|
|
627
|
-
else if (
|
|
628
|
-
J.moveTo(
|
|
629
|
-
else if (
|
|
630
|
+
al(J, Q);
|
|
631
|
+
else if (gr === "straight")
|
|
632
|
+
J.moveTo(A, w), J.lineTo(R, z);
|
|
633
|
+
else if (gr === "step" || gr === "smoothstep")
|
|
630
634
|
try {
|
|
631
|
-
var
|
|
632
|
-
|
|
633
|
-
var
|
|
634
|
-
|
|
635
|
-
var
|
|
636
|
-
Math.min(
|
|
637
|
-
Math.min(w, z) -
|
|
638
|
-
Math.max(
|
|
639
|
-
Math.max(w, z) +
|
|
640
|
-
|
|
635
|
+
var er = xt.position || "right", Sa = gt.position || "left", m = 20, U = A, O = w, c = R, or = z;
|
|
636
|
+
er === "right" ? U += m : er === "left" ? U -= m : er === "bottom" ? O += m : er === "top" && (O -= m), Sa === "right" ? c += m : Sa === "left" ? c -= m : Sa === "bottom" ? or += m : Sa === "top" && (or -= m);
|
|
637
|
+
var Mt = y(oa), kt = y(la), Na = oa.width || L, Da = oa.height || B, ce = la.width || L, Ve = la.height || B, jt = er === "left" || er === "right", Ne = Sa === "left" || Sa === "right", Yt = {};
|
|
638
|
+
Yt[D.source] = !0, Yt[D.target] = !0;
|
|
639
|
+
var lr = vl(
|
|
640
|
+
Math.min(A, R) - Na,
|
|
641
|
+
Math.min(w, z) - Da,
|
|
642
|
+
Math.max(A, R) + ce,
|
|
643
|
+
Math.max(w, z) + Ve,
|
|
644
|
+
Yt
|
|
641
645
|
);
|
|
642
|
-
|
|
643
|
-
var
|
|
644
|
-
if (
|
|
645
|
-
var V,
|
|
646
|
-
if (
|
|
646
|
+
lr.push(oa), lr.push(la);
|
|
647
|
+
var I = [];
|
|
648
|
+
if (jt && Ne) {
|
|
649
|
+
var V, ul = er === "right" && U < c, sl = er === "left" && U > c;
|
|
650
|
+
if (ul || sl) {
|
|
647
651
|
V = (U + c) / 2;
|
|
648
|
-
var
|
|
649
|
-
if (
|
|
650
|
-
var
|
|
651
|
-
V <
|
|
652
|
+
var Xt = Sr(V, w, z, lr);
|
|
653
|
+
if (Xt) {
|
|
654
|
+
var Ht = y(Xt), Ir = Xt.width || L;
|
|
655
|
+
V < Ht.x + Ir / 2 ? V = Ht.x - m : V = Ht.x + Ir + m;
|
|
652
656
|
}
|
|
653
657
|
} else
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
var
|
|
657
|
-
if (
|
|
658
|
-
var
|
|
659
|
-
|
|
658
|
+
er === "right" ? V = Math.max(Mt.x + Na, kt.x + ce) + m : V = Math.min(Mt.x, kt.x) - m;
|
|
659
|
+
I = [{ x: U, y: w }, { x: V, y: w }, { x: V, y: z }, { x: c, y: z }];
|
|
660
|
+
var pt = Lr(V, c, z, lr);
|
|
661
|
+
if (pt) {
|
|
662
|
+
var De = y(pt), dl = pt.height || B, Oe = De.y - m, je = De.y + dl + m, Ye = Math.abs(w - Oe) <= Math.abs(w - je) ? Oe : je;
|
|
663
|
+
I = [
|
|
660
664
|
{ x: U, y: w },
|
|
661
665
|
{ x: V, y: w },
|
|
662
|
-
{ x: V, y:
|
|
663
|
-
{ x: c, y:
|
|
666
|
+
{ x: V, y: Ye },
|
|
667
|
+
{ x: c, y: Ye },
|
|
664
668
|
{ x: c, y: z }
|
|
665
669
|
];
|
|
666
670
|
}
|
|
667
|
-
var
|
|
668
|
-
if (
|
|
669
|
-
var
|
|
670
|
-
|
|
671
|
+
var re = Lr(U, V, w, lr);
|
|
672
|
+
if (re) {
|
|
673
|
+
var Xe = y(re), yl = re.height || B, He = Xe.y - m, pe = Xe.y + yl + m, ro = Math.abs(z - He) <= Math.abs(z - pe) ? He : pe;
|
|
674
|
+
I.splice(
|
|
671
675
|
1,
|
|
672
676
|
0,
|
|
673
677
|
{ x: U, y: ro },
|
|
674
678
|
{ x: V, y: ro }
|
|
675
|
-
),
|
|
676
|
-
return !(Math.abs(
|
|
677
|
-
}),
|
|
679
|
+
), I = I.filter(function(cr, No) {
|
|
680
|
+
return !(Math.abs(cr.x - V) < 1 && Math.abs(cr.y - w) < 1);
|
|
681
|
+
}), I.splice(0, 0, { x: U, y: w });
|
|
678
682
|
}
|
|
679
|
-
} else if (!
|
|
680
|
-
var N,
|
|
681
|
-
if (
|
|
682
|
-
N = (
|
|
683
|
-
var
|
|
684
|
-
if (
|
|
685
|
-
var
|
|
686
|
-
N <
|
|
683
|
+
} else if (!jt && !Ne) {
|
|
684
|
+
var N, xl = er === "bottom" && O < or, gl = er === "top" && O > or;
|
|
685
|
+
if (xl || gl) {
|
|
686
|
+
N = (O + or) / 2;
|
|
687
|
+
var ae = Lr(A, R, N, lr);
|
|
688
|
+
if (ae) {
|
|
689
|
+
var te = y(ae), ao = ae.height || B;
|
|
690
|
+
N < te.y + ao / 2 ? N = te.y - m : N = te.y + ao + m;
|
|
687
691
|
}
|
|
688
692
|
} else
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
var
|
|
692
|
-
if (
|
|
693
|
-
var
|
|
694
|
-
|
|
695
|
-
{ x:
|
|
696
|
-
{ x:
|
|
697
|
-
{ x:
|
|
693
|
+
er === "bottom" ? N = Math.max(Mt.y + Da, kt.y + Ve) + m : N = Math.min(Mt.y, kt.y) - m;
|
|
694
|
+
I = [{ x: A, y: O }, { x: A, y: N }, { x: R, y: N }, { x: R, y: or }];
|
|
695
|
+
var ee = Sr(A, O, N, lr);
|
|
696
|
+
if (ee) {
|
|
697
|
+
var to = y(ee), Ml = ee.width || L, eo = to.x - m, oo = to.x + Ml + m, lo = Math.abs(R - eo) <= Math.abs(R - oo) ? eo : oo;
|
|
698
|
+
I = [
|
|
699
|
+
{ x: A, y: O },
|
|
700
|
+
{ x: lo, y: O },
|
|
701
|
+
{ x: lo, y: N },
|
|
698
702
|
{ x: R, y: N },
|
|
699
|
-
{ x: R, y:
|
|
703
|
+
{ x: R, y: or }
|
|
700
704
|
];
|
|
701
705
|
}
|
|
702
|
-
var
|
|
703
|
-
if (
|
|
704
|
-
var
|
|
705
|
-
|
|
706
|
-
|
|
706
|
+
var oe = Sr(R, N, or, lr);
|
|
707
|
+
if (oe) {
|
|
708
|
+
var io = y(oe), kl = oe.height || B, fo = io.y - m, vo = io.y + kl + m, ml = Math.abs(N - fo) <= Math.abs(N - vo) ? fo : vo;
|
|
709
|
+
I.splice(
|
|
710
|
+
I.length - 1,
|
|
707
711
|
0,
|
|
708
|
-
{ x: c, y:
|
|
712
|
+
{ x: c, y: ml }
|
|
709
713
|
);
|
|
710
714
|
}
|
|
711
|
-
} else if (
|
|
712
|
-
|
|
713
|
-
var
|
|
714
|
-
if (
|
|
715
|
-
var ho = y(
|
|
716
|
-
|
|
715
|
+
} else if (jt) {
|
|
716
|
+
I = [{ x: U, y: w }, { x: R, y: w }, { x: R, y: or }];
|
|
717
|
+
var le = Sr(R, w, or, lr);
|
|
718
|
+
if (le) {
|
|
719
|
+
var ho = y(le), Tl = le.width || L, no = ho.x - m, uo = ho.x + Tl + m, so = Math.abs(A - no) <= Math.abs(A - uo) ? no : uo;
|
|
720
|
+
I = [{ x: U, y: w }, { x: so, y: w }, { x: so, y: z }, { x: R, y: z }, { x: R, y: or }];
|
|
717
721
|
}
|
|
718
|
-
var
|
|
719
|
-
if (
|
|
720
|
-
var yo = y(
|
|
721
|
-
|
|
722
|
+
var ie = Lr(U, R, w, lr);
|
|
723
|
+
if (ie) {
|
|
724
|
+
var yo = y(ie), Rl = ie.height || B, xo = yo.y - m, go = yo.y + Rl + m, Mo = Math.abs(z - xo) <= Math.abs(z - go) ? xo : go;
|
|
725
|
+
I = [{ x: U, y: w }, { x: U, y: Mo }, { x: R, y: Mo }, { x: R, y: or }];
|
|
722
726
|
}
|
|
723
727
|
} else {
|
|
724
|
-
|
|
725
|
-
var
|
|
726
|
-
if (
|
|
727
|
-
var ko = y(
|
|
728
|
-
|
|
728
|
+
I = [{ x: A, y: O }, { x: A, y: z }, { x: c, y: z }];
|
|
729
|
+
var fe = Lr(A, c, z, lr);
|
|
730
|
+
if (fe) {
|
|
731
|
+
var ko = y(fe), zl = fe.height || B, mo = ko.y - m, To = ko.y + zl + m, Ro = Math.abs(w - mo) <= Math.abs(w - To) ? mo : To;
|
|
732
|
+
I = [{ x: A, y: O }, { x: A, y: Ro }, { x: c, y: Ro }, { x: c, y: z }];
|
|
729
733
|
}
|
|
730
|
-
var
|
|
731
|
-
if (
|
|
732
|
-
var zo = y(
|
|
733
|
-
|
|
734
|
+
var ve = Sr(A, O, z, lr);
|
|
735
|
+
if (ve) {
|
|
736
|
+
var zo = y(ve), wl = ve.width || L, wo = zo.x - m, Bo = zo.x + wl + m, Ao = Math.abs(R - wo) <= Math.abs(R - Bo) ? wo : Bo;
|
|
737
|
+
I = [{ x: A, y: O }, { x: Ao, y: O }, { x: Ao, y: z }, { x: c, y: z }];
|
|
734
738
|
}
|
|
735
739
|
}
|
|
736
|
-
for (var
|
|
737
|
-
|
|
738
|
-
for (var
|
|
739
|
-
var
|
|
740
|
-
(Math.abs(
|
|
740
|
+
for (var ia = [{ x: A, y: w }], he = 0; he < I.length; he++) ia.push(I[he]);
|
|
741
|
+
ia.push({ x: R, y: z });
|
|
742
|
+
for (var ir = [ia[0]], Oa = 1; Oa < ia.length; Oa++) {
|
|
743
|
+
var ja = ir[ir.length - 1];
|
|
744
|
+
(Math.abs(ia[Oa].x - ja.x) > 0.1 || Math.abs(ia[Oa].y - ja.y) > 0.1) && ir.push(ia[Oa]);
|
|
741
745
|
}
|
|
742
|
-
var _o =
|
|
743
|
-
J.moveTo(
|
|
744
|
-
for (var rr = 1; rr <
|
|
745
|
-
if (_o > 0 && rr > 0 && rr <
|
|
746
|
-
var
|
|
747
|
-
if (Math.abs(
|
|
746
|
+
var _o = gr === "smoothstep" ? 8 : 0;
|
|
747
|
+
J.moveTo(ir[0].x, ir[0].y);
|
|
748
|
+
for (var rr = 1; rr < ir.length; rr++)
|
|
749
|
+
if (_o > 0 && rr > 0 && rr < ir.length - 1) {
|
|
750
|
+
var wr = ir[rr - 1], S = ir[rr], Kr = ir[rr + 1];
|
|
751
|
+
if (Math.abs(wr.x - S.x) < 0.5 && Math.abs(S.x - Kr.x) < 0.5 || Math.abs(wr.y - S.y) < 0.5 && Math.abs(S.y - Kr.y) < 0.5)
|
|
748
752
|
J.lineTo(S.x, S.y);
|
|
749
753
|
else {
|
|
750
|
-
var
|
|
751
|
-
Math.abs(
|
|
754
|
+
var mt = Math.min(Math.hypot(wr.x - S.x, wr.y - S.y) / 2, Math.hypot(S.x - Kr.x, S.y - Kr.y) / 2, _o);
|
|
755
|
+
Math.abs(wr.y - S.y) < 0.5 ? (J.lineTo(S.x + (wr.x < Kr.x ? -1 : 1) * mt, S.y), J.quadraticCurveTo(S.x, S.y, S.x, S.y + (wr.y < Kr.y ? 1 : -1) * mt)) : (J.lineTo(S.x, S.y + (wr.y < Kr.y ? -1 : 1) * mt), J.quadraticCurveTo(S.x, S.y, S.x + (wr.x < Kr.x ? 1 : -1) * mt, S.y));
|
|
752
756
|
}
|
|
753
757
|
} else
|
|
754
|
-
J.lineTo(
|
|
755
|
-
} catch (
|
|
756
|
-
console.error("[worker] smoothstep error:",
|
|
758
|
+
J.lineTo(ir[rr].x, ir[rr].y);
|
|
759
|
+
} catch (cr) {
|
|
760
|
+
console.error("[worker] smoothstep error:", cr, "edge:", D.id);
|
|
757
761
|
}
|
|
758
762
|
else {
|
|
759
|
-
var
|
|
760
|
-
|
|
761
|
-
var
|
|
762
|
-
J.moveTo(
|
|
763
|
+
var br = xt.position || "right", Jr = gt.position || "left", Qr = 20, Ya = A, Tt = w, Xa = R, Rt = z;
|
|
764
|
+
br === "right" ? Ya += Qr : br === "left" ? Ya -= Qr : br === "bottom" ? Tt += Qr : br === "top" && (Tt -= Qr), Jr === "right" ? Xa += Qr : Jr === "left" ? Xa -= Qr : Jr === "bottom" ? Rt += Qr : Jr === "top" && (Rt -= Qr);
|
|
765
|
+
var Bl = Math.abs(Xa - Ya), $r = Math.max(50, Bl * 0.5), Al = Ya + (br === "left" ? -$r : br === "right" ? $r : 0), _l = Tt + (br === "top" ? -$r : br === "bottom" ? $r : 0), El = Xa + (Jr === "left" ? -$r : Jr === "right" ? $r : 0), Ll = Rt + (Jr === "top" ? -$r : Jr === "bottom" ? $r : 0);
|
|
766
|
+
J.moveTo(A, w), J.lineTo(Ya, Tt), J.bezierCurveTo(Al, _l, El, Ll, Xa, Rt), J.lineTo(R, z);
|
|
763
767
|
}
|
|
764
|
-
if (
|
|
765
|
-
var
|
|
768
|
+
if (hl) {
|
|
769
|
+
var Sl = 8, Ha;
|
|
766
770
|
if (Q && Q.length >= 2) {
|
|
767
|
-
var
|
|
768
|
-
|
|
769
|
-
} else if (
|
|
770
|
-
|
|
771
|
-
else if (
|
|
772
|
-
|
|
771
|
+
var ja = Q[Q.length - 1], Eo = Q[Q.length - 2];
|
|
772
|
+
Ha = Math.atan2(ja.y - Eo.y, ja.x - Eo.x);
|
|
773
|
+
} else if (gr === "straight")
|
|
774
|
+
Ha = Math.atan2(z - w, R - A);
|
|
775
|
+
else if (gr === "step" || gr === "smoothstep")
|
|
776
|
+
Ha = 0;
|
|
773
777
|
else {
|
|
774
|
-
var Lo =
|
|
775
|
-
|
|
778
|
+
var Lo = Je(A, w, R, z);
|
|
779
|
+
Ha = Math.atan2(z - Lo.cp2y, R - Lo.cp2x);
|
|
776
780
|
}
|
|
777
|
-
var So = Q && Q.length >= 2 ? Q[Q.length - 1] : { x: R, y: z },
|
|
778
|
-
|
|
781
|
+
var So = Q && Q.length >= 2 ? Q[Q.length - 1] : { x: R, y: z }, ne = { x: So.x, y: So.y, angle: Ha, size: Sl };
|
|
782
|
+
Fe ? Ua.push(ne) : Ue ? ta.push(ne) : Fa.push(ne);
|
|
779
783
|
}
|
|
780
|
-
if (
|
|
781
|
-
var
|
|
782
|
-
Q && Q.length >= 2 ?
|
|
784
|
+
if (st && D.label) {
|
|
785
|
+
var pa;
|
|
786
|
+
Q && Q.length >= 2 ? pa = ri(Q) : gr === "straight" || gr === "step" || gr === "smoothstep" ? pa = { x: (A + R) / 2, y: (w + z) / 2 } : pa = ai(A, w, R, z), xr.push({ text: D.label, x: pa.x, y: pa.y });
|
|
783
787
|
}
|
|
784
788
|
}
|
|
785
789
|
}
|
|
786
|
-
if (
|
|
787
|
-
r.font =
|
|
788
|
-
for (var
|
|
789
|
-
var
|
|
790
|
-
r.fillStyle = F ? "#2a2a2a" : "#ffffff", r.fillRect(
|
|
790
|
+
if (Zr && (r.strokeStyle = k.edgeStroke, r.lineWidth = 1.5, r.setLineDash([]), r.stroke(Zr)), yr && (r.strokeStyle = k.edgeAnimated, r.lineWidth = 1.5, r.setLineDash([5, 5]), r.lineDashOffset = -be, r.stroke(yr), r.setLineDash([])), zr && (r.strokeStyle = k.edgeSelected, r.lineWidth = 2.5, r.setLineDash([]), r.stroke(zr)), qt(Fa, k.edgeStroke), qt(ta, k.edgeAnimated), qt(Ua, k.edgeSelected), xr.length > 0) {
|
|
791
|
+
r.font = Yl, r.textAlign = "center", r.textBaseline = "middle";
|
|
792
|
+
for (var ue = 0; ue < xr.length; ue++) {
|
|
793
|
+
var Ca = xr[ue], Cl = r.measureText(Ca.text), Co = Cl.width + 12;
|
|
794
|
+
r.fillStyle = F ? "#2a2a2a" : "#ffffff", r.fillRect(Ca.x - Co / 2, Ca.y - 9, Co, 18), r.fillStyle = k.nodeText, r.fillText(Ca.text, Ca.x, Ca.y);
|
|
791
795
|
}
|
|
792
796
|
r.textAlign = "start", r.textBaseline = "alphabetic";
|
|
793
797
|
}
|
|
794
798
|
}
|
|
795
|
-
if (
|
|
799
|
+
if (lt) {
|
|
796
800
|
r.beginPath(), r.strokeStyle = k.connectionLine, r.lineWidth = 2, r.setLineDash([6, 4]);
|
|
797
|
-
var
|
|
798
|
-
if (
|
|
801
|
+
var se = lt._routedPoints;
|
|
802
|
+
if (se && se.length >= 2) {
|
|
799
803
|
var Wo = new Path2D();
|
|
800
|
-
|
|
804
|
+
al(Wo, se), r.stroke(Wo);
|
|
801
805
|
} else {
|
|
802
|
-
var
|
|
803
|
-
r.moveTo(
|
|
806
|
+
var zt = lt.from, wt = lt.to, Bt = Je(zt.x, zt.y, wt.x, wt.y);
|
|
807
|
+
r.moveTo(zt.x, zt.y), r.bezierCurveTo(Bt.cp1x, Bt.cp1y, Bt.cp2x, Bt.cp2y, wt.x, wt.y), r.stroke();
|
|
804
808
|
}
|
|
805
809
|
r.setLineDash([]);
|
|
806
810
|
}
|
|
807
|
-
if (
|
|
808
|
-
var Po = Math.min(
|
|
809
|
-
r.fillStyle = F ? "rgba(59,130,246,0.08)" : "rgba(59,130,246,0.06)", r.fillRect(Po, qo,
|
|
811
|
+
if (Tr) {
|
|
812
|
+
var Po = Math.min(Tr.startWorld.x, Tr.endWorld.x), qo = Math.min(Tr.startWorld.y, Tr.endWorld.y), Na = Math.abs(Tr.endWorld.x - Tr.startWorld.x), Da = Math.abs(Tr.endWorld.y - Tr.startWorld.y);
|
|
813
|
+
r.fillStyle = F ? "rgba(59,130,246,0.08)" : "rgba(59,130,246,0.06)", r.fillRect(Po, qo, Na, Da), r.strokeStyle = "#3b82f6", r.lineWidth = 1 / M.zoom, r.setLineDash([]), r.strokeRect(Po, qo, Na, Da);
|
|
810
814
|
}
|
|
811
|
-
if (
|
|
812
|
-
var Go =
|
|
813
|
-
if (
|
|
814
|
-
|
|
815
|
-
for (var
|
|
816
|
-
var
|
|
817
|
-
|
|
815
|
+
if (dr > 0) {
|
|
816
|
+
var Go = Ia > 0, fa = M.zoom > 0.12 && (M.zoom > 0.25 || dr < 500), de = !Go && M.zoom > 0.08 && dr < 200, Wl = !Go && M.zoom > 0.2 && dr < 300, Pl = Object.keys(It).length > 0 || Object.keys(it).length > 0 || Object.keys(Zt).length > 0, Fr = nr, At = [], _t = [];
|
|
817
|
+
if (Pl) {
|
|
818
|
+
Fr = [];
|
|
819
|
+
for (var ye = 0; ye < dr; ye++) {
|
|
820
|
+
var Ur = nr[ye];
|
|
821
|
+
it[Ur.id] || Ur.type && It[Ur.type] ? At.push(Ur) : Ur.type && Zt[Ur.type] ? _t.push(Ur) : Fr.push(Ur);
|
|
818
822
|
}
|
|
819
823
|
}
|
|
820
|
-
var
|
|
821
|
-
if (
|
|
824
|
+
var rt = Fr.length;
|
|
825
|
+
if (de) {
|
|
822
826
|
r.shadowColor = k.nodeShadow, r.shadowBlur = 6, r.shadowOffsetY = 2, r.fillStyle = k.nodeBg, r.beginPath();
|
|
823
|
-
for (var
|
|
824
|
-
var
|
|
825
|
-
r.roundRect(y(
|
|
827
|
+
for (var xe = 0; xe < rt; xe++) {
|
|
828
|
+
var Et = Fr[xe];
|
|
829
|
+
r.roundRect(y(Et).x, y(Et).y, Et.width || L, Et.height || B, Ga);
|
|
826
830
|
}
|
|
827
831
|
r.fill(), r.shadowColor = "transparent", r.shadowBlur = 0, r.shadowOffsetY = 0;
|
|
828
832
|
}
|
|
829
|
-
if (!
|
|
833
|
+
if (!de) {
|
|
830
834
|
r.fillStyle = k.nodeBg, r.beginPath();
|
|
831
|
-
for (var
|
|
832
|
-
var
|
|
833
|
-
r.roundRect(y(
|
|
835
|
+
for (var ge = 0; ge < rt; ge++) {
|
|
836
|
+
var Lt = Fr[ge];
|
|
837
|
+
r.roundRect(y(Lt).x, y(Lt).y, Lt.width || L, Lt.height || B, Ga);
|
|
834
838
|
}
|
|
835
839
|
r.fill();
|
|
836
840
|
}
|
|
837
841
|
r.strokeStyle = k.nodeBorder, r.lineWidth = 1, r.beginPath();
|
|
838
|
-
for (var
|
|
839
|
-
var
|
|
840
|
-
|
|
842
|
+
for (var Me = 0; Me < rt; Me++) {
|
|
843
|
+
var at = Fr[Me];
|
|
844
|
+
at.selected || r.roundRect(y(at).x, y(at).y, at.width || L, at.height || B, Ga);
|
|
841
845
|
}
|
|
842
846
|
r.stroke();
|
|
843
847
|
var Io = !1;
|
|
844
848
|
r.strokeStyle = k.nodeSelectedBorder, r.lineWidth = 2, r.beginPath();
|
|
845
|
-
for (var
|
|
846
|
-
var
|
|
847
|
-
|
|
849
|
+
for (var ke = 0; ke < rt; ke++) {
|
|
850
|
+
var tt = Fr[ke];
|
|
851
|
+
tt.selected && (Io = !0, r.roundRect(y(tt).x, y(tt).y, tt.width || L, tt.height || B, Ga));
|
|
848
852
|
}
|
|
849
|
-
if (Io && r.stroke(),
|
|
853
|
+
if (Io && r.stroke(), fa) {
|
|
850
854
|
r.fillStyle = k.nodeText, r.font = Oo, r.textAlign = "center", r.textBaseline = "middle";
|
|
851
|
-
for (var
|
|
852
|
-
var
|
|
853
|
-
if (!(!
|
|
854
|
-
var Zo =
|
|
855
|
-
r.fillText(
|
|
855
|
+
for (var me = 0; me < rt; me++) {
|
|
856
|
+
var va = Fr[me];
|
|
857
|
+
if (!(!va.data || !va.data.label)) {
|
|
858
|
+
var Zo = va.width || L, ql = va.height || B;
|
|
859
|
+
r.fillText(va.data.label, y(va).x + Zo / 2, y(va).y + ql / 2, Zo - 24);
|
|
856
860
|
}
|
|
857
861
|
}
|
|
858
862
|
r.textAlign = "start", r.textBaseline = "alphabetic";
|
|
859
863
|
}
|
|
860
|
-
for (var
|
|
861
|
-
var
|
|
862
|
-
Ko && r.drawImage(Ko,
|
|
864
|
+
for (var Te = 0; Te < At.length; Te++) {
|
|
865
|
+
var Mr = At[Te], Wa = y(Mr), St = Mr.width || L, Re = Mr.height || B, Ko = it[Mr.id] && tl[it[Mr.id]] || It[Mr.type];
|
|
866
|
+
Ko && r.drawImage(Ko, Wa.x, Wa.y, St, Re), fa && Mr.data && Mr.data.label && (r.fillStyle = k.nodeText, r.font = Oo, r.textAlign = "center", r.textBaseline = "middle", r.fillText(Mr.data.label, Wa.x + St / 2, Wa.y + Re / 2, St - 24)), Mr.selected && (r.strokeStyle = k.nodeSelectedBorder, r.lineWidth = 2, r.beginPath(), r.roundRect(Wa.x, Wa.y, St, Re, Ga), r.stroke());
|
|
863
867
|
}
|
|
864
|
-
|
|
865
|
-
for (var
|
|
866
|
-
var
|
|
867
|
-
if (
|
|
868
|
-
var
|
|
869
|
-
r.fillStyle =
|
|
870
|
-
var
|
|
871
|
-
r.beginPath(),
|
|
872
|
-
}
|
|
873
|
-
if (
|
|
874
|
-
var
|
|
868
|
+
At.length > 0 && fa && (r.textAlign = "start", r.textBaseline = "alphabetic");
|
|
869
|
+
for (var ze = 0; ze < _t.length; ze++) {
|
|
870
|
+
var ha = _t[ze], G = Zt[ha.type], E = y(ha), Br = ha.width || L, na = ha.height || B, ur = G.radius || Ga, Ct = ha.data || {};
|
|
871
|
+
if (de && G.shadow !== !1 && (r.save(), r.shadowColor = G.shadowColor || k.nodeShadow, r.shadowBlur = G.shadowBlur || 6, r.shadowOffsetY = G.shadowOffsetY || 2, r.fillStyle = G.fill || k.nodeBg, r.beginPath(), r.roundRect(E.x, E.y, Br, na, ur), r.fill(), r.restore()), r.fillStyle = G.fill || k.nodeBg, r.beginPath(), r.roundRect(E.x, E.y, Br, na, ur), r.fill(), r.strokeStyle = ha.selected ? k.nodeSelectedBorder : G.stroke || k.nodeBorder, r.lineWidth = ha.selected ? 2 : G.strokeWidth || 1, r.beginPath(), r.roundRect(E.x, E.y, Br, na, ur), r.stroke(), G.accent) {
|
|
872
|
+
var et = G.accent;
|
|
873
|
+
r.fillStyle = et.color || "#3b82f6";
|
|
874
|
+
var Pa = et.width || 5;
|
|
875
|
+
r.beginPath(), et.side === "right" ? r.roundRect(E.x + Br - Pa, E.y, Pa, na, [0, ur, ur, 0]) : et.side === "top" ? r.roundRect(E.x, E.y, Br, Pa, [ur, ur, 0, 0]) : et.side === "bottom" ? r.roundRect(E.x, E.y + na - Pa, Br, Pa, [0, 0, ur, ur]) : r.roundRect(E.x, E.y, Pa, na, [ur, 0, 0, ur]), r.fill();
|
|
876
|
+
}
|
|
877
|
+
if (G.icon && fa) {
|
|
878
|
+
var Ar = G.icon, bo = Ar.dataField ? Ct[Ar.dataField] : Ar.text;
|
|
875
879
|
if (bo) {
|
|
876
|
-
r.font = (
|
|
877
|
-
var
|
|
878
|
-
r.fillText(bo,
|
|
880
|
+
r.font = (Ar.size || 18) + "px system-ui, sans-serif", r.textAlign = "center", r.textBaseline = "middle", r.fillStyle = Ar.color || k.nodeText;
|
|
881
|
+
var Gl = E.x + (Ar.x !== void 0 ? Ar.x : 20), Il = E.y + (Ar.y !== void 0 ? Ar.y : na / 2);
|
|
882
|
+
r.fillText(bo, Gl, Il);
|
|
879
883
|
}
|
|
880
884
|
}
|
|
881
|
-
if (
|
|
882
|
-
var
|
|
885
|
+
if (G.title && fa) {
|
|
886
|
+
var kr = G.title, Jo = kr.dataField ? Ct[kr.dataField] : kr.text;
|
|
883
887
|
if (Jo) {
|
|
884
|
-
r.font =
|
|
885
|
-
var Qo = E.x + (
|
|
886
|
-
r.fillText(Jo, Qo,
|
|
888
|
+
r.font = kr.font || "600 13px system-ui, sans-serif", r.textAlign = kr.align || "left", r.textBaseline = "top", r.fillStyle = kr.color || k.nodeText;
|
|
889
|
+
var Qo = E.x + (kr.x !== void 0 ? kr.x : 12), Zl = E.y + (kr.y !== void 0 ? kr.y : 12);
|
|
890
|
+
r.fillText(Jo, Qo, Zl, Br - Qo + E.x - 12);
|
|
887
891
|
}
|
|
888
892
|
}
|
|
889
|
-
if (
|
|
890
|
-
var
|
|
893
|
+
if (G.subtitle && fa) {
|
|
894
|
+
var mr = G.subtitle, $o = mr.dataField ? Ct[mr.dataField] : mr.text;
|
|
891
895
|
if ($o) {
|
|
892
|
-
r.font =
|
|
893
|
-
var Fo = E.x + (
|
|
894
|
-
r.fillText($o, Fo,
|
|
896
|
+
r.font = mr.font || "11px system-ui, sans-serif", r.textAlign = mr.align || "left", r.textBaseline = "top", r.fillStyle = mr.color || "#64748b";
|
|
897
|
+
var Fo = E.x + (mr.x !== void 0 ? mr.x : 12), Kl = E.y + (mr.y !== void 0 ? mr.y : 32);
|
|
898
|
+
r.fillText($o, Fo, Kl, Br - Fo + E.x - 12);
|
|
895
899
|
}
|
|
896
900
|
}
|
|
897
|
-
if (
|
|
898
|
-
var
|
|
899
|
-
if (
|
|
900
|
-
r.font =
|
|
901
|
-
var
|
|
902
|
-
r.fillStyle =
|
|
901
|
+
if (G.badge && fa) {
|
|
902
|
+
var _r = G.badge, we = _r.dataField ? Ct[_r.dataField] : _r.text;
|
|
903
|
+
if (we) {
|
|
904
|
+
r.font = _r.font || "700 9px system-ui, sans-serif";
|
|
905
|
+
var bl = r.measureText(we), Jl = _r.paddingX || 6, Ql = _r.paddingY || 3, Be = bl.width + Jl * 2, Ae = 14 + Ql, Uo = E.x + Br - Be / 2 - 4, co = E.y - Ae / 2;
|
|
906
|
+
r.fillStyle = _r.bg || "#3b82f6", r.beginPath(), r.roundRect(Uo, co, Be, Ae, _r.radius || 7), r.fill(), r.fillStyle = _r.color || "#fff", r.textAlign = "center", r.textBaseline = "middle", r.fillText(we, Uo + Be / 2, co + Ae / 2);
|
|
903
907
|
}
|
|
904
908
|
}
|
|
905
909
|
}
|
|
906
|
-
if (
|
|
907
|
-
for (var
|
|
908
|
-
for (var Vo =
|
|
909
|
-
|
|
910
|
+
if (_t.length > 0 && (r.textAlign = "start", r.textBaseline = "alphabetic"), Wl) {
|
|
911
|
+
for (var _e = [], Ee = 0; Ee < dr; Ee++)
|
|
912
|
+
for (var Vo = el(nr[Ee]), Le = 0; Le < Vo.length; Le++)
|
|
913
|
+
_e.push(Vo[Le]);
|
|
910
914
|
r.fillStyle = k.handleFill, r.beginPath();
|
|
911
|
-
for (var
|
|
912
|
-
var
|
|
913
|
-
r.moveTo(
|
|
915
|
+
for (var Se = 0; Se < _e.length; Se++) {
|
|
916
|
+
var Wt = _e[Se];
|
|
917
|
+
r.moveTo(Wt.x + Do, Wt.y), r.arc(Wt.x, Wt.y, Do, 0, 6.2832);
|
|
914
918
|
}
|
|
915
919
|
r.fill(), r.strokeStyle = k.handleBorder, r.lineWidth = 1.5, r.stroke();
|
|
916
920
|
}
|
|
917
921
|
}
|
|
918
922
|
r.restore();
|
|
919
|
-
var $
|
|
920
|
-
|
|
921
|
-
var
|
|
922
|
-
if (
|
|
923
|
-
po =
|
|
924
|
-
var
|
|
923
|
+
var $l = (performance.now() - a).toFixed(1);
|
|
924
|
+
qe++;
|
|
925
|
+
var Pt = performance.now();
|
|
926
|
+
if (Pt - Xo >= 1e3 && (Ho = qe, qe = 0, Xo = Pt), Pt - po >= 100) {
|
|
927
|
+
po = Pt;
|
|
928
|
+
var Fl = Math.round(-M.x / M.zoom), Ul = Math.round(-M.y / M.zoom);
|
|
925
929
|
self.postMessage({
|
|
926
930
|
type: "hud",
|
|
927
931
|
data: {
|
|
928
|
-
wx:
|
|
929
|
-
wy:
|
|
932
|
+
wx: Fl,
|
|
933
|
+
wy: Ul,
|
|
930
934
|
zoom: M.zoom.toFixed(2),
|
|
931
|
-
renderMs: $
|
|
935
|
+
renderMs: $l,
|
|
932
936
|
fps: Ho,
|
|
933
|
-
visible:
|
|
934
|
-
nodeCount:
|
|
935
|
-
visibleNodes:
|
|
936
|
-
edgeCount:
|
|
937
|
+
visible: Y.length > 0 ? jo(X, Yr, xa, Xr).length : 0,
|
|
938
|
+
nodeCount: W.length,
|
|
939
|
+
visibleNodes: dr,
|
|
940
|
+
edgeCount: C.length
|
|
937
941
|
}
|
|
938
942
|
});
|
|
939
943
|
}
|
|
940
944
|
}
|
|
941
945
|
}
|
|
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;
|
|
946
|
+
`,lr=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",wr],{type:"text/javascript;charset=utf-8"});function eo(e){let t;try{if(t=lr&&(self.URL||self.webkitURL).createObjectURL(lr),!t)throw"";const n=new Worker(t,{type:"module",name:e==null?void 0:e.name});return n.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),n}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(wr),{type:"module",name:e==null?void 0:e.name})}}const Xn=new WeakMap;function to(e,t){if(Xn.has(e))return Xn.get(e);const n=e.transferControlToOffscreen(),r=new eo;r.onerror=o=>console.error("[infinite-canvas] worker error:",o.message,o),r.postMessage({type:"init",data:{...t,canvas:n}},[n]);const i={worker:r};return Xn.set(e,i),i}const lt=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:O,onPaneMouseEnter:_,onPaneMouseMove:w,onPaneMouseLeave:g,onSelectionChange:v,onConnectStart:N,onConnectEnd:I,onInit:$,onMoveStart:V,onMove:se,onMoveEnd:te,onDelete:ce,onBeforeDelete:pe,onError:me,isValidConnection:ye,dark:le,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:Ke=!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:ln=!0,zoomOnDoubleClick:un=!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),Oe=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}),[Ot,xn]=a.useState(null),xt=a.useMemo(()=>new Set,[]),ot=a.useMemo(()=>new Set,[]),Ve=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:O,onPaneMouseEnter:_,onPaneMouseMove:w,onPaneMouseLeave:g,onSelectionChange:v,onConnectStart:N,onConnectEnd:I,onInit:$,onMoveStart:V,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 u=l=>{l.key===ze&&(hn.current=!0),l.key===kt&&(Ve.current=!0)},y=l=>{l.key===ze&&(hn.current=!1),l.key===kt&&(Ve.current=!1)};return window.addEventListener("keydown",u),window.addEventListener("keyup",y),()=>{window.removeEventListener("keydown",u),window.removeEventListener("keyup",y)}},[ze,kt]);const Ee={get current(){return J.current.onNodesChange?ut:null}},ut=u=>{var l,p,k;(p=(l=J.current).onNodesChange)==null||p.call(l,u);const y=[];for(let E=0;E<u.length;E++)u[E].type==="select"&&y.push({id:u[E].id,selected:u[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=u=>{var l,p,k;(p=(l=J.current).onEdgesChange)==null||p.call(l,u);const y=[];for(let E=0;E<u.length;E++)u[E].type==="select"&&y.push({id:u[E].id,selected:u[E].selected});y.length>0&&((k=Ne.current)==null||k.postMessage({type:"edgeSelections",data:{selections:y}}))},dt=a.useCallback(()=>{var p;const u=ee.current.filter(k=>k.selected),y=Pe.current.filter(k=>k.selected),l={nodes:u,edges:y};(p=Dt.current)==null||p.call(Dt,l);for(const k of ot)k(l)},[ot]);a.useEffect(()=>{var u;yt.current=[...e],(u=Ne.current)==null||u.postMessage({type:"cards",data:{cards:[...e]}})},[e]);const Wt=a.useCallback(u=>{const y={};for(const l of u)y[l.id]=l;return u.map(l=>{if(!l.parentId)return l;const p=y[l.parentId];if(!p)return l;let k=l.position.x,E=l.position.y,x=p;for(;x;)k+=x.position.x,E+=x.position.y,x=x.parentId?y[x.parentId]:null;return{...l,_absolutePosition:{x:k,y:E}}})},[]),it=a.useRef([]),mt=a.useCallback(u=>{const y=fn.current;if(!y||y.size===0)return u;const l={};for(const[,p]of y)l[p.nodeId]||(l[p.nodeId]=[]),l[p.nodeId].push({id:p.id,type:p.type,position:p.position,x:p.x,y:p.y});return u.map(p=>{const k=l[p.id];return k&&k.length>0?{...p,handles:k}:p})},[]),pn=a.useCallback(()=>{var y;if(We.current)return;const u=mt(it.current);(y=Ne.current)==null||y.postMessage({type:"nodes",data:{nodes:u}})},[mt]);a.useEffect(()=>{var l,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);(l=Ne.current)==null||l.postMessage({type:"nodes",data:{nodes:M}});return}ee.current=[...t];const u=Wt(t);it.current=u;const y=mt(u);(p=Ne.current)==null||p.postMessage({type:"nodes",data:{nodes:y}})},[t,Wt,mt]),a.useEffect(()=>{var u;Pe.current=[...n],(u=Ne.current)==null||u.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const Be=a.useCallback((u,y)=>{const l=we.current;if(!l)return{x:0,y:0};const p=l.getBoundingClientRect(),k=fe.current;return{x:(u-p.left-k.x)/k.zoom,y:(y-p.top-k.y)/k.zoom}},[]),ue=a.useCallback((u,y)=>{const l=it.current.length>0?it.current:ee.current;let p=null;for(let k=l.length-1;k>=0;k--){const E=l[k];if(E.hidden||E._customRendered)continue;const x=E._absolutePosition||E.position,M=E.width||lt,R=E.height||et;if(u>=x.x&&u<=x.x+M&&y>=x.y&&y<=x.y+R){if(E.type==="group"){p||(p=E);continue}return E}}return p},[]),Ut=a.useCallback((u,y)=>{const l=y.width||lt,p=y.height||et;if(u.x!==void 0&&u.y!==void 0)return{x:y.position.x+u.x,y:y.position.y+u.y};switch(u.position||(u.type==="source"?"right":"left")){case"top":return{x:y.position.x+l/2,y:y.position.y};case"bottom":return{x:y.position.x+l/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+l,y:y.position.y+p/2};default:return{x:y.position.x+l,y:y.position.y+p/2}}},[]),qt=a.useCallback(u=>{const y=u.width||lt,l=u.height||et;if(u.handles&&u.handles.length>0)return u.handles.map(R=>{const W=Ut(R,u);return{id:R.id||null,type:R.type,x:W.x,y:W.y}});const p=u.targetPosition||"left",k=u.sourcePosition||"right",E=R=>{switch(R){case"top":return{x:u.position.x+y/2,y:u.position.y};case"bottom":return{x:u.position.x+y/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+y,y:u.position.y+l/2};default:return{x:u.position.x+y,y:u.position.y+l/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}]},[Ut]),vt=a.useCallback((u,y)=>{const l=ee.current,p=fe.current,k=Math.max(no,Te)/p.zoom;for(let E=l.length-1;E>=0;E--){const x=l[E];if(x.hidden)continue;const M=qt(x);for(const R of M)if(Math.abs(u-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((u,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||lt,U=R.height||et,G=W.height||et,Z=R.position.x+L,ie=R.position.y+U/2,K=W.position.x,ae=W.position.y+G/2;if(ro(u,y,Z,ie,K,ae)<p)return M}return null},[]);a.useEffect(()=>{const u=Nt.current,y=we.current;if(!u||!y)return;const l=y.getBoundingClientRect(),p=le!==void 0?le:matchMedia("(prefers-color-scheme: dark)").matches,k=Wt(ee.current);it.current=k;const E=mt(k),{worker:x}=to(u,{width:l.width,height:l.height,camera:fe.current,cards:yt.current,nodes:E,edges:Pe.current,dark:p,gridSize:Ce,edgeRouting:bt});x.onmessage=L=>{var U,G,Z,ie;L.data.type==="hud"&&((U=Ht.current)==null||U.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 U,G;(G=(U=J.current).onError)==null||G.call(U,"worker-error",L.message||"Canvas worker crashed")},Ne.current=x;const M=new ResizeObserver(L=>{const{width:U,height:G}=L[0].contentRect;x.postMessage({type:"resize",data:{width:U,height:G}})});M.observe(y);let R,W;return le===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 u;le!==void 0&&((u=Ne.current)==null||u.postMessage({type:"theme",data:{dark:le}}))},[le]),a.useEffect(()=>{var u;(u=Ne.current)==null||u.postMessage({type:"edgeRouting",data:{enabled:bt}})},[bt]);const Zt=a.useRef(0),Re=a.useCallback((u=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,U=-ht[0][1]*y.zoom;y.x=Math.min(L,Math.max(R,y.x)),y.y=Math.min(U,Math.max(W,y.y))}}(p=Ne.current)==null||p.postMessage({type:"camera",data:{camera:{...y}}});const l={x:y.x,y:y.y,zoom:y.zoom};(E=(k=J.current).onMove)==null||E.call(k,u,l);for(const x of xt)x(l);cancelAnimationFrame(Zt.current),Zt.current=requestAnimationFrame(()=>{yn({x:y.x,y:y.y,zoom:y.zoom})})},[xt,ht]),at=a.useCallback(()=>{var l,p;const u=Oe.current,y=Lt.current;u&&y?((l=Ne.current)==null||l.postMessage({type:"connecting",data:{from:u.startPos,to:y,_routedPoints:null}}),xn({source:u.sourceId,sourceHandle:u.sourceHandle,target:null,targetHandle:null})):((p=Ne.current)==null||p.postMessage({type:"connecting",data:null}),xn(null))},[]),ct=a.useCallback(()=>{var y,l;const u=rt.current;u?(y=Ne.current)==null||y.postMessage({type:"selectionBox",data:u}):(l=Ne.current)==null||l.postMessage({type:"selectionBox",data:null})},[]),Gt=a.useCallback(u=>{var x,M,R,W,L,U,G,Z,ie,K,ae,ke,Ae,Fe,Ge,Ue,Jt,ft;const y=ee.current.length>0,l=Be(u.clientX,u.clientY),p=hn.current;if(y&&$e&&!p){const Q=vt(l.x,l.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,u,{nodeId:Q.nodeId,handleId:Q.handleId,handleType:Q.type});return}Oe.current={sourceId:Q.nodeId,sourceHandle:Q.handleId||null,sourceType:Q.type,startPos:{x:Q.x,y:Q.y}},Lt.current={x:l.x,y:l.y},(W=we.current)==null||W.setPointerCapture(u.pointerId),(U=(L=J.current).onConnectStart)==null||U.call(L,u,{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=ue(l.x,l.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,u,Q),he&&!k(u.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||lt,Vt=ge.height||et,vn=Q.width||((Z=Q.measured)==null?void 0:Z.width)||lt,Kt=Q.height||((ie=Q.measured)==null?void 0:ie.height)||et;oe={minX:0,minY:0,maxX:Qe-vn,maxY:Vt-Kt}}}if(We.current={id:Q.id,startPos:{...Q.position},startMouse:{x:l.x,y:l.y},parentClamp:oe,parentId:Q.parentId||null,selectedStarts:be?ee.current.filter(ge=>ge.selected&&ge.id!==Q.id).map(ge=>{var Vt,vn;let Qe=null;if(ge.parentId&&ge.extent==="parent"){const Kt=ee.current.find(Yn=>Yn.id===ge.parentId);if(Kt){const Yn=Kt.width||lt,Wr=Kt.height||et,Fr=ge.width||((Vt=ge.measured)==null?void 0:Vt.width)||lt,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}}):[]},(K=we.current)==null||K.setPointerCapture(u.pointerId),(ae=Bt.current)==null||ae.call(Bt,u,Q),We.current.selectedStarts.length>0){const ge=ee.current.filter(Qe=>Qe.selected);(Ae=(ke=J.current).onSelectionDragStart)==null||Ae.call(ke,u,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(l.x,l.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,u,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,u),Ke||p){rt.current={startWorld:{...l},endWorld:{...l}},(Ue=we.current)==null||Ue.setPointerCapture(u.pointerId),ct();return}E(u.target)||(Pt.current=!0,It.current={x:u.clientX,y:u.clientY},(Jt=we.current)==null||Jt.classList.add("dragging"),(ft=we.current)==null||ft.setPointerCapture(u.pointerId))},[Be,ue,vt,Ze,he,$e,He,Ke,at,ct,dt,St,zt]),Qt=a.useCallback(u=>{var l,p,k,E;if(Oe.current){if(Lt.current=Be(u.clientX,u.clientY),at(),In){const x=we.current;if(x){const M=x.getBoundingClientRect(),R=40,W=u.clientX-M.left,L=u.clientY-M.top;let U=0,G=0;W<R?U=nt:W>M.width-R&&(U=-nt),L<R?G=nt:L>M.height-R&&(G=-nt),(U||G)&&(fe.current.x+=U,fe.current.y+=G,Re(u))}}return}if(rt.current){rt.current.endWorld=Be(u.clientX,u.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 U=[];for(const G of ee.current){if(G.hidden)continue;const Z=G.width||lt,ie=G.height||et,K=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;K!==!!G.selected&&U.push({id:G.id,type:"select",selected:K})}U.length&&Ee.current(U)}return}if(We.current){const x=Be(u.clientX,u.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 K=M.parentClamp;L={x:Math.max(K.minX,Math.min(L.x,K.maxX)),y:Math.max(K.minY,Math.min(L.y,K.maxY))}}const U=[{id:M.id,position:L}];for(const K of M.selectedStarts){let ae={x:K.startPos.x+R,y:K.startPos.y+W};if(je&&(ae=Zn(ae,_e)),gt&&(ae=Gn(ae,gt)),K.parentClamp){const ke=K.parentClamp;ae={x:Math.max(ke.minX,Math.min(ae.x,ke.maxX)),y:Math.max(ke.minY,Math.min(ae.y,ke.maxY))}}U.push({id:K.id,position:ae})}const G=[];for(const K of U){const ae=ee.current.find(ke=>ke.id===K.id);if(ae){ae.position=K.position,ae.dragging=!0;let ke=K.position;if(ae.parentId){let Ae=ee.current.find(Ue=>Ue.id===ae.parentId),Fe=K.position.x,Ge=K.position.y;for(;Ae;)Fe+=Ae.position.x,Ge+=Ae.position.y,Ae=Ae.parentId?ee.current.find(Ue=>Ue.id===Ae.parentId):null;ke={x:Fe,y:Ge}}G.push({id:K.id,position:K.position,_absolutePosition:ke,width:ae.width,height:ae.height,dragging:!0,selected:ae.selected})}}const Z=new Set(U.map(K=>K.id));for(const K of ee.current)if(K.parentId&&Z.has(K.parentId)&&!Z.has(K.id)){let ae=ee.current.find(Fe=>Fe.id===K.parentId),ke=K.position.x,Ae=K.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:K.id,position:K.position,_absolutePosition:{x:ke,y:Ae},width:K.width,height:K.height,dragging:!1,selected:K.selected})}if((l=Ne.current)==null||l.postMessage({type:"nodePositions",data:{updates:G}}),Pn){const K=we.current;if(K){const ae=K.getBoundingClientRect(),ke=40,Ae=u.clientX-ae.left,Fe=u.clientY-ae.top;let Ge=0,Ue=0;Ae<ke?Ge=nt:Ae>ae.width-ke&&(Ge=-nt),Fe<ke?Ue=nt:Fe>ae.height-ke&&(Ue=-nt),(Ge||Ue)&&(fe.current.x+=Ge,fe.current.y+=Ue,Re(u))}}const ie=ee.current.find(K=>K.id===M.id);if(ie&&((p=$t.current)==null||p.call($t,u,ie)),M.selectedStarts.length>0){const K=ee.current.filter(ae=>ae.selected);(E=(k=J.current).onSelectionDrag)==null||E.call(k,u,K)}return}if(!Pt.current)return;const y=fe.current;y.x+=u.clientX-It.current.x,y.y+=u.clientY-It.current.y,It.current={x:u.clientX,y:u.clientY},Re()},[Re,Be,at,ct]),mn=a.useCallback(u=>{var y,l,p,k,E,x,M,R;if(Oe.current){const W=Be(u.clientX,u.clientY),L=vt(W.x,W.y);if(L&&L.nodeId!==Oe.current.sourceId&&(Me==="loose"||L.type==="target")){const Z=Oe.current.sourceType==="target"?{source:L.nodeId,target:Oe.current.sourceId,sourceHandle:L.handleId||null,targetHandle:Oe.current.sourceHandle}:{source:Oe.current.sourceId,target:L.nodeId,sourceHandle:Oe.current.sourceHandle,targetHandle:L.handleId||null};(J.current.isValidConnection?J.current.isValidConnection(Z):!0)&&((y=st.current)==null||y.call(st,{...Z,...Et}))}(p=(l=J.current).onConnectEnd)==null||p.call(l,u.nativeEvent||u),Oe.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),U=[{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(K=>K.id===Z.id);U.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:U}}),Ee.current){const Z=U.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,u,Z)}requestAnimationFrame(()=>{We.current=null});const G=ee.current.find(Z=>Z.id===W.id);G&&((M=jt.current)==null||M.call(jt,u,G));return}Pt.current=!1,(R=we.current)==null||R.classList.remove("dragging")},[Be,vt,at,ct,dt]);a.useEffect(()=>{const u=we.current;if(!u)return;const y=l=>{Xt&&l.preventDefault();const p=fe.current;if(an||Ve.current){const R=cn;Ct==="horizontal"?p.x-=l.deltaY*R:(Ct==="vertical"||(p.x-=l.deltaX*R),p.y-=l.deltaY*R),Re(l);return}if(!ln)return;const k=l.deltaY>0?.92:1.08,E=u.getBoundingClientRect(),x=l.clientX-E.left,M=l.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(l)};return u.addEventListener("wheel",y,{passive:!Xt}),()=>u.removeEventListener("wheel",y)},[Re,re,de,an,Ct,cn,ln,Xt]),a.useEffect(()=>{if(!dn)return;const u=we.current;if(!u)return;let y=0,l=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=u.getBoundingClientRect();l={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 U=fe.current,G=l.x,Z=l.y;U.x=G-(G-U.x)*L,U.y=Z-(Z-U.y)*L,U.zoom=Math.min(de,Math.max(re,U.zoom*L)),Re(x)}},E=()=>{y=0,l=null};return u.addEventListener("touchstart",p,{passive:!1}),u.addEventListener("touchmove",k,{passive:!1}),u.addEventListener("touchend",E),()=>{u.removeEventListener("touchstart",p),u.removeEventListener("touchmove",k),u.removeEventListener("touchend",E)}},[dn,Re,re,de]),a.useEffect(()=>{if(!un)return;const u=we.current;if(!u)return;const y=l=>{var L,U,G,Z;const p=Be(l.clientX,l.clientY);if(ue(p.x,p.y)){(U=(L=J.current).onNodeDoubleClick)==null||U.call(L,l,ue(p.x,p.y));return}const k=Ze(p.x,p.y);if(k){(Z=(G=J.current).onEdgeDoubleClick)==null||Z.call(G,l,k);return}const E=1.5,x=u.getBoundingClientRect(),M=l.clientX-x.left,R=l.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(l)};return u.addEventListener("dblclick",y),()=>u.removeEventListener("dblclick",y)},[un,Re,re,de,Be,ue,Ze]),a.useEffect(()=>{const u=we.current;if(!u)return;const y=l=>{var x,M,R,W,L,U;const p=Be(l.clientX,l.clientY),k=ue(p.x,p.y);if(k){(M=(x=J.current).onNodeContextMenu)==null||M.call(x,l,k);return}const E=Ze(p.x,p.y);if(E){(W=(R=J.current).onEdgeContextMenu)==null||W.call(R,l,E);return}(U=(L=J.current).onPaneContextMenu)==null||U.call(L,l)};return u.addEventListener("contextmenu",y),()=>u.removeEventListener("contextmenu",y)},[Be,ue,Ze]),a.useEffect(()=>{const u=we.current;if(!u)return;let y=null,l=null;const p=x=>{var W,L,U,G,Z,ie,K,ae,ke,Ae,Fe,Ge,Ue,Jt;if((L=(W=J.current).onPaneMouseMove)==null||L.call(W,x),Pt.current||We.current||Oe.current||rt.current)return;const M=Be(x.clientX,x.clientY),R=ue(M.x,M.y);if(R!==y&&(y&&((G=(U=J.current).onNodeMouseLeave)==null||G.call(U,x,y)),R&&((ie=(Z=J.current).onNodeMouseEnter)==null||ie.call(Z,x,R)),y=R),R&&((ae=(K=J.current).onNodeMouseMove)==null||ae.call(K,x,R)),!R){const ft=Ze(M.x,M.y);ft!==l&&(l&&((Ae=(ke=J.current).onEdgeMouseLeave)==null||Ae.call(ke,x,l)),ft&&((Ge=(Fe=J.current).onEdgeMouseEnter)==null||Ge.call(Fe,x,ft)),l=ft),ft&&((Jt=(Ue=J.current).onEdgeMouseMove)==null||Jt.call(Ue,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,U,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),l&&((G=(U=J.current).onEdgeMouseLeave)==null||G.call(U,x,l),l=null)};return u.addEventListener("mousemove",p),u.addEventListener("mouseenter",k),u.addEventListener("mouseleave",E),()=>{u.removeEventListener("mousemove",p),u.removeEventListener("mouseenter",k),u.removeEventListener("mouseleave",E)}},[Be,ue,Ze]),a.useEffect(()=>{const u=Array.isArray(qe)?qe:[qe],y=async l=>{var p,k,E,x;if(u.includes(l.key)){if(l.target.tagName==="INPUT"||l.target.tagName==="TEXTAREA"||l.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(U=>W.has(U.source)||W.has(U.target));L.length&&De.current(L.map(U=>({id:U.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((l.ctrlKey||l.metaKey)&&l.key==="a"){if(l.target.tagName==="INPUT"||l.target.tagName==="TEXTAREA")return;if(l.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 u,y;if(!Ft.current&&Ne.current){if(Ft.current=!0,Ye&&ee.current.length>0){const l=we.current;if(l){const p=l.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=(u=J.current).onInit)==null||y.call(u,{getNodes:()=>[...ee.current],getEdges:()=>[...Pe.current],getNode:l=>ee.current.find(p=>p.id===l),getEdge:l=>Pe.current.find(p=>p.id===l),getViewport:()=>({...fe.current}),getZoom:()=>fe.current.zoom,setViewport:l=>{fe.current={x:l.x??fe.current.x,y:l.y??fe.current.y,zoom:l.zoom??fe.current.zoom},Re()},fitView:(l={})=>{const p=we.current;if(!p||!ee.current.length)return;const k=p.getBoundingClientRect(),E=l.nodes?ee.current.filter(R=>l.nodes.some(W=>W.id===R.id)):ee.current;if(!E.length)return;const x=Mn(E),M=Yt(x,k.width,k.height,l.padding??.1);l.maxZoom&&(M.zoom=Math.min(M.zoom,l.maxZoom)),l.minZoom&&(M.zoom=Math.max(M.zoom,l.minZoom)),fe.current=M,Re()},screenToFlowPosition:l=>Be(l.x,l.y),flowToScreenPosition:l=>{const p=fe.current,k=we.current;if(!k)return{x:0,y:0};const E=k.getBoundingClientRect();return{x:l.x*p.zoom+p.x+E.left,y:l.y*p.zoom+p.y+E.top}},zoomIn:()=>{const l=fe.current;l.zoom=Math.min(de,l.zoom*1.2),Re()},zoomOut:()=>{const l=fe.current;l.zoom=Math.max(re,l.zoom/1.2),Re()},zoomTo:l=>{fe.current.zoom=Math.min(de,Math.max(re,l)),Re()},setNodes:l=>{var p,k;(k=(p=J.current).onNodesChange)==null||k.call(p,[...ee.current.map(E=>({id:E.id,type:"remove"})),...(typeof l=="function"?l(ee.current):l).map(E=>({type:"add",item:E}))])},setEdges:l=>{var p,k;(k=(p=J.current).onEdgesChange)==null||k.call(p,[...Pe.current.map(E=>({id:E.id,type:"remove"})),...(typeof l=="function"?l(Pe.current):l).map(E=>({type:"add",item:E}))])},addNodes:l=>{var k,E;const p=Array.isArray(l)?l:[l];(E=(k=J.current).onNodesChange)==null||E.call(k,p.map(x=>({type:"add",item:x})))},addEdges:l=>{var k,E;const p=Array.isArray(l)?l:[l];(E=(k=J.current).onEdgesChange)==null||E.call(k,p.map(x=>({type:"add",item:x})))},deleteElements:({nodes:l=[],edges:p=[]})=>{var k,E,x,M;l.length&&((E=(k=J.current).onNodesChange)==null||E.call(k,l.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:(l,p)=>{var x,M;const k=ee.current.find(R=>R.id===l);if(!k)return;const E=typeof p=="function"?p(k.data):{...k.data,...p};(M=(x=J.current).onNodesChange)==null||M.call(x,[{id:l,type:"replace",item:{...k,data:E}}])},toObject:()=>({nodes:[...ee.current],edges:[...Pe.current],viewport:{...fe.current}}),setCenter:(l,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-l*M,y:x.height/2-p*M,zoom:M},Re()},fitBounds:(l,p={})=>{const k=we.current;if(!k)return;const E=k.getBoundingClientRect(),x=Yt(l,E.width,E.height,p.padding??.1);fe.current=x,Re()}})}});const Hn=a.useCallback(()=>{fe.current={...Le},Re()},[Re,Le]),_n=a.useCallback(u=>{var y;if(u)yt.current.push(u);else{const l=fe.current,p=we.current;if(!p)return;const k=p.getBoundingClientRect(),E=Math.round(-l.x/l.zoom+k.width/2/l.zoom),x=Math.round(-l.y/l.zoom+k.height/2/l.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(u=>{if(u.id||(u.id="node-"+Date.now()),!u.position){const y=fe.current,l=we.current;if(!l)return;const p=l.getBoundingClientRect();u.position={x:Math.round(-y.x/y.zoom+p.width/2/y.zoom)-lt/2,y:Math.round(-y.y/y.zoom+p.height/2/y.zoom)-et/2}}u.data||(u.data={label:u.id}),Ee.current&&Ee.current([{type:"add",item:u}])},[]),Fn=a.useCallback(()=>({...fe.current}),[]),F=a.useCallback(u=>{fe.current={...fe.current,...u},Re()},[Re]),ve=a.useCallback(u=>Be(u.x,u.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 Ot}}),[t,n,ne,gn,Ot,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 ur=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?ur(e):ur),so=e=>e;function io(e,t=so){const n=a.useSyncExternalStore(e.subscribe,a.useCallback(()=>t(e.getState()),[e,t]),a.useCallback(()=>t(e.getInitialState()),[e,t]));return a.useDebugValue(n),n}const 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 lo({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,O,_,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)||((O=v==null?void 0:v.measured)==null?void 0:O.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 le=[];if(X.shiftKey)le.push({id:e.id,type:"select",selected:!e.selected});else for(const re of r.current.nodesRef.current)re.id===e.id&&!re.selected?le.push({id:re.id,type:"select",selected:!0}):re.id!==e.id&&re.selected&&le.push({id:re.id,type:"select",selected:!1});le.length&&r.current.onNodesChangeRef.current(le)}const q=r.current.cameraRef.current,O=r.current.wrapRef.current;if(!O)return;const _=O.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(le=>le.selected&&le.id!==e.id).map(le=>({id:le.id,startPos:{...le.position}})):[];c.current={startPos:{...e.position},startMouse:{x:w,y:g},selectedStarts:N};const I=[{id:e.id,type:"position",dragging:!0}];for(const le of N)I.push({id:le.id,type:"position",dragging:!0});(ye=(me=r.current.onNodesChangeRef).current)==null||ye.call(me,I);const $=i.current;$&&$.setPointerCapture(X.pointerId);let V=null;const se=le=>{var He,ze,Ke,tt;if(!c.current)return;const Ce=r.current.cameraRef.current,re=O.getBoundingClientRect(),de=(le.clientX-re.left-Ce.x)/Ce.zoom,Le=(le.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=O.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=(Ke=r.current.workerRef)==null?void 0:Ke.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)}V=$e},te=le=>{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(V)for(let he=0;he<V.length;he++)Ce[he]={id:V[he].id,position:V[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,V=null,$&&$.releasePointerCapture(le.pointerId),$==null||$.removeEventListener("pointermove",se),$==null||$.removeEventListener("pointerup",te)};$==null||$.addEventListener("pointermove",se),$==null||$.addEventListener("pointerup",te)},[e]),m=a.useCallback(X=>{var O,_,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":(_=(O=r.current.onNodesChangeRef).current)==null||_.call(O,[{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 uo=a.memo(lo),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,O;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,V=_==="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,le=(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:le,y:Ce}}})},ce=me=>{var xe,he,$e,He;const ye=N.cameraRef.current,le=(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 Ke=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+Ke/2,qe=Me.y;break;case"bottom":_e=Me.x+Ke/2,qe=Me.y+tt;break;case"left":_e=Me.x,qe=Me.y+tt/2;break;default:_e=Me.x+Ke,qe=Me.y+tt/2;break}if(Math.abs(le-_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:V,sourceHandle:Le,targetHandle:e.targetHandle}:{source:V,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=(O=C.handleRegistryRef)==null?void 0:O.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})},O=_=>{var V,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=(V=n.onNodesChangeRef).current)==null||se.call(V,$)),X=null,i(null)};return B.addEventListener("pointerdown",P,!0),B.addEventListener("pointermove",q),B.addEventListener("pointerup",O),window.addEventListener("keydown",Y),window.addEventListener("keyup",j),()=>{B.removeEventListener("pointerdown",P,!0),B.removeEventListener("pointermove",q),B.removeEventListener("pointerup",O),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 On=!1,Mt=null;function zr(e){Mt=e,!On&&(On=!0,requestAnimationFrame(()=>{var t;On=!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,$,V;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),O=(P==null?void 0:P.height)||((I=P==null?void 0:P.measured)==null?void 0:I.height);let _;q&&O?_=Qn(t,q,O):C.current?_=xo(C.current,(V=($=H.cameraRef)==null?void 0:$.current)==null?void 0:V.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,O=`${b}__${n||e}`;q==null||q.delete(O)}},[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}`,O=P==null?void 0:P.get(q);if(O&&O.x!==void 0&&O.y!==void 0)return{x:j.x+O.x,y:j.y+O.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(),O=B();if(!O)return;const _=O.x,w=O.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,V=(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:V}}})},v=I=>{var me,ye,le,Ce;const $=(I.clientX-q.left-j.x)/j.zoom,V=(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(V-$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};(le=(ye=Y.onEdgesChangeRef)==null?void 0:ye.current)==null||le.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),O=Math.max(50,q*.5);let _,w,g,v;switch(c){case"left":_=j.x-O,w=j.y;break;case"top":_=j.x,w=j.y-O;break;case"bottom":_=j.x,w=j.y+O;break;default:_=j.x+O,w=j.y;break}switch(f){case"right":g=P.x+O,v=P.y;break;case"top":g=P.x,v=P.y-O;break;case"bottom":g=P.x,v=P.y+O;break;default:g=P.x-O,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 Vn(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(Vn(e.x,e.y,t.x,t.y,n))return null;const r=new Set,i=new Set;r.add(e.x),r.add(t.x),i.add(e.y),i.add(t.y);const o=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 O=[D],_=15,w=[[1,0],[-1,0],[0,1],[0,-1]];for(;O.length>0;){let g=0;for(let te=1;te<O.length;te++)Y[O[te]]<Y[O[g]]&&(g=te);const v=O[g];if(O[g]=O[O.length-1],O.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],V=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],le=f[pe];if(Co(ye,le,n)||!Vn($,V,ye,le,n))continue;const Ce=Math.abs(ye-$)+Math.abs(le-V),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]-le),O.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)&&Vn(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,O,_;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||((O=m.measured)==null?void 0:O.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:O,onNodeMouseEnter:_,onNodeMouseMove:w,onNodeMouseLeave:g,onNodeContextMenu:v,onNodeDragStart:N,onNodeDrag:I,onNodeDragStop:$,onEdgeClick:V,onEdgeDoubleClick:se,onEdgeMouseEnter:te,onEdgeMouseMove:ce,onEdgeMouseLeave:pe,onEdgeContextMenu:me,onPaneClick:ye,onPaneContextMenu:le,onPaneMouseEnter:Ce,onPaneMouseMove:re,onPaneMouseLeave:de,onSelectionChange:Le,onInit:Ye,onMoveStart:xe,onMove:he,onMoveEnd:$e,onDelete:He,onBeforeDelete:ze,onError:Ke,onDragOver:tt,onDrop:Me,onDragEnter:Te,onDragLeave:Xe,nodesDraggable:je,nodesConnectable:_e,elementsSelectable:qe,multiSelectionKeyCode:kt,selectionOnDrag:an,selectionMode:Ct,connectionMode:cn,connectionRadius:ln,connectOnClick:un,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:Oe=!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),Ot=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]),Ve=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(()=>Ve.filter(F=>F.type&&xt[F.type]),[Ve,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]),ut=a.useMemo(()=>{if(c===0)return[];const F=Ve.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),u=ne.type==="group"||!ne.parentId&&F.some(y=>y.parentId===ne.id);return Se&&!u?-1:!Se&&u?1:0})},[Ve,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:ue}=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:O,onNodeMouseEnter:_,onNodeMouseMove:w,onNodeMouseLeave:g,onNodeContextMenu:v,onNodeDragStart:N,onNodeDrag:I,onNodeDragStop:$,onEdgeClick:V,onEdgeDoubleClick:se,onEdgeMouseEnter:te,onEdgeMouseMove:ce,onEdgeMouseLeave:pe,onEdgeContextMenu:me,onPaneClick:ye,onPaneContextMenu:le,onPaneMouseEnter:Ce,onPaneMouseMove:re,onPaneMouseLeave:de,onSelectionChange:Le,onInit:Ye,onMoveStart:xe,onMove:he,onMoveEnd:$e,onDelete:He,onBeforeDelete:ze,onError:Ke,nodesDraggable:je,nodesConnectable:_e,elementsSelectable:qe,multiSelectionKeyCode:kt,selectionOnDrag:an,selectionMode:Ct,connectionMode:cn,connectionRadius:ln,connectOnClick:un,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}),Ut=a.useRef(pt);Ut.current=pt;const qt=a.useRef(c);qt.current=c,a.useEffect(()=>{let F;const ve=()=>{const Se=Ut.current,u=qt.current;if(u===0||!Se.length)return;const y=ue.cameraRef.current,l=ue.wrapRef.current;if(!l)return;const p=l.clientWidth,k=l.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,u-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 U=[];for(let Z=0;Z<Se.length;Z++){const ie=Se[Z];if(L.has(ie.id))continue;const K=ie._absolutePosition||ie.position,ae=K.x+(ie.width||160)/2-E,ke=K.y+(ie.height||60)/2-x;U.push({id:ie.id,dist:ae*ae+ke*ke})}U.sort((Z,ie)=>Z.dist-ie.dist);const G=new Set;for(let Z=0;Z<Math.min(W,U.length);Z++)G.add(U[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)}},[ue.cameraRef,ue.wrapRef]);const vt=a.useRef(new Set);a.useEffect(()=>{if(!o||!ue.workerRef.current)return;let F=!1;async function ve(Se){const u=new Blob([Se],{type:"image/svg+xml"}),y=URL.createObjectURL(u),l=new Image;return l.src=y,await l.decode(),URL.revokeObjectURL(y),createImageBitmap(l)}async function ne(){var p,k,E;const Se={},u=[],y={},l={};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)){l[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,u.push(R))}catch(R){console.warn(`[InfiniteCanvas] Failed to convert canvasNodeType "${x}":`,R)}}if(!F&&Object.keys(Se).length>0&&((p=ue.workerRef.current)==null||p.postMessage({type:"nodeTypeBitmaps",data:{bitmaps:Se}},u)),!F&&Object.keys(l).length>0&&((k=ue.workerRef.current)==null||k.postMessage({type:"nodeTypeConfigs",data:{configs:l}})),!F&&Object.keys(y).length>0){const x=new Map,M={},R={},W=[];let L=vt.current.size;for(const U of t){const G=y[U.type];if(G)try{const Z=G(U.data);if(!Z)continue;let ie=x.get(Z);if(!ie&&(ie="bmp_"+L++,x.set(Z,ie),!vt.current.has(Z))){const K=await ve(Z);if(F)return;M[ie]=K,W.push(K),vt.current.add(Z)}R[U.id]=ie}catch(Z){console.warn(`[InfiniteCanvas] canvasNodeType fn error for node "${U.id}":`,Z)}}F||(E=ue.workerRef.current)==null||E.postMessage({type:"nodeBitmaps",data:{cache:M,keys:R}},W)}}return ne(),()=>{F=!0}},[o,t,ue.workerRef]);const Ze=a.useContext(Rt),Zt=Ze&&typeof Ze.getState=="function";a.useEffect(()=>{Zt&&queueMicrotask(()=>{Ze.setState({nodes:Ve,edges:n,nodesRef:ue.nodesRef,edgesRef:ue.edgesRef,onNodesChangeRef:ue.onNodesChangeRef,onEdgesChangeRef:ue.onEdgesChangeRef,cameraRef:ue.cameraRef,wrapRef:ue.wrapRef,workerRef:ue.workerRef})})},[Zt,Ve,n,ue,Ze]);const Re=a.useMemo(()=>({...ue,edgeLabelContainerRef:yn,viewportPortalRef:Ot,pinNode:Bt,unpinNode:$t,togglePinNode:jt,get pinnedNodeIds(){return wt.current},get nodes(){return Ve},get edges(){return n},get viewport(){return ue.cameraRef.current},get minZoom(){return ue.zoomMin||.1},get maxZoom(){return ue.zoomMax||5},get domNode(){return ue.wrapRef.current},get width(){var F;return((F=ue.wrapRef.current)==null?void 0:F.clientWidth)||0},get height(){var F;return((F=ue.wrapRef.current)==null?void 0:F.clientHeight)||0}}),[ue,Ve,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=ue.cameraRef.current,Se=`translate(${ne.x}px, ${ne.y}px) scale(${ne.zoom})`,u=`translate(${ne.x}, ${ne.y}) scale(${ne.zoom})`;at.current&&(at.current.style.transform=Se),ct.current&&ct.current.setAttribute("transform",u),Gt.current&&(Gt.current.style.transform=Se),Qt.current&&(Qt.current.style.transform=Se);const y=dt.current;if(y){const l=ne.zoom<.15?"lod-minimal":ne.zoom<.35?"lod-reduced":null;l!==mn.current&&(y.classList.remove("lod-minimal","lod-reduced"),l&&y.classList.add(l),mn.current=l)}F=requestAnimationFrame(ve)};return F=requestAnimationFrame(ve),()=>cancelAnimationFrame(F)},[ue]);const[Ft,Hn]=a.useState(null);a.useEffect(()=>{if(!ut.length)return;let F;const ve=()=>{var M,R;const ne=ue.cameraRef.current,Se=ue.wrapRef.current;if(!Se){F=requestAnimationFrame(ve);return}const u=Se.getBoundingClientRect(),y=200,l=-ne.x/ne.zoom-y,p=-ne.y/ne.zoom-y,k=(u.width-ne.x)/ne.zoom+y,E=(u.height-ne.y)/ne.zoom+y,x=new Set;for(const W of ut){const L=W._absolutePosition||W.position,U=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+U>=l&&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)},[ut,ue]);const _n=a.useMemo(()=>Ft?ut.filter(F=>Ft.has(F.id)):ut,[ut,Ft]),Wn=ut.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(uo,{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=>{Ot.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}}),Oe&&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(V=>({id:V.id,type:"remove"})),...$.map(V=>({type:"add",item:V}))])}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(V=>({id:V.id,type:"remove"})),...$.map(V=>({type:"add",item:V}))])}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 V=$-N,se=Math.min(V/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,V=1.2,se={x:I-(I-g.x)*V,y:$-($-g.y)*V,zoom:Math.min(t().zoomMax,g.zoom*V)};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,V=1/1.2,se={x:I-(I-g.x)*V,y:$-($-g.y)*V,zoom:Math.max(t().zoomMin,g.zoom*V)};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,V=I.height/2,se=Math.min(t().zoomMax,Math.max(t().zoomMin,w)),te=se/v.zoom,ce={x:$-($-v.x)*te,y:V-(V-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 V=Mn($),se=Yt(V,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,V={x:I.width/2-w*$,y:I.height/2-g*$,zoom:$};C(V,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]),O=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(V=>V.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:O,updateNodeData:_,toObject:P}}function Fo(){return Ie().nodes}function Yo(){return Ie().edges}function Xo(){return Ie().viewport}function Oo(){return Ie().connection}function Uo(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 Vo(){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 Ko=e=>{var t;return((t=e.nodes)==null?void 0:t.length)>0};function es(e={}){return Ie(Ko)}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 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: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||Un,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,O=(t-j*P)/2;for(const g of z){if(g.hidden)continue;const v=g.width||Un,N=g.height||qn,I=(g.position.x-A)*P+q,$=(g.position.y-B)*P+O,V=v*P,se=N*P;S.fillStyle=g.selected?"#f59e0b":typeof n=="function"?n(g):n,S.fillRect(I,$,Math.max(V,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 V=(v-A)*P+q,se=(N-B)*P+O,te=I*P,ce=$*P;S.clearRect(V,se,te,ce);for(const pe of z){if(pe.hidden)continue;const me=pe.width||Un,ye=pe.height||qn,le=(pe.position.x-A)*P+q,Ce=(pe.position.y-B)*P+O;S.fillStyle=pe.selected?"#f59e0b":typeof n=="function"?n(pe):n,S.fillRect(le,Ce,Math.max(me*P,2),Math.max(ye*P,2))}S.strokeStyle="#3b82f6",S.lineWidth=1.5,S.strokeRect(V,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 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: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]),O=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:O,disabled:j,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:T.jsx(ls,{})})]}),t&&T.jsx(nn,{onClick:_,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:T.jsx(us,{})}),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,O=S.cameraRef.current,_=(P.clientX-q.startX)/O.zoom,w=(P.clientY-q.startY)/O.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=Ur;exports.getNodeDimensions=Kn;exports.getNodesBounds=Mn;exports.getNodesInside=Zr;exports.getOutgoers=qr;exports.getOverlappingArea=Vr;exports.getRoutedLabelPosition=Nn;exports.getSimpleBezierPath=rr;exports.getSmoothStepPath=Rn;exports.getStraightPath=tr;exports.getViewportForBounds=Yt;exports.isEdge=Or;exports.isNode=Xr;exports.nodeToBox=Es;exports.nodeToRect=Kr;exports.reconnectEdge=Mo;exports.rectToBox=Gr;exports.routeSinglePath=Po;exports.routedPointsToPath=zn;exports.snapPosition=Zn;exports.useConnection=Oo;exports.useEdges=Yo;exports.useEdgesState=Wo;exports.useHandleConnections=Zo;exports.useInfiniteCanvas=Mr;exports.useInternalNode=ts;exports.useKeyPress=Jo;exports.useNodeConnections=qo;exports.useNodeId=co;exports.useNodes=Fo;exports.useNodesData=Uo;exports.useNodesInitialized=es;exports.useNodesState=_o;exports.useOnEdgesChangeMiddleware=is;exports.useOnNodesChangeMiddleware=ss;exports.useOnSelectionChange=Qo;exports.useOnViewportChange=Go;exports.useReactFlow=Hr;exports.useStore=ns;exports.useStoreApi=rs;exports.useUndoRedo=os;exports.useUpdateNodeInternals=Vo;exports.useViewport=Xo;
|