@infinit-canvas/react 0.1.17 → 0.1.18
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 +660 -597
- package/dist/react-infinite-canvas.js +3139 -2939
- package/dist/styles.css +9 -0
- package/package.json +1 -1
- package/src/types.d.ts +4 -0
|
@@ -1,867 +1,930 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("react/jsx-runtime"),l=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,a=new Set;for(const o of n)o.target===r&&a.add(o.source);return t.filter(o=>a.has(o.id))}function qr(e,t,n){const r=typeof e=="string"?e:e.id,a=new Set;for(const o of n)o.source===r&&a.add(o.target);return t.filter(o=>a.has(o.id))}function Rn(e){if(!e.length)return{x:0,y:0,width:0,height:0};let t=1/0,n=1/0,r=-1/0,a=-1/0;for(const o of e){const c=o.position.x,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>a&&(a=f+d)}return{x:t,y:n,width:r-t,height:a-n}}function Zt(e,t,n,r=.1){const a=e.width*(1+r*2),o=e.height*(1+r*2),c=Math.min(t/a,n/o,1),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 a=t.x,o=t.y,c=t.x+t.width,f=t.y+t.height;return e.filter(m=>{const{width:d,height:g}=Kn(m),b=m.position.x,E=m.position.y,C=b+d,S=E+g;return r?b<c&&C>a&&E<f&&S>o:b>=a&&C<=c&&E>=o&&S<=f})}function Gr(e){return{x:e.x,y:e.y,x2:e.x+e.width,y2:e.y+e.height}}function Qr(e){return{x:e.x,y:e.y,width:e.x2-e.x,height:e.y2-e.y}}function Vr(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}}function Jr(e,t){const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return n*r}function Kr(e){const{width:t,height:n}=Kn(e);return{x:e.position.x,y:e.position.y,width:t,height:n}}const wr=`var Pa = null, r = null, tr = 0, or = 0, g = { x: 0, y: 0, zoom: 1 }, Y = [], G = [], q = [], $ = !1, Wt = 40, _t = !1, Fr = "lines", ha = 1, Pe = null, ee = null, xr = null, Ce = {}, Xo = {}, te = {}, We = {}, L = 160, B = 60, qa = 8, Fo = 5;
|
|
2
2
|
function d(a) {
|
|
3
3
|
return a._absolutePosition || a.position;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
5
|
+
function Jl(a, e, t, l, f) {
|
|
6
6
|
if (a.x !== void 0 && a.y !== void 0)
|
|
7
|
-
return { x:
|
|
7
|
+
return { x: e + a.x, y: t + a.y };
|
|
8
8
|
var o = a.position || (a.type === "source" ? "right" : "left");
|
|
9
9
|
switch (o) {
|
|
10
10
|
case "top":
|
|
11
|
-
return { x:
|
|
11
|
+
return { x: e + l / 2, y: t };
|
|
12
12
|
case "bottom":
|
|
13
|
-
return { x:
|
|
13
|
+
return { x: e + l / 2, y: t + f };
|
|
14
14
|
case "left":
|
|
15
|
-
return { x:
|
|
15
|
+
return { x: e, y: t + f / 2 };
|
|
16
16
|
case "right":
|
|
17
|
-
return { x:
|
|
17
|
+
return { x: e + l, y: t + f / 2 };
|
|
18
18
|
default:
|
|
19
|
-
return { x:
|
|
19
|
+
return { x: e + l, y: t + f / 2 };
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
function
|
|
23
|
-
var
|
|
22
|
+
function Ho(a) {
|
|
23
|
+
var e = a.width || L, t = a.height || B;
|
|
24
24
|
if (a.handles && a.handles.length > 0)
|
|
25
25
|
return a.handles.map(function(u) {
|
|
26
|
-
var
|
|
27
|
-
return { id: u.id || null, type: u.type, x:
|
|
26
|
+
var M = Jl(u, d(a).x, d(a).y, e, t);
|
|
27
|
+
return { id: u.id || null, type: u.type, x: M.x, y: M.y, position: u.position };
|
|
28
28
|
});
|
|
29
|
-
var
|
|
30
|
-
function
|
|
29
|
+
var l = a.targetPosition || "left", f = a.sourcePosition || "right", o = d(a);
|
|
30
|
+
function i(u) {
|
|
31
31
|
switch (u) {
|
|
32
32
|
case "top":
|
|
33
|
-
return { x: o.x +
|
|
33
|
+
return { x: o.x + e / 2, y: o.y };
|
|
34
34
|
case "bottom":
|
|
35
|
-
return { x: o.x +
|
|
35
|
+
return { x: o.x + e / 2, y: o.y + t };
|
|
36
36
|
case "left":
|
|
37
|
-
return { x: o.x, y: o.y +
|
|
37
|
+
return { x: o.x, y: o.y + t / 2 };
|
|
38
38
|
case "right":
|
|
39
|
-
return { x: o.x +
|
|
39
|
+
return { x: o.x + e, y: o.y + t / 2 };
|
|
40
40
|
default:
|
|
41
|
-
return { x: o.x +
|
|
41
|
+
return { x: o.x + e, y: o.y + t / 2 };
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
var
|
|
44
|
+
var y = i(l), x = i(f);
|
|
45
45
|
return [
|
|
46
|
-
{ id: null, type: "target", x:
|
|
47
|
-
{ id: null, type: "source", x:
|
|
46
|
+
{ id: null, type: "target", x: y.x, y: y.y, position: l },
|
|
47
|
+
{ id: null, type: "source", x: x.x, y: x.y, position: f }
|
|
48
48
|
];
|
|
49
49
|
}
|
|
50
|
-
var
|
|
51
|
-
function
|
|
52
|
-
|
|
53
|
-
var
|
|
54
|
-
return
|
|
50
|
+
var Et = {}, fe = !0;
|
|
51
|
+
function Ql(a) {
|
|
52
|
+
fe && (Et = {}, fe = !1);
|
|
53
|
+
var e = Et[a.id];
|
|
54
|
+
return e || (e = Ho(a), Et[a.id] = e, e);
|
|
55
55
|
}
|
|
56
|
-
function
|
|
57
|
-
for (var
|
|
58
|
-
if (f
|
|
59
|
-
if (
|
|
60
|
-
if (f
|
|
56
|
+
function qe(a, e, t) {
|
|
57
|
+
for (var l = Ql(a), f = 0; f < l.length; f++)
|
|
58
|
+
if (l[f].type === e)
|
|
59
|
+
if (t) {
|
|
60
|
+
if (l[f].id === t) return l[f];
|
|
61
61
|
} else
|
|
62
|
-
return f
|
|
63
|
-
var o = a.width ||
|
|
64
|
-
return
|
|
62
|
+
return l[f];
|
|
63
|
+
var o = a.width || L, i = a.height || B;
|
|
64
|
+
return e === "source" ? { x: d(a).x + o, y: d(a).y + i / 2 } : { x: d(a).x, y: d(a).y + i / 2 };
|
|
65
65
|
}
|
|
66
|
-
var
|
|
67
|
-
function
|
|
68
|
-
|
|
69
|
-
grid:
|
|
70
|
-
origin:
|
|
71
|
-
cardBg:
|
|
72
|
-
cardBorder:
|
|
73
|
-
cardShadow:
|
|
66
|
+
var k = {};
|
|
67
|
+
function Pt() {
|
|
68
|
+
k = {
|
|
69
|
+
grid: $ ? "rgba(255,255,255,0.07)" : "rgba(0,0,0,0.07)",
|
|
70
|
+
origin: $ ? "rgba(255,255,255,0.2)" : "rgba(0,0,0,0.15)",
|
|
71
|
+
cardBg: $ ? "#2a2a28" : "#ffffff",
|
|
72
|
+
cardBorder: $ ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.1)",
|
|
73
|
+
cardShadow: $ ? "rgba(0,0,0,0.3)" : "rgba(0,0,0,0.06)",
|
|
74
74
|
titleText: "rgba(255,255,255,0.9)",
|
|
75
|
-
bodyText:
|
|
76
|
-
coordText:
|
|
77
|
-
nodeBg:
|
|
78
|
-
nodeBorder:
|
|
75
|
+
bodyText: $ ? "rgba(255,255,255,0.55)" : "rgba(0,0,0,0.5)",
|
|
76
|
+
coordText: $ ? "rgba(255,255,255,0.25)" : "rgba(0,0,0,0.2)",
|
|
77
|
+
nodeBg: $ ? "#1e1e2e" : "#ffffff",
|
|
78
|
+
nodeBorder: $ ? "rgba(255,255,255,0.15)" : "rgba(0,0,0,0.15)",
|
|
79
79
|
nodeSelectedBorder: "#3b82f6",
|
|
80
|
-
nodeShadow:
|
|
81
|
-
nodeText:
|
|
82
|
-
edgeStroke:
|
|
80
|
+
nodeShadow: $ ? "rgba(0,0,0,0.4)" : "rgba(0,0,0,0.08)",
|
|
81
|
+
nodeText: $ ? "rgba(255,255,255,0.9)" : "rgba(0,0,0,0.85)",
|
|
82
|
+
edgeStroke: $ ? "rgba(255,255,255,0.35)" : "rgba(0,0,0,0.3)",
|
|
83
83
|
edgeSelected: "#3b82f6",
|
|
84
84
|
edgeAnimated: "#3b82f6",
|
|
85
85
|
handleFill: "#ffffff",
|
|
86
86
|
handleBorder: "#3b82f6",
|
|
87
87
|
connectionLine: "#3b82f6"
|
|
88
|
-
},
|
|
88
|
+
}, Ia = !0;
|
|
89
89
|
}
|
|
90
|
-
|
|
91
|
-
var
|
|
92
|
-
function
|
|
93
|
-
|
|
94
|
-
for (var a = 0; a <
|
|
95
|
-
for (var
|
|
96
|
-
for (var
|
|
97
|
-
var
|
|
98
|
-
|
|
90
|
+
Pt();
|
|
91
|
+
var $l = ["#534AB7", "#0F6E56", "#993C1D", "#185FA5"], ae = 8, Fl = "500 11px system-ui, sans-serif", Ul = "400 11px system-ui, sans-serif", cl = "10px monospace", Uo = "500 13px system-ui, sans-serif", Vl = "400 11px system-ui, sans-serif", Ur = 400, oe = {}, Ge = !0;
|
|
92
|
+
function Nl() {
|
|
93
|
+
oe = {};
|
|
94
|
+
for (var a = 0; a < Y.length; a++)
|
|
95
|
+
for (var e = Y[a], t = Math.floor(e.x / Ur), l = Math.floor(e.y / Ur), f = Math.floor((e.x + e.w) / Ur), o = Math.floor((e.y + e.h) / Ur), i = t; i <= f; i++)
|
|
96
|
+
for (var y = l; y <= o; y++) {
|
|
97
|
+
var x = i + "," + y;
|
|
98
|
+
oe[x] || (oe[x] = []), oe[x].push(a);
|
|
99
99
|
}
|
|
100
|
-
|
|
100
|
+
Ge = !1;
|
|
101
101
|
}
|
|
102
|
-
function
|
|
103
|
-
|
|
104
|
-
for (var
|
|
105
|
-
for (var
|
|
106
|
-
var
|
|
102
|
+
function co(a, e, t, l) {
|
|
103
|
+
Ge && Nl();
|
|
104
|
+
for (var f = {}, o = [], i = Math.floor(a / Ur), y = Math.floor(e / Ur), x = Math.floor(t / Ur), u = Math.floor(l / Ur), M = i; M <= x; M++)
|
|
105
|
+
for (var v = y; v <= u; v++) {
|
|
106
|
+
var n = M + "," + v, s = oe[n];
|
|
107
107
|
if (s)
|
|
108
|
-
for (var
|
|
109
|
-
var
|
|
110
|
-
|
|
108
|
+
for (var h = 0; h < s.length; h++) {
|
|
109
|
+
var T = s[h];
|
|
110
|
+
f[T] || (f[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
|
|
122
|
-
for (var
|
|
123
|
-
var
|
|
124
|
-
|
|
115
|
+
var cr = 500, le = {}, ua = !0;
|
|
116
|
+
function Zt() {
|
|
117
|
+
le = {};
|
|
118
|
+
for (var a = 0; a < G.length; a++) {
|
|
119
|
+
var e = G[a];
|
|
120
|
+
if (!e.hidden)
|
|
121
|
+
for (var t = d(e), l = e.width || L, f = e.height || B, o = Math.floor(t.x / cr), i = Math.floor(t.y / cr), y = Math.floor((t.x + l) / cr), x = Math.floor((t.y + f) / cr), u = o; u <= y; u++)
|
|
122
|
+
for (var M = i; M <= x; M++) {
|
|
123
|
+
var v = u + "," + M;
|
|
124
|
+
le[v] || (le[v] = []), le[v].push(a);
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
|
|
127
|
+
ua = !1;
|
|
128
128
|
}
|
|
129
|
-
function
|
|
130
|
-
|
|
131
|
-
for (var
|
|
132
|
-
for (var
|
|
133
|
-
var
|
|
129
|
+
function po(a, e, t, l) {
|
|
130
|
+
ua && Zt();
|
|
131
|
+
for (var f = {}, o = [], i = Math.floor(a / cr), y = Math.floor(e / cr), x = Math.floor(t / cr), u = Math.floor(l / cr), M = i; M <= x; M++)
|
|
132
|
+
for (var v = y; v <= u; v++) {
|
|
133
|
+
var n = M + "," + v, s = le[n];
|
|
134
134
|
if (s)
|
|
135
|
-
for (var
|
|
136
|
-
var
|
|
137
|
-
|
|
135
|
+
for (var h = 0; h < s.length; h++) {
|
|
136
|
+
var T = s[h];
|
|
137
|
+
f[T] || (f[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 sa = {}, na = !0;
|
|
143
|
+
function Ie() {
|
|
144
|
+
sa = {};
|
|
145
|
+
for (var a = 0; a < G.length; a++)
|
|
146
|
+
sa[G[a].id] = G[a];
|
|
147
|
+
na = !1;
|
|
148
148
|
}
|
|
149
|
-
function
|
|
150
|
-
return
|
|
149
|
+
function Vo(a) {
|
|
150
|
+
return na && Ie(), sa[a];
|
|
151
151
|
}
|
|
152
|
-
var
|
|
153
|
-
function
|
|
154
|
-
|
|
155
|
-
for (var a = 0; a <
|
|
156
|
-
var
|
|
157
|
-
|
|
152
|
+
var $r = {}, Ze = !0;
|
|
153
|
+
function Dl() {
|
|
154
|
+
$r = {};
|
|
155
|
+
for (var a = 0; a < q.length; a++) {
|
|
156
|
+
var e = q[a];
|
|
157
|
+
$r[e.source] || ($r[e.source] = []), $r[e.source].push(a), e.source !== e.target && ($r[e.target] || ($r[e.target] = []), $r[e.target].push(a));
|
|
158
158
|
}
|
|
159
|
-
|
|
159
|
+
Ze = !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
|
-
|
|
176
|
-
var
|
|
177
|
-
|
|
161
|
+
var va = null, rl = 0, al = 0, el = "", Ia = !0;
|
|
162
|
+
function Ol(a) {
|
|
163
|
+
va || (va = new OffscreenCanvas(1, 1));
|
|
164
|
+
var e = Math.ceil(a), t = Math.ceil(a);
|
|
165
|
+
if (e < 2 || t < 2) return !1;
|
|
166
|
+
e > 512 && (e = 512), t > 512 && (t = 512), va.width = e, va.height = t, rl = e, al = a, el = Fr, Ia = !1;
|
|
167
|
+
var l = va.getContext("2d");
|
|
168
|
+
l.clearRect(0, 0, e, t);
|
|
169
|
+
var f = Pe || k.grid;
|
|
170
|
+
if (Fr === "dots") {
|
|
171
|
+
l.fillStyle = f;
|
|
172
|
+
var o = ha * g.zoom;
|
|
173
|
+
l.beginPath(), l.arc(0, 0, o, 0, 6.2832), l.fill();
|
|
174
|
+
} else if (Fr === "cross") {
|
|
175
|
+
l.strokeStyle = f, l.lineWidth = ha;
|
|
176
|
+
var i = 3 * g.zoom;
|
|
177
|
+
l.beginPath(), l.moveTo(-i, 0), l.lineTo(i, 0), l.moveTo(0, -i), l.lineTo(0, i), l.stroke();
|
|
178
178
|
} else
|
|
179
|
-
|
|
179
|
+
l.beginPath(), l.strokeStyle = f, l.lineWidth = ha * 0.5, l.moveTo(0.5, 0), l.lineTo(0.5, t), l.moveTo(0, 0.5), l.lineTo(e, 0.5), l.stroke();
|
|
180
180
|
return !0;
|
|
181
181
|
}
|
|
182
|
-
var
|
|
182
|
+
var No = 0, Lt = 0, Do = 0, Oo = 0, qt = 0, ie = !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 e = a.data.type, t = a.data.data;
|
|
188
|
+
switch (e) {
|
|
189
189
|
case "init":
|
|
190
|
-
|
|
191
|
-
return
|
|
192
|
-
}), console.log("[worker] init done — canvas:",
|
|
190
|
+
Pa = t.canvas, r = Pa.getContext("2d"), tr = t.width, or = t.height, Pa.width = tr, Pa.height = or, g = t.camera, Y = t.cards || [], G = t.nodes || [], q = t.edges || [], $ = t.dark, t.gridSize && (Wt = t.gridSize), t.edgeRouting !== void 0 && (Ga = !!t.edgeRouting), Pt(), Ge = !0, na = !0, ua = !0, fe = !0, Ze = !0, ie = q.some(function(A) {
|
|
191
|
+
return A.animated;
|
|
192
|
+
}), console.log("[worker] init done — canvas:", tr, "x", or, "| cards:", Y.length, "| nodes:", G.length, "| edges:", q.length, "| routing:", Ga), Ke(), self.postMessage({ type: "ready" }), ie && jo();
|
|
193
193
|
break;
|
|
194
194
|
case "resize":
|
|
195
|
-
|
|
195
|
+
tr = t.width, or = t.height, Pa.width = tr, Pa.height = or, Ia = !0, Ke();
|
|
196
196
|
break;
|
|
197
197
|
case "camera":
|
|
198
|
-
|
|
198
|
+
g = t.camera, Ia = !0, Q();
|
|
199
199
|
break;
|
|
200
200
|
case "cards":
|
|
201
|
-
|
|
201
|
+
Y = t.cards, Ge = !0, Q();
|
|
202
202
|
break;
|
|
203
203
|
case "nodes":
|
|
204
|
-
|
|
204
|
+
G = t.nodes, na = !0, ua = !0, fe = !0, Q(), Se(), self.postMessage({ type: "nodesProcessed", data: { nodeCount: G.length } });
|
|
205
205
|
break;
|
|
206
206
|
case "nodePositions":
|
|
207
|
-
|
|
208
|
-
for (var
|
|
209
|
-
var o = f
|
|
210
|
-
|
|
207
|
+
na && Ie();
|
|
208
|
+
for (var l = t.updates, f = 0; f < l.length; f++) {
|
|
209
|
+
var o = l[f], i = sa[o.id];
|
|
210
|
+
i && (i.position = o.position, o._absolutePosition && (i._absolutePosition = o._absolutePosition), o.width !== void 0 && (i.width = o.width), o.height !== void 0 && (i.height = o.height), i.dragging = o.dragging, i.selected = o.selected);
|
|
211
211
|
}
|
|
212
|
-
|
|
212
|
+
fe = !0, ua = !0, Q(), Se();
|
|
213
213
|
break;
|
|
214
214
|
case "nodeSelections":
|
|
215
|
-
|
|
216
|
-
for (var
|
|
217
|
-
var u =
|
|
218
|
-
|
|
215
|
+
na && Ie();
|
|
216
|
+
for (var y = t.selections, x = 0; x < y.length; x++) {
|
|
217
|
+
var u = y[x], M = sa[u.id];
|
|
218
|
+
M && (M.selected = u.selected);
|
|
219
219
|
}
|
|
220
|
-
|
|
220
|
+
Q();
|
|
221
221
|
break;
|
|
222
222
|
case "edgeSelections":
|
|
223
|
-
for (var
|
|
224
|
-
for (var s =
|
|
225
|
-
if (
|
|
226
|
-
|
|
223
|
+
for (var v = t.selections, n = 0; n < v.length; n++) {
|
|
224
|
+
for (var s = v[n], h = null, T = 0; T < q.length; T++)
|
|
225
|
+
if (q[T].id === s.id) {
|
|
226
|
+
h = q[T];
|
|
227
227
|
break;
|
|
228
228
|
}
|
|
229
|
-
|
|
229
|
+
h && (h.selected = s.selected);
|
|
230
230
|
}
|
|
231
|
-
|
|
231
|
+
Q();
|
|
232
232
|
break;
|
|
233
233
|
case "edges":
|
|
234
|
-
|
|
235
|
-
return
|
|
236
|
-
}),
|
|
234
|
+
q = t.edges, Ze = !0, ie = q.some(function(A) {
|
|
235
|
+
return A.animated;
|
|
236
|
+
}), ie && jo(), Q(), Se();
|
|
237
237
|
break;
|
|
238
238
|
case "theme":
|
|
239
|
-
|
|
239
|
+
$ = t.dark, Pt(), Q();
|
|
240
240
|
break;
|
|
241
241
|
case "connecting":
|
|
242
|
-
|
|
242
|
+
ee = t, Q();
|
|
243
243
|
break;
|
|
244
244
|
case "selectionBox":
|
|
245
|
-
|
|
245
|
+
xr = t, Q();
|
|
246
246
|
break;
|
|
247
247
|
case "background":
|
|
248
|
-
|
|
248
|
+
t.variant && (Fr = t.variant), t.gap && (Wt = t.gap), t.size && (ha = t.size), Pe = t.color || null, Ia = !0, Q();
|
|
249
|
+
break;
|
|
250
|
+
case "nodeTypeBitmaps":
|
|
251
|
+
Ce = t.bitmaps || {}, Q();
|
|
252
|
+
break;
|
|
253
|
+
case "nodeBitmaps":
|
|
254
|
+
Xo = t.cache || {}, te = t.keys || {}, Q();
|
|
255
|
+
break;
|
|
256
|
+
case "nodeTypeConfigs":
|
|
257
|
+
We = t.configs || {}, Q();
|
|
249
258
|
break;
|
|
250
259
|
case "edgeRouting":
|
|
251
|
-
if (
|
|
252
|
-
|
|
260
|
+
if (Ga = !!t.enabled, Ga)
|
|
261
|
+
Se();
|
|
253
262
|
else {
|
|
254
|
-
for (var
|
|
255
|
-
|
|
256
|
-
|
|
263
|
+
for (var I = 0; I < q.length; I++)
|
|
264
|
+
q[I]._routedPoints = null;
|
|
265
|
+
Q();
|
|
257
266
|
}
|
|
258
267
|
break;
|
|
259
268
|
}
|
|
260
|
-
} catch (
|
|
261
|
-
console.error("[worker] error:",
|
|
269
|
+
} catch (A) {
|
|
270
|
+
console.error("[worker] error:", A);
|
|
262
271
|
}
|
|
263
272
|
};
|
|
264
|
-
function
|
|
265
|
-
|
|
266
|
-
|
|
273
|
+
function Q() {
|
|
274
|
+
_t || (_t = !0, requestAnimationFrame(function() {
|
|
275
|
+
_t = !1, Ke();
|
|
267
276
|
}));
|
|
268
277
|
}
|
|
269
|
-
var
|
|
270
|
-
function
|
|
271
|
-
if (
|
|
272
|
-
|
|
278
|
+
var St = !1;
|
|
279
|
+
function jo() {
|
|
280
|
+
if (St) return;
|
|
281
|
+
St = !0;
|
|
273
282
|
function a() {
|
|
274
|
-
if (!
|
|
275
|
-
|
|
283
|
+
if (!ie) {
|
|
284
|
+
St = !1;
|
|
276
285
|
return;
|
|
277
286
|
}
|
|
278
|
-
|
|
287
|
+
qt = (qt + 0.5) % 20, Ke(), requestAnimationFrame(a);
|
|
279
288
|
}
|
|
280
289
|
requestAnimationFrame(a);
|
|
281
290
|
}
|
|
282
|
-
function
|
|
283
|
-
var
|
|
284
|
-
a.moveTo(
|
|
285
|
-
for (var
|
|
286
|
-
var
|
|
291
|
+
function Yo(a, e) {
|
|
292
|
+
var t = 6;
|
|
293
|
+
a.moveTo(e[0].x, e[0].y);
|
|
294
|
+
for (var l = 1; l < e.length - 1; l++) {
|
|
295
|
+
var f = e[l - 1], o = e[l], i = e[l + 1], y = Math.abs(o.x - f.x) + Math.abs(o.y - f.y), x = Math.abs(i.x - o.x) + Math.abs(i.y - o.y), u = Math.min(t, y / 2, x / 2);
|
|
287
296
|
if (u > 0.5) {
|
|
288
|
-
var
|
|
289
|
-
a.lineTo(o.x -
|
|
297
|
+
var M = o.x - f.x, v = o.y - f.y, n = i.x - o.x, s = i.y - o.y, h = Math.sqrt(M * M + v * v) || 1, T = Math.sqrt(n * n + s * s) || 1;
|
|
298
|
+
a.lineTo(o.x - M / h * u, o.y - v / h * u), a.quadraticCurveTo(o.x, o.y, o.x + n / T * u, o.y + s / T * u);
|
|
290
299
|
} else
|
|
291
300
|
a.lineTo(o.x, o.y);
|
|
292
301
|
}
|
|
293
|
-
a.lineTo(
|
|
302
|
+
a.lineTo(e[e.length - 1].x, e[e.length - 1].y);
|
|
294
303
|
}
|
|
295
|
-
function
|
|
296
|
-
for (var
|
|
297
|
-
|
|
298
|
-
for (var
|
|
299
|
-
var o = Math.abs(a[
|
|
300
|
-
if (
|
|
301
|
-
var
|
|
304
|
+
function jl(a) {
|
|
305
|
+
for (var e = 0, t = 1; t < a.length; t++)
|
|
306
|
+
e += Math.abs(a[t].x - a[t - 1].x) + Math.abs(a[t].y - a[t - 1].y);
|
|
307
|
+
for (var l = e / 2, f = 1; f < a.length; f++) {
|
|
308
|
+
var o = Math.abs(a[f].x - a[f - 1].x) + Math.abs(a[f].y - a[f - 1].y);
|
|
309
|
+
if (l <= o) {
|
|
310
|
+
var i = o > 0 ? l / o : 0;
|
|
302
311
|
return {
|
|
303
|
-
x: a[
|
|
304
|
-
y: a[
|
|
312
|
+
x: a[f - 1].x + (a[f].x - a[f - 1].x) * i,
|
|
313
|
+
y: a[f - 1].y + (a[f].y - a[f - 1].y) * i
|
|
305
314
|
};
|
|
306
315
|
}
|
|
307
|
-
|
|
316
|
+
l -= o;
|
|
308
317
|
}
|
|
309
318
|
return { x: a[0].x, y: a[0].y };
|
|
310
319
|
}
|
|
311
|
-
function
|
|
312
|
-
var
|
|
313
|
-
return { cp1x:
|
|
320
|
+
function Gt(a, e, t, l) {
|
|
321
|
+
var f = Math.abs(t - a), o = Math.max(50, f * 0.5), i = a + o, y = e, x = t - o, u = l;
|
|
322
|
+
return { cp1x: i, cp1y: y, cp2x: x, cp2y: u };
|
|
314
323
|
}
|
|
315
|
-
function
|
|
316
|
-
var
|
|
317
|
-
return { x:
|
|
324
|
+
function Yl(a, e, t, l) {
|
|
325
|
+
var f = Gt(a, e, t, l), o = 0.5, i = 1 - o, y = i * i * i * a + 3 * i * i * o * f.cp1x + 3 * i * o * o * f.cp2x + o * o * o * t, x = i * i * i * e + 3 * i * i * o * f.cp1y + 3 * i * o * o * f.cp2y + o * o * o * l;
|
|
326
|
+
return { x: y, y: x };
|
|
318
327
|
}
|
|
319
|
-
var
|
|
320
|
-
function
|
|
321
|
-
|
|
322
|
-
for (var o = Math.min(a,
|
|
323
|
-
var
|
|
324
|
-
|
|
328
|
+
var Ga = !0, It = !1, Ct = !1;
|
|
329
|
+
function tl(a, e, t, l, f) {
|
|
330
|
+
ua && Zt();
|
|
331
|
+
for (var o = Math.min(a, t) - 20, i = Math.min(e, l) - 20, y = Math.max(a, t) + 20, x = Math.max(e, l) + 20, u = po(o, i, y, x), M = [], v = 0; v < u.length; v++) {
|
|
332
|
+
var n = G[u[v]];
|
|
333
|
+
n.hidden || f[n.id] || n.type !== "group" && M.push(n);
|
|
325
334
|
}
|
|
326
|
-
return
|
|
335
|
+
return M;
|
|
327
336
|
}
|
|
328
|
-
function
|
|
329
|
-
for (var
|
|
330
|
-
var
|
|
331
|
-
if (
|
|
337
|
+
function zr(a, e, t, l) {
|
|
338
|
+
for (var f = Math.min(a, e), o = Math.max(a, e), i = 0; i < l.length; i++) {
|
|
339
|
+
var y = l[i], x = d(y), u = y.width || L, M = y.height || B;
|
|
340
|
+
if (t > x.y && t < x.y + M && o > x.x && f < x.x + u) return y;
|
|
332
341
|
}
|
|
333
342
|
return null;
|
|
334
343
|
}
|
|
335
|
-
function
|
|
336
|
-
for (var
|
|
337
|
-
var
|
|
338
|
-
if (a >
|
|
344
|
+
function wr(a, e, t, l) {
|
|
345
|
+
for (var f = Math.min(e, t), o = Math.max(e, t), i = 0; i < l.length; i++) {
|
|
346
|
+
var y = l[i], x = d(y), u = y.width || L, M = y.height || B;
|
|
347
|
+
if (a > x.x && a < x.x + u && o > x.y && f < x.y + M) return y;
|
|
339
348
|
}
|
|
340
349
|
return null;
|
|
341
350
|
}
|
|
342
|
-
function
|
|
343
|
-
if (
|
|
344
|
-
|
|
345
|
-
for (var a = 20,
|
|
346
|
-
var
|
|
347
|
-
if (!
|
|
348
|
-
var
|
|
349
|
-
if (!(
|
|
350
|
-
var o =
|
|
351
|
-
if (!(!o || !
|
|
352
|
-
var
|
|
353
|
-
u === "right" ?
|
|
354
|
-
var
|
|
355
|
-
|
|
356
|
-
var X =
|
|
357
|
-
Math.min(
|
|
358
|
-
Math.min(
|
|
359
|
-
Math.max(
|
|
360
|
-
Math.max(
|
|
361
|
-
|
|
351
|
+
function Xl() {
|
|
352
|
+
if (Ga && !(!It || q.length === 0 || G.length === 0)) {
|
|
353
|
+
It = !1, na && Ie(), ua && Zt();
|
|
354
|
+
for (var a = 20, e = !1, t = 0; t < q.length; t++) {
|
|
355
|
+
var l = q[t];
|
|
356
|
+
if (!l._customRendered) {
|
|
357
|
+
var f = l.type || "default";
|
|
358
|
+
if (!(f === "bezier" || f === "simplebezier" || f === "default")) {
|
|
359
|
+
var o = sa[l.source], i = sa[l.target];
|
|
360
|
+
if (!(!o || !i || o.hidden || i.hidden)) {
|
|
361
|
+
var y = qe(o, "source", l.sourceHandle), x = qe(i, "target", l.targetHandle), u = y.position || "right", M = x.position || "left", v = y.x, n = y.y, s = x.x, h = x.y, T = v, I = n, A = s, N = h;
|
|
362
|
+
u === "right" ? T += a : u === "left" ? T -= a : u === "bottom" ? I += a : u === "top" && (I -= a), M === "right" ? A += a : M === "left" ? A -= a : M === "bottom" ? N += a : M === "top" && (N -= a);
|
|
363
|
+
var Br = d(o), Vr = d(i), Nr = o.width || L, Dr = o.height || B, Or = i.width || L, da = i.height || B, jr = {};
|
|
364
|
+
jr[l.source] = !0, jr[l.target] = !0;
|
|
365
|
+
var X = tl(
|
|
366
|
+
Math.min(v, s) - Nr,
|
|
367
|
+
Math.min(n, h) - Dr,
|
|
368
|
+
Math.max(v, s) + Or,
|
|
369
|
+
Math.max(n, h) + da,
|
|
370
|
+
jr
|
|
362
371
|
);
|
|
363
|
-
X.push(o), X.push(
|
|
364
|
-
var
|
|
365
|
-
if (
|
|
366
|
-
var
|
|
367
|
-
if (fr ||
|
|
368
|
-
|
|
369
|
-
var
|
|
370
|
-
if (
|
|
371
|
-
var
|
|
372
|
-
|
|
372
|
+
X.push(o), X.push(i);
|
|
373
|
+
var ya = u === "left" || u === "right", Za = M === "left" || M === "right", W = null;
|
|
374
|
+
if (ya && Za) {
|
|
375
|
+
var C, fr = u === "right" && T < A, be = u === "left" && T > A;
|
|
376
|
+
if (fr || be) {
|
|
377
|
+
C = (T + A) / 2;
|
|
378
|
+
var Ka = wr(C, n, h, X);
|
|
379
|
+
if (Ka) {
|
|
380
|
+
var xa = d(Ka), Ma = Ka.width || L;
|
|
381
|
+
C = C < xa.x + Ma / 2 ? xa.x - a : xa.x + Ma + a;
|
|
373
382
|
}
|
|
374
383
|
} else
|
|
375
|
-
u === "right" ?
|
|
376
|
-
|
|
377
|
-
var
|
|
378
|
-
if (
|
|
379
|
-
var
|
|
380
|
-
|
|
384
|
+
u === "right" ? C = Math.max(Br.x + Nr, Vr.x + Or) + a : C = Math.min(Br.x, Vr.x) - a;
|
|
385
|
+
W = [{ x: v, y: n }, { x: T, y: n }, { x: C, y: n }, { x: C, y: h }, { x: A, y: h }, { x: s, y: h }];
|
|
386
|
+
var Ar = zr(C, A, h, X);
|
|
387
|
+
if (Ar) {
|
|
388
|
+
var ga = d(Ar), ka = Ar.height || B, Ta = ga.y - a, Yr = ga.y + ka + a, Xr = Math.abs(n - Ta) <= Math.abs(n - Yr) ? Ta : Yr;
|
|
389
|
+
W = [{ x: v, y: n }, { x: T, y: n }, { x: C, y: n }, { x: C, y: Xr }, { x: A, y: Xr }, { x: A, y: h }, { x: s, y: h }];
|
|
381
390
|
}
|
|
382
|
-
} else if (!
|
|
383
|
-
var
|
|
384
|
-
if (
|
|
385
|
-
|
|
386
|
-
var
|
|
387
|
-
if (
|
|
388
|
-
var
|
|
389
|
-
|
|
391
|
+
} else if (!ya && !Za) {
|
|
392
|
+
var K, ve = u === "bottom" && I < N, ba = u === "top" && I > N;
|
|
393
|
+
if (ve || ba) {
|
|
394
|
+
K = (I + N) / 2;
|
|
395
|
+
var _r = zr(v, s, K, X);
|
|
396
|
+
if (_r) {
|
|
397
|
+
var Er = d(_r), ma = _r.height || B;
|
|
398
|
+
K = K < Er.y + ma / 2 ? Er.y - a : Er.y + ma + a;
|
|
390
399
|
}
|
|
391
400
|
} else
|
|
392
|
-
u === "bottom" ?
|
|
393
|
-
|
|
394
|
-
var
|
|
395
|
-
if (
|
|
396
|
-
var
|
|
397
|
-
|
|
401
|
+
u === "bottom" ? K = Math.max(Br.y + Dr, Vr.y + da) + a : K = Math.min(Br.y, Vr.y) - a;
|
|
402
|
+
W = [{ x: v, y: n }, { x: v, y: I }, { x: v, y: K }, { x: s, y: K }, { x: s, y: N }, { x: s, y: h }];
|
|
403
|
+
var Hr = wr(s, K, N, X);
|
|
404
|
+
if (Hr) {
|
|
405
|
+
var Ra = d(Hr), Ja = Hr.height || B, za = Ra.y - a, wa = Ra.y + Ja + a, Ba = Math.abs(K - za) <= Math.abs(K - wa) ? za : wa;
|
|
406
|
+
W = [{ x: v, y: n }, { x: v, y: I }, { x: v, y: K }, { x: s, y: K }, { x: s, y: Ba }, { x: A, y: Ba }, { x: A, y: h }, { x: s, y: h }];
|
|
398
407
|
}
|
|
399
|
-
} else if (
|
|
400
|
-
|
|
401
|
-
var
|
|
402
|
-
if (
|
|
403
|
-
var
|
|
404
|
-
|
|
408
|
+
} else if (ya) {
|
|
409
|
+
W = [{ x: v, y: n }, { x: T, y: n }, { x: s, y: n }, { x: s, y: N }, { x: s, y: h }];
|
|
410
|
+
var Lr = wr(s, n, N, X);
|
|
411
|
+
if (Lr) {
|
|
412
|
+
var lr = d(Lr), Sr = Lr.width || L, Qa = Math.abs(v - lr.x + a) <= Math.abs(v - lr.x - Sr - a) ? lr.x - a : lr.x + Sr + a;
|
|
413
|
+
W = [{ x: v, y: n }, { x: T, y: n }, { x: Qa, y: n }, { x: Qa, y: h }, { x: s, y: h }, { x: s, y: N }, { x: s, y: h }];
|
|
405
414
|
}
|
|
406
|
-
var
|
|
407
|
-
if (
|
|
408
|
-
var
|
|
409
|
-
|
|
415
|
+
var pr = zr(T, s, n, X);
|
|
416
|
+
if (pr) {
|
|
417
|
+
var Cr = d(pr), Aa = pr.height || B, H = Math.abs(h - Cr.y + a) <= Math.abs(h - Cr.y - Aa - a) ? Cr.y - a : Cr.y + Aa + a;
|
|
418
|
+
W = [{ x: v, y: n }, { x: T, y: n }, { x: T, y: H }, { x: s, y: H }, { x: s, y: N }, { x: s, y: h }];
|
|
410
419
|
}
|
|
411
420
|
} else {
|
|
412
|
-
|
|
413
|
-
var
|
|
414
|
-
if (
|
|
415
|
-
var
|
|
416
|
-
|
|
421
|
+
W = [{ x: v, y: n }, { x: v, y: I }, { x: v, y: h }, { x: A, y: h }, { x: s, y: h }];
|
|
422
|
+
var Wr = zr(v, A, h, X);
|
|
423
|
+
if (Wr) {
|
|
424
|
+
var _a = d(Wr), vr = Wr.height || B, Pr = Math.abs(n - _a.y + a) <= Math.abs(n - _a.y - vr - a) ? _a.y - a : _a.y + vr + a;
|
|
425
|
+
W = [{ x: v, y: n }, { x: v, y: I }, { x: v, y: Pr }, { x: A, y: Pr }, { x: A, y: h }, { x: s, y: h }];
|
|
417
426
|
}
|
|
418
|
-
var
|
|
419
|
-
if (
|
|
420
|
-
var
|
|
421
|
-
|
|
427
|
+
var Mr = wr(v, I, h, X);
|
|
428
|
+
if (Mr) {
|
|
429
|
+
var nr = d(Mr), $a = Mr.width || L, Fa = Math.abs(s - nr.x + a) <= Math.abs(s - nr.x - $a - a) ? nr.x - a : nr.x + $a + a;
|
|
430
|
+
W = [{ x: v, y: n }, { x: v, y: I }, { x: Fa, y: I }, { x: Fa, y: h }, { x: A, y: h }, { x: s, y: h }];
|
|
422
431
|
}
|
|
423
432
|
}
|
|
424
|
-
if (
|
|
425
|
-
for (var
|
|
426
|
-
var
|
|
427
|
-
(Math.abs(
|
|
433
|
+
if (W) {
|
|
434
|
+
for (var ra = [W[0]], hr = 1; hr < W.length; hr++) {
|
|
435
|
+
var ne = ra[ra.length - 1];
|
|
436
|
+
(Math.abs(W[hr].x - ne.x) > 0.1 || Math.abs(W[hr].y - ne.y) > 0.1) && ra.push(W[hr]);
|
|
428
437
|
}
|
|
429
|
-
|
|
438
|
+
l._routedPoints = ra, e = !0;
|
|
430
439
|
}
|
|
431
440
|
}
|
|
432
441
|
}
|
|
433
442
|
}
|
|
434
443
|
}
|
|
435
|
-
|
|
444
|
+
e && Q();
|
|
436
445
|
}
|
|
437
446
|
}
|
|
438
|
-
function
|
|
439
|
-
|
|
440
|
-
|
|
447
|
+
function Se() {
|
|
448
|
+
Ga && (Ct || (Ct = !0, It = !0, requestAnimationFrame(function() {
|
|
449
|
+
Ct = !1;
|
|
441
450
|
try {
|
|
442
|
-
|
|
451
|
+
Xl();
|
|
443
452
|
} catch (a) {
|
|
444
453
|
console.error("[worker] async routing error:", a);
|
|
445
454
|
}
|
|
446
455
|
})));
|
|
447
456
|
}
|
|
448
|
-
function
|
|
457
|
+
function Ke() {
|
|
449
458
|
if (r) {
|
|
450
459
|
var a = performance.now();
|
|
451
|
-
r.clearRect(0, 0,
|
|
452
|
-
var
|
|
453
|
-
if (
|
|
454
|
-
if (
|
|
455
|
-
if ((
|
|
456
|
-
var
|
|
457
|
-
r.save(), r.translate(
|
|
458
|
-
var
|
|
459
|
-
|
|
460
|
+
r.clearRect(0, 0, tr, or);
|
|
461
|
+
var e = Wt * g.zoom;
|
|
462
|
+
if (e > 2)
|
|
463
|
+
if (Fr === "lines" && e >= 4 && e <= 512) {
|
|
464
|
+
if ((Ia || al !== e || el !== Fr) && Ol(e), va && rl > 0) {
|
|
465
|
+
var t = (g.x % e + e) % e, l = (g.y % e + e) % e;
|
|
466
|
+
r.save(), r.translate(t, l);
|
|
467
|
+
var f = r.createPattern(va, "repeat");
|
|
468
|
+
f && (r.fillStyle = f, r.fillRect(-t, -l, tr, or)), r.restore();
|
|
460
469
|
}
|
|
461
470
|
} else {
|
|
462
|
-
var o = (
|
|
463
|
-
if (
|
|
464
|
-
r.fillStyle =
|
|
465
|
-
for (var
|
|
466
|
-
for (var
|
|
467
|
-
r.beginPath(), r.arc(Math.round(u), Math.round(
|
|
468
|
-
} else if (
|
|
469
|
-
r.strokeStyle =
|
|
470
|
-
var
|
|
471
|
+
var o = (g.x % e + e) % e, i = (g.y % e + e) % e, y = Pe || k.grid;
|
|
472
|
+
if (Fr === "dots") {
|
|
473
|
+
r.fillStyle = y;
|
|
474
|
+
for (var x = ha * g.zoom, u = o; u < tr; u += e)
|
|
475
|
+
for (var M = i; M < or; M += e)
|
|
476
|
+
r.beginPath(), r.arc(Math.round(u), Math.round(M), x, 0, 6.2832), r.fill();
|
|
477
|
+
} else if (Fr === "cross") {
|
|
478
|
+
r.strokeStyle = y, r.lineWidth = ha;
|
|
479
|
+
var v = 3 * g.zoom;
|
|
471
480
|
r.beginPath();
|
|
472
|
-
for (var
|
|
473
|
-
for (var s =
|
|
474
|
-
var
|
|
475
|
-
r.moveTo(
|
|
481
|
+
for (var n = o; n < tr; n += e)
|
|
482
|
+
for (var s = i; s < or; s += e) {
|
|
483
|
+
var h = Math.round(n), T = Math.round(s);
|
|
484
|
+
r.moveTo(h - v, T), r.lineTo(h + v, T), r.moveTo(h, T - v), r.lineTo(h, T + v);
|
|
476
485
|
}
|
|
477
486
|
r.stroke();
|
|
478
487
|
} else {
|
|
479
|
-
var
|
|
480
|
-
r.beginPath(), r.strokeStyle =
|
|
481
|
-
for (var
|
|
482
|
-
var
|
|
483
|
-
r.moveTo(
|
|
488
|
+
var I = Pe || k.grid;
|
|
489
|
+
r.beginPath(), r.strokeStyle = I, r.lineWidth = ha * 0.5;
|
|
490
|
+
for (var A = o; A < tr; A += e) {
|
|
491
|
+
var N = Math.round(A) + 0.5;
|
|
492
|
+
r.moveTo(N, 0), r.lineTo(N, or);
|
|
484
493
|
}
|
|
485
|
-
for (var
|
|
486
|
-
var
|
|
487
|
-
r.moveTo(0,
|
|
494
|
+
for (var Br = i; Br < or; Br += e) {
|
|
495
|
+
var Vr = Math.round(Br) + 0.5;
|
|
496
|
+
r.moveTo(0, Vr), r.lineTo(tr, Vr);
|
|
488
497
|
}
|
|
489
498
|
r.stroke();
|
|
490
499
|
}
|
|
491
500
|
}
|
|
492
|
-
r.beginPath(), r.arc(
|
|
493
|
-
var
|
|
494
|
-
if (
|
|
495
|
-
var
|
|
496
|
-
if (
|
|
497
|
-
r.shadowColor =
|
|
498
|
-
for (var
|
|
499
|
-
var
|
|
500
|
-
r.roundRect(
|
|
501
|
+
r.beginPath(), r.arc(g.x, g.y, 4 * g.zoom, 0, 6.2832), r.fillStyle = k.origin, r.fill(), r.save(), r.translate(g.x, g.y), r.scale(g.zoom, g.zoom);
|
|
502
|
+
var Nr = 100, Dr = -g.x / g.zoom, Or = -g.y / g.zoom, da = Dr + tr / g.zoom, jr = Or + or / g.zoom, X = Dr - Nr, ya = Or - Nr, Za = da + Nr, W = jr + Nr;
|
|
503
|
+
if (Y.length > 0) {
|
|
504
|
+
var C = co(Dr, Or, da, jr), fr = C.length, be = g.zoom > 0.15, Ka = g.zoom > 0.3, xa = g.zoom > 0.08 && fr < 200;
|
|
505
|
+
if (xa) {
|
|
506
|
+
r.shadowColor = k.cardShadow, r.shadowBlur = 6, r.shadowOffsetY = 2, r.fillStyle = k.cardBg, r.beginPath();
|
|
507
|
+
for (var Ma = 0; Ma < fr; Ma++) {
|
|
508
|
+
var Ar = Y[C[Ma]];
|
|
509
|
+
r.roundRect(Ar.x, Ar.y, Ar.w, Ar.h, ae);
|
|
501
510
|
}
|
|
502
511
|
r.fill(), r.shadowColor = "transparent", r.shadowBlur = 0, r.shadowOffsetY = 0;
|
|
503
512
|
}
|
|
504
|
-
if (!
|
|
505
|
-
r.fillStyle =
|
|
506
|
-
for (var
|
|
507
|
-
var
|
|
508
|
-
r.roundRect(
|
|
513
|
+
if (!xa) {
|
|
514
|
+
r.fillStyle = k.cardBg, r.beginPath();
|
|
515
|
+
for (var ga = 0; ga < fr; ga++) {
|
|
516
|
+
var ka = Y[C[ga]];
|
|
517
|
+
r.roundRect(ka.x, ka.y, ka.w, ka.h, ae);
|
|
509
518
|
}
|
|
510
519
|
r.fill();
|
|
511
520
|
}
|
|
512
|
-
r.strokeStyle =
|
|
513
|
-
for (var
|
|
514
|
-
var
|
|
515
|
-
r.roundRect(
|
|
521
|
+
r.strokeStyle = k.cardBorder, r.lineWidth = 0.5, r.beginPath();
|
|
522
|
+
for (var Ta = 0; Ta < fr; Ta++) {
|
|
523
|
+
var Yr = Y[C[Ta]];
|
|
524
|
+
r.roundRect(Yr.x, Yr.y, Yr.w, Yr.h, ae);
|
|
516
525
|
}
|
|
517
526
|
r.stroke();
|
|
518
|
-
for (var
|
|
519
|
-
var
|
|
520
|
-
|
|
527
|
+
for (var Xr = [{}, {}, {}, {}], K = 0; K < fr; K++) {
|
|
528
|
+
var ve = C[K], ba = ve % 4;
|
|
529
|
+
Xr[ba].items || (Xr[ba].items = []), Xr[ba].items.push(Y[ve]);
|
|
521
530
|
}
|
|
522
|
-
for (var
|
|
523
|
-
var
|
|
524
|
-
if (!(!
|
|
525
|
-
r.fillStyle =
|
|
526
|
-
for (var
|
|
527
|
-
var
|
|
528
|
-
r.roundRect(
|
|
531
|
+
for (var _r = 0; _r < 4; _r++) {
|
|
532
|
+
var Er = Xr[_r].items;
|
|
533
|
+
if (!(!Er || Er.length === 0)) {
|
|
534
|
+
r.fillStyle = $l[_r], r.beginPath();
|
|
535
|
+
for (var ma = 0; ma < Er.length; ma++) {
|
|
536
|
+
var Hr = Er[ma];
|
|
537
|
+
r.roundRect(Hr.x, Hr.y, Hr.w, 30, [ae, ae, 0, 0]);
|
|
529
538
|
}
|
|
530
539
|
r.fill();
|
|
531
540
|
}
|
|
532
541
|
}
|
|
533
|
-
if (
|
|
534
|
-
r.fillStyle =
|
|
535
|
-
for (var
|
|
536
|
-
var
|
|
537
|
-
r.fillText(
|
|
538
|
-
}
|
|
539
|
-
r.fillStyle =
|
|
540
|
-
for (var
|
|
541
|
-
var
|
|
542
|
-
r.fillText(
|
|
543
|
-
}
|
|
544
|
-
if (
|
|
545
|
-
r.fillStyle =
|
|
546
|
-
for (var
|
|
547
|
-
var
|
|
548
|
-
r.fillText("(" +
|
|
542
|
+
if (be) {
|
|
543
|
+
r.fillStyle = k.titleText, r.font = Fl;
|
|
544
|
+
for (var Ra = 0; Ra < fr; Ra++) {
|
|
545
|
+
var Ja = Y[C[Ra]];
|
|
546
|
+
r.fillText(Ja.title, Ja.x + 12, Ja.y + 19);
|
|
547
|
+
}
|
|
548
|
+
r.fillStyle = k.bodyText, r.font = Ul;
|
|
549
|
+
for (var za = 0; za < fr; za++) {
|
|
550
|
+
var wa = Y[C[za]];
|
|
551
|
+
r.fillText(wa.body, wa.x + 12, wa.y + 52);
|
|
552
|
+
}
|
|
553
|
+
if (Ka) {
|
|
554
|
+
r.fillStyle = k.coordText, r.font = cl;
|
|
555
|
+
for (var Ba = 0; Ba < fr; Ba++) {
|
|
556
|
+
var Lr = Y[C[Ba]];
|
|
557
|
+
r.fillText("(" + Lr.x + ", " + Lr.y + ")", Lr.x + 12, Lr.y + 75);
|
|
549
558
|
}
|
|
550
559
|
}
|
|
551
560
|
}
|
|
552
561
|
}
|
|
553
|
-
var
|
|
554
|
-
if (
|
|
555
|
-
if (
|
|
556
|
-
for (var
|
|
557
|
-
var
|
|
558
|
-
|
|
562
|
+
var lr = [], Sr = null;
|
|
563
|
+
if (G.length > 0)
|
|
564
|
+
if (Sr = {}, G.length > 100)
|
|
565
|
+
for (var Qa = po(X, ya, Za, W), pr = 0; pr < Qa.length; pr++) {
|
|
566
|
+
var Cr = G[Qa[pr]];
|
|
567
|
+
Sr[Cr.id] = !0, Cr._customRendered || lr.push(Cr);
|
|
559
568
|
}
|
|
560
569
|
else
|
|
561
|
-
for (var
|
|
562
|
-
var H =
|
|
570
|
+
for (var Aa = 0; Aa < G.length; Aa++) {
|
|
571
|
+
var H = G[Aa];
|
|
563
572
|
if (!H.hidden) {
|
|
564
|
-
var
|
|
565
|
-
d(H).x +
|
|
573
|
+
var Wr = H.width || L, _a = H.height || B;
|
|
574
|
+
d(H).x + Wr < X || d(H).x > Za || d(H).y + _a < ya || d(H).y > W || (Sr[H.id] = !0, H._customRendered || lr.push(H));
|
|
566
575
|
}
|
|
567
576
|
}
|
|
568
|
-
var
|
|
569
|
-
if (
|
|
570
|
-
let
|
|
571
|
-
if (
|
|
572
|
-
r.fillStyle =
|
|
573
|
-
for (var
|
|
574
|
-
var j =
|
|
577
|
+
var vr = lr.length;
|
|
578
|
+
if (q.length > 0 && G.length > 0) {
|
|
579
|
+
let Le = function(Qr, $o) {
|
|
580
|
+
if (Qr.length) {
|
|
581
|
+
r.fillStyle = $o, r.beginPath();
|
|
582
|
+
for (var At = 0; At < Qr.length; At++) {
|
|
583
|
+
var j = Qr[At];
|
|
575
584
|
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();
|
|
576
585
|
}
|
|
577
586
|
r.fill();
|
|
578
587
|
}
|
|
579
588
|
};
|
|
580
|
-
var
|
|
581
|
-
|
|
582
|
-
var
|
|
583
|
-
if (
|
|
584
|
-
var
|
|
585
|
-
|
|
586
|
-
for (var
|
|
587
|
-
var
|
|
588
|
-
if (
|
|
589
|
-
for (var
|
|
590
|
-
var
|
|
591
|
-
|
|
589
|
+
var Hl = Le;
|
|
590
|
+
Ze && Dl();
|
|
591
|
+
var Pr = null, Mr = null, nr = null, $a = [], Fa = [], ra = [], hr = [], ne = g.zoom > 0.3, ol = g.zoom > 0.05, Ea;
|
|
592
|
+
if (Sr && G.length > 100) {
|
|
593
|
+
var Kt = {};
|
|
594
|
+
Ea = [];
|
|
595
|
+
for (var ll in Sr) {
|
|
596
|
+
var Je = $r[ll];
|
|
597
|
+
if (Je)
|
|
598
|
+
for (var Qe = 0; Qe < Je.length; Qe++) {
|
|
599
|
+
var $e = Je[Qe];
|
|
600
|
+
Kt[$e] || (Kt[$e] = !0, Ea.push($e));
|
|
592
601
|
}
|
|
593
602
|
}
|
|
594
603
|
} else {
|
|
595
|
-
|
|
596
|
-
for (var
|
|
604
|
+
Ea = [];
|
|
605
|
+
for (var Fe = 0; Fe < q.length; Fe++) Ea.push(Fe);
|
|
597
606
|
}
|
|
598
|
-
for (var
|
|
599
|
-
var D =
|
|
600
|
-
if (!(!
|
|
601
|
-
var
|
|
602
|
-
|
|
603
|
-
var
|
|
604
|
-
if (
|
|
605
|
-
|
|
606
|
-
else if (
|
|
607
|
-
|
|
608
|
-
else if (
|
|
607
|
+
for (var Ue = 0; Ue < Ea.length; Ue++) {
|
|
608
|
+
var D = q[Ea[Ue]], aa = Vo(D.source), ea = Vo(D.target);
|
|
609
|
+
if (!(!aa || !ea) && !(aa.hidden || ea.hidden) && !D._customRendered) {
|
|
610
|
+
var he = qe(aa, "source", D.sourceHandle), ue = qe(ea, "target", D.targetHandle), _ = he.x, w = he.y, R = ue.x, z = ue.y, ur = D.type || "default", bt = D.selected, Jt = D.animated, b;
|
|
611
|
+
bt ? (Mr || (Mr = new Path2D()), b = Mr) : Jt ? (nr || (nr = new Path2D()), b = nr) : (Pr || (Pr = new Path2D()), b = Pr);
|
|
612
|
+
var J = D._routedPoints;
|
|
613
|
+
if (J && J.length >= 2)
|
|
614
|
+
Yo(b, J);
|
|
615
|
+
else if (ur === "straight")
|
|
616
|
+
b.moveTo(_, w), b.lineTo(R, z);
|
|
617
|
+
else if (ur === "step" || ur === "smoothstep")
|
|
609
618
|
try {
|
|
610
|
-
var p =
|
|
611
|
-
p === "right" ?
|
|
612
|
-
var
|
|
613
|
-
|
|
614
|
-
var ar =
|
|
615
|
-
Math.min(
|
|
616
|
-
Math.min(w,
|
|
617
|
-
Math.max(
|
|
618
|
-
Math.max(w,
|
|
619
|
-
|
|
619
|
+
var p = he.position || "right", La = ue.position || "left", m = 20, F = _, O = w, U = R, rr = z;
|
|
620
|
+
p === "right" ? F += m : p === "left" ? F -= m : p === "bottom" ? O += m : p === "top" && (O -= m), La === "right" ? U += m : La === "left" ? U -= m : La === "bottom" ? rr += m : La === "top" && (rr -= m);
|
|
621
|
+
var se = d(aa), de = d(ea), Ua = aa.width || L, ca = aa.height || B, Qt = ea.width || L, $t = ea.height || B, ce = p === "left" || p === "right", Ft = La === "left" || La === "right", Ve = {};
|
|
622
|
+
Ve[D.source] = !0, Ve[D.target] = !0;
|
|
623
|
+
var ar = tl(
|
|
624
|
+
Math.min(_, R) - Ua,
|
|
625
|
+
Math.min(w, z) - ca,
|
|
626
|
+
Math.max(_, R) + Qt,
|
|
627
|
+
Math.max(w, z) + $t,
|
|
628
|
+
Ve
|
|
620
629
|
);
|
|
621
|
-
ar.push(
|
|
622
|
-
var
|
|
623
|
-
if (
|
|
624
|
-
var
|
|
625
|
-
if (
|
|
626
|
-
|
|
627
|
-
var
|
|
628
|
-
if (
|
|
629
|
-
var
|
|
630
|
-
|
|
630
|
+
ar.push(aa), ar.push(ea);
|
|
631
|
+
var Z = [];
|
|
632
|
+
if (ce && Ft) {
|
|
633
|
+
var c, il = p === "right" && F < U, fl = p === "left" && F > U;
|
|
634
|
+
if (il || fl) {
|
|
635
|
+
c = (F + U) / 2;
|
|
636
|
+
var Ne = wr(c, w, z, ar);
|
|
637
|
+
if (Ne) {
|
|
638
|
+
var De = d(Ne), Wr = Ne.width || L;
|
|
639
|
+
c < De.x + Wr / 2 ? c = De.x - m : c = De.x + Wr + m;
|
|
631
640
|
}
|
|
632
641
|
} else
|
|
633
|
-
p === "right" ?
|
|
634
|
-
|
|
635
|
-
var
|
|
636
|
-
if (
|
|
637
|
-
var
|
|
638
|
-
|
|
639
|
-
{ x:
|
|
640
|
-
{ x:
|
|
641
|
-
{ x:
|
|
642
|
-
{ x:
|
|
643
|
-
{ x:
|
|
642
|
+
p === "right" ? c = Math.max(se.x + Ua, de.x + Qt) + m : c = Math.min(se.x, de.x) - m;
|
|
643
|
+
Z = [{ x: F, y: w }, { x: c, y: w }, { x: c, y: z }, { x: U, y: z }];
|
|
644
|
+
var Oe = zr(c, U, z, ar);
|
|
645
|
+
if (Oe) {
|
|
646
|
+
var Ut = d(Oe), vl = Oe.height || B, ct = Ut.y - m, Vt = Ut.y + vl + m, Nt = Math.abs(w - ct) <= Math.abs(w - Vt) ? ct : Vt;
|
|
647
|
+
Z = [
|
|
648
|
+
{ x: F, y: w },
|
|
649
|
+
{ x: c, y: w },
|
|
650
|
+
{ x: c, y: Nt },
|
|
651
|
+
{ x: U, y: Nt },
|
|
652
|
+
{ x: U, y: z }
|
|
644
653
|
];
|
|
645
654
|
}
|
|
646
|
-
var
|
|
647
|
-
if (
|
|
648
|
-
var
|
|
649
|
-
|
|
655
|
+
var je = zr(F, c, w, ar);
|
|
656
|
+
if (je) {
|
|
657
|
+
var Dt = d(je), nl = je.height || B, Ot = Dt.y - m, jt = Dt.y + nl + m, Yt = Math.abs(z - Ot) <= Math.abs(z - jt) ? Ot : jt;
|
|
658
|
+
Z.splice(
|
|
650
659
|
1,
|
|
651
660
|
0,
|
|
652
|
-
{ x:
|
|
653
|
-
{ x:
|
|
654
|
-
),
|
|
655
|
-
return !(Math.abs(
|
|
656
|
-
}),
|
|
661
|
+
{ x: F, y: Yt },
|
|
662
|
+
{ x: c, y: Yt }
|
|
663
|
+
), Z = Z.filter(function(Qr, $o) {
|
|
664
|
+
return !(Math.abs(Qr.x - c) < 1 && Math.abs(Qr.y - w) < 1);
|
|
665
|
+
}), Z.splice(0, 0, { x: F, y: w });
|
|
657
666
|
}
|
|
658
|
-
} else if (!
|
|
659
|
-
var
|
|
660
|
-
if (
|
|
661
|
-
|
|
662
|
-
var
|
|
663
|
-
if (
|
|
664
|
-
var
|
|
665
|
-
|
|
667
|
+
} else if (!ce && !Ft) {
|
|
668
|
+
var V, hl = p === "bottom" && O < rr, ul = p === "top" && O > rr;
|
|
669
|
+
if (hl || ul) {
|
|
670
|
+
V = (O + rr) / 2;
|
|
671
|
+
var Ye = zr(_, R, V, ar);
|
|
672
|
+
if (Ye) {
|
|
673
|
+
var Xe = d(Ye), Xt = Ye.height || B;
|
|
674
|
+
V < Xe.y + Xt / 2 ? V = Xe.y - m : V = Xe.y + Xt + m;
|
|
666
675
|
}
|
|
667
676
|
} else
|
|
668
|
-
p === "bottom" ?
|
|
669
|
-
|
|
670
|
-
var
|
|
671
|
-
if (
|
|
672
|
-
var
|
|
673
|
-
|
|
674
|
-
{ x:
|
|
675
|
-
{ x:
|
|
676
|
-
{ x:
|
|
677
|
-
{ x:
|
|
678
|
-
{ x:
|
|
677
|
+
p === "bottom" ? V = Math.max(se.y + ca, de.y + $t) + m : V = Math.min(se.y, de.y) - m;
|
|
678
|
+
Z = [{ x: _, y: O }, { x: _, y: V }, { x: R, y: V }, { x: R, y: rr }];
|
|
679
|
+
var He = wr(_, O, V, ar);
|
|
680
|
+
if (He) {
|
|
681
|
+
var Ht = d(He), sl = He.width || L, pt = Ht.x - m, ro = Ht.x + sl + m, ao = Math.abs(R - pt) <= Math.abs(R - ro) ? pt : ro;
|
|
682
|
+
Z = [
|
|
683
|
+
{ x: _, y: O },
|
|
684
|
+
{ x: ao, y: O },
|
|
685
|
+
{ x: ao, y: V },
|
|
686
|
+
{ x: R, y: V },
|
|
687
|
+
{ x: R, y: rr }
|
|
679
688
|
];
|
|
680
689
|
}
|
|
681
|
-
var
|
|
682
|
-
if (
|
|
683
|
-
var
|
|
684
|
-
|
|
685
|
-
|
|
690
|
+
var pe = wr(R, V, rr, ar);
|
|
691
|
+
if (pe) {
|
|
692
|
+
var eo = d(pe), dl = pe.height || B, to = eo.y - m, oo = eo.y + dl + m, yl = Math.abs(V - to) <= Math.abs(V - oo) ? to : oo;
|
|
693
|
+
Z.splice(
|
|
694
|
+
Z.length - 1,
|
|
686
695
|
0,
|
|
687
|
-
{ x:
|
|
696
|
+
{ x: U, y: yl }
|
|
688
697
|
);
|
|
689
698
|
}
|
|
690
|
-
} else if (
|
|
691
|
-
|
|
692
|
-
var
|
|
693
|
-
if (
|
|
694
|
-
var
|
|
695
|
-
|
|
699
|
+
} else if (ce) {
|
|
700
|
+
Z = [{ x: F, y: w }, { x: R, y: w }, { x: R, y: rr }];
|
|
701
|
+
var rt = wr(R, w, rr, ar);
|
|
702
|
+
if (rt) {
|
|
703
|
+
var lo = d(rt), xl = rt.width || L, io = lo.x - m, fo = lo.x + xl + m, vo = Math.abs(_ - io) <= Math.abs(_ - fo) ? io : fo;
|
|
704
|
+
Z = [{ x: F, y: w }, { x: vo, y: w }, { x: vo, y: z }, { x: R, y: z }, { x: R, y: rr }];
|
|
696
705
|
}
|
|
697
|
-
var
|
|
698
|
-
if (
|
|
699
|
-
var
|
|
700
|
-
|
|
706
|
+
var at = zr(F, R, w, ar);
|
|
707
|
+
if (at) {
|
|
708
|
+
var no = d(at), Ml = at.height || B, ho = no.y - m, uo = no.y + Ml + m, so = Math.abs(z - ho) <= Math.abs(z - uo) ? ho : uo;
|
|
709
|
+
Z = [{ x: F, y: w }, { x: F, y: so }, { x: R, y: so }, { x: R, y: rr }];
|
|
701
710
|
}
|
|
702
711
|
} else {
|
|
703
|
-
|
|
704
|
-
var
|
|
705
|
-
if (
|
|
706
|
-
var
|
|
707
|
-
|
|
712
|
+
Z = [{ x: _, y: O }, { x: _, y: z }, { x: U, y: z }];
|
|
713
|
+
var et = zr(_, U, z, ar);
|
|
714
|
+
if (et) {
|
|
715
|
+
var yo = d(et), gl = et.height || B, xo = yo.y - m, Mo = yo.y + gl + m, go = Math.abs(w - xo) <= Math.abs(w - Mo) ? xo : Mo;
|
|
716
|
+
Z = [{ x: _, y: O }, { x: _, y: go }, { x: U, y: go }, { x: U, y: z }];
|
|
708
717
|
}
|
|
709
|
-
var
|
|
710
|
-
if (
|
|
711
|
-
var
|
|
712
|
-
|
|
718
|
+
var tt = wr(_, O, z, ar);
|
|
719
|
+
if (tt) {
|
|
720
|
+
var ko = d(tt), kl = tt.width || L, To = ko.x - m, mo = ko.x + kl + m, Ro = Math.abs(R - To) <= Math.abs(R - mo) ? To : mo;
|
|
721
|
+
Z = [{ x: _, y: O }, { x: Ro, y: O }, { x: Ro, y: z }, { x: U, y: z }];
|
|
713
722
|
}
|
|
714
723
|
}
|
|
715
|
-
for (var
|
|
716
|
-
|
|
717
|
-
for (var
|
|
718
|
-
var
|
|
719
|
-
(Math.abs(
|
|
724
|
+
for (var ta = [{ x: _, y: w }], ot = 0; ot < Z.length; ot++) ta.push(Z[ot]);
|
|
725
|
+
ta.push({ x: R, y: z });
|
|
726
|
+
for (var er = [ta[0]], Va = 1; Va < ta.length; Va++) {
|
|
727
|
+
var Na = er[er.length - 1];
|
|
728
|
+
(Math.abs(ta[Va].x - Na.x) > 0.1 || Math.abs(ta[Va].y - Na.y) > 0.1) && er.push(ta[Va]);
|
|
720
729
|
}
|
|
721
|
-
var
|
|
722
|
-
|
|
723
|
-
for (var
|
|
724
|
-
if (
|
|
725
|
-
var
|
|
726
|
-
if (Math.abs(
|
|
727
|
-
|
|
730
|
+
var zo = ur === "smoothstep" ? 8 : 0;
|
|
731
|
+
b.moveTo(er[0].x, er[0].y);
|
|
732
|
+
for (var gr = 1; gr < er.length; gr++)
|
|
733
|
+
if (zo > 0 && gr > 0 && gr < er.length - 1) {
|
|
734
|
+
var kr = er[gr - 1], S = er[gr], qr = er[gr + 1];
|
|
735
|
+
if (Math.abs(kr.x - S.x) < 0.5 && Math.abs(S.x - qr.x) < 0.5 || Math.abs(kr.y - S.y) < 0.5 && Math.abs(S.y - qr.y) < 0.5)
|
|
736
|
+
b.lineTo(S.x, S.y);
|
|
728
737
|
else {
|
|
729
|
-
var
|
|
730
|
-
Math.abs(
|
|
738
|
+
var ye = Math.min(Math.hypot(kr.x - S.x, kr.y - S.y) / 2, Math.hypot(S.x - qr.x, S.y - qr.y) / 2, zo);
|
|
739
|
+
Math.abs(kr.y - S.y) < 0.5 ? (b.lineTo(S.x + (kr.x < qr.x ? -1 : 1) * ye, S.y), b.quadraticCurveTo(S.x, S.y, S.x, S.y + (kr.y < qr.y ? 1 : -1) * ye)) : (b.lineTo(S.x, S.y + (kr.y < qr.y ? -1 : 1) * ye), b.quadraticCurveTo(S.x, S.y, S.x + (kr.x < qr.x ? 1 : -1) * ye, S.y));
|
|
731
740
|
}
|
|
732
741
|
} else
|
|
733
|
-
|
|
734
|
-
} catch (
|
|
735
|
-
console.error("[worker] smoothstep error:",
|
|
742
|
+
b.lineTo(er[gr].x, er[gr].y);
|
|
743
|
+
} catch (Qr) {
|
|
744
|
+
console.error("[worker] smoothstep error:", Qr, "edge:", D.id);
|
|
736
745
|
}
|
|
737
746
|
else {
|
|
738
|
-
var
|
|
739
|
-
|
|
740
|
-
var
|
|
741
|
-
|
|
747
|
+
var Gr = he.position || "right", Ir = ue.position || "left", Zr = 20, Da = _, xe = w, Oa = R, Me = z;
|
|
748
|
+
Gr === "right" ? Da += Zr : Gr === "left" ? Da -= Zr : Gr === "bottom" ? xe += Zr : Gr === "top" && (xe -= Zr), Ir === "right" ? Oa += Zr : Ir === "left" ? Oa -= Zr : Ir === "bottom" ? Me += Zr : Ir === "top" && (Me -= Zr);
|
|
749
|
+
var Tl = Math.abs(Oa - Da), Kr = Math.max(50, Tl * 0.5), ml = Da + (Gr === "left" ? -Kr : Gr === "right" ? Kr : 0), Rl = xe + (Gr === "top" ? -Kr : Gr === "bottom" ? Kr : 0), zl = Oa + (Ir === "left" ? -Kr : Ir === "right" ? Kr : 0), wl = Me + (Ir === "top" ? -Kr : Ir === "bottom" ? Kr : 0);
|
|
750
|
+
b.moveTo(_, w), b.lineTo(Da, xe), b.bezierCurveTo(ml, Rl, zl, wl, Oa, Me), b.lineTo(R, z);
|
|
742
751
|
}
|
|
743
|
-
if (
|
|
744
|
-
var
|
|
745
|
-
if (
|
|
746
|
-
var
|
|
747
|
-
|
|
748
|
-
} else if (
|
|
749
|
-
|
|
750
|
-
else if (
|
|
751
|
-
|
|
752
|
+
if (ol) {
|
|
753
|
+
var Bl = 8, ja;
|
|
754
|
+
if (J && J.length >= 2) {
|
|
755
|
+
var Na = J[J.length - 1], wo = J[J.length - 2];
|
|
756
|
+
ja = Math.atan2(Na.y - wo.y, Na.x - wo.x);
|
|
757
|
+
} else if (ur === "straight")
|
|
758
|
+
ja = Math.atan2(z - w, R - _);
|
|
759
|
+
else if (ur === "step" || ur === "smoothstep")
|
|
760
|
+
ja = 0;
|
|
752
761
|
else {
|
|
753
|
-
var
|
|
754
|
-
|
|
762
|
+
var Bo = Gt(_, w, R, z);
|
|
763
|
+
ja = Math.atan2(z - Bo.cp2y, R - Bo.cp2x);
|
|
755
764
|
}
|
|
756
|
-
var
|
|
757
|
-
|
|
765
|
+
var Ao = J && J.length >= 2 ? J[J.length - 1] : { x: R, y: z }, lt = { x: Ao.x, y: Ao.y, angle: ja, size: Bl };
|
|
766
|
+
bt ? Fa.push(lt) : Jt ? ra.push(lt) : $a.push(lt);
|
|
758
767
|
}
|
|
759
|
-
if (
|
|
760
|
-
var
|
|
761
|
-
|
|
768
|
+
if (ne && D.label) {
|
|
769
|
+
var Ya;
|
|
770
|
+
J && J.length >= 2 ? Ya = jl(J) : ur === "straight" || ur === "step" || ur === "smoothstep" ? Ya = { x: (_ + R) / 2, y: (w + z) / 2 } : Ya = Yl(_, w, R, z), hr.push({ text: D.label, x: Ya.x, y: Ya.y });
|
|
762
771
|
}
|
|
763
772
|
}
|
|
764
773
|
}
|
|
765
|
-
if (
|
|
766
|
-
r.font =
|
|
767
|
-
for (var
|
|
768
|
-
var
|
|
769
|
-
r.fillStyle =
|
|
774
|
+
if (Pr && (r.strokeStyle = k.edgeStroke, r.lineWidth = 1.5, r.setLineDash([]), r.stroke(Pr)), nr && (r.strokeStyle = k.edgeAnimated, r.lineWidth = 1.5, r.setLineDash([5, 5]), r.lineDashOffset = -qt, r.stroke(nr), r.setLineDash([])), Mr && (r.strokeStyle = k.edgeSelected, r.lineWidth = 2.5, r.setLineDash([]), r.stroke(Mr)), Le($a, k.edgeStroke), Le(ra, k.edgeAnimated), Le(Fa, k.edgeSelected), hr.length > 0) {
|
|
775
|
+
r.font = Vl, r.textAlign = "center", r.textBaseline = "middle";
|
|
776
|
+
for (var it = 0; it < hr.length; it++) {
|
|
777
|
+
var Sa = hr[it], Al = r.measureText(Sa.text), _o = Al.width + 12;
|
|
778
|
+
r.fillStyle = $ ? "#2a2a2a" : "#ffffff", r.fillRect(Sa.x - _o / 2, Sa.y - 9, _o, 18), r.fillStyle = k.nodeText, r.fillText(Sa.text, Sa.x, Sa.y);
|
|
770
779
|
}
|
|
771
780
|
r.textAlign = "start", r.textBaseline = "alphabetic";
|
|
772
781
|
}
|
|
773
782
|
}
|
|
774
|
-
if (
|
|
775
|
-
r.beginPath(), r.strokeStyle =
|
|
776
|
-
var
|
|
777
|
-
if (
|
|
778
|
-
var
|
|
779
|
-
|
|
783
|
+
if (ee) {
|
|
784
|
+
r.beginPath(), r.strokeStyle = k.connectionLine, r.lineWidth = 2, r.setLineDash([6, 4]);
|
|
785
|
+
var ft = ee._routedPoints;
|
|
786
|
+
if (ft && ft.length >= 2) {
|
|
787
|
+
var Eo = new Path2D();
|
|
788
|
+
Yo(Eo, ft), r.stroke(Eo);
|
|
780
789
|
} else {
|
|
781
|
-
var
|
|
782
|
-
r.moveTo(
|
|
790
|
+
var ge = ee.from, ke = ee.to, Te = Gt(ge.x, ge.y, ke.x, ke.y);
|
|
791
|
+
r.moveTo(ge.x, ge.y), r.bezierCurveTo(Te.cp1x, Te.cp1y, Te.cp2x, Te.cp2y, ke.x, ke.y), r.stroke();
|
|
783
792
|
}
|
|
784
793
|
r.setLineDash([]);
|
|
785
794
|
}
|
|
786
|
-
if (
|
|
787
|
-
var
|
|
788
|
-
r.fillStyle =
|
|
795
|
+
if (xr) {
|
|
796
|
+
var Lo = Math.min(xr.startWorld.x, xr.endWorld.x), So = Math.min(xr.startWorld.y, xr.endWorld.y), Ua = Math.abs(xr.endWorld.x - xr.startWorld.x), ca = Math.abs(xr.endWorld.y - xr.startWorld.y);
|
|
797
|
+
r.fillStyle = $ ? "rgba(59,130,246,0.08)" : "rgba(59,130,246,0.06)", r.fillRect(Lo, So, Ua, ca), r.strokeStyle = "#3b82f6", r.lineWidth = 1 / g.zoom, r.setLineDash([]), r.strokeRect(Lo, So, Ua, ca);
|
|
789
798
|
}
|
|
790
|
-
if (
|
|
791
|
-
var
|
|
792
|
-
if (
|
|
793
|
-
|
|
794
|
-
for (var
|
|
795
|
-
var
|
|
796
|
-
|
|
799
|
+
if (vr > 0) {
|
|
800
|
+
var oa = g.zoom > 0.12 && (g.zoom > 0.25 || vr < 500), vt = g.zoom > 0.08 && vr < 200, _l = g.zoom > 0.2 && vr < 300, El = Object.keys(Ce).length > 0 || Object.keys(te).length > 0 || Object.keys(We).length > 0, br = lr, me = [], Re = [];
|
|
801
|
+
if (El) {
|
|
802
|
+
br = [];
|
|
803
|
+
for (var nt = 0; nt < vr; nt++) {
|
|
804
|
+
var Jr = lr[nt];
|
|
805
|
+
te[Jr.id] || Jr.type && Ce[Jr.type] ? me.push(Jr) : Jr.type && We[Jr.type] ? Re.push(Jr) : br.push(Jr);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
var Xa = br.length;
|
|
809
|
+
if (vt) {
|
|
810
|
+
r.shadowColor = k.nodeShadow, r.shadowBlur = 6, r.shadowOffsetY = 2, r.fillStyle = k.nodeBg, r.beginPath();
|
|
811
|
+
for (var ht = 0; ht < Xa; ht++) {
|
|
812
|
+
var ze = br[ht];
|
|
813
|
+
r.roundRect(d(ze).x, d(ze).y, ze.width || L, ze.height || B, qa);
|
|
797
814
|
}
|
|
798
815
|
r.fill(), r.shadowColor = "transparent", r.shadowBlur = 0, r.shadowOffsetY = 0;
|
|
799
816
|
}
|
|
800
|
-
if (!
|
|
801
|
-
r.fillStyle =
|
|
802
|
-
for (var
|
|
803
|
-
var
|
|
804
|
-
r.roundRect(d(
|
|
817
|
+
if (!vt) {
|
|
818
|
+
r.fillStyle = k.nodeBg, r.beginPath();
|
|
819
|
+
for (var ut = 0; ut < Xa; ut++) {
|
|
820
|
+
var we = br[ut];
|
|
821
|
+
r.roundRect(d(we).x, d(we).y, we.width || L, we.height || B, qa);
|
|
805
822
|
}
|
|
806
823
|
r.fill();
|
|
807
824
|
}
|
|
808
|
-
r.strokeStyle =
|
|
809
|
-
for (var
|
|
810
|
-
var
|
|
811
|
-
|
|
825
|
+
r.strokeStyle = k.nodeBorder, r.lineWidth = 1, r.beginPath();
|
|
826
|
+
for (var st = 0; st < Xa; st++) {
|
|
827
|
+
var Ha = br[st];
|
|
828
|
+
Ha.selected || r.roundRect(d(Ha).x, d(Ha).y, Ha.width || L, Ha.height || B, qa);
|
|
812
829
|
}
|
|
813
830
|
r.stroke();
|
|
814
|
-
var
|
|
815
|
-
r.strokeStyle =
|
|
816
|
-
for (var
|
|
817
|
-
var
|
|
818
|
-
|
|
831
|
+
var Co = !1;
|
|
832
|
+
r.strokeStyle = k.nodeSelectedBorder, r.lineWidth = 2, r.beginPath();
|
|
833
|
+
for (var dt = 0; dt < Xa; dt++) {
|
|
834
|
+
var pa = br[dt];
|
|
835
|
+
pa.selected && (Co = !0, r.roundRect(d(pa).x, d(pa).y, pa.width || L, pa.height || B, qa));
|
|
819
836
|
}
|
|
820
|
-
if (
|
|
821
|
-
r.fillStyle =
|
|
822
|
-
for (var
|
|
823
|
-
var
|
|
824
|
-
if (!(!
|
|
825
|
-
var
|
|
826
|
-
r.fillText(
|
|
837
|
+
if (Co && r.stroke(), oa) {
|
|
838
|
+
r.fillStyle = k.nodeText, r.font = Uo, r.textAlign = "center", r.textBaseline = "middle";
|
|
839
|
+
for (var yt = 0; yt < Xa; yt++) {
|
|
840
|
+
var la = br[yt];
|
|
841
|
+
if (!(!la.data || !la.data.label)) {
|
|
842
|
+
var Wo = la.width || L, Ll = la.height || B;
|
|
843
|
+
r.fillText(la.data.label, d(la).x + Wo / 2, d(la).y + Ll / 2, Wo - 24);
|
|
827
844
|
}
|
|
828
845
|
}
|
|
829
846
|
r.textAlign = "start", r.textBaseline = "alphabetic";
|
|
830
847
|
}
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
848
|
+
for (var xt = 0; xt < me.length; xt++) {
|
|
849
|
+
var sr = me[xt], Ca = d(sr), Be = sr.width || L, Mt = sr.height || B, Po = te[sr.id] && Xo[te[sr.id]] || Ce[sr.type];
|
|
850
|
+
Po && r.drawImage(Po, Ca.x, Ca.y, Be, Mt), oa && sr.data && sr.data.label && (r.fillStyle = k.nodeText, r.font = Uo, r.textAlign = "center", r.textBaseline = "middle", r.fillText(sr.data.label, Ca.x + Be / 2, Ca.y + Mt / 2, Be - 24)), sr.selected && (r.strokeStyle = k.nodeSelectedBorder, r.lineWidth = 2, r.beginPath(), r.roundRect(Ca.x, Ca.y, Be, Mt, qa), r.stroke());
|
|
851
|
+
}
|
|
852
|
+
me.length > 0 && oa && (r.textAlign = "start", r.textBaseline = "alphabetic");
|
|
853
|
+
for (var gt = 0; gt < Re.length; gt++) {
|
|
854
|
+
var ia = Re[gt], P = We[ia.type], E = d(ia), Tr = ia.width || L, fa = ia.height || B, ir = P.radius || qa, Ae = ia.data || {};
|
|
855
|
+
if (vt && P.shadow !== !1 && (r.save(), r.shadowColor = P.shadowColor || k.nodeShadow, r.shadowBlur = P.shadowBlur || 6, r.shadowOffsetY = P.shadowOffsetY || 2, r.fillStyle = P.fill || k.nodeBg, r.beginPath(), r.roundRect(E.x, E.y, Tr, fa, ir), r.fill(), r.restore()), r.fillStyle = P.fill || k.nodeBg, r.beginPath(), r.roundRect(E.x, E.y, Tr, fa, ir), r.fill(), r.strokeStyle = ia.selected ? k.nodeSelectedBorder : P.stroke || k.nodeBorder, r.lineWidth = ia.selected ? 2 : P.strokeWidth || 1, r.beginPath(), r.roundRect(E.x, E.y, Tr, fa, ir), r.stroke(), P.accent) {
|
|
856
|
+
var re = P.accent;
|
|
857
|
+
r.fillStyle = re.color || "#3b82f6";
|
|
858
|
+
var Wa = re.width || 5;
|
|
859
|
+
r.beginPath(), re.side === "right" ? r.roundRect(E.x + Tr - Wa, E.y, Wa, fa, [0, ir, ir, 0]) : re.side === "top" ? r.roundRect(E.x, E.y, Tr, Wa, [ir, ir, 0, 0]) : re.side === "bottom" ? r.roundRect(E.x, E.y + fa - Wa, Tr, Wa, [0, 0, ir, ir]) : r.roundRect(E.x, E.y, Wa, fa, [ir, 0, 0, ir]), r.fill();
|
|
860
|
+
}
|
|
861
|
+
if (P.icon && oa) {
|
|
862
|
+
var mr = P.icon, qo = mr.dataField ? Ae[mr.dataField] : mr.text;
|
|
863
|
+
if (qo) {
|
|
864
|
+
r.font = (mr.size || 18) + "px system-ui, sans-serif", r.textAlign = "center", r.textBaseline = "middle", r.fillStyle = mr.color || k.nodeText;
|
|
865
|
+
var Sl = E.x + (mr.x !== void 0 ? mr.x : 20), Cl = E.y + (mr.y !== void 0 ? mr.y : fa / 2);
|
|
866
|
+
r.fillText(qo, Sl, Cl);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
if (P.title && oa) {
|
|
870
|
+
var dr = P.title, Go = dr.dataField ? Ae[dr.dataField] : dr.text;
|
|
871
|
+
if (Go) {
|
|
872
|
+
r.font = dr.font || "600 13px system-ui, sans-serif", r.textAlign = dr.align || "left", r.textBaseline = "top", r.fillStyle = dr.color || k.nodeText;
|
|
873
|
+
var Io = E.x + (dr.x !== void 0 ? dr.x : 12), Wl = E.y + (dr.y !== void 0 ? dr.y : 12);
|
|
874
|
+
r.fillText(Go, Io, Wl, Tr - Io + E.x - 12);
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
if (P.subtitle && oa) {
|
|
878
|
+
var yr = P.subtitle, Zo = yr.dataField ? Ae[yr.dataField] : yr.text;
|
|
879
|
+
if (Zo) {
|
|
880
|
+
r.font = yr.font || "11px system-ui, sans-serif", r.textAlign = yr.align || "left", r.textBaseline = "top", r.fillStyle = yr.color || "#64748b";
|
|
881
|
+
var Ko = E.x + (yr.x !== void 0 ? yr.x : 12), Pl = E.y + (yr.y !== void 0 ? yr.y : 32);
|
|
882
|
+
r.fillText(Zo, Ko, Pl, Tr - Ko + E.x - 12);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
if (P.badge && oa) {
|
|
886
|
+
var Rr = P.badge, kt = Rr.dataField ? Ae[Rr.dataField] : Rr.text;
|
|
887
|
+
if (kt) {
|
|
888
|
+
r.font = Rr.font || "700 9px system-ui, sans-serif";
|
|
889
|
+
var ql = r.measureText(kt), Gl = Rr.paddingX || 6, Il = Rr.paddingY || 3, Tt = ql.width + Gl * 2, mt = 14 + Il, bo = E.x + Tr - Tt / 2 - 4, Jo = E.y - mt / 2;
|
|
890
|
+
r.fillStyle = Rr.bg || "#3b82f6", r.beginPath(), r.roundRect(bo, Jo, Tt, mt, Rr.radius || 7), r.fill(), r.fillStyle = Rr.color || "#fff", r.textAlign = "center", r.textBaseline = "middle", r.fillText(kt, bo + Tt / 2, Jo + mt / 2);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
if (Re.length > 0 && (r.textAlign = "start", r.textBaseline = "alphabetic"), _l) {
|
|
895
|
+
for (var Rt = [], zt = 0; zt < vr; zt++)
|
|
896
|
+
for (var Qo = Ho(lr[zt]), wt = 0; wt < Qo.length; wt++)
|
|
897
|
+
Rt.push(Qo[wt]);
|
|
898
|
+
r.fillStyle = k.handleFill, r.beginPath();
|
|
899
|
+
for (var Bt = 0; Bt < Rt.length; Bt++) {
|
|
900
|
+
var _e = Rt[Bt];
|
|
901
|
+
r.moveTo(_e.x + Fo, _e.y), r.arc(_e.x, _e.y, Fo, 0, 6.2832);
|
|
902
|
+
}
|
|
903
|
+
r.fill(), r.strokeStyle = k.handleBorder, r.lineWidth = 1.5, r.stroke();
|
|
841
904
|
}
|
|
842
905
|
}
|
|
843
906
|
r.restore();
|
|
844
|
-
var
|
|
845
|
-
|
|
846
|
-
var
|
|
847
|
-
if (
|
|
848
|
-
|
|
849
|
-
var
|
|
907
|
+
var Zl = (performance.now() - a).toFixed(1);
|
|
908
|
+
Lt++;
|
|
909
|
+
var Ee = performance.now();
|
|
910
|
+
if (Ee - No >= 1e3 && (Do = Lt, Lt = 0, No = Ee), Ee - Oo >= 100) {
|
|
911
|
+
Oo = Ee;
|
|
912
|
+
var Kl = Math.round(-g.x / g.zoom), bl = Math.round(-g.y / g.zoom);
|
|
850
913
|
self.postMessage({
|
|
851
914
|
type: "hud",
|
|
852
915
|
data: {
|
|
853
|
-
wx:
|
|
854
|
-
wy:
|
|
855
|
-
zoom:
|
|
856
|
-
renderMs:
|
|
857
|
-
fps:
|
|
858
|
-
visible:
|
|
859
|
-
nodeCount:
|
|
860
|
-
visibleNodes:
|
|
861
|
-
edgeCount:
|
|
916
|
+
wx: Kl,
|
|
917
|
+
wy: bl,
|
|
918
|
+
zoom: g.zoom.toFixed(2),
|
|
919
|
+
renderMs: Zl,
|
|
920
|
+
fps: Do,
|
|
921
|
+
visible: Y.length > 0 ? co(Dr, Or, da, jr).length : 0,
|
|
922
|
+
nodeCount: G.length,
|
|
923
|
+
visibleNodes: vr,
|
|
924
|
+
edgeCount: q.length
|
|
862
925
|
}
|
|
863
926
|
});
|
|
864
927
|
}
|
|
865
928
|
}
|
|
866
929
|
}
|
|
867
|
-
`,ir=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",vr],{type:"text/javascript;charset=utf-8"});function eo(e){let t;try{if(t=ir&&(self.URL||self.webkitURL).createObjectURL(ir),!t)throw"";const n=new Worker(t,{type:"module",name:e==null?void 0:e.name});return n.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),n}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(vr),{type:"module",name:e==null?void 0:e.name})}}const Wn=new WeakMap;function to(e,t){if(Wn.has(e))return Wn.get(e);const n=e.transferControlToOffscreen(),r=new eo;r.onerror=o=>console.error("[infinite-canvas] worker error:",o.message,o),r.postMessage({type:"init",data:{...t,canvas:n}},[n]);const a={worker:r};return Wn.set(e,a),a}const it=160,rt=60,no=10;function br({cards:e=[],nodes:t=[],edges:n=[],onHudUpdate:r,onNodesProcessed:a,onNodesChange:o,onEdgesChange:i,onConnect:f,onNodeClick:p,onNodeDragStart:d,onNodeDrag:h,onNodeDragStop:v,onEdgeClick:E,onEdgeDoubleClick:M,onEdgeMouseEnter:z,onEdgeMouseMove:I,onEdgeMouseLeave:k,onEdgeContextMenu:j,onNodeDoubleClick:X,onNodeMouseEnter:D,onNodeMouseMove:_,onNodeMouseLeave:A,onNodeContextMenu:L,onPaneClick:Y,onPaneContextMenu:F,onPaneMouseEnter:B,onPaneMouseMove:b,onPaneMouseLeave:g,onSelectionChange:x,onConnectStart:N,onConnectEnd:$,onInit:W,onMoveStart:V,onMove:re,onMoveEnd:ee,onDelete:oe,onBeforeDelete:ge,onError:ye,isValidConnection:J,dark:fe,gridSize:me=40,zoomMin:ae=.1,zoomMax:ue=4,initialCamera:Ne={x:0,y:0,zoom:1},fitView:Je=!1,fitViewOptions:le,nodesDraggable:Be=!0,nodesConnectable:je=!0,elementsSelectable:_e=!0,multiSelectionKeyCode:he="Shift",selectionOnDrag:Me=!1,selectionMode:Oe="partial",connectionMode:Ae="loose",connectionRadius:ct=20,connectOnClick:zt=!1,snapToGrid:De=!1,snapGrid:Xe=[15,15],deleteKeyCode:Ze=["Delete","Backspace"],panActivationKeyCode:St=" ",panOnScroll:an=!1,panOnScrollMode:At="free",panOnScrollSpeed:cn=.5,zoomOnScroll:un=!0,zoomOnDoubleClick:ln=!0,zoomOnPinch:dn=!0,preventScrolling:Dt=!0,translateExtent:dt,nodeExtent:ft,defaultEdgeOptions:Nt={},autoPanOnNodeDrag:En=!0,autoPanOnConnect:zn=!0,autoPanSpeed:ot=5,edgesReconnectable:sr=!1,elevateNodesOnSelect:Sn=!1,elevateEdgesOnSelect:Nn=!1,noDragClassName:Pt="nodrag",noPanClassName:It="nopan",onSelectionDragStart:Pn,onSelectionDrag:In,onSelectionDragStop:Ln,edgeRouting:ht=!0}={}){const pe=c.useRef(null),Ht=c.useRef(null),Ee=c.useRef(null),ie=c.useRef({...Ne}),gt=c.useRef([...e]),K=c.useRef([...t]),Re=c.useRef([...n]),fn=c.useRef(new Map),ut=c.useRef(!1),Lt=c.useRef(null),[Tn,$n]=c.useState(!1),We=c.useRef(null),Ye=c.useRef(null),_t=c.useRef(null),He=c.useRef(null),Wt=c.useRef(!1),Mt=c.useRef(null),[Ft,Bn]=c.useState({x:Ne.x,y:Ne.y,zoom:Ne.zoom}),[yt,xt]=c.useState(null),tt=c.useMemo(()=>new Set,[]),Ke=c.useMemo(()=>new Set,[]),Tt=c.useRef(!1),O=c.useRef({});O.current={onHudUpdate:r,onNodesProcessed:a,onNodesChange:o,onEdgesChange:i,onConnect:f,onNodeClick:p,onNodeDragStart:d,onNodeDrag:h,onNodeDragStop:v,onEdgeClick:E,onEdgeDoubleClick:M,onEdgeMouseEnter:z,onEdgeMouseMove:I,onEdgeMouseLeave:k,onEdgeContextMenu:j,onNodeDoubleClick:X,onNodeMouseEnter:D,onNodeMouseMove:_,onNodeMouseLeave:A,onNodeContextMenu:L,onPaneClick:Y,onPaneContextMenu:F,onPaneMouseEnter:B,onPaneMouseMove:b,onPaneMouseLeave:g,onSelectionChange:x,onConnectStart:N,onConnectEnd:$,onInit:W,onMoveStart:V,onMove:re,onMoveEnd:ee,onDelete:oe,onBeforeDelete:ge,onError:ye,onSelectionDragStart:Pn,onSelectionDrag:In,onSelectionDragStop:Ln,isValidConnection:J};const pt={get current(){return O.current.onConnect}},$t={get current(){return O.current.onNodeClick}},Xt={get current(){return O.current.onNodeDragStart}},Yt={get current(){return O.current.onNodeDrag}},qt={get current(){return O.current.onNodeDragStop}},Ut={get current(){return O.current.onEdgeClick}},Ot={get current(){return O.current.onPaneClick}},we={get current(){return O.current.onSelectionChange}},mt={get current(){return O.current.onHudUpdate}},Bt={get current(){return O.current.onNodesProcessed}};c.useEffect(()=>{const l=u=>{u.key===he&&(Wt.current=!0),u.key===St&&(Tt.current=!0)},w=u=>{u.key===he&&(Wt.current=!1),u.key===St&&(Tt.current=!1)};return window.addEventListener("keydown",l),window.addEventListener("keyup",w),()=>{window.removeEventListener("keydown",l),window.removeEventListener("keyup",w)}},[he,St]);const ze={get current(){return O.current.onNodesChange?Zt:null}},Zt=l=>{var u,y,R;(y=(u=O.current).onNodesChange)==null||y.call(u,l);const w=[];for(let S=0;S<l.length;S++)l[S].type==="select"&&w.push({id:l[S].id,selected:l[S].selected});w.length>0&&((R=Ee.current)==null||R.postMessage({type:"nodeSelections",data:{selections:w}}))},Pe={get current(){return O.current.onEdgesChange?Gt:null}},Gt=l=>{var u,y,R;(y=(u=O.current).onEdgesChange)==null||y.call(u,l);const w=[];for(let S=0;S<l.length;S++)l[S].type==="select"&&w.push({id:l[S].id,selected:l[S].selected});w.length>0&&((R=Ee.current)==null||R.postMessage({type:"edgeSelections",data:{selections:w}}))},st=c.useCallback(()=>{var y;const l=K.current.filter(R=>R.selected),w=Re.current.filter(R=>R.selected),u={nodes:l,edges:w};(y=we.current)==null||y.call(we,u);for(const R of Ke)R(u)},[Ke]);c.useEffect(()=>{var l;gt.current=[...e],(l=Ee.current)==null||l.postMessage({type:"cards",data:{cards:[...e]}})},[e]);const Rt=c.useCallback(l=>{const w={};for(const u of l)w[u.id]=u;return l.map(u=>{if(!u.parentId)return u;const y=w[u.parentId];if(!y)return u;let R=u.position.x,S=u.position.y,m=y;for(;m;)R+=m.position.x,S+=m.position.y,m=m.parentId?w[m.parentId]:null;return{...u,_absolutePosition:{x:R,y:S}}})},[]),et=c.useRef([]),vt=c.useCallback(l=>{const w=fn.current;if(!w||w.size===0)return l;const u={};for(const[,y]of w)u[y.nodeId]||(u[y.nodeId]=[]),u[y.nodeId].push({id:y.id,type:y.type,position:y.position,x:y.x,y:y.y});return l.map(y=>{const R=u[y.id];return R&&R.length>0?{...y,handles:R}:y})},[]),hn=c.useCallback(()=>{var w;if(We.current)return;const l=vt(et.current);(w=Ee.current)==null||w.postMessage({type:"nodes",data:{nodes:l}})},[vt]);c.useEffect(()=>{var u,y;if(We.current){const R=We.current.id,S=new Set([R,...We.current.selectedStarts.map(C=>C.id)]),m={};for(const C of K.current)S.has(C.id)&&(m[C.id]={...C.position});K.current=[...t];for(const C of K.current)m[C.id]&&(C.position=m[C.id]);et.current=Rt(K.current);const T=vt(et.current);(u=Ee.current)==null||u.postMessage({type:"nodes",data:{nodes:T}});return}K.current=[...t];const l=Rt(t);et.current=l;const w=vt(l);(y=Ee.current)==null||y.postMessage({type:"nodes",data:{nodes:w}})},[t,Rt,vt]),c.useEffect(()=>{var l;Re.current=[...n],(l=Ee.current)==null||l.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const Se=c.useCallback((l,w)=>{const u=pe.current;if(!u)return{x:0,y:0};const y=u.getBoundingClientRect(),R=ie.current;return{x:(l-y.left-R.x)/R.zoom,y:(w-y.top-R.y)/R.zoom}},[]),nt=c.useCallback((l,w)=>{const u=et.current.length>0?et.current:K.current;let y=null;for(let R=u.length-1;R>=0;R--){const S=u[R];if(S.hidden)continue;const m=S._absolutePosition||S.position,T=S.width||it,C=S.height||rt;if(l>=m.x&&l<=m.x+T&&w>=m.y&&w<=m.y+C){if(S.type==="group"){y||(y=S);continue}return S}}return y},[]),G=c.useCallback((l,w)=>{const u=w.width||it,y=w.height||rt;if(l.x!==void 0&&l.y!==void 0)return{x:w.position.x+l.x,y:w.position.y+l.y};switch(l.position||(l.type==="source"?"right":"left")){case"top":return{x:w.position.x+u/2,y:w.position.y};case"bottom":return{x:w.position.x+u/2,y:w.position.y+y};case"left":return{x:w.position.x,y:w.position.y+y/2};case"right":return{x:w.position.x+u,y:w.position.y+y/2};default:return{x:w.position.x+u,y:w.position.y+y/2}}},[]),Ie=c.useCallback(l=>{const w=l.width||it,u=l.height||rt;if(l.handles&&l.handles.length>0)return l.handles.map(C=>{const U=G(C,l);return{id:C.id||null,type:C.type,x:U.x,y:U.y}});const y=l.targetPosition||"left",R=l.sourcePosition||"right",S=C=>{switch(C){case"top":return{x:l.position.x+w/2,y:l.position.y};case"bottom":return{x:l.position.x+w/2,y:l.position.y+u};case"left":return{x:l.position.x,y:l.position.y+u/2};case"right":return{x:l.position.x+w,y:l.position.y+u/2};default:return{x:l.position.x+w,y:l.position.y+u/2}}},m=S(y),T=S(R);return[{id:null,type:"target",x:m.x,y:m.y},{id:null,type:"source",x:T.x,y:T.y}]},[G]),ve=c.useCallback((l,w)=>{const u=K.current,y=ie.current,R=Math.max(no,ct)/y.zoom;for(let S=u.length-1;S>=0;S--){const m=u[S];if(m.hidden)continue;const T=Ie(m);for(const C of T)if(Math.abs(l-C.x)<R&&Math.abs(w-C.y)<R)return{nodeId:m.id,handleId:C.id,type:C.type,x:C.x,y:C.y}}return null},[Ie]),Le=c.useCallback((l,w)=>{const y=8/ie.current.zoom;for(let R=Re.current.length-1;R>=0;R--){const S=Re.current[R],m=K.current.find(se=>se.id===S.source),T=K.current.find(se=>se.id===S.target);if(!m||!T)continue;const C=m.width||it,U=m.height||rt,H=T.height||rt,Z=m.position.x+C,Q=m.position.y+U/2,be=T.position.x,Te=T.position.y+H/2;if(ro(l,w,Z,Q,be,Te)<y)return S}return null},[]);c.useEffect(()=>{const l=Ht.current,w=pe.current;if(!l||!w)return;const u=w.getBoundingClientRect(),y=fe!==void 0?fe:matchMedia("(prefers-color-scheme: dark)").matches,R=Rt(K.current);et.current=R;const S=vt(R),{worker:m}=to(l,{width:u.width,height:u.height,camera:ie.current,cards:gt.current,nodes:S,edges:Re.current,dark:y,gridSize:me,edgeRouting:ht});m.onmessage=H=>{var Z,Q,be,Te;H.data.type==="hud"&&((Z=mt.current)==null||Z.call(mt,H.data.data)),H.data.type==="ready"&&$n(!0),H.data.type==="nodesProcessed"&&((Q=Bt.current)==null||Q.call(Bt,H.data.data)),H.data.type==="error"&&((Te=(be=O.current).onError)==null||Te.call(be,"worker-error",H.data.message||"Canvas worker error"))},m.onerror=H=>{var Z,Q;(Q=(Z=O.current).onError)==null||Q.call(Z,"worker-error",H.message||"Canvas worker crashed")},Ee.current=m;const T=new ResizeObserver(H=>{const{width:Z,height:Q}=H[0].contentRect;m.postMessage({type:"resize",data:{width:Z,height:Q}})});T.observe(w);let C,U;return fe===void 0&&(C=matchMedia("(prefers-color-scheme: dark)"),U=H=>m.postMessage({type:"theme",data:{dark:H.matches}}),C.addEventListener("change",U)),()=>{T.disconnect(),C&&U&&C.removeEventListener("change",U),Ee.current=null}},[]),c.useEffect(()=>{var l;fe!==void 0&&((l=Ee.current)==null||l.postMessage({type:"theme",data:{dark:fe}}))},[fe]),c.useEffect(()=>{var l;(l=Ee.current)==null||l.postMessage({type:"edgeRouting",data:{enabled:ht}})},[ht]);const at=c.useRef(0),ce=c.useCallback((l=null)=>{var y,R,S;const w=ie.current;if(dt){const m=pe.current;if(m){const T=m.getBoundingClientRect(),C=-dt[1][0]*w.zoom+T.width,U=-dt[1][1]*w.zoom+T.height,H=-dt[0][0]*w.zoom,Z=-dt[0][1]*w.zoom;w.x=Math.min(H,Math.max(C,w.x)),w.y=Math.min(Z,Math.max(U,w.y))}}(y=Ee.current)==null||y.postMessage({type:"camera",data:{camera:{...w}}});const u={x:w.x,y:w.y,zoom:w.zoom};(S=(R=O.current).onMove)==null||S.call(R,l,u);for(const m of tt)m(u);cancelAnimationFrame(at.current),at.current=requestAnimationFrame(()=>{Bn({x:w.x,y:w.y,zoom:w.zoom})})},[tt,dt]),Ge=c.useCallback(()=>{var u,y;const l=Ye.current,w=_t.current;l&&w?((u=Ee.current)==null||u.postMessage({type:"connecting",data:{from:l.startPos,to:w,_routedPoints:null}}),xt({source:l.sourceId,sourceHandle:l.sourceHandle,target:null,targetHandle:null})):((y=Ee.current)==null||y.postMessage({type:"connecting",data:null}),xt(null))},[]),bt=c.useCallback(()=>{var w,u;const l=He.current;l?(w=Ee.current)==null||w.postMessage({type:"selectionBox",data:l}):(u=Ee.current)==null||u.postMessage({type:"selectionBox",data:null})},[]),jn=c.useCallback(l=>{var m,T,C,U,H,Z,Q,be,Te,te,se,ke,$e,Fe,Qe,Ue,Vt,lt;const w=K.current.length>0,u=Se(l.clientX,l.clientY),y=Wt.current;if(w&&je&&!y){const q=ve(u.x,u.y);if(zt&&Mt.current&&q){const ne=Mt.current;if(q.nodeId!==ne.nodeId){const Ve=ne.handleType==="target"?{source:q.nodeId,target:ne.nodeId,sourceHandle:q.handleId||null,targetHandle:ne.handleId}:{source:ne.nodeId,target:q.nodeId,sourceHandle:ne.handleId,targetHandle:q.handleId||null};(O.current.isValidConnection?O.current.isValidConnection(Ve):!0)&&((m=pt.current)==null||m.call(pt,{...Ve,...Nt}))}Mt.current=null;return}if(Ae==="strict"?q&&q.type==="source":q!=null){if(zt){Mt.current={nodeId:q.nodeId,handleId:q.handleId||null,handleType:q.type},(C=(T=O.current).onConnectStart)==null||C.call(T,l,{nodeId:q.nodeId,handleId:q.handleId,handleType:q.type});return}Ye.current={sourceId:q.nodeId,sourceHandle:q.handleId||null,sourceType:q.type,startPos:{x:q.x,y:q.y}},_t.current={x:u.x,y:u.y},(U=pe.current)==null||U.setPointerCapture(l.pointerId),(Z=(H=O.current).onConnectStart)==null||Z.call(H,l,{nodeId:q.nodeId,handleId:q.handleId,handleType:q.type}),Ge();return}}const R=q=>{var ne;let xe=q;for(;xe&&xe!==pe.current;){if((ne=xe.classList)!=null&&ne.contains(Pt))return!0;xe=xe.parentElement}return!1},S=q=>{var ne;let xe=q;for(;xe&&xe!==pe.current;){if((ne=xe.classList)!=null&&ne.contains(It))return!0;xe=xe.parentElement}return!1};if(w){const q=nt(u.x,u.y);if(q){if(ze.current&&_e){const xe=[];if(y)xe.push({id:q.id,type:"select",selected:!q.selected});else if(!q.selected){for(const ne of K.current)ne.id===q.id?xe.push({id:ne.id,type:"select",selected:!0}):ne.selected&&xe.push({id:ne.id,type:"select",selected:!1});if(Pe.current){const ne=Re.current.filter(de=>de.selected).map(de=>({id:de.id,type:"select",selected:!1}));ne.length&&Pe.current(ne)}}if(xe.length){if(ze.current(xe),Sn&&!y){const ne=K.current.findIndex(de=>de.id===q.id);ne>=0&&ne<K.current.length-1&&ze.current([{id:q.id,type:"remove"},{type:"add",item:{...K.current[ne],selected:!0}}])}st()}}if((Q=$t.current)==null||Q.call($t,l,q),Be&&!R(l.target)){const xe=q.selected;let ne=null;if(q.parentId&&q.extent==="parent"){const de=K.current.find(Ve=>Ve.id===q.parentId);if(de){const Ve=de.width||it,Jt=de.height||rt,yn=q.width||((be=q.measured)==null?void 0:be.width)||it,Kt=q.height||((Te=q.measured)==null?void 0:Te.height)||rt;ne={minX:0,minY:0,maxX:Ve-yn,maxY:Jt-Kt}}}if(We.current={id:q.id,startPos:{...q.position},startMouse:{x:u.x,y:u.y},parentClamp:ne,parentId:q.parentId||null,selectedStarts:xe?K.current.filter(de=>de.selected&&de.id!==q.id).map(de=>{var Jt,yn;let Ve=null;if(de.parentId&&de.extent==="parent"){const Kt=K.current.find(_n=>_n.id===de.parentId);if(Kt){const _n=Kt.width||it,Wr=Kt.height||rt,Fr=de.width||((Jt=de.measured)==null?void 0:Jt.width)||it,Xr=de.height||((yn=de.measured)==null?void 0:yn.height)||rt;Ve={minX:0,minY:0,maxX:_n-Fr,maxY:Wr-Xr}}}return{id:de.id,startPos:{...de.position},parentClamp:Ve,parentId:de.parentId||null}}):[]},(te=pe.current)==null||te.setPointerCapture(l.pointerId),(se=Xt.current)==null||se.call(Xt,l,q),We.current.selectedStarts.length>0){const de=K.current.filter(Ve=>Ve.selected);($e=(ke=O.current).onSelectionDragStart)==null||$e.call(ke,l,de)}if(ze.current){const de=[{id:q.id,type:"position",dragging:!0}];for(const Ve of We.current.selectedStarts)de.push({id:Ve.id,type:"position",dragging:!0});ze.current(de)}}return}}if(Re.current.length>0&&_e){const q=Le(u.x,u.y);if(q){if(Pe.current){const xe=[];if(y)xe.push({id:q.id,type:"select",selected:!q.selected});else{for(const ne of Re.current)ne.id===q.id?xe.push({id:ne.id,type:"select",selected:!0}):ne.selected&&xe.push({id:ne.id,type:"select",selected:!1});if(ze.current){const ne=K.current.filter(de=>de.selected).map(de=>({id:de.id,type:"select",selected:!1}));ne.length&&ze.current(ne)}}if(xe.length){if(Pe.current(xe),Nn&&!y){const ne=Re.current.findIndex(de=>de.id===q.id);ne>=0&&ne<Re.current.length-1&&Pe.current([{id:q.id,type:"remove"},{type:"add",item:{...Re.current[ne],selected:!0}}])}st()}}(Fe=Ut.current)==null||Fe.call(Ut,l,q);return}}if(!y){const q=K.current.filter(ne=>ne.selected).map(ne=>({id:ne.id,type:"select",selected:!1})),xe=Re.current.filter(ne=>ne.selected).map(ne=>({id:ne.id,type:"select",selected:!1}));q.length&&ze.current&&ze.current(q),xe.length&&Pe.current&&Pe.current(xe),(q.length||xe.length)&&st()}if((Qe=Ot.current)==null||Qe.call(Ot,l),Me||y){He.current={startWorld:{...u},endWorld:{...u}},(Ue=pe.current)==null||Ue.setPointerCapture(l.pointerId),bt();return}S(l.target)||(ut.current=!0,Lt.current={x:l.clientX,y:l.clientY},(Vt=pe.current)==null||Vt.classList.add("dragging"),(lt=pe.current)==null||lt.setPointerCapture(l.pointerId))},[Se,nt,ve,Le,Be,je,_e,Me,Ge,bt,st,Pt,It]),An=c.useCallback(l=>{var u,y,R,S;if(Ye.current){if(_t.current=Se(l.clientX,l.clientY),Ge(),zn){const m=pe.current;if(m){const T=m.getBoundingClientRect(),C=40,U=l.clientX-T.left,H=l.clientY-T.top;let Z=0,Q=0;U<C?Z=ot:U>T.width-C&&(Z=-ot),H<C?Q=ot:H>T.height-C&&(Q=-ot),(Z||Q)&&(ie.current.x+=Z,ie.current.y+=Q,ce(l))}}return}if(He.current){He.current.endWorld=Se(l.clientX,l.clientY),bt();const m=He.current,T=Math.min(m.startWorld.x,m.endWorld.x),C=Math.min(m.startWorld.y,m.endWorld.y),U=Math.max(m.startWorld.x,m.endWorld.x),H=Math.max(m.startWorld.y,m.endWorld.y);if(ze.current){const Z=[];for(const Q of K.current){if(Q.hidden)continue;const be=Q.width||it,Te=Q.height||rt,te=Oe==="full"?Q.position.x>=T&&Q.position.x+be<=U&&Q.position.y>=C&&Q.position.y+Te<=H:Q.position.x+be>T&&Q.position.x<U&&Q.position.y+Te>C&&Q.position.y<H;te!==!!Q.selected&&Z.push({id:Q.id,type:"select",selected:te})}Z.length&&ze.current(Z)}return}if(We.current){const m=Se(l.clientX,l.clientY),T=We.current,C=m.x-T.startMouse.x,U=m.y-T.startMouse.y;let H={x:T.startPos.x+C,y:T.startPos.y+U};if(De&&(H=qn(H,Xe)),ft&&(H=Un(H,ft)),T.parentClamp){const te=T.parentClamp;H={x:Math.max(te.minX,Math.min(H.x,te.maxX)),y:Math.max(te.minY,Math.min(H.y,te.maxY))}}const Z=[{id:T.id,position:H}];for(const te of T.selectedStarts){let se={x:te.startPos.x+C,y:te.startPos.y+U};if(De&&(se=qn(se,Xe)),ft&&(se=Un(se,ft)),te.parentClamp){const ke=te.parentClamp;se={x:Math.max(ke.minX,Math.min(se.x,ke.maxX)),y:Math.max(ke.minY,Math.min(se.y,ke.maxY))}}Z.push({id:te.id,position:se})}const Q=[];for(const te of Z){const se=K.current.find(ke=>ke.id===te.id);if(se){se.position=te.position,se.dragging=!0;let ke=te.position;if(se.parentId){let $e=K.current.find(Ue=>Ue.id===se.parentId),Fe=te.position.x,Qe=te.position.y;for(;$e;)Fe+=$e.position.x,Qe+=$e.position.y,$e=$e.parentId?K.current.find(Ue=>Ue.id===$e.parentId):null;ke={x:Fe,y:Qe}}Q.push({id:te.id,position:te.position,_absolutePosition:ke,width:se.width,height:se.height,dragging:!0,selected:se.selected})}}const be=new Set(Z.map(te=>te.id));for(const te of K.current)if(te.parentId&&be.has(te.parentId)&&!be.has(te.id)){let se=K.current.find(Fe=>Fe.id===te.parentId),ke=te.position.x,$e=te.position.y;for(;se;)ke+=se.position.x,$e+=se.position.y,se=se.parentId?K.current.find(Fe=>Fe.id===se.parentId):null;Q.push({id:te.id,position:te.position,_absolutePosition:{x:ke,y:$e},width:te.width,height:te.height,dragging:!1,selected:te.selected})}if((u=Ee.current)==null||u.postMessage({type:"nodePositions",data:{updates:Q}}),En){const te=pe.current;if(te){const se=te.getBoundingClientRect(),ke=40,$e=l.clientX-se.left,Fe=l.clientY-se.top;let Qe=0,Ue=0;$e<ke?Qe=ot:$e>se.width-ke&&(Qe=-ot),Fe<ke?Ue=ot:Fe>se.height-ke&&(Ue=-ot),(Qe||Ue)&&(ie.current.x+=Qe,ie.current.y+=Ue,ce(l))}}const Te=K.current.find(te=>te.id===T.id);if(Te&&((y=Yt.current)==null||y.call(Yt,l,Te)),T.selectedStarts.length>0){const te=K.current.filter(se=>se.selected);(S=(R=O.current).onSelectionDrag)==null||S.call(R,l,te)}return}if(!ut.current)return;const w=ie.current;w.x+=l.clientX-Lt.current.x,w.y+=l.clientY-Lt.current.y,Lt.current={x:l.clientX,y:l.clientY},ce()},[ce,Se,Ge,bt]),kt=c.useCallback(l=>{var w,u,y,R,S,m,T;if(Ye.current){const C=Se(l.clientX,l.clientY),U=ve(C.x,C.y);if(U&&U.nodeId!==Ye.current.sourceId&&(Ae==="loose"||U.type==="target")){const Q=Ye.current.sourceType==="target"?{source:U.nodeId,target:Ye.current.sourceId,sourceHandle:U.handleId||null,targetHandle:Ye.current.sourceHandle}:{source:Ye.current.sourceId,target:U.nodeId,sourceHandle:Ye.current.sourceHandle,targetHandle:U.handleId||null};(O.current.isValidConnection?O.current.isValidConnection(Q):!0)&&((w=pt.current)==null||w.call(pt,{...Q,...Nt}))}(y=(u=O.current).onConnectEnd)==null||y.call(u,l.nativeEvent||l),Ye.current=null,_t.current=null,Ge();return}if(He.current){He.current=null,bt(),st();return}if(We.current){const C=We.current;if(ze.current){const H=K.current.find(Q=>Q.id===C.id),Z=[{id:C.id,type:"position",position:H?{...H.position}:void 0,dragging:!1}];for(const Q of C.selectedStarts){const be=K.current.find(Te=>Te.id===Q.id);Z.push({id:Q.id,type:"position",position:be?{...be.position}:void 0,dragging:!1})}ze.current(Z)}if(C.selectedStarts.length>0){const H=K.current.filter(Z=>Z.selected);(S=(R=O.current).onSelectionDragStop)==null||S.call(R,l,H)}requestAnimationFrame(()=>{We.current=null});const U=K.current.find(H=>H.id===C.id);U&&((m=qt.current)==null||m.call(qt,l,U));return}ut.current=!1,(T=pe.current)==null||T.classList.remove("dragging")},[Se,ve,Ge,bt,st]);c.useEffect(()=>{const l=pe.current;if(!l)return;const w=u=>{Dt&&u.preventDefault();const y=ie.current;if(an||Tt.current){const C=cn;At==="horizontal"?y.x-=u.deltaY*C:(At==="vertical"||(y.x-=u.deltaX*C),y.y-=u.deltaY*C),ce(u);return}if(!un)return;const R=u.deltaY>0?.92:1.08,S=l.getBoundingClientRect(),m=u.clientX-S.left,T=u.clientY-S.top;y.x=m-(m-y.x)*R,y.y=T-(T-y.y)*R,y.zoom=Math.min(ue,Math.max(ae,y.zoom*R)),ce(u)};return l.addEventListener("wheel",w,{passive:!Dt}),()=>l.removeEventListener("wheel",w)},[ce,ae,ue,an,At,cn,un,Dt]),c.useEffect(()=>{if(!dn)return;const l=pe.current;if(!l)return;let w=0,u=null;const y=m=>{if(m.touches.length===2){const T=m.touches[0].clientX-m.touches[1].clientX,C=m.touches[0].clientY-m.touches[1].clientY;w=Math.hypot(T,C);const U=l.getBoundingClientRect();u={x:(m.touches[0].clientX+m.touches[1].clientX)/2-U.left,y:(m.touches[0].clientY+m.touches[1].clientY)/2-U.top},m.preventDefault()}},R=m=>{if(m.touches.length===2&&w>0){m.preventDefault();const T=m.touches[0].clientX-m.touches[1].clientX,C=m.touches[0].clientY-m.touches[1].clientY,U=Math.hypot(T,C),H=U/w;w=U;const Z=ie.current,Q=u.x,be=u.y;Z.x=Q-(Q-Z.x)*H,Z.y=be-(be-Z.y)*H,Z.zoom=Math.min(ue,Math.max(ae,Z.zoom*H)),ce(m)}},S=()=>{w=0,u=null};return l.addEventListener("touchstart",y,{passive:!1}),l.addEventListener("touchmove",R,{passive:!1}),l.addEventListener("touchend",S),()=>{l.removeEventListener("touchstart",y),l.removeEventListener("touchmove",R),l.removeEventListener("touchend",S)}},[dn,ce,ae,ue]),c.useEffect(()=>{if(!ln)return;const l=pe.current;if(!l)return;const w=u=>{var H,Z,Q,be;const y=Se(u.clientX,u.clientY);if(nt(y.x,y.y)){(Z=(H=O.current).onNodeDoubleClick)==null||Z.call(H,u,nt(y.x,y.y));return}const R=Le(y.x,y.y);if(R){(be=(Q=O.current).onEdgeDoubleClick)==null||be.call(Q,u,R);return}const S=1.5,m=l.getBoundingClientRect(),T=u.clientX-m.left,C=u.clientY-m.top,U=ie.current;U.x=T-(T-U.x)*S,U.y=C-(C-U.y)*S,U.zoom=Math.min(ue,Math.max(ae,U.zoom*S)),ce(u)};return l.addEventListener("dblclick",w),()=>l.removeEventListener("dblclick",w)},[ln,ce,ae,ue,Se,nt,Le]),c.useEffect(()=>{const l=pe.current;if(!l)return;const w=u=>{var m,T,C,U,H,Z;const y=Se(u.clientX,u.clientY),R=nt(y.x,y.y);if(R){(T=(m=O.current).onNodeContextMenu)==null||T.call(m,u,R);return}const S=Le(y.x,y.y);if(S){(U=(C=O.current).onEdgeContextMenu)==null||U.call(C,u,S);return}(Z=(H=O.current).onPaneContextMenu)==null||Z.call(H,u)};return l.addEventListener("contextmenu",w),()=>l.removeEventListener("contextmenu",w)},[Se,nt,Le]),c.useEffect(()=>{const l=pe.current;if(!l)return;let w=null,u=null;const y=m=>{var U,H,Z,Q,be,Te,te,se,ke,$e,Fe,Qe,Ue,Vt;if((H=(U=O.current).onPaneMouseMove)==null||H.call(U,m),ut.current||We.current||Ye.current||He.current)return;const T=Se(m.clientX,m.clientY),C=nt(T.x,T.y);if(C!==w&&(w&&((Q=(Z=O.current).onNodeMouseLeave)==null||Q.call(Z,m,w)),C&&((Te=(be=O.current).onNodeMouseEnter)==null||Te.call(be,m,C)),w=C),C&&((se=(te=O.current).onNodeMouseMove)==null||se.call(te,m,C)),!C){const lt=Le(T.x,T.y);lt!==u&&(u&&(($e=(ke=O.current).onEdgeMouseLeave)==null||$e.call(ke,m,u)),lt&&((Qe=(Fe=O.current).onEdgeMouseEnter)==null||Qe.call(Fe,m,lt)),u=lt),lt&&((Vt=(Ue=O.current).onEdgeMouseMove)==null||Vt.call(Ue,m,lt))}},R=m=>{var T,C;return(C=(T=O.current).onPaneMouseEnter)==null?void 0:C.call(T,m)},S=m=>{var T,C,U,H,Z,Q;(C=(T=O.current).onPaneMouseLeave)==null||C.call(T,m),w&&((H=(U=O.current).onNodeMouseLeave)==null||H.call(U,m,w),w=null),u&&((Q=(Z=O.current).onEdgeMouseLeave)==null||Q.call(Z,m,u),u=null)};return l.addEventListener("mousemove",y),l.addEventListener("mouseenter",R),l.addEventListener("mouseleave",S),()=>{l.removeEventListener("mousemove",y),l.removeEventListener("mouseenter",R),l.removeEventListener("mouseleave",S)}},[Se,nt,Le]),c.useEffect(()=>{const l=Array.isArray(Ze)?Ze:[Ze],w=async u=>{var y,R,S,m;if(l.includes(u.key)){if(u.target.tagName==="INPUT"||u.target.tagName==="TEXTAREA"||u.target.isContentEditable)return;const T=K.current.filter(H=>H.selected),C=Re.current.filter(H=>H.selected);if(!T.length&&!C.length)return;if(O.current.onBeforeDelete)try{if(!await O.current.onBeforeDelete({nodes:T,edges:C}))return}catch(H){(R=(y=O.current).onError)==null||R.call(y,"before-delete-error",H.message||"onBeforeDelete threw an error");return}const U=new Set(T.map(H=>H.id));if(T.length&&ze.current&&(ze.current(T.map(H=>({id:H.id,type:"remove"}))),Pe.current)){const H=Re.current.filter(Z=>U.has(Z.source)||U.has(Z.target));H.length&&Pe.current(H.map(Z=>({id:Z.id,type:"remove"})))}C.length&&Pe.current&&Pe.current(C.map(H=>({id:H.id,type:"remove"}))),(m=(S=O.current).onDelete)==null||m.call(S,{nodes:T,edges:C})}if((u.ctrlKey||u.metaKey)&&u.key==="a"){if(u.target.tagName==="INPUT"||u.target.tagName==="TEXTAREA")return;if(u.preventDefault(),ze.current){const T=K.current.filter(C=>!C.selected).map(C=>({id:C.id,type:"select",selected:!0}));T.length&&ze.current(T)}if(Pe.current){const T=Re.current.filter(C=>!C.selected).map(C=>({id:C.id,type:"select",selected:!0}));T.length&&Pe.current(T)}}};return window.addEventListener("keydown",w),()=>window.removeEventListener("keydown",w)},[Ze]);const Qt=c.useRef(!1);c.useEffect(()=>{var l,w;if(!Qt.current&&Ee.current){if(Qt.current=!0,Je&&K.current.length>0){const u=pe.current;if(u){const y=u.getBoundingClientRect(),R=(le==null?void 0:le.padding)??.1,S=mn(K.current),m=jt(S,y.width,y.height,R);le!=null&&le.maxZoom&&(m.zoom=Math.min(m.zoom,le.maxZoom)),le!=null&&le.minZoom&&(m.zoom=Math.max(m.zoom,le.minZoom)),ie.current=m,ce()}}(w=(l=O.current).onInit)==null||w.call(l,{getNodes:()=>[...K.current],getEdges:()=>[...Re.current],getNode:u=>K.current.find(y=>y.id===u),getEdge:u=>Re.current.find(y=>y.id===u),getViewport:()=>({...ie.current}),getZoom:()=>ie.current.zoom,setViewport:u=>{ie.current={x:u.x??ie.current.x,y:u.y??ie.current.y,zoom:u.zoom??ie.current.zoom},ce()},fitView:(u={})=>{const y=pe.current;if(!y||!K.current.length)return;const R=y.getBoundingClientRect(),S=u.nodes?K.current.filter(C=>u.nodes.some(U=>U.id===C.id)):K.current;if(!S.length)return;const m=mn(S),T=jt(m,R.width,R.height,u.padding??.1);u.maxZoom&&(T.zoom=Math.min(T.zoom,u.maxZoom)),u.minZoom&&(T.zoom=Math.max(T.zoom,u.minZoom)),ie.current=T,ce()},screenToFlowPosition:u=>Se(u.x,u.y),flowToScreenPosition:u=>{const y=ie.current,R=pe.current;if(!R)return{x:0,y:0};const S=R.getBoundingClientRect();return{x:u.x*y.zoom+y.x+S.left,y:u.y*y.zoom+y.y+S.top}},zoomIn:()=>{const u=ie.current;u.zoom=Math.min(ue,u.zoom*1.2),ce()},zoomOut:()=>{const u=ie.current;u.zoom=Math.max(ae,u.zoom/1.2),ce()},zoomTo:u=>{ie.current.zoom=Math.min(ue,Math.max(ae,u)),ce()},setNodes:u=>{var y,R;(R=(y=O.current).onNodesChange)==null||R.call(y,[...K.current.map(S=>({id:S.id,type:"remove"})),...(typeof u=="function"?u(K.current):u).map(S=>({type:"add",item:S}))])},setEdges:u=>{var y,R;(R=(y=O.current).onEdgesChange)==null||R.call(y,[...Re.current.map(S=>({id:S.id,type:"remove"})),...(typeof u=="function"?u(Re.current):u).map(S=>({type:"add",item:S}))])},addNodes:u=>{var R,S;const y=Array.isArray(u)?u:[u];(S=(R=O.current).onNodesChange)==null||S.call(R,y.map(m=>({type:"add",item:m})))},addEdges:u=>{var R,S;const y=Array.isArray(u)?u:[u];(S=(R=O.current).onEdgesChange)==null||S.call(R,y.map(m=>({type:"add",item:m})))},deleteElements:({nodes:u=[],edges:y=[]})=>{var R,S,m,T;u.length&&((S=(R=O.current).onNodesChange)==null||S.call(R,u.map(C=>({id:C.id,type:"remove"})))),y.length&&((T=(m=O.current).onEdgesChange)==null||T.call(m,y.map(C=>({id:C.id,type:"remove"}))))},updateNodeData:(u,y)=>{var m,T;const R=K.current.find(C=>C.id===u);if(!R)return;const S=typeof y=="function"?y(R.data):{...R.data,...y};(T=(m=O.current).onNodesChange)==null||T.call(m,[{id:u,type:"replace",item:{...R,data:S}}])},toObject:()=>({nodes:[...K.current],edges:[...Re.current],viewport:{...ie.current}}),setCenter:(u,y,R={})=>{const S=pe.current;if(!S)return;const m=S.getBoundingClientRect(),T=R.zoom??ie.current.zoom;ie.current={x:m.width/2-u*T,y:m.height/2-y*T,zoom:T},ce()},fitBounds:(u,y={})=>{const R=pe.current;if(!R)return;const S=R.getBoundingClientRect(),m=jt(u,S.width,S.height,y.padding??.1);ie.current=m,ce()}})}});const gn=c.useCallback(()=>{ie.current={...Ne},ce()},[ce,Ne]),qe=c.useCallback(l=>{var w;if(l)gt.current.push(l);else{const u=ie.current,y=pe.current;if(!y)return;const R=y.getBoundingClientRect(),S=Math.round(-u.x/u.zoom+R.width/2/u.zoom),m=Math.round(-u.y/u.zoom+R.height/2/u.zoom);gt.current.push({x:S-80,y:m-45,w:160,h:90,title:"Note "+(gt.current.length+1),body:"Added at viewport center"})}(w=Ee.current)==null||w.postMessage({type:"cards",data:{cards:[...gt.current]}})},[]),wt=c.useCallback(l=>{if(l.id||(l.id="node-"+Date.now()),!l.position){const w=ie.current,u=pe.current;if(!u)return;const y=u.getBoundingClientRect();l.position={x:Math.round(-w.x/w.zoom+y.width/2/w.zoom)-it/2,y:Math.round(-w.y/w.zoom+y.height/2/w.zoom)-rt/2}}l.data||(l.data={label:l.id}),ze.current&&ze.current([{type:"add",item:l}])},[]),Dn=c.useCallback(()=>({...ie.current}),[]),Hn=c.useCallback(l=>{ie.current={...ie.current,...l},ce()},[ce]),Hr=c.useCallback(l=>Se(l.x,l.y),[Se]),ar=n,_r=c.useMemo(()=>({wrapRef:pe,canvasRef:Ht,workerRef:Ee,cameraRef:ie,nodesRef:K,edgesRef:Re,handleRegistryRef:fn,syncNodesToWorker:hn,onNodesChangeRef:ze,onEdgesChangeRef:Pe,sendCamera:ce,screenToWorld:Se,viewportListeners:tt,selectionListeners:Ke,zoomMin:ae,zoomMax:ue,snapToGrid:De,snapGrid:Xe,nodeExtent:ft,defaultEdgeOptions:Nt,edgeRouting:ht,resolvedNodesRef:et,noDragClassName:Pt,noPanClassName:It,get nodes(){return t},get edges(){return n},get routedEdges(){return ar},get viewport(){return Ft},get connection(){return yt}}),[t,n,ar,Ft,yt,ce,Se,hn,tt,Ke,ae,ue,De,Xe,ft,Nt,ht,Pt,It]);return{wrapRef:pe,canvasRef:Ht,canvasReady:Tn,onPointerDown:jn,onPointerMove:An,onPointerUp:kt,resetView:gn,addCard:qe,addNode:wt,getCamera:Dn,setCamera:Hn,screenToFlowPosition:Hr,store:_r}}function ro(e,t,n,r,a,o){const i=a-n,f=o-r,p=i*i+f*f;if(p===0)return Math.hypot(e-n,t-r);let d=((e-n)*i+(t-r)*f)/p;return d=Math.max(0,Math.min(1,d)),Math.hypot(e-(n+d*i),t-(r+d*f))}const cr=e=>{let t;const n=new Set,r=(d,h)=>{const v=typeof d=="function"?d(t):d;if(!Object.is(v,t)){const E=t;t=h??(typeof v!="object"||v===null)?v:Object.assign({},t,v),n.forEach(M=>M(t,E))}},a=()=>t,f={setState:r,getState:a,getInitialState:()=>p,subscribe:d=>(n.add(d),()=>n.delete(d))},p=t=e(r,a,f);return f},oo=(e=>e?cr(e):cr),so=e=>e;function ao(e,t=so){const n=c.useSyncExternalStore(e.subscribe,c.useCallback(()=>t(e.getState()),[e,t]),c.useCallback(()=>t(e.getInitialState()),[e,t]));return c.useDebugValue(n),n}const Et=c.createContext(null);function io(e={}){return oo((t,n)=>({nodes:[],edges:[],viewport:{x:0,y:0,zoom:1},connection:null,minZoom:.1,maxZoom:5,width:0,height:0,domNode:null,nodesRef:{current:[]},edgesRef:{current:[]},cameraRef:{current:{x:0,y:0,zoom:1}},wrapRef:{current:null},workerRef:{current:null},onNodesChangeRef:{current:null},onEdgesChangeRef:{current:null},viewportListeners:new Set,selectionListeners:new Set,edgeLabelContainerRef:{current:null},viewportPortalRef:{current:null},screenToWorld:(r,a)=>{const o=n().cameraRef.current;return{x:(r-o.x)/o.zoom,y:(a-o.y)/o.zoom}},sendCamera:()=>{var a;const r=n();(a=r.workerRef.current)==null||a.postMessage({type:"camera",data:{camera:{...r.cameraRef.current}}})},...e}))}function Ce(e,t){const n=c.useContext(Et);if(!n)throw new Error("useCanvasStore must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");const r=typeof n.getState=="function"&&typeof n.subscribe=="function",a=c.useRef(e),o=c.useRef(t),i=c.useRef(void 0);a.current=e,o.current=t;const f=c.useCallback(p=>{const d=a.current;if(!d)return p;const h=d(p),v=o.current||Object.is;return i.current!==void 0&&v(i.current,h)?i.current:(i.current=h,h)},[]);return r?ao(n,e?f:void 0):e?f(n):n}function wr(){const e=c.useContext(Et);if(!e)throw new Error("useCanvasStoreApi must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");return typeof e.getState=="function"?e:{getState:()=>e,setState:()=>{},subscribe:()=>()=>{}}}const on=c.createContext(null);function co(){return c.useContext(on)}function uo({node:e,nodeType:t}){var E,M,z;const n=Ce(),r=c.useRef(n);r.current=n;const a=c.useRef(null),o=e._absolutePosition||e.position,i=c.useRef(null);c.useEffect(()=>{const I=a.current;if(!I)return;const k=new ResizeObserver(j=>{var _,A,L,Y;const{width:X,height:D}=j[0].contentRect;if(X>0&&D>0){const F=r.current,B=F.nodesRef.current.find(x=>x.id===e.id),b=(B==null?void 0:B.width)||((_=B==null?void 0:B.measured)==null?void 0:_.width),g=(B==null?void 0:B.height)||((A=B==null?void 0:B.measured)==null?void 0:A.height);(Math.abs((b||0)-X)>1||Math.abs((g||0)-D)>1)&&((Y=(L=F.onNodesChangeRef).current)==null||Y.call(L,[{id:e.id,type:"dimensions",dimensions:{width:X,height:D},setAttributes:!0}]))}});return k.observe(I),()=>k.disconnect()},[e.id]);const f=c.useCallback(I=>{var ee,oe,ge,ye;I.stopPropagation();const k=I.target.tagName;if(k==="INPUT"||k==="TEXTAREA"||k==="SELECT"||k==="BUTTON"||k==="A"||k==="LABEL"||I.target.isContentEditable)return;const j=r.current.noDragClassName||"nodrag",X=r.current.noPanClassName||"nopan";let D=I.target;for(;D&&D!==a.current;){if((ee=D.classList)!=null&&ee.contains(j)||(oe=D.classList)!=null&&oe.contains(X))return;D=D.parentElement}if(r.current.onNodesChangeRef.current){const J=[];if(I.shiftKey)J.push({id:e.id,type:"select",selected:!e.selected});else for(const me of r.current.nodesRef.current)me.id===e.id&&!me.selected?J.push({id:me.id,type:"select",selected:!0}):me.id!==e.id&&me.selected&&J.push({id:me.id,type:"select",selected:!1});J.length&&r.current.onNodesChangeRef.current(J)}const _=r.current.cameraRef.current,A=r.current.wrapRef.current;if(!A)return;const L=A.getBoundingClientRect(),Y=(I.clientX-L.left-_.x)/_.zoom,F=(I.clientY-L.top-_.y)/_.zoom,b=e.selected?r.current.nodesRef.current.filter(J=>J.selected&&J.id!==e.id).map(J=>({id:J.id,startPos:{...J.position}})):[];i.current={startPos:{...e.position},startMouse:{x:Y,y:F},selectedStarts:b};const g=[{id:e.id,type:"position",dragging:!0}];for(const J of b)g.push({id:J.id,type:"position",dragging:!0});(ye=(ge=r.current.onNodesChangeRef).current)==null||ye.call(ge,g);const x=a.current;x&&x.setPointerCapture(I.pointerId);let N=null,$=null;const W=()=>{var J,fe;$&&((fe=(J=r.current.onNodesChangeRef).current)==null||fe.call(J,$),$=null),N=null},V=J=>{var je,_e;if(!i.current)return;const fe=r.current.cameraRef.current,me=A.getBoundingClientRect(),ae=(J.clientX-me.left-fe.x)/fe.zoom,ue=(J.clientY-me.top-fe.y)/fe.zoom,Ne=ae-i.current.startMouse.x,Je=ue-i.current.startMouse.y;let le={x:i.current.startPos.x+Ne,y:i.current.startPos.y+Je};if(r.current.snapToGrid&&r.current.snapGrid&&(le={x:r.current.snapGrid[0]*Math.round(le.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(le.y/r.current.snapGrid[1])}),e.parentId&&e.extent==="parent"){const he=r.current.nodesRef.current.find(Me=>Me.id===e.parentId);if(he){const Me=he.width||160,Oe=he.height||60,Ae=e.width||((je=e.measured)==null?void 0:je.width)||160,ct=e.height||((_e=e.measured)==null?void 0:_e.height)||60;le={x:Math.max(0,Math.min(le.x,Me-Ae)),y:Math.max(0,Math.min(le.y,Oe-ct))}}}x&&(x.style.left=le.x+"px",x.style.top=le.y+"px");for(const he of i.current.selectedStarts){let Me={x:he.startPos.x+Ne,y:he.startPos.y+Je};r.current.snapToGrid&&r.current.snapGrid&&(Me={x:r.current.snapGrid[0]*Math.round(Me.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Me.y/r.current.snapGrid[1])});const Oe=A.querySelector(`[data-nodeid="${he.id}"]`);Oe&&(Oe.style.left=Me.x+"px",Oe.style.top=Me.y+"px")}const Be=[{id:e.id,type:"position",position:le,dragging:!0}];for(const he of i.current.selectedStarts){let Me={x:he.startPos.x+Ne,y:he.startPos.y+Je};r.current.snapToGrid&&r.current.snapGrid&&(Me={x:r.current.snapGrid[0]*Math.round(Me.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Me.y/r.current.snapGrid[1])}),Be.push({id:he.id,type:"position",position:Me,dragging:!0})}$=Be,N||(N=requestAnimationFrame(W))},re=J=>{var me,ae;if(!i.current)return;N&&(cancelAnimationFrame(N),W());const fe=[{id:e.id,type:"position",dragging:!1}];for(const ue of i.current.selectedStarts)fe.push({id:ue.id,type:"position",dragging:!1});(ae=(me=r.current.onNodesChangeRef).current)==null||ae.call(me,fe),i.current=null,x&&x.releasePointerCapture(J.pointerId),x==null||x.removeEventListener("pointermove",V),x==null||x.removeEventListener("pointerup",re)};x==null||x.addEventListener("pointermove",V),x==null||x.addEventListener("pointerup",re)},[e]),p=c.useCallback(I=>{var A,L,Y,F,B,b;if(!e.selected)return;const k=I.shiftKey?10:1;let j=0,X=0;switch(I.key){case"ArrowUp":X=-k;break;case"ArrowDown":X=k;break;case"ArrowLeft":j=-k;break;case"ArrowRight":j=k;break;case"Escape":(L=(A=r.current.onNodesChangeRef).current)==null||L.call(A,[{id:e.id,type:"select",selected:!1}]);return;case"Delete":case"Backspace":e.deletable!==!1&&((F=(Y=r.current.onNodesChangeRef).current)==null||F.call(Y,[{id:e.id,type:"remove"}]));return;default:return}I.preventDefault();const D={x:e.position.x+j,y:e.position.y+X},_=[{id:e.id,type:"position",position:D}];for(const g of r.current.nodesRef.current)g.selected&&g.id!==e.id&&_.push({id:g.id,type:"position",position:{x:g.position.x+j,y:g.position.y+X}});(b=(B=r.current.onNodesChangeRef).current)==null||b.call(B,_)},[e]),d=e.width||((E=e.measured)==null?void 0:E.width),h=e.height||((M=e.measured)==null?void 0:M.height),v=!!(d&&h);return P.jsx(on.Provider,{value:e.id,children:P.jsx("div",{ref:a,className:`ric-node-wrapper ${e.selected?"selected":""} ${e.dragging?"dragging":""}`,style:{position:"absolute",left:o.x,top:o.y,zIndex:e.type==="group"?0:e.zIndex||1,pointerEvents:e.type==="group"?"none":"all",visibility:v?"visible":"hidden",outline:"none"},"data-nodeid":e.id,tabIndex:e.selectable!==!1?0:void 0,role:"button","aria-label":`Node ${((z=e.data)==null?void 0:z.label)||e.id}`,"aria-selected":!!e.selected,onPointerDown:f,onKeyDown:p,children:P.jsx(t,{id:e.id,data:e.data,type:e.type,selected:!!e.selected,dragging:!!e.dragging,draggable:e.draggable!==!1,selectable:e.selectable!==!1,deletable:e.deletable!==!1,isConnectable:e.connectable!==!1,zIndex:e.zIndex||0,positionAbsoluteX:o.x,positionAbsoluteY:o.y,width:d,height:h,sourcePosition:e.sourcePosition,targetPosition:e.targetPosition,parentId:e.parentId,dragHandle:e.dragHandle})})})}const lo=c.memo(uo),Mr=160,Rr=60;function ur(e,t,n,r){var f,p;const a=e.width||((f=e.measured)==null?void 0:f.width)||Mr,o=e.height||((p=e.measured)==null?void 0:p.height)||Rr,i=e._absolutePosition||e.position;if(e.handleBounds){const d=e.handleBounds[t]||[],h=n?d.find(v=>v.id===n):d[0];if(h&&h.x!==void 0&&h.y!==void 0){const v=h.position||(t==="source"?"right":"left");return{x:i.x+h.x,y:i.y+h.y,position:v}}}if(r){const d=`${e.id}__${n||t}`,h=r.get(d);if(h&&h.x!==void 0&&h.y!==void 0)return{x:i.x+h.x,y:i.y+h.y,position:h.position||(t==="source"?"right":"left")}}if(e.handles&&e.handles.length){for(const d of e.handles)if(d.type===t&&(!n||d.id===n)){if(d.x!==void 0&&d.y!==void 0)return{x:i.x+d.x,y:i.y+d.y,position:d.position||(t==="source"?"right":"left")};const h=d.position||(t==="source"?"right":"left");switch(h){case"top":return{x:i.x+a/2,y:i.y,position:h};case"bottom":return{x:i.x+a/2,y:i.y+o,position:h};case"left":return{x:i.x,y:i.y+o/2,position:h};default:return{x:i.x+a,y:i.y+o/2,position:h}}}}return t==="source"?{x:i.x+a,y:i.y+o/2,position:"right"}:{x:i.x,y:i.y+o/2,position:"left"}}function fo(e,t,n){return n==="left"?e-t:n==="right"?e+t:e}function ho(e,t,n){return n==="top"?e-t:n==="bottom"?e+t:e}function lr({x:e,y:t,position:n,type:r,onPointerDown:a}){return P.jsx("circle",{className:`ric-edge-anchor ric-edge-anchor-${r}`,cx:fo(e,10,n),cy:ho(t,10,n),r:10,stroke:"transparent",fill:"transparent",style:{cursor:"move",pointerEvents:"stroke"},onPointerDown:a})}function go({edge:e,edgeType:t,nodes:n,reconnectable:r}){var L,Y,F;const a=c.useContext(Et),o=c.useRef(typeof a.getState=="function"?a.getState():a);o.current=typeof a.getState=="function"?a.getState():a;const[i,f]=c.useState(null),p=c.useCallback((B,b,g,x)=>{var ge;b.stopPropagation(),b.preventDefault();const N=o.current,$=N.wrapRef.current;if(!$)return;const W=B==="source"?x:g,V=B==="source"?e.target:e.source;(ge=N.workerRef.current)==null||ge.postMessage({type:"connecting",data:{from:{x:W.x,y:W.y},to:{x:W.x,y:W.y}}});const re=$.getBoundingClientRect(),ee=ye=>{var ae;const J=N.cameraRef.current,fe=(ye.clientX-re.left-J.x)/J.zoom,me=(ye.clientY-re.top-J.y)/J.zoom;(ae=N.workerRef.current)==null||ae.postMessage({type:"connecting",data:{from:{x:W.x,y:W.y},to:{x:fe,y:me}}})},oe=ye=>{var le,Be,je,_e;const J=N.cameraRef.current,fe=(ye.clientX-re.left-J.x)/J.zoom,me=(ye.clientY-re.top-J.y)/J.zoom,ae=20/J.zoom;let ue=null,Ne=null;const Je=(le=N.handleRegistryRef)==null?void 0:le.current;for(const he of N.nodesRef.current){if(he.hidden)continue;const Me=he.width||Mr,Oe=he.height||Rr,Ae=he._absolutePosition||he.position,ct=[];if(Je)for(const[,De]of Je)De.nodeId===he.id&&ct.push(De);const zt=ct.length>0?ct:he.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const De of zt){let Xe,Ze;if(De.x!==void 0&&De.y!==void 0)Xe=Ae.x+De.x,Ze=Ae.y+De.y;else switch(De.position||(De.type==="source"?"right":"left")){case"top":Xe=Ae.x+Me/2,Ze=Ae.y;break;case"bottom":Xe=Ae.x+Me/2,Ze=Ae.y+Oe;break;case"left":Xe=Ae.x,Ze=Ae.y+Oe/2;break;default:Xe=Ae.x+Me,Ze=Ae.y+Oe/2;break}if(Math.abs(fe-Xe)<ae&&Math.abs(me-Ze)<ae){ue=he,Ne=De.id||null;break}}if(ue)break}if(ue){const he=B==="source"?{source:ue.id,target:V,sourceHandle:Ne,targetHandle:e.targetHandle}:{source:V,target:ue.id,sourceHandle:e.sourceHandle,targetHandle:Ne};(je=(Be=N.onEdgesChangeRef).current)==null||je.call(Be,[{id:e.id,type:"remove"},{type:"add",item:{id:e.id,...he}}])}(_e=N.workerRef.current)==null||_e.postMessage({type:"connecting",data:null}),$.removeEventListener("pointermove",ee),$.removeEventListener("pointerup",oe)};$.addEventListener("pointermove",ee),$.addEventListener("pointerup",oe)},[e]),d=n.find(B=>B.id===e.source),h=n.find(B=>B.id===e.target),v=d&&!!(d.width||(L=d.measured)!=null&&L.width),E=h&&!!(h.width||(Y=h.measured)!=null&&Y.width),M=o.current,z=(F=M.handleRegistryRef)==null?void 0:F.current,I=v?ur(d,"source",e.sourceHandle,z):null,k=E?ur(h,"target",e.targetHandle,z):null,j=e.type==="bezier"||e.type==="simplebezier"||e.type==="default",X=M.routedEdges||M.edges,D=X==null?void 0:X.find(B=>B.id===e.id),_=j?null:(D==null?void 0:D._routedPoints)||e._routedPoints||null,A=r!==!1&&e.reconnectable!==!1;return!I||!k?null:P.jsxs("g",{className:`ric-edge-wrapper ${e.selected?"selected":""}`,"data-edgeid":e.id,onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),children:[P.jsx(t,{id:e.id,source:e.source,target:e.target,sourceX:I.x,sourceY:I.y,targetX:k.x,targetY:k.y,sourcePosition:I.position,targetPosition:k.position,sourceHandleId:e.sourceHandle,targetHandleId:e.targetHandle,data:e.data,type:e.type,selected:!!e.selected,animated:!!e.animated,label:e.label,style:e.style,selectable:e.selectable!==!1,deletable:e.deletable!==!1,routedPoints:_}),A&&(i||e.selected)&&P.jsxs(P.Fragment,{children:[P.jsx(lr,{x:I.x,y:I.y,position:I.position,type:"source",onPointerDown:B=>p("source",B,I,k)}),P.jsx(lr,{x:k.x,y:k.y,position:k.position,type:"target",onPointerDown:B=>p("target",B,I,k)})]})]})}const yo=c.memo(go);function kr({selectionKeyCode:e="Shift",selectionMode:t="partial"}){var I;const n=Ce(),[r,a]=c.useState(null),o=c.useRef(null);if(c.useEffect(()=>{const k=n.wrapRef.current;if(!k)return;let j=!1,X=null,D=!1;const _=B=>{B.key===e&&(D=!0)},A=B=>{B.key===e&&(D=!1)},L=B=>{if(!D)return;const b=B.target;if(b.closest(".ric-node-wrapper")||b.closest(".ric-handle"))return;j=!0;const g=n.cameraRef.current,x=k.getBoundingClientRect(),N=(B.clientX-x.left-g.x)/g.zoom,$=(B.clientY-x.top-g.y)/g.zoom;X={x:N,y:$},a({startX:N,startY:$,endX:N,endY:$}),B.stopPropagation()},Y=B=>{if(!j||!X)return;const b=n.cameraRef.current,g=k.getBoundingClientRect(),x=(B.clientX-g.left-b.x)/b.zoom,N=(B.clientY-g.top-b.y)/b.zoom;a({startX:X.x,startY:X.y,endX:x,endY:N})},F=B=>{var V,re;if(!j||!X)return;j=!1;const b=n.cameraRef.current,g=k.getBoundingClientRect(),x=(B.clientX-g.left-b.x)/b.zoom,N=(B.clientY-g.top-b.y)/b.zoom,$={x:Math.min(X.x,x),y:Math.min(X.y,N),width:Math.abs(x-X.x),height:Math.abs(N-X.y)},W=[];for(const ee of n.nodesRef.current){const oe=ee._absolutePosition||ee.position,ge=ee.width||160,ye=ee.height||60;let J;t==="full"?J=oe.x>=$.x&&oe.y>=$.y&&oe.x+ge<=$.x+$.width&&oe.y+ye<=$.y+$.height:J=oe.x+ge>$.x&&oe.x<$.x+$.width&&oe.y+ye>$.y&&oe.y<$.y+$.height,W.push({id:ee.id,type:"select",selected:J})}W.length&&((re=(V=n.onNodesChangeRef).current)==null||re.call(V,W)),X=null,a(null)};return k.addEventListener("pointerdown",L,!0),k.addEventListener("pointermove",Y),k.addEventListener("pointerup",F),window.addEventListener("keydown",_),window.addEventListener("keyup",A),()=>{k.removeEventListener("pointerdown",L,!0),k.removeEventListener("pointermove",Y),k.removeEventListener("pointerup",F),window.removeEventListener("keydown",_),window.removeEventListener("keyup",A)}},[n,e,t]),!r)return null;const i=((I=n.cameraRef)==null?void 0:I.current)||{x:0,y:0,zoom:1},f=Math.min(r.startX,r.endX),p=Math.min(r.startY,r.endY),d=Math.abs(r.endX-r.startX),h=Math.abs(r.endY-r.startY),v=f*i.zoom+i.x,E=p*i.zoom+i.y,M=d*i.zoom,z=h*i.zoom;return P.jsx("div",{ref:o,className:"ric-selection-box",style:{position:"absolute",left:v,top:E,width:M,height:z,border:"1px dashed #3b82f6",background:"rgba(59, 130, 246, 0.08)",pointerEvents:"none",zIndex:100}})}kr.displayName="SelectionBox";const Cr=c.memo(kr);function On(e,t,n){switch(e){case"top":return{x:t/2,y:0};case"bottom":return{x:t/2,y:n};case"left":return{x:0,y:n/2};case"right":return{x:t,y:n/2};default:return{x:t,y:n/2}}}function xo(e,t){const n=e.closest(".ric-node-wrapper");if(!n)return null;const r=n.getBoundingClientRect(),a=e.getBoundingClientRect(),o=t||1;return{x:(a.left+a.width/2-r.left)/o,y:(a.top+a.height/2-r.top)/o}}let Fn=!1,Ct=null;function Er(e){Ct=e,!Fn&&(Fn=!0,requestAnimationFrame(()=>{var t;Fn=!1,(t=Ct==null?void 0:Ct.syncNodesToWorker)==null||t.call(Ct),Ct=null}))}const Zn=new WeakMap;let xn=null;function po(){return xn||(xn=new ResizeObserver(e=>{var t;for(const n of e){const r=Zn.get(n.target);if(!r)continue;const{width:a,height:o}=n.contentRect;if(!a||!o)continue;const i=r.getStore(),f=(t=i.handleRegistryRef)==null?void 0:t.current;if(f){for(const[p,d]of f)if(d.nodeId===r.nodeId){const h=On(d.position,a,o);d.x=h.x,d.y=h.y,f.set(p,d)}Er(i)}}}),xn)}function mo({type:e="source",position:t=e==="source"?"right":"left",id:n,isConnectable:r=!0,isConnectableStart:a=!0,isConnectableEnd:o=!0,children:i,className:f="",style:p={},onConnect:d,...h}){const v=c.useContext(on),E=c.useContext(Et),M=c.useRef(null),z=c.useCallback(()=>typeof E.getState=="function"?E.getState():E,[E]),I=c.useRef(z);I.current=z,c.useLayoutEffect(()=>{var b,g,x,N,$,W,V;if(!v)return;const D=I.current(),_=(b=D.handleRegistryRef)==null?void 0:b.current;if(!_)return;const A=`${v}__${n||e}`,L=(x=(g=D.nodesRef)==null?void 0:g.current)==null?void 0:x.find(re=>re.id===v),Y=(L==null?void 0:L.width)||((N=L==null?void 0:L.measured)==null?void 0:N.width),F=(L==null?void 0:L.height)||(($=L==null?void 0:L.measured)==null?void 0:$.height);let B;Y&&F?B=On(t,Y,F):M.current?B=xo(M.current,(V=(W=D.cameraRef)==null?void 0:W.current)==null?void 0:V.zoom):B=On(t,160,60),_.set(A,{nodeId:v,id:n||null,type:e,position:t,x:B.x,y:B.y})},[v,n,e,t]),c.useEffect(()=>{if(!v)return;const D=I.current();Er(D);const _=M.current,A=_==null?void 0:_.closest(".ric-node-wrapper");return A&&!Zn.has(A)&&(Zn.set(A,{nodeId:v,getStore:I.current}),po().observe(A)),()=>{var B;const Y=(B=I.current().handleRegistryRef)==null?void 0:B.current,F=`${v}__${n||e}`;Y==null||Y.delete(F)}},[v,n,e,t]);const k=c.useCallback(()=>{var g;const D=I.current(),_=D.nodesRef.current.find(x=>x.id===v);if(!_)return null;const A=_._absolutePosition||_.position,L=(g=D.handleRegistryRef)==null?void 0:g.current,Y=`${v}__${n||e}`,F=L==null?void 0:L.get(Y);if(F&&F.x!==void 0&&F.y!==void 0)return{x:A.x+F.x,y:A.y+F.y};const B=_.width||160,b=_.height||60;switch(t){case"top":return{x:A.x+B/2,y:A.y};case"bottom":return{x:A.x+B/2,y:A.y+b};case"left":return{x:A.x,y:A.y+b/2};default:return{x:A.x+B,y:A.y+b/2}}},[v,n,e,t]),j=c.useCallback(D=>{var N;if(!r||!a)return;D.stopPropagation(),D.preventDefault();const _=I.current(),A=_.cameraRef.current,L=_.wrapRef.current;if(!L)return;const Y=L.getBoundingClientRect(),F=k();if(!F)return;const B=F.x,b=F.y;(N=_.workerRef.current)==null||N.postMessage({type:"connecting",data:{from:{x:B,y:b},to:{x:B,y:b}}}),L.setPointerCapture(D.pointerId);const g=$=>{var re;const W=($.clientX-Y.left-A.x)/A.zoom,V=($.clientY-Y.top-A.y)/A.zoom;(re=_.workerRef.current)==null||re.postMessage({type:"connecting",data:{from:{x:B,y:b},to:{x:W,y:V}}})},x=$=>{var ye,J,fe,me;const W=($.clientX-Y.left-A.x)/A.zoom,V=($.clientY-Y.top-A.y)/A.zoom,re=20/A.zoom;let ee=null,oe=null;const ge=(ye=_.handleRegistryRef)==null?void 0:ye.current;for(const ae of _.nodesRef.current){if(ae.id===v||ae.hidden)continue;const ue=ae._absolutePosition||ae.position,Ne=[];if(ge)for(const[,le]of ge)le.nodeId===ae.id&&Ne.push(le);const Je=Ne.length>0?Ne:ae.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const le of Je){let Be,je;if(le.x!==void 0&&le.y!==void 0)Be=ue.x+le.x,je=ue.y+le.y;else{const _e=ae.width||160,he=ae.height||60;switch(le.position||(le.type==="source"?"right":"left")){case"top":Be=ue.x+_e/2,je=ue.y;break;case"bottom":Be=ue.x+_e/2,je=ue.y+he;break;case"left":Be=ue.x,je=ue.y+he/2;break;default:Be=ue.x+_e,je=ue.y+he/2;break}}if(Math.abs(W-Be)<re&&Math.abs(V-je)<re){ee=ae,oe=le.id||null;break}}if(ee)break}if(ee){const ae={source:e==="source"?v:ee.id,target:e==="source"?ee.id:v,sourceHandle:e==="source"?n||null:oe,targetHandle:e==="source"?oe:n||null};(fe=(J=_.onEdgesChangeRef)==null?void 0:J.current)==null||fe.call(J,[{type:"add",item:{id:`e-${ae.source}-${ae.target}`,...ae}}])}(me=_.workerRef.current)==null||me.postMessage({type:"connecting",data:null}),L.removeEventListener("pointermove",g),L.removeEventListener("pointerup",x)};L.addEventListener("pointermove",g),L.addEventListener("pointerup",x)},[v,n,e,t,r,a,k]),X={top:{top:0,left:"50%",transform:"translate(-50%, -50%)"},bottom:{bottom:0,left:"50%",transform:"translate(-50%, 50%)"},left:{top:"50%",left:0,transform:"translate(-50%, -50%)"},right:{top:"50%",right:0,transform:"translate(50%, -50%)"}}[t]||{};return P.jsx("div",{ref:M,className:`ric-handle ric-handle-${t} ric-handle-${e} ${f}`,"data-handleid":n||null,"data-nodeid":v,"data-handlepos":t,"data-handletype":e,onPointerDown:j,style:{position:"absolute",width:8,height:8,borderRadius:"50%",background:"#1a192b",border:"none",zIndex:10,cursor:r?"crosshair":"default",boxSizing:"border-box",...X,...p},...h,children:i})}const rn=c.memo(mo);function vo({data:e,isConnectable:t,selected:n,targetPosition:r="left",sourcePosition:a="right",hideSourceHandle:o=!1,hideTargetHandle:i=!1}){return P.jsxs("div",{className:`ric-default-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!i&&P.jsx(rn,{type:"target",position:r,isConnectable:t}),P.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!o&&P.jsx(rn,{type:"source",position:a,isConnectable:t})]})}function zr({data:e,isConnectable:t,selected:n,sourcePosition:r="right",hideSourceHandle:a=!1}){return P.jsxs("div",{className:`ric-input-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderBottom:"2px solid #0041d0",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[P.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!a&&P.jsx(rn,{type:"source",position:r,isConnectable:t})]})}function Sr({data:e,isConnectable:t,selected:n,targetPosition:r="left",hideTargetHandle:a=!1}){return P.jsxs("div",{className:`ric-output-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderTop:"2px solid #ff0072",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!a&&P.jsx(rn,{type:"target",position:r,isConnectable:t}),P.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label})]})}function Nr({data:e,selected:t,width:n,height:r}){return P.jsx("div",{className:`ric-group-node${t?" selected":""}`,style:{width:n||300,height:r||200,background:"rgba(240, 240, 240, 0.25)",border:t?"2px solid #3b82f6":"1px dashed #ccc",borderRadius:8,padding:8,boxSizing:"border-box"},children:(e==null?void 0:e.label)&&P.jsx("div",{style:{fontSize:11,fontWeight:600,color:"#888",userSelect:"none"},children:e.label})})}function Pr({x:e,y:t,label:n,labelStyle:r,labelShowBg:a=!0,labelBgStyle:o,labelBgPadding:i=[2,4],labelBgBorderRadius:f=2,children:p,className:d="",...h}){const[v,E]=c.useState({x:1,y:0,width:0,height:0}),M=c.useRef(null);return c.useEffect(()=>{if(M.current){const z=M.current.getBBox();E({x:z.x,y:z.y,width:z.width,height:z.height})}},[n]),n?P.jsxs("g",{transform:`translate(${e-v.width/2} ${t-v.height/2})`,className:`ric-edge-textwrapper ${d}`,visibility:v.width?"visible":"hidden",...h,children:[a&&P.jsx("rect",{width:v.width+2*i[0],x:-i[0],y:-i[1],height:v.height+2*i[1],className:"ric-edge-textbg",style:o,rx:f,ry:f}),P.jsx("text",{className:"ric-edge-text",y:v.height/2,dy:"0.3em",ref:M,style:r,children:n}),p]}):null}Pr.displayName="EdgeText";const Ir=c.memo(Pr);function dr(e){return e!=null&&e!==""&&!isNaN(Number(e))}function sn({id:e,path:t,labelX:n,labelY:r,label:a,labelStyle:o,labelShowBg:i,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:d,interactionWidth:h=20,style:v,markerEnd:E,markerStart:M,className:z="",...I}){return P.jsxs(P.Fragment,{children:[P.jsx("path",{id:e,d:t,fill:"none",stroke:"#b1b1b7",strokeWidth:1.5,className:`ric-edge-path ${z}`,style:v,markerEnd:E,markerStart:M,...I}),h?P.jsx("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:h,className:"ric-edge-interaction",style:{pointerEvents:"stroke"}}):null,a&&dr(n)&&dr(r)?P.jsx(Ir,{x:n,y:r,label:a,labelStyle:o,labelShowBg:i,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:d}):null]})}const en=20;function fr(e,t,n){switch(n){case"right":return{x:e+en,y:t};case"left":return{x:e-en,y:t};case"bottom":return{x:e,y:t+en};case"top":return{x:e,y:t-en};default:return{x:e+en,y:t}}}const Vn=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:i="bottom",targetPosition:f="top",label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,interactionWidth:j}){let X,D,_;const A=fr(n,r,i),L=fr(a,o,f),Y=Math.abs(L.x-A.x),F=Math.max(50,Y*.5);let B,b,g,x;switch(i){case"left":B=A.x-F,b=A.y;break;case"top":B=A.x,b=A.y-F;break;case"bottom":B=A.x,b=A.y+F;break;default:B=A.x+F,b=A.y;break}switch(f){case"right":g=L.x+F,x=L.y;break;case"top":g=L.x,x=L.y-F;break;case"bottom":g=L.x,x=L.y+F;break;default:g=L.x-F,x=L.y;break}X=`M ${n},${r} L ${A.x},${A.y} C ${B},${b} ${g},${x} ${L.x},${L.y} L ${a},${o}`;const N=.5,$=.5;return D=$*$*$*A.x+3*$*$*N*B+3*$*N*N*g+N*N*N*L.x,_=$*$*$*A.y+3*$*$*N*b+3*$*N*N*x+N*N*N*L.y,P.jsx(sn,{id:t,path:X,labelX:D,labelY:_,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,interactionWidth:j})});Vn.displayName="BezierEdge";function Jn({sourceX:e,sourceY:t,targetX:n,targetY:r}){const a=`M ${e},${t}L ${n},${r}`,o=(e+n)/2,i=(t+r)/2;return[a,o,i,0,0]}function Kn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a="right",targetPosition:o="left",curvature:i=.25}){const f=Math.abs(n-e),p=Math.abs(r-t),d=Math.sqrt(f*f+p*p),h=Math.max(d*i,50);let v,E,M,z;switch(a){case"top":v=e,E=t-h;break;case"bottom":v=e,E=t+h;break;case"left":v=e-h,E=t;break;default:v=e+h,E=t;break}switch(o){case"top":M=n,z=r-h;break;case"bottom":M=n,z=r+h;break;case"right":M=n+h,z=r;break;default:M=n-h,z=r;break}const I=`M ${e},${t} C ${v},${E} ${M},${z} ${n},${r}`,k=.5,j=1-k,X=j*j*j*e+3*j*j*k*v+3*j*k*k*M+k*k*k*n,D=j*j*j*t+3*j*j*k*E+3*j*k*k*z+k*k*k*r;return[I,X,D,0,0]}function er({sourceX:e,sourceY:t,targetX:n,targetY:r}){const a=Math.abs(n-e),o=Math.max(a*.5,50),i=e+o,f=n-o,p=`M ${e},${t} C ${i},${t} ${f},${r} ${n},${r}`,d=.5,h=.5,v=h*h*h*e+3*h*h*d*i+3*h*d*d*f+d*d*d*n,E=h*h*h*t+3*h*h*d*t+3*h*d*d*r+d*d*d*r;return[p,v,E,0,0]}function vn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a="right",targetPosition:o="left",borderRadius:i=5,offset:f=20}){const p=a==="left"||a==="right",d=Math.min(i,Math.abs(n-e)/2,Math.abs(r-t)/2);if(p){if(Math.abs(r-t)<1)return[`M ${e},${t} L ${n},${r}`,(e+n)/2,t,0,0];const M=(e+n)/2,z=r>t?1:-1;return[`M ${e},${t} L ${M-d},${t} Q ${M},${t} ${M},${t+z*d} L ${M},${r-z*d} Q ${M},${r} ${M+(n>M?d:-d)},${r} L ${n},${r}`,M,(t+r)/2,0,0]}const h=(t+r)/2,v=n>e?1:-1;return[`M ${e},${t} L ${e},${h-d} Q ${e},${h} ${e+v*d},${h} L ${n-v*d},${h} Q ${n},${h} ${n},${h+(r>h?d:-d)} L ${n},${r}`,(e+n)/2,h,0,0]}function bo({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[,a,o]=Kn({sourceX:e,sourceY:t,targetX:n,targetY:r});return[a,o,0,0]}function wo({sourceX:e,sourceY:t,targetX:n,targetY:r}){return[(e+n)/2,(t+r)/2,0,0]}function Mo(e,t,n){const r=n.filter(o=>o.id!==e.id),a={...e,id:e.id,source:t.source,target:t.target,sourceHandle:t.sourceHandle??e.sourceHandle,targetHandle:t.targetHandle??e.targetHandle};return r.push(a),r}const bn=160,wn=60,tn=20,pn=12,Mn=20;function hr(e,t,n){var i,f;const r=e.width||((i=e.measured)==null?void 0:i.width)||bn,a=e.height||((f=e.measured)==null?void 0:f.height)||wn,o=e._absolutePosition||e.position;if(e.handles&&e.handles.length>0){for(const p of e.handles)if(p.type===t&&(!n||p.id===n)){if(p.x!==void 0&&p.y!==void 0)return{x:o.x+p.x,y:o.y+p.y,dir:p.position||(t==="source"?"right":"left")};switch(p.position||(t==="source"?"right":"left")){case"top":return{x:o.x+r/2,y:o.y,dir:"top"};case"bottom":return{x:o.x+r/2,y:o.y+a,dir:"bottom"};case"left":return{x:o.x,y:o.y+a/2,dir:"left"};default:return{x:o.x+r,y:o.y+a/2,dir:"right"}}}}return t==="source"?{x:o.x+r,y:o.y+a/2,dir:"right"}:{x:o.x,y:o.y+a/2,dir:"left"}}function Rn(e,t){switch(e.dir){case"right":return{x:e.x+t,y:e.y,dir:e.dir};case"left":return{x:e.x-t,y:e.y,dir:e.dir};case"bottom":return{x:e.x,y:e.y+t,dir:e.dir};case"top":return{x:e.x,y:e.y-t,dir:e.dir};default:return{x:e.x+t,y:e.y,dir:e.dir}}}function Ro(e,t,n,r,a,o,i,f){const p=Math.min(e,n),d=Math.max(e,n),h=Math.min(t,r),v=Math.max(t,r);if(d<=a||p>=a+i||v<=o||h>=o+f)return!1;const E=.5;if(e>a+E&&e<a+i-E&&t>o+E&&t<o+f-E||n>a+E&&n<a+i-E&&r>o+E&&r<o+f-E)return!0;const M=(e+n)/2,z=(t+r)/2;if(M>a+E&&M<a+i-E&&z>o+E&&z<o+f-E)return!0;const I=[[a,o],[a+i,o],[a+i,o+f],[a,o+f]];for(let k=0;k<4;k++)if(ko(e,t,n,r,I[k][0],I[k][1],I[(k+1)%4][0],I[(k+1)%4][1]))return!0;return!1}function ko(e,t,n,r,a,o,i,f){const p=(i-a)*(t-o)-(f-o)*(e-a),d=(i-a)*(r-o)-(f-o)*(n-a),h=(n-e)*(o-t)-(r-t)*(a-e),v=(n-e)*(f-t)-(r-t)*(i-e);return(p>0&&d<0||p<0&&d>0)&&(h>0&&v<0||h<0&&v>0)}function Gn(e,t,n,r,a){for(let o=0;o<a.length;o++){const i=a[o];if(Ro(e,t,n,r,i.x,i.y,i.w,i.h))return!1}return!0}function Co(e,t,n){for(let r=0;r<n.length;r++){const a=n[r];if(e>a.x&&e<a.x+a.w&&t>a.y&&t<a.y+a.h)return!0}return!1}function tr(e,t){var r,a;const n=[];for(let o=0;o<e.length;o++){const i=e[o];if(i.hidden||t&&t.has(i.id)||i.type==="group")continue;const f=i._absolutePosition||i.position,p=i.width||((r=i.measured)==null?void 0:r.width)||bn,d=i.height||((a=i.measured)==null?void 0:a.height)||wn;n.push({id:i.id,x:f.x-tn,y:f.y-tn,w:p+2*tn,h:d+2*tn})}return n}function Lr(e,t,n){if(Gn(e.x,e.y,t.x,t.y,n))return null;const r=new Set,a=new Set;r.add(e.x),r.add(t.x),a.add(e.y),a.add(t.y);const o=tn+5;e.dir==="right"?r.add(e.x+o):e.dir==="left"?r.add(e.x-o):e.dir==="top"?a.add(e.y-o):e.dir==="bottom"&&a.add(e.y+o),t.dir==="right"?r.add(t.x+o):t.dir==="left"?r.add(t.x-o):t.dir==="top"?a.add(t.y-o):t.dir==="bottom"&&a.add(t.y+o);for(let g=0;g<n.length;g++){const x=n[g];r.add(x.x),r.add(x.x+x.w),a.add(x.y),a.add(x.y+x.h)}const i=[...r].sort((g,x)=>g-x),f=[...a].sort((g,x)=>g-x),p=new Map,d=new Map;for(let g=0;g<i.length;g++)p.set(i[g],g);for(let g=0;g<f.length;g++)d.set(f[g],g);const h=i.length,v=f.length,E=(g,x)=>x*h+g,M=p.get(e.x),z=d.get(e.y),I=p.get(t.x),k=d.get(t.y);if(M===void 0||z===void 0||I===void 0||k===void 0)return null;const j=E(M,z),X=E(I,k),D=new Float64Array(h*v).fill(1/0),_=new Float64Array(h*v).fill(1/0),A=new Int32Array(h*v).fill(-1),L=new Int8Array(h*v).fill(-1),Y=new Uint8Array(h*v);D[j]=0,_[j]=Math.abs(i[I]-e.x)+Math.abs(f[k]-e.y);const F=[j],B=15,b=[[1,0],[-1,0],[0,1],[0,-1]];for(;F.length>0;){let g=0;for(let ee=1;ee<F.length;ee++)_[F[ee]]<_[F[g]]&&(g=ee);const x=F[g];if(F[g]=F[F.length-1],F.pop(),x===X){const ee=[];let oe=X;for(;oe!==-1&&oe!==j;){const ge=oe/h|0,ye=oe%h;ee.unshift({x:i[ye],y:f[ge]}),oe=A[oe]}return ee.unshift({x:e.x,y:e.y}),Eo(ee,n)}if(Y[x])continue;Y[x]=1;const N=x/h|0,$=x%h,W=i[$],V=f[N],re=L[x];for(let ee=0;ee<4;ee++){const oe=$+b[ee][0],ge=N+b[ee][1];if(oe<0||oe>=h||ge<0||ge>=v)continue;const ye=E(oe,ge);if(Y[ye])continue;const J=i[oe],fe=f[ge];if(Co(J,fe,n)||!Gn(W,V,J,fe,n))continue;const me=Math.abs(J-W)+Math.abs(fe-V),ae=re>=0&&re!==ee?B:0,ue=D[x]+me+ae;ue<D[ye]&&(A[ye]=x,L[ye]=ee,D[ye]=ue,_[ye]=ue+Math.abs(i[I]-J)+Math.abs(f[k]-fe),F.push(ye))}}return null}function Eo(e,t){if(!e||e.length<=2)return e;const n=[e[0]];for(let r=1;r<e.length-1;r++){const a=n[n.length-1],o=e[r],i=e[r+1],f=Math.abs(a.x-o.x)<.5&&Math.abs(o.x-i.x)<.5,p=Math.abs(a.y-o.y)<.5&&Math.abs(o.y-i.y)<.5;(f||p)&&Gn(a.x,a.y,i.x,i.y,t)||n.push(o)}return n.push(e[e.length-1]),n}function zo(e){const t=new Map,n=new Map;for(const a of e){const o=a._routedPoints;if(!(!o||o.length<2))for(let i=0;i<o.length-1;i++){const f=o[i],p=o[i+1];if(Math.abs(f.y-p.y)<.5){const d=Math.round(f.y*10)/10;t.has(d)||t.set(d,[]),t.get(d).push({edgeId:a.id,segIdx:i,x1:Math.min(f.x,p.x),x2:Math.max(f.x,p.x)})}else if(Math.abs(f.x-p.x)<.5){const d=Math.round(f.x*10)/10;n.has(d)||n.set(d,[]),n.get(d).push({edgeId:a.id,segIdx:i,y1:Math.min(f.y,p.y),y2:Math.max(f.y,p.y)})}}}const r=new Map;for(const a of e)a._routedPoints&&r.set(a.id,a._routedPoints.map(o=>({...o})));for(const[,a]of t){if(a.length<2)continue;const o=gr(a,"x1","x2");for(const i of o){if(i.length<2)continue;const f=(i.length-1)*pn/2;for(let p=0;p<i.length;p++){const d=i[p],h=-f+p*pn,v=r.get(d.edgeId);v&&(v[d.segIdx].y+=h,v[d.segIdx+1].y+=h)}}}for(const[,a]of n){if(a.length<2)continue;const o=gr(a,"y1","y2");for(const i of o){if(i.length<2)continue;const f=(i.length-1)*pn/2;for(let p=0;p<i.length;p++){const d=i[p],h=-f+p*pn,v=r.get(d.edgeId);v&&(v[d.segIdx].x+=h,v[d.segIdx+1].x+=h)}}}return e.map(a=>{const o=r.get(a.id);return o?{...a,_routedPoints:o}:a})}function gr(e,t,n){if(e.length<2)return[];const r=[...e].sort((i,f)=>i[t]-f[t]),a=[];let o=[r[0]];for(let i=1;i<r.length;i++){const f=o[o.length-1];r[i][t]<f[n]?o.push(r[i]):(o.length>1&&a.push(o),o=[r[i]])}return o.length>1&&a.push(o),a}function kn(e,t=6,n=!1){if(!e||e.length<2)return null;if(n)return So(e);const r=t;let a=`M ${e[0].x},${e[0].y}`;for(let o=1;o<e.length-1;o++){const i=e[o-1],f=e[o],p=e[o+1],d=Math.abs(f.x-i.x)+Math.abs(f.y-i.y),h=Math.abs(p.x-f.x)+Math.abs(p.y-f.y),v=Math.min(r,d/2,h/2);if(v>.5){const E=f.x-i.x,M=f.y-i.y,z=p.x-f.x,I=p.y-f.y,k=Math.sqrt(E*E+M*M)||1,j=Math.sqrt(z*z+I*I)||1;a+=` L ${f.x-E/k*v},${f.y-M/k*v}`,a+=` Q ${f.x},${f.y} ${f.x+z/j*v},${f.y+I/j*v}`}else a+=` L ${f.x},${f.y}`}return a+=` L ${e[e.length-1].x},${e[e.length-1].y}`,a}function So(e){if(e.length===2)return`M ${e[0].x},${e[0].y} L ${e[1].x},${e[1].y}`;if(e.length===3)return`M ${e[0].x},${e[0].y} Q ${e[1].x},${e[1].y} ${e[2].x},${e[2].y}`;const t=.3;let n=`M ${e[0].x},${e[0].y}`;for(let r=0;r<e.length-1;r++){const a=e[r===0?0:r-1],o=e[r],i=e[r+1],f=e[r+2<e.length?r+2:e.length-1],p=o.x+(i.x-a.x)*t,d=o.y+(i.y-a.y)*t,h=i.x-(f.x-o.x)*t,v=i.y-(f.y-o.y)*t;n+=` C ${p},${d} ${h},${v} ${i.x},${i.y}`}return n}function Cn(e){if(!e||e.length<2)return{x:0,y:0};let t=0;for(let r=1;r<e.length;r++)t+=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);let n=t/2;for(let r=1;r<e.length;r++){const a=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);if(n<=a){const o=a>0?n/a:0;return{x:e[r-1].x+(e[r].x-e[r-1].x)*o,y:e[r-1].y+(e[r].y-e[r-1].y)*o}}n-=a}return{x:e[0].x,y:e[0].y}}function No(e,t){if(!e||!t||e.length===0||t.length===0)return t;const n={};for(const o of e)n[o.id]=o;const r=tr(e,null),a=t.map(o=>{var L,Y,F,B;const i=o.type||"default";if(i==="bezier"||i==="simplebezier"||i==="default")return o;const f=n[o.source],p=n[o.target];if(!f||!p||f.hidden||p.hidden)return o;const d=hr(f,"source",o.sourceHandle),h=hr(p,"target",o.targetHandle),v=Rn(d,Mn),E=Rn(h,Mn),M=5,z=r.filter(b=>b.id!==o.source&&b.id!==o.target),I=f._absolutePosition||f.position,k=f.width||((L=f.measured)==null?void 0:L.width)||bn,j=f.height||((Y=f.measured)==null?void 0:Y.height)||wn;z.push({id:o.source,x:I.x-M,y:I.y-M,w:k+2*M,h:j+2*M});const X=p._absolutePosition||p.position,D=p.width||((F=p.measured)==null?void 0:F.width)||bn,_=p.height||((B=p.measured)==null?void 0:B.height)||wn;if(z.push({id:o.target,x:X.x-M,y:X.y-M,w:D+2*M,h:_+2*M}),z.length===0)return o;const A=Lr(v,E,z);return A&&A.length>=2?(A.unshift({x:d.x,y:d.y}),A.push({x:h.x,y:h.y}),{...o,_routedPoints:A}):o});return zo(a)}function Po(e,t,n,r,a,o,i,f){const p=tr(i,f?new Set(f):null);if(p.length===0)return null;const d={x:e,y:t,dir:a||"right"},h={x:n,y:r,dir:o||"left"},v=Rn(d,Mn),E=Rn(h,Mn),M=Lr(v,E,p);return M&&M.length>=2?(M.unshift({x:d.x,y:d.y}),M.push({x:h.x,y:h.y}),M):null}const nr=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,label:i,labelStyle:f,labelShowBg:p,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:v,style:E,markerEnd:M,markerStart:z,interactionWidth:I,routedPoints:k}){let j,X,D;if(k&&k.length>=2){j=kn(k);const _=Cn(k);X=_.x,D=_.y}else[j,X,D]=Jn({sourceX:n,sourceY:r,targetX:a,targetY:o});return P.jsx(sn,{id:t,path:j,labelX:X,labelY:D,label:i,labelStyle:f,labelShowBg:p,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:v,style:E,markerEnd:M,markerStart:z,interactionWidth:I})});nr.displayName="StraightEdge";const rr=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:i="bottom",targetPosition:f="top",label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,pathOptions:j,interactionWidth:X,routedPoints:D}){let _,A,L;if(D&&D.length>=2){_=kn(D);const Y=Cn(D);A=Y.x,L=Y.y}else[_,A,L]=vn({sourceX:n,sourceY:r,sourcePosition:i,targetX:a,targetY:o,targetPosition:f,borderRadius:j==null?void 0:j.borderRadius,offset:j==null?void 0:j.offset});return P.jsx(sn,{id:t,path:_,labelX:A,labelY:L,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,interactionWidth:X})});rr.displayName="SmoothStepEdge";const Tr=c.memo(function({id:t,...n}){var a;const r=c.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(a=n.pathOptions)==null?void 0:a.offset]);return P.jsx(rr,{...n,id:t,pathOptions:r})});Tr.displayName="StepEdge";const or=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:i,targetPosition:f,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,interactionWidth:j,routedPoints:X}){let D,_,A;if(X&&X.length>=2){D=kn(X);const L=Cn(X);_=L.x,A=L.y}else[D,_,A]=er({sourceX:n,sourceY:r,targetX:a,targetY:o});return P.jsx(sn,{id:t,path:D,labelX:_,labelY:A,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:v,labelBgPadding:E,labelBgBorderRadius:M,style:z,markerEnd:I,markerStart:k,interactionWidth:j})});or.displayName="SimpleBezierEdge";const Io={input:zr,output:Sr,group:Nr},Lo={bezier:Vn,straight:nr,simplebezier:or},To=160,$o=60;function Bo(e){let t=!1;for(let n=0;n<e.length;n++){const r=e[n];if(!r.measured||r.measured.width==null||r.measured.height==null){t=!0;break}}return t?e.map(n=>{var r,a;return((r=n.measured)==null?void 0:r.width)!=null&&((a=n.measured)==null?void 0:a.height)!=null?n:{...n,measured:{width:n.width||To,height:n.height||$o}}}):e}function jo({cards:e,nodes:t=[],edges:n=[],nodeTypes:r,edgeTypes:a,dark:o,gridSize:i,width:f="100%",height:p="420px",className:d="",style:h={},zoomMin:v,zoomMax:E,initialCamera:M,fitView:z,fitViewOptions:I,onNodesChange:k,onEdgesChange:j,onConnect:X,onConnectStart:D,onConnectEnd:_,onNodeClick:A,onNodeDoubleClick:L,onNodeMouseEnter:Y,onNodeMouseMove:F,onNodeMouseLeave:B,onNodeContextMenu:b,onNodeDragStart:g,onNodeDrag:x,onNodeDragStop:N,onEdgeClick:$,onEdgeDoubleClick:W,onEdgeMouseEnter:V,onEdgeMouseMove:re,onEdgeMouseLeave:ee,onEdgeContextMenu:oe,onPaneClick:ge,onPaneContextMenu:ye,onPaneMouseEnter:J,onPaneMouseMove:fe,onPaneMouseLeave:me,onSelectionChange:ae,onInit:ue,onMoveStart:Ne,onMove:Je,onMoveEnd:le,onDelete:Be,onBeforeDelete:je,onError:_e,onDragOver:he,onDrop:Me,onDragEnter:Oe,onDragLeave:Ae,nodesDraggable:ct,nodesConnectable:zt,elementsSelectable:De,multiSelectionKeyCode:Xe,selectionOnDrag:Ze,selectionMode:St,connectionMode:an,connectionRadius:At,connectOnClick:cn,isValidConnection:un,defaultEdgeOptions:ln,snapToGrid:dn,snapGrid:Dt,deleteKeyCode:dt,panActivationKeyCode:ft,panOnScroll:Nt,panOnScrollMode:En,panOnScrollSpeed:zn,zoomOnScroll:ot,zoomOnDoubleClick:sr,zoomOnPinch:Sn,preventScrolling:Nn,translateExtent:Pt,nodeExtent:It,autoPanOnNodeDrag:Pn,autoPanOnConnect:In,autoPanSpeed:Ln,edgesReconnectable:ht,elevateNodesOnSelect:pe,elevateEdgesOnSelect:Ht,noDragClassName:Ee,noPanClassName:ie,onSelectionDragStart:gt,onSelectionDrag:K,onSelectionDragStop:Re,edgeRouting:fn=!0,onHudUpdate:ut,onNodesProcessed:Lt,showHud:Tn=!0,showHint:$n=!0,hintText:We="Drag to pan · Scroll to zoom",children:Ye,..._t}){const[He,Wt]=c.useState({wx:0,wy:0,zoom:"1.00"}),Mt=c.useRef(null),Ft=c.useRef(null),Bn=c.useCallback(G=>{Wt(G),ut==null||ut(G)},[ut]),yt=c.useMemo(()=>({...Io,...r}),[r]),xt=c.useMemo(()=>({...Lo,...a}),[a]),tt=c.useMemo(()=>Bo(t),[t]),Ke=c.useMemo(()=>{const G=tt.filter(Ie=>Ie.type&&yt[Ie.type]&&(Ie.selected||Ie.dragging));return G.sort((Ie,ve)=>{const Le=Ie.type==="group"||!Ie.parentId&&G.some(ce=>ce.parentId===Ie.id),at=ve.type==="group"||!ve.parentId&&G.some(ce=>ce.parentId===ve.id);return Le&&!at?-1:!Le&&at?1:0})},[tt,yt]),Tt=c.useMemo(()=>n.filter(G=>G.type&&xt[G.type]),[n,xt]),O=c.useMemo(()=>t.map(G=>G.type&&yt[G.type]&&(G.selected||G.dragging)?{...G,_customRendered:!0}:G),[t,yt]),pt=c.useMemo(()=>n.map(G=>G.type&&xt[G.type]?{...G,_customRendered:!0}:G),[n,xt]),{wrapRef:$t,canvasRef:Xt,canvasReady:Yt,onPointerDown:qt,onPointerMove:Ut,onPointerUp:Ot,store:we}=br({cards:e,nodes:O,edges:pt,dark:o,gridSize:i,zoomMin:v,zoomMax:E,initialCamera:M,fitView:z,fitViewOptions:I,onHudUpdate:Bn,onNodesProcessed:Lt,onNodesChange:k,onEdgesChange:j,onConnect:X,onConnectStart:D,onConnectEnd:_,onNodeClick:A,onNodeDoubleClick:L,onNodeMouseEnter:Y,onNodeMouseMove:F,onNodeMouseLeave:B,onNodeContextMenu:b,onNodeDragStart:g,onNodeDrag:x,onNodeDragStop:N,onEdgeClick:$,onEdgeDoubleClick:W,onEdgeMouseEnter:V,onEdgeMouseMove:re,onEdgeMouseLeave:ee,onEdgeContextMenu:oe,onPaneClick:ge,onPaneContextMenu:ye,onPaneMouseEnter:J,onPaneMouseMove:fe,onPaneMouseLeave:me,onSelectionChange:ae,onInit:ue,onMoveStart:Ne,onMove:Je,onMoveEnd:le,onDelete:Be,onBeforeDelete:je,onError:_e,nodesDraggable:ct,nodesConnectable:zt,elementsSelectable:De,multiSelectionKeyCode:Xe,selectionOnDrag:Ze,selectionMode:St,connectionMode:an,connectionRadius:At,connectOnClick:cn,isValidConnection:un,defaultEdgeOptions:ln,snapToGrid:dn,snapGrid:Dt,deleteKeyCode:dt,panActivationKeyCode:ft,panOnScroll:Nt,panOnScrollMode:En,panOnScrollSpeed:zn,zoomOnScroll:ot,zoomOnDoubleClick:sr,zoomOnPinch:Sn,preventScrolling:Nn,translateExtent:Pt,nodeExtent:It,autoPanOnNodeDrag:Pn,autoPanOnConnect:In,autoPanSpeed:Ln,edgesReconnectable:ht,elevateNodesOnSelect:pe,elevateEdgesOnSelect:Ht,noDragClassName:Ee,noPanClassName:ie,onSelectionDragStart:gt,onSelectionDrag:K,onSelectionDragStop:Re,edgeRouting:fn}),mt=c.useContext(Et),Bt=mt&&typeof mt.getState=="function";c.useEffect(()=>{Bt&&queueMicrotask(()=>{mt.setState({nodes:tt,edges:n,nodesRef:we.nodesRef,edgesRef:we.edgesRef,onNodesChangeRef:we.onNodesChangeRef,onEdgesChangeRef:we.onEdgesChangeRef,cameraRef:we.cameraRef,wrapRef:we.wrapRef,workerRef:we.workerRef})})},[Bt,tt,n,we,mt]);const ze=c.useMemo(()=>({...we,edgeLabelContainerRef:Mt,viewportPortalRef:Ft,get nodes(){return tt},get edges(){return n},get viewport(){return we.cameraRef.current},get minZoom(){return we.zoomMin||.1},get maxZoom(){return we.zoomMax||5},get domNode(){return we.wrapRef.current},get width(){var G;return((G=we.wrapRef.current)==null?void 0:G.clientWidth)||0},get height(){var G;return((G=we.wrapRef.current)==null?void 0:G.clientHeight)||0}}),[we,tt,n]),Zt=c.useRef(null),Pe=c.useRef(null),Gt=c.useRef(null),st=c.useRef(null),Rt=c.useRef(null);c.useEffect(()=>{let G;const Ie=()=>{const ve=we.cameraRef.current,Le=`translate(${ve.x}px, ${ve.y}px) scale(${ve.zoom})`,at=`translate(${ve.x}, ${ve.y}) scale(${ve.zoom})`;Zt.current&&(Zt.current.style.transform=Le),Pe.current&&Pe.current.setAttribute("transform",at),Gt.current&&(Gt.current.style.transform=Le),st.current&&(st.current.style.transform=Le);const ce=$t.current;if(ce){const Ge=ve.zoom<.15?"lod-minimal":ve.zoom<.35?"lod-reduced":null;Ge!==Rt.current&&(ce.classList.remove("lod-minimal","lod-reduced"),Ge&&ce.classList.add(Ge),Rt.current=Ge)}G=requestAnimationFrame(Ie)};return G=requestAnimationFrame(Ie),()=>cancelAnimationFrame(G)},[we]);const[et,vt]=c.useState(null);c.useEffect(()=>{if(!Ke.length)return;let G;const Ie=()=>{var Qt,gn;const ve=we.cameraRef.current,Le=we.wrapRef.current;if(!Le){G=requestAnimationFrame(Ie);return}const at=Le.getBoundingClientRect(),ce=200,Ge=-ve.x/ve.zoom-ce,bt=-ve.y/ve.zoom-ce,jn=(at.width-ve.x)/ve.zoom+ce,An=(at.height-ve.y)/ve.zoom+ce,kt=new Set;for(const qe of Ke){const wt=qe._absolutePosition||qe.position,Dn=qe.width||((Qt=qe.measured)==null?void 0:Qt.width)||200,Hn=qe.height||((gn=qe.measured)==null?void 0:gn.height)||100;wt.x+Dn>=Ge&&wt.x<=jn&&wt.y+Hn>=bt&&wt.y<=An&&kt.add(qe.id)}vt(qe=>{if(!qe||qe.size!==kt.size)return kt;for(const wt of kt)if(!qe.has(wt))return kt;return qe}),G=requestAnimationFrame(Ie)};return G=requestAnimationFrame(Ie),()=>cancelAnimationFrame(G)},[Ke,we]);const hn=c.useMemo(()=>et?Ke.filter(G=>et.has(G.id)):Ke,[Ke,et]),Se=Ke.length>0,nt=Tt.length>0;return P.jsx(Et.Provider,{value:ze,children:P.jsxs("div",{ref:$t,className:`ric-wrap ${d}`,style:{width:f,height:p,...h},onPointerDown:qt,onPointerMove:Ut,onPointerUp:Ot,onDragOver:he,onDrop:Me,onDragEnter:Oe,onDragLeave:Ae,tabIndex:0,children:[P.jsx("canvas",{ref:Xt,className:"ric-canvas"}),!Yt&&P.jsx("div",{className:"ric-loader",children:P.jsx("div",{className:"ric-spinner"})}),nt&&P.jsx("svg",{className:"ric-edges-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:P.jsx("g",{ref:Pe,children:Tt.map(G=>P.jsx(yo,{edge:G,edgeType:xt[G.type],nodes:t,reconnectable:ht},G.id))})}),Se&&P.jsx("div",{ref:Zt,className:"ric-nodes-overlay",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:10},children:hn.map(G=>P.jsx(lo,{node:G,nodeType:yt[G.type]},G.id))}),P.jsx("div",{ref:G=>{Mt.current=G,Gt.current=G},className:"ric-edge-labels",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:5}}),P.jsx("div",{ref:G=>{Ft.current=G,st.current=G},className:"ric-viewport-portal",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:6}}),$n&&P.jsx("div",{className:"ric-hint",children:We}),Tn&&P.jsxs("div",{className:"ric-info",children:["world: (",He.wx,", ",He.wy,") zoom: ",He.zoom,"x",He.nodeCount>0&&P.jsxs(P.Fragment,{children:[" nodes: ",He.nodeCount]}),He.edgeCount>0&&P.jsxs(P.Fragment,{children:[" edges: ",He.edgeCount]})]}),P.jsx(Cr,{selectionKeyCode:Xe||"Shift",selectionMode:St||"partial"}),Ye]})})}function Ao({children:e}){const t=c.useRef(null);return t.current||(t.current=io()),P.jsx(Et.Provider,{value:t.current,children:e})}function $r(e,t){const n=[],r=new Map,a=[];for(const o of e)if(o.type==="add")a.push(o);else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const i=r.get(o.id);i?i.push(o):r.set(o.id,[o])}for(const o of t){const i=r.get(o.id);if(!i){n.push(o);continue}if(i[0].type==="remove")continue;if(i[0].type==="replace"){n.push({...i[0].item});continue}const f={...o};for(const p of i)Do(p,f);n.push(f)}for(const o of a)o.index!==void 0?n.splice(o.index,0,{...o.item}):n.push({...o.item});return n}function Do(e,t){switch(e.type){case"select":t.selected=e.selected;break;case"position":e.position!==void 0&&(t.position=e.position),e.dragging!==void 0&&(t.dragging=e.dragging);break;case"dimensions":e.dimensions!==void 0&&(t.measured={...e.dimensions},(e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height)),e.handleBounds!==void 0&&(t.handleBounds=e.handleBounds);break}}function Br(e,t){return $r(e,t)}function jr(e,t){return $r(e,t)}function Ho(e,t){return!e.source||!e.target?(console.warn("addEdge: source and target are required"),t):t.some(r=>r.source===e.source&&r.target===e.target&&(r.sourceHandle||null)===(e.sourceHandle||null)&&(r.targetHandle||null)===(e.targetHandle||null))?t:[...t,{id:e.id||`e-${e.source}-${e.target}`,...e}]}function _o(e){const[t,n]=c.useState(e),r=c.useCallback(a=>n(o=>Br(a,o)),[]);return[t,n,r]}function Wo(e){const[t,n]=c.useState(e),r=c.useCallback(a=>n(o=>jr(a,o)),[]);return[t,n,r]}function Ar(){const e=wr(),t=c.useCallback(()=>typeof e.getState=="function"?e.getState():e,[e]),n=c.useCallback(()=>[...t().nodesRef.current],[t]),r=c.useCallback(()=>[...t().edgesRef.current],[t]),a=c.useCallback(b=>t().nodesRef.current.find(g=>g.id===b),[t]),o=c.useCallback(b=>t().edgesRef.current.find(g=>g.id===b),[t]),i=c.useCallback(b=>{var g,x,N,$;if(typeof b=="function"){const W=b(t().nodesRef.current);(x=(g=t().onNodesChangeRef).current)==null||x.call(g,[...t().nodesRef.current.map(V=>({id:V.id,type:"remove"})),...W.map(V=>({type:"add",item:V}))])}else($=(N=t().onNodesChangeRef).current)==null||$.call(N,[...t().nodesRef.current.map(W=>({id:W.id,type:"remove"})),...b.map(W=>({type:"add",item:W}))])},[t]),f=c.useCallback(b=>{var g,x,N,$;if(typeof b=="function"){const W=b(t().edgesRef.current);(x=(g=t().onEdgesChangeRef).current)==null||x.call(g,[...t().edgesRef.current.map(V=>({id:V.id,type:"remove"})),...W.map(V=>({type:"add",item:V}))])}else($=(N=t().onEdgesChangeRef).current)==null||$.call(N,[...t().edgesRef.current.map(W=>({id:W.id,type:"remove"})),...b.map(W=>({type:"add",item:W}))])},[t]),p=c.useCallback(b=>{var x,N;const g=Array.isArray(b)?b:[b];(N=(x=t().onNodesChangeRef).current)==null||N.call(x,g.map($=>({type:"add",item:$})))},[t]),d=c.useCallback(b=>{var x,N;const g=Array.isArray(b)?b:[b];(N=(x=t().onEdgesChangeRef).current)==null||N.call(x,g.map($=>({type:"add",item:$})))},[t]),h=c.useCallback(({nodes:b=[],edges:g=[]})=>{if(b.length&&t().onNodesChangeRef.current){t().onNodesChangeRef.current(b.map(N=>({id:N.id,type:"remove"})));const x=mr(b,t().edgesRef.current);x.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(x.map(N=>({id:N.id,type:"remove"})))}g.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(g.map(x=>({id:x.id,type:"remove"})))},[t]),v=c.useCallback(()=>{const b=t().cameraRef.current;return{x:b.x,y:b.y,zoom:b.zoom}},[t]),E=c.useRef(null),M=c.useCallback((b,g)=>{if(E.current&&cancelAnimationFrame(E.current),!g||g<=0){t().cameraRef.current={...b},t().sendCamera();return}const x={...t().cameraRef.current},N=performance.now(),$=W=>{const V=W-N,re=Math.min(V/g,1),ee=1-Math.pow(1-re,3);t().cameraRef.current={x:x.x+(b.x-x.x)*ee,y:x.y+(b.y-x.y)*ee,zoom:x.zoom+(b.zoom-x.zoom)*ee},t().sendCamera(),re<1&&(E.current=requestAnimationFrame($))};E.current=requestAnimationFrame($)},[t]),z=c.useCallback((b,g)=>{const x={x:b.x??t().cameraRef.current.x,y:b.y??t().cameraRef.current.y,zoom:b.zoom??t().cameraRef.current.zoom};M(x,g==null?void 0:g.duration)},[t,M]),I=c.useCallback(()=>t().cameraRef.current.zoom,[t]),k=c.useCallback(b=>{const g=t().cameraRef.current,x=t().wrapRef.current;if(!x)return;const N=x.getBoundingClientRect(),$=N.width/2,W=N.height/2,V=1.2,re={x:$-($-g.x)*V,y:W-(W-g.y)*V,zoom:Math.min(t().zoomMax,g.zoom*V)};M(re,b==null?void 0:b.duration)},[t,M]),j=c.useCallback(b=>{const g=t().cameraRef.current,x=t().wrapRef.current;if(!x)return;const N=x.getBoundingClientRect(),$=N.width/2,W=N.height/2,V=1/1.2,re={x:$-($-g.x)*V,y:W-(W-g.y)*V,zoom:Math.max(t().zoomMin,g.zoom*V)};M(re,b==null?void 0:b.duration)},[t,M]),X=c.useCallback((b,g)=>{const x=t().cameraRef.current,N=t().wrapRef.current;if(!N)return;const $=N.getBoundingClientRect(),W=$.width/2,V=$.height/2,re=Math.min(t().zoomMax,Math.max(t().zoomMin,b)),ee=re/x.zoom,oe={x:W-(W-x.x)*ee,y:V-(V-x.y)*ee,zoom:re};M(oe,g==null?void 0:g.duration)},[t,M]),D=c.useCallback((b={})=>{const g=t().nodesRef.current;if(!g.length)return;const x=t().wrapRef.current;if(!x)return;const N=x.getBoundingClientRect(),$=b.padding??.1,W=b.nodes?g.filter(ee=>b.nodes.some(oe=>oe.id===ee.id)):g;if(!W.length)return;const V=mn(W),re=jt(V,N.width,N.height,$);b.maxZoom&&(re.zoom=Math.min(re.zoom,b.maxZoom)),b.minZoom&&(re.zoom=Math.max(re.zoom,b.minZoom)),M(re,b.duration)},[t,M]),_=c.useCallback((b,g={})=>{const x=t().wrapRef.current;if(!x)return;const N=x.getBoundingClientRect(),$=g.padding??.1,W=jt(b,N.width,N.height,$);g.maxZoom&&(W.zoom=Math.min(W.zoom,g.maxZoom)),g.minZoom&&(W.zoom=Math.max(W.zoom,g.minZoom)),M(W,g.duration)},[t,M]),A=c.useCallback((b,g,x={})=>{const N=t().wrapRef.current;if(!N)return;const $=N.getBoundingClientRect(),W=x.zoom??t().cameraRef.current.zoom,V={x:$.width/2-b*W,y:$.height/2-g*W,zoom:W};M(V,x.duration)},[t,M]),L=c.useCallback(()=>({nodes:[...t().nodesRef.current],edges:[...t().edgesRef.current],viewport:{...t().cameraRef.current}}),[t]),Y=c.useCallback(b=>t().screenToWorld(b.x,b.y),[t]),F=c.useCallback(b=>{const g=t().cameraRef.current,x=t().wrapRef.current;if(!x)return{x:0,y:0};const N=x.getBoundingClientRect();return{x:b.x*g.zoom+g.x+N.left,y:b.y*g.zoom+g.y+N.top}},[t]),B=c.useCallback((b,g)=>{var $,W;const x=t().nodesRef.current.find(V=>V.id===b);if(!x)return;const N=typeof g=="function"?g(x.data):{...x.data,...g};(W=($=t().onNodesChangeRef).current)==null||W.call($,[{id:b,type:"replace",item:{...x,data:N}}])},[t]);return{getNodes:n,getEdges:r,getNode:a,getEdge:o,setNodes:i,setEdges:f,addNodes:p,addEdges:d,deleteElements:h,getViewport:v,setViewport:z,getZoom:I,zoomIn:k,zoomOut:j,zoomTo:X,fitView:D,fitBounds:_,setCenter:A,screenToFlowPosition:Y,flowToScreenPosition:F,updateNodeData:B,toObject:L}}function Fo(){return Ce().nodes}function Xo(){return Ce().edges}function Yo(){return Ce().viewport}function qo(){return Ce().connection}function Uo(e){const t=Ce(),n=Array.isArray(e)?e:[e];return c.useMemo(()=>n.map(r=>{const a=t.nodes.find(o=>o.id===r);return a?{id:a.id,type:a.type,data:a.data}:null}).filter(Boolean),[t.nodes,...n])}function Oo(e){const t=Ce();return c.useMemo(()=>t.edges.filter(n=>n.source===e||n.target===e),[t.edges,e])}function Zo({nodeId:e,type:t,handleId:n}){const r=Ce();return c.useMemo(()=>r.edges.filter(a=>t==="source"?a.source===e&&(n?a.sourceHandle===n:!0):a.target===e&&(n?a.targetHandle===n:!0)),[r.edges,e,t,n])}function Go({onChange:e,onStart:t,onEnd:n}){const r=Ce(),a=c.useRef(e),o=c.useRef(t),i=c.useRef(n);c.useEffect(()=>{a.current=e},[e]),c.useEffect(()=>{o.current=t},[t]),c.useEffect(()=>{i.current=n},[n]),c.useEffect(()=>{const f=p=>{var d;(d=a.current)==null||d.call(a,{x:p.x,y:p.y,zoom:p.zoom})};return r.viewportListeners.add(f),()=>r.viewportListeners.delete(f)},[s])}function Qo({onChange:e}){const t=Ce(),n=c.useRef(e);c.useEffect(()=>{n.current=e},[e]),c.useEffect(()=>{const r=a=>{var o;(o=n.current)==null||o.call(n,a)};return t.selectionListeners.add(r),()=>t.selectionListeners.delete(r)},[s])}function Vo(e){const[t,n]=c.useState(!1),r=Array.isArray(e)?e:[e];return c.useEffect(()=>{const a=i=>{r.includes(i.key)&&n(!0)},o=i=>{r.includes(i.key)&&n(!1)};return window.addEventListener("keydown",a),window.addEventListener("keyup",o),()=>{window.removeEventListener("keydown",a),window.removeEventListener("keyup",o)}},[r.join(",")]),t}function Jo(){const e=Ce();return c.useCallback(t=>{var n;(n=e.workerRef.current)==null||n.postMessage({type:"nodes",data:{nodes:[...s().nodesRef.current]}})},[s])}const Ko=e=>{var t;return((t=e.nodes)==null?void 0:t.length)>0};function es(e={}){return Ce(Ko)}function ts(e){const t=Ce();return c.useMemo(()=>t.nodes.find(n=>n.id===e)||void 0,[t.nodes,e])}function ns(e,t){return Ce(e,t)}function rs(){return wr()}function os({maxHistorySize:e=100}={}){const t=Ce(),n=c.useRef([]),r=c.useRef([]),[,a]=c.useState(0),o=c.useRef(null),i=c.useCallback(()=>{const d={nodes:s().nodesRef.current.map(h=>({...h,data:{...h.data}})),edges:s().edgesRef.current.map(h=>({...h}))};o.current&&JSON.stringify(o.current.nodes.map(h=>h.id))===JSON.stringify(d.nodes.map(h=>h.id))&&JSON.stringify(o.current.edges.map(h=>h.id))===JSON.stringify(d.edges.map(h=>h.id))||(n.current.push(d),n.current.length>e&&n.current.shift(),r.current=[],o.current=d,a(h=>h+1))},[t,e]),f=c.useCallback(()=>{var h,v,E,M;const d=n.current.pop();d&&(r.current.push({nodes:s().nodesRef.current.map(z=>({...z,data:{...z.data}})),edges:s().edgesRef.current.map(z=>({...z}))}),(v=(h=s().onNodesChangeRef).current)==null||v.call(h,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...d.nodes.map(z=>({type:"add",item:z}))]),(M=(E=s().onEdgesChangeRef).current)==null||M.call(E,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...d.edges.map(z=>({type:"add",item:z}))]),o.current=d,a(z=>z+1))},[s]),p=c.useCallback(()=>{var h,v,E,M;const d=r.current.pop();d&&(n.current.push({nodes:s().nodesRef.current.map(z=>({...z,data:{...z.data}})),edges:s().edgesRef.current.map(z=>({...z}))}),(v=(h=s().onNodesChangeRef).current)==null||v.call(h,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...d.nodes.map(z=>({type:"add",item:z}))]),(M=(E=s().onEdgesChangeRef).current)==null||M.call(E,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...d.edges.map(z=>({type:"add",item:z}))]),o.current=d,a(z=>z+1))},[s]);return{undo:f,redo:p,takeSnapshot:i,canUndo:n.current.length>0,canRedo:r.current.length>0}}function ss(e){const t=c.useRef(e);return c.useEffect(()=>{t.current=e},[e]),c.useCallback(n=>r=>{const a=t.current(r);a!==!1&&a!=null&&n(Array.isArray(a)?a:r)},[])}function as(e){const t=c.useRef(e);return c.useEffect(()=>{t.current=e},[e]),c.useCallback(n=>r=>{const a=t.current(r);a!==!1&&a!=null&&n(Array.isArray(a)?a:r)},[])}const Xn=160,Yn=60;function is({width:e=200,height:t=150,nodeColor:n="#3b82f6",nodeStrokeColor:r="#fff",maskColor:a="rgba(0,0,0,0.1)",style:o={},className:i=""}){const f=Ce(),p=c.useRef(null),d=c.useRef(null),h=c.useCallback(()=>{const v=p.current;if(!v)return;const E=v.getContext("2d"),M=window.devicePixelRatio||1;v.width=e*M,v.height=t*M,E.scale(M,M),E.clearRect(0,0,e,t);const z=f.nodesRef.current;if(!z.length)return;let I=1/0,k=1/0,j=-1/0,X=-1/0;for(const g of z){const x=g.width||Xn,N=g.height||Yn;g.position.x<I&&(I=g.position.x),g.position.y<k&&(k=g.position.y),g.position.x+x>j&&(j=g.position.x+x),g.position.y+N>X&&(X=g.position.y+N)}const D=40;I-=D,k-=D,j+=D,X+=D;const _=j-I,A=X-k,L=Math.min(e/_,t/A),Y=(e-_*L)/2,F=(t-A*L)/2;for(const g of z){if(g.hidden)continue;const x=g.width||Xn,N=g.height||Yn,$=(g.position.x-I)*L+Y,W=(g.position.y-k)*L+F,V=x*L,re=N*L;E.fillStyle=g.selected?"#f59e0b":typeof n=="function"?n(g):n,E.fillRect($,W,Math.max(V,2),Math.max(re,2))}const B=f.cameraRef.current,b=f.wrapRef.current;if(b){const g=b.getBoundingClientRect(),x=-B.x/B.zoom,N=-B.y/B.zoom,$=g.width/B.zoom,W=g.height/B.zoom;E.fillStyle=a,E.fillRect(0,0,e,t);const V=(x-I)*L+Y,re=(N-k)*L+F,ee=$*L,oe=W*L;E.clearRect(V,re,ee,oe);for(const ge of z){if(ge.hidden)continue;const ye=ge.width||Xn,J=ge.height||Yn,fe=(ge.position.x-I)*L+Y,me=(ge.position.y-k)*L+F;E.fillStyle=ge.selected?"#f59e0b":typeof n=="function"?n(ge):n,E.fillRect(fe,me,Math.max(ye*L,2),Math.max(J*L,2))}E.strokeStyle="#3b82f6",E.lineWidth=1.5,E.strokeRect(V,re,ee,oe)}},[f,e,t,n,r,a]);return c.useEffect(()=>{let v=!0;function E(){v&&(h(),d.current=requestAnimationFrame(E))}const M=setInterval(()=>{cancelAnimationFrame(d.current),d.current=requestAnimationFrame(E)},66);return h(),()=>{v=!1,clearInterval(M),cancelAnimationFrame(d.current)}},[h]),P.jsx("canvas",{ref:p,className:`ric-minimap ${i}`,style:{position:"absolute",bottom:30,right:10,width:e,height:t,borderRadius:4,border:"1px solid rgba(0,0,0,0.1)",background:"rgba(255,255,255,0.9)",pointerEvents:"none",...o}})}function cs(){return P.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[P.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),P.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function us(){return P.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:P.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function ls(){return P.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:P.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}function ds(){return P.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[P.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),P.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function fs(){return P.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[P.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),P.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})}function nn({children:e,className:t="",...n}){return P.jsx("button",{className:`ric-controls-button ${t}`,style:gs,...n,children:e})}function hs({showZoom:e=!0,showFitView:t=!0,showInteractive:n=!1,fitViewOptions:r,onZoomIn:a,onZoomOut:o,onFitView:i,onInteractiveChange:f,position:p="bottom-left",orientation:d="vertical",style:h={},className:v="","aria-label":E="Canvas controls",children:M}){const z=Ce(),{zoomIn:I,zoomOut:k,fitView:j,getZoom:X}=Ar(),[D,_]=c.useState(!0),A=X()<=z.zoomMin,L=X()>=z.zoomMax,Y=c.useCallback(()=>{I(),a==null||a()},[I,a]),F=c.useCallback(()=>{k(),o==null||o()},[k,o]),B=c.useCallback(()=>{j(r||{padding:.1}),i==null||i()},[j,r,i]),b=c.useCallback(()=>{const x=!D;_(x),f==null||f(x)},[D,f]),g={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:30,left:10},"bottom-right":{bottom:30,right:10},"bottom-center":{bottom:30,left:"50%",transform:"translateX(-50%)"}}[p]||{bottom:30,left:10};return P.jsxs("div",{className:`ric-controls ${v}`,style:{position:"absolute",display:"flex",flexDirection:d==="horizontal"?"row":"column",gap:2,zIndex:5,...g,...h},role:"toolbar","aria-label":E,children:[e&&P.jsxs(P.Fragment,{children:[P.jsx(nn,{onClick:Y,disabled:L,title:"Zoom in","aria-label":"Zoom in",className:"ric-controls-zoomin",children:P.jsx(cs,{})}),P.jsx(nn,{onClick:F,disabled:A,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:P.jsx(us,{})})]}),t&&P.jsx(nn,{onClick:B,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:P.jsx(ls,{})}),n&&P.jsx(nn,{onClick:b,title:D?"Lock interactivity":"Unlock interactivity","aria-label":D?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:D?P.jsx(fs,{}):P.jsx(ds,{})}),M]})}const gs={width:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid rgba(0,0,0,0.12)",borderRadius:4,background:"#fff",cursor:"pointer",fontSize:16,lineHeight:1,color:"#333",padding:0},ys=c.memo(hs);function xs({variant:e="lines",gap:t=40,size:n=1,color:r,style:a={},className:o=""}){const i=Ce();return i.workerRef.current&&i.workerRef.current.postMessage({type:"background",data:{variant:e,gap:t,size:n,color:r}}),null}function ps({position:e="top-left",style:t={},className:n="",children:r}){const a={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:10,left:10},"bottom-right":{bottom:10,right:10},"bottom-center":{bottom:10,left:"50%",transform:"translateX(-50%)"}}[e]||{top:10,left:10};return P.jsx("div",{className:`ric-panel ${n}`,style:{position:"absolute",zIndex:5,pointerEvents:"all",...a,...t},onPointerDown:o=>o.stopPropagation(),children:r})}function ms({minWidth:e=10,minHeight:t=10,maxWidth:n=1/0,maxHeight:r=1/0,isVisible:a=!0,handleStyle:o={},lineStyle:i={},color:f="#3b82f6",onResizeStart:p,onResize:d,onResizeEnd:h}){const v=c.useContext(on),E=Ce(),M=c.useRef(null),z=c.useCallback((j,X)=>{j.stopPropagation(),j.preventDefault();const D=E.nodesRef.current.find(L=>L.id===v);if(!D)return;M.current={direction:X,startX:j.clientX,startY:j.clientY,width:D.width||160,height:D.height||60},p==null||p(j,{width:M.current.width,height:M.current.height});const _=L=>{var N,$;if(!M.current)return;const Y=M.current,F=E.cameraRef.current,B=(L.clientX-Y.startX)/F.zoom,b=(L.clientY-Y.startY)/F.zoom;let g=Y.width,x=Y.height;Y.direction.includes("e")&&(g=Math.min(n,Math.max(e,Y.width+B))),Y.direction.includes("w")&&(g=Math.min(n,Math.max(e,Y.width-B))),Y.direction.includes("s")&&(x=Math.min(r,Math.max(t,Y.height+b))),Y.direction.includes("n")&&(x=Math.min(r,Math.max(t,Y.height-b))),($=(N=E.onNodesChangeRef).current)==null||$.call(N,[{id:v,type:"dimensions",dimensions:{width:g,height:x},setAttributes:!0}]),d==null||d(L,{width:g,height:x})},A=L=>{M.current=null,h==null||h(L,{}),window.removeEventListener("pointermove",_),window.removeEventListener("pointerup",A)};window.addEventListener("pointermove",_),window.addEventListener("pointerup",A)},[v,E,e,t,n,r,p,d,h]);if(!a)return null;const I=8,k={position:"absolute",width:I,height:I,background:f,border:"1px solid #fff",borderRadius:2,zIndex:20,...o};return P.jsxs(P.Fragment,{children:[P.jsx("div",{style:{...k,bottom:-I/2,right:-I/2,cursor:"nwse-resize"},onPointerDown:j=>z(j,"se")}),P.jsx("div",{style:{...k,bottom:-I/2,left:-I/2,cursor:"nesw-resize"},onPointerDown:j=>z(j,"sw")}),P.jsx("div",{style:{...k,top:-I/2,right:-I/2,cursor:"nesw-resize"},onPointerDown:j=>z(j,"ne")}),P.jsx("div",{style:{...k,top:-I/2,left:-I/2,cursor:"nwse-resize"},onPointerDown:j=>z(j,"nw")}),P.jsx("div",{style:{...k,top:"50%",right:-I/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:j=>z(j,"e")}),P.jsx("div",{style:{...k,top:"50%",left:-I/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:j=>z(j,"w")}),P.jsx("div",{style:{...k,left:"50%",top:-I/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:j=>z(j,"n")}),P.jsx("div",{style:{...k,left:"50%",bottom:-I/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:j=>z(j,"s")})]})}function vs({isVisible:e,position:t="top",offset:n=10,align:r="center",children:a,style:o={},className:i=""}){const f=c.useContext(on),d=Ce().nodes.find(E=>E.id===f);if(!(e!==void 0?e:d==null?void 0:d.selected))return null;const v={top:{bottom:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginBottom:n},bottom:{top:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginTop:n},left:{right:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginRight:n},right:{left:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginLeft:n}}[t]||{};return P.jsx("div",{className:`ric-node-toolbar ${i}`,style:{position:"absolute",zIndex:1e3,pointerEvents:"all",...v,...o},onPointerDown:E=>E.stopPropagation(),children:a})}function bs({isVisible:e=!1,x:t=0,y:n=0,alignX:r="center",alignY:a="center",children:o,style:i={},className:f=""}){if(!e)return null;const p=r==="center"?"-50%":r==="right"?"-100%":"0",d=a==="center"?"-50%":a==="bottom"?"-100%":"0";return P.jsx("div",{className:`ric-edge-toolbar ${f}`,style:{position:"absolute",left:t,top:n,transform:`translate(${p}, ${d})`,zIndex:1e3,pointerEvents:"all",...i},children:o})}function ws({children:e}){var r;const n=(r=Ce().edgeLabelContainerRef)==null?void 0:r.current;return n?yr.createPortal(e,n):null}function Ms({children:e}){var r;const n=(r=Ce().viewportPortalRef)==null?void 0:r.current;return n?yr.createPortal(e,n):null}function Dr({fromX:e,fromY:t,toX:n,toY:r,fromPosition:a="right",toPosition:o="left",connectionLineType:i="default",connectionLineStyle:f,connectionLineComponent:p}){if(p)return P.jsx(p,{fromX:e,fromY:t,toX:n,toY:r,fromPosition:a,toPosition:o});let d;switch(i){case"straight":[d]=Jn({sourceX:e,sourceY:t,targetX:n,targetY:r});break;case"step":[d]=vn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o,borderRadius:0});break;case"smoothstep":[d]=vn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o});break;case"simplebezier":[d]=er({sourceX:e,sourceY:t,targetX:n,targetY:r});break;default:[d]=Kn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o});break}return P.jsx("path",{d,fill:"none",className:"ric-connection-line",stroke:"#b1b1b7",strokeWidth:1.5,style:f})}Dr.displayName="ConnectionLine";const Rs=c.memo(Dr),ks=Object.freeze({Top:"top",Bottom:"bottom",Left:"left",Right:"right"}),Cs=Object.freeze({Arrow:"arrow",ArrowClosed:"arrowclosed"});function Es(e){const t=e.width||e.measured&&e.measured.width||0,n=e.height||e.measured&&e.measured.height||0,r=e._absolutePosition||e.position||{x:0,y:0};return{x:r.x,y:r.y,x2:r.x+t,y2:r.y+n}}exports.Background=xs;exports.BaseEdge=sn;exports.BezierEdge=Vn;exports.ConnectionLine=Rs;exports.ControlButton=nn;exports.Controls=ys;exports.DefaultNode=vo;exports.EdgeLabelRenderer=ws;exports.EdgeText=Ir;exports.EdgeToolbar=bs;exports.GroupNode=Nr;exports.Handle=rn;exports.InfiniteCanvas=jo;exports.InfiniteCanvasProvider=Ao;exports.InputNode=zr;exports.MarkerType=Cs;exports.MiniMap=is;exports.NodeResizer=ms;exports.NodeToolbar=vs;exports.OutputNode=Sr;exports.Panel=ps;exports.Position=ks;exports.SelectionBox=Cr;exports.SimpleBezierEdge=or;exports.SmoothStepEdge=rr;exports.StepEdge=Tr;exports.StraightEdge=nr;exports.ViewportPortal=Ms;exports.addEdge=Ho;exports.applyEdgeChanges=jr;exports.applyNodeChanges=Br;exports.boxToRect=Qr;exports.buildObstacles=tr;exports.clampPosition=Un;exports.computeRoutedEdges=No;exports.getBezierEdgeCenter=bo;exports.getBezierPath=Kn;exports.getBoundsOfBoxes=Vr;exports.getConnectedEdges=mr;exports.getEdgeCenter=wo;exports.getIncomers=Ur;exports.getNodeDimensions=Qn;exports.getNodesBounds=mn;exports.getNodesInside=Zr;exports.getOutgoers=Or;exports.getOverlappingArea=Jr;exports.getRoutedLabelPosition=Cn;exports.getSimpleBezierPath=er;exports.getSmoothStepPath=vn;exports.getStraightPath=Jn;exports.getViewportForBounds=jt;exports.isEdge=qr;exports.isNode=Yr;exports.nodeToBox=Es;exports.nodeToRect=Kr;exports.reconnectEdge=Mo;exports.rectToBox=Gr;exports.routeSinglePath=Po;exports.routedPointsToPath=kn;exports.snapPosition=qn;exports.useConnection=qo;exports.useEdges=Xo;exports.useEdgesState=Wo;exports.useHandleConnections=Zo;exports.useInfiniteCanvas=br;exports.useInternalNode=ts;exports.useKeyPress=Vo;exports.useNodeConnections=Oo;exports.useNodeId=co;exports.useNodes=Fo;exports.useNodesData=Uo;exports.useNodesInitialized=es;exports.useNodesState=_o;exports.useOnEdgesChangeMiddleware=as;exports.useOnNodesChangeMiddleware=ss;exports.useOnSelectionChange=Qo;exports.useOnViewportChange=Go;exports.useReactFlow=Ar;exports.useStore=ns;exports.useStoreApi=rs;exports.useUndoRedo=os;exports.useUpdateNodeInternals=Jo;exports.useViewport=Yo;
|
|
930
|
+
`,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 a={worker:r};return Xn.set(e,a),a}const ht=160,st=60,no=10;function Mr({cards:e=[],nodes:t=[],edges:n=[],onHudUpdate:r,onNodesProcessed:a,onNodesChange:o,onEdgesChange:c,onConnect:f,onNodeClick:m,onNodeDragStart:d,onNodeDrag:g,onNodeDragStop:b,onEdgeClick:E,onEdgeDoubleClick:C,onEdgeMouseEnter:S,onEdgeMouseMove:j,onEdgeMouseLeave:L,onEdgeContextMenu:A,onNodeDoubleClick:Y,onNodeMouseEnter:D,onNodeMouseMove:F,onNodeMouseLeave:$,onNodeContextMenu:N,onPaneClick:O,onPaneContextMenu:X,onPaneMouseEnter:H,onPaneMouseMove:w,onPaneMouseLeave:y,onSelectionChange:v,onConnectStart:z,onConnectEnd:P,onInit:B,onMoveStart:G,onMove:ne,onMoveEnd:ee,onDelete:se,onBeforeDelete:he,onError:ge,isValidConnection:de,dark:Re,gridSize:We=40,zoomMin:V=.1,zoomMax:oe=4,initialCamera:xe={x:0,y:0,zoom:1},fitView:Ze=!1,fitViewOptions:fe,nodesDraggable:je=!0,nodesConnectable:Ae=!0,elementsSelectable:Pe=!0,multiSelectionKeyCode:Ce="Shift",selectionOnDrag:rt=!1,selectionMode:at="partial",connectionMode:be="loose",connectionRadius:Ie=20,connectOnClick:Je=!1,snapToGrid:$e=!1,snapGrid:Ye=[15,15],deleteKeyCode:Ge=["Delete","Backspace"],panActivationKeyCode:Nt=" ",panOnScroll:cn=!1,panOnScrollMode:Pt="free",panOnScrollSpeed:ln=.5,zoomOnScroll:un=!0,zoomOnDoubleClick:dn=!0,zoomOnPinch:fn=!0,preventScrolling:Gt=!0,translateExtent:xt,nodeExtent:pt,defaultEdgeOptions:It={},autoPanOnNodeDrag:In=!0,autoPanOnConnect:Tn=!0,autoPanSpeed:it=5,edgesReconnectable:cr=!1,elevateNodesOnSelect:Ln=!1,elevateEdgesOnSelect:Bn=!1,noDragClassName:Tt="nodrag",noPanClassName:Lt="nopan",onSelectionDragStart:$n,onSelectionDrag:jn,onSelectionDragStop:An,edgeRouting:Ct=!0}={}){const pe=l.useRef(null),Bt=l.useRef(null),Te=l.useRef(null),ce=l.useRef({...xe}),mt=l.useRef([...e]),K=l.useRef([...t]),Ee=l.useRef([...n]),hn=l.useRef(new Map),$t=l.useRef(!1),jt=l.useRef(null),[At,Dn]=l.useState(!1),Xe=l.useRef(null),Ue=l.useRef(null),Dt=l.useRef(null),ct=l.useRef(null),gn=l.useRef(!1),Ke=l.useRef(null),[yn,xn]=l.useState({x:xe.x,y:xe.y,zoom:xe.zoom}),[Qt,pn]=l.useState(null),vt=l.useMemo(()=>new Set,[]),lt=l.useMemo(()=>new Set,[]),et=l.useRef(!1),Z=l.useRef({});Z.current={onHudUpdate:r,onNodesProcessed:a,onNodesChange:o,onEdgesChange:c,onConnect:f,onNodeClick:m,onNodeDragStart:d,onNodeDrag:g,onNodeDragStop:b,onEdgeClick:E,onEdgeDoubleClick:C,onEdgeMouseEnter:S,onEdgeMouseMove:j,onEdgeMouseLeave:L,onEdgeContextMenu:A,onNodeDoubleClick:Y,onNodeMouseEnter:D,onNodeMouseMove:F,onNodeMouseLeave:$,onNodeContextMenu:N,onPaneClick:O,onPaneContextMenu:X,onPaneMouseEnter:H,onPaneMouseMove:w,onPaneMouseLeave:y,onSelectionChange:v,onConnectStart:z,onConnectEnd:P,onInit:B,onMoveStart:G,onMove:ne,onMoveEnd:ee,onDelete:se,onBeforeDelete:he,onError:ge,onSelectionDragStart:$n,onSelectionDrag:jn,onSelectionDragStop:An,isValidConnection:de};const ut={get current(){return Z.current.onConnect}},Ht={get current(){return Z.current.onNodeClick}},_t={get current(){return Z.current.onNodeDragStart}},Wt={get current(){return Z.current.onNodeDrag}},Ft={get current(){return Z.current.onNodeDragStop}},Et={get current(){return Z.current.onEdgeClick}},bt={get current(){return Z.current.onPaneClick}},ot={get current(){return Z.current.onSelectionChange}},Yt={get current(){return Z.current.onHudUpdate}},Vt={get current(){return Z.current.onNodesProcessed}};l.useEffect(()=>{const u=i=>{i.key===Ce&&(gn.current=!0),i.key===Nt&&(et.current=!0)},x=i=>{i.key===Ce&&(gn.current=!1),i.key===Nt&&(et.current=!1)};return window.addEventListener("keydown",u),window.addEventListener("keyup",x),()=>{window.removeEventListener("keydown",u),window.removeEventListener("keyup",x)}},[Ce,Nt]);const Le={get current(){return Z.current.onNodesChange?mn:null}},mn=u=>{var i,h,M;(h=(i=Z.current).onNodesChange)==null||h.call(i,u);const x=[];for(let k=0;k<u.length;k++)u[k].type==="select"&&x.push({id:u[k].id,selected:u[k].selected});x.length>0&&((M=Te.current)==null||M.postMessage({type:"nodeSelections",data:{selections:x}}))},Fe={get current(){return Z.current.onEdgesChange?Hn:null}},Hn=u=>{var i,h,M;(h=(i=Z.current).onEdgesChange)==null||h.call(i,u);const x=[];for(let k=0;k<u.length;k++)u[k].type==="select"&&x.push({id:u[k].id,selected:u[k].selected});x.length>0&&((M=Te.current)==null||M.postMessage({type:"edgeSelections",data:{selections:x}}))},wt=l.useCallback(()=>{var h;const u=K.current.filter(M=>M.selected),x=Ee.current.filter(M=>M.selected),i={nodes:u,edges:x};(h=ot.current)==null||h.call(ot,i);for(const M of lt)M(i)},[lt]);l.useEffect(()=>{var u;mt.current=[...e],(u=Te.current)==null||u.postMessage({type:"cards",data:{cards:[...e]}})},[e]);const Xt=l.useCallback(u=>{const x={};for(const i of u)x[i.id]=i;return u.map(i=>{if(!i.parentId)return i;const h=x[i.parentId];if(!h)return i;let M=i.position.x,k=i.position.y,p=h;for(;p;)M+=p.position.x,k+=p.position.y,p=p.parentId?x[p.parentId]:null;return{...i,_absolutePosition:{x:M,y:k}}})},[]),dt=l.useRef([]),le=l.useCallback(u=>{const x=hn.current;if(!x||x.size===0)return u;const i={};for(const[,h]of x)i[h.nodeId]||(i[h.nodeId]=[]),i[h.nodeId].push({id:h.id,type:h.type,position:h.position,x:h.x,y:h.y});return u.map(h=>{const M=i[h.id];return M&&M.length>0?{...h,handles:M}:h})},[]),Ot=l.useCallback(()=>{var x;if(Xe.current)return;const u=le(dt.current);(x=Te.current)==null||x.postMessage({type:"nodes",data:{nodes:u}})},[le]);l.useEffect(()=>{var i,h;if(Xe.current){const M=Xe.current.id,k=new Set([M,...Xe.current.selectedStarts.map(R=>R.id)]),p={};for(const R of K.current)k.has(R.id)&&(p[R.id]={...R.position});K.current=[...t];for(const R of K.current)p[R.id]&&(R.position=p[R.id]);dt.current=Xt(K.current);const I=le(dt.current);(i=Te.current)==null||i.postMessage({type:"nodes",data:{nodes:I}});return}K.current=[...t];const u=Xt(t);dt.current=u;const x=le(u);(h=Te.current)==null||h.postMessage({type:"nodes",data:{nodes:x}})},[t,Xt,le]),l.useEffect(()=>{var u;Ee.current=[...n],(u=Te.current)==null||u.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const ke=l.useCallback((u,x)=>{const i=pe.current;if(!i)return{x:0,y:0};const h=i.getBoundingClientRect(),M=ce.current;return{x:(u-h.left-M.x)/M.zoom,y:(x-h.top-M.y)/M.zoom}},[]),tt=l.useCallback((u,x)=>{const i=dt.current.length>0?dt.current:K.current;let h=null;for(let M=i.length-1;M>=0;M--){const k=i[M];if(k.hidden)continue;const p=k._absolutePosition||k.position,I=k.width||ht,R=k.height||st;if(u>=p.x&&u<=p.x+I&&x>=p.y&&x<=p.y+R){if(k.type==="group"){h||(h=k);continue}return k}}return h},[]),vn=l.useCallback((u,x)=>{const i=x.width||ht,h=x.height||st;if(u.x!==void 0&&u.y!==void 0)return{x:x.position.x+u.x,y:x.position.y+u.y};switch(u.position||(u.type==="source"?"right":"left")){case"top":return{x:x.position.x+i/2,y:x.position.y};case"bottom":return{x:x.position.x+i/2,y:x.position.y+h};case"left":return{x:x.position.x,y:x.position.y+h/2};case"right":return{x:x.position.x+i,y:x.position.y+h/2};default:return{x:x.position.x+i,y:x.position.y+h/2}}},[]),Ut=l.useCallback(u=>{const x=u.width||ht,i=u.height||st;if(u.handles&&u.handles.length>0)return u.handles.map(R=>{const U=vn(R,u);return{id:R.id||null,type:R.type,x:U.x,y:U.y}});const h=u.targetPosition||"left",M=u.sourcePosition||"right",k=R=>{switch(R){case"top":return{x:u.position.x+x/2,y:u.position.y};case"bottom":return{x:u.position.x+x/2,y:u.position.y+i};case"left":return{x:u.position.x,y:u.position.y+i/2};case"right":return{x:u.position.x+x,y:u.position.y+i/2};default:return{x:u.position.x+x,y:u.position.y+i/2}}},p=k(h),I=k(M);return[{id:null,type:"target",x:p.x,y:p.y},{id:null,type:"source",x:I.x,y:I.y}]},[vn]),Mt=l.useCallback((u,x)=>{const i=K.current,h=ce.current,M=Math.max(no,Ie)/h.zoom;for(let k=i.length-1;k>=0;k--){const p=i[k];if(p.hidden)continue;const I=Ut(p);for(const R of I)if(Math.abs(u-R.x)<M&&Math.abs(x-R.y)<M)return{nodeId:p.id,handleId:R.id,type:R.type,x:R.x,y:R.y}}return null},[Ut]),nt=l.useCallback((u,x)=>{const h=8/ce.current.zoom;for(let M=Ee.current.length-1;M>=0;M--){const k=Ee.current[M],p=K.current.find(ae=>ae.id===k.source),I=K.current.find(ae=>ae.id===k.target);if(!p||!I)continue;const R=p.width||ht,U=p.height||st,W=I.height||st,Q=p.position.x+R,J=p.position.y+U/2,Me=I.position.x,He=I.position.y+W/2;if(ro(u,x,Q,J,Me,He)<h)return k}return null},[]);l.useEffect(()=>{const u=Bt.current,x=pe.current;if(!u||!x)return;const i=x.getBoundingClientRect(),h=Re!==void 0?Re:matchMedia("(prefers-color-scheme: dark)").matches,M=Xt(K.current);dt.current=M;const k=le(M),{worker:p}=to(u,{width:i.width,height:i.height,camera:ce.current,cards:mt.current,nodes:k,edges:Ee.current,dark:h,gridSize:We,edgeRouting:Ct});p.onmessage=W=>{var Q,J,Me,He;W.data.type==="hud"&&((Q=Yt.current)==null||Q.call(Yt,W.data.data)),W.data.type==="ready"&&Dn(!0),W.data.type==="nodesProcessed"&&((J=Vt.current)==null||J.call(Vt,W.data.data)),W.data.type==="error"&&((He=(Me=Z.current).onError)==null||He.call(Me,"worker-error",W.data.message||"Canvas worker error"))},p.onerror=W=>{var Q,J;(J=(Q=Z.current).onError)==null||J.call(Q,"worker-error",W.message||"Canvas worker crashed")},Te.current=p;const I=new ResizeObserver(W=>{const{width:Q,height:J}=W[0].contentRect;p.postMessage({type:"resize",data:{width:Q,height:J}})});I.observe(x);let R,U;return Re===void 0&&(R=matchMedia("(prefers-color-scheme: dark)"),U=W=>p.postMessage({type:"theme",data:{dark:W.matches}}),R.addEventListener("change",U)),()=>{I.disconnect(),R&&U&&R.removeEventListener("change",U),Te.current=null}},[]),l.useEffect(()=>{var u;Re!==void 0&&((u=Te.current)==null||u.postMessage({type:"theme",data:{dark:Re}}))},[Re]),l.useEffect(()=>{var u;(u=Te.current)==null||u.postMessage({type:"edgeRouting",data:{enabled:Ct}})},[Ct]);const qt=l.useRef(0),me=l.useCallback((u=null)=>{var h,M,k;const x=ce.current;if(xt){const p=pe.current;if(p){const I=p.getBoundingClientRect(),R=-xt[1][0]*x.zoom+I.width,U=-xt[1][1]*x.zoom+I.height,W=-xt[0][0]*x.zoom,Q=-xt[0][1]*x.zoom;x.x=Math.min(W,Math.max(R,x.x)),x.y=Math.min(Q,Math.max(U,x.y))}}(h=Te.current)==null||h.postMessage({type:"camera",data:{camera:{...x}}});const i={x:x.x,y:x.y,zoom:x.zoom};(k=(M=Z.current).onMove)==null||k.call(M,u,i);for(const p of vt)p(i);cancelAnimationFrame(qt.current),qt.current=requestAnimationFrame(()=>{xn({x:x.x,y:x.y,zoom:x.zoom})})},[vt,xt]),ft=l.useCallback(()=>{var i,h;const u=Ue.current,x=Dt.current;u&&x?((i=Te.current)==null||i.postMessage({type:"connecting",data:{from:u.startPos,to:x,_routedPoints:null}}),pn({source:u.sourceId,sourceHandle:u.sourceHandle,target:null,targetHandle:null})):((h=Te.current)==null||h.postMessage({type:"connecting",data:null}),pn(null))},[]),Rt=l.useCallback(()=>{var x,i;const u=ct.current;u?(x=Te.current)==null||x.postMessage({type:"selectionBox",data:u}):(i=Te.current)==null||i.postMessage({type:"selectionBox",data:null})},[]),_n=l.useCallback(u=>{var p,I,R,U,W,Q,J,Me,He,te,ae,ze,_e,Oe,Qe,qe,Jt,yt;const x=K.current.length>0,i=ke(u.clientX,u.clientY),h=gn.current;if(x&&Ae&&!h){const q=Mt(i.x,i.y);if(Je&&Ke.current&&q){const re=Ke.current;if(q.nodeId!==re.nodeId){const Ve=re.handleType==="target"?{source:q.nodeId,target:re.nodeId,sourceHandle:q.handleId||null,targetHandle:re.handleId}:{source:re.nodeId,target:q.nodeId,sourceHandle:re.handleId,targetHandle:q.handleId||null};(Z.current.isValidConnection?Z.current.isValidConnection(Ve):!0)&&((p=ut.current)==null||p.call(ut,{...Ve,...It}))}Ke.current=null;return}if(be==="strict"?q&&q.type==="source":q!=null){if(Je){Ke.current={nodeId:q.nodeId,handleId:q.handleId||null,handleType:q.type},(R=(I=Z.current).onConnectStart)==null||R.call(I,u,{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}},Dt.current={x:i.x,y:i.y},(U=pe.current)==null||U.setPointerCapture(u.pointerId),(Q=(W=Z.current).onConnectStart)==null||Q.call(W,u,{nodeId:q.nodeId,handleId:q.handleId,handleType:q.type}),ft();return}}const M=q=>{var re;let ye=q;for(;ye&&ye!==pe.current;){if((re=ye.classList)!=null&&re.contains(Tt))return!0;ye=ye.parentElement}return!1},k=q=>{var re;let ye=q;for(;ye&&ye!==pe.current;){if((re=ye.classList)!=null&&re.contains(Lt))return!0;ye=ye.parentElement}return!1};if(x){const q=tt(i.x,i.y);if(q){if(Le.current&&Pe){const ye=[];if(h)ye.push({id:q.id,type:"select",selected:!q.selected});else if(!q.selected){for(const re of K.current)re.id===q.id?ye.push({id:re.id,type:"select",selected:!0}):re.selected&&ye.push({id:re.id,type:"select",selected:!1});if(Fe.current){const re=Ee.current.filter(ue=>ue.selected).map(ue=>({id:ue.id,type:"select",selected:!1}));re.length&&Fe.current(re)}}if(ye.length){if(Le.current(ye),Ln&&!h){const re=K.current.findIndex(ue=>ue.id===q.id);re>=0&&re<K.current.length-1&&Le.current([{id:q.id,type:"remove"},{type:"add",item:{...K.current[re],selected:!0}}])}wt()}}if((J=Ht.current)==null||J.call(Ht,u,q),je&&!M(u.target)){const ye=q.selected;let re=null;if(q.parentId&&q.extent==="parent"){const ue=K.current.find(Ve=>Ve.id===q.parentId);if(ue){const Ve=ue.width||ht,Kt=ue.height||st,bn=q.width||((Me=q.measured)==null?void 0:Me.width)||ht,en=q.height||((He=q.measured)==null?void 0:He.height)||st;re={minX:0,minY:0,maxX:Ve-bn,maxY:Kt-en}}}if(Xe.current={id:q.id,startPos:{...q.position},startMouse:{x:i.x,y:i.y},parentClamp:re,parentId:q.parentId||null,selectedStarts:ye?K.current.filter(ue=>ue.selected&&ue.id!==q.id).map(ue=>{var Kt,bn;let Ve=null;if(ue.parentId&&ue.extent==="parent"){const en=K.current.find(Yn=>Yn.id===ue.parentId);if(en){const Yn=en.width||ht,Wr=en.height||st,Fr=ue.width||((Kt=ue.measured)==null?void 0:Kt.width)||ht,Yr=ue.height||((bn=ue.measured)==null?void 0:bn.height)||st;Ve={minX:0,minY:0,maxX:Yn-Fr,maxY:Wr-Yr}}}return{id:ue.id,startPos:{...ue.position},parentClamp:Ve,parentId:ue.parentId||null}}):[]},(te=pe.current)==null||te.setPointerCapture(u.pointerId),(ae=_t.current)==null||ae.call(_t,u,q),Xe.current.selectedStarts.length>0){const ue=K.current.filter(Ve=>Ve.selected);(_e=(ze=Z.current).onSelectionDragStart)==null||_e.call(ze,u,ue)}if(Le.current){const ue=[{id:q.id,type:"position",dragging:!0}];for(const Ve of Xe.current.selectedStarts)ue.push({id:Ve.id,type:"position",dragging:!0});Le.current(ue)}}return}}if(Ee.current.length>0&&Pe){const q=nt(i.x,i.y);if(q){if(Fe.current){const ye=[];if(h)ye.push({id:q.id,type:"select",selected:!q.selected});else{for(const re of Ee.current)re.id===q.id?ye.push({id:re.id,type:"select",selected:!0}):re.selected&&ye.push({id:re.id,type:"select",selected:!1});if(Le.current){const re=K.current.filter(ue=>ue.selected).map(ue=>({id:ue.id,type:"select",selected:!1}));re.length&&Le.current(re)}}if(ye.length){if(Fe.current(ye),Bn&&!h){const re=Ee.current.findIndex(ue=>ue.id===q.id);re>=0&&re<Ee.current.length-1&&Fe.current([{id:q.id,type:"remove"},{type:"add",item:{...Ee.current[re],selected:!0}}])}wt()}}(Oe=Et.current)==null||Oe.call(Et,u,q);return}}if(!h){const q=K.current.filter(re=>re.selected).map(re=>({id:re.id,type:"select",selected:!1})),ye=Ee.current.filter(re=>re.selected).map(re=>({id:re.id,type:"select",selected:!1}));q.length&&Le.current&&Le.current(q),ye.length&&Fe.current&&Fe.current(ye),(q.length||ye.length)&&wt()}if((Qe=bt.current)==null||Qe.call(bt,u),rt||h){ct.current={startWorld:{...i},endWorld:{...i}},(qe=pe.current)==null||qe.setPointerCapture(u.pointerId),Rt();return}k(u.target)||($t.current=!0,jt.current={x:u.clientX,y:u.clientY},(Jt=pe.current)==null||Jt.classList.add("dragging"),(yt=pe.current)==null||yt.setPointerCapture(u.pointerId))},[ke,tt,Mt,nt,je,Ae,Pe,rt,ft,Rt,wt,Tt,Lt]),Wn=l.useCallback(u=>{var i,h,M,k;if(Ue.current){if(Dt.current=ke(u.clientX,u.clientY),ft(),Tn){const p=pe.current;if(p){const I=p.getBoundingClientRect(),R=40,U=u.clientX-I.left,W=u.clientY-I.top;let Q=0,J=0;U<R?Q=it:U>I.width-R&&(Q=-it),W<R?J=it:W>I.height-R&&(J=-it),(Q||J)&&(ce.current.x+=Q,ce.current.y+=J,me(u))}}return}if(ct.current){ct.current.endWorld=ke(u.clientX,u.clientY),Rt();const p=ct.current,I=Math.min(p.startWorld.x,p.endWorld.x),R=Math.min(p.startWorld.y,p.endWorld.y),U=Math.max(p.startWorld.x,p.endWorld.x),W=Math.max(p.startWorld.y,p.endWorld.y);if(Le.current){const Q=[];for(const J of K.current){if(J.hidden)continue;const Me=J.width||ht,He=J.height||st,te=at==="full"?J.position.x>=I&&J.position.x+Me<=U&&J.position.y>=R&&J.position.y+He<=W:J.position.x+Me>I&&J.position.x<U&&J.position.y+He>R&&J.position.y<W;te!==!!J.selected&&Q.push({id:J.id,type:"select",selected:te})}Q.length&&Le.current(Q)}return}if(Xe.current){const p=ke(u.clientX,u.clientY),I=Xe.current,R=p.x-I.startMouse.x,U=p.y-I.startMouse.y;let W={x:I.startPos.x+R,y:I.startPos.y+U};if($e&&(W=Zn(W,Ye)),pt&&(W=Gn(W,pt)),I.parentClamp){const te=I.parentClamp;W={x:Math.max(te.minX,Math.min(W.x,te.maxX)),y:Math.max(te.minY,Math.min(W.y,te.maxY))}}const Q=[{id:I.id,position:W}];for(const te of I.selectedStarts){let ae={x:te.startPos.x+R,y:te.startPos.y+U};if($e&&(ae=Zn(ae,Ye)),pt&&(ae=Gn(ae,pt)),te.parentClamp){const ze=te.parentClamp;ae={x:Math.max(ze.minX,Math.min(ae.x,ze.maxX)),y:Math.max(ze.minY,Math.min(ae.y,ze.maxY))}}Q.push({id:te.id,position:ae})}const J=[];for(const te of Q){const ae=K.current.find(ze=>ze.id===te.id);if(ae){ae.position=te.position,ae.dragging=!0;let ze=te.position;if(ae.parentId){let _e=K.current.find(qe=>qe.id===ae.parentId),Oe=te.position.x,Qe=te.position.y;for(;_e;)Oe+=_e.position.x,Qe+=_e.position.y,_e=_e.parentId?K.current.find(qe=>qe.id===_e.parentId):null;ze={x:Oe,y:Qe}}J.push({id:te.id,position:te.position,_absolutePosition:ze,width:ae.width,height:ae.height,dragging:!0,selected:ae.selected})}}const Me=new Set(Q.map(te=>te.id));for(const te of K.current)if(te.parentId&&Me.has(te.parentId)&&!Me.has(te.id)){let ae=K.current.find(Oe=>Oe.id===te.parentId),ze=te.position.x,_e=te.position.y;for(;ae;)ze+=ae.position.x,_e+=ae.position.y,ae=ae.parentId?K.current.find(Oe=>Oe.id===ae.parentId):null;J.push({id:te.id,position:te.position,_absolutePosition:{x:ze,y:_e},width:te.width,height:te.height,dragging:!1,selected:te.selected})}if((i=Te.current)==null||i.postMessage({type:"nodePositions",data:{updates:J}}),In){const te=pe.current;if(te){const ae=te.getBoundingClientRect(),ze=40,_e=u.clientX-ae.left,Oe=u.clientY-ae.top;let Qe=0,qe=0;_e<ze?Qe=it:_e>ae.width-ze&&(Qe=-it),Oe<ze?qe=it:Oe>ae.height-ze&&(qe=-it),(Qe||qe)&&(ce.current.x+=Qe,ce.current.y+=qe,me(u))}}const He=K.current.find(te=>te.id===I.id);if(He&&((h=Wt.current)==null||h.call(Wt,u,He)),I.selectedStarts.length>0){const te=K.current.filter(ae=>ae.selected);(k=(M=Z.current).onSelectionDrag)==null||k.call(M,u,te)}return}if(!$t.current)return;const x=ce.current;x.x+=u.clientX-jt.current.x,x.y+=u.clientY-jt.current.y,jt.current={x:u.clientX,y:u.clientY},me()},[me,ke,ft,Rt]),Fn=l.useCallback(u=>{var x,i,h,M,k,p,I;if(Ue.current){const R=ke(u.clientX,u.clientY),U=Mt(R.x,R.y);if(U&&U.nodeId!==Ue.current.sourceId&&(be==="loose"||U.type==="target")){const J=Ue.current.sourceType==="target"?{source:U.nodeId,target:Ue.current.sourceId,sourceHandle:U.handleId||null,targetHandle:Ue.current.sourceHandle}:{source:Ue.current.sourceId,target:U.nodeId,sourceHandle:Ue.current.sourceHandle,targetHandle:U.handleId||null};(Z.current.isValidConnection?Z.current.isValidConnection(J):!0)&&((x=ut.current)==null||x.call(ut,{...J,...It}))}(h=(i=Z.current).onConnectEnd)==null||h.call(i,u.nativeEvent||u),Ue.current=null,Dt.current=null,ft();return}if(ct.current){ct.current=null,Rt(),wt();return}if(Xe.current){const R=Xe.current;if(Le.current){const W=K.current.find(J=>J.id===R.id),Q=[{id:R.id,type:"position",position:W?{...W.position}:void 0,dragging:!1}];for(const J of R.selectedStarts){const Me=K.current.find(He=>He.id===J.id);Q.push({id:J.id,type:"position",position:Me?{...Me.position}:void 0,dragging:!1})}Le.current(Q)}if(R.selectedStarts.length>0){const W=K.current.filter(Q=>Q.selected);(k=(M=Z.current).onSelectionDragStop)==null||k.call(M,u,W)}requestAnimationFrame(()=>{Xe.current=null});const U=K.current.find(W=>W.id===R.id);U&&((p=Ft.current)==null||p.call(Ft,u,U));return}$t.current=!1,(I=pe.current)==null||I.classList.remove("dragging")},[ke,Mt,ft,Rt,wt]);l.useEffect(()=>{const u=pe.current;if(!u)return;const x=i=>{Gt&&i.preventDefault();const h=ce.current;if(cn||et.current){const R=ln;Pt==="horizontal"?h.x-=i.deltaY*R:(Pt==="vertical"||(h.x-=i.deltaX*R),h.y-=i.deltaY*R),me(i);return}if(!un)return;const M=i.deltaY>0?.92:1.08,k=u.getBoundingClientRect(),p=i.clientX-k.left,I=i.clientY-k.top;h.x=p-(p-h.x)*M,h.y=I-(I-h.y)*M,h.zoom=Math.min(oe,Math.max(V,h.zoom*M)),me(i)};return u.addEventListener("wheel",x,{passive:!Gt}),()=>u.removeEventListener("wheel",x)},[me,V,oe,cn,Pt,ln,un,Gt]),l.useEffect(()=>{if(!fn)return;const u=pe.current;if(!u)return;let x=0,i=null;const h=p=>{if(p.touches.length===2){const I=p.touches[0].clientX-p.touches[1].clientX,R=p.touches[0].clientY-p.touches[1].clientY;x=Math.hypot(I,R);const U=u.getBoundingClientRect();i={x:(p.touches[0].clientX+p.touches[1].clientX)/2-U.left,y:(p.touches[0].clientY+p.touches[1].clientY)/2-U.top},p.preventDefault()}},M=p=>{if(p.touches.length===2&&x>0){p.preventDefault();const I=p.touches[0].clientX-p.touches[1].clientX,R=p.touches[0].clientY-p.touches[1].clientY,U=Math.hypot(I,R),W=U/x;x=U;const Q=ce.current,J=i.x,Me=i.y;Q.x=J-(J-Q.x)*W,Q.y=Me-(Me-Q.y)*W,Q.zoom=Math.min(oe,Math.max(V,Q.zoom*W)),me(p)}},k=()=>{x=0,i=null};return u.addEventListener("touchstart",h,{passive:!1}),u.addEventListener("touchmove",M,{passive:!1}),u.addEventListener("touchend",k),()=>{u.removeEventListener("touchstart",h),u.removeEventListener("touchmove",M),u.removeEventListener("touchend",k)}},[fn,me,V,oe]),l.useEffect(()=>{if(!dn)return;const u=pe.current;if(!u)return;const x=i=>{var W,Q,J,Me;const h=ke(i.clientX,i.clientY);if(tt(h.x,h.y)){(Q=(W=Z.current).onNodeDoubleClick)==null||Q.call(W,i,tt(h.x,h.y));return}const M=nt(h.x,h.y);if(M){(Me=(J=Z.current).onEdgeDoubleClick)==null||Me.call(J,i,M);return}const k=1.5,p=u.getBoundingClientRect(),I=i.clientX-p.left,R=i.clientY-p.top,U=ce.current;U.x=I-(I-U.x)*k,U.y=R-(R-U.y)*k,U.zoom=Math.min(oe,Math.max(V,U.zoom*k)),me(i)};return u.addEventListener("dblclick",x),()=>u.removeEventListener("dblclick",x)},[dn,me,V,oe,ke,tt,nt]),l.useEffect(()=>{const u=pe.current;if(!u)return;const x=i=>{var p,I,R,U,W,Q;const h=ke(i.clientX,i.clientY),M=tt(h.x,h.y);if(M){(I=(p=Z.current).onNodeContextMenu)==null||I.call(p,i,M);return}const k=nt(h.x,h.y);if(k){(U=(R=Z.current).onEdgeContextMenu)==null||U.call(R,i,k);return}(Q=(W=Z.current).onPaneContextMenu)==null||Q.call(W,i)};return u.addEventListener("contextmenu",x),()=>u.removeEventListener("contextmenu",x)},[ke,tt,nt]),l.useEffect(()=>{const u=pe.current;if(!u)return;let x=null,i=null;const h=p=>{var U,W,Q,J,Me,He,te,ae,ze,_e,Oe,Qe,qe,Jt;if((W=(U=Z.current).onPaneMouseMove)==null||W.call(U,p),$t.current||Xe.current||Ue.current||ct.current)return;const I=ke(p.clientX,p.clientY),R=tt(I.x,I.y);if(R!==x&&(x&&((J=(Q=Z.current).onNodeMouseLeave)==null||J.call(Q,p,x)),R&&((He=(Me=Z.current).onNodeMouseEnter)==null||He.call(Me,p,R)),x=R),R&&((ae=(te=Z.current).onNodeMouseMove)==null||ae.call(te,p,R)),!R){const yt=nt(I.x,I.y);yt!==i&&(i&&((_e=(ze=Z.current).onEdgeMouseLeave)==null||_e.call(ze,p,i)),yt&&((Qe=(Oe=Z.current).onEdgeMouseEnter)==null||Qe.call(Oe,p,yt)),i=yt),yt&&((Jt=(qe=Z.current).onEdgeMouseMove)==null||Jt.call(qe,p,yt))}},M=p=>{var I,R;return(R=(I=Z.current).onPaneMouseEnter)==null?void 0:R.call(I,p)},k=p=>{var I,R,U,W,Q,J;(R=(I=Z.current).onPaneMouseLeave)==null||R.call(I,p),x&&((W=(U=Z.current).onNodeMouseLeave)==null||W.call(U,p,x),x=null),i&&((J=(Q=Z.current).onEdgeMouseLeave)==null||J.call(Q,p,i),i=null)};return u.addEventListener("mousemove",h),u.addEventListener("mouseenter",M),u.addEventListener("mouseleave",k),()=>{u.removeEventListener("mousemove",h),u.removeEventListener("mouseenter",M),u.removeEventListener("mouseleave",k)}},[ke,tt,nt]),l.useEffect(()=>{const u=Array.isArray(Ge)?Ge:[Ge],x=async i=>{var h,M,k,p;if(u.includes(i.key)){if(i.target.tagName==="INPUT"||i.target.tagName==="TEXTAREA"||i.target.isContentEditable)return;const I=K.current.filter(W=>W.selected),R=Ee.current.filter(W=>W.selected);if(!I.length&&!R.length)return;if(Z.current.onBeforeDelete)try{if(!await Z.current.onBeforeDelete({nodes:I,edges:R}))return}catch(W){(M=(h=Z.current).onError)==null||M.call(h,"before-delete-error",W.message||"onBeforeDelete threw an error");return}const U=new Set(I.map(W=>W.id));if(I.length&&Le.current&&(Le.current(I.map(W=>({id:W.id,type:"remove"}))),Fe.current)){const W=Ee.current.filter(Q=>U.has(Q.source)||U.has(Q.target));W.length&&Fe.current(W.map(Q=>({id:Q.id,type:"remove"})))}R.length&&Fe.current&&Fe.current(R.map(W=>({id:W.id,type:"remove"}))),(p=(k=Z.current).onDelete)==null||p.call(k,{nodes:I,edges:R})}if((i.ctrlKey||i.metaKey)&&i.key==="a"){if(i.target.tagName==="INPUT"||i.target.tagName==="TEXTAREA")return;if(i.preventDefault(),Le.current){const I=K.current.filter(R=>!R.selected).map(R=>({id:R.id,type:"select",selected:!0}));I.length&&Le.current(I)}if(Fe.current){const I=Ee.current.filter(R=>!R.selected).map(R=>({id:R.id,type:"select",selected:!0}));I.length&&Fe.current(I)}}};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[Ge]);const _=l.useRef(!1);l.useEffect(()=>{var u,x;if(!_.current&&Te.current){if(_.current=!0,Ze&&K.current.length>0){const i=pe.current;if(i){const h=i.getBoundingClientRect(),M=(fe==null?void 0:fe.padding)??.1,k=Rn(K.current),p=Zt(k,h.width,h.height,M);fe!=null&&fe.maxZoom&&(p.zoom=Math.min(p.zoom,fe.maxZoom)),fe!=null&&fe.minZoom&&(p.zoom=Math.max(p.zoom,fe.minZoom)),ce.current=p,me()}}(x=(u=Z.current).onInit)==null||x.call(u,{getNodes:()=>[...K.current],getEdges:()=>[...Ee.current],getNode:i=>K.current.find(h=>h.id===i),getEdge:i=>Ee.current.find(h=>h.id===i),getViewport:()=>({...ce.current}),getZoom:()=>ce.current.zoom,setViewport:i=>{ce.current={x:i.x??ce.current.x,y:i.y??ce.current.y,zoom:i.zoom??ce.current.zoom},me()},fitView:(i={})=>{const h=pe.current;if(!h||!K.current.length)return;const M=h.getBoundingClientRect(),k=i.nodes?K.current.filter(R=>i.nodes.some(U=>U.id===R.id)):K.current;if(!k.length)return;const p=Rn(k),I=Zt(p,M.width,M.height,i.padding??.1);i.maxZoom&&(I.zoom=Math.min(I.zoom,i.maxZoom)),i.minZoom&&(I.zoom=Math.max(I.zoom,i.minZoom)),ce.current=I,me()},screenToFlowPosition:i=>ke(i.x,i.y),flowToScreenPosition:i=>{const h=ce.current,M=pe.current;if(!M)return{x:0,y:0};const k=M.getBoundingClientRect();return{x:i.x*h.zoom+h.x+k.left,y:i.y*h.zoom+h.y+k.top}},zoomIn:()=>{const i=ce.current;i.zoom=Math.min(oe,i.zoom*1.2),me()},zoomOut:()=>{const i=ce.current;i.zoom=Math.max(V,i.zoom/1.2),me()},zoomTo:i=>{ce.current.zoom=Math.min(oe,Math.max(V,i)),me()},setNodes:i=>{var h,M;(M=(h=Z.current).onNodesChange)==null||M.call(h,[...K.current.map(k=>({id:k.id,type:"remove"})),...(typeof i=="function"?i(K.current):i).map(k=>({type:"add",item:k}))])},setEdges:i=>{var h,M;(M=(h=Z.current).onEdgesChange)==null||M.call(h,[...Ee.current.map(k=>({id:k.id,type:"remove"})),...(typeof i=="function"?i(Ee.current):i).map(k=>({type:"add",item:k}))])},addNodes:i=>{var M,k;const h=Array.isArray(i)?i:[i];(k=(M=Z.current).onNodesChange)==null||k.call(M,h.map(p=>({type:"add",item:p})))},addEdges:i=>{var M,k;const h=Array.isArray(i)?i:[i];(k=(M=Z.current).onEdgesChange)==null||k.call(M,h.map(p=>({type:"add",item:p})))},deleteElements:({nodes:i=[],edges:h=[]})=>{var M,k,p,I;i.length&&((k=(M=Z.current).onNodesChange)==null||k.call(M,i.map(R=>({id:R.id,type:"remove"})))),h.length&&((I=(p=Z.current).onEdgesChange)==null||I.call(p,h.map(R=>({id:R.id,type:"remove"}))))},updateNodeData:(i,h)=>{var p,I;const M=K.current.find(R=>R.id===i);if(!M)return;const k=typeof h=="function"?h(M.data):{...M.data,...h};(I=(p=Z.current).onNodesChange)==null||I.call(p,[{id:i,type:"replace",item:{...M,data:k}}])},toObject:()=>({nodes:[...K.current],edges:[...Ee.current],viewport:{...ce.current}}),setCenter:(i,h,M={})=>{const k=pe.current;if(!k)return;const p=k.getBoundingClientRect(),I=M.zoom??ce.current.zoom;ce.current={x:p.width/2-i*I,y:p.height/2-h*I,zoom:I},me()},fitBounds:(i,h={})=>{const M=pe.current;if(!M)return;const k=M.getBoundingClientRect(),p=Zt(i,k.width,k.height,h.padding??.1);ce.current=p,me()}})}});const we=l.useCallback(()=>{ce.current={...xe},me()},[me,xe]),ie=l.useCallback(u=>{var x;if(u)mt.current.push(u);else{const i=ce.current,h=pe.current;if(!h)return;const M=h.getBoundingClientRect(),k=Math.round(-i.x/i.zoom+M.width/2/i.zoom),p=Math.round(-i.y/i.zoom+M.height/2/i.zoom);mt.current.push({x:k-80,y:p-45,w:160,h:90,title:"Note "+(mt.current.length+1),body:"Added at viewport center"})}(x=Te.current)==null||x.postMessage({type:"cards",data:{cards:[...mt.current]}})},[]),ve=l.useCallback(u=>{if(u.id||(u.id="node-"+Date.now()),!u.position){const x=ce.current,i=pe.current;if(!i)return;const h=i.getBoundingClientRect();u.position={x:Math.round(-x.x/x.zoom+h.width/2/x.zoom)-ht/2,y:Math.round(-x.y/x.zoom+h.height/2/x.zoom)-st/2}}u.data||(u.data={label:u.id}),Le.current&&Le.current([{type:"add",item:u}])},[]),Be=l.useCallback(()=>({...ce.current}),[]),Se=l.useCallback(u=>{ce.current={...ce.current,...u},me()},[me]),De=l.useCallback(u=>ke(u.x,u.y),[ke]),gt=n,kt=l.useMemo(()=>({wrapRef:pe,canvasRef:Bt,workerRef:Te,cameraRef:ce,nodesRef:K,edgesRef:Ee,handleRegistryRef:hn,syncNodesToWorker:Ot,onNodesChangeRef:Le,onEdgesChangeRef:Fe,sendCamera:me,screenToWorld:ke,viewportListeners:vt,selectionListeners:lt,zoomMin:V,zoomMax:oe,snapToGrid:$e,snapGrid:Ye,nodeExtent:pt,defaultEdgeOptions:It,edgeRouting:Ct,resolvedNodesRef:dt,noDragClassName:Tt,noPanClassName:Lt,get nodes(){return t},get edges(){return n},get routedEdges(){return gt},get viewport(){return yn},get connection(){return Qt}}),[t,n,gt,yn,Qt,me,ke,Ot,vt,lt,V,oe,$e,Ye,pt,It,Ct,Tt,Lt]);return{wrapRef:pe,canvasRef:Bt,canvasReady:At,onPointerDown:_n,onPointerMove:Wn,onPointerUp:Fn,resetView:we,addCard:ie,addNode:ve,getCamera:Be,setCamera:Se,screenToFlowPosition:De,store:kt}}function ro(e,t,n,r,a,o){const c=a-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,g)=>{const b=typeof d=="function"?d(t):d;if(!Object.is(b,t)){const E=t;t=g??(typeof b!="object"||b===null)?b:Object.assign({},t,b),n.forEach(C=>C(t,E))}},a=()=>t,f={setState:r,getState:a,getInitialState:()=>m,subscribe:d=>(n.add(d),()=>n.delete(d))},m=t=e(r,a,f);return f},oo=(e=>e?ur(e):ur),so=e=>e;function ao(e,t=so){const n=l.useSyncExternalStore(e.subscribe,l.useCallback(()=>t(e.getState()),[e,t]),l.useCallback(()=>t(e.getInitialState()),[e,t]));return l.useDebugValue(n),n}const zt=l.createContext(null);function io(e={}){return oo((t,n)=>({nodes:[],edges:[],viewport:{x:0,y:0,zoom:1},connection:null,minZoom:.1,maxZoom:5,width:0,height:0,domNode:null,nodesRef:{current:[]},edgesRef:{current:[]},cameraRef:{current:{x:0,y:0,zoom:1}},wrapRef:{current:null},workerRef:{current:null},onNodesChangeRef:{current:null},onEdgesChangeRef:{current:null},viewportListeners:new Set,selectionListeners:new Set,edgeLabelContainerRef:{current:null},viewportPortalRef:{current:null},screenToWorld:(r,a)=>{const o=n().cameraRef.current;return{x:(r-o.x)/o.zoom,y:(a-o.y)/o.zoom}},sendCamera:()=>{var a;const r=n();(a=r.workerRef.current)==null||a.postMessage({type:"camera",data:{camera:{...r.cameraRef.current}}})},...e}))}function Ne(e,t){const n=l.useContext(zt);if(!n)throw new Error("useCanvasStore must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");const r=typeof n.getState=="function"&&typeof n.subscribe=="function",a=l.useRef(e),o=l.useRef(t),c=l.useRef(void 0);a.current=e,o.current=t;const f=l.useCallback(m=>{const d=a.current;if(!d)return m;const g=d(m),b=o.current||Object.is;return c.current!==void 0&&b(c.current,g)?c.current:(c.current=g,g)},[]);return r?ao(n,e?f:void 0):e?f(n):n}function Rr(){const e=l.useContext(zt);if(!e)throw new Error("useCanvasStoreApi must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");return typeof e.getState=="function"?e:{getState:()=>e,setState:()=>{},subscribe:()=>()=>{}}}const sn=l.createContext(null);function co(){return l.useContext(sn)}function lo({node:e,nodeType:t}){var S,j,L,A;const n=Ne(),r=l.useRef(n);r.current=n;const a=l.useRef(null),o=e._absolutePosition||e.position,c=l.useRef(null);l.useEffect(()=>{const Y=a.current;if(!Y)return;const D=new ResizeObserver(F=>{var O,X,H,w;const{width:$,height:N}=F[0].contentRect;if($>0&&N>0){const y=r.current,v=y.nodesRef.current.find(B=>B.id===e.id),z=(v==null?void 0:v.width)||((O=v==null?void 0:v.measured)==null?void 0:O.width),P=(v==null?void 0:v.height)||((X=v==null?void 0:v.measured)==null?void 0:X.height);(Math.abs((z||0)-$)>1||Math.abs((P||0)-N)>1)&&((w=(H=y.onNodesChangeRef).current)==null||w.call(H,[{id:e.id,type:"dimensions",dimensions:{width:$,height:N},setAttributes:!0}]))}});return D.observe(Y),()=>D.disconnect()},[e.id]);const f=l.useCallback(Y=>{var ge,de,Re,We;Y.stopPropagation();const D=Y.target.tagName;if(D==="INPUT"||D==="TEXTAREA"||D==="SELECT"||D==="BUTTON"||D==="A"||D==="LABEL"||Y.target.isContentEditable)return;const F=r.current.noDragClassName||"nodrag",$=r.current.noPanClassName||"nopan";let N=Y.target;for(;N&&N!==a.current;){if((ge=N.classList)!=null&&ge.contains(F)||(de=N.classList)!=null&&de.contains($))return;N=N.parentElement}if(r.current.onNodesChangeRef.current){const V=[];if(Y.shiftKey)V.push({id:e.id,type:"select",selected:!e.selected});else for(const xe of r.current.nodesRef.current)xe.id===e.id&&!xe.selected?V.push({id:xe.id,type:"select",selected:!0}):xe.id!==e.id&&xe.selected&&V.push({id:xe.id,type:"select",selected:!1});V.length&&r.current.onNodesChangeRef.current(V)}const O=r.current.cameraRef.current,X=r.current.wrapRef.current;if(!X)return;const H=X.getBoundingClientRect(),w=(Y.clientX-H.left-O.x)/O.zoom,y=(Y.clientY-H.top-O.y)/O.zoom,z=e.selected?r.current.nodesRef.current.filter(V=>V.selected&&V.id!==e.id).map(V=>({id:V.id,startPos:{...V.position}})):[];c.current={startPos:{...e.position},startMouse:{x:w,y},selectedStarts:z};const P=[{id:e.id,type:"position",dragging:!0}];for(const V of z)P.push({id:V.id,type:"position",dragging:!0});(We=(Re=r.current.onNodesChangeRef).current)==null||We.call(Re,P);const B=a.current;B&&B.setPointerCapture(Y.pointerId);let G=null,ne=null;const ee=()=>{var V,oe;ne&&((oe=(V=r.current.onNodesChangeRef).current)==null||oe.call(V,ne),ne=null),G=null},se=V=>{var rt,at;if(!c.current)return;const oe=r.current.cameraRef.current,xe=X.getBoundingClientRect(),Ze=(V.clientX-xe.left-oe.x)/oe.zoom,fe=(V.clientY-xe.top-oe.y)/oe.zoom,je=Ze-c.current.startMouse.x,Ae=fe-c.current.startMouse.y;let Pe={x:c.current.startPos.x+je,y:c.current.startPos.y+Ae};if(r.current.snapToGrid&&r.current.snapGrid&&(Pe={x:r.current.snapGrid[0]*Math.round(Pe.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Pe.y/r.current.snapGrid[1])}),e.parentId&&e.extent==="parent"){const be=r.current.nodesRef.current.find(Ie=>Ie.id===e.parentId);if(be){const Ie=be.width||160,Je=be.height||60,$e=e.width||((rt=e.measured)==null?void 0:rt.width)||160,Ye=e.height||((at=e.measured)==null?void 0:at.height)||60;Pe={x:Math.max(0,Math.min(Pe.x,Ie-$e)),y:Math.max(0,Math.min(Pe.y,Je-Ye))}}}B&&(B.style.left=Pe.x+"px",B.style.top=Pe.y+"px");for(const be of c.current.selectedStarts){let Ie={x:be.startPos.x+je,y:be.startPos.y+Ae};r.current.snapToGrid&&r.current.snapGrid&&(Ie={x:r.current.snapGrid[0]*Math.round(Ie.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Ie.y/r.current.snapGrid[1])});const Je=X.querySelector(`[data-nodeid="${be.id}"]`);Je&&(Je.style.left=Ie.x+"px",Je.style.top=Ie.y+"px")}const Ce=[{id:e.id,type:"position",position:Pe,dragging:!0}];for(const be of c.current.selectedStarts){let Ie={x:be.startPos.x+je,y:be.startPos.y+Ae};r.current.snapToGrid&&r.current.snapGrid&&(Ie={x:r.current.snapGrid[0]*Math.round(Ie.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Ie.y/r.current.snapGrid[1])}),Ce.push({id:be.id,type:"position",position:Ie,dragging:!0})}ne=Ce,G||(G=requestAnimationFrame(ee))},he=V=>{var xe,Ze;if(!c.current)return;G&&(cancelAnimationFrame(G),ee());const oe=[{id:e.id,type:"position",dragging:!1}];for(const fe of c.current.selectedStarts)oe.push({id:fe.id,type:"position",dragging:!1});(Ze=(xe=r.current.onNodesChangeRef).current)==null||Ze.call(xe,oe),c.current=null,B&&B.releasePointerCapture(V.pointerId),B==null||B.removeEventListener("pointermove",se),B==null||B.removeEventListener("pointerup",he)};B==null||B.addEventListener("pointermove",se),B==null||B.addEventListener("pointerup",he)},[e]),m=l.useCallback(Y=>{var X,H,w,y,v,z;if(!e.selected)return;const D=Y.shiftKey?10:1;let F=0,$=0;switch(Y.key){case"ArrowUp":$=-D;break;case"ArrowDown":$=D;break;case"ArrowLeft":F=-D;break;case"ArrowRight":F=D;break;case"Escape":(H=(X=r.current.onNodesChangeRef).current)==null||H.call(X,[{id:e.id,type:"select",selected:!1}]);return;case"Delete":case"Backspace":e.deletable!==!1&&((y=(w=r.current.onNodesChangeRef).current)==null||y.call(w,[{id:e.id,type:"remove"}]));return;default:return}Y.preventDefault();const N={x:e.position.x+F,y:e.position.y+$},O=[{id:e.id,type:"position",position:N}];for(const P of r.current.nodesRef.current)P.selected&&P.id!==e.id&&O.push({id:P.id,type:"position",position:{x:P.position.x+F,y:P.position.y+$}});(z=(v=r.current.onNodesChangeRef).current)==null||z.call(v,O)},[e]),d=e.width||((S=e.measured)==null?void 0:S.width),g=e.height||((j=e.measured)==null?void 0:j.height),b=!!(d&&g),E=(L=n.pinnedNodeIds)==null?void 0:L.has(e.id),C=l.useCallback(Y=>{var D,F;Y.stopPropagation(),(F=(D=r.current).togglePinNode)==null||F.call(D,e.id)},[e.id]);return T.jsx(sn.Provider,{value:e.id,children:T.jsxs("div",{ref:a,className:`ric-node-wrapper ${e.selected?"selected":""} ${e.dragging?"dragging":""}`,style:{position:"absolute",left:o.x,top:o.y,zIndex:e.type==="group"?0:e.zIndex||1,pointerEvents:e.type==="group"?"none":"all",visibility:b?"visible":"hidden",outline:"none"},"data-nodeid":e.id,tabIndex:e.selectable!==!1?0:void 0,role:"button","aria-label":`Node ${((A=e.data)==null?void 0:A.label)||e.id}`,"aria-selected":!!e.selected,onPointerDown:f,onKeyDown: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:g,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:E?"Unpin from DOM":"Pin to DOM",style:{position:"absolute",top:-8,left:-8,width:20,height:20,borderRadius:"50%",border:"1.5px solid "+(E?"#3b82f6":"#ccc"),background:E?"#3b82f6":"#fff",color:E?"#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=l.memo(lo),kr=160,Cr=60;function dr(e,t,n,r){var f,m;const a=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]||[],g=n?d.find(b=>b.id===n):d[0];if(g&&g.x!==void 0&&g.y!==void 0){const b=g.position||(t==="source"?"right":"left");return{x:c.x+g.x,y:c.y+g.y,position:b}}}if(r){const d=`${e.id}__${n||t}`,g=r.get(d);if(g&&g.x!==void 0&&g.y!==void 0)return{x:c.x+g.x,y:c.y+g.y,position:g.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 g=d.position||(t==="source"?"right":"left");switch(g){case"top":return{x:c.x+a/2,y:c.y,position:g};case"bottom":return{x:c.x+a/2,y:c.y+o,position:g};case"left":return{x:c.x,y:c.y+o/2,position:g};default:return{x:c.x+a,y:c.y+o/2,position:g}}}}return t==="source"?{x:c.x+a,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:a}){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:a})}function go({edge:e,edgeType:t,nodes:n,reconnectable:r}){var N,O,X;const a=l.useContext(zt),o=l.useRef(typeof a.getState=="function"?a.getState():a);o.current=typeof a.getState=="function"?a.getState():a;const[c,f]=l.useState(null),m=l.useCallback((H,w,y,v)=>{var he;w.stopPropagation(),w.preventDefault();const z=o.current,P=z.wrapRef.current;if(!P)return;const B=H==="source"?v:y,G=H==="source"?e.target:e.source;(he=z.workerRef.current)==null||he.postMessage({type:"connecting",data:{from:{x:B.x,y:B.y},to:{x:B.x,y:B.y}}});const ne=P.getBoundingClientRect(),ee=ge=>{var V;const de=z.cameraRef.current,Re=(ge.clientX-ne.left-de.x)/de.zoom,We=(ge.clientY-ne.top-de.y)/de.zoom;(V=z.workerRef.current)==null||V.postMessage({type:"connecting",data:{from:{x:B.x,y:B.y},to:{x:Re,y:We}}})},se=ge=>{var fe,je,Ae,Pe;const de=z.cameraRef.current,Re=(ge.clientX-ne.left-de.x)/de.zoom,We=(ge.clientY-ne.top-de.y)/de.zoom,V=20/de.zoom;let oe=null,xe=null;const Ze=(fe=z.handleRegistryRef)==null?void 0:fe.current;for(const Ce of z.nodesRef.current){if(Ce.hidden)continue;const rt=Ce.width||kr,at=Ce.height||Cr,be=Ce._absolutePosition||Ce.position,Ie=[];if(Ze)for(const[,$e]of Ze)$e.nodeId===Ce.id&&Ie.push($e);const Je=Ie.length>0?Ie:Ce.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const $e of Je){let Ye,Ge;if($e.x!==void 0&&$e.y!==void 0)Ye=be.x+$e.x,Ge=be.y+$e.y;else switch($e.position||($e.type==="source"?"right":"left")){case"top":Ye=be.x+rt/2,Ge=be.y;break;case"bottom":Ye=be.x+rt/2,Ge=be.y+at;break;case"left":Ye=be.x,Ge=be.y+at/2;break;default:Ye=be.x+rt,Ge=be.y+at/2;break}if(Math.abs(Re-Ye)<V&&Math.abs(We-Ge)<V){oe=Ce,xe=$e.id||null;break}}if(oe)break}if(oe){const Ce=H==="source"?{source:oe.id,target:G,sourceHandle:xe,targetHandle:e.targetHandle}:{source:G,target:oe.id,sourceHandle:e.sourceHandle,targetHandle:xe};(Ae=(je=z.onEdgesChangeRef).current)==null||Ae.call(je,[{id:e.id,type:"remove"},{type:"add",item:{id:e.id,...Ce}}])}(Pe=z.workerRef.current)==null||Pe.postMessage({type:"connecting",data:null}),P.removeEventListener("pointermove",ee),P.removeEventListener("pointerup",se)};P.addEventListener("pointermove",ee),P.addEventListener("pointerup",se)},[e]),d=n.find(H=>H.id===e.source),g=n.find(H=>H.id===e.target),b=d&&!!(d.width||(N=d.measured)!=null&&N.width),E=g&&!!(g.width||(O=g.measured)!=null&&O.width),C=o.current,S=(X=C.handleRegistryRef)==null?void 0:X.current,j=b?dr(d,"source",e.sourceHandle,S):null,L=E?dr(g,"target",e.targetHandle,S):null,A=e.type==="bezier"||e.type==="simplebezier"||e.type==="default",Y=C.routedEdges||C.edges,D=Y==null?void 0:Y.find(H=>H.id===e.id),F=A?null:(D==null?void 0:D._routedPoints)||e._routedPoints||null,$=r!==!1&&e.reconnectable!==!1;return!j||!L?null:T.jsxs("g",{className:`ric-edge-wrapper ${e.selected?"selected":""}`,"data-edgeid":e.id,onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),children:[T.jsx(t,{id:e.id,source:e.source,target:e.target,sourceX:j.x,sourceY:j.y,targetX:L.x,targetY:L.y,sourcePosition:j.position,targetPosition:L.position,sourceHandleId:e.sourceHandle,targetHandleId:e.targetHandle,data:e.data,type:e.type,selected:!!e.selected,animated:!!e.animated,label:e.label,style:e.style,selectable:e.selectable!==!1,deletable:e.deletable!==!1,routedPoints:F}),$&&(c||e.selected)&&T.jsxs(T.Fragment,{children:[T.jsx(fr,{x:j.x,y:j.y,position:j.position,type:"source",onPointerDown:H=>m("source",H,j,L)}),T.jsx(fr,{x:L.x,y:L.y,position:L.position,type:"target",onPointerDown:H=>m("target",H,j,L)})]})]})}const yo=l.memo(go);function Er({selectionKeyCode:e="Shift",selectionMode:t="partial"}){var j;const n=Ne(),[r,a]=l.useState(null),o=l.useRef(null);if(l.useEffect(()=>{const L=n.wrapRef.current;if(!L)return;let A=!1,Y=null,D=!1;const F=H=>{H.key===e&&(D=!0)},$=H=>{H.key===e&&(D=!1)},N=H=>{if(!D)return;const w=H.target;if(w.closest(".ric-node-wrapper")||w.closest(".ric-handle"))return;A=!0;const y=n.cameraRef.current,v=L.getBoundingClientRect(),z=(H.clientX-v.left-y.x)/y.zoom,P=(H.clientY-v.top-y.y)/y.zoom;Y={x:z,y:P},a({startX:z,startY:P,endX:z,endY:P}),H.stopPropagation()},O=H=>{if(!A||!Y)return;const w=n.cameraRef.current,y=L.getBoundingClientRect(),v=(H.clientX-y.left-w.x)/w.zoom,z=(H.clientY-y.top-w.y)/w.zoom;a({startX:Y.x,startY:Y.y,endX:v,endY:z})},X=H=>{var G,ne;if(!A||!Y)return;A=!1;const w=n.cameraRef.current,y=L.getBoundingClientRect(),v=(H.clientX-y.left-w.x)/w.zoom,z=(H.clientY-y.top-w.y)/w.zoom,P={x:Math.min(Y.x,v),y:Math.min(Y.y,z),width:Math.abs(v-Y.x),height:Math.abs(z-Y.y)},B=[];for(const ee of n.nodesRef.current){const se=ee._absolutePosition||ee.position,he=ee.width||160,ge=ee.height||60;let de;t==="full"?de=se.x>=P.x&&se.y>=P.y&&se.x+he<=P.x+P.width&&se.y+ge<=P.y+P.height:de=se.x+he>P.x&&se.x<P.x+P.width&&se.y+ge>P.y&&se.y<P.y+P.height,B.push({id:ee.id,type:"select",selected:de})}B.length&&((ne=(G=n.onNodesChangeRef).current)==null||ne.call(G,B)),Y=null,a(null)};return L.addEventListener("pointerdown",N,!0),L.addEventListener("pointermove",O),L.addEventListener("pointerup",X),window.addEventListener("keydown",F),window.addEventListener("keyup",$),()=>{L.removeEventListener("pointerdown",N,!0),L.removeEventListener("pointermove",O),L.removeEventListener("pointerup",X),window.removeEventListener("keydown",F),window.removeEventListener("keyup",$)}},[n,e,t]),!r)return null;const c=((j=n.cameraRef)==null?void 0:j.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),g=Math.abs(r.endY-r.startY),b=f*c.zoom+c.x,E=m*c.zoom+c.y,C=d*c.zoom,S=g*c.zoom;return T.jsx("div",{ref:o,className:"ric-selection-box",style:{position:"absolute",left:b,top:E,width:C,height:S,border:"1px dashed #3b82f6",background:"rgba(59, 130, 246, 0.08)",pointerEvents:"none",zIndex:100}})}Er.displayName="SelectionBox";const Sr=l.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(),a=e.getBoundingClientRect(),o=t||1;return{x:(a.left+a.width/2-r.left)/o,y:(a.top+a.height/2-r.top)/o}}let On=!1,St=null;function zr(e){St=e,!On&&(On=!0,requestAnimationFrame(()=>{var t;On=!1,(t=St==null?void 0:St.syncNodesToWorker)==null||t.call(St),St=null}))}const Vn=new WeakMap;let wn=null;function po(){return wn||(wn=new ResizeObserver(e=>{var t;for(const n of e){const r=Vn.get(n.target);if(!r)continue;const{width:a,height:o}=n.contentRect;if(!a||!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 g=Qn(d.position,a,o);d.x=g.x,d.y=g.y,f.set(m,d)}zr(c)}}}),wn)}function mo({type:e="source",position:t=e==="source"?"right":"left",id:n,isConnectable:r=!0,isConnectableStart:a=!0,isConnectableEnd:o=!0,children:c,className:f="",style:m={},onConnect:d,...g}){const b=l.useContext(sn),E=l.useContext(zt),C=l.useRef(null),S=l.useCallback(()=>typeof E.getState=="function"?E.getState():E,[E]),j=l.useRef(S);j.current=S,l.useLayoutEffect(()=>{var w,y,v,z,P,B,G;if(!b)return;const D=j.current(),F=(w=D.handleRegistryRef)==null?void 0:w.current;if(!F)return;const $=`${b}__${n||e}`,N=(v=(y=D.nodesRef)==null?void 0:y.current)==null?void 0:v.find(ne=>ne.id===b),O=(N==null?void 0:N.width)||((z=N==null?void 0:N.measured)==null?void 0:z.width),X=(N==null?void 0:N.height)||((P=N==null?void 0:N.measured)==null?void 0:P.height);let H;O&&X?H=Qn(t,O,X):C.current?H=xo(C.current,(G=(B=D.cameraRef)==null?void 0:B.current)==null?void 0:G.zoom):H=Qn(t,160,60),F.set($,{nodeId:b,id:n||null,type:e,position:t,x:H.x,y:H.y})},[b,n,e,t]),l.useEffect(()=>{if(!b)return;const D=j.current();zr(D);const F=C.current,$=F==null?void 0:F.closest(".ric-node-wrapper");return $&&!Vn.has($)&&(Vn.set($,{nodeId:b,getStore:j.current}),po().observe($)),()=>{var H;const O=(H=j.current().handleRegistryRef)==null?void 0:H.current,X=`${b}__${n||e}`;O==null||O.delete(X)}},[b,n,e,t]);const L=l.useCallback(()=>{var y;const D=j.current(),F=D.nodesRef.current.find(v=>v.id===b);if(!F)return null;const $=F._absolutePosition||F.position,N=(y=D.handleRegistryRef)==null?void 0:y.current,O=`${b}__${n||e}`,X=N==null?void 0:N.get(O);if(X&&X.x!==void 0&&X.y!==void 0)return{x:$.x+X.x,y:$.y+X.y};const H=F.width||160,w=F.height||60;switch(t){case"top":return{x:$.x+H/2,y:$.y};case"bottom":return{x:$.x+H/2,y:$.y+w};case"left":return{x:$.x,y:$.y+w/2};default:return{x:$.x+H,y:$.y+w/2}}},[b,n,e,t]),A=l.useCallback(D=>{var z;if(!r||!a)return;D.stopPropagation(),D.preventDefault();const F=j.current(),$=F.cameraRef.current,N=F.wrapRef.current;if(!N)return;const O=N.getBoundingClientRect(),X=L();if(!X)return;const H=X.x,w=X.y;(z=F.workerRef.current)==null||z.postMessage({type:"connecting",data:{from:{x:H,y:w},to:{x:H,y:w}}}),N.setPointerCapture(D.pointerId);const y=P=>{var ne;const B=(P.clientX-O.left-$.x)/$.zoom,G=(P.clientY-O.top-$.y)/$.zoom;(ne=F.workerRef.current)==null||ne.postMessage({type:"connecting",data:{from:{x:H,y:w},to:{x:B,y:G}}})},v=P=>{var ge,de,Re,We;const B=(P.clientX-O.left-$.x)/$.zoom,G=(P.clientY-O.top-$.y)/$.zoom,ne=20/$.zoom;let ee=null,se=null;const he=(ge=F.handleRegistryRef)==null?void 0:ge.current;for(const V of F.nodesRef.current){if(V.id===b||V.hidden)continue;const oe=V._absolutePosition||V.position,xe=[];if(he)for(const[,fe]of he)fe.nodeId===V.id&&xe.push(fe);const Ze=xe.length>0?xe:V.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const fe of Ze){let je,Ae;if(fe.x!==void 0&&fe.y!==void 0)je=oe.x+fe.x,Ae=oe.y+fe.y;else{const Pe=V.width||160,Ce=V.height||60;switch(fe.position||(fe.type==="source"?"right":"left")){case"top":je=oe.x+Pe/2,Ae=oe.y;break;case"bottom":je=oe.x+Pe/2,Ae=oe.y+Ce;break;case"left":je=oe.x,Ae=oe.y+Ce/2;break;default:je=oe.x+Pe,Ae=oe.y+Ce/2;break}}if(Math.abs(B-je)<ne&&Math.abs(G-Ae)<ne){ee=V,se=fe.id||null;break}}if(ee)break}if(ee){const V={source:e==="source"?b:ee.id,target:e==="source"?ee.id:b,sourceHandle:e==="source"?n||null:se,targetHandle:e==="source"?se:n||null};(Re=(de=F.onEdgesChangeRef)==null?void 0:de.current)==null||Re.call(de,[{type:"add",item:{id:`e-${V.source}-${V.target}`,...V}}])}(We=F.workerRef.current)==null||We.postMessage({type:"connecting",data:null}),N.removeEventListener("pointermove",y),N.removeEventListener("pointerup",v)};N.addEventListener("pointermove",y),N.addEventListener("pointerup",v)},[b,n,e,t,r,a,L]),Y={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:A,style:{position:"absolute",width:8,height:8,borderRadius:"50%",background:"#1a192b",border:"none",zIndex:10,cursor:r?"crosshair":"default",boxSizing:"border-box",...Y,...m},...g,children:c})}const on=l.memo(mo);function vo({data:e,isConnectable:t,selected:n,targetPosition:r="left",sourcePosition:a="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(on,{type:"target",position:r,isConnectable:t}),T.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!o&&T.jsx(on,{type:"source",position:a,isConnectable:t})]})}function Nr({data:e,isConnectable:t,selected:n,sourcePosition:r="right",hideSourceHandle:a=!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}),!a&&T.jsx(on,{type:"source",position:r,isConnectable:t})]})}function Pr({data:e,isConnectable:t,selected:n,targetPosition:r="left",hideTargetHandle:a=!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:[!a&&T.jsx(on,{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:a=!0,labelBgStyle:o,labelBgPadding:c=[2,4],labelBgBorderRadius:f=2,children:m,className:d="",...g}){const[b,E]=l.useState({x:1,y:0,width:0,height:0}),C=l.useRef(null);return l.useEffect(()=>{if(C.current){const S=C.current.getBBox();E({x:S.x,y:S.y,width:S.width,height:S.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",...g,children:[a&&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=l.memo(Tr);function hr(e){return e!=null&&e!==""&&!isNaN(Number(e))}function an({id:e,path:t,labelX:n,labelY:r,label:a,labelStyle:o,labelShowBg:c,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:d,interactionWidth:g=20,style:b,markerEnd:E,markerStart:C,className:S="",...j}){return T.jsxs(T.Fragment,{children:[T.jsx("path",{id:e,d:t,fill:"none",stroke:"#b1b1b7",strokeWidth:1.5,className:`ric-edge-path ${S}`,style:b,markerEnd:E,markerStart:C,...j}),g?T.jsx("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:g,className:"ric-edge-interaction",style:{pointerEvents:"stroke"}}):null,a&&hr(n)&&hr(r)?T.jsx(Lr,{x:n,y:r,label:a,labelStyle:o,labelShowBg:c,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:d}):null]})}const tn=20;function gr(e,t,n){switch(n){case"right":return{x:e+tn,y:t};case"left":return{x:e-tn,y:t};case"bottom":return{x:e,y:t+tn};case"top":return{x:e,y:t-tn};default:return{x:e+tn,y:t}}}const er=l.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:c="bottom",targetPosition:f="top",label:m,labelStyle:d,labelShowBg:g,labelBgStyle:b,labelBgPadding:E,labelBgBorderRadius:C,style:S,markerEnd:j,markerStart:L,interactionWidth:A}){let Y,D,F;const $=gr(n,r,c),N=gr(a,o,f),O=Math.abs(N.x-$.x),X=Math.max(50,O*.5);let H,w,y,v;switch(c){case"left":H=$.x-X,w=$.y;break;case"top":H=$.x,w=$.y-X;break;case"bottom":H=$.x,w=$.y+X;break;default:H=$.x+X,w=$.y;break}switch(f){case"right":y=N.x+X,v=N.y;break;case"top":y=N.x,v=N.y-X;break;case"bottom":y=N.x,v=N.y+X;break;default:y=N.x-X,v=N.y;break}Y=`M ${n},${r} L ${$.x},${$.y} C ${H},${w} ${y},${v} ${N.x},${N.y} L ${a},${o}`;const z=.5,P=.5;return D=P*P*P*$.x+3*P*P*z*H+3*P*z*z*y+z*z*z*N.x,F=P*P*P*$.y+3*P*P*z*w+3*P*z*z*v+z*z*z*N.y,T.jsx(an,{id:t,path:Y,labelX:D,labelY:F,label:m,labelStyle:d,labelShowBg:g,labelBgStyle:b,labelBgPadding:E,labelBgBorderRadius:C,style:S,markerEnd:j,markerStart:L,interactionWidth:A})});er.displayName="BezierEdge";function tr({sourceX:e,sourceY:t,targetX:n,targetY:r}){const a=`M ${e},${t}L ${n},${r}`,o=(e+n)/2,c=(t+r)/2;return[a,o,c,0,0]}function nr({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a="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),g=Math.max(d*c,50);let b,E,C,S;switch(a){case"top":b=e,E=t-g;break;case"bottom":b=e,E=t+g;break;case"left":b=e-g,E=t;break;default:b=e+g,E=t;break}switch(o){case"top":C=n,S=r-g;break;case"bottom":C=n,S=r+g;break;case"right":C=n+g,S=r;break;default:C=n-g,S=r;break}const j=`M ${e},${t} C ${b},${E} ${C},${S} ${n},${r}`,L=.5,A=1-L,Y=A*A*A*e+3*A*A*L*b+3*A*L*L*C+L*L*L*n,D=A*A*A*t+3*A*A*L*E+3*A*L*L*S+L*L*L*r;return[j,Y,D,0,0]}function rr({sourceX:e,sourceY:t,targetX:n,targetY:r}){const a=Math.abs(n-e),o=Math.max(a*.5,50),c=e+o,f=n-o,m=`M ${e},${t} C ${c},${t} ${f},${r} ${n},${r}`,d=.5,g=.5,b=g*g*g*e+3*g*g*d*c+3*g*d*d*f+d*d*d*n,E=g*g*g*t+3*g*g*d*t+3*g*d*d*r+d*d*d*r;return[m,b,E,0,0]}function kn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a="right",targetPosition:o="left",borderRadius:c=5,offset:f=20}){const m=a==="left"||a==="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,S=r>t?1:-1;return[`M ${e},${t} L ${C-d},${t} Q ${C},${t} ${C},${t+S*d} L ${C},${r-S*d} Q ${C},${r} ${C+(n>C?d:-d)},${r} L ${n},${r}`,C,(t+r)/2,0,0]}const g=(t+r)/2,b=n>e?1:-1;return[`M ${e},${t} L ${e},${g-d} Q ${e},${g} ${e+b*d},${g} L ${n-b*d},${g} Q ${n},${g} ${n},${g+(r>g?d:-d)} L ${n},${r}`,(e+n)/2,g,0,0]}function bo({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[,a,o]=nr({sourceX:e,sourceY:t,targetX:n,targetY:r});return[a,o,0,0]}function wo({sourceX:e,sourceY:t,targetX:n,targetY:r}){return[(e+n)/2,(t+r)/2,0,0]}function Mo(e,t,n){const r=n.filter(o=>o.id!==e.id),a={...e,id:e.id,source:t.source,target:t.target,sourceHandle:t.sourceHandle??e.sourceHandle,targetHandle:t.targetHandle??e.targetHandle};return r.push(a),r}const Cn=160,En=60,nn=20,Mn=12,Sn=20;function yr(e,t,n){var c,f;const r=e.width||((c=e.measured)==null?void 0:c.width)||Cn,a=e.height||((f=e.measured)==null?void 0:f.height)||En,o=e._absolutePosition||e.position;if(e.handles&&e.handles.length>0){for(const m of e.handles)if(m.type===t&&(!n||m.id===n)){if(m.x!==void 0&&m.y!==void 0)return{x:o.x+m.x,y:o.y+m.y,dir:m.position||(t==="source"?"right":"left")};switch(m.position||(t==="source"?"right":"left")){case"top":return{x:o.x+r/2,y:o.y,dir:"top"};case"bottom":return{x:o.x+r/2,y:o.y+a,dir:"bottom"};case"left":return{x:o.x,y:o.y+a/2,dir:"left"};default:return{x:o.x+r,y:o.y+a/2,dir:"right"}}}}return t==="source"?{x:o.x+r,y:o.y+a/2,dir:"right"}:{x:o.x,y:o.y+a/2,dir:"left"}}function zn(e,t){switch(e.dir){case"right":return{x:e.x+t,y:e.y,dir:e.dir};case"left":return{x:e.x-t,y:e.y,dir:e.dir};case"bottom":return{x:e.x,y:e.y+t,dir:e.dir};case"top":return{x:e.x,y:e.y-t,dir:e.dir};default:return{x:e.x+t,y:e.y,dir:e.dir}}}function Ro(e,t,n,r,a,o,c,f){const m=Math.min(e,n),d=Math.max(e,n),g=Math.min(t,r),b=Math.max(t,r);if(d<=a||m>=a+c||b<=o||g>=o+f)return!1;const E=.5;if(e>a+E&&e<a+c-E&&t>o+E&&t<o+f-E||n>a+E&&n<a+c-E&&r>o+E&&r<o+f-E)return!0;const C=(e+n)/2,S=(t+r)/2;if(C>a+E&&C<a+c-E&&S>o+E&&S<o+f-E)return!0;const j=[[a,o],[a+c,o],[a+c,o+f],[a,o+f]];for(let L=0;L<4;L++)if(ko(e,t,n,r,j[L][0],j[L][1],j[(L+1)%4][0],j[(L+1)%4][1]))return!0;return!1}function ko(e,t,n,r,a,o,c,f){const m=(c-a)*(t-o)-(f-o)*(e-a),d=(c-a)*(r-o)-(f-o)*(n-a),g=(n-e)*(o-t)-(r-t)*(a-e),b=(n-e)*(f-t)-(r-t)*(c-e);return(m>0&&d<0||m<0&&d>0)&&(g>0&&b<0||g<0&&b>0)}function Jn(e,t,n,r,a){for(let o=0;o<a.length;o++){const c=a[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 a=n[r];if(e>a.x&&e<a.x+a.w&&t>a.y&&t<a.y+a.h)return!0}return!1}function or(e,t){var r,a;const n=[];for(let o=0;o<e.length;o++){const c=e[o];if(c.hidden||t&&t.has(c.id)||c.type==="group")continue;const f=c._absolutePosition||c.position,m=c.width||((r=c.measured)==null?void 0:r.width)||Cn,d=c.height||((a=c.measured)==null?void 0:a.height)||En;n.push({id:c.id,x:f.x-nn,y:f.y-nn,w:m+2*nn,h:d+2*nn})}return n}function Br(e,t,n){if(Jn(e.x,e.y,t.x,t.y,n))return null;const r=new Set,a=new Set;r.add(e.x),r.add(t.x),a.add(e.y),a.add(t.y);const o=nn+5;e.dir==="right"?r.add(e.x+o):e.dir==="left"?r.add(e.x-o):e.dir==="top"?a.add(e.y-o):e.dir==="bottom"&&a.add(e.y+o),t.dir==="right"?r.add(t.x+o):t.dir==="left"?r.add(t.x-o):t.dir==="top"?a.add(t.y-o):t.dir==="bottom"&&a.add(t.y+o);for(let y=0;y<n.length;y++){const v=n[y];r.add(v.x),r.add(v.x+v.w),a.add(v.y),a.add(v.y+v.h)}const c=[...r].sort((y,v)=>y-v),f=[...a].sort((y,v)=>y-v),m=new Map,d=new Map;for(let y=0;y<c.length;y++)m.set(c[y],y);for(let y=0;y<f.length;y++)d.set(f[y],y);const g=c.length,b=f.length,E=(y,v)=>v*g+y,C=m.get(e.x),S=d.get(e.y),j=m.get(t.x),L=d.get(t.y);if(C===void 0||S===void 0||j===void 0||L===void 0)return null;const A=E(C,S),Y=E(j,L),D=new Float64Array(g*b).fill(1/0),F=new Float64Array(g*b).fill(1/0),$=new Int32Array(g*b).fill(-1),N=new Int8Array(g*b).fill(-1),O=new Uint8Array(g*b);D[A]=0,F[A]=Math.abs(c[j]-e.x)+Math.abs(f[L]-e.y);const X=[A],H=15,w=[[1,0],[-1,0],[0,1],[0,-1]];for(;X.length>0;){let y=0;for(let ee=1;ee<X.length;ee++)F[X[ee]]<F[X[y]]&&(y=ee);const v=X[y];if(X[y]=X[X.length-1],X.pop(),v===Y){const ee=[];let se=Y;for(;se!==-1&&se!==A;){const he=se/g|0,ge=se%g;ee.unshift({x:c[ge],y:f[he]}),se=$[se]}return ee.unshift({x:e.x,y:e.y}),Eo(ee,n)}if(O[v])continue;O[v]=1;const z=v/g|0,P=v%g,B=c[P],G=f[z],ne=N[v];for(let ee=0;ee<4;ee++){const se=P+w[ee][0],he=z+w[ee][1];if(se<0||se>=g||he<0||he>=b)continue;const ge=E(se,he);if(O[ge])continue;const de=c[se],Re=f[he];if(Co(de,Re,n)||!Jn(B,G,de,Re,n))continue;const We=Math.abs(de-B)+Math.abs(Re-G),V=ne>=0&&ne!==ee?H:0,oe=D[v]+We+V;oe<D[ge]&&($[ge]=v,N[ge]=ee,D[ge]=oe,F[ge]=oe+Math.abs(c[j]-de)+Math.abs(f[L]-Re),X.push(ge))}}return null}function Eo(e,t){if(!e||e.length<=2)return e;const n=[e[0]];for(let r=1;r<e.length-1;r++){const a=n[n.length-1],o=e[r],c=e[r+1],f=Math.abs(a.x-o.x)<.5&&Math.abs(o.x-c.x)<.5,m=Math.abs(a.y-o.y)<.5&&Math.abs(o.y-c.y)<.5;(f||m)&&Jn(a.x,a.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 a of e){const o=a._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:a.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:a.id,segIdx:c,y1:Math.min(f.y,m.y),y2:Math.max(f.y,m.y)})}}}const r=new Map;for(const a of e)a._routedPoints&&r.set(a.id,a._routedPoints.map(o=>({...o})));for(const[,a]of t){if(a.length<2)continue;const o=xr(a,"x1","x2");for(const c of o){if(c.length<2)continue;const f=(c.length-1)*Mn/2;for(let m=0;m<c.length;m++){const d=c[m],g=-f+m*Mn,b=r.get(d.edgeId);b&&(b[d.segIdx].y+=g,b[d.segIdx+1].y+=g)}}}for(const[,a]of n){if(a.length<2)continue;const o=xr(a,"y1","y2");for(const c of o){if(c.length<2)continue;const f=(c.length-1)*Mn/2;for(let m=0;m<c.length;m++){const d=c[m],g=-f+m*Mn,b=r.get(d.edgeId);b&&(b[d.segIdx].x+=g,b[d.segIdx+1].x+=g)}}}return e.map(a=>{const o=r.get(a.id);return o?{...a,_routedPoints:o}:a})}function xr(e,t,n){if(e.length<2)return[];const r=[...e].sort((c,f)=>c[t]-f[t]),a=[];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&&a.push(o),o=[r[c]])}return o.length>1&&a.push(o),a}function Nn(e,t=6,n=!1){if(!e||e.length<2)return null;if(n)return zo(e);const r=t;let a=`M ${e[0].x},${e[0].y}`;for(let o=1;o<e.length-1;o++){const c=e[o-1],f=e[o],m=e[o+1],d=Math.abs(f.x-c.x)+Math.abs(f.y-c.y),g=Math.abs(m.x-f.x)+Math.abs(m.y-f.y),b=Math.min(r,d/2,g/2);if(b>.5){const E=f.x-c.x,C=f.y-c.y,S=m.x-f.x,j=m.y-f.y,L=Math.sqrt(E*E+C*C)||1,A=Math.sqrt(S*S+j*j)||1;a+=` L ${f.x-E/L*b},${f.y-C/L*b}`,a+=` Q ${f.x},${f.y} ${f.x+S/A*b},${f.y+j/A*b}`}else a+=` L ${f.x},${f.y}`}return a+=` L ${e[e.length-1].x},${e[e.length-1].y}`,a}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 a=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-a.x)*t,d=o.y+(c.y-a.y)*t,g=c.x-(f.x-o.x)*t,b=c.y-(f.y-o.y)*t;n+=` C ${m},${d} ${g},${b} ${c.x},${c.y}`}return n}function Pn(e){if(!e||e.length<2)return{x:0,y:0};let t=0;for(let r=1;r<e.length;r++)t+=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);let n=t/2;for(let r=1;r<e.length;r++){const a=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);if(n<=a){const o=a>0?n/a:0;return{x:e[r-1].x+(e[r].x-e[r-1].x)*o,y:e[r-1].y+(e[r].y-e[r-1].y)*o}}n-=a}return{x:e[0].x,y:e[0].y}}function No(e,t){if(!e||!t||e.length===0||t.length===0)return t;const n={};for(const o of e)n[o.id]=o;const r=or(e,null),a=t.map(o=>{var N,O,X,H;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),g=yr(m,"target",o.targetHandle),b=zn(d,Sn),E=zn(g,Sn),C=5,S=r.filter(w=>w.id!==o.source&&w.id!==o.target),j=f._absolutePosition||f.position,L=f.width||((N=f.measured)==null?void 0:N.width)||Cn,A=f.height||((O=f.measured)==null?void 0:O.height)||En;S.push({id:o.source,x:j.x-C,y:j.y-C,w:L+2*C,h:A+2*C});const Y=m._absolutePosition||m.position,D=m.width||((X=m.measured)==null?void 0:X.width)||Cn,F=m.height||((H=m.measured)==null?void 0:H.height)||En;if(S.push({id:o.target,x:Y.x-C,y:Y.y-C,w:D+2*C,h:F+2*C}),S.length===0)return o;const $=Br(b,E,S);return $&&$.length>=2?($.unshift({x:d.x,y:d.y}),$.push({x:g.x,y:g.y}),{...o,_routedPoints:$}):o});return So(a)}function Po(e,t,n,r,a,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:a||"right"},g={x:n,y:r,dir:o||"left"},b=zn(d,Sn),E=zn(g,Sn),C=Br(b,E,m);return C&&C.length>=2?(C.unshift({x:d.x,y:d.y}),C.push({x:g.x,y:g.y}),C):null}const sr=l.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,label:c,labelStyle:f,labelShowBg:m,labelBgStyle:d,labelBgPadding:g,labelBgBorderRadius:b,style:E,markerEnd:C,markerStart:S,interactionWidth:j,routedPoints:L}){let A,Y,D;if(L&&L.length>=2){A=Nn(L);const F=Pn(L);Y=F.x,D=F.y}else[A,Y,D]=tr({sourceX:n,sourceY:r,targetX:a,targetY:o});return T.jsx(an,{id:t,path:A,labelX:Y,labelY:D,label:c,labelStyle:f,labelShowBg:m,labelBgStyle:d,labelBgPadding:g,labelBgBorderRadius:b,style:E,markerEnd:C,markerStart:S,interactionWidth:j})});sr.displayName="StraightEdge";const ar=l.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:c="bottom",targetPosition:f="top",label:m,labelStyle:d,labelShowBg:g,labelBgStyle:b,labelBgPadding:E,labelBgBorderRadius:C,style:S,markerEnd:j,markerStart:L,pathOptions:A,interactionWidth:Y,routedPoints:D}){let F,$,N;if(D&&D.length>=2){F=Nn(D);const O=Pn(D);$=O.x,N=O.y}else[F,$,N]=kn({sourceX:n,sourceY:r,sourcePosition:c,targetX:a,targetY:o,targetPosition:f,borderRadius:A==null?void 0:A.borderRadius,offset:A==null?void 0:A.offset});return T.jsx(an,{id:t,path:F,labelX:$,labelY:N,label:m,labelStyle:d,labelShowBg:g,labelBgStyle:b,labelBgPadding:E,labelBgBorderRadius:C,style:S,markerEnd:j,markerStart:L,interactionWidth:Y})});ar.displayName="SmoothStepEdge";const $r=l.memo(function({id:t,...n}){var a;const r=l.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(a=n.pathOptions)==null?void 0:a.offset]);return T.jsx(ar,{...n,id:t,pathOptions:r})});$r.displayName="StepEdge";const ir=l.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:c,targetPosition:f,label:m,labelStyle:d,labelShowBg:g,labelBgStyle:b,labelBgPadding:E,labelBgBorderRadius:C,style:S,markerEnd:j,markerStart:L,interactionWidth:A,routedPoints:Y}){let D,F,$;if(Y&&Y.length>=2){D=Nn(Y);const N=Pn(Y);F=N.x,$=N.y}else[D,F,$]=rr({sourceX:n,sourceY:r,targetX:a,targetY:o});return T.jsx(an,{id:t,path:D,labelX:F,labelY:$,label:m,labelStyle:d,labelShowBg:g,labelBgStyle:b,labelBgPadding:E,labelBgBorderRadius:C,style:S,markerEnd:j,markerStart:L,interactionWidth:A})});ir.displayName="SimpleBezierEdge";const Io={input:Nr,output:Pr,group:Ir},To={bezier:er,straight:sr,simplebezier:ir},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,a;return((r=n.measured)==null?void 0:r.width)!=null&&((a=n.measured)==null?void 0:a.height)!=null?n:{...n,measured:{width:n.width||Lo,height:n.height||Bo}}}):e}function jo({cards:e,nodes:t=[],edges:n=[],nodeTypes:r,edgeTypes:a,canvasNodeTypes:o,domNodeLimit:c=50,dark:f,gridSize:m,width:d="100%",height:g="420px",className:b="",style:E={},zoomMin:C,zoomMax:S,initialCamera:j,fitView:L,fitViewOptions:A,onNodesChange:Y,onEdgesChange:D,onConnect:F,onConnectStart:$,onConnectEnd:N,onNodeClick:O,onNodeDoubleClick:X,onNodeMouseEnter:H,onNodeMouseMove:w,onNodeMouseLeave:y,onNodeContextMenu:v,onNodeDragStart:z,onNodeDrag:P,onNodeDragStop:B,onEdgeClick:G,onEdgeDoubleClick:ne,onEdgeMouseEnter:ee,onEdgeMouseMove:se,onEdgeMouseLeave:he,onEdgeContextMenu:ge,onPaneClick:de,onPaneContextMenu:Re,onPaneMouseEnter:We,onPaneMouseMove:V,onPaneMouseLeave:oe,onSelectionChange:xe,onInit:Ze,onMoveStart:fe,onMove:je,onMoveEnd:Ae,onDelete:Pe,onBeforeDelete:Ce,onError:rt,onDragOver:at,onDrop:be,onDragEnter:Ie,onDragLeave:Je,nodesDraggable:$e,nodesConnectable:Ye,elementsSelectable:Ge,multiSelectionKeyCode:Nt,selectionOnDrag:cn,selectionMode:Pt,connectionMode:ln,connectionRadius:un,connectOnClick:dn,isValidConnection:fn,defaultEdgeOptions:Gt,snapToGrid:xt,snapGrid:pt,deleteKeyCode:It,panActivationKeyCode:In,panOnScroll:Tn,panOnScrollMode:it,panOnScrollSpeed:cr,zoomOnScroll:Ln,zoomOnDoubleClick:Bn,zoomOnPinch:Tt,preventScrolling:Lt,translateExtent:$n,nodeExtent:jn,autoPanOnNodeDrag:An,autoPanOnConnect:Ct,autoPanSpeed:pe,edgesReconnectable:Bt,elevateNodesOnSelect:Te,elevateEdgesOnSelect:ce,noDragClassName:mt,noPanClassName:K,onSelectionDragStart:Ee,onSelectionDrag:hn,onSelectionDragStop:$t,edgeRouting:jt=!0,onHudUpdate:At,onNodesProcessed:Dn,showHud:Xe=!0,showHint:Ue=!0,hintText:Dt="Drag to pan · Scroll to zoom",children:ct,...gn}){const[Ke,yn]=l.useState({wx:0,wy:0,zoom:"1.00"}),xn=l.useRef(null),Qt=l.useRef(null),pn=l.useCallback(_=>{yn(_),At==null||At(_)},[At]),vt=l.useMemo(()=>({...Io,...r}),[r]),lt=l.useMemo(()=>({...To,...a}),[a]),et=l.useMemo(()=>$o(t),[t]),[Z,ut]=l.useState(()=>new Set),Ht=l.useRef(Z);Ht.current=Z;const _t=l.useCallback(_=>{ut(we=>{const ie=new Set(we);return ie.add(_),ie})},[]),Wt=l.useCallback(_=>{ut(we=>{const ie=new Set(we);return ie.delete(_),ie})},[]),Ft=l.useCallback(_=>{ut(we=>{const ie=new Set(we);return ie.has(_)?ie.delete(_):ie.add(_),ie})},[]),Et=l.useMemo(()=>et.filter(_=>_.type&&vt[_.type]),[et,vt]),bt=l.useMemo(()=>{var we,ie;if(c===0)return new Set;const _=new Set;for(const ve of Z)_.add(ve);for(const ve of Et)(ve.selected||ve.dragging)&&_.add(ve.id);if(_.size<c){const ve=((we=le.cameraRef)==null?void 0:we.current)||{x:0,y:0,zoom:1},Be=(ie=le.wrapRef)==null?void 0:ie.current,Se=(Be==null?void 0:Be.clientWidth)||800,De=(Be==null?void 0:Be.clientHeight)||600,gt=(-ve.x+Se/2)/ve.zoom,kt=(-ve.y+De/2)/ve.zoom,u=Et.filter(i=>!_.has(i.id)).map(i=>{const h=i._absolutePosition||i.position,M=h.x+(i.width||160)/2-gt,k=h.y+(i.height||60)/2-kt;return{id:i.id,dist:M*M+k*k}}).sort((i,h)=>i.dist-h.dist),x=c-_.size;for(let i=0;i<Math.min(x,u.length);i++)_.add(u[i].id)}return _},[Et,Z,c,le.cameraRef,le.wrapRef]),ot=l.useMemo(()=>{const _=et.filter(we=>bt.has(we.id));return _.sort((we,ie)=>{const ve=we.type==="group"||!we.parentId&&_.some(Se=>Se.parentId===we.id),Be=ie.type==="group"||!ie.parentId&&_.some(Se=>Se.parentId===ie.id);return ve&&!Be?-1:!ve&&Be?1:0})},[et,bt]),Yt=l.useMemo(()=>n.filter(_=>_.type&<[_.type]),[n,lt]),Vt=l.useMemo(()=>t.map(_=>bt.has(_.id)?{..._,_customRendered:!0}:_),[t,bt]),Le=l.useMemo(()=>n.map(_=>_.type&<[_.type]?{..._,_customRendered:!0}:_),[n,lt]),{wrapRef:mn,canvasRef:Fe,canvasReady:Hn,onPointerDown:wt,onPointerMove:Xt,onPointerUp:dt,store:le}=Mr({cards:e,nodes:Vt,edges:Le,dark:f,gridSize:m,zoomMin:C,zoomMax:S,initialCamera:j,fitView:L,fitViewOptions:A,onHudUpdate:pn,onNodesProcessed:Dn,onNodesChange:Y,onEdgesChange:D,onConnect:F,onConnectStart:$,onConnectEnd:N,onNodeClick:O,onNodeDoubleClick:X,onNodeMouseEnter:H,onNodeMouseMove:w,onNodeMouseLeave:y,onNodeContextMenu:v,onNodeDragStart:z,onNodeDrag:P,onNodeDragStop:B,onEdgeClick:G,onEdgeDoubleClick:ne,onEdgeMouseEnter:ee,onEdgeMouseMove:se,onEdgeMouseLeave:he,onEdgeContextMenu:ge,onPaneClick:de,onPaneContextMenu:Re,onPaneMouseEnter:We,onPaneMouseMove:V,onPaneMouseLeave:oe,onSelectionChange:xe,onInit:Ze,onMoveStart:fe,onMove:je,onMoveEnd:Ae,onDelete:Pe,onBeforeDelete:Ce,onError:rt,nodesDraggable:$e,nodesConnectable:Ye,elementsSelectable:Ge,multiSelectionKeyCode:Nt,selectionOnDrag:cn,selectionMode:Pt,connectionMode:ln,connectionRadius:un,connectOnClick:dn,isValidConnection:fn,defaultEdgeOptions:Gt,snapToGrid:xt,snapGrid:pt,deleteKeyCode:It,panActivationKeyCode:In,panOnScroll:Tn,panOnScrollMode:it,panOnScrollSpeed:cr,zoomOnScroll:Ln,zoomOnDoubleClick:Bn,zoomOnPinch:Tt,preventScrolling:Lt,translateExtent:$n,nodeExtent:jn,autoPanOnNodeDrag:An,autoPanOnConnect:Ct,autoPanSpeed:pe,edgesReconnectable:Bt,elevateNodesOnSelect:Te,elevateEdgesOnSelect:ce,noDragClassName:mt,noPanClassName:K,onSelectionDragStart:Ee,onSelectionDrag:hn,onSelectionDragStop:$t,edgeRouting:jt}),Ot=l.useRef(new Set);l.useEffect(()=>{if(!o||!le.workerRef.current)return;let _=!1;async function we(ve){const Be=new Blob([ve],{type:"image/svg+xml"}),Se=URL.createObjectURL(Be),De=new Image;return De.src=Se,await De.decode(),URL.revokeObjectURL(Se),createImageBitmap(De)}async function ie(){var gt,kt,u;const ve={},Be=[],Se={},De={};for(const[x,i]of Object.entries(o)){if(typeof i=="function"){Se[x]=i;continue}if(typeof i=="object"&&i!==null&&!(i instanceof ImageBitmap)&&!(i instanceof HTMLImageElement)&&!(i instanceof HTMLCanvasElement)&&("fill"in i||"stroke"in i||"title"in i||"accent"in i)){De[x]=i;continue}try{let h;i instanceof ImageBitmap?h=i:typeof i=="string"?h=await we(i):i instanceof HTMLImageElement?h=await createImageBitmap(i):i instanceof HTMLCanvasElement&&(h=await createImageBitmap(i)),h&&!_&&(ve[x]=h,Be.push(h))}catch(h){console.warn(`[InfiniteCanvas] Failed to convert canvasNodeType "${x}":`,h)}}if(!_&&Object.keys(ve).length>0&&((gt=le.workerRef.current)==null||gt.postMessage({type:"nodeTypeBitmaps",data:{bitmaps:ve}},Be)),!_&&Object.keys(De).length>0&&((kt=le.workerRef.current)==null||kt.postMessage({type:"nodeTypeConfigs",data:{configs:De}})),!_&&Object.keys(Se).length>0){const x=new Map,i={},h={},M=[];let k=Ot.current.size;for(const p of t){const I=Se[p.type];if(I)try{const R=I(p.data);if(!R)continue;let U=x.get(R);if(!U&&(U="bmp_"+k++,x.set(R,U),!Ot.current.has(R))){const W=await we(R);if(_)return;i[U]=W,M.push(W),Ot.current.add(R)}h[p.id]=U}catch(R){console.warn(`[InfiniteCanvas] canvasNodeType fn error for node "${p.id}":`,R)}}_||(u=le.workerRef.current)==null||u.postMessage({type:"nodeBitmaps",data:{cache:i,keys:h}},M)}}return ie(),()=>{_=!0}},[o,t,le.workerRef]);const ke=l.useContext(zt),tt=ke&&typeof ke.getState=="function";l.useEffect(()=>{tt&&queueMicrotask(()=>{ke.setState({nodes:et,edges:n,nodesRef:le.nodesRef,edgesRef:le.edgesRef,onNodesChangeRef:le.onNodesChangeRef,onEdgesChangeRef:le.onEdgesChangeRef,cameraRef:le.cameraRef,wrapRef:le.wrapRef,workerRef:le.workerRef})})},[tt,et,n,le,ke]);const vn=l.useMemo(()=>({...le,edgeLabelContainerRef:xn,viewportPortalRef:Qt,pinNode:_t,unpinNode:Wt,togglePinNode:Ft,get pinnedNodeIds(){return Ht.current},get nodes(){return et},get edges(){return n},get viewport(){return le.cameraRef.current},get minZoom(){return le.zoomMin||.1},get maxZoom(){return le.zoomMax||5},get domNode(){return le.wrapRef.current},get width(){var _;return((_=le.wrapRef.current)==null?void 0:_.clientWidth)||0},get height(){var _;return((_=le.wrapRef.current)==null?void 0:_.clientHeight)||0}}),[le,et,n,_t,Wt,Ft]),Ut=l.useRef(null),Mt=l.useRef(null),nt=l.useRef(null),qt=l.useRef(null),me=l.useRef(null);l.useEffect(()=>{let _;const we=()=>{const ie=le.cameraRef.current,ve=`translate(${ie.x}px, ${ie.y}px) scale(${ie.zoom})`,Be=`translate(${ie.x}, ${ie.y}) scale(${ie.zoom})`;Ut.current&&(Ut.current.style.transform=ve),Mt.current&&Mt.current.setAttribute("transform",Be),nt.current&&(nt.current.style.transform=ve),qt.current&&(qt.current.style.transform=ve);const Se=mn.current;if(Se){const De=ie.zoom<.15?"lod-minimal":ie.zoom<.35?"lod-reduced":null;De!==me.current&&(Se.classList.remove("lod-minimal","lod-reduced"),De&&Se.classList.add(De),me.current=De)}_=requestAnimationFrame(we)};return _=requestAnimationFrame(we),()=>cancelAnimationFrame(_)},[le]);const[ft,Rt]=l.useState(null);l.useEffect(()=>{if(!ot.length)return;let _;const we=()=>{var i,h;const ie=le.cameraRef.current,ve=le.wrapRef.current;if(!ve){_=requestAnimationFrame(we);return}const Be=ve.getBoundingClientRect(),Se=200,De=-ie.x/ie.zoom-Se,gt=-ie.y/ie.zoom-Se,kt=(Be.width-ie.x)/ie.zoom+Se,u=(Be.height-ie.y)/ie.zoom+Se,x=new Set;for(const M of ot){const k=M._absolutePosition||M.position,p=M.width||((i=M.measured)==null?void 0:i.width)||200,I=M.height||((h=M.measured)==null?void 0:h.height)||100;k.x+p>=De&&k.x<=kt&&k.y+I>=gt&&k.y<=u&&x.add(M.id)}Rt(M=>{if(!M||M.size!==x.size)return x;for(const k of x)if(!M.has(k))return x;return M}),_=requestAnimationFrame(we)};return _=requestAnimationFrame(we),()=>cancelAnimationFrame(_)},[ot,le]);const _n=l.useMemo(()=>ft?ot.filter(_=>ft.has(_.id)):ot,[ot,ft]),Wn=ot.length>0,Fn=Yt.length>0;return T.jsx(zt.Provider,{value:vn,children:T.jsxs("div",{ref:mn,className:`ric-wrap ${b}`,style:{width:d,height:g,...E},onPointerDown:wt,onPointerMove:Xt,onPointerUp:dt,onDragOver:at,onDrop:be,onDragEnter:Ie,onDragLeave:Je,tabIndex:0,children:[T.jsx("canvas",{ref:Fe,className:"ric-canvas"}),!Hn&&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:Mt,children:Yt.map(_=>T.jsx(yo,{edge:_,edgeType:lt[_.type],nodes:t,reconnectable:Bt},_.id))})}),Wn&&T.jsx("div",{ref:Ut,className:"ric-nodes-overlay",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:10},children:_n.map(_=>T.jsx(uo,{node:_,nodeType:vt[_.type]},_.id))}),T.jsx("div",{ref:_=>{xn.current=_,nt.current=_},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:_=>{Qt.current=_,qt.current=_},className:"ric-viewport-portal",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:6}}),Ue&&T.jsx("div",{className:"ric-hint",children:Dt}),Xe&&T.jsxs("div",{className:"ric-info",children:["world: (",Ke.wx,", ",Ke.wy,") zoom: ",Ke.zoom,"x",Ke.nodeCount>0&&T.jsxs(T.Fragment,{children:[" nodes: ",Ke.nodeCount]}),Ke.edgeCount>0&&T.jsxs(T.Fragment,{children:[" edges: ",Ke.edgeCount]})]}),T.jsx(Sr,{selectionKeyCode:Nt||"Shift",selectionMode:Pt||"partial"}),ct]})})}function Ao({children:e}){const t=l.useRef(null);return t.current||(t.current=io()),T.jsx(zt.Provider,{value:t.current,children:e})}function jr(e,t){const n=[],r=new Map,a=[];for(const o of e)if(o.type==="add")a.push(o);else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const c=r.get(o.id);c?c.push(o):r.set(o.id,[o])}for(const o of t){const c=r.get(o.id);if(!c){n.push(o);continue}if(c[0].type==="remove")continue;if(c[0].type==="replace"){n.push({...c[0].item});continue}const f={...o};for(const m of c)Do(m,f);n.push(f)}for(const o of a)o.index!==void 0?n.splice(o.index,0,{...o.item}):n.push({...o.item});return n}function Do(e,t){switch(e.type){case"select":t.selected=e.selected;break;case"position":e.position!==void 0&&(t.position=e.position),e.dragging!==void 0&&(t.dragging=e.dragging);break;case"dimensions":e.dimensions!==void 0&&(t.measured={...e.dimensions},(e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height)),e.handleBounds!==void 0&&(t.handleBounds=e.handleBounds);break}}function 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]=l.useState(e),r=l.useCallback(a=>n(o=>Ar(a,o)),[]);return[t,n,r]}function Wo(e){const[t,n]=l.useState(e),r=l.useCallback(a=>n(o=>Dr(a,o)),[]);return[t,n,r]}function Hr(){const e=Rr(),t=l.useCallback(()=>typeof e.getState=="function"?e.getState():e,[e]),n=l.useCallback(()=>[...t().nodesRef.current],[t]),r=l.useCallback(()=>[...t().edgesRef.current],[t]),a=l.useCallback(w=>t().nodesRef.current.find(y=>y.id===w),[t]),o=l.useCallback(w=>t().edgesRef.current.find(y=>y.id===w),[t]),c=l.useCallback(w=>{var y,v,z,P;if(typeof w=="function"){const B=w(t().nodesRef.current);(v=(y=t().onNodesChangeRef).current)==null||v.call(y,[...t().nodesRef.current.map(G=>({id:G.id,type:"remove"})),...B.map(G=>({type:"add",item:G}))])}else(P=(z=t().onNodesChangeRef).current)==null||P.call(z,[...t().nodesRef.current.map(B=>({id:B.id,type:"remove"})),...w.map(B=>({type:"add",item:B}))])},[t]),f=l.useCallback(w=>{var y,v,z,P;if(typeof w=="function"){const B=w(t().edgesRef.current);(v=(y=t().onEdgesChangeRef).current)==null||v.call(y,[...t().edgesRef.current.map(G=>({id:G.id,type:"remove"})),...B.map(G=>({type:"add",item:G}))])}else(P=(z=t().onEdgesChangeRef).current)==null||P.call(z,[...t().edgesRef.current.map(B=>({id:B.id,type:"remove"})),...w.map(B=>({type:"add",item:B}))])},[t]),m=l.useCallback(w=>{var v,z;const y=Array.isArray(w)?w:[w];(z=(v=t().onNodesChangeRef).current)==null||z.call(v,y.map(P=>({type:"add",item:P})))},[t]),d=l.useCallback(w=>{var v,z;const y=Array.isArray(w)?w:[w];(z=(v=t().onEdgesChangeRef).current)==null||z.call(v,y.map(P=>({type:"add",item:P})))},[t]),g=l.useCallback(({nodes:w=[],edges:y=[]})=>{if(w.length&&t().onNodesChangeRef.current){t().onNodesChangeRef.current(w.map(z=>({id:z.id,type:"remove"})));const v=br(w,t().edgesRef.current);v.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(v.map(z=>({id:z.id,type:"remove"})))}y.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(y.map(v=>({id:v.id,type:"remove"})))},[t]),b=l.useCallback(()=>{const w=t().cameraRef.current;return{x:w.x,y:w.y,zoom:w.zoom}},[t]),E=l.useRef(null),C=l.useCallback((w,y)=>{if(E.current&&cancelAnimationFrame(E.current),!y||y<=0){t().cameraRef.current={...w},t().sendCamera();return}const v={...t().cameraRef.current},z=performance.now(),P=B=>{const G=B-z,ne=Math.min(G/y,1),ee=1-Math.pow(1-ne,3);t().cameraRef.current={x:v.x+(w.x-v.x)*ee,y:v.y+(w.y-v.y)*ee,zoom:v.zoom+(w.zoom-v.zoom)*ee},t().sendCamera(),ne<1&&(E.current=requestAnimationFrame(P))};E.current=requestAnimationFrame(P)},[t]),S=l.useCallback((w,y)=>{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,y==null?void 0:y.duration)},[t,C]),j=l.useCallback(()=>t().cameraRef.current.zoom,[t]),L=l.useCallback(w=>{const y=t().cameraRef.current,v=t().wrapRef.current;if(!v)return;const z=v.getBoundingClientRect(),P=z.width/2,B=z.height/2,G=1.2,ne={x:P-(P-y.x)*G,y:B-(B-y.y)*G,zoom:Math.min(t().zoomMax,y.zoom*G)};C(ne,w==null?void 0:w.duration)},[t,C]),A=l.useCallback(w=>{const y=t().cameraRef.current,v=t().wrapRef.current;if(!v)return;const z=v.getBoundingClientRect(),P=z.width/2,B=z.height/2,G=1/1.2,ne={x:P-(P-y.x)*G,y:B-(B-y.y)*G,zoom:Math.max(t().zoomMin,y.zoom*G)};C(ne,w==null?void 0:w.duration)},[t,C]),Y=l.useCallback((w,y)=>{const v=t().cameraRef.current,z=t().wrapRef.current;if(!z)return;const P=z.getBoundingClientRect(),B=P.width/2,G=P.height/2,ne=Math.min(t().zoomMax,Math.max(t().zoomMin,w)),ee=ne/v.zoom,se={x:B-(B-v.x)*ee,y:G-(G-v.y)*ee,zoom:ne};C(se,y==null?void 0:y.duration)},[t,C]),D=l.useCallback((w={})=>{const y=t().nodesRef.current;if(!y.length)return;const v=t().wrapRef.current;if(!v)return;const z=v.getBoundingClientRect(),P=w.padding??.1,B=w.nodes?y.filter(ee=>w.nodes.some(se=>se.id===ee.id)):y;if(!B.length)return;const G=Rn(B),ne=Zt(G,z.width,z.height,P);w.maxZoom&&(ne.zoom=Math.min(ne.zoom,w.maxZoom)),w.minZoom&&(ne.zoom=Math.max(ne.zoom,w.minZoom)),C(ne,w.duration)},[t,C]),F=l.useCallback((w,y={})=>{const v=t().wrapRef.current;if(!v)return;const z=v.getBoundingClientRect(),P=y.padding??.1,B=Zt(w,z.width,z.height,P);y.maxZoom&&(B.zoom=Math.min(B.zoom,y.maxZoom)),y.minZoom&&(B.zoom=Math.max(B.zoom,y.minZoom)),C(B,y.duration)},[t,C]),$=l.useCallback((w,y,v={})=>{const z=t().wrapRef.current;if(!z)return;const P=z.getBoundingClientRect(),B=v.zoom??t().cameraRef.current.zoom,G={x:P.width/2-w*B,y:P.height/2-y*B,zoom:B};C(G,v.duration)},[t,C]),N=l.useCallback(()=>({nodes:[...t().nodesRef.current],edges:[...t().edgesRef.current],viewport:{...t().cameraRef.current}}),[t]),O=l.useCallback(w=>t().screenToWorld(w.x,w.y),[t]),X=l.useCallback(w=>{const y=t().cameraRef.current,v=t().wrapRef.current;if(!v)return{x:0,y:0};const z=v.getBoundingClientRect();return{x:w.x*y.zoom+y.x+z.left,y:w.y*y.zoom+y.y+z.top}},[t]),H=l.useCallback((w,y)=>{var P,B;const v=t().nodesRef.current.find(G=>G.id===w);if(!v)return;const z=typeof y=="function"?y(v.data):{...v.data,...y};(B=(P=t().onNodesChangeRef).current)==null||B.call(P,[{id:w,type:"replace",item:{...v,data:z}}])},[t]);return{getNodes:n,getEdges:r,getNode:a,getEdge:o,setNodes:c,setEdges:f,addNodes:m,addEdges:d,deleteElements:g,getViewport:b,setViewport:S,getZoom:j,zoomIn:L,zoomOut:A,zoomTo:Y,fitView:D,fitBounds:F,setCenter:$,screenToFlowPosition:O,flowToScreenPosition:X,updateNodeData:H,toObject:N}}function Fo(){return Ne().nodes}function Yo(){return Ne().edges}function Xo(){return Ne().viewport}function Oo(){return Ne().connection}function Uo(e){const t=Ne(),n=Array.isArray(e)?e:[e];return l.useMemo(()=>n.map(r=>{const a=t.nodes.find(o=>o.id===r);return a?{id:a.id,type:a.type,data:a.data}:null}).filter(Boolean),[t.nodes,...n])}function qo(e){const t=Ne();return l.useMemo(()=>t.edges.filter(n=>n.source===e||n.target===e),[t.edges,e])}function Zo({nodeId:e,type:t,handleId:n}){const r=Ne();return l.useMemo(()=>r.edges.filter(a=>t==="source"?a.source===e&&(n?a.sourceHandle===n:!0):a.target===e&&(n?a.targetHandle===n:!0)),[r.edges,e,t,n])}function Go({onChange:e,onStart:t,onEnd:n}){const r=Ne(),a=l.useRef(e),o=l.useRef(t),c=l.useRef(n);l.useEffect(()=>{a.current=e},[e]),l.useEffect(()=>{o.current=t},[t]),l.useEffect(()=>{c.current=n},[n]),l.useEffect(()=>{const f=m=>{var d;(d=a.current)==null||d.call(a,{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=Ne(),n=l.useRef(e);l.useEffect(()=>{n.current=e},[e]),l.useEffect(()=>{const r=a=>{var o;(o=n.current)==null||o.call(n,a)};return t.selectionListeners.add(r),()=>t.selectionListeners.delete(r)},[s])}function Vo(e){const[t,n]=l.useState(!1),r=Array.isArray(e)?e:[e];return l.useEffect(()=>{const a=c=>{r.includes(c.key)&&n(!0)},o=c=>{r.includes(c.key)&&n(!1)};return window.addEventListener("keydown",a),window.addEventListener("keyup",o),()=>{window.removeEventListener("keydown",a),window.removeEventListener("keyup",o)}},[r.join(",")]),t}function Jo(){const e=Ne();return l.useCallback(t=>{var n;(n=e.workerRef.current)==null||n.postMessage({type:"nodes",data:{nodes:[...s().nodesRef.current]}})},[s])}const Ko=e=>{var t;return((t=e.nodes)==null?void 0:t.length)>0};function es(e={}){return Ne(Ko)}function ts(e){const t=Ne();return l.useMemo(()=>t.nodes.find(n=>n.id===e)||void 0,[t.nodes,e])}function ns(e,t){return Ne(e,t)}function rs(){return Rr()}function os({maxHistorySize:e=100}={}){const t=Ne(),n=l.useRef([]),r=l.useRef([]),[,a]=l.useState(0),o=l.useRef(null),c=l.useCallback(()=>{const d={nodes:s().nodesRef.current.map(g=>({...g,data:{...g.data}})),edges:s().edgesRef.current.map(g=>({...g}))};o.current&&JSON.stringify(o.current.nodes.map(g=>g.id))===JSON.stringify(d.nodes.map(g=>g.id))&&JSON.stringify(o.current.edges.map(g=>g.id))===JSON.stringify(d.edges.map(g=>g.id))||(n.current.push(d),n.current.length>e&&n.current.shift(),r.current=[],o.current=d,a(g=>g+1))},[t,e]),f=l.useCallback(()=>{var g,b,E,C;const d=n.current.pop();d&&(r.current.push({nodes:s().nodesRef.current.map(S=>({...S,data:{...S.data}})),edges:s().edgesRef.current.map(S=>({...S}))}),(b=(g=s().onNodesChangeRef).current)==null||b.call(g,[...s().nodesRef.current.map(S=>({id:S.id,type:"remove"})),...d.nodes.map(S=>({type:"add",item:S}))]),(C=(E=s().onEdgesChangeRef).current)==null||C.call(E,[...s().edgesRef.current.map(S=>({id:S.id,type:"remove"})),...d.edges.map(S=>({type:"add",item:S}))]),o.current=d,a(S=>S+1))},[s]),m=l.useCallback(()=>{var g,b,E,C;const d=r.current.pop();d&&(n.current.push({nodes:s().nodesRef.current.map(S=>({...S,data:{...S.data}})),edges:s().edgesRef.current.map(S=>({...S}))}),(b=(g=s().onNodesChangeRef).current)==null||b.call(g,[...s().nodesRef.current.map(S=>({id:S.id,type:"remove"})),...d.nodes.map(S=>({type:"add",item:S}))]),(C=(E=s().onEdgesChangeRef).current)==null||C.call(E,[...s().edgesRef.current.map(S=>({id:S.id,type:"remove"})),...d.edges.map(S=>({type:"add",item:S}))]),o.current=d,a(S=>S+1))},[s]);return{undo:f,redo:m,takeSnapshot:c,canUndo:n.current.length>0,canRedo:r.current.length>0}}function ss(e){const t=l.useRef(e);return l.useEffect(()=>{t.current=e},[e]),l.useCallback(n=>r=>{const a=t.current(r);a!==!1&&a!=null&&n(Array.isArray(a)?a:r)},[])}function as(e){const t=l.useRef(e);return l.useEffect(()=>{t.current=e},[e]),l.useCallback(n=>r=>{const a=t.current(r);a!==!1&&a!=null&&n(Array.isArray(a)?a:r)},[])}const Un=160,qn=60;function is({width:e=200,height:t=150,nodeColor:n="#3b82f6",nodeStrokeColor:r="#fff",maskColor:a="rgba(0,0,0,0.1)",style:o={},className:c=""}){const f=Ne(),m=l.useRef(null),d=l.useRef(null),g=l.useCallback(()=>{const b=m.current;if(!b)return;const E=b.getContext("2d"),C=window.devicePixelRatio||1;b.width=e*C,b.height=t*C,E.scale(C,C),E.clearRect(0,0,e,t);const S=f.nodesRef.current;if(!S.length)return;let j=1/0,L=1/0,A=-1/0,Y=-1/0;for(const y of S){const v=y.width||Un,z=y.height||qn;y.position.x<j&&(j=y.position.x),y.position.y<L&&(L=y.position.y),y.position.x+v>A&&(A=y.position.x+v),y.position.y+z>Y&&(Y=y.position.y+z)}const D=40;j-=D,L-=D,A+=D,Y+=D;const F=A-j,$=Y-L,N=Math.min(e/F,t/$),O=(e-F*N)/2,X=(t-$*N)/2;for(const y of S){if(y.hidden)continue;const v=y.width||Un,z=y.height||qn,P=(y.position.x-j)*N+O,B=(y.position.y-L)*N+X,G=v*N,ne=z*N;E.fillStyle=y.selected?"#f59e0b":typeof n=="function"?n(y):n,E.fillRect(P,B,Math.max(G,2),Math.max(ne,2))}const H=f.cameraRef.current,w=f.wrapRef.current;if(w){const y=w.getBoundingClientRect(),v=-H.x/H.zoom,z=-H.y/H.zoom,P=y.width/H.zoom,B=y.height/H.zoom;E.fillStyle=a,E.fillRect(0,0,e,t);const G=(v-j)*N+O,ne=(z-L)*N+X,ee=P*N,se=B*N;E.clearRect(G,ne,ee,se);for(const he of S){if(he.hidden)continue;const ge=he.width||Un,de=he.height||qn,Re=(he.position.x-j)*N+O,We=(he.position.y-L)*N+X;E.fillStyle=he.selected?"#f59e0b":typeof n=="function"?n(he):n,E.fillRect(Re,We,Math.max(ge*N,2),Math.max(de*N,2))}E.strokeStyle="#3b82f6",E.lineWidth=1.5,E.strokeRect(G,ne,ee,se)}},[f,e,t,n,r,a]);return l.useEffect(()=>{let b=!0;function E(){b&&(g(),d.current=requestAnimationFrame(E))}const C=setInterval(()=>{cancelAnimationFrame(d.current),d.current=requestAnimationFrame(E)},66);return g(),()=>{b=!1,clearInterval(C),cancelAnimationFrame(d.current)}},[g]),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 rn({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:a,onZoomOut:o,onFitView:c,onInteractiveChange:f,position:m="bottom-left",orientation:d="vertical",style:g={},className:b="","aria-label":E="Canvas controls",children:C}){const S=Ne(),{zoomIn:j,zoomOut:L,fitView:A,getZoom:Y}=Hr(),[D,F]=l.useState(!0),$=Y()<=S.zoomMin,N=Y()>=S.zoomMax,O=l.useCallback(()=>{j(),a==null||a()},[j,a]),X=l.useCallback(()=>{L(),o==null||o()},[L,o]),H=l.useCallback(()=>{A(r||{padding:.1}),c==null||c()},[A,r,c]),w=l.useCallback(()=>{const v=!D;F(v),f==null||f(v)},[D,f]),y={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:30,left:10},"bottom-right":{bottom:30,right:10},"bottom-center":{bottom:30,left:"50%",transform:"translateX(-50%)"}}[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,...y,...g},role:"toolbar","aria-label":E,children:[e&&T.jsxs(T.Fragment,{children:[T.jsx(rn,{onClick:O,disabled:N,title:"Zoom in","aria-label":"Zoom in",className:"ric-controls-zoomin",children:T.jsx(cs,{})}),T.jsx(rn,{onClick:X,disabled:$,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:T.jsx(ls,{})})]}),t&&T.jsx(rn,{onClick:H,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:T.jsx(us,{})}),n&&T.jsx(rn,{onClick:w,title:D?"Lock interactivity":"Unlock interactivity","aria-label":D?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:D?T.jsx(fs,{}):T.jsx(ds,{})}),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=l.memo(hs);function xs({variant:e="lines",gap:t=40,size:n=1,color:r,style:a={},className:o=""}){const c=Ne();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 a={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:10,left:10},"bottom-right":{bottom:10,right:10},"bottom-center":{bottom:10,left:"50%",transform:"translateX(-50%)"}}[e]||{top:10,left:10};return T.jsx("div",{className:`ric-panel ${n}`,style:{position:"absolute",zIndex:5,pointerEvents:"all",...a,...t},onPointerDown:o=>o.stopPropagation(),children:r})}function ms({minWidth:e=10,minHeight:t=10,maxWidth:n=1/0,maxHeight:r=1/0,isVisible:a=!0,handleStyle:o={},lineStyle:c={},color:f="#3b82f6",onResizeStart:m,onResize:d,onResizeEnd:g}){const b=l.useContext(sn),E=Ne(),C=l.useRef(null),S=l.useCallback((A,Y)=>{A.stopPropagation(),A.preventDefault();const D=E.nodesRef.current.find(N=>N.id===b);if(!D)return;C.current={direction:Y,startX:A.clientX,startY:A.clientY,width:D.width||160,height:D.height||60},m==null||m(A,{width:C.current.width,height:C.current.height});const F=N=>{var z,P;if(!C.current)return;const O=C.current,X=E.cameraRef.current,H=(N.clientX-O.startX)/X.zoom,w=(N.clientY-O.startY)/X.zoom;let y=O.width,v=O.height;O.direction.includes("e")&&(y=Math.min(n,Math.max(e,O.width+H))),O.direction.includes("w")&&(y=Math.min(n,Math.max(e,O.width-H))),O.direction.includes("s")&&(v=Math.min(r,Math.max(t,O.height+w))),O.direction.includes("n")&&(v=Math.min(r,Math.max(t,O.height-w))),(P=(z=E.onNodesChangeRef).current)==null||P.call(z,[{id:b,type:"dimensions",dimensions:{width:y,height:v},setAttributes:!0}]),d==null||d(N,{width:y,height:v})},$=N=>{C.current=null,g==null||g(N,{}),window.removeEventListener("pointermove",F),window.removeEventListener("pointerup",$)};window.addEventListener("pointermove",F),window.addEventListener("pointerup",$)},[b,E,e,t,n,r,m,d,g]);if(!a)return null;const j=8,L={position:"absolute",width:j,height:j,background:f,border:"1px solid #fff",borderRadius:2,zIndex:20,...o};return T.jsxs(T.Fragment,{children:[T.jsx("div",{style:{...L,bottom:-j/2,right:-j/2,cursor:"nwse-resize"},onPointerDown:A=>S(A,"se")}),T.jsx("div",{style:{...L,bottom:-j/2,left:-j/2,cursor:"nesw-resize"},onPointerDown:A=>S(A,"sw")}),T.jsx("div",{style:{...L,top:-j/2,right:-j/2,cursor:"nesw-resize"},onPointerDown:A=>S(A,"ne")}),T.jsx("div",{style:{...L,top:-j/2,left:-j/2,cursor:"nwse-resize"},onPointerDown:A=>S(A,"nw")}),T.jsx("div",{style:{...L,top:"50%",right:-j/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:A=>S(A,"e")}),T.jsx("div",{style:{...L,top:"50%",left:-j/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:A=>S(A,"w")}),T.jsx("div",{style:{...L,left:"50%",top:-j/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:A=>S(A,"n")}),T.jsx("div",{style:{...L,left:"50%",bottom:-j/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:A=>S(A,"s")})]})}function vs({isVisible:e,position:t="top",offset:n=10,align:r="center",children:a,style:o={},className:c=""}){const f=l.useContext(sn),d=Ne().nodes.find(E=>E.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:E=>E.stopPropagation(),children:a})}function bs({isVisible:e=!1,x:t=0,y:n=0,alignX:r="center",alignY:a="center",children:o,style:c={},className:f=""}){if(!e)return null;const m=r==="center"?"-50%":r==="right"?"-100%":"0",d=a==="center"?"-50%":a==="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=Ne().edgeLabelContainerRef)==null?void 0:r.current;return n?pr.createPortal(e,n):null}function Ms({children:e}){var r;const n=(r=Ne().viewportPortalRef)==null?void 0:r.current;return n?pr.createPortal(e,n):null}function _r({fromX:e,fromY:t,toX:n,toY:r,fromPosition:a="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:a,toPosition:o});let d;switch(c){case"straight":[d]=tr({sourceX:e,sourceY:t,targetX:n,targetY:r});break;case"step":[d]=kn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o,borderRadius:0});break;case"smoothstep":[d]=kn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,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:a,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=l.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=an;exports.BezierEdge=er;exports.ConnectionLine=Rs;exports.ControlButton=rn;exports.Controls=ys;exports.DefaultNode=vo;exports.EdgeLabelRenderer=ws;exports.EdgeText=Lr;exports.EdgeToolbar=bs;exports.GroupNode=Ir;exports.Handle=on;exports.InfiniteCanvas=jo;exports.InfiniteCanvasProvider=Ao;exports.InputNode=Nr;exports.MarkerType=Cs;exports.MiniMap=is;exports.NodeResizer=ms;exports.NodeToolbar=vs;exports.OutputNode=Pr;exports.Panel=ps;exports.Position=ks;exports.SelectionBox=Sr;exports.SimpleBezierEdge=ir;exports.SmoothStepEdge=ar;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=Vr;exports.getConnectedEdges=br;exports.getEdgeCenter=wo;exports.getIncomers=Ur;exports.getNodeDimensions=Kn;exports.getNodesBounds=Rn;exports.getNodesInside=Zr;exports.getOutgoers=qr;exports.getOverlappingArea=Jr;exports.getRoutedLabelPosition=Pn;exports.getSimpleBezierPath=rr;exports.getSmoothStepPath=kn;exports.getStraightPath=tr;exports.getViewportForBounds=Zt;exports.isEdge=Or;exports.isNode=Xr;exports.nodeToBox=Es;exports.nodeToRect=Kr;exports.reconnectEdge=Mo;exports.rectToBox=Gr;exports.routeSinglePath=Po;exports.routedPointsToPath=Nn;exports.snapPosition=Zn;exports.useConnection=Oo;exports.useEdges=Yo;exports.useEdgesState=Wo;exports.useHandleConnections=Zo;exports.useInfiniteCanvas=Mr;exports.useInternalNode=ts;exports.useKeyPress=Vo;exports.useNodeConnections=qo;exports.useNodeId=co;exports.useNodes=Fo;exports.useNodesData=Uo;exports.useNodesInitialized=es;exports.useNodesState=_o;exports.useOnEdgesChangeMiddleware=as;exports.useOnNodesChangeMiddleware=ss;exports.useOnSelectionChange=Qo;exports.useOnViewportChange=Go;exports.useReactFlow=Hr;exports.useStore=ns;exports.useStoreApi=rs;exports.useUndoRedo=os;exports.useUpdateNodeInternals=Jo;exports.useViewport=Xo;
|