@infinit-canvas/react 0.1.18 → 0.1.20

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.
@@ -1,8 +1,8 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("react/jsx-runtime"),l=require("react"),pr=require("react-dom"),mr=160,vr=60;function Xr(e){return e&&typeof e=="object"&&"position"in e&&"data"in e}function Or(e){return e&&typeof e=="object"&&"source"in e&&"target"in e}function br(e,t){const n=typeof e=="string"?new Set([e]):new Set(Array.isArray(e)?e.map(r=>r.id):[e.id]);return t.filter(r=>n.has(r.source)||n.has(r.target))}function Ur(e,t,n){const r=typeof e=="string"?e:e.id,a=new Set;for(const o of n)o.target===r&&a.add(o.source);return t.filter(o=>a.has(o.id))}function qr(e,t,n){const r=typeof e=="string"?e:e.id,a=new Set;for(const o of n)o.source===r&&a.add(o.target);return t.filter(o=>a.has(o.id))}function Rn(e){if(!e.length)return{x:0,y:0,width:0,height:0};let t=1/0,n=1/0,r=-1/0,a=-1/0;for(const o of e){const c=o.position.x,f=o.position.y,m=o.width||mr,d=o.height||vr;c<t&&(t=c),f<n&&(n=f),c+m>r&&(r=c+m),f+d>a&&(a=f+d)}return{x:t,y:n,width:r-t,height:a-n}}function Zt(e,t,n,r=.1){const a=e.width*(1+r*2),o=e.height*(1+r*2),c=Math.min(t/a,n/o,1),f=e.x+e.width/2,m=e.y+e.height/2;return{x:t/2-f*c,y:n/2-m*c,zoom:c}}function Zn(e,t){return{x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}}function Gn(e,t){return{x:Math.min(Math.max(e.x,t[0][0]),t[1][0]),y:Math.min(Math.max(e.y,t[0][1]),t[1][1])}}function Kn(e){var t,n;return{width:e.width||((t=e.measured)==null?void 0:t.width)||mr,height:e.height||((n=e.measured)==null?void 0:n.height)||vr}}function Zr(e,t,n={x:0,y:0,zoom:1},r=!1){const a=t.x,o=t.y,c=t.x+t.width,f=t.y+t.height;return e.filter(m=>{const{width:d,height:g}=Kn(m),b=m.position.x,E=m.position.y,C=b+d,S=E+g;return r?b<c&&C>a&&E<f&&S>o:b>=a&&C<=c&&E>=o&&S<=f})}function Gr(e){return{x:e.x,y:e.y,x2:e.x+e.width,y2:e.y+e.height}}function Qr(e){return{x:e.x,y:e.y,width:e.x2-e.x,height:e.y2-e.y}}function Vr(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}}function Jr(e,t){const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return n*r}function Kr(e){const{width:t,height:n}=Kn(e);return{x:e.position.x,y:e.position.y,width:t,height:n}}const wr=`var Pa = null, r = null, tr = 0, or = 0, g = { x: 0, y: 0, zoom: 1 }, Y = [], G = [], q = [], $ = !1, Wt = 40, _t = !1, Fr = "lines", ha = 1, Pe = null, ee = null, xr = null, Ce = {}, Xo = {}, te = {}, We = {}, L = 160, B = 60, qa = 8, Fo = 5;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("react/jsx-runtime"),c=require("react"),pr=require("react-dom"),mr=160,vr=60;function Xr(e){return e&&typeof e=="object"&&"position"in e&&"data"in e}function Or(e){return e&&typeof e=="object"&&"source"in e&&"target"in e}function br(e,t){const n=typeof e=="string"?new Set([e]):new Set(Array.isArray(e)?e.map(r=>r.id):[e.id]);return t.filter(r=>n.has(r.source)||n.has(r.target))}function Ur(e,t,n){const r=typeof e=="string"?e:e.id,i=new Set;for(const o of n)o.target===r&&i.add(o.source);return t.filter(o=>i.has(o.id))}function qr(e,t,n){const r=typeof e=="string"?e:e.id,i=new Set;for(const o of n)o.source===r&&i.add(o.target);return t.filter(o=>i.has(o.id))}function Rn(e){if(!e.length)return{x:0,y:0,width:0,height:0};let t=1/0,n=1/0,r=-1/0,i=-1/0;for(const o of e){const a=o.position.x,f=o.position.y,p=o.width||mr,d=o.height||vr;a<t&&(t=a),f<n&&(n=f),a+p>r&&(r=a+p),f+d>i&&(i=f+d)}return{x:t,y:n,width:r-t,height:i-n}}function qt(e,t,n,r=.1){const i=e.width*(1+r*2),o=e.height*(1+r*2),a=Math.min(t/i,n/o,1),f=e.x+e.width/2,p=e.y+e.height/2;return{x:t/2-f*a,y:n/2-p*a,zoom:a}}function Zn(e,t){return{x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}}function Gn(e,t){return{x:Math.min(Math.max(e.x,t[0][0]),t[1][0]),y:Math.min(Math.max(e.y,t[0][1]),t[1][1])}}function Vn(e){var t,n;return{width:e.width||((t=e.measured)==null?void 0:t.width)||mr,height:e.height||((n=e.measured)==null?void 0:n.height)||vr}}function Zr(e,t,n={x:0,y:0,zoom:1},r=!1){const i=t.x,o=t.y,a=t.x+t.width,f=t.y+t.height;return e.filter(p=>{const{width:d,height:h}=Vn(p),k=p.position.x,S=p.position.y,E=k+d,z=S+h;return r?k<a&&E>i&&S<f&&z>o:k>=i&&E<=a&&S>=o&&z<=f})}function Gr(e){return{x:e.x,y:e.y,x2:e.x+e.width,y2:e.y+e.height}}function Qr(e){return{x:e.x,y:e.y,width:e.x2-e.x,height:e.y2-e.y}}function Jr(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}}function Kr(e,t){const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return n*r}function Vr(e){const{width:t,height:n}=Vn(e);return{x:e.position.x,y:e.position.y,width:t,height:n}}const wr=`var Pa = null, r = null, or = 0, lr = 0, M = { x: 0, y: 0, zoom: 1 }, Y = [], C = [], Z = [], F = !1, Zt = 40, Ct = !1, Fr = "lines", ua = 1, Ze = null, oe = null, gr = null, Ge = {}, el = {}, le = {}, Ie = {}, Kt = 0, L = 160, B = 60, qa = 8, Oo = 5;
2
2
  function d(a) {
3
3
  return a._absolutePosition || a.position;
4
4
  }
5
- function Jl(a, e, t, l, f) {
5
+ function Ul(a, e, t, l, f) {
6
6
  if (a.x !== void 0 && a.y !== void 0)
7
7
  return { x: e + a.x, y: t + a.y };
8
8
  var o = a.position || (a.type === "source" ? "right" : "left");
@@ -19,16 +19,16 @@ function Jl(a, e, t, l, f) {
19
19
  return { x: e + l, y: t + f / 2 };
20
20
  }
21
21
  }
22
- function Ho(a) {
22
+ function tl(a) {
23
23
  var e = a.width || L, t = a.height || B;
24
24
  if (a.handles && a.handles.length > 0)
25
- return a.handles.map(function(u) {
26
- var M = Jl(u, d(a).x, d(a).y, e, t);
27
- return { id: u.id || null, type: u.type, x: M.x, y: M.y, position: u.position };
25
+ return a.handles.map(function(h) {
26
+ var g = Ul(h, d(a).x, d(a).y, e, t);
27
+ return { id: h.id || null, type: h.type, x: g.x, y: g.y, position: h.position };
28
28
  });
29
29
  var l = a.targetPosition || "left", f = a.sourcePosition || "right", o = d(a);
30
- function i(u) {
31
- switch (u) {
30
+ function i(h) {
31
+ switch (h) {
32
32
  case "top":
33
33
  return { x: o.x + e / 2, y: o.y };
34
34
  case "bottom":
@@ -47,14 +47,14 @@ function Ho(a) {
47
47
  { id: null, type: "source", x: x.x, y: x.y, position: f }
48
48
  ];
49
49
  }
50
- var Et = {}, fe = !0;
51
- function Ql(a) {
52
- fe && (Et = {}, fe = !1);
53
- var e = Et[a.id];
54
- return e || (e = Ho(a), Et[a.id] = e, e);
50
+ var Wt = {}, he = !0;
51
+ function Vl(a) {
52
+ he && (Wt = {}, he = !1);
53
+ var e = Wt[a.id];
54
+ return e || (e = tl(a), Wt[a.id] = e, e);
55
55
  }
56
- function qe(a, e, t) {
57
- for (var l = Ql(a), f = 0; f < l.length; f++)
56
+ function Ke(a, e, t) {
57
+ for (var l = Vl(a), f = 0; f < l.length; f++)
58
58
  if (l[f].type === e)
59
59
  if (t) {
60
60
  if (l[f].id === t) return l[f];
@@ -64,22 +64,22 @@ function qe(a, e, t) {
64
64
  return e === "source" ? { x: d(a).x + o, y: d(a).y + i / 2 } : { x: d(a).x, y: d(a).y + i / 2 };
65
65
  }
66
66
  var k = {};
67
- function Pt() {
67
+ function bt() {
68
68
  k = {
69
- grid: $ ? "rgba(255,255,255,0.07)" : "rgba(0,0,0,0.07)",
70
- origin: $ ? "rgba(255,255,255,0.2)" : "rgba(0,0,0,0.15)",
71
- cardBg: $ ? "#2a2a28" : "#ffffff",
72
- cardBorder: $ ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.1)",
73
- cardShadow: $ ? "rgba(0,0,0,0.3)" : "rgba(0,0,0,0.06)",
69
+ grid: F ? "rgba(255,255,255,0.07)" : "rgba(0,0,0,0.07)",
70
+ origin: F ? "rgba(255,255,255,0.2)" : "rgba(0,0,0,0.15)",
71
+ cardBg: F ? "#2a2a28" : "#ffffff",
72
+ cardBorder: F ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.1)",
73
+ cardShadow: F ? "rgba(0,0,0,0.3)" : "rgba(0,0,0,0.06)",
74
74
  titleText: "rgba(255,255,255,0.9)",
75
- bodyText: $ ? "rgba(255,255,255,0.55)" : "rgba(0,0,0,0.5)",
76
- coordText: $ ? "rgba(255,255,255,0.25)" : "rgba(0,0,0,0.2)",
77
- nodeBg: $ ? "#1e1e2e" : "#ffffff",
78
- nodeBorder: $ ? "rgba(255,255,255,0.15)" : "rgba(0,0,0,0.15)",
75
+ bodyText: F ? "rgba(255,255,255,0.55)" : "rgba(0,0,0,0.5)",
76
+ coordText: F ? "rgba(255,255,255,0.25)" : "rgba(0,0,0,0.2)",
77
+ nodeBg: F ? "#1e1e2e" : "#ffffff",
78
+ nodeBorder: F ? "rgba(255,255,255,0.15)" : "rgba(0,0,0,0.15)",
79
79
  nodeSelectedBorder: "#3b82f6",
80
- nodeShadow: $ ? "rgba(0,0,0,0.4)" : "rgba(0,0,0,0.08)",
81
- nodeText: $ ? "rgba(255,255,255,0.9)" : "rgba(0,0,0,0.85)",
82
- edgeStroke: $ ? "rgba(255,255,255,0.35)" : "rgba(0,0,0,0.3)",
80
+ nodeShadow: F ? "rgba(0,0,0,0.4)" : "rgba(0,0,0,0.08)",
81
+ nodeText: F ? "rgba(255,255,255,0.9)" : "rgba(0,0,0,0.85)",
82
+ edgeStroke: F ? "rgba(255,255,255,0.35)" : "rgba(0,0,0,0.3)",
83
83
  edgeSelected: "#3b82f6",
84
84
  edgeAnimated: "#3b82f6",
85
85
  handleFill: "#ffffff",
@@ -87,99 +87,99 @@ function Pt() {
87
87
  connectionLine: "#3b82f6"
88
88
  }, Ia = !0;
89
89
  }
90
- Pt();
91
- var $l = ["#534AB7", "#0F6E56", "#993C1D", "#185FA5"], ae = 8, Fl = "500 11px system-ui, sans-serif", Ul = "400 11px system-ui, sans-serif", cl = "10px monospace", Uo = "500 13px system-ui, sans-serif", Vl = "400 11px system-ui, sans-serif", Ur = 400, oe = {}, Ge = !0;
92
- function Nl() {
93
- oe = {};
90
+ bt();
91
+ var Nl = ["#534AB7", "#0F6E56", "#993C1D", "#185FA5"], te = 8, Ol = "500 11px system-ui, sans-serif", Dl = "400 11px system-ui, sans-serif", jl = "10px monospace", Do = "500 13px system-ui, sans-serif", Yl = "400 11px system-ui, sans-serif", cr = 400, ie = {}, be = !0;
92
+ function Xl() {
93
+ ie = {};
94
94
  for (var a = 0; a < Y.length; a++)
95
- for (var e = Y[a], t = Math.floor(e.x / Ur), l = Math.floor(e.y / Ur), f = Math.floor((e.x + e.w) / Ur), o = Math.floor((e.y + e.h) / Ur), i = t; i <= f; i++)
95
+ for (var e = Y[a], t = Math.floor(e.x / cr), l = Math.floor(e.y / cr), f = Math.floor((e.x + e.w) / cr), o = Math.floor((e.y + e.h) / cr), i = t; i <= f; i++)
96
96
  for (var y = l; y <= o; y++) {
97
97
  var x = i + "," + y;
98
- oe[x] || (oe[x] = []), oe[x].push(a);
98
+ ie[x] || (ie[x] = []), ie[x].push(a);
99
99
  }
100
- Ge = !1;
100
+ be = !1;
101
101
  }
102
- function co(a, e, t, l) {
103
- Ge && Nl();
104
- for (var f = {}, o = [], i = Math.floor(a / Ur), y = Math.floor(e / Ur), x = Math.floor(t / Ur), u = Math.floor(l / Ur), M = i; M <= x; M++)
105
- for (var v = y; v <= u; v++) {
106
- var n = M + "," + v, s = oe[n];
107
- if (s)
108
- for (var h = 0; h < s.length; h++) {
109
- var T = s[h];
110
- f[T] || (f[T] = !0, o.push(T));
102
+ function jo(a, e, t, l) {
103
+ be && Xl();
104
+ for (var f = {}, o = [], i = Math.floor(a / cr), y = Math.floor(e / cr), x = Math.floor(t / cr), h = Math.floor(l / cr), g = i; g <= x; g++)
105
+ for (var v = y; v <= h; v++) {
106
+ var n = g + "," + v, u = ie[n];
107
+ if (u)
108
+ for (var s = 0; s < u.length; s++) {
109
+ var m = u[s];
110
+ f[m] || (f[m] = !0, o.push(m));
111
111
  }
112
112
  }
113
113
  return o;
114
114
  }
115
- var cr = 500, le = {}, ua = !0;
116
- function Zt() {
117
- le = {};
118
- for (var a = 0; a < G.length; a++) {
119
- var e = G[a];
115
+ var Ur = 500, fe = {}, sa = !0;
116
+ function Ft() {
117
+ fe = {};
118
+ for (var a = 0; a < C.length; a++) {
119
+ var e = C[a];
120
120
  if (!e.hidden)
121
- for (var t = d(e), l = e.width || L, f = e.height || B, o = Math.floor(t.x / cr), i = Math.floor(t.y / cr), y = Math.floor((t.x + l) / cr), x = Math.floor((t.y + f) / cr), u = o; u <= y; u++)
122
- for (var M = i; M <= x; M++) {
123
- var v = u + "," + M;
124
- le[v] || (le[v] = []), le[v].push(a);
121
+ for (var t = d(e), l = e.width || L, f = e.height || B, o = Math.floor(t.x / Ur), i = Math.floor(t.y / Ur), y = Math.floor((t.x + l) / Ur), x = Math.floor((t.y + f) / Ur), h = o; h <= y; h++)
122
+ for (var g = i; g <= x; g++) {
123
+ var v = h + "," + g;
124
+ fe[v] || (fe[v] = []), fe[v].push(a);
125
125
  }
126
126
  }
127
- ua = !1;
127
+ sa = !1;
128
128
  }
129
- function po(a, e, t, l) {
130
- ua && Zt();
131
- for (var f = {}, o = [], i = Math.floor(a / cr), y = Math.floor(e / cr), x = Math.floor(t / cr), u = Math.floor(l / cr), M = i; M <= x; M++)
132
- for (var v = y; v <= u; v++) {
133
- var n = M + "," + v, s = le[n];
134
- if (s)
135
- for (var h = 0; h < s.length; h++) {
136
- var T = s[h];
137
- f[T] || (f[T] = !0, o.push(T));
129
+ function ol(a, e, t, l) {
130
+ sa && Ft();
131
+ for (var f = {}, o = [], i = Math.floor(a / Ur), y = Math.floor(e / Ur), x = Math.floor(t / Ur), h = Math.floor(l / Ur), g = i; g <= x; g++)
132
+ for (var v = y; v <= h; v++) {
133
+ var n = g + "," + v, u = fe[n];
134
+ if (u)
135
+ for (var s = 0; s < u.length; s++) {
136
+ var m = u[s];
137
+ f[m] || (f[m] = !0, o.push(m));
138
138
  }
139
139
  }
140
140
  return o;
141
141
  }
142
- var sa = {}, na = !0;
143
- function Ie() {
144
- sa = {};
145
- for (var a = 0; a < G.length; a++)
146
- sa[G[a].id] = G[a];
142
+ var da = {}, na = !0;
143
+ function Je() {
144
+ da = {};
145
+ for (var a = 0; a < C.length; a++)
146
+ da[C[a].id] = C[a];
147
147
  na = !1;
148
148
  }
149
- function Vo(a) {
150
- return na && Ie(), sa[a];
149
+ function Yo(a) {
150
+ return na && Je(), da[a];
151
151
  }
152
- var $r = {}, Ze = !0;
153
- function Dl() {
154
- $r = {};
155
- for (var a = 0; a < q.length; a++) {
156
- var e = q[a];
157
- $r[e.source] || ($r[e.source] = []), $r[e.source].push(a), e.source !== e.target && ($r[e.target] || ($r[e.target] = []), $r[e.target].push(a));
152
+ var wr = {}, Qe = !0;
153
+ function Hl() {
154
+ wr = {};
155
+ for (var a = 0; a < Z.length; a++) {
156
+ var e = Z[a];
157
+ wr[e.source] || (wr[e.source] = []), wr[e.source].push(a), e.source !== e.target && (wr[e.target] || (wr[e.target] = []), wr[e.target].push(a));
158
158
  }
159
- Ze = !1;
159
+ Qe = !1;
160
160
  }
161
- var va = null, rl = 0, al = 0, el = "", Ia = !0;
162
- function Ol(a) {
163
- va || (va = new OffscreenCanvas(1, 1));
161
+ var ha = null, ll = 0, il = 0, fl = "", Ia = !0;
162
+ function pl(a) {
163
+ ha || (ha = new OffscreenCanvas(1, 1));
164
164
  var e = Math.ceil(a), t = Math.ceil(a);
165
165
  if (e < 2 || t < 2) return !1;
166
- e > 512 && (e = 512), t > 512 && (t = 512), va.width = e, va.height = t, rl = e, al = a, el = Fr, Ia = !1;
167
- var l = va.getContext("2d");
166
+ e > 512 && (e = 512), t > 512 && (t = 512), ha.width = e, ha.height = t, ll = e, il = a, fl = Fr, Ia = !1;
167
+ var l = ha.getContext("2d");
168
168
  l.clearRect(0, 0, e, t);
169
- var f = Pe || k.grid;
169
+ var f = Ze || k.grid;
170
170
  if (Fr === "dots") {
171
171
  l.fillStyle = f;
172
- var o = ha * g.zoom;
172
+ var o = ua * M.zoom;
173
173
  l.beginPath(), l.arc(0, 0, o, 0, 6.2832), l.fill();
174
174
  } else if (Fr === "cross") {
175
- l.strokeStyle = f, l.lineWidth = ha;
176
- var i = 3 * g.zoom;
175
+ l.strokeStyle = f, l.lineWidth = ua;
176
+ var i = 3 * M.zoom;
177
177
  l.beginPath(), l.moveTo(-i, 0), l.lineTo(i, 0), l.moveTo(0, -i), l.lineTo(0, i), l.stroke();
178
178
  } else
179
- l.beginPath(), l.strokeStyle = f, l.lineWidth = ha * 0.5, l.moveTo(0.5, 0), l.lineTo(0.5, t), l.moveTo(0, 0.5), l.lineTo(e, 0.5), l.stroke();
179
+ l.beginPath(), l.strokeStyle = f, l.lineWidth = ua * 0.5, l.moveTo(0.5, 0), l.lineTo(0.5, t), l.moveTo(0, 0.5), l.lineTo(e, 0.5), l.stroke();
180
180
  return !0;
181
181
  }
182
- var No = 0, Lt = 0, Do = 0, Oo = 0, qt = 0, ie = !1;
182
+ var Xo = 0, Pt = 0, Ho = 0, po = 0, Jt = 0, ve = !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,121 +187,121 @@ self.onmessage = function(a) {
187
187
  var e = a.data.type, t = a.data.data;
188
188
  switch (e) {
189
189
  case "init":
190
- Pa = t.canvas, r = Pa.getContext("2d"), tr = t.width, or = t.height, Pa.width = tr, Pa.height = or, g = t.camera, Y = t.cards || [], G = t.nodes || [], q = t.edges || [], $ = t.dark, t.gridSize && (Wt = t.gridSize), t.edgeRouting !== void 0 && (Ga = !!t.edgeRouting), Pt(), Ge = !0, na = !0, ua = !0, fe = !0, Ze = !0, ie = q.some(function(A) {
191
- return A.animated;
192
- }), console.log("[worker] init done — canvas:", tr, "x", or, "| cards:", Y.length, "| nodes:", G.length, "| edges:", q.length, "| routing:", Ga), Ke(), self.postMessage({ type: "ready" }), ie && jo();
190
+ Pa = t.canvas, r = Pa.getContext("2d"), or = t.width, lr = t.height, Pa.width = or, Pa.height = lr, M = t.camera, Y = t.cards || [], C = t.nodes || [], Z = t.edges || [], F = t.dark, t.gridSize && (Zt = t.gridSize), t.edgeRouting !== void 0 && (Ga = !!t.edgeRouting), bt(), be = !0, na = !0, sa = !0, he = !0, Qe = !0, ve = Z.some(function(W) {
191
+ return W.animated;
192
+ }), console.log("[worker] init done — canvas:", or, "x", lr, "| cards:", Y.length, "| nodes:", C.length, "| edges:", Z.length, "| routing:", Ga), $e(), self.postMessage({ type: "ready" }), ve && rl();
193
193
  break;
194
194
  case "resize":
195
- tr = t.width, or = t.height, Pa.width = tr, Pa.height = or, Ia = !0, Ke();
195
+ or = t.width, lr = t.height, Pa.width = or, Pa.height = lr, Ia = !0, $e();
196
196
  break;
197
197
  case "camera":
198
- g = t.camera, Ia = !0, Q();
198
+ M = t.camera, Ia = !0, $();
199
199
  break;
200
200
  case "cards":
201
- Y = t.cards, Ge = !0, Q();
201
+ Y = t.cards, be = !0, $();
202
202
  break;
203
203
  case "nodes":
204
- G = t.nodes, na = !0, ua = !0, fe = !0, Q(), Se(), self.postMessage({ type: "nodesProcessed", data: { nodeCount: G.length } });
204
+ C = t.nodes, na = !0, sa = !0, he = !0, $(), It(), self.postMessage({ type: "nodesProcessed", data: { nodeCount: C.length } });
205
205
  break;
206
206
  case "nodePositions":
207
- na && Ie();
208
- for (var l = t.updates, f = 0; f < l.length; f++) {
209
- var o = l[f], i = sa[o.id];
210
- i && (i.position = o.position, o._absolutePosition && (i._absolutePosition = o._absolutePosition), o.width !== void 0 && (i.width = o.width), o.height !== void 0 && (i.height = o.height), i.dragging = o.dragging, i.selected = o.selected);
207
+ na && Je();
208
+ for (var l = t.updates, f = 0, o = 0; o < l.length; o++) {
209
+ var i = l[o], y = da[i.id];
210
+ y && (y.position = i.position, i._absolutePosition && (y._absolutePosition = i._absolutePosition), i.width !== void 0 && (y.width = i.width), i.height !== void 0 && (y.height = i.height), i.dragging && !y.dragging ? f++ : !i.dragging && y.dragging && f--, y.dragging = i.dragging, y.selected = i.selected);
211
211
  }
212
- fe = !0, ua = !0, Q(), Se();
212
+ Kt = Math.max(0, Kt + f), he = !0, l.length > 10 && (sa = !0), $();
213
213
  break;
214
214
  case "nodeSelections":
215
- na && Ie();
216
- for (var y = t.selections, x = 0; x < y.length; x++) {
217
- var u = y[x], M = sa[u.id];
218
- M && (M.selected = u.selected);
215
+ na && Je();
216
+ for (var x = t.selections, h = 0; h < x.length; h++) {
217
+ var g = x[h], v = da[g.id];
218
+ v && (v.selected = g.selected);
219
219
  }
220
- Q();
220
+ $();
221
221
  break;
222
222
  case "edgeSelections":
223
- for (var v = t.selections, n = 0; n < v.length; n++) {
224
- for (var s = v[n], h = null, T = 0; T < q.length; T++)
225
- if (q[T].id === s.id) {
226
- h = q[T];
223
+ for (var n = t.selections, u = 0; u < n.length; u++) {
224
+ for (var s = n[u], m = null, q = 0; q < Z.length; q++)
225
+ if (Z[q].id === s.id) {
226
+ m = Z[q];
227
227
  break;
228
228
  }
229
- h && (h.selected = s.selected);
229
+ m && (m.selected = s.selected);
230
230
  }
231
- Q();
231
+ $();
232
232
  break;
233
233
  case "edges":
234
- q = t.edges, Ze = !0, ie = q.some(function(A) {
235
- return A.animated;
236
- }), ie && jo(), Q(), Se();
234
+ Z = t.edges, Qe = !0, ve = Z.some(function(W) {
235
+ return W.animated;
236
+ }), ve && rl(), $(), It();
237
237
  break;
238
238
  case "theme":
239
- $ = t.dark, Pt(), Q();
239
+ F = t.dark, bt(), $();
240
240
  break;
241
241
  case "connecting":
242
- ee = t, Q();
242
+ oe = t, $();
243
243
  break;
244
244
  case "selectionBox":
245
- xr = t, Q();
245
+ gr = t, $();
246
246
  break;
247
247
  case "background":
248
- t.variant && (Fr = t.variant), t.gap && (Wt = t.gap), t.size && (ha = t.size), Pe = t.color || null, Ia = !0, Q();
248
+ t.variant && (Fr = t.variant), t.gap && (Zt = t.gap), t.size && (ua = t.size), Ze = t.color || null, Ia = !0, $();
249
249
  break;
250
250
  case "nodeTypeBitmaps":
251
- Ce = t.bitmaps || {}, Q();
251
+ Ge = t.bitmaps || {}, $();
252
252
  break;
253
253
  case "nodeBitmaps":
254
- Xo = t.cache || {}, te = t.keys || {}, Q();
254
+ el = t.cache || {}, le = t.keys || {}, $();
255
255
  break;
256
256
  case "nodeTypeConfigs":
257
- We = t.configs || {}, Q();
257
+ Ie = t.configs || {}, $();
258
258
  break;
259
259
  case "edgeRouting":
260
260
  if (Ga = !!t.enabled, Ga)
261
- Se();
261
+ It();
262
262
  else {
263
- for (var I = 0; I < q.length; I++)
264
- q[I]._routedPoints = null;
265
- Q();
263
+ for (var _ = 0; _ < Z.length; _++)
264
+ Z[_]._routedPoints = null;
265
+ $();
266
266
  }
267
267
  break;
268
268
  }
269
- } catch (A) {
270
- console.error("[worker] error:", A);
269
+ } catch (W) {
270
+ console.error("[worker] error:", W);
271
271
  }
272
272
  };
273
- function Q() {
274
- _t || (_t = !0, requestAnimationFrame(function() {
275
- _t = !1, Ke();
273
+ function $() {
274
+ Ct || (Ct = !0, requestAnimationFrame(function() {
275
+ Ct = !1, $e();
276
276
  }));
277
277
  }
278
- var St = !1;
279
- function jo() {
280
- if (St) return;
281
- St = !0;
278
+ var qt = !1;
279
+ function rl() {
280
+ if (qt) return;
281
+ qt = !0;
282
282
  function a() {
283
- if (!ie) {
284
- St = !1;
283
+ if (!ve) {
284
+ qt = !1;
285
285
  return;
286
286
  }
287
- qt = (qt + 0.5) % 20, Ke(), requestAnimationFrame(a);
287
+ Jt = (Jt + 0.5) % 20, $e(), requestAnimationFrame(a);
288
288
  }
289
289
  requestAnimationFrame(a);
290
290
  }
291
- function Yo(a, e) {
291
+ function al(a, e) {
292
292
  var t = 6;
293
293
  a.moveTo(e[0].x, e[0].y);
294
294
  for (var l = 1; l < e.length - 1; l++) {
295
- var f = e[l - 1], o = e[l], i = e[l + 1], y = Math.abs(o.x - f.x) + Math.abs(o.y - f.y), x = Math.abs(i.x - o.x) + Math.abs(i.y - o.y), u = Math.min(t, y / 2, x / 2);
296
- if (u > 0.5) {
297
- var M = o.x - f.x, v = o.y - f.y, n = i.x - o.x, s = i.y - o.y, h = Math.sqrt(M * M + v * v) || 1, T = Math.sqrt(n * n + s * s) || 1;
298
- a.lineTo(o.x - M / h * u, o.y - v / h * u), a.quadraticCurveTo(o.x, o.y, o.x + n / T * u, o.y + s / T * u);
295
+ var f = e[l - 1], o = e[l], i = e[l + 1], y = Math.abs(o.x - f.x) + Math.abs(o.y - f.y), x = Math.abs(i.x - o.x) + Math.abs(i.y - o.y), h = Math.min(t, y / 2, x / 2);
296
+ if (h > 0.5) {
297
+ var g = o.x - f.x, v = o.y - f.y, n = i.x - o.x, u = i.y - o.y, s = Math.sqrt(g * g + v * v) || 1, m = Math.sqrt(n * n + u * u) || 1;
298
+ a.lineTo(o.x - g / s * h, o.y - v / s * h), a.quadraticCurveTo(o.x, o.y, o.x + n / m * h, o.y + u / m * h);
299
299
  } else
300
300
  a.lineTo(o.x, o.y);
301
301
  }
302
302
  a.lineTo(e[e.length - 1].x, e[e.length - 1].y);
303
303
  }
304
- function jl(a) {
304
+ function ri(a) {
305
305
  for (var e = 0, t = 1; t < a.length; t++)
306
306
  e += Math.abs(a[t].x - a[t - 1].x) + Math.abs(a[t].y - a[t - 1].y);
307
307
  for (var l = e / 2, f = 1; f < a.length; f++) {
@@ -317,123 +317,123 @@ function jl(a) {
317
317
  }
318
318
  return { x: a[0].x, y: a[0].y };
319
319
  }
320
- function Gt(a, e, t, l) {
321
- var f = Math.abs(t - a), o = Math.max(50, f * 0.5), i = a + o, y = e, x = t - o, u = l;
322
- return { cp1x: i, cp1y: y, cp2x: x, cp2y: u };
320
+ function Qt(a, e, t, l) {
321
+ var f = Math.abs(t - a), o = Math.max(50, f * 0.5), i = a + o, y = e, x = t - o, h = l;
322
+ return { cp1x: i, cp1y: y, cp2x: x, cp2y: h };
323
323
  }
324
- function Yl(a, e, t, l) {
325
- var f = Gt(a, e, t, l), o = 0.5, i = 1 - o, y = i * i * i * a + 3 * i * i * o * f.cp1x + 3 * i * o * o * f.cp2x + o * o * o * t, x = i * i * i * e + 3 * i * i * o * f.cp1y + 3 * i * o * o * f.cp2y + o * o * o * l;
324
+ function ai(a, e, t, l) {
325
+ var f = Qt(a, e, t, l), o = 0.5, i = 1 - o, y = i * i * i * a + 3 * i * i * o * f.cp1x + 3 * i * o * o * f.cp2x + o * o * o * t, x = i * i * i * e + 3 * i * i * o * f.cp1y + 3 * i * o * o * f.cp2y + o * o * o * l;
326
326
  return { x: y, y: x };
327
327
  }
328
- var Ga = !0, It = !1, Ct = !1;
329
- function tl(a, e, t, l, f) {
330
- ua && Zt();
331
- for (var o = Math.min(a, t) - 20, i = Math.min(e, l) - 20, y = Math.max(a, t) + 20, x = Math.max(e, l) + 20, u = po(o, i, y, x), M = [], v = 0; v < u.length; v++) {
332
- var n = G[u[v]];
333
- n.hidden || f[n.id] || n.type !== "group" && M.push(n);
328
+ var Ga = !0, $t = !1, Gt = !1;
329
+ function vl(a, e, t, l, f) {
330
+ sa && Ft();
331
+ for (var o = Math.min(a, t) - 20, i = Math.min(e, l) - 20, y = Math.max(a, t) + 20, x = Math.max(e, l) + 20, h = ol(o, i, y, x), g = [], v = 0; v < h.length; v++) {
332
+ var n = C[h[v]];
333
+ n.hidden || f[n.id] || n.type !== "group" && g.push(n);
334
334
  }
335
- return M;
335
+ return g;
336
336
  }
337
- function zr(a, e, t, l) {
337
+ function Br(a, e, t, l) {
338
338
  for (var f = Math.min(a, e), o = Math.max(a, e), i = 0; i < l.length; i++) {
339
- var y = l[i], x = d(y), u = y.width || L, M = y.height || B;
340
- if (t > x.y && t < x.y + M && o > x.x && f < x.x + u) return y;
339
+ var y = l[i], x = d(y), h = y.width || L, g = y.height || B;
340
+ if (t > x.y && t < x.y + g && o > x.x && f < x.x + h) return y;
341
341
  }
342
342
  return null;
343
343
  }
344
- function wr(a, e, t, l) {
344
+ function Ar(a, e, t, l) {
345
345
  for (var f = Math.min(e, t), o = Math.max(e, t), i = 0; i < l.length; i++) {
346
- var y = l[i], x = d(y), u = y.width || L, M = y.height || B;
347
- if (a > x.x && a < x.x + u && o > x.y && f < x.y + M) return y;
346
+ var y = l[i], x = d(y), h = y.width || L, g = y.height || B;
347
+ if (a > x.x && a < x.x + h && o > x.y && f < x.y + g) return y;
348
348
  }
349
349
  return null;
350
350
  }
351
- function Xl() {
352
- if (Ga && !(!It || q.length === 0 || G.length === 0)) {
353
- It = !1, na && Ie(), ua && Zt();
354
- for (var a = 20, e = !1, t = 0; t < q.length; t++) {
355
- var l = q[t];
351
+ function ei() {
352
+ if (Ga && !(!$t || Z.length === 0 || C.length === 0)) {
353
+ $t = !1, na && Je(), sa && Ft();
354
+ for (var a = 20, e = !1, t = 0; t < Z.length; t++) {
355
+ var l = Z[t];
356
356
  if (!l._customRendered) {
357
357
  var f = l.type || "default";
358
358
  if (!(f === "bezier" || f === "simplebezier" || f === "default")) {
359
- var o = sa[l.source], i = sa[l.target];
359
+ var o = da[l.source], i = da[l.target];
360
360
  if (!(!o || !i || o.hidden || i.hidden)) {
361
- var y = qe(o, "source", l.sourceHandle), x = qe(i, "target", l.targetHandle), u = y.position || "right", M = x.position || "left", v = y.x, n = y.y, s = x.x, h = x.y, T = v, I = n, A = s, N = h;
362
- u === "right" ? T += a : u === "left" ? T -= a : u === "bottom" ? I += a : u === "top" && (I -= a), M === "right" ? A += a : M === "left" ? A -= a : M === "bottom" ? N += a : M === "top" && (N -= a);
363
- var Br = d(o), Vr = d(i), Nr = o.width || L, Dr = o.height || B, Or = i.width || L, da = i.height || B, jr = {};
361
+ var y = Ke(o, "source", l.sourceHandle), x = Ke(i, "target", l.targetHandle), h = y.position || "right", g = x.position || "left", v = y.x, n = y.y, u = x.x, s = x.y, m = v, q = n, _ = u, W = s;
362
+ h === "right" ? m += a : h === "left" ? m -= a : h === "bottom" ? q += a : h === "top" && (q -= a), g === "right" ? _ += a : g === "left" ? _ -= a : g === "bottom" ? W += a : g === "top" && (W -= a);
363
+ var _r = d(o), Vr = d(i), Nr = o.width || L, Or = o.height || B, Dr = i.width || L, ya = i.height || B, jr = {};
364
364
  jr[l.source] = !0, jr[l.target] = !0;
365
- var X = tl(
366
- Math.min(v, s) - Nr,
367
- Math.min(n, h) - Dr,
368
- Math.max(v, s) + Or,
369
- Math.max(n, h) + da,
365
+ var X = vl(
366
+ Math.min(v, u) - Nr,
367
+ Math.min(n, s) - Or,
368
+ Math.max(v, u) + Dr,
369
+ Math.max(n, s) + ya,
370
370
  jr
371
371
  );
372
372
  X.push(o), X.push(i);
373
- var ya = u === "left" || u === "right", Za = M === "left" || M === "right", W = null;
374
- if (ya && Za) {
375
- var C, fr = u === "right" && T < A, be = u === "left" && T > A;
376
- if (fr || be) {
377
- C = (T + A) / 2;
378
- var Ka = wr(C, n, h, X);
373
+ var xa = h === "left" || h === "right", Za = g === "left" || g === "right", G = null;
374
+ if (xa && Za) {
375
+ var P, vr = h === "right" && m < _, Fe = h === "left" && m > _;
376
+ if (vr || Fe) {
377
+ P = (m + _) / 2;
378
+ var Ka = Ar(P, n, s, X);
379
379
  if (Ka) {
380
- var xa = d(Ka), Ma = Ka.width || L;
381
- C = C < xa.x + Ma / 2 ? xa.x - a : xa.x + Ma + a;
380
+ var ga = d(Ka), Ma = Ka.width || L;
381
+ P = P < ga.x + Ma / 2 ? ga.x - a : ga.x + Ma + a;
382
382
  }
383
383
  } else
384
- u === "right" ? C = Math.max(Br.x + Nr, Vr.x + Or) + a : C = Math.min(Br.x, Vr.x) - a;
385
- W = [{ x: v, y: n }, { x: T, y: n }, { x: C, y: n }, { x: C, y: h }, { x: A, y: h }, { x: s, y: h }];
386
- var Ar = zr(C, A, h, X);
387
- if (Ar) {
388
- var ga = d(Ar), ka = Ar.height || B, Ta = ga.y - a, Yr = ga.y + ka + a, Xr = Math.abs(n - Ta) <= Math.abs(n - Yr) ? Ta : Yr;
389
- W = [{ x: v, y: n }, { x: T, y: n }, { x: C, y: n }, { x: C, y: Xr }, { x: A, y: Xr }, { x: A, y: h }, { x: s, y: h }];
384
+ h === "right" ? P = Math.max(_r.x + Nr, Vr.x + Dr) + a : P = Math.min(_r.x, Vr.x) - a;
385
+ G = [{ x: v, y: n }, { x: m, y: n }, { x: P, y: n }, { x: P, y: s }, { x: _, y: s }, { x: u, y: s }];
386
+ var Er = Br(P, _, s, X);
387
+ if (Er) {
388
+ var ka = d(Er), ma = Er.height || B, Ta = ka.y - a, Yr = ka.y + ma + a, Xr = Math.abs(n - Ta) <= Math.abs(n - Yr) ? Ta : Yr;
389
+ G = [{ x: v, y: n }, { x: m, y: n }, { x: P, y: n }, { x: P, y: Xr }, { x: _, y: Xr }, { x: _, y: s }, { x: u, y: s }];
390
390
  }
391
- } else if (!ya && !Za) {
392
- var K, ve = u === "bottom" && I < N, ba = u === "top" && I > N;
393
- if (ve || ba) {
394
- K = (I + N) / 2;
395
- var _r = zr(v, s, K, X);
396
- if (_r) {
397
- var Er = d(_r), ma = _r.height || B;
398
- K = K < Er.y + ma / 2 ? Er.y - a : Er.y + ma + a;
391
+ } else if (!xa && !Za) {
392
+ var b, ne = h === "bottom" && q < W, ba = h === "top" && q > W;
393
+ if (ne || ba) {
394
+ b = (q + W) / 2;
395
+ var Lr = Br(v, u, b, X);
396
+ if (Lr) {
397
+ var Sr = d(Lr), Ra = Lr.height || B;
398
+ b = b < Sr.y + Ra / 2 ? Sr.y - a : Sr.y + Ra + a;
399
399
  }
400
400
  } else
401
- u === "bottom" ? K = Math.max(Br.y + Dr, Vr.y + da) + a : K = Math.min(Br.y, Vr.y) - a;
402
- W = [{ x: v, y: n }, { x: v, y: I }, { x: v, y: K }, { x: s, y: K }, { x: s, y: N }, { x: s, y: h }];
403
- var Hr = wr(s, K, N, X);
401
+ h === "bottom" ? b = Math.max(_r.y + Or, Vr.y + ya) + a : b = Math.min(_r.y, Vr.y) - a;
402
+ G = [{ x: v, y: n }, { x: v, y: q }, { x: v, y: b }, { x: u, y: b }, { x: u, y: W }, { x: u, y: s }];
403
+ var Hr = Ar(u, b, W, X);
404
404
  if (Hr) {
405
- var Ra = d(Hr), Ja = Hr.height || B, za = Ra.y - a, wa = Ra.y + Ja + a, Ba = Math.abs(K - za) <= Math.abs(K - wa) ? za : wa;
406
- W = [{ x: v, y: n }, { x: v, y: I }, { x: v, y: K }, { x: s, y: K }, { x: s, y: Ba }, { x: A, y: Ba }, { x: A, y: h }, { x: s, y: h }];
405
+ var za = d(Hr), Ja = Hr.height || B, wa = za.y - a, Ba = za.y + Ja + a, Aa = Math.abs(b - wa) <= Math.abs(b - Ba) ? wa : Ba;
406
+ G = [{ x: v, y: n }, { x: v, y: q }, { x: v, y: b }, { x: u, y: b }, { x: u, y: Aa }, { x: _, y: Aa }, { x: _, y: s }, { x: u, y: s }];
407
407
  }
408
- } else if (ya) {
409
- W = [{ x: v, y: n }, { x: T, y: n }, { x: s, y: n }, { x: s, y: N }, { x: s, y: h }];
410
- var Lr = wr(s, n, N, X);
411
- if (Lr) {
412
- var lr = d(Lr), Sr = Lr.width || L, Qa = Math.abs(v - lr.x + a) <= Math.abs(v - lr.x - Sr - a) ? lr.x - a : lr.x + Sr + a;
413
- W = [{ x: v, y: n }, { x: T, y: n }, { x: Qa, y: n }, { x: Qa, y: h }, { x: s, y: h }, { x: s, y: N }, { x: s, y: h }];
408
+ } else if (xa) {
409
+ G = [{ x: v, y: n }, { x: m, y: n }, { x: u, y: n }, { x: u, y: W }, { x: u, y: s }];
410
+ var Cr = Ar(u, n, W, X);
411
+ if (Cr) {
412
+ var ir = d(Cr), Mr = Cr.width || L, Qa = Math.abs(v - ir.x + a) <= Math.abs(v - ir.x - Mr - a) ? ir.x - a : ir.x + Mr + a;
413
+ G = [{ x: v, y: n }, { x: m, y: n }, { x: Qa, y: n }, { x: Qa, y: s }, { x: u, y: s }, { x: u, y: W }, { x: u, y: s }];
414
414
  }
415
- var pr = zr(T, s, n, X);
415
+ var pr = Br(m, u, n, X);
416
416
  if (pr) {
417
- var Cr = d(pr), Aa = pr.height || B, H = Math.abs(h - Cr.y + a) <= Math.abs(h - Cr.y - Aa - a) ? Cr.y - a : Cr.y + Aa + a;
418
- W = [{ x: v, y: n }, { x: T, y: n }, { x: T, y: H }, { x: s, y: H }, { x: s, y: N }, { x: s, y: h }];
417
+ var Wr = d(pr), _a = pr.height || B, H = Math.abs(s - Wr.y + a) <= Math.abs(s - Wr.y - _a - a) ? Wr.y - a : Wr.y + _a + a;
418
+ G = [{ x: v, y: n }, { x: m, y: n }, { x: m, y: H }, { x: u, y: H }, { x: u, y: W }, { x: u, y: s }];
419
419
  }
420
420
  } else {
421
- W = [{ x: v, y: n }, { x: v, y: I }, { x: v, y: h }, { x: A, y: h }, { x: s, y: h }];
422
- var Wr = zr(v, A, h, X);
423
- if (Wr) {
424
- var _a = d(Wr), vr = Wr.height || B, Pr = Math.abs(n - _a.y + a) <= Math.abs(n - _a.y - vr - a) ? _a.y - a : _a.y + vr + a;
425
- W = [{ x: v, y: n }, { x: v, y: I }, { x: v, y: Pr }, { x: A, y: Pr }, { x: A, y: h }, { x: s, y: h }];
421
+ G = [{ x: v, y: n }, { x: v, y: q }, { x: v, y: s }, { x: _, y: s }, { x: u, y: s }];
422
+ var Pr = Br(v, _, s, X);
423
+ if (Pr) {
424
+ var Ea = d(Pr), hr = Pr.height || B, qr = Math.abs(n - Ea.y + a) <= Math.abs(n - Ea.y - hr - a) ? Ea.y - a : Ea.y + hr + a;
425
+ G = [{ x: v, y: n }, { x: v, y: q }, { x: v, y: qr }, { x: _, y: qr }, { x: _, y: s }, { x: u, y: s }];
426
426
  }
427
- var Mr = wr(v, I, h, X);
428
- if (Mr) {
429
- var nr = d(Mr), $a = Mr.width || L, Fa = Math.abs(s - nr.x + a) <= Math.abs(s - nr.x - $a - a) ? nr.x - a : nr.x + $a + a;
430
- W = [{ x: v, y: n }, { x: v, y: I }, { x: Fa, y: I }, { x: Fa, y: h }, { x: A, y: h }, { x: s, y: h }];
427
+ var kr = Ar(v, q, s, X);
428
+ if (kr) {
429
+ var nr = d(kr), $a = kr.width || L, Fa = Math.abs(u - nr.x + a) <= Math.abs(u - nr.x - $a - a) ? nr.x - a : nr.x + $a + a;
430
+ G = [{ x: v, y: n }, { x: v, y: q }, { x: Fa, y: q }, { x: Fa, y: s }, { x: _, y: s }, { x: u, y: s }];
431
431
  }
432
432
  }
433
- if (W) {
434
- for (var ra = [W[0]], hr = 1; hr < W.length; hr++) {
435
- var ne = ra[ra.length - 1];
436
- (Math.abs(W[hr].x - ne.x) > 0.1 || Math.abs(W[hr].y - ne.y) > 0.1) && ra.push(W[hr]);
433
+ if (G) {
434
+ for (var ra = [G[0]], ur = 1; ur < G.length; ur++) {
435
+ var ue = ra[ra.length - 1];
436
+ (Math.abs(G[ur].x - ue.x) > 0.1 || Math.abs(G[ur].y - ue.y) > 0.1) && ra.push(G[ur]);
437
437
  }
438
438
  l._routedPoints = ra, e = !0;
439
439
  }
@@ -441,490 +441,499 @@ function Xl() {
441
441
  }
442
442
  }
443
443
  }
444
- e && Q();
444
+ e && $();
445
445
  }
446
446
  }
447
- function Se() {
448
- Ga && (Ct || (Ct = !0, It = !0, requestAnimationFrame(function() {
449
- Ct = !1;
447
+ function It() {
448
+ Ga && (Gt || (Gt = !0, $t = !0, requestAnimationFrame(function() {
449
+ Gt = !1;
450
450
  try {
451
- Xl();
451
+ ei();
452
452
  } catch (a) {
453
453
  console.error("[worker] async routing error:", a);
454
454
  }
455
455
  })));
456
456
  }
457
- function Ke() {
457
+ function $e() {
458
458
  if (r) {
459
459
  var a = performance.now();
460
- r.clearRect(0, 0, tr, or);
461
- var e = Wt * g.zoom;
460
+ r.clearRect(0, 0, or, lr);
461
+ var e = Zt * M.zoom;
462
462
  if (e > 2)
463
463
  if (Fr === "lines" && e >= 4 && e <= 512) {
464
- if ((Ia || al !== e || el !== Fr) && Ol(e), va && rl > 0) {
465
- var t = (g.x % e + e) % e, l = (g.y % e + e) % e;
464
+ if ((Ia || il !== e || fl !== Fr) && pl(e), ha && ll > 0) {
465
+ var t = (M.x % e + e) % e, l = (M.y % e + e) % e;
466
466
  r.save(), r.translate(t, l);
467
- var f = r.createPattern(va, "repeat");
468
- f && (r.fillStyle = f, r.fillRect(-t, -l, tr, or)), r.restore();
467
+ var f = r.createPattern(ha, "repeat");
468
+ f && (r.fillStyle = f, r.fillRect(-t, -l, or, lr)), r.restore();
469
469
  }
470
470
  } else {
471
- var o = (g.x % e + e) % e, i = (g.y % e + e) % e, y = Pe || k.grid;
471
+ var o = (M.x % e + e) % e, i = (M.y % e + e) % e, y = Ze || k.grid;
472
472
  if (Fr === "dots") {
473
473
  r.fillStyle = y;
474
- for (var x = ha * g.zoom, u = o; u < tr; u += e)
475
- for (var M = i; M < or; M += e)
476
- r.beginPath(), r.arc(Math.round(u), Math.round(M), x, 0, 6.2832), r.fill();
474
+ for (var x = ua * M.zoom, h = o; h < or; h += e)
475
+ for (var g = i; g < lr; g += e)
476
+ r.beginPath(), r.arc(Math.round(h), Math.round(g), x, 0, 6.2832), r.fill();
477
477
  } else if (Fr === "cross") {
478
- r.strokeStyle = y, r.lineWidth = ha;
479
- var v = 3 * g.zoom;
478
+ r.strokeStyle = y, r.lineWidth = ua;
479
+ var v = 3 * M.zoom;
480
480
  r.beginPath();
481
- for (var n = o; n < tr; n += e)
482
- for (var s = i; s < or; s += e) {
483
- var h = Math.round(n), T = Math.round(s);
484
- r.moveTo(h - v, T), r.lineTo(h + v, T), r.moveTo(h, T - v), r.lineTo(h, T + v);
481
+ for (var n = o; n < or; n += e)
482
+ for (var u = i; u < lr; u += e) {
483
+ var s = Math.round(n), m = Math.round(u);
484
+ r.moveTo(s - v, m), r.lineTo(s + v, m), r.moveTo(s, m - v), r.lineTo(s, m + v);
485
485
  }
486
486
  r.stroke();
487
487
  } else {
488
- var I = Pe || k.grid;
489
- r.beginPath(), r.strokeStyle = I, r.lineWidth = ha * 0.5;
490
- for (var A = o; A < tr; A += e) {
491
- var N = Math.round(A) + 0.5;
492
- r.moveTo(N, 0), r.lineTo(N, or);
488
+ var q = Ze || k.grid;
489
+ r.beginPath(), r.strokeStyle = q, r.lineWidth = ua * 0.5;
490
+ for (var _ = o; _ < or; _ += e) {
491
+ var W = Math.round(_) + 0.5;
492
+ r.moveTo(W, 0), r.lineTo(W, lr);
493
493
  }
494
- for (var Br = i; Br < or; Br += e) {
495
- var Vr = Math.round(Br) + 0.5;
496
- r.moveTo(0, Vr), r.lineTo(tr, Vr);
494
+ for (var _r = i; _r < lr; _r += e) {
495
+ var Vr = Math.round(_r) + 0.5;
496
+ r.moveTo(0, Vr), r.lineTo(or, Vr);
497
497
  }
498
498
  r.stroke();
499
499
  }
500
500
  }
501
- r.beginPath(), r.arc(g.x, g.y, 4 * g.zoom, 0, 6.2832), r.fillStyle = k.origin, r.fill(), r.save(), r.translate(g.x, g.y), r.scale(g.zoom, g.zoom);
502
- var Nr = 100, Dr = -g.x / g.zoom, Or = -g.y / g.zoom, da = Dr + tr / g.zoom, jr = Or + or / g.zoom, X = Dr - Nr, ya = Or - Nr, Za = da + Nr, W = jr + Nr;
501
+ r.beginPath(), r.arc(M.x, M.y, 4 * M.zoom, 0, 6.2832), r.fillStyle = k.origin, r.fill(), r.save(), r.translate(M.x, M.y), r.scale(M.zoom, M.zoom);
502
+ var Nr = 100, Or = -M.x / M.zoom, Dr = -M.y / M.zoom, ya = Or + or / M.zoom, jr = Dr + lr / M.zoom, X = Or - Nr, xa = Dr - Nr, Za = ya + Nr, G = jr + Nr;
503
503
  if (Y.length > 0) {
504
- var C = co(Dr, Or, da, jr), fr = C.length, be = g.zoom > 0.15, Ka = g.zoom > 0.3, xa = g.zoom > 0.08 && fr < 200;
505
- if (xa) {
504
+ var P = jo(Or, Dr, ya, jr), vr = P.length, Fe = M.zoom > 0.15, Ka = M.zoom > 0.3, ga = M.zoom > 0.08 && vr < 200;
505
+ if (ga) {
506
506
  r.shadowColor = k.cardShadow, r.shadowBlur = 6, r.shadowOffsetY = 2, r.fillStyle = k.cardBg, r.beginPath();
507
- for (var Ma = 0; Ma < fr; Ma++) {
508
- var Ar = Y[C[Ma]];
509
- r.roundRect(Ar.x, Ar.y, Ar.w, Ar.h, ae);
507
+ for (var Ma = 0; Ma < vr; Ma++) {
508
+ var Er = Y[P[Ma]];
509
+ r.roundRect(Er.x, Er.y, Er.w, Er.h, te);
510
510
  }
511
511
  r.fill(), r.shadowColor = "transparent", r.shadowBlur = 0, r.shadowOffsetY = 0;
512
512
  }
513
- if (!xa) {
513
+ if (!ga) {
514
514
  r.fillStyle = k.cardBg, r.beginPath();
515
- for (var ga = 0; ga < fr; ga++) {
516
- var ka = Y[C[ga]];
517
- r.roundRect(ka.x, ka.y, ka.w, ka.h, ae);
515
+ for (var ka = 0; ka < vr; ka++) {
516
+ var ma = Y[P[ka]];
517
+ r.roundRect(ma.x, ma.y, ma.w, ma.h, te);
518
518
  }
519
519
  r.fill();
520
520
  }
521
521
  r.strokeStyle = k.cardBorder, r.lineWidth = 0.5, r.beginPath();
522
- for (var Ta = 0; Ta < fr; Ta++) {
523
- var Yr = Y[C[Ta]];
524
- r.roundRect(Yr.x, Yr.y, Yr.w, Yr.h, ae);
522
+ for (var Ta = 0; Ta < vr; Ta++) {
523
+ var Yr = Y[P[Ta]];
524
+ r.roundRect(Yr.x, Yr.y, Yr.w, Yr.h, te);
525
525
  }
526
526
  r.stroke();
527
- for (var Xr = [{}, {}, {}, {}], K = 0; K < fr; K++) {
528
- var ve = C[K], ba = ve % 4;
529
- Xr[ba].items || (Xr[ba].items = []), Xr[ba].items.push(Y[ve]);
527
+ for (var Xr = [{}, {}, {}, {}], b = 0; b < vr; b++) {
528
+ var ne = P[b], ba = ne % 4;
529
+ Xr[ba].items || (Xr[ba].items = []), Xr[ba].items.push(Y[ne]);
530
530
  }
531
- for (var _r = 0; _r < 4; _r++) {
532
- var Er = Xr[_r].items;
533
- if (!(!Er || Er.length === 0)) {
534
- r.fillStyle = $l[_r], r.beginPath();
535
- for (var ma = 0; ma < Er.length; ma++) {
536
- var Hr = Er[ma];
537
- r.roundRect(Hr.x, Hr.y, Hr.w, 30, [ae, ae, 0, 0]);
531
+ for (var Lr = 0; Lr < 4; Lr++) {
532
+ var Sr = Xr[Lr].items;
533
+ if (!(!Sr || Sr.length === 0)) {
534
+ r.fillStyle = Nl[Lr], r.beginPath();
535
+ for (var Ra = 0; Ra < Sr.length; Ra++) {
536
+ var Hr = Sr[Ra];
537
+ r.roundRect(Hr.x, Hr.y, Hr.w, 30, [te, te, 0, 0]);
538
538
  }
539
539
  r.fill();
540
540
  }
541
541
  }
542
- if (be) {
543
- r.fillStyle = k.titleText, r.font = Fl;
544
- for (var Ra = 0; Ra < fr; Ra++) {
545
- var Ja = Y[C[Ra]];
542
+ if (Fe) {
543
+ r.fillStyle = k.titleText, r.font = Ol;
544
+ for (var za = 0; za < vr; za++) {
545
+ var Ja = Y[P[za]];
546
546
  r.fillText(Ja.title, Ja.x + 12, Ja.y + 19);
547
547
  }
548
- r.fillStyle = k.bodyText, r.font = Ul;
549
- for (var za = 0; za < fr; za++) {
550
- var wa = Y[C[za]];
551
- r.fillText(wa.body, wa.x + 12, wa.y + 52);
548
+ r.fillStyle = k.bodyText, r.font = Dl;
549
+ for (var wa = 0; wa < vr; wa++) {
550
+ var Ba = Y[P[wa]];
551
+ r.fillText(Ba.body, Ba.x + 12, Ba.y + 52);
552
552
  }
553
553
  if (Ka) {
554
- r.fillStyle = k.coordText, r.font = cl;
555
- for (var Ba = 0; Ba < fr; Ba++) {
556
- var Lr = Y[C[Ba]];
557
- r.fillText("(" + Lr.x + ", " + Lr.y + ")", Lr.x + 12, Lr.y + 75);
554
+ r.fillStyle = k.coordText, r.font = jl;
555
+ for (var Aa = 0; Aa < vr; Aa++) {
556
+ var Cr = Y[P[Aa]];
557
+ r.fillText("(" + Cr.x + ", " + Cr.y + ")", Cr.x + 12, Cr.y + 75);
558
558
  }
559
559
  }
560
560
  }
561
561
  }
562
- var lr = [], Sr = null;
563
- if (G.length > 0)
564
- if (Sr = {}, G.length > 100)
565
- for (var Qa = po(X, ya, Za, W), pr = 0; pr < Qa.length; pr++) {
566
- var Cr = G[Qa[pr]];
567
- Sr[Cr.id] = !0, Cr._customRendered || lr.push(Cr);
562
+ var ir = [], Mr = null;
563
+ if (C.length > 0)
564
+ if (Mr = {}, C.length > 100)
565
+ for (var Qa = ol(X, xa, Za, G), pr = 0; pr < Qa.length; pr++) {
566
+ var Wr = C[Qa[pr]];
567
+ Mr[Wr.id] = !0, Wr._customRendered || ir.push(Wr);
568
568
  }
569
569
  else
570
- for (var Aa = 0; Aa < G.length; Aa++) {
571
- var H = G[Aa];
570
+ for (var _a = 0; _a < C.length; _a++) {
571
+ var H = C[_a];
572
572
  if (!H.hidden) {
573
- var Wr = H.width || L, _a = H.height || B;
574
- d(H).x + Wr < X || d(H).x > Za || d(H).y + _a < ya || d(H).y > W || (Sr[H.id] = !0, H._customRendered || lr.push(H));
573
+ var Pr = H.width || L, Ea = H.height || B;
574
+ d(H).x + Pr < X || d(H).x > Za || d(H).y + Ea < xa || d(H).y > G || (Mr[H.id] = !0, H._customRendered || ir.push(H));
575
575
  }
576
576
  }
577
- var vr = lr.length;
578
- if (q.length > 0 && G.length > 0) {
579
- let Le = function(Qr, $o) {
580
- if (Qr.length) {
581
- r.fillStyle = $o, r.beginPath();
582
- for (var At = 0; At < Qr.length; At++) {
583
- var j = Qr[At];
577
+ var hr = ir.length;
578
+ if (Z.length > 0 && C.length > 0) {
579
+ let qe = function($r, No) {
580
+ if ($r.length) {
581
+ r.fillStyle = No, r.beginPath();
582
+ for (var St = 0; St < $r.length; St++) {
583
+ var j = $r[St];
584
584
  r.moveTo(j.x, j.y), r.lineTo(j.x - j.size * Math.cos(j.angle - 0.5236), j.y - j.size * Math.sin(j.angle - 0.5236)), r.lineTo(j.x - j.size * Math.cos(j.angle + 0.5236), j.y - j.size * Math.sin(j.angle + 0.5236)), r.closePath();
585
585
  }
586
586
  r.fill();
587
587
  }
588
588
  };
589
- var Hl = Le;
590
- Ze && Dl();
591
- var Pr = null, Mr = null, nr = null, $a = [], Fa = [], ra = [], hr = [], ne = g.zoom > 0.3, ol = g.zoom > 0.05, Ea;
592
- if (Sr && G.length > 100) {
593
- var Kt = {};
594
- Ea = [];
595
- for (var ll in Sr) {
596
- var Je = $r[ll];
597
- if (Je)
598
- for (var Qe = 0; Qe < Je.length; Qe++) {
599
- var $e = Je[Qe];
600
- Kt[$e] || (Kt[$e] = !0, Ea.push($e));
589
+ var ti = qe;
590
+ Qe && Hl();
591
+ var qr = null, kr = null, nr = null, $a = [], Fa = [], ra = [], ur = [], ue = M.zoom > 0.3, hl = M.zoom > 0.05, aa;
592
+ if (Mr && C.length > 100) {
593
+ var se = {};
594
+ aa = [];
595
+ for (var nl in Mr) {
596
+ var ce = wr[nl];
597
+ if (ce)
598
+ for (var Ue = 0; Ue < ce.length; Ue++) {
599
+ var Ve = ce[Ue];
600
+ se[Ve] || (se[Ve] = !0, aa.push(Ve));
601
601
  }
602
602
  }
603
+ for (var p = 0; p < C.length; p++) {
604
+ var de = C[p];
605
+ if ((de.dragging || de.selected) && !Mr[de.id]) {
606
+ var ca = wr[de.id];
607
+ if (ca)
608
+ for (var Ua = 0; Ua < ca.length; Ua++)
609
+ se[ca[Ua]] || (se[ca[Ua]] = !0, aa.push(ca[Ua]));
610
+ }
611
+ }
603
612
  } else {
604
- Ea = [];
605
- for (var Fe = 0; Fe < q.length; Fe++) Ea.push(Fe);
613
+ aa = [];
614
+ for (var Ne = 0; Ne < Z.length; Ne++) aa.push(Ne);
606
615
  }
607
- for (var Ue = 0; Ue < Ea.length; Ue++) {
608
- var D = q[Ea[Ue]], aa = Vo(D.source), ea = Vo(D.target);
609
- if (!(!aa || !ea) && !(aa.hidden || ea.hidden) && !D._customRendered) {
610
- var he = qe(aa, "source", D.sourceHandle), ue = qe(ea, "target", D.targetHandle), _ = he.x, w = he.y, R = ue.x, z = ue.y, ur = D.type || "default", bt = D.selected, Jt = D.animated, b;
611
- bt ? (Mr || (Mr = new Path2D()), b = Mr) : Jt ? (nr || (nr = new Path2D()), b = nr) : (Pr || (Pr = new Path2D()), b = Pr);
612
- var J = D._routedPoints;
613
- if (J && J.length >= 2)
614
- Yo(b, J);
615
- else if (ur === "straight")
616
- b.moveTo(_, w), b.lineTo(R, z);
617
- else if (ur === "step" || ur === "smoothstep")
616
+ for (var Oe = 0; Oe < aa.length; Oe++) {
617
+ var O = Z[aa[Oe]], ea = Yo(O.source), ta = Yo(O.target);
618
+ if (!(!ea || !ta) && !(ea.hidden || ta.hidden) && !O._customRendered) {
619
+ var ye = Ke(ea, "source", O.sourceHandle), xe = Ke(ta, "target", O.targetHandle), A = ye.x, w = ye.y, R = xe.x, z = xe.y, sr = O.type || "default", ct = O.selected, Ut = O.animated, J;
620
+ ct ? (kr || (kr = new Path2D()), J = kr) : Ut ? (nr || (nr = new Path2D()), J = nr) : (qr || (qr = new Path2D()), J = qr);
621
+ var Q = O._routedPoints;
622
+ if (Q && Q.length >= 2)
623
+ al(J, Q);
624
+ else if (sr === "straight")
625
+ J.moveTo(A, w), J.lineTo(R, z);
626
+ else if (sr === "step" || sr === "smoothstep")
618
627
  try {
619
- var p = he.position || "right", La = ue.position || "left", m = 20, F = _, O = w, U = R, rr = z;
620
- p === "right" ? F += m : p === "left" ? F -= m : p === "bottom" ? O += m : p === "top" && (O -= m), La === "right" ? U += m : La === "left" ? U -= m : La === "bottom" ? rr += m : La === "top" && (rr -= m);
621
- var se = d(aa), de = d(ea), Ua = aa.width || L, ca = aa.height || B, Qt = ea.width || L, $t = ea.height || B, ce = p === "left" || p === "right", Ft = La === "left" || La === "right", Ve = {};
622
- Ve[D.source] = !0, Ve[D.target] = !0;
623
- var ar = tl(
624
- Math.min(_, R) - Ua,
625
- Math.min(w, z) - ca,
626
- Math.max(_, R) + Qt,
627
- Math.max(w, z) + $t,
628
- Ve
628
+ var rr = ye.position || "right", La = xe.position || "left", T = 20, c = A, D = w, U = R, ar = z;
629
+ rr === "right" ? c += T : rr === "left" ? c -= T : rr === "bottom" ? D += T : rr === "top" && (D -= T), La === "right" ? U += T : La === "left" ? U -= T : La === "bottom" ? ar += T : La === "top" && (ar -= T);
630
+ var ge = d(ea), Me = d(ta), Va = ea.width || L, Na = ea.height || B, Vt = ta.width || L, Nt = ta.height || B, De = rr === "left" || rr === "right", Ot = La === "left" || La === "right", je = {};
631
+ je[O.source] = !0, je[O.target] = !0;
632
+ var er = vl(
633
+ Math.min(A, R) - Va,
634
+ Math.min(w, z) - Na,
635
+ Math.max(A, R) + Vt,
636
+ Math.max(w, z) + Nt,
637
+ je
629
638
  );
630
- ar.push(aa), ar.push(ea);
631
- var Z = [];
632
- if (ce && Ft) {
633
- var c, il = p === "right" && F < U, fl = p === "left" && F > U;
634
- if (il || fl) {
635
- c = (F + U) / 2;
636
- var Ne = wr(c, w, z, ar);
637
- if (Ne) {
638
- var De = d(Ne), Wr = Ne.width || L;
639
- c < De.x + Wr / 2 ? c = De.x - m : c = De.x + Wr + m;
639
+ er.push(ea), er.push(ta);
640
+ var K = [];
641
+ if (De && Ot) {
642
+ var V, ul = rr === "right" && c < U, sl = rr === "left" && c > U;
643
+ if (ul || sl) {
644
+ V = (c + U) / 2;
645
+ var Ye = Ar(V, w, z, er);
646
+ if (Ye) {
647
+ var Xe = d(Ye), Pr = Ye.width || L;
648
+ V < Xe.x + Pr / 2 ? V = Xe.x - T : V = Xe.x + Pr + T;
640
649
  }
641
650
  } else
642
- p === "right" ? c = Math.max(se.x + Ua, de.x + Qt) + m : c = Math.min(se.x, de.x) - m;
643
- Z = [{ x: F, y: w }, { x: c, y: w }, { x: c, y: z }, { x: U, y: z }];
644
- var Oe = zr(c, U, z, ar);
645
- if (Oe) {
646
- var Ut = d(Oe), vl = Oe.height || B, ct = Ut.y - m, Vt = Ut.y + vl + m, Nt = Math.abs(w - ct) <= Math.abs(w - Vt) ? ct : Vt;
647
- Z = [
648
- { x: F, y: w },
651
+ rr === "right" ? V = Math.max(ge.x + Va, Me.x + Vt) + T : V = Math.min(ge.x, Me.x) - T;
652
+ K = [{ x: c, y: w }, { x: V, y: w }, { x: V, y: z }, { x: U, y: z }];
653
+ var He = Br(V, U, z, er);
654
+ if (He) {
655
+ var Dt = d(He), dl = He.height || B, jt = Dt.y - T, Yt = Dt.y + dl + T, Xt = Math.abs(w - jt) <= Math.abs(w - Yt) ? jt : Yt;
656
+ K = [
649
657
  { x: c, y: w },
650
- { x: c, y: Nt },
651
- { x: U, y: Nt },
658
+ { x: V, y: w },
659
+ { x: V, y: Xt },
660
+ { x: U, y: Xt },
652
661
  { x: U, y: z }
653
662
  ];
654
663
  }
655
- var je = zr(F, c, w, ar);
656
- if (je) {
657
- var Dt = d(je), nl = je.height || B, Ot = Dt.y - m, jt = Dt.y + nl + m, Yt = Math.abs(z - Ot) <= Math.abs(z - jt) ? Ot : jt;
658
- Z.splice(
664
+ var pe = Br(c, V, w, er);
665
+ if (pe) {
666
+ var Ht = d(pe), yl = pe.height || B, pt = Ht.y - T, ro = Ht.y + yl + T, ao = Math.abs(z - pt) <= Math.abs(z - ro) ? pt : ro;
667
+ K.splice(
659
668
  1,
660
669
  0,
661
- { x: F, y: Yt },
662
- { x: c, y: Yt }
663
- ), Z = Z.filter(function(Qr, $o) {
664
- return !(Math.abs(Qr.x - c) < 1 && Math.abs(Qr.y - w) < 1);
665
- }), Z.splice(0, 0, { x: F, y: w });
670
+ { x: c, y: ao },
671
+ { x: V, y: ao }
672
+ ), K = K.filter(function($r, No) {
673
+ return !(Math.abs($r.x - V) < 1 && Math.abs($r.y - w) < 1);
674
+ }), K.splice(0, 0, { x: c, y: w });
666
675
  }
667
- } else if (!ce && !Ft) {
668
- var V, hl = p === "bottom" && O < rr, ul = p === "top" && O > rr;
669
- if (hl || ul) {
670
- V = (O + rr) / 2;
671
- var Ye = zr(_, R, V, ar);
672
- if (Ye) {
673
- var Xe = d(Ye), Xt = Ye.height || B;
674
- V < Xe.y + Xt / 2 ? V = Xe.y - m : V = Xe.y + Xt + m;
676
+ } else if (!De && !Ot) {
677
+ var N, xl = rr === "bottom" && D < ar, gl = rr === "top" && D > ar;
678
+ if (xl || gl) {
679
+ N = (D + ar) / 2;
680
+ var rt = Br(A, R, N, er);
681
+ if (rt) {
682
+ var at = d(rt), eo = rt.height || B;
683
+ N < at.y + eo / 2 ? N = at.y - T : N = at.y + eo + T;
675
684
  }
676
685
  } else
677
- p === "bottom" ? V = Math.max(se.y + ca, de.y + $t) + m : V = Math.min(se.y, de.y) - m;
678
- Z = [{ x: _, y: O }, { x: _, y: V }, { x: R, y: V }, { x: R, y: rr }];
679
- var He = wr(_, O, V, ar);
680
- if (He) {
681
- var Ht = d(He), sl = He.width || L, pt = Ht.x - m, ro = Ht.x + sl + m, ao = Math.abs(R - pt) <= Math.abs(R - ro) ? pt : ro;
682
- Z = [
683
- { x: _, y: O },
684
- { x: ao, y: O },
685
- { x: ao, y: V },
686
- { x: R, y: V },
687
- { x: R, y: rr }
686
+ rr === "bottom" ? N = Math.max(ge.y + Na, Me.y + Nt) + T : N = Math.min(ge.y, Me.y) - T;
687
+ K = [{ x: A, y: D }, { x: A, y: N }, { x: R, y: N }, { x: R, y: ar }];
688
+ var et = Ar(A, D, N, er);
689
+ if (et) {
690
+ var to = d(et), Ml = et.width || L, oo = to.x - T, lo = to.x + Ml + T, io = Math.abs(R - oo) <= Math.abs(R - lo) ? oo : lo;
691
+ K = [
692
+ { x: A, y: D },
693
+ { x: io, y: D },
694
+ { x: io, y: N },
695
+ { x: R, y: N },
696
+ { x: R, y: ar }
688
697
  ];
689
698
  }
690
- var pe = wr(R, V, rr, ar);
691
- if (pe) {
692
- var eo = d(pe), dl = pe.height || B, to = eo.y - m, oo = eo.y + dl + m, yl = Math.abs(V - to) <= Math.abs(V - oo) ? to : oo;
693
- Z.splice(
694
- Z.length - 1,
699
+ var tt = Ar(R, N, ar, er);
700
+ if (tt) {
701
+ var fo = d(tt), kl = tt.height || B, vo = fo.y - T, ho = fo.y + kl + T, ml = Math.abs(N - vo) <= Math.abs(N - ho) ? vo : ho;
702
+ K.splice(
703
+ K.length - 1,
695
704
  0,
696
- { x: U, y: yl }
705
+ { x: U, y: ml }
697
706
  );
698
707
  }
699
- } else if (ce) {
700
- Z = [{ x: F, y: w }, { x: R, y: w }, { x: R, y: rr }];
701
- var rt = wr(R, w, rr, ar);
702
- if (rt) {
703
- var lo = d(rt), xl = rt.width || L, io = lo.x - m, fo = lo.x + xl + m, vo = Math.abs(_ - io) <= Math.abs(_ - fo) ? io : fo;
704
- Z = [{ x: F, y: w }, { x: vo, y: w }, { x: vo, y: z }, { x: R, y: z }, { x: R, y: rr }];
708
+ } else if (De) {
709
+ K = [{ x: c, y: w }, { x: R, y: w }, { x: R, y: ar }];
710
+ var ot = Ar(R, w, ar, er);
711
+ if (ot) {
712
+ var no = d(ot), Tl = ot.width || L, uo = no.x - T, so = no.x + Tl + T, yo = Math.abs(A - uo) <= Math.abs(A - so) ? uo : so;
713
+ K = [{ x: c, y: w }, { x: yo, y: w }, { x: yo, y: z }, { x: R, y: z }, { x: R, y: ar }];
705
714
  }
706
- var at = zr(F, R, w, ar);
707
- if (at) {
708
- var no = d(at), Ml = at.height || B, ho = no.y - m, uo = no.y + Ml + m, so = Math.abs(z - ho) <= Math.abs(z - uo) ? ho : uo;
709
- Z = [{ x: F, y: w }, { x: F, y: so }, { x: R, y: so }, { x: R, y: rr }];
715
+ var lt = Br(c, R, w, er);
716
+ if (lt) {
717
+ var xo = d(lt), Rl = lt.height || B, go = xo.y - T, Mo = xo.y + Rl + T, ko = Math.abs(z - go) <= Math.abs(z - Mo) ? go : Mo;
718
+ K = [{ x: c, y: w }, { x: c, y: ko }, { x: R, y: ko }, { x: R, y: ar }];
710
719
  }
711
720
  } else {
712
- Z = [{ x: _, y: O }, { x: _, y: z }, { x: U, y: z }];
713
- var et = zr(_, U, z, ar);
714
- if (et) {
715
- var yo = d(et), gl = et.height || B, xo = yo.y - m, Mo = yo.y + gl + m, go = Math.abs(w - xo) <= Math.abs(w - Mo) ? xo : Mo;
716
- Z = [{ x: _, y: O }, { x: _, y: go }, { x: U, y: go }, { x: U, y: z }];
721
+ K = [{ x: A, y: D }, { x: A, y: z }, { x: U, y: z }];
722
+ var it = Br(A, U, z, er);
723
+ if (it) {
724
+ var mo = d(it), zl = it.height || B, To = mo.y - T, Ro = mo.y + zl + T, zo = Math.abs(w - To) <= Math.abs(w - Ro) ? To : Ro;
725
+ K = [{ x: A, y: D }, { x: A, y: zo }, { x: U, y: zo }, { x: U, y: z }];
717
726
  }
718
- var tt = wr(_, O, z, ar);
719
- if (tt) {
720
- var ko = d(tt), kl = tt.width || L, To = ko.x - m, mo = ko.x + kl + m, Ro = Math.abs(R - To) <= Math.abs(R - mo) ? To : mo;
721
- Z = [{ x: _, y: O }, { x: Ro, y: O }, { x: Ro, y: z }, { x: U, y: z }];
727
+ var ft = Ar(A, D, z, er);
728
+ if (ft) {
729
+ var wo = d(ft), wl = ft.width || L, Bo = wo.x - T, Ao = wo.x + wl + T, _o = Math.abs(R - Bo) <= Math.abs(R - Ao) ? Bo : Ao;
730
+ K = [{ x: A, y: D }, { x: _o, y: D }, { x: _o, y: z }, { x: U, y: z }];
722
731
  }
723
732
  }
724
- for (var ta = [{ x: _, y: w }], ot = 0; ot < Z.length; ot++) ta.push(Z[ot]);
725
- ta.push({ x: R, y: z });
726
- for (var er = [ta[0]], Va = 1; Va < ta.length; Va++) {
727
- var Na = er[er.length - 1];
728
- (Math.abs(ta[Va].x - Na.x) > 0.1 || Math.abs(ta[Va].y - Na.y) > 0.1) && er.push(ta[Va]);
733
+ for (var oa = [{ x: A, y: w }], vt = 0; vt < K.length; vt++) oa.push(K[vt]);
734
+ oa.push({ x: R, y: z });
735
+ for (var tr = [oa[0]], Oa = 1; Oa < oa.length; Oa++) {
736
+ var Da = tr[tr.length - 1];
737
+ (Math.abs(oa[Oa].x - Da.x) > 0.1 || Math.abs(oa[Oa].y - Da.y) > 0.1) && tr.push(oa[Oa]);
729
738
  }
730
- var zo = ur === "smoothstep" ? 8 : 0;
731
- b.moveTo(er[0].x, er[0].y);
732
- for (var gr = 1; gr < er.length; gr++)
733
- if (zo > 0 && gr > 0 && gr < er.length - 1) {
734
- var kr = er[gr - 1], S = er[gr], qr = er[gr + 1];
735
- if (Math.abs(kr.x - S.x) < 0.5 && Math.abs(S.x - qr.x) < 0.5 || Math.abs(kr.y - S.y) < 0.5 && Math.abs(S.y - qr.y) < 0.5)
736
- b.lineTo(S.x, S.y);
739
+ var Eo = sr === "smoothstep" ? 8 : 0;
740
+ J.moveTo(tr[0].x, tr[0].y);
741
+ for (var p = 1; p < tr.length; p++)
742
+ if (Eo > 0 && p > 0 && p < tr.length - 1) {
743
+ var mr = tr[p - 1], S = tr[p], Gr = tr[p + 1];
744
+ if (Math.abs(mr.x - S.x) < 0.5 && Math.abs(S.x - Gr.x) < 0.5 || Math.abs(mr.y - S.y) < 0.5 && Math.abs(S.y - Gr.y) < 0.5)
745
+ J.lineTo(S.x, S.y);
737
746
  else {
738
- var ye = Math.min(Math.hypot(kr.x - S.x, kr.y - S.y) / 2, Math.hypot(S.x - qr.x, S.y - qr.y) / 2, zo);
739
- Math.abs(kr.y - S.y) < 0.5 ? (b.lineTo(S.x + (kr.x < qr.x ? -1 : 1) * ye, S.y), b.quadraticCurveTo(S.x, S.y, S.x, S.y + (kr.y < qr.y ? 1 : -1) * ye)) : (b.lineTo(S.x, S.y + (kr.y < qr.y ? -1 : 1) * ye), b.quadraticCurveTo(S.x, S.y, S.x + (kr.x < qr.x ? 1 : -1) * ye, S.y));
747
+ var ke = Math.min(Math.hypot(mr.x - S.x, mr.y - S.y) / 2, Math.hypot(S.x - Gr.x, S.y - Gr.y) / 2, Eo);
748
+ Math.abs(mr.y - S.y) < 0.5 ? (J.lineTo(S.x + (mr.x < Gr.x ? -1 : 1) * ke, S.y), J.quadraticCurveTo(S.x, S.y, S.x, S.y + (mr.y < Gr.y ? 1 : -1) * ke)) : (J.lineTo(S.x, S.y + (mr.y < Gr.y ? -1 : 1) * ke), J.quadraticCurveTo(S.x, S.y, S.x + (mr.x < Gr.x ? 1 : -1) * ke, S.y));
740
749
  }
741
750
  } else
742
- b.lineTo(er[gr].x, er[gr].y);
743
- } catch (Qr) {
744
- console.error("[worker] smoothstep error:", Qr, "edge:", D.id);
751
+ J.lineTo(tr[p].x, tr[p].y);
752
+ } catch ($r) {
753
+ console.error("[worker] smoothstep error:", $r, "edge:", O.id);
745
754
  }
746
755
  else {
747
- var Gr = he.position || "right", Ir = ue.position || "left", Zr = 20, Da = _, xe = w, Oa = R, Me = z;
748
- Gr === "right" ? Da += Zr : Gr === "left" ? Da -= Zr : Gr === "bottom" ? xe += Zr : Gr === "top" && (xe -= Zr), Ir === "right" ? Oa += Zr : Ir === "left" ? Oa -= Zr : Ir === "bottom" ? Me += Zr : Ir === "top" && (Me -= Zr);
749
- var Tl = Math.abs(Oa - Da), Kr = Math.max(50, Tl * 0.5), ml = Da + (Gr === "left" ? -Kr : Gr === "right" ? Kr : 0), Rl = xe + (Gr === "top" ? -Kr : Gr === "bottom" ? Kr : 0), zl = Oa + (Ir === "left" ? -Kr : Ir === "right" ? Kr : 0), wl = Me + (Ir === "top" ? -Kr : Ir === "bottom" ? Kr : 0);
750
- b.moveTo(_, w), b.lineTo(Da, xe), b.bezierCurveTo(ml, Rl, zl, wl, Oa, Me), b.lineTo(R, z);
756
+ var Ir = ye.position || "right", Zr = xe.position || "left", Kr = 20, ja = A, me = w, Ya = R, Te = z;
757
+ Ir === "right" ? ja += Kr : Ir === "left" ? ja -= Kr : Ir === "bottom" ? me += Kr : Ir === "top" && (me -= Kr), Zr === "right" ? Ya += Kr : Zr === "left" ? Ya -= Kr : Zr === "bottom" ? Te += Kr : Zr === "top" && (Te -= Kr);
758
+ var Bl = Math.abs(Ya - ja), br = Math.max(50, Bl * 0.5), Al = ja + (Ir === "left" ? -br : Ir === "right" ? br : 0), _l = me + (Ir === "top" ? -br : Ir === "bottom" ? br : 0), El = Ya + (Zr === "left" ? -br : Zr === "right" ? br : 0), Ll = Te + (Zr === "top" ? -br : Zr === "bottom" ? br : 0);
759
+ J.moveTo(A, w), J.lineTo(ja, me), J.bezierCurveTo(Al, _l, El, Ll, Ya, Te), J.lineTo(R, z);
751
760
  }
752
- if (ol) {
753
- var Bl = 8, ja;
754
- if (J && J.length >= 2) {
755
- var Na = J[J.length - 1], wo = J[J.length - 2];
756
- ja = Math.atan2(Na.y - wo.y, Na.x - wo.x);
757
- } else if (ur === "straight")
758
- ja = Math.atan2(z - w, R - _);
759
- else if (ur === "step" || ur === "smoothstep")
760
- ja = 0;
761
+ if (hl) {
762
+ var Sl = 8, Xa;
763
+ if (Q && Q.length >= 2) {
764
+ var Da = Q[Q.length - 1], Lo = Q[Q.length - 2];
765
+ Xa = Math.atan2(Da.y - Lo.y, Da.x - Lo.x);
766
+ } else if (sr === "straight")
767
+ Xa = Math.atan2(z - w, R - A);
768
+ else if (sr === "step" || sr === "smoothstep")
769
+ Xa = 0;
761
770
  else {
762
- var Bo = Gt(_, w, R, z);
763
- ja = Math.atan2(z - Bo.cp2y, R - Bo.cp2x);
771
+ var So = Qt(A, w, R, z);
772
+ Xa = Math.atan2(z - So.cp2y, R - So.cp2x);
764
773
  }
765
- var Ao = J && J.length >= 2 ? J[J.length - 1] : { x: R, y: z }, lt = { x: Ao.x, y: Ao.y, angle: ja, size: Bl };
766
- bt ? Fa.push(lt) : Jt ? ra.push(lt) : $a.push(lt);
774
+ var Co = Q && Q.length >= 2 ? Q[Q.length - 1] : { x: R, y: z }, ht = { x: Co.x, y: Co.y, angle: Xa, size: Sl };
775
+ ct ? Fa.push(ht) : Ut ? ra.push(ht) : $a.push(ht);
767
776
  }
768
- if (ne && D.label) {
769
- var Ya;
770
- J && J.length >= 2 ? Ya = jl(J) : ur === "straight" || ur === "step" || ur === "smoothstep" ? Ya = { x: (_ + R) / 2, y: (w + z) / 2 } : Ya = Yl(_, w, R, z), hr.push({ text: D.label, x: Ya.x, y: Ya.y });
777
+ if (ue && O.label) {
778
+ var Ha;
779
+ Q && Q.length >= 2 ? Ha = ri(Q) : sr === "straight" || sr === "step" || sr === "smoothstep" ? Ha = { x: (A + R) / 2, y: (w + z) / 2 } : Ha = ai(A, w, R, z), ur.push({ text: O.label, x: Ha.x, y: Ha.y });
771
780
  }
772
781
  }
773
782
  }
774
- if (Pr && (r.strokeStyle = k.edgeStroke, r.lineWidth = 1.5, r.setLineDash([]), r.stroke(Pr)), nr && (r.strokeStyle = k.edgeAnimated, r.lineWidth = 1.5, r.setLineDash([5, 5]), r.lineDashOffset = -qt, r.stroke(nr), r.setLineDash([])), Mr && (r.strokeStyle = k.edgeSelected, r.lineWidth = 2.5, r.setLineDash([]), r.stroke(Mr)), Le($a, k.edgeStroke), Le(ra, k.edgeAnimated), Le(Fa, k.edgeSelected), hr.length > 0) {
775
- r.font = Vl, r.textAlign = "center", r.textBaseline = "middle";
776
- for (var it = 0; it < hr.length; it++) {
777
- var Sa = hr[it], Al = r.measureText(Sa.text), _o = Al.width + 12;
778
- r.fillStyle = $ ? "#2a2a2a" : "#ffffff", r.fillRect(Sa.x - _o / 2, Sa.y - 9, _o, 18), r.fillStyle = k.nodeText, r.fillText(Sa.text, Sa.x, Sa.y);
783
+ if (qr && (r.strokeStyle = k.edgeStroke, r.lineWidth = 1.5, r.setLineDash([]), r.stroke(qr)), nr && (r.strokeStyle = k.edgeAnimated, r.lineWidth = 1.5, r.setLineDash([5, 5]), r.lineDashOffset = -Jt, r.stroke(nr), r.setLineDash([])), kr && (r.strokeStyle = k.edgeSelected, r.lineWidth = 2.5, r.setLineDash([]), r.stroke(kr)), qe($a, k.edgeStroke), qe(ra, k.edgeAnimated), qe(Fa, k.edgeSelected), ur.length > 0) {
784
+ r.font = Yl, r.textAlign = "center", r.textBaseline = "middle";
785
+ for (var nt = 0; nt < ur.length; nt++) {
786
+ var Sa = ur[nt], Cl = r.measureText(Sa.text), Wo = Cl.width + 12;
787
+ r.fillStyle = F ? "#2a2a2a" : "#ffffff", r.fillRect(Sa.x - Wo / 2, Sa.y - 9, Wo, 18), r.fillStyle = k.nodeText, r.fillText(Sa.text, Sa.x, Sa.y);
779
788
  }
780
789
  r.textAlign = "start", r.textBaseline = "alphabetic";
781
790
  }
782
791
  }
783
- if (ee) {
792
+ if (oe) {
784
793
  r.beginPath(), r.strokeStyle = k.connectionLine, r.lineWidth = 2, r.setLineDash([6, 4]);
785
- var ft = ee._routedPoints;
786
- if (ft && ft.length >= 2) {
787
- var Eo = new Path2D();
788
- Yo(Eo, ft), r.stroke(Eo);
794
+ var ut = oe._routedPoints;
795
+ if (ut && ut.length >= 2) {
796
+ var Po = new Path2D();
797
+ al(Po, ut), r.stroke(Po);
789
798
  } else {
790
- var ge = ee.from, ke = ee.to, Te = Gt(ge.x, ge.y, ke.x, ke.y);
791
- r.moveTo(ge.x, ge.y), r.bezierCurveTo(Te.cp1x, Te.cp1y, Te.cp2x, Te.cp2y, ke.x, ke.y), r.stroke();
799
+ var Re = oe.from, ze = oe.to, we = Qt(Re.x, Re.y, ze.x, ze.y);
800
+ r.moveTo(Re.x, Re.y), r.bezierCurveTo(we.cp1x, we.cp1y, we.cp2x, we.cp2y, ze.x, ze.y), r.stroke();
792
801
  }
793
802
  r.setLineDash([]);
794
803
  }
795
- if (xr) {
796
- var Lo = Math.min(xr.startWorld.x, xr.endWorld.x), So = Math.min(xr.startWorld.y, xr.endWorld.y), Ua = Math.abs(xr.endWorld.x - xr.startWorld.x), ca = Math.abs(xr.endWorld.y - xr.startWorld.y);
797
- r.fillStyle = $ ? "rgba(59,130,246,0.08)" : "rgba(59,130,246,0.06)", r.fillRect(Lo, So, Ua, ca), r.strokeStyle = "#3b82f6", r.lineWidth = 1 / g.zoom, r.setLineDash([]), r.strokeRect(Lo, So, Ua, ca);
804
+ if (gr) {
805
+ var qo = Math.min(gr.startWorld.x, gr.endWorld.x), Go = Math.min(gr.startWorld.y, gr.endWorld.y), Va = Math.abs(gr.endWorld.x - gr.startWorld.x), Na = Math.abs(gr.endWorld.y - gr.startWorld.y);
806
+ r.fillStyle = F ? "rgba(59,130,246,0.08)" : "rgba(59,130,246,0.06)", r.fillRect(qo, Go, Va, Na), r.strokeStyle = "#3b82f6", r.lineWidth = 1 / M.zoom, r.setLineDash([]), r.strokeRect(qo, Go, Va, Na);
798
807
  }
799
- if (vr > 0) {
800
- var oa = g.zoom > 0.12 && (g.zoom > 0.25 || vr < 500), vt = g.zoom > 0.08 && vr < 200, _l = g.zoom > 0.2 && vr < 300, El = Object.keys(Ce).length > 0 || Object.keys(te).length > 0 || Object.keys(We).length > 0, br = lr, me = [], Re = [];
801
- if (El) {
802
- br = [];
803
- for (var nt = 0; nt < vr; nt++) {
804
- var Jr = lr[nt];
805
- te[Jr.id] || Jr.type && Ce[Jr.type] ? me.push(Jr) : Jr.type && We[Jr.type] ? Re.push(Jr) : br.push(Jr);
808
+ if (hr > 0) {
809
+ var Be = Kt > 0, la = !Be && M.zoom > 0.12 && (M.zoom > 0.25 || hr < 500), st = !Be && M.zoom > 0.08 && hr < 200, Wl = !Be && M.zoom > 0.2 && hr < 300, Pl = !Be && (Object.keys(Ge).length > 0 || Object.keys(le).length > 0 || Object.keys(Ie).length > 0), Jr = ir, Ae = [], _e = [];
810
+ if (Pl) {
811
+ Jr = [];
812
+ for (var dt = 0; dt < hr; dt++) {
813
+ var Qr = ir[dt];
814
+ le[Qr.id] || Qr.type && Ge[Qr.type] ? Ae.push(Qr) : Qr.type && Ie[Qr.type] ? _e.push(Qr) : Jr.push(Qr);
806
815
  }
807
816
  }
808
- var Xa = br.length;
809
- if (vt) {
817
+ var pa = Jr.length;
818
+ if (st) {
810
819
  r.shadowColor = k.nodeShadow, r.shadowBlur = 6, r.shadowOffsetY = 2, r.fillStyle = k.nodeBg, r.beginPath();
811
- for (var ht = 0; ht < Xa; ht++) {
812
- var ze = br[ht];
813
- r.roundRect(d(ze).x, d(ze).y, ze.width || L, ze.height || B, qa);
820
+ for (var yt = 0; yt < pa; yt++) {
821
+ var Ee = Jr[yt];
822
+ r.roundRect(d(Ee).x, d(Ee).y, Ee.width || L, Ee.height || B, qa);
814
823
  }
815
824
  r.fill(), r.shadowColor = "transparent", r.shadowBlur = 0, r.shadowOffsetY = 0;
816
825
  }
817
- if (!vt) {
826
+ if (!st) {
818
827
  r.fillStyle = k.nodeBg, r.beginPath();
819
- for (var ut = 0; ut < Xa; ut++) {
820
- var we = br[ut];
821
- r.roundRect(d(we).x, d(we).y, we.width || L, we.height || B, qa);
828
+ for (var xt = 0; xt < pa; xt++) {
829
+ var Le = Jr[xt];
830
+ r.roundRect(d(Le).x, d(Le).y, Le.width || L, Le.height || B, qa);
822
831
  }
823
832
  r.fill();
824
833
  }
825
834
  r.strokeStyle = k.nodeBorder, r.lineWidth = 1, r.beginPath();
826
- for (var st = 0; st < Xa; st++) {
827
- var Ha = br[st];
828
- Ha.selected || r.roundRect(d(Ha).x, d(Ha).y, Ha.width || L, Ha.height || B, qa);
835
+ for (var gt = 0; gt < pa; gt++) {
836
+ var re = Jr[gt];
837
+ re.selected || r.roundRect(d(re).x, d(re).y, re.width || L, re.height || B, qa);
829
838
  }
830
839
  r.stroke();
831
- var Co = !1;
840
+ var Io = !1;
832
841
  r.strokeStyle = k.nodeSelectedBorder, r.lineWidth = 2, r.beginPath();
833
- for (var dt = 0; dt < Xa; dt++) {
834
- var pa = br[dt];
835
- pa.selected && (Co = !0, r.roundRect(d(pa).x, d(pa).y, pa.width || L, pa.height || B, qa));
842
+ for (var Mt = 0; Mt < pa; Mt++) {
843
+ var ae = Jr[Mt];
844
+ ae.selected && (Io = !0, r.roundRect(d(ae).x, d(ae).y, ae.width || L, ae.height || B, qa));
836
845
  }
837
- if (Co && r.stroke(), oa) {
838
- r.fillStyle = k.nodeText, r.font = Uo, r.textAlign = "center", r.textBaseline = "middle";
839
- for (var yt = 0; yt < Xa; yt++) {
840
- var la = br[yt];
841
- if (!(!la.data || !la.data.label)) {
842
- var Wo = la.width || L, Ll = la.height || B;
843
- r.fillText(la.data.label, d(la).x + Wo / 2, d(la).y + Ll / 2, Wo - 24);
846
+ if (Io && r.stroke(), la) {
847
+ r.fillStyle = k.nodeText, r.font = Do, r.textAlign = "center", r.textBaseline = "middle";
848
+ for (var kt = 0; kt < pa; kt++) {
849
+ var ia = Jr[kt];
850
+ if (!(!ia.data || !ia.data.label)) {
851
+ var Zo = ia.width || L, ql = ia.height || B;
852
+ r.fillText(ia.data.label, d(ia).x + Zo / 2, d(ia).y + ql / 2, Zo - 24);
844
853
  }
845
854
  }
846
855
  r.textAlign = "start", r.textBaseline = "alphabetic";
847
856
  }
848
- for (var xt = 0; xt < me.length; xt++) {
849
- var sr = me[xt], Ca = d(sr), Be = sr.width || L, Mt = sr.height || B, Po = te[sr.id] && Xo[te[sr.id]] || Ce[sr.type];
850
- Po && r.drawImage(Po, Ca.x, Ca.y, Be, Mt), oa && sr.data && sr.data.label && (r.fillStyle = k.nodeText, r.font = Uo, r.textAlign = "center", r.textBaseline = "middle", r.fillText(sr.data.label, Ca.x + Be / 2, Ca.y + Mt / 2, Be - 24)), sr.selected && (r.strokeStyle = k.nodeSelectedBorder, r.lineWidth = 2, r.beginPath(), r.roundRect(Ca.x, Ca.y, Be, Mt, qa), r.stroke());
857
+ for (var mt = 0; mt < Ae.length; mt++) {
858
+ var dr = Ae[mt], Ca = d(dr), Se = dr.width || L, Tt = dr.height || B, Ko = le[dr.id] && el[le[dr.id]] || Ge[dr.type];
859
+ Ko && r.drawImage(Ko, Ca.x, Ca.y, Se, Tt), la && dr.data && dr.data.label && (r.fillStyle = k.nodeText, r.font = Do, r.textAlign = "center", r.textBaseline = "middle", r.fillText(dr.data.label, Ca.x + Se / 2, Ca.y + Tt / 2, Se - 24)), dr.selected && (r.strokeStyle = k.nodeSelectedBorder, r.lineWidth = 2, r.beginPath(), r.roundRect(Ca.x, Ca.y, Se, Tt, qa), r.stroke());
851
860
  }
852
- me.length > 0 && oa && (r.textAlign = "start", r.textBaseline = "alphabetic");
853
- for (var gt = 0; gt < Re.length; gt++) {
854
- var ia = Re[gt], P = We[ia.type], E = d(ia), Tr = ia.width || L, fa = ia.height || B, ir = P.radius || qa, Ae = ia.data || {};
855
- if (vt && P.shadow !== !1 && (r.save(), r.shadowColor = P.shadowColor || k.nodeShadow, r.shadowBlur = P.shadowBlur || 6, r.shadowOffsetY = P.shadowOffsetY || 2, r.fillStyle = P.fill || k.nodeBg, r.beginPath(), r.roundRect(E.x, E.y, Tr, fa, ir), r.fill(), r.restore()), r.fillStyle = P.fill || k.nodeBg, r.beginPath(), r.roundRect(E.x, E.y, Tr, fa, ir), r.fill(), r.strokeStyle = ia.selected ? k.nodeSelectedBorder : P.stroke || k.nodeBorder, r.lineWidth = ia.selected ? 2 : P.strokeWidth || 1, r.beginPath(), r.roundRect(E.x, E.y, Tr, fa, ir), r.stroke(), P.accent) {
856
- var re = P.accent;
857
- r.fillStyle = re.color || "#3b82f6";
858
- var Wa = re.width || 5;
859
- r.beginPath(), re.side === "right" ? r.roundRect(E.x + Tr - Wa, E.y, Wa, fa, [0, ir, ir, 0]) : re.side === "top" ? r.roundRect(E.x, E.y, Tr, Wa, [ir, ir, 0, 0]) : re.side === "bottom" ? r.roundRect(E.x, E.y + fa - Wa, Tr, Wa, [0, 0, ir, ir]) : r.roundRect(E.x, E.y, Wa, fa, [ir, 0, 0, ir]), r.fill();
860
- }
861
- if (P.icon && oa) {
862
- var mr = P.icon, qo = mr.dataField ? Ae[mr.dataField] : mr.text;
863
- if (qo) {
864
- r.font = (mr.size || 18) + "px system-ui, sans-serif", r.textAlign = "center", r.textBaseline = "middle", r.fillStyle = mr.color || k.nodeText;
865
- var Sl = E.x + (mr.x !== void 0 ? mr.x : 20), Cl = E.y + (mr.y !== void 0 ? mr.y : fa / 2);
866
- r.fillText(qo, Sl, Cl);
861
+ Ae.length > 0 && la && (r.textAlign = "start", r.textBaseline = "alphabetic");
862
+ for (var Rt = 0; Rt < _e.length; Rt++) {
863
+ var fa = _e[Rt], I = Ie[fa.type], E = d(fa), Tr = fa.width || L, va = fa.height || B, fr = I.radius || qa, Ce = fa.data || {};
864
+ if (st && I.shadow !== !1 && (r.save(), r.shadowColor = I.shadowColor || k.nodeShadow, r.shadowBlur = I.shadowBlur || 6, r.shadowOffsetY = I.shadowOffsetY || 2, r.fillStyle = I.fill || k.nodeBg, r.beginPath(), r.roundRect(E.x, E.y, Tr, va, fr), r.fill(), r.restore()), r.fillStyle = I.fill || k.nodeBg, r.beginPath(), r.roundRect(E.x, E.y, Tr, va, fr), r.fill(), r.strokeStyle = fa.selected ? k.nodeSelectedBorder : I.stroke || k.nodeBorder, r.lineWidth = fa.selected ? 2 : I.strokeWidth || 1, r.beginPath(), r.roundRect(E.x, E.y, Tr, va, fr), r.stroke(), I.accent) {
865
+ var ee = I.accent;
866
+ r.fillStyle = ee.color || "#3b82f6";
867
+ var Wa = ee.width || 5;
868
+ r.beginPath(), ee.side === "right" ? r.roundRect(E.x + Tr - Wa, E.y, Wa, va, [0, fr, fr, 0]) : ee.side === "top" ? r.roundRect(E.x, E.y, Tr, Wa, [fr, fr, 0, 0]) : ee.side === "bottom" ? r.roundRect(E.x, E.y + va - Wa, Tr, Wa, [0, 0, fr, fr]) : r.roundRect(E.x, E.y, Wa, va, [fr, 0, 0, fr]), r.fill();
869
+ }
870
+ if (I.icon && la) {
871
+ var Rr = I.icon, bo = Rr.dataField ? Ce[Rr.dataField] : Rr.text;
872
+ if (bo) {
873
+ r.font = (Rr.size || 18) + "px system-ui, sans-serif", r.textAlign = "center", r.textBaseline = "middle", r.fillStyle = Rr.color || k.nodeText;
874
+ var Gl = E.x + (Rr.x !== void 0 ? Rr.x : 20), Il = E.y + (Rr.y !== void 0 ? Rr.y : va / 2);
875
+ r.fillText(bo, Gl, Il);
867
876
  }
868
877
  }
869
- if (P.title && oa) {
870
- var dr = P.title, Go = dr.dataField ? Ae[dr.dataField] : dr.text;
871
- if (Go) {
872
- r.font = dr.font || "600 13px system-ui, sans-serif", r.textAlign = dr.align || "left", r.textBaseline = "top", r.fillStyle = dr.color || k.nodeText;
873
- var Io = E.x + (dr.x !== void 0 ? dr.x : 12), Wl = E.y + (dr.y !== void 0 ? dr.y : 12);
874
- r.fillText(Go, Io, Wl, Tr - Io + E.x - 12);
878
+ if (I.title && la) {
879
+ var yr = I.title, Jo = yr.dataField ? Ce[yr.dataField] : yr.text;
880
+ if (Jo) {
881
+ r.font = yr.font || "600 13px system-ui, sans-serif", r.textAlign = yr.align || "left", r.textBaseline = "top", r.fillStyle = yr.color || k.nodeText;
882
+ var Qo = E.x + (yr.x !== void 0 ? yr.x : 12), Zl = E.y + (yr.y !== void 0 ? yr.y : 12);
883
+ r.fillText(Jo, Qo, Zl, Tr - Qo + E.x - 12);
875
884
  }
876
885
  }
877
- if (P.subtitle && oa) {
878
- var yr = P.subtitle, Zo = yr.dataField ? Ae[yr.dataField] : yr.text;
879
- if (Zo) {
880
- r.font = yr.font || "11px system-ui, sans-serif", r.textAlign = yr.align || "left", r.textBaseline = "top", r.fillStyle = yr.color || "#64748b";
881
- var Ko = E.x + (yr.x !== void 0 ? yr.x : 12), Pl = E.y + (yr.y !== void 0 ? yr.y : 32);
882
- r.fillText(Zo, Ko, Pl, Tr - Ko + E.x - 12);
886
+ if (I.subtitle && la) {
887
+ var xr = I.subtitle, $o = xr.dataField ? Ce[xr.dataField] : xr.text;
888
+ if ($o) {
889
+ r.font = xr.font || "11px system-ui, sans-serif", r.textAlign = xr.align || "left", r.textBaseline = "top", r.fillStyle = xr.color || "#64748b";
890
+ var Fo = E.x + (xr.x !== void 0 ? xr.x : 12), Kl = E.y + (xr.y !== void 0 ? xr.y : 32);
891
+ r.fillText($o, Fo, Kl, Tr - Fo + E.x - 12);
883
892
  }
884
893
  }
885
- if (P.badge && oa) {
886
- var Rr = P.badge, kt = Rr.dataField ? Ae[Rr.dataField] : Rr.text;
887
- if (kt) {
888
- r.font = Rr.font || "700 9px system-ui, sans-serif";
889
- var ql = r.measureText(kt), Gl = Rr.paddingX || 6, Il = Rr.paddingY || 3, Tt = ql.width + Gl * 2, mt = 14 + Il, bo = E.x + Tr - Tt / 2 - 4, Jo = E.y - mt / 2;
890
- r.fillStyle = Rr.bg || "#3b82f6", r.beginPath(), r.roundRect(bo, Jo, Tt, mt, Rr.radius || 7), r.fill(), r.fillStyle = Rr.color || "#fff", r.textAlign = "center", r.textBaseline = "middle", r.fillText(kt, bo + Tt / 2, Jo + mt / 2);
894
+ if (I.badge && la) {
895
+ var zr = I.badge, zt = zr.dataField ? Ce[zr.dataField] : zr.text;
896
+ if (zt) {
897
+ r.font = zr.font || "700 9px system-ui, sans-serif";
898
+ var bl = r.measureText(zt), Jl = zr.paddingX || 6, Ql = zr.paddingY || 3, wt = bl.width + Jl * 2, Bt = 14 + Ql, co = E.x + Tr - wt / 2 - 4, Uo = E.y - Bt / 2;
899
+ r.fillStyle = zr.bg || "#3b82f6", r.beginPath(), r.roundRect(co, Uo, wt, Bt, zr.radius || 7), r.fill(), r.fillStyle = zr.color || "#fff", r.textAlign = "center", r.textBaseline = "middle", r.fillText(zt, co + wt / 2, Uo + Bt / 2);
891
900
  }
892
901
  }
893
902
  }
894
- if (Re.length > 0 && (r.textAlign = "start", r.textBaseline = "alphabetic"), _l) {
895
- for (var Rt = [], zt = 0; zt < vr; zt++)
896
- for (var Qo = Ho(lr[zt]), wt = 0; wt < Qo.length; wt++)
897
- Rt.push(Qo[wt]);
903
+ if (_e.length > 0 && (r.textAlign = "start", r.textBaseline = "alphabetic"), Wl) {
904
+ for (var At = [], _t = 0; _t < hr; _t++)
905
+ for (var Vo = tl(ir[_t]), Et = 0; Et < Vo.length; Et++)
906
+ At.push(Vo[Et]);
898
907
  r.fillStyle = k.handleFill, r.beginPath();
899
- for (var Bt = 0; Bt < Rt.length; Bt++) {
900
- var _e = Rt[Bt];
901
- r.moveTo(_e.x + Fo, _e.y), r.arc(_e.x, _e.y, Fo, 0, 6.2832);
908
+ for (var Lt = 0; Lt < At.length; Lt++) {
909
+ var We = At[Lt];
910
+ r.moveTo(We.x + Oo, We.y), r.arc(We.x, We.y, Oo, 0, 6.2832);
902
911
  }
903
912
  r.fill(), r.strokeStyle = k.handleBorder, r.lineWidth = 1.5, r.stroke();
904
913
  }
905
914
  }
906
915
  r.restore();
907
- var Zl = (performance.now() - a).toFixed(1);
908
- Lt++;
909
- var Ee = performance.now();
910
- if (Ee - No >= 1e3 && (Do = Lt, Lt = 0, No = Ee), Ee - Oo >= 100) {
911
- Oo = Ee;
912
- var Kl = Math.round(-g.x / g.zoom), bl = Math.round(-g.y / g.zoom);
916
+ var $l = (performance.now() - a).toFixed(1);
917
+ Pt++;
918
+ var Pe = performance.now();
919
+ if (Pe - Xo >= 1e3 && (Ho = Pt, Pt = 0, Xo = Pe), Pe - po >= 100) {
920
+ po = Pe;
921
+ var Fl = Math.round(-M.x / M.zoom), cl = Math.round(-M.y / M.zoom);
913
922
  self.postMessage({
914
923
  type: "hud",
915
924
  data: {
916
- wx: Kl,
917
- wy: bl,
918
- zoom: g.zoom.toFixed(2),
919
- renderMs: Zl,
920
- fps: Do,
921
- visible: Y.length > 0 ? co(Dr, Or, da, jr).length : 0,
922
- nodeCount: G.length,
923
- visibleNodes: vr,
924
- edgeCount: q.length
925
+ wx: Fl,
926
+ wy: cl,
927
+ zoom: M.zoom.toFixed(2),
928
+ renderMs: $l,
929
+ fps: Ho,
930
+ visible: Y.length > 0 ? jo(Or, Dr, ya, jr).length : 0,
931
+ nodeCount: C.length,
932
+ visibleNodes: hr,
933
+ edgeCount: Z.length
925
934
  }
926
935
  });
927
936
  }
928
937
  }
929
938
  }
930
- `,lr=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",wr],{type:"text/javascript;charset=utf-8"});function eo(e){let t;try{if(t=lr&&(self.URL||self.webkitURL).createObjectURL(lr),!t)throw"";const n=new Worker(t,{type:"module",name:e==null?void 0:e.name});return n.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),n}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(wr),{type:"module",name:e==null?void 0:e.name})}}const Xn=new WeakMap;function to(e,t){if(Xn.has(e))return Xn.get(e);const n=e.transferControlToOffscreen(),r=new eo;r.onerror=o=>console.error("[infinite-canvas] worker error:",o.message,o),r.postMessage({type:"init",data:{...t,canvas:n}},[n]);const a={worker:r};return Xn.set(e,a),a}const ht=160,st=60,no=10;function Mr({cards:e=[],nodes:t=[],edges:n=[],onHudUpdate:r,onNodesProcessed:a,onNodesChange:o,onEdgesChange:c,onConnect:f,onNodeClick:m,onNodeDragStart:d,onNodeDrag:g,onNodeDragStop:b,onEdgeClick:E,onEdgeDoubleClick:C,onEdgeMouseEnter:S,onEdgeMouseMove:j,onEdgeMouseLeave:L,onEdgeContextMenu:A,onNodeDoubleClick:Y,onNodeMouseEnter:D,onNodeMouseMove:F,onNodeMouseLeave:$,onNodeContextMenu:N,onPaneClick:O,onPaneContextMenu:X,onPaneMouseEnter:H,onPaneMouseMove:w,onPaneMouseLeave:y,onSelectionChange:v,onConnectStart:z,onConnectEnd:P,onInit:B,onMoveStart:G,onMove:ne,onMoveEnd:ee,onDelete:se,onBeforeDelete:he,onError:ge,isValidConnection:de,dark:Re,gridSize:We=40,zoomMin:V=.1,zoomMax:oe=4,initialCamera:xe={x:0,y:0,zoom:1},fitView:Ze=!1,fitViewOptions:fe,nodesDraggable:je=!0,nodesConnectable:Ae=!0,elementsSelectable:Pe=!0,multiSelectionKeyCode:Ce="Shift",selectionOnDrag:rt=!1,selectionMode:at="partial",connectionMode:be="loose",connectionRadius:Ie=20,connectOnClick:Je=!1,snapToGrid:$e=!1,snapGrid:Ye=[15,15],deleteKeyCode:Ge=["Delete","Backspace"],panActivationKeyCode:Nt=" ",panOnScroll:cn=!1,panOnScrollMode:Pt="free",panOnScrollSpeed:ln=.5,zoomOnScroll:un=!0,zoomOnDoubleClick:dn=!0,zoomOnPinch:fn=!0,preventScrolling:Gt=!0,translateExtent:xt,nodeExtent:pt,defaultEdgeOptions:It={},autoPanOnNodeDrag:In=!0,autoPanOnConnect:Tn=!0,autoPanSpeed:it=5,edgesReconnectable:cr=!1,elevateNodesOnSelect:Ln=!1,elevateEdgesOnSelect:Bn=!1,noDragClassName:Tt="nodrag",noPanClassName:Lt="nopan",onSelectionDragStart:$n,onSelectionDrag:jn,onSelectionDragStop:An,edgeRouting:Ct=!0}={}){const pe=l.useRef(null),Bt=l.useRef(null),Te=l.useRef(null),ce=l.useRef({...xe}),mt=l.useRef([...e]),K=l.useRef([...t]),Ee=l.useRef([...n]),hn=l.useRef(new Map),$t=l.useRef(!1),jt=l.useRef(null),[At,Dn]=l.useState(!1),Xe=l.useRef(null),Ue=l.useRef(null),Dt=l.useRef(null),ct=l.useRef(null),gn=l.useRef(!1),Ke=l.useRef(null),[yn,xn]=l.useState({x:xe.x,y:xe.y,zoom:xe.zoom}),[Qt,pn]=l.useState(null),vt=l.useMemo(()=>new Set,[]),lt=l.useMemo(()=>new Set,[]),et=l.useRef(!1),Z=l.useRef({});Z.current={onHudUpdate:r,onNodesProcessed:a,onNodesChange:o,onEdgesChange:c,onConnect:f,onNodeClick:m,onNodeDragStart:d,onNodeDrag:g,onNodeDragStop:b,onEdgeClick:E,onEdgeDoubleClick:C,onEdgeMouseEnter:S,onEdgeMouseMove:j,onEdgeMouseLeave:L,onEdgeContextMenu:A,onNodeDoubleClick:Y,onNodeMouseEnter:D,onNodeMouseMove:F,onNodeMouseLeave:$,onNodeContextMenu:N,onPaneClick:O,onPaneContextMenu:X,onPaneMouseEnter:H,onPaneMouseMove:w,onPaneMouseLeave:y,onSelectionChange:v,onConnectStart:z,onConnectEnd:P,onInit:B,onMoveStart:G,onMove:ne,onMoveEnd:ee,onDelete:se,onBeforeDelete:he,onError:ge,onSelectionDragStart:$n,onSelectionDrag:jn,onSelectionDragStop:An,isValidConnection:de};const ut={get current(){return Z.current.onConnect}},Ht={get current(){return Z.current.onNodeClick}},_t={get current(){return Z.current.onNodeDragStart}},Wt={get current(){return Z.current.onNodeDrag}},Ft={get current(){return Z.current.onNodeDragStop}},Et={get current(){return Z.current.onEdgeClick}},bt={get current(){return Z.current.onPaneClick}},ot={get current(){return Z.current.onSelectionChange}},Yt={get current(){return Z.current.onHudUpdate}},Vt={get current(){return Z.current.onNodesProcessed}};l.useEffect(()=>{const u=i=>{i.key===Ce&&(gn.current=!0),i.key===Nt&&(et.current=!0)},x=i=>{i.key===Ce&&(gn.current=!1),i.key===Nt&&(et.current=!1)};return window.addEventListener("keydown",u),window.addEventListener("keyup",x),()=>{window.removeEventListener("keydown",u),window.removeEventListener("keyup",x)}},[Ce,Nt]);const Le={get current(){return Z.current.onNodesChange?mn:null}},mn=u=>{var i,h,M;(h=(i=Z.current).onNodesChange)==null||h.call(i,u);const x=[];for(let k=0;k<u.length;k++)u[k].type==="select"&&x.push({id:u[k].id,selected:u[k].selected});x.length>0&&((M=Te.current)==null||M.postMessage({type:"nodeSelections",data:{selections:x}}))},Fe={get current(){return Z.current.onEdgesChange?Hn:null}},Hn=u=>{var i,h,M;(h=(i=Z.current).onEdgesChange)==null||h.call(i,u);const x=[];for(let k=0;k<u.length;k++)u[k].type==="select"&&x.push({id:u[k].id,selected:u[k].selected});x.length>0&&((M=Te.current)==null||M.postMessage({type:"edgeSelections",data:{selections:x}}))},wt=l.useCallback(()=>{var h;const u=K.current.filter(M=>M.selected),x=Ee.current.filter(M=>M.selected),i={nodes:u,edges:x};(h=ot.current)==null||h.call(ot,i);for(const M of lt)M(i)},[lt]);l.useEffect(()=>{var u;mt.current=[...e],(u=Te.current)==null||u.postMessage({type:"cards",data:{cards:[...e]}})},[e]);const Xt=l.useCallback(u=>{const x={};for(const i of u)x[i.id]=i;return u.map(i=>{if(!i.parentId)return i;const h=x[i.parentId];if(!h)return i;let M=i.position.x,k=i.position.y,p=h;for(;p;)M+=p.position.x,k+=p.position.y,p=p.parentId?x[p.parentId]:null;return{...i,_absolutePosition:{x:M,y:k}}})},[]),dt=l.useRef([]),le=l.useCallback(u=>{const x=hn.current;if(!x||x.size===0)return u;const i={};for(const[,h]of x)i[h.nodeId]||(i[h.nodeId]=[]),i[h.nodeId].push({id:h.id,type:h.type,position:h.position,x:h.x,y:h.y});return u.map(h=>{const M=i[h.id];return M&&M.length>0?{...h,handles:M}:h})},[]),Ot=l.useCallback(()=>{var x;if(Xe.current)return;const u=le(dt.current);(x=Te.current)==null||x.postMessage({type:"nodes",data:{nodes:u}})},[le]);l.useEffect(()=>{var i,h;if(Xe.current){const M=Xe.current.id,k=new Set([M,...Xe.current.selectedStarts.map(R=>R.id)]),p={};for(const R of K.current)k.has(R.id)&&(p[R.id]={...R.position});K.current=[...t];for(const R of K.current)p[R.id]&&(R.position=p[R.id]);dt.current=Xt(K.current);const I=le(dt.current);(i=Te.current)==null||i.postMessage({type:"nodes",data:{nodes:I}});return}K.current=[...t];const u=Xt(t);dt.current=u;const x=le(u);(h=Te.current)==null||h.postMessage({type:"nodes",data:{nodes:x}})},[t,Xt,le]),l.useEffect(()=>{var u;Ee.current=[...n],(u=Te.current)==null||u.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const ke=l.useCallback((u,x)=>{const i=pe.current;if(!i)return{x:0,y:0};const h=i.getBoundingClientRect(),M=ce.current;return{x:(u-h.left-M.x)/M.zoom,y:(x-h.top-M.y)/M.zoom}},[]),tt=l.useCallback((u,x)=>{const i=dt.current.length>0?dt.current:K.current;let h=null;for(let M=i.length-1;M>=0;M--){const k=i[M];if(k.hidden)continue;const p=k._absolutePosition||k.position,I=k.width||ht,R=k.height||st;if(u>=p.x&&u<=p.x+I&&x>=p.y&&x<=p.y+R){if(k.type==="group"){h||(h=k);continue}return k}}return h},[]),vn=l.useCallback((u,x)=>{const i=x.width||ht,h=x.height||st;if(u.x!==void 0&&u.y!==void 0)return{x:x.position.x+u.x,y:x.position.y+u.y};switch(u.position||(u.type==="source"?"right":"left")){case"top":return{x:x.position.x+i/2,y:x.position.y};case"bottom":return{x:x.position.x+i/2,y:x.position.y+h};case"left":return{x:x.position.x,y:x.position.y+h/2};case"right":return{x:x.position.x+i,y:x.position.y+h/2};default:return{x:x.position.x+i,y:x.position.y+h/2}}},[]),Ut=l.useCallback(u=>{const x=u.width||ht,i=u.height||st;if(u.handles&&u.handles.length>0)return u.handles.map(R=>{const U=vn(R,u);return{id:R.id||null,type:R.type,x:U.x,y:U.y}});const h=u.targetPosition||"left",M=u.sourcePosition||"right",k=R=>{switch(R){case"top":return{x:u.position.x+x/2,y:u.position.y};case"bottom":return{x:u.position.x+x/2,y:u.position.y+i};case"left":return{x:u.position.x,y:u.position.y+i/2};case"right":return{x:u.position.x+x,y:u.position.y+i/2};default:return{x:u.position.x+x,y:u.position.y+i/2}}},p=k(h),I=k(M);return[{id:null,type:"target",x:p.x,y:p.y},{id:null,type:"source",x:I.x,y:I.y}]},[vn]),Mt=l.useCallback((u,x)=>{const i=K.current,h=ce.current,M=Math.max(no,Ie)/h.zoom;for(let k=i.length-1;k>=0;k--){const p=i[k];if(p.hidden)continue;const I=Ut(p);for(const R of I)if(Math.abs(u-R.x)<M&&Math.abs(x-R.y)<M)return{nodeId:p.id,handleId:R.id,type:R.type,x:R.x,y:R.y}}return null},[Ut]),nt=l.useCallback((u,x)=>{const h=8/ce.current.zoom;for(let M=Ee.current.length-1;M>=0;M--){const k=Ee.current[M],p=K.current.find(ae=>ae.id===k.source),I=K.current.find(ae=>ae.id===k.target);if(!p||!I)continue;const R=p.width||ht,U=p.height||st,W=I.height||st,Q=p.position.x+R,J=p.position.y+U/2,Me=I.position.x,He=I.position.y+W/2;if(ro(u,x,Q,J,Me,He)<h)return k}return null},[]);l.useEffect(()=>{const u=Bt.current,x=pe.current;if(!u||!x)return;const i=x.getBoundingClientRect(),h=Re!==void 0?Re:matchMedia("(prefers-color-scheme: dark)").matches,M=Xt(K.current);dt.current=M;const k=le(M),{worker:p}=to(u,{width:i.width,height:i.height,camera:ce.current,cards:mt.current,nodes:k,edges:Ee.current,dark:h,gridSize:We,edgeRouting:Ct});p.onmessage=W=>{var Q,J,Me,He;W.data.type==="hud"&&((Q=Yt.current)==null||Q.call(Yt,W.data.data)),W.data.type==="ready"&&Dn(!0),W.data.type==="nodesProcessed"&&((J=Vt.current)==null||J.call(Vt,W.data.data)),W.data.type==="error"&&((He=(Me=Z.current).onError)==null||He.call(Me,"worker-error",W.data.message||"Canvas worker error"))},p.onerror=W=>{var Q,J;(J=(Q=Z.current).onError)==null||J.call(Q,"worker-error",W.message||"Canvas worker crashed")},Te.current=p;const I=new ResizeObserver(W=>{const{width:Q,height:J}=W[0].contentRect;p.postMessage({type:"resize",data:{width:Q,height:J}})});I.observe(x);let R,U;return Re===void 0&&(R=matchMedia("(prefers-color-scheme: dark)"),U=W=>p.postMessage({type:"theme",data:{dark:W.matches}}),R.addEventListener("change",U)),()=>{I.disconnect(),R&&U&&R.removeEventListener("change",U),Te.current=null}},[]),l.useEffect(()=>{var u;Re!==void 0&&((u=Te.current)==null||u.postMessage({type:"theme",data:{dark:Re}}))},[Re]),l.useEffect(()=>{var u;(u=Te.current)==null||u.postMessage({type:"edgeRouting",data:{enabled:Ct}})},[Ct]);const qt=l.useRef(0),me=l.useCallback((u=null)=>{var h,M,k;const x=ce.current;if(xt){const p=pe.current;if(p){const I=p.getBoundingClientRect(),R=-xt[1][0]*x.zoom+I.width,U=-xt[1][1]*x.zoom+I.height,W=-xt[0][0]*x.zoom,Q=-xt[0][1]*x.zoom;x.x=Math.min(W,Math.max(R,x.x)),x.y=Math.min(Q,Math.max(U,x.y))}}(h=Te.current)==null||h.postMessage({type:"camera",data:{camera:{...x}}});const i={x:x.x,y:x.y,zoom:x.zoom};(k=(M=Z.current).onMove)==null||k.call(M,u,i);for(const p of vt)p(i);cancelAnimationFrame(qt.current),qt.current=requestAnimationFrame(()=>{xn({x:x.x,y:x.y,zoom:x.zoom})})},[vt,xt]),ft=l.useCallback(()=>{var i,h;const u=Ue.current,x=Dt.current;u&&x?((i=Te.current)==null||i.postMessage({type:"connecting",data:{from:u.startPos,to:x,_routedPoints:null}}),pn({source:u.sourceId,sourceHandle:u.sourceHandle,target:null,targetHandle:null})):((h=Te.current)==null||h.postMessage({type:"connecting",data:null}),pn(null))},[]),Rt=l.useCallback(()=>{var x,i;const u=ct.current;u?(x=Te.current)==null||x.postMessage({type:"selectionBox",data:u}):(i=Te.current)==null||i.postMessage({type:"selectionBox",data:null})},[]),_n=l.useCallback(u=>{var p,I,R,U,W,Q,J,Me,He,te,ae,ze,_e,Oe,Qe,qe,Jt,yt;const x=K.current.length>0,i=ke(u.clientX,u.clientY),h=gn.current;if(x&&Ae&&!h){const q=Mt(i.x,i.y);if(Je&&Ke.current&&q){const re=Ke.current;if(q.nodeId!==re.nodeId){const Ve=re.handleType==="target"?{source:q.nodeId,target:re.nodeId,sourceHandle:q.handleId||null,targetHandle:re.handleId}:{source:re.nodeId,target:q.nodeId,sourceHandle:re.handleId,targetHandle:q.handleId||null};(Z.current.isValidConnection?Z.current.isValidConnection(Ve):!0)&&((p=ut.current)==null||p.call(ut,{...Ve,...It}))}Ke.current=null;return}if(be==="strict"?q&&q.type==="source":q!=null){if(Je){Ke.current={nodeId:q.nodeId,handleId:q.handleId||null,handleType:q.type},(R=(I=Z.current).onConnectStart)==null||R.call(I,u,{nodeId:q.nodeId,handleId:q.handleId,handleType:q.type});return}Ue.current={sourceId:q.nodeId,sourceHandle:q.handleId||null,sourceType:q.type,startPos:{x:q.x,y:q.y}},Dt.current={x:i.x,y:i.y},(U=pe.current)==null||U.setPointerCapture(u.pointerId),(Q=(W=Z.current).onConnectStart)==null||Q.call(W,u,{nodeId:q.nodeId,handleId:q.handleId,handleType:q.type}),ft();return}}const M=q=>{var re;let ye=q;for(;ye&&ye!==pe.current;){if((re=ye.classList)!=null&&re.contains(Tt))return!0;ye=ye.parentElement}return!1},k=q=>{var re;let ye=q;for(;ye&&ye!==pe.current;){if((re=ye.classList)!=null&&re.contains(Lt))return!0;ye=ye.parentElement}return!1};if(x){const q=tt(i.x,i.y);if(q){if(Le.current&&Pe){const ye=[];if(h)ye.push({id:q.id,type:"select",selected:!q.selected});else if(!q.selected){for(const re of K.current)re.id===q.id?ye.push({id:re.id,type:"select",selected:!0}):re.selected&&ye.push({id:re.id,type:"select",selected:!1});if(Fe.current){const re=Ee.current.filter(ue=>ue.selected).map(ue=>({id:ue.id,type:"select",selected:!1}));re.length&&Fe.current(re)}}if(ye.length){if(Le.current(ye),Ln&&!h){const re=K.current.findIndex(ue=>ue.id===q.id);re>=0&&re<K.current.length-1&&Le.current([{id:q.id,type:"remove"},{type:"add",item:{...K.current[re],selected:!0}}])}wt()}}if((J=Ht.current)==null||J.call(Ht,u,q),je&&!M(u.target)){const ye=q.selected;let re=null;if(q.parentId&&q.extent==="parent"){const ue=K.current.find(Ve=>Ve.id===q.parentId);if(ue){const Ve=ue.width||ht,Kt=ue.height||st,bn=q.width||((Me=q.measured)==null?void 0:Me.width)||ht,en=q.height||((He=q.measured)==null?void 0:He.height)||st;re={minX:0,minY:0,maxX:Ve-bn,maxY:Kt-en}}}if(Xe.current={id:q.id,startPos:{...q.position},startMouse:{x:i.x,y:i.y},parentClamp:re,parentId:q.parentId||null,selectedStarts:ye?K.current.filter(ue=>ue.selected&&ue.id!==q.id).map(ue=>{var Kt,bn;let Ve=null;if(ue.parentId&&ue.extent==="parent"){const en=K.current.find(Yn=>Yn.id===ue.parentId);if(en){const Yn=en.width||ht,Wr=en.height||st,Fr=ue.width||((Kt=ue.measured)==null?void 0:Kt.width)||ht,Yr=ue.height||((bn=ue.measured)==null?void 0:bn.height)||st;Ve={minX:0,minY:0,maxX:Yn-Fr,maxY:Wr-Yr}}}return{id:ue.id,startPos:{...ue.position},parentClamp:Ve,parentId:ue.parentId||null}}):[]},(te=pe.current)==null||te.setPointerCapture(u.pointerId),(ae=_t.current)==null||ae.call(_t,u,q),Xe.current.selectedStarts.length>0){const ue=K.current.filter(Ve=>Ve.selected);(_e=(ze=Z.current).onSelectionDragStart)==null||_e.call(ze,u,ue)}if(Le.current){const ue=[{id:q.id,type:"position",dragging:!0}];for(const Ve of Xe.current.selectedStarts)ue.push({id:Ve.id,type:"position",dragging:!0});Le.current(ue)}}return}}if(Ee.current.length>0&&Pe){const q=nt(i.x,i.y);if(q){if(Fe.current){const ye=[];if(h)ye.push({id:q.id,type:"select",selected:!q.selected});else{for(const re of Ee.current)re.id===q.id?ye.push({id:re.id,type:"select",selected:!0}):re.selected&&ye.push({id:re.id,type:"select",selected:!1});if(Le.current){const re=K.current.filter(ue=>ue.selected).map(ue=>({id:ue.id,type:"select",selected:!1}));re.length&&Le.current(re)}}if(ye.length){if(Fe.current(ye),Bn&&!h){const re=Ee.current.findIndex(ue=>ue.id===q.id);re>=0&&re<Ee.current.length-1&&Fe.current([{id:q.id,type:"remove"},{type:"add",item:{...Ee.current[re],selected:!0}}])}wt()}}(Oe=Et.current)==null||Oe.call(Et,u,q);return}}if(!h){const q=K.current.filter(re=>re.selected).map(re=>({id:re.id,type:"select",selected:!1})),ye=Ee.current.filter(re=>re.selected).map(re=>({id:re.id,type:"select",selected:!1}));q.length&&Le.current&&Le.current(q),ye.length&&Fe.current&&Fe.current(ye),(q.length||ye.length)&&wt()}if((Qe=bt.current)==null||Qe.call(bt,u),rt||h){ct.current={startWorld:{...i},endWorld:{...i}},(qe=pe.current)==null||qe.setPointerCapture(u.pointerId),Rt();return}k(u.target)||($t.current=!0,jt.current={x:u.clientX,y:u.clientY},(Jt=pe.current)==null||Jt.classList.add("dragging"),(yt=pe.current)==null||yt.setPointerCapture(u.pointerId))},[ke,tt,Mt,nt,je,Ae,Pe,rt,ft,Rt,wt,Tt,Lt]),Wn=l.useCallback(u=>{var i,h,M,k;if(Ue.current){if(Dt.current=ke(u.clientX,u.clientY),ft(),Tn){const p=pe.current;if(p){const I=p.getBoundingClientRect(),R=40,U=u.clientX-I.left,W=u.clientY-I.top;let Q=0,J=0;U<R?Q=it:U>I.width-R&&(Q=-it),W<R?J=it:W>I.height-R&&(J=-it),(Q||J)&&(ce.current.x+=Q,ce.current.y+=J,me(u))}}return}if(ct.current){ct.current.endWorld=ke(u.clientX,u.clientY),Rt();const p=ct.current,I=Math.min(p.startWorld.x,p.endWorld.x),R=Math.min(p.startWorld.y,p.endWorld.y),U=Math.max(p.startWorld.x,p.endWorld.x),W=Math.max(p.startWorld.y,p.endWorld.y);if(Le.current){const Q=[];for(const J of K.current){if(J.hidden)continue;const Me=J.width||ht,He=J.height||st,te=at==="full"?J.position.x>=I&&J.position.x+Me<=U&&J.position.y>=R&&J.position.y+He<=W:J.position.x+Me>I&&J.position.x<U&&J.position.y+He>R&&J.position.y<W;te!==!!J.selected&&Q.push({id:J.id,type:"select",selected:te})}Q.length&&Le.current(Q)}return}if(Xe.current){const p=ke(u.clientX,u.clientY),I=Xe.current,R=p.x-I.startMouse.x,U=p.y-I.startMouse.y;let W={x:I.startPos.x+R,y:I.startPos.y+U};if($e&&(W=Zn(W,Ye)),pt&&(W=Gn(W,pt)),I.parentClamp){const te=I.parentClamp;W={x:Math.max(te.minX,Math.min(W.x,te.maxX)),y:Math.max(te.minY,Math.min(W.y,te.maxY))}}const Q=[{id:I.id,position:W}];for(const te of I.selectedStarts){let ae={x:te.startPos.x+R,y:te.startPos.y+U};if($e&&(ae=Zn(ae,Ye)),pt&&(ae=Gn(ae,pt)),te.parentClamp){const ze=te.parentClamp;ae={x:Math.max(ze.minX,Math.min(ae.x,ze.maxX)),y:Math.max(ze.minY,Math.min(ae.y,ze.maxY))}}Q.push({id:te.id,position:ae})}const J=[];for(const te of Q){const ae=K.current.find(ze=>ze.id===te.id);if(ae){ae.position=te.position,ae.dragging=!0;let ze=te.position;if(ae.parentId){let _e=K.current.find(qe=>qe.id===ae.parentId),Oe=te.position.x,Qe=te.position.y;for(;_e;)Oe+=_e.position.x,Qe+=_e.position.y,_e=_e.parentId?K.current.find(qe=>qe.id===_e.parentId):null;ze={x:Oe,y:Qe}}J.push({id:te.id,position:te.position,_absolutePosition:ze,width:ae.width,height:ae.height,dragging:!0,selected:ae.selected})}}const Me=new Set(Q.map(te=>te.id));for(const te of K.current)if(te.parentId&&Me.has(te.parentId)&&!Me.has(te.id)){let ae=K.current.find(Oe=>Oe.id===te.parentId),ze=te.position.x,_e=te.position.y;for(;ae;)ze+=ae.position.x,_e+=ae.position.y,ae=ae.parentId?K.current.find(Oe=>Oe.id===ae.parentId):null;J.push({id:te.id,position:te.position,_absolutePosition:{x:ze,y:_e},width:te.width,height:te.height,dragging:!1,selected:te.selected})}if((i=Te.current)==null||i.postMessage({type:"nodePositions",data:{updates:J}}),In){const te=pe.current;if(te){const ae=te.getBoundingClientRect(),ze=40,_e=u.clientX-ae.left,Oe=u.clientY-ae.top;let Qe=0,qe=0;_e<ze?Qe=it:_e>ae.width-ze&&(Qe=-it),Oe<ze?qe=it:Oe>ae.height-ze&&(qe=-it),(Qe||qe)&&(ce.current.x+=Qe,ce.current.y+=qe,me(u))}}const He=K.current.find(te=>te.id===I.id);if(He&&((h=Wt.current)==null||h.call(Wt,u,He)),I.selectedStarts.length>0){const te=K.current.filter(ae=>ae.selected);(k=(M=Z.current).onSelectionDrag)==null||k.call(M,u,te)}return}if(!$t.current)return;const x=ce.current;x.x+=u.clientX-jt.current.x,x.y+=u.clientY-jt.current.y,jt.current={x:u.clientX,y:u.clientY},me()},[me,ke,ft,Rt]),Fn=l.useCallback(u=>{var x,i,h,M,k,p,I;if(Ue.current){const R=ke(u.clientX,u.clientY),U=Mt(R.x,R.y);if(U&&U.nodeId!==Ue.current.sourceId&&(be==="loose"||U.type==="target")){const J=Ue.current.sourceType==="target"?{source:U.nodeId,target:Ue.current.sourceId,sourceHandle:U.handleId||null,targetHandle:Ue.current.sourceHandle}:{source:Ue.current.sourceId,target:U.nodeId,sourceHandle:Ue.current.sourceHandle,targetHandle:U.handleId||null};(Z.current.isValidConnection?Z.current.isValidConnection(J):!0)&&((x=ut.current)==null||x.call(ut,{...J,...It}))}(h=(i=Z.current).onConnectEnd)==null||h.call(i,u.nativeEvent||u),Ue.current=null,Dt.current=null,ft();return}if(ct.current){ct.current=null,Rt(),wt();return}if(Xe.current){const R=Xe.current;if(Le.current){const W=K.current.find(J=>J.id===R.id),Q=[{id:R.id,type:"position",position:W?{...W.position}:void 0,dragging:!1}];for(const J of R.selectedStarts){const Me=K.current.find(He=>He.id===J.id);Q.push({id:J.id,type:"position",position:Me?{...Me.position}:void 0,dragging:!1})}Le.current(Q)}if(R.selectedStarts.length>0){const W=K.current.filter(Q=>Q.selected);(k=(M=Z.current).onSelectionDragStop)==null||k.call(M,u,W)}requestAnimationFrame(()=>{Xe.current=null});const U=K.current.find(W=>W.id===R.id);U&&((p=Ft.current)==null||p.call(Ft,u,U));return}$t.current=!1,(I=pe.current)==null||I.classList.remove("dragging")},[ke,Mt,ft,Rt,wt]);l.useEffect(()=>{const u=pe.current;if(!u)return;const x=i=>{Gt&&i.preventDefault();const h=ce.current;if(cn||et.current){const R=ln;Pt==="horizontal"?h.x-=i.deltaY*R:(Pt==="vertical"||(h.x-=i.deltaX*R),h.y-=i.deltaY*R),me(i);return}if(!un)return;const M=i.deltaY>0?.92:1.08,k=u.getBoundingClientRect(),p=i.clientX-k.left,I=i.clientY-k.top;h.x=p-(p-h.x)*M,h.y=I-(I-h.y)*M,h.zoom=Math.min(oe,Math.max(V,h.zoom*M)),me(i)};return u.addEventListener("wheel",x,{passive:!Gt}),()=>u.removeEventListener("wheel",x)},[me,V,oe,cn,Pt,ln,un,Gt]),l.useEffect(()=>{if(!fn)return;const u=pe.current;if(!u)return;let x=0,i=null;const h=p=>{if(p.touches.length===2){const I=p.touches[0].clientX-p.touches[1].clientX,R=p.touches[0].clientY-p.touches[1].clientY;x=Math.hypot(I,R);const U=u.getBoundingClientRect();i={x:(p.touches[0].clientX+p.touches[1].clientX)/2-U.left,y:(p.touches[0].clientY+p.touches[1].clientY)/2-U.top},p.preventDefault()}},M=p=>{if(p.touches.length===2&&x>0){p.preventDefault();const I=p.touches[0].clientX-p.touches[1].clientX,R=p.touches[0].clientY-p.touches[1].clientY,U=Math.hypot(I,R),W=U/x;x=U;const Q=ce.current,J=i.x,Me=i.y;Q.x=J-(J-Q.x)*W,Q.y=Me-(Me-Q.y)*W,Q.zoom=Math.min(oe,Math.max(V,Q.zoom*W)),me(p)}},k=()=>{x=0,i=null};return u.addEventListener("touchstart",h,{passive:!1}),u.addEventListener("touchmove",M,{passive:!1}),u.addEventListener("touchend",k),()=>{u.removeEventListener("touchstart",h),u.removeEventListener("touchmove",M),u.removeEventListener("touchend",k)}},[fn,me,V,oe]),l.useEffect(()=>{if(!dn)return;const u=pe.current;if(!u)return;const x=i=>{var W,Q,J,Me;const h=ke(i.clientX,i.clientY);if(tt(h.x,h.y)){(Q=(W=Z.current).onNodeDoubleClick)==null||Q.call(W,i,tt(h.x,h.y));return}const M=nt(h.x,h.y);if(M){(Me=(J=Z.current).onEdgeDoubleClick)==null||Me.call(J,i,M);return}const k=1.5,p=u.getBoundingClientRect(),I=i.clientX-p.left,R=i.clientY-p.top,U=ce.current;U.x=I-(I-U.x)*k,U.y=R-(R-U.y)*k,U.zoom=Math.min(oe,Math.max(V,U.zoom*k)),me(i)};return u.addEventListener("dblclick",x),()=>u.removeEventListener("dblclick",x)},[dn,me,V,oe,ke,tt,nt]),l.useEffect(()=>{const u=pe.current;if(!u)return;const x=i=>{var p,I,R,U,W,Q;const h=ke(i.clientX,i.clientY),M=tt(h.x,h.y);if(M){(I=(p=Z.current).onNodeContextMenu)==null||I.call(p,i,M);return}const k=nt(h.x,h.y);if(k){(U=(R=Z.current).onEdgeContextMenu)==null||U.call(R,i,k);return}(Q=(W=Z.current).onPaneContextMenu)==null||Q.call(W,i)};return u.addEventListener("contextmenu",x),()=>u.removeEventListener("contextmenu",x)},[ke,tt,nt]),l.useEffect(()=>{const u=pe.current;if(!u)return;let x=null,i=null;const h=p=>{var U,W,Q,J,Me,He,te,ae,ze,_e,Oe,Qe,qe,Jt;if((W=(U=Z.current).onPaneMouseMove)==null||W.call(U,p),$t.current||Xe.current||Ue.current||ct.current)return;const I=ke(p.clientX,p.clientY),R=tt(I.x,I.y);if(R!==x&&(x&&((J=(Q=Z.current).onNodeMouseLeave)==null||J.call(Q,p,x)),R&&((He=(Me=Z.current).onNodeMouseEnter)==null||He.call(Me,p,R)),x=R),R&&((ae=(te=Z.current).onNodeMouseMove)==null||ae.call(te,p,R)),!R){const yt=nt(I.x,I.y);yt!==i&&(i&&((_e=(ze=Z.current).onEdgeMouseLeave)==null||_e.call(ze,p,i)),yt&&((Qe=(Oe=Z.current).onEdgeMouseEnter)==null||Qe.call(Oe,p,yt)),i=yt),yt&&((Jt=(qe=Z.current).onEdgeMouseMove)==null||Jt.call(qe,p,yt))}},M=p=>{var I,R;return(R=(I=Z.current).onPaneMouseEnter)==null?void 0:R.call(I,p)},k=p=>{var I,R,U,W,Q,J;(R=(I=Z.current).onPaneMouseLeave)==null||R.call(I,p),x&&((W=(U=Z.current).onNodeMouseLeave)==null||W.call(U,p,x),x=null),i&&((J=(Q=Z.current).onEdgeMouseLeave)==null||J.call(Q,p,i),i=null)};return u.addEventListener("mousemove",h),u.addEventListener("mouseenter",M),u.addEventListener("mouseleave",k),()=>{u.removeEventListener("mousemove",h),u.removeEventListener("mouseenter",M),u.removeEventListener("mouseleave",k)}},[ke,tt,nt]),l.useEffect(()=>{const u=Array.isArray(Ge)?Ge:[Ge],x=async i=>{var h,M,k,p;if(u.includes(i.key)){if(i.target.tagName==="INPUT"||i.target.tagName==="TEXTAREA"||i.target.isContentEditable)return;const I=K.current.filter(W=>W.selected),R=Ee.current.filter(W=>W.selected);if(!I.length&&!R.length)return;if(Z.current.onBeforeDelete)try{if(!await Z.current.onBeforeDelete({nodes:I,edges:R}))return}catch(W){(M=(h=Z.current).onError)==null||M.call(h,"before-delete-error",W.message||"onBeforeDelete threw an error");return}const U=new Set(I.map(W=>W.id));if(I.length&&Le.current&&(Le.current(I.map(W=>({id:W.id,type:"remove"}))),Fe.current)){const W=Ee.current.filter(Q=>U.has(Q.source)||U.has(Q.target));W.length&&Fe.current(W.map(Q=>({id:Q.id,type:"remove"})))}R.length&&Fe.current&&Fe.current(R.map(W=>({id:W.id,type:"remove"}))),(p=(k=Z.current).onDelete)==null||p.call(k,{nodes:I,edges:R})}if((i.ctrlKey||i.metaKey)&&i.key==="a"){if(i.target.tagName==="INPUT"||i.target.tagName==="TEXTAREA")return;if(i.preventDefault(),Le.current){const I=K.current.filter(R=>!R.selected).map(R=>({id:R.id,type:"select",selected:!0}));I.length&&Le.current(I)}if(Fe.current){const I=Ee.current.filter(R=>!R.selected).map(R=>({id:R.id,type:"select",selected:!0}));I.length&&Fe.current(I)}}};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[Ge]);const _=l.useRef(!1);l.useEffect(()=>{var u,x;if(!_.current&&Te.current){if(_.current=!0,Ze&&K.current.length>0){const i=pe.current;if(i){const h=i.getBoundingClientRect(),M=(fe==null?void 0:fe.padding)??.1,k=Rn(K.current),p=Zt(k,h.width,h.height,M);fe!=null&&fe.maxZoom&&(p.zoom=Math.min(p.zoom,fe.maxZoom)),fe!=null&&fe.minZoom&&(p.zoom=Math.max(p.zoom,fe.minZoom)),ce.current=p,me()}}(x=(u=Z.current).onInit)==null||x.call(u,{getNodes:()=>[...K.current],getEdges:()=>[...Ee.current],getNode:i=>K.current.find(h=>h.id===i),getEdge:i=>Ee.current.find(h=>h.id===i),getViewport:()=>({...ce.current}),getZoom:()=>ce.current.zoom,setViewport:i=>{ce.current={x:i.x??ce.current.x,y:i.y??ce.current.y,zoom:i.zoom??ce.current.zoom},me()},fitView:(i={})=>{const h=pe.current;if(!h||!K.current.length)return;const M=h.getBoundingClientRect(),k=i.nodes?K.current.filter(R=>i.nodes.some(U=>U.id===R.id)):K.current;if(!k.length)return;const p=Rn(k),I=Zt(p,M.width,M.height,i.padding??.1);i.maxZoom&&(I.zoom=Math.min(I.zoom,i.maxZoom)),i.minZoom&&(I.zoom=Math.max(I.zoom,i.minZoom)),ce.current=I,me()},screenToFlowPosition:i=>ke(i.x,i.y),flowToScreenPosition:i=>{const h=ce.current,M=pe.current;if(!M)return{x:0,y:0};const k=M.getBoundingClientRect();return{x:i.x*h.zoom+h.x+k.left,y:i.y*h.zoom+h.y+k.top}},zoomIn:()=>{const i=ce.current;i.zoom=Math.min(oe,i.zoom*1.2),me()},zoomOut:()=>{const i=ce.current;i.zoom=Math.max(V,i.zoom/1.2),me()},zoomTo:i=>{ce.current.zoom=Math.min(oe,Math.max(V,i)),me()},setNodes:i=>{var h,M;(M=(h=Z.current).onNodesChange)==null||M.call(h,[...K.current.map(k=>({id:k.id,type:"remove"})),...(typeof i=="function"?i(K.current):i).map(k=>({type:"add",item:k}))])},setEdges:i=>{var h,M;(M=(h=Z.current).onEdgesChange)==null||M.call(h,[...Ee.current.map(k=>({id:k.id,type:"remove"})),...(typeof i=="function"?i(Ee.current):i).map(k=>({type:"add",item:k}))])},addNodes:i=>{var M,k;const h=Array.isArray(i)?i:[i];(k=(M=Z.current).onNodesChange)==null||k.call(M,h.map(p=>({type:"add",item:p})))},addEdges:i=>{var M,k;const h=Array.isArray(i)?i:[i];(k=(M=Z.current).onEdgesChange)==null||k.call(M,h.map(p=>({type:"add",item:p})))},deleteElements:({nodes:i=[],edges:h=[]})=>{var M,k,p,I;i.length&&((k=(M=Z.current).onNodesChange)==null||k.call(M,i.map(R=>({id:R.id,type:"remove"})))),h.length&&((I=(p=Z.current).onEdgesChange)==null||I.call(p,h.map(R=>({id:R.id,type:"remove"}))))},updateNodeData:(i,h)=>{var p,I;const M=K.current.find(R=>R.id===i);if(!M)return;const k=typeof h=="function"?h(M.data):{...M.data,...h};(I=(p=Z.current).onNodesChange)==null||I.call(p,[{id:i,type:"replace",item:{...M,data:k}}])},toObject:()=>({nodes:[...K.current],edges:[...Ee.current],viewport:{...ce.current}}),setCenter:(i,h,M={})=>{const k=pe.current;if(!k)return;const p=k.getBoundingClientRect(),I=M.zoom??ce.current.zoom;ce.current={x:p.width/2-i*I,y:p.height/2-h*I,zoom:I},me()},fitBounds:(i,h={})=>{const M=pe.current;if(!M)return;const k=M.getBoundingClientRect(),p=Zt(i,k.width,k.height,h.padding??.1);ce.current=p,me()}})}});const we=l.useCallback(()=>{ce.current={...xe},me()},[me,xe]),ie=l.useCallback(u=>{var x;if(u)mt.current.push(u);else{const i=ce.current,h=pe.current;if(!h)return;const M=h.getBoundingClientRect(),k=Math.round(-i.x/i.zoom+M.width/2/i.zoom),p=Math.round(-i.y/i.zoom+M.height/2/i.zoom);mt.current.push({x:k-80,y:p-45,w:160,h:90,title:"Note "+(mt.current.length+1),body:"Added at viewport center"})}(x=Te.current)==null||x.postMessage({type:"cards",data:{cards:[...mt.current]}})},[]),ve=l.useCallback(u=>{if(u.id||(u.id="node-"+Date.now()),!u.position){const x=ce.current,i=pe.current;if(!i)return;const h=i.getBoundingClientRect();u.position={x:Math.round(-x.x/x.zoom+h.width/2/x.zoom)-ht/2,y:Math.round(-x.y/x.zoom+h.height/2/x.zoom)-st/2}}u.data||(u.data={label:u.id}),Le.current&&Le.current([{type:"add",item:u}])},[]),Be=l.useCallback(()=>({...ce.current}),[]),Se=l.useCallback(u=>{ce.current={...ce.current,...u},me()},[me]),De=l.useCallback(u=>ke(u.x,u.y),[ke]),gt=n,kt=l.useMemo(()=>({wrapRef:pe,canvasRef:Bt,workerRef:Te,cameraRef:ce,nodesRef:K,edgesRef:Ee,handleRegistryRef:hn,syncNodesToWorker:Ot,onNodesChangeRef:Le,onEdgesChangeRef:Fe,sendCamera:me,screenToWorld:ke,viewportListeners:vt,selectionListeners:lt,zoomMin:V,zoomMax:oe,snapToGrid:$e,snapGrid:Ye,nodeExtent:pt,defaultEdgeOptions:It,edgeRouting:Ct,resolvedNodesRef:dt,noDragClassName:Tt,noPanClassName:Lt,get nodes(){return t},get edges(){return n},get routedEdges(){return gt},get viewport(){return yn},get connection(){return Qt}}),[t,n,gt,yn,Qt,me,ke,Ot,vt,lt,V,oe,$e,Ye,pt,It,Ct,Tt,Lt]);return{wrapRef:pe,canvasRef:Bt,canvasReady:At,onPointerDown:_n,onPointerMove:Wn,onPointerUp:Fn,resetView:we,addCard:ie,addNode:ve,getCamera:Be,setCamera:Se,screenToFlowPosition:De,store:kt}}function ro(e,t,n,r,a,o){const c=a-n,f=o-r,m=c*c+f*f;if(m===0)return Math.hypot(e-n,t-r);let d=((e-n)*c+(t-r)*f)/m;return d=Math.max(0,Math.min(1,d)),Math.hypot(e-(n+d*c),t-(r+d*f))}const ur=e=>{let t;const n=new Set,r=(d,g)=>{const b=typeof d=="function"?d(t):d;if(!Object.is(b,t)){const E=t;t=g??(typeof b!="object"||b===null)?b:Object.assign({},t,b),n.forEach(C=>C(t,E))}},a=()=>t,f={setState:r,getState:a,getInitialState:()=>m,subscribe:d=>(n.add(d),()=>n.delete(d))},m=t=e(r,a,f);return f},oo=(e=>e?ur(e):ur),so=e=>e;function ao(e,t=so){const n=l.useSyncExternalStore(e.subscribe,l.useCallback(()=>t(e.getState()),[e,t]),l.useCallback(()=>t(e.getInitialState()),[e,t]));return l.useDebugValue(n),n}const zt=l.createContext(null);function io(e={}){return oo((t,n)=>({nodes:[],edges:[],viewport:{x:0,y:0,zoom:1},connection:null,minZoom:.1,maxZoom:5,width:0,height:0,domNode:null,nodesRef:{current:[]},edgesRef:{current:[]},cameraRef:{current:{x:0,y:0,zoom:1}},wrapRef:{current:null},workerRef:{current:null},onNodesChangeRef:{current:null},onEdgesChangeRef:{current:null},viewportListeners:new Set,selectionListeners:new Set,edgeLabelContainerRef:{current:null},viewportPortalRef:{current:null},screenToWorld:(r,a)=>{const o=n().cameraRef.current;return{x:(r-o.x)/o.zoom,y:(a-o.y)/o.zoom}},sendCamera:()=>{var a;const r=n();(a=r.workerRef.current)==null||a.postMessage({type:"camera",data:{camera:{...r.cameraRef.current}}})},...e}))}function Ne(e,t){const n=l.useContext(zt);if(!n)throw new Error("useCanvasStore must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");const r=typeof n.getState=="function"&&typeof n.subscribe=="function",a=l.useRef(e),o=l.useRef(t),c=l.useRef(void 0);a.current=e,o.current=t;const f=l.useCallback(m=>{const d=a.current;if(!d)return m;const g=d(m),b=o.current||Object.is;return c.current!==void 0&&b(c.current,g)?c.current:(c.current=g,g)},[]);return r?ao(n,e?f:void 0):e?f(n):n}function Rr(){const e=l.useContext(zt);if(!e)throw new Error("useCanvasStoreApi must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");return typeof e.getState=="function"?e:{getState:()=>e,setState:()=>{},subscribe:()=>()=>{}}}const sn=l.createContext(null);function co(){return l.useContext(sn)}function lo({node:e,nodeType:t}){var S,j,L,A;const n=Ne(),r=l.useRef(n);r.current=n;const a=l.useRef(null),o=e._absolutePosition||e.position,c=l.useRef(null);l.useEffect(()=>{const Y=a.current;if(!Y)return;const D=new ResizeObserver(F=>{var O,X,H,w;const{width:$,height:N}=F[0].contentRect;if($>0&&N>0){const y=r.current,v=y.nodesRef.current.find(B=>B.id===e.id),z=(v==null?void 0:v.width)||((O=v==null?void 0:v.measured)==null?void 0:O.width),P=(v==null?void 0:v.height)||((X=v==null?void 0:v.measured)==null?void 0:X.height);(Math.abs((z||0)-$)>1||Math.abs((P||0)-N)>1)&&((w=(H=y.onNodesChangeRef).current)==null||w.call(H,[{id:e.id,type:"dimensions",dimensions:{width:$,height:N},setAttributes:!0}]))}});return D.observe(Y),()=>D.disconnect()},[e.id]);const f=l.useCallback(Y=>{var ge,de,Re,We;Y.stopPropagation();const D=Y.target.tagName;if(D==="INPUT"||D==="TEXTAREA"||D==="SELECT"||D==="BUTTON"||D==="A"||D==="LABEL"||Y.target.isContentEditable)return;const F=r.current.noDragClassName||"nodrag",$=r.current.noPanClassName||"nopan";let N=Y.target;for(;N&&N!==a.current;){if((ge=N.classList)!=null&&ge.contains(F)||(de=N.classList)!=null&&de.contains($))return;N=N.parentElement}if(r.current.onNodesChangeRef.current){const V=[];if(Y.shiftKey)V.push({id:e.id,type:"select",selected:!e.selected});else for(const xe of r.current.nodesRef.current)xe.id===e.id&&!xe.selected?V.push({id:xe.id,type:"select",selected:!0}):xe.id!==e.id&&xe.selected&&V.push({id:xe.id,type:"select",selected:!1});V.length&&r.current.onNodesChangeRef.current(V)}const O=r.current.cameraRef.current,X=r.current.wrapRef.current;if(!X)return;const H=X.getBoundingClientRect(),w=(Y.clientX-H.left-O.x)/O.zoom,y=(Y.clientY-H.top-O.y)/O.zoom,z=e.selected?r.current.nodesRef.current.filter(V=>V.selected&&V.id!==e.id).map(V=>({id:V.id,startPos:{...V.position}})):[];c.current={startPos:{...e.position},startMouse:{x:w,y},selectedStarts:z};const P=[{id:e.id,type:"position",dragging:!0}];for(const V of z)P.push({id:V.id,type:"position",dragging:!0});(We=(Re=r.current.onNodesChangeRef).current)==null||We.call(Re,P);const B=a.current;B&&B.setPointerCapture(Y.pointerId);let G=null,ne=null;const ee=()=>{var V,oe;ne&&((oe=(V=r.current.onNodesChangeRef).current)==null||oe.call(V,ne),ne=null),G=null},se=V=>{var rt,at;if(!c.current)return;const oe=r.current.cameraRef.current,xe=X.getBoundingClientRect(),Ze=(V.clientX-xe.left-oe.x)/oe.zoom,fe=(V.clientY-xe.top-oe.y)/oe.zoom,je=Ze-c.current.startMouse.x,Ae=fe-c.current.startMouse.y;let Pe={x:c.current.startPos.x+je,y:c.current.startPos.y+Ae};if(r.current.snapToGrid&&r.current.snapGrid&&(Pe={x:r.current.snapGrid[0]*Math.round(Pe.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Pe.y/r.current.snapGrid[1])}),e.parentId&&e.extent==="parent"){const be=r.current.nodesRef.current.find(Ie=>Ie.id===e.parentId);if(be){const Ie=be.width||160,Je=be.height||60,$e=e.width||((rt=e.measured)==null?void 0:rt.width)||160,Ye=e.height||((at=e.measured)==null?void 0:at.height)||60;Pe={x:Math.max(0,Math.min(Pe.x,Ie-$e)),y:Math.max(0,Math.min(Pe.y,Je-Ye))}}}B&&(B.style.left=Pe.x+"px",B.style.top=Pe.y+"px");for(const be of c.current.selectedStarts){let Ie={x:be.startPos.x+je,y:be.startPos.y+Ae};r.current.snapToGrid&&r.current.snapGrid&&(Ie={x:r.current.snapGrid[0]*Math.round(Ie.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Ie.y/r.current.snapGrid[1])});const Je=X.querySelector(`[data-nodeid="${be.id}"]`);Je&&(Je.style.left=Ie.x+"px",Je.style.top=Ie.y+"px")}const Ce=[{id:e.id,type:"position",position:Pe,dragging:!0}];for(const be of c.current.selectedStarts){let Ie={x:be.startPos.x+je,y:be.startPos.y+Ae};r.current.snapToGrid&&r.current.snapGrid&&(Ie={x:r.current.snapGrid[0]*Math.round(Ie.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Ie.y/r.current.snapGrid[1])}),Ce.push({id:be.id,type:"position",position:Ie,dragging:!0})}ne=Ce,G||(G=requestAnimationFrame(ee))},he=V=>{var xe,Ze;if(!c.current)return;G&&(cancelAnimationFrame(G),ee());const oe=[{id:e.id,type:"position",dragging:!1}];for(const fe of c.current.selectedStarts)oe.push({id:fe.id,type:"position",dragging:!1});(Ze=(xe=r.current.onNodesChangeRef).current)==null||Ze.call(xe,oe),c.current=null,B&&B.releasePointerCapture(V.pointerId),B==null||B.removeEventListener("pointermove",se),B==null||B.removeEventListener("pointerup",he)};B==null||B.addEventListener("pointermove",se),B==null||B.addEventListener("pointerup",he)},[e]),m=l.useCallback(Y=>{var X,H,w,y,v,z;if(!e.selected)return;const D=Y.shiftKey?10:1;let F=0,$=0;switch(Y.key){case"ArrowUp":$=-D;break;case"ArrowDown":$=D;break;case"ArrowLeft":F=-D;break;case"ArrowRight":F=D;break;case"Escape":(H=(X=r.current.onNodesChangeRef).current)==null||H.call(X,[{id:e.id,type:"select",selected:!1}]);return;case"Delete":case"Backspace":e.deletable!==!1&&((y=(w=r.current.onNodesChangeRef).current)==null||y.call(w,[{id:e.id,type:"remove"}]));return;default:return}Y.preventDefault();const N={x:e.position.x+F,y:e.position.y+$},O=[{id:e.id,type:"position",position:N}];for(const P of r.current.nodesRef.current)P.selected&&P.id!==e.id&&O.push({id:P.id,type:"position",position:{x:P.position.x+F,y:P.position.y+$}});(z=(v=r.current.onNodesChangeRef).current)==null||z.call(v,O)},[e]),d=e.width||((S=e.measured)==null?void 0:S.width),g=e.height||((j=e.measured)==null?void 0:j.height),b=!!(d&&g),E=(L=n.pinnedNodeIds)==null?void 0:L.has(e.id),C=l.useCallback(Y=>{var D,F;Y.stopPropagation(),(F=(D=r.current).togglePinNode)==null||F.call(D,e.id)},[e.id]);return T.jsx(sn.Provider,{value:e.id,children:T.jsxs("div",{ref:a,className:`ric-node-wrapper ${e.selected?"selected":""} ${e.dragging?"dragging":""}`,style:{position:"absolute",left:o.x,top:o.y,zIndex:e.type==="group"?0:e.zIndex||1,pointerEvents:e.type==="group"?"none":"all",visibility:b?"visible":"hidden",outline:"none"},"data-nodeid":e.id,tabIndex:e.selectable!==!1?0:void 0,role:"button","aria-label":`Node ${((A=e.data)==null?void 0:A.label)||e.id}`,"aria-selected":!!e.selected,onPointerDown:f,onKeyDown:m,children:[T.jsx(t,{id:e.id,data:e.data,type:e.type,selected:!!e.selected,dragging:!!e.dragging,draggable:e.draggable!==!1,selectable:e.selectable!==!1,deletable:e.deletable!==!1,isConnectable:e.connectable!==!1,zIndex:e.zIndex||0,positionAbsoluteX:o.x,positionAbsoluteY:o.y,width:d,height:g,sourcePosition:e.sourcePosition,targetPosition:e.targetPosition,parentId:e.parentId,dragHandle:e.dragHandle}),n.togglePinNode&&T.jsx("button",{className:"ric-pin-btn nodrag",onClick:C,title:E?"Unpin from DOM":"Pin to DOM",style:{position:"absolute",top:-8,left:-8,width:20,height:20,borderRadius:"50%",border:"1.5px solid "+(E?"#3b82f6":"#ccc"),background:E?"#3b82f6":"#fff",color:E?"#fff":"#999",fontSize:10,lineHeight:"16px",textAlign:"center",cursor:"pointer",padding:0,zIndex:10,pointerEvents:"all",boxShadow:"0 1px 3px rgba(0,0,0,0.12)"},children:"📌"})]})})}const uo=l.memo(lo),kr=160,Cr=60;function dr(e,t,n,r){var f,m;const a=e.width||((f=e.measured)==null?void 0:f.width)||kr,o=e.height||((m=e.measured)==null?void 0:m.height)||Cr,c=e._absolutePosition||e.position;if(e.handleBounds){const d=e.handleBounds[t]||[],g=n?d.find(b=>b.id===n):d[0];if(g&&g.x!==void 0&&g.y!==void 0){const b=g.position||(t==="source"?"right":"left");return{x:c.x+g.x,y:c.y+g.y,position:b}}}if(r){const d=`${e.id}__${n||t}`,g=r.get(d);if(g&&g.x!==void 0&&g.y!==void 0)return{x:c.x+g.x,y:c.y+g.y,position:g.position||(t==="source"?"right":"left")}}if(e.handles&&e.handles.length){for(const d of e.handles)if(d.type===t&&(!n||d.id===n)){if(d.x!==void 0&&d.y!==void 0)return{x:c.x+d.x,y:c.y+d.y,position:d.position||(t==="source"?"right":"left")};const g=d.position||(t==="source"?"right":"left");switch(g){case"top":return{x:c.x+a/2,y:c.y,position:g};case"bottom":return{x:c.x+a/2,y:c.y+o,position:g};case"left":return{x:c.x,y:c.y+o/2,position:g};default:return{x:c.x+a,y:c.y+o/2,position:g}}}}return t==="source"?{x:c.x+a,y:c.y+o/2,position:"right"}:{x:c.x,y:c.y+o/2,position:"left"}}function fo(e,t,n){return n==="left"?e-t:n==="right"?e+t:e}function ho(e,t,n){return n==="top"?e-t:n==="bottom"?e+t:e}function fr({x:e,y:t,position:n,type:r,onPointerDown:a}){return T.jsx("circle",{className:`ric-edge-anchor ric-edge-anchor-${r}`,cx:fo(e,10,n),cy:ho(t,10,n),r:10,stroke:"transparent",fill:"transparent",style:{cursor:"move",pointerEvents:"stroke"},onPointerDown:a})}function go({edge:e,edgeType:t,nodes:n,reconnectable:r}){var N,O,X;const a=l.useContext(zt),o=l.useRef(typeof a.getState=="function"?a.getState():a);o.current=typeof a.getState=="function"?a.getState():a;const[c,f]=l.useState(null),m=l.useCallback((H,w,y,v)=>{var he;w.stopPropagation(),w.preventDefault();const z=o.current,P=z.wrapRef.current;if(!P)return;const B=H==="source"?v:y,G=H==="source"?e.target:e.source;(he=z.workerRef.current)==null||he.postMessage({type:"connecting",data:{from:{x:B.x,y:B.y},to:{x:B.x,y:B.y}}});const ne=P.getBoundingClientRect(),ee=ge=>{var V;const de=z.cameraRef.current,Re=(ge.clientX-ne.left-de.x)/de.zoom,We=(ge.clientY-ne.top-de.y)/de.zoom;(V=z.workerRef.current)==null||V.postMessage({type:"connecting",data:{from:{x:B.x,y:B.y},to:{x:Re,y:We}}})},se=ge=>{var fe,je,Ae,Pe;const de=z.cameraRef.current,Re=(ge.clientX-ne.left-de.x)/de.zoom,We=(ge.clientY-ne.top-de.y)/de.zoom,V=20/de.zoom;let oe=null,xe=null;const Ze=(fe=z.handleRegistryRef)==null?void 0:fe.current;for(const Ce of z.nodesRef.current){if(Ce.hidden)continue;const rt=Ce.width||kr,at=Ce.height||Cr,be=Ce._absolutePosition||Ce.position,Ie=[];if(Ze)for(const[,$e]of Ze)$e.nodeId===Ce.id&&Ie.push($e);const Je=Ie.length>0?Ie:Ce.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const $e of Je){let Ye,Ge;if($e.x!==void 0&&$e.y!==void 0)Ye=be.x+$e.x,Ge=be.y+$e.y;else switch($e.position||($e.type==="source"?"right":"left")){case"top":Ye=be.x+rt/2,Ge=be.y;break;case"bottom":Ye=be.x+rt/2,Ge=be.y+at;break;case"left":Ye=be.x,Ge=be.y+at/2;break;default:Ye=be.x+rt,Ge=be.y+at/2;break}if(Math.abs(Re-Ye)<V&&Math.abs(We-Ge)<V){oe=Ce,xe=$e.id||null;break}}if(oe)break}if(oe){const Ce=H==="source"?{source:oe.id,target:G,sourceHandle:xe,targetHandle:e.targetHandle}:{source:G,target:oe.id,sourceHandle:e.sourceHandle,targetHandle:xe};(Ae=(je=z.onEdgesChangeRef).current)==null||Ae.call(je,[{id:e.id,type:"remove"},{type:"add",item:{id:e.id,...Ce}}])}(Pe=z.workerRef.current)==null||Pe.postMessage({type:"connecting",data:null}),P.removeEventListener("pointermove",ee),P.removeEventListener("pointerup",se)};P.addEventListener("pointermove",ee),P.addEventListener("pointerup",se)},[e]),d=n.find(H=>H.id===e.source),g=n.find(H=>H.id===e.target),b=d&&!!(d.width||(N=d.measured)!=null&&N.width),E=g&&!!(g.width||(O=g.measured)!=null&&O.width),C=o.current,S=(X=C.handleRegistryRef)==null?void 0:X.current,j=b?dr(d,"source",e.sourceHandle,S):null,L=E?dr(g,"target",e.targetHandle,S):null,A=e.type==="bezier"||e.type==="simplebezier"||e.type==="default",Y=C.routedEdges||C.edges,D=Y==null?void 0:Y.find(H=>H.id===e.id),F=A?null:(D==null?void 0:D._routedPoints)||e._routedPoints||null,$=r!==!1&&e.reconnectable!==!1;return!j||!L?null:T.jsxs("g",{className:`ric-edge-wrapper ${e.selected?"selected":""}`,"data-edgeid":e.id,onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),children:[T.jsx(t,{id:e.id,source:e.source,target:e.target,sourceX:j.x,sourceY:j.y,targetX:L.x,targetY:L.y,sourcePosition:j.position,targetPosition:L.position,sourceHandleId:e.sourceHandle,targetHandleId:e.targetHandle,data:e.data,type:e.type,selected:!!e.selected,animated:!!e.animated,label:e.label,style:e.style,selectable:e.selectable!==!1,deletable:e.deletable!==!1,routedPoints:F}),$&&(c||e.selected)&&T.jsxs(T.Fragment,{children:[T.jsx(fr,{x:j.x,y:j.y,position:j.position,type:"source",onPointerDown:H=>m("source",H,j,L)}),T.jsx(fr,{x:L.x,y:L.y,position:L.position,type:"target",onPointerDown:H=>m("target",H,j,L)})]})]})}const yo=l.memo(go);function Er({selectionKeyCode:e="Shift",selectionMode:t="partial"}){var j;const n=Ne(),[r,a]=l.useState(null),o=l.useRef(null);if(l.useEffect(()=>{const L=n.wrapRef.current;if(!L)return;let A=!1,Y=null,D=!1;const F=H=>{H.key===e&&(D=!0)},$=H=>{H.key===e&&(D=!1)},N=H=>{if(!D)return;const w=H.target;if(w.closest(".ric-node-wrapper")||w.closest(".ric-handle"))return;A=!0;const y=n.cameraRef.current,v=L.getBoundingClientRect(),z=(H.clientX-v.left-y.x)/y.zoom,P=(H.clientY-v.top-y.y)/y.zoom;Y={x:z,y:P},a({startX:z,startY:P,endX:z,endY:P}),H.stopPropagation()},O=H=>{if(!A||!Y)return;const w=n.cameraRef.current,y=L.getBoundingClientRect(),v=(H.clientX-y.left-w.x)/w.zoom,z=(H.clientY-y.top-w.y)/w.zoom;a({startX:Y.x,startY:Y.y,endX:v,endY:z})},X=H=>{var G,ne;if(!A||!Y)return;A=!1;const w=n.cameraRef.current,y=L.getBoundingClientRect(),v=(H.clientX-y.left-w.x)/w.zoom,z=(H.clientY-y.top-w.y)/w.zoom,P={x:Math.min(Y.x,v),y:Math.min(Y.y,z),width:Math.abs(v-Y.x),height:Math.abs(z-Y.y)},B=[];for(const ee of n.nodesRef.current){const se=ee._absolutePosition||ee.position,he=ee.width||160,ge=ee.height||60;let de;t==="full"?de=se.x>=P.x&&se.y>=P.y&&se.x+he<=P.x+P.width&&se.y+ge<=P.y+P.height:de=se.x+he>P.x&&se.x<P.x+P.width&&se.y+ge>P.y&&se.y<P.y+P.height,B.push({id:ee.id,type:"select",selected:de})}B.length&&((ne=(G=n.onNodesChangeRef).current)==null||ne.call(G,B)),Y=null,a(null)};return L.addEventListener("pointerdown",N,!0),L.addEventListener("pointermove",O),L.addEventListener("pointerup",X),window.addEventListener("keydown",F),window.addEventListener("keyup",$),()=>{L.removeEventListener("pointerdown",N,!0),L.removeEventListener("pointermove",O),L.removeEventListener("pointerup",X),window.removeEventListener("keydown",F),window.removeEventListener("keyup",$)}},[n,e,t]),!r)return null;const c=((j=n.cameraRef)==null?void 0:j.current)||{x:0,y:0,zoom:1},f=Math.min(r.startX,r.endX),m=Math.min(r.startY,r.endY),d=Math.abs(r.endX-r.startX),g=Math.abs(r.endY-r.startY),b=f*c.zoom+c.x,E=m*c.zoom+c.y,C=d*c.zoom,S=g*c.zoom;return T.jsx("div",{ref:o,className:"ric-selection-box",style:{position:"absolute",left:b,top:E,width:C,height:S,border:"1px dashed #3b82f6",background:"rgba(59, 130, 246, 0.08)",pointerEvents:"none",zIndex:100}})}Er.displayName="SelectionBox";const Sr=l.memo(Er);function Qn(e,t,n){switch(e){case"top":return{x:t/2,y:0};case"bottom":return{x:t/2,y:n};case"left":return{x:0,y:n/2};case"right":return{x:t,y:n/2};default:return{x:t,y:n/2}}}function xo(e,t){const n=e.closest(".ric-node-wrapper");if(!n)return null;const r=n.getBoundingClientRect(),a=e.getBoundingClientRect(),o=t||1;return{x:(a.left+a.width/2-r.left)/o,y:(a.top+a.height/2-r.top)/o}}let On=!1,St=null;function zr(e){St=e,!On&&(On=!0,requestAnimationFrame(()=>{var t;On=!1,(t=St==null?void 0:St.syncNodesToWorker)==null||t.call(St),St=null}))}const Vn=new WeakMap;let wn=null;function po(){return wn||(wn=new ResizeObserver(e=>{var t;for(const n of e){const r=Vn.get(n.target);if(!r)continue;const{width:a,height:o}=n.contentRect;if(!a||!o)continue;const c=r.getStore(),f=(t=c.handleRegistryRef)==null?void 0:t.current;if(f){for(const[m,d]of f)if(d.nodeId===r.nodeId){const g=Qn(d.position,a,o);d.x=g.x,d.y=g.y,f.set(m,d)}zr(c)}}}),wn)}function mo({type:e="source",position:t=e==="source"?"right":"left",id:n,isConnectable:r=!0,isConnectableStart:a=!0,isConnectableEnd:o=!0,children:c,className:f="",style:m={},onConnect:d,...g}){const b=l.useContext(sn),E=l.useContext(zt),C=l.useRef(null),S=l.useCallback(()=>typeof E.getState=="function"?E.getState():E,[E]),j=l.useRef(S);j.current=S,l.useLayoutEffect(()=>{var w,y,v,z,P,B,G;if(!b)return;const D=j.current(),F=(w=D.handleRegistryRef)==null?void 0:w.current;if(!F)return;const $=`${b}__${n||e}`,N=(v=(y=D.nodesRef)==null?void 0:y.current)==null?void 0:v.find(ne=>ne.id===b),O=(N==null?void 0:N.width)||((z=N==null?void 0:N.measured)==null?void 0:z.width),X=(N==null?void 0:N.height)||((P=N==null?void 0:N.measured)==null?void 0:P.height);let H;O&&X?H=Qn(t,O,X):C.current?H=xo(C.current,(G=(B=D.cameraRef)==null?void 0:B.current)==null?void 0:G.zoom):H=Qn(t,160,60),F.set($,{nodeId:b,id:n||null,type:e,position:t,x:H.x,y:H.y})},[b,n,e,t]),l.useEffect(()=>{if(!b)return;const D=j.current();zr(D);const F=C.current,$=F==null?void 0:F.closest(".ric-node-wrapper");return $&&!Vn.has($)&&(Vn.set($,{nodeId:b,getStore:j.current}),po().observe($)),()=>{var H;const O=(H=j.current().handleRegistryRef)==null?void 0:H.current,X=`${b}__${n||e}`;O==null||O.delete(X)}},[b,n,e,t]);const L=l.useCallback(()=>{var y;const D=j.current(),F=D.nodesRef.current.find(v=>v.id===b);if(!F)return null;const $=F._absolutePosition||F.position,N=(y=D.handleRegistryRef)==null?void 0:y.current,O=`${b}__${n||e}`,X=N==null?void 0:N.get(O);if(X&&X.x!==void 0&&X.y!==void 0)return{x:$.x+X.x,y:$.y+X.y};const H=F.width||160,w=F.height||60;switch(t){case"top":return{x:$.x+H/2,y:$.y};case"bottom":return{x:$.x+H/2,y:$.y+w};case"left":return{x:$.x,y:$.y+w/2};default:return{x:$.x+H,y:$.y+w/2}}},[b,n,e,t]),A=l.useCallback(D=>{var z;if(!r||!a)return;D.stopPropagation(),D.preventDefault();const F=j.current(),$=F.cameraRef.current,N=F.wrapRef.current;if(!N)return;const O=N.getBoundingClientRect(),X=L();if(!X)return;const H=X.x,w=X.y;(z=F.workerRef.current)==null||z.postMessage({type:"connecting",data:{from:{x:H,y:w},to:{x:H,y:w}}}),N.setPointerCapture(D.pointerId);const y=P=>{var ne;const B=(P.clientX-O.left-$.x)/$.zoom,G=(P.clientY-O.top-$.y)/$.zoom;(ne=F.workerRef.current)==null||ne.postMessage({type:"connecting",data:{from:{x:H,y:w},to:{x:B,y:G}}})},v=P=>{var ge,de,Re,We;const B=(P.clientX-O.left-$.x)/$.zoom,G=(P.clientY-O.top-$.y)/$.zoom,ne=20/$.zoom;let ee=null,se=null;const he=(ge=F.handleRegistryRef)==null?void 0:ge.current;for(const V of F.nodesRef.current){if(V.id===b||V.hidden)continue;const oe=V._absolutePosition||V.position,xe=[];if(he)for(const[,fe]of he)fe.nodeId===V.id&&xe.push(fe);const Ze=xe.length>0?xe:V.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const fe of Ze){let je,Ae;if(fe.x!==void 0&&fe.y!==void 0)je=oe.x+fe.x,Ae=oe.y+fe.y;else{const Pe=V.width||160,Ce=V.height||60;switch(fe.position||(fe.type==="source"?"right":"left")){case"top":je=oe.x+Pe/2,Ae=oe.y;break;case"bottom":je=oe.x+Pe/2,Ae=oe.y+Ce;break;case"left":je=oe.x,Ae=oe.y+Ce/2;break;default:je=oe.x+Pe,Ae=oe.y+Ce/2;break}}if(Math.abs(B-je)<ne&&Math.abs(G-Ae)<ne){ee=V,se=fe.id||null;break}}if(ee)break}if(ee){const V={source:e==="source"?b:ee.id,target:e==="source"?ee.id:b,sourceHandle:e==="source"?n||null:se,targetHandle:e==="source"?se:n||null};(Re=(de=F.onEdgesChangeRef)==null?void 0:de.current)==null||Re.call(de,[{type:"add",item:{id:`e-${V.source}-${V.target}`,...V}}])}(We=F.workerRef.current)==null||We.postMessage({type:"connecting",data:null}),N.removeEventListener("pointermove",y),N.removeEventListener("pointerup",v)};N.addEventListener("pointermove",y),N.addEventListener("pointerup",v)},[b,n,e,t,r,a,L]),Y={top:{top:0,left:"50%",transform:"translate(-50%, -50%)"},bottom:{bottom:0,left:"50%",transform:"translate(-50%, 50%)"},left:{top:"50%",left:0,transform:"translate(-50%, -50%)"},right:{top:"50%",right:0,transform:"translate(50%, -50%)"}}[t]||{};return T.jsx("div",{ref:C,className:`ric-handle ric-handle-${t} ric-handle-${e} ${f}`,"data-handleid":n||null,"data-nodeid":b,"data-handlepos":t,"data-handletype":e,onPointerDown:A,style:{position:"absolute",width:8,height:8,borderRadius:"50%",background:"#1a192b",border:"none",zIndex:10,cursor:r?"crosshair":"default",boxSizing:"border-box",...Y,...m},...g,children:c})}const on=l.memo(mo);function vo({data:e,isConnectable:t,selected:n,targetPosition:r="left",sourcePosition:a="right",hideSourceHandle:o=!1,hideTargetHandle:c=!1}){return T.jsxs("div",{className:`ric-default-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!c&&T.jsx(on,{type:"target",position:r,isConnectable:t}),T.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!o&&T.jsx(on,{type:"source",position:a,isConnectable:t})]})}function Nr({data:e,isConnectable:t,selected:n,sourcePosition:r="right",hideSourceHandle:a=!1}){return T.jsxs("div",{className:`ric-input-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderBottom:"2px solid #0041d0",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[T.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!a&&T.jsx(on,{type:"source",position:r,isConnectable:t})]})}function Pr({data:e,isConnectable:t,selected:n,targetPosition:r="left",hideTargetHandle:a=!1}){return T.jsxs("div",{className:`ric-output-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderTop:"2px solid #ff0072",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!a&&T.jsx(on,{type:"target",position:r,isConnectable:t}),T.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label})]})}function Ir({data:e,selected:t,width:n,height:r}){return T.jsx("div",{className:`ric-group-node${t?" selected":""}`,style:{width:n||300,height:r||200,background:"rgba(240, 240, 240, 0.25)",border:t?"2px solid #3b82f6":"1px dashed #ccc",borderRadius:8,padding:8,boxSizing:"border-box"},children:(e==null?void 0:e.label)&&T.jsx("div",{style:{fontSize:11,fontWeight:600,color:"#888",userSelect:"none"},children:e.label})})}function Tr({x:e,y:t,label:n,labelStyle:r,labelShowBg:a=!0,labelBgStyle:o,labelBgPadding:c=[2,4],labelBgBorderRadius:f=2,children:m,className:d="",...g}){const[b,E]=l.useState({x:1,y:0,width:0,height:0}),C=l.useRef(null);return l.useEffect(()=>{if(C.current){const S=C.current.getBBox();E({x:S.x,y:S.y,width:S.width,height:S.height})}},[n]),n?T.jsxs("g",{transform:`translate(${e-b.width/2} ${t-b.height/2})`,className:`ric-edge-textwrapper ${d}`,visibility:b.width?"visible":"hidden",...g,children:[a&&T.jsx("rect",{width:b.width+2*c[0],x:-c[0],y:-c[1],height:b.height+2*c[1],className:"ric-edge-textbg",style:o,rx:f,ry:f}),T.jsx("text",{className:"ric-edge-text",y:b.height/2,dy:"0.3em",ref:C,style:r,children:n}),m]}):null}Tr.displayName="EdgeText";const Lr=l.memo(Tr);function hr(e){return e!=null&&e!==""&&!isNaN(Number(e))}function an({id:e,path:t,labelX:n,labelY:r,label:a,labelStyle:o,labelShowBg:c,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:d,interactionWidth:g=20,style:b,markerEnd:E,markerStart:C,className:S="",...j}){return T.jsxs(T.Fragment,{children:[T.jsx("path",{id:e,d:t,fill:"none",stroke:"#b1b1b7",strokeWidth:1.5,className:`ric-edge-path ${S}`,style:b,markerEnd:E,markerStart:C,...j}),g?T.jsx("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:g,className:"ric-edge-interaction",style:{pointerEvents:"stroke"}}):null,a&&hr(n)&&hr(r)?T.jsx(Lr,{x:n,y:r,label:a,labelStyle:o,labelShowBg:c,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:d}):null]})}const tn=20;function gr(e,t,n){switch(n){case"right":return{x:e+tn,y:t};case"left":return{x:e-tn,y:t};case"bottom":return{x:e,y:t+tn};case"top":return{x:e,y:t-tn};default:return{x:e+tn,y:t}}}const er=l.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:c="bottom",targetPosition:f="top",label:m,labelStyle:d,labelShowBg:g,labelBgStyle:b,labelBgPadding:E,labelBgBorderRadius:C,style:S,markerEnd:j,markerStart:L,interactionWidth:A}){let Y,D,F;const $=gr(n,r,c),N=gr(a,o,f),O=Math.abs(N.x-$.x),X=Math.max(50,O*.5);let H,w,y,v;switch(c){case"left":H=$.x-X,w=$.y;break;case"top":H=$.x,w=$.y-X;break;case"bottom":H=$.x,w=$.y+X;break;default:H=$.x+X,w=$.y;break}switch(f){case"right":y=N.x+X,v=N.y;break;case"top":y=N.x,v=N.y-X;break;case"bottom":y=N.x,v=N.y+X;break;default:y=N.x-X,v=N.y;break}Y=`M ${n},${r} L ${$.x},${$.y} C ${H},${w} ${y},${v} ${N.x},${N.y} L ${a},${o}`;const z=.5,P=.5;return D=P*P*P*$.x+3*P*P*z*H+3*P*z*z*y+z*z*z*N.x,F=P*P*P*$.y+3*P*P*z*w+3*P*z*z*v+z*z*z*N.y,T.jsx(an,{id:t,path:Y,labelX:D,labelY:F,label:m,labelStyle:d,labelShowBg:g,labelBgStyle:b,labelBgPadding:E,labelBgBorderRadius:C,style:S,markerEnd:j,markerStart:L,interactionWidth:A})});er.displayName="BezierEdge";function tr({sourceX:e,sourceY:t,targetX:n,targetY:r}){const a=`M ${e},${t}L ${n},${r}`,o=(e+n)/2,c=(t+r)/2;return[a,o,c,0,0]}function nr({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a="right",targetPosition:o="left",curvature:c=.25}){const f=Math.abs(n-e),m=Math.abs(r-t),d=Math.sqrt(f*f+m*m),g=Math.max(d*c,50);let b,E,C,S;switch(a){case"top":b=e,E=t-g;break;case"bottom":b=e,E=t+g;break;case"left":b=e-g,E=t;break;default:b=e+g,E=t;break}switch(o){case"top":C=n,S=r-g;break;case"bottom":C=n,S=r+g;break;case"right":C=n+g,S=r;break;default:C=n-g,S=r;break}const j=`M ${e},${t} C ${b},${E} ${C},${S} ${n},${r}`,L=.5,A=1-L,Y=A*A*A*e+3*A*A*L*b+3*A*L*L*C+L*L*L*n,D=A*A*A*t+3*A*A*L*E+3*A*L*L*S+L*L*L*r;return[j,Y,D,0,0]}function rr({sourceX:e,sourceY:t,targetX:n,targetY:r}){const a=Math.abs(n-e),o=Math.max(a*.5,50),c=e+o,f=n-o,m=`M ${e},${t} C ${c},${t} ${f},${r} ${n},${r}`,d=.5,g=.5,b=g*g*g*e+3*g*g*d*c+3*g*d*d*f+d*d*d*n,E=g*g*g*t+3*g*g*d*t+3*g*d*d*r+d*d*d*r;return[m,b,E,0,0]}function kn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a="right",targetPosition:o="left",borderRadius:c=5,offset:f=20}){const m=a==="left"||a==="right",d=Math.min(c,Math.abs(n-e)/2,Math.abs(r-t)/2);if(m){if(Math.abs(r-t)<1)return[`M ${e},${t} L ${n},${r}`,(e+n)/2,t,0,0];const C=(e+n)/2,S=r>t?1:-1;return[`M ${e},${t} L ${C-d},${t} Q ${C},${t} ${C},${t+S*d} L ${C},${r-S*d} Q ${C},${r} ${C+(n>C?d:-d)},${r} L ${n},${r}`,C,(t+r)/2,0,0]}const g=(t+r)/2,b=n>e?1:-1;return[`M ${e},${t} L ${e},${g-d} Q ${e},${g} ${e+b*d},${g} L ${n-b*d},${g} Q ${n},${g} ${n},${g+(r>g?d:-d)} L ${n},${r}`,(e+n)/2,g,0,0]}function bo({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[,a,o]=nr({sourceX:e,sourceY:t,targetX:n,targetY:r});return[a,o,0,0]}function wo({sourceX:e,sourceY:t,targetX:n,targetY:r}){return[(e+n)/2,(t+r)/2,0,0]}function Mo(e,t,n){const r=n.filter(o=>o.id!==e.id),a={...e,id:e.id,source:t.source,target:t.target,sourceHandle:t.sourceHandle??e.sourceHandle,targetHandle:t.targetHandle??e.targetHandle};return r.push(a),r}const Cn=160,En=60,nn=20,Mn=12,Sn=20;function yr(e,t,n){var c,f;const r=e.width||((c=e.measured)==null?void 0:c.width)||Cn,a=e.height||((f=e.measured)==null?void 0:f.height)||En,o=e._absolutePosition||e.position;if(e.handles&&e.handles.length>0){for(const m of e.handles)if(m.type===t&&(!n||m.id===n)){if(m.x!==void 0&&m.y!==void 0)return{x:o.x+m.x,y:o.y+m.y,dir:m.position||(t==="source"?"right":"left")};switch(m.position||(t==="source"?"right":"left")){case"top":return{x:o.x+r/2,y:o.y,dir:"top"};case"bottom":return{x:o.x+r/2,y:o.y+a,dir:"bottom"};case"left":return{x:o.x,y:o.y+a/2,dir:"left"};default:return{x:o.x+r,y:o.y+a/2,dir:"right"}}}}return t==="source"?{x:o.x+r,y:o.y+a/2,dir:"right"}:{x:o.x,y:o.y+a/2,dir:"left"}}function zn(e,t){switch(e.dir){case"right":return{x:e.x+t,y:e.y,dir:e.dir};case"left":return{x:e.x-t,y:e.y,dir:e.dir};case"bottom":return{x:e.x,y:e.y+t,dir:e.dir};case"top":return{x:e.x,y:e.y-t,dir:e.dir};default:return{x:e.x+t,y:e.y,dir:e.dir}}}function Ro(e,t,n,r,a,o,c,f){const m=Math.min(e,n),d=Math.max(e,n),g=Math.min(t,r),b=Math.max(t,r);if(d<=a||m>=a+c||b<=o||g>=o+f)return!1;const E=.5;if(e>a+E&&e<a+c-E&&t>o+E&&t<o+f-E||n>a+E&&n<a+c-E&&r>o+E&&r<o+f-E)return!0;const C=(e+n)/2,S=(t+r)/2;if(C>a+E&&C<a+c-E&&S>o+E&&S<o+f-E)return!0;const j=[[a,o],[a+c,o],[a+c,o+f],[a,o+f]];for(let L=0;L<4;L++)if(ko(e,t,n,r,j[L][0],j[L][1],j[(L+1)%4][0],j[(L+1)%4][1]))return!0;return!1}function ko(e,t,n,r,a,o,c,f){const m=(c-a)*(t-o)-(f-o)*(e-a),d=(c-a)*(r-o)-(f-o)*(n-a),g=(n-e)*(o-t)-(r-t)*(a-e),b=(n-e)*(f-t)-(r-t)*(c-e);return(m>0&&d<0||m<0&&d>0)&&(g>0&&b<0||g<0&&b>0)}function Jn(e,t,n,r,a){for(let o=0;o<a.length;o++){const c=a[o];if(Ro(e,t,n,r,c.x,c.y,c.w,c.h))return!1}return!0}function Co(e,t,n){for(let r=0;r<n.length;r++){const a=n[r];if(e>a.x&&e<a.x+a.w&&t>a.y&&t<a.y+a.h)return!0}return!1}function or(e,t){var r,a;const n=[];for(let o=0;o<e.length;o++){const c=e[o];if(c.hidden||t&&t.has(c.id)||c.type==="group")continue;const f=c._absolutePosition||c.position,m=c.width||((r=c.measured)==null?void 0:r.width)||Cn,d=c.height||((a=c.measured)==null?void 0:a.height)||En;n.push({id:c.id,x:f.x-nn,y:f.y-nn,w:m+2*nn,h:d+2*nn})}return n}function Br(e,t,n){if(Jn(e.x,e.y,t.x,t.y,n))return null;const r=new Set,a=new Set;r.add(e.x),r.add(t.x),a.add(e.y),a.add(t.y);const o=nn+5;e.dir==="right"?r.add(e.x+o):e.dir==="left"?r.add(e.x-o):e.dir==="top"?a.add(e.y-o):e.dir==="bottom"&&a.add(e.y+o),t.dir==="right"?r.add(t.x+o):t.dir==="left"?r.add(t.x-o):t.dir==="top"?a.add(t.y-o):t.dir==="bottom"&&a.add(t.y+o);for(let y=0;y<n.length;y++){const v=n[y];r.add(v.x),r.add(v.x+v.w),a.add(v.y),a.add(v.y+v.h)}const c=[...r].sort((y,v)=>y-v),f=[...a].sort((y,v)=>y-v),m=new Map,d=new Map;for(let y=0;y<c.length;y++)m.set(c[y],y);for(let y=0;y<f.length;y++)d.set(f[y],y);const g=c.length,b=f.length,E=(y,v)=>v*g+y,C=m.get(e.x),S=d.get(e.y),j=m.get(t.x),L=d.get(t.y);if(C===void 0||S===void 0||j===void 0||L===void 0)return null;const A=E(C,S),Y=E(j,L),D=new Float64Array(g*b).fill(1/0),F=new Float64Array(g*b).fill(1/0),$=new Int32Array(g*b).fill(-1),N=new Int8Array(g*b).fill(-1),O=new Uint8Array(g*b);D[A]=0,F[A]=Math.abs(c[j]-e.x)+Math.abs(f[L]-e.y);const X=[A],H=15,w=[[1,0],[-1,0],[0,1],[0,-1]];for(;X.length>0;){let y=0;for(let ee=1;ee<X.length;ee++)F[X[ee]]<F[X[y]]&&(y=ee);const v=X[y];if(X[y]=X[X.length-1],X.pop(),v===Y){const ee=[];let se=Y;for(;se!==-1&&se!==A;){const he=se/g|0,ge=se%g;ee.unshift({x:c[ge],y:f[he]}),se=$[se]}return ee.unshift({x:e.x,y:e.y}),Eo(ee,n)}if(O[v])continue;O[v]=1;const z=v/g|0,P=v%g,B=c[P],G=f[z],ne=N[v];for(let ee=0;ee<4;ee++){const se=P+w[ee][0],he=z+w[ee][1];if(se<0||se>=g||he<0||he>=b)continue;const ge=E(se,he);if(O[ge])continue;const de=c[se],Re=f[he];if(Co(de,Re,n)||!Jn(B,G,de,Re,n))continue;const We=Math.abs(de-B)+Math.abs(Re-G),V=ne>=0&&ne!==ee?H:0,oe=D[v]+We+V;oe<D[ge]&&($[ge]=v,N[ge]=ee,D[ge]=oe,F[ge]=oe+Math.abs(c[j]-de)+Math.abs(f[L]-Re),X.push(ge))}}return null}function Eo(e,t){if(!e||e.length<=2)return e;const n=[e[0]];for(let r=1;r<e.length-1;r++){const a=n[n.length-1],o=e[r],c=e[r+1],f=Math.abs(a.x-o.x)<.5&&Math.abs(o.x-c.x)<.5,m=Math.abs(a.y-o.y)<.5&&Math.abs(o.y-c.y)<.5;(f||m)&&Jn(a.x,a.y,c.x,c.y,t)||n.push(o)}return n.push(e[e.length-1]),n}function So(e){const t=new Map,n=new Map;for(const a of e){const o=a._routedPoints;if(!(!o||o.length<2))for(let c=0;c<o.length-1;c++){const f=o[c],m=o[c+1];if(Math.abs(f.y-m.y)<.5){const d=Math.round(f.y*10)/10;t.has(d)||t.set(d,[]),t.get(d).push({edgeId:a.id,segIdx:c,x1:Math.min(f.x,m.x),x2:Math.max(f.x,m.x)})}else if(Math.abs(f.x-m.x)<.5){const d=Math.round(f.x*10)/10;n.has(d)||n.set(d,[]),n.get(d).push({edgeId:a.id,segIdx:c,y1:Math.min(f.y,m.y),y2:Math.max(f.y,m.y)})}}}const r=new Map;for(const a of e)a._routedPoints&&r.set(a.id,a._routedPoints.map(o=>({...o})));for(const[,a]of t){if(a.length<2)continue;const o=xr(a,"x1","x2");for(const c of o){if(c.length<2)continue;const f=(c.length-1)*Mn/2;for(let m=0;m<c.length;m++){const d=c[m],g=-f+m*Mn,b=r.get(d.edgeId);b&&(b[d.segIdx].y+=g,b[d.segIdx+1].y+=g)}}}for(const[,a]of n){if(a.length<2)continue;const o=xr(a,"y1","y2");for(const c of o){if(c.length<2)continue;const f=(c.length-1)*Mn/2;for(let m=0;m<c.length;m++){const d=c[m],g=-f+m*Mn,b=r.get(d.edgeId);b&&(b[d.segIdx].x+=g,b[d.segIdx+1].x+=g)}}}return e.map(a=>{const o=r.get(a.id);return o?{...a,_routedPoints:o}:a})}function xr(e,t,n){if(e.length<2)return[];const r=[...e].sort((c,f)=>c[t]-f[t]),a=[];let o=[r[0]];for(let c=1;c<r.length;c++){const f=o[o.length-1];r[c][t]<f[n]?o.push(r[c]):(o.length>1&&a.push(o),o=[r[c]])}return o.length>1&&a.push(o),a}function Nn(e,t=6,n=!1){if(!e||e.length<2)return null;if(n)return zo(e);const r=t;let a=`M ${e[0].x},${e[0].y}`;for(let o=1;o<e.length-1;o++){const c=e[o-1],f=e[o],m=e[o+1],d=Math.abs(f.x-c.x)+Math.abs(f.y-c.y),g=Math.abs(m.x-f.x)+Math.abs(m.y-f.y),b=Math.min(r,d/2,g/2);if(b>.5){const E=f.x-c.x,C=f.y-c.y,S=m.x-f.x,j=m.y-f.y,L=Math.sqrt(E*E+C*C)||1,A=Math.sqrt(S*S+j*j)||1;a+=` L ${f.x-E/L*b},${f.y-C/L*b}`,a+=` Q ${f.x},${f.y} ${f.x+S/A*b},${f.y+j/A*b}`}else a+=` L ${f.x},${f.y}`}return a+=` L ${e[e.length-1].x},${e[e.length-1].y}`,a}function zo(e){if(e.length===2)return`M ${e[0].x},${e[0].y} L ${e[1].x},${e[1].y}`;if(e.length===3)return`M ${e[0].x},${e[0].y} Q ${e[1].x},${e[1].y} ${e[2].x},${e[2].y}`;const t=.3;let n=`M ${e[0].x},${e[0].y}`;for(let r=0;r<e.length-1;r++){const a=e[r===0?0:r-1],o=e[r],c=e[r+1],f=e[r+2<e.length?r+2:e.length-1],m=o.x+(c.x-a.x)*t,d=o.y+(c.y-a.y)*t,g=c.x-(f.x-o.x)*t,b=c.y-(f.y-o.y)*t;n+=` C ${m},${d} ${g},${b} ${c.x},${c.y}`}return n}function Pn(e){if(!e||e.length<2)return{x:0,y:0};let t=0;for(let r=1;r<e.length;r++)t+=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);let n=t/2;for(let r=1;r<e.length;r++){const a=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);if(n<=a){const o=a>0?n/a:0;return{x:e[r-1].x+(e[r].x-e[r-1].x)*o,y:e[r-1].y+(e[r].y-e[r-1].y)*o}}n-=a}return{x:e[0].x,y:e[0].y}}function No(e,t){if(!e||!t||e.length===0||t.length===0)return t;const n={};for(const o of e)n[o.id]=o;const r=or(e,null),a=t.map(o=>{var N,O,X,H;const c=o.type||"default";if(c==="bezier"||c==="simplebezier"||c==="default")return o;const f=n[o.source],m=n[o.target];if(!f||!m||f.hidden||m.hidden)return o;const d=yr(f,"source",o.sourceHandle),g=yr(m,"target",o.targetHandle),b=zn(d,Sn),E=zn(g,Sn),C=5,S=r.filter(w=>w.id!==o.source&&w.id!==o.target),j=f._absolutePosition||f.position,L=f.width||((N=f.measured)==null?void 0:N.width)||Cn,A=f.height||((O=f.measured)==null?void 0:O.height)||En;S.push({id:o.source,x:j.x-C,y:j.y-C,w:L+2*C,h:A+2*C});const Y=m._absolutePosition||m.position,D=m.width||((X=m.measured)==null?void 0:X.width)||Cn,F=m.height||((H=m.measured)==null?void 0:H.height)||En;if(S.push({id:o.target,x:Y.x-C,y:Y.y-C,w:D+2*C,h:F+2*C}),S.length===0)return o;const $=Br(b,E,S);return $&&$.length>=2?($.unshift({x:d.x,y:d.y}),$.push({x:g.x,y:g.y}),{...o,_routedPoints:$}):o});return So(a)}function Po(e,t,n,r,a,o,c,f){const m=or(c,f?new Set(f):null);if(m.length===0)return null;const d={x:e,y:t,dir:a||"right"},g={x:n,y:r,dir:o||"left"},b=zn(d,Sn),E=zn(g,Sn),C=Br(b,E,m);return C&&C.length>=2?(C.unshift({x:d.x,y:d.y}),C.push({x:g.x,y:g.y}),C):null}const sr=l.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,label:c,labelStyle:f,labelShowBg:m,labelBgStyle:d,labelBgPadding:g,labelBgBorderRadius:b,style:E,markerEnd:C,markerStart:S,interactionWidth:j,routedPoints:L}){let A,Y,D;if(L&&L.length>=2){A=Nn(L);const F=Pn(L);Y=F.x,D=F.y}else[A,Y,D]=tr({sourceX:n,sourceY:r,targetX:a,targetY:o});return T.jsx(an,{id:t,path:A,labelX:Y,labelY:D,label:c,labelStyle:f,labelShowBg:m,labelBgStyle:d,labelBgPadding:g,labelBgBorderRadius:b,style:E,markerEnd:C,markerStart:S,interactionWidth:j})});sr.displayName="StraightEdge";const ar=l.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:c="bottom",targetPosition:f="top",label:m,labelStyle:d,labelShowBg:g,labelBgStyle:b,labelBgPadding:E,labelBgBorderRadius:C,style:S,markerEnd:j,markerStart:L,pathOptions:A,interactionWidth:Y,routedPoints:D}){let F,$,N;if(D&&D.length>=2){F=Nn(D);const O=Pn(D);$=O.x,N=O.y}else[F,$,N]=kn({sourceX:n,sourceY:r,sourcePosition:c,targetX:a,targetY:o,targetPosition:f,borderRadius:A==null?void 0:A.borderRadius,offset:A==null?void 0:A.offset});return T.jsx(an,{id:t,path:F,labelX:$,labelY:N,label:m,labelStyle:d,labelShowBg:g,labelBgStyle:b,labelBgPadding:E,labelBgBorderRadius:C,style:S,markerEnd:j,markerStart:L,interactionWidth:Y})});ar.displayName="SmoothStepEdge";const $r=l.memo(function({id:t,...n}){var a;const r=l.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(a=n.pathOptions)==null?void 0:a.offset]);return T.jsx(ar,{...n,id:t,pathOptions:r})});$r.displayName="StepEdge";const ir=l.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:c,targetPosition:f,label:m,labelStyle:d,labelShowBg:g,labelBgStyle:b,labelBgPadding:E,labelBgBorderRadius:C,style:S,markerEnd:j,markerStart:L,interactionWidth:A,routedPoints:Y}){let D,F,$;if(Y&&Y.length>=2){D=Nn(Y);const N=Pn(Y);F=N.x,$=N.y}else[D,F,$]=rr({sourceX:n,sourceY:r,targetX:a,targetY:o});return T.jsx(an,{id:t,path:D,labelX:F,labelY:$,label:m,labelStyle:d,labelShowBg:g,labelBgStyle:b,labelBgPadding:E,labelBgBorderRadius:C,style:S,markerEnd:j,markerStart:L,interactionWidth:A})});ir.displayName="SimpleBezierEdge";const Io={input:Nr,output:Pr,group:Ir},To={bezier:er,straight:sr,simplebezier:ir},Lo=160,Bo=60;function $o(e){let t=!1;for(let n=0;n<e.length;n++){const r=e[n];if(!r.measured||r.measured.width==null||r.measured.height==null){t=!0;break}}return t?e.map(n=>{var r,a;return((r=n.measured)==null?void 0:r.width)!=null&&((a=n.measured)==null?void 0:a.height)!=null?n:{...n,measured:{width:n.width||Lo,height:n.height||Bo}}}):e}function jo({cards:e,nodes:t=[],edges:n=[],nodeTypes:r,edgeTypes:a,canvasNodeTypes:o,domNodeLimit:c=50,dark:f,gridSize:m,width:d="100%",height:g="420px",className:b="",style:E={},zoomMin:C,zoomMax:S,initialCamera:j,fitView:L,fitViewOptions:A,onNodesChange:Y,onEdgesChange:D,onConnect:F,onConnectStart:$,onConnectEnd:N,onNodeClick:O,onNodeDoubleClick:X,onNodeMouseEnter:H,onNodeMouseMove:w,onNodeMouseLeave:y,onNodeContextMenu:v,onNodeDragStart:z,onNodeDrag:P,onNodeDragStop:B,onEdgeClick:G,onEdgeDoubleClick:ne,onEdgeMouseEnter:ee,onEdgeMouseMove:se,onEdgeMouseLeave:he,onEdgeContextMenu:ge,onPaneClick:de,onPaneContextMenu:Re,onPaneMouseEnter:We,onPaneMouseMove:V,onPaneMouseLeave:oe,onSelectionChange:xe,onInit:Ze,onMoveStart:fe,onMove:je,onMoveEnd:Ae,onDelete:Pe,onBeforeDelete:Ce,onError:rt,onDragOver:at,onDrop:be,onDragEnter:Ie,onDragLeave:Je,nodesDraggable:$e,nodesConnectable:Ye,elementsSelectable:Ge,multiSelectionKeyCode:Nt,selectionOnDrag:cn,selectionMode:Pt,connectionMode:ln,connectionRadius:un,connectOnClick:dn,isValidConnection:fn,defaultEdgeOptions:Gt,snapToGrid:xt,snapGrid:pt,deleteKeyCode:It,panActivationKeyCode:In,panOnScroll:Tn,panOnScrollMode:it,panOnScrollSpeed:cr,zoomOnScroll:Ln,zoomOnDoubleClick:Bn,zoomOnPinch:Tt,preventScrolling:Lt,translateExtent:$n,nodeExtent:jn,autoPanOnNodeDrag:An,autoPanOnConnect:Ct,autoPanSpeed:pe,edgesReconnectable:Bt,elevateNodesOnSelect:Te,elevateEdgesOnSelect:ce,noDragClassName:mt,noPanClassName:K,onSelectionDragStart:Ee,onSelectionDrag:hn,onSelectionDragStop:$t,edgeRouting:jt=!0,onHudUpdate:At,onNodesProcessed:Dn,showHud:Xe=!0,showHint:Ue=!0,hintText:Dt="Drag to pan · Scroll to zoom",children:ct,...gn}){const[Ke,yn]=l.useState({wx:0,wy:0,zoom:"1.00"}),xn=l.useRef(null),Qt=l.useRef(null),pn=l.useCallback(_=>{yn(_),At==null||At(_)},[At]),vt=l.useMemo(()=>({...Io,...r}),[r]),lt=l.useMemo(()=>({...To,...a}),[a]),et=l.useMemo(()=>$o(t),[t]),[Z,ut]=l.useState(()=>new Set),Ht=l.useRef(Z);Ht.current=Z;const _t=l.useCallback(_=>{ut(we=>{const ie=new Set(we);return ie.add(_),ie})},[]),Wt=l.useCallback(_=>{ut(we=>{const ie=new Set(we);return ie.delete(_),ie})},[]),Ft=l.useCallback(_=>{ut(we=>{const ie=new Set(we);return ie.has(_)?ie.delete(_):ie.add(_),ie})},[]),Et=l.useMemo(()=>et.filter(_=>_.type&&vt[_.type]),[et,vt]),bt=l.useMemo(()=>{var we,ie;if(c===0)return new Set;const _=new Set;for(const ve of Z)_.add(ve);for(const ve of Et)(ve.selected||ve.dragging)&&_.add(ve.id);if(_.size<c){const ve=((we=le.cameraRef)==null?void 0:we.current)||{x:0,y:0,zoom:1},Be=(ie=le.wrapRef)==null?void 0:ie.current,Se=(Be==null?void 0:Be.clientWidth)||800,De=(Be==null?void 0:Be.clientHeight)||600,gt=(-ve.x+Se/2)/ve.zoom,kt=(-ve.y+De/2)/ve.zoom,u=Et.filter(i=>!_.has(i.id)).map(i=>{const h=i._absolutePosition||i.position,M=h.x+(i.width||160)/2-gt,k=h.y+(i.height||60)/2-kt;return{id:i.id,dist:M*M+k*k}}).sort((i,h)=>i.dist-h.dist),x=c-_.size;for(let i=0;i<Math.min(x,u.length);i++)_.add(u[i].id)}return _},[Et,Z,c,le.cameraRef,le.wrapRef]),ot=l.useMemo(()=>{const _=et.filter(we=>bt.has(we.id));return _.sort((we,ie)=>{const ve=we.type==="group"||!we.parentId&&_.some(Se=>Se.parentId===we.id),Be=ie.type==="group"||!ie.parentId&&_.some(Se=>Se.parentId===ie.id);return ve&&!Be?-1:!ve&&Be?1:0})},[et,bt]),Yt=l.useMemo(()=>n.filter(_=>_.type&&lt[_.type]),[n,lt]),Vt=l.useMemo(()=>t.map(_=>bt.has(_.id)?{..._,_customRendered:!0}:_),[t,bt]),Le=l.useMemo(()=>n.map(_=>_.type&&lt[_.type]?{..._,_customRendered:!0}:_),[n,lt]),{wrapRef:mn,canvasRef:Fe,canvasReady:Hn,onPointerDown:wt,onPointerMove:Xt,onPointerUp:dt,store:le}=Mr({cards:e,nodes:Vt,edges:Le,dark:f,gridSize:m,zoomMin:C,zoomMax:S,initialCamera:j,fitView:L,fitViewOptions:A,onHudUpdate:pn,onNodesProcessed:Dn,onNodesChange:Y,onEdgesChange:D,onConnect:F,onConnectStart:$,onConnectEnd:N,onNodeClick:O,onNodeDoubleClick:X,onNodeMouseEnter:H,onNodeMouseMove:w,onNodeMouseLeave:y,onNodeContextMenu:v,onNodeDragStart:z,onNodeDrag:P,onNodeDragStop:B,onEdgeClick:G,onEdgeDoubleClick:ne,onEdgeMouseEnter:ee,onEdgeMouseMove:se,onEdgeMouseLeave:he,onEdgeContextMenu:ge,onPaneClick:de,onPaneContextMenu:Re,onPaneMouseEnter:We,onPaneMouseMove:V,onPaneMouseLeave:oe,onSelectionChange:xe,onInit:Ze,onMoveStart:fe,onMove:je,onMoveEnd:Ae,onDelete:Pe,onBeforeDelete:Ce,onError:rt,nodesDraggable:$e,nodesConnectable:Ye,elementsSelectable:Ge,multiSelectionKeyCode:Nt,selectionOnDrag:cn,selectionMode:Pt,connectionMode:ln,connectionRadius:un,connectOnClick:dn,isValidConnection:fn,defaultEdgeOptions:Gt,snapToGrid:xt,snapGrid:pt,deleteKeyCode:It,panActivationKeyCode:In,panOnScroll:Tn,panOnScrollMode:it,panOnScrollSpeed:cr,zoomOnScroll:Ln,zoomOnDoubleClick:Bn,zoomOnPinch:Tt,preventScrolling:Lt,translateExtent:$n,nodeExtent:jn,autoPanOnNodeDrag:An,autoPanOnConnect:Ct,autoPanSpeed:pe,edgesReconnectable:Bt,elevateNodesOnSelect:Te,elevateEdgesOnSelect:ce,noDragClassName:mt,noPanClassName:K,onSelectionDragStart:Ee,onSelectionDrag:hn,onSelectionDragStop:$t,edgeRouting:jt}),Ot=l.useRef(new Set);l.useEffect(()=>{if(!o||!le.workerRef.current)return;let _=!1;async function we(ve){const Be=new Blob([ve],{type:"image/svg+xml"}),Se=URL.createObjectURL(Be),De=new Image;return De.src=Se,await De.decode(),URL.revokeObjectURL(Se),createImageBitmap(De)}async function ie(){var gt,kt,u;const ve={},Be=[],Se={},De={};for(const[x,i]of Object.entries(o)){if(typeof i=="function"){Se[x]=i;continue}if(typeof i=="object"&&i!==null&&!(i instanceof ImageBitmap)&&!(i instanceof HTMLImageElement)&&!(i instanceof HTMLCanvasElement)&&("fill"in i||"stroke"in i||"title"in i||"accent"in i)){De[x]=i;continue}try{let h;i instanceof ImageBitmap?h=i:typeof i=="string"?h=await we(i):i instanceof HTMLImageElement?h=await createImageBitmap(i):i instanceof HTMLCanvasElement&&(h=await createImageBitmap(i)),h&&!_&&(ve[x]=h,Be.push(h))}catch(h){console.warn(`[InfiniteCanvas] Failed to convert canvasNodeType "${x}":`,h)}}if(!_&&Object.keys(ve).length>0&&((gt=le.workerRef.current)==null||gt.postMessage({type:"nodeTypeBitmaps",data:{bitmaps:ve}},Be)),!_&&Object.keys(De).length>0&&((kt=le.workerRef.current)==null||kt.postMessage({type:"nodeTypeConfigs",data:{configs:De}})),!_&&Object.keys(Se).length>0){const x=new Map,i={},h={},M=[];let k=Ot.current.size;for(const p of t){const I=Se[p.type];if(I)try{const R=I(p.data);if(!R)continue;let U=x.get(R);if(!U&&(U="bmp_"+k++,x.set(R,U),!Ot.current.has(R))){const W=await we(R);if(_)return;i[U]=W,M.push(W),Ot.current.add(R)}h[p.id]=U}catch(R){console.warn(`[InfiniteCanvas] canvasNodeType fn error for node "${p.id}":`,R)}}_||(u=le.workerRef.current)==null||u.postMessage({type:"nodeBitmaps",data:{cache:i,keys:h}},M)}}return ie(),()=>{_=!0}},[o,t,le.workerRef]);const ke=l.useContext(zt),tt=ke&&typeof ke.getState=="function";l.useEffect(()=>{tt&&queueMicrotask(()=>{ke.setState({nodes:et,edges:n,nodesRef:le.nodesRef,edgesRef:le.edgesRef,onNodesChangeRef:le.onNodesChangeRef,onEdgesChangeRef:le.onEdgesChangeRef,cameraRef:le.cameraRef,wrapRef:le.wrapRef,workerRef:le.workerRef})})},[tt,et,n,le,ke]);const vn=l.useMemo(()=>({...le,edgeLabelContainerRef:xn,viewportPortalRef:Qt,pinNode:_t,unpinNode:Wt,togglePinNode:Ft,get pinnedNodeIds(){return Ht.current},get nodes(){return et},get edges(){return n},get viewport(){return le.cameraRef.current},get minZoom(){return le.zoomMin||.1},get maxZoom(){return le.zoomMax||5},get domNode(){return le.wrapRef.current},get width(){var _;return((_=le.wrapRef.current)==null?void 0:_.clientWidth)||0},get height(){var _;return((_=le.wrapRef.current)==null?void 0:_.clientHeight)||0}}),[le,et,n,_t,Wt,Ft]),Ut=l.useRef(null),Mt=l.useRef(null),nt=l.useRef(null),qt=l.useRef(null),me=l.useRef(null);l.useEffect(()=>{let _;const we=()=>{const ie=le.cameraRef.current,ve=`translate(${ie.x}px, ${ie.y}px) scale(${ie.zoom})`,Be=`translate(${ie.x}, ${ie.y}) scale(${ie.zoom})`;Ut.current&&(Ut.current.style.transform=ve),Mt.current&&Mt.current.setAttribute("transform",Be),nt.current&&(nt.current.style.transform=ve),qt.current&&(qt.current.style.transform=ve);const Se=mn.current;if(Se){const De=ie.zoom<.15?"lod-minimal":ie.zoom<.35?"lod-reduced":null;De!==me.current&&(Se.classList.remove("lod-minimal","lod-reduced"),De&&Se.classList.add(De),me.current=De)}_=requestAnimationFrame(we)};return _=requestAnimationFrame(we),()=>cancelAnimationFrame(_)},[le]);const[ft,Rt]=l.useState(null);l.useEffect(()=>{if(!ot.length)return;let _;const we=()=>{var i,h;const ie=le.cameraRef.current,ve=le.wrapRef.current;if(!ve){_=requestAnimationFrame(we);return}const Be=ve.getBoundingClientRect(),Se=200,De=-ie.x/ie.zoom-Se,gt=-ie.y/ie.zoom-Se,kt=(Be.width-ie.x)/ie.zoom+Se,u=(Be.height-ie.y)/ie.zoom+Se,x=new Set;for(const M of ot){const k=M._absolutePosition||M.position,p=M.width||((i=M.measured)==null?void 0:i.width)||200,I=M.height||((h=M.measured)==null?void 0:h.height)||100;k.x+p>=De&&k.x<=kt&&k.y+I>=gt&&k.y<=u&&x.add(M.id)}Rt(M=>{if(!M||M.size!==x.size)return x;for(const k of x)if(!M.has(k))return x;return M}),_=requestAnimationFrame(we)};return _=requestAnimationFrame(we),()=>cancelAnimationFrame(_)},[ot,le]);const _n=l.useMemo(()=>ft?ot.filter(_=>ft.has(_.id)):ot,[ot,ft]),Wn=ot.length>0,Fn=Yt.length>0;return T.jsx(zt.Provider,{value:vn,children:T.jsxs("div",{ref:mn,className:`ric-wrap ${b}`,style:{width:d,height:g,...E},onPointerDown:wt,onPointerMove:Xt,onPointerUp:dt,onDragOver:at,onDrop:be,onDragEnter:Ie,onDragLeave:Je,tabIndex:0,children:[T.jsx("canvas",{ref:Fe,className:"ric-canvas"}),!Hn&&T.jsx("div",{className:"ric-loader",children:T.jsx("div",{className:"ric-spinner"})}),Fn&&T.jsx("svg",{className:"ric-edges-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:T.jsx("g",{ref:Mt,children:Yt.map(_=>T.jsx(yo,{edge:_,edgeType:lt[_.type],nodes:t,reconnectable:Bt},_.id))})}),Wn&&T.jsx("div",{ref:Ut,className:"ric-nodes-overlay",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:10},children:_n.map(_=>T.jsx(uo,{node:_,nodeType:vt[_.type]},_.id))}),T.jsx("div",{ref:_=>{xn.current=_,nt.current=_},className:"ric-edge-labels",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:5}}),T.jsx("div",{ref:_=>{Qt.current=_,qt.current=_},className:"ric-viewport-portal",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:6}}),Ue&&T.jsx("div",{className:"ric-hint",children:Dt}),Xe&&T.jsxs("div",{className:"ric-info",children:["world: (",Ke.wx,", ",Ke.wy,")   zoom: ",Ke.zoom,"x",Ke.nodeCount>0&&T.jsxs(T.Fragment,{children:["   nodes: ",Ke.nodeCount]}),Ke.edgeCount>0&&T.jsxs(T.Fragment,{children:["   edges: ",Ke.edgeCount]})]}),T.jsx(Sr,{selectionKeyCode:Nt||"Shift",selectionMode:Pt||"partial"}),ct]})})}function Ao({children:e}){const t=l.useRef(null);return t.current||(t.current=io()),T.jsx(zt.Provider,{value:t.current,children:e})}function jr(e,t){const n=[],r=new Map,a=[];for(const o of e)if(o.type==="add")a.push(o);else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const c=r.get(o.id);c?c.push(o):r.set(o.id,[o])}for(const o of t){const c=r.get(o.id);if(!c){n.push(o);continue}if(c[0].type==="remove")continue;if(c[0].type==="replace"){n.push({...c[0].item});continue}const f={...o};for(const m of c)Do(m,f);n.push(f)}for(const o of a)o.index!==void 0?n.splice(o.index,0,{...o.item}):n.push({...o.item});return n}function Do(e,t){switch(e.type){case"select":t.selected=e.selected;break;case"position":e.position!==void 0&&(t.position=e.position),e.dragging!==void 0&&(t.dragging=e.dragging);break;case"dimensions":e.dimensions!==void 0&&(t.measured={...e.dimensions},(e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height)),e.handleBounds!==void 0&&(t.handleBounds=e.handleBounds);break}}function Ar(e,t){return jr(e,t)}function Dr(e,t){return jr(e,t)}function Ho(e,t){return!e.source||!e.target?(console.warn("addEdge: source and target are required"),t):t.some(r=>r.source===e.source&&r.target===e.target&&(r.sourceHandle||null)===(e.sourceHandle||null)&&(r.targetHandle||null)===(e.targetHandle||null))?t:[...t,{id:e.id||`e-${e.source}-${e.target}`,...e}]}function _o(e){const[t,n]=l.useState(e),r=l.useCallback(a=>n(o=>Ar(a,o)),[]);return[t,n,r]}function Wo(e){const[t,n]=l.useState(e),r=l.useCallback(a=>n(o=>Dr(a,o)),[]);return[t,n,r]}function Hr(){const e=Rr(),t=l.useCallback(()=>typeof e.getState=="function"?e.getState():e,[e]),n=l.useCallback(()=>[...t().nodesRef.current],[t]),r=l.useCallback(()=>[...t().edgesRef.current],[t]),a=l.useCallback(w=>t().nodesRef.current.find(y=>y.id===w),[t]),o=l.useCallback(w=>t().edgesRef.current.find(y=>y.id===w),[t]),c=l.useCallback(w=>{var y,v,z,P;if(typeof w=="function"){const B=w(t().nodesRef.current);(v=(y=t().onNodesChangeRef).current)==null||v.call(y,[...t().nodesRef.current.map(G=>({id:G.id,type:"remove"})),...B.map(G=>({type:"add",item:G}))])}else(P=(z=t().onNodesChangeRef).current)==null||P.call(z,[...t().nodesRef.current.map(B=>({id:B.id,type:"remove"})),...w.map(B=>({type:"add",item:B}))])},[t]),f=l.useCallback(w=>{var y,v,z,P;if(typeof w=="function"){const B=w(t().edgesRef.current);(v=(y=t().onEdgesChangeRef).current)==null||v.call(y,[...t().edgesRef.current.map(G=>({id:G.id,type:"remove"})),...B.map(G=>({type:"add",item:G}))])}else(P=(z=t().onEdgesChangeRef).current)==null||P.call(z,[...t().edgesRef.current.map(B=>({id:B.id,type:"remove"})),...w.map(B=>({type:"add",item:B}))])},[t]),m=l.useCallback(w=>{var v,z;const y=Array.isArray(w)?w:[w];(z=(v=t().onNodesChangeRef).current)==null||z.call(v,y.map(P=>({type:"add",item:P})))},[t]),d=l.useCallback(w=>{var v,z;const y=Array.isArray(w)?w:[w];(z=(v=t().onEdgesChangeRef).current)==null||z.call(v,y.map(P=>({type:"add",item:P})))},[t]),g=l.useCallback(({nodes:w=[],edges:y=[]})=>{if(w.length&&t().onNodesChangeRef.current){t().onNodesChangeRef.current(w.map(z=>({id:z.id,type:"remove"})));const v=br(w,t().edgesRef.current);v.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(v.map(z=>({id:z.id,type:"remove"})))}y.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(y.map(v=>({id:v.id,type:"remove"})))},[t]),b=l.useCallback(()=>{const w=t().cameraRef.current;return{x:w.x,y:w.y,zoom:w.zoom}},[t]),E=l.useRef(null),C=l.useCallback((w,y)=>{if(E.current&&cancelAnimationFrame(E.current),!y||y<=0){t().cameraRef.current={...w},t().sendCamera();return}const v={...t().cameraRef.current},z=performance.now(),P=B=>{const G=B-z,ne=Math.min(G/y,1),ee=1-Math.pow(1-ne,3);t().cameraRef.current={x:v.x+(w.x-v.x)*ee,y:v.y+(w.y-v.y)*ee,zoom:v.zoom+(w.zoom-v.zoom)*ee},t().sendCamera(),ne<1&&(E.current=requestAnimationFrame(P))};E.current=requestAnimationFrame(P)},[t]),S=l.useCallback((w,y)=>{const v={x:w.x??t().cameraRef.current.x,y:w.y??t().cameraRef.current.y,zoom:w.zoom??t().cameraRef.current.zoom};C(v,y==null?void 0:y.duration)},[t,C]),j=l.useCallback(()=>t().cameraRef.current.zoom,[t]),L=l.useCallback(w=>{const y=t().cameraRef.current,v=t().wrapRef.current;if(!v)return;const z=v.getBoundingClientRect(),P=z.width/2,B=z.height/2,G=1.2,ne={x:P-(P-y.x)*G,y:B-(B-y.y)*G,zoom:Math.min(t().zoomMax,y.zoom*G)};C(ne,w==null?void 0:w.duration)},[t,C]),A=l.useCallback(w=>{const y=t().cameraRef.current,v=t().wrapRef.current;if(!v)return;const z=v.getBoundingClientRect(),P=z.width/2,B=z.height/2,G=1/1.2,ne={x:P-(P-y.x)*G,y:B-(B-y.y)*G,zoom:Math.max(t().zoomMin,y.zoom*G)};C(ne,w==null?void 0:w.duration)},[t,C]),Y=l.useCallback((w,y)=>{const v=t().cameraRef.current,z=t().wrapRef.current;if(!z)return;const P=z.getBoundingClientRect(),B=P.width/2,G=P.height/2,ne=Math.min(t().zoomMax,Math.max(t().zoomMin,w)),ee=ne/v.zoom,se={x:B-(B-v.x)*ee,y:G-(G-v.y)*ee,zoom:ne};C(se,y==null?void 0:y.duration)},[t,C]),D=l.useCallback((w={})=>{const y=t().nodesRef.current;if(!y.length)return;const v=t().wrapRef.current;if(!v)return;const z=v.getBoundingClientRect(),P=w.padding??.1,B=w.nodes?y.filter(ee=>w.nodes.some(se=>se.id===ee.id)):y;if(!B.length)return;const G=Rn(B),ne=Zt(G,z.width,z.height,P);w.maxZoom&&(ne.zoom=Math.min(ne.zoom,w.maxZoom)),w.minZoom&&(ne.zoom=Math.max(ne.zoom,w.minZoom)),C(ne,w.duration)},[t,C]),F=l.useCallback((w,y={})=>{const v=t().wrapRef.current;if(!v)return;const z=v.getBoundingClientRect(),P=y.padding??.1,B=Zt(w,z.width,z.height,P);y.maxZoom&&(B.zoom=Math.min(B.zoom,y.maxZoom)),y.minZoom&&(B.zoom=Math.max(B.zoom,y.minZoom)),C(B,y.duration)},[t,C]),$=l.useCallback((w,y,v={})=>{const z=t().wrapRef.current;if(!z)return;const P=z.getBoundingClientRect(),B=v.zoom??t().cameraRef.current.zoom,G={x:P.width/2-w*B,y:P.height/2-y*B,zoom:B};C(G,v.duration)},[t,C]),N=l.useCallback(()=>({nodes:[...t().nodesRef.current],edges:[...t().edgesRef.current],viewport:{...t().cameraRef.current}}),[t]),O=l.useCallback(w=>t().screenToWorld(w.x,w.y),[t]),X=l.useCallback(w=>{const y=t().cameraRef.current,v=t().wrapRef.current;if(!v)return{x:0,y:0};const z=v.getBoundingClientRect();return{x:w.x*y.zoom+y.x+z.left,y:w.y*y.zoom+y.y+z.top}},[t]),H=l.useCallback((w,y)=>{var P,B;const v=t().nodesRef.current.find(G=>G.id===w);if(!v)return;const z=typeof y=="function"?y(v.data):{...v.data,...y};(B=(P=t().onNodesChangeRef).current)==null||B.call(P,[{id:w,type:"replace",item:{...v,data:z}}])},[t]);return{getNodes:n,getEdges:r,getNode:a,getEdge:o,setNodes:c,setEdges:f,addNodes:m,addEdges:d,deleteElements:g,getViewport:b,setViewport:S,getZoom:j,zoomIn:L,zoomOut:A,zoomTo:Y,fitView:D,fitBounds:F,setCenter:$,screenToFlowPosition:O,flowToScreenPosition:X,updateNodeData:H,toObject:N}}function Fo(){return Ne().nodes}function Yo(){return Ne().edges}function Xo(){return Ne().viewport}function Oo(){return Ne().connection}function Uo(e){const t=Ne(),n=Array.isArray(e)?e:[e];return l.useMemo(()=>n.map(r=>{const a=t.nodes.find(o=>o.id===r);return a?{id:a.id,type:a.type,data:a.data}:null}).filter(Boolean),[t.nodes,...n])}function qo(e){const t=Ne();return l.useMemo(()=>t.edges.filter(n=>n.source===e||n.target===e),[t.edges,e])}function Zo({nodeId:e,type:t,handleId:n}){const r=Ne();return l.useMemo(()=>r.edges.filter(a=>t==="source"?a.source===e&&(n?a.sourceHandle===n:!0):a.target===e&&(n?a.targetHandle===n:!0)),[r.edges,e,t,n])}function Go({onChange:e,onStart:t,onEnd:n}){const r=Ne(),a=l.useRef(e),o=l.useRef(t),c=l.useRef(n);l.useEffect(()=>{a.current=e},[e]),l.useEffect(()=>{o.current=t},[t]),l.useEffect(()=>{c.current=n},[n]),l.useEffect(()=>{const f=m=>{var d;(d=a.current)==null||d.call(a,{x:m.x,y:m.y,zoom:m.zoom})};return r.viewportListeners.add(f),()=>r.viewportListeners.delete(f)},[s])}function Qo({onChange:e}){const t=Ne(),n=l.useRef(e);l.useEffect(()=>{n.current=e},[e]),l.useEffect(()=>{const r=a=>{var o;(o=n.current)==null||o.call(n,a)};return t.selectionListeners.add(r),()=>t.selectionListeners.delete(r)},[s])}function Vo(e){const[t,n]=l.useState(!1),r=Array.isArray(e)?e:[e];return l.useEffect(()=>{const a=c=>{r.includes(c.key)&&n(!0)},o=c=>{r.includes(c.key)&&n(!1)};return window.addEventListener("keydown",a),window.addEventListener("keyup",o),()=>{window.removeEventListener("keydown",a),window.removeEventListener("keyup",o)}},[r.join(",")]),t}function Jo(){const e=Ne();return l.useCallback(t=>{var n;(n=e.workerRef.current)==null||n.postMessage({type:"nodes",data:{nodes:[...s().nodesRef.current]}})},[s])}const Ko=e=>{var t;return((t=e.nodes)==null?void 0:t.length)>0};function es(e={}){return Ne(Ko)}function ts(e){const t=Ne();return l.useMemo(()=>t.nodes.find(n=>n.id===e)||void 0,[t.nodes,e])}function ns(e,t){return Ne(e,t)}function rs(){return Rr()}function os({maxHistorySize:e=100}={}){const t=Ne(),n=l.useRef([]),r=l.useRef([]),[,a]=l.useState(0),o=l.useRef(null),c=l.useCallback(()=>{const d={nodes:s().nodesRef.current.map(g=>({...g,data:{...g.data}})),edges:s().edgesRef.current.map(g=>({...g}))};o.current&&JSON.stringify(o.current.nodes.map(g=>g.id))===JSON.stringify(d.nodes.map(g=>g.id))&&JSON.stringify(o.current.edges.map(g=>g.id))===JSON.stringify(d.edges.map(g=>g.id))||(n.current.push(d),n.current.length>e&&n.current.shift(),r.current=[],o.current=d,a(g=>g+1))},[t,e]),f=l.useCallback(()=>{var g,b,E,C;const d=n.current.pop();d&&(r.current.push({nodes:s().nodesRef.current.map(S=>({...S,data:{...S.data}})),edges:s().edgesRef.current.map(S=>({...S}))}),(b=(g=s().onNodesChangeRef).current)==null||b.call(g,[...s().nodesRef.current.map(S=>({id:S.id,type:"remove"})),...d.nodes.map(S=>({type:"add",item:S}))]),(C=(E=s().onEdgesChangeRef).current)==null||C.call(E,[...s().edgesRef.current.map(S=>({id:S.id,type:"remove"})),...d.edges.map(S=>({type:"add",item:S}))]),o.current=d,a(S=>S+1))},[s]),m=l.useCallback(()=>{var g,b,E,C;const d=r.current.pop();d&&(n.current.push({nodes:s().nodesRef.current.map(S=>({...S,data:{...S.data}})),edges:s().edgesRef.current.map(S=>({...S}))}),(b=(g=s().onNodesChangeRef).current)==null||b.call(g,[...s().nodesRef.current.map(S=>({id:S.id,type:"remove"})),...d.nodes.map(S=>({type:"add",item:S}))]),(C=(E=s().onEdgesChangeRef).current)==null||C.call(E,[...s().edgesRef.current.map(S=>({id:S.id,type:"remove"})),...d.edges.map(S=>({type:"add",item:S}))]),o.current=d,a(S=>S+1))},[s]);return{undo:f,redo:m,takeSnapshot:c,canUndo:n.current.length>0,canRedo:r.current.length>0}}function ss(e){const t=l.useRef(e);return l.useEffect(()=>{t.current=e},[e]),l.useCallback(n=>r=>{const a=t.current(r);a!==!1&&a!=null&&n(Array.isArray(a)?a:r)},[])}function as(e){const t=l.useRef(e);return l.useEffect(()=>{t.current=e},[e]),l.useCallback(n=>r=>{const a=t.current(r);a!==!1&&a!=null&&n(Array.isArray(a)?a:r)},[])}const Un=160,qn=60;function is({width:e=200,height:t=150,nodeColor:n="#3b82f6",nodeStrokeColor:r="#fff",maskColor:a="rgba(0,0,0,0.1)",style:o={},className:c=""}){const f=Ne(),m=l.useRef(null),d=l.useRef(null),g=l.useCallback(()=>{const b=m.current;if(!b)return;const E=b.getContext("2d"),C=window.devicePixelRatio||1;b.width=e*C,b.height=t*C,E.scale(C,C),E.clearRect(0,0,e,t);const S=f.nodesRef.current;if(!S.length)return;let j=1/0,L=1/0,A=-1/0,Y=-1/0;for(const y of S){const v=y.width||Un,z=y.height||qn;y.position.x<j&&(j=y.position.x),y.position.y<L&&(L=y.position.y),y.position.x+v>A&&(A=y.position.x+v),y.position.y+z>Y&&(Y=y.position.y+z)}const D=40;j-=D,L-=D,A+=D,Y+=D;const F=A-j,$=Y-L,N=Math.min(e/F,t/$),O=(e-F*N)/2,X=(t-$*N)/2;for(const y of S){if(y.hidden)continue;const v=y.width||Un,z=y.height||qn,P=(y.position.x-j)*N+O,B=(y.position.y-L)*N+X,G=v*N,ne=z*N;E.fillStyle=y.selected?"#f59e0b":typeof n=="function"?n(y):n,E.fillRect(P,B,Math.max(G,2),Math.max(ne,2))}const H=f.cameraRef.current,w=f.wrapRef.current;if(w){const y=w.getBoundingClientRect(),v=-H.x/H.zoom,z=-H.y/H.zoom,P=y.width/H.zoom,B=y.height/H.zoom;E.fillStyle=a,E.fillRect(0,0,e,t);const G=(v-j)*N+O,ne=(z-L)*N+X,ee=P*N,se=B*N;E.clearRect(G,ne,ee,se);for(const he of S){if(he.hidden)continue;const ge=he.width||Un,de=he.height||qn,Re=(he.position.x-j)*N+O,We=(he.position.y-L)*N+X;E.fillStyle=he.selected?"#f59e0b":typeof n=="function"?n(he):n,E.fillRect(Re,We,Math.max(ge*N,2),Math.max(de*N,2))}E.strokeStyle="#3b82f6",E.lineWidth=1.5,E.strokeRect(G,ne,ee,se)}},[f,e,t,n,r,a]);return l.useEffect(()=>{let b=!0;function E(){b&&(g(),d.current=requestAnimationFrame(E))}const C=setInterval(()=>{cancelAnimationFrame(d.current),d.current=requestAnimationFrame(E)},66);return g(),()=>{b=!1,clearInterval(C),cancelAnimationFrame(d.current)}},[g]),T.jsx("canvas",{ref:m,className:`ric-minimap ${c}`,style:{position:"absolute",bottom:30,right:10,width:e,height:t,borderRadius:4,border:"1px solid rgba(0,0,0,0.1)",background:"rgba(255,255,255,0.9)",pointerEvents:"none",...o}})}function cs(){return T.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[T.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),T.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function ls(){return T.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:T.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function us(){return T.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:T.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}function ds(){return T.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[T.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),T.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function fs(){return T.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[T.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),T.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})}function rn({children:e,className:t="",...n}){return T.jsx("button",{className:`ric-controls-button ${t}`,style:gs,...n,children:e})}function hs({showZoom:e=!0,showFitView:t=!0,showInteractive:n=!1,fitViewOptions:r,onZoomIn:a,onZoomOut:o,onFitView:c,onInteractiveChange:f,position:m="bottom-left",orientation:d="vertical",style:g={},className:b="","aria-label":E="Canvas controls",children:C}){const S=Ne(),{zoomIn:j,zoomOut:L,fitView:A,getZoom:Y}=Hr(),[D,F]=l.useState(!0),$=Y()<=S.zoomMin,N=Y()>=S.zoomMax,O=l.useCallback(()=>{j(),a==null||a()},[j,a]),X=l.useCallback(()=>{L(),o==null||o()},[L,o]),H=l.useCallback(()=>{A(r||{padding:.1}),c==null||c()},[A,r,c]),w=l.useCallback(()=>{const v=!D;F(v),f==null||f(v)},[D,f]),y={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:30,left:10},"bottom-right":{bottom:30,right:10},"bottom-center":{bottom:30,left:"50%",transform:"translateX(-50%)"}}[m]||{bottom:30,left:10};return T.jsxs("div",{className:`ric-controls ${b}`,style:{position:"absolute",display:"flex",flexDirection:d==="horizontal"?"row":"column",gap:2,zIndex:5,...y,...g},role:"toolbar","aria-label":E,children:[e&&T.jsxs(T.Fragment,{children:[T.jsx(rn,{onClick:O,disabled:N,title:"Zoom in","aria-label":"Zoom in",className:"ric-controls-zoomin",children:T.jsx(cs,{})}),T.jsx(rn,{onClick:X,disabled:$,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:T.jsx(ls,{})})]}),t&&T.jsx(rn,{onClick:H,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:T.jsx(us,{})}),n&&T.jsx(rn,{onClick:w,title:D?"Lock interactivity":"Unlock interactivity","aria-label":D?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:D?T.jsx(fs,{}):T.jsx(ds,{})}),C]})}const gs={width:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid rgba(0,0,0,0.12)",borderRadius:4,background:"#fff",cursor:"pointer",fontSize:16,lineHeight:1,color:"#333",padding:0},ys=l.memo(hs);function xs({variant:e="lines",gap:t=40,size:n=1,color:r,style:a={},className:o=""}){const c=Ne();return c.workerRef.current&&c.workerRef.current.postMessage({type:"background",data:{variant:e,gap:t,size:n,color:r}}),null}function ps({position:e="top-left",style:t={},className:n="",children:r}){const a={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:10,left:10},"bottom-right":{bottom:10,right:10},"bottom-center":{bottom:10,left:"50%",transform:"translateX(-50%)"}}[e]||{top:10,left:10};return T.jsx("div",{className:`ric-panel ${n}`,style:{position:"absolute",zIndex:5,pointerEvents:"all",...a,...t},onPointerDown:o=>o.stopPropagation(),children:r})}function ms({minWidth:e=10,minHeight:t=10,maxWidth:n=1/0,maxHeight:r=1/0,isVisible:a=!0,handleStyle:o={},lineStyle:c={},color:f="#3b82f6",onResizeStart:m,onResize:d,onResizeEnd:g}){const b=l.useContext(sn),E=Ne(),C=l.useRef(null),S=l.useCallback((A,Y)=>{A.stopPropagation(),A.preventDefault();const D=E.nodesRef.current.find(N=>N.id===b);if(!D)return;C.current={direction:Y,startX:A.clientX,startY:A.clientY,width:D.width||160,height:D.height||60},m==null||m(A,{width:C.current.width,height:C.current.height});const F=N=>{var z,P;if(!C.current)return;const O=C.current,X=E.cameraRef.current,H=(N.clientX-O.startX)/X.zoom,w=(N.clientY-O.startY)/X.zoom;let y=O.width,v=O.height;O.direction.includes("e")&&(y=Math.min(n,Math.max(e,O.width+H))),O.direction.includes("w")&&(y=Math.min(n,Math.max(e,O.width-H))),O.direction.includes("s")&&(v=Math.min(r,Math.max(t,O.height+w))),O.direction.includes("n")&&(v=Math.min(r,Math.max(t,O.height-w))),(P=(z=E.onNodesChangeRef).current)==null||P.call(z,[{id:b,type:"dimensions",dimensions:{width:y,height:v},setAttributes:!0}]),d==null||d(N,{width:y,height:v})},$=N=>{C.current=null,g==null||g(N,{}),window.removeEventListener("pointermove",F),window.removeEventListener("pointerup",$)};window.addEventListener("pointermove",F),window.addEventListener("pointerup",$)},[b,E,e,t,n,r,m,d,g]);if(!a)return null;const j=8,L={position:"absolute",width:j,height:j,background:f,border:"1px solid #fff",borderRadius:2,zIndex:20,...o};return T.jsxs(T.Fragment,{children:[T.jsx("div",{style:{...L,bottom:-j/2,right:-j/2,cursor:"nwse-resize"},onPointerDown:A=>S(A,"se")}),T.jsx("div",{style:{...L,bottom:-j/2,left:-j/2,cursor:"nesw-resize"},onPointerDown:A=>S(A,"sw")}),T.jsx("div",{style:{...L,top:-j/2,right:-j/2,cursor:"nesw-resize"},onPointerDown:A=>S(A,"ne")}),T.jsx("div",{style:{...L,top:-j/2,left:-j/2,cursor:"nwse-resize"},onPointerDown:A=>S(A,"nw")}),T.jsx("div",{style:{...L,top:"50%",right:-j/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:A=>S(A,"e")}),T.jsx("div",{style:{...L,top:"50%",left:-j/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:A=>S(A,"w")}),T.jsx("div",{style:{...L,left:"50%",top:-j/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:A=>S(A,"n")}),T.jsx("div",{style:{...L,left:"50%",bottom:-j/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:A=>S(A,"s")})]})}function vs({isVisible:e,position:t="top",offset:n=10,align:r="center",children:a,style:o={},className:c=""}){const f=l.useContext(sn),d=Ne().nodes.find(E=>E.id===f);if(!(e!==void 0?e:d==null?void 0:d.selected))return null;const b={top:{bottom:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginBottom:n},bottom:{top:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginTop:n},left:{right:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginRight:n},right:{left:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginLeft:n}}[t]||{};return T.jsx("div",{className:`ric-node-toolbar ${c}`,style:{position:"absolute",zIndex:1e3,pointerEvents:"all",...b,...o},onPointerDown:E=>E.stopPropagation(),children:a})}function bs({isVisible:e=!1,x:t=0,y:n=0,alignX:r="center",alignY:a="center",children:o,style:c={},className:f=""}){if(!e)return null;const m=r==="center"?"-50%":r==="right"?"-100%":"0",d=a==="center"?"-50%":a==="bottom"?"-100%":"0";return T.jsx("div",{className:`ric-edge-toolbar ${f}`,style:{position:"absolute",left:t,top:n,transform:`translate(${m}, ${d})`,zIndex:1e3,pointerEvents:"all",...c},children:o})}function ws({children:e}){var r;const n=(r=Ne().edgeLabelContainerRef)==null?void 0:r.current;return n?pr.createPortal(e,n):null}function Ms({children:e}){var r;const n=(r=Ne().viewportPortalRef)==null?void 0:r.current;return n?pr.createPortal(e,n):null}function _r({fromX:e,fromY:t,toX:n,toY:r,fromPosition:a="right",toPosition:o="left",connectionLineType:c="default",connectionLineStyle:f,connectionLineComponent:m}){if(m)return T.jsx(m,{fromX:e,fromY:t,toX:n,toY:r,fromPosition:a,toPosition:o});let d;switch(c){case"straight":[d]=tr({sourceX:e,sourceY:t,targetX:n,targetY:r});break;case"step":[d]=kn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o,borderRadius:0});break;case"smoothstep":[d]=kn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o});break;case"simplebezier":[d]=rr({sourceX:e,sourceY:t,targetX:n,targetY:r});break;default:[d]=nr({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o});break}return T.jsx("path",{d,fill:"none",className:"ric-connection-line",stroke:"#b1b1b7",strokeWidth:1.5,style:f})}_r.displayName="ConnectionLine";const Rs=l.memo(_r),ks=Object.freeze({Top:"top",Bottom:"bottom",Left:"left",Right:"right"}),Cs=Object.freeze({Arrow:"arrow",ArrowClosed:"arrowclosed"});function Es(e){const t=e.width||e.measured&&e.measured.width||0,n=e.height||e.measured&&e.measured.height||0,r=e._absolutePosition||e.position||{x:0,y:0};return{x:r.x,y:r.y,x2:r.x+t,y2:r.y+n}}exports.Background=xs;exports.BaseEdge=an;exports.BezierEdge=er;exports.ConnectionLine=Rs;exports.ControlButton=rn;exports.Controls=ys;exports.DefaultNode=vo;exports.EdgeLabelRenderer=ws;exports.EdgeText=Lr;exports.EdgeToolbar=bs;exports.GroupNode=Ir;exports.Handle=on;exports.InfiniteCanvas=jo;exports.InfiniteCanvasProvider=Ao;exports.InputNode=Nr;exports.MarkerType=Cs;exports.MiniMap=is;exports.NodeResizer=ms;exports.NodeToolbar=vs;exports.OutputNode=Pr;exports.Panel=ps;exports.Position=ks;exports.SelectionBox=Sr;exports.SimpleBezierEdge=ir;exports.SmoothStepEdge=ar;exports.StepEdge=$r;exports.StraightEdge=sr;exports.ViewportPortal=Ms;exports.addEdge=Ho;exports.applyEdgeChanges=Dr;exports.applyNodeChanges=Ar;exports.boxToRect=Qr;exports.buildObstacles=or;exports.clampPosition=Gn;exports.computeRoutedEdges=No;exports.getBezierEdgeCenter=bo;exports.getBezierPath=nr;exports.getBoundsOfBoxes=Vr;exports.getConnectedEdges=br;exports.getEdgeCenter=wo;exports.getIncomers=Ur;exports.getNodeDimensions=Kn;exports.getNodesBounds=Rn;exports.getNodesInside=Zr;exports.getOutgoers=qr;exports.getOverlappingArea=Jr;exports.getRoutedLabelPosition=Pn;exports.getSimpleBezierPath=rr;exports.getSmoothStepPath=kn;exports.getStraightPath=tr;exports.getViewportForBounds=Zt;exports.isEdge=Or;exports.isNode=Xr;exports.nodeToBox=Es;exports.nodeToRect=Kr;exports.reconnectEdge=Mo;exports.rectToBox=Gr;exports.routeSinglePath=Po;exports.routedPointsToPath=Nn;exports.snapPosition=Zn;exports.useConnection=Oo;exports.useEdges=Yo;exports.useEdgesState=Wo;exports.useHandleConnections=Zo;exports.useInfiniteCanvas=Mr;exports.useInternalNode=ts;exports.useKeyPress=Vo;exports.useNodeConnections=qo;exports.useNodeId=co;exports.useNodes=Fo;exports.useNodesData=Uo;exports.useNodesInitialized=es;exports.useNodesState=_o;exports.useOnEdgesChangeMiddleware=as;exports.useOnNodesChangeMiddleware=ss;exports.useOnSelectionChange=Qo;exports.useOnViewportChange=Go;exports.useReactFlow=Hr;exports.useStore=ns;exports.useStoreApi=rs;exports.useUndoRedo=os;exports.useUpdateNodeInternals=Jo;exports.useViewport=Xo;
939
+ `,lr=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",wr],{type:"text/javascript;charset=utf-8"});function eo(e){let t;try{if(t=lr&&(self.URL||self.webkitURL).createObjectURL(lr),!t)throw"";const n=new Worker(t,{type:"module",name:e==null?void 0:e.name});return n.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),n}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(wr),{type:"module",name:e==null?void 0:e.name})}}const Xn=new WeakMap;function to(e,t){if(Xn.has(e))return Xn.get(e);const n=e.transferControlToOffscreen(),r=new eo;r.onerror=o=>console.error("[infinite-canvas] worker error:",o.message,o),r.postMessage({type:"init",data:{...t,canvas:n}},[n]);const i={worker:r};return Xn.set(e,i),i}const ft=160,nt=60,no=10;function Mr({cards:e=[],nodes:t=[],edges:n=[],onHudUpdate:r,onNodesProcessed:i,onNodesChange:o,onEdgesChange:a,onConnect:f,onNodeClick:p,onNodeDragStart:d,onNodeDrag:h,onNodeDragStop:k,onEdgeClick:S,onEdgeDoubleClick:E,onEdgeMouseEnter:z,onEdgeMouseMove:j,onEdgeMouseLeave:L,onEdgeContextMenu:A,onNodeDoubleClick:X,onNodeMouseEnter:D,onNodeMouseMove:Y,onNodeMouseLeave:$,onNodeContextMenu:I,onPaneClick:q,onPaneContextMenu:O,onPaneMouseEnter:H,onPaneMouseMove:C,onPaneMouseLeave:y,onSelectionChange:v,onConnectStart:N,onConnectEnd:P,onInit:B,onMoveStart:J,onMove:oe,onMoveEnd:te,onDelete:se,onBeforeDelete:he,onError:ge,isValidConnection:fe,dark:ie,gridSize:Me=40,zoomMin:ne=.1,zoomMax:le=4,initialCamera:Ee={x:0,y:0,zoom:1},fitView:et=!1,fitViewOptions:ye,nodesDraggable:Re=!0,nodesConnectable:$e=!0,elementsSelectable:We=!0,multiSelectionKeyCode:Se="Shift",selectionOnDrag:tt=!1,selectionMode:rt="partial",connectionMode:we="loose",connectionRadius:Te=20,connectOnClick:Oe=!1,snapToGrid:je=!1,snapGrid:Fe=[15,15],deleteKeyCode:Ze=["Delete","Backspace"],panActivationKeyCode:Et=" ",panOnScroll:an=!1,panOnScrollMode:St="free",panOnScrollSpeed:cn=.5,zoomOnScroll:ln=!0,zoomOnDoubleClick:un=!0,zoomOnPinch:dn=!0,preventScrolling:Zt=!0,translateExtent:xt,nodeExtent:pt,defaultEdgeOptions:zt={},autoPanOnNodeDrag:Pn=!0,autoPanOnConnect:Tn=!0,autoPanSpeed:ot=5,edgesReconnectable:cr=!1,elevateNodesOnSelect:Ln=!1,elevateEdgesOnSelect:Bn=!1,noDragClassName:Nt="nodrag",noPanClassName:It="nopan",onSelectionDragStart:$n,onSelectionDrag:jn,onSelectionDragStop:An,edgeRouting:wt=!0}={}){const me=c.useRef(null),Pt=c.useRef(null),Le=c.useRef(null),ue=c.useRef({...Ee}),mt=c.useRef([...e]),K=c.useRef([...t]),ze=c.useRef([...n]),fn=c.useRef(new Map),Tt=c.useRef(!1),Lt=c.useRef(null),[Bt,Dn]=c.useState(!1),Ye=c.useRef(null),Ue=c.useRef(null),$t=c.useRef(null),st=c.useRef(null),hn=c.useRef(!1),Je=c.useRef(null),[gn,yn]=c.useState({x:Ee.x,y:Ee.y,zoom:Ee.zoom}),[Gt,xn]=c.useState(null),vt=c.useMemo(()=>new Set,[]),it=c.useMemo(()=>new Set,[]),Ke=c.useRef(!1),Z=c.useRef({});Z.current={onHudUpdate:r,onNodesProcessed:i,onNodesChange:o,onEdgesChange:a,onConnect:f,onNodeClick:p,onNodeDragStart:d,onNodeDrag:h,onNodeDragStop:k,onEdgeClick:S,onEdgeDoubleClick:E,onEdgeMouseEnter:z,onEdgeMouseMove:j,onEdgeMouseLeave:L,onEdgeContextMenu:A,onNodeDoubleClick:X,onNodeMouseEnter:D,onNodeMouseMove:Y,onNodeMouseLeave:$,onNodeContextMenu:I,onPaneClick:q,onPaneContextMenu:O,onPaneMouseEnter:H,onPaneMouseMove:C,onPaneMouseLeave:y,onSelectionChange:v,onConnectStart:N,onConnectEnd:P,onInit:B,onMoveStart:J,onMove:oe,onMoveEnd:te,onDelete:se,onBeforeDelete:he,onError:ge,onSelectionDragStart:$n,onSelectionDrag:jn,onSelectionDragStop:An,isValidConnection:fe};const at={get current(){return Z.current.onConnect}},jt={get current(){return Z.current.onNodeClick}},At={get current(){return Z.current.onNodeDragStart}},Dt={get current(){return Z.current.onNodeDrag}},Ht={get current(){return Z.current.onNodeDragStop}},Ve={get current(){return Z.current.onEdgeClick}},_t={get current(){return Z.current.onPaneClick}},Wt={get current(){return Z.current.onSelectionChange}},Ft={get current(){return Z.current.onHudUpdate}},Yt={get current(){return Z.current.onNodesProcessed}};c.useEffect(()=>{const u=l=>{l.key===Se&&(hn.current=!0),l.key===Et&&(Ke.current=!0)},b=l=>{l.key===Se&&(hn.current=!1),l.key===Et&&(Ke.current=!1)};return window.addEventListener("keydown",u),window.addEventListener("keyup",b),()=>{window.removeEventListener("keydown",u),window.removeEventListener("keyup",b)}},[Se,Et]);const ke={get current(){return Z.current.onNodesChange?ht:null}},ht=u=>{var l,x,w;(x=(l=Z.current).onNodesChange)==null||x.call(l,u);const b=[];for(let m=0;m<u.length;m++)u[m].type==="select"&&b.push({id:u[m].id,selected:u[m].selected});b.length>0&&((w=Le.current)==null||w.postMessage({type:"nodeSelections",data:{selections:b}}))},_e={get current(){return Z.current.onEdgesChange?Hn:null}},Hn=u=>{var l,x,w;(x=(l=Z.current).onEdgesChange)==null||x.call(l,u);const b=[];for(let m=0;m<u.length;m++)u[m].type==="select"&&b.push({id:u[m].id,selected:u[m].selected});b.length>0&&((w=Le.current)==null||w.postMessage({type:"edgeSelections",data:{selections:b}}))},gt=c.useCallback(()=>{var x;const u=K.current.filter(w=>w.selected),b=ze.current.filter(w=>w.selected),l={nodes:u,edges:b};(x=Wt.current)==null||x.call(Wt,l);for(const w of it)w(l)},[it]);c.useEffect(()=>{var u;mt.current=[...e],(u=Le.current)==null||u.postMessage({type:"cards",data:{cards:[...e]}})},[e]);const Xt=c.useCallback(u=>{const b={};for(const l of u)b[l.id]=l;return u.map(l=>{if(!l.parentId)return l;const x=b[l.parentId];if(!x)return l;let w=l.position.x,m=l.position.y,g=x;for(;g;)w+=g.position.x,m+=g.position.y,g=g.parentId?b[g.parentId]:null;return{...l,_absolutePosition:{x:w,y:m}}})},[]),ct=c.useRef([]),bt=c.useCallback(u=>{const b=fn.current;if(!b||b.size===0)return u;const l={};for(const[,x]of b)l[x.nodeId]||(l[x.nodeId]=[]),l[x.nodeId].push({id:x.id,type:x.type,position:x.position,x:x.x,y:x.y});return u.map(x=>{const w=l[x.id];return w&&w.length>0?{...x,handles:w}:x})},[]),pn=c.useCallback(()=>{var b;if(Ye.current)return;const u=bt(ct.current);(b=Le.current)==null||b.postMessage({type:"nodes",data:{nodes:u}})},[bt]);c.useEffect(()=>{var l,x;if(Ye.current){const w=Ye.current.id,m=new Set([w,...Ye.current.selectedStarts.map(M=>M.id)]),g={};for(const M of K.current)m.has(M.id)&&(g[M.id]={...M.position});K.current=[...t];for(const M of K.current)g[M.id]&&(M.position=g[M.id]);ct.current=Xt(K.current);const R=bt(ct.current);(l=Le.current)==null||l.postMessage({type:"nodes",data:{nodes:R}});return}K.current=[...t];const u=Xt(t);ct.current=u;const b=bt(u);(x=Le.current)==null||x.postMessage({type:"nodes",data:{nodes:b}})},[t,Xt,bt]),c.useEffect(()=>{var u;ze.current=[...n],(u=Le.current)==null||u.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const Be=c.useCallback((u,b)=>{const l=me.current;if(!l)return{x:0,y:0};const x=l.getBoundingClientRect(),w=ue.current;return{x:(u-x.left-w.x)/w.zoom,y:(b-x.top-w.y)/w.zoom}},[]),ae=c.useCallback((u,b)=>{const l=ct.current.length>0?ct.current:K.current;let x=null;for(let w=l.length-1;w>=0;w--){const m=l[w];if(m.hidden||m._customRendered)continue;const g=m._absolutePosition||m.position,R=m.width||ft,M=m.height||nt;if(u>=g.x&&u<=g.x+R&&b>=g.y&&b<=g.y+M){if(m.type==="group"){x||(x=m);continue}return m}}return x},[]),Ot=c.useCallback((u,b)=>{const l=b.width||ft,x=b.height||nt;if(u.x!==void 0&&u.y!==void 0)return{x:b.position.x+u.x,y:b.position.y+u.y};switch(u.position||(u.type==="source"?"right":"left")){case"top":return{x:b.position.x+l/2,y:b.position.y};case"bottom":return{x:b.position.x+l/2,y:b.position.y+x};case"left":return{x:b.position.x,y:b.position.y+x/2};case"right":return{x:b.position.x+l,y:b.position.y+x/2};default:return{x:b.position.x+l,y:b.position.y+x/2}}},[]),Mt=c.useCallback(u=>{const b=u.width||ft,l=u.height||nt;if(u.handles&&u.handles.length>0)return u.handles.map(M=>{const F=Ot(M,u);return{id:M.id||null,type:M.type,x:F.x,y:F.y}});const x=u.targetPosition||"left",w=u.sourcePosition||"right",m=M=>{switch(M){case"top":return{x:u.position.x+b/2,y:u.position.y};case"bottom":return{x:u.position.x+b/2,y:u.position.y+l};case"left":return{x:u.position.x,y:u.position.y+l/2};case"right":return{x:u.position.x+b,y:u.position.y+l/2};default:return{x:u.position.x+b,y:u.position.y+l/2}}},g=m(x),R=m(w);return[{id:null,type:"target",x:g.x,y:g.y},{id:null,type:"source",x:R.x,y:R.y}]},[Ot]),Rt=c.useCallback((u,b)=>{const l=K.current,x=ue.current,w=Math.max(no,Te)/x.zoom;for(let m=l.length-1;m>=0;m--){const g=l[m];if(g.hidden)continue;const R=Mt(g);for(const M of R)if(Math.abs(u-M.x)<w&&Math.abs(b-M.y)<w)return{nodeId:g.id,handleId:M.id,type:M.type,x:M.x,y:M.y}}return null},[Mt]),lt=c.useCallback((u,b)=>{const x=8/ue.current.zoom,w=K.current,m={};for(let g=0;g<w.length;g++)m[w[g].id]=w[g];for(let g=ze.current.length-1;g>=0;g--){const R=ze.current[g],M=m[R.source],F=m[R.target];if(!M||!F)continue;const _=M.width||ft,U=M.height||nt,Q=F.height||nt,be=M.position.x+_,Ae=M.position.y+U/2,ee=F.position.x,ce=F.position.y+Q/2;if(ro(u,b,be,Ae,ee,ce)<x)return R}return null},[]);c.useEffect(()=>{const u=Pt.current,b=me.current;if(!u||!b)return;const l=b.getBoundingClientRect(),x=ie!==void 0?ie:matchMedia("(prefers-color-scheme: dark)").matches,w=Xt(K.current);ct.current=w;const m=bt(w),{worker:g}=to(u,{width:l.width,height:l.height,camera:ue.current,cards:mt.current,nodes:m,edges:ze.current,dark:x,gridSize:Me,edgeRouting:wt});g.onmessage=_=>{var U,Q,be,Ae;_.data.type==="hud"&&((U=Ft.current)==null||U.call(Ft,_.data.data)),_.data.type==="ready"&&Dn(!0),_.data.type==="nodesProcessed"&&((Q=Yt.current)==null||Q.call(Yt,_.data.data)),_.data.type==="error"&&((Ae=(be=Z.current).onError)==null||Ae.call(be,"worker-error",_.data.message||"Canvas worker error"))},g.onerror=_=>{var U,Q;(Q=(U=Z.current).onError)==null||Q.call(U,"worker-error",_.message||"Canvas worker crashed")},Le.current=g;const R=new ResizeObserver(_=>{const{width:U,height:Q}=_[0].contentRect;g.postMessage({type:"resize",data:{width:U,height:Q}})});R.observe(b);let M,F;return ie===void 0&&(M=matchMedia("(prefers-color-scheme: dark)"),F=_=>g.postMessage({type:"theme",data:{dark:_.matches}}),M.addEventListener("change",F)),()=>{R.disconnect(),M&&F&&M.removeEventListener("change",F),Le.current=null}},[]),c.useEffect(()=>{var u;ie!==void 0&&((u=Le.current)==null||u.postMessage({type:"theme",data:{dark:ie}}))},[ie]),c.useEffect(()=>{var u;(u=Le.current)==null||u.postMessage({type:"edgeRouting",data:{enabled:wt}})},[wt]);const Ut=c.useRef(0),ve=c.useCallback((u=null)=>{var x,w,m;const b=ue.current;if(xt){const g=me.current;if(g){const R=g.getBoundingClientRect(),M=-xt[1][0]*b.zoom+R.width,F=-xt[1][1]*b.zoom+R.height,_=-xt[0][0]*b.zoom,U=-xt[0][1]*b.zoom;b.x=Math.min(_,Math.max(M,b.x)),b.y=Math.min(U,Math.max(F,b.y))}}(x=Le.current)==null||x.postMessage({type:"camera",data:{camera:{...b}}});const l={x:b.x,y:b.y,zoom:b.zoom};(m=(w=Z.current).onMove)==null||m.call(w,u,l);for(const g of vt)g(l);cancelAnimationFrame(Ut.current),Ut.current=requestAnimationFrame(()=>{yn({x:b.x,y:b.y,zoom:b.zoom})})},[vt,xt]),ut=c.useCallback(()=>{var l,x;const u=Ue.current,b=$t.current;u&&b?((l=Le.current)==null||l.postMessage({type:"connecting",data:{from:u.startPos,to:b,_routedPoints:null}}),xn({source:u.sourceId,sourceHandle:u.sourceHandle,target:null,targetHandle:null})):((x=Le.current)==null||x.postMessage({type:"connecting",data:null}),xn(null))},[]),dt=c.useCallback(()=>{var b,l;const u=st.current;u?(b=Le.current)==null||b.postMessage({type:"selectionBox",data:u}):(l=Le.current)==null||l.postMessage({type:"selectionBox",data:null})},[]),mn=c.useCallback(u=>{var g,R,M,F,_,U,Q,be,Ae,ee,ce,Ce,De,Xe,Ge,qe,Jt,yt;const b=K.current.length>0,l=Be(u.clientX,u.clientY),x=hn.current;if(b&&$e&&!x){const G=Rt(l.x,l.y);if(Oe&&Je.current&&G){const re=Je.current;if(G.nodeId!==re.nodeId){const Qe=re.handleType==="target"?{source:G.nodeId,target:re.nodeId,sourceHandle:G.handleId||null,targetHandle:re.handleId}:{source:re.nodeId,target:G.nodeId,sourceHandle:re.handleId,targetHandle:G.handleId||null};(Z.current.isValidConnection?Z.current.isValidConnection(Qe):!0)&&((g=at.current)==null||g.call(at,{...Qe,...zt}))}Je.current=null;return}if(we==="strict"?G&&G.type==="source":G!=null){if(Oe){Je.current={nodeId:G.nodeId,handleId:G.handleId||null,handleType:G.type},(M=(R=Z.current).onConnectStart)==null||M.call(R,u,{nodeId:G.nodeId,handleId:G.handleId,handleType:G.type});return}Ue.current={sourceId:G.nodeId,sourceHandle:G.handleId||null,sourceType:G.type,startPos:{x:G.x,y:G.y}},$t.current={x:l.x,y:l.y},(F=me.current)==null||F.setPointerCapture(u.pointerId),(U=(_=Z.current).onConnectStart)==null||U.call(_,u,{nodeId:G.nodeId,handleId:G.handleId,handleType:G.type}),ut();return}}const w=G=>{var re;let pe=G;for(;pe&&pe!==me.current;){if((re=pe.classList)!=null&&re.contains(Nt))return!0;pe=pe.parentElement}return!1},m=G=>{var re;let pe=G;for(;pe&&pe!==me.current;){if((re=pe.classList)!=null&&re.contains(It))return!0;pe=pe.parentElement}return!1};if(b){const G=ae(l.x,l.y);if(G){if(ke.current&&We){const pe=[];if(x)pe.push({id:G.id,type:"select",selected:!G.selected});else if(!G.selected){for(const re of K.current)re.id===G.id?pe.push({id:re.id,type:"select",selected:!0}):re.selected&&pe.push({id:re.id,type:"select",selected:!1});if(_e.current){const re=ze.current.filter(de=>de.selected).map(de=>({id:de.id,type:"select",selected:!1}));re.length&&_e.current(re)}}if(pe.length){if(ke.current(pe),Ln&&!x){const re=K.current.findIndex(de=>de.id===G.id);re>=0&&re<K.current.length-1&&ke.current([{id:G.id,type:"remove"},{type:"add",item:{...K.current[re],selected:!0}}])}gt()}}if((Q=jt.current)==null||Q.call(jt,u,G),Re&&!w(u.target)){const pe=G.selected;let re=null;if(G.parentId&&G.extent==="parent"){const de=K.current.find(Qe=>Qe.id===G.parentId);if(de){const Qe=de.width||ft,Kt=de.height||nt,bn=G.width||((be=G.measured)==null?void 0:be.width)||ft,Vt=G.height||((Ae=G.measured)==null?void 0:Ae.height)||nt;re={minX:0,minY:0,maxX:Qe-bn,maxY:Kt-Vt}}}if(Ye.current={id:G.id,startPos:{...G.position},startMouse:{x:l.x,y:l.y},parentClamp:re,parentId:G.parentId||null,selectedStarts:pe?K.current.filter(de=>de.selected&&de.id!==G.id).map(de=>{var Kt,bn;let Qe=null;if(de.parentId&&de.extent==="parent"){const Vt=K.current.find(Yn=>Yn.id===de.parentId);if(Vt){const Yn=Vt.width||ft,Wr=Vt.height||nt,Fr=de.width||((Kt=de.measured)==null?void 0:Kt.width)||ft,Yr=de.height||((bn=de.measured)==null?void 0:bn.height)||nt;Qe={minX:0,minY:0,maxX:Yn-Fr,maxY:Wr-Yr}}}return{id:de.id,startPos:{...de.position},parentClamp:Qe,parentId:de.parentId||null}}):[]},(ee=me.current)==null||ee.setPointerCapture(u.pointerId),(ce=At.current)==null||ce.call(At,u,G),Ye.current.selectedStarts.length>0){const de=K.current.filter(Qe=>Qe.selected);(De=(Ce=Z.current).onSelectionDragStart)==null||De.call(Ce,u,de)}if(ke.current){const de=[{id:G.id,type:"position",dragging:!0}];for(const Qe of Ye.current.selectedStarts)de.push({id:Qe.id,type:"position",dragging:!0});ke.current(de)}}return}}if(ze.current.length>0&&We){const G=lt(l.x,l.y);if(G){if(_e.current){const pe=[];if(x)pe.push({id:G.id,type:"select",selected:!G.selected});else{for(const re of ze.current)re.id===G.id?pe.push({id:re.id,type:"select",selected:!0}):re.selected&&pe.push({id:re.id,type:"select",selected:!1});if(ke.current){const re=K.current.filter(de=>de.selected).map(de=>({id:de.id,type:"select",selected:!1}));re.length&&ke.current(re)}}if(pe.length){if(_e.current(pe),Bn&&!x){const re=ze.current.findIndex(de=>de.id===G.id);re>=0&&re<ze.current.length-1&&_e.current([{id:G.id,type:"remove"},{type:"add",item:{...ze.current[re],selected:!0}}])}gt()}}(Xe=Ve.current)==null||Xe.call(Ve,u,G);return}}if(!x){const G=K.current.filter(re=>re.selected).map(re=>({id:re.id,type:"select",selected:!1})),pe=ze.current.filter(re=>re.selected).map(re=>({id:re.id,type:"select",selected:!1}));G.length&&ke.current&&ke.current(G),pe.length&&_e.current&&_e.current(pe),(G.length||pe.length)&&gt()}if((Ge=_t.current)==null||Ge.call(_t,u),tt||x){st.current={startWorld:{...l},endWorld:{...l}},(qe=me.current)==null||qe.setPointerCapture(u.pointerId),dt();return}m(u.target)||(Tt.current=!0,Lt.current={x:u.clientX,y:u.clientY},(Jt=me.current)==null||Jt.classList.add("dragging"),(yt=me.current)==null||yt.setPointerCapture(u.pointerId))},[Be,ae,Rt,lt,Re,$e,We,tt,ut,dt,gt,Nt,It]),Qt=c.useCallback(u=>{var l,x,w,m;if(Ue.current){if($t.current=Be(u.clientX,u.clientY),ut(),Tn){const g=me.current;if(g){const R=g.getBoundingClientRect(),M=40,F=u.clientX-R.left,_=u.clientY-R.top;let U=0,Q=0;F<M?U=ot:F>R.width-M&&(U=-ot),_<M?Q=ot:_>R.height-M&&(Q=-ot),(U||Q)&&(ue.current.x+=U,ue.current.y+=Q,ve(u))}}return}if(st.current){st.current.endWorld=Be(u.clientX,u.clientY),dt();const g=st.current,R=Math.min(g.startWorld.x,g.endWorld.x),M=Math.min(g.startWorld.y,g.endWorld.y),F=Math.max(g.startWorld.x,g.endWorld.x),_=Math.max(g.startWorld.y,g.endWorld.y);if(ke.current){const U=[];for(const Q of K.current){if(Q.hidden)continue;const be=Q.width||ft,Ae=Q.height||nt,ee=rt==="full"?Q.position.x>=R&&Q.position.x+be<=F&&Q.position.y>=M&&Q.position.y+Ae<=_:Q.position.x+be>R&&Q.position.x<F&&Q.position.y+Ae>M&&Q.position.y<_;ee!==!!Q.selected&&U.push({id:Q.id,type:"select",selected:ee})}U.length&&ke.current(U)}return}if(Ye.current){const g=Be(u.clientX,u.clientY),R=Ye.current,M=g.x-R.startMouse.x,F=g.y-R.startMouse.y;let _={x:R.startPos.x+M,y:R.startPos.y+F};if(je&&(_=Zn(_,Fe)),pt&&(_=Gn(_,pt)),R.parentClamp){const ee=R.parentClamp;_={x:Math.max(ee.minX,Math.min(_.x,ee.maxX)),y:Math.max(ee.minY,Math.min(_.y,ee.maxY))}}const U=[{id:R.id,position:_}];for(const ee of R.selectedStarts){let ce={x:ee.startPos.x+M,y:ee.startPos.y+F};if(je&&(ce=Zn(ce,Fe)),pt&&(ce=Gn(ce,pt)),ee.parentClamp){const Ce=ee.parentClamp;ce={x:Math.max(Ce.minX,Math.min(ce.x,Ce.maxX)),y:Math.max(Ce.minY,Math.min(ce.y,Ce.maxY))}}U.push({id:ee.id,position:ce})}const Q=[];for(const ee of U){const ce=K.current.find(Ce=>Ce.id===ee.id);if(ce){ce.position=ee.position,ce.dragging=!0;let Ce=ee.position;if(ce.parentId){let De=K.current.find(qe=>qe.id===ce.parentId),Xe=ee.position.x,Ge=ee.position.y;for(;De;)Xe+=De.position.x,Ge+=De.position.y,De=De.parentId?K.current.find(qe=>qe.id===De.parentId):null;Ce={x:Xe,y:Ge}}Q.push({id:ee.id,position:ee.position,_absolutePosition:Ce,width:ce.width,height:ce.height,dragging:!0,selected:ce.selected})}}const be=new Set(U.map(ee=>ee.id));for(const ee of K.current)if(ee.parentId&&be.has(ee.parentId)&&!be.has(ee.id)){let ce=K.current.find(Xe=>Xe.id===ee.parentId),Ce=ee.position.x,De=ee.position.y;for(;ce;)Ce+=ce.position.x,De+=ce.position.y,ce=ce.parentId?K.current.find(Xe=>Xe.id===ce.parentId):null;Q.push({id:ee.id,position:ee.position,_absolutePosition:{x:Ce,y:De},width:ee.width,height:ee.height,dragging:!1,selected:ee.selected})}if((l=Le.current)==null||l.postMessage({type:"nodePositions",data:{updates:Q}}),Pn){const ee=me.current;if(ee){const ce=ee.getBoundingClientRect(),Ce=40,De=u.clientX-ce.left,Xe=u.clientY-ce.top;let Ge=0,qe=0;De<Ce?Ge=ot:De>ce.width-Ce&&(Ge=-ot),Xe<Ce?qe=ot:Xe>ce.height-Ce&&(qe=-ot),(Ge||qe)&&(ue.current.x+=Ge,ue.current.y+=qe,ve(u))}}const Ae=K.current.find(ee=>ee.id===R.id);if(Ae&&((x=Dt.current)==null||x.call(Dt,u,Ae)),R.selectedStarts.length>0){const ee=K.current.filter(ce=>ce.selected);(m=(w=Z.current).onSelectionDrag)==null||m.call(w,u,ee)}return}if(!Tt.current)return;const b=ue.current;b.x+=u.clientX-Lt.current.x,b.y+=u.clientY-Lt.current.y,Lt.current={x:u.clientX,y:u.clientY},ve()},[ve,Be,ut,dt]),_n=c.useCallback(u=>{var b,l,x,w,m,g,R;if(Ue.current){const M=Be(u.clientX,u.clientY),F=Rt(M.x,M.y);if(F&&F.nodeId!==Ue.current.sourceId&&(we==="loose"||F.type==="target")){const Q=Ue.current.sourceType==="target"?{source:F.nodeId,target:Ue.current.sourceId,sourceHandle:F.handleId||null,targetHandle:Ue.current.sourceHandle}:{source:Ue.current.sourceId,target:F.nodeId,sourceHandle:Ue.current.sourceHandle,targetHandle:F.handleId||null};(Z.current.isValidConnection?Z.current.isValidConnection(Q):!0)&&((b=at.current)==null||b.call(at,{...Q,...zt}))}(x=(l=Z.current).onConnectEnd)==null||x.call(l,u.nativeEvent||u),Ue.current=null,$t.current=null,ut();return}if(st.current){st.current=null,dt(),gt();return}if(Ye.current){const M=Ye.current;if(ke.current){const _=K.current.find(Q=>Q.id===M.id),U=[{id:M.id,type:"position",position:_?{..._.position}:void 0,dragging:!1}];for(const Q of M.selectedStarts){const be=K.current.find(Ae=>Ae.id===Q.id);U.push({id:Q.id,type:"position",position:be?{...be.position}:void 0,dragging:!1})}ke.current(U)}if(M.selectedStarts.length>0){const _=K.current.filter(U=>U.selected);(m=(w=Z.current).onSelectionDragStop)==null||m.call(w,u,_)}requestAnimationFrame(()=>{Ye.current=null});const F=K.current.find(_=>_.id===M.id);F&&((g=Ht.current)==null||g.call(Ht,u,F));return}Tt.current=!1,(R=me.current)==null||R.classList.remove("dragging")},[Be,Rt,ut,dt,gt]);c.useEffect(()=>{const u=me.current;if(!u)return;const b=l=>{Zt&&l.preventDefault();const x=ue.current;if(an||Ke.current){const M=cn;St==="horizontal"?x.x-=l.deltaY*M:(St==="vertical"||(x.x-=l.deltaX*M),x.y-=l.deltaY*M),ve(l);return}if(!ln)return;const w=l.deltaY>0?.92:1.08,m=u.getBoundingClientRect(),g=l.clientX-m.left,R=l.clientY-m.top;x.x=g-(g-x.x)*w,x.y=R-(R-x.y)*w,x.zoom=Math.min(le,Math.max(ne,x.zoom*w)),ve(l)};return u.addEventListener("wheel",b,{passive:!Zt}),()=>u.removeEventListener("wheel",b)},[ve,ne,le,an,St,cn,ln,Zt]),c.useEffect(()=>{if(!dn)return;const u=me.current;if(!u)return;let b=0,l=null;const x=g=>{if(g.touches.length===2){const R=g.touches[0].clientX-g.touches[1].clientX,M=g.touches[0].clientY-g.touches[1].clientY;b=Math.hypot(R,M);const F=u.getBoundingClientRect();l={x:(g.touches[0].clientX+g.touches[1].clientX)/2-F.left,y:(g.touches[0].clientY+g.touches[1].clientY)/2-F.top},g.preventDefault()}},w=g=>{if(g.touches.length===2&&b>0){g.preventDefault();const R=g.touches[0].clientX-g.touches[1].clientX,M=g.touches[0].clientY-g.touches[1].clientY,F=Math.hypot(R,M),_=F/b;b=F;const U=ue.current,Q=l.x,be=l.y;U.x=Q-(Q-U.x)*_,U.y=be-(be-U.y)*_,U.zoom=Math.min(le,Math.max(ne,U.zoom*_)),ve(g)}},m=()=>{b=0,l=null};return u.addEventListener("touchstart",x,{passive:!1}),u.addEventListener("touchmove",w,{passive:!1}),u.addEventListener("touchend",m),()=>{u.removeEventListener("touchstart",x),u.removeEventListener("touchmove",w),u.removeEventListener("touchend",m)}},[dn,ve,ne,le]),c.useEffect(()=>{if(!un)return;const u=me.current;if(!u)return;const b=l=>{var _,U,Q,be;const x=Be(l.clientX,l.clientY);if(ae(x.x,x.y)){(U=(_=Z.current).onNodeDoubleClick)==null||U.call(_,l,ae(x.x,x.y));return}const w=lt(x.x,x.y);if(w){(be=(Q=Z.current).onEdgeDoubleClick)==null||be.call(Q,l,w);return}const m=1.5,g=u.getBoundingClientRect(),R=l.clientX-g.left,M=l.clientY-g.top,F=ue.current;F.x=R-(R-F.x)*m,F.y=M-(M-F.y)*m,F.zoom=Math.min(le,Math.max(ne,F.zoom*m)),ve(l)};return u.addEventListener("dblclick",b),()=>u.removeEventListener("dblclick",b)},[un,ve,ne,le,Be,ae,lt]),c.useEffect(()=>{const u=me.current;if(!u)return;const b=l=>{var g,R,M,F,_,U;const x=Be(l.clientX,l.clientY),w=ae(x.x,x.y);if(w){(R=(g=Z.current).onNodeContextMenu)==null||R.call(g,l,w);return}const m=lt(x.x,x.y);if(m){(F=(M=Z.current).onEdgeContextMenu)==null||F.call(M,l,m);return}(U=(_=Z.current).onPaneContextMenu)==null||U.call(_,l)};return u.addEventListener("contextmenu",b),()=>u.removeEventListener("contextmenu",b)},[Be,ae,lt]),c.useEffect(()=>{const u=me.current;if(!u)return;let b=null,l=null;const x=g=>{var F,_,U,Q,be,Ae,ee,ce,Ce,De,Xe,Ge,qe,Jt;if((_=(F=Z.current).onPaneMouseMove)==null||_.call(F,g),Tt.current||Ye.current||Ue.current||st.current)return;const R=Be(g.clientX,g.clientY),M=ae(R.x,R.y);if(M!==b&&(b&&((Q=(U=Z.current).onNodeMouseLeave)==null||Q.call(U,g,b)),M&&((Ae=(be=Z.current).onNodeMouseEnter)==null||Ae.call(be,g,M)),b=M),M&&((ce=(ee=Z.current).onNodeMouseMove)==null||ce.call(ee,g,M)),!M){const yt=lt(R.x,R.y);yt!==l&&(l&&((De=(Ce=Z.current).onEdgeMouseLeave)==null||De.call(Ce,g,l)),yt&&((Ge=(Xe=Z.current).onEdgeMouseEnter)==null||Ge.call(Xe,g,yt)),l=yt),yt&&((Jt=(qe=Z.current).onEdgeMouseMove)==null||Jt.call(qe,g,yt))}},w=g=>{var R,M;return(M=(R=Z.current).onPaneMouseEnter)==null?void 0:M.call(R,g)},m=g=>{var R,M,F,_,U,Q;(M=(R=Z.current).onPaneMouseLeave)==null||M.call(R,g),b&&((_=(F=Z.current).onNodeMouseLeave)==null||_.call(F,g,b),b=null),l&&((Q=(U=Z.current).onEdgeMouseLeave)==null||Q.call(U,g,l),l=null)};return u.addEventListener("mousemove",x),u.addEventListener("mouseenter",w),u.addEventListener("mouseleave",m),()=>{u.removeEventListener("mousemove",x),u.removeEventListener("mouseenter",w),u.removeEventListener("mouseleave",m)}},[Be,ae,lt]),c.useEffect(()=>{const u=Array.isArray(Ze)?Ze:[Ze],b=async l=>{var x,w,m,g;if(u.includes(l.key)){if(l.target.tagName==="INPUT"||l.target.tagName==="TEXTAREA"||l.target.isContentEditable)return;const R=K.current.filter(_=>_.selected),M=ze.current.filter(_=>_.selected);if(!R.length&&!M.length)return;if(Z.current.onBeforeDelete)try{if(!await Z.current.onBeforeDelete({nodes:R,edges:M}))return}catch(_){(w=(x=Z.current).onError)==null||w.call(x,"before-delete-error",_.message||"onBeforeDelete threw an error");return}const F=new Set(R.map(_=>_.id));if(R.length&&ke.current&&(ke.current(R.map(_=>({id:_.id,type:"remove"}))),_e.current)){const _=ze.current.filter(U=>F.has(U.source)||F.has(U.target));_.length&&_e.current(_.map(U=>({id:U.id,type:"remove"})))}M.length&&_e.current&&_e.current(M.map(_=>({id:_.id,type:"remove"}))),(g=(m=Z.current).onDelete)==null||g.call(m,{nodes:R,edges:M})}if((l.ctrlKey||l.metaKey)&&l.key==="a"){if(l.target.tagName==="INPUT"||l.target.tagName==="TEXTAREA")return;if(l.preventDefault(),ke.current){const R=K.current.filter(M=>!M.selected).map(M=>({id:M.id,type:"select",selected:!0}));R.length&&ke.current(R)}if(_e.current){const R=ze.current.filter(M=>!M.selected).map(M=>({id:M.id,type:"select",selected:!0}));R.length&&_e.current(R)}}};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[Ze]);const vn=c.useRef(!1);c.useEffect(()=>{var u,b;if(!vn.current&&Le.current){if(vn.current=!0,et&&K.current.length>0){const l=me.current;if(l){const x=l.getBoundingClientRect(),w=(ye==null?void 0:ye.padding)??.1,m=Rn(K.current),g=qt(m,x.width,x.height,w);ye!=null&&ye.maxZoom&&(g.zoom=Math.min(g.zoom,ye.maxZoom)),ye!=null&&ye.minZoom&&(g.zoom=Math.max(g.zoom,ye.minZoom)),ue.current=g,ve()}}(b=(u=Z.current).onInit)==null||b.call(u,{getNodes:()=>[...K.current],getEdges:()=>[...ze.current],getNode:l=>K.current.find(x=>x.id===l),getEdge:l=>ze.current.find(x=>x.id===l),getViewport:()=>({...ue.current}),getZoom:()=>ue.current.zoom,setViewport:l=>{ue.current={x:l.x??ue.current.x,y:l.y??ue.current.y,zoom:l.zoom??ue.current.zoom},ve()},fitView:(l={})=>{const x=me.current;if(!x||!K.current.length)return;const w=x.getBoundingClientRect(),m=l.nodes?K.current.filter(M=>l.nodes.some(F=>F.id===M.id)):K.current;if(!m.length)return;const g=Rn(m),R=qt(g,w.width,w.height,l.padding??.1);l.maxZoom&&(R.zoom=Math.min(R.zoom,l.maxZoom)),l.minZoom&&(R.zoom=Math.max(R.zoom,l.minZoom)),ue.current=R,ve()},screenToFlowPosition:l=>Be(l.x,l.y),flowToScreenPosition:l=>{const x=ue.current,w=me.current;if(!w)return{x:0,y:0};const m=w.getBoundingClientRect();return{x:l.x*x.zoom+x.x+m.left,y:l.y*x.zoom+x.y+m.top}},zoomIn:()=>{const l=ue.current;l.zoom=Math.min(le,l.zoom*1.2),ve()},zoomOut:()=>{const l=ue.current;l.zoom=Math.max(ne,l.zoom/1.2),ve()},zoomTo:l=>{ue.current.zoom=Math.min(le,Math.max(ne,l)),ve()},setNodes:l=>{var x,w;(w=(x=Z.current).onNodesChange)==null||w.call(x,[...K.current.map(m=>({id:m.id,type:"remove"})),...(typeof l=="function"?l(K.current):l).map(m=>({type:"add",item:m}))])},setEdges:l=>{var x,w;(w=(x=Z.current).onEdgesChange)==null||w.call(x,[...ze.current.map(m=>({id:m.id,type:"remove"})),...(typeof l=="function"?l(ze.current):l).map(m=>({type:"add",item:m}))])},addNodes:l=>{var w,m;const x=Array.isArray(l)?l:[l];(m=(w=Z.current).onNodesChange)==null||m.call(w,x.map(g=>({type:"add",item:g})))},addEdges:l=>{var w,m;const x=Array.isArray(l)?l:[l];(m=(w=Z.current).onEdgesChange)==null||m.call(w,x.map(g=>({type:"add",item:g})))},deleteElements:({nodes:l=[],edges:x=[]})=>{var w,m,g,R;l.length&&((m=(w=Z.current).onNodesChange)==null||m.call(w,l.map(M=>({id:M.id,type:"remove"})))),x.length&&((R=(g=Z.current).onEdgesChange)==null||R.call(g,x.map(M=>({id:M.id,type:"remove"}))))},updateNodeData:(l,x)=>{var g,R;const w=K.current.find(M=>M.id===l);if(!w)return;const m=typeof x=="function"?x(w.data):{...w.data,...x};(R=(g=Z.current).onNodesChange)==null||R.call(g,[{id:l,type:"replace",item:{...w,data:m}}])},toObject:()=>({nodes:[...K.current],edges:[...ze.current],viewport:{...ue.current}}),setCenter:(l,x,w={})=>{const m=me.current;if(!m)return;const g=m.getBoundingClientRect(),R=w.zoom??ue.current.zoom;ue.current={x:g.width/2-l*R,y:g.height/2-x*R,zoom:R},ve()},fitBounds:(l,x={})=>{const w=me.current;if(!w)return;const m=w.getBoundingClientRect(),g=qt(l,m.width,m.height,x.padding??.1);ue.current=g,ve()}})}});const Wn=c.useCallback(()=>{ue.current={...Ee},ve()},[ve,Ee]),Fn=c.useCallback(u=>{var b;if(u)mt.current.push(u);else{const l=ue.current,x=me.current;if(!x)return;const w=x.getBoundingClientRect(),m=Math.round(-l.x/l.zoom+w.width/2/l.zoom),g=Math.round(-l.y/l.zoom+w.height/2/l.zoom);mt.current.push({x:m-80,y:g-45,w:160,h:90,title:"Note "+(mt.current.length+1),body:"Added at viewport center"})}(b=Le.current)==null||b.postMessage({type:"cards",data:{cards:[...mt.current]}})},[]),W=c.useCallback(u=>{if(u.id||(u.id="node-"+Date.now()),!u.position){const b=ue.current,l=me.current;if(!l)return;const x=l.getBoundingClientRect();u.position={x:Math.round(-b.x/b.zoom+x.width/2/b.zoom)-ft/2,y:Math.round(-b.y/b.zoom+x.height/2/b.zoom)-nt/2}}u.data||(u.data={label:u.id}),ke.current&&ke.current([{type:"add",item:u}])},[]),xe=c.useCallback(()=>({...ue.current}),[]),V=c.useCallback(u=>{ue.current={...ue.current,...u},ve()},[ve]),Ne=c.useCallback(u=>Be(u.x,u.y),[Be]),He=n,Ie=c.useMemo(()=>({wrapRef:me,canvasRef:Pt,workerRef:Le,cameraRef:ue,nodesRef:K,edgesRef:ze,handleRegistryRef:fn,syncNodesToWorker:pn,onNodesChangeRef:ke,onEdgesChangeRef:_e,sendCamera:ve,screenToWorld:Be,viewportListeners:vt,selectionListeners:it,zoomMin:ne,zoomMax:le,snapToGrid:je,snapGrid:Fe,nodeExtent:pt,defaultEdgeOptions:zt,edgeRouting:wt,resolvedNodesRef:ct,noDragClassName:Nt,noPanClassName:It,get nodes(){return t},get edges(){return n},get routedEdges(){return He},get viewport(){return gn},get connection(){return Gt}}),[t,n,He,gn,Gt,ve,Be,pn,vt,it,ne,le,je,Fe,pt,zt,wt,Nt,It]);return{wrapRef:me,canvasRef:Pt,canvasReady:Bt,onPointerDown:mn,onPointerMove:Qt,onPointerUp:_n,resetView:Wn,addCard:Fn,addNode:W,getCamera:xe,setCamera:V,screenToFlowPosition:Ne,store:Ie}}function ro(e,t,n,r,i,o){const a=i-n,f=o-r,p=a*a+f*f;if(p===0)return Math.hypot(e-n,t-r);let d=((e-n)*a+(t-r)*f)/p;return d=Math.max(0,Math.min(1,d)),Math.hypot(e-(n+d*a),t-(r+d*f))}const ur=e=>{let t;const n=new Set,r=(d,h)=>{const k=typeof d=="function"?d(t):d;if(!Object.is(k,t)){const S=t;t=h??(typeof k!="object"||k===null)?k:Object.assign({},t,k),n.forEach(E=>E(t,S))}},i=()=>t,f={setState:r,getState:i,getInitialState:()=>p,subscribe:d=>(n.add(d),()=>n.delete(d))},p=t=e(r,i,f);return f},oo=(e=>e?ur(e):ur),so=e=>e;function io(e,t=so){const n=c.useSyncExternalStore(e.subscribe,c.useCallback(()=>t(e.getState()),[e,t]),c.useCallback(()=>t(e.getInitialState()),[e,t]));return c.useDebugValue(n),n}const Ct=c.createContext(null);function ao(e={}){return oo((t,n)=>({nodes:[],edges:[],viewport:{x:0,y:0,zoom:1},connection:null,minZoom:.1,maxZoom:5,width:0,height:0,domNode:null,nodesRef:{current:[]},edgesRef:{current:[]},cameraRef:{current:{x:0,y:0,zoom:1}},wrapRef:{current:null},workerRef:{current:null},onNodesChangeRef:{current:null},onEdgesChangeRef:{current:null},viewportListeners:new Set,selectionListeners:new Set,edgeLabelContainerRef:{current:null},viewportPortalRef:{current:null},screenToWorld:(r,i)=>{const o=n().cameraRef.current;return{x:(r-o.x)/o.zoom,y:(i-o.y)/o.zoom}},sendCamera:()=>{var i;const r=n();(i=r.workerRef.current)==null||i.postMessage({type:"camera",data:{camera:{...r.cameraRef.current}}})},...e}))}function Pe(e,t){const n=c.useContext(Ct);if(!n)throw new Error("useCanvasStore must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");const r=typeof n.getState=="function"&&typeof n.subscribe=="function",i=c.useRef(e),o=c.useRef(t),a=c.useRef(void 0);i.current=e,o.current=t;const f=c.useCallback(p=>{const d=i.current;if(!d)return p;const h=d(p),k=o.current||Object.is;return a.current!==void 0&&k(a.current,h)?a.current:(a.current=h,h)},[]);return r?io(n,e?f:void 0):e?f(n):n}function Rr(){const e=c.useContext(Ct);if(!e)throw new Error("useCanvasStoreApi must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");return typeof e.getState=="function"?e:{getState:()=>e,setState:()=>{},subscribe:()=>()=>{}}}const on=c.createContext(null);function co(){return c.useContext(on)}function lo({node:e,nodeType:t}){var z,j,L,A;const n=Pe(),r=c.useRef(n);r.current=n;const i=c.useRef(null),o=e._absolutePosition||e.position,a=c.useRef(null);c.useEffect(()=>{const X=i.current;if(!X)return;const D=new ResizeObserver(Y=>{var q,O,H,C;const{width:$,height:I}=Y[0].contentRect;if($>0&&I>0){const y=r.current,v=y.nodesRef.current.find(B=>B.id===e.id),N=(v==null?void 0:v.width)||((q=v==null?void 0:v.measured)==null?void 0:q.width),P=(v==null?void 0:v.height)||((O=v==null?void 0:v.measured)==null?void 0:O.height);(Math.abs((N||0)-$)>1||Math.abs((P||0)-I)>1)&&((C=(H=y.onNodesChangeRef).current)==null||C.call(H,[{id:e.id,type:"dimensions",dimensions:{width:$,height:I},setAttributes:!0}]))}});return D.observe(X),()=>D.disconnect()},[e.id]);const f=c.useCallback(X=>{var se,he,ge,fe;X.stopPropagation();const D=X.target.tagName;if(D==="INPUT"||D==="TEXTAREA"||D==="SELECT"||D==="BUTTON"||D==="A"||D==="LABEL"||X.target.isContentEditable)return;const Y=r.current.noDragClassName||"nodrag",$=r.current.noPanClassName||"nopan";let I=X.target;for(;I&&I!==i.current;){if((se=I.classList)!=null&&se.contains(Y)||(he=I.classList)!=null&&he.contains($))return;I=I.parentElement}if(r.current.onNodesChangeRef.current){const ie=[];if(X.shiftKey)ie.push({id:e.id,type:"select",selected:!e.selected});else for(const ne of r.current.nodesRef.current)ne.id===e.id&&!ne.selected?ie.push({id:ne.id,type:"select",selected:!0}):ne.id!==e.id&&ne.selected&&ie.push({id:ne.id,type:"select",selected:!1});ie.length&&r.current.onNodesChangeRef.current(ie)}const q=r.current.cameraRef.current,O=r.current.wrapRef.current;if(!O)return;const H=O.getBoundingClientRect(),C=(X.clientX-H.left-q.x)/q.zoom,y=(X.clientY-H.top-q.y)/q.zoom,N=e.selected?r.current.nodesRef.current.filter(ie=>ie.selected&&ie.id!==e.id).map(ie=>({id:ie.id,startPos:{...ie.position}})):[];a.current={startPos:{...e.position},startMouse:{x:C,y},selectedStarts:N};const P=[{id:e.id,type:"position",dragging:!0}];for(const ie of N)P.push({id:ie.id,type:"position",dragging:!0});(fe=(ge=r.current.onNodesChangeRef).current)==null||fe.call(ge,P);const B=i.current;B&&B.setPointerCapture(X.pointerId);let J=null;const oe=ie=>{var We,Se,tt,rt;if(!a.current)return;const Me=r.current.cameraRef.current,ne=O.getBoundingClientRect(),le=(ie.clientX-ne.left-Me.x)/Me.zoom,Ee=(ie.clientY-ne.top-Me.y)/Me.zoom,et=le-a.current.startMouse.x,ye=Ee-a.current.startMouse.y;let Re={x:a.current.startPos.x+et,y:a.current.startPos.y+ye};if(r.current.snapToGrid&&r.current.snapGrid&&(Re={x:r.current.snapGrid[0]*Math.round(Re.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Re.y/r.current.snapGrid[1])}),e.parentId&&e.extent==="parent"){const we=r.current.nodesRef.current.find(Te=>Te.id===e.parentId);if(we){const Te=we.width||160,Oe=we.height||60,je=e.width||((We=e.measured)==null?void 0:We.width)||160,Fe=e.height||((Se=e.measured)==null?void 0:Se.height)||60;Re={x:Math.max(0,Math.min(Re.x,Te-je)),y:Math.max(0,Math.min(Re.y,Oe-Fe))}}}B&&(B.style.left=Re.x+"px",B.style.top=Re.y+"px");const $e=[{id:e.id,position:Re,_absolutePosition:Re,dragging:!0}];for(const we of a.current.selectedStarts){let Te={x:we.startPos.x+et,y:we.startPos.y+ye};r.current.snapToGrid&&r.current.snapGrid&&(Te={x:r.current.snapGrid[0]*Math.round(Te.x/r.current.snapGrid[0]),y:r.current.snapGrid[1]*Math.round(Te.y/r.current.snapGrid[1])});const Oe=O.querySelector(`[data-nodeid="${we.id}"]`);Oe&&(Oe.style.left=Te.x+"px",Oe.style.top=Te.y+"px"),$e.push({id:we.id,position:Te,_absolutePosition:Te,dragging:!0})}(rt=(tt=r.current.workerRef)==null?void 0:tt.current)==null||rt.postMessage({type:"nodePositions",data:{updates:$e}});for(const we of $e){const Te=r.current.nodesRef.current.find(Oe=>Oe.id===we.id);Te&&(Te.position=we.position)}J=$e},te=ie=>{var ne,le;if(!a.current)return;const Me=[];if(J)for(const Ee of J)Me.push({id:Ee.id,type:"position",position:Ee.position,dragging:!1});else{Me.push({id:e.id,type:"position",dragging:!1});for(const Ee of a.current.selectedStarts)Me.push({id:Ee.id,type:"position",dragging:!1})}(le=(ne=r.current.onNodesChangeRef).current)==null||le.call(ne,Me),a.current=null,J=null,B&&B.releasePointerCapture(ie.pointerId),B==null||B.removeEventListener("pointermove",oe),B==null||B.removeEventListener("pointerup",te)};B==null||B.addEventListener("pointermove",oe),B==null||B.addEventListener("pointerup",te)},[e]),p=c.useCallback(X=>{var O,H,C,y,v,N;if(!e.selected)return;const D=X.shiftKey?10:1;let Y=0,$=0;switch(X.key){case"ArrowUp":$=-D;break;case"ArrowDown":$=D;break;case"ArrowLeft":Y=-D;break;case"ArrowRight":Y=D;break;case"Escape":(H=(O=r.current.onNodesChangeRef).current)==null||H.call(O,[{id:e.id,type:"select",selected:!1}]);return;case"Delete":case"Backspace":e.deletable!==!1&&((y=(C=r.current.onNodesChangeRef).current)==null||y.call(C,[{id:e.id,type:"remove"}]));return;default:return}X.preventDefault();const I={x:e.position.x+Y,y:e.position.y+$},q=[{id:e.id,type:"position",position:I}];for(const P of r.current.nodesRef.current)P.selected&&P.id!==e.id&&q.push({id:P.id,type:"position",position:{x:P.position.x+Y,y:P.position.y+$}});(N=(v=r.current.onNodesChangeRef).current)==null||N.call(v,q)},[e]),d=e.width||((z=e.measured)==null?void 0:z.width),h=e.height||((j=e.measured)==null?void 0:j.height),k=!!(d&&h),S=(L=n.pinnedNodeIds)==null?void 0:L.has(e.id),E=c.useCallback(X=>{var D,Y;X.stopPropagation(),(Y=(D=r.current).togglePinNode)==null||Y.call(D,e.id)},[e.id]);return T.jsx(on.Provider,{value:e.id,children:T.jsxs("div",{ref:i,className:`ric-node-wrapper ${e.selected?"selected":""} ${e.dragging?"dragging":""}`,style:{position:"absolute",left:o.x,top:o.y,zIndex:e.type==="group"?0:e.zIndex||1,pointerEvents:e.type==="group"?"none":"all",visibility:k?"visible":"hidden",outline:"none"},"data-nodeid":e.id,tabIndex:e.selectable!==!1?0:void 0,role:"button","aria-label":`Node ${((A=e.data)==null?void 0:A.label)||e.id}`,"aria-selected":!!e.selected,onPointerDown:f,onKeyDown:p,children:[T.jsx(t,{id:e.id,data:e.data,type:e.type,selected:!!e.selected,dragging:!!e.dragging,draggable:e.draggable!==!1,selectable:e.selectable!==!1,deletable:e.deletable!==!1,isConnectable:e.connectable!==!1,zIndex:e.zIndex||0,positionAbsoluteX:o.x,positionAbsoluteY:o.y,width:d,height:h,sourcePosition:e.sourcePosition,targetPosition:e.targetPosition,parentId:e.parentId,dragHandle:e.dragHandle}),n.togglePinNode&&T.jsx("button",{className:"ric-pin-btn nodrag",onClick:E,title:S?"Unpin from DOM":"Pin to DOM",style:{position:"absolute",top:-8,left:-8,width:20,height:20,borderRadius:"50%",border:"1.5px solid "+(S?"#3b82f6":"#ccc"),background:S?"#3b82f6":"#fff",color:S?"#fff":"#999",fontSize:10,lineHeight:"16px",textAlign:"center",cursor:"pointer",padding:0,zIndex:10,pointerEvents:"all",boxShadow:"0 1px 3px rgba(0,0,0,0.12)"},children:"📌"})]})})}const uo=c.memo(lo),kr=160,Cr=60;function dr(e,t,n,r){var f,p;const i=e.width||((f=e.measured)==null?void 0:f.width)||kr,o=e.height||((p=e.measured)==null?void 0:p.height)||Cr,a=e._absolutePosition||e.position;if(e.handleBounds){const d=e.handleBounds[t]||[],h=n?d.find(k=>k.id===n):d[0];if(h&&h.x!==void 0&&h.y!==void 0){const k=h.position||(t==="source"?"right":"left");return{x:a.x+h.x,y:a.y+h.y,position:k}}}if(r){const d=`${e.id}__${n||t}`,h=r.get(d);if(h&&h.x!==void 0&&h.y!==void 0)return{x:a.x+h.x,y:a.y+h.y,position:h.position||(t==="source"?"right":"left")}}if(e.handles&&e.handles.length){for(const d of e.handles)if(d.type===t&&(!n||d.id===n)){if(d.x!==void 0&&d.y!==void 0)return{x:a.x+d.x,y:a.y+d.y,position:d.position||(t==="source"?"right":"left")};const h=d.position||(t==="source"?"right":"left");switch(h){case"top":return{x:a.x+i/2,y:a.y,position:h};case"bottom":return{x:a.x+i/2,y:a.y+o,position:h};case"left":return{x:a.x,y:a.y+o/2,position:h};default:return{x:a.x+i,y:a.y+o/2,position:h}}}}return t==="source"?{x:a.x+i,y:a.y+o/2,position:"right"}:{x:a.x,y:a.y+o/2,position:"left"}}function fo(e,t,n){return n==="left"?e-t:n==="right"?e+t:e}function ho(e,t,n){return n==="top"?e-t:n==="bottom"?e+t:e}function fr({x:e,y:t,position:n,type:r,onPointerDown:i}){return T.jsx("circle",{className:`ric-edge-anchor ric-edge-anchor-${r}`,cx:fo(e,10,n),cy:ho(t,10,n),r:10,stroke:"transparent",fill:"transparent",style:{cursor:"move",pointerEvents:"stroke"},onPointerDown:i})}function go({edge:e,edgeType:t,nodes:n,reconnectable:r}){var I,q,O;const i=c.useContext(Ct),o=c.useRef(typeof i.getState=="function"?i.getState():i);o.current=typeof i.getState=="function"?i.getState():i;const[a,f]=c.useState(null),p=c.useCallback((H,C,y,v)=>{var he;C.stopPropagation(),C.preventDefault();const N=o.current,P=N.wrapRef.current;if(!P)return;const B=H==="source"?v:y,J=H==="source"?e.target:e.source;(he=N.workerRef.current)==null||he.postMessage({type:"connecting",data:{from:{x:B.x,y:B.y},to:{x:B.x,y:B.y}}});const oe=P.getBoundingClientRect(),te=ge=>{var ne;const fe=N.cameraRef.current,ie=(ge.clientX-oe.left-fe.x)/fe.zoom,Me=(ge.clientY-oe.top-fe.y)/fe.zoom;(ne=N.workerRef.current)==null||ne.postMessage({type:"connecting",data:{from:{x:B.x,y:B.y},to:{x:ie,y:Me}}})},se=ge=>{var ye,Re,$e,We;const fe=N.cameraRef.current,ie=(ge.clientX-oe.left-fe.x)/fe.zoom,Me=(ge.clientY-oe.top-fe.y)/fe.zoom,ne=20/fe.zoom;let le=null,Ee=null;const et=(ye=N.handleRegistryRef)==null?void 0:ye.current;for(const Se of N.nodesRef.current){if(Se.hidden)continue;const tt=Se.width||kr,rt=Se.height||Cr,we=Se._absolutePosition||Se.position,Te=[];if(et)for(const[,je]of et)je.nodeId===Se.id&&Te.push(je);const Oe=Te.length>0?Te:Se.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const je of Oe){let Fe,Ze;if(je.x!==void 0&&je.y!==void 0)Fe=we.x+je.x,Ze=we.y+je.y;else switch(je.position||(je.type==="source"?"right":"left")){case"top":Fe=we.x+tt/2,Ze=we.y;break;case"bottom":Fe=we.x+tt/2,Ze=we.y+rt;break;case"left":Fe=we.x,Ze=we.y+rt/2;break;default:Fe=we.x+tt,Ze=we.y+rt/2;break}if(Math.abs(ie-Fe)<ne&&Math.abs(Me-Ze)<ne){le=Se,Ee=je.id||null;break}}if(le)break}if(le){const Se=H==="source"?{source:le.id,target:J,sourceHandle:Ee,targetHandle:e.targetHandle}:{source:J,target:le.id,sourceHandle:e.sourceHandle,targetHandle:Ee};($e=(Re=N.onEdgesChangeRef).current)==null||$e.call(Re,[{id:e.id,type:"remove"},{type:"add",item:{id:e.id,...Se}}])}(We=N.workerRef.current)==null||We.postMessage({type:"connecting",data:null}),P.removeEventListener("pointermove",te),P.removeEventListener("pointerup",se)};P.addEventListener("pointermove",te),P.addEventListener("pointerup",se)},[e]),d=n.find(H=>H.id===e.source),h=n.find(H=>H.id===e.target),k=d&&!!(d.width||(I=d.measured)!=null&&I.width),S=h&&!!(h.width||(q=h.measured)!=null&&q.width),E=o.current,z=(O=E.handleRegistryRef)==null?void 0:O.current,j=k?dr(d,"source",e.sourceHandle,z):null,L=S?dr(h,"target",e.targetHandle,z):null,A=e.type==="bezier"||e.type==="simplebezier"||e.type==="default",X=E.routedEdges||E.edges,D=X==null?void 0:X.find(H=>H.id===e.id),Y=A?null:(D==null?void 0:D._routedPoints)||e._routedPoints||null,$=r!==!1&&e.reconnectable!==!1;return!j||!L?null:T.jsxs("g",{className:`ric-edge-wrapper ${e.selected?"selected":""}`,"data-edgeid":e.id,onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),children:[T.jsx(t,{id:e.id,source:e.source,target:e.target,sourceX:j.x,sourceY:j.y,targetX:L.x,targetY:L.y,sourcePosition:j.position,targetPosition:L.position,sourceHandleId:e.sourceHandle,targetHandleId:e.targetHandle,data:e.data,type:e.type,selected:!!e.selected,animated:!!e.animated,label:e.label,style:e.style,selectable:e.selectable!==!1,deletable:e.deletable!==!1,routedPoints:Y}),$&&(a||e.selected)&&T.jsxs(T.Fragment,{children:[T.jsx(fr,{x:j.x,y:j.y,position:j.position,type:"source",onPointerDown:H=>p("source",H,j,L)}),T.jsx(fr,{x:L.x,y:L.y,position:L.position,type:"target",onPointerDown:H=>p("target",H,j,L)})]})]})}const yo=c.memo(go);function Er({selectionKeyCode:e="Shift",selectionMode:t="partial"}){var j;const n=Pe(),[r,i]=c.useState(null),o=c.useRef(null);if(c.useEffect(()=>{const L=n.wrapRef.current;if(!L)return;let A=!1,X=null,D=!1;const Y=H=>{H.key===e&&(D=!0)},$=H=>{H.key===e&&(D=!1)},I=H=>{if(!D)return;const C=H.target;if(C.closest(".ric-node-wrapper")||C.closest(".ric-handle"))return;A=!0;const y=n.cameraRef.current,v=L.getBoundingClientRect(),N=(H.clientX-v.left-y.x)/y.zoom,P=(H.clientY-v.top-y.y)/y.zoom;X={x:N,y:P},i({startX:N,startY:P,endX:N,endY:P}),H.stopPropagation()},q=H=>{if(!A||!X)return;const C=n.cameraRef.current,y=L.getBoundingClientRect(),v=(H.clientX-y.left-C.x)/C.zoom,N=(H.clientY-y.top-C.y)/C.zoom;i({startX:X.x,startY:X.y,endX:v,endY:N})},O=H=>{var J,oe;if(!A||!X)return;A=!1;const C=n.cameraRef.current,y=L.getBoundingClientRect(),v=(H.clientX-y.left-C.x)/C.zoom,N=(H.clientY-y.top-C.y)/C.zoom,P={x:Math.min(X.x,v),y:Math.min(X.y,N),width:Math.abs(v-X.x),height:Math.abs(N-X.y)},B=[];for(const te of n.nodesRef.current){const se=te._absolutePosition||te.position,he=te.width||160,ge=te.height||60;let fe;t==="full"?fe=se.x>=P.x&&se.y>=P.y&&se.x+he<=P.x+P.width&&se.y+ge<=P.y+P.height:fe=se.x+he>P.x&&se.x<P.x+P.width&&se.y+ge>P.y&&se.y<P.y+P.height,B.push({id:te.id,type:"select",selected:fe})}B.length&&((oe=(J=n.onNodesChangeRef).current)==null||oe.call(J,B)),X=null,i(null)};return L.addEventListener("pointerdown",I,!0),L.addEventListener("pointermove",q),L.addEventListener("pointerup",O),window.addEventListener("keydown",Y),window.addEventListener("keyup",$),()=>{L.removeEventListener("pointerdown",I,!0),L.removeEventListener("pointermove",q),L.removeEventListener("pointerup",O),window.removeEventListener("keydown",Y),window.removeEventListener("keyup",$)}},[n,e,t]),!r)return null;const a=((j=n.cameraRef)==null?void 0:j.current)||{x:0,y:0,zoom:1},f=Math.min(r.startX,r.endX),p=Math.min(r.startY,r.endY),d=Math.abs(r.endX-r.startX),h=Math.abs(r.endY-r.startY),k=f*a.zoom+a.x,S=p*a.zoom+a.y,E=d*a.zoom,z=h*a.zoom;return T.jsx("div",{ref:o,className:"ric-selection-box",style:{position:"absolute",left:k,top:S,width:E,height:z,border:"1px dashed #3b82f6",background:"rgba(59, 130, 246, 0.08)",pointerEvents:"none",zIndex:100}})}Er.displayName="SelectionBox";const Sr=c.memo(Er);function Qn(e,t,n){switch(e){case"top":return{x:t/2,y:0};case"bottom":return{x:t/2,y:n};case"left":return{x:0,y:n/2};case"right":return{x:t,y:n/2};default:return{x:t,y:n/2}}}function xo(e,t){const n=e.closest(".ric-node-wrapper");if(!n)return null;const r=n.getBoundingClientRect(),i=e.getBoundingClientRect(),o=t||1;return{x:(i.left+i.width/2-r.left)/o,y:(i.top+i.height/2-r.top)/o}}let On=!1,kt=null;function zr(e){kt=e,!On&&(On=!0,requestAnimationFrame(()=>{var t;On=!1,(t=kt==null?void 0:kt.syncNodesToWorker)==null||t.call(kt),kt=null}))}const Jn=new WeakMap;let wn=null;function po(){return wn||(wn=new ResizeObserver(e=>{var t;for(const n of e){const r=Jn.get(n.target);if(!r)continue;const{width:i,height:o}=n.contentRect;if(!i||!o)continue;const a=r.getStore(),f=(t=a.handleRegistryRef)==null?void 0:t.current;if(f){for(const[p,d]of f)if(d.nodeId===r.nodeId){const h=Qn(d.position,i,o);d.x=h.x,d.y=h.y,f.set(p,d)}zr(a)}}}),wn)}function mo({type:e="source",position:t=e==="source"?"right":"left",id:n,isConnectable:r=!0,isConnectableStart:i=!0,isConnectableEnd:o=!0,children:a,className:f="",style:p={},onConnect:d,...h}){const k=c.useContext(on),S=c.useContext(Ct),E=c.useRef(null),z=c.useCallback(()=>typeof S.getState=="function"?S.getState():S,[S]),j=c.useRef(z);j.current=z,c.useLayoutEffect(()=>{var C,y,v,N,P,B,J;if(!k)return;const D=j.current(),Y=(C=D.handleRegistryRef)==null?void 0:C.current;if(!Y)return;const $=`${k}__${n||e}`,I=(v=(y=D.nodesRef)==null?void 0:y.current)==null?void 0:v.find(oe=>oe.id===k),q=(I==null?void 0:I.width)||((N=I==null?void 0:I.measured)==null?void 0:N.width),O=(I==null?void 0:I.height)||((P=I==null?void 0:I.measured)==null?void 0:P.height);let H;q&&O?H=Qn(t,q,O):E.current?H=xo(E.current,(J=(B=D.cameraRef)==null?void 0:B.current)==null?void 0:J.zoom):H=Qn(t,160,60),Y.set($,{nodeId:k,id:n||null,type:e,position:t,x:H.x,y:H.y})},[k,n,e,t]),c.useEffect(()=>{if(!k)return;const D=j.current();zr(D);const Y=E.current,$=Y==null?void 0:Y.closest(".ric-node-wrapper");return $&&!Jn.has($)&&(Jn.set($,{nodeId:k,getStore:j.current}),po().observe($)),()=>{var H;const q=(H=j.current().handleRegistryRef)==null?void 0:H.current,O=`${k}__${n||e}`;q==null||q.delete(O)}},[k,n,e,t]);const L=c.useCallback(()=>{var y;const D=j.current(),Y=D.nodesRef.current.find(v=>v.id===k);if(!Y)return null;const $=Y._absolutePosition||Y.position,I=(y=D.handleRegistryRef)==null?void 0:y.current,q=`${k}__${n||e}`,O=I==null?void 0:I.get(q);if(O&&O.x!==void 0&&O.y!==void 0)return{x:$.x+O.x,y:$.y+O.y};const H=Y.width||160,C=Y.height||60;switch(t){case"top":return{x:$.x+H/2,y:$.y};case"bottom":return{x:$.x+H/2,y:$.y+C};case"left":return{x:$.x,y:$.y+C/2};default:return{x:$.x+H,y:$.y+C/2}}},[k,n,e,t]),A=c.useCallback(D=>{var N;if(!r||!i)return;D.stopPropagation(),D.preventDefault();const Y=j.current(),$=Y.cameraRef.current,I=Y.wrapRef.current;if(!I)return;const q=I.getBoundingClientRect(),O=L();if(!O)return;const H=O.x,C=O.y;(N=Y.workerRef.current)==null||N.postMessage({type:"connecting",data:{from:{x:H,y:C},to:{x:H,y:C}}}),I.setPointerCapture(D.pointerId);const y=P=>{var oe;const B=(P.clientX-q.left-$.x)/$.zoom,J=(P.clientY-q.top-$.y)/$.zoom;(oe=Y.workerRef.current)==null||oe.postMessage({type:"connecting",data:{from:{x:H,y:C},to:{x:B,y:J}}})},v=P=>{var ge,fe,ie,Me;const B=(P.clientX-q.left-$.x)/$.zoom,J=(P.clientY-q.top-$.y)/$.zoom,oe=20/$.zoom;let te=null,se=null;const he=(ge=Y.handleRegistryRef)==null?void 0:ge.current;for(const ne of Y.nodesRef.current){if(ne.id===k||ne.hidden)continue;const le=ne._absolutePosition||ne.position,Ee=[];if(he)for(const[,ye]of he)ye.nodeId===ne.id&&Ee.push(ye);const et=Ee.length>0?Ee:ne.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const ye of et){let Re,$e;if(ye.x!==void 0&&ye.y!==void 0)Re=le.x+ye.x,$e=le.y+ye.y;else{const We=ne.width||160,Se=ne.height||60;switch(ye.position||(ye.type==="source"?"right":"left")){case"top":Re=le.x+We/2,$e=le.y;break;case"bottom":Re=le.x+We/2,$e=le.y+Se;break;case"left":Re=le.x,$e=le.y+Se/2;break;default:Re=le.x+We,$e=le.y+Se/2;break}}if(Math.abs(B-Re)<oe&&Math.abs(J-$e)<oe){te=ne,se=ye.id||null;break}}if(te)break}if(te){const ne={source:e==="source"?k:te.id,target:e==="source"?te.id:k,sourceHandle:e==="source"?n||null:se,targetHandle:e==="source"?se:n||null};(ie=(fe=Y.onEdgesChangeRef)==null?void 0:fe.current)==null||ie.call(fe,[{type:"add",item:{id:`e-${ne.source}-${ne.target}`,...ne}}])}(Me=Y.workerRef.current)==null||Me.postMessage({type:"connecting",data:null}),I.removeEventListener("pointermove",y),I.removeEventListener("pointerup",v)};I.addEventListener("pointermove",y),I.addEventListener("pointerup",v)},[k,n,e,t,r,i,L]),X={top:{top:0,left:"50%",transform:"translate(-50%, -50%)"},bottom:{bottom:0,left:"50%",transform:"translate(-50%, 50%)"},left:{top:"50%",left:0,transform:"translate(-50%, -50%)"},right:{top:"50%",right:0,transform:"translate(50%, -50%)"}}[t]||{};return T.jsx("div",{ref:E,className:`ric-handle ric-handle-${t} ric-handle-${e} ${f}`,"data-handleid":n||null,"data-nodeid":k,"data-handlepos":t,"data-handletype":e,onPointerDown:A,style:{position:"absolute",width:8,height:8,borderRadius:"50%",background:"#1a192b",border:"none",zIndex:10,cursor:r?"crosshair":"default",boxSizing:"border-box",...X,...p},...h,children:a})}const rn=c.memo(mo);function vo({data:e,isConnectable:t,selected:n,targetPosition:r="left",sourcePosition:i="right",hideSourceHandle:o=!1,hideTargetHandle:a=!1}){return T.jsxs("div",{className:`ric-default-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!a&&T.jsx(rn,{type:"target",position:r,isConnectable:t}),T.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!o&&T.jsx(rn,{type:"source",position:i,isConnectable:t})]})}function Nr({data:e,isConnectable:t,selected:n,sourcePosition:r="right",hideSourceHandle:i=!1}){return T.jsxs("div",{className:`ric-input-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderBottom:"2px solid #0041d0",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[T.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!i&&T.jsx(rn,{type:"source",position:r,isConnectable:t})]})}function Ir({data:e,isConnectable:t,selected:n,targetPosition:r="left",hideTargetHandle:i=!1}){return T.jsxs("div",{className:`ric-output-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderTop:"2px solid #ff0072",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!i&&T.jsx(rn,{type:"target",position:r,isConnectable:t}),T.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label})]})}function Pr({data:e,selected:t,width:n,height:r}){return T.jsx("div",{className:`ric-group-node${t?" selected":""}`,style:{width:n||300,height:r||200,background:"rgba(240, 240, 240, 0.25)",border:t?"2px solid #3b82f6":"1px dashed #ccc",borderRadius:8,padding:8,boxSizing:"border-box"},children:(e==null?void 0:e.label)&&T.jsx("div",{style:{fontSize:11,fontWeight:600,color:"#888",userSelect:"none"},children:e.label})})}function Tr({x:e,y:t,label:n,labelStyle:r,labelShowBg:i=!0,labelBgStyle:o,labelBgPadding:a=[2,4],labelBgBorderRadius:f=2,children:p,className:d="",...h}){const[k,S]=c.useState({x:1,y:0,width:0,height:0}),E=c.useRef(null);return c.useEffect(()=>{if(E.current){const z=E.current.getBBox();S({x:z.x,y:z.y,width:z.width,height:z.height})}},[n]),n?T.jsxs("g",{transform:`translate(${e-k.width/2} ${t-k.height/2})`,className:`ric-edge-textwrapper ${d}`,visibility:k.width?"visible":"hidden",...h,children:[i&&T.jsx("rect",{width:k.width+2*a[0],x:-a[0],y:-a[1],height:k.height+2*a[1],className:"ric-edge-textbg",style:o,rx:f,ry:f}),T.jsx("text",{className:"ric-edge-text",y:k.height/2,dy:"0.3em",ref:E,style:r,children:n}),p]}):null}Tr.displayName="EdgeText";const Lr=c.memo(Tr);function hr(e){return e!=null&&e!==""&&!isNaN(Number(e))}function sn({id:e,path:t,labelX:n,labelY:r,label:i,labelStyle:o,labelShowBg:a,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:d,interactionWidth:h=20,style:k,markerEnd:S,markerStart:E,className:z="",...j}){return T.jsxs(T.Fragment,{children:[T.jsx("path",{id:e,d:t,fill:"none",stroke:"#b1b1b7",strokeWidth:1.5,className:`ric-edge-path ${z}`,style:k,markerEnd:S,markerStart:E,...j}),h?T.jsx("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:h,className:"ric-edge-interaction",style:{pointerEvents:"stroke"}}):null,i&&hr(n)&&hr(r)?T.jsx(Lr,{x:n,y:r,label:i,labelStyle:o,labelShowBg:a,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:d}):null]})}const en=20;function gr(e,t,n){switch(n){case"right":return{x:e+en,y:t};case"left":return{x:e-en,y:t};case"bottom":return{x:e,y:t+en};case"top":return{x:e,y:t-en};default:return{x:e+en,y:t}}}const er=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:a="bottom",targetPosition:f="top",label:p,labelStyle:d,labelShowBg:h,labelBgStyle:k,labelBgPadding:S,labelBgBorderRadius:E,style:z,markerEnd:j,markerStart:L,interactionWidth:A}){let X,D,Y;const $=gr(n,r,a),I=gr(i,o,f),q=Math.abs(I.x-$.x),O=Math.max(50,q*.5);let H,C,y,v;switch(a){case"left":H=$.x-O,C=$.y;break;case"top":H=$.x,C=$.y-O;break;case"bottom":H=$.x,C=$.y+O;break;default:H=$.x+O,C=$.y;break}switch(f){case"right":y=I.x+O,v=I.y;break;case"top":y=I.x,v=I.y-O;break;case"bottom":y=I.x,v=I.y+O;break;default:y=I.x-O,v=I.y;break}X=`M ${n},${r} L ${$.x},${$.y} C ${H},${C} ${y},${v} ${I.x},${I.y} L ${i},${o}`;const N=.5,P=.5;return D=P*P*P*$.x+3*P*P*N*H+3*P*N*N*y+N*N*N*I.x,Y=P*P*P*$.y+3*P*P*N*C+3*P*N*N*v+N*N*N*I.y,T.jsx(sn,{id:t,path:X,labelX:D,labelY:Y,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:k,labelBgPadding:S,labelBgBorderRadius:E,style:z,markerEnd:j,markerStart:L,interactionWidth:A})});er.displayName="BezierEdge";function tr({sourceX:e,sourceY:t,targetX:n,targetY:r}){const i=`M ${e},${t}L ${n},${r}`,o=(e+n)/2,a=(t+r)/2;return[i,o,a,0,0]}function nr({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i="right",targetPosition:o="left",curvature:a=.25}){const f=Math.abs(n-e),p=Math.abs(r-t),d=Math.sqrt(f*f+p*p),h=Math.max(d*a,50);let k,S,E,z;switch(i){case"top":k=e,S=t-h;break;case"bottom":k=e,S=t+h;break;case"left":k=e-h,S=t;break;default:k=e+h,S=t;break}switch(o){case"top":E=n,z=r-h;break;case"bottom":E=n,z=r+h;break;case"right":E=n+h,z=r;break;default:E=n-h,z=r;break}const j=`M ${e},${t} C ${k},${S} ${E},${z} ${n},${r}`,L=.5,A=1-L,X=A*A*A*e+3*A*A*L*k+3*A*L*L*E+L*L*L*n,D=A*A*A*t+3*A*A*L*S+3*A*L*L*z+L*L*L*r;return[j,X,D,0,0]}function rr({sourceX:e,sourceY:t,targetX:n,targetY:r}){const i=Math.abs(n-e),o=Math.max(i*.5,50),a=e+o,f=n-o,p=`M ${e},${t} C ${a},${t} ${f},${r} ${n},${r}`,d=.5,h=.5,k=h*h*h*e+3*h*h*d*a+3*h*d*d*f+d*d*d*n,S=h*h*h*t+3*h*h*d*t+3*h*d*d*r+d*d*d*r;return[p,k,S,0,0]}function kn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i="right",targetPosition:o="left",borderRadius:a=5,offset:f=20}){const p=i==="left"||i==="right",d=Math.min(a,Math.abs(n-e)/2,Math.abs(r-t)/2);if(p){if(Math.abs(r-t)<1)return[`M ${e},${t} L ${n},${r}`,(e+n)/2,t,0,0];const E=(e+n)/2,z=r>t?1:-1;return[`M ${e},${t} L ${E-d},${t} Q ${E},${t} ${E},${t+z*d} L ${E},${r-z*d} Q ${E},${r} ${E+(n>E?d:-d)},${r} L ${n},${r}`,E,(t+r)/2,0,0]}const h=(t+r)/2,k=n>e?1:-1;return[`M ${e},${t} L ${e},${h-d} Q ${e},${h} ${e+k*d},${h} L ${n-k*d},${h} Q ${n},${h} ${n},${h+(r>h?d:-d)} L ${n},${r}`,(e+n)/2,h,0,0]}function bo({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[,i,o]=nr({sourceX:e,sourceY:t,targetX:n,targetY:r});return[i,o,0,0]}function wo({sourceX:e,sourceY:t,targetX:n,targetY:r}){return[(e+n)/2,(t+r)/2,0,0]}function Mo(e,t,n){const r=n.filter(o=>o.id!==e.id),i={...e,id:e.id,source:t.source,target:t.target,sourceHandle:t.sourceHandle??e.sourceHandle,targetHandle:t.targetHandle??e.targetHandle};return r.push(i),r}const Cn=160,En=60,tn=20,Mn=12,Sn=20;function yr(e,t,n){var a,f;const r=e.width||((a=e.measured)==null?void 0:a.width)||Cn,i=e.height||((f=e.measured)==null?void 0:f.height)||En,o=e._absolutePosition||e.position;if(e.handles&&e.handles.length>0){for(const p of e.handles)if(p.type===t&&(!n||p.id===n)){if(p.x!==void 0&&p.y!==void 0)return{x:o.x+p.x,y:o.y+p.y,dir:p.position||(t==="source"?"right":"left")};switch(p.position||(t==="source"?"right":"left")){case"top":return{x:o.x+r/2,y:o.y,dir:"top"};case"bottom":return{x:o.x+r/2,y:o.y+i,dir:"bottom"};case"left":return{x:o.x,y:o.y+i/2,dir:"left"};default:return{x:o.x+r,y:o.y+i/2,dir:"right"}}}}return t==="source"?{x:o.x+r,y:o.y+i/2,dir:"right"}:{x:o.x,y:o.y+i/2,dir:"left"}}function zn(e,t){switch(e.dir){case"right":return{x:e.x+t,y:e.y,dir:e.dir};case"left":return{x:e.x-t,y:e.y,dir:e.dir};case"bottom":return{x:e.x,y:e.y+t,dir:e.dir};case"top":return{x:e.x,y:e.y-t,dir:e.dir};default:return{x:e.x+t,y:e.y,dir:e.dir}}}function Ro(e,t,n,r,i,o,a,f){const p=Math.min(e,n),d=Math.max(e,n),h=Math.min(t,r),k=Math.max(t,r);if(d<=i||p>=i+a||k<=o||h>=o+f)return!1;const S=.5;if(e>i+S&&e<i+a-S&&t>o+S&&t<o+f-S||n>i+S&&n<i+a-S&&r>o+S&&r<o+f-S)return!0;const E=(e+n)/2,z=(t+r)/2;if(E>i+S&&E<i+a-S&&z>o+S&&z<o+f-S)return!0;const j=[[i,o],[i+a,o],[i+a,o+f],[i,o+f]];for(let L=0;L<4;L++)if(ko(e,t,n,r,j[L][0],j[L][1],j[(L+1)%4][0],j[(L+1)%4][1]))return!0;return!1}function ko(e,t,n,r,i,o,a,f){const p=(a-i)*(t-o)-(f-o)*(e-i),d=(a-i)*(r-o)-(f-o)*(n-i),h=(n-e)*(o-t)-(r-t)*(i-e),k=(n-e)*(f-t)-(r-t)*(a-e);return(p>0&&d<0||p<0&&d>0)&&(h>0&&k<0||h<0&&k>0)}function Kn(e,t,n,r,i){for(let o=0;o<i.length;o++){const a=i[o];if(Ro(e,t,n,r,a.x,a.y,a.w,a.h))return!1}return!0}function Co(e,t,n){for(let r=0;r<n.length;r++){const i=n[r];if(e>i.x&&e<i.x+i.w&&t>i.y&&t<i.y+i.h)return!0}return!1}function or(e,t){var r,i;const n=[];for(let o=0;o<e.length;o++){const a=e[o];if(a.hidden||t&&t.has(a.id)||a.type==="group")continue;const f=a._absolutePosition||a.position,p=a.width||((r=a.measured)==null?void 0:r.width)||Cn,d=a.height||((i=a.measured)==null?void 0:i.height)||En;n.push({id:a.id,x:f.x-tn,y:f.y-tn,w:p+2*tn,h:d+2*tn})}return n}function Br(e,t,n){if(Kn(e.x,e.y,t.x,t.y,n))return null;const r=new Set,i=new Set;r.add(e.x),r.add(t.x),i.add(e.y),i.add(t.y);const o=tn+5;e.dir==="right"?r.add(e.x+o):e.dir==="left"?r.add(e.x-o):e.dir==="top"?i.add(e.y-o):e.dir==="bottom"&&i.add(e.y+o),t.dir==="right"?r.add(t.x+o):t.dir==="left"?r.add(t.x-o):t.dir==="top"?i.add(t.y-o):t.dir==="bottom"&&i.add(t.y+o);for(let y=0;y<n.length;y++){const v=n[y];r.add(v.x),r.add(v.x+v.w),i.add(v.y),i.add(v.y+v.h)}const a=[...r].sort((y,v)=>y-v),f=[...i].sort((y,v)=>y-v),p=new Map,d=new Map;for(let y=0;y<a.length;y++)p.set(a[y],y);for(let y=0;y<f.length;y++)d.set(f[y],y);const h=a.length,k=f.length,S=(y,v)=>v*h+y,E=p.get(e.x),z=d.get(e.y),j=p.get(t.x),L=d.get(t.y);if(E===void 0||z===void 0||j===void 0||L===void 0)return null;const A=S(E,z),X=S(j,L),D=new Float64Array(h*k).fill(1/0),Y=new Float64Array(h*k).fill(1/0),$=new Int32Array(h*k).fill(-1),I=new Int8Array(h*k).fill(-1),q=new Uint8Array(h*k);D[A]=0,Y[A]=Math.abs(a[j]-e.x)+Math.abs(f[L]-e.y);const O=[A],H=15,C=[[1,0],[-1,0],[0,1],[0,-1]];for(;O.length>0;){let y=0;for(let te=1;te<O.length;te++)Y[O[te]]<Y[O[y]]&&(y=te);const v=O[y];if(O[y]=O[O.length-1],O.pop(),v===X){const te=[];let se=X;for(;se!==-1&&se!==A;){const he=se/h|0,ge=se%h;te.unshift({x:a[ge],y:f[he]}),se=$[se]}return te.unshift({x:e.x,y:e.y}),Eo(te,n)}if(q[v])continue;q[v]=1;const N=v/h|0,P=v%h,B=a[P],J=f[N],oe=I[v];for(let te=0;te<4;te++){const se=P+C[te][0],he=N+C[te][1];if(se<0||se>=h||he<0||he>=k)continue;const ge=S(se,he);if(q[ge])continue;const fe=a[se],ie=f[he];if(Co(fe,ie,n)||!Kn(B,J,fe,ie,n))continue;const Me=Math.abs(fe-B)+Math.abs(ie-J),ne=oe>=0&&oe!==te?H:0,le=D[v]+Me+ne;le<D[ge]&&($[ge]=v,I[ge]=te,D[ge]=le,Y[ge]=le+Math.abs(a[j]-fe)+Math.abs(f[L]-ie),O.push(ge))}}return null}function Eo(e,t){if(!e||e.length<=2)return e;const n=[e[0]];for(let r=1;r<e.length-1;r++){const i=n[n.length-1],o=e[r],a=e[r+1],f=Math.abs(i.x-o.x)<.5&&Math.abs(o.x-a.x)<.5,p=Math.abs(i.y-o.y)<.5&&Math.abs(o.y-a.y)<.5;(f||p)&&Kn(i.x,i.y,a.x,a.y,t)||n.push(o)}return n.push(e[e.length-1]),n}function So(e){const t=new Map,n=new Map;for(const i of e){const o=i._routedPoints;if(!(!o||o.length<2))for(let a=0;a<o.length-1;a++){const f=o[a],p=o[a+1];if(Math.abs(f.y-p.y)<.5){const d=Math.round(f.y*10)/10;t.has(d)||t.set(d,[]),t.get(d).push({edgeId:i.id,segIdx:a,x1:Math.min(f.x,p.x),x2:Math.max(f.x,p.x)})}else if(Math.abs(f.x-p.x)<.5){const d=Math.round(f.x*10)/10;n.has(d)||n.set(d,[]),n.get(d).push({edgeId:i.id,segIdx:a,y1:Math.min(f.y,p.y),y2:Math.max(f.y,p.y)})}}}const r=new Map;for(const i of e)i._routedPoints&&r.set(i.id,i._routedPoints.map(o=>({...o})));for(const[,i]of t){if(i.length<2)continue;const o=xr(i,"x1","x2");for(const a of o){if(a.length<2)continue;const f=(a.length-1)*Mn/2;for(let p=0;p<a.length;p++){const d=a[p],h=-f+p*Mn,k=r.get(d.edgeId);k&&(k[d.segIdx].y+=h,k[d.segIdx+1].y+=h)}}}for(const[,i]of n){if(i.length<2)continue;const o=xr(i,"y1","y2");for(const a of o){if(a.length<2)continue;const f=(a.length-1)*Mn/2;for(let p=0;p<a.length;p++){const d=a[p],h=-f+p*Mn,k=r.get(d.edgeId);k&&(k[d.segIdx].x+=h,k[d.segIdx+1].x+=h)}}}return e.map(i=>{const o=r.get(i.id);return o?{...i,_routedPoints:o}:i})}function xr(e,t,n){if(e.length<2)return[];const r=[...e].sort((a,f)=>a[t]-f[t]),i=[];let o=[r[0]];for(let a=1;a<r.length;a++){const f=o[o.length-1];r[a][t]<f[n]?o.push(r[a]):(o.length>1&&i.push(o),o=[r[a]])}return o.length>1&&i.push(o),i}function Nn(e,t=6,n=!1){if(!e||e.length<2)return null;if(n)return zo(e);const r=t;let i=`M ${e[0].x},${e[0].y}`;for(let o=1;o<e.length-1;o++){const a=e[o-1],f=e[o],p=e[o+1],d=Math.abs(f.x-a.x)+Math.abs(f.y-a.y),h=Math.abs(p.x-f.x)+Math.abs(p.y-f.y),k=Math.min(r,d/2,h/2);if(k>.5){const S=f.x-a.x,E=f.y-a.y,z=p.x-f.x,j=p.y-f.y,L=Math.sqrt(S*S+E*E)||1,A=Math.sqrt(z*z+j*j)||1;i+=` L ${f.x-S/L*k},${f.y-E/L*k}`,i+=` Q ${f.x},${f.y} ${f.x+z/A*k},${f.y+j/A*k}`}else i+=` L ${f.x},${f.y}`}return i+=` L ${e[e.length-1].x},${e[e.length-1].y}`,i}function zo(e){if(e.length===2)return`M ${e[0].x},${e[0].y} L ${e[1].x},${e[1].y}`;if(e.length===3)return`M ${e[0].x},${e[0].y} Q ${e[1].x},${e[1].y} ${e[2].x},${e[2].y}`;const t=.3;let n=`M ${e[0].x},${e[0].y}`;for(let r=0;r<e.length-1;r++){const i=e[r===0?0:r-1],o=e[r],a=e[r+1],f=e[r+2<e.length?r+2:e.length-1],p=o.x+(a.x-i.x)*t,d=o.y+(a.y-i.y)*t,h=a.x-(f.x-o.x)*t,k=a.y-(f.y-o.y)*t;n+=` C ${p},${d} ${h},${k} ${a.x},${a.y}`}return n}function In(e){if(!e||e.length<2)return{x:0,y:0};let t=0;for(let r=1;r<e.length;r++)t+=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);let n=t/2;for(let r=1;r<e.length;r++){const i=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);if(n<=i){const o=i>0?n/i:0;return{x:e[r-1].x+(e[r].x-e[r-1].x)*o,y:e[r-1].y+(e[r].y-e[r-1].y)*o}}n-=i}return{x:e[0].x,y:e[0].y}}function No(e,t){if(!e||!t||e.length===0||t.length===0)return t;const n={};for(const o of e)n[o.id]=o;const r=or(e,null),i=t.map(o=>{var I,q,O,H;const a=o.type||"default";if(a==="bezier"||a==="simplebezier"||a==="default")return o;const f=n[o.source],p=n[o.target];if(!f||!p||f.hidden||p.hidden)return o;const d=yr(f,"source",o.sourceHandle),h=yr(p,"target",o.targetHandle),k=zn(d,Sn),S=zn(h,Sn),E=5,z=r.filter(C=>C.id!==o.source&&C.id!==o.target),j=f._absolutePosition||f.position,L=f.width||((I=f.measured)==null?void 0:I.width)||Cn,A=f.height||((q=f.measured)==null?void 0:q.height)||En;z.push({id:o.source,x:j.x-E,y:j.y-E,w:L+2*E,h:A+2*E});const X=p._absolutePosition||p.position,D=p.width||((O=p.measured)==null?void 0:O.width)||Cn,Y=p.height||((H=p.measured)==null?void 0:H.height)||En;if(z.push({id:o.target,x:X.x-E,y:X.y-E,w:D+2*E,h:Y+2*E}),z.length===0)return o;const $=Br(k,S,z);return $&&$.length>=2?($.unshift({x:d.x,y:d.y}),$.push({x:h.x,y:h.y}),{...o,_routedPoints:$}):o});return So(i)}function Io(e,t,n,r,i,o,a,f){const p=or(a,f?new Set(f):null);if(p.length===0)return null;const d={x:e,y:t,dir:i||"right"},h={x:n,y:r,dir:o||"left"},k=zn(d,Sn),S=zn(h,Sn),E=Br(k,S,p);return E&&E.length>=2?(E.unshift({x:d.x,y:d.y}),E.push({x:h.x,y:h.y}),E):null}const sr=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,label:a,labelStyle:f,labelShowBg:p,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:k,style:S,markerEnd:E,markerStart:z,interactionWidth:j,routedPoints:L}){let A,X,D;if(L&&L.length>=2){A=Nn(L);const Y=In(L);X=Y.x,D=Y.y}else[A,X,D]=tr({sourceX:n,sourceY:r,targetX:i,targetY:o});return T.jsx(sn,{id:t,path:A,labelX:X,labelY:D,label:a,labelStyle:f,labelShowBg:p,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:k,style:S,markerEnd:E,markerStart:z,interactionWidth:j})});sr.displayName="StraightEdge";const ir=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:a="bottom",targetPosition:f="top",label:p,labelStyle:d,labelShowBg:h,labelBgStyle:k,labelBgPadding:S,labelBgBorderRadius:E,style:z,markerEnd:j,markerStart:L,pathOptions:A,interactionWidth:X,routedPoints:D}){let Y,$,I;if(D&&D.length>=2){Y=Nn(D);const q=In(D);$=q.x,I=q.y}else[Y,$,I]=kn({sourceX:n,sourceY:r,sourcePosition:a,targetX:i,targetY:o,targetPosition:f,borderRadius:A==null?void 0:A.borderRadius,offset:A==null?void 0:A.offset});return T.jsx(sn,{id:t,path:Y,labelX:$,labelY:I,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:k,labelBgPadding:S,labelBgBorderRadius:E,style:z,markerEnd:j,markerStart:L,interactionWidth:X})});ir.displayName="SmoothStepEdge";const $r=c.memo(function({id:t,...n}){var i;const r=c.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(i=n.pathOptions)==null?void 0:i.offset]);return T.jsx(ir,{...n,id:t,pathOptions:r})});$r.displayName="StepEdge";const ar=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:i,targetY:o,sourcePosition:a,targetPosition:f,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:k,labelBgPadding:S,labelBgBorderRadius:E,style:z,markerEnd:j,markerStart:L,interactionWidth:A,routedPoints:X}){let D,Y,$;if(X&&X.length>=2){D=Nn(X);const I=In(X);Y=I.x,$=I.y}else[D,Y,$]=rr({sourceX:n,sourceY:r,targetX:i,targetY:o});return T.jsx(sn,{id:t,path:D,labelX:Y,labelY:$,label:p,labelStyle:d,labelShowBg:h,labelBgStyle:k,labelBgPadding:S,labelBgBorderRadius:E,style:z,markerEnd:j,markerStart:L,interactionWidth:A})});ar.displayName="SimpleBezierEdge";const Po={input:Nr,output:Ir,group:Pr},To={bezier:er,straight:sr,simplebezier:ar},Lo=160,Bo=60;function $o(e){let t=!1;for(let n=0;n<e.length;n++){const r=e[n];if(!r.measured||r.measured.width==null||r.measured.height==null){t=!0;break}}return t?e.map(n=>{var r,i;return((r=n.measured)==null?void 0:r.width)!=null&&((i=n.measured)==null?void 0:i.height)!=null?n:{...n,measured:{width:n.width||Lo,height:n.height||Bo}}}):e}function jo({cards:e,nodes:t=[],edges:n=[],nodeTypes:r,edgeTypes:i,canvasNodeTypes:o,domNodeLimit:a=50,dark:f,gridSize:p,width:d="100%",height:h="420px",className:k="",style:S={},zoomMin:E,zoomMax:z,initialCamera:j,fitView:L,fitViewOptions:A,onNodesChange:X,onEdgesChange:D,onConnect:Y,onConnectStart:$,onConnectEnd:I,onNodeClick:q,onNodeDoubleClick:O,onNodeMouseEnter:H,onNodeMouseMove:C,onNodeMouseLeave:y,onNodeContextMenu:v,onNodeDragStart:N,onNodeDrag:P,onNodeDragStop:B,onEdgeClick:J,onEdgeDoubleClick:oe,onEdgeMouseEnter:te,onEdgeMouseMove:se,onEdgeMouseLeave:he,onEdgeContextMenu:ge,onPaneClick:fe,onPaneContextMenu:ie,onPaneMouseEnter:Me,onPaneMouseMove:ne,onPaneMouseLeave:le,onSelectionChange:Ee,onInit:et,onMoveStart:ye,onMove:Re,onMoveEnd:$e,onDelete:We,onBeforeDelete:Se,onError:tt,onDragOver:rt,onDrop:we,onDragEnter:Te,onDragLeave:Oe,nodesDraggable:je,nodesConnectable:Fe,elementsSelectable:Ze,multiSelectionKeyCode:Et,selectionOnDrag:an,selectionMode:St,connectionMode:cn,connectionRadius:ln,connectOnClick:un,isValidConnection:dn,defaultEdgeOptions:Zt,snapToGrid:xt,snapGrid:pt,deleteKeyCode:zt,panActivationKeyCode:Pn,panOnScroll:Tn,panOnScrollMode:ot,panOnScrollSpeed:cr,zoomOnScroll:Ln,zoomOnDoubleClick:Bn,zoomOnPinch:Nt,preventScrolling:It,translateExtent:$n,nodeExtent:jn,autoPanOnNodeDrag:An,autoPanOnConnect:wt,autoPanSpeed:me,edgesReconnectable:Pt,elevateNodesOnSelect:Le,elevateEdgesOnSelect:ue,noDragClassName:mt,noPanClassName:K,onSelectionDragStart:ze,onSelectionDrag:fn,onSelectionDragStop:Tt,edgeRouting:Lt=!0,onHudUpdate:Bt,onNodesProcessed:Dn,showHud:Ye=!0,showHint:Ue=!0,hintText:$t="Drag to pan · Scroll to zoom",children:st,...hn}){const[Je,gn]=c.useState({wx:0,wy:0,zoom:"1.00"}),yn=c.useRef(null),Gt=c.useRef(null),xn=c.useCallback(W=>{gn(W),Bt==null||Bt(W)},[Bt]),vt=c.useMemo(()=>({...Po,...r}),[r]),it=c.useMemo(()=>({...To,...i}),[i]),Ke=c.useMemo(()=>$o(t),[t]),[Z,at]=c.useState(()=>new Set),jt=c.useRef(Z);jt.current=Z;const At=c.useCallback(W=>{at(xe=>{const V=new Set(xe);return V.add(W),V})},[]),Dt=c.useCallback(W=>{at(xe=>{const V=new Set(xe);return V.delete(W),V})},[]),Ht=c.useCallback(W=>{at(xe=>{const V=new Set(xe);return V.has(W)?V.delete(W):V.add(W),V})},[]),Ve=c.useMemo(()=>Ke.filter(W=>W.type&&vt[W.type]),[Ke,vt]),_t=c.useMemo(()=>n.filter(W=>W.type&&it[W.type]),[n,it]),[Wt,Ft]=c.useState(()=>new Set),Yt=c.useRef(new Set),ke=c.useMemo(()=>{const W=new Set(Wt);for(const V of Z)W.add(V);for(const V of Ve)(V.selected||V.dragging)&&W.add(V.id);const xe=Yt.current;if(xe.size===W.size){let V=!0;for(const Ne of W)if(!xe.has(Ne)){V=!1;break}if(V)return xe}return Yt.current=W,W},[Ve,Z,Wt]),ht=c.useMemo(()=>{if(a===0)return[];const W=Ke.filter(xe=>ke.has(xe.id));return W.sort((xe,V)=>{const Ne=xe.type==="group"||!xe.parentId&&W.some(Ie=>Ie.parentId===xe.id),He=V.type==="group"||!V.parentId&&W.some(Ie=>Ie.parentId===V.id);return Ne&&!He?-1:!Ne&&He?1:0})},[Ke,ke,a]),_e=c.useMemo(()=>t.map(W=>ke.has(W.id)?{...W,_customRendered:!0}:W),[t,ke]),Hn=c.useMemo(()=>n.map(W=>W.type&&it[W.type]?{...W,_customRendered:!0}:W),[n,it]),{wrapRef:gt,canvasRef:Xt,canvasReady:ct,onPointerDown:bt,onPointerMove:pn,onPointerUp:Be,store:ae}=Mr({cards:e,nodes:_e,edges:Hn,dark:f,gridSize:p,zoomMin:E,zoomMax:z,initialCamera:j,fitView:L,fitViewOptions:A,onHudUpdate:xn,onNodesProcessed:Dn,onNodesChange:X,onEdgesChange:D,onConnect:Y,onConnectStart:$,onConnectEnd:I,onNodeClick:q,onNodeDoubleClick:O,onNodeMouseEnter:H,onNodeMouseMove:C,onNodeMouseLeave:y,onNodeContextMenu:v,onNodeDragStart:N,onNodeDrag:P,onNodeDragStop:B,onEdgeClick:J,onEdgeDoubleClick:oe,onEdgeMouseEnter:te,onEdgeMouseMove:se,onEdgeMouseLeave:he,onEdgeContextMenu:ge,onPaneClick:fe,onPaneContextMenu:ie,onPaneMouseEnter:Me,onPaneMouseMove:ne,onPaneMouseLeave:le,onSelectionChange:Ee,onInit:et,onMoveStart:ye,onMove:Re,onMoveEnd:$e,onDelete:We,onBeforeDelete:Se,onError:tt,nodesDraggable:je,nodesConnectable:Fe,elementsSelectable:Ze,multiSelectionKeyCode:Et,selectionOnDrag:an,selectionMode:St,connectionMode:cn,connectionRadius:ln,connectOnClick:un,isValidConnection:dn,defaultEdgeOptions:Zt,snapToGrid:xt,snapGrid:pt,deleteKeyCode:zt,panActivationKeyCode:Pn,panOnScroll:Tn,panOnScrollMode:ot,panOnScrollSpeed:cr,zoomOnScroll:Ln,zoomOnDoubleClick:Bn,zoomOnPinch:Nt,preventScrolling:It,translateExtent:$n,nodeExtent:jn,autoPanOnNodeDrag:An,autoPanOnConnect:wt,autoPanSpeed:me,edgesReconnectable:Pt,elevateNodesOnSelect:Le,elevateEdgesOnSelect:ue,noDragClassName:mt,noPanClassName:K,onSelectionDragStart:ze,onSelectionDrag:fn,onSelectionDragStop:Tt,edgeRouting:Lt});c.useEffect(()=>{if(a===0||!Ve.length)return;let W;const xe=()=>{const V=ae.cameraRef.current,Ne=ae.wrapRef.current;if(!Ne)return;const He=Ne.clientWidth,Ie=Ne.clientHeight,u=(-V.x+He/2)/V.zoom,b=(-V.y+Ie/2)/V.zoom;let l=Z.size;for(const w of Ve)(w.selected||w.dragging)&&l++;const x=Math.max(0,a-l);if(x===0)Ft(w=>w.size===0?w:new Set);else{const w=new Set(Z);for(const R of Ve)(R.selected||R.dragging)&&w.add(R.id);const m=[];for(let R=0;R<Ve.length;R++){const M=Ve[R];if(w.has(M.id))continue;const F=M._absolutePosition||M.position,_=F.x+(M.width||160)/2-u,U=F.y+(M.height||60)/2-b;m.push({id:M.id,dist:_*_+U*U})}m.sort((R,M)=>R.dist-M.dist);const g=new Set;for(let R=0;R<Math.min(x,m.length);R++)g.add(m[R].id);Ft(R=>{if(R.size!==g.size)return g;for(const M of g)if(!R.has(M))return g;return R})}};return xe(),W=setInterval(xe,500),()=>clearInterval(W)},[Ve,Z,a,ae]);const Ot=c.useRef(new Set);c.useEffect(()=>{if(!o||!ae.workerRef.current)return;let W=!1;async function xe(Ne){const He=new Blob([Ne],{type:"image/svg+xml"}),Ie=URL.createObjectURL(He),u=new Image;return u.src=Ie,await u.decode(),URL.revokeObjectURL(Ie),createImageBitmap(u)}async function V(){var b,l,x;const Ne={},He=[],Ie={},u={};for(const[w,m]of Object.entries(o)){if(typeof m=="function"){Ie[w]=m;continue}if(typeof m=="object"&&m!==null&&!(m instanceof ImageBitmap)&&!(m instanceof HTMLImageElement)&&!(m instanceof HTMLCanvasElement)&&("fill"in m||"stroke"in m||"title"in m||"accent"in m)){u[w]=m;continue}try{let g;m instanceof ImageBitmap?g=m:typeof m=="string"?g=await xe(m):m instanceof HTMLImageElement?g=await createImageBitmap(m):m instanceof HTMLCanvasElement&&(g=await createImageBitmap(m)),g&&!W&&(Ne[w]=g,He.push(g))}catch(g){console.warn(`[InfiniteCanvas] Failed to convert canvasNodeType "${w}":`,g)}}if(!W&&Object.keys(Ne).length>0&&((b=ae.workerRef.current)==null||b.postMessage({type:"nodeTypeBitmaps",data:{bitmaps:Ne}},He)),!W&&Object.keys(u).length>0&&((l=ae.workerRef.current)==null||l.postMessage({type:"nodeTypeConfigs",data:{configs:u}})),!W&&Object.keys(Ie).length>0){const w=new Map,m={},g={},R=[];let M=Ot.current.size;for(const F of t){const _=Ie[F.type];if(_)try{const U=_(F.data);if(!U)continue;let Q=w.get(U);if(!Q&&(Q="bmp_"+M++,w.set(U,Q),!Ot.current.has(U))){const be=await xe(U);if(W)return;m[Q]=be,R.push(be),Ot.current.add(U)}g[F.id]=Q}catch(U){console.warn(`[InfiniteCanvas] canvasNodeType fn error for node "${F.id}":`,U)}}W||(x=ae.workerRef.current)==null||x.postMessage({type:"nodeBitmaps",data:{cache:m,keys:g}},R)}}return V(),()=>{W=!0}},[o,t,ae.workerRef]);const Mt=c.useContext(Ct),Rt=Mt&&typeof Mt.getState=="function";c.useEffect(()=>{Rt&&queueMicrotask(()=>{Mt.setState({nodes:Ke,edges:n,nodesRef:ae.nodesRef,edgesRef:ae.edgesRef,onNodesChangeRef:ae.onNodesChangeRef,onEdgesChangeRef:ae.onEdgesChangeRef,cameraRef:ae.cameraRef,wrapRef:ae.wrapRef,workerRef:ae.workerRef})})},[Rt,Ke,n,ae,Mt]);const lt=c.useMemo(()=>({...ae,edgeLabelContainerRef:yn,viewportPortalRef:Gt,pinNode:At,unpinNode:Dt,togglePinNode:Ht,get pinnedNodeIds(){return jt.current},get nodes(){return Ke},get edges(){return n},get viewport(){return ae.cameraRef.current},get minZoom(){return ae.zoomMin||.1},get maxZoom(){return ae.zoomMax||5},get domNode(){return ae.wrapRef.current},get width(){var W;return((W=ae.wrapRef.current)==null?void 0:W.clientWidth)||0},get height(){var W;return((W=ae.wrapRef.current)==null?void 0:W.clientHeight)||0}}),[ae,Ke,n,At,Dt,Ht]),Ut=c.useRef(null),ve=c.useRef(null),ut=c.useRef(null),dt=c.useRef(null),mn=c.useRef(null);c.useEffect(()=>{let W;const xe=()=>{const V=ae.cameraRef.current,Ne=`translate(${V.x}px, ${V.y}px) scale(${V.zoom})`,He=`translate(${V.x}, ${V.y}) scale(${V.zoom})`;Ut.current&&(Ut.current.style.transform=Ne),ve.current&&ve.current.setAttribute("transform",He),ut.current&&(ut.current.style.transform=Ne),dt.current&&(dt.current.style.transform=Ne);const Ie=gt.current;if(Ie){const u=V.zoom<.15?"lod-minimal":V.zoom<.35?"lod-reduced":null;u!==mn.current&&(Ie.classList.remove("lod-minimal","lod-reduced"),u&&Ie.classList.add(u),mn.current=u)}W=requestAnimationFrame(xe)};return W=requestAnimationFrame(xe),()=>cancelAnimationFrame(W)},[ae]);const[Qt,_n]=c.useState(null);c.useEffect(()=>{if(!ht.length)return;let W;const xe=()=>{var m,g;const V=ae.cameraRef.current,Ne=ae.wrapRef.current;if(!Ne){W=requestAnimationFrame(xe);return}const He=Ne.getBoundingClientRect(),Ie=200,u=-V.x/V.zoom-Ie,b=-V.y/V.zoom-Ie,l=(He.width-V.x)/V.zoom+Ie,x=(He.height-V.y)/V.zoom+Ie,w=new Set;for(const R of ht){const M=R._absolutePosition||R.position,F=R.width||((m=R.measured)==null?void 0:m.width)||200,_=R.height||((g=R.measured)==null?void 0:g.height)||100;M.x+F>=u&&M.x<=l&&M.y+_>=b&&M.y<=x&&w.add(R.id)}_n(R=>{if(!R||R.size!==w.size)return w;for(const M of w)if(!R.has(M))return w;return R}),W=requestAnimationFrame(xe)};return W=requestAnimationFrame(xe),()=>cancelAnimationFrame(W)},[ht,ae]);const vn=c.useMemo(()=>Qt?ht.filter(W=>Qt.has(W.id)):ht,[ht,Qt]),Wn=ht.length>0,Fn=_t.length>0;return T.jsx(Ct.Provider,{value:lt,children:T.jsxs("div",{ref:gt,className:`ric-wrap ${k}`,style:{width:d,height:h,...S},onPointerDown:bt,onPointerMove:pn,onPointerUp:Be,onDragOver:rt,onDrop:we,onDragEnter:Te,onDragLeave:Oe,tabIndex:0,children:[T.jsx("canvas",{ref:Xt,className:"ric-canvas"}),!ct&&T.jsx("div",{className:"ric-loader",children:T.jsx("div",{className:"ric-spinner"})}),Fn&&T.jsx("svg",{className:"ric-edges-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:T.jsx("g",{ref:ve,children:_t.map(W=>T.jsx(yo,{edge:W,edgeType:it[W.type],nodes:t,reconnectable:Pt},W.id))})}),Wn&&T.jsx("div",{ref:Ut,className:"ric-nodes-overlay",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:10},children:vn.map(W=>T.jsx(uo,{node:W,nodeType:vt[W.type]},W.id))}),T.jsx("div",{ref:W=>{yn.current=W,ut.current=W},className:"ric-edge-labels",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:5}}),T.jsx("div",{ref:W=>{Gt.current=W,dt.current=W},className:"ric-viewport-portal",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:6}}),Ue&&T.jsx("div",{className:"ric-hint",children:$t}),Ye&&T.jsxs("div",{className:"ric-info",children:["world: (",Je.wx,", ",Je.wy,")   zoom: ",Je.zoom,"x",Je.nodeCount>0&&T.jsxs(T.Fragment,{children:["   nodes: ",Je.nodeCount]}),Je.edgeCount>0&&T.jsxs(T.Fragment,{children:["   edges: ",Je.edgeCount]})]}),T.jsx(Sr,{selectionKeyCode:Et||"Shift",selectionMode:St||"partial"}),st]})})}function Ao({children:e}){const t=c.useRef(null);return t.current||(t.current=ao()),T.jsx(Ct.Provider,{value:t.current,children:e})}function jr(e,t){const n=[],r=new Map,i=[];for(const o of e)if(o.type==="add")i.push(o);else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const a=r.get(o.id);a?a.push(o):r.set(o.id,[o])}for(const o of t){const a=r.get(o.id);if(!a){n.push(o);continue}if(a[0].type==="remove")continue;if(a[0].type==="replace"){n.push({...a[0].item});continue}const f={...o};for(const p of a)Do(p,f);n.push(f)}for(const o of i)o.index!==void 0?n.splice(o.index,0,{...o.item}):n.push({...o.item});return n}function Do(e,t){switch(e.type){case"select":t.selected=e.selected;break;case"position":e.position!==void 0&&(t.position=e.position),e.dragging!==void 0&&(t.dragging=e.dragging);break;case"dimensions":e.dimensions!==void 0&&(t.measured={...e.dimensions},(e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height)),e.handleBounds!==void 0&&(t.handleBounds=e.handleBounds);break}}function Ar(e,t){return jr(e,t)}function Dr(e,t){return jr(e,t)}function Ho(e,t){return!e.source||!e.target?(console.warn("addEdge: source and target are required"),t):t.some(r=>r.source===e.source&&r.target===e.target&&(r.sourceHandle||null)===(e.sourceHandle||null)&&(r.targetHandle||null)===(e.targetHandle||null))?t:[...t,{id:e.id||`e-${e.source}-${e.target}`,...e}]}function _o(e){const[t,n]=c.useState(e),r=c.useCallback(i=>n(o=>Ar(i,o)),[]);return[t,n,r]}function Wo(e){const[t,n]=c.useState(e),r=c.useCallback(i=>n(o=>Dr(i,o)),[]);return[t,n,r]}function Hr(){const e=Rr(),t=c.useCallback(()=>typeof e.getState=="function"?e.getState():e,[e]),n=c.useCallback(()=>[...t().nodesRef.current],[t]),r=c.useCallback(()=>[...t().edgesRef.current],[t]),i=c.useCallback(C=>t().nodesRef.current.find(y=>y.id===C),[t]),o=c.useCallback(C=>t().edgesRef.current.find(y=>y.id===C),[t]),a=c.useCallback(C=>{var y,v,N,P;if(typeof C=="function"){const B=C(t().nodesRef.current);(v=(y=t().onNodesChangeRef).current)==null||v.call(y,[...t().nodesRef.current.map(J=>({id:J.id,type:"remove"})),...B.map(J=>({type:"add",item:J}))])}else(P=(N=t().onNodesChangeRef).current)==null||P.call(N,[...t().nodesRef.current.map(B=>({id:B.id,type:"remove"})),...C.map(B=>({type:"add",item:B}))])},[t]),f=c.useCallback(C=>{var y,v,N,P;if(typeof C=="function"){const B=C(t().edgesRef.current);(v=(y=t().onEdgesChangeRef).current)==null||v.call(y,[...t().edgesRef.current.map(J=>({id:J.id,type:"remove"})),...B.map(J=>({type:"add",item:J}))])}else(P=(N=t().onEdgesChangeRef).current)==null||P.call(N,[...t().edgesRef.current.map(B=>({id:B.id,type:"remove"})),...C.map(B=>({type:"add",item:B}))])},[t]),p=c.useCallback(C=>{var v,N;const y=Array.isArray(C)?C:[C];(N=(v=t().onNodesChangeRef).current)==null||N.call(v,y.map(P=>({type:"add",item:P})))},[t]),d=c.useCallback(C=>{var v,N;const y=Array.isArray(C)?C:[C];(N=(v=t().onEdgesChangeRef).current)==null||N.call(v,y.map(P=>({type:"add",item:P})))},[t]),h=c.useCallback(({nodes:C=[],edges:y=[]})=>{if(C.length&&t().onNodesChangeRef.current){t().onNodesChangeRef.current(C.map(N=>({id:N.id,type:"remove"})));const v=br(C,t().edgesRef.current);v.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(v.map(N=>({id:N.id,type:"remove"})))}y.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(y.map(v=>({id:v.id,type:"remove"})))},[t]),k=c.useCallback(()=>{const C=t().cameraRef.current;return{x:C.x,y:C.y,zoom:C.zoom}},[t]),S=c.useRef(null),E=c.useCallback((C,y)=>{if(S.current&&cancelAnimationFrame(S.current),!y||y<=0){t().cameraRef.current={...C},t().sendCamera();return}const v={...t().cameraRef.current},N=performance.now(),P=B=>{const J=B-N,oe=Math.min(J/y,1),te=1-Math.pow(1-oe,3);t().cameraRef.current={x:v.x+(C.x-v.x)*te,y:v.y+(C.y-v.y)*te,zoom:v.zoom+(C.zoom-v.zoom)*te},t().sendCamera(),oe<1&&(S.current=requestAnimationFrame(P))};S.current=requestAnimationFrame(P)},[t]),z=c.useCallback((C,y)=>{const v={x:C.x??t().cameraRef.current.x,y:C.y??t().cameraRef.current.y,zoom:C.zoom??t().cameraRef.current.zoom};E(v,y==null?void 0:y.duration)},[t,E]),j=c.useCallback(()=>t().cameraRef.current.zoom,[t]),L=c.useCallback(C=>{const y=t().cameraRef.current,v=t().wrapRef.current;if(!v)return;const N=v.getBoundingClientRect(),P=N.width/2,B=N.height/2,J=1.2,oe={x:P-(P-y.x)*J,y:B-(B-y.y)*J,zoom:Math.min(t().zoomMax,y.zoom*J)};E(oe,C==null?void 0:C.duration)},[t,E]),A=c.useCallback(C=>{const y=t().cameraRef.current,v=t().wrapRef.current;if(!v)return;const N=v.getBoundingClientRect(),P=N.width/2,B=N.height/2,J=1/1.2,oe={x:P-(P-y.x)*J,y:B-(B-y.y)*J,zoom:Math.max(t().zoomMin,y.zoom*J)};E(oe,C==null?void 0:C.duration)},[t,E]),X=c.useCallback((C,y)=>{const v=t().cameraRef.current,N=t().wrapRef.current;if(!N)return;const P=N.getBoundingClientRect(),B=P.width/2,J=P.height/2,oe=Math.min(t().zoomMax,Math.max(t().zoomMin,C)),te=oe/v.zoom,se={x:B-(B-v.x)*te,y:J-(J-v.y)*te,zoom:oe};E(se,y==null?void 0:y.duration)},[t,E]),D=c.useCallback((C={})=>{const y=t().nodesRef.current;if(!y.length)return;const v=t().wrapRef.current;if(!v)return;const N=v.getBoundingClientRect(),P=C.padding??.1,B=C.nodes?y.filter(te=>C.nodes.some(se=>se.id===te.id)):y;if(!B.length)return;const J=Rn(B),oe=qt(J,N.width,N.height,P);C.maxZoom&&(oe.zoom=Math.min(oe.zoom,C.maxZoom)),C.minZoom&&(oe.zoom=Math.max(oe.zoom,C.minZoom)),E(oe,C.duration)},[t,E]),Y=c.useCallback((C,y={})=>{const v=t().wrapRef.current;if(!v)return;const N=v.getBoundingClientRect(),P=y.padding??.1,B=qt(C,N.width,N.height,P);y.maxZoom&&(B.zoom=Math.min(B.zoom,y.maxZoom)),y.minZoom&&(B.zoom=Math.max(B.zoom,y.minZoom)),E(B,y.duration)},[t,E]),$=c.useCallback((C,y,v={})=>{const N=t().wrapRef.current;if(!N)return;const P=N.getBoundingClientRect(),B=v.zoom??t().cameraRef.current.zoom,J={x:P.width/2-C*B,y:P.height/2-y*B,zoom:B};E(J,v.duration)},[t,E]),I=c.useCallback(()=>({nodes:[...t().nodesRef.current],edges:[...t().edgesRef.current],viewport:{...t().cameraRef.current}}),[t]),q=c.useCallback(C=>t().screenToWorld(C.x,C.y),[t]),O=c.useCallback(C=>{const y=t().cameraRef.current,v=t().wrapRef.current;if(!v)return{x:0,y:0};const N=v.getBoundingClientRect();return{x:C.x*y.zoom+y.x+N.left,y:C.y*y.zoom+y.y+N.top}},[t]),H=c.useCallback((C,y)=>{var P,B;const v=t().nodesRef.current.find(J=>J.id===C);if(!v)return;const N=typeof y=="function"?y(v.data):{...v.data,...y};(B=(P=t().onNodesChangeRef).current)==null||B.call(P,[{id:C,type:"replace",item:{...v,data:N}}])},[t]);return{getNodes:n,getEdges:r,getNode:i,getEdge:o,setNodes:a,setEdges:f,addNodes:p,addEdges:d,deleteElements:h,getViewport:k,setViewport:z,getZoom:j,zoomIn:L,zoomOut:A,zoomTo:X,fitView:D,fitBounds:Y,setCenter:$,screenToFlowPosition:q,flowToScreenPosition:O,updateNodeData:H,toObject:I}}function Fo(){return Pe().nodes}function Yo(){return Pe().edges}function Xo(){return Pe().viewport}function Oo(){return Pe().connection}function Uo(e){const t=Pe(),n=Array.isArray(e)?e:[e];return c.useMemo(()=>n.map(r=>{const i=t.nodes.find(o=>o.id===r);return i?{id:i.id,type:i.type,data:i.data}:null}).filter(Boolean),[t.nodes,...n])}function qo(e){const t=Pe();return c.useMemo(()=>t.edges.filter(n=>n.source===e||n.target===e),[t.edges,e])}function Zo({nodeId:e,type:t,handleId:n}){const r=Pe();return c.useMemo(()=>r.edges.filter(i=>t==="source"?i.source===e&&(n?i.sourceHandle===n:!0):i.target===e&&(n?i.targetHandle===n:!0)),[r.edges,e,t,n])}function Go({onChange:e,onStart:t,onEnd:n}){const r=Pe(),i=c.useRef(e),o=c.useRef(t),a=c.useRef(n);c.useEffect(()=>{i.current=e},[e]),c.useEffect(()=>{o.current=t},[t]),c.useEffect(()=>{a.current=n},[n]),c.useEffect(()=>{const f=p=>{var d;(d=i.current)==null||d.call(i,{x:p.x,y:p.y,zoom:p.zoom})};return r.viewportListeners.add(f),()=>r.viewportListeners.delete(f)},[s])}function Qo({onChange:e}){const t=Pe(),n=c.useRef(e);c.useEffect(()=>{n.current=e},[e]),c.useEffect(()=>{const r=i=>{var o;(o=n.current)==null||o.call(n,i)};return t.selectionListeners.add(r),()=>t.selectionListeners.delete(r)},[s])}function Jo(e){const[t,n]=c.useState(!1),r=Array.isArray(e)?e:[e];return c.useEffect(()=>{const i=a=>{r.includes(a.key)&&n(!0)},o=a=>{r.includes(a.key)&&n(!1)};return window.addEventListener("keydown",i),window.addEventListener("keyup",o),()=>{window.removeEventListener("keydown",i),window.removeEventListener("keyup",o)}},[r.join(",")]),t}function Ko(){const e=Pe();return c.useCallback(t=>{var n;(n=e.workerRef.current)==null||n.postMessage({type:"nodes",data:{nodes:[...s().nodesRef.current]}})},[s])}const Vo=e=>{var t;return((t=e.nodes)==null?void 0:t.length)>0};function es(e={}){return Pe(Vo)}function ts(e){const t=Pe();return c.useMemo(()=>t.nodes.find(n=>n.id===e)||void 0,[t.nodes,e])}function ns(e,t){return Pe(e,t)}function rs(){return Rr()}function os({maxHistorySize:e=100}={}){const t=Pe(),n=c.useRef([]),r=c.useRef([]),[,i]=c.useState(0),o=c.useRef(null),a=c.useCallback(()=>{const d={nodes:s().nodesRef.current.map(h=>({...h,data:{...h.data}})),edges:s().edgesRef.current.map(h=>({...h}))};o.current&&JSON.stringify(o.current.nodes.map(h=>h.id))===JSON.stringify(d.nodes.map(h=>h.id))&&JSON.stringify(o.current.edges.map(h=>h.id))===JSON.stringify(d.edges.map(h=>h.id))||(n.current.push(d),n.current.length>e&&n.current.shift(),r.current=[],o.current=d,i(h=>h+1))},[t,e]),f=c.useCallback(()=>{var h,k,S,E;const d=n.current.pop();d&&(r.current.push({nodes:s().nodesRef.current.map(z=>({...z,data:{...z.data}})),edges:s().edgesRef.current.map(z=>({...z}))}),(k=(h=s().onNodesChangeRef).current)==null||k.call(h,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...d.nodes.map(z=>({type:"add",item:z}))]),(E=(S=s().onEdgesChangeRef).current)==null||E.call(S,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...d.edges.map(z=>({type:"add",item:z}))]),o.current=d,i(z=>z+1))},[s]),p=c.useCallback(()=>{var h,k,S,E;const d=r.current.pop();d&&(n.current.push({nodes:s().nodesRef.current.map(z=>({...z,data:{...z.data}})),edges:s().edgesRef.current.map(z=>({...z}))}),(k=(h=s().onNodesChangeRef).current)==null||k.call(h,[...s().nodesRef.current.map(z=>({id:z.id,type:"remove"})),...d.nodes.map(z=>({type:"add",item:z}))]),(E=(S=s().onEdgesChangeRef).current)==null||E.call(S,[...s().edgesRef.current.map(z=>({id:z.id,type:"remove"})),...d.edges.map(z=>({type:"add",item:z}))]),o.current=d,i(z=>z+1))},[s]);return{undo:f,redo:p,takeSnapshot:a,canUndo:n.current.length>0,canRedo:r.current.length>0}}function ss(e){const t=c.useRef(e);return c.useEffect(()=>{t.current=e},[e]),c.useCallback(n=>r=>{const i=t.current(r);i!==!1&&i!=null&&n(Array.isArray(i)?i:r)},[])}function is(e){const t=c.useRef(e);return c.useEffect(()=>{t.current=e},[e]),c.useCallback(n=>r=>{const i=t.current(r);i!==!1&&i!=null&&n(Array.isArray(i)?i:r)},[])}const Un=160,qn=60;function as({width:e=200,height:t=150,nodeColor:n="#3b82f6",nodeStrokeColor:r="#fff",maskColor:i="rgba(0,0,0,0.1)",style:o={},className:a=""}){const f=Pe(),p=c.useRef(null),d=c.useRef(null),h=c.useCallback(()=>{const k=p.current;if(!k)return;const S=k.getContext("2d"),E=window.devicePixelRatio||1;k.width=e*E,k.height=t*E,S.scale(E,E),S.clearRect(0,0,e,t);const z=f.nodesRef.current;if(!z.length)return;let j=1/0,L=1/0,A=-1/0,X=-1/0;for(const y of z){const v=y.width||Un,N=y.height||qn;y.position.x<j&&(j=y.position.x),y.position.y<L&&(L=y.position.y),y.position.x+v>A&&(A=y.position.x+v),y.position.y+N>X&&(X=y.position.y+N)}const D=40;j-=D,L-=D,A+=D,X+=D;const Y=A-j,$=X-L,I=Math.min(e/Y,t/$),q=(e-Y*I)/2,O=(t-$*I)/2;for(const y of z){if(y.hidden)continue;const v=y.width||Un,N=y.height||qn,P=(y.position.x-j)*I+q,B=(y.position.y-L)*I+O,J=v*I,oe=N*I;S.fillStyle=y.selected?"#f59e0b":typeof n=="function"?n(y):n,S.fillRect(P,B,Math.max(J,2),Math.max(oe,2))}const H=f.cameraRef.current,C=f.wrapRef.current;if(C){const y=C.getBoundingClientRect(),v=-H.x/H.zoom,N=-H.y/H.zoom,P=y.width/H.zoom,B=y.height/H.zoom;S.fillStyle=i,S.fillRect(0,0,e,t);const J=(v-j)*I+q,oe=(N-L)*I+O,te=P*I,se=B*I;S.clearRect(J,oe,te,se);for(const he of z){if(he.hidden)continue;const ge=he.width||Un,fe=he.height||qn,ie=(he.position.x-j)*I+q,Me=(he.position.y-L)*I+O;S.fillStyle=he.selected?"#f59e0b":typeof n=="function"?n(he):n,S.fillRect(ie,Me,Math.max(ge*I,2),Math.max(fe*I,2))}S.strokeStyle="#3b82f6",S.lineWidth=1.5,S.strokeRect(J,oe,te,se)}},[f,e,t,n,r,i]);return c.useEffect(()=>{let k=!0;function S(){k&&(h(),d.current=requestAnimationFrame(S))}const E=setInterval(()=>{cancelAnimationFrame(d.current),d.current=requestAnimationFrame(S)},66);return h(),()=>{k=!1,clearInterval(E),cancelAnimationFrame(d.current)}},[h]),T.jsx("canvas",{ref:p,className:`ric-minimap ${a}`,style:{position:"absolute",bottom:30,right:10,width:e,height:t,borderRadius:4,border:"1px solid rgba(0,0,0,0.1)",background:"rgba(255,255,255,0.9)",pointerEvents:"none",...o}})}function cs(){return T.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[T.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),T.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function ls(){return T.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:T.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function us(){return T.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:T.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}function ds(){return T.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[T.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),T.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function fs(){return T.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[T.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),T.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})}function nn({children:e,className:t="",...n}){return T.jsx("button",{className:`ric-controls-button ${t}`,style:gs,...n,children:e})}function hs({showZoom:e=!0,showFitView:t=!0,showInteractive:n=!1,fitViewOptions:r,onZoomIn:i,onZoomOut:o,onFitView:a,onInteractiveChange:f,position:p="bottom-left",orientation:d="vertical",style:h={},className:k="","aria-label":S="Canvas controls",children:E}){const z=Pe(),{zoomIn:j,zoomOut:L,fitView:A,getZoom:X}=Hr(),[D,Y]=c.useState(!0),$=X()<=z.zoomMin,I=X()>=z.zoomMax,q=c.useCallback(()=>{j(),i==null||i()},[j,i]),O=c.useCallback(()=>{L(),o==null||o()},[L,o]),H=c.useCallback(()=>{A(r||{padding:.1}),a==null||a()},[A,r,a]),C=c.useCallback(()=>{const v=!D;Y(v),f==null||f(v)},[D,f]),y={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:30,left:10},"bottom-right":{bottom:30,right:10},"bottom-center":{bottom:30,left:"50%",transform:"translateX(-50%)"}}[p]||{bottom:30,left:10};return T.jsxs("div",{className:`ric-controls ${k}`,style:{position:"absolute",display:"flex",flexDirection:d==="horizontal"?"row":"column",gap:2,zIndex:5,...y,...h},role:"toolbar","aria-label":S,children:[e&&T.jsxs(T.Fragment,{children:[T.jsx(nn,{onClick:q,disabled:I,title:"Zoom in","aria-label":"Zoom in",className:"ric-controls-zoomin",children:T.jsx(cs,{})}),T.jsx(nn,{onClick:O,disabled:$,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:T.jsx(ls,{})})]}),t&&T.jsx(nn,{onClick:H,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:T.jsx(us,{})}),n&&T.jsx(nn,{onClick:C,title:D?"Lock interactivity":"Unlock interactivity","aria-label":D?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:D?T.jsx(fs,{}):T.jsx(ds,{})}),E]})}const gs={width:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid rgba(0,0,0,0.12)",borderRadius:4,background:"#fff",cursor:"pointer",fontSize:16,lineHeight:1,color:"#333",padding:0},ys=c.memo(hs);function xs({variant:e="lines",gap:t=40,size:n=1,color:r,style:i={},className:o=""}){const a=Pe();return a.workerRef.current&&a.workerRef.current.postMessage({type:"background",data:{variant:e,gap:t,size:n,color:r}}),null}function ps({position:e="top-left",style:t={},className:n="",children:r}){const i={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:10,left:10},"bottom-right":{bottom:10,right:10},"bottom-center":{bottom:10,left:"50%",transform:"translateX(-50%)"}}[e]||{top:10,left:10};return T.jsx("div",{className:`ric-panel ${n}`,style:{position:"absolute",zIndex:5,pointerEvents:"all",...i,...t},onPointerDown:o=>o.stopPropagation(),children:r})}function ms({minWidth:e=10,minHeight:t=10,maxWidth:n=1/0,maxHeight:r=1/0,isVisible:i=!0,handleStyle:o={},lineStyle:a={},color:f="#3b82f6",onResizeStart:p,onResize:d,onResizeEnd:h}){const k=c.useContext(on),S=Pe(),E=c.useRef(null),z=c.useCallback((A,X)=>{A.stopPropagation(),A.preventDefault();const D=S.nodesRef.current.find(I=>I.id===k);if(!D)return;E.current={direction:X,startX:A.clientX,startY:A.clientY,width:D.width||160,height:D.height||60},p==null||p(A,{width:E.current.width,height:E.current.height});const Y=I=>{var N,P;if(!E.current)return;const q=E.current,O=S.cameraRef.current,H=(I.clientX-q.startX)/O.zoom,C=(I.clientY-q.startY)/O.zoom;let y=q.width,v=q.height;q.direction.includes("e")&&(y=Math.min(n,Math.max(e,q.width+H))),q.direction.includes("w")&&(y=Math.min(n,Math.max(e,q.width-H))),q.direction.includes("s")&&(v=Math.min(r,Math.max(t,q.height+C))),q.direction.includes("n")&&(v=Math.min(r,Math.max(t,q.height-C))),(P=(N=S.onNodesChangeRef).current)==null||P.call(N,[{id:k,type:"dimensions",dimensions:{width:y,height:v},setAttributes:!0}]),d==null||d(I,{width:y,height:v})},$=I=>{E.current=null,h==null||h(I,{}),window.removeEventListener("pointermove",Y),window.removeEventListener("pointerup",$)};window.addEventListener("pointermove",Y),window.addEventListener("pointerup",$)},[k,S,e,t,n,r,p,d,h]);if(!i)return null;const j=8,L={position:"absolute",width:j,height:j,background:f,border:"1px solid #fff",borderRadius:2,zIndex:20,...o};return T.jsxs(T.Fragment,{children:[T.jsx("div",{style:{...L,bottom:-j/2,right:-j/2,cursor:"nwse-resize"},onPointerDown:A=>z(A,"se")}),T.jsx("div",{style:{...L,bottom:-j/2,left:-j/2,cursor:"nesw-resize"},onPointerDown:A=>z(A,"sw")}),T.jsx("div",{style:{...L,top:-j/2,right:-j/2,cursor:"nesw-resize"},onPointerDown:A=>z(A,"ne")}),T.jsx("div",{style:{...L,top:-j/2,left:-j/2,cursor:"nwse-resize"},onPointerDown:A=>z(A,"nw")}),T.jsx("div",{style:{...L,top:"50%",right:-j/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:A=>z(A,"e")}),T.jsx("div",{style:{...L,top:"50%",left:-j/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:A=>z(A,"w")}),T.jsx("div",{style:{...L,left:"50%",top:-j/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:A=>z(A,"n")}),T.jsx("div",{style:{...L,left:"50%",bottom:-j/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:A=>z(A,"s")})]})}function vs({isVisible:e,position:t="top",offset:n=10,align:r="center",children:i,style:o={},className:a=""}){const f=c.useContext(on),d=Pe().nodes.find(S=>S.id===f);if(!(e!==void 0?e:d==null?void 0:d.selected))return null;const k={top:{bottom:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginBottom:n},bottom:{top:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginTop:n},left:{right:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginRight:n},right:{left:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginLeft:n}}[t]||{};return T.jsx("div",{className:`ric-node-toolbar ${a}`,style:{position:"absolute",zIndex:1e3,pointerEvents:"all",...k,...o},onPointerDown:S=>S.stopPropagation(),children:i})}function bs({isVisible:e=!1,x:t=0,y:n=0,alignX:r="center",alignY:i="center",children:o,style:a={},className:f=""}){if(!e)return null;const p=r==="center"?"-50%":r==="right"?"-100%":"0",d=i==="center"?"-50%":i==="bottom"?"-100%":"0";return T.jsx("div",{className:`ric-edge-toolbar ${f}`,style:{position:"absolute",left:t,top:n,transform:`translate(${p}, ${d})`,zIndex:1e3,pointerEvents:"all",...a},children:o})}function ws({children:e}){var r;const n=(r=Pe().edgeLabelContainerRef)==null?void 0:r.current;return n?pr.createPortal(e,n):null}function Ms({children:e}){var r;const n=(r=Pe().viewportPortalRef)==null?void 0:r.current;return n?pr.createPortal(e,n):null}function _r({fromX:e,fromY:t,toX:n,toY:r,fromPosition:i="right",toPosition:o="left",connectionLineType:a="default",connectionLineStyle:f,connectionLineComponent:p}){if(p)return T.jsx(p,{fromX:e,fromY:t,toX:n,toY:r,fromPosition:i,toPosition:o});let d;switch(a){case"straight":[d]=tr({sourceX:e,sourceY:t,targetX:n,targetY:r});break;case"step":[d]=kn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o,borderRadius:0});break;case"smoothstep":[d]=kn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o});break;case"simplebezier":[d]=rr({sourceX:e,sourceY:t,targetX:n,targetY:r});break;default:[d]=nr({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:o});break}return T.jsx("path",{d,fill:"none",className:"ric-connection-line",stroke:"#b1b1b7",strokeWidth:1.5,style:f})}_r.displayName="ConnectionLine";const Rs=c.memo(_r),ks=Object.freeze({Top:"top",Bottom:"bottom",Left:"left",Right:"right"}),Cs=Object.freeze({Arrow:"arrow",ArrowClosed:"arrowclosed"});function Es(e){const t=e.width||e.measured&&e.measured.width||0,n=e.height||e.measured&&e.measured.height||0,r=e._absolutePosition||e.position||{x:0,y:0};return{x:r.x,y:r.y,x2:r.x+t,y2:r.y+n}}exports.Background=xs;exports.BaseEdge=sn;exports.BezierEdge=er;exports.ConnectionLine=Rs;exports.ControlButton=nn;exports.Controls=ys;exports.DefaultNode=vo;exports.EdgeLabelRenderer=ws;exports.EdgeText=Lr;exports.EdgeToolbar=bs;exports.GroupNode=Pr;exports.Handle=rn;exports.InfiniteCanvas=jo;exports.InfiniteCanvasProvider=Ao;exports.InputNode=Nr;exports.MarkerType=Cs;exports.MiniMap=as;exports.NodeResizer=ms;exports.NodeToolbar=vs;exports.OutputNode=Ir;exports.Panel=ps;exports.Position=ks;exports.SelectionBox=Sr;exports.SimpleBezierEdge=ar;exports.SmoothStepEdge=ir;exports.StepEdge=$r;exports.StraightEdge=sr;exports.ViewportPortal=Ms;exports.addEdge=Ho;exports.applyEdgeChanges=Dr;exports.applyNodeChanges=Ar;exports.boxToRect=Qr;exports.buildObstacles=or;exports.clampPosition=Gn;exports.computeRoutedEdges=No;exports.getBezierEdgeCenter=bo;exports.getBezierPath=nr;exports.getBoundsOfBoxes=Jr;exports.getConnectedEdges=br;exports.getEdgeCenter=wo;exports.getIncomers=Ur;exports.getNodeDimensions=Vn;exports.getNodesBounds=Rn;exports.getNodesInside=Zr;exports.getOutgoers=qr;exports.getOverlappingArea=Kr;exports.getRoutedLabelPosition=In;exports.getSimpleBezierPath=rr;exports.getSmoothStepPath=kn;exports.getStraightPath=tr;exports.getViewportForBounds=qt;exports.isEdge=Or;exports.isNode=Xr;exports.nodeToBox=Es;exports.nodeToRect=Vr;exports.reconnectEdge=Mo;exports.rectToBox=Gr;exports.routeSinglePath=Io;exports.routedPointsToPath=Nn;exports.snapPosition=Zn;exports.useConnection=Oo;exports.useEdges=Yo;exports.useEdgesState=Wo;exports.useHandleConnections=Zo;exports.useInfiniteCanvas=Mr;exports.useInternalNode=ts;exports.useKeyPress=Jo;exports.useNodeConnections=qo;exports.useNodeId=co;exports.useNodes=Fo;exports.useNodesData=Uo;exports.useNodesInitialized=es;exports.useNodesState=_o;exports.useOnEdgesChangeMiddleware=is;exports.useOnNodesChangeMiddleware=ss;exports.useOnSelectionChange=Qo;exports.useOnViewportChange=Go;exports.useReactFlow=Hr;exports.useStore=ns;exports.useStoreApi=rs;exports.useUndoRedo=os;exports.useUpdateNodeInternals=Ko;exports.useViewport=Xo;