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