@infinit-canvas/react 0.1.8 → 0.1.11
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/LICENSE +21 -0
- package/README.md +129 -37
- package/dist/react-infinite-canvas.cjs +513 -476
- package/dist/react-infinite-canvas.js +3273 -2806
- package/package.json +4 -2
- package/src/types.d.ts +88 -11
|
@@ -1,167 +1,185 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("react/jsx-runtime"),u=require("react"),dr=require("react-dom"),fr=160,hr=60;function Hr(e){return e&&typeof e=="object"&&"position"in e&&"data"in e}function _r(e){return e&&typeof e=="object"&&"source"in e&&"target"in e}function yr(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 Wr(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 Fr(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 yn(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 i=o.position.x,h=o.position.y,g=o.width||fr,d=o.height||hr;i<t&&(t=i),h<n&&(n=h),i+g>r&&(r=i+g),h+d>a&&(a=h+d)}return{x:t,y:n,width:r-t,height:a-n}}function Lt(e,t,n,r=.1){const a=e.width*(1+r*2),o=e.height*(1+r*2),i=Math.min(t/a,n/o,1),h=e.x+e.width/2,g=e.y+e.height/2;return{x:t/2-h*i,y:n/2-g*i,zoom:i}}function Fn(e,t){return{x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}}function Xn(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 Un(e){var t,n;return{width:e.width||((t=e.measured)==null?void 0:t.width)||fr,height:e.height||((n=e.measured)==null?void 0:n.height)||hr}}function Xr(e,t,n={x:0,y:0,zoom:1},r=!1){const a=t.x,o=t.y,i=t.x+t.width,h=t.y+t.height;return e.filter(g=>{const{width:d,height:y}=Un(g),w=g.position.x,C=g.position.y,R=w+d,b=C+y;return r?w<i&&R>a&&C<h&&b>o:w>=a&&R<=i&&C>=o&&b<=h})}function Yr(e){return{x:e.x,y:e.y,x2:e.x+e.width,y2:e.y+e.height}}function Ur(e){return{x:e.x,y:e.y,width:e.x2-e.x,height:e.y2-e.y}}function qr(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 Or(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 Zr(e){const{width:t,height:n}=Un(e);return{x:e.position.x,y:e.position.y,width:t,height:n}}const gr=`var ga = null, r = null, er = 0, or = 0, x = { x: 0, y: 0, zoom: 1 }, O = [], B = [], b = [], I = !1, Yt = 40, Ft = !1, br = "lines", Xr = 1, lt = null, Ga = null, hr = null, W = 160, _ = 60, ft = 8, ao = 5;
|
|
2
|
+
function d(a) {
|
|
3
3
|
return a._absolutePosition || a.position;
|
|
4
4
|
}
|
|
5
|
-
function Vo(a, t, e,
|
|
5
|
+
function Vo(a, t, e, f, l) {
|
|
6
6
|
if (a.x !== void 0 && a.y !== void 0)
|
|
7
7
|
return { x: t + a.x, y: e + a.y };
|
|
8
|
-
var
|
|
9
|
-
switch (
|
|
8
|
+
var o = a.position || (a.type === "source" ? "right" : "left");
|
|
9
|
+
switch (o) {
|
|
10
10
|
case "top":
|
|
11
|
-
return { x: t +
|
|
11
|
+
return { x: t + f / 2, y: e };
|
|
12
12
|
case "bottom":
|
|
13
|
-
return { x: t +
|
|
13
|
+
return { x: t + f / 2, y: e + l };
|
|
14
14
|
case "left":
|
|
15
|
-
return { x: t, y: e +
|
|
15
|
+
return { x: t, y: e + l / 2 };
|
|
16
16
|
case "right":
|
|
17
|
-
return { x: t +
|
|
17
|
+
return { x: t + f, y: e + l / 2 };
|
|
18
18
|
default:
|
|
19
|
-
return { x: t +
|
|
19
|
+
return { x: t + f, y: e + l / 2 };
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
function ho(a) {
|
|
23
|
-
var t = a.width ||
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
var t = a.width || W, e = a.height || _;
|
|
24
|
+
if (a.handles && a.handles.length > 0)
|
|
25
|
+
return a.handles.map(function(u) {
|
|
26
|
+
var g = Vo(u, d(a).x, d(a).y, t, e);
|
|
27
|
+
return { id: u.id || null, type: u.type, x: g.x, y: g.y, position: u.position };
|
|
28
|
+
});
|
|
29
|
+
var f = a.targetPosition || "left", l = a.sourcePosition || "right", o = d(a);
|
|
30
|
+
function v(u) {
|
|
31
|
+
switch (u) {
|
|
32
|
+
case "top":
|
|
33
|
+
return { x: o.x + t / 2, y: o.y };
|
|
34
|
+
case "bottom":
|
|
35
|
+
return { x: o.x + t / 2, y: o.y + e };
|
|
36
|
+
case "left":
|
|
37
|
+
return { x: o.x, y: o.y + e / 2 };
|
|
38
|
+
case "right":
|
|
39
|
+
return { x: o.x + t, y: o.y + e / 2 };
|
|
40
|
+
default:
|
|
41
|
+
return { x: o.x + t, y: o.y + e / 2 };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
var M = v(f), y = v(l);
|
|
45
|
+
return [
|
|
46
|
+
{ id: null, type: "target", x: M.x, y: M.y, position: f },
|
|
47
|
+
{ id: null, type: "source", x: y.x, y: y.y, position: l }
|
|
30
48
|
];
|
|
31
49
|
}
|
|
32
|
-
var
|
|
50
|
+
var jt = {}, Ka = !0;
|
|
33
51
|
function Uo(a) {
|
|
34
|
-
Ka && (
|
|
35
|
-
var t =
|
|
36
|
-
return t || (t = ho(a),
|
|
52
|
+
Ka && (jt = {}, Ka = !1);
|
|
53
|
+
var t = jt[a.id];
|
|
54
|
+
return t || (t = ho(a), jt[a.id] = t, t);
|
|
37
55
|
}
|
|
38
56
|
function it(a, t, e) {
|
|
39
|
-
for (var
|
|
40
|
-
if (
|
|
57
|
+
for (var f = Uo(a), l = 0; l < f.length; l++)
|
|
58
|
+
if (f[l].type === t)
|
|
41
59
|
if (e) {
|
|
42
|
-
if (
|
|
60
|
+
if (f[l].id === e) return f[l];
|
|
43
61
|
} else
|
|
44
|
-
return
|
|
45
|
-
var
|
|
46
|
-
return t === "source" ? { x:
|
|
62
|
+
return f[l];
|
|
63
|
+
var o = a.width || W, v = a.height || _;
|
|
64
|
+
return t === "source" ? { x: d(a).x + o, y: d(a).y + v / 2 } : { x: d(a).x, y: d(a).y + v / 2 };
|
|
47
65
|
}
|
|
48
|
-
var
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
grid:
|
|
52
|
-
origin:
|
|
53
|
-
cardBg:
|
|
54
|
-
cardBorder:
|
|
55
|
-
cardShadow:
|
|
66
|
+
var R = {};
|
|
67
|
+
function pt() {
|
|
68
|
+
R = {
|
|
69
|
+
grid: I ? "rgba(255,255,255,0.07)" : "rgba(0,0,0,0.07)",
|
|
70
|
+
origin: I ? "rgba(255,255,255,0.2)" : "rgba(0,0,0,0.15)",
|
|
71
|
+
cardBg: I ? "#2a2a28" : "#ffffff",
|
|
72
|
+
cardBorder: I ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.1)",
|
|
73
|
+
cardShadow: I ? "rgba(0,0,0,0.3)" : "rgba(0,0,0,0.06)",
|
|
56
74
|
titleText: "rgba(255,255,255,0.9)",
|
|
57
|
-
bodyText:
|
|
58
|
-
coordText:
|
|
59
|
-
nodeBg:
|
|
60
|
-
nodeBorder:
|
|
75
|
+
bodyText: I ? "rgba(255,255,255,0.55)" : "rgba(0,0,0,0.5)",
|
|
76
|
+
coordText: I ? "rgba(255,255,255,0.25)" : "rgba(0,0,0,0.2)",
|
|
77
|
+
nodeBg: I ? "#1e1e2e" : "#ffffff",
|
|
78
|
+
nodeBorder: I ? "rgba(255,255,255,0.15)" : "rgba(0,0,0,0.15)",
|
|
61
79
|
nodeSelectedBorder: "#3b82f6",
|
|
62
|
-
nodeShadow:
|
|
63
|
-
nodeText:
|
|
64
|
-
edgeStroke:
|
|
80
|
+
nodeShadow: I ? "rgba(0,0,0,0.4)" : "rgba(0,0,0,0.08)",
|
|
81
|
+
nodeText: I ? "rgba(255,255,255,0.9)" : "rgba(0,0,0,0.85)",
|
|
82
|
+
edgeStroke: I ? "rgba(255,255,255,0.35)" : "rgba(0,0,0,0.3)",
|
|
65
83
|
edgeSelected: "#3b82f6",
|
|
66
84
|
edgeAnimated: "#3b82f6",
|
|
67
85
|
handleFill: "#ffffff",
|
|
68
86
|
handleBorder: "#3b82f6",
|
|
69
87
|
connectionLine: "#3b82f6"
|
|
70
|
-
},
|
|
88
|
+
}, ka = !0;
|
|
71
89
|
}
|
|
72
|
-
|
|
73
|
-
var Do = ["#534AB7", "#0F6E56", "#993C1D", "#185FA5"],
|
|
90
|
+
pt();
|
|
91
|
+
var Do = ["#534AB7", "#0F6E56", "#993C1D", "#185FA5"], Sa = 8, Fo = "500 11px system-ui, sans-serif", jo = "400 11px system-ui, sans-serif", Oo = "10px monospace", Xo = "500 13px system-ui, sans-serif", Ho = "400 11px system-ui, sans-serif", Br = 400, Ia = {}, ht = !0;
|
|
74
92
|
function Yo() {
|
|
75
93
|
Ia = {};
|
|
76
94
|
for (var a = 0; a < O.length; a++)
|
|
77
|
-
for (var t = O[a], e = Math.floor(t.x /
|
|
78
|
-
for (var
|
|
79
|
-
var
|
|
80
|
-
Ia[
|
|
95
|
+
for (var t = O[a], e = Math.floor(t.x / Br), f = Math.floor(t.y / Br), l = Math.floor((t.x + t.w) / Br), o = Math.floor((t.y + t.h) / Br), v = e; v <= l; v++)
|
|
96
|
+
for (var M = f; M <= o; M++) {
|
|
97
|
+
var y = v + "," + M;
|
|
98
|
+
Ia[y] || (Ia[y] = []), Ia[y].push(a);
|
|
81
99
|
}
|
|
82
100
|
ht = !1;
|
|
83
101
|
}
|
|
84
|
-
function to(a, t, e,
|
|
102
|
+
function to(a, t, e, f) {
|
|
85
103
|
ht && Yo();
|
|
86
|
-
for (var
|
|
87
|
-
for (var i =
|
|
88
|
-
var
|
|
104
|
+
for (var l = {}, o = [], v = Math.floor(a / Br), M = Math.floor(t / Br), y = Math.floor(e / Br), u = Math.floor(f / Br), g = v; g <= y; g++)
|
|
105
|
+
for (var i = M; i <= u; i++) {
|
|
106
|
+
var h = g + "," + i, s = Ia[h];
|
|
89
107
|
if (s)
|
|
90
|
-
for (var
|
|
91
|
-
var
|
|
92
|
-
|
|
108
|
+
for (var n = 0; n < s.length; n++) {
|
|
109
|
+
var k = s[n];
|
|
110
|
+
l[k] || (l[k] = !0, o.push(k));
|
|
93
111
|
}
|
|
94
112
|
}
|
|
95
|
-
return
|
|
113
|
+
return o;
|
|
96
114
|
}
|
|
97
|
-
var Nr = 500, Za = {},
|
|
98
|
-
function
|
|
115
|
+
var Nr = 500, Za = {}, Hr = !0;
|
|
116
|
+
function ee() {
|
|
99
117
|
Za = {};
|
|
100
118
|
for (var a = 0; a < B.length; a++) {
|
|
101
119
|
var t = B[a];
|
|
102
120
|
if (!t.hidden)
|
|
103
|
-
for (var e =
|
|
104
|
-
for (var
|
|
105
|
-
var i =
|
|
121
|
+
for (var e = d(t), f = t.width || W, l = t.height || _, o = Math.floor(e.x / Nr), v = Math.floor(e.y / Nr), M = Math.floor((e.x + f) / Nr), y = Math.floor((e.y + l) / Nr), u = o; u <= M; u++)
|
|
122
|
+
for (var g = v; g <= y; g++) {
|
|
123
|
+
var i = u + "," + g;
|
|
106
124
|
Za[i] || (Za[i] = []), Za[i].push(a);
|
|
107
125
|
}
|
|
108
126
|
}
|
|
109
|
-
|
|
127
|
+
Hr = !1;
|
|
110
128
|
}
|
|
111
|
-
function no(a, t, e,
|
|
112
|
-
|
|
113
|
-
for (var
|
|
114
|
-
for (var i =
|
|
115
|
-
var
|
|
129
|
+
function no(a, t, e, f) {
|
|
130
|
+
Hr && ee();
|
|
131
|
+
for (var l = {}, o = [], v = Math.floor(a / Nr), M = Math.floor(t / Nr), y = Math.floor(e / Nr), u = Math.floor(f / Nr), g = v; g <= y; g++)
|
|
132
|
+
for (var i = M; i <= u; i++) {
|
|
133
|
+
var h = g + "," + i, s = Za[h];
|
|
116
134
|
if (s)
|
|
117
|
-
for (var
|
|
118
|
-
var
|
|
119
|
-
|
|
135
|
+
for (var n = 0; n < s.length; n++) {
|
|
136
|
+
var k = s[n];
|
|
137
|
+
l[k] || (l[k] = !0, o.push(k));
|
|
120
138
|
}
|
|
121
139
|
}
|
|
122
|
-
return
|
|
140
|
+
return o;
|
|
123
141
|
}
|
|
124
|
-
var
|
|
125
|
-
function
|
|
126
|
-
|
|
142
|
+
var Yr = {}, Or = !0;
|
|
143
|
+
function nt() {
|
|
144
|
+
Yr = {};
|
|
127
145
|
for (var a = 0; a < B.length; a++)
|
|
128
|
-
|
|
129
|
-
|
|
146
|
+
Yr[B[a].id] = B[a];
|
|
147
|
+
Or = !1;
|
|
130
148
|
}
|
|
131
149
|
function eo(a) {
|
|
132
|
-
return
|
|
150
|
+
return Or && nt(), Yr[a];
|
|
133
151
|
}
|
|
134
|
-
var Cr = {},
|
|
152
|
+
var Cr = {}, ut = !0;
|
|
135
153
|
function po() {
|
|
136
154
|
Cr = {};
|
|
137
|
-
for (var a = 0; a <
|
|
138
|
-
var t =
|
|
155
|
+
for (var a = 0; a < b.length; a++) {
|
|
156
|
+
var t = b[a];
|
|
139
157
|
Cr[t.source] || (Cr[t.source] = []), Cr[t.source].push(a), t.source !== t.target && (Cr[t.target] || (Cr[t.target] = []), Cr[t.target].push(a));
|
|
140
158
|
}
|
|
141
|
-
|
|
159
|
+
ut = !1;
|
|
142
160
|
}
|
|
143
|
-
var jr = null, uo = 0, so = 0, Mo = "",
|
|
161
|
+
var jr = null, uo = 0, so = 0, Mo = "", ka = !0;
|
|
144
162
|
function rf(a) {
|
|
145
163
|
jr || (jr = new OffscreenCanvas(1, 1));
|
|
146
164
|
var t = Math.ceil(a), e = Math.ceil(a);
|
|
147
165
|
if (t < 2 || e < 2) return !1;
|
|
148
|
-
t > 512 && (t = 512), e > 512 && (e = 512), jr.width = t, jr.height = e, uo = t, so = a, Mo =
|
|
149
|
-
var
|
|
150
|
-
|
|
151
|
-
var
|
|
152
|
-
if (
|
|
153
|
-
|
|
154
|
-
var
|
|
155
|
-
|
|
156
|
-
} else if (
|
|
157
|
-
|
|
158
|
-
var
|
|
159
|
-
|
|
166
|
+
t > 512 && (t = 512), e > 512 && (e = 512), jr.width = t, jr.height = e, uo = t, so = a, Mo = br, ka = !1;
|
|
167
|
+
var f = jr.getContext("2d");
|
|
168
|
+
f.clearRect(0, 0, t, e);
|
|
169
|
+
var l = lt || R.grid;
|
|
170
|
+
if (br === "dots") {
|
|
171
|
+
f.fillStyle = l;
|
|
172
|
+
var o = Xr * x.zoom;
|
|
173
|
+
f.beginPath(), f.arc(0, 0, o, 0, 6.2832), f.fill();
|
|
174
|
+
} else if (br === "cross") {
|
|
175
|
+
f.strokeStyle = l, f.lineWidth = Xr;
|
|
176
|
+
var v = 3 * x.zoom;
|
|
177
|
+
f.beginPath(), f.moveTo(-v, 0), f.lineTo(v, 0), f.moveTo(0, -v), f.lineTo(0, v), f.stroke();
|
|
160
178
|
} else
|
|
161
|
-
|
|
179
|
+
f.beginPath(), f.strokeStyle = l, f.lineWidth = Xr * 0.5, f.moveTo(0.5, 0), f.lineTo(0.5, e), f.moveTo(0, 0.5), f.lineTo(t, 0.5), f.stroke();
|
|
162
180
|
return !0;
|
|
163
181
|
}
|
|
164
|
-
var oo = 0,
|
|
182
|
+
var oo = 0, Ot = 0, fo = 0, vo = 0, re = 0, Ja = !1;
|
|
165
183
|
console.log("[worker] script loaded v2 - FRESH");
|
|
166
184
|
self.postMessage({ type: "ping", data: { status: "alive" } });
|
|
167
185
|
self.onmessage = function(a) {
|
|
@@ -169,219 +187,238 @@ self.onmessage = function(a) {
|
|
|
169
187
|
var t = a.data.type, e = a.data.data;
|
|
170
188
|
switch (t) {
|
|
171
189
|
case "init":
|
|
172
|
-
|
|
173
|
-
return
|
|
174
|
-
}), console.log("[worker] init done — canvas:",
|
|
190
|
+
ga = e.canvas, r = ga.getContext("2d"), er = e.width, or = e.height, ga.width = er, ga.height = or, x = e.camera, O = e.cards || [], B = e.nodes || [], b = e.edges || [], I = e.dark, e.gridSize && (Yt = e.gridSize), e.edgeRouting !== void 0 && (xa = !!e.edgeRouting), pt(), ht = !0, Or = !0, Hr = !0, Ka = !0, ut = !0, Ja = b.some(function(z) {
|
|
191
|
+
return z.animated;
|
|
192
|
+
}), console.log("[worker] init done — canvas:", er, "x", or, "| cards:", O.length, "| nodes:", B.length, "| edges:", b.length, "| routing:", xa), st(), self.postMessage({ type: "ready" }), Ja && lo();
|
|
175
193
|
break;
|
|
176
194
|
case "resize":
|
|
177
|
-
|
|
195
|
+
er = e.width, or = e.height, ga.width = er, ga.height = or, ka = !0, st();
|
|
178
196
|
break;
|
|
179
197
|
case "camera":
|
|
180
|
-
|
|
198
|
+
x = e.camera, ka = !0, Y();
|
|
181
199
|
break;
|
|
182
200
|
case "cards":
|
|
183
|
-
O = e.cards, ht = !0,
|
|
201
|
+
O = e.cards, ht = !0, Y();
|
|
184
202
|
break;
|
|
185
203
|
case "nodes":
|
|
186
|
-
B = e.nodes,
|
|
204
|
+
B = e.nodes, Or = !0, Hr = !0, Ka = !0, Y(), vt(), self.postMessage({ type: "nodesProcessed", data: { nodeCount: B.length } });
|
|
187
205
|
break;
|
|
188
206
|
case "nodePositions":
|
|
189
|
-
|
|
190
|
-
for (var
|
|
191
|
-
var
|
|
192
|
-
|
|
207
|
+
Or && nt();
|
|
208
|
+
for (var f = e.updates, l = 0; l < f.length; l++) {
|
|
209
|
+
var o = f[l], v = Yr[o.id];
|
|
210
|
+
v && (v.position = o.position, o._absolutePosition && (v._absolutePosition = o._absolutePosition), o.width !== void 0 && (v.width = o.width), o.height !== void 0 && (v.height = o.height), v.dragging = o.dragging, v.selected = o.selected);
|
|
211
|
+
}
|
|
212
|
+
Ka = !0, Hr = !0, Y(), vt();
|
|
213
|
+
break;
|
|
214
|
+
case "nodeSelections":
|
|
215
|
+
Or && nt();
|
|
216
|
+
for (var M = e.selections, y = 0; y < M.length; y++) {
|
|
217
|
+
var u = M[y], g = Yr[u.id];
|
|
218
|
+
g && (g.selected = u.selected);
|
|
193
219
|
}
|
|
194
|
-
|
|
220
|
+
Y();
|
|
221
|
+
break;
|
|
222
|
+
case "edgeSelections":
|
|
223
|
+
for (var i = e.selections, h = 0; h < i.length; h++) {
|
|
224
|
+
for (var s = i[h], n = null, k = 0; k < b.length; k++)
|
|
225
|
+
if (b[k].id === s.id) {
|
|
226
|
+
n = b[k];
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
n && (n.selected = s.selected);
|
|
230
|
+
}
|
|
231
|
+
Y();
|
|
195
232
|
break;
|
|
196
233
|
case "edges":
|
|
197
|
-
|
|
198
|
-
return
|
|
199
|
-
}), Ja && lo(),
|
|
234
|
+
b = e.edges, ut = !0, Ja = b.some(function(z) {
|
|
235
|
+
return z.animated;
|
|
236
|
+
}), Ja && lo(), Y(), vt();
|
|
200
237
|
break;
|
|
201
238
|
case "theme":
|
|
202
|
-
|
|
239
|
+
I = e.dark, pt(), Y();
|
|
203
240
|
break;
|
|
204
241
|
case "connecting":
|
|
205
|
-
|
|
242
|
+
Ga = e, Y();
|
|
206
243
|
break;
|
|
207
244
|
case "selectionBox":
|
|
208
|
-
hr = e,
|
|
245
|
+
hr = e, Y();
|
|
209
246
|
break;
|
|
210
247
|
case "background":
|
|
211
|
-
e.variant && (
|
|
248
|
+
e.variant && (br = e.variant), e.gap && (Yt = e.gap), e.size && (Xr = e.size), lt = e.color || null, ka = !0, Y();
|
|
212
249
|
break;
|
|
213
250
|
case "edgeRouting":
|
|
214
|
-
if (
|
|
251
|
+
if (xa = !!e.enabled, xa)
|
|
215
252
|
vt();
|
|
216
253
|
else {
|
|
217
|
-
for (var
|
|
218
|
-
|
|
219
|
-
|
|
254
|
+
for (var N = 0; N < b.length; N++)
|
|
255
|
+
b[N]._routedPoints = null;
|
|
256
|
+
Y();
|
|
220
257
|
}
|
|
221
258
|
break;
|
|
222
259
|
}
|
|
223
|
-
} catch (
|
|
224
|
-
console.error("[worker] error:",
|
|
260
|
+
} catch (z) {
|
|
261
|
+
console.error("[worker] error:", z);
|
|
225
262
|
}
|
|
226
263
|
};
|
|
227
|
-
function
|
|
228
|
-
|
|
229
|
-
|
|
264
|
+
function Y() {
|
|
265
|
+
Ft || (Ft = !0, requestAnimationFrame(function() {
|
|
266
|
+
Ft = !1, st();
|
|
230
267
|
}));
|
|
231
268
|
}
|
|
232
|
-
var
|
|
269
|
+
var Xt = !1;
|
|
233
270
|
function lo() {
|
|
234
|
-
if (
|
|
235
|
-
|
|
271
|
+
if (Xt) return;
|
|
272
|
+
Xt = !0;
|
|
236
273
|
function a() {
|
|
237
274
|
if (!Ja) {
|
|
238
|
-
|
|
275
|
+
Xt = !1;
|
|
239
276
|
return;
|
|
240
277
|
}
|
|
241
|
-
|
|
278
|
+
re = (re + 0.5) % 20, st(), requestAnimationFrame(a);
|
|
242
279
|
}
|
|
243
280
|
requestAnimationFrame(a);
|
|
244
281
|
}
|
|
245
282
|
function io(a, t) {
|
|
246
283
|
var e = 6;
|
|
247
284
|
a.moveTo(t[0].x, t[0].y);
|
|
248
|
-
for (var
|
|
249
|
-
var
|
|
250
|
-
if (
|
|
251
|
-
var
|
|
252
|
-
a.lineTo(
|
|
285
|
+
for (var f = 1; f < t.length - 1; f++) {
|
|
286
|
+
var l = t[f - 1], o = t[f], v = t[f + 1], M = Math.abs(o.x - l.x) + Math.abs(o.y - l.y), y = Math.abs(v.x - o.x) + Math.abs(v.y - o.y), u = Math.min(e, M / 2, y / 2);
|
|
287
|
+
if (u > 0.5) {
|
|
288
|
+
var g = o.x - l.x, i = o.y - l.y, h = v.x - o.x, s = v.y - o.y, n = Math.sqrt(g * g + i * i) || 1, k = Math.sqrt(h * h + s * s) || 1;
|
|
289
|
+
a.lineTo(o.x - g / n * u, o.y - i / n * u), a.quadraticCurveTo(o.x, o.y, o.x + h / k * u, o.y + s / k * u);
|
|
253
290
|
} else
|
|
254
|
-
a.lineTo(
|
|
291
|
+
a.lineTo(o.x, o.y);
|
|
255
292
|
}
|
|
256
293
|
a.lineTo(t[t.length - 1].x, t[t.length - 1].y);
|
|
257
294
|
}
|
|
258
295
|
function af(a) {
|
|
259
296
|
for (var t = 0, e = 1; e < a.length; e++)
|
|
260
297
|
t += Math.abs(a[e].x - a[e - 1].x) + Math.abs(a[e].y - a[e - 1].y);
|
|
261
|
-
for (var
|
|
262
|
-
var
|
|
263
|
-
if (
|
|
264
|
-
var
|
|
298
|
+
for (var f = t / 2, l = 1; l < a.length; l++) {
|
|
299
|
+
var o = Math.abs(a[l].x - a[l - 1].x) + Math.abs(a[l].y - a[l - 1].y);
|
|
300
|
+
if (f <= o) {
|
|
301
|
+
var v = o > 0 ? f / o : 0;
|
|
265
302
|
return {
|
|
266
|
-
x: a[
|
|
267
|
-
y: a[
|
|
303
|
+
x: a[l - 1].x + (a[l].x - a[l - 1].x) * v,
|
|
304
|
+
y: a[l - 1].y + (a[l].y - a[l - 1].y) * v
|
|
268
305
|
};
|
|
269
306
|
}
|
|
270
|
-
|
|
307
|
+
f -= o;
|
|
271
308
|
}
|
|
272
309
|
return { x: a[0].x, y: a[0].y };
|
|
273
310
|
}
|
|
274
|
-
function
|
|
275
|
-
var
|
|
276
|
-
return { cp1x:
|
|
311
|
+
function ae(a, t, e, f) {
|
|
312
|
+
var l = Math.abs(e - a), o = Math.max(50, l * 0.5), v = a + o, M = t, y = e - o, u = f;
|
|
313
|
+
return { cp1x: v, cp1y: M, cp2x: y, cp2y: u };
|
|
277
314
|
}
|
|
278
|
-
function tf(a, t, e,
|
|
279
|
-
var
|
|
280
|
-
return { x:
|
|
315
|
+
function tf(a, t, e, f) {
|
|
316
|
+
var l = ae(a, t, e, f), o = 0.5, v = 1 - o, M = v * v * v * a + 3 * v * v * o * l.cp1x + 3 * v * o * o * l.cp2x + o * o * o * e, y = v * v * v * t + 3 * v * v * o * l.cp1y + 3 * v * o * o * l.cp2y + o * o * o * f;
|
|
317
|
+
return { x: M, y };
|
|
281
318
|
}
|
|
282
|
-
var
|
|
283
|
-
function
|
|
284
|
-
|
|
285
|
-
for (var
|
|
286
|
-
var
|
|
287
|
-
|
|
319
|
+
var xa = !0, te = !1, Ht = !1;
|
|
320
|
+
function yo(a, t, e, f, l) {
|
|
321
|
+
Hr && ee();
|
|
322
|
+
for (var o = Math.min(a, e) - 20, v = Math.min(t, f) - 20, M = Math.max(a, e) + 20, y = Math.max(t, f) + 20, u = no(o, v, M, y), g = [], i = 0; i < u.length; i++) {
|
|
323
|
+
var h = B[u[i]];
|
|
324
|
+
h.hidden || l[h.id] || h.type !== "group" && g.push(h);
|
|
288
325
|
}
|
|
289
|
-
return
|
|
326
|
+
return g;
|
|
290
327
|
}
|
|
291
|
-
function dr(a, t, e,
|
|
292
|
-
for (var
|
|
293
|
-
var
|
|
294
|
-
if (e >
|
|
328
|
+
function dr(a, t, e, f) {
|
|
329
|
+
for (var l = Math.min(a, t), o = Math.max(a, t), v = 0; v < f.length; v++) {
|
|
330
|
+
var M = f[v], y = d(M), u = M.width || W, g = M.height || _;
|
|
331
|
+
if (e > y.y && e < y.y + g && o > y.x && l < y.x + u) return M;
|
|
295
332
|
}
|
|
296
333
|
return null;
|
|
297
334
|
}
|
|
298
|
-
function Mr(a, t, e,
|
|
299
|
-
for (var
|
|
300
|
-
var
|
|
301
|
-
if (a >
|
|
335
|
+
function Mr(a, t, e, f) {
|
|
336
|
+
for (var l = Math.min(t, e), o = Math.max(t, e), v = 0; v < f.length; v++) {
|
|
337
|
+
var M = f[v], y = d(M), u = M.width || W, g = M.height || _;
|
|
338
|
+
if (a > y.x && a < y.x + u && o > y.y && l < y.y + g) return M;
|
|
302
339
|
}
|
|
303
340
|
return null;
|
|
304
341
|
}
|
|
305
342
|
function ef() {
|
|
306
|
-
if (
|
|
307
|
-
|
|
308
|
-
for (var a = 20, t = !1, e = 0; e <
|
|
309
|
-
var
|
|
310
|
-
if (!
|
|
311
|
-
var
|
|
312
|
-
if (!(
|
|
313
|
-
var
|
|
314
|
-
if (!(!
|
|
315
|
-
var
|
|
316
|
-
|
|
317
|
-
var
|
|
318
|
-
Ir[
|
|
319
|
-
var X =
|
|
320
|
-
Math.min(i, s) -
|
|
321
|
-
Math.min(
|
|
322
|
-
Math.max(i, s) +
|
|
323
|
-
Math.max(
|
|
343
|
+
if (xa && !(!te || b.length === 0 || B.length === 0)) {
|
|
344
|
+
te = !1, Or && nt(), Hr && ee();
|
|
345
|
+
for (var a = 20, t = !1, e = 0; e < b.length; e++) {
|
|
346
|
+
var f = b[e];
|
|
347
|
+
if (!f._customRendered) {
|
|
348
|
+
var l = f.type || "default";
|
|
349
|
+
if (!(l === "bezier" || l === "simplebezier" || l === "default")) {
|
|
350
|
+
var o = Yr[f.source], v = Yr[f.target];
|
|
351
|
+
if (!(!o || !v || o.hidden || v.hidden)) {
|
|
352
|
+
var M = it(o, "source", f.sourceHandle), y = it(v, "target", f.targetHandle), u = M.position || "right", g = y.position || "left", i = M.x, h = M.y, s = y.x, n = y.y, k = i, N = h, z = s, $ = n;
|
|
353
|
+
u === "right" ? k += a : u === "left" ? k -= a : u === "bottom" ? N += a : u === "top" && (N -= a), g === "right" ? z += a : g === "left" ? z -= a : g === "bottom" ? $ += a : g === "top" && ($ -= a);
|
|
354
|
+
var yr = d(o), Pr = d(v), qr = o.width || W, Sr = o.height || _, Gr = v.width || W, pr = v.height || _, Ir = {};
|
|
355
|
+
Ir[f.source] = !0, Ir[f.target] = !0;
|
|
356
|
+
var X = yo(
|
|
357
|
+
Math.min(i, s) - qr,
|
|
358
|
+
Math.min(h, n) - Sr,
|
|
359
|
+
Math.max(i, s) + Gr,
|
|
360
|
+
Math.max(h, n) + pr,
|
|
324
361
|
Ir
|
|
325
362
|
);
|
|
326
|
-
X.push(
|
|
327
|
-
var
|
|
328
|
-
if (
|
|
329
|
-
var L, fr =
|
|
330
|
-
if (fr ||
|
|
331
|
-
L = (
|
|
332
|
-
var
|
|
333
|
-
if (
|
|
334
|
-
var
|
|
335
|
-
L = L <
|
|
363
|
+
X.push(o), X.push(v);
|
|
364
|
+
var ra = u === "left" || u === "right", ca = g === "left" || g === "right", C = null;
|
|
365
|
+
if (ra && ca) {
|
|
366
|
+
var L, fr = u === "right" && k < z, dt = u === "left" && k > z;
|
|
367
|
+
if (fr || dt) {
|
|
368
|
+
L = (k + z) / 2;
|
|
369
|
+
var Ta = Mr(L, h, n, X);
|
|
370
|
+
if (Ta) {
|
|
371
|
+
var aa = d(Ta), ta = Ta.width || W;
|
|
372
|
+
L = L < aa.x + ta / 2 ? aa.x - a : aa.x + ta + a;
|
|
336
373
|
}
|
|
337
374
|
} else
|
|
338
|
-
|
|
339
|
-
C = [{ x: i, y:
|
|
340
|
-
var
|
|
341
|
-
if (
|
|
342
|
-
var
|
|
343
|
-
C = [{ x: i, y:
|
|
375
|
+
u === "right" ? L = Math.max(yr.x + qr, Pr.x + Gr) + a : L = Math.min(yr.x, Pr.x) - a;
|
|
376
|
+
C = [{ x: i, y: h }, { x: k, y: h }, { x: L, y: h }, { x: L, y: n }, { x: z, y: n }, { x: s, y: n }];
|
|
377
|
+
var gr = dr(L, z, n, X);
|
|
378
|
+
if (gr) {
|
|
379
|
+
var ea = d(gr), oa = gr.height || _, fa = ea.y - a, Zr = ea.y + oa + a, Jr = Math.abs(h - fa) <= Math.abs(h - Zr) ? fa : Zr;
|
|
380
|
+
C = [{ x: i, y: h }, { x: k, y: h }, { x: L, y: h }, { x: L, y: Jr }, { x: z, y: Jr }, { x: z, y: n }, { x: s, y: n }];
|
|
344
381
|
}
|
|
345
|
-
} else if (!
|
|
346
|
-
var
|
|
347
|
-
if (Qa ||
|
|
348
|
-
|
|
349
|
-
var xr = dr(i, s,
|
|
382
|
+
} else if (!ra && !ca) {
|
|
383
|
+
var q, Qa = u === "bottom" && N < $, ma = u === "top" && N > $;
|
|
384
|
+
if (Qa || ma) {
|
|
385
|
+
q = (N + $) / 2;
|
|
386
|
+
var xr = dr(i, s, q, X);
|
|
350
387
|
if (xr) {
|
|
351
|
-
var kr =
|
|
352
|
-
|
|
388
|
+
var kr = d(xr), va = xr.height || _;
|
|
389
|
+
q = q < kr.y + va / 2 ? kr.y - a : kr.y + va + a;
|
|
353
390
|
}
|
|
354
391
|
} else
|
|
355
|
-
|
|
356
|
-
C = [{ x: i, y:
|
|
357
|
-
var Kr = Mr(s,
|
|
392
|
+
u === "bottom" ? q = Math.max(yr.y + Sr, Pr.y + pr) + a : q = Math.min(yr.y, Pr.y) - a;
|
|
393
|
+
C = [{ x: i, y: h }, { x: i, y: N }, { x: i, y: q }, { x: s, y: q }, { x: s, y: $ }, { x: s, y: n }];
|
|
394
|
+
var Kr = Mr(s, q, $, X);
|
|
358
395
|
if (Kr) {
|
|
359
|
-
var
|
|
360
|
-
C = [{ x: i, y:
|
|
396
|
+
var la = d(Kr), wa = Kr.height || _, ia = la.y - a, ha = la.y + wa + a, na = Math.abs(q - ia) <= Math.abs(q - ha) ? ia : ha;
|
|
397
|
+
C = [{ x: i, y: h }, { x: i, y: N }, { x: i, y: q }, { x: s, y: q }, { x: s, y: na }, { x: z, y: na }, { x: z, y: n }, { x: s, y: n }];
|
|
361
398
|
}
|
|
362
|
-
} else if (
|
|
363
|
-
C = [{ x: i, y:
|
|
364
|
-
var
|
|
365
|
-
if (
|
|
366
|
-
var V =
|
|
367
|
-
C = [{ x: i, y:
|
|
399
|
+
} else if (ra) {
|
|
400
|
+
C = [{ x: i, y: h }, { x: k, y: h }, { x: s, y: h }, { x: s, y: $ }, { x: s, y: n }];
|
|
401
|
+
var cr = Mr(s, h, $, X);
|
|
402
|
+
if (cr) {
|
|
403
|
+
var V = d(cr), Tr = cr.width || W, Ra = Math.abs(i - V.x + a) <= Math.abs(i - V.x - Tr - a) ? V.x - a : V.x + Tr + a;
|
|
404
|
+
C = [{ x: i, y: h }, { x: k, y: h }, { x: Ra, y: h }, { x: Ra, y: n }, { x: s, y: n }, { x: s, y: $ }, { x: s, y: n }];
|
|
368
405
|
}
|
|
369
|
-
var Qr = dr(
|
|
406
|
+
var Qr = dr(k, s, h, X);
|
|
370
407
|
if (Qr) {
|
|
371
|
-
var
|
|
372
|
-
C = [{ x: i, y:
|
|
408
|
+
var mr = d(Qr), ua = Qr.height || _, H = Math.abs(n - mr.y + a) <= Math.abs(n - mr.y - ua - a) ? mr.y - a : mr.y + ua + a;
|
|
409
|
+
C = [{ x: i, y: h }, { x: k, y: h }, { x: k, y: H }, { x: s, y: H }, { x: s, y: $ }, { x: s, y: n }];
|
|
373
410
|
}
|
|
374
411
|
} else {
|
|
375
|
-
C = [{ x: i, y:
|
|
376
|
-
var wr = dr(i,
|
|
412
|
+
C = [{ x: i, y: h }, { x: i, y: N }, { x: i, y: n }, { x: z, y: n }, { x: s, y: n }];
|
|
413
|
+
var wr = dr(i, z, n, X);
|
|
377
414
|
if (wr) {
|
|
378
|
-
var
|
|
379
|
-
C = [{ x: i, y:
|
|
415
|
+
var sa = d(wr), U = wr.height || _, Rr = Math.abs(h - sa.y + a) <= Math.abs(h - sa.y - U - a) ? sa.y - a : sa.y + U + a;
|
|
416
|
+
C = [{ x: i, y: h }, { x: i, y: N }, { x: i, y: Rr }, { x: z, y: Rr }, { x: z, y: n }, { x: s, y: n }];
|
|
380
417
|
}
|
|
381
|
-
var nr = Mr(i,
|
|
418
|
+
var nr = Mr(i, N, n, X);
|
|
382
419
|
if (nr) {
|
|
383
|
-
var vr =
|
|
384
|
-
C = [{ x: i, y:
|
|
420
|
+
var vr = d(nr), za = nr.width || W, _a = Math.abs(s - vr.x + a) <= Math.abs(s - vr.x - za - a) ? vr.x - a : vr.x + za + a;
|
|
421
|
+
C = [{ x: i, y: h }, { x: i, y: N }, { x: _a, y: N }, { x: _a, y: n }, { x: z, y: n }, { x: s, y: n }];
|
|
385
422
|
}
|
|
386
423
|
}
|
|
387
424
|
if (C) {
|
|
@@ -389,18 +426,18 @@ function ef() {
|
|
|
389
426
|
var $a = $r[$r.length - 1];
|
|
390
427
|
(Math.abs(C[lr].x - $a.x) > 0.1 || Math.abs(C[lr].y - $a.y) > 0.1) && $r.push(C[lr]);
|
|
391
428
|
}
|
|
392
|
-
|
|
429
|
+
f._routedPoints = $r, t = !0;
|
|
393
430
|
}
|
|
394
431
|
}
|
|
395
432
|
}
|
|
396
433
|
}
|
|
397
434
|
}
|
|
398
|
-
t &&
|
|
435
|
+
t && Y();
|
|
399
436
|
}
|
|
400
437
|
}
|
|
401
438
|
function vt() {
|
|
402
|
-
|
|
403
|
-
|
|
439
|
+
xa && (Ht || (Ht = !0, te = !0, requestAnimationFrame(function() {
|
|
440
|
+
Ht = !1;
|
|
404
441
|
try {
|
|
405
442
|
ef();
|
|
406
443
|
} catch (a) {
|
|
@@ -408,423 +445,423 @@ function vt() {
|
|
|
408
445
|
}
|
|
409
446
|
})));
|
|
410
447
|
}
|
|
411
|
-
function
|
|
448
|
+
function st() {
|
|
412
449
|
if (r) {
|
|
413
450
|
var a = performance.now();
|
|
414
|
-
r.clearRect(0, 0,
|
|
415
|
-
var t =
|
|
451
|
+
r.clearRect(0, 0, er, or);
|
|
452
|
+
var t = Yt * x.zoom;
|
|
416
453
|
if (t > 2)
|
|
417
|
-
if (
|
|
418
|
-
if ((
|
|
419
|
-
var e = (
|
|
420
|
-
r.save(), r.translate(e,
|
|
421
|
-
var
|
|
422
|
-
|
|
454
|
+
if (br === "lines" && t >= 4 && t <= 512) {
|
|
455
|
+
if ((ka || so !== t || Mo !== br) && rf(t), jr && uo > 0) {
|
|
456
|
+
var e = (x.x % t + t) % t, f = (x.y % t + t) % t;
|
|
457
|
+
r.save(), r.translate(e, f);
|
|
458
|
+
var l = r.createPattern(jr, "repeat");
|
|
459
|
+
l && (r.fillStyle = l, r.fillRect(-e, -f, er, or)), r.restore();
|
|
423
460
|
}
|
|
424
461
|
} else {
|
|
425
|
-
var
|
|
426
|
-
if (
|
|
427
|
-
r.fillStyle =
|
|
428
|
-
for (var
|
|
429
|
-
for (var
|
|
430
|
-
r.beginPath(), r.arc(Math.round(
|
|
431
|
-
} else if (
|
|
432
|
-
r.strokeStyle =
|
|
433
|
-
var i = 3 *
|
|
462
|
+
var o = (x.x % t + t) % t, v = (x.y % t + t) % t, M = lt || R.grid;
|
|
463
|
+
if (br === "dots") {
|
|
464
|
+
r.fillStyle = M;
|
|
465
|
+
for (var y = Xr * x.zoom, u = o; u < er; u += t)
|
|
466
|
+
for (var g = v; g < or; g += t)
|
|
467
|
+
r.beginPath(), r.arc(Math.round(u), Math.round(g), y, 0, 6.2832), r.fill();
|
|
468
|
+
} else if (br === "cross") {
|
|
469
|
+
r.strokeStyle = M, r.lineWidth = Xr;
|
|
470
|
+
var i = 3 * x.zoom;
|
|
434
471
|
r.beginPath();
|
|
435
|
-
for (var
|
|
436
|
-
for (var s =
|
|
437
|
-
var
|
|
438
|
-
r.moveTo(
|
|
472
|
+
for (var h = o; h < er; h += t)
|
|
473
|
+
for (var s = v; s < or; s += t) {
|
|
474
|
+
var n = Math.round(h), k = Math.round(s);
|
|
475
|
+
r.moveTo(n - i, k), r.lineTo(n + i, k), r.moveTo(n, k - i), r.lineTo(n, k + i);
|
|
439
476
|
}
|
|
440
477
|
r.stroke();
|
|
441
478
|
} else {
|
|
442
|
-
var
|
|
443
|
-
r.beginPath(), r.strokeStyle =
|
|
444
|
-
for (var
|
|
445
|
-
var $ = Math.round(
|
|
446
|
-
r.moveTo($, 0), r.lineTo($,
|
|
479
|
+
var N = lt || R.grid;
|
|
480
|
+
r.beginPath(), r.strokeStyle = N, r.lineWidth = Xr * 0.5;
|
|
481
|
+
for (var z = o; z < er; z += t) {
|
|
482
|
+
var $ = Math.round(z) + 0.5;
|
|
483
|
+
r.moveTo($, 0), r.lineTo($, or);
|
|
447
484
|
}
|
|
448
|
-
for (var
|
|
449
|
-
var
|
|
450
|
-
r.moveTo(0,
|
|
485
|
+
for (var yr = v; yr < or; yr += t) {
|
|
486
|
+
var Pr = Math.round(yr) + 0.5;
|
|
487
|
+
r.moveTo(0, Pr), r.lineTo(er, Pr);
|
|
451
488
|
}
|
|
452
489
|
r.stroke();
|
|
453
490
|
}
|
|
454
491
|
}
|
|
455
|
-
r.beginPath(), r.arc(
|
|
456
|
-
var
|
|
492
|
+
r.beginPath(), r.arc(x.x, x.y, 4 * x.zoom, 0, 6.2832), r.fillStyle = R.origin, r.fill(), r.save(), r.translate(x.x, x.y), r.scale(x.zoom, x.zoom);
|
|
493
|
+
var qr = 100, Sr = -x.x / x.zoom, Gr = -x.y / x.zoom, pr = Sr + er / x.zoom, Ir = Gr + or / x.zoom, X = Sr - qr, ra = Gr - qr, ca = pr + qr, C = Ir + qr;
|
|
457
494
|
if (O.length > 0) {
|
|
458
|
-
var L = to(
|
|
459
|
-
if (
|
|
460
|
-
r.shadowColor =
|
|
461
|
-
for (var
|
|
462
|
-
var
|
|
463
|
-
r.roundRect(
|
|
495
|
+
var L = to(Sr, Gr, pr, Ir), fr = L.length, dt = x.zoom > 0.15, Ta = x.zoom > 0.3, aa = x.zoom > 0.08 && fr < 200;
|
|
496
|
+
if (aa) {
|
|
497
|
+
r.shadowColor = R.cardShadow, r.shadowBlur = 6, r.shadowOffsetY = 2, r.fillStyle = R.cardBg, r.beginPath();
|
|
498
|
+
for (var ta = 0; ta < fr; ta++) {
|
|
499
|
+
var gr = O[L[ta]];
|
|
500
|
+
r.roundRect(gr.x, gr.y, gr.w, gr.h, Sa);
|
|
464
501
|
}
|
|
465
502
|
r.fill(), r.shadowColor = "transparent", r.shadowBlur = 0, r.shadowOffsetY = 0;
|
|
466
503
|
}
|
|
467
|
-
if (!
|
|
468
|
-
r.fillStyle =
|
|
469
|
-
for (var
|
|
470
|
-
var
|
|
471
|
-
r.roundRect(
|
|
504
|
+
if (!aa) {
|
|
505
|
+
r.fillStyle = R.cardBg, r.beginPath();
|
|
506
|
+
for (var ea = 0; ea < fr; ea++) {
|
|
507
|
+
var oa = O[L[ea]];
|
|
508
|
+
r.roundRect(oa.x, oa.y, oa.w, oa.h, Sa);
|
|
472
509
|
}
|
|
473
510
|
r.fill();
|
|
474
511
|
}
|
|
475
|
-
r.strokeStyle =
|
|
476
|
-
for (var
|
|
477
|
-
var Zr = O[L[
|
|
478
|
-
r.roundRect(Zr.x, Zr.y, Zr.w, Zr.h,
|
|
512
|
+
r.strokeStyle = R.cardBorder, r.lineWidth = 0.5, r.beginPath();
|
|
513
|
+
for (var fa = 0; fa < fr; fa++) {
|
|
514
|
+
var Zr = O[L[fa]];
|
|
515
|
+
r.roundRect(Zr.x, Zr.y, Zr.w, Zr.h, Sa);
|
|
479
516
|
}
|
|
480
517
|
r.stroke();
|
|
481
|
-
for (var Jr = [{}, {}, {}, {}],
|
|
482
|
-
var Qa = L[
|
|
483
|
-
Jr[
|
|
518
|
+
for (var Jr = [{}, {}, {}, {}], q = 0; q < fr; q++) {
|
|
519
|
+
var Qa = L[q], ma = Qa % 4;
|
|
520
|
+
Jr[ma].items || (Jr[ma].items = []), Jr[ma].items.push(O[Qa]);
|
|
484
521
|
}
|
|
485
522
|
for (var xr = 0; xr < 4; xr++) {
|
|
486
523
|
var kr = Jr[xr].items;
|
|
487
524
|
if (!(!kr || kr.length === 0)) {
|
|
488
525
|
r.fillStyle = Do[xr], r.beginPath();
|
|
489
|
-
for (var
|
|
490
|
-
var Kr = kr[
|
|
491
|
-
r.roundRect(Kr.x, Kr.y, Kr.w, 30, [
|
|
526
|
+
for (var va = 0; va < kr.length; va++) {
|
|
527
|
+
var Kr = kr[va];
|
|
528
|
+
r.roundRect(Kr.x, Kr.y, Kr.w, 30, [Sa, Sa, 0, 0]);
|
|
492
529
|
}
|
|
493
530
|
r.fill();
|
|
494
531
|
}
|
|
495
532
|
}
|
|
496
|
-
if (
|
|
497
|
-
r.fillStyle =
|
|
498
|
-
for (var
|
|
499
|
-
var wa = O[L[
|
|
533
|
+
if (dt) {
|
|
534
|
+
r.fillStyle = R.titleText, r.font = Fo;
|
|
535
|
+
for (var la = 0; la < fr; la++) {
|
|
536
|
+
var wa = O[L[la]];
|
|
500
537
|
r.fillText(wa.title, wa.x + 12, wa.y + 19);
|
|
501
538
|
}
|
|
502
|
-
r.fillStyle =
|
|
503
|
-
for (var
|
|
504
|
-
var
|
|
505
|
-
r.fillText(
|
|
539
|
+
r.fillStyle = R.bodyText, r.font = jo;
|
|
540
|
+
for (var ia = 0; ia < fr; ia++) {
|
|
541
|
+
var ha = O[L[ia]];
|
|
542
|
+
r.fillText(ha.body, ha.x + 12, ha.y + 52);
|
|
506
543
|
}
|
|
507
|
-
if (
|
|
508
|
-
r.fillStyle =
|
|
509
|
-
for (var
|
|
510
|
-
var
|
|
511
|
-
r.fillText("(" +
|
|
544
|
+
if (Ta) {
|
|
545
|
+
r.fillStyle = R.coordText, r.font = Oo;
|
|
546
|
+
for (var na = 0; na < fr; na++) {
|
|
547
|
+
var cr = O[L[na]];
|
|
548
|
+
r.fillText("(" + cr.x + ", " + cr.y + ")", cr.x + 12, cr.y + 75);
|
|
512
549
|
}
|
|
513
550
|
}
|
|
514
551
|
}
|
|
515
552
|
}
|
|
516
|
-
var V = [],
|
|
553
|
+
var V = [], Tr = null;
|
|
517
554
|
if (B.length > 0)
|
|
518
|
-
if (
|
|
519
|
-
for (var
|
|
520
|
-
var
|
|
521
|
-
mr
|
|
555
|
+
if (Tr = {}, B.length > 100)
|
|
556
|
+
for (var Ra = no(X, ra, ca, C), Qr = 0; Qr < Ra.length; Qr++) {
|
|
557
|
+
var mr = B[Ra[Qr]];
|
|
558
|
+
Tr[mr.id] = !0, mr._customRendered || V.push(mr);
|
|
522
559
|
}
|
|
523
560
|
else
|
|
524
|
-
for (var
|
|
525
|
-
var H = B[
|
|
561
|
+
for (var ua = 0; ua < B.length; ua++) {
|
|
562
|
+
var H = B[ua];
|
|
526
563
|
if (!H.hidden) {
|
|
527
|
-
var wr = H.width ||
|
|
528
|
-
|
|
564
|
+
var wr = H.width || W, sa = H.height || _;
|
|
565
|
+
d(H).x + wr < X || d(H).x > ca || d(H).y + sa < ra || d(H).y > C || (Tr[H.id] = !0, H._customRendered || V.push(H));
|
|
529
566
|
}
|
|
530
567
|
}
|
|
531
568
|
var U = V.length;
|
|
532
|
-
if (
|
|
569
|
+
if (b.length > 0 && B.length > 0) {
|
|
533
570
|
let ot = function(Lr, ro) {
|
|
534
571
|
if (Lr.length) {
|
|
535
572
|
r.fillStyle = ro, r.beginPath();
|
|
536
|
-
for (var
|
|
537
|
-
var j = Lr[
|
|
573
|
+
for (var Dt = 0; Dt < Lr.length; Dt++) {
|
|
574
|
+
var j = Lr[Dt];
|
|
538
575
|
r.moveTo(j.x, j.y), r.lineTo(j.x - j.size * Math.cos(j.angle - 0.5236), j.y - j.size * Math.sin(j.angle - 0.5236)), r.lineTo(j.x - j.size * Math.cos(j.angle + 0.5236), j.y - j.size * Math.sin(j.angle + 0.5236)), r.closePath();
|
|
539
576
|
}
|
|
540
577
|
r.fill();
|
|
541
578
|
}
|
|
542
579
|
};
|
|
543
580
|
var of = ot;
|
|
544
|
-
|
|
545
|
-
var
|
|
546
|
-
if (
|
|
581
|
+
ut && po();
|
|
582
|
+
var Rr = null, nr = null, vr = null, za = [], _a = [], $r = [], lr = [], $a = x.zoom > 0.3, go = x.zoom > 0.05, da;
|
|
583
|
+
if (Tr && B.length > 100) {
|
|
547
584
|
var oe = {};
|
|
548
|
-
|
|
549
|
-
for (var xo in
|
|
550
|
-
var
|
|
551
|
-
if (
|
|
552
|
-
for (var
|
|
553
|
-
var gt =
|
|
554
|
-
oe[gt] || (oe[gt] = !0,
|
|
585
|
+
da = [];
|
|
586
|
+
for (var xo in Tr) {
|
|
587
|
+
var Mt = Cr[xo];
|
|
588
|
+
if (Mt)
|
|
589
|
+
for (var yt = 0; yt < Mt.length; yt++) {
|
|
590
|
+
var gt = Mt[yt];
|
|
591
|
+
oe[gt] || (oe[gt] = !0, da.push(gt));
|
|
555
592
|
}
|
|
556
593
|
}
|
|
557
594
|
} else {
|
|
558
|
-
|
|
559
|
-
for (var
|
|
595
|
+
da = [];
|
|
596
|
+
for (var xt = 0; xt < b.length; xt++) da.push(xt);
|
|
560
597
|
}
|
|
561
|
-
for (var
|
|
562
|
-
var D =
|
|
598
|
+
for (var kt = 0; kt < da.length; kt++) {
|
|
599
|
+
var D = b[da[kt]], Vr = eo(D.source), Ur = eo(D.target);
|
|
563
600
|
if (!(!Vr || !Ur) && !(Vr.hidden || Ur.hidden) && !D._customRendered) {
|
|
564
|
-
var Va = it(Vr, "source", D.sourceHandle), Ua = it(Ur, "target", D.targetHandle),
|
|
565
|
-
fe ? (nr || (nr = new Path2D()),
|
|
566
|
-
var
|
|
567
|
-
if (
|
|
568
|
-
io(
|
|
601
|
+
var Va = it(Vr, "source", D.sourceHandle), Ua = it(Ur, "target", D.targetHandle), A = Va.x, w = Va.y, T = Ua.x, m = Ua.y, ir = D.type || "default", fe = D.selected, ve = D.animated, S;
|
|
602
|
+
fe ? (nr || (nr = new Path2D()), S = nr) : ve ? (vr || (vr = new Path2D()), S = vr) : (Rr || (Rr = new Path2D()), S = Rr);
|
|
603
|
+
var G = D._routedPoints;
|
|
604
|
+
if (G && G.length >= 2)
|
|
605
|
+
io(S, G);
|
|
569
606
|
else if (ir === "straight")
|
|
570
|
-
|
|
607
|
+
S.moveTo(A, w), S.lineTo(T, m);
|
|
571
608
|
else if (ir === "step" || ir === "smoothstep")
|
|
572
609
|
try {
|
|
573
|
-
var
|
|
574
|
-
|
|
575
|
-
var Da =
|
|
610
|
+
var p = Va.position || "right", Ma = Ua.position || "left", c = 20, Z = A, F = w, J = T, rr = m;
|
|
611
|
+
p === "right" ? Z += c : p === "left" ? Z -= c : p === "bottom" ? F += c : p === "top" && (F -= c), Ma === "right" ? J += c : Ma === "left" ? J -= c : Ma === "bottom" ? rr += c : Ma === "top" && (rr -= c);
|
|
612
|
+
var Da = d(Vr), Fa = d(Ur), Aa = Vr.width || W, Ea = Vr.height || _, le = Ur.width || W, ie = Ur.height || _, ct = p === "left" || p === "right", he = Ma === "left" || Ma === "right", Tt = {};
|
|
576
613
|
Tt[D.source] = !0, Tt[D.target] = !0;
|
|
577
|
-
var
|
|
578
|
-
Math.min(
|
|
579
|
-
Math.min(
|
|
580
|
-
Math.max(
|
|
581
|
-
Math.max(
|
|
614
|
+
var ar = yo(
|
|
615
|
+
Math.min(A, T) - Aa,
|
|
616
|
+
Math.min(w, m) - Ea,
|
|
617
|
+
Math.max(A, T) + le,
|
|
618
|
+
Math.max(w, m) + ie,
|
|
582
619
|
Tt
|
|
583
620
|
);
|
|
584
|
-
|
|
585
|
-
var
|
|
586
|
-
if (
|
|
587
|
-
var
|
|
588
|
-
if (ko ||
|
|
589
|
-
|
|
590
|
-
var mt = Mr(
|
|
621
|
+
ar.push(Vr), ar.push(Ur);
|
|
622
|
+
var P = [];
|
|
623
|
+
if (ct && he) {
|
|
624
|
+
var K, ko = p === "right" && Z < J, co = p === "left" && Z > J;
|
|
625
|
+
if (ko || co) {
|
|
626
|
+
K = (Z + J) / 2;
|
|
627
|
+
var mt = Mr(K, w, m, ar);
|
|
591
628
|
if (mt) {
|
|
592
|
-
var
|
|
593
|
-
|
|
629
|
+
var wt = d(mt), wr = mt.width || W;
|
|
630
|
+
K < wt.x + wr / 2 ? K = wt.x - c : K = wt.x + wr + c;
|
|
594
631
|
}
|
|
595
632
|
} else
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
var
|
|
599
|
-
if (
|
|
600
|
-
var ne =
|
|
601
|
-
|
|
602
|
-
{ x:
|
|
603
|
-
{ x:
|
|
633
|
+
p === "right" ? K = Math.max(Da.x + Aa, Fa.x + le) + c : K = Math.min(Da.x, Fa.x) - c;
|
|
634
|
+
P = [{ x: Z, y: w }, { x: K, y: w }, { x: K, y: m }, { x: J, y: m }];
|
|
635
|
+
var Rt = dr(K, J, m, ar);
|
|
636
|
+
if (Rt) {
|
|
637
|
+
var ne = d(Rt), To = Rt.height || _, ue = ne.y - c, se = ne.y + To + c, de = Math.abs(w - ue) <= Math.abs(w - se) ? ue : se;
|
|
638
|
+
P = [
|
|
639
|
+
{ x: Z, y: w },
|
|
640
|
+
{ x: K, y: w },
|
|
641
|
+
{ x: K, y: de },
|
|
604
642
|
{ x: J, y: de },
|
|
605
|
-
{ x:
|
|
606
|
-
{ x: Z, y: m }
|
|
643
|
+
{ x: J, y: m }
|
|
607
644
|
];
|
|
608
645
|
}
|
|
609
|
-
var zt = dr(
|
|
646
|
+
var zt = dr(Z, K, w, ar);
|
|
610
647
|
if (zt) {
|
|
611
|
-
var Me =
|
|
612
|
-
|
|
648
|
+
var Me = d(zt), mo = zt.height || _, ye = Me.y - c, ge = Me.y + mo + c, xe = Math.abs(m - ye) <= Math.abs(m - ge) ? ye : ge;
|
|
649
|
+
P.splice(
|
|
613
650
|
1,
|
|
614
651
|
0,
|
|
615
|
-
{ x:
|
|
616
|
-
{ x:
|
|
617
|
-
),
|
|
618
|
-
return !(Math.abs(Lr.x -
|
|
619
|
-
}),
|
|
652
|
+
{ x: Z, y: xe },
|
|
653
|
+
{ x: K, y: xe }
|
|
654
|
+
), P = P.filter(function(Lr, ro) {
|
|
655
|
+
return !(Math.abs(Lr.x - K) < 1 && Math.abs(Lr.y - w) < 1);
|
|
656
|
+
}), P.splice(0, 0, { x: Z, y: w });
|
|
620
657
|
}
|
|
621
|
-
} else if (!
|
|
622
|
-
var
|
|
623
|
-
if (wo ||
|
|
624
|
-
|
|
625
|
-
var
|
|
626
|
-
if (
|
|
627
|
-
var
|
|
628
|
-
|
|
658
|
+
} else if (!ct && !he) {
|
|
659
|
+
var Q, wo = p === "bottom" && F < rr, Ro = p === "top" && F > rr;
|
|
660
|
+
if (wo || Ro) {
|
|
661
|
+
Q = (F + rr) / 2;
|
|
662
|
+
var _t = dr(A, T, Q, ar);
|
|
663
|
+
if (_t) {
|
|
664
|
+
var At = d(_t), ke = _t.height || _;
|
|
665
|
+
Q < At.y + ke / 2 ? Q = At.y - c : Q = At.y + ke + c;
|
|
629
666
|
}
|
|
630
667
|
} else
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
var
|
|
634
|
-
if (
|
|
635
|
-
var
|
|
636
|
-
|
|
637
|
-
{ x:
|
|
668
|
+
p === "bottom" ? Q = Math.max(Da.y + Ea, Fa.y + ie) + c : Q = Math.min(Da.y, Fa.y) - c;
|
|
669
|
+
P = [{ x: A, y: F }, { x: A, y: Q }, { x: T, y: Q }, { x: T, y: rr }];
|
|
670
|
+
var Et = Mr(A, F, Q, ar);
|
|
671
|
+
if (Et) {
|
|
672
|
+
var ce = d(Et), zo = Et.width || W, Te = ce.x - c, me = ce.x + zo + c, we = Math.abs(T - Te) <= Math.abs(T - me) ? Te : me;
|
|
673
|
+
P = [
|
|
674
|
+
{ x: A, y: F },
|
|
638
675
|
{ x: we, y: F },
|
|
639
|
-
{ x: we, y:
|
|
640
|
-
{ x: T, y:
|
|
641
|
-
{ x: T, y:
|
|
676
|
+
{ x: we, y: Q },
|
|
677
|
+
{ x: T, y: Q },
|
|
678
|
+
{ x: T, y: rr }
|
|
642
679
|
];
|
|
643
680
|
}
|
|
644
|
-
var
|
|
645
|
-
if (
|
|
646
|
-
var
|
|
647
|
-
|
|
648
|
-
|
|
681
|
+
var Wt = Mr(T, Q, rr, ar);
|
|
682
|
+
if (Wt) {
|
|
683
|
+
var Re = d(Wt), _o = Wt.height || _, ze = Re.y - c, _e = Re.y + _o + c, Ao = Math.abs(Q - ze) <= Math.abs(Q - _e) ? ze : _e;
|
|
684
|
+
P.splice(
|
|
685
|
+
P.length - 1,
|
|
649
686
|
0,
|
|
650
|
-
{ x:
|
|
687
|
+
{ x: J, y: Ao }
|
|
651
688
|
);
|
|
652
689
|
}
|
|
653
|
-
} else if (
|
|
654
|
-
|
|
655
|
-
var
|
|
656
|
-
if (Wt) {
|
|
657
|
-
var Ae = h(Wt), Eo = Wt.width || E, Ee = Ae.x - k, We = Ae.x + Eo + k, Le = Math.abs(_ - Ee) <= Math.abs(_ - We) ? Ee : We;
|
|
658
|
-
b = [{ x: I, y: R }, { x: Le, y: R }, { x: Le, y: m }, { x: T, y: m }, { x: T, y: p }];
|
|
659
|
-
}
|
|
660
|
-
var Lt = dr(I, T, R, rr);
|
|
690
|
+
} else if (ct) {
|
|
691
|
+
P = [{ x: Z, y: w }, { x: T, y: w }, { x: T, y: rr }];
|
|
692
|
+
var Lt = Mr(T, w, rr, ar);
|
|
661
693
|
if (Lt) {
|
|
662
|
-
var
|
|
663
|
-
|
|
694
|
+
var Ae = d(Lt), Eo = Lt.width || W, Ee = Ae.x - c, We = Ae.x + Eo + c, Le = Math.abs(A - Ee) <= Math.abs(A - We) ? Ee : We;
|
|
695
|
+
P = [{ x: Z, y: w }, { x: Le, y: w }, { x: Le, y: m }, { x: T, y: m }, { x: T, y: rr }];
|
|
664
696
|
}
|
|
665
|
-
|
|
666
|
-
b = [{ x: _, y: F }, { x: _, y: m }, { x: Z, y: m }];
|
|
667
|
-
var Ct = dr(_, Z, m, rr);
|
|
697
|
+
var Ct = dr(Z, T, w, ar);
|
|
668
698
|
if (Ct) {
|
|
669
|
-
var
|
|
670
|
-
|
|
699
|
+
var Ce = d(Ct), Wo = Ct.height || _, be = Ce.y - c, Be = Ce.y + Wo + c, Ne = Math.abs(m - be) <= Math.abs(m - Be) ? be : Be;
|
|
700
|
+
P = [{ x: Z, y: w }, { x: Z, y: Ne }, { x: T, y: Ne }, { x: T, y: rr }];
|
|
671
701
|
}
|
|
672
|
-
|
|
702
|
+
} else {
|
|
703
|
+
P = [{ x: A, y: F }, { x: A, y: m }, { x: J, y: m }];
|
|
704
|
+
var bt = dr(A, J, m, ar);
|
|
705
|
+
if (bt) {
|
|
706
|
+
var Pe = d(bt), Lo = bt.height || _, qe = Pe.y - c, Se = Pe.y + Lo + c, Ge = Math.abs(w - qe) <= Math.abs(w - Se) ? qe : Se;
|
|
707
|
+
P = [{ x: A, y: F }, { x: A, y: Ge }, { x: J, y: Ge }, { x: J, y: m }];
|
|
708
|
+
}
|
|
709
|
+
var Bt = Mr(A, F, m, ar);
|
|
673
710
|
if (Bt) {
|
|
674
|
-
var Ie =
|
|
675
|
-
|
|
711
|
+
var Ie = d(Bt), Co = Bt.width || W, Ze = Ie.x - c, Je = Ie.x + Co + c, Ke = Math.abs(T - Ze) <= Math.abs(T - Je) ? Ze : Je;
|
|
712
|
+
P = [{ x: A, y: F }, { x: Ke, y: F }, { x: Ke, y: m }, { x: J, y: m }];
|
|
676
713
|
}
|
|
677
714
|
}
|
|
678
|
-
for (var Dr = [{ x:
|
|
715
|
+
for (var Dr = [{ x: A, y: w }], Nt = 0; Nt < P.length; Nt++) Dr.push(P[Nt]);
|
|
679
716
|
Dr.push({ x: T, y: m });
|
|
680
|
-
for (var
|
|
681
|
-
var La =
|
|
682
|
-
(Math.abs(Dr[Wa].x - La.x) > 0.1 || Math.abs(Dr[Wa].y - La.y) > 0.1) &&
|
|
717
|
+
for (var tr = [Dr[0]], Wa = 1; Wa < Dr.length; Wa++) {
|
|
718
|
+
var La = tr[tr.length - 1];
|
|
719
|
+
(Math.abs(Dr[Wa].x - La.x) > 0.1 || Math.abs(Dr[Wa].y - La.y) > 0.1) && tr.push(Dr[Wa]);
|
|
683
720
|
}
|
|
684
721
|
var Qe = ir === "smoothstep" ? 8 : 0;
|
|
685
|
-
|
|
686
|
-
for (var ur = 1; ur <
|
|
687
|
-
if (Qe > 0 && ur > 0 && ur <
|
|
688
|
-
var sr =
|
|
689
|
-
if (Math.abs(sr.x -
|
|
690
|
-
|
|
722
|
+
S.moveTo(tr[0].x, tr[0].y);
|
|
723
|
+
for (var ur = 1; ur < tr.length; ur++)
|
|
724
|
+
if (Qe > 0 && ur > 0 && ur < tr.length - 1) {
|
|
725
|
+
var sr = tr[ur - 1], E = tr[ur], zr = tr[ur + 1];
|
|
726
|
+
if (Math.abs(sr.x - E.x) < 0.5 && Math.abs(E.x - zr.x) < 0.5 || Math.abs(sr.y - E.y) < 0.5 && Math.abs(E.y - zr.y) < 0.5)
|
|
727
|
+
S.lineTo(E.x, E.y);
|
|
691
728
|
else {
|
|
692
|
-
var ja = Math.min(Math.hypot(sr.x -
|
|
693
|
-
Math.abs(sr.y -
|
|
729
|
+
var ja = Math.min(Math.hypot(sr.x - E.x, sr.y - E.y) / 2, Math.hypot(E.x - zr.x, E.y - zr.y) / 2, Qe);
|
|
730
|
+
Math.abs(sr.y - E.y) < 0.5 ? (S.lineTo(E.x + (sr.x < zr.x ? -1 : 1) * ja, E.y), S.quadraticCurveTo(E.x, E.y, E.x, E.y + (sr.y < zr.y ? 1 : -1) * ja)) : (S.lineTo(E.x, E.y + (sr.y < zr.y ? -1 : 1) * ja), S.quadraticCurveTo(E.x, E.y, E.x + (sr.x < zr.x ? 1 : -1) * ja, E.y));
|
|
694
731
|
}
|
|
695
732
|
} else
|
|
696
|
-
|
|
733
|
+
S.lineTo(tr[ur].x, tr[ur].y);
|
|
697
734
|
} catch (Lr) {
|
|
698
735
|
console.error("[worker] smoothstep error:", Lr, "edge:", D.id);
|
|
699
736
|
}
|
|
700
737
|
else {
|
|
701
|
-
var _r = Va.position || "right", Ar = Ua.position || "left", Er = 20, Ca =
|
|
702
|
-
_r === "right" ? Ca += Er : _r === "left" ? Ca -= Er : _r === "bottom" ? Oa += Er : _r === "top" && (Oa -= Er), Ar === "right" ?
|
|
703
|
-
var
|
|
704
|
-
|
|
738
|
+
var _r = Va.position || "right", Ar = Ua.position || "left", Er = 20, Ca = A, Oa = w, ba = T, Xa = m;
|
|
739
|
+
_r === "right" ? Ca += Er : _r === "left" ? Ca -= Er : _r === "bottom" ? Oa += Er : _r === "top" && (Oa -= Er), Ar === "right" ? ba += Er : Ar === "left" ? ba -= Er : Ar === "bottom" ? Xa += Er : Ar === "top" && (Xa -= Er);
|
|
740
|
+
var bo = Math.abs(ba - Ca), Wr = Math.max(50, bo * 0.5), Bo = Ca + (_r === "left" ? -Wr : _r === "right" ? Wr : 0), No = Oa + (_r === "top" ? -Wr : _r === "bottom" ? Wr : 0), Po = ba + (Ar === "left" ? -Wr : Ar === "right" ? Wr : 0), qo = Xa + (Ar === "top" ? -Wr : Ar === "bottom" ? Wr : 0);
|
|
741
|
+
S.moveTo(A, w), S.lineTo(Ca, Oa), S.bezierCurveTo(Bo, No, Po, qo, ba, Xa), S.lineTo(T, m);
|
|
705
742
|
}
|
|
706
|
-
if (
|
|
707
|
-
var
|
|
708
|
-
if (
|
|
709
|
-
var La =
|
|
710
|
-
|
|
743
|
+
if (go) {
|
|
744
|
+
var So = 8, Ba;
|
|
745
|
+
if (G && G.length >= 2) {
|
|
746
|
+
var La = G[G.length - 1], $e = G[G.length - 2];
|
|
747
|
+
Ba = Math.atan2(La.y - $e.y, La.x - $e.x);
|
|
711
748
|
} else if (ir === "straight")
|
|
712
|
-
|
|
749
|
+
Ba = Math.atan2(m - w, T - A);
|
|
713
750
|
else if (ir === "step" || ir === "smoothstep")
|
|
714
|
-
|
|
751
|
+
Ba = 0;
|
|
715
752
|
else {
|
|
716
|
-
var Ve =
|
|
717
|
-
|
|
753
|
+
var Ve = ae(A, w, T, m);
|
|
754
|
+
Ba = Math.atan2(m - Ve.cp2y, T - Ve.cp2x);
|
|
718
755
|
}
|
|
719
|
-
var Ue =
|
|
720
|
-
fe ? _a.push(
|
|
756
|
+
var Ue = G && G.length >= 2 ? G[G.length - 1] : { x: T, y: m }, Pt = { x: Ue.x, y: Ue.y, angle: Ba, size: So };
|
|
757
|
+
fe ? _a.push(Pt) : ve ? $r.push(Pt) : za.push(Pt);
|
|
721
758
|
}
|
|
722
759
|
if ($a && D.label) {
|
|
723
760
|
var Na;
|
|
724
|
-
|
|
761
|
+
G && G.length >= 2 ? Na = af(G) : ir === "straight" || ir === "step" || ir === "smoothstep" ? Na = { x: (A + T) / 2, y: (w + m) / 2 } : Na = tf(A, w, T, m), lr.push({ text: D.label, x: Na.x, y: Na.y });
|
|
725
762
|
}
|
|
726
763
|
}
|
|
727
764
|
}
|
|
728
|
-
if (
|
|
765
|
+
if (Rr && (r.strokeStyle = R.edgeStroke, r.lineWidth = 1.5, r.setLineDash([]), r.stroke(Rr)), vr && (r.strokeStyle = R.edgeAnimated, r.lineWidth = 1.5, r.setLineDash([5, 5]), r.lineDashOffset = -re, r.stroke(vr), r.setLineDash([])), nr && (r.strokeStyle = R.edgeSelected, r.lineWidth = 2.5, r.setLineDash([]), r.stroke(nr)), ot(za, R.edgeStroke), ot($r, R.edgeAnimated), ot(_a, R.edgeSelected), lr.length > 0) {
|
|
729
766
|
r.font = Ho, r.textAlign = "center", r.textBaseline = "middle";
|
|
730
767
|
for (var qt = 0; qt < lr.length; qt++) {
|
|
731
|
-
var
|
|
732
|
-
r.fillStyle =
|
|
768
|
+
var ya = lr[qt], Go = r.measureText(ya.text), De = Go.width + 12;
|
|
769
|
+
r.fillStyle = I ? "#2a2a2a" : "#ffffff", r.fillRect(ya.x - De / 2, ya.y - 9, De, 18), r.fillStyle = R.nodeText, r.fillText(ya.text, ya.x, ya.y);
|
|
733
770
|
}
|
|
734
771
|
r.textAlign = "start", r.textBaseline = "alphabetic";
|
|
735
772
|
}
|
|
736
773
|
}
|
|
737
|
-
if (
|
|
738
|
-
r.beginPath(), r.strokeStyle =
|
|
739
|
-
var St =
|
|
774
|
+
if (Ga) {
|
|
775
|
+
r.beginPath(), r.strokeStyle = R.connectionLine, r.lineWidth = 2, r.setLineDash([6, 4]);
|
|
776
|
+
var St = Ga._routedPoints;
|
|
740
777
|
if (St && St.length >= 2) {
|
|
741
778
|
var Fe = new Path2D();
|
|
742
779
|
io(Fe, St), r.stroke(Fe);
|
|
743
780
|
} else {
|
|
744
|
-
var Ha =
|
|
781
|
+
var Ha = Ga.from, Ya = Ga.to, pa = ae(Ha.x, Ha.y, Ya.x, Ya.y);
|
|
745
782
|
r.moveTo(Ha.x, Ha.y), r.bezierCurveTo(pa.cp1x, pa.cp1y, pa.cp2x, pa.cp2y, Ya.x, Ya.y), r.stroke();
|
|
746
783
|
}
|
|
747
784
|
r.setLineDash([]);
|
|
748
785
|
}
|
|
749
786
|
if (hr) {
|
|
750
787
|
var je = Math.min(hr.startWorld.x, hr.endWorld.x), Oe = Math.min(hr.startWorld.y, hr.endWorld.y), Aa = Math.abs(hr.endWorld.x - hr.startWorld.x), Ea = Math.abs(hr.endWorld.y - hr.startWorld.y);
|
|
751
|
-
r.fillStyle =
|
|
788
|
+
r.fillStyle = I ? "rgba(59,130,246,0.08)" : "rgba(59,130,246,0.06)", r.fillRect(je, Oe, Aa, Ea), r.strokeStyle = "#3b82f6", r.lineWidth = 1 / x.zoom, r.setLineDash([]), r.strokeRect(je, Oe, Aa, Ea);
|
|
752
789
|
}
|
|
753
790
|
if (U > 0) {
|
|
754
|
-
var Io =
|
|
791
|
+
var Io = x.zoom > 0.12 && (x.zoom > 0.25 || U < 500), Xe = x.zoom > 0.08 && U < 200, Zo = x.zoom > 0.2 && U < 300;
|
|
755
792
|
if (Xe) {
|
|
756
|
-
r.shadowColor =
|
|
793
|
+
r.shadowColor = R.nodeShadow, r.shadowBlur = 6, r.shadowOffsetY = 2, r.fillStyle = R.nodeBg, r.beginPath();
|
|
757
794
|
for (var Gt = 0; Gt < U; Gt++) {
|
|
758
795
|
var rt = V[Gt];
|
|
759
|
-
r.roundRect(
|
|
796
|
+
r.roundRect(d(rt).x, d(rt).y, rt.width || W, rt.height || _, ft);
|
|
760
797
|
}
|
|
761
798
|
r.fill(), r.shadowColor = "transparent", r.shadowBlur = 0, r.shadowOffsetY = 0;
|
|
762
799
|
}
|
|
763
800
|
if (!Xe) {
|
|
764
|
-
r.fillStyle =
|
|
765
|
-
for (var
|
|
766
|
-
var at = V[
|
|
767
|
-
r.roundRect(
|
|
801
|
+
r.fillStyle = R.nodeBg, r.beginPath();
|
|
802
|
+
for (var It = 0; It < U; It++) {
|
|
803
|
+
var at = V[It];
|
|
804
|
+
r.roundRect(d(at).x, d(at).y, at.width || W, at.height || _, ft);
|
|
768
805
|
}
|
|
769
806
|
r.fill();
|
|
770
807
|
}
|
|
771
|
-
r.strokeStyle =
|
|
772
|
-
for (var
|
|
773
|
-
var
|
|
774
|
-
|
|
808
|
+
r.strokeStyle = R.nodeBorder, r.lineWidth = 1, r.beginPath();
|
|
809
|
+
for (var Zt = 0; Zt < U; Zt++) {
|
|
810
|
+
var Pa = V[Zt];
|
|
811
|
+
Pa.selected || r.roundRect(d(Pa).x, d(Pa).y, Pa.width || W, Pa.height || _, ft);
|
|
775
812
|
}
|
|
776
813
|
r.stroke();
|
|
777
814
|
var He = !1;
|
|
778
|
-
r.strokeStyle =
|
|
779
|
-
for (var
|
|
780
|
-
var
|
|
781
|
-
|
|
815
|
+
r.strokeStyle = R.nodeSelectedBorder, r.lineWidth = 2, r.beginPath();
|
|
816
|
+
for (var Jt = 0; Jt < U; Jt++) {
|
|
817
|
+
var qa = V[Jt];
|
|
818
|
+
qa.selected && (He = !0, r.roundRect(d(qa).x, d(qa).y, qa.width || W, qa.height || _, ft));
|
|
782
819
|
}
|
|
783
820
|
if (He && r.stroke(), Io) {
|
|
784
|
-
r.fillStyle =
|
|
785
|
-
for (var
|
|
786
|
-
var Fr = V[
|
|
821
|
+
r.fillStyle = R.nodeText, r.font = Xo, r.textAlign = "center", r.textBaseline = "middle";
|
|
822
|
+
for (var Kt = 0; Kt < U; Kt++) {
|
|
823
|
+
var Fr = V[Kt];
|
|
787
824
|
if (!(!Fr.data || !Fr.data.label)) {
|
|
788
|
-
var Ye = Fr.width ||
|
|
789
|
-
r.fillText(Fr.data.label,
|
|
825
|
+
var Ye = Fr.width || W, Jo = Fr.height || _;
|
|
826
|
+
r.fillText(Fr.data.label, d(Fr).x + Ye / 2, d(Fr).y + Jo / 2, Ye - 24);
|
|
790
827
|
}
|
|
791
828
|
}
|
|
792
829
|
r.textAlign = "start", r.textBaseline = "alphabetic";
|
|
793
830
|
}
|
|
794
831
|
if (Zo) {
|
|
795
|
-
for (var
|
|
796
|
-
for (var pe = ho(V[
|
|
797
|
-
|
|
798
|
-
r.fillStyle =
|
|
799
|
-
for (var
|
|
800
|
-
var tt =
|
|
832
|
+
for (var Qt = [], $t = 0; $t < U; $t++)
|
|
833
|
+
for (var pe = ho(V[$t]), Vt = 0; Vt < pe.length; Vt++)
|
|
834
|
+
Qt.push(pe[Vt]);
|
|
835
|
+
r.fillStyle = R.handleFill, r.beginPath();
|
|
836
|
+
for (var Ut = 0; Ut < Qt.length; Ut++) {
|
|
837
|
+
var tt = Qt[Ut];
|
|
801
838
|
r.moveTo(tt.x + ao, tt.y), r.arc(tt.x, tt.y, ao, 0, 6.2832);
|
|
802
839
|
}
|
|
803
|
-
r.fill(), r.strokeStyle =
|
|
840
|
+
r.fill(), r.strokeStyle = R.handleBorder, r.lineWidth = 1.5, r.stroke();
|
|
804
841
|
}
|
|
805
842
|
}
|
|
806
843
|
r.restore();
|
|
807
844
|
var Ko = (performance.now() - a).toFixed(1);
|
|
808
|
-
|
|
845
|
+
Ot++;
|
|
809
846
|
var et = performance.now();
|
|
810
|
-
if (et - oo >= 1e3 && (fo =
|
|
847
|
+
if (et - oo >= 1e3 && (fo = Ot, Ot = 0, oo = et), et - vo >= 100) {
|
|
811
848
|
vo = et;
|
|
812
|
-
var Qo = Math.round(-
|
|
849
|
+
var Qo = Math.round(-x.x / x.zoom), $o = Math.round(-x.y / x.zoom);
|
|
813
850
|
self.postMessage({
|
|
814
851
|
type: "hud",
|
|
815
852
|
data: {
|
|
816
853
|
wx: Qo,
|
|
817
854
|
wy: $o,
|
|
818
|
-
zoom:
|
|
855
|
+
zoom: x.zoom.toFixed(2),
|
|
819
856
|
renderMs: Ko,
|
|
820
857
|
fps: fo,
|
|
821
|
-
visible: O.length > 0 ? to(
|
|
858
|
+
visible: O.length > 0 ? to(Sr, Gr, pr, Ir).length : 0,
|
|
822
859
|
nodeCount: B.length,
|
|
823
860
|
visibleNodes: U,
|
|
824
|
-
edgeCount:
|
|
861
|
+
edgeCount: b.length
|
|
825
862
|
}
|
|
826
863
|
});
|
|
827
864
|
}
|
|
828
865
|
}
|
|
829
866
|
}
|
|
830
|
-
`,Bn=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",Gn],{type:"text/javascript;charset=utf-8"});function jr(t){let e;try{if(e=Bn&&(self.URL||self.webkitURL).createObjectURL(Bn),!e)throw"";const n=new Worker(e,{type:"module",name:t==null?void 0:t.name});return n.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),n}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(Gn),{type:"module",name:t==null?void 0:t.name})}}const gn=new WeakMap;function Dr(t,e){if(gn.has(t))return gn.get(t);const n=t.transferControlToOffscreen(),r=new jr;r.onerror=o=>console.error("[infinite-canvas] worker error:",o.message,o),r.postMessage({type:"init",data:{...e,canvas:n}},[n]);const s={worker:r};return gn.set(t,s),s}const Gt=160,Ft=60,Ar=10;function On({cards:t=[],nodes:e=[],edges:n=[],onHudUpdate:r,onNodesProcessed:s,onNodesChange:o,onEdgesChange:i,onConnect:l,onNodeClick:d,onNodeDragStart:u,onNodeDrag:x,onNodeDragStop:b,onEdgeClick:L,onEdgeDoubleClick:E,onEdgeMouseEnter:k,onEdgeMouseMove:T,onEdgeMouseLeave:C,onEdgeContextMenu:z,onNodeDoubleClick:_,onNodeMouseEnter:j,onNodeMouseMove:D,onNodeMouseLeave:h,onNodeContextMenu:y,onPaneClick:p,onPaneContextMenu:R,onPaneMouseEnter:w,onPaneMouseMove:P,onPaneMouseLeave:m,onSelectionChange:B,onConnectStart:q,onConnectEnd:W,onInit:gt,onMoveStart:K,onMove:nt,onMoveEnd:U,onDelete:G,onBeforeDelete:rt,onError:ct,isValidConnection:lt,dark:ot,gridSize:Nt=40,zoomMin:st=.1,zoomMax:xt=4,initialCamera:Et={x:0,y:0,zoom:1},fitView:Rt=!1,fitViewOptions:ut,nodesDraggable:dt=!0,nodesConnectable:wt=!0,elementsSelectable:zt=!0,multiSelectionKeyCode:ht="Shift",selectionOnDrag:Qt=!1,selectionMode:Re="partial",connectionMode:It="loose",connectionRadius:Xt=20,connectOnClick:Ht=!1,snapToGrid:fe=!1,snapGrid:se=[15,15],deleteKeyCode:he=["Delete","Backspace"],panActivationKeyCode:ye=" ",panOnScroll:Fe=!1,panOnScrollMode:ke="free",panOnScrollSpeed:Xe=.5,zoomOnScroll:Ye=!0,zoomOnDoubleClick:Ue=!0,zoomOnPinch:qe=!0,preventScrolling:Ce=!0,translateExtent:Kt,nodeExtent:Vt,defaultEdgeOptions:ge={},autoPanOnNodeDrag:cn=!0,autoPanOnConnect:ln=!0,autoPanSpeed:Yt=5,edgesReconnectable:In=!1,elevateNodesOnSelect:un=!1,edgeRouting:ie=!0}={}){const pt=a.useRef(null),Ee=a.useRef(null),kt=a.useRef(null),yt=a.useRef({...Et}),Jt=a.useRef([...t]),O=a.useRef([...e]),Pt=a.useRef([...n]),dn=a.useRef(new Map),ze=a.useRef(!1),Ot=a.useRef(null),[fn,hn]=a.useState(!1),Bt=a.useRef(null),jt=a.useRef(null),xe=a.useRef(null),te=a.useRef(null),_t=a.useRef(!1),pe=a.useRef(null),[Ne,Ge]=a.useState({x:Et.x,y:Et.y,zoom:Et.zoom}),[Oe,ee]=a.useState(null),Ut=a.useMemo(()=>new Set,[]),ae=a.useMemo(()=>new Set,[]),me=a.useRef(!1),Z=a.useRef({});Z.current={onHudUpdate:r,onNodesProcessed:s,onNodesChange:o,onEdgesChange:i,onConnect:l,onNodeClick:d,onNodeDragStart:u,onNodeDrag:x,onNodeDragStop:b,onEdgeClick:L,onEdgeDoubleClick:E,onEdgeMouseEnter:k,onEdgeMouseMove:T,onEdgeMouseLeave:C,onEdgeContextMenu:z,onNodeDoubleClick:_,onNodeMouseEnter:j,onNodeMouseMove:D,onNodeMouseLeave:h,onNodeContextMenu:y,onPaneClick:p,onPaneContextMenu:R,onPaneMouseEnter:w,onPaneMouseMove:P,onPaneMouseLeave:m,onSelectionChange:B,onConnectStart:q,onConnectEnd:W,onInit:gt,onMoveStart:K,onMove:nt,onMoveEnd:U,onDelete:G,onBeforeDelete:rt,onError:ct,isValidConnection:lt};const vt={get current(){return Z.current.onNodesChange}},St={get current(){return Z.current.onEdgesChange}},ne={get current(){return Z.current.onConnect}},Pe={get current(){return Z.current.onNodeClick}},Le={get current(){return Z.current.onNodeDragStart}},Ie={get current(){return Z.current.onNodeDrag}},Se={get current(){return Z.current.onNodeDragStop}},re={get current(){return Z.current.onEdgeClick}},Te={get current(){return Z.current.onPaneClick}},ce={get current(){return Z.current.onSelectionChange}},le={get current(){return Z.current.onHudUpdate}},ue={get current(){return Z.current.onNodesProcessed}};a.useEffect(()=>{const c=f=>{f.key===ht&&(_t.current=!0),f.key===ye&&(me.current=!0)},v=f=>{f.key===ht&&(_t.current=!1),f.key===ye&&(me.current=!1)};return window.addEventListener("keydown",c),window.addEventListener("keyup",v),()=>{window.removeEventListener("keydown",c),window.removeEventListener("keyup",v)}},[ht,ye]);const qt=a.useCallback(()=>{var M;const c=O.current.filter(I=>I.selected),v=Pt.current.filter(I=>I.selected),f={nodes:c,edges:v};(M=ce.current)==null||M.call(ce,f);for(const I of ae)I(f)},[ae]);a.useEffect(()=>{var c;Jt.current=[...t],(c=kt.current)==null||c.postMessage({type:"cards",data:{cards:[...t]}})},[t]);const ve=a.useCallback(c=>{const v={};for(const f of c)v[f.id]=f;return c.map(f=>{if(!f.parentId)return f;const M=v[f.parentId];if(!M)return f;let I=f.position.x,S=f.position.y,g=M;for(;g;)I+=g.position.x,S+=g.position.y,g=g.parentId?v[g.parentId]:null;return{...f,_absolutePosition:{x:I,y:S}}})},[]),Zt=a.useRef([]),Q=a.useCallback(c=>{const v=dn.current;if(!v||v.size===0)return c;const f={};for(const[,M]of v)f[M.nodeId]||(f[M.nodeId]=[]),f[M.nodeId].push({id:M.id,type:M.type,position:M.position,x:M.x,y:M.y});return c.map(M=>{const I=f[M.id];return I&&I.length>0?{...M,handles:I}:M})},[]),At=a.useCallback(()=>{var v;if(Bt.current)return;const c=Q(Zt.current);(v=kt.current)==null||v.postMessage({type:"nodes",data:{nodes:c}})},[Q]);a.useEffect(()=>{var f;if(Bt.current){const M=Bt.current.id,I=new Set([M,...Bt.current.selectedStarts.map(g=>g.id)]),S={};for(const g of O.current)I.has(g.id)&&(S[g.id]={...g.position});O.current=[...e];for(const g of O.current)S[g.id]&&(g.position=S[g.id]);Zt.current=ve(O.current);return}O.current=[...e];const c=ve(e);Zt.current=c;const v=Q(c);(f=kt.current)==null||f.postMessage({type:"nodes",data:{nodes:v}})},[e,ve,Q]),a.useEffect(()=>{var c;Pt.current=[...n],(c=kt.current)==null||c.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const it=a.useCallback((c,v)=>{const f=pt.current;if(!f)return{x:0,y:0};const M=f.getBoundingClientRect(),I=yt.current;return{x:(c-M.left-I.x)/I.zoom,y:(v-M.top-I.y)/I.zoom}},[]),Lt=a.useCallback((c,v)=>{const f=Zt.current.length>0?Zt.current:O.current;let M=null;for(let I=f.length-1;I>=0;I--){const S=f[I];if(S.hidden)continue;const g=S._absolutePosition||S.position,A=S.width||Gt,$=S.height||Ft;if(c>=g.x&&c<=g.x+A&&v>=g.y&&v<=g.y+$){if(S.type==="group"){M||(M=S);continue}return S}}return M},[]),de=a.useCallback((c,v)=>{const f=v.width||Gt,M=v.height||Ft;if(c.x!==void 0&&c.y!==void 0)return{x:v.position.x+c.x,y:v.position.y+c.y};switch(c.position||(c.type==="source"?"right":"left")){case"top":return{x:v.position.x+f/2,y:v.position.y};case"bottom":return{x:v.position.x+f/2,y:v.position.y+M};case"left":return{x:v.position.x,y:v.position.y+M/2};case"right":return{x:v.position.x+f,y:v.position.y+M/2};default:return{x:v.position.x+f,y:v.position.y+M/2}}},[]),be=a.useCallback(c=>{const v=c.width||Gt,f=c.height||Ft;return c.handles&&c.handles.length>0?c.handles.map(M=>{const I=de(M,c);return{id:M.id||null,type:M.type,x:I.x,y:I.y}}):[{id:null,type:"target",x:c.position.x,y:c.position.y+f/2},{id:null,type:"source",x:c.position.x+v,y:c.position.y+f/2}]},[de]),Ze=a.useCallback((c,v)=>{const f=O.current,M=yt.current,I=Math.max(Ar,Xt)/M.zoom;for(let S=f.length-1;S>=0;S--){const g=f[S];if(g.hidden)continue;const A=be(g);for(const $ of A)if(Math.abs(c-$.x)<I&&Math.abs(v-$.y)<I)return{nodeId:g.id,handleId:$.id,type:$.type,x:$.x,y:$.y}}return null},[be]),oe=a.useCallback((c,v)=>{const M=8/yt.current.zoom;for(let I=Pt.current.length-1;I>=0;I--){const S=Pt.current[I],g=O.current.find(bt=>bt.id===S.source),A=O.current.find(bt=>bt.id===S.target);if(!g||!A)continue;const $=g.width||Gt,X=g.height||Ft,H=A.height||Ft,V=g.position.x+$,at=g.position.y+X/2,Y=A.position.x,et=A.position.y+H/2;if(Hr(c,v,V,at,Y,et)<M)return S}return null},[]);a.useEffect(()=>{const c=Ee.current,v=pt.current;if(!c||!v)return;const f=v.getBoundingClientRect(),M=ot!==void 0?ot:matchMedia("(prefers-color-scheme: dark)").matches,I=ve(O.current);Zt.current=I;const S=Q(I),{worker:g}=Dr(c,{width:f.width,height:f.height,camera:yt.current,cards:Jt.current,nodes:S,edges:Pt.current,dark:M,gridSize:Nt,edgeRouting:ie});g.onmessage=H=>{var V,at;H.data.type==="hud"&&((V=le.current)==null||V.call(le,H.data.data)),H.data.type==="ready"&&hn(!0),H.data.type==="nodesProcessed"&&((at=ue.current)==null||at.call(ue,H.data.data))},kt.current=g;const A=new ResizeObserver(H=>{const{width:V,height:at}=H[0].contentRect;g.postMessage({type:"resize",data:{width:V,height:at}})});A.observe(v);let $,X;return ot===void 0&&($=matchMedia("(prefers-color-scheme: dark)"),X=H=>g.postMessage({type:"theme",data:{dark:H.matches}}),$.addEventListener("change",X)),()=>{A.disconnect(),$&&X&&$.removeEventListener("change",X),kt.current=null}},[]),a.useEffect(()=>{var c;ot!==void 0&&((c=kt.current)==null||c.postMessage({type:"theme",data:{dark:ot}}))},[ot]),a.useEffect(()=>{var c;(c=kt.current)==null||c.postMessage({type:"edgeRouting",data:{enabled:ie}})},[ie]);const Sn=a.useRef(0),Ct=a.useCallback((c=null)=>{var M,I,S;const v=yt.current;if(Kt){const g=pt.current;if(g){const A=g.getBoundingClientRect(),$=-Kt[1][0]*v.zoom+A.width,X=-Kt[1][1]*v.zoom+A.height,H=-Kt[0][0]*v.zoom,V=-Kt[0][1]*v.zoom;v.x=Math.min(H,Math.max($,v.x)),v.y=Math.min(V,Math.max(X,v.y))}}(M=kt.current)==null||M.postMessage({type:"camera",data:{camera:{...v}}});const f={x:v.x,y:v.y,zoom:v.zoom};(S=(I=Z.current).onMove)==null||S.call(I,c,f);for(const g of Ut)g(f);cancelAnimationFrame(Sn.current),Sn.current=requestAnimationFrame(()=>{Ge({x:v.x,y:v.y,zoom:v.zoom})})},[Ut,Kt]),we=a.useCallback(()=>{var f,M;const c=jt.current,v=xe.current;c&&v?((f=kt.current)==null||f.postMessage({type:"connecting",data:{from:c.startPos,to:v,_routedPoints:null}}),ee({source:c.sourceId,sourceHandle:c.sourceHandle,target:null,targetHandle:null})):((M=kt.current)==null||M.postMessage({type:"connecting",data:null}),ee(null))},[]),Me=a.useCallback(()=>{var v,f;const c=te.current;c?(v=kt.current)==null||v.postMessage({type:"selectionBox",data:c}):(f=kt.current)==null||f.postMessage({type:"selectionBox",data:null})},[]),hr=a.useCallback(c=>{var I,S,g,A,$,X,H,V,at,Y,et,mt,bt,Tt,Dt,$t;const v=O.current.length>0,f=it(c.clientX,c.clientY),M=_t.current;if(v&&wt){const F=Ze(f.x,f.y);if(Ht&&pe.current&&F){const J=pe.current;if(F.nodeId!==J.nodeId){const Wt=J.handleType==="target"?{source:F.nodeId,target:J.nodeId,sourceHandle:F.handleId||null,targetHandle:J.handleId}:{source:J.nodeId,target:F.nodeId,sourceHandle:J.handleId,targetHandle:F.handleId||null};(Z.current.isValidConnection?Z.current.isValidConnection(Wt):!0)&&((I=ne.current)==null||I.call(ne,{...Wt,...ge}))}pe.current=null;return}if(It==="strict"?F&&F.type==="source":F!=null){if(Ht){pe.current={nodeId:F.nodeId,handleId:F.handleId||null,handleType:F.type},(g=(S=Z.current).onConnectStart)==null||g.call(S,c,{nodeId:F.nodeId,handleId:F.handleId,handleType:F.type});return}jt.current={sourceId:F.nodeId,sourceHandle:F.handleId||null,sourceType:F.type,startPos:{x:F.x,y:F.y}},xe.current={x:f.x,y:f.y},(A=pt.current)==null||A.setPointerCapture(c.pointerId),(X=($=Z.current).onConnectStart)==null||X.call($,c,{nodeId:F.nodeId,handleId:F.handleId,handleType:F.type}),we();return}}if(v){const F=Lt(f.x,f.y);if(F){if(vt.current&&zt){const Mt=[];if(M)Mt.push({id:F.id,type:"select",selected:!F.selected});else if(!F.selected){for(const J of O.current)J.id===F.id?Mt.push({id:J.id,type:"select",selected:!0}):J.selected&&Mt.push({id:J.id,type:"select",selected:!1});if(St.current){const J=Pt.current.filter(tt=>tt.selected).map(tt=>({id:tt.id,type:"select",selected:!1}));J.length&&St.current(J)}}if(Mt.length){if(vt.current(Mt),un&&!M){const J=O.current.findIndex(tt=>tt.id===F.id);J>=0&&J<O.current.length-1&&vt.current([{id:F.id,type:"remove"},{type:"add",item:{...O.current[J],selected:!0}}])}qt()}}if((H=Pe.current)==null||H.call(Pe,c,F),dt){const Mt=M&&F.selected;let J=null;if(F.parentId&&F.extent==="parent"){const tt=O.current.find(Wt=>Wt.id===F.parentId);if(tt){const Wt=tt.width||Gt,$e=tt.height||Ft,Qe=F.width||((V=F.measured)==null?void 0:V.width)||Gt,Be=F.height||((at=F.measured)==null?void 0:at.height)||Ft;J={minX:0,minY:0,maxX:Wt-Qe,maxY:$e-Be}}}if(Bt.current={id:F.id,startPos:{...F.position},startMouse:{x:f.x,y:f.y},parentClamp:J,parentId:F.parentId||null,selectedStarts:Mt?O.current.filter(tt=>tt.selected&&tt.id!==F.id).map(tt=>{var $e,Qe;let Wt=null;if(tt.parentId&&tt.extent==="parent"){const Be=O.current.find(yn=>yn.id===tt.parentId);if(Be){const yn=Be.width||Gt,Rr=Be.height||Ft,kr=tt.width||(($e=tt.measured)==null?void 0:$e.width)||Gt,Cr=tt.height||((Qe=tt.measured)==null?void 0:Qe.height)||Ft;Wt={minX:0,minY:0,maxX:yn-kr,maxY:Rr-Cr}}}return{id:tt.id,startPos:{...tt.position},parentClamp:Wt,parentId:tt.parentId||null}}):[]},(Y=pt.current)==null||Y.setPointerCapture(c.pointerId),(et=Le.current)==null||et.call(Le,c,F),vt.current){const tt=[{id:F.id,type:"position",dragging:!0}];for(const Wt of Bt.current.selectedStarts)tt.push({id:Wt.id,type:"position",dragging:!0});vt.current(tt)}}return}}if(Pt.current.length>0&&zt){const F=oe(f.x,f.y);if(F){if(St.current){const Mt=[];if(M)Mt.push({id:F.id,type:"select",selected:!F.selected});else{for(const J of Pt.current)J.id===F.id?Mt.push({id:J.id,type:"select",selected:!0}):J.selected&&Mt.push({id:J.id,type:"select",selected:!1});if(vt.current){const J=O.current.filter(tt=>tt.selected).map(tt=>({id:tt.id,type:"select",selected:!1}));J.length&&vt.current(J)}}Mt.length&&(St.current(Mt),qt())}(mt=re.current)==null||mt.call(re,c,F);return}}if(!M){const F=O.current.filter(J=>J.selected).map(J=>({id:J.id,type:"select",selected:!1})),Mt=Pt.current.filter(J=>J.selected).map(J=>({id:J.id,type:"select",selected:!1}));F.length&&vt.current&&vt.current(F),Mt.length&&St.current&&St.current(Mt),(F.length||Mt.length)&&qt()}if((bt=Te.current)==null||bt.call(Te,c),Qt||M){te.current={startWorld:{...f},endWorld:{...f}},(Tt=pt.current)==null||Tt.setPointerCapture(c.pointerId),Me();return}ze.current=!0,Ot.current={x:c.clientX,y:c.clientY},(Dt=pt.current)==null||Dt.classList.add("dragging"),($t=pt.current)==null||$t.setPointerCapture(c.pointerId)},[it,Lt,Ze,oe,dt,wt,zt,Qt,we,Me,qt]),yr=a.useCallback(c=>{var f,M;if(jt.current){if(xe.current=it(c.clientX,c.clientY),we(),ln){const I=pt.current;if(I){const S=I.getBoundingClientRect(),g=40,A=c.clientX-S.left,$=c.clientY-S.top;let X=0,H=0;A<g?X=Yt:A>S.width-g&&(X=-Yt),$<g?H=Yt:$>S.height-g&&(H=-Yt),(X||H)&&(yt.current.x+=X,yt.current.y+=H,Ct(c))}}return}if(te.current){te.current.endWorld=it(c.clientX,c.clientY),Me();const I=te.current,S=Math.min(I.startWorld.x,I.endWorld.x),g=Math.min(I.startWorld.y,I.endWorld.y),A=Math.max(I.startWorld.x,I.endWorld.x),$=Math.max(I.startWorld.y,I.endWorld.y);if(vt.current){const X=[];for(const H of O.current){if(H.hidden)continue;const V=H.width||Gt,at=H.height||Ft,Y=Re==="full"?H.position.x>=S&&H.position.x+V<=A&&H.position.y>=g&&H.position.y+at<=$:H.position.x+V>S&&H.position.x<A&&H.position.y+at>g&&H.position.y<$;Y!==!!H.selected&&X.push({id:H.id,type:"select",selected:Y})}X.length&&vt.current(X)}return}if(Bt.current){const I=it(c.clientX,c.clientY),S=Bt.current,g=I.x-S.startMouse.x,A=I.y-S.startMouse.y;let $={x:S.startPos.x+g,y:S.startPos.y+A};if(fe&&($=vn($,se)),Vt&&($=bn($,Vt)),S.parentClamp){const Y=S.parentClamp;$={x:Math.max(Y.minX,Math.min($.x,Y.maxX)),y:Math.max(Y.minY,Math.min($.y,Y.maxY))}}const X=[{id:S.id,position:$}];for(const Y of S.selectedStarts){let et={x:Y.startPos.x+g,y:Y.startPos.y+A};if(fe&&(et=vn(et,se)),Vt&&(et=bn(et,Vt)),Y.parentClamp){const mt=Y.parentClamp;et={x:Math.max(mt.minX,Math.min(et.x,mt.maxX)),y:Math.max(mt.minY,Math.min(et.y,mt.maxY))}}X.push({id:Y.id,position:et})}const H=[];for(const Y of X){const et=O.current.find(mt=>mt.id===Y.id);if(et){et.position=Y.position,et.dragging=!0;let mt=Y.position;if(et.parentId){let bt=O.current.find($t=>$t.id===et.parentId),Tt=Y.position.x,Dt=Y.position.y;for(;bt;)Tt+=bt.position.x,Dt+=bt.position.y,bt=bt.parentId?O.current.find($t=>$t.id===bt.parentId):null;mt={x:Tt,y:Dt}}H.push({id:Y.id,position:Y.position,_absolutePosition:mt,width:et.width,height:et.height,dragging:!0,selected:et.selected})}}const V=new Set(X.map(Y=>Y.id));for(const Y of O.current)if(Y.parentId&&V.has(Y.parentId)&&!V.has(Y.id)){let et=O.current.find(Tt=>Tt.id===Y.parentId),mt=Y.position.x,bt=Y.position.y;for(;et;)mt+=et.position.x,bt+=et.position.y,et=et.parentId?O.current.find(Tt=>Tt.id===et.parentId):null;H.push({id:Y.id,position:Y.position,_absolutePosition:{x:mt,y:bt},width:Y.width,height:Y.height,dragging:!1,selected:Y.selected})}if((f=kt.current)==null||f.postMessage({type:"nodePositions",data:{updates:H}}),cn){const Y=pt.current;if(Y){const et=Y.getBoundingClientRect(),mt=40,bt=c.clientX-et.left,Tt=c.clientY-et.top;let Dt=0,$t=0;bt<mt?Dt=Yt:bt>et.width-mt&&(Dt=-Yt),Tt<mt?$t=Yt:Tt>et.height-mt&&($t=-Yt),(Dt||$t)&&(yt.current.x+=Dt,yt.current.y+=$t,Ct(c))}}const at=O.current.find(Y=>Y.id===S.id);at&&((M=Ie.current)==null||M.call(Ie,c,at));return}if(!ze.current)return;const v=yt.current;v.x+=c.clientX-Ot.current.x,v.y+=c.clientY-Ot.current.y,Ot.current={x:c.clientX,y:c.clientY},Ct()},[Ct,it,we,Me]),gr=a.useCallback(c=>{var v,f,M,I,S;if(jt.current){const g=it(c.clientX,c.clientY),A=Ze(g.x,g.y);if(A&&A.nodeId!==jt.current.sourceId&&(It==="loose"||A.type==="target")){const H=jt.current.sourceType==="target"?{source:A.nodeId,target:jt.current.sourceId,sourceHandle:A.handleId||null,targetHandle:jt.current.sourceHandle}:{source:jt.current.sourceId,target:A.nodeId,sourceHandle:jt.current.sourceHandle,targetHandle:A.handleId||null};(Z.current.isValidConnection?Z.current.isValidConnection(H):!0)&&((v=ne.current)==null||v.call(ne,{...H,...ge}))}(M=(f=Z.current).onConnectEnd)==null||M.call(f,c.nativeEvent||c),jt.current=null,xe.current=null,we();return}if(te.current){te.current=null,Me(),qt();return}if(Bt.current){const g=Bt.current;if(vt.current){const $=O.current.find(H=>H.id===g.id),X=[{id:g.id,type:"position",position:$?{...$.position}:void 0,dragging:!1}];for(const H of g.selectedStarts){const V=O.current.find(at=>at.id===H.id);X.push({id:H.id,type:"position",position:V?{...V.position}:void 0,dragging:!1})}vt.current(X)}requestAnimationFrame(()=>{Bt.current=null});const A=O.current.find($=>$.id===g.id);A&&((I=Se.current)==null||I.call(Se,c,A));return}ze.current=!1,(S=pt.current)==null||S.classList.remove("dragging")},[it,Ze,we,Me,qt]);a.useEffect(()=>{const c=pt.current;if(!c)return;const v=f=>{Ce&&f.preventDefault();const M=yt.current;if(Fe||me.current){const $=Xe;ke==="horizontal"?M.x-=f.deltaY*$:(ke==="vertical"||(M.x-=f.deltaX*$),M.y-=f.deltaY*$),Ct(f);return}if(!Ye)return;const I=f.deltaY>0?.92:1.08,S=c.getBoundingClientRect(),g=f.clientX-S.left,A=f.clientY-S.top;M.x=g-(g-M.x)*I,M.y=A-(A-M.y)*I,M.zoom=Math.min(xt,Math.max(st,M.zoom*I)),Ct(f)};return c.addEventListener("wheel",v,{passive:!Ce}),()=>c.removeEventListener("wheel",v)},[Ct,st,xt,Fe,ke,Xe,Ye,Ce]),a.useEffect(()=>{if(!qe)return;const c=pt.current;if(!c)return;let v=0,f=null;const M=g=>{if(g.touches.length===2){const A=g.touches[0].clientX-g.touches[1].clientX,$=g.touches[0].clientY-g.touches[1].clientY;v=Math.hypot(A,$);const X=c.getBoundingClientRect();f={x:(g.touches[0].clientX+g.touches[1].clientX)/2-X.left,y:(g.touches[0].clientY+g.touches[1].clientY)/2-X.top},g.preventDefault()}},I=g=>{if(g.touches.length===2&&v>0){g.preventDefault();const A=g.touches[0].clientX-g.touches[1].clientX,$=g.touches[0].clientY-g.touches[1].clientY,X=Math.hypot(A,$),H=X/v;v=X;const V=yt.current,at=f.x,Y=f.y;V.x=at-(at-V.x)*H,V.y=Y-(Y-V.y)*H,V.zoom=Math.min(xt,Math.max(st,V.zoom*H)),Ct(g)}},S=()=>{v=0,f=null};return c.addEventListener("touchstart",M,{passive:!1}),c.addEventListener("touchmove",I,{passive:!1}),c.addEventListener("touchend",S),()=>{c.removeEventListener("touchstart",M),c.removeEventListener("touchmove",I),c.removeEventListener("touchend",S)}},[qe,Ct,st,xt]),a.useEffect(()=>{if(!Ue)return;const c=pt.current;if(!c)return;const v=f=>{var H,V,at,Y;const M=it(f.clientX,f.clientY);if(Lt(M.x,M.y)){(V=(H=Z.current).onNodeDoubleClick)==null||V.call(H,f,Lt(M.x,M.y));return}const I=oe(M.x,M.y);if(I){(Y=(at=Z.current).onEdgeDoubleClick)==null||Y.call(at,f,I);return}const S=1.5,g=c.getBoundingClientRect(),A=f.clientX-g.left,$=f.clientY-g.top,X=yt.current;X.x=A-(A-X.x)*S,X.y=$-($-X.y)*S,X.zoom=Math.min(xt,Math.max(st,X.zoom*S)),Ct(f)};return c.addEventListener("dblclick",v),()=>c.removeEventListener("dblclick",v)},[Ue,Ct,st,xt,it,Lt,oe]),a.useEffect(()=>{const c=pt.current;if(!c)return;const v=f=>{var g,A,$,X,H,V;const M=it(f.clientX,f.clientY),I=Lt(M.x,M.y);if(I){(A=(g=Z.current).onNodeContextMenu)==null||A.call(g,f,I);return}const S=oe(M.x,M.y);if(S){(X=($=Z.current).onEdgeContextMenu)==null||X.call($,f,S);return}(V=(H=Z.current).onPaneContextMenu)==null||V.call(H,f)};return c.addEventListener("contextmenu",v),()=>c.removeEventListener("contextmenu",v)},[it,Lt,oe]),a.useEffect(()=>{const c=pt.current;if(!c)return;let v=null,f=null;const M=g=>{var X,H,V,at,Y,et,mt,bt,Tt,Dt,$t,F,Mt,J;(H=(X=Z.current).onPaneMouseMove)==null||H.call(X,g);const A=it(g.clientX,g.clientY),$=Lt(A.x,A.y);if($!==v&&(v&&((at=(V=Z.current).onNodeMouseLeave)==null||at.call(V,g,v)),$&&((et=(Y=Z.current).onNodeMouseEnter)==null||et.call(Y,g,$)),v=$),$&&((bt=(mt=Z.current).onNodeMouseMove)==null||bt.call(mt,g,$)),!$){const tt=oe(A.x,A.y);tt!==f&&(f&&((Dt=(Tt=Z.current).onEdgeMouseLeave)==null||Dt.call(Tt,g,f)),tt&&((F=($t=Z.current).onEdgeMouseEnter)==null||F.call($t,g,tt)),f=tt),tt&&((J=(Mt=Z.current).onEdgeMouseMove)==null||J.call(Mt,g,tt))}},I=g=>{var A,$;return($=(A=Z.current).onPaneMouseEnter)==null?void 0:$.call(A,g)},S=g=>{var A,$,X,H,V,at;($=(A=Z.current).onPaneMouseLeave)==null||$.call(A,g),v&&((H=(X=Z.current).onNodeMouseLeave)==null||H.call(X,g,v),v=null),f&&((at=(V=Z.current).onEdgeMouseLeave)==null||at.call(V,g,f),f=null)};return c.addEventListener("mousemove",M),c.addEventListener("mouseenter",I),c.addEventListener("mouseleave",S),()=>{c.removeEventListener("mousemove",M),c.removeEventListener("mouseenter",I),c.removeEventListener("mouseleave",S)}},[it,Lt,oe]),a.useEffect(()=>{const c=Array.isArray(he)?he:[he],v=async f=>{var M,I;if(c.includes(f.key)){if(f.target.tagName==="INPUT"||f.target.tagName==="TEXTAREA"||f.target.isContentEditable)return;const S=O.current.filter($=>$.selected),g=Pt.current.filter($=>$.selected);if(!S.length&&!g.length||Z.current.onBeforeDelete&&!await Z.current.onBeforeDelete({nodes:S,edges:g}))return;const A=new Set(S.map($=>$.id));if(S.length&&vt.current&&(vt.current(S.map($=>({id:$.id,type:"remove"}))),St.current)){const $=Pt.current.filter(X=>A.has(X.source)||A.has(X.target));$.length&&St.current($.map(X=>({id:X.id,type:"remove"})))}g.length&&St.current&&St.current(g.map($=>({id:$.id,type:"remove"}))),(I=(M=Z.current).onDelete)==null||I.call(M,{nodes:S,edges:g})}if((f.ctrlKey||f.metaKey)&&f.key==="a"){if(f.target.tagName==="INPUT"||f.target.tagName==="TEXTAREA")return;if(f.preventDefault(),vt.current){const S=O.current.filter(g=>!g.selected).map(g=>({id:g.id,type:"select",selected:!0}));S.length&&vt.current(S)}if(St.current){const S=Pt.current.filter(g=>!g.selected).map(g=>({id:g.id,type:"select",selected:!0}));S.length&&St.current(S)}}};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[he]);const Tn=a.useRef(!1);a.useEffect(()=>{var c,v;if(!Tn.current&&kt.current){if(Tn.current=!0,Rt&&O.current.length>0){const f=pt.current;if(f){const M=f.getBoundingClientRect(),I=(ut==null?void 0:ut.padding)??.1,S=Ve(O.current),g=Je(S,M.width,M.height,I);ut!=null&&ut.maxZoom&&(g.zoom=Math.min(g.zoom,ut.maxZoom)),ut!=null&&ut.minZoom&&(g.zoom=Math.max(g.zoom,ut.minZoom)),yt.current=g,Ct()}}(v=(c=Z.current).onInit)==null||v.call(c,{getNodes:()=>[...O.current],getEdges:()=>[...Pt.current],getViewport:()=>({...yt.current}),fitView:(f={})=>{const M=pt.current;if(!M||!O.current.length)return;const I=M.getBoundingClientRect(),S=Ve(O.current),g=Je(S,I.width,I.height,f.padding??.1);yt.current=g,Ct()}})}});const xr=a.useCallback(()=>{yt.current={...Et},Ct()},[Ct,Et]),pr=a.useCallback(c=>{var v;if(c)Jt.current.push(c);else{const f=yt.current,M=pt.current;if(!M)return;const I=M.getBoundingClientRect(),S=Math.round(-f.x/f.zoom+I.width/2/f.zoom),g=Math.round(-f.y/f.zoom+I.height/2/f.zoom);Jt.current.push({x:S-80,y:g-45,w:160,h:90,title:"Note "+(Jt.current.length+1),body:"Added at viewport center"})}(v=kt.current)==null||v.postMessage({type:"cards",data:{cards:[...Jt.current]}})},[]),mr=a.useCallback(c=>{if(c.id||(c.id="node-"+Date.now()),!c.position){const v=yt.current,f=pt.current;if(!f)return;const M=f.getBoundingClientRect();c.position={x:Math.round(-v.x/v.zoom+M.width/2/v.zoom)-Gt/2,y:Math.round(-v.y/v.zoom+M.height/2/v.zoom)-Ft/2}}c.data||(c.data={label:c.id}),vt.current&&vt.current([{type:"add",item:c}])},[]),vr=a.useCallback(()=>({...yt.current}),[]),br=a.useCallback(c=>{yt.current={...yt.current,...c},Ct()},[Ct]),wr=a.useCallback(c=>it(c.x,c.y),[it]),$n=n,Mr=a.useMemo(()=>({wrapRef:pt,canvasRef:Ee,workerRef:kt,cameraRef:yt,nodesRef:O,edgesRef:Pt,handleRegistryRef:dn,syncNodesToWorker:At,onNodesChangeRef:vt,onEdgesChangeRef:St,sendCamera:Ct,screenToWorld:it,viewportListeners:Ut,selectionListeners:ae,zoomMin:st,zoomMax:xt,snapToGrid:fe,snapGrid:se,nodeExtent:Vt,defaultEdgeOptions:ge,edgeRouting:ie,resolvedNodesRef:Zt,get nodes(){return e},get edges(){return n},get routedEdges(){return $n},get viewport(){return Ne},get connection(){return Oe}}),[e,n,$n,Ne,Oe,Ct,it,At,Ut,ae,st,xt,fe,se,Vt,ge,ie]);return{wrapRef:pt,canvasRef:Ee,canvasReady:fn,onPointerDown:hr,onPointerMove:yr,onPointerUp:gr,resetView:xr,addCard:pr,addNode:mr,getCamera:vr,setCamera:br,screenToFlowPosition:wr,store:Mr}}function Hr(t,e,n,r,s,o){const i=s-n,l=o-r,d=i*i+l*l;if(d===0)return Math.hypot(t-n,e-r);let u=((t-n)*i+(e-r)*l)/d;return u=Math.max(0,Math.min(1,u)),Math.hypot(t-(n+u*i),e-(r+u*l))}const Zn=a.createContext(null);function ft(){const t=a.useContext(Zn);if(!t)throw new Error("useCanvasStore must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");return t}const _e=a.createContext(null);function _r(){return a.useContext(_e)}function Wr({node:t,nodeType:e}){var b,L,E;const n=ft(),r=a.useRef(null),s=t._absolutePosition||t.position,o=a.useRef(null);a.useEffect(()=>{const k=r.current;if(!k)return;const T=new ResizeObserver(C=>{var j,D,h,y;const{width:z,height:_}=C[0].contentRect;if(z>0&&_>0){const p=n.nodesRef.current.find(P=>P.id===t.id),R=(p==null?void 0:p.width)||((j=p==null?void 0:p.measured)==null?void 0:j.width),w=(p==null?void 0:p.height)||((D=p==null?void 0:p.measured)==null?void 0:D.height);(Math.abs((R||0)-z)>1||Math.abs((w||0)-_)>1)&&((y=(h=n.onNodesChangeRef).current)==null||y.call(h,[{id:t.id,type:"dimensions",dimensions:{width:z,height:_},setAttributes:!0}]))}});return T.observe(k),()=>T.disconnect()},[t.id,n]);const i=a.useCallback(k=>{var B,q,W,gt;k.stopPropagation();const T=k.target.tagName;if(T==="INPUT"||T==="TEXTAREA"||T==="SELECT"||T==="BUTTON"||T==="A"||T==="LABEL"||k.target.isContentEditable)return;let C=k.target;for(;C&&C!==r.current;){if((B=C.classList)!=null&&B.contains("nodrag")||(q=C.classList)!=null&&q.contains("nopan"))return;C=C.parentElement}if(n.onNodesChangeRef.current){const K=[];if(k.shiftKey)K.push({id:t.id,type:"select",selected:!t.selected});else for(const U of n.nodesRef.current)U.id===t.id&&!U.selected?K.push({id:U.id,type:"select",selected:!0}):U.id!==t.id&&U.selected&&K.push({id:U.id,type:"select",selected:!1});K.length&&n.onNodesChangeRef.current(K)}const z=n.cameraRef.current,_=n.wrapRef.current;if(!_)return;const j=_.getBoundingClientRect(),D=(k.clientX-j.left-z.x)/z.zoom,h=(k.clientY-j.top-z.y)/z.zoom,p=k.shiftKey&&t.selected?n.nodesRef.current.filter(K=>K.selected&&K.id!==t.id).map(K=>({id:K.id,startPos:{...K.position}})):[];o.current={startPos:{...t.position},startMouse:{x:D,y:h},selectedStarts:p};const R=[{id:t.id,type:"position",dragging:!0}];for(const K of p)R.push({id:K.id,type:"position",dragging:!0});(gt=(W=n.onNodesChangeRef).current)==null||gt.call(W,R);const w=r.current;w&&w.setPointerCapture(k.pointerId);const P=K=>{var st,xt,Et,Rt;if(!o.current)return;const nt=n.cameraRef.current,U=_.getBoundingClientRect(),G=(K.clientX-U.left-nt.x)/nt.zoom,rt=(K.clientY-U.top-nt.y)/nt.zoom,ct=G-o.current.startMouse.x,lt=rt-o.current.startMouse.y;let ot={x:o.current.startPos.x+ct,y:o.current.startPos.y+lt};if(n.snapToGrid&&n.snapGrid&&(ot={x:n.snapGrid[0]*Math.round(ot.x/n.snapGrid[0]),y:n.snapGrid[1]*Math.round(ot.y/n.snapGrid[1])}),t.parentId&&t.extent==="parent"){const ut=n.nodesRef.current.find(dt=>dt.id===t.parentId);if(ut){const dt=ut.width||160,wt=ut.height||60,zt=t.width||((st=t.measured)==null?void 0:st.width)||160,ht=t.height||((xt=t.measured)==null?void 0:xt.height)||60;ot={x:Math.max(0,Math.min(ot.x,dt-zt)),y:Math.max(0,Math.min(ot.y,wt-ht))}}}const Nt=[{id:t.id,type:"position",position:ot,dragging:!0}];for(const ut of o.current.selectedStarts){let dt={x:ut.startPos.x+ct,y:ut.startPos.y+lt};n.snapToGrid&&n.snapGrid&&(dt={x:n.snapGrid[0]*Math.round(dt.x/n.snapGrid[0]),y:n.snapGrid[1]*Math.round(dt.y/n.snapGrid[1])}),Nt.push({id:ut.id,type:"position",position:dt,dragging:!0})}(Rt=(Et=n.onNodesChangeRef).current)==null||Rt.call(Et,Nt)},m=K=>{var U,G;if(!o.current)return;const nt=[{id:t.id,type:"position",dragging:!1}];for(const rt of o.current.selectedStarts)nt.push({id:rt.id,type:"position",dragging:!1});(G=(U=n.onNodesChangeRef).current)==null||G.call(U,nt),o.current=null,w&&w.releasePointerCapture(K.pointerId),w==null||w.removeEventListener("pointermove",P),w==null||w.removeEventListener("pointerup",m)};w==null||w.addEventListener("pointermove",P),w==null||w.addEventListener("pointerup",m)},[t,n]),l=a.useCallback(k=>{var D,h,y,p,R,w;if(!t.selected)return;const T=k.shiftKey?10:1;let C=0,z=0;switch(k.key){case"ArrowUp":z=-T;break;case"ArrowDown":z=T;break;case"ArrowLeft":C=-T;break;case"ArrowRight":C=T;break;case"Escape":(h=(D=n.onNodesChangeRef).current)==null||h.call(D,[{id:t.id,type:"select",selected:!1}]);return;case"Delete":case"Backspace":t.deletable!==!1&&((p=(y=n.onNodesChangeRef).current)==null||p.call(y,[{id:t.id,type:"remove"}]));return;default:return}k.preventDefault();const _={x:t.position.x+C,y:t.position.y+z},j=[{id:t.id,type:"position",position:_}];for(const P of n.nodesRef.current)P.selected&&P.id!==t.id&&j.push({id:P.id,type:"position",position:{x:P.position.x+C,y:P.position.y+z}});(w=(R=n.onNodesChangeRef).current)==null||w.call(R,j)},[t,n]),d=t.width||((b=t.measured)==null?void 0:b.width),u=t.height||((L=t.measured)==null?void 0:L.height),x=!!(d&&u);return N.jsx(_e.Provider,{value:t.id,children:N.jsx("div",{ref:r,className:`ric-node-wrapper ${t.selected?"selected":""} ${t.dragging?"dragging":""}`,style:{position:"absolute",left:s.x,top:s.y,zIndex:t.type==="group"?0:t.zIndex||1,pointerEvents:t.type==="group"?"none":"all",visibility:x?"visible":"hidden",outline:"none"},"data-nodeid":t.id,tabIndex:t.selectable!==!1?0:void 0,role:"button","aria-label":`Node ${((E=t.data)==null?void 0:E.label)||t.id}`,"aria-selected":!!t.selected,onPointerDown:i,onKeyDown:l,children:N.jsx(e,{id:t.id,data:t.data,type:t.type,selected:!!t.selected,dragging:!!t.dragging,draggable:t.draggable!==!1,selectable:t.selectable!==!1,deletable:t.deletable!==!1,isConnectable:t.connectable!==!1,zIndex:t.zIndex||0,positionAbsoluteX:s.x,positionAbsoluteY:s.y,width:d,height:u,sourcePosition:t.sourcePosition,targetPosition:t.targetPosition,parentId:t.parentId,dragHandle:t.dragHandle})})})}const Fr=a.memo(Wr),Qn=160,Kn=60;function jn(t,e,n,r){var l,d;const s=t.width||((l=t.measured)==null?void 0:l.width)||Qn,o=t.height||((d=t.measured)==null?void 0:d.height)||Kn,i=t._absolutePosition||t.position;if(t.handleBounds){const u=t.handleBounds[e]||[],x=n?u.find(b=>b.id===n):u[0];if(x&&x.x!==void 0&&x.y!==void 0){const b=x.position||(e==="source"?"right":"left");return{x:i.x+x.x,y:i.y+x.y,position:b}}}if(r){const u=`${t.id}__${n||e}`,x=r.get(u);if(x&&x.x!==void 0&&x.y!==void 0)return{x:i.x+x.x,y:i.y+x.y,position:x.position||(e==="source"?"right":"left")}}if(t.handles&&t.handles.length){for(const u of t.handles)if(u.type===e&&(!n||u.id===n)){if(u.x!==void 0&&u.y!==void 0)return{x:i.x+u.x,y:i.y+u.y,position:u.position||(e==="source"?"right":"left")};const x=u.position||(e==="source"?"right":"left");switch(x){case"top":return{x:i.x+s/2,y:i.y,position:x};case"bottom":return{x:i.x+s/2,y:i.y+o,position:x};case"left":return{x:i.x,y:i.y+o/2,position:x};default:return{x:i.x+s,y:i.y+o/2,position:x}}}}return e==="source"?{x:i.x+s,y:i.y+o/2,position:"right"}:{x:i.x,y:i.y+o/2,position:"left"}}function Xr(t,e,n){return n==="left"?t-e:n==="right"?t+e:t}function Yr(t,e,n){return n==="top"?t-e:n==="bottom"?t+e:t}function Dn({x:t,y:e,position:n,type:r,onPointerDown:s}){return N.jsx("circle",{className:`ric-edge-anchor ric-edge-anchor-${r}`,cx:Xr(t,10,n),cy:Yr(e,10,n),r:10,stroke:"transparent",fill:"transparent",style:{cursor:"move",pointerEvents:"stroke"},onPointerDown:s})}function Ur({edge:t,edgeType:e,nodes:n,reconnectable:r}){var D,h,y;const s=ft(),[o,i]=a.useState(null),l=a.useCallback((p,R,w,P)=>{var nt;R.stopPropagation(),R.preventDefault();const m=s.wrapRef.current;if(!m)return;const B=p==="source"?P:w,q=p==="source"?t.target:t.source;(nt=s.workerRef.current)==null||nt.postMessage({type:"connecting",data:{from:{x:B.x,y:B.y},to:{x:B.x,y:B.y}}});const W=m.getBoundingClientRect(),gt=U=>{var lt;const G=s.cameraRef.current,rt=(U.clientX-W.left-G.x)/G.zoom,ct=(U.clientY-W.top-G.y)/G.zoom;(lt=s.workerRef.current)==null||lt.postMessage({type:"connecting",data:{from:{x:B.x,y:B.y},to:{x:rt,y:ct}}})},K=U=>{var xt,Et,Rt,ut;const G=s.cameraRef.current,rt=(U.clientX-W.left-G.x)/G.zoom,ct=(U.clientY-W.top-G.y)/G.zoom,lt=20/G.zoom;let ot=null,Nt=null;const st=(xt=s.handleRegistryRef)==null?void 0:xt.current;for(const dt of s.nodesRef.current){if(dt.hidden)continue;const wt=dt.width||Qn,zt=dt.height||Kn,ht=dt._absolutePosition||dt.position,Qt=[];if(st)for(const[,It]of st)It.nodeId===dt.id&&Qt.push(It);const Re=Qt.length>0?Qt:dt.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const It of Re){let Xt,Ht;if(It.x!==void 0&&It.y!==void 0)Xt=ht.x+It.x,Ht=ht.y+It.y;else switch(It.position||(It.type==="source"?"right":"left")){case"top":Xt=ht.x+wt/2,Ht=ht.y;break;case"bottom":Xt=ht.x+wt/2,Ht=ht.y+zt;break;case"left":Xt=ht.x,Ht=ht.y+zt/2;break;default:Xt=ht.x+wt,Ht=ht.y+zt/2;break}if(Math.abs(rt-Xt)<lt&&Math.abs(ct-Ht)<lt){ot=dt,Nt=It.id||null;break}}if(ot)break}if(ot){const dt=p==="source"?{source:ot.id,target:q,sourceHandle:Nt,targetHandle:t.targetHandle}:{source:q,target:ot.id,sourceHandle:t.sourceHandle,targetHandle:Nt};(Rt=(Et=s.onEdgesChangeRef).current)==null||Rt.call(Et,[{id:t.id,type:"remove"},{type:"add",item:{id:t.id,...dt}}])}(ut=s.workerRef.current)==null||ut.postMessage({type:"connecting",data:null}),m.removeEventListener("pointermove",gt),m.removeEventListener("pointerup",K)};m.addEventListener("pointermove",gt),m.addEventListener("pointerup",K)},[t,s]),d=n.find(p=>p.id===t.source),u=n.find(p=>p.id===t.target),x=d&&!!(d.width||(D=d.measured)!=null&&D.width),b=u&&!!(u.width||(h=u.measured)!=null&&h.width),L=(y=s.handleRegistryRef)==null?void 0:y.current,E=x?jn(d,"source",t.sourceHandle,L):null,k=b?jn(u,"target",t.targetHandle,L):null,T=t.type==="bezier"||t.type==="simplebezier"||t.type==="default",C=s.routedEdges||s.edges,z=C==null?void 0:C.find(p=>p.id===t.id),_=T?null:(z==null?void 0:z._routedPoints)||t._routedPoints||null,j=r!==!1&&t.reconnectable!==!1;return!E||!k?null:N.jsxs("g",{className:`ric-edge-wrapper ${t.selected?"selected":""}`,"data-edgeid":t.id,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),children:[N.jsx(e,{id:t.id,source:t.source,target:t.target,sourceX:E.x,sourceY:E.y,targetX:k.x,targetY:k.y,sourcePosition:E.position,targetPosition:k.position,sourceHandleId:t.sourceHandle,targetHandleId:t.targetHandle,data:t.data,type:t.type,selected:!!t.selected,animated:!!t.animated,label:t.label,style:t.style,selectable:t.selectable!==!1,deletable:t.deletable!==!1,routedPoints:_}),j&&(o||t.selected)&&N.jsxs(N.Fragment,{children:[N.jsx(Dn,{x:E.x,y:E.y,position:E.position,type:"source",onPointerDown:p=>l("source",p,E,k)}),N.jsx(Dn,{x:k.x,y:k.y,position:k.position,type:"target",onPointerDown:p=>l("target",p,E,k)})]})]})}const qr=a.memo(Ur);function Vn({selectionKeyCode:t="Shift",selectionMode:e="partial"}){var T;const n=ft(),[r,s]=a.useState(null),o=a.useRef(null);if(a.useEffect(()=>{const C=n.wrapRef.current;if(!C)return;let z=!1,_=null,j=!1;const D=w=>{w.key===t&&(j=!0)},h=w=>{w.key===t&&(j=!1)},y=w=>{if(!j)return;const P=w.target;if(P.closest(".ric-node-wrapper")||P.closest(".ric-handle"))return;z=!0;const m=n.cameraRef.current,B=C.getBoundingClientRect(),q=(w.clientX-B.left-m.x)/m.zoom,W=(w.clientY-B.top-m.y)/m.zoom;_={x:q,y:W},s({startX:q,startY:W,endX:q,endY:W}),w.stopPropagation()},p=w=>{if(!z||!_)return;const P=n.cameraRef.current,m=C.getBoundingClientRect(),B=(w.clientX-m.left-P.x)/P.zoom,q=(w.clientY-m.top-P.y)/P.zoom;s({startX:_.x,startY:_.y,endX:B,endY:q})},R=w=>{var K,nt;if(!z||!_)return;z=!1;const P=n.cameraRef.current,m=C.getBoundingClientRect(),B=(w.clientX-m.left-P.x)/P.zoom,q=(w.clientY-m.top-P.y)/P.zoom,W={x:Math.min(_.x,B),y:Math.min(_.y,q),width:Math.abs(B-_.x),height:Math.abs(q-_.y)},gt=[];for(const U of n.nodesRef.current){const G=U._absolutePosition||U.position,rt=U.width||160,ct=U.height||60;let lt;e==="full"?lt=G.x>=W.x&&G.y>=W.y&&G.x+rt<=W.x+W.width&&G.y+ct<=W.y+W.height:lt=G.x+rt>W.x&&G.x<W.x+W.width&&G.y+ct>W.y&&G.y<W.y+W.height,gt.push({id:U.id,type:"select",selected:lt})}gt.length&&((nt=(K=n.onNodesChangeRef).current)==null||nt.call(K,gt)),_=null,s(null)};return C.addEventListener("pointerdown",y,!0),C.addEventListener("pointermove",p),C.addEventListener("pointerup",R),window.addEventListener("keydown",D),window.addEventListener("keyup",h),()=>{C.removeEventListener("pointerdown",y,!0),C.removeEventListener("pointermove",p),C.removeEventListener("pointerup",R),window.removeEventListener("keydown",D),window.removeEventListener("keyup",h)}},[n,t,e]),!r)return null;const i=((T=n.cameraRef)==null?void 0:T.current)||{x:0,y:0,zoom:1},l=Math.min(r.startX,r.endX),d=Math.min(r.startY,r.endY),u=Math.abs(r.endX-r.startX),x=Math.abs(r.endY-r.startY),b=l*i.zoom+i.x,L=d*i.zoom+i.y,E=u*i.zoom,k=x*i.zoom;return N.jsx("div",{ref:o,className:"ric-selection-box",style:{position:"absolute",left:b,top:L,width:E,height:k,border:"1px dashed #3b82f6",background:"rgba(59, 130, 246, 0.08)",pointerEvents:"none",zIndex:100}})}Vn.displayName="SelectionBox";const Jn=a.memo(Vn);function tr(t,e){var s,o,i,l;const n=(s=t.handleRegistryRef)==null?void 0:s.current;if(!n)return;const r={source:[],target:[]};for(const[,d]of n)if(d.nodeId===e){const u={id:d.id,type:d.type,position:d.position,x:d.x,y:d.y,width:8,height:8};d.type==="source"?r.source.push(u):r.target.push(u)}(i=(o=t.onNodesChangeRef).current)==null||i.call(o,[{id:e,type:"dimensions",handleBounds:r,setAttributes:!1}]),(l=t.syncNodesToWorker)==null||l.call(t)}const xn=new Set;function An(t,e){xn.has(e)||(xn.add(e),queueMicrotask(()=>{xn.delete(e),tr(t,e)}))}function Gr(t,e){const n=t.closest(".ric-node-wrapper");if(!n)return null;const r=n.getBoundingClientRect(),s=t.getBoundingClientRect(),o=e||1;return{x:(s.left+s.width/2-r.left)/o,y:(s.top+s.height/2-r.top)/o}}function He({type:t="source",position:e=t==="source"?"right":"left",id:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:o=!0,children:i,className:l="",style:d={},onConnect:u,...x}){const b=a.useContext(_e),L=ft(),E=a.useRef(null),k=a.useRef(L);k.current=L;const T=a.useCallback(()=>{var w,P,m;const j=E.current;if(!j||!b)return;const D=k.current,h=(w=D.handleRegistryRef)==null?void 0:w.current;if(!h)return;const y=`${b}__${n||t}`,p=(m=(P=D.cameraRef)==null?void 0:P.current)==null?void 0:m.zoom,R=Gr(j,p);if(R){const B={nodeId:b,id:n||null,type:t,position:e,x:R.x,y:R.y};h.set(y,B)}},[b,n,t,e]);a.useLayoutEffect(()=>{T()},[T]),a.useEffect(()=>{if(!b)return;const j=k.current;An(j,b);const D=E.current,h=D==null?void 0:D.closest(".ric-node-wrapper"),y=new ResizeObserver(()=>{T(),An(k.current,b)});return h&&y.observe(h),()=>{var P;y.disconnect();const p=k.current,R=(P=p.handleRegistryRef)==null?void 0:P.current,w=`${b}__${n||t}`;R==null||R.delete(w),tr(p,b)}},[b,n,t,e,T]);const C=a.useCallback(()=>{var m;const j=k.current,D=j.nodesRef.current.find(B=>B.id===b);if(!D)return null;const h=D._absolutePosition||D.position,y=(m=j.handleRegistryRef)==null?void 0:m.current,p=`${b}__${n||t}`,R=y==null?void 0:y.get(p);if(R&&R.x!==void 0&&R.y!==void 0)return{x:h.x+R.x,y:h.y+R.y};const w=D.width||160,P=D.height||60;switch(e){case"top":return{x:h.x+w/2,y:h.y};case"bottom":return{x:h.x+w/2,y:h.y+P};case"left":return{x:h.x,y:h.y+P/2};default:return{x:h.x+w,y:h.y+P/2}}},[b,n,t,e]),z=a.useCallback(j=>{var q;if(!r||!s)return;j.stopPropagation(),j.preventDefault();const D=k.current,h=D.cameraRef.current,y=D.wrapRef.current;if(!y)return;const p=y.getBoundingClientRect(),R=C();if(!R)return;const w=R.x,P=R.y;(q=D.workerRef.current)==null||q.postMessage({type:"connecting",data:{from:{x:w,y:P},to:{x:w,y:P}}}),y.setPointerCapture(j.pointerId);const m=W=>{var nt;const gt=(W.clientX-p.left-h.x)/h.zoom,K=(W.clientY-p.top-h.y)/h.zoom;(nt=D.workerRef.current)==null||nt.postMessage({type:"connecting",data:{from:{x:w,y:P},to:{x:gt,y:K}}})},B=W=>{var ct,lt,ot,Nt;const gt=(W.clientX-p.left-h.x)/h.zoom,K=(W.clientY-p.top-h.y)/h.zoom,nt=20/h.zoom;let U=null,G=null;const rt=(ct=D.handleRegistryRef)==null?void 0:ct.current;for(const st of D.nodesRef.current){if(st.id===b||st.hidden)continue;const xt=st.width||160,Et=st.height||60,Rt=st._absolutePosition||st.position,ut=[];if(rt)for(const[,wt]of rt)wt.nodeId===st.id&&ut.push(wt);const dt=ut.length>0?ut:st.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const wt of dt){let zt,ht;if(wt.x!==void 0&&wt.y!==void 0)zt=Rt.x+wt.x,ht=Rt.y+wt.y;else switch(wt.position||(wt.type==="source"?"right":"left")){case"top":zt=Rt.x+xt/2,ht=Rt.y;break;case"bottom":zt=Rt.x+xt/2,ht=Rt.y+Et;break;case"left":zt=Rt.x,ht=Rt.y+Et/2;break;default:zt=Rt.x+xt,ht=Rt.y+Et/2;break}if(Math.abs(gt-zt)<nt&&Math.abs(K-ht)<nt){U=st,G=wt.id||null;break}}if(U)break}if(U){const st={source:t==="source"?b:U.id,target:t==="source"?U.id:b,sourceHandle:t==="source"?n||null:G,targetHandle:t==="source"?G:n||null};(ot=(lt=D.onEdgesChangeRef)==null?void 0:lt.current)==null||ot.call(lt,[{type:"add",item:{id:`e-${st.source}-${st.target}`,...st}}])}(Nt=D.workerRef.current)==null||Nt.postMessage({type:"connecting",data:null}),y.removeEventListener("pointermove",m),y.removeEventListener("pointerup",B)};y.addEventListener("pointermove",m),y.addEventListener("pointerup",B)},[b,n,t,e,r,s,C]),_={top:{top:0,left:"50%",transform:"translate(-50%, -50%)"},bottom:{bottom:0,left:"50%",transform:"translate(-50%, 50%)"},left:{top:"50%",left:0,transform:"translate(-50%, -50%)"},right:{top:"50%",right:0,transform:"translate(50%, -50%)"}}[e]||{};return N.jsx("div",{ref:E,className:`ric-handle ric-handle-${e} ric-handle-${t} ${l}`,"data-handleid":n||null,"data-nodeid":b,"data-handlepos":e,"data-handletype":t,onPointerDown:z,style:{position:"absolute",width:8,height:8,borderRadius:"50%",background:"#1a192b",border:"none",zIndex:10,cursor:r?"crosshair":"default",boxSizing:"border-box",..._,...d},...x,children:i})}function Or({data:t,isConnectable:e,selected:n,targetPosition:r="left",sourcePosition:s="right",hideSourceHandle:o=!1,hideTargetHandle:i=!1}){return N.jsxs("div",{className:`ric-default-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!i&&N.jsx(He,{type:"target",position:r,isConnectable:e}),N.jsx("div",{className:"ric-node-content",children:t==null?void 0:t.label}),!o&&N.jsx(He,{type:"source",position:s,isConnectable:e})]})}function er({data:t,isConnectable:e,selected:n,sourcePosition:r="right",hideSourceHandle:s=!1}){return N.jsxs("div",{className:`ric-input-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderBottom:"2px solid #0041d0",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[N.jsx("div",{className:"ric-node-content",children:t==null?void 0:t.label}),!s&&N.jsx(He,{type:"source",position:r,isConnectable:e})]})}function nr({data:t,isConnectable:e,selected:n,targetPosition:r="left",hideTargetHandle:s=!1}){return N.jsxs("div",{className:`ric-output-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderTop:"2px solid #ff0072",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!s&&N.jsx(He,{type:"target",position:r,isConnectable:e}),N.jsx("div",{className:"ric-node-content",children:t==null?void 0:t.label})]})}function rr({data:t,selected:e,width:n,height:r}){return N.jsx("div",{className:`ric-group-node${e?" selected":""}`,style:{width:n||300,height:r||200,background:"rgba(240, 240, 240, 0.25)",border:e?"2px solid #3b82f6":"1px dashed #ccc",borderRadius:8,padding:8,boxSizing:"border-box"},children:(t==null?void 0:t.label)&&N.jsx("div",{style:{fontSize:11,fontWeight:600,color:"#888",userSelect:"none"},children:t.label})})}function or({x:t,y:e,label:n,labelStyle:r,labelShowBg:s=!0,labelBgStyle:o,labelBgPadding:i=[2,4],labelBgBorderRadius:l=2,children:d,className:u="",...x}){const[b,L]=a.useState({x:1,y:0,width:0,height:0}),E=a.useRef(null);return a.useEffect(()=>{if(E.current){const k=E.current.getBBox();L({x:k.x,y:k.y,width:k.width,height:k.height})}},[n]),n?N.jsxs("g",{transform:`translate(${t-b.width/2} ${e-b.height/2})`,className:`ric-edge-textwrapper ${u}`,visibility:b.width?"visible":"hidden",...x,children:[s&&N.jsx("rect",{width:b.width+2*i[0],x:-i[0],y:-i[1],height:b.height+2*i[1],className:"ric-edge-textbg",style:o,rx:l,ry:l}),N.jsx("text",{className:"ric-edge-text",y:b.height/2,dy:"0.3em",ref:E,style:r,children:n}),d]}):null}or.displayName="EdgeText";const sr=a.memo(or);function Hn(t){return t!=null&&t!==""&&!isNaN(Number(t))}function We({id:t,path:e,labelX:n,labelY:r,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:l,labelBgPadding:d,labelBgBorderRadius:u,interactionWidth:x=20,style:b,markerEnd:L,markerStart:E,className:k="",...T}){return N.jsxs(N.Fragment,{children:[N.jsx("path",{id:t,d:e,fill:"none",stroke:"#b1b1b7",strokeWidth:1.5,className:`ric-edge-path ${k}`,style:b,markerEnd:L,markerStart:E,...T}),x?N.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:x,className:"ric-edge-interaction",style:{pointerEvents:"stroke"}}):null,s&&Hn(n)&&Hn(r)?N.jsx(sr,{x:n,y:r,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:l,labelBgPadding:d,labelBgBorderRadius:u}):null]})}const je=20;function _n(t,e,n){switch(n){case"right":return{x:t+je,y:e};case"left":return{x:t-je,y:e};case"bottom":return{x:t,y:e+je};case"top":return{x:t,y:e-je};default:return{x:t+je,y:e}}}const Rn=a.memo(function({id:e,sourceX:n,sourceY:r,targetX:s,targetY:o,sourcePosition:i="bottom",targetPosition:l="top",label:d,labelStyle:u,labelShowBg:x,labelBgStyle:b,labelBgPadding:L,labelBgBorderRadius:E,style:k,markerEnd:T,markerStart:C,interactionWidth:z}){let _,j,D;const h=_n(n,r,i),y=_n(s,o,l),p=Math.abs(y.x-h.x),R=Math.max(50,p*.5);let w,P,m,B;switch(i){case"left":w=h.x-R,P=h.y;break;case"top":w=h.x,P=h.y-R;break;case"bottom":w=h.x,P=h.y+R;break;default:w=h.x+R,P=h.y;break}switch(l){case"right":m=y.x+R,B=y.y;break;case"top":m=y.x,B=y.y-R;break;case"bottom":m=y.x,B=y.y+R;break;default:m=y.x-R,B=y.y;break}_=`M ${n},${r} L ${h.x},${h.y} C ${w},${P} ${m},${B} ${y.x},${y.y} L ${s},${o}`;const q=.5,W=.5;return j=W*W*W*h.x+3*W*W*q*w+3*W*q*q*m+q*q*q*y.x,D=W*W*W*h.y+3*W*W*q*P+3*W*q*q*B+q*q*q*y.y,N.jsx(We,{id:e,path:_,labelX:j,labelY:D,label:d,labelStyle:u,labelShowBg:x,labelBgStyle:b,labelBgPadding:L,labelBgBorderRadius:E,style:k,markerEnd:T,markerStart:C,interactionWidth:z})});Rn.displayName="BezierEdge";function kn({sourceX:t,sourceY:e,targetX:n,targetY:r}){const s=`M ${t},${e}L ${n},${r}`,o=(t+n)/2,i=(e+r)/2;return[s,o,i,0,0]}function Cn({sourceX:t,sourceY:e,targetX:n,targetY:r,sourcePosition:s="right",targetPosition:o="left",curvature:i=.25}){const l=Math.abs(n-t),d=Math.abs(r-e),u=Math.sqrt(l*l+d*d),x=Math.max(u*i,50);let b,L,E,k;switch(s){case"top":b=t,L=e-x;break;case"bottom":b=t,L=e+x;break;case"left":b=t-x,L=e;break;default:b=t+x,L=e;break}switch(o){case"top":E=n,k=r-x;break;case"bottom":E=n,k=r+x;break;case"right":E=n+x,k=r;break;default:E=n-x,k=r;break}const T=`M ${t},${e} C ${b},${L} ${E},${k} ${n},${r}`,C=.5,z=1-C,_=z*z*z*t+3*z*z*C*b+3*z*C*C*E+C*C*C*n,j=z*z*z*e+3*z*z*C*L+3*z*C*C*k+C*C*C*r;return[T,_,j,0,0]}function En({sourceX:t,sourceY:e,targetX:n,targetY:r}){const s=Math.abs(n-t),o=Math.max(s*.5,50),i=t+o,l=n-o,d=`M ${t},${e} C ${i},${e} ${l},${r} ${n},${r}`,u=.5,x=.5,b=x*x*x*t+3*x*x*u*i+3*x*u*u*l+u*u*u*n,L=x*x*x*e+3*x*x*u*e+3*x*u*u*r+u*u*u*r;return[d,b,L,0,0]}function tn({sourceX:t,sourceY:e,targetX:n,targetY:r,sourcePosition:s="right",targetPosition:o="left",borderRadius:i=5,offset:l=20}){const d=s==="left"||s==="right",u=Math.min(i,Math.abs(n-t)/2,Math.abs(r-e)/2);if(d){if(Math.abs(r-e)<1)return[`M ${t},${e} L ${n},${r}`,(t+n)/2,e,0,0];const E=(t+n)/2,k=r>e?1:-1;return[`M ${t},${e} L ${E-u},${e} Q ${E},${e} ${E},${e+k*u} L ${E},${r-k*u} Q ${E},${r} ${E+(n>E?u:-u)},${r} L ${n},${r}`,E,(e+r)/2,0,0]}const x=(e+r)/2,b=n>t?1:-1;return[`M ${t},${e} L ${t},${x-u} Q ${t},${x} ${t+b*u},${x} L ${n-b*u},${x} Q ${n},${x} ${n},${x+(r>x?u:-u)} L ${n},${r}`,(t+n)/2,x,0,0]}function Zr({sourceX:t,sourceY:e,targetX:n,targetY:r}){const[,s,o]=Cn({sourceX:t,sourceY:e,targetX:n,targetY:r});return[s,o,0,0]}function Qr({sourceX:t,sourceY:e,targetX:n,targetY:r}){return[(t+n)/2,(e+r)/2,0,0]}function Kr(t,e,n){const r=n.filter(o=>o.id!==t.id),s={...t,id:t.id,source:e.source,target:e.target,sourceHandle:e.sourceHandle??t.sourceHandle,targetHandle:e.targetHandle??t.targetHandle};return r.push(s),r}const en=160,nn=60,De=20,Ke=12,rn=20;function Wn(t,e,n){var i,l;const r=t.width||((i=t.measured)==null?void 0:i.width)||en,s=t.height||((l=t.measured)==null?void 0:l.height)||nn,o=t._absolutePosition||t.position;if(t.handles&&t.handles.length>0){for(const d of t.handles)if(d.type===e&&(!n||d.id===n)){if(d.x!==void 0&&d.y!==void 0)return{x:o.x+d.x,y:o.y+d.y,dir:d.position||(e==="source"?"right":"left")};switch(d.position||(e==="source"?"right":"left")){case"top":return{x:o.x+r/2,y:o.y,dir:"top"};case"bottom":return{x:o.x+r/2,y:o.y+s,dir:"bottom"};case"left":return{x:o.x,y:o.y+s/2,dir:"left"};default:return{x:o.x+r,y:o.y+s/2,dir:"right"}}}}return e==="source"?{x:o.x+r,y:o.y+s/2,dir:"right"}:{x:o.x,y:o.y+s/2,dir:"left"}}function on(t,e){switch(t.dir){case"right":return{x:t.x+e,y:t.y,dir:t.dir};case"left":return{x:t.x-e,y:t.y,dir:t.dir};case"bottom":return{x:t.x,y:t.y+e,dir:t.dir};case"top":return{x:t.x,y:t.y-e,dir:t.dir};default:return{x:t.x+e,y:t.y,dir:t.dir}}}function Vr(t,e,n,r,s,o,i,l){const d=Math.min(t,n),u=Math.max(t,n),x=Math.min(e,r),b=Math.max(e,r);if(u<=s||d>=s+i||b<=o||x>=o+l)return!1;const L=.5;if(t>s+L&&t<s+i-L&&e>o+L&&e<o+l-L||n>s+L&&n<s+i-L&&r>o+L&&r<o+l-L)return!0;const E=(t+n)/2,k=(e+r)/2;if(E>s+L&&E<s+i-L&&k>o+L&&k<o+l-L)return!0;const T=[[s,o],[s+i,o],[s+i,o+l],[s,o+l]];for(let C=0;C<4;C++)if(Jr(t,e,n,r,T[C][0],T[C][1],T[(C+1)%4][0],T[(C+1)%4][1]))return!0;return!1}function Jr(t,e,n,r,s,o,i,l){const d=(i-s)*(e-o)-(l-o)*(t-s),u=(i-s)*(r-o)-(l-o)*(n-s),x=(n-t)*(o-e)-(r-e)*(s-t),b=(n-t)*(l-e)-(r-e)*(i-t);return(d>0&&u<0||d<0&&u>0)&&(x>0&&b<0||x<0&&b>0)}function wn(t,e,n,r,s){for(let o=0;o<s.length;o++){const i=s[o];if(Vr(t,e,n,r,i.x,i.y,i.w,i.h))return!1}return!0}function to(t,e,n){for(let r=0;r<n.length;r++){const s=n[r];if(t>s.x&&t<s.x+s.w&&e>s.y&&e<s.y+s.h)return!0}return!1}function zn(t,e){var r,s;const n=[];for(let o=0;o<t.length;o++){const i=t[o];if(i.hidden||e&&e.has(i.id)||i.type==="group")continue;const l=i._absolutePosition||i.position,d=i.width||((r=i.measured)==null?void 0:r.width)||en,u=i.height||((s=i.measured)==null?void 0:s.height)||nn;n.push({id:i.id,x:l.x-De,y:l.y-De,w:d+2*De,h:u+2*De})}return n}function ir(t,e,n){if(wn(t.x,t.y,e.x,e.y,n))return null;const r=new Set,s=new Set;r.add(t.x),r.add(e.x),s.add(t.y),s.add(e.y);const o=De+5;t.dir==="right"?r.add(t.x+o):t.dir==="left"?r.add(t.x-o):t.dir==="top"?s.add(t.y-o):t.dir==="bottom"&&s.add(t.y+o),e.dir==="right"?r.add(e.x+o):e.dir==="left"?r.add(e.x-o):e.dir==="top"?s.add(e.y-o):e.dir==="bottom"&&s.add(e.y+o);for(let m=0;m<n.length;m++){const B=n[m];r.add(B.x),r.add(B.x+B.w),s.add(B.y),s.add(B.y+B.h)}const i=[...r].sort((m,B)=>m-B),l=[...s].sort((m,B)=>m-B),d=new Map,u=new Map;for(let m=0;m<i.length;m++)d.set(i[m],m);for(let m=0;m<l.length;m++)u.set(l[m],m);const x=i.length,b=l.length,L=(m,B)=>B*x+m,E=d.get(t.x),k=u.get(t.y),T=d.get(e.x),C=u.get(e.y);if(E===void 0||k===void 0||T===void 0||C===void 0)return null;const z=L(E,k),_=L(T,C),j=new Float64Array(x*b).fill(1/0),D=new Float64Array(x*b).fill(1/0),h=new Int32Array(x*b).fill(-1),y=new Int8Array(x*b).fill(-1),p=new Uint8Array(x*b);j[z]=0,D[z]=Math.abs(i[T]-t.x)+Math.abs(l[C]-t.y);const R=[z],w=15,P=[[1,0],[-1,0],[0,1],[0,-1]];for(;R.length>0;){let m=0;for(let U=1;U<R.length;U++)D[R[U]]<D[R[m]]&&(m=U);const B=R[m];if(R[m]=R[R.length-1],R.pop(),B===_){const U=[];let G=_;for(;G!==-1&&G!==z;){const rt=G/x|0,ct=G%x;U.unshift({x:i[ct],y:l[rt]}),G=h[G]}return U.unshift({x:t.x,y:t.y}),eo(U,n)}if(p[B])continue;p[B]=1;const q=B/x|0,W=B%x,gt=i[W],K=l[q],nt=y[B];for(let U=0;U<4;U++){const G=W+P[U][0],rt=q+P[U][1];if(G<0||G>=x||rt<0||rt>=b)continue;const ct=L(G,rt);if(p[ct])continue;const lt=i[G],ot=l[rt];if(to(lt,ot,n)||!wn(gt,K,lt,ot,n))continue;const Nt=Math.abs(lt-gt)+Math.abs(ot-K),st=nt>=0&&nt!==U?w:0,xt=j[B]+Nt+st;xt<j[ct]&&(h[ct]=B,y[ct]=U,j[ct]=xt,D[ct]=xt+Math.abs(i[T]-lt)+Math.abs(l[C]-ot),R.push(ct))}}return null}function eo(t,e){if(!t||t.length<=2)return t;const n=[t[0]];for(let r=1;r<t.length-1;r++){const s=n[n.length-1],o=t[r],i=t[r+1],l=Math.abs(s.x-o.x)<.5&&Math.abs(o.x-i.x)<.5,d=Math.abs(s.y-o.y)<.5&&Math.abs(o.y-i.y)<.5;(l||d)&&wn(s.x,s.y,i.x,i.y,e)||n.push(o)}return n.push(t[t.length-1]),n}function no(t){const e=new Map,n=new Map;for(const s of t){const o=s._routedPoints;if(!(!o||o.length<2))for(let i=0;i<o.length-1;i++){const l=o[i],d=o[i+1];if(Math.abs(l.y-d.y)<.5){const u=Math.round(l.y*10)/10;e.has(u)||e.set(u,[]),e.get(u).push({edgeId:s.id,segIdx:i,x1:Math.min(l.x,d.x),x2:Math.max(l.x,d.x)})}else if(Math.abs(l.x-d.x)<.5){const u=Math.round(l.x*10)/10;n.has(u)||n.set(u,[]),n.get(u).push({edgeId:s.id,segIdx:i,y1:Math.min(l.y,d.y),y2:Math.max(l.y,d.y)})}}}const r=new Map;for(const s of t)s._routedPoints&&r.set(s.id,s._routedPoints.map(o=>({...o})));for(const[,s]of e){if(s.length<2)continue;const o=Fn(s,"x1","x2");for(const i of o){if(i.length<2)continue;const l=(i.length-1)*Ke/2;for(let d=0;d<i.length;d++){const u=i[d],x=-l+d*Ke,b=r.get(u.edgeId);b&&(b[u.segIdx].y+=x,b[u.segIdx+1].y+=x)}}}for(const[,s]of n){if(s.length<2)continue;const o=Fn(s,"y1","y2");for(const i of o){if(i.length<2)continue;const l=(i.length-1)*Ke/2;for(let d=0;d<i.length;d++){const u=i[d],x=-l+d*Ke,b=r.get(u.edgeId);b&&(b[u.segIdx].x+=x,b[u.segIdx+1].x+=x)}}}return t.map(s=>{const o=r.get(s.id);return o?{...s,_routedPoints:o}:s})}function Fn(t,e,n){if(t.length<2)return[];const r=[...t].sort((i,l)=>i[e]-l[e]),s=[];let o=[r[0]];for(let i=1;i<r.length;i++){const l=o[o.length-1];r[i][e]<l[n]?o.push(r[i]):(o.length>1&&s.push(o),o=[r[i]])}return o.length>1&&s.push(o),s}function sn(t,e=6,n=!1){if(!t||t.length<2)return null;if(n)return ro(t);const r=e;let s=`M ${t[0].x},${t[0].y}`;for(let o=1;o<t.length-1;o++){const i=t[o-1],l=t[o],d=t[o+1],u=Math.abs(l.x-i.x)+Math.abs(l.y-i.y),x=Math.abs(d.x-l.x)+Math.abs(d.y-l.y),b=Math.min(r,u/2,x/2);if(b>.5){const L=l.x-i.x,E=l.y-i.y,k=d.x-l.x,T=d.y-l.y,C=Math.sqrt(L*L+E*E)||1,z=Math.sqrt(k*k+T*T)||1;s+=` L ${l.x-L/C*b},${l.y-E/C*b}`,s+=` Q ${l.x},${l.y} ${l.x+k/z*b},${l.y+T/z*b}`}else s+=` L ${l.x},${l.y}`}return s+=` L ${t[t.length-1].x},${t[t.length-1].y}`,s}function ro(t){if(t.length===2)return`M ${t[0].x},${t[0].y} L ${t[1].x},${t[1].y}`;if(t.length===3)return`M ${t[0].x},${t[0].y} Q ${t[1].x},${t[1].y} ${t[2].x},${t[2].y}`;const e=.3;let n=`M ${t[0].x},${t[0].y}`;for(let r=0;r<t.length-1;r++){const s=t[r===0?0:r-1],o=t[r],i=t[r+1],l=t[r+2<t.length?r+2:t.length-1],d=o.x+(i.x-s.x)*e,u=o.y+(i.y-s.y)*e,x=i.x-(l.x-o.x)*e,b=i.y-(l.y-o.y)*e;n+=` C ${d},${u} ${x},${b} ${i.x},${i.y}`}return n}function an(t){if(!t||t.length<2)return{x:0,y:0};let e=0;for(let r=1;r<t.length;r++)e+=Math.abs(t[r].x-t[r-1].x)+Math.abs(t[r].y-t[r-1].y);let n=e/2;for(let r=1;r<t.length;r++){const s=Math.abs(t[r].x-t[r-1].x)+Math.abs(t[r].y-t[r-1].y);if(n<=s){const o=s>0?n/s:0;return{x:t[r-1].x+(t[r].x-t[r-1].x)*o,y:t[r-1].y+(t[r].y-t[r-1].y)*o}}n-=s}return{x:t[0].x,y:t[0].y}}function oo(t,e){if(!t||!e||t.length===0||e.length===0)return e;const n={};for(const o of t)n[o.id]=o;const r=zn(t,null),s=e.map(o=>{var y,p,R,w;const i=o.type||"default";if(i==="bezier"||i==="simplebezier"||i==="default")return o;const l=n[o.source],d=n[o.target];if(!l||!d||l.hidden||d.hidden)return o;const u=Wn(l,"source",o.sourceHandle),x=Wn(d,"target",o.targetHandle),b=on(u,rn),L=on(x,rn),E=5,k=r.filter(P=>P.id!==o.source&&P.id!==o.target),T=l._absolutePosition||l.position,C=l.width||((y=l.measured)==null?void 0:y.width)||en,z=l.height||((p=l.measured)==null?void 0:p.height)||nn;k.push({id:o.source,x:T.x-E,y:T.y-E,w:C+2*E,h:z+2*E});const _=d._absolutePosition||d.position,j=d.width||((R=d.measured)==null?void 0:R.width)||en,D=d.height||((w=d.measured)==null?void 0:w.height)||nn;if(k.push({id:o.target,x:_.x-E,y:_.y-E,w:j+2*E,h:D+2*E}),k.length===0)return o;const h=ir(b,L,k);return h&&h.length>=2?(h.unshift({x:u.x,y:u.y}),h.push({x:x.x,y:x.y}),{...o,_routedPoints:h}):o});return no(s)}function so(t,e,n,r,s,o,i,l){const d=zn(i,l?new Set(l):null);if(d.length===0)return null;const u={x:t,y:e,dir:s||"right"},x={x:n,y:r,dir:o||"left"},b=on(u,rn),L=on(x,rn),E=ir(b,L,d);return E&&E.length>=2?(E.unshift({x:u.x,y:u.y}),E.push({x:x.x,y:x.y}),E):null}const Nn=a.memo(function({id:e,sourceX:n,sourceY:r,targetX:s,targetY:o,label:i,labelStyle:l,labelShowBg:d,labelBgStyle:u,labelBgPadding:x,labelBgBorderRadius:b,style:L,markerEnd:E,markerStart:k,interactionWidth:T,routedPoints:C}){let z,_,j;if(C&&C.length>=2){z=sn(C);const D=an(C);_=D.x,j=D.y}else[z,_,j]=kn({sourceX:n,sourceY:r,targetX:s,targetY:o});return N.jsx(We,{id:e,path:z,labelX:_,labelY:j,label:i,labelStyle:l,labelShowBg:d,labelBgStyle:u,labelBgPadding:x,labelBgBorderRadius:b,style:L,markerEnd:E,markerStart:k,interactionWidth:T})});Nn.displayName="StraightEdge";const Pn=a.memo(function({id:e,sourceX:n,sourceY:r,targetX:s,targetY:o,sourcePosition:i="bottom",targetPosition:l="top",label:d,labelStyle:u,labelShowBg:x,labelBgStyle:b,labelBgPadding:L,labelBgBorderRadius:E,style:k,markerEnd:T,markerStart:C,pathOptions:z,interactionWidth:_,routedPoints:j}){let D,h,y;if(j&&j.length>=2){D=sn(j);const p=an(j);h=p.x,y=p.y}else[D,h,y]=tn({sourceX:n,sourceY:r,sourcePosition:i,targetX:s,targetY:o,targetPosition:l,borderRadius:z==null?void 0:z.borderRadius,offset:z==null?void 0:z.offset});return N.jsx(We,{id:e,path:D,labelX:h,labelY:y,label:d,labelStyle:u,labelShowBg:x,labelBgStyle:b,labelBgPadding:L,labelBgBorderRadius:E,style:k,markerEnd:T,markerStart:C,interactionWidth:_})});Pn.displayName="SmoothStepEdge";const ar=a.memo(function({id:e,...n}){var s;const r=a.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(s=n.pathOptions)==null?void 0:s.offset]);return N.jsx(Pn,{...n,id:e,pathOptions:r})});ar.displayName="StepEdge";const Ln=a.memo(function({id:e,sourceX:n,sourceY:r,targetX:s,targetY:o,sourcePosition:i,targetPosition:l,label:d,labelStyle:u,labelShowBg:x,labelBgStyle:b,labelBgPadding:L,labelBgBorderRadius:E,style:k,markerEnd:T,markerStart:C,interactionWidth:z,routedPoints:_}){let j,D,h;if(_&&_.length>=2){j=sn(_);const y=an(_);D=y.x,h=y.y}else[j,D,h]=En({sourceX:n,sourceY:r,targetX:s,targetY:o});return N.jsx(We,{id:e,path:j,labelX:D,labelY:h,label:d,labelStyle:u,labelShowBg:x,labelBgStyle:b,labelBgPadding:L,labelBgBorderRadius:E,style:k,markerEnd:T,markerStart:C,interactionWidth:z})});Ln.displayName="SimpleBezierEdge";const io={input:er,output:nr,group:rr},ao={bezier:Rn,straight:Nn,simplebezier:Ln};function co({cards:t,nodes:e=[],edges:n=[],nodeTypes:r,edgeTypes:s,dark:o,gridSize:i,width:l="100%",height:d="420px",className:u="",style:x={},zoomMin:b,zoomMax:L,initialCamera:E,fitView:k,fitViewOptions:T,onNodesChange:C,onEdgesChange:z,onConnect:_,onConnectStart:j,onConnectEnd:D,onNodeClick:h,onNodeDoubleClick:y,onNodeMouseEnter:p,onNodeMouseMove:R,onNodeMouseLeave:w,onNodeContextMenu:P,onNodeDragStart:m,onNodeDrag:B,onNodeDragStop:q,onEdgeClick:W,onEdgeDoubleClick:gt,onEdgeMouseEnter:K,onEdgeMouseMove:nt,onEdgeMouseLeave:U,onEdgeContextMenu:G,onPaneClick:rt,onPaneContextMenu:ct,onPaneMouseEnter:lt,onPaneMouseMove:ot,onPaneMouseLeave:Nt,onSelectionChange:st,onInit:xt,onMoveStart:Et,onMove:Rt,onMoveEnd:ut,onDelete:dt,onBeforeDelete:wt,onError:zt,onDragOver:ht,onDrop:Qt,onDragEnter:Re,onDragLeave:It,nodesDraggable:Xt,nodesConnectable:Ht,elementsSelectable:fe,multiSelectionKeyCode:se,selectionOnDrag:he,selectionMode:ye,connectionMode:Fe,connectionRadius:ke,connectOnClick:Xe,isValidConnection:Ye,defaultEdgeOptions:Ue,snapToGrid:qe,snapGrid:Ce,deleteKeyCode:Kt,panActivationKeyCode:Vt,panOnScroll:ge,panOnScrollMode:cn,panOnScrollSpeed:ln,zoomOnScroll:Yt,zoomOnDoubleClick:In,zoomOnPinch:un,preventScrolling:ie,translateExtent:pt,nodeExtent:Ee,autoPanOnNodeDrag:kt,autoPanOnConnect:yt,autoPanSpeed:Jt,edgesReconnectable:O,elevateNodesOnSelect:Pt,elevateEdgesOnSelect:dn,edgeRouting:ze=!0,onHudUpdate:Ot,onNodesProcessed:fn,showHud:hn=!0,showHint:Bt=!0,hintText:jt="Drag to pan · Scroll to zoom",children:xe,...te}){const[_t,pe]=a.useState({wx:0,wy:0,zoom:"1.00"}),Ne=a.useRef(null),Ge=a.useRef(null),Oe=a.useCallback(Q=>{pe(Q),Ot==null||Ot(Q)},[Ot]),ee=a.useMemo(()=>({...io,...r}),[r]),Ut=a.useMemo(()=>({...ao,...s}),[s]),ae=a.useMemo(()=>{const Q=e.filter(At=>At.type&&ee[At.type]);return Q.sort((At,it)=>{const Lt=At.type==="group"||!At.parentId&&Q.some(be=>be.parentId===At.id),de=it.type==="group"||!it.parentId&&Q.some(be=>be.parentId===it.id);return Lt&&!de?-1:!Lt&&de?1:0})},[e,ee]),me=a.useMemo(()=>n.filter(Q=>Q.type&&Ut[Q.type]),[n,Ut]),Z=a.useMemo(()=>e.map(Q=>Q.type&&ee[Q.type]?{...Q,_customRendered:!0}:Q),[e,ee]),vt=a.useMemo(()=>n.map(Q=>Q.type&&Ut[Q.type]?{...Q,_customRendered:!0}:Q),[n,Ut]),{wrapRef:St,canvasRef:ne,canvasReady:Pe,onPointerDown:Le,onPointerMove:Ie,onPointerUp:Se,store:re}=On({cards:t,nodes:Z,edges:vt,dark:o,gridSize:i,zoomMin:b,zoomMax:L,initialCamera:E,fitView:k,fitViewOptions:T,onHudUpdate:Oe,onNodesProcessed:fn,onNodesChange:C,onEdgesChange:z,onConnect:_,onConnectStart:j,onConnectEnd:D,onNodeClick:h,onNodeDoubleClick:y,onNodeMouseEnter:p,onNodeMouseMove:R,onNodeMouseLeave:w,onNodeContextMenu:P,onNodeDragStart:m,onNodeDrag:B,onNodeDragStop:q,onEdgeClick:W,onEdgeDoubleClick:gt,onEdgeMouseEnter:K,onEdgeMouseMove:nt,onEdgeMouseLeave:U,onEdgeContextMenu:G,onPaneClick:rt,onPaneContextMenu:ct,onPaneMouseEnter:lt,onPaneMouseMove:ot,onPaneMouseLeave:Nt,onSelectionChange:st,onInit:xt,onMoveStart:Et,onMove:Rt,onMoveEnd:ut,onDelete:dt,onBeforeDelete:wt,onError:zt,nodesDraggable:Xt,nodesConnectable:Ht,elementsSelectable:fe,multiSelectionKeyCode:se,selectionOnDrag:he,selectionMode:ye,connectionMode:Fe,connectionRadius:ke,connectOnClick:Xe,isValidConnection:Ye,defaultEdgeOptions:Ue,snapToGrid:qe,snapGrid:Ce,deleteKeyCode:Kt,panActivationKeyCode:Vt,panOnScroll:ge,panOnScrollMode:cn,panOnScrollSpeed:ln,zoomOnScroll:Yt,zoomOnDoubleClick:In,zoomOnPinch:un,preventScrolling:ie,translateExtent:pt,nodeExtent:Ee,autoPanOnNodeDrag:kt,autoPanOnConnect:yt,autoPanSpeed:Jt,edgesReconnectable:O,elevateNodesOnSelect:Pt,edgeRouting:ze}),Te=a.useMemo(()=>({...re,edgeLabelContainerRef:Ne,viewportPortalRef:Ge,get nodes(){return e},get edges(){return n}}),[re,e,n]),ce=a.useRef(null),le=a.useRef(null),ue=a.useRef(null),qt=a.useRef(null);a.useEffect(()=>{let Q;const At=()=>{const it=re.cameraRef.current,Lt=`translate(${it.x}px, ${it.y}px) scale(${it.zoom})`,de=`translate(${it.x}, ${it.y}) scale(${it.zoom})`;ce.current&&(ce.current.style.transform=Lt),le.current&&le.current.setAttribute("transform",de),ue.current&&(ue.current.style.transform=Lt),qt.current&&(qt.current.style.transform=Lt),Q=requestAnimationFrame(At)};return Q=requestAnimationFrame(At),()=>cancelAnimationFrame(Q)},[re]);const ve=ae.length>0,Zt=me.length>0;return N.jsx(Zn.Provider,{value:Te,children:N.jsxs("div",{ref:St,className:`ric-wrap ${u}`,style:{width:l,height:d,...x},onPointerDown:Le,onPointerMove:Ie,onPointerUp:Se,onDragOver:ht,onDrop:Qt,onDragEnter:Re,onDragLeave:It,tabIndex:0,children:[N.jsx("canvas",{ref:ne,className:"ric-canvas"}),!Pe&&N.jsx("div",{className:"ric-loader",children:N.jsx("div",{className:"ric-spinner"})}),Zt&&N.jsx("svg",{className:"ric-edges-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:N.jsx("g",{ref:le,children:me.map(Q=>N.jsx(qr,{edge:Q,edgeType:Ut[Q.type],nodes:e,reconnectable:O},Q.id))})}),ve&&N.jsx("div",{ref:ce,className:"ric-nodes-overlay",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:10},children:ae.map(Q=>N.jsx(Fr,{node:Q,nodeType:ee[Q.type]},Q.id))}),N.jsx("div",{ref:Q=>{Ne.current=Q,ue.current=Q},className:"ric-edge-labels",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:5}}),N.jsx("div",{ref:Q=>{Ge.current=Q,qt.current=Q},className:"ric-viewport-portal",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:6}}),Bt&&N.jsx("div",{className:"ric-hint",children:jt}),hn&&N.jsxs("div",{className:"ric-info",children:["world: (",_t.wx,", ",_t.wy,") zoom: ",_t.zoom,"x",_t.nodeCount>0&&N.jsxs(N.Fragment,{children:[" nodes: ",_t.nodeCount]}),_t.edgeCount>0&&N.jsxs(N.Fragment,{children:[" edges: ",_t.edgeCount]})]}),N.jsx(Jn,{selectionKeyCode:se||"Shift",selectionMode:ye||"partial"}),xe]})})}function lo({children:t}){return t}function cr(t,e){const n=[],r=new Map,s=[];for(const o of t)if(o.type==="add")s.push(o);else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const i=r.get(o.id);i?i.push(o):r.set(o.id,[o])}for(const o of e){const i=r.get(o.id);if(!i){n.push(o);continue}if(i[0].type==="remove")continue;if(i[0].type==="replace"){n.push({...i[0].item});continue}const l={...o};for(const d of i)uo(d,l);n.push(l)}for(const o of s)o.index!==void 0?n.splice(o.index,0,{...o.item}):n.push({...o.item});return n}function uo(t,e){switch(t.type){case"select":e.selected=t.selected;break;case"position":t.position!==void 0&&(e.position=t.position),t.dragging!==void 0&&(e.dragging=t.dragging);break;case"dimensions":t.dimensions!==void 0&&(e.measured={...t.dimensions},(t.setAttributes===!0||t.setAttributes==="width")&&(e.width=t.dimensions.width),(t.setAttributes===!0||t.setAttributes==="height")&&(e.height=t.dimensions.height)),t.handleBounds!==void 0&&(e.handleBounds=t.handleBounds);break}}function lr(t,e){return cr(t,e)}function ur(t,e){return cr(t,e)}function fo(t,e){return!t.source||!t.target?(console.warn("addEdge: source and target are required"),e):e.some(r=>r.source===t.source&&r.target===t.target&&(r.sourceHandle||null)===(t.sourceHandle||null)&&(r.targetHandle||null)===(t.targetHandle||null))?e:[...e,{id:t.id||`e-${t.source}-${t.target}`,...t}]}function ho(t){const[e,n]=a.useState(t),r=a.useCallback(s=>n(o=>lr(s,o)),[]);return[e,n,r]}function yo(t){const[e,n]=a.useState(t),r=a.useCallback(s=>n(o=>ur(s,o)),[]);return[e,n,r]}function dr(){const t=ft(),e=a.useCallback(()=>[...t.nodesRef.current],[t]),n=a.useCallback(()=>[...t.edgesRef.current],[t]),r=a.useCallback(h=>t.nodesRef.current.find(y=>y.id===h),[t]),s=a.useCallback(h=>t.edgesRef.current.find(y=>y.id===h),[t]),o=a.useCallback(h=>{var y,p,R,w;if(typeof h=="function"){const P=h(t.nodesRef.current);(p=(y=t.onNodesChangeRef).current)==null||p.call(y,[...t.nodesRef.current.map(m=>({id:m.id,type:"remove"})),...P.map(m=>({type:"add",item:m}))])}else(w=(R=t.onNodesChangeRef).current)==null||w.call(R,[...t.nodesRef.current.map(P=>({id:P.id,type:"remove"})),...h.map(P=>({type:"add",item:P}))])},[t]),i=a.useCallback(h=>{var y,p,R,w;if(typeof h=="function"){const P=h(t.edgesRef.current);(p=(y=t.onEdgesChangeRef).current)==null||p.call(y,[...t.edgesRef.current.map(m=>({id:m.id,type:"remove"})),...P.map(m=>({type:"add",item:m}))])}else(w=(R=t.onEdgesChangeRef).current)==null||w.call(R,[...t.edgesRef.current.map(P=>({id:P.id,type:"remove"})),...h.map(P=>({type:"add",item:P}))])},[t]),l=a.useCallback(h=>{var p,R;const y=Array.isArray(h)?h:[h];(R=(p=t.onNodesChangeRef).current)==null||R.call(p,y.map(w=>({type:"add",item:w})))},[t]),d=a.useCallback(h=>{var p,R;const y=Array.isArray(h)?h:[h];(R=(p=t.onEdgesChangeRef).current)==null||R.call(p,y.map(w=>({type:"add",item:w})))},[t]),u=a.useCallback(({nodes:h=[],edges:y=[]})=>{if(h.length&&t.onNodesChangeRef.current){t.onNodesChangeRef.current(h.map(R=>({id:R.id,type:"remove"})));const p=qn(h,t.edgesRef.current);p.length&&t.onEdgesChangeRef.current&&t.onEdgesChangeRef.current(p.map(R=>({id:R.id,type:"remove"})))}y.length&&t.onEdgesChangeRef.current&&t.onEdgesChangeRef.current(y.map(p=>({id:p.id,type:"remove"})))},[t]),x=a.useCallback(()=>{const h=t.cameraRef.current;return{x:h.x,y:h.y,zoom:h.zoom}},[t]),b=a.useCallback((h,y)=>{t.cameraRef.current={x:h.x??t.cameraRef.current.x,y:h.y??t.cameraRef.current.y,zoom:h.zoom??t.cameraRef.current.zoom},t.sendCamera()},[t]),L=a.useCallback(()=>t.cameraRef.current.zoom,[t]),E=a.useCallback(h=>{const y=t.cameraRef.current,p=t.wrapRef.current;if(!p)return;const R=p.getBoundingClientRect(),w=R.width/2,P=R.height/2,m=1.2;y.x=w-(w-y.x)*m,y.y=P-(P-y.y)*m,y.zoom=Math.min(t.zoomMax,y.zoom*m),t.sendCamera()},[t]),k=a.useCallback(h=>{const y=t.cameraRef.current,p=t.wrapRef.current;if(!p)return;const R=p.getBoundingClientRect(),w=R.width/2,P=R.height/2,m=1/1.2;y.x=w-(w-y.x)*m,y.y=P-(P-y.y)*m,y.zoom=Math.max(t.zoomMin,y.zoom*m),t.sendCamera()},[t]),T=a.useCallback(h=>{const y=t.cameraRef.current,p=t.wrapRef.current;if(!p)return;const R=p.getBoundingClientRect(),w=R.width/2,P=R.height/2,m=h/y.zoom;y.x=w-(w-y.x)*m,y.y=P-(P-y.y)*m,y.zoom=Math.min(t.zoomMax,Math.max(t.zoomMin,h)),t.sendCamera()},[t]),C=a.useCallback((h={})=>{const y=t.nodesRef.current;if(!y.length)return;const p=t.wrapRef.current;if(!p)return;const R=p.getBoundingClientRect(),w=h.padding??.1,P=h.nodes?y.filter(q=>h.nodes.some(W=>W.id===q.id)):y;if(!P.length)return;const m=Ve(P),B=Je(m,R.width,R.height,w);h.maxZoom&&(B.zoom=Math.min(B.zoom,h.maxZoom)),h.minZoom&&(B.zoom=Math.max(B.zoom,h.minZoom)),t.cameraRef.current=B,t.sendCamera()},[t]),z=a.useCallback((h,y,p={})=>{const R=t.wrapRef.current;if(!R)return;const w=R.getBoundingClientRect(),P=p.zoom??t.cameraRef.current.zoom;t.cameraRef.current={x:w.width/2-h*P,y:w.height/2-y*P,zoom:P},t.sendCamera()},[t]),_=a.useCallback(h=>t.screenToWorld(h.x,h.y),[t]),j=a.useCallback(h=>{const y=t.cameraRef.current,p=t.wrapRef.current;if(!p)return{x:0,y:0};const R=p.getBoundingClientRect();return{x:h.x*y.zoom+y.x+R.left,y:h.y*y.zoom+y.y+R.top}},[t]),D=a.useCallback((h,y)=>{var w,P;const p=t.nodesRef.current.find(m=>m.id===h);if(!p)return;const R=typeof y=="function"?y(p.data):{...p.data,...y};(P=(w=t.onNodesChangeRef).current)==null||P.call(w,[{id:h,type:"replace",item:{...p,data:R}}])},[t]);return{getNodes:e,getEdges:n,getNode:r,getEdge:s,setNodes:o,setEdges:i,addNodes:l,addEdges:d,deleteElements:u,getViewport:x,setViewport:b,getZoom:L,zoomIn:E,zoomOut:k,zoomTo:T,fitView:C,setCenter:z,screenToFlowPosition:_,flowToScreenPosition:j,updateNodeData:D}}function go(){return ft().nodes}function xo(){return ft().edges}function po(){return ft().viewport}function mo(){return ft().connection}function vo(t){const e=ft(),n=Array.isArray(t)?t:[t];return a.useMemo(()=>n.map(r=>{const s=e.nodes.find(o=>o.id===r);return s?{id:s.id,type:s.type,data:s.data}:null}).filter(Boolean),[e.nodes,...n])}function bo(t){const e=ft();return a.useMemo(()=>e.edges.filter(n=>n.source===t||n.target===t),[e.edges,t])}function wo({nodeId:t,type:e,handleId:n}){const r=ft();return a.useMemo(()=>r.edges.filter(s=>e==="source"?s.source===t&&(n?s.sourceHandle===n:!0):s.target===t&&(n?s.targetHandle===n:!0)),[r.edges,t,e,n])}function Mo({onChange:t,onStart:e,onEnd:n}){const r=ft(),s=a.useRef(t),o=a.useRef(e),i=a.useRef(n);a.useEffect(()=>{s.current=t},[t]),a.useEffect(()=>{o.current=e},[e]),a.useEffect(()=>{i.current=n},[n]),a.useEffect(()=>{const l=d=>{var u;(u=s.current)==null||u.call(s,{x:d.x,y:d.y,zoom:d.zoom})};return r.viewportListeners.add(l),()=>r.viewportListeners.delete(l)},[r])}function Ro({onChange:t}){const e=ft(),n=a.useRef(t);a.useEffect(()=>{n.current=t},[t]),a.useEffect(()=>{const r=s=>{var o;(o=n.current)==null||o.call(n,s)};return e.selectionListeners.add(r),()=>e.selectionListeners.delete(r)},[e])}function ko(t){const[e,n]=a.useState(!1),r=Array.isArray(t)?t:[t];return a.useEffect(()=>{const s=i=>{r.includes(i.key)&&n(!0)},o=i=>{r.includes(i.key)&&n(!1)};return window.addEventListener("keydown",s),window.addEventListener("keyup",o),()=>{window.removeEventListener("keydown",s),window.removeEventListener("keyup",o)}},[r.join(",")]),e}function Co(){const t=ft();return a.useCallback(e=>{var n;(n=t.workerRef.current)==null||n.postMessage({type:"nodes",data:{nodes:[...t.nodesRef.current]}})},[t])}function Eo(t={}){return ft().nodes.length>0}function zo(t){const e=ft();return a.useMemo(()=>e.nodes.find(n=>n.id===t)||void 0,[e.nodes,t])}function No(t){const e=ft();return typeof t=="function"?t(e):e}function Po(){const t=ft();return a.useMemo(()=>({getState:()=>t,setState:()=>{console.warn("[infinite-canvas] setState on storeApi is not supported. Use onNodesChange/onEdgesChange instead.")}}),[t])}const pn=160,mn=60;function Lo({width:t=200,height:e=150,nodeColor:n="#3b82f6",nodeStrokeColor:r="#fff",maskColor:s="rgba(0,0,0,0.1)",style:o={},className:i=""}){const l=ft(),d=a.useRef(null),u=a.useRef(null),x=a.useCallback(()=>{const b=d.current;if(!b)return;const L=b.getContext("2d"),E=window.devicePixelRatio||1;b.width=t*E,b.height=e*E,L.scale(E,E),L.clearRect(0,0,t,e);const k=l.nodesRef.current;if(!k.length)return;let T=1/0,C=1/0,z=-1/0,_=-1/0;for(const m of k){const B=m.width||pn,q=m.height||mn;m.position.x<T&&(T=m.position.x),m.position.y<C&&(C=m.position.y),m.position.x+B>z&&(z=m.position.x+B),m.position.y+q>_&&(_=m.position.y+q)}const j=40;T-=j,C-=j,z+=j,_+=j;const D=z-T,h=_-C,y=Math.min(t/D,e/h),p=(t-D*y)/2,R=(e-h*y)/2;for(const m of k){if(m.hidden)continue;const B=m.width||pn,q=m.height||mn,W=(m.position.x-T)*y+p,gt=(m.position.y-C)*y+R,K=B*y,nt=q*y;L.fillStyle=m.selected?"#f59e0b":typeof n=="function"?n(m):n,L.fillRect(W,gt,Math.max(K,2),Math.max(nt,2))}const w=l.cameraRef.current,P=l.wrapRef.current;if(P){const m=P.getBoundingClientRect(),B=-w.x/w.zoom,q=-w.y/w.zoom,W=m.width/w.zoom,gt=m.height/w.zoom;L.fillStyle=s,L.fillRect(0,0,t,e);const K=(B-T)*y+p,nt=(q-C)*y+R,U=W*y,G=gt*y;L.clearRect(K,nt,U,G);for(const rt of k){if(rt.hidden)continue;const ct=rt.width||pn,lt=rt.height||mn,ot=(rt.position.x-T)*y+p,Nt=(rt.position.y-C)*y+R;L.fillStyle=rt.selected?"#f59e0b":typeof n=="function"?n(rt):n,L.fillRect(ot,Nt,Math.max(ct*y,2),Math.max(lt*y,2))}L.strokeStyle="#3b82f6",L.lineWidth=1.5,L.strokeRect(K,nt,U,G)}},[l,t,e,n,r,s]);return a.useEffect(()=>{let b=!0;function L(){b&&(x(),u.current=requestAnimationFrame(L))}const E=setInterval(()=>{cancelAnimationFrame(u.current),u.current=requestAnimationFrame(L)},66);return x(),()=>{b=!1,clearInterval(E),cancelAnimationFrame(u.current)}},[x]),N.jsx("canvas",{ref:d,className:`ric-minimap ${i}`,style:{position:"absolute",bottom:30,right:10,width:t,height:e,borderRadius:4,border:"1px solid rgba(0,0,0,0.1)",background:"rgba(255,255,255,0.9)",pointerEvents:"none",...o}})}function Io(){return N.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),N.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function So(){return N.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:N.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function To(){return N.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:N.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}function $o(){return N.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),N.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function Bo(){return N.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),N.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})}function Ae({children:t,className:e="",...n}){return N.jsx("button",{className:`ric-controls-button ${e}`,style:Do,...n,children:t})}function jo({showZoom:t=!0,showFitView:e=!0,showInteractive:n=!1,fitViewOptions:r,onZoomIn:s,onZoomOut:o,onFitView:i,onInteractiveChange:l,position:d="bottom-left",orientation:u="vertical",style:x={},className:b="","aria-label":L="Canvas controls",children:E}){const k=ft(),{zoomIn:T,zoomOut:C,fitView:z,getZoom:_}=dr(),[j,D]=a.useState(!0),h=_()<=k.zoomMin,y=_()>=k.zoomMax,p=a.useCallback(()=>{T(),s==null||s()},[T,s]),R=a.useCallback(()=>{C(),o==null||o()},[C,o]),w=a.useCallback(()=>{z(r||{padding:.1}),i==null||i()},[z,r,i]),P=a.useCallback(()=>{const B=!j;D(B),l==null||l(B)},[j,l]),m={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:30,left:10},"bottom-right":{bottom:30,right:10},"bottom-center":{bottom:30,left:"50%",transform:"translateX(-50%)"}}[d]||{bottom:30,left:10};return N.jsxs("div",{className:`ric-controls ${b}`,style:{position:"absolute",display:"flex",flexDirection:u==="horizontal"?"row":"column",gap:2,zIndex:5,...m,...x},role:"toolbar","aria-label":L,children:[t&&N.jsxs(N.Fragment,{children:[N.jsx(Ae,{onClick:p,disabled:y,title:"Zoom in","aria-label":"Zoom in",className:"ric-controls-zoomin",children:N.jsx(Io,{})}),N.jsx(Ae,{onClick:R,disabled:h,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:N.jsx(So,{})})]}),e&&N.jsx(Ae,{onClick:w,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:N.jsx(To,{})}),n&&N.jsx(Ae,{onClick:P,title:j?"Lock interactivity":"Unlock interactivity","aria-label":j?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:j?N.jsx(Bo,{}):N.jsx($o,{})}),E]})}const Do={width:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid rgba(0,0,0,0.12)",borderRadius:4,background:"#fff",cursor:"pointer",fontSize:16,lineHeight:1,color:"#333",padding:0},Ao=a.memo(jo);function Ho({variant:t="lines",gap:e=40,size:n=1,color:r,style:s={},className:o=""}){const i=ft();return i.workerRef.current&&i.workerRef.current.postMessage({type:"background",data:{variant:t,gap:e,size:n,color:r}}),null}function _o({position:t="top-left",style:e={},className:n="",children:r}){const s={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:10,left:10},"bottom-right":{bottom:10,right:10},"bottom-center":{bottom:10,left:"50%",transform:"translateX(-50%)"}}[t]||{top:10,left:10};return N.jsx("div",{className:`ric-panel ${n}`,style:{position:"absolute",zIndex:5,pointerEvents:"all",...s,...e},onPointerDown:o=>o.stopPropagation(),children:r})}function Wo({minWidth:t=10,minHeight:e=10,maxWidth:n=1/0,maxHeight:r=1/0,isVisible:s=!0,handleStyle:o={},lineStyle:i={},color:l="#3b82f6",onResizeStart:d,onResize:u,onResizeEnd:x}){const b=a.useContext(_e),L=ft(),E=a.useRef(null),k=a.useCallback((z,_)=>{z.stopPropagation(),z.preventDefault();const j=L.nodesRef.current.find(y=>y.id===b);if(!j)return;E.current={direction:_,startX:z.clientX,startY:z.clientY,width:j.width||160,height:j.height||60},d==null||d(z,{width:E.current.width,height:E.current.height});const D=y=>{var q,W;if(!E.current)return;const p=E.current,R=L.cameraRef.current,w=(y.clientX-p.startX)/R.zoom,P=(y.clientY-p.startY)/R.zoom;let m=p.width,B=p.height;p.direction.includes("e")&&(m=Math.min(n,Math.max(t,p.width+w))),p.direction.includes("w")&&(m=Math.min(n,Math.max(t,p.width-w))),p.direction.includes("s")&&(B=Math.min(r,Math.max(e,p.height+P))),p.direction.includes("n")&&(B=Math.min(r,Math.max(e,p.height-P))),(W=(q=L.onNodesChangeRef).current)==null||W.call(q,[{id:b,type:"dimensions",dimensions:{width:m,height:B},setAttributes:!0}]),u==null||u(y,{width:m,height:B})},h=y=>{E.current=null,x==null||x(y,{}),window.removeEventListener("pointermove",D),window.removeEventListener("pointerup",h)};window.addEventListener("pointermove",D),window.addEventListener("pointerup",h)},[b,L,t,e,n,r,d,u,x]);if(!s)return null;const T=8,C={position:"absolute",width:T,height:T,background:l,border:"1px solid #fff",borderRadius:2,zIndex:20,...o};return N.jsxs(N.Fragment,{children:[N.jsx("div",{style:{...C,bottom:-T/2,right:-T/2,cursor:"nwse-resize"},onPointerDown:z=>k(z,"se")}),N.jsx("div",{style:{...C,bottom:-T/2,left:-T/2,cursor:"nesw-resize"},onPointerDown:z=>k(z,"sw")}),N.jsx("div",{style:{...C,top:-T/2,right:-T/2,cursor:"nesw-resize"},onPointerDown:z=>k(z,"ne")}),N.jsx("div",{style:{...C,top:-T/2,left:-T/2,cursor:"nwse-resize"},onPointerDown:z=>k(z,"nw")}),N.jsx("div",{style:{...C,top:"50%",right:-T/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:z=>k(z,"e")}),N.jsx("div",{style:{...C,top:"50%",left:-T/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:z=>k(z,"w")}),N.jsx("div",{style:{...C,left:"50%",top:-T/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:z=>k(z,"n")}),N.jsx("div",{style:{...C,left:"50%",bottom:-T/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:z=>k(z,"s")})]})}function Fo({isVisible:t,position:e="top",offset:n=10,align:r="center",children:s,style:o={},className:i=""}){const l=a.useContext(_e),u=ft().nodes.find(L=>L.id===l);if(!(t!==void 0?t:u==null?void 0:u.selected))return null;const b={top:{bottom:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginBottom:n},bottom:{top:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginTop:n},left:{right:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginRight:n},right:{left:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginLeft:n}}[e]||{};return N.jsx("div",{className:`ric-node-toolbar ${i}`,style:{position:"absolute",zIndex:1e3,pointerEvents:"all",...b,...o},onPointerDown:L=>L.stopPropagation(),children:s})}function Xo({isVisible:t=!1,x:e=0,y:n=0,alignX:r="center",alignY:s="center",children:o,style:i={},className:l=""}){if(!t)return null;const d=r==="center"?"-50%":r==="right"?"-100%":"0",u=s==="center"?"-50%":s==="bottom"?"-100%":"0";return N.jsx("div",{className:`ric-edge-toolbar ${l}`,style:{position:"absolute",left:e,top:n,transform:`translate(${d}, ${u})`,zIndex:1e3,pointerEvents:"all",...i},children:o})}function Yo({children:t}){var r;const n=(r=ft().edgeLabelContainerRef)==null?void 0:r.current;return n?Xn.createPortal(t,n):null}function Uo({children:t}){var r;const n=(r=ft().viewportPortalRef)==null?void 0:r.current;return n?Xn.createPortal(t,n):null}function fr({fromX:t,fromY:e,toX:n,toY:r,fromPosition:s="right",toPosition:o="left",connectionLineType:i="default",connectionLineStyle:l,connectionLineComponent:d}){if(d)return N.jsx(d,{fromX:t,fromY:e,toX:n,toY:r,fromPosition:s,toPosition:o});let u;switch(i){case"straight":[u]=kn({sourceX:t,sourceY:e,targetX:n,targetY:r});break;case"step":[u]=tn({sourceX:t,sourceY:e,targetX:n,targetY:r,sourcePosition:s,targetPosition:o,borderRadius:0});break;case"smoothstep":[u]=tn({sourceX:t,sourceY:e,targetX:n,targetY:r,sourcePosition:s,targetPosition:o});break;case"simplebezier":[u]=En({sourceX:t,sourceY:e,targetX:n,targetY:r});break;default:[u]=Cn({sourceX:t,sourceY:e,targetX:n,targetY:r,sourcePosition:s,targetPosition:o});break}return N.jsx("path",{d:u,fill:"none",className:"ric-connection-line",stroke:"#b1b1b7",strokeWidth:1.5,style:l})}fr.displayName="ConnectionLine";const qo=a.memo(fr),Go=Object.freeze({Top:"top",Bottom:"bottom",Left:"left",Right:"right"}),Oo=Object.freeze({Arrow:"arrow",ArrowClosed:"arrowclosed"});function Zo(t){const e=t.width||t.measured&&t.measured.width||0,n=t.height||t.measured&&t.measured.height||0,r=t._absolutePosition||t.position||{x:0,y:0};return{x:r.x,y:r.y,x2:r.x+e,y2:r.y+n}}exports.Background=Ho;exports.BaseEdge=We;exports.BezierEdge=Rn;exports.ConnectionLine=qo;exports.ControlButton=Ae;exports.Controls=Ao;exports.DefaultNode=Or;exports.EdgeLabelRenderer=Yo;exports.EdgeText=sr;exports.EdgeToolbar=Xo;exports.GroupNode=rr;exports.Handle=He;exports.InfiniteCanvas=co;exports.InfiniteCanvasProvider=lo;exports.InputNode=er;exports.MarkerType=Oo;exports.MiniMap=Lo;exports.NodeResizer=Wo;exports.NodeToolbar=Fo;exports.OutputNode=nr;exports.Panel=_o;exports.Position=Go;exports.SelectionBox=Jn;exports.SimpleBezierEdge=Ln;exports.SmoothStepEdge=Pn;exports.StepEdge=ar;exports.StraightEdge=Nn;exports.ViewportPortal=Uo;exports.addEdge=fo;exports.applyEdgeChanges=ur;exports.applyNodeChanges=lr;exports.boxToRect=Sr;exports.buildObstacles=zn;exports.clampPosition=bn;exports.computeRoutedEdges=oo;exports.getBezierEdgeCenter=Zr;exports.getBezierPath=Cn;exports.getBoundsOfBoxes=Tr;exports.getConnectedEdges=qn;exports.getEdgeCenter=Qr;exports.getIncomers=Nr;exports.getNodeDimensions=Mn;exports.getNodesBounds=Ve;exports.getNodesInside=Lr;exports.getOutgoers=Pr;exports.getOverlappingArea=$r;exports.getRoutedLabelPosition=an;exports.getSimpleBezierPath=En;exports.getSmoothStepPath=tn;exports.getStraightPath=kn;exports.getViewportForBounds=Je;exports.isEdge=zr;exports.isNode=Er;exports.nodeToBox=Zo;exports.nodeToRect=Br;exports.reconnectEdge=Kr;exports.rectToBox=Ir;exports.routeSinglePath=so;exports.routedPointsToPath=sn;exports.snapPosition=vn;exports.useConnection=mo;exports.useEdges=xo;exports.useEdgesState=yo;exports.useHandleConnections=wo;exports.useInfiniteCanvas=On;exports.useInternalNode=zo;exports.useKeyPress=ko;exports.useNodeConnections=bo;exports.useNodeId=_r;exports.useNodes=go;exports.useNodesData=vo;exports.useNodesInitialized=Eo;exports.useNodesState=ho;exports.useOnSelectionChange=Ro;exports.useOnViewportChange=Mo;exports.useReactFlow=dr;exports.useStore=No;exports.useStoreApi=Po;exports.useUpdateNodeInternals=Co;exports.useViewport=po;
|
|
867
|
+
`,nr=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",gr],{type:"text/javascript;charset=utf-8"});function Gr(e){let t;try{if(t=nr&&(self.URL||self.webkitURL).createObjectURL(nr),!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(gr),{type:"module",name:e==null?void 0:e.name})}}const Dn=new WeakMap;function Qr(e,t){if(Dn.has(e))return Dn.get(e);const n=e.transferControlToOffscreen(),r=new Gr;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 Dn.set(e,a),a}const ot=160,Ke=60,Vr=10;function xr({cards:e=[],nodes:t=[],edges:n=[],onHudUpdate:r,onNodesProcessed:a,onNodesChange:o,onEdgesChange:i,onConnect:h,onNodeClick:g,onNodeDragStart:d,onNodeDrag:y,onNodeDragStop:w,onEdgeClick:C,onEdgeDoubleClick:R,onEdgeMouseEnter:b,onEdgeMouseMove:B,onEdgeMouseLeave:S,onEdgeContextMenu:N,onNodeDoubleClick:X,onNodeMouseEnter:H,onNodeMouseMove:_,onNodeMouseLeave:j,onNodeContextMenu:$,onPaneClick:A,onPaneContextMenu:W,onPaneMouseEnter:F,onPaneMouseMove:m,onPaneMouseLeave:f,onSelectionChange:M,onConnectStart:L,onConnectEnd:T,onInit:Y,onMoveStart:J,onMove:oe,onMoveEnd:V,onDelete:ee,onBeforeDelete:he,onError:ne,isValidConnection:ce,dark:ue,gridSize:Ie=40,zoomMin:le=.1,zoomMax:me=4,initialCamera:Le={x:0,y:0,zoom:1},fitView:ve=!1,fitViewOptions:Re,nodesDraggable:Pe=!0,nodesConnectable:Ee=!0,elementsSelectable:xe=!0,multiSelectionKeyCode:ae="Shift",selectionOnDrag:Fe=!1,selectionMode:bt="partial",connectionMode:Ae="loose",connectionRadius:et=20,connectOnClick:Ve=!1,snapToGrid:Rt=!1,snapGrid:wt=[15,15],deleteKeyCode:kt=["Delete","Backspace"],panActivationKeyCode:Ct=" ",panOnScroll:tn=!1,panOnScrollMode:Tt="free",panOnScrollSpeed:nn=.5,zoomOnScroll:rn=!0,zoomOnDoubleClick:on=!0,zoomOnPinch:sn=!0,preventScrolling:$t=!0,translateExtent:ct,nodeExtent:ut,defaultEdgeOptions:Et={},autoPanOnNodeDrag:Mn=!0,autoPanOnConnect:Rn=!0,autoPanSpeed:tt=5,edgesReconnectable:er=!1,elevateNodesOnSelect:kn=!1,elevateEdgesOnSelect:Cn=!1,noDragClassName:zt="nodrag",noPanClassName:St="nopan",onSelectionDragStart:En,onSelectionDrag:zn,onSelectionDragStop:Sn,edgeRouting:lt=!0}={}){const ge=u.useRef(null),Bt=u.useRef(null),ze=u.useRef(null),ie=u.useRef({...Le}),dt=u.useRef([...e]),K=u.useRef([...t]),ke=u.useRef([...n]),an=u.useRef(new Map),st=u.useRef(!1),Nt=u.useRef(null),[Nn,Pn]=u.useState(!1),He=u.useRef(null),Xe=u.useRef(null),jt=u.useRef(null),De=u.useRef(null),At=u.useRef(!1),Mt=u.useRef(null),[Dt,In]=u.useState({x:Le.x,y:Le.y,zoom:Le.zoom}),[ft,ht]=u.useState(null),at=u.useMemo(()=>new Set,[]),Ze=u.useMemo(()=>new Set,[]),Pt=u.useRef(!1),Z=u.useRef({});Z.current={onHudUpdate:r,onNodesProcessed:a,onNodesChange:o,onEdgesChange:i,onConnect:h,onNodeClick:g,onNodeDragStart:d,onNodeDrag:y,onNodeDragStop:w,onEdgeClick:C,onEdgeDoubleClick:R,onEdgeMouseEnter:b,onEdgeMouseMove:B,onEdgeMouseLeave:S,onEdgeContextMenu:N,onNodeDoubleClick:X,onNodeMouseEnter:H,onNodeMouseMove:_,onNodeMouseLeave:j,onNodeContextMenu:$,onPaneClick:A,onPaneContextMenu:W,onPaneMouseEnter:F,onPaneMouseMove:m,onPaneMouseLeave:f,onSelectionChange:M,onConnectStart:L,onConnectEnd:T,onInit:Y,onMoveStart:J,onMove:oe,onMoveEnd:V,onDelete:ee,onBeforeDelete:he,onError:ne,onSelectionDragStart:En,onSelectionDrag:zn,onSelectionDragStop:Sn,isValidConnection:ce};const yt={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}},Xt={get current(){return Z.current.onEdgeClick}},Yt={get current(){return Z.current.onPaneClick}},we={get current(){return Z.current.onSelectionChange}},gt={get current(){return Z.current.onHudUpdate}},It={get current(){return Z.current.onNodesProcessed}};u.useEffect(()=>{const l=c=>{c.key===ae&&(At.current=!0),c.key===Ct&&(Pt.current=!0)},v=c=>{c.key===ae&&(At.current=!1),c.key===Ct&&(Pt.current=!1)};return window.addEventListener("keydown",l),window.addEventListener("keyup",v),()=>{window.removeEventListener("keydown",l),window.removeEventListener("keyup",v)}},[ae,Ct]);const Se={get current(){const l=Z.current.onNodesChange;return l?v=>{var x;l(v);const c=[];for(let k=0;k<v.length;k++)v[k].type==="select"&&c.push({id:v[k].id,selected:v[k].selected});c.length>0&&((x=ze.current)==null||x.postMessage({type:"nodeSelections",data:{selections:c}}))}:null}},Te={get current(){const l=Z.current.onEdgesChange;return l?v=>{var x;l(v);const c=[];for(let k=0;k<v.length;k++)v[k].type==="select"&&c.push({id:v[k].id,selected:v[k].selected});c.length>0&&((x=ze.current)==null||x.postMessage({type:"edgeSelections",data:{selections:c}}))}:null}},nt=u.useCallback(()=>{var x;const l=K.current.filter(k=>k.selected),v=ke.current.filter(k=>k.selected),c={nodes:l,edges:v};(x=we.current)==null||x.call(we,c);for(const k of Ze)k(c)},[Ze]);u.useEffect(()=>{var l;dt.current=[...e],(l=ze.current)==null||l.postMessage({type:"cards",data:{cards:[...e]}})},[e]);const xt=u.useCallback(l=>{const v={};for(const c of l)v[c.id]=c;return l.map(c=>{if(!c.parentId)return c;const x=v[c.parentId];if(!x)return c;let k=c.position.x,I=c.position.y,p=x;for(;p;)k+=p.position.x,I+=p.position.y,p=p.parentId?v[p.parentId]:null;return{...c,_absolutePosition:{x:k,y:I}}})},[]),Ge=u.useRef([]),rt=u.useCallback(l=>{const v=an.current;if(!v||v.size===0)return l;const c={};for(const[,x]of v)c[x.nodeId]||(c[x.nodeId]=[]),c[x.nodeId].push({id:x.id,type:x.type,position:x.position,x:x.x,y:x.y});return l.map(x=>{const k=c[x.id];return k&&k.length>0?{...x,handles:k}:x})},[]),cn=u.useCallback(()=>{var v;if(He.current)return;const l=rt(Ge.current);(v=ze.current)==null||v.postMessage({type:"nodes",data:{nodes:l}})},[rt]);u.useEffect(()=>{var c;if(He.current){const x=He.current.id,k=new Set([x,...He.current.selectedStarts.map(p=>p.id)]),I={};for(const p of K.current)k.has(p.id)&&(I[p.id]={...p.position});K.current=[...t];for(const p of K.current)I[p.id]&&(p.position=I[p.id]);Ge.current=xt(K.current);return}K.current=[...t];const l=xt(t);Ge.current=l;const v=rt(l);(c=ze.current)==null||c.postMessage({type:"nodes",data:{nodes:v}})},[t,xt,rt]),u.useEffect(()=>{var l;ke.current=[...n],(l=ze.current)==null||l.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const Ne=u.useCallback((l,v)=>{const c=ge.current;if(!c)return{x:0,y:0};const x=c.getBoundingClientRect(),k=ie.current;return{x:(l-x.left-k.x)/k.zoom,y:(v-x.top-k.y)/k.zoom}},[]),Je=u.useCallback((l,v)=>{const c=Ge.current.length>0?Ge.current:K.current;let x=null;for(let k=c.length-1;k>=0;k--){const I=c[k];if(I.hidden)continue;const p=I._absolutePosition||I.position,P=I.width||ot,z=I.height||Ke;if(l>=p.x&&l<=p.x+P&&v>=p.y&&v<=p.y+z){if(I.type==="group"){x||(x=I);continue}return I}}return x},[]),un=u.useCallback((l,v)=>{const c=v.width||ot,x=v.height||Ke;if(l.x!==void 0&&l.y!==void 0)return{x:v.position.x+l.x,y:v.position.y+l.y};switch(l.position||(l.type==="source"?"right":"left")){case"top":return{x:v.position.x+c/2,y:v.position.y};case"bottom":return{x:v.position.x+c/2,y:v.position.y+x};case"left":return{x:v.position.x,y:v.position.y+x/2};case"right":return{x:v.position.x+c,y:v.position.y+x/2};default:return{x:v.position.x+c,y:v.position.y+x/2}}},[]),Q=u.useCallback(l=>{const v=l.width||ot,c=l.height||Ke;if(l.handles&&l.handles.length>0)return l.handles.map(z=>{const q=un(z,l);return{id:z.id||null,type:z.type,x:q.x,y:q.y}});const x=l.targetPosition||"left",k=l.sourcePosition||"right",I=z=>{switch(z){case"top":return{x:l.position.x+v/2,y:l.position.y};case"bottom":return{x:l.position.x+v/2,y:l.position.y+c};case"left":return{x:l.position.x,y:l.position.y+c/2};case"right":return{x:l.position.x+v,y:l.position.y+c/2};default:return{x:l.position.x+v,y:l.position.y+c/2}}},p=I(x),P=I(k);return[{id:null,type:"target",x:p.x,y:p.y},{id:null,type:"source",x:P.x,y:P.y}]},[un]),$e=u.useCallback((l,v)=>{const c=K.current,x=ie.current,k=Math.max(Vr,et)/x.zoom;for(let I=c.length-1;I>=0;I--){const p=c[I];if(p.hidden)continue;const P=Q(p);for(const z of P)if(Math.abs(l-z.x)<k&&Math.abs(v-z.y)<k)return{nodeId:p.id,handleId:z.id,type:z.type,x:z.x,y:z.y}}return null},[Q]),pe=u.useCallback((l,v)=>{const x=8/ie.current.zoom;for(let k=ke.current.length-1;k>=0;k--){const I=ke.current[k],p=K.current.find(se=>se.id===I.source),P=K.current.find(se=>se.id===I.target);if(!p||!P)continue;const z=p.width||ot,q=p.height||Ke,D=P.height||Ke,O=p.position.x+z,G=p.position.y+q/2,be=P.position.x,Be=P.position.y+D/2;if(Jr(l,v,O,G,be,Be)<x)return I}return null},[]);u.useEffect(()=>{const l=Bt.current,v=ge.current;if(!l||!v)return;const c=v.getBoundingClientRect(),x=ue!==void 0?ue:matchMedia("(prefers-color-scheme: dark)").matches,k=xt(K.current);Ge.current=k;const I=rt(k),{worker:p}=Qr(l,{width:c.width,height:c.height,camera:ie.current,cards:dt.current,nodes:I,edges:ke.current,dark:x,gridSize:Ie,edgeRouting:lt});p.onmessage=D=>{var O,G,be,Be;D.data.type==="hud"&&((O=gt.current)==null||O.call(gt,D.data.data)),D.data.type==="ready"&&Pn(!0),D.data.type==="nodesProcessed"&&((G=It.current)==null||G.call(It,D.data.data)),D.data.type==="error"&&((Be=(be=Z.current).onError)==null||Be.call(be,"worker-error",D.data.message||"Canvas worker error"))},p.onerror=D=>{var O,G;(G=(O=Z.current).onError)==null||G.call(O,"worker-error",D.message||"Canvas worker crashed")},ze.current=p;const P=new ResizeObserver(D=>{const{width:O,height:G}=D[0].contentRect;p.postMessage({type:"resize",data:{width:O,height:G}})});P.observe(v);let z,q;return ue===void 0&&(z=matchMedia("(prefers-color-scheme: dark)"),q=D=>p.postMessage({type:"theme",data:{dark:D.matches}}),z.addEventListener("change",q)),()=>{P.disconnect(),z&&q&&z.removeEventListener("change",q),ze.current=null}},[]),u.useEffect(()=>{var l;ue!==void 0&&((l=ze.current)==null||l.postMessage({type:"theme",data:{dark:ue}}))},[ue]),u.useEffect(()=>{var l;(l=ze.current)==null||l.postMessage({type:"edgeRouting",data:{enabled:lt}})},[lt]);const Qe=u.useRef(0),fe=u.useCallback((l=null)=>{var x,k,I;const v=ie.current;if(ct){const p=ge.current;if(p){const P=p.getBoundingClientRect(),z=-ct[1][0]*v.zoom+P.width,q=-ct[1][1]*v.zoom+P.height,D=-ct[0][0]*v.zoom,O=-ct[0][1]*v.zoom;v.x=Math.min(D,Math.max(z,v.x)),v.y=Math.min(O,Math.max(q,v.y))}}(x=ze.current)==null||x.postMessage({type:"camera",data:{camera:{...v}}});const c={x:v.x,y:v.y,zoom:v.zoom};(I=(k=Z.current).onMove)==null||I.call(k,l,c);for(const p of at)p(c);cancelAnimationFrame(Qe.current),Qe.current=requestAnimationFrame(()=>{In({x:v.x,y:v.y,zoom:v.zoom})})},[at,ct]),_e=u.useCallback(()=>{var c,x;const l=Xe.current,v=jt.current;l&&v?((c=ze.current)==null||c.postMessage({type:"connecting",data:{from:l.startPos,to:v,_routedPoints:null}}),ht({source:l.sourceId,sourceHandle:l.sourceHandle,target:null,targetHandle:null})):((x=ze.current)==null||x.postMessage({type:"connecting",data:null}),ht(null))},[]),pt=u.useCallback(()=>{var v,c;const l=De.current;l?(v=ze.current)==null||v.postMessage({type:"selectionBox",data:l}):(c=ze.current)==null||c.postMessage({type:"selectionBox",data:null})},[]),Ln=u.useCallback(l=>{var p,P,z,q,D,O,G,be,Be,te,se,Ce,je,We,qe,Ue,Ut,it;const v=K.current.length>0,c=Ne(l.clientX,l.clientY),x=At.current;if(v&&Ee&&!x){const U=$e(c.x,c.y);if(Ve&&Mt.current&&U){const re=Mt.current;if(U.nodeId!==re.nodeId){const Oe=re.handleType==="target"?{source:U.nodeId,target:re.nodeId,sourceHandle:U.handleId||null,targetHandle:re.handleId}:{source:re.nodeId,target:U.nodeId,sourceHandle:re.handleId,targetHandle:U.handleId||null};(Z.current.isValidConnection?Z.current.isValidConnection(Oe):!0)&&((p=yt.current)==null||p.call(yt,{...Oe,...Et}))}Mt.current=null;return}if(Ae==="strict"?U&&U.type==="source":U!=null){if(Ve){Mt.current={nodeId:U.nodeId,handleId:U.handleId||null,handleType:U.type},(z=(P=Z.current).onConnectStart)==null||z.call(P,l,{nodeId:U.nodeId,handleId:U.handleId,handleType:U.type});return}Xe.current={sourceId:U.nodeId,sourceHandle:U.handleId||null,sourceType:U.type,startPos:{x:U.x,y:U.y}},jt.current={x:c.x,y:c.y},(q=ge.current)==null||q.setPointerCapture(l.pointerId),(O=(D=Z.current).onConnectStart)==null||O.call(D,l,{nodeId:U.nodeId,handleId:U.handleId,handleType:U.type}),_e();return}}const k=U=>{var re;let ye=U;for(;ye&&ye!==ge.current;){if((re=ye.classList)!=null&&re.contains(zt))return!0;ye=ye.parentElement}return!1},I=U=>{var re;let ye=U;for(;ye&&ye!==ge.current;){if((re=ye.classList)!=null&&re.contains(St))return!0;ye=ye.parentElement}return!1};if(v){const U=Je(c.x,c.y);if(U){if(Se.current&&xe){const ye=[];if(x)ye.push({id:U.id,type:"select",selected:!U.selected});else if(!U.selected){for(const re of K.current)re.id===U.id?ye.push({id:re.id,type:"select",selected:!0}):re.selected&&ye.push({id:re.id,type:"select",selected:!1});if(Te.current){const re=ke.current.filter(de=>de.selected).map(de=>({id:de.id,type:"select",selected:!1}));re.length&&Te.current(re)}}if(ye.length){if(Se.current(ye),kn&&!x){const re=K.current.findIndex(de=>de.id===U.id);re>=0&&re<K.current.length-1&&Se.current([{id:U.id,type:"remove"},{type:"add",item:{...K.current[re],selected:!0}}])}nt()}}if((G=Ht.current)==null||G.call(Ht,l,U),Pe&&!k(l.target)){const ye=U.selected;let re=null;if(U.parentId&&U.extent==="parent"){const de=K.current.find(Oe=>Oe.id===U.parentId);if(de){const Oe=de.width||ot,qt=de.height||Ke,fn=U.width||((be=U.measured)==null?void 0:be.width)||ot,Ot=U.height||((Be=U.measured)==null?void 0:Be.height)||Ke;re={minX:0,minY:0,maxX:Oe-fn,maxY:qt-Ot}}}if(He.current={id:U.id,startPos:{...U.position},startMouse:{x:c.x,y:c.y},parentClamp:re,parentId:U.parentId||null,selectedStarts:ye?K.current.filter(de=>de.selected&&de.id!==U.id).map(de=>{var qt,fn;let Oe=null;if(de.parentId&&de.extent==="parent"){const Ot=K.current.find(An=>An.id===de.parentId);if(Ot){const An=Ot.width||ot,jr=Ot.height||Ke,Ar=de.width||((qt=de.measured)==null?void 0:qt.width)||ot,Dr=de.height||((fn=de.measured)==null?void 0:fn.height)||Ke;Oe={minX:0,minY:0,maxX:An-Ar,maxY:jr-Dr}}}return{id:de.id,startPos:{...de.position},parentClamp:Oe,parentId:de.parentId||null}}):[]},(te=ge.current)==null||te.setPointerCapture(l.pointerId),(se=_t.current)==null||se.call(_t,l,U),He.current.selectedStarts.length>0){const de=K.current.filter(Oe=>Oe.selected);(je=(Ce=Z.current).onSelectionDragStart)==null||je.call(Ce,l,de)}if(Se.current){const de=[{id:U.id,type:"position",dragging:!0}];for(const Oe of He.current.selectedStarts)de.push({id:Oe.id,type:"position",dragging:!0});Se.current(de)}}return}}if(ke.current.length>0&&xe){const U=pe(c.x,c.y);if(U){if(Te.current){const ye=[];if(x)ye.push({id:U.id,type:"select",selected:!U.selected});else{for(const re of ke.current)re.id===U.id?ye.push({id:re.id,type:"select",selected:!0}):re.selected&&ye.push({id:re.id,type:"select",selected:!1});if(Se.current){const re=K.current.filter(de=>de.selected).map(de=>({id:de.id,type:"select",selected:!1}));re.length&&Se.current(re)}}if(ye.length){if(Te.current(ye),Cn&&!x){const re=ke.current.findIndex(de=>de.id===U.id);re>=0&&re<ke.current.length-1&&Te.current([{id:U.id,type:"remove"},{type:"add",item:{...ke.current[re],selected:!0}}])}nt()}}(We=Xt.current)==null||We.call(Xt,l,U);return}}if(!x){const U=K.current.filter(re=>re.selected).map(re=>({id:re.id,type:"select",selected:!1})),ye=ke.current.filter(re=>re.selected).map(re=>({id:re.id,type:"select",selected:!1}));U.length&&Se.current&&Se.current(U),ye.length&&Te.current&&Te.current(ye),(U.length||ye.length)&&nt()}if((qe=Yt.current)==null||qe.call(Yt,l),Fe||x){De.current={startWorld:{...c},endWorld:{...c}},(Ue=ge.current)==null||Ue.setPointerCapture(l.pointerId),pt();return}I(l.target)||(st.current=!0,Nt.current={x:l.clientX,y:l.clientY},(Ut=ge.current)==null||Ut.classList.add("dragging"),(it=ge.current)==null||it.setPointerCapture(l.pointerId))},[Ne,Je,$e,pe,Pe,Ee,xe,Fe,_e,pt,nt,zt,St]),Tn=u.useCallback(l=>{var c,x,k,I;if(Xe.current){if(jt.current=Ne(l.clientX,l.clientY),_e(),Rn){const p=ge.current;if(p){const P=p.getBoundingClientRect(),z=40,q=l.clientX-P.left,D=l.clientY-P.top;let O=0,G=0;q<z?O=tt:q>P.width-z&&(O=-tt),D<z?G=tt:D>P.height-z&&(G=-tt),(O||G)&&(ie.current.x+=O,ie.current.y+=G,fe(l))}}return}if(De.current){De.current.endWorld=Ne(l.clientX,l.clientY),pt();const p=De.current,P=Math.min(p.startWorld.x,p.endWorld.x),z=Math.min(p.startWorld.y,p.endWorld.y),q=Math.max(p.startWorld.x,p.endWorld.x),D=Math.max(p.startWorld.y,p.endWorld.y);if(Se.current){const O=[];for(const G of K.current){if(G.hidden)continue;const be=G.width||ot,Be=G.height||Ke,te=bt==="full"?G.position.x>=P&&G.position.x+be<=q&&G.position.y>=z&&G.position.y+Be<=D:G.position.x+be>P&&G.position.x<q&&G.position.y+Be>z&&G.position.y<D;te!==!!G.selected&&O.push({id:G.id,type:"select",selected:te})}O.length&&Se.current(O)}return}if(He.current){const p=Ne(l.clientX,l.clientY),P=He.current,z=p.x-P.startMouse.x,q=p.y-P.startMouse.y;let D={x:P.startPos.x+z,y:P.startPos.y+q};if(Rt&&(D=Fn(D,wt)),ut&&(D=Xn(D,ut)),P.parentClamp){const te=P.parentClamp;D={x:Math.max(te.minX,Math.min(D.x,te.maxX)),y:Math.max(te.minY,Math.min(D.y,te.maxY))}}const O=[{id:P.id,position:D}];for(const te of P.selectedStarts){let se={x:te.startPos.x+z,y:te.startPos.y+q};if(Rt&&(se=Fn(se,wt)),ut&&(se=Xn(se,ut)),te.parentClamp){const Ce=te.parentClamp;se={x:Math.max(Ce.minX,Math.min(se.x,Ce.maxX)),y:Math.max(Ce.minY,Math.min(se.y,Ce.maxY))}}O.push({id:te.id,position:se})}const G=[];for(const te of O){const se=K.current.find(Ce=>Ce.id===te.id);if(se){se.position=te.position,se.dragging=!0;let Ce=te.position;if(se.parentId){let je=K.current.find(Ue=>Ue.id===se.parentId),We=te.position.x,qe=te.position.y;for(;je;)We+=je.position.x,qe+=je.position.y,je=je.parentId?K.current.find(Ue=>Ue.id===je.parentId):null;Ce={x:We,y:qe}}G.push({id:te.id,position:te.position,_absolutePosition:Ce,width:se.width,height:se.height,dragging:!0,selected:se.selected})}}const be=new Set(O.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(We=>We.id===te.parentId),Ce=te.position.x,je=te.position.y;for(;se;)Ce+=se.position.x,je+=se.position.y,se=se.parentId?K.current.find(We=>We.id===se.parentId):null;G.push({id:te.id,position:te.position,_absolutePosition:{x:Ce,y:je},width:te.width,height:te.height,dragging:!1,selected:te.selected})}if((c=ze.current)==null||c.postMessage({type:"nodePositions",data:{updates:G}}),Mn){const te=ge.current;if(te){const se=te.getBoundingClientRect(),Ce=40,je=l.clientX-se.left,We=l.clientY-se.top;let qe=0,Ue=0;je<Ce?qe=tt:je>se.width-Ce&&(qe=-tt),We<Ce?Ue=tt:We>se.height-Ce&&(Ue=-tt),(qe||Ue)&&(ie.current.x+=qe,ie.current.y+=Ue,fe(l))}}const Be=K.current.find(te=>te.id===P.id);if(Be&&((x=Wt.current)==null||x.call(Wt,l,Be)),P.selectedStarts.length>0){const te=K.current.filter(se=>se.selected);(I=(k=Z.current).onSelectionDrag)==null||I.call(k,l,te)}return}if(!st.current)return;const v=ie.current;v.x+=l.clientX-Nt.current.x,v.y+=l.clientY-Nt.current.y,Nt.current={x:l.clientX,y:l.clientY},fe()},[fe,Ne,_e,pt]),$n=u.useCallback(l=>{var v,c,x,k,I,p,P;if(Xe.current){const z=Ne(l.clientX,l.clientY),q=$e(z.x,z.y);if(q&&q.nodeId!==Xe.current.sourceId&&(Ae==="loose"||q.type==="target")){const G=Xe.current.sourceType==="target"?{source:q.nodeId,target:Xe.current.sourceId,sourceHandle:q.handleId||null,targetHandle:Xe.current.sourceHandle}:{source:Xe.current.sourceId,target:q.nodeId,sourceHandle:Xe.current.sourceHandle,targetHandle:q.handleId||null};(Z.current.isValidConnection?Z.current.isValidConnection(G):!0)&&((v=yt.current)==null||v.call(yt,{...G,...Et}))}(x=(c=Z.current).onConnectEnd)==null||x.call(c,l.nativeEvent||l),Xe.current=null,jt.current=null,_e();return}if(De.current){De.current=null,pt(),nt();return}if(He.current){const z=He.current;if(Se.current){const D=K.current.find(G=>G.id===z.id),O=[{id:z.id,type:"position",position:D?{...D.position}:void 0,dragging:!1}];for(const G of z.selectedStarts){const be=K.current.find(Be=>Be.id===G.id);O.push({id:G.id,type:"position",position:be?{...be.position}:void 0,dragging:!1})}Se.current(O)}if(z.selectedStarts.length>0){const D=K.current.filter(O=>O.selected);(I=(k=Z.current).onSelectionDragStop)==null||I.call(k,l,D)}requestAnimationFrame(()=>{var O;He.current=null;const D=rt(Ge.current);(O=ze.current)==null||O.postMessage({type:"nodes",data:{nodes:D}})});const q=K.current.find(D=>D.id===z.id);q&&((p=Ft.current)==null||p.call(Ft,l,q));return}st.current=!1,(P=ge.current)==null||P.classList.remove("dragging")},[Ne,$e,_e,pt,nt]);u.useEffect(()=>{const l=ge.current;if(!l)return;const v=c=>{$t&&c.preventDefault();const x=ie.current;if(tn||Pt.current){const z=nn;Tt==="horizontal"?x.x-=c.deltaY*z:(Tt==="vertical"||(x.x-=c.deltaX*z),x.y-=c.deltaY*z),fe(c);return}if(!rn)return;const k=c.deltaY>0?.92:1.08,I=l.getBoundingClientRect(),p=c.clientX-I.left,P=c.clientY-I.top;x.x=p-(p-x.x)*k,x.y=P-(P-x.y)*k,x.zoom=Math.min(me,Math.max(le,x.zoom*k)),fe(c)};return l.addEventListener("wheel",v,{passive:!$t}),()=>l.removeEventListener("wheel",v)},[fe,le,me,tn,Tt,nn,rn,$t]),u.useEffect(()=>{if(!sn)return;const l=ge.current;if(!l)return;let v=0,c=null;const x=p=>{if(p.touches.length===2){const P=p.touches[0].clientX-p.touches[1].clientX,z=p.touches[0].clientY-p.touches[1].clientY;v=Math.hypot(P,z);const q=l.getBoundingClientRect();c={x:(p.touches[0].clientX+p.touches[1].clientX)/2-q.left,y:(p.touches[0].clientY+p.touches[1].clientY)/2-q.top},p.preventDefault()}},k=p=>{if(p.touches.length===2&&v>0){p.preventDefault();const P=p.touches[0].clientX-p.touches[1].clientX,z=p.touches[0].clientY-p.touches[1].clientY,q=Math.hypot(P,z),D=q/v;v=q;const O=ie.current,G=c.x,be=c.y;O.x=G-(G-O.x)*D,O.y=be-(be-O.y)*D,O.zoom=Math.min(me,Math.max(le,O.zoom*D)),fe(p)}},I=()=>{v=0,c=null};return l.addEventListener("touchstart",x,{passive:!1}),l.addEventListener("touchmove",k,{passive:!1}),l.addEventListener("touchend",I),()=>{l.removeEventListener("touchstart",x),l.removeEventListener("touchmove",k),l.removeEventListener("touchend",I)}},[sn,fe,le,me]),u.useEffect(()=>{if(!on)return;const l=ge.current;if(!l)return;const v=c=>{var D,O,G,be;const x=Ne(c.clientX,c.clientY);if(Je(x.x,x.y)){(O=(D=Z.current).onNodeDoubleClick)==null||O.call(D,c,Je(x.x,x.y));return}const k=pe(x.x,x.y);if(k){(be=(G=Z.current).onEdgeDoubleClick)==null||be.call(G,c,k);return}const I=1.5,p=l.getBoundingClientRect(),P=c.clientX-p.left,z=c.clientY-p.top,q=ie.current;q.x=P-(P-q.x)*I,q.y=z-(z-q.y)*I,q.zoom=Math.min(me,Math.max(le,q.zoom*I)),fe(c)};return l.addEventListener("dblclick",v),()=>l.removeEventListener("dblclick",v)},[on,fe,le,me,Ne,Je,pe]),u.useEffect(()=>{const l=ge.current;if(!l)return;const v=c=>{var p,P,z,q,D,O;const x=Ne(c.clientX,c.clientY),k=Je(x.x,x.y);if(k){(P=(p=Z.current).onNodeContextMenu)==null||P.call(p,c,k);return}const I=pe(x.x,x.y);if(I){(q=(z=Z.current).onEdgeContextMenu)==null||q.call(z,c,I);return}(O=(D=Z.current).onPaneContextMenu)==null||O.call(D,c)};return l.addEventListener("contextmenu",v),()=>l.removeEventListener("contextmenu",v)},[Ne,Je,pe]),u.useEffect(()=>{const l=ge.current;if(!l)return;let v=null,c=null;const x=p=>{var q,D,O,G,be,Be,te,se,Ce,je,We,qe,Ue,Ut;if((D=(q=Z.current).onPaneMouseMove)==null||D.call(q,p),st.current||He.current||Xe.current||De.current)return;const P=Ne(p.clientX,p.clientY),z=Je(P.x,P.y);if(z!==v&&(v&&((G=(O=Z.current).onNodeMouseLeave)==null||G.call(O,p,v)),z&&((Be=(be=Z.current).onNodeMouseEnter)==null||Be.call(be,p,z)),v=z),z&&((se=(te=Z.current).onNodeMouseMove)==null||se.call(te,p,z)),!z){const it=pe(P.x,P.y);it!==c&&(c&&((je=(Ce=Z.current).onEdgeMouseLeave)==null||je.call(Ce,p,c)),it&&((qe=(We=Z.current).onEdgeMouseEnter)==null||qe.call(We,p,it)),c=it),it&&((Ut=(Ue=Z.current).onEdgeMouseMove)==null||Ut.call(Ue,p,it))}},k=p=>{var P,z;return(z=(P=Z.current).onPaneMouseEnter)==null?void 0:z.call(P,p)},I=p=>{var P,z,q,D,O,G;(z=(P=Z.current).onPaneMouseLeave)==null||z.call(P,p),v&&((D=(q=Z.current).onNodeMouseLeave)==null||D.call(q,p,v),v=null),c&&((G=(O=Z.current).onEdgeMouseLeave)==null||G.call(O,p,c),c=null)};return l.addEventListener("mousemove",x),l.addEventListener("mouseenter",k),l.addEventListener("mouseleave",I),()=>{l.removeEventListener("mousemove",x),l.removeEventListener("mouseenter",k),l.removeEventListener("mouseleave",I)}},[Ne,Je,pe]),u.useEffect(()=>{const l=Array.isArray(kt)?kt:[kt],v=async c=>{var x,k,I,p;if(l.includes(c.key)){if(c.target.tagName==="INPUT"||c.target.tagName==="TEXTAREA"||c.target.isContentEditable)return;const P=K.current.filter(D=>D.selected),z=ke.current.filter(D=>D.selected);if(!P.length&&!z.length)return;if(Z.current.onBeforeDelete)try{if(!await Z.current.onBeforeDelete({nodes:P,edges:z}))return}catch(D){(k=(x=Z.current).onError)==null||k.call(x,"before-delete-error",D.message||"onBeforeDelete threw an error");return}const q=new Set(P.map(D=>D.id));if(P.length&&Se.current&&(Se.current(P.map(D=>({id:D.id,type:"remove"}))),Te.current)){const D=ke.current.filter(O=>q.has(O.source)||q.has(O.target));D.length&&Te.current(D.map(O=>({id:O.id,type:"remove"})))}z.length&&Te.current&&Te.current(z.map(D=>({id:D.id,type:"remove"}))),(p=(I=Z.current).onDelete)==null||p.call(I,{nodes:P,edges:z})}if((c.ctrlKey||c.metaKey)&&c.key==="a"){if(c.target.tagName==="INPUT"||c.target.tagName==="TEXTAREA")return;if(c.preventDefault(),Se.current){const P=K.current.filter(z=>!z.selected).map(z=>({id:z.id,type:"select",selected:!0}));P.length&&Se.current(P)}if(Te.current){const P=ke.current.filter(z=>!z.selected).map(z=>({id:z.id,type:"select",selected:!0}));P.length&&Te.current(P)}}};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[kt]);const mt=u.useRef(!1);u.useEffect(()=>{var l,v;if(!mt.current&&ze.current){if(mt.current=!0,ve&&K.current.length>0){const c=ge.current;if(c){const x=c.getBoundingClientRect(),k=(Re==null?void 0:Re.padding)??.1,I=yn(K.current),p=Lt(I,x.width,x.height,k);Re!=null&&Re.maxZoom&&(p.zoom=Math.min(p.zoom,Re.maxZoom)),Re!=null&&Re.minZoom&&(p.zoom=Math.max(p.zoom,Re.minZoom)),ie.current=p,fe()}}(v=(l=Z.current).onInit)==null||v.call(l,{getNodes:()=>[...K.current],getEdges:()=>[...ke.current],getNode:c=>K.current.find(x=>x.id===c),getEdge:c=>ke.current.find(x=>x.id===c),getViewport:()=>({...ie.current}),getZoom:()=>ie.current.zoom,setViewport:c=>{ie.current={x:c.x??ie.current.x,y:c.y??ie.current.y,zoom:c.zoom??ie.current.zoom},fe()},fitView:(c={})=>{const x=ge.current;if(!x||!K.current.length)return;const k=x.getBoundingClientRect(),I=c.nodes?K.current.filter(z=>c.nodes.some(q=>q.id===z.id)):K.current;if(!I.length)return;const p=yn(I),P=Lt(p,k.width,k.height,c.padding??.1);c.maxZoom&&(P.zoom=Math.min(P.zoom,c.maxZoom)),c.minZoom&&(P.zoom=Math.max(P.zoom,c.minZoom)),ie.current=P,fe()},screenToFlowPosition:c=>Ne(c.x,c.y),flowToScreenPosition:c=>{const x=ie.current,k=ge.current;if(!k)return{x:0,y:0};const I=k.getBoundingClientRect();return{x:c.x*x.zoom+x.x+I.left,y:c.y*x.zoom+x.y+I.top}},zoomIn:()=>{const c=ie.current;c.zoom=Math.min(me,c.zoom*1.2),fe()},zoomOut:()=>{const c=ie.current;c.zoom=Math.max(le,c.zoom/1.2),fe()},zoomTo:c=>{ie.current.zoom=Math.min(me,Math.max(le,c)),fe()},setNodes:c=>{var x,k;(k=(x=Z.current).onNodesChange)==null||k.call(x,[...K.current.map(I=>({id:I.id,type:"remove"})),...(typeof c=="function"?c(K.current):c).map(I=>({type:"add",item:I}))])},setEdges:c=>{var x,k;(k=(x=Z.current).onEdgesChange)==null||k.call(x,[...ke.current.map(I=>({id:I.id,type:"remove"})),...(typeof c=="function"?c(ke.current):c).map(I=>({type:"add",item:I}))])},addNodes:c=>{var k,I;const x=Array.isArray(c)?c:[c];(I=(k=Z.current).onNodesChange)==null||I.call(k,x.map(p=>({type:"add",item:p})))},addEdges:c=>{var k,I;const x=Array.isArray(c)?c:[c];(I=(k=Z.current).onEdgesChange)==null||I.call(k,x.map(p=>({type:"add",item:p})))},deleteElements:({nodes:c=[],edges:x=[]})=>{var k,I,p,P;c.length&&((I=(k=Z.current).onNodesChange)==null||I.call(k,c.map(z=>({id:z.id,type:"remove"})))),x.length&&((P=(p=Z.current).onEdgesChange)==null||P.call(p,x.map(z=>({id:z.id,type:"remove"}))))},updateNodeData:(c,x)=>{var p,P;const k=K.current.find(z=>z.id===c);if(!k)return;const I=typeof x=="function"?x(k.data):{...k.data,...x};(P=(p=Z.current).onNodesChange)==null||P.call(p,[{id:c,type:"replace",item:{...k,data:I}}])},toObject:()=>({nodes:[...K.current],edges:[...ke.current],viewport:{...ie.current}}),setCenter:(c,x,k={})=>{const I=ge.current;if(!I)return;const p=I.getBoundingClientRect(),P=k.zoom??ie.current.zoom;ie.current={x:p.width/2-c*P,y:p.height/2-x*P,zoom:P},fe()},fitBounds:(c,x={})=>{const k=ge.current;if(!k)return;const I=k.getBoundingClientRect(),p=Lt(c,I.width,I.height,x.padding??.1);ie.current=p,fe()}})}});const ln=u.useCallback(()=>{ie.current={...Le},fe()},[fe,Le]),dn=u.useCallback(l=>{var v;if(l)dt.current.push(l);else{const c=ie.current,x=ge.current;if(!x)return;const k=x.getBoundingClientRect(),I=Math.round(-c.x/c.zoom+k.width/2/c.zoom),p=Math.round(-c.y/c.zoom+k.height/2/c.zoom);dt.current.push({x:I-80,y:p-45,w:160,h:90,title:"Note "+(dt.current.length+1),body:"Added at viewport center"})}(v=ze.current)==null||v.postMessage({type:"cards",data:{cards:[...dt.current]}})},[]),Ye=u.useCallback(l=>{if(l.id||(l.id="node-"+Date.now()),!l.position){const v=ie.current,c=ge.current;if(!c)return;const x=c.getBoundingClientRect();l.position={x:Math.round(-v.x/v.zoom+x.width/2/v.zoom)-ot/2,y:Math.round(-v.y/v.zoom+x.height/2/v.zoom)-Ke/2}}l.data||(l.data={label:l.id}),Se.current&&Se.current([{type:"add",item:l}])},[]),vt=u.useCallback(()=>({...ie.current}),[]),Bn=u.useCallback(l=>{ie.current={...ie.current,...l},fe()},[fe]),jn=u.useCallback(l=>Ne(l.x,l.y),[Ne]),tr=n,Br=u.useMemo(()=>({wrapRef:ge,canvasRef:Bt,workerRef:ze,cameraRef:ie,nodesRef:K,edgesRef:ke,handleRegistryRef:an,syncNodesToWorker:cn,onNodesChangeRef:Se,onEdgesChangeRef:Te,sendCamera:fe,screenToWorld:Ne,viewportListeners:at,selectionListeners:Ze,zoomMin:le,zoomMax:me,snapToGrid:Rt,snapGrid:wt,nodeExtent:ut,defaultEdgeOptions:Et,edgeRouting:lt,resolvedNodesRef:Ge,noDragClassName:zt,noPanClassName:St,get nodes(){return t},get edges(){return n},get routedEdges(){return tr},get viewport(){return Dt},get connection(){return ft}}),[t,n,tr,Dt,ft,fe,Ne,cn,at,Ze,le,me,Rt,wt,ut,Et,lt,zt,St]);return{wrapRef:ge,canvasRef:Bt,canvasReady:Nn,onPointerDown:Ln,onPointerMove:Tn,onPointerUp:$n,resetView:ln,addCard:dn,addNode:Ye,getCamera:vt,setCamera:Bn,screenToFlowPosition:jn,store:Br}}function Jr(e,t,n,r,a,o){const i=a-n,h=o-r,g=i*i+h*h;if(g===0)return Math.hypot(e-n,t-r);let d=((e-n)*i+(t-r)*h)/g;return d=Math.max(0,Math.min(1,d)),Math.hypot(e-(n+d*i),t-(r+d*h))}const rr=e=>{let t;const n=new Set,r=(d,y)=>{const w=typeof d=="function"?d(t):d;if(!Object.is(w,t)){const C=t;t=y??(typeof w!="object"||w===null)?w:Object.assign({},t,w),n.forEach(R=>R(t,C))}},a=()=>t,h={setState:r,getState:a,getInitialState:()=>g,subscribe:d=>(n.add(d),()=>n.delete(d))},g=t=e(r,a,h);return h},Kr=(e=>e?rr(e):rr),eo=e=>e;function to(e,t=eo){const n=u.useSyncExternalStore(e.subscribe,u.useCallback(()=>t(e.getState()),[e,t]),u.useCallback(()=>t(e.getInitialState()),[e,t]));return u.useDebugValue(n),n}const Vt=u.createContext(null);function no(e={}){return Kr((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 Me(e,t){const n=u.useContext(Vt);if(!n)throw new Error("useCanvasStore must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");const r=typeof n.getState=="function"&&typeof n.subscribe=="function",a=u.useRef(e),o=u.useRef(t),i=u.useRef(void 0);a.current=e,o.current=t;const h=u.useCallback(g=>{const d=a.current;if(!d)return g;const y=d(g),w=o.current||Object.is;return i.current!==void 0&&w(i.current,y)?i.current:(i.current=y,y)},[]);return r?to(n,e?h:void 0):e?h(n):n}function pr(){const e=u.useContext(Vt);if(!e)throw new Error("useCanvasStoreApi must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");return typeof e.getState=="function"?e:{getState:()=>e,setState:()=>{},subscribe:()=>()=>{}}}const Kt=u.createContext(null);function ro(){return u.useContext(Kt)}function oo({node:e,nodeType:t}){var w,C,R;const n=Me(),r=u.useRef(null),a=e._absolutePosition||e.position,o=u.useRef(null);u.useEffect(()=>{const b=r.current;if(!b)return;const B=new ResizeObserver(S=>{var H,_,j,$;const{width:N,height:X}=S[0].contentRect;if(N>0&&X>0){const A=n.nodesRef.current.find(m=>m.id===e.id),W=(A==null?void 0:A.width)||((H=A==null?void 0:A.measured)==null?void 0:H.width),F=(A==null?void 0:A.height)||((_=A==null?void 0:A.measured)==null?void 0:_.height);(Math.abs((W||0)-N)>1||Math.abs((F||0)-X)>1)&&(($=(j=n.onNodesChangeRef).current)==null||$.call(j,[{id:e.id,type:"dimensions",dimensions:{width:N,height:X},setAttributes:!0}]))}});return B.observe(b),()=>B.disconnect()},[e.id,n]);const i=u.useCallback(b=>{var oe,V,ee,he;b.stopPropagation();const B=b.target.tagName;if(B==="INPUT"||B==="TEXTAREA"||B==="SELECT"||B==="BUTTON"||B==="A"||B==="LABEL"||b.target.isContentEditable)return;const S=n.noDragClassName||"nodrag",N=n.noPanClassName||"nopan";let X=b.target;for(;X&&X!==r.current;){if((oe=X.classList)!=null&&oe.contains(S)||(V=X.classList)!=null&&V.contains(N))return;X=X.parentElement}if(n.onNodesChangeRef.current){const ne=[];if(b.shiftKey)ne.push({id:e.id,type:"select",selected:!e.selected});else for(const ue of n.nodesRef.current)ue.id===e.id&&!ue.selected?ne.push({id:ue.id,type:"select",selected:!0}):ue.id!==e.id&&ue.selected&&ne.push({id:ue.id,type:"select",selected:!1});ne.length&&n.onNodesChangeRef.current(ne)}const H=n.cameraRef.current,_=n.wrapRef.current;if(!_)return;const j=_.getBoundingClientRect(),$=(b.clientX-j.left-H.x)/H.zoom,A=(b.clientY-j.top-H.y)/H.zoom,F=e.selected?n.nodesRef.current.filter(ne=>ne.selected&&ne.id!==e.id).map(ne=>({id:ne.id,startPos:{...ne.position}})):[];o.current={startPos:{...e.position},startMouse:{x:$,y:A},selectedStarts:F};const m=[{id:e.id,type:"position",dragging:!0}];for(const ne of F)m.push({id:ne.id,type:"position",dragging:!0});(he=(ee=n.onNodesChangeRef).current)==null||he.call(ee,m);const f=r.current;f&&f.setPointerCapture(b.pointerId);let M=null,L=null;const T=()=>{var ne,ce;L&&((ce=(ne=n.onNodesChangeRef).current)==null||ce.call(ne,L),L=null),M=null},Y=ne=>{var Pe,Ee;if(!o.current)return;const ce=n.cameraRef.current,ue=_.getBoundingClientRect(),Ie=(ne.clientX-ue.left-ce.x)/ce.zoom,le=(ne.clientY-ue.top-ce.y)/ce.zoom,me=Ie-o.current.startMouse.x,Le=le-o.current.startMouse.y;let ve={x:o.current.startPos.x+me,y:o.current.startPos.y+Le};if(n.snapToGrid&&n.snapGrid&&(ve={x:n.snapGrid[0]*Math.round(ve.x/n.snapGrid[0]),y:n.snapGrid[1]*Math.round(ve.y/n.snapGrid[1])}),e.parentId&&e.extent==="parent"){const xe=n.nodesRef.current.find(ae=>ae.id===e.parentId);if(xe){const ae=xe.width||160,Fe=xe.height||60,bt=e.width||((Pe=e.measured)==null?void 0:Pe.width)||160,Ae=e.height||((Ee=e.measured)==null?void 0:Ee.height)||60;ve={x:Math.max(0,Math.min(ve.x,ae-bt)),y:Math.max(0,Math.min(ve.y,Fe-Ae))}}}f&&(f.style.left=ve.x+"px",f.style.top=ve.y+"px");for(const xe of o.current.selectedStarts){let ae={x:xe.startPos.x+me,y:xe.startPos.y+Le};n.snapToGrid&&n.snapGrid&&(ae={x:n.snapGrid[0]*Math.round(ae.x/n.snapGrid[0]),y:n.snapGrid[1]*Math.round(ae.y/n.snapGrid[1])});const Fe=_.querySelector(`[data-nodeid="${xe.id}"]`);Fe&&(Fe.style.left=ae.x+"px",Fe.style.top=ae.y+"px")}const Re=[{id:e.id,type:"position",position:ve,dragging:!0}];for(const xe of o.current.selectedStarts){let ae={x:xe.startPos.x+me,y:xe.startPos.y+Le};n.snapToGrid&&n.snapGrid&&(ae={x:n.snapGrid[0]*Math.round(ae.x/n.snapGrid[0]),y:n.snapGrid[1]*Math.round(ae.y/n.snapGrid[1])}),Re.push({id:xe.id,type:"position",position:ae,dragging:!0})}L=Re,M||(M=requestAnimationFrame(T))},J=ne=>{var ue,Ie;if(!o.current)return;M&&(cancelAnimationFrame(M),T());const ce=[{id:e.id,type:"position",dragging:!1}];for(const le of o.current.selectedStarts)ce.push({id:le.id,type:"position",dragging:!1});(Ie=(ue=n.onNodesChangeRef).current)==null||Ie.call(ue,ce),o.current=null,f&&f.releasePointerCapture(ne.pointerId),f==null||f.removeEventListener("pointermove",Y),f==null||f.removeEventListener("pointerup",J)};f==null||f.addEventListener("pointermove",Y),f==null||f.addEventListener("pointerup",J)},[e,n]),h=u.useCallback(b=>{var _,j,$,A,W,F;if(!e.selected)return;const B=b.shiftKey?10:1;let S=0,N=0;switch(b.key){case"ArrowUp":N=-B;break;case"ArrowDown":N=B;break;case"ArrowLeft":S=-B;break;case"ArrowRight":S=B;break;case"Escape":(j=(_=n.onNodesChangeRef).current)==null||j.call(_,[{id:e.id,type:"select",selected:!1}]);return;case"Delete":case"Backspace":e.deletable!==!1&&((A=($=n.onNodesChangeRef).current)==null||A.call($,[{id:e.id,type:"remove"}]));return;default:return}b.preventDefault();const X={x:e.position.x+S,y:e.position.y+N},H=[{id:e.id,type:"position",position:X}];for(const m of n.nodesRef.current)m.selected&&m.id!==e.id&&H.push({id:m.id,type:"position",position:{x:m.position.x+S,y:m.position.y+N}});(F=(W=n.onNodesChangeRef).current)==null||F.call(W,H)},[e,n]),g=e.width||((w=e.measured)==null?void 0:w.width),d=e.height||((C=e.measured)==null?void 0:C.height),y=!!(g&&d);return E.jsx(Kt.Provider,{value:e.id,children:E.jsx("div",{ref:r,className:`ric-node-wrapper ${e.selected?"selected":""} ${e.dragging?"dragging":""}`,style:{position:"absolute",left:a.x,top:a.y,zIndex:e.type==="group"?0:e.zIndex||1,pointerEvents:e.type==="group"?"none":"all",visibility:y?"visible":"hidden",outline:"none"},"data-nodeid":e.id,tabIndex:e.selectable!==!1?0:void 0,role:"button","aria-label":`Node ${((R=e.data)==null?void 0:R.label)||e.id}`,"aria-selected":!!e.selected,onPointerDown:i,onKeyDown:h,children:E.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:a.x,positionAbsoluteY:a.y,width:g,height:d,sourcePosition:e.sourcePosition,targetPosition:e.targetPosition,parentId:e.parentId,dragHandle:e.dragHandle})})})}const so=u.memo(oo),mr=160,vr=60;function or(e,t,n,r){var h,g;const a=e.width||((h=e.measured)==null?void 0:h.width)||mr,o=e.height||((g=e.measured)==null?void 0:g.height)||vr,i=e._absolutePosition||e.position;if(e.handleBounds){const d=e.handleBounds[t]||[],y=n?d.find(w=>w.id===n):d[0];if(y&&y.x!==void 0&&y.y!==void 0){const w=y.position||(t==="source"?"right":"left");return{x:i.x+y.x,y:i.y+y.y,position:w}}}if(r){const d=`${e.id}__${n||t}`,y=r.get(d);if(y&&y.x!==void 0&&y.y!==void 0)return{x:i.x+y.x,y:i.y+y.y,position:y.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 y=d.position||(t==="source"?"right":"left");switch(y){case"top":return{x:i.x+a/2,y:i.y,position:y};case"bottom":return{x:i.x+a/2,y:i.y+o,position:y};case"left":return{x:i.x,y:i.y+o/2,position:y};default:return{x:i.x+a,y:i.y+o/2,position:y}}}}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 ao(e,t,n){return n==="left"?e-t:n==="right"?e+t:e}function io(e,t,n){return n==="top"?e-t:n==="bottom"?e+t:e}function sr({x:e,y:t,position:n,type:r,onPointerDown:a}){return E.jsx("circle",{className:`ric-edge-anchor ric-edge-anchor-${r}`,cx:ao(e,10,n),cy:io(t,10,n),r:10,stroke:"transparent",fill:"transparent",style:{cursor:"move",pointerEvents:"stroke"},onPointerDown:a})}function co({edge:e,edgeType:t,nodes:n,reconnectable:r}){var _,j,$;const a=Me(),[o,i]=u.useState(null),h=u.useCallback((A,W,F,m)=>{var oe;W.stopPropagation(),W.preventDefault();const f=a.wrapRef.current;if(!f)return;const M=A==="source"?m:F,L=A==="source"?e.target:e.source;(oe=a.workerRef.current)==null||oe.postMessage({type:"connecting",data:{from:{x:M.x,y:M.y},to:{x:M.x,y:M.y}}});const T=f.getBoundingClientRect(),Y=V=>{var ce;const ee=a.cameraRef.current,he=(V.clientX-T.left-ee.x)/ee.zoom,ne=(V.clientY-T.top-ee.y)/ee.zoom;(ce=a.workerRef.current)==null||ce.postMessage({type:"connecting",data:{from:{x:M.x,y:M.y},to:{x:he,y:ne}}})},J=V=>{var me,Le,ve,Re;const ee=a.cameraRef.current,he=(V.clientX-T.left-ee.x)/ee.zoom,ne=(V.clientY-T.top-ee.y)/ee.zoom,ce=20/ee.zoom;let ue=null,Ie=null;const le=(me=a.handleRegistryRef)==null?void 0:me.current;for(const Pe of a.nodesRef.current){if(Pe.hidden)continue;const Ee=Pe.width||mr,xe=Pe.height||vr,ae=Pe._absolutePosition||Pe.position,Fe=[];if(le)for(const[,Ae]of le)Ae.nodeId===Pe.id&&Fe.push(Ae);const bt=Fe.length>0?Fe:Pe.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const Ae of bt){let et,Ve;if(Ae.x!==void 0&&Ae.y!==void 0)et=ae.x+Ae.x,Ve=ae.y+Ae.y;else switch(Ae.position||(Ae.type==="source"?"right":"left")){case"top":et=ae.x+Ee/2,Ve=ae.y;break;case"bottom":et=ae.x+Ee/2,Ve=ae.y+xe;break;case"left":et=ae.x,Ve=ae.y+xe/2;break;default:et=ae.x+Ee,Ve=ae.y+xe/2;break}if(Math.abs(he-et)<ce&&Math.abs(ne-Ve)<ce){ue=Pe,Ie=Ae.id||null;break}}if(ue)break}if(ue){const Pe=A==="source"?{source:ue.id,target:L,sourceHandle:Ie,targetHandle:e.targetHandle}:{source:L,target:ue.id,sourceHandle:e.sourceHandle,targetHandle:Ie};(ve=(Le=a.onEdgesChangeRef).current)==null||ve.call(Le,[{id:e.id,type:"remove"},{type:"add",item:{id:e.id,...Pe}}])}(Re=a.workerRef.current)==null||Re.postMessage({type:"connecting",data:null}),f.removeEventListener("pointermove",Y),f.removeEventListener("pointerup",J)};f.addEventListener("pointermove",Y),f.addEventListener("pointerup",J)},[e,a]),g=n.find(A=>A.id===e.source),d=n.find(A=>A.id===e.target),y=g&&!!(g.width||(_=g.measured)!=null&&_.width),w=d&&!!(d.width||(j=d.measured)!=null&&j.width),C=($=a.handleRegistryRef)==null?void 0:$.current,R=y?or(g,"source",e.sourceHandle,C):null,b=w?or(d,"target",e.targetHandle,C):null,B=e.type==="bezier"||e.type==="simplebezier"||e.type==="default",S=a.routedEdges||a.edges,N=S==null?void 0:S.find(A=>A.id===e.id),X=B?null:(N==null?void 0:N._routedPoints)||e._routedPoints||null,H=r!==!1&&e.reconnectable!==!1;return!R||!b?null:E.jsxs("g",{className:`ric-edge-wrapper ${e.selected?"selected":""}`,"data-edgeid":e.id,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),children:[E.jsx(t,{id:e.id,source:e.source,target:e.target,sourceX:R.x,sourceY:R.y,targetX:b.x,targetY:b.y,sourcePosition:R.position,targetPosition:b.position,sourceHandleId:e.sourceHandle,targetHandleId:e.targetHandle,data:e.data,type:e.type,selected:!!e.selected,animated:!!e.animated,label:e.label,style:e.style,selectable:e.selectable!==!1,deletable:e.deletable!==!1,routedPoints:X}),H&&(o||e.selected)&&E.jsxs(E.Fragment,{children:[E.jsx(sr,{x:R.x,y:R.y,position:R.position,type:"source",onPointerDown:A=>h("source",A,R,b)}),E.jsx(sr,{x:b.x,y:b.y,position:b.position,type:"target",onPointerDown:A=>h("target",A,R,b)})]})]})}const uo=u.memo(co);function br({selectionKeyCode:e="Shift",selectionMode:t="partial"}){var B;const n=Me(),[r,a]=u.useState(null),o=u.useRef(null);if(u.useEffect(()=>{const S=n.wrapRef.current;if(!S)return;let N=!1,X=null,H=!1;const _=F=>{F.key===e&&(H=!0)},j=F=>{F.key===e&&(H=!1)},$=F=>{if(!H)return;const m=F.target;if(m.closest(".ric-node-wrapper")||m.closest(".ric-handle"))return;N=!0;const f=n.cameraRef.current,M=S.getBoundingClientRect(),L=(F.clientX-M.left-f.x)/f.zoom,T=(F.clientY-M.top-f.y)/f.zoom;X={x:L,y:T},a({startX:L,startY:T,endX:L,endY:T}),F.stopPropagation()},A=F=>{if(!N||!X)return;const m=n.cameraRef.current,f=S.getBoundingClientRect(),M=(F.clientX-f.left-m.x)/m.zoom,L=(F.clientY-f.top-m.y)/m.zoom;a({startX:X.x,startY:X.y,endX:M,endY:L})},W=F=>{var J,oe;if(!N||!X)return;N=!1;const m=n.cameraRef.current,f=S.getBoundingClientRect(),M=(F.clientX-f.left-m.x)/m.zoom,L=(F.clientY-f.top-m.y)/m.zoom,T={x:Math.min(X.x,M),y:Math.min(X.y,L),width:Math.abs(M-X.x),height:Math.abs(L-X.y)},Y=[];for(const V of n.nodesRef.current){const ee=V._absolutePosition||V.position,he=V.width||160,ne=V.height||60;let ce;t==="full"?ce=ee.x>=T.x&&ee.y>=T.y&&ee.x+he<=T.x+T.width&&ee.y+ne<=T.y+T.height:ce=ee.x+he>T.x&&ee.x<T.x+T.width&&ee.y+ne>T.y&&ee.y<T.y+T.height,Y.push({id:V.id,type:"select",selected:ce})}Y.length&&((oe=(J=n.onNodesChangeRef).current)==null||oe.call(J,Y)),X=null,a(null)};return S.addEventListener("pointerdown",$,!0),S.addEventListener("pointermove",A),S.addEventListener("pointerup",W),window.addEventListener("keydown",_),window.addEventListener("keyup",j),()=>{S.removeEventListener("pointerdown",$,!0),S.removeEventListener("pointermove",A),S.removeEventListener("pointerup",W),window.removeEventListener("keydown",_),window.removeEventListener("keyup",j)}},[n,e,t]),!r)return null;const i=((B=n.cameraRef)==null?void 0:B.current)||{x:0,y:0,zoom:1},h=Math.min(r.startX,r.endX),g=Math.min(r.startY,r.endY),d=Math.abs(r.endX-r.startX),y=Math.abs(r.endY-r.startY),w=h*i.zoom+i.x,C=g*i.zoom+i.y,R=d*i.zoom,b=y*i.zoom;return E.jsx("div",{ref:o,className:"ric-selection-box",style:{position:"absolute",left:w,top:C,width:R,height:b,border:"1px dashed #3b82f6",background:"rgba(59, 130, 246, 0.08)",pointerEvents:"none",zIndex:100}})}br.displayName="SelectionBox";const wr=u.memo(br);function Mr(e,t){var a,o,i,h;const n=(a=e.handleRegistryRef)==null?void 0:a.current;if(!n)return;const r={source:[],target:[]};for(const[,g]of n)if(g.nodeId===t){const d={id:g.id,type:g.type,position:g.position,x:g.x,y:g.y,width:8,height:8};g.type==="source"?r.source.push(d):r.target.push(d)}(i=(o=e.onNodesChangeRef).current)==null||i.call(o,[{id:t,type:"dimensions",handleBounds:r,setAttributes:!1}]),(h=e.syncNodesToWorker)==null||h.call(e)}const Hn=new Set;function ar(e,t){Hn.has(t)||(Hn.add(t),queueMicrotask(()=>{Hn.delete(t),Mr(e,t)}))}function lo(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}}function Jt({type:e="source",position:t=e==="source"?"right":"left",id:n,isConnectable:r=!0,isConnectableStart:a=!0,isConnectableEnd:o=!0,children:i,className:h="",style:g={},onConnect:d,...y}){const w=u.useContext(Kt),C=Me(),R=u.useRef(null),b=u.useRef(C);b.current=C;const B=u.useCallback(()=>{var F,m,f;const H=R.current;if(!H||!w)return;const _=b.current,j=(F=_.handleRegistryRef)==null?void 0:F.current;if(!j)return;const $=`${w}__${n||e}`,A=(f=(m=_.cameraRef)==null?void 0:m.current)==null?void 0:f.zoom,W=lo(H,A);if(W){const M={nodeId:w,id:n||null,type:e,position:t,x:W.x,y:W.y};j.set($,M)}},[w,n,e,t]);u.useLayoutEffect(()=>{B()},[B]),u.useEffect(()=>{if(!w)return;const H=b.current;ar(H,w);const _=R.current,j=_==null?void 0:_.closest(".ric-node-wrapper"),$=new ResizeObserver(()=>{B(),ar(b.current,w)});return j&&$.observe(j),()=>{var m;$.disconnect();const A=b.current,W=(m=A.handleRegistryRef)==null?void 0:m.current,F=`${w}__${n||e}`;W==null||W.delete(F),Mr(A,w)}},[w,n,e,t,B]);const S=u.useCallback(()=>{var f;const H=b.current,_=H.nodesRef.current.find(M=>M.id===w);if(!_)return null;const j=_._absolutePosition||_.position,$=(f=H.handleRegistryRef)==null?void 0:f.current,A=`${w}__${n||e}`,W=$==null?void 0:$.get(A);if(W&&W.x!==void 0&&W.y!==void 0)return{x:j.x+W.x,y:j.y+W.y};const F=_.width||160,m=_.height||60;switch(t){case"top":return{x:j.x+F/2,y:j.y};case"bottom":return{x:j.x+F/2,y:j.y+m};case"left":return{x:j.x,y:j.y+m/2};default:return{x:j.x+F,y:j.y+m/2}}},[w,n,e,t]),N=u.useCallback(H=>{var L;if(!r||!a)return;H.stopPropagation(),H.preventDefault();const _=b.current,j=_.cameraRef.current,$=_.wrapRef.current;if(!$)return;const A=$.getBoundingClientRect(),W=S();if(!W)return;const F=W.x,m=W.y;(L=_.workerRef.current)==null||L.postMessage({type:"connecting",data:{from:{x:F,y:m},to:{x:F,y:m}}}),$.setPointerCapture(H.pointerId);const f=T=>{var oe;const Y=(T.clientX-A.left-j.x)/j.zoom,J=(T.clientY-A.top-j.y)/j.zoom;(oe=_.workerRef.current)==null||oe.postMessage({type:"connecting",data:{from:{x:F,y:m},to:{x:Y,y:J}}})},M=T=>{var ne,ce,ue,Ie;const Y=(T.clientX-A.left-j.x)/j.zoom,J=(T.clientY-A.top-j.y)/j.zoom,oe=20/j.zoom;let V=null,ee=null;const he=(ne=_.handleRegistryRef)==null?void 0:ne.current;for(const le of _.nodesRef.current){if(le.id===w||le.hidden)continue;const me=le.width||160,Le=le.height||60,ve=le._absolutePosition||le.position,Re=[];if(he)for(const[,Ee]of he)Ee.nodeId===le.id&&Re.push(Ee);const Pe=Re.length>0?Re:le.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const Ee of Pe){let xe,ae;if(Ee.x!==void 0&&Ee.y!==void 0)xe=ve.x+Ee.x,ae=ve.y+Ee.y;else switch(Ee.position||(Ee.type==="source"?"right":"left")){case"top":xe=ve.x+me/2,ae=ve.y;break;case"bottom":xe=ve.x+me/2,ae=ve.y+Le;break;case"left":xe=ve.x,ae=ve.y+Le/2;break;default:xe=ve.x+me,ae=ve.y+Le/2;break}if(Math.abs(Y-xe)<oe&&Math.abs(J-ae)<oe){V=le,ee=Ee.id||null;break}}if(V)break}if(V){const le={source:e==="source"?w:V.id,target:e==="source"?V.id:w,sourceHandle:e==="source"?n||null:ee,targetHandle:e==="source"?ee:n||null};(ue=(ce=_.onEdgesChangeRef)==null?void 0:ce.current)==null||ue.call(ce,[{type:"add",item:{id:`e-${le.source}-${le.target}`,...le}}])}(Ie=_.workerRef.current)==null||Ie.postMessage({type:"connecting",data:null}),$.removeEventListener("pointermove",f),$.removeEventListener("pointerup",M)};$.addEventListener("pointermove",f),$.addEventListener("pointerup",M)},[w,n,e,t,r,a,S]),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 E.jsx("div",{ref:R,className:`ric-handle ric-handle-${t} ric-handle-${e} ${h}`,"data-handleid":n||null,"data-nodeid":w,"data-handlepos":t,"data-handletype":e,onPointerDown:N,style:{position:"absolute",width:8,height:8,borderRadius:"50%",background:"#1a192b",border:"none",zIndex:10,cursor:r?"crosshair":"default",boxSizing:"border-box",...X,...g},...y,children:i})}function fo({data:e,isConnectable:t,selected:n,targetPosition:r="left",sourcePosition:a="right",hideSourceHandle:o=!1,hideTargetHandle:i=!1}){return E.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&&E.jsx(Jt,{type:"target",position:r,isConnectable:t}),E.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!o&&E.jsx(Jt,{type:"source",position:a,isConnectable:t})]})}function Rr({data:e,isConnectable:t,selected:n,sourcePosition:r="right",hideSourceHandle:a=!1}){return E.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:[E.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!a&&E.jsx(Jt,{type:"source",position:r,isConnectable:t})]})}function kr({data:e,isConnectable:t,selected:n,targetPosition:r="left",hideTargetHandle:a=!1}){return E.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&&E.jsx(Jt,{type:"target",position:r,isConnectable:t}),E.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label})]})}function Cr({data:e,selected:t,width:n,height:r}){return E.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)&&E.jsx("div",{style:{fontSize:11,fontWeight:600,color:"#888",userSelect:"none"},children:e.label})})}function Er({x:e,y:t,label:n,labelStyle:r,labelShowBg:a=!0,labelBgStyle:o,labelBgPadding:i=[2,4],labelBgBorderRadius:h=2,children:g,className:d="",...y}){const[w,C]=u.useState({x:1,y:0,width:0,height:0}),R=u.useRef(null);return u.useEffect(()=>{if(R.current){const b=R.current.getBBox();C({x:b.x,y:b.y,width:b.width,height:b.height})}},[n]),n?E.jsxs("g",{transform:`translate(${e-w.width/2} ${t-w.height/2})`,className:`ric-edge-textwrapper ${d}`,visibility:w.width?"visible":"hidden",...y,children:[a&&E.jsx("rect",{width:w.width+2*i[0],x:-i[0],y:-i[1],height:w.height+2*i[1],className:"ric-edge-textbg",style:o,rx:h,ry:h}),E.jsx("text",{className:"ric-edge-text",y:w.height/2,dy:"0.3em",ref:R,style:r,children:n}),g]}):null}Er.displayName="EdgeText";const zr=u.memo(Er);function ir(e){return e!=null&&e!==""&&!isNaN(Number(e))}function en({id:e,path:t,labelX:n,labelY:r,label:a,labelStyle:o,labelShowBg:i,labelBgStyle:h,labelBgPadding:g,labelBgBorderRadius:d,interactionWidth:y=20,style:w,markerEnd:C,markerStart:R,className:b="",...B}){return E.jsxs(E.Fragment,{children:[E.jsx("path",{id:e,d:t,fill:"none",stroke:"#b1b1b7",strokeWidth:1.5,className:`ric-edge-path ${b}`,style:w,markerEnd:C,markerStart:R,...B}),y?E.jsx("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:y,className:"ric-edge-interaction",style:{pointerEvents:"stroke"}}):null,a&&ir(n)&&ir(r)?E.jsx(zr,{x:n,y:r,label:a,labelStyle:o,labelShowBg:i,labelBgStyle:h,labelBgPadding:g,labelBgBorderRadius:d}):null]})}const Zt=20;function cr(e,t,n){switch(n){case"right":return{x:e+Zt,y:t};case"left":return{x:e-Zt,y:t};case"bottom":return{x:e,y:t+Zt};case"top":return{x:e,y:t-Zt};default:return{x:e+Zt,y:t}}}const qn=u.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:i="bottom",targetPosition:h="top",label:g,labelStyle:d,labelShowBg:y,labelBgStyle:w,labelBgPadding:C,labelBgBorderRadius:R,style:b,markerEnd:B,markerStart:S,interactionWidth:N}){let X,H,_;const j=cr(n,r,i),$=cr(a,o,h),A=Math.abs($.x-j.x),W=Math.max(50,A*.5);let F,m,f,M;switch(i){case"left":F=j.x-W,m=j.y;break;case"top":F=j.x,m=j.y-W;break;case"bottom":F=j.x,m=j.y+W;break;default:F=j.x+W,m=j.y;break}switch(h){case"right":f=$.x+W,M=$.y;break;case"top":f=$.x,M=$.y-W;break;case"bottom":f=$.x,M=$.y+W;break;default:f=$.x-W,M=$.y;break}X=`M ${n},${r} L ${j.x},${j.y} C ${F},${m} ${f},${M} ${$.x},${$.y} L ${a},${o}`;const L=.5,T=.5;return H=T*T*T*j.x+3*T*T*L*F+3*T*L*L*f+L*L*L*$.x,_=T*T*T*j.y+3*T*T*L*m+3*T*L*L*M+L*L*L*$.y,E.jsx(en,{id:t,path:X,labelX:H,labelY:_,label:g,labelStyle:d,labelShowBg:y,labelBgStyle:w,labelBgPadding:C,labelBgBorderRadius:R,style:b,markerEnd:B,markerStart:S,interactionWidth:N})});qn.displayName="BezierEdge";function On({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 Zn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a="right",targetPosition:o="left",curvature:i=.25}){const h=Math.abs(n-e),g=Math.abs(r-t),d=Math.sqrt(h*h+g*g),y=Math.max(d*i,50);let w,C,R,b;switch(a){case"top":w=e,C=t-y;break;case"bottom":w=e,C=t+y;break;case"left":w=e-y,C=t;break;default:w=e+y,C=t;break}switch(o){case"top":R=n,b=r-y;break;case"bottom":R=n,b=r+y;break;case"right":R=n+y,b=r;break;default:R=n-y,b=r;break}const B=`M ${e},${t} C ${w},${C} ${R},${b} ${n},${r}`,S=.5,N=1-S,X=N*N*N*e+3*N*N*S*w+3*N*S*S*R+S*S*S*n,H=N*N*N*t+3*N*N*S*C+3*N*S*S*b+S*S*S*r;return[B,X,H,0,0]}function Gn({sourceX:e,sourceY:t,targetX:n,targetY:r}){const a=Math.abs(n-e),o=Math.max(a*.5,50),i=e+o,h=n-o,g=`M ${e},${t} C ${i},${t} ${h},${r} ${n},${r}`,d=.5,y=.5,w=y*y*y*e+3*y*y*d*i+3*y*d*d*h+d*d*d*n,C=y*y*y*t+3*y*y*d*t+3*y*d*d*r+d*d*d*r;return[g,w,C,0,0]}function gn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a="right",targetPosition:o="left",borderRadius:i=5,offset:h=20}){const g=a==="left"||a==="right",d=Math.min(i,Math.abs(n-e)/2,Math.abs(r-t)/2);if(g){if(Math.abs(r-t)<1)return[`M ${e},${t} L ${n},${r}`,(e+n)/2,t,0,0];const R=(e+n)/2,b=r>t?1:-1;return[`M ${e},${t} L ${R-d},${t} Q ${R},${t} ${R},${t+b*d} L ${R},${r-b*d} Q ${R},${r} ${R+(n>R?d:-d)},${r} L ${n},${r}`,R,(t+r)/2,0,0]}const y=(t+r)/2,w=n>e?1:-1;return[`M ${e},${t} L ${e},${y-d} Q ${e},${y} ${e+w*d},${y} L ${n-w*d},${y} Q ${n},${y} ${n},${y+(r>y?d:-d)} L ${n},${r}`,(e+n)/2,y,0,0]}function ho({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[,a,o]=Zn({sourceX:e,sourceY:t,targetX:n,targetY:r});return[a,o,0,0]}function yo({sourceX:e,sourceY:t,targetX:n,targetY:r}){return[(e+n)/2,(t+r)/2,0,0]}function go(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 xn=160,pn=60,Gt=20,hn=12,mn=20;function ur(e,t,n){var i,h;const r=e.width||((i=e.measured)==null?void 0:i.width)||xn,a=e.height||((h=e.measured)==null?void 0:h.height)||pn,o=e._absolutePosition||e.position;if(e.handles&&e.handles.length>0){for(const g of e.handles)if(g.type===t&&(!n||g.id===n)){if(g.x!==void 0&&g.y!==void 0)return{x:o.x+g.x,y:o.y+g.y,dir:g.position||(t==="source"?"right":"left")};switch(g.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 vn(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 xo(e,t,n,r,a,o,i,h){const g=Math.min(e,n),d=Math.max(e,n),y=Math.min(t,r),w=Math.max(t,r);if(d<=a||g>=a+i||w<=o||y>=o+h)return!1;const C=.5;if(e>a+C&&e<a+i-C&&t>o+C&&t<o+h-C||n>a+C&&n<a+i-C&&r>o+C&&r<o+h-C)return!0;const R=(e+n)/2,b=(t+r)/2;if(R>a+C&&R<a+i-C&&b>o+C&&b<o+h-C)return!0;const B=[[a,o],[a+i,o],[a+i,o+h],[a,o+h]];for(let S=0;S<4;S++)if(po(e,t,n,r,B[S][0],B[S][1],B[(S+1)%4][0],B[(S+1)%4][1]))return!0;return!1}function po(e,t,n,r,a,o,i,h){const g=(i-a)*(t-o)-(h-o)*(e-a),d=(i-a)*(r-o)-(h-o)*(n-a),y=(n-e)*(o-t)-(r-t)*(a-e),w=(n-e)*(h-t)-(r-t)*(i-e);return(g>0&&d<0||g<0&&d>0)&&(y>0&&w<0||y<0&&w>0)}function Yn(e,t,n,r,a){for(let o=0;o<a.length;o++){const i=a[o];if(xo(e,t,n,r,i.x,i.y,i.w,i.h))return!1}return!0}function mo(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 Qn(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 h=i._absolutePosition||i.position,g=i.width||((r=i.measured)==null?void 0:r.width)||xn,d=i.height||((a=i.measured)==null?void 0:a.height)||pn;n.push({id:i.id,x:h.x-Gt,y:h.y-Gt,w:g+2*Gt,h:d+2*Gt})}return n}function Sr(e,t,n){if(Yn(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=Gt+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 f=0;f<n.length;f++){const M=n[f];r.add(M.x),r.add(M.x+M.w),a.add(M.y),a.add(M.y+M.h)}const i=[...r].sort((f,M)=>f-M),h=[...a].sort((f,M)=>f-M),g=new Map,d=new Map;for(let f=0;f<i.length;f++)g.set(i[f],f);for(let f=0;f<h.length;f++)d.set(h[f],f);const y=i.length,w=h.length,C=(f,M)=>M*y+f,R=g.get(e.x),b=d.get(e.y),B=g.get(t.x),S=d.get(t.y);if(R===void 0||b===void 0||B===void 0||S===void 0)return null;const N=C(R,b),X=C(B,S),H=new Float64Array(y*w).fill(1/0),_=new Float64Array(y*w).fill(1/0),j=new Int32Array(y*w).fill(-1),$=new Int8Array(y*w).fill(-1),A=new Uint8Array(y*w);H[N]=0,_[N]=Math.abs(i[B]-e.x)+Math.abs(h[S]-e.y);const W=[N],F=15,m=[[1,0],[-1,0],[0,1],[0,-1]];for(;W.length>0;){let f=0;for(let V=1;V<W.length;V++)_[W[V]]<_[W[f]]&&(f=V);const M=W[f];if(W[f]=W[W.length-1],W.pop(),M===X){const V=[];let ee=X;for(;ee!==-1&&ee!==N;){const he=ee/y|0,ne=ee%y;V.unshift({x:i[ne],y:h[he]}),ee=j[ee]}return V.unshift({x:e.x,y:e.y}),vo(V,n)}if(A[M])continue;A[M]=1;const L=M/y|0,T=M%y,Y=i[T],J=h[L],oe=$[M];for(let V=0;V<4;V++){const ee=T+m[V][0],he=L+m[V][1];if(ee<0||ee>=y||he<0||he>=w)continue;const ne=C(ee,he);if(A[ne])continue;const ce=i[ee],ue=h[he];if(mo(ce,ue,n)||!Yn(Y,J,ce,ue,n))continue;const Ie=Math.abs(ce-Y)+Math.abs(ue-J),le=oe>=0&&oe!==V?F:0,me=H[M]+Ie+le;me<H[ne]&&(j[ne]=M,$[ne]=V,H[ne]=me,_[ne]=me+Math.abs(i[B]-ce)+Math.abs(h[S]-ue),W.push(ne))}}return null}function vo(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],h=Math.abs(a.x-o.x)<.5&&Math.abs(o.x-i.x)<.5,g=Math.abs(a.y-o.y)<.5&&Math.abs(o.y-i.y)<.5;(h||g)&&Yn(a.x,a.y,i.x,i.y,t)||n.push(o)}return n.push(e[e.length-1]),n}function bo(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 h=o[i],g=o[i+1];if(Math.abs(h.y-g.y)<.5){const d=Math.round(h.y*10)/10;t.has(d)||t.set(d,[]),t.get(d).push({edgeId:a.id,segIdx:i,x1:Math.min(h.x,g.x),x2:Math.max(h.x,g.x)})}else if(Math.abs(h.x-g.x)<.5){const d=Math.round(h.x*10)/10;n.has(d)||n.set(d,[]),n.get(d).push({edgeId:a.id,segIdx:i,y1:Math.min(h.y,g.y),y2:Math.max(h.y,g.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=lr(a,"x1","x2");for(const i of o){if(i.length<2)continue;const h=(i.length-1)*hn/2;for(let g=0;g<i.length;g++){const d=i[g],y=-h+g*hn,w=r.get(d.edgeId);w&&(w[d.segIdx].y+=y,w[d.segIdx+1].y+=y)}}}for(const[,a]of n){if(a.length<2)continue;const o=lr(a,"y1","y2");for(const i of o){if(i.length<2)continue;const h=(i.length-1)*hn/2;for(let g=0;g<i.length;g++){const d=i[g],y=-h+g*hn,w=r.get(d.edgeId);w&&(w[d.segIdx].x+=y,w[d.segIdx+1].x+=y)}}}return e.map(a=>{const o=r.get(a.id);return o?{...a,_routedPoints:o}:a})}function lr(e,t,n){if(e.length<2)return[];const r=[...e].sort((i,h)=>i[t]-h[t]),a=[];let o=[r[0]];for(let i=1;i<r.length;i++){const h=o[o.length-1];r[i][t]<h[n]?o.push(r[i]):(o.length>1&&a.push(o),o=[r[i]])}return o.length>1&&a.push(o),a}function bn(e,t=6,n=!1){if(!e||e.length<2)return null;if(n)return wo(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],h=e[o],g=e[o+1],d=Math.abs(h.x-i.x)+Math.abs(h.y-i.y),y=Math.abs(g.x-h.x)+Math.abs(g.y-h.y),w=Math.min(r,d/2,y/2);if(w>.5){const C=h.x-i.x,R=h.y-i.y,b=g.x-h.x,B=g.y-h.y,S=Math.sqrt(C*C+R*R)||1,N=Math.sqrt(b*b+B*B)||1;a+=` L ${h.x-C/S*w},${h.y-R/S*w}`,a+=` Q ${h.x},${h.y} ${h.x+b/N*w},${h.y+B/N*w}`}else a+=` L ${h.x},${h.y}`}return a+=` L ${e[e.length-1].x},${e[e.length-1].y}`,a}function wo(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],h=e[r+2<e.length?r+2:e.length-1],g=o.x+(i.x-a.x)*t,d=o.y+(i.y-a.y)*t,y=i.x-(h.x-o.x)*t,w=i.y-(h.y-o.y)*t;n+=` C ${g},${d} ${y},${w} ${i.x},${i.y}`}return n}function wn(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 Mo(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=Qn(e,null),a=t.map(o=>{var $,A,W,F;const i=o.type||"default";if(i==="bezier"||i==="simplebezier"||i==="default")return o;const h=n[o.source],g=n[o.target];if(!h||!g||h.hidden||g.hidden)return o;const d=ur(h,"source",o.sourceHandle),y=ur(g,"target",o.targetHandle),w=vn(d,mn),C=vn(y,mn),R=5,b=r.filter(m=>m.id!==o.source&&m.id!==o.target),B=h._absolutePosition||h.position,S=h.width||(($=h.measured)==null?void 0:$.width)||xn,N=h.height||((A=h.measured)==null?void 0:A.height)||pn;b.push({id:o.source,x:B.x-R,y:B.y-R,w:S+2*R,h:N+2*R});const X=g._absolutePosition||g.position,H=g.width||((W=g.measured)==null?void 0:W.width)||xn,_=g.height||((F=g.measured)==null?void 0:F.height)||pn;if(b.push({id:o.target,x:X.x-R,y:X.y-R,w:H+2*R,h:_+2*R}),b.length===0)return o;const j=Sr(w,C,b);return j&&j.length>=2?(j.unshift({x:d.x,y:d.y}),j.push({x:y.x,y:y.y}),{...o,_routedPoints:j}):o});return bo(a)}function Ro(e,t,n,r,a,o,i,h){const g=Qn(i,h?new Set(h):null);if(g.length===0)return null;const d={x:e,y:t,dir:a||"right"},y={x:n,y:r,dir:o||"left"},w=vn(d,mn),C=vn(y,mn),R=Sr(w,C,g);return R&&R.length>=2?(R.unshift({x:d.x,y:d.y}),R.push({x:y.x,y:y.y}),R):null}const Vn=u.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,label:i,labelStyle:h,labelShowBg:g,labelBgStyle:d,labelBgPadding:y,labelBgBorderRadius:w,style:C,markerEnd:R,markerStart:b,interactionWidth:B,routedPoints:S}){let N,X,H;if(S&&S.length>=2){N=bn(S);const _=wn(S);X=_.x,H=_.y}else[N,X,H]=On({sourceX:n,sourceY:r,targetX:a,targetY:o});return E.jsx(en,{id:t,path:N,labelX:X,labelY:H,label:i,labelStyle:h,labelShowBg:g,labelBgStyle:d,labelBgPadding:y,labelBgBorderRadius:w,style:C,markerEnd:R,markerStart:b,interactionWidth:B})});Vn.displayName="StraightEdge";const Jn=u.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:i="bottom",targetPosition:h="top",label:g,labelStyle:d,labelShowBg:y,labelBgStyle:w,labelBgPadding:C,labelBgBorderRadius:R,style:b,markerEnd:B,markerStart:S,pathOptions:N,interactionWidth:X,routedPoints:H}){let _,j,$;if(H&&H.length>=2){_=bn(H);const A=wn(H);j=A.x,$=A.y}else[_,j,$]=gn({sourceX:n,sourceY:r,sourcePosition:i,targetX:a,targetY:o,targetPosition:h,borderRadius:N==null?void 0:N.borderRadius,offset:N==null?void 0:N.offset});return E.jsx(en,{id:t,path:_,labelX:j,labelY:$,label:g,labelStyle:d,labelShowBg:y,labelBgStyle:w,labelBgPadding:C,labelBgBorderRadius:R,style:b,markerEnd:B,markerStart:S,interactionWidth:X})});Jn.displayName="SmoothStepEdge";const Nr=u.memo(function({id:t,...n}){var a;const r=u.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(a=n.pathOptions)==null?void 0:a.offset]);return E.jsx(Jn,{...n,id:t,pathOptions:r})});Nr.displayName="StepEdge";const Kn=u.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:i,targetPosition:h,label:g,labelStyle:d,labelShowBg:y,labelBgStyle:w,labelBgPadding:C,labelBgBorderRadius:R,style:b,markerEnd:B,markerStart:S,interactionWidth:N,routedPoints:X}){let H,_,j;if(X&&X.length>=2){H=bn(X);const $=wn(X);_=$.x,j=$.y}else[H,_,j]=Gn({sourceX:n,sourceY:r,targetX:a,targetY:o});return E.jsx(en,{id:t,path:H,labelX:_,labelY:j,label:g,labelStyle:d,labelShowBg:y,labelBgStyle:w,labelBgPadding:C,labelBgBorderRadius:R,style:b,markerEnd:B,markerStart:S,interactionWidth:N})});Kn.displayName="SimpleBezierEdge";const ko={input:Rr,output:kr,group:Cr},Co={bezier:qn,straight:Vn,simplebezier:Kn},Eo=160,zo=60;function So(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||Eo,height:n.height||zo}}}):e}function No({cards:e,nodes:t=[],edges:n=[],nodeTypes:r,edgeTypes:a,dark:o,gridSize:i,width:h="100%",height:g="420px",className:d="",style:y={},zoomMin:w,zoomMax:C,initialCamera:R,fitView:b,fitViewOptions:B,onNodesChange:S,onEdgesChange:N,onConnect:X,onConnectStart:H,onConnectEnd:_,onNodeClick:j,onNodeDoubleClick:$,onNodeMouseEnter:A,onNodeMouseMove:W,onNodeMouseLeave:F,onNodeContextMenu:m,onNodeDragStart:f,onNodeDrag:M,onNodeDragStop:L,onEdgeClick:T,onEdgeDoubleClick:Y,onEdgeMouseEnter:J,onEdgeMouseMove:oe,onEdgeMouseLeave:V,onEdgeContextMenu:ee,onPaneClick:he,onPaneContextMenu:ne,onPaneMouseEnter:ce,onPaneMouseMove:ue,onPaneMouseLeave:Ie,onSelectionChange:le,onInit:me,onMoveStart:Le,onMove:ve,onMoveEnd:Re,onDelete:Pe,onBeforeDelete:Ee,onError:xe,onDragOver:ae,onDrop:Fe,onDragEnter:bt,onDragLeave:Ae,nodesDraggable:et,nodesConnectable:Ve,elementsSelectable:Rt,multiSelectionKeyCode:wt,selectionOnDrag:kt,selectionMode:Ct,connectionMode:tn,connectionRadius:Tt,connectOnClick:nn,isValidConnection:rn,defaultEdgeOptions:on,snapToGrid:sn,snapGrid:$t,deleteKeyCode:ct,panActivationKeyCode:ut,panOnScroll:Et,panOnScrollMode:Mn,panOnScrollSpeed:Rn,zoomOnScroll:tt,zoomOnDoubleClick:er,zoomOnPinch:kn,preventScrolling:Cn,translateExtent:zt,nodeExtent:St,autoPanOnNodeDrag:En,autoPanOnConnect:zn,autoPanSpeed:Sn,edgesReconnectable:lt,elevateNodesOnSelect:ge,elevateEdgesOnSelect:Bt,noDragClassName:ze,noPanClassName:ie,onSelectionDragStart:dt,onSelectionDrag:K,onSelectionDragStop:ke,edgeRouting:an=!0,onHudUpdate:st,onNodesProcessed:Nt,showHud:Nn=!0,showHint:Pn=!0,hintText:He="Drag to pan · Scroll to zoom",children:Xe,...jt}){const[De,At]=u.useState({wx:0,wy:0,zoom:"1.00"}),Mt=u.useRef(null),Dt=u.useRef(null),In=u.useCallback(Q=>{At(Q),st==null||st(Q)},[st]),ft=u.useMemo(()=>({...ko,...r}),[r]),ht=u.useMemo(()=>({...Co,...a}),[a]),at=u.useMemo(()=>So(t),[t]),Ze=u.useMemo(()=>{const Q=t.filter($e=>$e.type&&ft[$e.type]);return Q.sort(($e,pe)=>{const Qe=$e.type==="group"||!$e.parentId&&Q.some(_e=>_e.parentId===$e.id),fe=pe.type==="group"||!pe.parentId&&Q.some(_e=>_e.parentId===pe.id);return Qe&&!fe?-1:!Qe&&fe?1:0})},[t,ft]),Pt=u.useMemo(()=>n.filter(Q=>Q.type&&ht[Q.type]),[n,ht]),Z=u.useMemo(()=>t.map(Q=>Q.type&&ft[Q.type]?{...Q,_customRendered:!0}:Q),[t,ft]),yt=u.useMemo(()=>n.map(Q=>Q.type&&ht[Q.type]?{...Q,_customRendered:!0}:Q),[n,ht]),{wrapRef:Ht,canvasRef:_t,canvasReady:Wt,onPointerDown:Ft,onPointerMove:Xt,onPointerUp:Yt,store:we}=xr({cards:e,nodes:Z,edges:yt,dark:o,gridSize:i,zoomMin:w,zoomMax:C,initialCamera:R,fitView:b,fitViewOptions:B,onHudUpdate:In,onNodesProcessed:Nt,onNodesChange:S,onEdgesChange:N,onConnect:X,onConnectStart:H,onConnectEnd:_,onNodeClick:j,onNodeDoubleClick:$,onNodeMouseEnter:A,onNodeMouseMove:W,onNodeMouseLeave:F,onNodeContextMenu:m,onNodeDragStart:f,onNodeDrag:M,onNodeDragStop:L,onEdgeClick:T,onEdgeDoubleClick:Y,onEdgeMouseEnter:J,onEdgeMouseMove:oe,onEdgeMouseLeave:V,onEdgeContextMenu:ee,onPaneClick:he,onPaneContextMenu:ne,onPaneMouseEnter:ce,onPaneMouseMove:ue,onPaneMouseLeave:Ie,onSelectionChange:le,onInit:me,onMoveStart:Le,onMove:ve,onMoveEnd:Re,onDelete:Pe,onBeforeDelete:Ee,onError:xe,nodesDraggable:et,nodesConnectable:Ve,elementsSelectable:Rt,multiSelectionKeyCode:wt,selectionOnDrag:kt,selectionMode:Ct,connectionMode:tn,connectionRadius:Tt,connectOnClick:nn,isValidConnection:rn,defaultEdgeOptions:on,snapToGrid:sn,snapGrid:$t,deleteKeyCode:ct,panActivationKeyCode:ut,panOnScroll:Et,panOnScrollMode:Mn,panOnScrollSpeed:Rn,zoomOnScroll:tt,zoomOnDoubleClick:er,zoomOnPinch:kn,preventScrolling:Cn,translateExtent:zt,nodeExtent:St,autoPanOnNodeDrag:En,autoPanOnConnect:zn,autoPanSpeed:Sn,edgesReconnectable:lt,elevateNodesOnSelect:ge,elevateEdgesOnSelect:Bt,noDragClassName:ze,noPanClassName:ie,onSelectionDragStart:dt,onSelectionDrag:K,onSelectionDragStop:ke,edgeRouting:an}),gt=u.useContext(Vt),It=gt&&typeof gt.getState=="function";u.useEffect(()=>{It&&queueMicrotask(()=>{gt.setState({nodes:at,edges:n,nodesRef:we.nodesRef,edgesRef:we.edgesRef,onNodesChangeRef:we.onNodesChangeRef,onEdgesChangeRef:we.onEdgesChangeRef,cameraRef:we.cameraRef,wrapRef:we.wrapRef,workerRef:we.workerRef})})},[It,at,n,we,gt]);const Se=u.useMemo(()=>({...we,edgeLabelContainerRef:Mt,viewportPortalRef:Dt,get nodes(){return at},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 Q;return((Q=we.wrapRef.current)==null?void 0:Q.clientWidth)||0},get height(){var Q;return((Q=we.wrapRef.current)==null?void 0:Q.clientHeight)||0}}),[we,at,n]),Te=u.useRef(null),nt=u.useRef(null),xt=u.useRef(null),Ge=u.useRef(null);u.useEffect(()=>{let Q;const $e=()=>{const pe=we.cameraRef.current,Qe=`translate(${pe.x}px, ${pe.y}px) scale(${pe.zoom})`,fe=`translate(${pe.x}, ${pe.y}) scale(${pe.zoom})`;Te.current&&(Te.current.style.transform=Qe),nt.current&&nt.current.setAttribute("transform",fe),xt.current&&(xt.current.style.transform=Qe),Ge.current&&(Ge.current.style.transform=Qe),Q=requestAnimationFrame($e)};return Q=requestAnimationFrame($e),()=>cancelAnimationFrame(Q)},[we]);const[rt,cn]=u.useState(null);u.useEffect(()=>{if(!Ze.length)return;let Q;const $e=()=>{var ln,dn;const pe=we.cameraRef.current,Qe=we.wrapRef.current;if(!Qe){Q=requestAnimationFrame($e);return}const fe=Qe.getBoundingClientRect(),_e=200,pt=-pe.x/pe.zoom-_e,Ln=-pe.y/pe.zoom-_e,Tn=(fe.width-pe.x)/pe.zoom+_e,$n=(fe.height-pe.y)/pe.zoom+_e,mt=new Set;for(const Ye of Ze){const vt=Ye._absolutePosition||Ye.position,Bn=Ye.width||((ln=Ye.measured)==null?void 0:ln.width)||200,jn=Ye.height||((dn=Ye.measured)==null?void 0:dn.height)||100;vt.x+Bn>=pt&&vt.x<=Tn&&vt.y+jn>=Ln&&vt.y<=$n&&mt.add(Ye.id)}cn(Ye=>{if(!Ye||Ye.size!==mt.size)return mt;for(const vt of mt)if(!Ye.has(vt))return mt;return Ye}),Q=requestAnimationFrame($e)};return Q=requestAnimationFrame($e),()=>cancelAnimationFrame(Q)},[Ze,we]);const Ne=u.useMemo(()=>rt?Ze.filter(Q=>rt.has(Q.id)):Ze,[Ze,rt]),Je=Ze.length>0,un=Pt.length>0;return E.jsx(Vt.Provider,{value:Se,children:E.jsxs("div",{ref:Ht,className:`ric-wrap ${d}`,style:{width:h,height:g,...y},onPointerDown:Ft,onPointerMove:Xt,onPointerUp:Yt,onDragOver:ae,onDrop:Fe,onDragEnter:bt,onDragLeave:Ae,tabIndex:0,children:[E.jsx("canvas",{ref:_t,className:"ric-canvas"}),!Wt&&E.jsx("div",{className:"ric-loader",children:E.jsx("div",{className:"ric-spinner"})}),un&&E.jsx("svg",{className:"ric-edges-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:E.jsx("g",{ref:nt,children:Pt.map(Q=>E.jsx(uo,{edge:Q,edgeType:ht[Q.type],nodes:t,reconnectable:lt},Q.id))})}),Je&&E.jsx("div",{ref:Te,className:"ric-nodes-overlay",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:10},children:Ne.map(Q=>E.jsx(so,{node:Q,nodeType:ft[Q.type]},Q.id))}),E.jsx("div",{ref:Q=>{Mt.current=Q,xt.current=Q},className:"ric-edge-labels",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:5}}),E.jsx("div",{ref:Q=>{Dt.current=Q,Ge.current=Q},className:"ric-viewport-portal",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:6}}),Pn&&E.jsx("div",{className:"ric-hint",children:He}),Nn&&E.jsxs("div",{className:"ric-info",children:["world: (",De.wx,", ",De.wy,") zoom: ",De.zoom,"x",De.nodeCount>0&&E.jsxs(E.Fragment,{children:[" nodes: ",De.nodeCount]}),De.edgeCount>0&&E.jsxs(E.Fragment,{children:[" edges: ",De.edgeCount]})]}),E.jsx(wr,{selectionKeyCode:wt||"Shift",selectionMode:Ct||"partial"}),Xe]})})}function Po({children:e}){const t=u.useRef(null);return t.current||(t.current=no()),E.jsx(Vt.Provider,{value:t.current,children:e})}function Pr(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 h={...o};for(const g of i)Io(g,h);n.push(h)}for(const o of a)o.index!==void 0?n.splice(o.index,0,{...o.item}):n.push({...o.item});return n}function Io(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 Ir(e,t){return Pr(e,t)}function Lr(e,t){return Pr(e,t)}function Lo(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 To(e){const[t,n]=u.useState(e),r=u.useCallback(a=>n(o=>Ir(a,o)),[]);return[t,n,r]}function $o(e){const[t,n]=u.useState(e),r=u.useCallback(a=>n(o=>Lr(a,o)),[]);return[t,n,r]}function Tr(){const e=pr(),t=u.useCallback(()=>typeof e.getState=="function"?e.getState():e,[e]),n=u.useCallback(()=>[...t().nodesRef.current],[t]),r=u.useCallback(()=>[...t().edgesRef.current],[t]),a=u.useCallback(m=>t().nodesRef.current.find(f=>f.id===m),[t]),o=u.useCallback(m=>t().edgesRef.current.find(f=>f.id===m),[t]),i=u.useCallback(m=>{var f,M,L,T;if(typeof m=="function"){const Y=m(t().nodesRef.current);(M=(f=t().onNodesChangeRef).current)==null||M.call(f,[...t().nodesRef.current.map(J=>({id:J.id,type:"remove"})),...Y.map(J=>({type:"add",item:J}))])}else(T=(L=t().onNodesChangeRef).current)==null||T.call(L,[...t().nodesRef.current.map(Y=>({id:Y.id,type:"remove"})),...m.map(Y=>({type:"add",item:Y}))])},[t]),h=u.useCallback(m=>{var f,M,L,T;if(typeof m=="function"){const Y=m(t().edgesRef.current);(M=(f=t().onEdgesChangeRef).current)==null||M.call(f,[...t().edgesRef.current.map(J=>({id:J.id,type:"remove"})),...Y.map(J=>({type:"add",item:J}))])}else(T=(L=t().onEdgesChangeRef).current)==null||T.call(L,[...t().edgesRef.current.map(Y=>({id:Y.id,type:"remove"})),...m.map(Y=>({type:"add",item:Y}))])},[t]),g=u.useCallback(m=>{var M,L;const f=Array.isArray(m)?m:[m];(L=(M=t().onNodesChangeRef).current)==null||L.call(M,f.map(T=>({type:"add",item:T})))},[t]),d=u.useCallback(m=>{var M,L;const f=Array.isArray(m)?m:[m];(L=(M=t().onEdgesChangeRef).current)==null||L.call(M,f.map(T=>({type:"add",item:T})))},[t]),y=u.useCallback(({nodes:m=[],edges:f=[]})=>{if(m.length&&t().onNodesChangeRef.current){t().onNodesChangeRef.current(m.map(L=>({id:L.id,type:"remove"})));const M=yr(m,t().edgesRef.current);M.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(M.map(L=>({id:L.id,type:"remove"})))}f.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(f.map(M=>({id:M.id,type:"remove"})))},[t]),w=u.useCallback(()=>{const m=t().cameraRef.current;return{x:m.x,y:m.y,zoom:m.zoom}},[t]),C=u.useRef(null),R=u.useCallback((m,f)=>{if(C.current&&cancelAnimationFrame(C.current),!f||f<=0){t().cameraRef.current={...m},t().sendCamera();return}const M={...t().cameraRef.current},L=performance.now(),T=Y=>{const J=Y-L,oe=Math.min(J/f,1),V=1-Math.pow(1-oe,3);t().cameraRef.current={x:M.x+(m.x-M.x)*V,y:M.y+(m.y-M.y)*V,zoom:M.zoom+(m.zoom-M.zoom)*V},t().sendCamera(),oe<1&&(C.current=requestAnimationFrame(T))};C.current=requestAnimationFrame(T)},[t]),b=u.useCallback((m,f)=>{const M={x:m.x??t().cameraRef.current.x,y:m.y??t().cameraRef.current.y,zoom:m.zoom??t().cameraRef.current.zoom};R(M,f==null?void 0:f.duration)},[t,R]),B=u.useCallback(()=>t().cameraRef.current.zoom,[t]),S=u.useCallback(m=>{const f=t().cameraRef.current,M=t().wrapRef.current;if(!M)return;const L=M.getBoundingClientRect(),T=L.width/2,Y=L.height/2,J=1.2,oe={x:T-(T-f.x)*J,y:Y-(Y-f.y)*J,zoom:Math.min(t().zoomMax,f.zoom*J)};R(oe,m==null?void 0:m.duration)},[t,R]),N=u.useCallback(m=>{const f=t().cameraRef.current,M=t().wrapRef.current;if(!M)return;const L=M.getBoundingClientRect(),T=L.width/2,Y=L.height/2,J=1/1.2,oe={x:T-(T-f.x)*J,y:Y-(Y-f.y)*J,zoom:Math.max(t().zoomMin,f.zoom*J)};R(oe,m==null?void 0:m.duration)},[t,R]),X=u.useCallback((m,f)=>{const M=t().cameraRef.current,L=t().wrapRef.current;if(!L)return;const T=L.getBoundingClientRect(),Y=T.width/2,J=T.height/2,oe=Math.min(t().zoomMax,Math.max(t().zoomMin,m)),V=oe/M.zoom,ee={x:Y-(Y-M.x)*V,y:J-(J-M.y)*V,zoom:oe};R(ee,f==null?void 0:f.duration)},[t,R]),H=u.useCallback((m={})=>{const f=t().nodesRef.current;if(!f.length)return;const M=t().wrapRef.current;if(!M)return;const L=M.getBoundingClientRect(),T=m.padding??.1,Y=m.nodes?f.filter(V=>m.nodes.some(ee=>ee.id===V.id)):f;if(!Y.length)return;const J=yn(Y),oe=Lt(J,L.width,L.height,T);m.maxZoom&&(oe.zoom=Math.min(oe.zoom,m.maxZoom)),m.minZoom&&(oe.zoom=Math.max(oe.zoom,m.minZoom)),R(oe,m.duration)},[t,R]),_=u.useCallback((m,f={})=>{const M=t().wrapRef.current;if(!M)return;const L=M.getBoundingClientRect(),T=f.padding??.1,Y=Lt(m,L.width,L.height,T);f.maxZoom&&(Y.zoom=Math.min(Y.zoom,f.maxZoom)),f.minZoom&&(Y.zoom=Math.max(Y.zoom,f.minZoom)),R(Y,f.duration)},[t,R]),j=u.useCallback((m,f,M={})=>{const L=t().wrapRef.current;if(!L)return;const T=L.getBoundingClientRect(),Y=M.zoom??t().cameraRef.current.zoom,J={x:T.width/2-m*Y,y:T.height/2-f*Y,zoom:Y};R(J,M.duration)},[t,R]),$=u.useCallback(()=>({nodes:[...t().nodesRef.current],edges:[...t().edgesRef.current],viewport:{...t().cameraRef.current}}),[t]),A=u.useCallback(m=>t().screenToWorld(m.x,m.y),[t]),W=u.useCallback(m=>{const f=t().cameraRef.current,M=t().wrapRef.current;if(!M)return{x:0,y:0};const L=M.getBoundingClientRect();return{x:m.x*f.zoom+f.x+L.left,y:m.y*f.zoom+f.y+L.top}},[t]),F=u.useCallback((m,f)=>{var T,Y;const M=t().nodesRef.current.find(J=>J.id===m);if(!M)return;const L=typeof f=="function"?f(M.data):{...M.data,...f};(Y=(T=t().onNodesChangeRef).current)==null||Y.call(T,[{id:m,type:"replace",item:{...M,data:L}}])},[t]);return{getNodes:n,getEdges:r,getNode:a,getEdge:o,setNodes:i,setEdges:h,addNodes:g,addEdges:d,deleteElements:y,getViewport:w,setViewport:b,getZoom:B,zoomIn:S,zoomOut:N,zoomTo:X,fitView:H,fitBounds:_,setCenter:j,screenToFlowPosition:A,flowToScreenPosition:W,updateNodeData:F,toObject:$}}function Bo(){return Me().nodes}function jo(){return Me().edges}function Ao(){return Me().viewport}function Do(){return Me().connection}function Ho(e){const t=Me(),n=Array.isArray(e)?e:[e];return u.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 _o(e){const t=Me();return u.useMemo(()=>t.edges.filter(n=>n.source===e||n.target===e),[t.edges,e])}function Wo({nodeId:e,type:t,handleId:n}){const r=Me();return u.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 Fo({onChange:e,onStart:t,onEnd:n}){const r=Me(),a=u.useRef(e),o=u.useRef(t),i=u.useRef(n);u.useEffect(()=>{a.current=e},[e]),u.useEffect(()=>{o.current=t},[t]),u.useEffect(()=>{i.current=n},[n]),u.useEffect(()=>{const h=g=>{var d;(d=a.current)==null||d.call(a,{x:g.x,y:g.y,zoom:g.zoom})};return r.viewportListeners.add(h),()=>r.viewportListeners.delete(h)},[s])}function Xo({onChange:e}){const t=Me(),n=u.useRef(e);u.useEffect(()=>{n.current=e},[e]),u.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 Yo(e){const[t,n]=u.useState(!1),r=Array.isArray(e)?e:[e];return u.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 Uo(){const e=Me();return u.useCallback(t=>{var n;(n=e.workerRef.current)==null||n.postMessage({type:"nodes",data:{nodes:[...s().nodesRef.current]}})},[s])}const qo=e=>{var t;return((t=e.nodes)==null?void 0:t.length)>0};function Oo(e={}){return Me(qo)}function Zo(e){const t=Me();return u.useMemo(()=>t.nodes.find(n=>n.id===e)||void 0,[t.nodes,e])}function Go(e,t){return Me(e,t)}function Qo(){return pr()}function Vo({maxHistorySize:e=100}={}){const t=Me(),n=u.useRef([]),r=u.useRef([]),[,a]=u.useState(0),o=u.useRef(null),i=u.useCallback(()=>{const d={nodes:s().nodesRef.current.map(y=>({...y,data:{...y.data}})),edges:s().edgesRef.current.map(y=>({...y}))};o.current&&JSON.stringify(o.current.nodes.map(y=>y.id))===JSON.stringify(d.nodes.map(y=>y.id))&&JSON.stringify(o.current.edges.map(y=>y.id))===JSON.stringify(d.edges.map(y=>y.id))||(n.current.push(d),n.current.length>e&&n.current.shift(),r.current=[],o.current=d,a(y=>y+1))},[t,e]),h=u.useCallback(()=>{var y,w,C,R;const d=n.current.pop();d&&(r.current.push({nodes:s().nodesRef.current.map(b=>({...b,data:{...b.data}})),edges:s().edgesRef.current.map(b=>({...b}))}),(w=(y=s().onNodesChangeRef).current)==null||w.call(y,[...s().nodesRef.current.map(b=>({id:b.id,type:"remove"})),...d.nodes.map(b=>({type:"add",item:b}))]),(R=(C=s().onEdgesChangeRef).current)==null||R.call(C,[...s().edgesRef.current.map(b=>({id:b.id,type:"remove"})),...d.edges.map(b=>({type:"add",item:b}))]),o.current=d,a(b=>b+1))},[s]),g=u.useCallback(()=>{var y,w,C,R;const d=r.current.pop();d&&(n.current.push({nodes:s().nodesRef.current.map(b=>({...b,data:{...b.data}})),edges:s().edgesRef.current.map(b=>({...b}))}),(w=(y=s().onNodesChangeRef).current)==null||w.call(y,[...s().nodesRef.current.map(b=>({id:b.id,type:"remove"})),...d.nodes.map(b=>({type:"add",item:b}))]),(R=(C=s().onEdgesChangeRef).current)==null||R.call(C,[...s().edgesRef.current.map(b=>({id:b.id,type:"remove"})),...d.edges.map(b=>({type:"add",item:b}))]),o.current=d,a(b=>b+1))},[s]);return{undo:h,redo:g,takeSnapshot:i,canUndo:n.current.length>0,canRedo:r.current.length>0}}function Jo(e){const t=u.useRef(e);return u.useEffect(()=>{t.current=e},[e]),u.useCallback(n=>r=>{const a=t.current(r);a!==!1&&a!=null&&n(Array.isArray(a)?a:r)},[])}function Ko(e){const t=u.useRef(e);return u.useEffect(()=>{t.current=e},[e]),u.useCallback(n=>r=>{const a=t.current(r);a!==!1&&a!=null&&n(Array.isArray(a)?a:r)},[])}const _n=160,Wn=60;function es({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 h=Me(),g=u.useRef(null),d=u.useRef(null),y=u.useCallback(()=>{const w=g.current;if(!w)return;const C=w.getContext("2d"),R=window.devicePixelRatio||1;w.width=e*R,w.height=t*R,C.scale(R,R),C.clearRect(0,0,e,t);const b=h.nodesRef.current;if(!b.length)return;let B=1/0,S=1/0,N=-1/0,X=-1/0;for(const f of b){const M=f.width||_n,L=f.height||Wn;f.position.x<B&&(B=f.position.x),f.position.y<S&&(S=f.position.y),f.position.x+M>N&&(N=f.position.x+M),f.position.y+L>X&&(X=f.position.y+L)}const H=40;B-=H,S-=H,N+=H,X+=H;const _=N-B,j=X-S,$=Math.min(e/_,t/j),A=(e-_*$)/2,W=(t-j*$)/2;for(const f of b){if(f.hidden)continue;const M=f.width||_n,L=f.height||Wn,T=(f.position.x-B)*$+A,Y=(f.position.y-S)*$+W,J=M*$,oe=L*$;C.fillStyle=f.selected?"#f59e0b":typeof n=="function"?n(f):n,C.fillRect(T,Y,Math.max(J,2),Math.max(oe,2))}const F=h.cameraRef.current,m=h.wrapRef.current;if(m){const f=m.getBoundingClientRect(),M=-F.x/F.zoom,L=-F.y/F.zoom,T=f.width/F.zoom,Y=f.height/F.zoom;C.fillStyle=a,C.fillRect(0,0,e,t);const J=(M-B)*$+A,oe=(L-S)*$+W,V=T*$,ee=Y*$;C.clearRect(J,oe,V,ee);for(const he of b){if(he.hidden)continue;const ne=he.width||_n,ce=he.height||Wn,ue=(he.position.x-B)*$+A,Ie=(he.position.y-S)*$+W;C.fillStyle=he.selected?"#f59e0b":typeof n=="function"?n(he):n,C.fillRect(ue,Ie,Math.max(ne*$,2),Math.max(ce*$,2))}C.strokeStyle="#3b82f6",C.lineWidth=1.5,C.strokeRect(J,oe,V,ee)}},[h,e,t,n,r,a]);return u.useEffect(()=>{let w=!0;function C(){w&&(y(),d.current=requestAnimationFrame(C))}const R=setInterval(()=>{cancelAnimationFrame(d.current),d.current=requestAnimationFrame(C)},66);return y(),()=>{w=!1,clearInterval(R),cancelAnimationFrame(d.current)}},[y]),E.jsx("canvas",{ref:g,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 ts(){return E.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:[E.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),E.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function ns(){return E.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:E.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function rs(){return E.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:E.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}function os(){return E.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:[E.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),E.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function ss(){return E.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:[E.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),E.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})}function Qt({children:e,className:t="",...n}){return E.jsx("button",{className:`ric-controls-button ${t}`,style:is,...n,children:e})}function as({showZoom:e=!0,showFitView:t=!0,showInteractive:n=!1,fitViewOptions:r,onZoomIn:a,onZoomOut:o,onFitView:i,onInteractiveChange:h,position:g="bottom-left",orientation:d="vertical",style:y={},className:w="","aria-label":C="Canvas controls",children:R}){const b=Me(),{zoomIn:B,zoomOut:S,fitView:N,getZoom:X}=Tr(),[H,_]=u.useState(!0),j=X()<=b.zoomMin,$=X()>=b.zoomMax,A=u.useCallback(()=>{B(),a==null||a()},[B,a]),W=u.useCallback(()=>{S(),o==null||o()},[S,o]),F=u.useCallback(()=>{N(r||{padding:.1}),i==null||i()},[N,r,i]),m=u.useCallback(()=>{const M=!H;_(M),h==null||h(M)},[H,h]),f={"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%)"}}[g]||{bottom:30,left:10};return E.jsxs("div",{className:`ric-controls ${w}`,style:{position:"absolute",display:"flex",flexDirection:d==="horizontal"?"row":"column",gap:2,zIndex:5,...f,...y},role:"toolbar","aria-label":C,children:[e&&E.jsxs(E.Fragment,{children:[E.jsx(Qt,{onClick:A,disabled:$,title:"Zoom in","aria-label":"Zoom in",className:"ric-controls-zoomin",children:E.jsx(ts,{})}),E.jsx(Qt,{onClick:W,disabled:j,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:E.jsx(ns,{})})]}),t&&E.jsx(Qt,{onClick:F,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:E.jsx(rs,{})}),n&&E.jsx(Qt,{onClick:m,title:H?"Lock interactivity":"Unlock interactivity","aria-label":H?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:H?E.jsx(ss,{}):E.jsx(os,{})}),R]})}const is={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},cs=u.memo(as);function us({variant:e="lines",gap:t=40,size:n=1,color:r,style:a={},className:o=""}){const i=Me();return i.workerRef.current&&i.workerRef.current.postMessage({type:"background",data:{variant:e,gap:t,size:n,color:r}}),null}function ls({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 E.jsx("div",{className:`ric-panel ${n}`,style:{position:"absolute",zIndex:5,pointerEvents:"all",...a,...t},onPointerDown:o=>o.stopPropagation(),children:r})}function ds({minWidth:e=10,minHeight:t=10,maxWidth:n=1/0,maxHeight:r=1/0,isVisible:a=!0,handleStyle:o={},lineStyle:i={},color:h="#3b82f6",onResizeStart:g,onResize:d,onResizeEnd:y}){const w=u.useContext(Kt),C=Me(),R=u.useRef(null),b=u.useCallback((N,X)=>{N.stopPropagation(),N.preventDefault();const H=C.nodesRef.current.find($=>$.id===w);if(!H)return;R.current={direction:X,startX:N.clientX,startY:N.clientY,width:H.width||160,height:H.height||60},g==null||g(N,{width:R.current.width,height:R.current.height});const _=$=>{var L,T;if(!R.current)return;const A=R.current,W=C.cameraRef.current,F=($.clientX-A.startX)/W.zoom,m=($.clientY-A.startY)/W.zoom;let f=A.width,M=A.height;A.direction.includes("e")&&(f=Math.min(n,Math.max(e,A.width+F))),A.direction.includes("w")&&(f=Math.min(n,Math.max(e,A.width-F))),A.direction.includes("s")&&(M=Math.min(r,Math.max(t,A.height+m))),A.direction.includes("n")&&(M=Math.min(r,Math.max(t,A.height-m))),(T=(L=C.onNodesChangeRef).current)==null||T.call(L,[{id:w,type:"dimensions",dimensions:{width:f,height:M},setAttributes:!0}]),d==null||d($,{width:f,height:M})},j=$=>{R.current=null,y==null||y($,{}),window.removeEventListener("pointermove",_),window.removeEventListener("pointerup",j)};window.addEventListener("pointermove",_),window.addEventListener("pointerup",j)},[w,C,e,t,n,r,g,d,y]);if(!a)return null;const B=8,S={position:"absolute",width:B,height:B,background:h,border:"1px solid #fff",borderRadius:2,zIndex:20,...o};return E.jsxs(E.Fragment,{children:[E.jsx("div",{style:{...S,bottom:-B/2,right:-B/2,cursor:"nwse-resize"},onPointerDown:N=>b(N,"se")}),E.jsx("div",{style:{...S,bottom:-B/2,left:-B/2,cursor:"nesw-resize"},onPointerDown:N=>b(N,"sw")}),E.jsx("div",{style:{...S,top:-B/2,right:-B/2,cursor:"nesw-resize"},onPointerDown:N=>b(N,"ne")}),E.jsx("div",{style:{...S,top:-B/2,left:-B/2,cursor:"nwse-resize"},onPointerDown:N=>b(N,"nw")}),E.jsx("div",{style:{...S,top:"50%",right:-B/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:N=>b(N,"e")}),E.jsx("div",{style:{...S,top:"50%",left:-B/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:N=>b(N,"w")}),E.jsx("div",{style:{...S,left:"50%",top:-B/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:N=>b(N,"n")}),E.jsx("div",{style:{...S,left:"50%",bottom:-B/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:N=>b(N,"s")})]})}function fs({isVisible:e,position:t="top",offset:n=10,align:r="center",children:a,style:o={},className:i=""}){const h=u.useContext(Kt),d=Me().nodes.find(C=>C.id===h);if(!(e!==void 0?e:d==null?void 0:d.selected))return null;const w={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 E.jsx("div",{className:`ric-node-toolbar ${i}`,style:{position:"absolute",zIndex:1e3,pointerEvents:"all",...w,...o},onPointerDown:C=>C.stopPropagation(),children:a})}function hs({isVisible:e=!1,x:t=0,y:n=0,alignX:r="center",alignY:a="center",children:o,style:i={},className:h=""}){if(!e)return null;const g=r==="center"?"-50%":r==="right"?"-100%":"0",d=a==="center"?"-50%":a==="bottom"?"-100%":"0";return E.jsx("div",{className:`ric-edge-toolbar ${h}`,style:{position:"absolute",left:t,top:n,transform:`translate(${g}, ${d})`,zIndex:1e3,pointerEvents:"all",...i},children:o})}function ys({children:e}){var r;const n=(r=Me().edgeLabelContainerRef)==null?void 0:r.current;return n?dr.createPortal(e,n):null}function gs({children:e}){var r;const n=(r=Me().viewportPortalRef)==null?void 0:r.current;return n?dr.createPortal(e,n):null}function $r({fromX:e,fromY:t,toX:n,toY:r,fromPosition:a="right",toPosition:o="left",connectionLineType:i="default",connectionLineStyle:h,connectionLineComponent:g}){if(g)return E.jsx(g,{fromX:e,fromY:t,toX:n,toY:r,fromPosition:a,toPosition:o});let d;switch(i){case"straight":[d]=On({sourceX:e,sourceY:t,targetX:n,targetY:r});break;case"step":[d]=gn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o,borderRadius:0});break;case"smoothstep":[d]=gn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o});break;case"simplebezier":[d]=Gn({sourceX:e,sourceY:t,targetX:n,targetY:r});break;default:[d]=Zn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o});break}return E.jsx("path",{d,fill:"none",className:"ric-connection-line",stroke:"#b1b1b7",strokeWidth:1.5,style:h})}$r.displayName="ConnectionLine";const xs=u.memo($r),ps=Object.freeze({Top:"top",Bottom:"bottom",Left:"left",Right:"right"}),ms=Object.freeze({Arrow:"arrow",ArrowClosed:"arrowclosed"});function vs(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=us;exports.BaseEdge=en;exports.BezierEdge=qn;exports.ConnectionLine=xs;exports.ControlButton=Qt;exports.Controls=cs;exports.DefaultNode=fo;exports.EdgeLabelRenderer=ys;exports.EdgeText=zr;exports.EdgeToolbar=hs;exports.GroupNode=Cr;exports.Handle=Jt;exports.InfiniteCanvas=No;exports.InfiniteCanvasProvider=Po;exports.InputNode=Rr;exports.MarkerType=ms;exports.MiniMap=es;exports.NodeResizer=ds;exports.NodeToolbar=fs;exports.OutputNode=kr;exports.Panel=ls;exports.Position=ps;exports.SelectionBox=wr;exports.SimpleBezierEdge=Kn;exports.SmoothStepEdge=Jn;exports.StepEdge=Nr;exports.StraightEdge=Vn;exports.ViewportPortal=gs;exports.addEdge=Lo;exports.applyEdgeChanges=Lr;exports.applyNodeChanges=Ir;exports.boxToRect=Ur;exports.buildObstacles=Qn;exports.clampPosition=Xn;exports.computeRoutedEdges=Mo;exports.getBezierEdgeCenter=ho;exports.getBezierPath=Zn;exports.getBoundsOfBoxes=qr;exports.getConnectedEdges=yr;exports.getEdgeCenter=yo;exports.getIncomers=Wr;exports.getNodeDimensions=Un;exports.getNodesBounds=yn;exports.getNodesInside=Xr;exports.getOutgoers=Fr;exports.getOverlappingArea=Or;exports.getRoutedLabelPosition=wn;exports.getSimpleBezierPath=Gn;exports.getSmoothStepPath=gn;exports.getStraightPath=On;exports.getViewportForBounds=Lt;exports.isEdge=_r;exports.isNode=Hr;exports.nodeToBox=vs;exports.nodeToRect=Zr;exports.reconnectEdge=go;exports.rectToBox=Yr;exports.routeSinglePath=Ro;exports.routedPointsToPath=bn;exports.snapPosition=Fn;exports.useConnection=Do;exports.useEdges=jo;exports.useEdgesState=$o;exports.useHandleConnections=Wo;exports.useInfiniteCanvas=xr;exports.useInternalNode=Zo;exports.useKeyPress=Yo;exports.useNodeConnections=_o;exports.useNodeId=ro;exports.useNodes=Bo;exports.useNodesData=Ho;exports.useNodesInitialized=Oo;exports.useNodesState=To;exports.useOnEdgesChangeMiddleware=Ko;exports.useOnNodesChangeMiddleware=Jo;exports.useOnSelectionChange=Xo;exports.useOnViewportChange=Fo;exports.useReactFlow=Tr;exports.useStore=Go;exports.useStoreApi=Qo;exports.useUndoRedo=Vo;exports.useUpdateNodeInternals=Uo;exports.useViewport=Ao;
|