@infinit-canvas/react 0.1.7 → 0.1.10

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,32 +1,50 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("react/jsx-runtime"),a=require("react"),Xn=require("react-dom"),Yn=160,Un=60;function Er(t){return t&&typeof t=="object"&&"position"in t&&"data"in t}function zr(t){return t&&typeof t=="object"&&"source"in t&&"target"in t}function qn(t,e){const n=typeof t=="string"?new Set([t]):new Set(Array.isArray(t)?t.map(r=>r.id):[t.id]);return e.filter(r=>n.has(r.source)||n.has(r.target))}function Nr(t,e,n){const r=typeof t=="string"?t:t.id,s=new Set;for(const o of n)o.target===r&&s.add(o.source);return e.filter(o=>s.has(o.id))}function Pr(t,e,n){const r=typeof t=="string"?t:t.id,s=new Set;for(const o of n)o.source===r&&s.add(o.target);return e.filter(o=>s.has(o.id))}function Ve(t){if(!t.length)return{x:0,y:0,width:0,height:0};let e=1/0,n=1/0,r=-1/0,s=-1/0;for(const o of t){const i=o.position.x,l=o.position.y,d=o.width||Yn,u=o.height||Un;i<e&&(e=i),l<n&&(n=l),i+d>r&&(r=i+d),l+u>s&&(s=l+u)}return{x:e,y:n,width:r-e,height:s-n}}function Je(t,e,n,r=.1){const s=t.width*(1+r*2),o=t.height*(1+r*2),i=Math.min(e/s,n/o,1),l=t.x+t.width/2,d=t.y+t.height/2;return{x:e/2-l*i,y:n/2-d*i,zoom:i}}function vn(t,e){return{x:e[0]*Math.round(t.x/e[0]),y:e[1]*Math.round(t.y/e[1])}}function bn(t,e){return{x:Math.min(Math.max(t.x,e[0][0]),e[1][0]),y:Math.min(Math.max(t.y,e[0][1]),e[1][1])}}function Mn(t){var e,n;return{width:t.width||((e=t.measured)==null?void 0:e.width)||Yn,height:t.height||((n=t.measured)==null?void 0:n.height)||Un}}function Ir(t,e,n={x:0,y:0,zoom:1},r=!1){const s=e.x,o=e.y,i=e.x+e.width,l=e.y+e.height;return t.filter(d=>{const{width:u,height:g}=Mn(d),v=d.position.x,P=d.position.y,E=v+u,R=P+g;return r?v<i&&E>s&&P<l&&R>o:v>=s&&E<=i&&P>=o&&R<=l})}function Lr(t){return{x:t.x,y:t.y,x2:t.x+t.width,y2:t.y+t.height}}function Sr(t){return{x:t.x,y:t.y,width:t.x2-t.x,height:t.y2-t.y}}function Tr(t,e){return{x:Math.min(t.x,e.x),y:Math.min(t.y,e.y),x2:Math.max(t.x2,e.x2),y2:Math.max(t.y2,e.y2)}}function $r(t,e){const n=Math.max(0,Math.min(t.x+t.width,e.x+e.width)-Math.max(t.x,e.x)),r=Math.max(0,Math.min(t.y+t.height,e.y+e.height)-Math.max(t.y,e.y));return n*r}function Br(t){const{width:e,height:n}=Mn(t);return{x:t.position.x,y:t.position.y,width:e,height:n}}const Gn=`var Ma = null, r = null, tr = 0, er = 0, g = { x: 0, y: 0, zoom: 1 }, O = [], B = [], P = [], G = !1, Ht = 40, Dt = !1, Br = "lines", Or = 1, lt = null, Pa = null, hr = null, E = 160, c = 60, ft = 8, ao = 5;
2
- function h(a) {
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("react/jsx-runtime"),c=require("react"),tr=require("react-dom"),nr=160,rr=60;function Sr(e){return e&&typeof e=="object"&&"position"in e&&"data"in e}function Pr(e){return e&&typeof e=="object"&&"source"in e&&"target"in e}function or(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 Ir(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 Tr(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 ln(e){if(!e.length)return{x:0,y:0,width:0,height:0};let t=1/0,n=1/0,r=-1/0,a=-1/0;for(const o of e){const i=o.position.x,f=o.position.y,x=o.width||nr,l=o.height||rr;i<t&&(t=i),f<n&&(n=f),i+x>r&&(r=i+x),f+l>a&&(a=f+l)}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),i=Math.min(t/a,n/o,1),f=e.x+e.width/2,x=e.y+e.height/2;return{x:t/2-f*i,y:n/2-x*i,zoom:i}}function Ln(e,t){return{x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}}function $n(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 jn(e){var t,n;return{width:e.width||((t=e.measured)==null?void 0:t.width)||nr,height:e.height||((n=e.measured)==null?void 0:n.height)||rr}}function Lr(e,t,n={x:0,y:0,zoom:1},r=!1){const a=t.x,o=t.y,i=t.x+t.width,f=t.y+t.height;return e.filter(x=>{const{width:l,height:y}=jn(x),b=x.position.x,E=x.position.y,R=b+l,v=E+y;return r?b<i&&R>a&&E<f&&v>o:b>=a&&R<=i&&E>=o&&v<=f})}function $r(e){return{x:e.x,y:e.y,x2:e.x+e.width,y2:e.y+e.height}}function Br(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 Ar(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 Dr(e){const{width:t,height:n}=jn(e);return{x:e.position.x,y:e.position.y,width:t,height:n}}const sr=`var Ma = null, r = null, tr = 0, er = 0, g = { x: 0, y: 0, zoom: 1 }, O = [], B = [], G = [], S = !1, Ht = 40, Dt = !1, Br = "lines", Or = 1, lt = null, Ga = null, hr = null, E = 160, z = 60, ft = 8, ao = 5;
2
+ function s(a) {
3
3
  return a._absolutePosition || a.position;
4
4
  }
5
- function Vo(a, t, e, o, v) {
5
+ function Vo(a, t, e, f, l) {
6
6
  if (a.x !== void 0 && a.y !== void 0)
7
7
  return { x: t + a.x, y: e + a.y };
8
- var f = a.position || (a.type === "source" ? "right" : "left");
9
- switch (f) {
8
+ var o = a.position || (a.type === "source" ? "right" : "left");
9
+ switch (o) {
10
10
  case "top":
11
- return { x: t + o / 2, y: e };
11
+ return { x: t + f / 2, y: e };
12
12
  case "bottom":
13
- return { x: t + o / 2, y: e + v };
13
+ return { x: t + f / 2, y: e + l };
14
14
  case "left":
15
- return { x: t, y: e + v / 2 };
15
+ return { x: t, y: e + l / 2 };
16
16
  case "right":
17
- return { x: t + o, y: e + v / 2 };
17
+ return { x: t + f, y: e + l / 2 };
18
18
  default:
19
- return { x: t + o, y: e + v / 2 };
19
+ return { x: t + f, y: e + l / 2 };
20
20
  }
21
21
  }
22
22
  function ho(a) {
23
- var t = a.width || E, e = a.height || c;
24
- return a.handles && a.handles.length > 0 ? a.handles.map(function(o) {
25
- var v = Vo(o, h(a).x, h(a).y, t, e);
26
- return { id: o.id || null, type: o.type, x: v.x, y: v.y, position: o.position };
27
- }) : [
28
- { id: null, type: "target", x: h(a).x, y: h(a).y + e / 2, position: "left" },
29
- { id: null, type: "source", x: h(a).x + t, y: h(a).y + e / 2, position: "right" }
23
+ var t = a.width || E, e = a.height || z;
24
+ if (a.handles && a.handles.length > 0)
25
+ return a.handles.map(function(h) {
26
+ var x = Vo(h, s(a).x, s(a).y, t, e);
27
+ return { id: h.id || null, type: h.type, x: x.x, y: x.y, position: h.position };
28
+ });
29
+ var f = a.targetPosition || "left", l = a.sourcePosition || "right", o = s(a);
30
+ function v(h) {
31
+ switch (h) {
32
+ case "top":
33
+ return { x: o.x + t / 2, y: o.y };
34
+ case "bottom":
35
+ return { x: o.x + t / 2, y: o.y + e };
36
+ case "left":
37
+ return { x: o.x, y: o.y + e / 2 };
38
+ case "right":
39
+ return { x: o.x + t, y: o.y + e / 2 };
40
+ default:
41
+ return { x: o.x + t, y: o.y + e / 2 };
42
+ }
43
+ }
44
+ var y = v(f), M = v(l);
45
+ return [
46
+ { id: null, type: "target", x: y.x, y: y.y, position: f },
47
+ { id: null, type: "source", x: M.x, y: M.y, position: l }
30
48
  ];
31
49
  }
32
50
  var Ft = {}, Ka = !0;
@@ -36,32 +54,32 @@ function Uo(a) {
36
54
  return t || (t = ho(a), Ft[a.id] = t, t);
37
55
  }
38
56
  function it(a, t, e) {
39
- for (var o = Uo(a), v = 0; v < o.length; v++)
40
- if (o[v].type === t)
57
+ for (var f = Uo(a), l = 0; l < f.length; l++)
58
+ if (f[l].type === t)
41
59
  if (e) {
42
- if (o[v].id === e) return o[v];
60
+ if (f[l].id === e) return f[l];
43
61
  } else
44
- return o[v];
45
- var f = a.width || E, l = a.height || c;
46
- return t === "source" ? { x: h(a).x + f, y: h(a).y + l / 2 } : { x: h(a).x, y: h(a).y + l / 2 };
62
+ return f[l];
63
+ var o = a.width || E, v = a.height || z;
64
+ return t === "source" ? { x: s(a).x + o, y: s(a).y + v / 2 } : { x: s(a).x, y: s(a).y + v / 2 };
47
65
  }
48
- var z = {};
66
+ var R = {};
49
67
  function Yt() {
50
- z = {
51
- grid: G ? "rgba(255,255,255,0.07)" : "rgba(0,0,0,0.07)",
52
- origin: G ? "rgba(255,255,255,0.2)" : "rgba(0,0,0,0.15)",
53
- cardBg: G ? "#2a2a28" : "#ffffff",
54
- cardBorder: G ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.1)",
55
- cardShadow: G ? "rgba(0,0,0,0.3)" : "rgba(0,0,0,0.06)",
68
+ R = {
69
+ grid: S ? "rgba(255,255,255,0.07)" : "rgba(0,0,0,0.07)",
70
+ origin: S ? "rgba(255,255,255,0.2)" : "rgba(0,0,0,0.15)",
71
+ cardBg: S ? "#2a2a28" : "#ffffff",
72
+ cardBorder: S ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.1)",
73
+ cardShadow: S ? "rgba(0,0,0,0.3)" : "rgba(0,0,0,0.06)",
56
74
  titleText: "rgba(255,255,255,0.9)",
57
- bodyText: G ? "rgba(255,255,255,0.55)" : "rgba(0,0,0,0.5)",
58
- coordText: G ? "rgba(255,255,255,0.25)" : "rgba(0,0,0,0.2)",
59
- nodeBg: G ? "#1e1e2e" : "#ffffff",
60
- nodeBorder: G ? "rgba(255,255,255,0.15)" : "rgba(0,0,0,0.15)",
75
+ bodyText: S ? "rgba(255,255,255,0.55)" : "rgba(0,0,0,0.5)",
76
+ coordText: S ? "rgba(255,255,255,0.25)" : "rgba(0,0,0,0.2)",
77
+ nodeBg: S ? "#1e1e2e" : "#ffffff",
78
+ nodeBorder: S ? "rgba(255,255,255,0.15)" : "rgba(0,0,0,0.15)",
61
79
  nodeSelectedBorder: "#3b82f6",
62
- nodeShadow: G ? "rgba(0,0,0,0.4)" : "rgba(0,0,0,0.08)",
63
- nodeText: G ? "rgba(255,255,255,0.9)" : "rgba(0,0,0,0.85)",
64
- edgeStroke: G ? "rgba(255,255,255,0.35)" : "rgba(0,0,0,0.3)",
80
+ nodeShadow: S ? "rgba(0,0,0,0.4)" : "rgba(0,0,0,0.08)",
81
+ nodeText: S ? "rgba(255,255,255,0.9)" : "rgba(0,0,0,0.85)",
82
+ edgeStroke: S ? "rgba(255,255,255,0.35)" : "rgba(0,0,0,0.3)",
65
83
  edgeSelected: "#3b82f6",
66
84
  edgeAnimated: "#3b82f6",
67
85
  handleFill: "#ffffff",
@@ -70,29 +88,29 @@ function Yt() {
70
88
  }, xa = !0;
71
89
  }
72
90
  Yt();
73
- var Do = ["#534AB7", "#0F6E56", "#993C1D", "#185FA5"], Ga = 8, Fo = "500 11px system-ui, sans-serif", jo = "400 11px system-ui, sans-serif", Oo = "10px monospace", Xo = "500 13px system-ui, sans-serif", Ho = "400 11px system-ui, sans-serif", br = 400, Ia = {}, ht = !0;
91
+ var Do = ["#534AB7", "#0F6E56", "#993C1D", "#185FA5"], Sa = 8, Fo = "500 11px system-ui, sans-serif", jo = "400 11px system-ui, sans-serif", Oo = "10px monospace", Xo = "500 13px system-ui, sans-serif", Ho = "400 11px system-ui, sans-serif", br = 400, Ia = {}, ht = !0;
74
92
  function Yo() {
75
93
  Ia = {};
76
94
  for (var a = 0; a < O.length; a++)
77
- for (var t = O[a], e = Math.floor(t.x / br), o = Math.floor(t.y / br), v = Math.floor((t.x + t.w) / br), f = Math.floor((t.y + t.h) / br), l = e; l <= v; l++)
78
- for (var y = o; y <= f; y++) {
79
- var d = l + "," + y;
80
- Ia[d] || (Ia[d] = []), Ia[d].push(a);
95
+ for (var t = O[a], e = Math.floor(t.x / br), f = Math.floor(t.y / br), l = Math.floor((t.x + t.w) / br), o = Math.floor((t.y + t.h) / br), v = e; v <= l; v++)
96
+ for (var y = f; y <= o; y++) {
97
+ var M = v + "," + y;
98
+ Ia[M] || (Ia[M] = []), Ia[M].push(a);
81
99
  }
82
100
  ht = !1;
83
101
  }
84
- function to(a, t, e, o) {
102
+ function to(a, t, e, f) {
85
103
  ht && Yo();
86
- for (var v = {}, f = [], l = Math.floor(a / br), y = Math.floor(t / br), d = Math.floor(e / br), M = Math.floor(o / br), x = l; x <= d; x++)
87
- for (var i = y; i <= M; i++) {
88
- var n = x + "," + i, s = Ia[n];
89
- if (s)
90
- for (var u = 0; u < s.length; u++) {
91
- var w = s[u];
92
- v[w] || (v[w] = !0, f.push(w));
104
+ for (var l = {}, o = [], v = Math.floor(a / br), y = Math.floor(t / br), M = Math.floor(e / br), h = Math.floor(f / br), x = v; x <= M; x++)
105
+ for (var i = y; i <= h; i++) {
106
+ var n = x + "," + i, d = Ia[n];
107
+ if (d)
108
+ for (var u = 0; u < d.length; u++) {
109
+ var w = d[u];
110
+ l[w] || (l[w] = !0, o.push(w));
93
111
  }
94
112
  }
95
- return f;
113
+ return o;
96
114
  }
97
115
  var Nr = 500, Za = {}, Xr = !0;
98
116
  function te() {
@@ -100,42 +118,42 @@ function te() {
100
118
  for (var a = 0; a < B.length; a++) {
101
119
  var t = B[a];
102
120
  if (!t.hidden)
103
- for (var e = h(t), o = t.width || E, v = t.height || c, f = Math.floor(e.x / Nr), l = Math.floor(e.y / Nr), y = Math.floor((e.x + o) / Nr), d = Math.floor((e.y + v) / Nr), M = f; M <= y; M++)
104
- for (var x = l; x <= d; x++) {
105
- var i = M + "," + x;
121
+ for (var e = s(t), f = t.width || E, l = t.height || z, o = Math.floor(e.x / Nr), v = Math.floor(e.y / Nr), y = Math.floor((e.x + f) / Nr), M = Math.floor((e.y + l) / Nr), h = o; h <= y; h++)
122
+ for (var x = v; x <= M; x++) {
123
+ var i = h + "," + x;
106
124
  Za[i] || (Za[i] = []), Za[i].push(a);
107
125
  }
108
126
  }
109
127
  Xr = !1;
110
128
  }
111
- function no(a, t, e, o) {
129
+ function no(a, t, e, f) {
112
130
  Xr && te();
113
- for (var v = {}, f = [], l = Math.floor(a / Nr), y = Math.floor(t / Nr), d = Math.floor(e / Nr), M = Math.floor(o / Nr), x = l; x <= d; x++)
114
- for (var i = y; i <= M; i++) {
115
- var n = x + "," + i, s = Za[n];
116
- if (s)
117
- for (var u = 0; u < s.length; u++) {
118
- var w = s[u];
119
- v[w] || (v[w] = !0, f.push(w));
131
+ for (var l = {}, o = [], v = Math.floor(a / Nr), y = Math.floor(t / Nr), M = Math.floor(e / Nr), h = Math.floor(f / Nr), x = v; x <= M; x++)
132
+ for (var i = y; i <= h; i++) {
133
+ var n = x + "," + i, d = Za[n];
134
+ if (d)
135
+ for (var u = 0; u < d.length; u++) {
136
+ var w = d[u];
137
+ l[w] || (l[w] = !0, o.push(w));
120
138
  }
121
139
  }
122
- return f;
140
+ return o;
123
141
  }
124
- var ka = {}, ya = !0;
142
+ var Ta = {}, ga = !0;
125
143
  function ee() {
126
- ka = {};
144
+ Ta = {};
127
145
  for (var a = 0; a < B.length; a++)
128
- ka[B[a].id] = B[a];
129
- ya = !1;
146
+ Ta[B[a].id] = B[a];
147
+ ga = !1;
130
148
  }
131
149
  function eo(a) {
132
- return ya && ee(), ka[a];
150
+ return ga && ee(), Ta[a];
133
151
  }
134
152
  var Cr = {}, nt = !0;
135
153
  function po() {
136
154
  Cr = {};
137
- for (var a = 0; a < P.length; a++) {
138
- var t = P[a];
155
+ for (var a = 0; a < G.length; a++) {
156
+ var t = G[a];
139
157
  Cr[t.source] || (Cr[t.source] = []), Cr[t.source].push(a), t.source !== t.target && (Cr[t.target] || (Cr[t.target] = []), Cr[t.target].push(a));
140
158
  }
141
159
  nt = !1;
@@ -146,19 +164,19 @@ function rf(a) {
146
164
  var t = Math.ceil(a), e = Math.ceil(a);
147
165
  if (t < 2 || e < 2) return !1;
148
166
  t > 512 && (t = 512), e > 512 && (e = 512), jr.width = t, jr.height = e, uo = t, so = a, Mo = Br, xa = !1;
149
- var o = jr.getContext("2d");
150
- o.clearRect(0, 0, t, e);
151
- var v = lt || z.grid;
167
+ var f = jr.getContext("2d");
168
+ f.clearRect(0, 0, t, e);
169
+ var l = lt || R.grid;
152
170
  if (Br === "dots") {
153
- o.fillStyle = v;
154
- var f = Or * g.zoom;
155
- o.beginPath(), o.arc(0, 0, f, 0, 6.2832), o.fill();
171
+ f.fillStyle = l;
172
+ var o = Or * g.zoom;
173
+ f.beginPath(), f.arc(0, 0, o, 0, 6.2832), f.fill();
156
174
  } else if (Br === "cross") {
157
- o.strokeStyle = v, o.lineWidth = Or;
158
- var l = 3 * g.zoom;
159
- o.beginPath(), o.moveTo(-l, 0), o.lineTo(l, 0), o.moveTo(0, -l), o.lineTo(0, l), o.stroke();
175
+ f.strokeStyle = l, f.lineWidth = Or;
176
+ var v = 3 * g.zoom;
177
+ f.beginPath(), f.moveTo(-v, 0), f.lineTo(v, 0), f.moveTo(0, -v), f.lineTo(0, v), f.stroke();
160
178
  } else
161
- o.beginPath(), o.strokeStyle = v, o.lineWidth = Or * 0.5, o.moveTo(0.5, 0), o.lineTo(0.5, e), o.moveTo(0, 0.5), o.lineTo(t, 0.5), o.stroke();
179
+ f.beginPath(), f.strokeStyle = l, f.lineWidth = Or * 0.5, f.moveTo(0.5, 0), f.lineTo(0.5, e), f.moveTo(0, 0.5), f.lineTo(t, 0.5), f.stroke();
162
180
  return !0;
163
181
  }
164
182
  var oo = 0, jt = 0, fo = 0, vo = 0, pt = 0, Ja = !1;
@@ -169,9 +187,9 @@ self.onmessage = function(a) {
169
187
  var t = a.data.type, e = a.data.data;
170
188
  switch (t) {
171
189
  case "init":
172
- Ma = e.canvas, r = Ma.getContext("2d"), tr = e.width, er = e.height, Ma.width = tr, Ma.height = er, g = e.camera, O = e.cards || [], B = e.nodes || [], P = e.edges || [], G = e.dark, e.gridSize && (Ht = e.gridSize), e.edgeRouting !== void 0 && (ga = !!e.edgeRouting), Yt(), ht = !0, ya = !0, Xr = !0, Ka = !0, nt = !0, Ja = P.some(function(d) {
173
- return d.animated;
174
- }), console.log("[worker] init done — canvas:", tr, "x", er, "| cards:", O.length, "| nodes:", B.length, "| edges:", P.length, "| routing:", ga), ut(), self.postMessage({ type: "ready" }), Ja && lo();
190
+ Ma = e.canvas, r = Ma.getContext("2d"), tr = e.width, er = e.height, Ma.width = tr, Ma.height = er, g = e.camera, O = e.cards || [], B = e.nodes || [], G = e.edges || [], S = e.dark, e.gridSize && (Ht = e.gridSize), e.edgeRouting !== void 0 && (ya = !!e.edgeRouting), Yt(), ht = !0, ga = !0, Xr = !0, Ka = !0, nt = !0, Ja = G.some(function(M) {
191
+ return M.animated;
192
+ }), console.log("[worker] init done — canvas:", tr, "x", er, "| cards:", O.length, "| nodes:", B.length, "| edges:", G.length, "| routing:", ya), ut(), self.postMessage({ type: "ready" }), Ja && lo();
175
193
  break;
176
194
  case "resize":
177
195
  tr = e.width, er = e.height, Ma.width = tr, Ma.height = er, xa = !0, ut();
@@ -183,26 +201,26 @@ self.onmessage = function(a) {
183
201
  O = e.cards, ht = !0, or();
184
202
  break;
185
203
  case "nodes":
186
- B = e.nodes, ya = !0, Xr = !0, Ka = !0, or(), vt(), self.postMessage({ type: "nodesProcessed", data: { nodeCount: B.length } });
204
+ B = e.nodes, ga = !0, Xr = !0, Ka = !0, or(), vt(), self.postMessage({ type: "nodesProcessed", data: { nodeCount: B.length } });
187
205
  break;
188
206
  case "nodePositions":
189
- ya && ee();
190
- for (var o = e.updates, v = 0; v < o.length; v++) {
191
- var f = o[v], l = ka[f.id];
192
- l && (l.position = f.position, f._absolutePosition && (l._absolutePosition = f._absolutePosition), f.width !== void 0 && (l.width = f.width), f.height !== void 0 && (l.height = f.height), l.dragging = f.dragging, l.selected = f.selected);
207
+ ga && ee();
208
+ for (var f = e.updates, l = 0; l < f.length; l++) {
209
+ var o = f[l], v = Ta[o.id];
210
+ v && (v.position = o.position, o._absolutePosition && (v._absolutePosition = o._absolutePosition), o.width !== void 0 && (v.width = o.width), o.height !== void 0 && (v.height = o.height), v.dragging = o.dragging, v.selected = o.selected);
193
211
  }
194
212
  Ka = !0, Xr = !0, or(), vt();
195
213
  break;
196
214
  case "edges":
197
- P = e.edges, nt = !0, Ja = P.some(function(d) {
198
- return d.animated;
215
+ G = e.edges, nt = !0, Ja = G.some(function(M) {
216
+ return M.animated;
199
217
  }), Ja && lo(), or(), vt();
200
218
  break;
201
219
  case "theme":
202
- G = e.dark, Yt(), or();
220
+ S = e.dark, Yt(), or();
203
221
  break;
204
222
  case "connecting":
205
- Pa = e, or();
223
+ Ga = e, or();
206
224
  break;
207
225
  case "selectionBox":
208
226
  hr = e, or();
@@ -211,17 +229,17 @@ self.onmessage = function(a) {
211
229
  e.variant && (Br = e.variant), e.gap && (Ht = e.gap), e.size && (Or = e.size), lt = e.color || null, xa = !0, or();
212
230
  break;
213
231
  case "edgeRouting":
214
- if (ga = !!e.enabled, ga)
232
+ if (ya = !!e.enabled, ya)
215
233
  vt();
216
234
  else {
217
- for (var y = 0; y < P.length; y++)
218
- P[y]._routedPoints = null;
235
+ for (var y = 0; y < G.length; y++)
236
+ G[y]._routedPoints = null;
219
237
  or();
220
238
  }
221
239
  break;
222
240
  }
223
- } catch (d) {
224
- console.error("[worker] error:", d);
241
+ } catch (M) {
242
+ console.error("[worker] error:", M);
225
243
  }
226
244
  };
227
245
  function or() {
@@ -245,143 +263,143 @@ function lo() {
245
263
  function io(a, t) {
246
264
  var e = 6;
247
265
  a.moveTo(t[0].x, t[0].y);
248
- for (var o = 1; o < t.length - 1; o++) {
249
- var v = t[o - 1], f = t[o], l = t[o + 1], y = Math.abs(f.x - v.x) + Math.abs(f.y - v.y), d = Math.abs(l.x - f.x) + Math.abs(l.y - f.y), M = Math.min(e, y / 2, d / 2);
250
- if (M > 0.5) {
251
- var x = f.x - v.x, i = f.y - v.y, n = l.x - f.x, s = l.y - f.y, u = Math.sqrt(x * x + i * i) || 1, w = Math.sqrt(n * n + s * s) || 1;
252
- a.lineTo(f.x - x / u * M, f.y - i / u * M), a.quadraticCurveTo(f.x, f.y, f.x + n / w * M, f.y + s / w * M);
266
+ for (var f = 1; f < t.length - 1; f++) {
267
+ var l = t[f - 1], o = t[f], v = t[f + 1], y = Math.abs(o.x - l.x) + Math.abs(o.y - l.y), M = Math.abs(v.x - o.x) + Math.abs(v.y - o.y), h = Math.min(e, y / 2, M / 2);
268
+ if (h > 0.5) {
269
+ var x = o.x - l.x, i = o.y - l.y, n = v.x - o.x, d = v.y - o.y, u = Math.sqrt(x * x + i * i) || 1, w = Math.sqrt(n * n + d * d) || 1;
270
+ a.lineTo(o.x - x / u * h, o.y - i / u * h), a.quadraticCurveTo(o.x, o.y, o.x + n / w * h, o.y + d / w * h);
253
271
  } else
254
- a.lineTo(f.x, f.y);
272
+ a.lineTo(o.x, o.y);
255
273
  }
256
274
  a.lineTo(t[t.length - 1].x, t[t.length - 1].y);
257
275
  }
258
276
  function af(a) {
259
277
  for (var t = 0, e = 1; e < a.length; e++)
260
278
  t += Math.abs(a[e].x - a[e - 1].x) + Math.abs(a[e].y - a[e - 1].y);
261
- for (var o = t / 2, v = 1; v < a.length; v++) {
262
- var f = Math.abs(a[v].x - a[v - 1].x) + Math.abs(a[v].y - a[v - 1].y);
263
- if (o <= f) {
264
- var l = f > 0 ? o / f : 0;
279
+ for (var f = t / 2, l = 1; l < a.length; l++) {
280
+ var o = Math.abs(a[l].x - a[l - 1].x) + Math.abs(a[l].y - a[l - 1].y);
281
+ if (f <= o) {
282
+ var v = o > 0 ? f / o : 0;
265
283
  return {
266
- x: a[v - 1].x + (a[v].x - a[v - 1].x) * l,
267
- y: a[v - 1].y + (a[v].y - a[v - 1].y) * l
284
+ x: a[l - 1].x + (a[l].x - a[l - 1].x) * v,
285
+ y: a[l - 1].y + (a[l].y - a[l - 1].y) * v
268
286
  };
269
287
  }
270
- o -= f;
288
+ f -= o;
271
289
  }
272
290
  return { x: a[0].x, y: a[0].y };
273
291
  }
274
- function re(a, t, e, o) {
275
- var v = Math.abs(e - a), f = Math.max(50, v * 0.5), l = a + f, y = t, d = e - f, M = o;
276
- return { cp1x: l, cp1y: y, cp2x: d, cp2y: M };
292
+ function re(a, t, e, f) {
293
+ var l = Math.abs(e - a), o = Math.max(50, l * 0.5), v = a + o, y = t, M = e - o, h = f;
294
+ return { cp1x: v, cp1y: y, cp2x: M, cp2y: h };
277
295
  }
278
- function tf(a, t, e, o) {
279
- var v = re(a, t, e, o), f = 0.5, l = 1 - f, y = l * l * l * a + 3 * l * l * f * v.cp1x + 3 * l * f * f * v.cp2x + f * f * f * e, d = l * l * l * t + 3 * l * l * f * v.cp1y + 3 * l * f * f * v.cp2y + f * f * f * o;
280
- return { x: y, y: d };
296
+ function tf(a, t, e, f) {
297
+ var l = re(a, t, e, f), o = 0.5, v = 1 - o, y = v * v * v * a + 3 * v * v * o * l.cp1x + 3 * v * o * o * l.cp2x + o * o * o * e, M = v * v * v * t + 3 * v * v * o * l.cp1y + 3 * v * o * o * l.cp2y + o * o * o * f;
298
+ return { x: y, y: M };
281
299
  }
282
- var ga = !0, ae = !1, Xt = !1;
283
- function go(a, t, e, o, v) {
300
+ var ya = !0, ae = !1, Xt = !1;
301
+ function yo(a, t, e, f, l) {
284
302
  Xr && te();
285
- for (var f = Math.min(a, e) - 20, l = Math.min(t, o) - 20, y = Math.max(a, e) + 20, d = Math.max(t, o) + 20, M = no(f, l, y, d), x = [], i = 0; i < M.length; i++) {
286
- var n = B[M[i]];
287
- n.hidden || v[n.id] || n.type !== "group" && x.push(n);
303
+ for (var o = Math.min(a, e) - 20, v = Math.min(t, f) - 20, y = Math.max(a, e) + 20, M = Math.max(t, f) + 20, h = no(o, v, y, M), x = [], i = 0; i < h.length; i++) {
304
+ var n = B[h[i]];
305
+ n.hidden || l[n.id] || n.type !== "group" && x.push(n);
288
306
  }
289
307
  return x;
290
308
  }
291
- function dr(a, t, e, o) {
292
- for (var v = Math.min(a, t), f = Math.max(a, t), l = 0; l < o.length; l++) {
293
- var y = o[l], d = h(y), M = y.width || E, x = y.height || c;
294
- if (e > d.y && e < d.y + x && f > d.x && v < d.x + M) return y;
309
+ function dr(a, t, e, f) {
310
+ for (var l = Math.min(a, t), o = Math.max(a, t), v = 0; v < f.length; v++) {
311
+ var y = f[v], M = s(y), h = y.width || E, x = y.height || z;
312
+ if (e > M.y && e < M.y + x && o > M.x && l < M.x + h) return y;
295
313
  }
296
314
  return null;
297
315
  }
298
- function Mr(a, t, e, o) {
299
- for (var v = Math.min(t, e), f = Math.max(t, e), l = 0; l < o.length; l++) {
300
- var y = o[l], d = h(y), M = y.width || E, x = y.height || c;
301
- if (a > d.x && a < d.x + M && f > d.y && v < d.y + x) return y;
316
+ function Mr(a, t, e, f) {
317
+ for (var l = Math.min(t, e), o = Math.max(t, e), v = 0; v < f.length; v++) {
318
+ var y = f[v], M = s(y), h = y.width || E, x = y.height || z;
319
+ if (a > M.x && a < M.x + h && o > M.y && l < M.y + x) return y;
302
320
  }
303
321
  return null;
304
322
  }
305
323
  function ef() {
306
- if (ga && !(!ae || P.length === 0 || B.length === 0)) {
307
- ae = !1, ya && ee(), Xr && te();
308
- for (var a = 20, t = !1, e = 0; e < P.length; e++) {
309
- var o = P[e];
310
- if (!o._customRendered) {
311
- var v = o.type || "default";
312
- if (!(v === "bezier" || v === "simplebezier" || v === "default")) {
313
- var f = ka[o.source], l = ka[o.target];
314
- if (!(!f || !l || f.hidden || l.hidden)) {
315
- var y = it(f, "source", o.sourceHandle), d = it(l, "target", o.targetHandle), M = y.position || "right", x = d.position || "left", i = y.x, n = y.y, s = d.x, u = d.y, w = i, Q = n, W = s, $ = u;
316
- M === "right" ? w += a : M === "left" ? w -= a : M === "bottom" ? Q += a : M === "top" && (Q -= a), x === "right" ? W += a : x === "left" ? W -= a : x === "bottom" ? $ += a : x === "top" && ($ -= a);
317
- var gr = h(f), qr = h(l), Sr = f.width || E, Gr = f.height || c, Pr = l.width || E, Hr = l.height || c, Ir = {};
318
- Ir[o.source] = !0, Ir[o.target] = !0;
319
- var X = go(
320
- Math.min(i, s) - Sr,
321
- Math.min(n, u) - Gr,
322
- Math.max(i, s) + Pr,
324
+ if (ya && !(!ae || G.length === 0 || B.length === 0)) {
325
+ ae = !1, ga && ee(), Xr && te();
326
+ for (var a = 20, t = !1, e = 0; e < G.length; e++) {
327
+ var f = G[e];
328
+ if (!f._customRendered) {
329
+ var l = f.type || "default";
330
+ if (!(l === "bezier" || l === "simplebezier" || l === "default")) {
331
+ var o = Ta[f.source], v = Ta[f.target];
332
+ if (!(!o || !v || o.hidden || v.hidden)) {
333
+ var y = it(o, "source", f.sourceHandle), M = it(v, "target", f.targetHandle), h = y.position || "right", x = M.position || "left", i = y.x, n = y.y, d = M.x, u = M.y, w = i, Q = n, W = d, $ = u;
334
+ h === "right" ? w += a : h === "left" ? w -= a : h === "bottom" ? Q += a : h === "top" && (Q -= a), x === "right" ? W += a : x === "left" ? W -= a : x === "bottom" ? $ += a : x === "top" && ($ -= a);
335
+ var yr = s(o), Pr = s(v), qr = o.width || E, Sr = o.height || z, Gr = v.width || E, Hr = v.height || z, Ir = {};
336
+ Ir[f.source] = !0, Ir[f.target] = !0;
337
+ var X = yo(
338
+ Math.min(i, d) - qr,
339
+ Math.min(n, u) - Sr,
340
+ Math.max(i, d) + Gr,
323
341
  Math.max(n, u) + Hr,
324
342
  Ir
325
343
  );
326
- X.push(f), X.push(l);
327
- var Yr = M === "left" || M === "right", Ta = x === "left" || x === "right", C = null;
328
- if (Yr && Ta) {
329
- var L, fr = M === "right" && w < W, st = M === "left" && w > W;
344
+ X.push(o), X.push(v);
345
+ var Yr = h === "left" || h === "right", ka = x === "left" || x === "right", C = null;
346
+ if (Yr && ka) {
347
+ var L, fr = h === "right" && w < W, st = h === "left" && w > W;
330
348
  if (fr || st) {
331
349
  L = (w + W) / 2;
332
350
  var ma = Mr(L, n, u, X);
333
351
  if (ma) {
334
- var pr = h(ma), ra = ma.width || E;
352
+ var pr = s(ma), ra = ma.width || E;
335
353
  L = L < pr.x + ra / 2 ? pr.x - a : pr.x + ra + a;
336
354
  }
337
355
  } else
338
- M === "right" ? L = Math.max(gr.x + Sr, qr.x + Pr) + a : L = Math.min(gr.x, qr.x) - a;
339
- C = [{ x: i, y: n }, { x: w, y: n }, { x: L, y: n }, { x: L, y: u }, { x: W, y: u }, { x: s, y: u }];
340
- var yr = dr(L, W, u, X);
341
- if (yr) {
342
- var aa = h(yr), ta = yr.height || c, ea = aa.y - a, Zr = aa.y + ta + a, Jr = Math.abs(n - ea) <= Math.abs(n - Zr) ? ea : Zr;
343
- C = [{ x: i, y: n }, { x: w, y: n }, { x: L, y: n }, { x: L, y: Jr }, { x: W, y: Jr }, { x: W, y: u }, { x: s, y: u }];
356
+ h === "right" ? L = Math.max(yr.x + qr, Pr.x + Gr) + a : L = Math.min(yr.x, Pr.x) - a;
357
+ C = [{ x: i, y: n }, { x: w, y: n }, { x: L, y: n }, { x: L, y: u }, { x: W, y: u }, { x: d, y: u }];
358
+ var gr = dr(L, W, u, X);
359
+ if (gr) {
360
+ var aa = s(gr), ta = gr.height || z, ea = aa.y - a, Zr = aa.y + ta + a, Jr = Math.abs(n - ea) <= Math.abs(n - Zr) ? ea : Zr;
361
+ C = [{ x: i, y: n }, { x: w, y: n }, { x: L, y: n }, { x: L, y: Jr }, { x: W, y: Jr }, { x: W, y: u }, { x: d, y: u }];
344
362
  }
345
- } else if (!Yr && !Ta) {
346
- var N, Qa = M === "bottom" && Q < $, Ra = M === "top" && Q > $;
347
- if (Qa || Ra) {
363
+ } else if (!Yr && !ka) {
364
+ var N, Qa = h === "bottom" && Q < $, ca = h === "top" && Q > $;
365
+ if (Qa || ca) {
348
366
  N = (Q + $) / 2;
349
- var xr = dr(i, s, N, X);
367
+ var xr = dr(i, d, N, X);
350
368
  if (xr) {
351
- var kr = h(xr), oa = xr.height || c;
352
- N = N < kr.y + oa / 2 ? kr.y - a : kr.y + oa + a;
369
+ var Tr = s(xr), oa = xr.height || z;
370
+ N = N < Tr.y + oa / 2 ? Tr.y - a : Tr.y + oa + a;
353
371
  }
354
372
  } else
355
- M === "bottom" ? N = Math.max(gr.y + Gr, qr.y + Hr) + a : N = Math.min(gr.y, qr.y) - a;
356
- C = [{ x: i, y: n }, { x: i, y: Q }, { x: i, y: N }, { x: s, y: N }, { x: s, y: $ }, { x: s, y: u }];
357
- var Kr = Mr(s, N, $, X);
373
+ h === "bottom" ? N = Math.max(yr.y + Sr, Pr.y + Hr) + a : N = Math.min(yr.y, Pr.y) - a;
374
+ C = [{ x: i, y: n }, { x: i, y: Q }, { x: i, y: N }, { x: d, y: N }, { x: d, y: $ }, { x: d, y: u }];
375
+ var Kr = Mr(d, N, $, X);
358
376
  if (Kr) {
359
- var fa = h(Kr), wa = Kr.height || c, va = fa.y - a, la = fa.y + wa + a, ia = Math.abs(N - va) <= Math.abs(N - la) ? va : la;
360
- C = [{ x: i, y: n }, { x: i, y: Q }, { x: i, y: N }, { x: s, y: N }, { x: s, y: ia }, { x: W, y: ia }, { x: W, y: u }, { x: s, y: u }];
377
+ var fa = s(Kr), wa = Kr.height || z, va = fa.y - a, la = fa.y + wa + a, ia = Math.abs(N - va) <= Math.abs(N - la) ? va : la;
378
+ C = [{ x: i, y: n }, { x: i, y: Q }, { x: i, y: N }, { x: d, y: N }, { x: d, y: ia }, { x: W, y: ia }, { x: W, y: u }, { x: d, y: u }];
361
379
  }
362
380
  } else if (Yr) {
363
- C = [{ x: i, y: n }, { x: w, y: n }, { x: s, y: n }, { x: s, y: $ }, { x: s, y: u }];
364
- var Tr = Mr(s, n, $, X);
365
- if (Tr) {
366
- var V = h(Tr), mr = Tr.width || E, za = Math.abs(i - V.x + a) <= Math.abs(i - V.x - mr - a) ? V.x - a : V.x + mr + a;
367
- C = [{ x: i, y: n }, { x: w, y: n }, { x: za, y: n }, { x: za, y: u }, { x: s, y: u }, { x: s, y: $ }, { x: s, y: u }];
381
+ C = [{ x: i, y: n }, { x: w, y: n }, { x: d, y: n }, { x: d, y: $ }, { x: d, y: u }];
382
+ var kr = Mr(d, n, $, X);
383
+ if (kr) {
384
+ var V = s(kr), mr = kr.width || E, Ra = Math.abs(i - V.x + a) <= Math.abs(i - V.x - mr - a) ? V.x - a : V.x + mr + a;
385
+ C = [{ x: i, y: n }, { x: w, y: n }, { x: Ra, y: n }, { x: Ra, y: u }, { x: d, y: u }, { x: d, y: $ }, { x: d, y: u }];
368
386
  }
369
- var Qr = dr(w, s, n, X);
387
+ var Qr = dr(w, d, n, X);
370
388
  if (Qr) {
371
- var Rr = h(Qr), ha = Qr.height || c, H = Math.abs(u - Rr.y + a) <= Math.abs(u - Rr.y - ha - a) ? Rr.y - a : Rr.y + ha + a;
372
- C = [{ x: i, y: n }, { x: w, y: n }, { x: w, y: H }, { x: s, y: H }, { x: s, y: $ }, { x: s, y: u }];
389
+ var cr = s(Qr), ha = Qr.height || z, H = Math.abs(u - cr.y + a) <= Math.abs(u - cr.y - ha - a) ? cr.y - a : cr.y + ha + a;
390
+ C = [{ x: i, y: n }, { x: w, y: n }, { x: w, y: H }, { x: d, y: H }, { x: d, y: $ }, { x: d, y: u }];
373
391
  }
374
392
  } else {
375
- C = [{ x: i, y: n }, { x: i, y: Q }, { x: i, y: u }, { x: W, y: u }, { x: s, y: u }];
393
+ C = [{ x: i, y: n }, { x: i, y: Q }, { x: i, y: u }, { x: W, y: u }, { x: d, y: u }];
376
394
  var wr = dr(i, W, u, X);
377
395
  if (wr) {
378
- var na = h(wr), U = wr.height || c, zr = Math.abs(n - na.y + a) <= Math.abs(n - na.y - U - a) ? na.y - a : na.y + U + a;
379
- C = [{ x: i, y: n }, { x: i, y: Q }, { x: i, y: zr }, { x: W, y: zr }, { x: W, y: u }, { x: s, y: u }];
396
+ var na = s(wr), U = wr.height || z, Rr = Math.abs(n - na.y + a) <= Math.abs(n - na.y - U - a) ? na.y - a : na.y + U + a;
397
+ C = [{ x: i, y: n }, { x: i, y: Q }, { x: i, y: Rr }, { x: W, y: Rr }, { x: W, y: u }, { x: d, y: u }];
380
398
  }
381
399
  var nr = Mr(i, Q, u, X);
382
400
  if (nr) {
383
- var vr = h(nr), ca = nr.width || E, _a = Math.abs(s - vr.x + a) <= Math.abs(s - vr.x - ca - a) ? vr.x - a : vr.x + ca + a;
384
- C = [{ x: i, y: n }, { x: i, y: Q }, { x: _a, y: Q }, { x: _a, y: u }, { x: W, y: u }, { x: s, y: u }];
401
+ var vr = s(nr), za = nr.width || E, _a = Math.abs(d - vr.x + a) <= Math.abs(d - vr.x - za - a) ? vr.x - a : vr.x + za + a;
402
+ C = [{ x: i, y: n }, { x: i, y: Q }, { x: _a, y: Q }, { x: _a, y: u }, { x: W, y: u }, { x: d, y: u }];
385
403
  }
386
404
  }
387
405
  if (C) {
@@ -389,7 +407,7 @@ function ef() {
389
407
  var $a = $r[$r.length - 1];
390
408
  (Math.abs(C[lr].x - $a.x) > 0.1 || Math.abs(C[lr].y - $a.y) > 0.1) && $r.push(C[lr]);
391
409
  }
392
- o._routedPoints = $r, t = !0;
410
+ f._routedPoints = $r, t = !0;
393
411
  }
394
412
  }
395
413
  }
@@ -399,7 +417,7 @@ function ef() {
399
417
  }
400
418
  }
401
419
  function vt() {
402
- ga && (Xt || (Xt = !0, ae = !0, requestAnimationFrame(function() {
420
+ ya && (Xt || (Xt = !0, ae = !0, requestAnimationFrame(function() {
403
421
  Xt = !1;
404
422
  try {
405
423
  ef();
@@ -416,99 +434,99 @@ function ut() {
416
434
  if (t > 2)
417
435
  if (Br === "lines" && t >= 4 && t <= 512) {
418
436
  if ((xa || so !== t || Mo !== Br) && rf(t), jr && uo > 0) {
419
- var e = (g.x % t + t) % t, o = (g.y % t + t) % t;
420
- r.save(), r.translate(e, o);
421
- var v = r.createPattern(jr, "repeat");
422
- v && (r.fillStyle = v, r.fillRect(-e, -o, tr, er)), r.restore();
437
+ var e = (g.x % t + t) % t, f = (g.y % t + t) % t;
438
+ r.save(), r.translate(e, f);
439
+ var l = r.createPattern(jr, "repeat");
440
+ l && (r.fillStyle = l, r.fillRect(-e, -f, tr, er)), r.restore();
423
441
  }
424
442
  } else {
425
- var f = (g.x % t + t) % t, l = (g.y % t + t) % t, y = lt || z.grid;
443
+ var o = (g.x % t + t) % t, v = (g.y % t + t) % t, y = lt || R.grid;
426
444
  if (Br === "dots") {
427
445
  r.fillStyle = y;
428
- for (var d = Or * g.zoom, M = f; M < tr; M += t)
429
- for (var x = l; x < er; x += t)
430
- r.beginPath(), r.arc(Math.round(M), Math.round(x), d, 0, 6.2832), r.fill();
446
+ for (var M = Or * g.zoom, h = o; h < tr; h += t)
447
+ for (var x = v; x < er; x += t)
448
+ r.beginPath(), r.arc(Math.round(h), Math.round(x), M, 0, 6.2832), r.fill();
431
449
  } else if (Br === "cross") {
432
450
  r.strokeStyle = y, r.lineWidth = Or;
433
451
  var i = 3 * g.zoom;
434
452
  r.beginPath();
435
- for (var n = f; n < tr; n += t)
436
- for (var s = l; s < er; s += t) {
437
- var u = Math.round(n), w = Math.round(s);
453
+ for (var n = o; n < tr; n += t)
454
+ for (var d = v; d < er; d += t) {
455
+ var u = Math.round(n), w = Math.round(d);
438
456
  r.moveTo(u - i, w), r.lineTo(u + i, w), r.moveTo(u, w - i), r.lineTo(u, w + i);
439
457
  }
440
458
  r.stroke();
441
459
  } else {
442
- var Q = lt || z.grid;
460
+ var Q = lt || R.grid;
443
461
  r.beginPath(), r.strokeStyle = Q, r.lineWidth = Or * 0.5;
444
- for (var W = f; W < tr; W += t) {
462
+ for (var W = o; W < tr; W += t) {
445
463
  var $ = Math.round(W) + 0.5;
446
464
  r.moveTo($, 0), r.lineTo($, er);
447
465
  }
448
- for (var gr = l; gr < er; gr += t) {
449
- var qr = Math.round(gr) + 0.5;
450
- r.moveTo(0, qr), r.lineTo(tr, qr);
466
+ for (var yr = v; yr < er; yr += t) {
467
+ var Pr = Math.round(yr) + 0.5;
468
+ r.moveTo(0, Pr), r.lineTo(tr, Pr);
451
469
  }
452
470
  r.stroke();
453
471
  }
454
472
  }
455
- r.beginPath(), r.arc(g.x, g.y, 4 * g.zoom, 0, 6.2832), r.fillStyle = z.origin, r.fill(), r.save(), r.translate(g.x, g.y), r.scale(g.zoom, g.zoom);
456
- var Sr = 100, Gr = -g.x / g.zoom, Pr = -g.y / g.zoom, Hr = Gr + tr / g.zoom, Ir = Pr + er / g.zoom, X = Gr - Sr, Yr = Pr - Sr, Ta = Hr + Sr, C = Ir + Sr;
473
+ r.beginPath(), r.arc(g.x, g.y, 4 * g.zoom, 0, 6.2832), r.fillStyle = R.origin, r.fill(), r.save(), r.translate(g.x, g.y), r.scale(g.zoom, g.zoom);
474
+ var qr = 100, Sr = -g.x / g.zoom, Gr = -g.y / g.zoom, Hr = Sr + tr / g.zoom, Ir = Gr + er / g.zoom, X = Sr - qr, Yr = Gr - qr, ka = Hr + qr, C = Ir + qr;
457
475
  if (O.length > 0) {
458
- var L = to(Gr, Pr, Hr, Ir), fr = L.length, st = g.zoom > 0.15, ma = g.zoom > 0.3, pr = g.zoom > 0.08 && fr < 200;
476
+ var L = to(Sr, Gr, Hr, Ir), fr = L.length, st = g.zoom > 0.15, ma = g.zoom > 0.3, pr = g.zoom > 0.08 && fr < 200;
459
477
  if (pr) {
460
- r.shadowColor = z.cardShadow, r.shadowBlur = 6, r.shadowOffsetY = 2, r.fillStyle = z.cardBg, r.beginPath();
478
+ r.shadowColor = R.cardShadow, r.shadowBlur = 6, r.shadowOffsetY = 2, r.fillStyle = R.cardBg, r.beginPath();
461
479
  for (var ra = 0; ra < fr; ra++) {
462
- var yr = O[L[ra]];
463
- r.roundRect(yr.x, yr.y, yr.w, yr.h, Ga);
480
+ var gr = O[L[ra]];
481
+ r.roundRect(gr.x, gr.y, gr.w, gr.h, Sa);
464
482
  }
465
483
  r.fill(), r.shadowColor = "transparent", r.shadowBlur = 0, r.shadowOffsetY = 0;
466
484
  }
467
485
  if (!pr) {
468
- r.fillStyle = z.cardBg, r.beginPath();
486
+ r.fillStyle = R.cardBg, r.beginPath();
469
487
  for (var aa = 0; aa < fr; aa++) {
470
488
  var ta = O[L[aa]];
471
- r.roundRect(ta.x, ta.y, ta.w, ta.h, Ga);
489
+ r.roundRect(ta.x, ta.y, ta.w, ta.h, Sa);
472
490
  }
473
491
  r.fill();
474
492
  }
475
- r.strokeStyle = z.cardBorder, r.lineWidth = 0.5, r.beginPath();
493
+ r.strokeStyle = R.cardBorder, r.lineWidth = 0.5, r.beginPath();
476
494
  for (var ea = 0; ea < fr; ea++) {
477
495
  var Zr = O[L[ea]];
478
- r.roundRect(Zr.x, Zr.y, Zr.w, Zr.h, Ga);
496
+ r.roundRect(Zr.x, Zr.y, Zr.w, Zr.h, Sa);
479
497
  }
480
498
  r.stroke();
481
499
  for (var Jr = [{}, {}, {}, {}], N = 0; N < fr; N++) {
482
- var Qa = L[N], Ra = Qa % 4;
483
- Jr[Ra].items || (Jr[Ra].items = []), Jr[Ra].items.push(O[Qa]);
500
+ var Qa = L[N], ca = Qa % 4;
501
+ Jr[ca].items || (Jr[ca].items = []), Jr[ca].items.push(O[Qa]);
484
502
  }
485
503
  for (var xr = 0; xr < 4; xr++) {
486
- var kr = Jr[xr].items;
487
- if (!(!kr || kr.length === 0)) {
504
+ var Tr = Jr[xr].items;
505
+ if (!(!Tr || Tr.length === 0)) {
488
506
  r.fillStyle = Do[xr], r.beginPath();
489
- for (var oa = 0; oa < kr.length; oa++) {
490
- var Kr = kr[oa];
491
- r.roundRect(Kr.x, Kr.y, Kr.w, 30, [Ga, Ga, 0, 0]);
507
+ for (var oa = 0; oa < Tr.length; oa++) {
508
+ var Kr = Tr[oa];
509
+ r.roundRect(Kr.x, Kr.y, Kr.w, 30, [Sa, Sa, 0, 0]);
492
510
  }
493
511
  r.fill();
494
512
  }
495
513
  }
496
514
  if (st) {
497
- r.fillStyle = z.titleText, r.font = Fo;
515
+ r.fillStyle = R.titleText, r.font = Fo;
498
516
  for (var fa = 0; fa < fr; fa++) {
499
517
  var wa = O[L[fa]];
500
518
  r.fillText(wa.title, wa.x + 12, wa.y + 19);
501
519
  }
502
- r.fillStyle = z.bodyText, r.font = jo;
520
+ r.fillStyle = R.bodyText, r.font = jo;
503
521
  for (var va = 0; va < fr; va++) {
504
522
  var la = O[L[va]];
505
523
  r.fillText(la.body, la.x + 12, la.y + 52);
506
524
  }
507
525
  if (ma) {
508
- r.fillStyle = z.coordText, r.font = Oo;
526
+ r.fillStyle = R.coordText, r.font = Oo;
509
527
  for (var ia = 0; ia < fr; ia++) {
510
- var Tr = O[L[ia]];
511
- r.fillText("(" + Tr.x + ", " + Tr.y + ")", Tr.x + 12, Tr.y + 75);
528
+ var kr = O[L[ia]];
529
+ r.fillText("(" + kr.x + ", " + kr.y + ")", kr.x + 12, kr.y + 75);
512
530
  }
513
531
  }
514
532
  }
@@ -516,20 +534,20 @@ function ut() {
516
534
  var V = [], mr = null;
517
535
  if (B.length > 0)
518
536
  if (mr = {}, B.length > 100)
519
- for (var za = no(X, Yr, Ta, C), Qr = 0; Qr < za.length; Qr++) {
520
- var Rr = B[za[Qr]];
521
- mr[Rr.id] = !0, Rr._customRendered || V.push(Rr);
537
+ for (var Ra = no(X, Yr, ka, C), Qr = 0; Qr < Ra.length; Qr++) {
538
+ var cr = B[Ra[Qr]];
539
+ mr[cr.id] = !0, cr._customRendered || V.push(cr);
522
540
  }
523
541
  else
524
542
  for (var ha = 0; ha < B.length; ha++) {
525
543
  var H = B[ha];
526
544
  if (!H.hidden) {
527
- var wr = H.width || E, na = H.height || c;
528
- h(H).x + wr < X || h(H).x > Ta || h(H).y + na < Yr || h(H).y > C || (mr[H.id] = !0, H._customRendered || V.push(H));
545
+ var wr = H.width || E, na = H.height || z;
546
+ s(H).x + wr < X || s(H).x > ka || s(H).y + na < Yr || s(H).y > C || (mr[H.id] = !0, H._customRendered || V.push(H));
529
547
  }
530
548
  }
531
549
  var U = V.length;
532
- if (P.length > 0 && B.length > 0) {
550
+ if (G.length > 0 && B.length > 0) {
533
551
  let ot = function(Lr, ro) {
534
552
  if (Lr.length) {
535
553
  r.fillStyle = ro, r.beginPath();
@@ -542,7 +560,7 @@ function ut() {
542
560
  };
543
561
  var of = ot;
544
562
  nt && po();
545
- var zr = null, nr = null, vr = null, ca = [], _a = [], $r = [], lr = [], $a = g.zoom > 0.3, yo = g.zoom > 0.05, ua;
563
+ var Rr = null, nr = null, vr = null, za = [], _a = [], $r = [], lr = [], $a = g.zoom > 0.3, go = g.zoom > 0.05, ua;
546
564
  if (mr && B.length > 100) {
547
565
  var oe = {};
548
566
  ua = [];
@@ -550,243 +568,243 @@ function ut() {
550
568
  var dt = Cr[xo];
551
569
  if (dt)
552
570
  for (var Mt = 0; Mt < dt.length; Mt++) {
553
- var gt = dt[Mt];
554
- oe[gt] || (oe[gt] = !0, ua.push(gt));
571
+ var yt = dt[Mt];
572
+ oe[yt] || (oe[yt] = !0, ua.push(yt));
555
573
  }
556
574
  }
557
575
  } else {
558
576
  ua = [];
559
- for (var yt = 0; yt < P.length; yt++) ua.push(yt);
577
+ for (var gt = 0; gt < G.length; gt++) ua.push(gt);
560
578
  }
561
579
  for (var xt = 0; xt < ua.length; xt++) {
562
- var D = P[ua[xt]], Vr = eo(D.source), Ur = eo(D.target);
580
+ var D = G[ua[xt]], Vr = eo(D.source), Ur = eo(D.target);
563
581
  if (!(!Vr || !Ur) && !(Vr.hidden || Ur.hidden) && !D._customRendered) {
564
- var Va = it(Vr, "source", D.sourceHandle), Ua = it(Ur, "target", D.targetHandle), _ = Va.x, R = Va.y, T = Ua.x, m = Ua.y, ir = D.type || "default", fe = D.selected, ve = D.animated, q;
565
- fe ? (nr || (nr = new Path2D()), q = nr) : ve ? (vr || (vr = new Path2D()), q = vr) : (zr || (zr = new Path2D()), q = zr);
566
- var S = D._routedPoints;
567
- if (S && S.length >= 2)
568
- io(q, S);
582
+ var Va = it(Vr, "source", D.sourceHandle), Ua = it(Ur, "target", D.targetHandle), _ = Va.x, c = Va.y, k = Ua.x, m = Ua.y, ir = D.type || "default", fe = D.selected, ve = D.animated, P;
583
+ fe ? (nr || (nr = new Path2D()), P = nr) : ve ? (vr || (vr = new Path2D()), P = vr) : (Rr || (Rr = new Path2D()), P = Rr);
584
+ var q = D._routedPoints;
585
+ if (q && q.length >= 2)
586
+ io(P, q);
569
587
  else if (ir === "straight")
570
- q.moveTo(_, R), q.lineTo(T, m);
588
+ P.moveTo(_, c), P.lineTo(k, m);
571
589
  else if (ir === "step" || ir === "smoothstep")
572
590
  try {
573
- var Y = Va.position || "right", sa = Ua.position || "left", k = 20, I = _, F = R, Z = T, p = m;
574
- Y === "right" ? I += k : Y === "left" ? I -= k : Y === "bottom" ? F += k : Y === "top" && (F -= k), sa === "right" ? Z += k : sa === "left" ? Z -= k : sa === "bottom" ? p += k : sa === "top" && (p -= k);
575
- var Da = h(Vr), Fa = h(Ur), Aa = Vr.width || E, Ea = Vr.height || c, le = Ur.width || E, ie = Ur.height || c, kt = Y === "left" || Y === "right", he = sa === "left" || sa === "right", Tt = {};
576
- Tt[D.source] = !0, Tt[D.target] = !0;
577
- var rr = go(
578
- Math.min(_, T) - Aa,
579
- Math.min(R, m) - Ea,
580
- Math.max(_, T) + le,
581
- Math.max(R, m) + ie,
582
- Tt
591
+ var Y = Va.position || "right", sa = Ua.position || "left", T = 20, I = _, F = c, Z = k, p = m;
592
+ Y === "right" ? I += T : Y === "left" ? I -= T : Y === "bottom" ? F += T : Y === "top" && (F -= T), sa === "right" ? Z += T : sa === "left" ? Z -= T : sa === "bottom" ? p += T : sa === "top" && (p -= T);
593
+ var Da = s(Vr), Fa = s(Ur), Aa = Vr.width || E, Ea = Vr.height || z, le = Ur.width || E, ie = Ur.height || z, Tt = Y === "left" || Y === "right", he = sa === "left" || sa === "right", kt = {};
594
+ kt[D.source] = !0, kt[D.target] = !0;
595
+ var rr = yo(
596
+ Math.min(_, k) - Aa,
597
+ Math.min(c, m) - Ea,
598
+ Math.max(_, k) + le,
599
+ Math.max(c, m) + ie,
600
+ kt
583
601
  );
584
602
  rr.push(Vr), rr.push(Ur);
585
603
  var b = [];
586
- if (kt && he) {
587
- var J, ko = Y === "right" && I < Z, To = Y === "left" && I > Z;
588
- if (ko || To) {
604
+ if (Tt && he) {
605
+ var J, To = Y === "right" && I < Z, ko = Y === "left" && I > Z;
606
+ if (To || ko) {
589
607
  J = (I + Z) / 2;
590
- var mt = Mr(J, R, m, rr);
608
+ var mt = Mr(J, c, m, rr);
591
609
  if (mt) {
592
- var Rt = h(mt), wr = mt.width || E;
593
- J < Rt.x + wr / 2 ? J = Rt.x - k : J = Rt.x + wr + k;
610
+ var ct = s(mt), wr = mt.width || E;
611
+ J < ct.x + wr / 2 ? J = ct.x - T : J = ct.x + wr + T;
594
612
  }
595
613
  } else
596
- Y === "right" ? J = Math.max(Da.x + Aa, Fa.x + le) + k : J = Math.min(Da.x, Fa.x) - k;
597
- b = [{ x: I, y: R }, { x: J, y: R }, { x: J, y: m }, { x: Z, y: m }];
614
+ Y === "right" ? J = Math.max(Da.x + Aa, Fa.x + le) + T : J = Math.min(Da.x, Fa.x) - T;
615
+ b = [{ x: I, y: c }, { x: J, y: c }, { x: J, y: m }, { x: Z, y: m }];
598
616
  var wt = dr(J, Z, m, rr);
599
617
  if (wt) {
600
- var ne = h(wt), mo = wt.height || c, ue = ne.y - k, se = ne.y + mo + k, de = Math.abs(R - ue) <= Math.abs(R - se) ? ue : se;
618
+ var ne = s(wt), mo = wt.height || z, ue = ne.y - T, se = ne.y + mo + T, de = Math.abs(c - ue) <= Math.abs(c - se) ? ue : se;
601
619
  b = [
602
- { x: I, y: R },
603
- { x: J, y: R },
620
+ { x: I, y: c },
621
+ { x: J, y: c },
604
622
  { x: J, y: de },
605
623
  { x: Z, y: de },
606
624
  { x: Z, y: m }
607
625
  ];
608
626
  }
609
- var zt = dr(I, J, R, rr);
610
- if (zt) {
611
- var Me = h(zt), Ro = zt.height || c, ge = Me.y - k, ye = Me.y + Ro + k, xe = Math.abs(m - ge) <= Math.abs(m - ye) ? ge : ye;
627
+ var Rt = dr(I, J, c, rr);
628
+ if (Rt) {
629
+ var Me = s(Rt), co = Rt.height || z, ye = Me.y - T, ge = Me.y + co + T, xe = Math.abs(m - ye) <= Math.abs(m - ge) ? ye : ge;
612
630
  b.splice(
613
631
  1,
614
632
  0,
615
633
  { x: I, y: xe },
616
634
  { x: J, y: xe }
617
635
  ), b = b.filter(function(Lr, ro) {
618
- return !(Math.abs(Lr.x - J) < 1 && Math.abs(Lr.y - R) < 1);
619
- }), b.splice(0, 0, { x: I, y: R });
636
+ return !(Math.abs(Lr.x - J) < 1 && Math.abs(Lr.y - c) < 1);
637
+ }), b.splice(0, 0, { x: I, y: c });
620
638
  }
621
- } else if (!kt && !he) {
622
- var K, wo = Y === "bottom" && F < p, zo = Y === "top" && F > p;
623
- if (wo || zo) {
639
+ } else if (!Tt && !he) {
640
+ var K, wo = Y === "bottom" && F < p, Ro = Y === "top" && F > p;
641
+ if (wo || Ro) {
624
642
  K = (F + p) / 2;
625
- var ct = dr(_, T, K, rr);
626
- if (ct) {
627
- var _t = h(ct), ke = ct.height || c;
628
- K < _t.y + ke / 2 ? K = _t.y - k : K = _t.y + ke + k;
643
+ var zt = dr(_, k, K, rr);
644
+ if (zt) {
645
+ var _t = s(zt), Te = zt.height || z;
646
+ K < _t.y + Te / 2 ? K = _t.y - T : K = _t.y + Te + T;
629
647
  }
630
648
  } else
631
- Y === "bottom" ? K = Math.max(Da.y + Ea, Fa.y + ie) + k : K = Math.min(Da.y, Fa.y) - k;
632
- b = [{ x: _, y: F }, { x: _, y: K }, { x: T, y: K }, { x: T, y: p }];
649
+ Y === "bottom" ? K = Math.max(Da.y + Ea, Fa.y + ie) + T : K = Math.min(Da.y, Fa.y) - T;
650
+ b = [{ x: _, y: F }, { x: _, y: K }, { x: k, y: K }, { x: k, y: p }];
633
651
  var At = Mr(_, F, K, rr);
634
652
  if (At) {
635
- var Te = h(At), co = At.width || E, me = Te.x - k, Re = Te.x + co + k, we = Math.abs(T - me) <= Math.abs(T - Re) ? me : Re;
653
+ var ke = s(At), zo = At.width || E, me = ke.x - T, ce = ke.x + zo + T, we = Math.abs(k - me) <= Math.abs(k - ce) ? me : ce;
636
654
  b = [
637
655
  { x: _, y: F },
638
656
  { x: we, y: F },
639
657
  { x: we, y: K },
640
- { x: T, y: K },
641
- { x: T, y: p }
658
+ { x: k, y: K },
659
+ { x: k, y: p }
642
660
  ];
643
661
  }
644
- var Et = Mr(T, K, p, rr);
662
+ var Et = Mr(k, K, p, rr);
645
663
  if (Et) {
646
- var ze = h(Et), _o = Et.height || c, ce = ze.y - k, _e = ze.y + _o + k, Ao = Math.abs(K - ce) <= Math.abs(K - _e) ? ce : _e;
664
+ var Re = s(Et), _o = Et.height || z, ze = Re.y - T, _e = Re.y + _o + T, Ao = Math.abs(K - ze) <= Math.abs(K - _e) ? ze : _e;
647
665
  b.splice(
648
666
  b.length - 1,
649
667
  0,
650
668
  { x: Z, y: Ao }
651
669
  );
652
670
  }
653
- } else if (kt) {
654
- b = [{ x: I, y: R }, { x: T, y: R }, { x: T, y: p }];
655
- var Wt = Mr(T, R, p, rr);
671
+ } else if (Tt) {
672
+ b = [{ x: I, y: c }, { x: k, y: c }, { x: k, y: p }];
673
+ var Wt = Mr(k, c, p, rr);
656
674
  if (Wt) {
657
- var Ae = h(Wt), Eo = Wt.width || E, Ee = Ae.x - k, We = Ae.x + Eo + k, Le = Math.abs(_ - Ee) <= Math.abs(_ - We) ? Ee : We;
658
- b = [{ x: I, y: R }, { x: Le, y: R }, { x: Le, y: m }, { x: T, y: m }, { x: T, y: p }];
675
+ var Ae = s(Wt), Eo = Wt.width || E, Ee = Ae.x - T, We = Ae.x + Eo + T, Le = Math.abs(_ - Ee) <= Math.abs(_ - We) ? Ee : We;
676
+ b = [{ x: I, y: c }, { x: Le, y: c }, { x: Le, y: m }, { x: k, y: m }, { x: k, y: p }];
659
677
  }
660
- var Lt = dr(I, T, R, rr);
678
+ var Lt = dr(I, k, c, rr);
661
679
  if (Lt) {
662
- var Ce = h(Lt), Wo = Lt.height || c, Be = Ce.y - k, be = Ce.y + Wo + k, Ne = Math.abs(m - Be) <= Math.abs(m - be) ? Be : be;
663
- b = [{ x: I, y: R }, { x: I, y: Ne }, { x: T, y: Ne }, { x: T, y: p }];
680
+ var Ce = s(Lt), Wo = Lt.height || z, Be = Ce.y - T, be = Ce.y + Wo + T, Ne = Math.abs(m - Be) <= Math.abs(m - be) ? Be : be;
681
+ b = [{ x: I, y: c }, { x: I, y: Ne }, { x: k, y: Ne }, { x: k, y: p }];
664
682
  }
665
683
  } else {
666
684
  b = [{ x: _, y: F }, { x: _, y: m }, { x: Z, y: m }];
667
685
  var Ct = dr(_, Z, m, rr);
668
686
  if (Ct) {
669
- var qe = h(Ct), Lo = Ct.height || c, Se = qe.y - k, Ge = qe.y + Lo + k, Pe = Math.abs(R - Se) <= Math.abs(R - Ge) ? Se : Ge;
670
- b = [{ x: _, y: F }, { x: _, y: Pe }, { x: Z, y: Pe }, { x: Z, y: m }];
687
+ var Pe = s(Ct), Lo = Ct.height || z, qe = Pe.y - T, Se = Pe.y + Lo + T, Ge = Math.abs(c - qe) <= Math.abs(c - Se) ? qe : Se;
688
+ b = [{ x: _, y: F }, { x: _, y: Ge }, { x: Z, y: Ge }, { x: Z, y: m }];
671
689
  }
672
690
  var Bt = Mr(_, F, m, rr);
673
691
  if (Bt) {
674
- var Ie = h(Bt), Co = Bt.width || E, Ze = Ie.x - k, Je = Ie.x + Co + k, Ke = Math.abs(T - Ze) <= Math.abs(T - Je) ? Ze : Je;
692
+ var Ie = s(Bt), Co = Bt.width || E, Ze = Ie.x - T, Je = Ie.x + Co + T, Ke = Math.abs(k - Ze) <= Math.abs(k - Je) ? Ze : Je;
675
693
  b = [{ x: _, y: F }, { x: Ke, y: F }, { x: Ke, y: m }, { x: Z, y: m }];
676
694
  }
677
695
  }
678
- for (var Dr = [{ x: _, y: R }], bt = 0; bt < b.length; bt++) Dr.push(b[bt]);
679
- Dr.push({ x: T, y: m });
696
+ for (var Dr = [{ x: _, y: c }], bt = 0; bt < b.length; bt++) Dr.push(b[bt]);
697
+ Dr.push({ x: k, y: m });
680
698
  for (var ar = [Dr[0]], Wa = 1; Wa < Dr.length; Wa++) {
681
699
  var La = ar[ar.length - 1];
682
700
  (Math.abs(Dr[Wa].x - La.x) > 0.1 || Math.abs(Dr[Wa].y - La.y) > 0.1) && ar.push(Dr[Wa]);
683
701
  }
684
702
  var Qe = ir === "smoothstep" ? 8 : 0;
685
- q.moveTo(ar[0].x, ar[0].y);
703
+ P.moveTo(ar[0].x, ar[0].y);
686
704
  for (var ur = 1; ur < ar.length; ur++)
687
705
  if (Qe > 0 && ur > 0 && ur < ar.length - 1) {
688
- var sr = ar[ur - 1], A = ar[ur], cr = ar[ur + 1];
689
- if (Math.abs(sr.x - A.x) < 0.5 && Math.abs(A.x - cr.x) < 0.5 || Math.abs(sr.y - A.y) < 0.5 && Math.abs(A.y - cr.y) < 0.5)
690
- q.lineTo(A.x, A.y);
706
+ var sr = ar[ur - 1], A = ar[ur], zr = ar[ur + 1];
707
+ if (Math.abs(sr.x - A.x) < 0.5 && Math.abs(A.x - zr.x) < 0.5 || Math.abs(sr.y - A.y) < 0.5 && Math.abs(A.y - zr.y) < 0.5)
708
+ P.lineTo(A.x, A.y);
691
709
  else {
692
- var ja = Math.min(Math.hypot(sr.x - A.x, sr.y - A.y) / 2, Math.hypot(A.x - cr.x, A.y - cr.y) / 2, Qe);
693
- Math.abs(sr.y - A.y) < 0.5 ? (q.lineTo(A.x + (sr.x < cr.x ? -1 : 1) * ja, A.y), q.quadraticCurveTo(A.x, A.y, A.x, A.y + (sr.y < cr.y ? 1 : -1) * ja)) : (q.lineTo(A.x, A.y + (sr.y < cr.y ? -1 : 1) * ja), q.quadraticCurveTo(A.x, A.y, A.x + (sr.x < cr.x ? 1 : -1) * ja, A.y));
710
+ var ja = Math.min(Math.hypot(sr.x - A.x, sr.y - A.y) / 2, Math.hypot(A.x - zr.x, A.y - zr.y) / 2, Qe);
711
+ Math.abs(sr.y - A.y) < 0.5 ? (P.lineTo(A.x + (sr.x < zr.x ? -1 : 1) * ja, A.y), P.quadraticCurveTo(A.x, A.y, A.x, A.y + (sr.y < zr.y ? 1 : -1) * ja)) : (P.lineTo(A.x, A.y + (sr.y < zr.y ? -1 : 1) * ja), P.quadraticCurveTo(A.x, A.y, A.x + (sr.x < zr.x ? 1 : -1) * ja, A.y));
694
712
  }
695
713
  } else
696
- q.lineTo(ar[ur].x, ar[ur].y);
714
+ P.lineTo(ar[ur].x, ar[ur].y);
697
715
  } catch (Lr) {
698
716
  console.error("[worker] smoothstep error:", Lr, "edge:", D.id);
699
717
  }
700
718
  else {
701
- var _r = Va.position || "right", Ar = Ua.position || "left", Er = 20, Ca = _, Oa = R, Ba = T, Xa = m;
719
+ var _r = Va.position || "right", Ar = Ua.position || "left", Er = 20, Ca = _, Oa = c, Ba = k, Xa = m;
702
720
  _r === "right" ? Ca += Er : _r === "left" ? Ca -= Er : _r === "bottom" ? Oa += Er : _r === "top" && (Oa -= Er), Ar === "right" ? Ba += Er : Ar === "left" ? Ba -= Er : Ar === "bottom" ? Xa += Er : Ar === "top" && (Xa -= Er);
703
- var Bo = Math.abs(Ba - Ca), Wr = Math.max(50, Bo * 0.5), bo = Ca + (_r === "left" ? -Wr : _r === "right" ? Wr : 0), No = Oa + (_r === "top" ? -Wr : _r === "bottom" ? Wr : 0), qo = Ba + (Ar === "left" ? -Wr : Ar === "right" ? Wr : 0), So = Xa + (Ar === "top" ? -Wr : Ar === "bottom" ? Wr : 0);
704
- q.moveTo(_, R), q.lineTo(Ca, Oa), q.bezierCurveTo(bo, No, qo, So, Ba, Xa), q.lineTo(T, m);
721
+ var Bo = Math.abs(Ba - Ca), Wr = Math.max(50, Bo * 0.5), bo = Ca + (_r === "left" ? -Wr : _r === "right" ? Wr : 0), No = Oa + (_r === "top" ? -Wr : _r === "bottom" ? Wr : 0), Po = Ba + (Ar === "left" ? -Wr : Ar === "right" ? Wr : 0), qo = Xa + (Ar === "top" ? -Wr : Ar === "bottom" ? Wr : 0);
722
+ P.moveTo(_, c), P.lineTo(Ca, Oa), P.bezierCurveTo(bo, No, Po, qo, Ba, Xa), P.lineTo(k, m);
705
723
  }
706
- if (yo) {
707
- var Go = 8, ba;
708
- if (S && S.length >= 2) {
709
- var La = S[S.length - 1], $e = S[S.length - 2];
724
+ if (go) {
725
+ var So = 8, ba;
726
+ if (q && q.length >= 2) {
727
+ var La = q[q.length - 1], $e = q[q.length - 2];
710
728
  ba = Math.atan2(La.y - $e.y, La.x - $e.x);
711
729
  } else if (ir === "straight")
712
- ba = Math.atan2(m - R, T - _);
730
+ ba = Math.atan2(m - c, k - _);
713
731
  else if (ir === "step" || ir === "smoothstep")
714
732
  ba = 0;
715
733
  else {
716
- var Ve = re(_, R, T, m);
717
- ba = Math.atan2(m - Ve.cp2y, T - Ve.cp2x);
734
+ var Ve = re(_, c, k, m);
735
+ ba = Math.atan2(m - Ve.cp2y, k - Ve.cp2x);
718
736
  }
719
- var Ue = S && S.length >= 2 ? S[S.length - 1] : { x: T, y: m }, Nt = { x: Ue.x, y: Ue.y, angle: ba, size: Go };
720
- fe ? _a.push(Nt) : ve ? $r.push(Nt) : ca.push(Nt);
737
+ var Ue = q && q.length >= 2 ? q[q.length - 1] : { x: k, y: m }, Nt = { x: Ue.x, y: Ue.y, angle: ba, size: So };
738
+ fe ? _a.push(Nt) : ve ? $r.push(Nt) : za.push(Nt);
721
739
  }
722
740
  if ($a && D.label) {
723
741
  var Na;
724
- S && S.length >= 2 ? Na = af(S) : ir === "straight" || ir === "step" || ir === "smoothstep" ? Na = { x: (_ + T) / 2, y: (R + m) / 2 } : Na = tf(_, R, T, m), lr.push({ text: D.label, x: Na.x, y: Na.y });
742
+ q && q.length >= 2 ? Na = af(q) : ir === "straight" || ir === "step" || ir === "smoothstep" ? Na = { x: (_ + k) / 2, y: (c + m) / 2 } : Na = tf(_, c, k, m), lr.push({ text: D.label, x: Na.x, y: Na.y });
725
743
  }
726
744
  }
727
745
  }
728
- if (zr && (r.strokeStyle = z.edgeStroke, r.lineWidth = 1.5, r.setLineDash([]), r.stroke(zr)), vr && (r.strokeStyle = z.edgeAnimated, r.lineWidth = 1.5, r.setLineDash([5, 5]), r.lineDashOffset = -pt, r.stroke(vr), r.setLineDash([])), nr && (r.strokeStyle = z.edgeSelected, r.lineWidth = 2.5, r.setLineDash([]), r.stroke(nr)), ot(ca, z.edgeStroke), ot($r, z.edgeAnimated), ot(_a, z.edgeSelected), lr.length > 0) {
746
+ if (Rr && (r.strokeStyle = R.edgeStroke, r.lineWidth = 1.5, r.setLineDash([]), r.stroke(Rr)), vr && (r.strokeStyle = R.edgeAnimated, r.lineWidth = 1.5, r.setLineDash([5, 5]), r.lineDashOffset = -pt, r.stroke(vr), r.setLineDash([])), nr && (r.strokeStyle = R.edgeSelected, r.lineWidth = 2.5, r.setLineDash([]), r.stroke(nr)), ot(za, R.edgeStroke), ot($r, R.edgeAnimated), ot(_a, R.edgeSelected), lr.length > 0) {
729
747
  r.font = Ho, r.textAlign = "center", r.textBaseline = "middle";
730
- for (var qt = 0; qt < lr.length; qt++) {
731
- var da = lr[qt], Po = r.measureText(da.text), De = Po.width + 12;
732
- r.fillStyle = G ? "#2a2a2a" : "#ffffff", r.fillRect(da.x - De / 2, da.y - 9, De, 18), r.fillStyle = z.nodeText, r.fillText(da.text, da.x, da.y);
748
+ for (var Pt = 0; Pt < lr.length; Pt++) {
749
+ var da = lr[Pt], Go = r.measureText(da.text), De = Go.width + 12;
750
+ r.fillStyle = S ? "#2a2a2a" : "#ffffff", r.fillRect(da.x - De / 2, da.y - 9, De, 18), r.fillStyle = R.nodeText, r.fillText(da.text, da.x, da.y);
733
751
  }
734
752
  r.textAlign = "start", r.textBaseline = "alphabetic";
735
753
  }
736
754
  }
737
- if (Pa) {
738
- r.beginPath(), r.strokeStyle = z.connectionLine, r.lineWidth = 2, r.setLineDash([6, 4]);
739
- var St = Pa._routedPoints;
740
- if (St && St.length >= 2) {
755
+ if (Ga) {
756
+ r.beginPath(), r.strokeStyle = R.connectionLine, r.lineWidth = 2, r.setLineDash([6, 4]);
757
+ var qt = Ga._routedPoints;
758
+ if (qt && qt.length >= 2) {
741
759
  var Fe = new Path2D();
742
- io(Fe, St), r.stroke(Fe);
760
+ io(Fe, qt), r.stroke(Fe);
743
761
  } else {
744
- var Ha = Pa.from, Ya = Pa.to, pa = re(Ha.x, Ha.y, Ya.x, Ya.y);
762
+ var Ha = Ga.from, Ya = Ga.to, pa = re(Ha.x, Ha.y, Ya.x, Ya.y);
745
763
  r.moveTo(Ha.x, Ha.y), r.bezierCurveTo(pa.cp1x, pa.cp1y, pa.cp2x, pa.cp2y, Ya.x, Ya.y), r.stroke();
746
764
  }
747
765
  r.setLineDash([]);
748
766
  }
749
767
  if (hr) {
750
768
  var je = Math.min(hr.startWorld.x, hr.endWorld.x), Oe = Math.min(hr.startWorld.y, hr.endWorld.y), Aa = Math.abs(hr.endWorld.x - hr.startWorld.x), Ea = Math.abs(hr.endWorld.y - hr.startWorld.y);
751
- r.fillStyle = G ? "rgba(59,130,246,0.08)" : "rgba(59,130,246,0.06)", r.fillRect(je, Oe, Aa, Ea), r.strokeStyle = "#3b82f6", r.lineWidth = 1 / g.zoom, r.setLineDash([]), r.strokeRect(je, Oe, Aa, Ea);
769
+ r.fillStyle = S ? "rgba(59,130,246,0.08)" : "rgba(59,130,246,0.06)", r.fillRect(je, Oe, Aa, Ea), r.strokeStyle = "#3b82f6", r.lineWidth = 1 / g.zoom, r.setLineDash([]), r.strokeRect(je, Oe, Aa, Ea);
752
770
  }
753
771
  if (U > 0) {
754
772
  var Io = g.zoom > 0.12 && (g.zoom > 0.25 || U < 500), Xe = g.zoom > 0.08 && U < 200, Zo = g.zoom > 0.2 && U < 300;
755
773
  if (Xe) {
756
- r.shadowColor = z.nodeShadow, r.shadowBlur = 6, r.shadowOffsetY = 2, r.fillStyle = z.nodeBg, r.beginPath();
757
- for (var Gt = 0; Gt < U; Gt++) {
758
- var rt = V[Gt];
759
- r.roundRect(h(rt).x, h(rt).y, rt.width || E, rt.height || c, ft);
774
+ r.shadowColor = R.nodeShadow, r.shadowBlur = 6, r.shadowOffsetY = 2, r.fillStyle = R.nodeBg, r.beginPath();
775
+ for (var St = 0; St < U; St++) {
776
+ var rt = V[St];
777
+ r.roundRect(s(rt).x, s(rt).y, rt.width || E, rt.height || z, ft);
760
778
  }
761
779
  r.fill(), r.shadowColor = "transparent", r.shadowBlur = 0, r.shadowOffsetY = 0;
762
780
  }
763
781
  if (!Xe) {
764
- r.fillStyle = z.nodeBg, r.beginPath();
765
- for (var Pt = 0; Pt < U; Pt++) {
766
- var at = V[Pt];
767
- r.roundRect(h(at).x, h(at).y, at.width || E, at.height || c, ft);
782
+ r.fillStyle = R.nodeBg, r.beginPath();
783
+ for (var Gt = 0; Gt < U; Gt++) {
784
+ var at = V[Gt];
785
+ r.roundRect(s(at).x, s(at).y, at.width || E, at.height || z, ft);
768
786
  }
769
787
  r.fill();
770
788
  }
771
- r.strokeStyle = z.nodeBorder, r.lineWidth = 1, r.beginPath();
789
+ r.strokeStyle = R.nodeBorder, r.lineWidth = 1, r.beginPath();
772
790
  for (var It = 0; It < U; It++) {
773
- var qa = V[It];
774
- qa.selected || r.roundRect(h(qa).x, h(qa).y, qa.width || E, qa.height || c, ft);
791
+ var Pa = V[It];
792
+ Pa.selected || r.roundRect(s(Pa).x, s(Pa).y, Pa.width || E, Pa.height || z, ft);
775
793
  }
776
794
  r.stroke();
777
795
  var He = !1;
778
- r.strokeStyle = z.nodeSelectedBorder, r.lineWidth = 2, r.beginPath();
796
+ r.strokeStyle = R.nodeSelectedBorder, r.lineWidth = 2, r.beginPath();
779
797
  for (var Zt = 0; Zt < U; Zt++) {
780
- var Sa = V[Zt];
781
- Sa.selected && (He = !0, r.roundRect(h(Sa).x, h(Sa).y, Sa.width || E, Sa.height || c, ft));
798
+ var qa = V[Zt];
799
+ qa.selected && (He = !0, r.roundRect(s(qa).x, s(qa).y, qa.width || E, qa.height || z, ft));
782
800
  }
783
801
  if (He && r.stroke(), Io) {
784
- r.fillStyle = z.nodeText, r.font = Xo, r.textAlign = "center", r.textBaseline = "middle";
802
+ r.fillStyle = R.nodeText, r.font = Xo, r.textAlign = "center", r.textBaseline = "middle";
785
803
  for (var Jt = 0; Jt < U; Jt++) {
786
804
  var Fr = V[Jt];
787
805
  if (!(!Fr.data || !Fr.data.label)) {
788
- var Ye = Fr.width || E, Jo = Fr.height || c;
789
- r.fillText(Fr.data.label, h(Fr).x + Ye / 2, h(Fr).y + Jo / 2, Ye - 24);
806
+ var Ye = Fr.width || E, Jo = Fr.height || z;
807
+ r.fillText(Fr.data.label, s(Fr).x + Ye / 2, s(Fr).y + Jo / 2, Ye - 24);
790
808
  }
791
809
  }
792
810
  r.textAlign = "start", r.textBaseline = "alphabetic";
@@ -795,12 +813,12 @@ function ut() {
795
813
  for (var Kt = [], Qt = 0; Qt < U; Qt++)
796
814
  for (var pe = ho(V[Qt]), $t = 0; $t < pe.length; $t++)
797
815
  Kt.push(pe[$t]);
798
- r.fillStyle = z.handleFill, r.beginPath();
816
+ r.fillStyle = R.handleFill, r.beginPath();
799
817
  for (var Vt = 0; Vt < Kt.length; Vt++) {
800
818
  var tt = Kt[Vt];
801
819
  r.moveTo(tt.x + ao, tt.y), r.arc(tt.x, tt.y, ao, 0, 6.2832);
802
820
  }
803
- r.fill(), r.strokeStyle = z.handleBorder, r.lineWidth = 1.5, r.stroke();
821
+ r.fill(), r.strokeStyle = R.handleBorder, r.lineWidth = 1.5, r.stroke();
804
822
  }
805
823
  }
806
824
  r.restore();
@@ -818,13 +836,13 @@ function ut() {
818
836
  zoom: g.zoom.toFixed(2),
819
837
  renderMs: Ko,
820
838
  fps: fo,
821
- visible: O.length > 0 ? to(Gr, Pr, Hr, Ir).length : 0,
839
+ visible: O.length > 0 ? to(Sr, Gr, Hr, Ir).length : 0,
822
840
  nodeCount: B.length,
823
841
  visibleNodes: U,
824
- edgeCount: P.length
842
+ edgeCount: G.length
825
843
  }
826
844
  });
827
845
  }
828
846
  }
829
847
  }
830
- `,Bn=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",Gn],{type:"text/javascript;charset=utf-8"});function jr(t){let e;try{if(e=Bn&&(self.URL||self.webkitURL).createObjectURL(Bn),!e)throw"";const n=new Worker(e,{type:"module",name:t==null?void 0:t.name});return n.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),n}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(Gn),{type:"module",name:t==null?void 0:t.name})}}const gn=new WeakMap;function Dr(t,e){if(gn.has(t))return gn.get(t);const n=t.transferControlToOffscreen(),r=new jr;r.onerror=o=>console.error("[infinite-canvas] worker error:",o.message,o),r.postMessage({type:"init",data:{...e,canvas:n}},[n]);const s={worker:r};return gn.set(t,s),s}const Gt=160,Ft=60,Ar=10;function On({cards:t=[],nodes:e=[],edges:n=[],onHudUpdate:r,onNodesProcessed:s,onNodesChange:o,onEdgesChange:i,onConnect:l,onNodeClick:d,onNodeDragStart:u,onNodeDrag:g,onNodeDragStop:v,onEdgeClick:P,onEdgeDoubleClick:E,onEdgeMouseEnter:R,onEdgeMouseMove:T,onEdgeMouseLeave:k,onEdgeContextMenu:z,onNodeDoubleClick:_,onNodeMouseEnter:D,onNodeMouseMove:x,onNodeMouseLeave:h,onNodeContextMenu:p,onPaneClick:b,onPaneContextMenu:I,onPaneMouseEnter:w,onPaneMouseMove:$,onPaneMouseLeave:C,onSelectionChange:j,onConnectStart:q,onConnectEnd:F,onInit:gt,onMoveStart:K,onMove:nt,onMoveEnd:U,onDelete:G,onBeforeDelete:rt,onError:ct,isValidConnection:lt,dark:ot,gridSize:Nt=40,zoomMin:st=.1,zoomMax:xt=4,initialCamera:Et={x:0,y:0,zoom:1},fitView:Rt=!1,fitViewOptions:ut,nodesDraggable:dt=!0,nodesConnectable:wt=!0,elementsSelectable:zt=!0,multiSelectionKeyCode:ht="Shift",selectionOnDrag:Qt=!1,selectionMode:Re="partial",connectionMode:Lt="loose",connectionRadius:Xt=20,connectOnClick:Ht=!1,snapToGrid:fe=!1,snapGrid:se=[15,15],deleteKeyCode:he=["Delete","Backspace"],panActivationKeyCode:ye=" ",panOnScroll:Fe=!1,panOnScrollMode:ke="free",panOnScrollSpeed:Xe=.5,zoomOnScroll:Ye=!0,zoomOnDoubleClick:Ue=!0,zoomOnPinch:qe=!0,preventScrolling:Ce=!0,translateExtent:Kt,nodeExtent:Vt,defaultEdgeOptions:ge={},autoPanOnNodeDrag:cn=!0,autoPanOnConnect:ln=!0,autoPanSpeed:Yt=5,edgesReconnectable:Ln=!1,elevateNodesOnSelect:un=!1,edgeRouting:ie=!0}={}){const pt=a.useRef(null),Ee=a.useRef(null),kt=a.useRef(null),yt=a.useRef({...Et}),Jt=a.useRef([...t]),O=a.useRef([...e]),Pt=a.useRef([...n]),dn=a.useRef(new Map),ze=a.useRef(!1),Ot=a.useRef(null),[fn,hn]=a.useState(!1),Bt=a.useRef(null),jt=a.useRef(null),xe=a.useRef(null),te=a.useRef(null),_t=a.useRef(!1),pe=a.useRef(null),[Ne,Ge]=a.useState({x:Et.x,y:Et.y,zoom:Et.zoom}),[Oe,ee]=a.useState(null),Ut=a.useMemo(()=>new Set,[]),ae=a.useMemo(()=>new Set,[]),me=a.useRef(!1),Z=a.useRef({});Z.current={onHudUpdate:r,onNodesProcessed:s,onNodesChange:o,onEdgesChange:i,onConnect:l,onNodeClick:d,onNodeDragStart:u,onNodeDrag:g,onNodeDragStop:v,onEdgeClick:P,onEdgeDoubleClick:E,onEdgeMouseEnter:R,onEdgeMouseMove:T,onEdgeMouseLeave:k,onEdgeContextMenu:z,onNodeDoubleClick:_,onNodeMouseEnter:D,onNodeMouseMove:x,onNodeMouseLeave:h,onNodeContextMenu:p,onPaneClick:b,onPaneContextMenu:I,onPaneMouseEnter:w,onPaneMouseMove:$,onPaneMouseLeave:C,onSelectionChange:j,onConnectStart:q,onConnectEnd:F,onInit:gt,onMoveStart:K,onMove:nt,onMoveEnd:U,onDelete:G,onBeforeDelete:rt,onError:ct,isValidConnection:lt};const vt={get current(){return Z.current.onNodesChange}},St={get current(){return Z.current.onEdgesChange}},ne={get current(){return Z.current.onConnect}},Pe={get current(){return Z.current.onNodeClick}},Ie={get current(){return Z.current.onNodeDragStart}},Le={get current(){return Z.current.onNodeDrag}},Se={get current(){return Z.current.onNodeDragStop}},re={get current(){return Z.current.onEdgeClick}},Te={get current(){return Z.current.onPaneClick}},ce={get current(){return Z.current.onSelectionChange}},le={get current(){return Z.current.onHudUpdate}},ue={get current(){return Z.current.onNodesProcessed}};a.useEffect(()=>{const c=f=>{f.key===ht&&(_t.current=!0),f.key===ye&&(me.current=!0)},m=f=>{f.key===ht&&(_t.current=!1),f.key===ye&&(me.current=!1)};return window.addEventListener("keydown",c),window.addEventListener("keyup",m),()=>{window.removeEventListener("keydown",c),window.removeEventListener("keyup",m)}},[ht,ye]);const qt=a.useCallback(()=>{var M;const c=O.current.filter(L=>L.selected),m=Pt.current.filter(L=>L.selected),f={nodes:c,edges:m};(M=ce.current)==null||M.call(ce,f);for(const L of ae)L(f)},[ae]);a.useEffect(()=>{var c;Jt.current=[...t],(c=kt.current)==null||c.postMessage({type:"cards",data:{cards:[...t]}})},[t]);const ve=a.useCallback(c=>{const m={};for(const f of c)m[f.id]=f;return c.map(f=>{if(!f.parentId)return f;const M=m[f.parentId];if(!M)return f;let L=f.position.x,S=f.position.y,y=M;for(;y;)L+=y.position.x,S+=y.position.y,y=y.parentId?m[y.parentId]:null;return{...f,_absolutePosition:{x:L,y:S}}})},[]),Zt=a.useRef([]),Q=a.useCallback(c=>{const m=dn.current;if(!m||m.size===0)return c;const f={};for(const[,M]of m)f[M.nodeId]||(f[M.nodeId]=[]),f[M.nodeId].push({id:M.id,type:M.type,position:M.position,x:M.x,y:M.y});return c.map(M=>{const L=f[M.id];return L&&L.length>0?{...M,handles:L}:M})},[]),At=a.useCallback(()=>{var m;if(Bt.current)return;const c=Q(Zt.current);(m=kt.current)==null||m.postMessage({type:"nodes",data:{nodes:c}})},[Q]);a.useEffect(()=>{var f;if(Bt.current){const M=Bt.current.id,L=new Set([M,...Bt.current.selectedStarts.map(y=>y.id)]),S={};for(const y of O.current)L.has(y.id)&&(S[y.id]={...y.position});O.current=[...e];for(const y of O.current)S[y.id]&&(y.position=S[y.id]);Zt.current=ve(O.current);return}O.current=[...e];const c=ve(e);Zt.current=c;const m=Q(c);(f=kt.current)==null||f.postMessage({type:"nodes",data:{nodes:m}})},[e,ve,Q]),a.useEffect(()=>{var c;Pt.current=[...n],(c=kt.current)==null||c.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const it=a.useCallback((c,m)=>{const f=pt.current;if(!f)return{x:0,y:0};const M=f.getBoundingClientRect(),L=yt.current;return{x:(c-M.left-L.x)/L.zoom,y:(m-M.top-L.y)/L.zoom}},[]),It=a.useCallback((c,m)=>{const f=Zt.current.length>0?Zt.current:O.current;let M=null;for(let L=f.length-1;L>=0;L--){const S=f[L];if(S.hidden)continue;const y=S._absolutePosition||S.position,A=S.width||Gt,B=S.height||Ft;if(c>=y.x&&c<=y.x+A&&m>=y.y&&m<=y.y+B){if(S.type==="group"){M||(M=S);continue}return S}}return M},[]),de=a.useCallback((c,m)=>{const f=m.width||Gt,M=m.height||Ft;if(c.x!==void 0&&c.y!==void 0)return{x:m.position.x+c.x,y:m.position.y+c.y};switch(c.position||(c.type==="source"?"right":"left")){case"top":return{x:m.position.x+f/2,y:m.position.y};case"bottom":return{x:m.position.x+f/2,y:m.position.y+M};case"left":return{x:m.position.x,y:m.position.y+M/2};case"right":return{x:m.position.x+f,y:m.position.y+M/2};default:return{x:m.position.x+f,y:m.position.y+M/2}}},[]),be=a.useCallback(c=>{const m=c.width||Gt,f=c.height||Ft;return c.handles&&c.handles.length>0?c.handles.map(M=>{const L=de(M,c);return{id:M.id||null,type:M.type,x:L.x,y:L.y}}):[{id:null,type:"target",x:c.position.x,y:c.position.y+f/2},{id:null,type:"source",x:c.position.x+m,y:c.position.y+f/2}]},[de]),Ze=a.useCallback((c,m)=>{const f=O.current,M=yt.current,L=Math.max(Ar,Xt)/M.zoom;for(let S=f.length-1;S>=0;S--){const y=f[S];if(y.hidden)continue;const A=be(y);for(const B of A)if(Math.abs(c-B.x)<L&&Math.abs(m-B.y)<L)return{nodeId:y.id,handleId:B.id,type:B.type,x:B.x,y:B.y}}return null},[be]),oe=a.useCallback((c,m)=>{const M=8/yt.current.zoom;for(let L=Pt.current.length-1;L>=0;L--){const S=Pt.current[L],y=O.current.find(bt=>bt.id===S.source),A=O.current.find(bt=>bt.id===S.target);if(!y||!A)continue;const B=y.width||Gt,X=y.height||Ft,H=A.height||Ft,V=y.position.x+B,at=y.position.y+X/2,Y=A.position.x,et=A.position.y+H/2;if(Hr(c,m,V,at,Y,et)<M)return S}return null},[]);a.useEffect(()=>{const c=Ee.current,m=pt.current;if(!c||!m)return;const f=m.getBoundingClientRect(),M=ot!==void 0?ot:matchMedia("(prefers-color-scheme: dark)").matches,L=ve(O.current);Zt.current=L;const S=Q(L),{worker:y}=Dr(c,{width:f.width,height:f.height,camera:yt.current,cards:Jt.current,nodes:S,edges:Pt.current,dark:M,gridSize:Nt,edgeRouting:ie});y.onmessage=H=>{var V,at;H.data.type==="hud"&&((V=le.current)==null||V.call(le,H.data.data)),H.data.type==="ready"&&hn(!0),H.data.type==="nodesProcessed"&&((at=ue.current)==null||at.call(ue,H.data.data))},kt.current=y;const A=new ResizeObserver(H=>{const{width:V,height:at}=H[0].contentRect;y.postMessage({type:"resize",data:{width:V,height:at}})});A.observe(m);let B,X;return ot===void 0&&(B=matchMedia("(prefers-color-scheme: dark)"),X=H=>y.postMessage({type:"theme",data:{dark:H.matches}}),B.addEventListener("change",X)),()=>{A.disconnect(),B&&X&&B.removeEventListener("change",X),kt.current=null}},[]),a.useEffect(()=>{var c;ot!==void 0&&((c=kt.current)==null||c.postMessage({type:"theme",data:{dark:ot}}))},[ot]),a.useEffect(()=>{var c;(c=kt.current)==null||c.postMessage({type:"edgeRouting",data:{enabled:ie}})},[ie]);const Sn=a.useRef(0),Ct=a.useCallback((c=null)=>{var M,L,S;const m=yt.current;if(Kt){const y=pt.current;if(y){const A=y.getBoundingClientRect(),B=-Kt[1][0]*m.zoom+A.width,X=-Kt[1][1]*m.zoom+A.height,H=-Kt[0][0]*m.zoom,V=-Kt[0][1]*m.zoom;m.x=Math.min(H,Math.max(B,m.x)),m.y=Math.min(V,Math.max(X,m.y))}}(M=kt.current)==null||M.postMessage({type:"camera",data:{camera:{...m}}});const f={x:m.x,y:m.y,zoom:m.zoom};(S=(L=Z.current).onMove)==null||S.call(L,c,f);for(const y of Ut)y(f);cancelAnimationFrame(Sn.current),Sn.current=requestAnimationFrame(()=>{Ge({x:m.x,y:m.y,zoom:m.zoom})})},[Ut,Kt]),we=a.useCallback(()=>{var f,M;const c=jt.current,m=xe.current;c&&m?((f=kt.current)==null||f.postMessage({type:"connecting",data:{from:c.startPos,to:m,_routedPoints:null}}),ee({source:c.sourceId,sourceHandle:c.sourceHandle,target:null,targetHandle:null})):((M=kt.current)==null||M.postMessage({type:"connecting",data:null}),ee(null))},[]),Me=a.useCallback(()=>{var m,f;const c=te.current;c?(m=kt.current)==null||m.postMessage({type:"selectionBox",data:c}):(f=kt.current)==null||f.postMessage({type:"selectionBox",data:null})},[]),hr=a.useCallback(c=>{var L,S,y,A,B,X,H,V,at,Y,et,mt,bt,Tt,Dt,$t;const m=O.current.length>0,f=it(c.clientX,c.clientY),M=_t.current;if(m&&wt){const W=Ze(f.x,f.y);if(Ht&&pe.current&&W){const J=pe.current;if(W.nodeId!==J.nodeId){const Wt=J.handleType==="target"?{source:W.nodeId,target:J.nodeId,sourceHandle:W.handleId||null,targetHandle:J.handleId}:{source:J.nodeId,target:W.nodeId,sourceHandle:J.handleId,targetHandle:W.handleId||null};(Z.current.isValidConnection?Z.current.isValidConnection(Wt):!0)&&((L=ne.current)==null||L.call(ne,{...Wt,...ge}))}pe.current=null;return}if(Lt==="strict"?W&&W.type==="source":W!=null){if(Ht){pe.current={nodeId:W.nodeId,handleId:W.handleId||null,handleType:W.type},(y=(S=Z.current).onConnectStart)==null||y.call(S,c,{nodeId:W.nodeId,handleId:W.handleId,handleType:W.type});return}jt.current={sourceId:W.nodeId,sourceHandle:W.handleId||null,sourceType:W.type,startPos:{x:W.x,y:W.y}},xe.current={x:f.x,y:f.y},(A=pt.current)==null||A.setPointerCapture(c.pointerId),(X=(B=Z.current).onConnectStart)==null||X.call(B,c,{nodeId:W.nodeId,handleId:W.handleId,handleType:W.type}),we();return}}if(m){const W=It(f.x,f.y);if(W){if(vt.current&&zt){const Mt=[];if(M)Mt.push({id:W.id,type:"select",selected:!W.selected});else if(!W.selected){for(const J of O.current)J.id===W.id?Mt.push({id:J.id,type:"select",selected:!0}):J.selected&&Mt.push({id:J.id,type:"select",selected:!1});if(St.current){const J=Pt.current.filter(tt=>tt.selected).map(tt=>({id:tt.id,type:"select",selected:!1}));J.length&&St.current(J)}}if(Mt.length){if(vt.current(Mt),un&&!M){const J=O.current.findIndex(tt=>tt.id===W.id);J>=0&&J<O.current.length-1&&vt.current([{id:W.id,type:"remove"},{type:"add",item:{...O.current[J],selected:!0}}])}qt()}}if((H=Pe.current)==null||H.call(Pe,c,W),dt){const Mt=M&&W.selected;let J=null;if(W.parentId&&W.extent==="parent"){const tt=O.current.find(Wt=>Wt.id===W.parentId);if(tt){const Wt=tt.width||Gt,$e=tt.height||Ft,Qe=W.width||((V=W.measured)==null?void 0:V.width)||Gt,Be=W.height||((at=W.measured)==null?void 0:at.height)||Ft;J={minX:0,minY:0,maxX:Wt-Qe,maxY:$e-Be}}}if(Bt.current={id:W.id,startPos:{...W.position},startMouse:{x:f.x,y:f.y},parentClamp:J,parentId:W.parentId||null,selectedStarts:Mt?O.current.filter(tt=>tt.selected&&tt.id!==W.id).map(tt=>{var $e,Qe;let Wt=null;if(tt.parentId&&tt.extent==="parent"){const Be=O.current.find(yn=>yn.id===tt.parentId);if(Be){const yn=Be.width||Gt,Rr=Be.height||Ft,kr=tt.width||(($e=tt.measured)==null?void 0:$e.width)||Gt,Cr=tt.height||((Qe=tt.measured)==null?void 0:Qe.height)||Ft;Wt={minX:0,minY:0,maxX:yn-kr,maxY:Rr-Cr}}}return{id:tt.id,startPos:{...tt.position},parentClamp:Wt,parentId:tt.parentId||null}}):[]},(Y=pt.current)==null||Y.setPointerCapture(c.pointerId),(et=Ie.current)==null||et.call(Ie,c,W),vt.current){const tt=[{id:W.id,type:"position",dragging:!0}];for(const Wt of Bt.current.selectedStarts)tt.push({id:Wt.id,type:"position",dragging:!0});vt.current(tt)}}return}}if(Pt.current.length>0&&zt){const W=oe(f.x,f.y);if(W){if(St.current){const Mt=[];if(M)Mt.push({id:W.id,type:"select",selected:!W.selected});else{for(const J of Pt.current)J.id===W.id?Mt.push({id:J.id,type:"select",selected:!0}):J.selected&&Mt.push({id:J.id,type:"select",selected:!1});if(vt.current){const J=O.current.filter(tt=>tt.selected).map(tt=>({id:tt.id,type:"select",selected:!1}));J.length&&vt.current(J)}}Mt.length&&(St.current(Mt),qt())}(mt=re.current)==null||mt.call(re,c,W);return}}if(!M){const W=O.current.filter(J=>J.selected).map(J=>({id:J.id,type:"select",selected:!1})),Mt=Pt.current.filter(J=>J.selected).map(J=>({id:J.id,type:"select",selected:!1}));W.length&&vt.current&&vt.current(W),Mt.length&&St.current&&St.current(Mt),(W.length||Mt.length)&&qt()}if((bt=Te.current)==null||bt.call(Te,c),Qt||M){te.current={startWorld:{...f},endWorld:{...f}},(Tt=pt.current)==null||Tt.setPointerCapture(c.pointerId),Me();return}ze.current=!0,Ot.current={x:c.clientX,y:c.clientY},(Dt=pt.current)==null||Dt.classList.add("dragging"),($t=pt.current)==null||$t.setPointerCapture(c.pointerId)},[it,It,Ze,oe,dt,wt,zt,Qt,we,Me,qt]),yr=a.useCallback(c=>{var f,M;if(jt.current){if(xe.current=it(c.clientX,c.clientY),we(),ln){const L=pt.current;if(L){const S=L.getBoundingClientRect(),y=40,A=c.clientX-S.left,B=c.clientY-S.top;let X=0,H=0;A<y?X=Yt:A>S.width-y&&(X=-Yt),B<y?H=Yt:B>S.height-y&&(H=-Yt),(X||H)&&(yt.current.x+=X,yt.current.y+=H,Ct(c))}}return}if(te.current){te.current.endWorld=it(c.clientX,c.clientY),Me();const L=te.current,S=Math.min(L.startWorld.x,L.endWorld.x),y=Math.min(L.startWorld.y,L.endWorld.y),A=Math.max(L.startWorld.x,L.endWorld.x),B=Math.max(L.startWorld.y,L.endWorld.y);if(vt.current){const X=[];for(const H of O.current){if(H.hidden)continue;const V=H.width||Gt,at=H.height||Ft,Y=Re==="full"?H.position.x>=S&&H.position.x+V<=A&&H.position.y>=y&&H.position.y+at<=B:H.position.x+V>S&&H.position.x<A&&H.position.y+at>y&&H.position.y<B;Y!==!!H.selected&&X.push({id:H.id,type:"select",selected:Y})}X.length&&vt.current(X)}return}if(Bt.current){const L=it(c.clientX,c.clientY),S=Bt.current,y=L.x-S.startMouse.x,A=L.y-S.startMouse.y;let B={x:S.startPos.x+y,y:S.startPos.y+A};if(fe&&(B=vn(B,se)),Vt&&(B=bn(B,Vt)),S.parentClamp){const Y=S.parentClamp;B={x:Math.max(Y.minX,Math.min(B.x,Y.maxX)),y:Math.max(Y.minY,Math.min(B.y,Y.maxY))}}const X=[{id:S.id,position:B}];for(const Y of S.selectedStarts){let et={x:Y.startPos.x+y,y:Y.startPos.y+A};if(fe&&(et=vn(et,se)),Vt&&(et=bn(et,Vt)),Y.parentClamp){const mt=Y.parentClamp;et={x:Math.max(mt.minX,Math.min(et.x,mt.maxX)),y:Math.max(mt.minY,Math.min(et.y,mt.maxY))}}X.push({id:Y.id,position:et})}const H=[];for(const Y of X){const et=O.current.find(mt=>mt.id===Y.id);if(et){et.position=Y.position,et.dragging=!0;let mt=Y.position;if(et.parentId){let bt=O.current.find($t=>$t.id===et.parentId),Tt=Y.position.x,Dt=Y.position.y;for(;bt;)Tt+=bt.position.x,Dt+=bt.position.y,bt=bt.parentId?O.current.find($t=>$t.id===bt.parentId):null;mt={x:Tt,y:Dt}}H.push({id:Y.id,position:Y.position,_absolutePosition:mt,width:et.width,height:et.height,dragging:!0,selected:et.selected})}}const V=new Set(X.map(Y=>Y.id));for(const Y of O.current)if(Y.parentId&&V.has(Y.parentId)&&!V.has(Y.id)){let et=O.current.find(Tt=>Tt.id===Y.parentId),mt=Y.position.x,bt=Y.position.y;for(;et;)mt+=et.position.x,bt+=et.position.y,et=et.parentId?O.current.find(Tt=>Tt.id===et.parentId):null;H.push({id:Y.id,position:Y.position,_absolutePosition:{x:mt,y:bt},width:Y.width,height:Y.height,dragging:!1,selected:Y.selected})}if((f=kt.current)==null||f.postMessage({type:"nodePositions",data:{updates:H}}),cn){const Y=pt.current;if(Y){const et=Y.getBoundingClientRect(),mt=40,bt=c.clientX-et.left,Tt=c.clientY-et.top;let Dt=0,$t=0;bt<mt?Dt=Yt:bt>et.width-mt&&(Dt=-Yt),Tt<mt?$t=Yt:Tt>et.height-mt&&($t=-Yt),(Dt||$t)&&(yt.current.x+=Dt,yt.current.y+=$t,Ct(c))}}const at=O.current.find(Y=>Y.id===S.id);at&&((M=Le.current)==null||M.call(Le,c,at));return}if(!ze.current)return;const m=yt.current;m.x+=c.clientX-Ot.current.x,m.y+=c.clientY-Ot.current.y,Ot.current={x:c.clientX,y:c.clientY},Ct()},[Ct,it,we,Me]),gr=a.useCallback(c=>{var m,f,M,L,S;if(jt.current){const y=it(c.clientX,c.clientY),A=Ze(y.x,y.y);if(A&&A.nodeId!==jt.current.sourceId&&(Lt==="loose"||A.type==="target")){const H=jt.current.sourceType==="target"?{source:A.nodeId,target:jt.current.sourceId,sourceHandle:A.handleId||null,targetHandle:jt.current.sourceHandle}:{source:jt.current.sourceId,target:A.nodeId,sourceHandle:jt.current.sourceHandle,targetHandle:A.handleId||null};(Z.current.isValidConnection?Z.current.isValidConnection(H):!0)&&((m=ne.current)==null||m.call(ne,{...H,...ge}))}(M=(f=Z.current).onConnectEnd)==null||M.call(f,c.nativeEvent||c),jt.current=null,xe.current=null,we();return}if(te.current){te.current=null,Me(),qt();return}if(Bt.current){const y=Bt.current;if(vt.current){const B=O.current.find(H=>H.id===y.id),X=[{id:y.id,type:"position",position:B?{...B.position}:void 0,dragging:!1}];for(const H of y.selectedStarts){const V=O.current.find(at=>at.id===H.id);X.push({id:H.id,type:"position",position:V?{...V.position}:void 0,dragging:!1})}vt.current(X)}requestAnimationFrame(()=>{Bt.current=null});const A=O.current.find(B=>B.id===y.id);A&&((L=Se.current)==null||L.call(Se,c,A));return}ze.current=!1,(S=pt.current)==null||S.classList.remove("dragging")},[it,Ze,we,Me,qt]);a.useEffect(()=>{const c=pt.current;if(!c)return;const m=f=>{Ce&&f.preventDefault();const M=yt.current;if(Fe||me.current){const B=Xe;ke==="horizontal"?M.x-=f.deltaY*B:(ke==="vertical"||(M.x-=f.deltaX*B),M.y-=f.deltaY*B),Ct(f);return}if(!Ye)return;const L=f.deltaY>0?.92:1.08,S=c.getBoundingClientRect(),y=f.clientX-S.left,A=f.clientY-S.top;M.x=y-(y-M.x)*L,M.y=A-(A-M.y)*L,M.zoom=Math.min(xt,Math.max(st,M.zoom*L)),Ct(f)};return c.addEventListener("wheel",m,{passive:!Ce}),()=>c.removeEventListener("wheel",m)},[Ct,st,xt,Fe,ke,Xe,Ye,Ce]),a.useEffect(()=>{if(!qe)return;const c=pt.current;if(!c)return;let m=0,f=null;const M=y=>{if(y.touches.length===2){const A=y.touches[0].clientX-y.touches[1].clientX,B=y.touches[0].clientY-y.touches[1].clientY;m=Math.hypot(A,B);const X=c.getBoundingClientRect();f={x:(y.touches[0].clientX+y.touches[1].clientX)/2-X.left,y:(y.touches[0].clientY+y.touches[1].clientY)/2-X.top},y.preventDefault()}},L=y=>{if(y.touches.length===2&&m>0){y.preventDefault();const A=y.touches[0].clientX-y.touches[1].clientX,B=y.touches[0].clientY-y.touches[1].clientY,X=Math.hypot(A,B),H=X/m;m=X;const V=yt.current,at=f.x,Y=f.y;V.x=at-(at-V.x)*H,V.y=Y-(Y-V.y)*H,V.zoom=Math.min(xt,Math.max(st,V.zoom*H)),Ct(y)}},S=()=>{m=0,f=null};return c.addEventListener("touchstart",M,{passive:!1}),c.addEventListener("touchmove",L,{passive:!1}),c.addEventListener("touchend",S),()=>{c.removeEventListener("touchstart",M),c.removeEventListener("touchmove",L),c.removeEventListener("touchend",S)}},[qe,Ct,st,xt]),a.useEffect(()=>{if(!Ue)return;const c=pt.current;if(!c)return;const m=f=>{var H,V,at,Y;const M=it(f.clientX,f.clientY);if(It(M.x,M.y)){(V=(H=Z.current).onNodeDoubleClick)==null||V.call(H,f,It(M.x,M.y));return}const L=oe(M.x,M.y);if(L){(Y=(at=Z.current).onEdgeDoubleClick)==null||Y.call(at,f,L);return}const S=1.5,y=c.getBoundingClientRect(),A=f.clientX-y.left,B=f.clientY-y.top,X=yt.current;X.x=A-(A-X.x)*S,X.y=B-(B-X.y)*S,X.zoom=Math.min(xt,Math.max(st,X.zoom*S)),Ct(f)};return c.addEventListener("dblclick",m),()=>c.removeEventListener("dblclick",m)},[Ue,Ct,st,xt,it,It,oe]),a.useEffect(()=>{const c=pt.current;if(!c)return;const m=f=>{var y,A,B,X,H,V;const M=it(f.clientX,f.clientY),L=It(M.x,M.y);if(L){(A=(y=Z.current).onNodeContextMenu)==null||A.call(y,f,L);return}const S=oe(M.x,M.y);if(S){(X=(B=Z.current).onEdgeContextMenu)==null||X.call(B,f,S);return}(V=(H=Z.current).onPaneContextMenu)==null||V.call(H,f)};return c.addEventListener("contextmenu",m),()=>c.removeEventListener("contextmenu",m)},[it,It,oe]),a.useEffect(()=>{const c=pt.current;if(!c)return;let m=null,f=null;const M=y=>{var X,H,V,at,Y,et,mt,bt,Tt,Dt,$t,W,Mt,J;(H=(X=Z.current).onPaneMouseMove)==null||H.call(X,y);const A=it(y.clientX,y.clientY),B=It(A.x,A.y);if(B!==m&&(m&&((at=(V=Z.current).onNodeMouseLeave)==null||at.call(V,y,m)),B&&((et=(Y=Z.current).onNodeMouseEnter)==null||et.call(Y,y,B)),m=B),B&&((bt=(mt=Z.current).onNodeMouseMove)==null||bt.call(mt,y,B)),!B){const tt=oe(A.x,A.y);tt!==f&&(f&&((Dt=(Tt=Z.current).onEdgeMouseLeave)==null||Dt.call(Tt,y,f)),tt&&((W=($t=Z.current).onEdgeMouseEnter)==null||W.call($t,y,tt)),f=tt),tt&&((J=(Mt=Z.current).onEdgeMouseMove)==null||J.call(Mt,y,tt))}},L=y=>{var A,B;return(B=(A=Z.current).onPaneMouseEnter)==null?void 0:B.call(A,y)},S=y=>{var A,B,X,H,V,at;(B=(A=Z.current).onPaneMouseLeave)==null||B.call(A,y),m&&((H=(X=Z.current).onNodeMouseLeave)==null||H.call(X,y,m),m=null),f&&((at=(V=Z.current).onEdgeMouseLeave)==null||at.call(V,y,f),f=null)};return c.addEventListener("mousemove",M),c.addEventListener("mouseenter",L),c.addEventListener("mouseleave",S),()=>{c.removeEventListener("mousemove",M),c.removeEventListener("mouseenter",L),c.removeEventListener("mouseleave",S)}},[it,It,oe]),a.useEffect(()=>{const c=Array.isArray(he)?he:[he],m=async f=>{var M,L;if(c.includes(f.key)){if(f.target.tagName==="INPUT"||f.target.tagName==="TEXTAREA"||f.target.isContentEditable)return;const S=O.current.filter(B=>B.selected),y=Pt.current.filter(B=>B.selected);if(!S.length&&!y.length||Z.current.onBeforeDelete&&!await Z.current.onBeforeDelete({nodes:S,edges:y}))return;const A=new Set(S.map(B=>B.id));if(S.length&&vt.current&&(vt.current(S.map(B=>({id:B.id,type:"remove"}))),St.current)){const B=Pt.current.filter(X=>A.has(X.source)||A.has(X.target));B.length&&St.current(B.map(X=>({id:X.id,type:"remove"})))}y.length&&St.current&&St.current(y.map(B=>({id:B.id,type:"remove"}))),(L=(M=Z.current).onDelete)==null||L.call(M,{nodes:S,edges:y})}if((f.ctrlKey||f.metaKey)&&f.key==="a"){if(f.target.tagName==="INPUT"||f.target.tagName==="TEXTAREA")return;if(f.preventDefault(),vt.current){const S=O.current.filter(y=>!y.selected).map(y=>({id:y.id,type:"select",selected:!0}));S.length&&vt.current(S)}if(St.current){const S=Pt.current.filter(y=>!y.selected).map(y=>({id:y.id,type:"select",selected:!0}));S.length&&St.current(S)}}};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[he]);const Tn=a.useRef(!1);a.useEffect(()=>{var c,m;if(!Tn.current&&kt.current){if(Tn.current=!0,Rt&&O.current.length>0){const f=pt.current;if(f){const M=f.getBoundingClientRect(),L=(ut==null?void 0:ut.padding)??.1,S=Ve(O.current),y=Je(S,M.width,M.height,L);ut!=null&&ut.maxZoom&&(y.zoom=Math.min(y.zoom,ut.maxZoom)),ut!=null&&ut.minZoom&&(y.zoom=Math.max(y.zoom,ut.minZoom)),yt.current=y,Ct()}}(m=(c=Z.current).onInit)==null||m.call(c,{getNodes:()=>[...O.current],getEdges:()=>[...Pt.current],getViewport:()=>({...yt.current}),fitView:(f={})=>{const M=pt.current;if(!M||!O.current.length)return;const L=M.getBoundingClientRect(),S=Ve(O.current),y=Je(S,L.width,L.height,f.padding??.1);yt.current=y,Ct()}})}});const xr=a.useCallback(()=>{yt.current={...Et},Ct()},[Ct,Et]),pr=a.useCallback(c=>{var m;if(c)Jt.current.push(c);else{const f=yt.current,M=pt.current;if(!M)return;const L=M.getBoundingClientRect(),S=Math.round(-f.x/f.zoom+L.width/2/f.zoom),y=Math.round(-f.y/f.zoom+L.height/2/f.zoom);Jt.current.push({x:S-80,y:y-45,w:160,h:90,title:"Note "+(Jt.current.length+1),body:"Added at viewport center"})}(m=kt.current)==null||m.postMessage({type:"cards",data:{cards:[...Jt.current]}})},[]),mr=a.useCallback(c=>{if(c.id||(c.id="node-"+Date.now()),!c.position){const m=yt.current,f=pt.current;if(!f)return;const M=f.getBoundingClientRect();c.position={x:Math.round(-m.x/m.zoom+M.width/2/m.zoom)-Gt/2,y:Math.round(-m.y/m.zoom+M.height/2/m.zoom)-Ft/2}}c.data||(c.data={label:c.id}),vt.current&&vt.current([{type:"add",item:c}])},[]),vr=a.useCallback(()=>({...yt.current}),[]),br=a.useCallback(c=>{yt.current={...yt.current,...c},Ct()},[Ct]),wr=a.useCallback(c=>it(c.x,c.y),[it]),$n=n,Mr=a.useMemo(()=>({wrapRef:pt,canvasRef:Ee,workerRef:kt,cameraRef:yt,nodesRef:O,edgesRef:Pt,handleRegistryRef:dn,syncNodesToWorker:At,onNodesChangeRef:vt,onEdgesChangeRef:St,sendCamera:Ct,screenToWorld:it,viewportListeners:Ut,selectionListeners:ae,zoomMin:st,zoomMax:xt,snapToGrid:fe,snapGrid:se,nodeExtent:Vt,defaultEdgeOptions:ge,edgeRouting:ie,resolvedNodesRef:Zt,get nodes(){return e},get edges(){return n},get routedEdges(){return $n},get viewport(){return Ne},get connection(){return Oe}}),[e,n,$n,Ne,Oe,Ct,it,At,Ut,ae,st,xt,fe,se,Vt,ge,ie]);return{wrapRef:pt,canvasRef:Ee,canvasReady:fn,onPointerDown:hr,onPointerMove:yr,onPointerUp:gr,resetView:xr,addCard:pr,addNode:mr,getCamera:vr,setCamera:br,screenToFlowPosition:wr,store:Mr}}function Hr(t,e,n,r,s,o){const i=s-n,l=o-r,d=i*i+l*l;if(d===0)return Math.hypot(t-n,e-r);let u=((t-n)*i+(e-r)*l)/d;return u=Math.max(0,Math.min(1,u)),Math.hypot(t-(n+u*i),e-(r+u*l))}const Zn=a.createContext(null);function ft(){const t=a.useContext(Zn);if(!t)throw new Error("useCanvasStore must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");return t}const _e=a.createContext(null);function _r(){return a.useContext(_e)}function Wr({node:t,nodeType:e}){var v,P,E;const n=ft(),r=a.useRef(null),s=t._absolutePosition||t.position,o=a.useRef(null);a.useEffect(()=>{const R=r.current;if(!R)return;const T=new ResizeObserver(k=>{var D,x,h,p;const{width:z,height:_}=k[0].contentRect;if(z>0&&_>0){const b=n.nodesRef.current.find($=>$.id===t.id),I=(b==null?void 0:b.width)||((D=b==null?void 0:b.measured)==null?void 0:D.width),w=(b==null?void 0:b.height)||((x=b==null?void 0:b.measured)==null?void 0:x.height);(Math.abs((I||0)-z)>1||Math.abs((w||0)-_)>1)&&((p=(h=n.onNodesChangeRef).current)==null||p.call(h,[{id:t.id,type:"dimensions",dimensions:{width:z,height:_},setAttributes:!0}]))}});return T.observe(R),()=>T.disconnect()},[t.id,n]);const i=a.useCallback(R=>{var j,q,F,gt;R.stopPropagation();const T=R.target.tagName;if(T==="INPUT"||T==="TEXTAREA"||T==="SELECT"||T==="BUTTON"||T==="A"||T==="LABEL"||R.target.isContentEditable)return;let k=R.target;for(;k&&k!==r.current;){if((j=k.classList)!=null&&j.contains("nodrag")||(q=k.classList)!=null&&q.contains("nopan"))return;k=k.parentElement}if(n.onNodesChangeRef.current){const K=[];if(R.shiftKey)K.push({id:t.id,type:"select",selected:!t.selected});else for(const U of n.nodesRef.current)U.id===t.id&&!U.selected?K.push({id:U.id,type:"select",selected:!0}):U.id!==t.id&&U.selected&&K.push({id:U.id,type:"select",selected:!1});K.length&&n.onNodesChangeRef.current(K)}const z=n.cameraRef.current,_=n.wrapRef.current;if(!_)return;const D=_.getBoundingClientRect(),x=(R.clientX-D.left-z.x)/z.zoom,h=(R.clientY-D.top-z.y)/z.zoom,b=R.shiftKey&&t.selected?n.nodesRef.current.filter(K=>K.selected&&K.id!==t.id).map(K=>({id:K.id,startPos:{...K.position}})):[];o.current={startPos:{...t.position},startMouse:{x,y:h},selectedStarts:b};const I=[{id:t.id,type:"position",dragging:!0}];for(const K of b)I.push({id:K.id,type:"position",dragging:!0});(gt=(F=n.onNodesChangeRef).current)==null||gt.call(F,I);const w=r.current;w&&w.setPointerCapture(R.pointerId);const $=K=>{var st,xt,Et,Rt;if(!o.current)return;const nt=n.cameraRef.current,U=_.getBoundingClientRect(),G=(K.clientX-U.left-nt.x)/nt.zoom,rt=(K.clientY-U.top-nt.y)/nt.zoom,ct=G-o.current.startMouse.x,lt=rt-o.current.startMouse.y;let ot={x:o.current.startPos.x+ct,y:o.current.startPos.y+lt};if(n.snapToGrid&&n.snapGrid&&(ot={x:n.snapGrid[0]*Math.round(ot.x/n.snapGrid[0]),y:n.snapGrid[1]*Math.round(ot.y/n.snapGrid[1])}),t.parentId&&t.extent==="parent"){const ut=n.nodesRef.current.find(dt=>dt.id===t.parentId);if(ut){const dt=ut.width||160,wt=ut.height||60,zt=t.width||((st=t.measured)==null?void 0:st.width)||160,ht=t.height||((xt=t.measured)==null?void 0:xt.height)||60;ot={x:Math.max(0,Math.min(ot.x,dt-zt)),y:Math.max(0,Math.min(ot.y,wt-ht))}}}const Nt=[{id:t.id,type:"position",position:ot,dragging:!0}];for(const ut of o.current.selectedStarts){let dt={x:ut.startPos.x+ct,y:ut.startPos.y+lt};n.snapToGrid&&n.snapGrid&&(dt={x:n.snapGrid[0]*Math.round(dt.x/n.snapGrid[0]),y:n.snapGrid[1]*Math.round(dt.y/n.snapGrid[1])}),Nt.push({id:ut.id,type:"position",position:dt,dragging:!0})}(Rt=(Et=n.onNodesChangeRef).current)==null||Rt.call(Et,Nt)},C=K=>{var U,G;if(!o.current)return;const nt=[{id:t.id,type:"position",dragging:!1}];for(const rt of o.current.selectedStarts)nt.push({id:rt.id,type:"position",dragging:!1});(G=(U=n.onNodesChangeRef).current)==null||G.call(U,nt),o.current=null,w&&w.releasePointerCapture(K.pointerId),w==null||w.removeEventListener("pointermove",$),w==null||w.removeEventListener("pointerup",C)};w==null||w.addEventListener("pointermove",$),w==null||w.addEventListener("pointerup",C)},[t,n]),l=a.useCallback(R=>{var x,h,p,b,I,w;if(!t.selected)return;const T=R.shiftKey?10:1;let k=0,z=0;switch(R.key){case"ArrowUp":z=-T;break;case"ArrowDown":z=T;break;case"ArrowLeft":k=-T;break;case"ArrowRight":k=T;break;case"Escape":(h=(x=n.onNodesChangeRef).current)==null||h.call(x,[{id:t.id,type:"select",selected:!1}]);return;case"Delete":case"Backspace":t.deletable!==!1&&((b=(p=n.onNodesChangeRef).current)==null||b.call(p,[{id:t.id,type:"remove"}]));return;default:return}R.preventDefault();const _={x:t.position.x+k,y:t.position.y+z},D=[{id:t.id,type:"position",position:_}];for(const $ of n.nodesRef.current)$.selected&&$.id!==t.id&&D.push({id:$.id,type:"position",position:{x:$.position.x+k,y:$.position.y+z}});(w=(I=n.onNodesChangeRef).current)==null||w.call(I,D)},[t,n]),d=t.width||((v=t.measured)==null?void 0:v.width),u=t.height||((P=t.measured)==null?void 0:P.height),g=!!(d&&u);return N.jsx(_e.Provider,{value:t.id,children:N.jsx("div",{ref:r,className:`ric-node-wrapper ${t.selected?"selected":""} ${t.dragging?"dragging":""}`,style:{position:"absolute",left:s.x,top:s.y,zIndex:t.type==="group"?0:t.zIndex||1,pointerEvents:t.type==="group"?"none":"all",visibility:g?"visible":"hidden",outline:"none"},"data-nodeid":t.id,tabIndex:t.selectable!==!1?0:void 0,role:"button","aria-label":`Node ${((E=t.data)==null?void 0:E.label)||t.id}`,"aria-selected":!!t.selected,onPointerDown:i,onKeyDown:l,children:N.jsx(e,{id:t.id,data:t.data,type:t.type,selected:!!t.selected,dragging:!!t.dragging,draggable:t.draggable!==!1,selectable:t.selectable!==!1,deletable:t.deletable!==!1,isConnectable:t.connectable!==!1,zIndex:t.zIndex||0,positionAbsoluteX:s.x,positionAbsoluteY:s.y,width:d,height:u,sourcePosition:t.sourcePosition,targetPosition:t.targetPosition,parentId:t.parentId,dragHandle:t.dragHandle})})})}const Fr=a.memo(Wr),Qn=160,Kn=60;function jn(t,e,n,r){var l,d;const s=t.width||((l=t.measured)==null?void 0:l.width)||Qn,o=t.height||((d=t.measured)==null?void 0:d.height)||Kn,i=t._absolutePosition||t.position;if(t.handleBounds){const u=t.handleBounds[e]||[],g=n?u.find(v=>v.id===n):u[0];if(g&&g.x!==void 0&&g.y!==void 0){const v=g.position||(e==="source"?"right":"left");return{x:i.x+g.x,y:i.y+g.y,position:v}}}if(r){const u=`${t.id}__${n||e}`,g=r.get(u);if(g&&g.x!==void 0&&g.y!==void 0)return{x:i.x+g.x,y:i.y+g.y,position:g.position||(e==="source"?"right":"left")}}if(t.handles&&t.handles.length){for(const u of t.handles)if(u.type===e&&(!n||u.id===n)){if(u.x!==void 0&&u.y!==void 0)return{x:i.x+u.x,y:i.y+u.y,position:u.position||(e==="source"?"right":"left")};const g=u.position||(e==="source"?"right":"left");switch(g){case"top":return{x:i.x+s/2,y:i.y,position:g};case"bottom":return{x:i.x+s/2,y:i.y+o,position:g};case"left":return{x:i.x,y:i.y+o/2,position:g};default:return{x:i.x+s,y:i.y+o/2,position:g}}}}return e==="source"?{x:i.x+s,y:i.y+o/2,position:"right"}:{x:i.x,y:i.y+o/2,position:"left"}}function Xr(t,e,n){return n==="left"?t-e:n==="right"?t+e:t}function Yr(t,e,n){return n==="top"?t-e:n==="bottom"?t+e:t}function Dn({x:t,y:e,position:n,type:r,onPointerDown:s}){return N.jsx("circle",{className:`ric-edge-anchor ric-edge-anchor-${r}`,cx:Xr(t,10,n),cy:Yr(e,10,n),r:10,stroke:"transparent",fill:"transparent",style:{cursor:"move",pointerEvents:"stroke"},onPointerDown:s})}function Ur({edge:t,edgeType:e,nodes:n,reconnectable:r}){var x,h,p;const s=ft(),[o,i]=a.useState(null),l=a.useCallback((b,I,w,$)=>{var nt;I.stopPropagation(),I.preventDefault();const C=s.wrapRef.current;if(!C)return;const j=b==="source"?$:w,q=b==="source"?t.target:t.source;(nt=s.workerRef.current)==null||nt.postMessage({type:"connecting",data:{from:{x:j.x,y:j.y},to:{x:j.x,y:j.y}}});const F=C.getBoundingClientRect(),gt=U=>{var lt;const G=s.cameraRef.current,rt=(U.clientX-F.left-G.x)/G.zoom,ct=(U.clientY-F.top-G.y)/G.zoom;(lt=s.workerRef.current)==null||lt.postMessage({type:"connecting",data:{from:{x:j.x,y:j.y},to:{x:rt,y:ct}}})},K=U=>{var xt,Et,Rt,ut;const G=s.cameraRef.current,rt=(U.clientX-F.left-G.x)/G.zoom,ct=(U.clientY-F.top-G.y)/G.zoom,lt=20/G.zoom;let ot=null,Nt=null;const st=(xt=s.handleRegistryRef)==null?void 0:xt.current;for(const dt of s.nodesRef.current){if(dt.hidden)continue;const wt=dt.width||Qn,zt=dt.height||Kn,ht=dt._absolutePosition||dt.position,Qt=[];if(st)for(const[,Lt]of st)Lt.nodeId===dt.id&&Qt.push(Lt);const Re=Qt.length>0?Qt:dt.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const Lt of Re){let Xt,Ht;if(Lt.x!==void 0&&Lt.y!==void 0)Xt=ht.x+Lt.x,Ht=ht.y+Lt.y;else switch(Lt.position||(Lt.type==="source"?"right":"left")){case"top":Xt=ht.x+wt/2,Ht=ht.y;break;case"bottom":Xt=ht.x+wt/2,Ht=ht.y+zt;break;case"left":Xt=ht.x,Ht=ht.y+zt/2;break;default:Xt=ht.x+wt,Ht=ht.y+zt/2;break}if(Math.abs(rt-Xt)<lt&&Math.abs(ct-Ht)<lt){ot=dt,Nt=Lt.id||null;break}}if(ot)break}if(ot){const dt=b==="source"?{source:ot.id,target:q,sourceHandle:Nt,targetHandle:t.targetHandle}:{source:q,target:ot.id,sourceHandle:t.sourceHandle,targetHandle:Nt};(Rt=(Et=s.onEdgesChangeRef).current)==null||Rt.call(Et,[{id:t.id,type:"remove"},{type:"add",item:{id:t.id,...dt}}])}(ut=s.workerRef.current)==null||ut.postMessage({type:"connecting",data:null}),C.removeEventListener("pointermove",gt),C.removeEventListener("pointerup",K)};C.addEventListener("pointermove",gt),C.addEventListener("pointerup",K)},[t,s]),d=n.find(b=>b.id===t.source),u=n.find(b=>b.id===t.target),g=d&&!!(d.width||(x=d.measured)!=null&&x.width),v=u&&!!(u.width||(h=u.measured)!=null&&h.width),P=(p=s.handleRegistryRef)==null?void 0:p.current,E=g?jn(d,"source",t.sourceHandle,P):null,R=v?jn(u,"target",t.targetHandle,P):null,T=t.type==="bezier"||t.type==="simplebezier"||t.type==="default",k=s.routedEdges||s.edges,z=k==null?void 0:k.find(b=>b.id===t.id),_=T?null:(z==null?void 0:z._routedPoints)||t._routedPoints||null,D=r!==!1&&t.reconnectable!==!1;return!E||!R?null:N.jsxs("g",{className:`ric-edge-wrapper ${t.selected?"selected":""}`,"data-edgeid":t.id,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),children:[N.jsx(e,{id:t.id,source:t.source,target:t.target,sourceX:E.x,sourceY:E.y,targetX:R.x,targetY:R.y,sourcePosition:E.position,targetPosition:R.position,sourceHandleId:t.sourceHandle,targetHandleId:t.targetHandle,data:t.data,type:t.type,selected:!!t.selected,animated:!!t.animated,label:t.label,style:t.style,selectable:t.selectable!==!1,deletable:t.deletable!==!1,routedPoints:_}),D&&(o||t.selected)&&N.jsxs(N.Fragment,{children:[N.jsx(Dn,{x:E.x,y:E.y,position:E.position,type:"source",onPointerDown:b=>l("source",b,E,R)}),N.jsx(Dn,{x:R.x,y:R.y,position:R.position,type:"target",onPointerDown:b=>l("target",b,E,R)})]})]})}const qr=a.memo(Ur);function Vn({selectionKeyCode:t="Shift",selectionMode:e="partial"}){var T;const n=ft(),[r,s]=a.useState(null),o=a.useRef(null);if(a.useEffect(()=>{const k=n.wrapRef.current;if(!k)return;let z=!1,_=null,D=!1;const x=w=>{w.key===t&&(D=!0)},h=w=>{w.key===t&&(D=!1)},p=w=>{if(!D)return;const $=w.target;if($.closest(".ric-node-wrapper")||$.closest(".ric-handle"))return;z=!0;const C=n.cameraRef.current,j=k.getBoundingClientRect(),q=(w.clientX-j.left-C.x)/C.zoom,F=(w.clientY-j.top-C.y)/C.zoom;_={x:q,y:F},s({startX:q,startY:F,endX:q,endY:F}),w.stopPropagation()},b=w=>{if(!z||!_)return;const $=n.cameraRef.current,C=k.getBoundingClientRect(),j=(w.clientX-C.left-$.x)/$.zoom,q=(w.clientY-C.top-$.y)/$.zoom;s({startX:_.x,startY:_.y,endX:j,endY:q})},I=w=>{var K,nt;if(!z||!_)return;z=!1;const $=n.cameraRef.current,C=k.getBoundingClientRect(),j=(w.clientX-C.left-$.x)/$.zoom,q=(w.clientY-C.top-$.y)/$.zoom,F={x:Math.min(_.x,j),y:Math.min(_.y,q),width:Math.abs(j-_.x),height:Math.abs(q-_.y)},gt=[];for(const U of n.nodesRef.current){const G=U._absolutePosition||U.position,rt=U.width||160,ct=U.height||60;let lt;e==="full"?lt=G.x>=F.x&&G.y>=F.y&&G.x+rt<=F.x+F.width&&G.y+ct<=F.y+F.height:lt=G.x+rt>F.x&&G.x<F.x+F.width&&G.y+ct>F.y&&G.y<F.y+F.height,gt.push({id:U.id,type:"select",selected:lt})}gt.length&&((nt=(K=n.onNodesChangeRef).current)==null||nt.call(K,gt)),_=null,s(null)};return k.addEventListener("pointerdown",p,!0),k.addEventListener("pointermove",b),k.addEventListener("pointerup",I),window.addEventListener("keydown",x),window.addEventListener("keyup",h),()=>{k.removeEventListener("pointerdown",p,!0),k.removeEventListener("pointermove",b),k.removeEventListener("pointerup",I),window.removeEventListener("keydown",x),window.removeEventListener("keyup",h)}},[n,t,e]),!r)return null;const i=((T=n.cameraRef)==null?void 0:T.current)||{x:0,y:0,zoom:1},l=Math.min(r.startX,r.endX),d=Math.min(r.startY,r.endY),u=Math.abs(r.endX-r.startX),g=Math.abs(r.endY-r.startY),v=l*i.zoom+i.x,P=d*i.zoom+i.y,E=u*i.zoom,R=g*i.zoom;return N.jsx("div",{ref:o,className:"ric-selection-box",style:{position:"absolute",left:v,top:P,width:E,height:R,border:"1px dashed #3b82f6",background:"rgba(59, 130, 246, 0.08)",pointerEvents:"none",zIndex:100}})}Vn.displayName="SelectionBox";const Jn=a.memo(Vn);function tr(t,e){var s,o,i,l;const n=(s=t.handleRegistryRef)==null?void 0:s.current;if(!n)return;const r={source:[],target:[]};for(const[,d]of n)if(d.nodeId===e){const u={id:d.id,type:d.type,position:d.position,x:d.x,y:d.y,width:8,height:8};d.type==="source"?r.source.push(u):r.target.push(u)}(i=(o=t.onNodesChangeRef).current)==null||i.call(o,[{id:e,type:"dimensions",handleBounds:r,setAttributes:!1}]),(l=t.syncNodesToWorker)==null||l.call(t)}const xn=new Set;function An(t,e){xn.has(e)||(xn.add(e),queueMicrotask(()=>{xn.delete(e),tr(t,e)}))}function Gr(t,e){const n=t.closest(".ric-node-wrapper");if(!n)return null;const r=n.getBoundingClientRect(),s=t.getBoundingClientRect(),o=e||1;return{x:(s.left+s.width/2-r.left)/o,y:(s.top+s.height/2-r.top)/o}}function He({type:t="source",position:e=t==="source"?"right":"left",id:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:o=!0,children:i,className:l="",style:d={},onConnect:u,...g}){const v=a.useContext(_e),P=ft(),E=a.useRef(null),R=a.useRef(P);R.current=P;const T=a.useCallback(()=>{var w,$,C;const D=E.current;if(!D||!v)return;const x=R.current,h=(w=x.handleRegistryRef)==null?void 0:w.current;if(!h)return;const p=`${v}__${n||t}`,b=(C=($=x.cameraRef)==null?void 0:$.current)==null?void 0:C.zoom,I=Gr(D,b);if(I){const j={nodeId:v,id:n||null,type:t,position:e,x:I.x,y:I.y};h.set(p,j)}},[v,n,t,e]);a.useLayoutEffect(()=>{T()},[T]),a.useEffect(()=>{if(!v)return;const D=R.current;An(D,v);const x=E.current,h=x==null?void 0:x.closest(".ric-node-wrapper"),p=new ResizeObserver(()=>{T(),An(R.current,v)});return h&&p.observe(h),()=>{var $;p.disconnect();const b=R.current,I=($=b.handleRegistryRef)==null?void 0:$.current,w=`${v}__${n||t}`;I==null||I.delete(w),tr(b,v)}},[v,n,t,e,T]);const k=a.useCallback(()=>{var C;const D=R.current,x=D.nodesRef.current.find(j=>j.id===v);if(!x)return null;const h=x._absolutePosition||x.position,p=(C=D.handleRegistryRef)==null?void 0:C.current,b=`${v}__${n||t}`,I=p==null?void 0:p.get(b);if(I&&I.x!==void 0&&I.y!==void 0)return{x:h.x+I.x,y:h.y+I.y};const w=x.width||160,$=x.height||60;switch(e){case"top":return{x:h.x+w/2,y:h.y};case"bottom":return{x:h.x+w/2,y:h.y+$};case"left":return{x:h.x,y:h.y+$/2};default:return{x:h.x+w,y:h.y+$/2}}},[v,n,t,e]),z=a.useCallback(D=>{var q;if(!r||!s)return;D.stopPropagation(),D.preventDefault();const x=R.current,h=x.cameraRef.current,p=x.wrapRef.current;if(!p)return;const b=p.getBoundingClientRect(),I=k();if(!I)return;const w=I.x,$=I.y;(q=x.workerRef.current)==null||q.postMessage({type:"connecting",data:{from:{x:w,y:$},to:{x:w,y:$}}}),p.setPointerCapture(D.pointerId);const C=F=>{var nt;const gt=(F.clientX-b.left-h.x)/h.zoom,K=(F.clientY-b.top-h.y)/h.zoom;(nt=x.workerRef.current)==null||nt.postMessage({type:"connecting",data:{from:{x:w,y:$},to:{x:gt,y:K}}})},j=F=>{var ct,lt,ot,Nt;const gt=(F.clientX-b.left-h.x)/h.zoom,K=(F.clientY-b.top-h.y)/h.zoom,nt=20/h.zoom;let U=null,G=null;const rt=(ct=x.handleRegistryRef)==null?void 0:ct.current;for(const st of x.nodesRef.current){if(st.id===v||st.hidden)continue;const xt=st.width||160,Et=st.height||60,Rt=st._absolutePosition||st.position,ut=[];if(rt)for(const[,wt]of rt)wt.nodeId===st.id&&ut.push(wt);const dt=ut.length>0?ut:st.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const wt of dt){let zt,ht;if(wt.x!==void 0&&wt.y!==void 0)zt=Rt.x+wt.x,ht=Rt.y+wt.y;else switch(wt.position||(wt.type==="source"?"right":"left")){case"top":zt=Rt.x+xt/2,ht=Rt.y;break;case"bottom":zt=Rt.x+xt/2,ht=Rt.y+Et;break;case"left":zt=Rt.x,ht=Rt.y+Et/2;break;default:zt=Rt.x+xt,ht=Rt.y+Et/2;break}if(Math.abs(gt-zt)<nt&&Math.abs(K-ht)<nt){U=st,G=wt.id||null;break}}if(U)break}if(U){const st={source:t==="source"?v:U.id,target:t==="source"?U.id:v,sourceHandle:t==="source"?n||null:G,targetHandle:t==="source"?G:n||null};(ot=(lt=x.onEdgesChangeRef)==null?void 0:lt.current)==null||ot.call(lt,[{type:"add",item:{id:`e-${st.source}-${st.target}`,...st}}])}(Nt=x.workerRef.current)==null||Nt.postMessage({type:"connecting",data:null}),p.removeEventListener("pointermove",C),p.removeEventListener("pointerup",j)};p.addEventListener("pointermove",C),p.addEventListener("pointerup",j)},[v,n,t,e,r,s,k]),_={top:{top:0,left:"50%",transform:"translate(-50%, -50%)"},bottom:{bottom:0,left:"50%",transform:"translate(-50%, 50%)"},left:{top:"50%",left:0,transform:"translate(-50%, -50%)"},right:{top:"50%",right:0,transform:"translate(50%, -50%)"}}[e]||{};return N.jsx("div",{ref:E,className:`ric-handle ric-handle-${e} ric-handle-${t} ${l}`,"data-handleid":n||null,"data-nodeid":v,"data-handlepos":e,"data-handletype":t,onPointerDown:z,style:{position:"absolute",width:8,height:8,borderRadius:"50%",background:"#1a192b",border:"none",zIndex:10,cursor:r?"crosshair":"default",boxSizing:"border-box",..._,...d},...g,children:i})}function Or({data:t,isConnectable:e,selected:n,targetPosition:r="left",sourcePosition:s="right",hideSourceHandle:o=!1,hideTargetHandle:i=!1}){return N.jsxs("div",{className:`ric-default-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!i&&N.jsx(He,{type:"target",position:r,isConnectable:e}),N.jsx("div",{className:"ric-node-content",children:t==null?void 0:t.label}),!o&&N.jsx(He,{type:"source",position:s,isConnectable:e})]})}function er({data:t,isConnectable:e,selected:n,sourcePosition:r="right",hideSourceHandle:s=!1}){return N.jsxs("div",{className:`ric-input-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderBottom:"2px solid #0041d0",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[N.jsx("div",{className:"ric-node-content",children:t==null?void 0:t.label}),!s&&N.jsx(He,{type:"source",position:r,isConnectable:e})]})}function nr({data:t,isConnectable:e,selected:n,targetPosition:r="left",hideTargetHandle:s=!1}){return N.jsxs("div",{className:`ric-output-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderTop:"2px solid #ff0072",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!s&&N.jsx(He,{type:"target",position:r,isConnectable:e}),N.jsx("div",{className:"ric-node-content",children:t==null?void 0:t.label})]})}function rr({data:t,selected:e,width:n,height:r}){return N.jsx("div",{className:`ric-group-node${e?" selected":""}`,style:{width:n||300,height:r||200,background:"rgba(240, 240, 240, 0.25)",border:e?"2px solid #3b82f6":"1px dashed #ccc",borderRadius:8,padding:8,boxSizing:"border-box"},children:(t==null?void 0:t.label)&&N.jsx("div",{style:{fontSize:11,fontWeight:600,color:"#888",userSelect:"none"},children:t.label})})}function or({x:t,y:e,label:n,labelStyle:r,labelShowBg:s=!0,labelBgStyle:o,labelBgPadding:i=[2,4],labelBgBorderRadius:l=2,children:d,className:u="",...g}){const[v,P]=a.useState({x:1,y:0,width:0,height:0}),E=a.useRef(null);return a.useEffect(()=>{if(E.current){const R=E.current.getBBox();P({x:R.x,y:R.y,width:R.width,height:R.height})}},[n]),n?N.jsxs("g",{transform:`translate(${t-v.width/2} ${e-v.height/2})`,className:`ric-edge-textwrapper ${u}`,visibility:v.width?"visible":"hidden",...g,children:[s&&N.jsx("rect",{width:v.width+2*i[0],x:-i[0],y:-i[1],height:v.height+2*i[1],className:"ric-edge-textbg",style:o,rx:l,ry:l}),N.jsx("text",{className:"ric-edge-text",y:v.height/2,dy:"0.3em",ref:E,style:r,children:n}),d]}):null}or.displayName="EdgeText";const sr=a.memo(or);function Hn(t){return t!=null&&t!==""&&!isNaN(Number(t))}function We({id:t,path:e,labelX:n,labelY:r,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:l,labelBgPadding:d,labelBgBorderRadius:u,interactionWidth:g=20,style:v,markerEnd:P,markerStart:E,className:R="",...T}){return N.jsxs(N.Fragment,{children:[N.jsx("path",{id:t,d:e,fill:"none",stroke:"#b1b1b7",strokeWidth:1.5,className:`ric-edge-path ${R}`,style:v,markerEnd:P,markerStart:E,...T}),g?N.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:g,className:"ric-edge-interaction",style:{pointerEvents:"stroke"}}):null,s&&Hn(n)&&Hn(r)?N.jsx(sr,{x:n,y:r,label:s,labelStyle:o,labelShowBg:i,labelBgStyle:l,labelBgPadding:d,labelBgBorderRadius:u}):null]})}const je=20;function _n(t,e,n){switch(n){case"right":return{x:t+je,y:e};case"left":return{x:t-je,y:e};case"bottom":return{x:t,y:e+je};case"top":return{x:t,y:e-je};default:return{x:t+je,y:e}}}const Rn=a.memo(function({id:e,sourceX:n,sourceY:r,targetX:s,targetY:o,sourcePosition:i="bottom",targetPosition:l="top",label:d,labelStyle:u,labelShowBg:g,labelBgStyle:v,labelBgPadding:P,labelBgBorderRadius:E,style:R,markerEnd:T,markerStart:k,interactionWidth:z}){let _,D,x;const h=_n(n,r,i),p=_n(s,o,l),b=Math.abs(p.x-h.x),I=Math.max(50,b*.5);let w,$,C,j;switch(i){case"left":w=h.x-I,$=h.y;break;case"top":w=h.x,$=h.y-I;break;case"bottom":w=h.x,$=h.y+I;break;default:w=h.x+I,$=h.y;break}switch(l){case"right":C=p.x+I,j=p.y;break;case"top":C=p.x,j=p.y-I;break;case"bottom":C=p.x,j=p.y+I;break;default:C=p.x-I,j=p.y;break}_=`M ${n},${r} L ${h.x},${h.y} C ${w},${$} ${C},${j} ${p.x},${p.y} L ${s},${o}`;const q=.5,F=.5;return D=F*F*F*h.x+3*F*F*q*w+3*F*q*q*C+q*q*q*p.x,x=F*F*F*h.y+3*F*F*q*$+3*F*q*q*j+q*q*q*p.y,N.jsx(We,{id:e,path:_,labelX:D,labelY:x,label:d,labelStyle:u,labelShowBg:g,labelBgStyle:v,labelBgPadding:P,labelBgBorderRadius:E,style:R,markerEnd:T,markerStart:k,interactionWidth:z})});Rn.displayName="BezierEdge";function kn({sourceX:t,sourceY:e,targetX:n,targetY:r}){const s=`M ${t},${e}L ${n},${r}`,o=(t+n)/2,i=(e+r)/2;return[s,o,i,0,0]}function Cn({sourceX:t,sourceY:e,targetX:n,targetY:r,sourcePosition:s="right",targetPosition:o="left",curvature:i=.25}){const l=Math.abs(n-t),d=Math.abs(r-e),u=Math.sqrt(l*l+d*d),g=Math.max(u*i,50);let v,P,E,R;switch(s){case"top":v=t,P=e-g;break;case"bottom":v=t,P=e+g;break;case"left":v=t-g,P=e;break;default:v=t+g,P=e;break}switch(o){case"top":E=n,R=r-g;break;case"bottom":E=n,R=r+g;break;case"right":E=n+g,R=r;break;default:E=n-g,R=r;break}const T=`M ${t},${e} C ${v},${P} ${E},${R} ${n},${r}`,k=.5,z=1-k,_=z*z*z*t+3*z*z*k*v+3*z*k*k*E+k*k*k*n,D=z*z*z*e+3*z*z*k*P+3*z*k*k*R+k*k*k*r;return[T,_,D,0,0]}function En({sourceX:t,sourceY:e,targetX:n,targetY:r}){const s=Math.abs(n-t),o=Math.max(s*.5,50),i=t+o,l=n-o,d=`M ${t},${e} C ${i},${e} ${l},${r} ${n},${r}`,u=.5,g=.5,v=g*g*g*t+3*g*g*u*i+3*g*u*u*l+u*u*u*n,P=g*g*g*e+3*g*g*u*e+3*g*u*u*r+u*u*u*r;return[d,v,P,0,0]}function tn({sourceX:t,sourceY:e,targetX:n,targetY:r,sourcePosition:s="right",targetPosition:o="left",borderRadius:i=5,offset:l=20}){const d=s==="left"||s==="right",u=Math.min(i,Math.abs(n-t)/2,Math.abs(r-e)/2);if(d){if(Math.abs(r-e)<1)return[`M ${t},${e} L ${n},${r}`,(t+n)/2,e,0,0];const E=(t+n)/2,R=r>e?1:-1;return[`M ${t},${e} L ${E-u},${e} Q ${E},${e} ${E},${e+R*u} L ${E},${r-R*u} Q ${E},${r} ${E+(n>E?u:-u)},${r} L ${n},${r}`,E,(e+r)/2,0,0]}const g=(e+r)/2,v=n>t?1:-1;return[`M ${t},${e} L ${t},${g-u} Q ${t},${g} ${t+v*u},${g} L ${n-v*u},${g} Q ${n},${g} ${n},${g+(r>g?u:-u)} L ${n},${r}`,(t+n)/2,g,0,0]}function Zr({sourceX:t,sourceY:e,targetX:n,targetY:r}){const[,s,o]=Cn({sourceX:t,sourceY:e,targetX:n,targetY:r});return[s,o,0,0]}function Qr({sourceX:t,sourceY:e,targetX:n,targetY:r}){return[(t+n)/2,(e+r)/2,0,0]}function Kr(t,e,n){const r=n.filter(o=>o.id!==t.id),s={...t,id:t.id,source:e.source,target:e.target,sourceHandle:e.sourceHandle??t.sourceHandle,targetHandle:e.targetHandle??t.targetHandle};return r.push(s),r}const en=160,nn=60,De=20,Ke=12,rn=20;function Wn(t,e,n){var i,l;const r=t.width||((i=t.measured)==null?void 0:i.width)||en,s=t.height||((l=t.measured)==null?void 0:l.height)||nn,o=t._absolutePosition||t.position;if(t.handles&&t.handles.length>0){for(const d of t.handles)if(d.type===e&&(!n||d.id===n)){if(d.x!==void 0&&d.y!==void 0)return{x:o.x+d.x,y:o.y+d.y,dir:d.position||(e==="source"?"right":"left")};switch(d.position||(e==="source"?"right":"left")){case"top":return{x:o.x+r/2,y:o.y,dir:"top"};case"bottom":return{x:o.x+r/2,y:o.y+s,dir:"bottom"};case"left":return{x:o.x,y:o.y+s/2,dir:"left"};default:return{x:o.x+r,y:o.y+s/2,dir:"right"}}}}return e==="source"?{x:o.x+r,y:o.y+s/2,dir:"right"}:{x:o.x,y:o.y+s/2,dir:"left"}}function on(t,e){switch(t.dir){case"right":return{x:t.x+e,y:t.y,dir:t.dir};case"left":return{x:t.x-e,y:t.y,dir:t.dir};case"bottom":return{x:t.x,y:t.y+e,dir:t.dir};case"top":return{x:t.x,y:t.y-e,dir:t.dir};default:return{x:t.x+e,y:t.y,dir:t.dir}}}function Vr(t,e,n,r,s,o,i,l){const d=Math.min(t,n),u=Math.max(t,n),g=Math.min(e,r),v=Math.max(e,r);if(u<=s||d>=s+i||v<=o||g>=o+l)return!1;const P=.5;if(t>s+P&&t<s+i-P&&e>o+P&&e<o+l-P||n>s+P&&n<s+i-P&&r>o+P&&r<o+l-P)return!0;const E=(t+n)/2,R=(e+r)/2;if(E>s+P&&E<s+i-P&&R>o+P&&R<o+l-P)return!0;const T=[[s,o],[s+i,o],[s+i,o+l],[s,o+l]];for(let k=0;k<4;k++)if(Jr(t,e,n,r,T[k][0],T[k][1],T[(k+1)%4][0],T[(k+1)%4][1]))return!0;return!1}function Jr(t,e,n,r,s,o,i,l){const d=(i-s)*(e-o)-(l-o)*(t-s),u=(i-s)*(r-o)-(l-o)*(n-s),g=(n-t)*(o-e)-(r-e)*(s-t),v=(n-t)*(l-e)-(r-e)*(i-t);return(d>0&&u<0||d<0&&u>0)&&(g>0&&v<0||g<0&&v>0)}function wn(t,e,n,r,s){for(let o=0;o<s.length;o++){const i=s[o];if(Vr(t,e,n,r,i.x,i.y,i.w,i.h))return!1}return!0}function to(t,e,n){for(let r=0;r<n.length;r++){const s=n[r];if(t>s.x&&t<s.x+s.w&&e>s.y&&e<s.y+s.h)return!0}return!1}function zn(t,e){var r,s;const n=[];for(let o=0;o<t.length;o++){const i=t[o];if(i.hidden||e&&e.has(i.id)||i.type==="group")continue;const l=i._absolutePosition||i.position,d=i.width||((r=i.measured)==null?void 0:r.width)||en,u=i.height||((s=i.measured)==null?void 0:s.height)||nn;n.push({id:i.id,x:l.x-De,y:l.y-De,w:d+2*De,h:u+2*De})}return n}function ir(t,e,n){if(wn(t.x,t.y,e.x,e.y,n))return null;const r=new Set,s=new Set;r.add(t.x),r.add(e.x),s.add(t.y),s.add(e.y);const o=De+5;t.dir==="right"?r.add(t.x+o):t.dir==="left"?r.add(t.x-o):t.dir==="top"?s.add(t.y-o):t.dir==="bottom"&&s.add(t.y+o),e.dir==="right"?r.add(e.x+o):e.dir==="left"?r.add(e.x-o):e.dir==="top"?s.add(e.y-o):e.dir==="bottom"&&s.add(e.y+o);for(let C=0;C<n.length;C++){const j=n[C];r.add(j.x),r.add(j.x+j.w),s.add(j.y),s.add(j.y+j.h)}const i=[...r].sort((C,j)=>C-j),l=[...s].sort((C,j)=>C-j),d=new Map,u=new Map;for(let C=0;C<i.length;C++)d.set(i[C],C);for(let C=0;C<l.length;C++)u.set(l[C],C);const g=i.length,v=l.length,P=(C,j)=>j*g+C,E=d.get(t.x),R=u.get(t.y),T=d.get(e.x),k=u.get(e.y);if(E===void 0||R===void 0||T===void 0||k===void 0)return null;const z=P(E,R),_=P(T,k),D=new Float64Array(g*v).fill(1/0),x=new Float64Array(g*v).fill(1/0),h=new Int32Array(g*v).fill(-1),p=new Int8Array(g*v).fill(-1),b=new Uint8Array(g*v);D[z]=0,x[z]=Math.abs(i[T]-t.x)+Math.abs(l[k]-t.y);const I=[z],w=15,$=[[1,0],[-1,0],[0,1],[0,-1]];for(;I.length>0;){let C=0;for(let U=1;U<I.length;U++)x[I[U]]<x[I[C]]&&(C=U);const j=I[C];if(I[C]=I[I.length-1],I.pop(),j===_){const U=[];let G=_;for(;G!==-1&&G!==z;){const rt=G/g|0,ct=G%g;U.unshift({x:i[ct],y:l[rt]}),G=h[G]}return U.unshift({x:t.x,y:t.y}),eo(U,n)}if(b[j])continue;b[j]=1;const q=j/g|0,F=j%g,gt=i[F],K=l[q],nt=p[j];for(let U=0;U<4;U++){const G=F+$[U][0],rt=q+$[U][1];if(G<0||G>=g||rt<0||rt>=v)continue;const ct=P(G,rt);if(b[ct])continue;const lt=i[G],ot=l[rt];if(to(lt,ot,n)||!wn(gt,K,lt,ot,n))continue;const Nt=Math.abs(lt-gt)+Math.abs(ot-K),st=nt>=0&&nt!==U?w:0,xt=D[j]+Nt+st;xt<D[ct]&&(h[ct]=j,p[ct]=U,D[ct]=xt,x[ct]=xt+Math.abs(i[T]-lt)+Math.abs(l[k]-ot),I.push(ct))}}return null}function eo(t,e){if(!t||t.length<=2)return t;const n=[t[0]];for(let r=1;r<t.length-1;r++){const s=n[n.length-1],o=t[r],i=t[r+1],l=Math.abs(s.x-o.x)<.5&&Math.abs(o.x-i.x)<.5,d=Math.abs(s.y-o.y)<.5&&Math.abs(o.y-i.y)<.5;(l||d)&&wn(s.x,s.y,i.x,i.y,e)||n.push(o)}return n.push(t[t.length-1]),n}function no(t){const e=new Map,n=new Map;for(const s of t){const o=s._routedPoints;if(!(!o||o.length<2))for(let i=0;i<o.length-1;i++){const l=o[i],d=o[i+1];if(Math.abs(l.y-d.y)<.5){const u=Math.round(l.y*10)/10;e.has(u)||e.set(u,[]),e.get(u).push({edgeId:s.id,segIdx:i,x1:Math.min(l.x,d.x),x2:Math.max(l.x,d.x)})}else if(Math.abs(l.x-d.x)<.5){const u=Math.round(l.x*10)/10;n.has(u)||n.set(u,[]),n.get(u).push({edgeId:s.id,segIdx:i,y1:Math.min(l.y,d.y),y2:Math.max(l.y,d.y)})}}}const r=new Map;for(const s of t)s._routedPoints&&r.set(s.id,s._routedPoints.map(o=>({...o})));for(const[,s]of e){if(s.length<2)continue;const o=Fn(s,"x1","x2");for(const i of o){if(i.length<2)continue;const l=(i.length-1)*Ke/2;for(let d=0;d<i.length;d++){const u=i[d],g=-l+d*Ke,v=r.get(u.edgeId);v&&(v[u.segIdx].y+=g,v[u.segIdx+1].y+=g)}}}for(const[,s]of n){if(s.length<2)continue;const o=Fn(s,"y1","y2");for(const i of o){if(i.length<2)continue;const l=(i.length-1)*Ke/2;for(let d=0;d<i.length;d++){const u=i[d],g=-l+d*Ke,v=r.get(u.edgeId);v&&(v[u.segIdx].x+=g,v[u.segIdx+1].x+=g)}}}return t.map(s=>{const o=r.get(s.id);return o?{...s,_routedPoints:o}:s})}function Fn(t,e,n){if(t.length<2)return[];const r=[...t].sort((i,l)=>i[e]-l[e]),s=[];let o=[r[0]];for(let i=1;i<r.length;i++){const l=o[o.length-1];r[i][e]<l[n]?o.push(r[i]):(o.length>1&&s.push(o),o=[r[i]])}return o.length>1&&s.push(o),s}function sn(t,e=6,n=!1){if(!t||t.length<2)return null;if(n)return ro(t);const r=e;let s=`M ${t[0].x},${t[0].y}`;for(let o=1;o<t.length-1;o++){const i=t[o-1],l=t[o],d=t[o+1],u=Math.abs(l.x-i.x)+Math.abs(l.y-i.y),g=Math.abs(d.x-l.x)+Math.abs(d.y-l.y),v=Math.min(r,u/2,g/2);if(v>.5){const P=l.x-i.x,E=l.y-i.y,R=d.x-l.x,T=d.y-l.y,k=Math.sqrt(P*P+E*E)||1,z=Math.sqrt(R*R+T*T)||1;s+=` L ${l.x-P/k*v},${l.y-E/k*v}`,s+=` Q ${l.x},${l.y} ${l.x+R/z*v},${l.y+T/z*v}`}else s+=` L ${l.x},${l.y}`}return s+=` L ${t[t.length-1].x},${t[t.length-1].y}`,s}function ro(t){if(t.length===2)return`M ${t[0].x},${t[0].y} L ${t[1].x},${t[1].y}`;if(t.length===3)return`M ${t[0].x},${t[0].y} Q ${t[1].x},${t[1].y} ${t[2].x},${t[2].y}`;const e=.3;let n=`M ${t[0].x},${t[0].y}`;for(let r=0;r<t.length-1;r++){const s=t[r===0?0:r-1],o=t[r],i=t[r+1],l=t[r+2<t.length?r+2:t.length-1],d=o.x+(i.x-s.x)*e,u=o.y+(i.y-s.y)*e,g=i.x-(l.x-o.x)*e,v=i.y-(l.y-o.y)*e;n+=` C ${d},${u} ${g},${v} ${i.x},${i.y}`}return n}function an(t){if(!t||t.length<2)return{x:0,y:0};let e=0;for(let r=1;r<t.length;r++)e+=Math.abs(t[r].x-t[r-1].x)+Math.abs(t[r].y-t[r-1].y);let n=e/2;for(let r=1;r<t.length;r++){const s=Math.abs(t[r].x-t[r-1].x)+Math.abs(t[r].y-t[r-1].y);if(n<=s){const o=s>0?n/s:0;return{x:t[r-1].x+(t[r].x-t[r-1].x)*o,y:t[r-1].y+(t[r].y-t[r-1].y)*o}}n-=s}return{x:t[0].x,y:t[0].y}}function oo(t,e){if(!t||!e||t.length===0||e.length===0)return e;const n={};for(const o of t)n[o.id]=o;const r=zn(t,null),s=e.map(o=>{var p,b,I,w;const i=o.type||"default";if(i==="bezier"||i==="simplebezier"||i==="default")return o;const l=n[o.source],d=n[o.target];if(!l||!d||l.hidden||d.hidden)return o;const u=Wn(l,"source",o.sourceHandle),g=Wn(d,"target",o.targetHandle),v=on(u,rn),P=on(g,rn),E=5,R=r.filter($=>$.id!==o.source&&$.id!==o.target),T=l._absolutePosition||l.position,k=l.width||((p=l.measured)==null?void 0:p.width)||en,z=l.height||((b=l.measured)==null?void 0:b.height)||nn;R.push({id:o.source,x:T.x-E,y:T.y-E,w:k+2*E,h:z+2*E});const _=d._absolutePosition||d.position,D=d.width||((I=d.measured)==null?void 0:I.width)||en,x=d.height||((w=d.measured)==null?void 0:w.height)||nn;if(R.push({id:o.target,x:_.x-E,y:_.y-E,w:D+2*E,h:x+2*E}),R.length===0)return o;const h=ir(v,P,R);return h&&h.length>=2?(h.unshift({x:u.x,y:u.y}),h.push({x:g.x,y:g.y}),{...o,_routedPoints:h}):o});return no(s)}function so(t,e,n,r,s,o,i,l){const d=zn(i,l?new Set(l):null);if(d.length===0)return null;const u={x:t,y:e,dir:s||"right"},g={x:n,y:r,dir:o||"left"},v=on(u,rn),P=on(g,rn),E=ir(v,P,d);return E&&E.length>=2?(E.unshift({x:u.x,y:u.y}),E.push({x:g.x,y:g.y}),E):null}const Nn=a.memo(function({id:e,sourceX:n,sourceY:r,targetX:s,targetY:o,label:i,labelStyle:l,labelShowBg:d,labelBgStyle:u,labelBgPadding:g,labelBgBorderRadius:v,style:P,markerEnd:E,markerStart:R,interactionWidth:T,routedPoints:k}){let z,_,D;if(k&&k.length>=2){z=sn(k);const x=an(k);_=x.x,D=x.y}else[z,_,D]=kn({sourceX:n,sourceY:r,targetX:s,targetY:o});return N.jsx(We,{id:e,path:z,labelX:_,labelY:D,label:i,labelStyle:l,labelShowBg:d,labelBgStyle:u,labelBgPadding:g,labelBgBorderRadius:v,style:P,markerEnd:E,markerStart:R,interactionWidth:T})});Nn.displayName="StraightEdge";const Pn=a.memo(function({id:e,sourceX:n,sourceY:r,targetX:s,targetY:o,sourcePosition:i="bottom",targetPosition:l="top",label:d,labelStyle:u,labelShowBg:g,labelBgStyle:v,labelBgPadding:P,labelBgBorderRadius:E,style:R,markerEnd:T,markerStart:k,pathOptions:z,interactionWidth:_,routedPoints:D}){let x,h,p;if(D&&D.length>=2){x=sn(D);const b=an(D);h=b.x,p=b.y}else[x,h,p]=tn({sourceX:n,sourceY:r,sourcePosition:i,targetX:s,targetY:o,targetPosition:l,borderRadius:z==null?void 0:z.borderRadius,offset:z==null?void 0:z.offset});return N.jsx(We,{id:e,path:x,labelX:h,labelY:p,label:d,labelStyle:u,labelShowBg:g,labelBgStyle:v,labelBgPadding:P,labelBgBorderRadius:E,style:R,markerEnd:T,markerStart:k,interactionWidth:_})});Pn.displayName="SmoothStepEdge";const ar=a.memo(function({id:e,...n}){var s;const r=a.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(s=n.pathOptions)==null?void 0:s.offset]);return N.jsx(Pn,{...n,id:e,pathOptions:r})});ar.displayName="StepEdge";const In=a.memo(function({id:e,sourceX:n,sourceY:r,targetX:s,targetY:o,sourcePosition:i,targetPosition:l,label:d,labelStyle:u,labelShowBg:g,labelBgStyle:v,labelBgPadding:P,labelBgBorderRadius:E,style:R,markerEnd:T,markerStart:k,interactionWidth:z,routedPoints:_}){let D,x,h;if(_&&_.length>=2){D=sn(_);const p=an(_);x=p.x,h=p.y}else[D,x,h]=En({sourceX:n,sourceY:r,targetX:s,targetY:o});return N.jsx(We,{id:e,path:D,labelX:x,labelY:h,label:d,labelStyle:u,labelShowBg:g,labelBgStyle:v,labelBgPadding:P,labelBgBorderRadius:E,style:R,markerEnd:T,markerStart:k,interactionWidth:z})});In.displayName="SimpleBezierEdge";const io={input:er,output:nr,group:rr},ao={bezier:Rn,straight:Nn,simplebezier:In};function co({cards:t,nodes:e=[],edges:n=[],nodeTypes:r,edgeTypes:s,dark:o,gridSize:i,width:l="100%",height:d="420px",className:u="",style:g={},zoomMin:v,zoomMax:P,initialCamera:E,fitView:R,fitViewOptions:T,onNodesChange:k,onEdgesChange:z,onConnect:_,onConnectStart:D,onConnectEnd:x,onNodeClick:h,onNodeDoubleClick:p,onNodeMouseEnter:b,onNodeMouseMove:I,onNodeMouseLeave:w,onNodeContextMenu:$,onNodeDragStart:C,onNodeDrag:j,onNodeDragStop:q,onEdgeClick:F,onEdgeDoubleClick:gt,onEdgeMouseEnter:K,onEdgeMouseMove:nt,onEdgeMouseLeave:U,onEdgeContextMenu:G,onPaneClick:rt,onPaneContextMenu:ct,onPaneMouseEnter:lt,onPaneMouseMove:ot,onPaneMouseLeave:Nt,onSelectionChange:st,onInit:xt,onMoveStart:Et,onMove:Rt,onMoveEnd:ut,onDelete:dt,onBeforeDelete:wt,onError:zt,onDragOver:ht,onDrop:Qt,onDragEnter:Re,onDragLeave:Lt,nodesDraggable:Xt,nodesConnectable:Ht,elementsSelectable:fe,multiSelectionKeyCode:se,selectionOnDrag:he,selectionMode:ye,connectionMode:Fe,connectionRadius:ke,connectOnClick:Xe,isValidConnection:Ye,defaultEdgeOptions:Ue,snapToGrid:qe,snapGrid:Ce,deleteKeyCode:Kt,panActivationKeyCode:Vt,panOnScroll:ge,panOnScrollMode:cn,panOnScrollSpeed:ln,zoomOnScroll:Yt,zoomOnDoubleClick:Ln,zoomOnPinch:un,preventScrolling:ie,translateExtent:pt,nodeExtent:Ee,autoPanOnNodeDrag:kt,autoPanOnConnect:yt,autoPanSpeed:Jt,edgesReconnectable:O,elevateNodesOnSelect:Pt,elevateEdgesOnSelect:dn,edgeRouting:ze=!0,onHudUpdate:Ot,onNodesProcessed:fn,showHud:hn=!0,showHint:Bt=!0,hintText:jt="Drag to pan · Scroll to zoom",children:xe,...te}){const[_t,pe]=a.useState({wx:0,wy:0,zoom:"1.00"}),Ne=a.useRef(null),Ge=a.useRef(null),Oe=a.useCallback(Q=>{pe(Q),Ot==null||Ot(Q)},[Ot]),ee=a.useMemo(()=>({...io,...r}),[r]),Ut=a.useMemo(()=>({...ao,...s}),[s]),ae=a.useMemo(()=>{const Q=e.filter(At=>At.type&&ee[At.type]);return Q.sort((At,it)=>{const It=At.type==="group"||!At.parentId&&Q.some(be=>be.parentId===At.id),de=it.type==="group"||!it.parentId&&Q.some(be=>be.parentId===it.id);return It&&!de?-1:!It&&de?1:0})},[e,ee]),me=a.useMemo(()=>n.filter(Q=>Q.type&&Ut[Q.type]),[n,Ut]),Z=a.useMemo(()=>e.map(Q=>Q.type&&ee[Q.type]?{...Q,_customRendered:!0}:Q),[e,ee]),vt=a.useMemo(()=>n.map(Q=>Q.type&&Ut[Q.type]?{...Q,_customRendered:!0}:Q),[n,Ut]),{wrapRef:St,canvasRef:ne,canvasReady:Pe,onPointerDown:Ie,onPointerMove:Le,onPointerUp:Se,store:re}=On({cards:t,nodes:Z,edges:vt,dark:o,gridSize:i,zoomMin:v,zoomMax:P,initialCamera:E,fitView:R,fitViewOptions:T,onHudUpdate:Oe,onNodesProcessed:fn,onNodesChange:k,onEdgesChange:z,onConnect:_,onConnectStart:D,onConnectEnd:x,onNodeClick:h,onNodeDoubleClick:p,onNodeMouseEnter:b,onNodeMouseMove:I,onNodeMouseLeave:w,onNodeContextMenu:$,onNodeDragStart:C,onNodeDrag:j,onNodeDragStop:q,onEdgeClick:F,onEdgeDoubleClick:gt,onEdgeMouseEnter:K,onEdgeMouseMove:nt,onEdgeMouseLeave:U,onEdgeContextMenu:G,onPaneClick:rt,onPaneContextMenu:ct,onPaneMouseEnter:lt,onPaneMouseMove:ot,onPaneMouseLeave:Nt,onSelectionChange:st,onInit:xt,onMoveStart:Et,onMove:Rt,onMoveEnd:ut,onDelete:dt,onBeforeDelete:wt,onError:zt,nodesDraggable:Xt,nodesConnectable:Ht,elementsSelectable:fe,multiSelectionKeyCode:se,selectionOnDrag:he,selectionMode:ye,connectionMode:Fe,connectionRadius:ke,connectOnClick:Xe,isValidConnection:Ye,defaultEdgeOptions:Ue,snapToGrid:qe,snapGrid:Ce,deleteKeyCode:Kt,panActivationKeyCode:Vt,panOnScroll:ge,panOnScrollMode:cn,panOnScrollSpeed:ln,zoomOnScroll:Yt,zoomOnDoubleClick:Ln,zoomOnPinch:un,preventScrolling:ie,translateExtent:pt,nodeExtent:Ee,autoPanOnNodeDrag:kt,autoPanOnConnect:yt,autoPanSpeed:Jt,edgesReconnectable:O,elevateNodesOnSelect:Pt,edgeRouting:ze}),Te=a.useMemo(()=>({...re,edgeLabelContainerRef:Ne,viewportPortalRef:Ge,get nodes(){return e},get edges(){return n}}),[re,e,n]),ce=a.useRef(null),le=a.useRef(null),ue=a.useRef(null),qt=a.useRef(null);a.useEffect(()=>{let Q;const At=()=>{const it=re.cameraRef.current,It=`translate(${it.x}px, ${it.y}px) scale(${it.zoom})`,de=`translate(${it.x}, ${it.y}) scale(${it.zoom})`;ce.current&&(ce.current.style.transform=It),le.current&&le.current.setAttribute("transform",de),ue.current&&(ue.current.style.transform=It),qt.current&&(qt.current.style.transform=It),Q=requestAnimationFrame(At)};return Q=requestAnimationFrame(At),()=>cancelAnimationFrame(Q)},[re]);const ve=ae.length>0,Zt=me.length>0;return N.jsx(Zn.Provider,{value:Te,children:N.jsxs("div",{ref:St,className:`ric-wrap ${u}`,style:{width:l,height:d,...g},onPointerDown:Ie,onPointerMove:Le,onPointerUp:Se,onDragOver:ht,onDrop:Qt,onDragEnter:Re,onDragLeave:Lt,tabIndex:0,children:[N.jsx("canvas",{ref:ne,className:"ric-canvas"}),!Pe&&N.jsx("div",{className:"ric-loader",children:N.jsx("div",{className:"ric-spinner"})}),Zt&&N.jsx("svg",{className:"ric-edges-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:N.jsx("g",{ref:le,children:me.map(Q=>N.jsx(qr,{edge:Q,edgeType:Ut[Q.type],nodes:e,reconnectable:O},Q.id))})}),ve&&N.jsx("div",{ref:ce,className:"ric-nodes-overlay",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:10},children:ae.map(Q=>N.jsx(Fr,{node:Q,nodeType:ee[Q.type]},Q.id))}),N.jsx("div",{ref:Q=>{Ne.current=Q,ue.current=Q},className:"ric-edge-labels",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:5}}),N.jsx("div",{ref:Q=>{Ge.current=Q,qt.current=Q},className:"ric-viewport-portal",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:6}}),Bt&&N.jsx("div",{className:"ric-hint",children:jt}),hn&&N.jsxs("div",{className:"ric-info",children:["world: (",_t.wx,", ",_t.wy,")   zoom: ",_t.zoom,"x",_t.nodeCount>0&&N.jsxs(N.Fragment,{children:["   nodes: ",_t.nodeCount]}),_t.edgeCount>0&&N.jsxs(N.Fragment,{children:["   edges: ",_t.edgeCount]})]}),N.jsx(Jn,{selectionKeyCode:se||"Shift",selectionMode:ye||"partial"}),xe]})})}function lo({children:t}){return t}function cr(t,e){const n=[],r=new Map,s=[];for(const o of t)if(o.type==="add")s.push(o);else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const i=r.get(o.id);i?i.push(o):r.set(o.id,[o])}for(const o of e){const i=r.get(o.id);if(!i){n.push(o);continue}if(i[0].type==="remove")continue;if(i[0].type==="replace"){n.push({...i[0].item});continue}const l={...o};for(const d of i)uo(d,l);n.push(l)}for(const o of s)o.index!==void 0?n.splice(o.index,0,{...o.item}):n.push({...o.item});return n}function uo(t,e){switch(t.type){case"select":e.selected=t.selected;break;case"position":t.position!==void 0&&(e.position=t.position),t.dragging!==void 0&&(e.dragging=t.dragging);break;case"dimensions":t.dimensions!==void 0&&(e.measured={...t.dimensions},(t.setAttributes===!0||t.setAttributes==="width")&&(e.width=t.dimensions.width),(t.setAttributes===!0||t.setAttributes==="height")&&(e.height=t.dimensions.height)),t.handleBounds!==void 0&&(e.handleBounds=t.handleBounds);break}}function lr(t,e){return cr(t,e)}function ur(t,e){return cr(t,e)}function fo(t,e){return!t.source||!t.target?(console.warn("addEdge: source and target are required"),e):e.some(r=>r.source===t.source&&r.target===t.target&&(r.sourceHandle||null)===(t.sourceHandle||null)&&(r.targetHandle||null)===(t.targetHandle||null))?e:[...e,{id:t.id||`e-${t.source}-${t.target}`,...t}]}function ho(t){const[e,n]=a.useState(t),r=a.useCallback(s=>n(o=>lr(s,o)),[]);return[e,n,r]}function yo(t){const[e,n]=a.useState(t),r=a.useCallback(s=>n(o=>ur(s,o)),[]);return[e,n,r]}function dr(){const t=ft(),e=a.useCallback(()=>[...t.nodesRef.current],[t]),n=a.useCallback(()=>[...t.edgesRef.current],[t]),r=a.useCallback(x=>t.nodesRef.current.find(h=>h.id===x),[t]),s=a.useCallback(x=>t.edgesRef.current.find(h=>h.id===x),[t]),o=a.useCallback(x=>{var h,p,b,I;if(typeof x=="function"){const w=x(t.nodesRef.current);(p=(h=t.onNodesChangeRef).current)==null||p.call(h,[...t.nodesRef.current.map($=>({id:$.id,type:"remove"})),...w.map($=>({type:"add",item:$}))])}else(I=(b=t.onNodesChangeRef).current)==null||I.call(b,[...t.nodesRef.current.map(w=>({id:w.id,type:"remove"})),...x.map(w=>({type:"add",item:w}))])},[t]),i=a.useCallback(x=>{var h,p,b,I;if(typeof x=="function"){const w=x(t.edgesRef.current);(p=(h=t.onEdgesChangeRef).current)==null||p.call(h,[...t.edgesRef.current.map($=>({id:$.id,type:"remove"})),...w.map($=>({type:"add",item:$}))])}else(I=(b=t.onEdgesChangeRef).current)==null||I.call(b,[...t.edgesRef.current.map(w=>({id:w.id,type:"remove"})),...x.map(w=>({type:"add",item:w}))])},[t]),l=a.useCallback(x=>{var p,b;const h=Array.isArray(x)?x:[x];(b=(p=t.onNodesChangeRef).current)==null||b.call(p,h.map(I=>({type:"add",item:I})))},[t]),d=a.useCallback(x=>{var p,b;const h=Array.isArray(x)?x:[x];(b=(p=t.onEdgesChangeRef).current)==null||b.call(p,h.map(I=>({type:"add",item:I})))},[t]),u=a.useCallback(({nodes:x=[],edges:h=[]})=>{if(x.length&&t.onNodesChangeRef.current){t.onNodesChangeRef.current(x.map(b=>({id:b.id,type:"remove"})));const p=qn(x,t.edgesRef.current);p.length&&t.onEdgesChangeRef.current&&t.onEdgesChangeRef.current(p.map(b=>({id:b.id,type:"remove"})))}h.length&&t.onEdgesChangeRef.current&&t.onEdgesChangeRef.current(h.map(p=>({id:p.id,type:"remove"})))},[t]),g=a.useCallback(()=>{const x=t.cameraRef.current;return{x:x.x,y:x.y,zoom:x.zoom}},[t]),v=a.useCallback((x,h)=>{t.cameraRef.current={x:x.x??t.cameraRef.current.x,y:x.y??t.cameraRef.current.y,zoom:x.zoom??t.cameraRef.current.zoom},t.sendCamera()},[t]),P=a.useCallback(()=>t.cameraRef.current.zoom,[t]),E=a.useCallback(x=>{const h=t.cameraRef.current,p=t.wrapRef.current;if(!p)return;const b=p.getBoundingClientRect(),I=b.width/2,w=b.height/2,$=1.2;h.x=I-(I-h.x)*$,h.y=w-(w-h.y)*$,h.zoom=Math.min(t.zoomMax,h.zoom*$),t.sendCamera()},[t]),R=a.useCallback(x=>{const h=t.cameraRef.current,p=t.wrapRef.current;if(!p)return;const b=p.getBoundingClientRect(),I=b.width/2,w=b.height/2,$=1/1.2;h.x=I-(I-h.x)*$,h.y=w-(w-h.y)*$,h.zoom=Math.max(t.zoomMin,h.zoom*$),t.sendCamera()},[t]),T=a.useCallback(x=>{const h=t.cameraRef.current,p=t.wrapRef.current;if(!p)return;const b=p.getBoundingClientRect(),I=b.width/2,w=b.height/2,$=x/h.zoom;h.x=I-(I-h.x)*$,h.y=w-(w-h.y)*$,h.zoom=Math.min(t.zoomMax,Math.max(t.zoomMin,x)),t.sendCamera()},[t]),k=a.useCallback((x={})=>{const h=t.nodesRef.current;if(!h.length)return;const p=t.wrapRef.current;if(!p)return;const b=p.getBoundingClientRect(),I=x.padding??.1,w=x.nodes?h.filter(j=>x.nodes.some(q=>q.id===j.id)):h;if(!w.length)return;const $=Ve(w),C=Je($,b.width,b.height,I);x.maxZoom&&(C.zoom=Math.min(C.zoom,x.maxZoom)),x.minZoom&&(C.zoom=Math.max(C.zoom,x.minZoom)),t.cameraRef.current=C,t.sendCamera()},[t]),z=a.useCallback((x,h,p={})=>{const b=t.wrapRef.current;if(!b)return;const I=b.getBoundingClientRect(),w=p.zoom??t.cameraRef.current.zoom;t.cameraRef.current={x:I.width/2-x*w,y:I.height/2-h*w,zoom:w},t.sendCamera()},[t]),_=a.useCallback(x=>t.screenToWorld(x.x,x.y),[t]),D=a.useCallback(x=>{const h=t.cameraRef.current,p=t.wrapRef.current;if(!p)return{x:0,y:0};const b=p.getBoundingClientRect();return{x:x.x*h.zoom+h.x+b.left,y:x.y*h.zoom+h.y+b.top}},[t]);return{getNodes:e,getEdges:n,getNode:r,getEdge:s,setNodes:o,setEdges:i,addNodes:l,addEdges:d,deleteElements:u,getViewport:g,setViewport:v,getZoom:P,zoomIn:E,zoomOut:R,zoomTo:T,fitView:k,setCenter:z,screenToFlowPosition:_,flowToScreenPosition:D}}function go(){return ft().nodes}function xo(){return ft().edges}function po(){return ft().viewport}function mo(){return ft().connection}function vo(t){const e=ft(),n=Array.isArray(t)?t:[t];return a.useMemo(()=>n.map(r=>{const s=e.nodes.find(o=>o.id===r);return s?{id:s.id,type:s.type,data:s.data}:null}).filter(Boolean),[e.nodes,...n])}function bo(t){const e=ft();return a.useMemo(()=>e.edges.filter(n=>n.source===t||n.target===t),[e.edges,t])}function wo({nodeId:t,type:e,handleId:n}){const r=ft();return a.useMemo(()=>r.edges.filter(s=>e==="source"?s.source===t&&(n?s.sourceHandle===n:!0):s.target===t&&(n?s.targetHandle===n:!0)),[r.edges,t,e,n])}function Mo({onChange:t,onStart:e,onEnd:n}){const r=ft(),s=a.useRef(t),o=a.useRef(e),i=a.useRef(n);a.useEffect(()=>{s.current=t},[t]),a.useEffect(()=>{o.current=e},[e]),a.useEffect(()=>{i.current=n},[n]),a.useEffect(()=>{const l=d=>{var u;(u=s.current)==null||u.call(s,{x:d.x,y:d.y,zoom:d.zoom})};return r.viewportListeners.add(l),()=>r.viewportListeners.delete(l)},[r])}function Ro({onChange:t}){const e=ft(),n=a.useRef(t);a.useEffect(()=>{n.current=t},[t]),a.useEffect(()=>{const r=s=>{var o;(o=n.current)==null||o.call(n,s)};return e.selectionListeners.add(r),()=>e.selectionListeners.delete(r)},[e])}function ko(t){const[e,n]=a.useState(!1),r=Array.isArray(t)?t:[t];return a.useEffect(()=>{const s=i=>{r.includes(i.key)&&n(!0)},o=i=>{r.includes(i.key)&&n(!1)};return window.addEventListener("keydown",s),window.addEventListener("keyup",o),()=>{window.removeEventListener("keydown",s),window.removeEventListener("keyup",o)}},[r.join(",")]),e}function Co(){const t=ft();return a.useCallback(e=>{var n;(n=t.workerRef.current)==null||n.postMessage({type:"nodes",data:{nodes:[...t.nodesRef.current]}})},[t])}function Eo(t={}){return ft().nodes.length>0}function zo(t){const e=ft();return a.useMemo(()=>e.nodes.find(n=>n.id===t)||void 0,[e.nodes,t])}function No(t){const e=ft();return typeof t=="function"?t(e):e}function Po(){const t=ft();return a.useMemo(()=>({getState:()=>t,setState:()=>{console.warn("[infinite-canvas] setState on storeApi is not supported. Use onNodesChange/onEdgesChange instead.")}}),[t])}const pn=160,mn=60;function Io({width:t=200,height:e=150,nodeColor:n="#3b82f6",nodeStrokeColor:r="#fff",maskColor:s="rgba(0,0,0,0.1)",style:o={},className:i=""}){const l=ft(),d=a.useRef(null),u=a.useRef(null),g=a.useCallback(()=>{const v=d.current;if(!v)return;const P=v.getContext("2d"),E=window.devicePixelRatio||1;v.width=t*E,v.height=e*E,P.scale(E,E),P.clearRect(0,0,t,e);const R=l.nodesRef.current;if(!R.length)return;let T=1/0,k=1/0,z=-1/0,_=-1/0;for(const C of R){const j=C.width||pn,q=C.height||mn;C.position.x<T&&(T=C.position.x),C.position.y<k&&(k=C.position.y),C.position.x+j>z&&(z=C.position.x+j),C.position.y+q>_&&(_=C.position.y+q)}const D=40;T-=D,k-=D,z+=D,_+=D;const x=z-T,h=_-k,p=Math.min(t/x,e/h),b=(t-x*p)/2,I=(e-h*p)/2;for(const C of R){if(C.hidden)continue;const j=C.width||pn,q=C.height||mn,F=(C.position.x-T)*p+b,gt=(C.position.y-k)*p+I,K=j*p,nt=q*p;P.fillStyle=C.selected?"#f59e0b":typeof n=="function"?n(C):n,P.fillRect(F,gt,Math.max(K,2),Math.max(nt,2))}const w=l.cameraRef.current,$=l.wrapRef.current;if($){const C=$.getBoundingClientRect(),j=-w.x/w.zoom,q=-w.y/w.zoom,F=C.width/w.zoom,gt=C.height/w.zoom;P.fillStyle=s,P.fillRect(0,0,t,e);const K=(j-T)*p+b,nt=(q-k)*p+I,U=F*p,G=gt*p;P.clearRect(K,nt,U,G);for(const rt of R){if(rt.hidden)continue;const ct=rt.width||pn,lt=rt.height||mn,ot=(rt.position.x-T)*p+b,Nt=(rt.position.y-k)*p+I;P.fillStyle=rt.selected?"#f59e0b":typeof n=="function"?n(rt):n,P.fillRect(ot,Nt,Math.max(ct*p,2),Math.max(lt*p,2))}P.strokeStyle="#3b82f6",P.lineWidth=1.5,P.strokeRect(K,nt,U,G)}},[l,t,e,n,r,s]);return a.useEffect(()=>{let v=!0;function P(){v&&(g(),u.current=requestAnimationFrame(P))}const E=setInterval(()=>{cancelAnimationFrame(u.current),u.current=requestAnimationFrame(P)},66);return g(),()=>{v=!1,clearInterval(E),cancelAnimationFrame(u.current)}},[g]),N.jsx("canvas",{ref:d,className:`ric-minimap ${i}`,style:{position:"absolute",bottom:30,right:10,width:t,height:e,borderRadius:4,border:"1px solid rgba(0,0,0,0.1)",background:"rgba(255,255,255,0.9)",pointerEvents:"none",...o}})}function Lo(){return N.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),N.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function So(){return N.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:N.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function To(){return N.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:N.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}function $o(){return N.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),N.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function Bo(){return N.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),N.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})}function Ae({children:t,className:e="",...n}){return N.jsx("button",{className:`ric-controls-button ${e}`,style:Do,...n,children:t})}function jo({showZoom:t=!0,showFitView:e=!0,showInteractive:n=!1,fitViewOptions:r,onZoomIn:s,onZoomOut:o,onFitView:i,onInteractiveChange:l,position:d="bottom-left",orientation:u="vertical",style:g={},className:v="","aria-label":P="Canvas controls",children:E}){const R=ft(),{zoomIn:T,zoomOut:k,fitView:z,getZoom:_}=dr(),[D,x]=a.useState(!0),h=_()<=R.zoomMin,p=_()>=R.zoomMax,b=a.useCallback(()=>{T(),s==null||s()},[T,s]),I=a.useCallback(()=>{k(),o==null||o()},[k,o]),w=a.useCallback(()=>{z(r||{padding:.1}),i==null||i()},[z,r,i]),$=a.useCallback(()=>{const j=!D;x(j),l==null||l(j)},[D,l]),C={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:30,left:10},"bottom-right":{bottom:30,right:10},"bottom-center":{bottom:30,left:"50%",transform:"translateX(-50%)"}}[d]||{bottom:30,left:10};return N.jsxs("div",{className:`ric-controls ${v}`,style:{position:"absolute",display:"flex",flexDirection:u==="horizontal"?"row":"column",gap:2,zIndex:5,...C,...g},role:"toolbar","aria-label":P,children:[t&&N.jsxs(N.Fragment,{children:[N.jsx(Ae,{onClick:b,disabled:p,title:"Zoom in","aria-label":"Zoom in",className:"ric-controls-zoomin",children:N.jsx(Lo,{})}),N.jsx(Ae,{onClick:I,disabled:h,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:N.jsx(So,{})})]}),e&&N.jsx(Ae,{onClick:w,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:N.jsx(To,{})}),n&&N.jsx(Ae,{onClick:$,title:D?"Lock interactivity":"Unlock interactivity","aria-label":D?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:D?N.jsx(Bo,{}):N.jsx($o,{})}),E]})}const Do={width:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid rgba(0,0,0,0.12)",borderRadius:4,background:"#fff",cursor:"pointer",fontSize:16,lineHeight:1,color:"#333",padding:0},Ao=a.memo(jo);function Ho({variant:t="lines",gap:e=40,size:n=1,color:r,style:s={},className:o=""}){const i=ft();return i.workerRef.current&&i.workerRef.current.postMessage({type:"background",data:{variant:t,gap:e,size:n,color:r}}),null}function _o({position:t="top-left",style:e={},className:n="",children:r}){const s={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:10,left:10},"bottom-right":{bottom:10,right:10},"bottom-center":{bottom:10,left:"50%",transform:"translateX(-50%)"}}[t]||{top:10,left:10};return N.jsx("div",{className:`ric-panel ${n}`,style:{position:"absolute",zIndex:5,pointerEvents:"all",...s,...e},onPointerDown:o=>o.stopPropagation(),children:r})}function Wo({minWidth:t=10,minHeight:e=10,maxWidth:n=1/0,maxHeight:r=1/0,isVisible:s=!0,handleStyle:o={},lineStyle:i={},color:l="#3b82f6",onResizeStart:d,onResize:u,onResizeEnd:g}){const v=a.useContext(_e),P=ft(),E=a.useRef(null),R=a.useCallback((z,_)=>{z.stopPropagation(),z.preventDefault();const D=P.nodesRef.current.find(p=>p.id===v);if(!D)return;E.current={direction:_,startX:z.clientX,startY:z.clientY,width:D.width||160,height:D.height||60},d==null||d(z,{width:E.current.width,height:E.current.height});const x=p=>{var q,F;if(!E.current)return;const b=E.current,I=P.cameraRef.current,w=(p.clientX-b.startX)/I.zoom,$=(p.clientY-b.startY)/I.zoom;let C=b.width,j=b.height;b.direction.includes("e")&&(C=Math.min(n,Math.max(t,b.width+w))),b.direction.includes("w")&&(C=Math.min(n,Math.max(t,b.width-w))),b.direction.includes("s")&&(j=Math.min(r,Math.max(e,b.height+$))),b.direction.includes("n")&&(j=Math.min(r,Math.max(e,b.height-$))),(F=(q=P.onNodesChangeRef).current)==null||F.call(q,[{id:v,type:"dimensions",dimensions:{width:C,height:j},setAttributes:!0}]),u==null||u(p,{width:C,height:j})},h=p=>{E.current=null,g==null||g(p,{}),window.removeEventListener("pointermove",x),window.removeEventListener("pointerup",h)};window.addEventListener("pointermove",x),window.addEventListener("pointerup",h)},[v,P,t,e,n,r,d,u,g]);if(!s)return null;const T=8,k={position:"absolute",width:T,height:T,background:l,border:"1px solid #fff",borderRadius:2,zIndex:20,...o};return N.jsxs(N.Fragment,{children:[N.jsx("div",{style:{...k,bottom:-T/2,right:-T/2,cursor:"nwse-resize"},onPointerDown:z=>R(z,"se")}),N.jsx("div",{style:{...k,bottom:-T/2,left:-T/2,cursor:"nesw-resize"},onPointerDown:z=>R(z,"sw")}),N.jsx("div",{style:{...k,top:-T/2,right:-T/2,cursor:"nesw-resize"},onPointerDown:z=>R(z,"ne")}),N.jsx("div",{style:{...k,top:-T/2,left:-T/2,cursor:"nwse-resize"},onPointerDown:z=>R(z,"nw")}),N.jsx("div",{style:{...k,top:"50%",right:-T/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:z=>R(z,"e")}),N.jsx("div",{style:{...k,top:"50%",left:-T/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:z=>R(z,"w")}),N.jsx("div",{style:{...k,left:"50%",top:-T/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:z=>R(z,"n")}),N.jsx("div",{style:{...k,left:"50%",bottom:-T/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:z=>R(z,"s")})]})}function Fo({isVisible:t,position:e="top",offset:n=10,align:r="center",children:s,style:o={},className:i=""}){const l=a.useContext(_e),u=ft().nodes.find(P=>P.id===l);if(!(t!==void 0?t:u==null?void 0:u.selected))return null;const v={top:{bottom:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginBottom:n},bottom:{top:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginTop:n},left:{right:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginRight:n},right:{left:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginLeft:n}}[e]||{};return N.jsx("div",{className:`ric-node-toolbar ${i}`,style:{position:"absolute",zIndex:1e3,pointerEvents:"all",...v,...o},onPointerDown:P=>P.stopPropagation(),children:s})}function Xo({isVisible:t=!1,x:e=0,y:n=0,alignX:r="center",alignY:s="center",children:o,style:i={},className:l=""}){if(!t)return null;const d=r==="center"?"-50%":r==="right"?"-100%":"0",u=s==="center"?"-50%":s==="bottom"?"-100%":"0";return N.jsx("div",{className:`ric-edge-toolbar ${l}`,style:{position:"absolute",left:e,top:n,transform:`translate(${d}, ${u})`,zIndex:1e3,pointerEvents:"all",...i},children:o})}function Yo({children:t}){var r;const n=(r=ft().edgeLabelContainerRef)==null?void 0:r.current;return n?Xn.createPortal(t,n):null}function Uo({children:t}){var r;const n=(r=ft().viewportPortalRef)==null?void 0:r.current;return n?Xn.createPortal(t,n):null}function fr({fromX:t,fromY:e,toX:n,toY:r,fromPosition:s="right",toPosition:o="left",connectionLineType:i="default",connectionLineStyle:l,connectionLineComponent:d}){if(d)return N.jsx(d,{fromX:t,fromY:e,toX:n,toY:r,fromPosition:s,toPosition:o});let u;switch(i){case"straight":[u]=kn({sourceX:t,sourceY:e,targetX:n,targetY:r});break;case"step":[u]=tn({sourceX:t,sourceY:e,targetX:n,targetY:r,sourcePosition:s,targetPosition:o,borderRadius:0});break;case"smoothstep":[u]=tn({sourceX:t,sourceY:e,targetX:n,targetY:r,sourcePosition:s,targetPosition:o});break;case"simplebezier":[u]=En({sourceX:t,sourceY:e,targetX:n,targetY:r});break;default:[u]=Cn({sourceX:t,sourceY:e,targetX:n,targetY:r,sourcePosition:s,targetPosition:o});break}return N.jsx("path",{d:u,fill:"none",className:"ric-connection-line",stroke:"#b1b1b7",strokeWidth:1.5,style:l})}fr.displayName="ConnectionLine";const qo=a.memo(fr),Go=Object.freeze({Top:"top",Bottom:"bottom",Left:"left",Right:"right"}),Oo=Object.freeze({Arrow:"arrow",ArrowClosed:"arrowclosed"});function Zo(t){const e=t.width||t.measured&&t.measured.width||0,n=t.height||t.measured&&t.measured.height||0,r=t._absolutePosition||t.position||{x:0,y:0};return{x:r.x,y:r.y,x2:r.x+e,y2:r.y+n}}exports.Background=Ho;exports.BaseEdge=We;exports.BezierEdge=Rn;exports.ConnectionLine=qo;exports.ControlButton=Ae;exports.Controls=Ao;exports.DefaultNode=Or;exports.EdgeLabelRenderer=Yo;exports.EdgeText=sr;exports.EdgeToolbar=Xo;exports.GroupNode=rr;exports.Handle=He;exports.InfiniteCanvas=co;exports.InfiniteCanvasProvider=lo;exports.InputNode=er;exports.MarkerType=Oo;exports.MiniMap=Io;exports.NodeResizer=Wo;exports.NodeToolbar=Fo;exports.OutputNode=nr;exports.Panel=_o;exports.Position=Go;exports.SelectionBox=Jn;exports.SimpleBezierEdge=In;exports.SmoothStepEdge=Pn;exports.StepEdge=ar;exports.StraightEdge=Nn;exports.ViewportPortal=Uo;exports.addEdge=fo;exports.applyEdgeChanges=ur;exports.applyNodeChanges=lr;exports.boxToRect=Sr;exports.buildObstacles=zn;exports.clampPosition=bn;exports.computeRoutedEdges=oo;exports.getBezierEdgeCenter=Zr;exports.getBezierPath=Cn;exports.getBoundsOfBoxes=Tr;exports.getConnectedEdges=qn;exports.getEdgeCenter=Qr;exports.getIncomers=Nr;exports.getNodeDimensions=Mn;exports.getNodesBounds=Ve;exports.getNodesInside=Ir;exports.getOutgoers=Pr;exports.getOverlappingArea=$r;exports.getRoutedLabelPosition=an;exports.getSimpleBezierPath=En;exports.getSmoothStepPath=tn;exports.getStraightPath=kn;exports.getViewportForBounds=Je;exports.isEdge=zr;exports.isNode=Er;exports.nodeToBox=Zo;exports.nodeToRect=Br;exports.reconnectEdge=Kr;exports.rectToBox=Lr;exports.routeSinglePath=so;exports.routedPointsToPath=sn;exports.snapPosition=vn;exports.useConnection=mo;exports.useEdges=xo;exports.useEdgesState=yo;exports.useHandleConnections=wo;exports.useInfiniteCanvas=On;exports.useInternalNode=zo;exports.useKeyPress=ko;exports.useNodeConnections=bo;exports.useNodeId=_r;exports.useNodes=go;exports.useNodesData=vo;exports.useNodesInitialized=Eo;exports.useNodesState=ho;exports.useOnSelectionChange=Ro;exports.useOnViewportChange=Mo;exports.useReactFlow=dr;exports.useStore=No;exports.useStoreApi=Po;exports.useUpdateNodeInternals=Co;exports.useViewport=po;
848
+ `,qn=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",sr],{type:"text/javascript;charset=utf-8"});function Hr(e){let t;try{if(t=qn&&(self.URL||self.webkitURL).createObjectURL(qn),!t)throw"";const n=new Worker(t,{type:"module",name:e==null?void 0:e.name});return n.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),n}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(sr),{type:"module",name:e==null?void 0:e.name})}}const Sn=new WeakMap;function _r(e,t){if(Sn.has(e))return Sn.get(e);const n=e.transferControlToOffscreen(),r=new Hr;r.onerror=o=>console.error("[infinite-canvas] worker error:",o.message,o),r.postMessage({type:"init",data:{...t,canvas:n}},[n]);const a={worker:r};return Sn.set(e,a),a}const nt=160,Ve=60,Wr=10;function ar({cards:e=[],nodes:t=[],edges:n=[],onHudUpdate:r,onNodesProcessed:a,onNodesChange:o,onEdgesChange:i,onConnect:f,onNodeClick:x,onNodeDragStart:l,onNodeDrag:y,onNodeDragStop:b,onEdgeClick:E,onEdgeDoubleClick:R,onEdgeMouseEnter:v,onEdgeMouseMove:$,onEdgeMouseLeave:z,onEdgeContextMenu:S,onNodeDoubleClick:X,onNodeMouseEnter:H,onNodeMouseMove:_,onNodeMouseLeave:B,onNodeContextMenu:L,onPaneClick:j,onPaneContextMenu:W,onPaneMouseEnter:A,onPaneMouseMove:p,onPaneMouseLeave:h,onSelectionChange:w,onConnectStart:T,onConnectEnd:I,onInit:Y,onMoveStart:J,onMove:ee,onMoveEnd:V,onDelete:F,onBeforeDelete:te,onError:oe,isValidConnection:fe,dark:ge,gridSize:Te=40,zoomMin:ce=.1,zoomMax:de=4,initialCamera:Le={x:0,y:0,zoom:1},fitView:Se=!1,fitViewOptions:we,nodesDraggable:he=!0,nodesConnectable:le=!0,elementsSelectable:Me=!0,multiSelectionKeyCode:pe="Shift",selectionOnDrag:Je=!1,selectionMode:Nt="partial",connectionMode:$e="loose",connectionRadius:Qe=20,connectOnClick:Ye=!1,snapToGrid:mt=!1,snapGrid:gt=[15,15],deleteKeyCode:vt=["Delete","Backspace"],panActivationKeyCode:bt=" ",panOnScroll:Zt=!1,panOnScrollMode:St="free",panOnScrollSpeed:Gt=.5,zoomOnScroll:Vt=!0,zoomOnDoubleClick:Jt=!0,zoomOnPinch:Qt=!0,preventScrolling:Pt=!0,translateExtent:it,nodeExtent:ct,defaultEdgeOptions:wt={},autoPanOnNodeDrag:mn=!0,autoPanOnConnect:vn=!0,autoPanSpeed:Ke=5,edgesReconnectable:Un=!1,elevateNodesOnSelect:bn=!1,edgeRouting:xt=!0}={}){const xe=c.useRef(null),It=c.useRef(null),Ie=c.useRef(null),se=c.useRef({...Le}),ut=c.useRef([...e]),K=c.useRef([...t]),Pe=c.useRef([...n]),wn=c.useRef(new Map),Mt=c.useRef(!1),rt=c.useRef(null),[Mn,Rn]=c.useState(!1),De=c.useRef(null),He=c.useRef(null),Rt=c.useRef(null),ot=c.useRef(null),Ue=c.useRef(!1),kt=c.useRef(null),[Tt,Kt]=c.useState({x:Le.x,y:Le.y,zoom:Le.zoom}),[en,lt]=c.useState(null),et=c.useMemo(()=>new Set,[]),st=c.useMemo(()=>new Set,[]),qe=c.useRef(!1),Q=c.useRef({});Q.current={onHudUpdate:r,onNodesProcessed:a,onNodesChange:o,onEdgesChange:i,onConnect:f,onNodeClick:x,onNodeDragStart:l,onNodeDrag:y,onNodeDragStop:b,onEdgeClick:E,onEdgeDoubleClick:R,onEdgeMouseEnter:v,onEdgeMouseMove:$,onEdgeMouseLeave:z,onEdgeContextMenu:S,onNodeDoubleClick:X,onNodeMouseEnter:H,onNodeMouseMove:_,onNodeMouseLeave:B,onNodeContextMenu:L,onPaneClick:j,onPaneContextMenu:W,onPaneMouseEnter:A,onPaneMouseMove:p,onPaneMouseLeave:h,onSelectionChange:w,onConnectStart:T,onConnectEnd:I,onInit:Y,onMoveStart:J,onMove:ee,onMoveEnd:V,onDelete:F,onBeforeDelete:te,onError:oe,isValidConnection:fe};const Re={get current(){return Q.current.onNodesChange}},Be={get current(){return Q.current.onEdgesChange}},dt={get current(){return Q.current.onConnect}},Lt={get current(){return Q.current.onNodeClick}},$t={get current(){return Q.current.onNodeDragStart}},Bt={get current(){return Q.current.onNodeDrag}},jt={get current(){return Q.current.onNodeDragStop}},At={get current(){return Q.current.onEdgeClick}},me={get current(){return Q.current.onPaneClick}},ft={get current(){return Q.current.onSelectionChange}},Ct={get current(){return Q.current.onHudUpdate}},Dt={get current(){return Q.current.onNodesProcessed}};c.useEffect(()=>{const d=u=>{u.key===pe&&(Ue.current=!0),u.key===bt&&(qe.current=!0)},M=u=>{u.key===pe&&(Ue.current=!1),u.key===bt&&(qe.current=!1)};return window.addEventListener("keydown",d),window.addEventListener("keyup",M),()=>{window.removeEventListener("keydown",d),window.removeEventListener("keyup",M)}},[pe,bt]);const tt=c.useCallback(()=>{var m;const d=K.current.filter(C=>C.selected),M=Pe.current.filter(C=>C.selected),u={nodes:d,edges:M};(m=ft.current)==null||m.call(ft,u);for(const C of st)C(u)},[st]);c.useEffect(()=>{var d;ut.current=[...e],(d=Ie.current)==null||d.postMessage({type:"cards",data:{cards:[...e]}})},[e]);const ht=c.useCallback(d=>{const M={};for(const u of d)M[u.id]=u;return d.map(u=>{if(!u.parentId)return u;const m=M[u.parentId];if(!m)return u;let C=u.position.x,k=u.position.y,g=m;for(;g;)C+=g.position.x,k+=g.position.y,g=g.parentId?M[g.parentId]:null;return{...u,_absolutePosition:{x:C,y:k}}})},[]),Oe=c.useRef([]),at=c.useCallback(d=>{const M=wn.current;if(!M||M.size===0)return d;const u={};for(const[,m]of M)u[m.nodeId]||(u[m.nodeId]=[]),u[m.nodeId].push({id:m.id,type:m.type,position:m.position,x:m.x,y:m.y});return d.map(m=>{const C=u[m.id];return C&&C.length>0?{...m,handles:C}:m})},[]),Et=c.useCallback(()=>{var M;if(De.current)return;const d=at(Oe.current);(M=Ie.current)==null||M.postMessage({type:"nodes",data:{nodes:d}})},[at]);c.useEffect(()=>{var u;if(De.current){const m=De.current.id,C=new Set([m,...De.current.selectedStarts.map(g=>g.id)]),k={};for(const g of K.current)C.has(g.id)&&(k[g.id]={...g.position});K.current=[...t];for(const g of K.current)k[g.id]&&(g.position=k[g.id]);Oe.current=ht(K.current);return}K.current=[...t];const d=ht(t);Oe.current=d;const M=at(d);(u=Ie.current)==null||u.postMessage({type:"nodes",data:{nodes:M}})},[t,ht,at]),c.useEffect(()=>{var d;Pe.current=[...n],(d=Ie.current)==null||d.postMessage({type:"edges",data:{edges:[...n]}})},[n]);const ze=c.useCallback((d,M)=>{const u=xe.current;if(!u)return{x:0,y:0};const m=u.getBoundingClientRect(),C=se.current;return{x:(d-m.left-C.x)/C.zoom,y:(M-m.top-C.y)/C.zoom}},[]),Ze=c.useCallback((d,M)=>{const u=Oe.current.length>0?Oe.current:K.current;let m=null;for(let C=u.length-1;C>=0;C--){const k=u[C];if(k.hidden)continue;const g=k._absolutePosition||k.position,D=k.width||nt,P=k.height||Ve;if(d>=g.x&&d<=g.x+D&&M>=g.y&&M<=g.y+P){if(k.type==="group"){m||(m=k);continue}return k}}return m},[]),tn=c.useCallback((d,M)=>{const u=M.width||nt,m=M.height||Ve;if(d.x!==void 0&&d.y!==void 0)return{x:M.position.x+d.x,y:M.position.y+d.y};switch(d.position||(d.type==="source"?"right":"left")){case"top":return{x:M.position.x+u/2,y:M.position.y};case"bottom":return{x:M.position.x+u/2,y:M.position.y+m};case"left":return{x:M.position.x,y:M.position.y+m/2};case"right":return{x:M.position.x+u,y:M.position.y+m/2};default:return{x:M.position.x+u,y:M.position.y+m/2}}},[]),nn=c.useCallback(d=>{const M=d.width||nt,u=d.height||Ve;if(d.handles&&d.handles.length>0)return d.handles.map(P=>{const q=tn(P,d);return{id:P.id||null,type:P.type,x:q.x,y:q.y}});const m=d.targetPosition||"left",C=d.sourcePosition||"right",k=P=>{switch(P){case"top":return{x:d.position.x+M/2,y:d.position.y};case"bottom":return{x:d.position.x+M/2,y:d.position.y+u};case"left":return{x:d.position.x,y:d.position.y+u/2};case"right":return{x:d.position.x+M,y:d.position.y+u/2};default:return{x:d.position.x+M,y:d.position.y+u/2}}},g=k(m),D=k(C);return[{id:null,type:"target",x:g.x,y:g.y},{id:null,type:"source",x:D.x,y:D.y}]},[tn]),Z=c.useCallback((d,M)=>{const u=K.current,m=se.current,C=Math.max(Wr,Qe)/m.zoom;for(let k=u.length-1;k>=0;k--){const g=u[k];if(g.hidden)continue;const D=nn(g);for(const P of D)if(Math.abs(d-P.x)<C&&Math.abs(M-P.y)<C)return{nodeId:g.id,handleId:P.id,type:P.type,x:P.x,y:P.y}}return null},[nn]),ke=c.useCallback((d,M)=>{const m=8/se.current.zoom;for(let C=Pe.current.length-1;C>=0;C--){const k=Pe.current[C],g=K.current.find(Ee=>Ee.id===k.source),D=K.current.find(Ee=>Ee.id===k.target);if(!g||!D)continue;const P=g.width||nt,q=g.height||Ve,U=D.height||Ve,ne=g.position.x+P,ye=g.position.y+q/2,G=D.position.x,ie=D.position.y+U/2;if(Fr(d,M,ne,ye,G,ie)<m)return k}return null},[]);c.useEffect(()=>{const d=It.current,M=xe.current;if(!d||!M)return;const u=M.getBoundingClientRect(),m=ge!==void 0?ge:matchMedia("(prefers-color-scheme: dark)").matches,C=ht(K.current);Oe.current=C;const k=at(C),{worker:g}=_r(d,{width:u.width,height:u.height,camera:se.current,cards:ut.current,nodes:k,edges:Pe.current,dark:m,gridSize:Te,edgeRouting:xt});g.onmessage=U=>{var ne,ye;U.data.type==="hud"&&((ne=Ct.current)==null||ne.call(Ct,U.data.data)),U.data.type==="ready"&&Rn(!0),U.data.type==="nodesProcessed"&&((ye=Dt.current)==null||ye.call(Dt,U.data.data))},Ie.current=g;const D=new ResizeObserver(U=>{const{width:ne,height:ye}=U[0].contentRect;g.postMessage({type:"resize",data:{width:ne,height:ye}})});D.observe(M);let P,q;return ge===void 0&&(P=matchMedia("(prefers-color-scheme: dark)"),q=U=>g.postMessage({type:"theme",data:{dark:U.matches}}),P.addEventListener("change",q)),()=>{D.disconnect(),P&&q&&P.removeEventListener("change",q),Ie.current=null}},[]),c.useEffect(()=>{var d;ge!==void 0&&((d=Ie.current)==null||d.postMessage({type:"theme",data:{dark:ge}}))},[ge]),c.useEffect(()=>{var d;(d=Ie.current)==null||d.postMessage({type:"edgeRouting",data:{enabled:xt}})},[xt]);const Ce=c.useRef(0),ue=c.useCallback((d=null)=>{var m,C,k;const M=se.current;if(it){const g=xe.current;if(g){const D=g.getBoundingClientRect(),P=-it[1][0]*M.zoom+D.width,q=-it[1][1]*M.zoom+D.height,U=-it[0][0]*M.zoom,ne=-it[0][1]*M.zoom;M.x=Math.min(U,Math.max(P,M.x)),M.y=Math.min(ne,Math.max(q,M.y))}}(m=Ie.current)==null||m.postMessage({type:"camera",data:{camera:{...M}}});const u={x:M.x,y:M.y,zoom:M.zoom};(k=(C=Q.current).onMove)==null||k.call(C,d,u);for(const g of et)g(u);cancelAnimationFrame(Ce.current),Ce.current=requestAnimationFrame(()=>{Kt({x:M.x,y:M.y,zoom:M.zoom})})},[et,it]),_e=c.useCallback(()=>{var u,m;const d=He.current,M=Rt.current;d&&M?((u=Ie.current)==null||u.postMessage({type:"connecting",data:{from:d.startPos,to:M,_routedPoints:null}}),lt({source:d.sourceId,sourceHandle:d.sourceHandle,target:null,targetHandle:null})):((m=Ie.current)==null||m.postMessage({type:"connecting",data:null}),lt(null))},[]),je=c.useCallback(()=>{var M,u;const d=ot.current;d?(M=Ie.current)==null||M.postMessage({type:"selectionBox",data:d}):(u=Ie.current)==null||u.postMessage({type:"selectionBox",data:null})},[]),kn=c.useCallback(d=>{var C,k,g,D,P,q,U,ne,ye,G,ie,be,Ee,Ae,Xe,Fe;const M=K.current.length>0,u=ze(d.clientX,d.clientY),m=Ue.current;if(M&&le){const O=Z(u.x,u.y);if(Ye&&kt.current&&O){const re=kt.current;if(O.nodeId!==re.nodeId){const Ge=re.handleType==="target"?{source:O.nodeId,target:re.nodeId,sourceHandle:O.handleId||null,targetHandle:re.handleId}:{source:re.nodeId,target:O.nodeId,sourceHandle:re.handleId,targetHandle:O.handleId||null};(Q.current.isValidConnection?Q.current.isValidConnection(Ge):!0)&&((C=dt.current)==null||C.call(dt,{...Ge,...wt}))}kt.current=null;return}if($e==="strict"?O&&O.type==="source":O!=null){if(Ye){kt.current={nodeId:O.nodeId,handleId:O.handleId||null,handleType:O.type},(g=(k=Q.current).onConnectStart)==null||g.call(k,d,{nodeId:O.nodeId,handleId:O.handleId,handleType:O.type});return}He.current={sourceId:O.nodeId,sourceHandle:O.handleId||null,sourceType:O.type,startPos:{x:O.x,y:O.y}},Rt.current={x:u.x,y:u.y},(D=xe.current)==null||D.setPointerCapture(d.pointerId),(q=(P=Q.current).onConnectStart)==null||q.call(P,d,{nodeId:O.nodeId,handleId:O.handleId,handleType:O.type}),_e();return}}if(M){const O=Ze(u.x,u.y);if(O){if(Re.current&&Me){const Ne=[];if(m)Ne.push({id:O.id,type:"select",selected:!O.selected});else if(!O.selected){for(const re of K.current)re.id===O.id?Ne.push({id:re.id,type:"select",selected:!0}):re.selected&&Ne.push({id:re.id,type:"select",selected:!1});if(Be.current){const re=Pe.current.filter(ae=>ae.selected).map(ae=>({id:ae.id,type:"select",selected:!1}));re.length&&Be.current(re)}}if(Ne.length){if(Re.current(Ne),bn&&!m){const re=K.current.findIndex(ae=>ae.id===O.id);re>=0&&re<K.current.length-1&&Re.current([{id:O.id,type:"remove"},{type:"add",item:{...K.current[re],selected:!0}}])}tt()}}if((U=Lt.current)==null||U.call(Lt,d,O),he){const Ne=m&&O.selected;let re=null;if(O.parentId&&O.extent==="parent"){const ae=K.current.find(Ge=>Ge.id===O.parentId);if(ae){const Ge=ae.width||nt,Ht=ae.height||Ve,cn=O.width||((ne=O.measured)==null?void 0:ne.width)||nt,_t=O.height||((ye=O.measured)==null?void 0:ye.height)||Ve;re={minX:0,minY:0,maxX:Ge-cn,maxY:Ht-_t}}}if(De.current={id:O.id,startPos:{...O.position},startMouse:{x:u.x,y:u.y},parentClamp:re,parentId:O.parentId||null,selectedStarts:Ne?K.current.filter(ae=>ae.selected&&ae.id!==O.id).map(ae=>{var Ht,cn;let Ge=null;if(ae.parentId&&ae.extent==="parent"){const _t=K.current.find(Nn=>Nn.id===ae.parentId);if(_t){const Nn=_t.width||nt,Er=_t.height||Ve,zr=ae.width||((Ht=ae.measured)==null?void 0:Ht.width)||nt,Nr=ae.height||((cn=ae.measured)==null?void 0:cn.height)||Ve;Ge={minX:0,minY:0,maxX:Nn-zr,maxY:Er-Nr}}}return{id:ae.id,startPos:{...ae.position},parentClamp:Ge,parentId:ae.parentId||null}}):[]},(G=xe.current)==null||G.setPointerCapture(d.pointerId),(ie=$t.current)==null||ie.call($t,d,O),Re.current){const ae=[{id:O.id,type:"position",dragging:!0}];for(const Ge of De.current.selectedStarts)ae.push({id:Ge.id,type:"position",dragging:!0});Re.current(ae)}}return}}if(Pe.current.length>0&&Me){const O=ke(u.x,u.y);if(O){if(Be.current){const Ne=[];if(m)Ne.push({id:O.id,type:"select",selected:!O.selected});else{for(const re of Pe.current)re.id===O.id?Ne.push({id:re.id,type:"select",selected:!0}):re.selected&&Ne.push({id:re.id,type:"select",selected:!1});if(Re.current){const re=K.current.filter(ae=>ae.selected).map(ae=>({id:ae.id,type:"select",selected:!1}));re.length&&Re.current(re)}}Ne.length&&(Be.current(Ne),tt())}(be=At.current)==null||be.call(At,d,O);return}}if(!m){const O=K.current.filter(re=>re.selected).map(re=>({id:re.id,type:"select",selected:!1})),Ne=Pe.current.filter(re=>re.selected).map(re=>({id:re.id,type:"select",selected:!1}));O.length&&Re.current&&Re.current(O),Ne.length&&Be.current&&Be.current(Ne),(O.length||Ne.length)&&tt()}if((Ee=me.current)==null||Ee.call(me,d),Je||m){ot.current={startWorld:{...u},endWorld:{...u}},(Ae=xe.current)==null||Ae.setPointerCapture(d.pointerId),je();return}Mt.current=!0,rt.current={x:d.clientX,y:d.clientY},(Xe=xe.current)==null||Xe.classList.add("dragging"),(Fe=xe.current)==null||Fe.setPointerCapture(d.pointerId)},[ze,Ze,Z,ke,he,le,Me,Je,_e,je,tt]),Cn=c.useCallback(d=>{var u,m;if(He.current){if(Rt.current=ze(d.clientX,d.clientY),_e(),vn){const C=xe.current;if(C){const k=C.getBoundingClientRect(),g=40,D=d.clientX-k.left,P=d.clientY-k.top;let q=0,U=0;D<g?q=Ke:D>k.width-g&&(q=-Ke),P<g?U=Ke:P>k.height-g&&(U=-Ke),(q||U)&&(se.current.x+=q,se.current.y+=U,ue(d))}}return}if(ot.current){ot.current.endWorld=ze(d.clientX,d.clientY),je();const C=ot.current,k=Math.min(C.startWorld.x,C.endWorld.x),g=Math.min(C.startWorld.y,C.endWorld.y),D=Math.max(C.startWorld.x,C.endWorld.x),P=Math.max(C.startWorld.y,C.endWorld.y);if(Re.current){const q=[];for(const U of K.current){if(U.hidden)continue;const ne=U.width||nt,ye=U.height||Ve,G=Nt==="full"?U.position.x>=k&&U.position.x+ne<=D&&U.position.y>=g&&U.position.y+ye<=P:U.position.x+ne>k&&U.position.x<D&&U.position.y+ye>g&&U.position.y<P;G!==!!U.selected&&q.push({id:U.id,type:"select",selected:G})}q.length&&Re.current(q)}return}if(De.current){const C=ze(d.clientX,d.clientY),k=De.current,g=C.x-k.startMouse.x,D=C.y-k.startMouse.y;let P={x:k.startPos.x+g,y:k.startPos.y+D};if(mt&&(P=Ln(P,gt)),ct&&(P=$n(P,ct)),k.parentClamp){const G=k.parentClamp;P={x:Math.max(G.minX,Math.min(P.x,G.maxX)),y:Math.max(G.minY,Math.min(P.y,G.maxY))}}const q=[{id:k.id,position:P}];for(const G of k.selectedStarts){let ie={x:G.startPos.x+g,y:G.startPos.y+D};if(mt&&(ie=Ln(ie,gt)),ct&&(ie=$n(ie,ct)),G.parentClamp){const be=G.parentClamp;ie={x:Math.max(be.minX,Math.min(ie.x,be.maxX)),y:Math.max(be.minY,Math.min(ie.y,be.maxY))}}q.push({id:G.id,position:ie})}const U=[];for(const G of q){const ie=K.current.find(be=>be.id===G.id);if(ie){ie.position=G.position,ie.dragging=!0;let be=G.position;if(ie.parentId){let Ee=K.current.find(Fe=>Fe.id===ie.parentId),Ae=G.position.x,Xe=G.position.y;for(;Ee;)Ae+=Ee.position.x,Xe+=Ee.position.y,Ee=Ee.parentId?K.current.find(Fe=>Fe.id===Ee.parentId):null;be={x:Ae,y:Xe}}U.push({id:G.id,position:G.position,_absolutePosition:be,width:ie.width,height:ie.height,dragging:!0,selected:ie.selected})}}const ne=new Set(q.map(G=>G.id));for(const G of K.current)if(G.parentId&&ne.has(G.parentId)&&!ne.has(G.id)){let ie=K.current.find(Ae=>Ae.id===G.parentId),be=G.position.x,Ee=G.position.y;for(;ie;)be+=ie.position.x,Ee+=ie.position.y,ie=ie.parentId?K.current.find(Ae=>Ae.id===ie.parentId):null;U.push({id:G.id,position:G.position,_absolutePosition:{x:be,y:Ee},width:G.width,height:G.height,dragging:!1,selected:G.selected})}if((u=Ie.current)==null||u.postMessage({type:"nodePositions",data:{updates:U}}),mn){const G=xe.current;if(G){const ie=G.getBoundingClientRect(),be=40,Ee=d.clientX-ie.left,Ae=d.clientY-ie.top;let Xe=0,Fe=0;Ee<be?Xe=Ke:Ee>ie.width-be&&(Xe=-Ke),Ae<be?Fe=Ke:Ae>ie.height-be&&(Fe=-Ke),(Xe||Fe)&&(se.current.x+=Xe,se.current.y+=Fe,ue(d))}}const ye=K.current.find(G=>G.id===k.id);ye&&((m=Bt.current)==null||m.call(Bt,d,ye));return}if(!Mt.current)return;const M=se.current;M.x+=d.clientX-rt.current.x,M.y+=d.clientY-rt.current.y,rt.current={x:d.clientX,y:d.clientY},ue()},[ue,ze,_e,je]),En=c.useCallback(d=>{var M,u,m,C,k;if(He.current){const g=ze(d.clientX,d.clientY),D=Z(g.x,g.y);if(D&&D.nodeId!==He.current.sourceId&&($e==="loose"||D.type==="target")){const U=He.current.sourceType==="target"?{source:D.nodeId,target:He.current.sourceId,sourceHandle:D.handleId||null,targetHandle:He.current.sourceHandle}:{source:He.current.sourceId,target:D.nodeId,sourceHandle:He.current.sourceHandle,targetHandle:D.handleId||null};(Q.current.isValidConnection?Q.current.isValidConnection(U):!0)&&((M=dt.current)==null||M.call(dt,{...U,...wt}))}(m=(u=Q.current).onConnectEnd)==null||m.call(u,d.nativeEvent||d),He.current=null,Rt.current=null,_e();return}if(ot.current){ot.current=null,je(),tt();return}if(De.current){const g=De.current;if(Re.current){const P=K.current.find(U=>U.id===g.id),q=[{id:g.id,type:"position",position:P?{...P.position}:void 0,dragging:!1}];for(const U of g.selectedStarts){const ne=K.current.find(ye=>ye.id===U.id);q.push({id:U.id,type:"position",position:ne?{...ne.position}:void 0,dragging:!1})}Re.current(q)}requestAnimationFrame(()=>{De.current=null});const D=K.current.find(P=>P.id===g.id);D&&((C=jt.current)==null||C.call(jt,d,D));return}Mt.current=!1,(k=xe.current)==null||k.classList.remove("dragging")},[ze,Z,_e,je,tt]);c.useEffect(()=>{const d=xe.current;if(!d)return;const M=u=>{Pt&&u.preventDefault();const m=se.current;if(Zt||qe.current){const P=Gt;St==="horizontal"?m.x-=u.deltaY*P:(St==="vertical"||(m.x-=u.deltaX*P),m.y-=u.deltaY*P),ue(u);return}if(!Vt)return;const C=u.deltaY>0?.92:1.08,k=d.getBoundingClientRect(),g=u.clientX-k.left,D=u.clientY-k.top;m.x=g-(g-m.x)*C,m.y=D-(D-m.y)*C,m.zoom=Math.min(de,Math.max(ce,m.zoom*C)),ue(u)};return d.addEventListener("wheel",M,{passive:!Pt}),()=>d.removeEventListener("wheel",M)},[ue,ce,de,Zt,St,Gt,Vt,Pt]),c.useEffect(()=>{if(!Qt)return;const d=xe.current;if(!d)return;let M=0,u=null;const m=g=>{if(g.touches.length===2){const D=g.touches[0].clientX-g.touches[1].clientX,P=g.touches[0].clientY-g.touches[1].clientY;M=Math.hypot(D,P);const q=d.getBoundingClientRect();u={x:(g.touches[0].clientX+g.touches[1].clientX)/2-q.left,y:(g.touches[0].clientY+g.touches[1].clientY)/2-q.top},g.preventDefault()}},C=g=>{if(g.touches.length===2&&M>0){g.preventDefault();const D=g.touches[0].clientX-g.touches[1].clientX,P=g.touches[0].clientY-g.touches[1].clientY,q=Math.hypot(D,P),U=q/M;M=q;const ne=se.current,ye=u.x,G=u.y;ne.x=ye-(ye-ne.x)*U,ne.y=G-(G-ne.y)*U,ne.zoom=Math.min(de,Math.max(ce,ne.zoom*U)),ue(g)}},k=()=>{M=0,u=null};return d.addEventListener("touchstart",m,{passive:!1}),d.addEventListener("touchmove",C,{passive:!1}),d.addEventListener("touchend",k),()=>{d.removeEventListener("touchstart",m),d.removeEventListener("touchmove",C),d.removeEventListener("touchend",k)}},[Qt,ue,ce,de]),c.useEffect(()=>{if(!Jt)return;const d=xe.current;if(!d)return;const M=u=>{var U,ne,ye,G;const m=ze(u.clientX,u.clientY);if(Ze(m.x,m.y)){(ne=(U=Q.current).onNodeDoubleClick)==null||ne.call(U,u,Ze(m.x,m.y));return}const C=ke(m.x,m.y);if(C){(G=(ye=Q.current).onEdgeDoubleClick)==null||G.call(ye,u,C);return}const k=1.5,g=d.getBoundingClientRect(),D=u.clientX-g.left,P=u.clientY-g.top,q=se.current;q.x=D-(D-q.x)*k,q.y=P-(P-q.y)*k,q.zoom=Math.min(de,Math.max(ce,q.zoom*k)),ue(u)};return d.addEventListener("dblclick",M),()=>d.removeEventListener("dblclick",M)},[Jt,ue,ce,de,ze,Ze,ke]),c.useEffect(()=>{const d=xe.current;if(!d)return;const M=u=>{var g,D,P,q,U,ne;const m=ze(u.clientX,u.clientY),C=Ze(m.x,m.y);if(C){(D=(g=Q.current).onNodeContextMenu)==null||D.call(g,u,C);return}const k=ke(m.x,m.y);if(k){(q=(P=Q.current).onEdgeContextMenu)==null||q.call(P,u,k);return}(ne=(U=Q.current).onPaneContextMenu)==null||ne.call(U,u)};return d.addEventListener("contextmenu",M),()=>d.removeEventListener("contextmenu",M)},[ze,Ze,ke]),c.useEffect(()=>{const d=xe.current;if(!d)return;let M=null,u=null;const m=g=>{var q,U,ne,ye,G,ie,be,Ee,Ae,Xe,Fe,O,Ne,re;if((U=(q=Q.current).onPaneMouseMove)==null||U.call(q,g),Mt.current||De.current||He.current||ot.current)return;const D=ze(g.clientX,g.clientY),P=Ze(D.x,D.y);if(P!==M&&(M&&((ye=(ne=Q.current).onNodeMouseLeave)==null||ye.call(ne,g,M)),P&&((ie=(G=Q.current).onNodeMouseEnter)==null||ie.call(G,g,P)),M=P),P&&((Ee=(be=Q.current).onNodeMouseMove)==null||Ee.call(be,g,P)),!P){const ae=ke(D.x,D.y);ae!==u&&(u&&((Xe=(Ae=Q.current).onEdgeMouseLeave)==null||Xe.call(Ae,g,u)),ae&&((O=(Fe=Q.current).onEdgeMouseEnter)==null||O.call(Fe,g,ae)),u=ae),ae&&((re=(Ne=Q.current).onEdgeMouseMove)==null||re.call(Ne,g,ae))}},C=g=>{var D,P;return(P=(D=Q.current).onPaneMouseEnter)==null?void 0:P.call(D,g)},k=g=>{var D,P,q,U,ne,ye;(P=(D=Q.current).onPaneMouseLeave)==null||P.call(D,g),M&&((U=(q=Q.current).onNodeMouseLeave)==null||U.call(q,g,M),M=null),u&&((ye=(ne=Q.current).onEdgeMouseLeave)==null||ye.call(ne,g,u),u=null)};return d.addEventListener("mousemove",m),d.addEventListener("mouseenter",C),d.addEventListener("mouseleave",k),()=>{d.removeEventListener("mousemove",m),d.removeEventListener("mouseenter",C),d.removeEventListener("mouseleave",k)}},[ze,Ze,ke]),c.useEffect(()=>{const d=Array.isArray(vt)?vt:[vt],M=async u=>{var m,C;if(d.includes(u.key)){if(u.target.tagName==="INPUT"||u.target.tagName==="TEXTAREA"||u.target.isContentEditable)return;const k=K.current.filter(P=>P.selected),g=Pe.current.filter(P=>P.selected);if(!k.length&&!g.length||Q.current.onBeforeDelete&&!await Q.current.onBeforeDelete({nodes:k,edges:g}))return;const D=new Set(k.map(P=>P.id));if(k.length&&Re.current&&(Re.current(k.map(P=>({id:P.id,type:"remove"}))),Be.current)){const P=Pe.current.filter(q=>D.has(q.source)||D.has(q.target));P.length&&Be.current(P.map(q=>({id:q.id,type:"remove"})))}g.length&&Be.current&&Be.current(g.map(P=>({id:P.id,type:"remove"}))),(C=(m=Q.current).onDelete)==null||C.call(m,{nodes:k,edges:g})}if((u.ctrlKey||u.metaKey)&&u.key==="a"){if(u.target.tagName==="INPUT"||u.target.tagName==="TEXTAREA")return;if(u.preventDefault(),Re.current){const k=K.current.filter(g=>!g.selected).map(g=>({id:g.id,type:"select",selected:!0}));k.length&&Re.current(k)}if(Be.current){const k=Pe.current.filter(g=>!g.selected).map(g=>({id:g.id,type:"select",selected:!0}));k.length&&Be.current(k)}}};return window.addEventListener("keydown",M),()=>window.removeEventListener("keydown",M)},[vt]);const rn=c.useRef(!1);c.useEffect(()=>{var d,M;if(!rn.current&&Ie.current){if(rn.current=!0,Se&&K.current.length>0){const u=xe.current;if(u){const m=u.getBoundingClientRect(),C=(we==null?void 0:we.padding)??.1,k=ln(K.current),g=zt(k,m.width,m.height,C);we!=null&&we.maxZoom&&(g.zoom=Math.min(g.zoom,we.maxZoom)),we!=null&&we.minZoom&&(g.zoom=Math.max(g.zoom,we.minZoom)),se.current=g,ue()}}(M=(d=Q.current).onInit)==null||M.call(d,{getNodes:()=>[...K.current],getEdges:()=>[...Pe.current],getNode:u=>K.current.find(m=>m.id===u),getEdge:u=>Pe.current.find(m=>m.id===u),getViewport:()=>({...se.current}),getZoom:()=>se.current.zoom,setViewport:u=>{se.current={x:u.x??se.current.x,y:u.y??se.current.y,zoom:u.zoom??se.current.zoom},ue()},fitView:(u={})=>{const m=xe.current;if(!m||!K.current.length)return;const C=m.getBoundingClientRect(),k=u.nodes?K.current.filter(P=>u.nodes.some(q=>q.id===P.id)):K.current;if(!k.length)return;const g=ln(k),D=zt(g,C.width,C.height,u.padding??.1);u.maxZoom&&(D.zoom=Math.min(D.zoom,u.maxZoom)),u.minZoom&&(D.zoom=Math.max(D.zoom,u.minZoom)),se.current=D,ue()},screenToFlowPosition:u=>ze(u.x,u.y),flowToScreenPosition:u=>{const m=se.current,C=xe.current;if(!C)return{x:0,y:0};const k=C.getBoundingClientRect();return{x:u.x*m.zoom+m.x+k.left,y:u.y*m.zoom+m.y+k.top}},zoomIn:()=>{const u=se.current;u.zoom=Math.min(de,u.zoom*1.2),ue()},zoomOut:()=>{const u=se.current;u.zoom=Math.max(ce,u.zoom/1.2),ue()},zoomTo:u=>{se.current.zoom=Math.min(de,Math.max(ce,u)),ue()},setNodes:u=>{var m,C;(C=(m=Q.current).onNodesChange)==null||C.call(m,[...K.current.map(k=>({id:k.id,type:"remove"})),...(typeof u=="function"?u(K.current):u).map(k=>({type:"add",item:k}))])},setEdges:u=>{var m,C;(C=(m=Q.current).onEdgesChange)==null||C.call(m,[...Pe.current.map(k=>({id:k.id,type:"remove"})),...(typeof u=="function"?u(Pe.current):u).map(k=>({type:"add",item:k}))])},addNodes:u=>{var C,k;const m=Array.isArray(u)?u:[u];(k=(C=Q.current).onNodesChange)==null||k.call(C,m.map(g=>({type:"add",item:g})))},addEdges:u=>{var C,k;const m=Array.isArray(u)?u:[u];(k=(C=Q.current).onEdgesChange)==null||k.call(C,m.map(g=>({type:"add",item:g})))},deleteElements:({nodes:u=[],edges:m=[]})=>{var C,k,g,D;u.length&&((k=(C=Q.current).onNodesChange)==null||k.call(C,u.map(P=>({id:P.id,type:"remove"})))),m.length&&((D=(g=Q.current).onEdgesChange)==null||D.call(g,m.map(P=>({id:P.id,type:"remove"}))))},updateNodeData:(u,m)=>{var g,D;const C=K.current.find(P=>P.id===u);if(!C)return;const k=typeof m=="function"?m(C.data):{...C.data,...m};(D=(g=Q.current).onNodesChange)==null||D.call(g,[{id:u,type:"replace",item:{...C,data:k}}])},toObject:()=>({nodes:[...K.current],edges:[...Pe.current],viewport:{...se.current}}),setCenter:(u,m,C={})=>{const k=xe.current;if(!k)return;const g=k.getBoundingClientRect(),D=C.zoom??se.current.zoom;se.current={x:g.width/2-u*D,y:g.height/2-m*D,zoom:D},ue()},fitBounds:(u,m={})=>{const C=xe.current;if(!C)return;const k=C.getBoundingClientRect(),g=zt(u,k.width,k.height,m.padding??.1);se.current=g,ue()}})}});const pt=c.useCallback(()=>{se.current={...Le},ue()},[ue,Le]),on=c.useCallback(d=>{var M;if(d)ut.current.push(d);else{const u=se.current,m=xe.current;if(!m)return;const C=m.getBoundingClientRect(),k=Math.round(-u.x/u.zoom+C.width/2/u.zoom),g=Math.round(-u.y/u.zoom+C.height/2/u.zoom);ut.current.push({x:k-80,y:g-45,w:160,h:90,title:"Note "+(ut.current.length+1),body:"Added at viewport center"})}(M=Ie.current)==null||M.postMessage({type:"cards",data:{cards:[...ut.current]}})},[]),sn=c.useCallback(d=>{if(d.id||(d.id="node-"+Date.now()),!d.position){const M=se.current,u=xe.current;if(!u)return;const m=u.getBoundingClientRect();d.position={x:Math.round(-M.x/M.zoom+m.width/2/M.zoom)-nt/2,y:Math.round(-M.y/M.zoom+m.height/2/M.zoom)-Ve/2}}d.data||(d.data={label:d.id}),Re.current&&Re.current([{type:"add",item:d}])},[]),We=c.useCallback(()=>({...se.current}),[]),yt=c.useCallback(d=>{se.current={...se.current,...d},ue()},[ue]),zn=c.useCallback(d=>ze(d.x,d.y),[ze]),an=n,Cr=c.useMemo(()=>({wrapRef:xe,canvasRef:It,workerRef:Ie,cameraRef:se,nodesRef:K,edgesRef:Pe,handleRegistryRef:wn,syncNodesToWorker:Et,onNodesChangeRef:Re,onEdgesChangeRef:Be,sendCamera:ue,screenToWorld:ze,viewportListeners:et,selectionListeners:st,zoomMin:ce,zoomMax:de,snapToGrid:mt,snapGrid:gt,nodeExtent:ct,defaultEdgeOptions:wt,edgeRouting:xt,resolvedNodesRef:Oe,get nodes(){return t},get edges(){return n},get routedEdges(){return an},get viewport(){return Tt},get connection(){return en}}),[t,n,an,Tt,en,ue,ze,Et,et,st,ce,de,mt,gt,ct,wt,xt]);return{wrapRef:xe,canvasRef:It,canvasReady:Mn,onPointerDown:kn,onPointerMove:Cn,onPointerUp:En,resetView:pt,addCard:on,addNode:sn,getCamera:We,setCamera:yt,screenToFlowPosition:zn,store:Cr}}function Fr(e,t,n,r,a,o){const i=a-n,f=o-r,x=i*i+f*f;if(x===0)return Math.hypot(e-n,t-r);let l=((e-n)*i+(t-r)*f)/x;return l=Math.max(0,Math.min(1,l)),Math.hypot(e-(n+l*i),t-(r+l*f))}const On=e=>{let t;const n=new Set,r=(l,y)=>{const b=typeof l=="function"?l(t):l;if(!Object.is(b,t)){const E=t;t=y??(typeof b!="object"||b===null)?b:Object.assign({},t,b),n.forEach(R=>R(t,E))}},a=()=>t,f={setState:r,getState:a,getInitialState:()=>x,subscribe:l=>(n.add(l),()=>n.delete(l))},x=t=e(r,a,f);return f},Xr=(e=>e?On(e):On),Yr=e=>e;function Ur(e,t=Yr){const n=c.useSyncExternalStore(e.subscribe,c.useCallback(()=>t(e.getState()),[e,t]),c.useCallback(()=>t(e.getInitialState()),[e,t]));return c.useDebugValue(n),n}const Yt=c.createContext(null);function qr(e={}){return Xr((t,n)=>({nodes:[],edges:[],viewport:{x:0,y:0,zoom:1},connection:null,minZoom:.1,maxZoom:5,width:0,height:0,domNode:null,nodesRef:{current:[]},edgesRef:{current:[]},cameraRef:{current:{x:0,y:0,zoom:1}},wrapRef:{current:null},workerRef:{current:null},onNodesChangeRef:{current:null},onEdgesChangeRef:{current:null},viewportListeners:new Set,selectionListeners:new Set,edgeLabelContainerRef:{current:null},viewportPortalRef:{current:null},screenToWorld:(r,a)=>{const o=n().cameraRef.current;return{x:(r-o.x)/o.zoom,y:(a-o.y)/o.zoom}},sendCamera:()=>{var a;const r=n();(a=r.workerRef.current)==null||a.postMessage({type:"camera",data:{camera:{...r.cameraRef.current}}})},...e}))}function ve(e,t){const n=c.useContext(Yt);if(!n)throw new Error("useCanvasStore must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");const r=typeof n.getState=="function"&&typeof n.subscribe=="function",a=c.useRef(e),o=c.useRef(t),i=c.useRef(void 0);a.current=e,o.current=t;const f=c.useCallback(x=>{const l=a.current;if(!l)return x;const y=l(x),b=o.current||Object.is;return i.current!==void 0&&b(i.current,y)?i.current:(i.current=y,y)},[]);return r?Ur(n,e?f:void 0):e?f(n):n}function ir(){const e=c.useContext(Yt);if(!e)throw new Error("useCanvasStoreApi must be used within <InfiniteCanvas> or <InfiniteCanvasProvider>");return typeof e.getState=="function"?e:{getState:()=>e,setState:()=>{},subscribe:()=>()=>{}}}const qt=c.createContext(null);function Or(){return c.useContext(qt)}function Zr({node:e,nodeType:t}){var b,E,R;const n=ve(),r=c.useRef(null),a=e._absolutePosition||e.position,o=c.useRef(null);c.useEffect(()=>{const v=r.current;if(!v)return;const $=new ResizeObserver(z=>{var H,_,B,L;const{width:S,height:X}=z[0].contentRect;if(S>0&&X>0){const j=n.nodesRef.current.find(p=>p.id===e.id),W=(j==null?void 0:j.width)||((H=j==null?void 0:j.measured)==null?void 0:H.width),A=(j==null?void 0:j.height)||((_=j==null?void 0:j.measured)==null?void 0:_.height);(Math.abs((W||0)-S)>1||Math.abs((A||0)-X)>1)&&((L=(B=n.onNodesChangeRef).current)==null||L.call(B,[{id:e.id,type:"dimensions",dimensions:{width:S,height:X},setAttributes:!0}]))}});return $.observe(v),()=>$.disconnect()},[e.id,n]);const i=c.useCallback(v=>{var Y,J,ee,V;v.stopPropagation();const $=v.target.tagName;if($==="INPUT"||$==="TEXTAREA"||$==="SELECT"||$==="BUTTON"||$==="A"||$==="LABEL"||v.target.isContentEditable)return;let z=v.target;for(;z&&z!==r.current;){if((Y=z.classList)!=null&&Y.contains("nodrag")||(J=z.classList)!=null&&J.contains("nopan"))return;z=z.parentElement}if(n.onNodesChangeRef.current){const F=[];if(v.shiftKey)F.push({id:e.id,type:"select",selected:!e.selected});else for(const oe of n.nodesRef.current)oe.id===e.id&&!oe.selected?F.push({id:oe.id,type:"select",selected:!0}):oe.id!==e.id&&oe.selected&&F.push({id:oe.id,type:"select",selected:!1});F.length&&n.onNodesChangeRef.current(F)}const S=n.cameraRef.current,X=n.wrapRef.current;if(!X)return;const H=X.getBoundingClientRect(),_=(v.clientX-H.left-S.x)/S.zoom,B=(v.clientY-H.top-S.y)/S.zoom,j=v.shiftKey&&e.selected?n.nodesRef.current.filter(F=>F.selected&&F.id!==e.id).map(F=>({id:F.id,startPos:{...F.position}})):[];o.current={startPos:{...e.position},startMouse:{x:_,y:B},selectedStarts:j};const W=[{id:e.id,type:"position",dragging:!0}];for(const F of j)W.push({id:F.id,type:"position",dragging:!0});(V=(ee=n.onNodesChangeRef).current)==null||V.call(ee,W);const A=r.current;A&&A.setPointerCapture(v.pointerId);let p=null,h=null;const w=()=>{var F,te;h&&((te=(F=n.onNodesChangeRef).current)==null||te.call(F,h),h=null),p=null},T=F=>{var Se,we;if(!o.current)return;const te=n.cameraRef.current,oe=X.getBoundingClientRect(),fe=(F.clientX-oe.left-te.x)/te.zoom,ge=(F.clientY-oe.top-te.y)/te.zoom,Te=fe-o.current.startMouse.x,ce=ge-o.current.startMouse.y;let de={x:o.current.startPos.x+Te,y:o.current.startPos.y+ce};if(n.snapToGrid&&n.snapGrid&&(de={x:n.snapGrid[0]*Math.round(de.x/n.snapGrid[0]),y:n.snapGrid[1]*Math.round(de.y/n.snapGrid[1])}),e.parentId&&e.extent==="parent"){const he=n.nodesRef.current.find(le=>le.id===e.parentId);if(he){const le=he.width||160,Me=he.height||60,pe=e.width||((Se=e.measured)==null?void 0:Se.width)||160,Je=e.height||((we=e.measured)==null?void 0:we.height)||60;de={x:Math.max(0,Math.min(de.x,le-pe)),y:Math.max(0,Math.min(de.y,Me-Je))}}}A&&(A.style.left=de.x+"px",A.style.top=de.y+"px");for(const he of o.current.selectedStarts){let le={x:he.startPos.x+Te,y:he.startPos.y+ce};n.snapToGrid&&n.snapGrid&&(le={x:n.snapGrid[0]*Math.round(le.x/n.snapGrid[0]),y:n.snapGrid[1]*Math.round(le.y/n.snapGrid[1])});const Me=X.querySelector(`[data-nodeid="${he.id}"]`);Me&&(Me.style.left=le.x+"px",Me.style.top=le.y+"px")}const Le=[{id:e.id,type:"position",position:de,dragging:!0}];for(const he of o.current.selectedStarts){let le={x:he.startPos.x+Te,y:he.startPos.y+ce};n.snapToGrid&&n.snapGrid&&(le={x:n.snapGrid[0]*Math.round(le.x/n.snapGrid[0]),y:n.snapGrid[1]*Math.round(le.y/n.snapGrid[1])}),Le.push({id:he.id,type:"position",position:le,dragging:!0})}h=Le,p||(p=requestAnimationFrame(w))},I=F=>{var oe,fe;if(!o.current)return;p&&(cancelAnimationFrame(p),w());const te=[{id:e.id,type:"position",dragging:!1}];for(const ge of o.current.selectedStarts)te.push({id:ge.id,type:"position",dragging:!1});(fe=(oe=n.onNodesChangeRef).current)==null||fe.call(oe,te),o.current=null,A&&A.releasePointerCapture(F.pointerId),A==null||A.removeEventListener("pointermove",T),A==null||A.removeEventListener("pointerup",I)};A==null||A.addEventListener("pointermove",T),A==null||A.addEventListener("pointerup",I)},[e,n]),f=c.useCallback(v=>{var _,B,L,j,W,A;if(!e.selected)return;const $=v.shiftKey?10:1;let z=0,S=0;switch(v.key){case"ArrowUp":S=-$;break;case"ArrowDown":S=$;break;case"ArrowLeft":z=-$;break;case"ArrowRight":z=$;break;case"Escape":(B=(_=n.onNodesChangeRef).current)==null||B.call(_,[{id:e.id,type:"select",selected:!1}]);return;case"Delete":case"Backspace":e.deletable!==!1&&((j=(L=n.onNodesChangeRef).current)==null||j.call(L,[{id:e.id,type:"remove"}]));return;default:return}v.preventDefault();const X={x:e.position.x+z,y:e.position.y+S},H=[{id:e.id,type:"position",position:X}];for(const p of n.nodesRef.current)p.selected&&p.id!==e.id&&H.push({id:p.id,type:"position",position:{x:p.position.x+z,y:p.position.y+S}});(A=(W=n.onNodesChangeRef).current)==null||A.call(W,H)},[e,n]),x=e.width||((b=e.measured)==null?void 0:b.width),l=e.height||((E=e.measured)==null?void 0:E.height),y=!!(x&&l);return N.jsx(qt.Provider,{value:e.id,children:N.jsx("div",{ref:r,className:`ric-node-wrapper ${e.selected?"selected":""} ${e.dragging?"dragging":""}`,style:{position:"absolute",left:a.x,top:a.y,zIndex:e.type==="group"?0:e.zIndex||1,pointerEvents:e.type==="group"?"none":"all",visibility:y?"visible":"hidden",outline:"none"},"data-nodeid":e.id,tabIndex:e.selectable!==!1?0:void 0,role:"button","aria-label":`Node ${((R=e.data)==null?void 0:R.label)||e.id}`,"aria-selected":!!e.selected,onPointerDown:i,onKeyDown:f,children:N.jsx(t,{id:e.id,data:e.data,type:e.type,selected:!!e.selected,dragging:!!e.dragging,draggable:e.draggable!==!1,selectable:e.selectable!==!1,deletable:e.deletable!==!1,isConnectable:e.connectable!==!1,zIndex:e.zIndex||0,positionAbsoluteX:a.x,positionAbsoluteY:a.y,width:x,height:l,sourcePosition:e.sourcePosition,targetPosition:e.targetPosition,parentId:e.parentId,dragHandle:e.dragHandle})})})}const Gr=c.memo(Zr),cr=160,ur=60;function Zn(e,t,n,r){var f,x;const a=e.width||((f=e.measured)==null?void 0:f.width)||cr,o=e.height||((x=e.measured)==null?void 0:x.height)||ur,i=e._absolutePosition||e.position;if(e.handleBounds){const l=e.handleBounds[t]||[],y=n?l.find(b=>b.id===n):l[0];if(y&&y.x!==void 0&&y.y!==void 0){const b=y.position||(t==="source"?"right":"left");return{x:i.x+y.x,y:i.y+y.y,position:b}}}if(r){const l=`${e.id}__${n||t}`,y=r.get(l);if(y&&y.x!==void 0&&y.y!==void 0)return{x:i.x+y.x,y:i.y+y.y,position:y.position||(t==="source"?"right":"left")}}if(e.handles&&e.handles.length){for(const l of e.handles)if(l.type===t&&(!n||l.id===n)){if(l.x!==void 0&&l.y!==void 0)return{x:i.x+l.x,y:i.y+l.y,position:l.position||(t==="source"?"right":"left")};const y=l.position||(t==="source"?"right":"left");switch(y){case"top":return{x:i.x+a/2,y:i.y,position:y};case"bottom":return{x:i.x+a/2,y:i.y+o,position:y};case"left":return{x:i.x,y:i.y+o/2,position:y};default:return{x:i.x+a,y:i.y+o/2,position:y}}}}return t==="source"?{x:i.x+a,y:i.y+o/2,position:"right"}:{x:i.x,y:i.y+o/2,position:"left"}}function Vr(e,t,n){return n==="left"?e-t:n==="right"?e+t:e}function Jr(e,t,n){return n==="top"?e-t:n==="bottom"?e+t:e}function Gn({x:e,y:t,position:n,type:r,onPointerDown:a}){return N.jsx("circle",{className:`ric-edge-anchor ric-edge-anchor-${r}`,cx:Vr(e,10,n),cy:Jr(t,10,n),r:10,stroke:"transparent",fill:"transparent",style:{cursor:"move",pointerEvents:"stroke"},onPointerDown:a})}function Qr({edge:e,edgeType:t,nodes:n,reconnectable:r}){var _,B,L;const a=ve(),[o,i]=c.useState(null),f=c.useCallback((j,W,A,p)=>{var ee;W.stopPropagation(),W.preventDefault();const h=a.wrapRef.current;if(!h)return;const w=j==="source"?p:A,T=j==="source"?e.target:e.source;(ee=a.workerRef.current)==null||ee.postMessage({type:"connecting",data:{from:{x:w.x,y:w.y},to:{x:w.x,y:w.y}}});const I=h.getBoundingClientRect(),Y=V=>{var fe;const F=a.cameraRef.current,te=(V.clientX-I.left-F.x)/F.zoom,oe=(V.clientY-I.top-F.y)/F.zoom;(fe=a.workerRef.current)==null||fe.postMessage({type:"connecting",data:{from:{x:w.x,y:w.y},to:{x:te,y:oe}}})},J=V=>{var de,Le,Se,we;const F=a.cameraRef.current,te=(V.clientX-I.left-F.x)/F.zoom,oe=(V.clientY-I.top-F.y)/F.zoom,fe=20/F.zoom;let ge=null,Te=null;const ce=(de=a.handleRegistryRef)==null?void 0:de.current;for(const he of a.nodesRef.current){if(he.hidden)continue;const le=he.width||cr,Me=he.height||ur,pe=he._absolutePosition||he.position,Je=[];if(ce)for(const[,$e]of ce)$e.nodeId===he.id&&Je.push($e);const Nt=Je.length>0?Je:he.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const $e of Nt){let Qe,Ye;if($e.x!==void 0&&$e.y!==void 0)Qe=pe.x+$e.x,Ye=pe.y+$e.y;else switch($e.position||($e.type==="source"?"right":"left")){case"top":Qe=pe.x+le/2,Ye=pe.y;break;case"bottom":Qe=pe.x+le/2,Ye=pe.y+Me;break;case"left":Qe=pe.x,Ye=pe.y+Me/2;break;default:Qe=pe.x+le,Ye=pe.y+Me/2;break}if(Math.abs(te-Qe)<fe&&Math.abs(oe-Ye)<fe){ge=he,Te=$e.id||null;break}}if(ge)break}if(ge){const he=j==="source"?{source:ge.id,target:T,sourceHandle:Te,targetHandle:e.targetHandle}:{source:T,target:ge.id,sourceHandle:e.sourceHandle,targetHandle:Te};(Se=(Le=a.onEdgesChangeRef).current)==null||Se.call(Le,[{id:e.id,type:"remove"},{type:"add",item:{id:e.id,...he}}])}(we=a.workerRef.current)==null||we.postMessage({type:"connecting",data:null}),h.removeEventListener("pointermove",Y),h.removeEventListener("pointerup",J)};h.addEventListener("pointermove",Y),h.addEventListener("pointerup",J)},[e,a]),x=n.find(j=>j.id===e.source),l=n.find(j=>j.id===e.target),y=x&&!!(x.width||(_=x.measured)!=null&&_.width),b=l&&!!(l.width||(B=l.measured)!=null&&B.width),E=(L=a.handleRegistryRef)==null?void 0:L.current,R=y?Zn(x,"source",e.sourceHandle,E):null,v=b?Zn(l,"target",e.targetHandle,E):null,$=e.type==="bezier"||e.type==="simplebezier"||e.type==="default",z=a.routedEdges||a.edges,S=z==null?void 0:z.find(j=>j.id===e.id),X=$?null:(S==null?void 0:S._routedPoints)||e._routedPoints||null,H=r!==!1&&e.reconnectable!==!1;return!R||!v?null:N.jsxs("g",{className:`ric-edge-wrapper ${e.selected?"selected":""}`,"data-edgeid":e.id,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),children:[N.jsx(t,{id:e.id,source:e.source,target:e.target,sourceX:R.x,sourceY:R.y,targetX:v.x,targetY:v.y,sourcePosition:R.position,targetPosition:v.position,sourceHandleId:e.sourceHandle,targetHandleId:e.targetHandle,data:e.data,type:e.type,selected:!!e.selected,animated:!!e.animated,label:e.label,style:e.style,selectable:e.selectable!==!1,deletable:e.deletable!==!1,routedPoints:X}),H&&(o||e.selected)&&N.jsxs(N.Fragment,{children:[N.jsx(Gn,{x:R.x,y:R.y,position:R.position,type:"source",onPointerDown:j=>f("source",j,R,v)}),N.jsx(Gn,{x:v.x,y:v.y,position:v.position,type:"target",onPointerDown:j=>f("target",j,R,v)})]})]})}const Kr=c.memo(Qr);function lr({selectionKeyCode:e="Shift",selectionMode:t="partial"}){var $;const n=ve(),[r,a]=c.useState(null),o=c.useRef(null);if(c.useEffect(()=>{const z=n.wrapRef.current;if(!z)return;let S=!1,X=null,H=!1;const _=A=>{A.key===e&&(H=!0)},B=A=>{A.key===e&&(H=!1)},L=A=>{if(!H)return;const p=A.target;if(p.closest(".ric-node-wrapper")||p.closest(".ric-handle"))return;S=!0;const h=n.cameraRef.current,w=z.getBoundingClientRect(),T=(A.clientX-w.left-h.x)/h.zoom,I=(A.clientY-w.top-h.y)/h.zoom;X={x:T,y:I},a({startX:T,startY:I,endX:T,endY:I}),A.stopPropagation()},j=A=>{if(!S||!X)return;const p=n.cameraRef.current,h=z.getBoundingClientRect(),w=(A.clientX-h.left-p.x)/p.zoom,T=(A.clientY-h.top-p.y)/p.zoom;a({startX:X.x,startY:X.y,endX:w,endY:T})},W=A=>{var J,ee;if(!S||!X)return;S=!1;const p=n.cameraRef.current,h=z.getBoundingClientRect(),w=(A.clientX-h.left-p.x)/p.zoom,T=(A.clientY-h.top-p.y)/p.zoom,I={x:Math.min(X.x,w),y:Math.min(X.y,T),width:Math.abs(w-X.x),height:Math.abs(T-X.y)},Y=[];for(const V of n.nodesRef.current){const F=V._absolutePosition||V.position,te=V.width||160,oe=V.height||60;let fe;t==="full"?fe=F.x>=I.x&&F.y>=I.y&&F.x+te<=I.x+I.width&&F.y+oe<=I.y+I.height:fe=F.x+te>I.x&&F.x<I.x+I.width&&F.y+oe>I.y&&F.y<I.y+I.height,Y.push({id:V.id,type:"select",selected:fe})}Y.length&&((ee=(J=n.onNodesChangeRef).current)==null||ee.call(J,Y)),X=null,a(null)};return z.addEventListener("pointerdown",L,!0),z.addEventListener("pointermove",j),z.addEventListener("pointerup",W),window.addEventListener("keydown",_),window.addEventListener("keyup",B),()=>{z.removeEventListener("pointerdown",L,!0),z.removeEventListener("pointermove",j),z.removeEventListener("pointerup",W),window.removeEventListener("keydown",_),window.removeEventListener("keyup",B)}},[n,e,t]),!r)return null;const i=(($=n.cameraRef)==null?void 0:$.current)||{x:0,y:0,zoom:1},f=Math.min(r.startX,r.endX),x=Math.min(r.startY,r.endY),l=Math.abs(r.endX-r.startX),y=Math.abs(r.endY-r.startY),b=f*i.zoom+i.x,E=x*i.zoom+i.y,R=l*i.zoom,v=y*i.zoom;return N.jsx("div",{ref:o,className:"ric-selection-box",style:{position:"absolute",left:b,top:E,width:R,height:v,border:"1px dashed #3b82f6",background:"rgba(59, 130, 246, 0.08)",pointerEvents:"none",zIndex:100}})}lr.displayName="SelectionBox";const dr=c.memo(lr);function fr(e,t){var a,o,i,f;const n=(a=e.handleRegistryRef)==null?void 0:a.current;if(!n)return;const r={source:[],target:[]};for(const[,x]of n)if(x.nodeId===t){const l={id:x.id,type:x.type,position:x.position,x:x.x,y:x.y,width:8,height:8};x.type==="source"?r.source.push(l):r.target.push(l)}(i=(o=e.onNodesChangeRef).current)==null||i.call(o,[{id:t,type:"dimensions",handleBounds:r,setAttributes:!1}]),(f=e.syncNodesToWorker)==null||f.call(e)}const Pn=new Set;function Vn(e,t){Pn.has(t)||(Pn.add(t),queueMicrotask(()=>{Pn.delete(t),fr(e,t)}))}function eo(e,t){const n=e.closest(".ric-node-wrapper");if(!n)return null;const r=n.getBoundingClientRect(),a=e.getBoundingClientRect(),o=t||1;return{x:(a.left+a.width/2-r.left)/o,y:(a.top+a.height/2-r.top)/o}}function Ut({type:e="source",position:t=e==="source"?"right":"left",id:n,isConnectable:r=!0,isConnectableStart:a=!0,isConnectableEnd:o=!0,children:i,className:f="",style:x={},onConnect:l,...y}){const b=c.useContext(qt),E=ve(),R=c.useRef(null),v=c.useRef(E);v.current=E;const $=c.useCallback(()=>{var A,p,h;const H=R.current;if(!H||!b)return;const _=v.current,B=(A=_.handleRegistryRef)==null?void 0:A.current;if(!B)return;const L=`${b}__${n||e}`,j=(h=(p=_.cameraRef)==null?void 0:p.current)==null?void 0:h.zoom,W=eo(H,j);if(W){const w={nodeId:b,id:n||null,type:e,position:t,x:W.x,y:W.y};B.set(L,w)}},[b,n,e,t]);c.useLayoutEffect(()=>{$()},[$]),c.useEffect(()=>{if(!b)return;const H=v.current;Vn(H,b);const _=R.current,B=_==null?void 0:_.closest(".ric-node-wrapper"),L=new ResizeObserver(()=>{$(),Vn(v.current,b)});return B&&L.observe(B),()=>{var p;L.disconnect();const j=v.current,W=(p=j.handleRegistryRef)==null?void 0:p.current,A=`${b}__${n||e}`;W==null||W.delete(A),fr(j,b)}},[b,n,e,t,$]);const z=c.useCallback(()=>{var h;const H=v.current,_=H.nodesRef.current.find(w=>w.id===b);if(!_)return null;const B=_._absolutePosition||_.position,L=(h=H.handleRegistryRef)==null?void 0:h.current,j=`${b}__${n||e}`,W=L==null?void 0:L.get(j);if(W&&W.x!==void 0&&W.y!==void 0)return{x:B.x+W.x,y:B.y+W.y};const A=_.width||160,p=_.height||60;switch(t){case"top":return{x:B.x+A/2,y:B.y};case"bottom":return{x:B.x+A/2,y:B.y+p};case"left":return{x:B.x,y:B.y+p/2};default:return{x:B.x+A,y:B.y+p/2}}},[b,n,e,t]),S=c.useCallback(H=>{var T;if(!r||!a)return;H.stopPropagation(),H.preventDefault();const _=v.current,B=_.cameraRef.current,L=_.wrapRef.current;if(!L)return;const j=L.getBoundingClientRect(),W=z();if(!W)return;const A=W.x,p=W.y;(T=_.workerRef.current)==null||T.postMessage({type:"connecting",data:{from:{x:A,y:p},to:{x:A,y:p}}}),L.setPointerCapture(H.pointerId);const h=I=>{var ee;const Y=(I.clientX-j.left-B.x)/B.zoom,J=(I.clientY-j.top-B.y)/B.zoom;(ee=_.workerRef.current)==null||ee.postMessage({type:"connecting",data:{from:{x:A,y:p},to:{x:Y,y:J}}})},w=I=>{var oe,fe,ge,Te;const Y=(I.clientX-j.left-B.x)/B.zoom,J=(I.clientY-j.top-B.y)/B.zoom,ee=20/B.zoom;let V=null,F=null;const te=(oe=_.handleRegistryRef)==null?void 0:oe.current;for(const ce of _.nodesRef.current){if(ce.id===b||ce.hidden)continue;const de=ce.width||160,Le=ce.height||60,Se=ce._absolutePosition||ce.position,we=[];if(te)for(const[,le]of te)le.nodeId===ce.id&&we.push(le);const he=we.length>0?we:ce.handles||[{type:"target",position:"left"},{type:"source",position:"right"}];for(const le of he){let Me,pe;if(le.x!==void 0&&le.y!==void 0)Me=Se.x+le.x,pe=Se.y+le.y;else switch(le.position||(le.type==="source"?"right":"left")){case"top":Me=Se.x+de/2,pe=Se.y;break;case"bottom":Me=Se.x+de/2,pe=Se.y+Le;break;case"left":Me=Se.x,pe=Se.y+Le/2;break;default:Me=Se.x+de,pe=Se.y+Le/2;break}if(Math.abs(Y-Me)<ee&&Math.abs(J-pe)<ee){V=ce,F=le.id||null;break}}if(V)break}if(V){const ce={source:e==="source"?b:V.id,target:e==="source"?V.id:b,sourceHandle:e==="source"?n||null:F,targetHandle:e==="source"?F:n||null};(ge=(fe=_.onEdgesChangeRef)==null?void 0:fe.current)==null||ge.call(fe,[{type:"add",item:{id:`e-${ce.source}-${ce.target}`,...ce}}])}(Te=_.workerRef.current)==null||Te.postMessage({type:"connecting",data:null}),L.removeEventListener("pointermove",h),L.removeEventListener("pointerup",w)};L.addEventListener("pointermove",h),L.addEventListener("pointerup",w)},[b,n,e,t,r,a,z]),X={top:{top:0,left:"50%",transform:"translate(-50%, -50%)"},bottom:{bottom:0,left:"50%",transform:"translate(-50%, 50%)"},left:{top:"50%",left:0,transform:"translate(-50%, -50%)"},right:{top:"50%",right:0,transform:"translate(50%, -50%)"}}[t]||{};return N.jsx("div",{ref:R,className:`ric-handle ric-handle-${t} ric-handle-${e} ${f}`,"data-handleid":n||null,"data-nodeid":b,"data-handlepos":t,"data-handletype":e,onPointerDown:S,style:{position:"absolute",width:8,height:8,borderRadius:"50%",background:"#1a192b",border:"none",zIndex:10,cursor:r?"crosshair":"default",boxSizing:"border-box",...X,...x},...y,children:i})}function to({data:e,isConnectable:t,selected:n,targetPosition:r="left",sourcePosition:a="right",hideSourceHandle:o=!1,hideTargetHandle:i=!1}){return N.jsxs("div",{className:`ric-default-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!i&&N.jsx(Ut,{type:"target",position:r,isConnectable:t}),N.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!o&&N.jsx(Ut,{type:"source",position:a,isConnectable:t})]})}function hr({data:e,isConnectable:t,selected:n,sourcePosition:r="right",hideSourceHandle:a=!1}){return N.jsxs("div",{className:`ric-input-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderBottom:"2px solid #0041d0",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[N.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label}),!a&&N.jsx(Ut,{type:"source",position:r,isConnectable:t})]})}function yr({data:e,isConnectable:t,selected:n,targetPosition:r="left",hideTargetHandle:a=!1}){return N.jsxs("div",{className:`ric-output-node${n?" selected":""}`,style:{background:"#fff",border:"1px solid #1a192b",borderTop:"2px solid #ff0072",borderRadius:3,padding:"10px",minWidth:150,fontSize:12,fontFamily:"inherit",boxShadow:n?"0 0 0 0.5px #1a192b":"none"},children:[!a&&N.jsx(Ut,{type:"target",position:r,isConnectable:t}),N.jsx("div",{className:"ric-node-content",children:e==null?void 0:e.label})]})}function gr({data:e,selected:t,width:n,height:r}){return N.jsx("div",{className:`ric-group-node${t?" selected":""}`,style:{width:n||300,height:r||200,background:"rgba(240, 240, 240, 0.25)",border:t?"2px solid #3b82f6":"1px dashed #ccc",borderRadius:8,padding:8,boxSizing:"border-box"},children:(e==null?void 0:e.label)&&N.jsx("div",{style:{fontSize:11,fontWeight:600,color:"#888",userSelect:"none"},children:e.label})})}function xr({x:e,y:t,label:n,labelStyle:r,labelShowBg:a=!0,labelBgStyle:o,labelBgPadding:i=[2,4],labelBgBorderRadius:f=2,children:x,className:l="",...y}){const[b,E]=c.useState({x:1,y:0,width:0,height:0}),R=c.useRef(null);return c.useEffect(()=>{if(R.current){const v=R.current.getBBox();E({x:v.x,y:v.y,width:v.width,height:v.height})}},[n]),n?N.jsxs("g",{transform:`translate(${e-b.width/2} ${t-b.height/2})`,className:`ric-edge-textwrapper ${l}`,visibility:b.width?"visible":"hidden",...y,children:[a&&N.jsx("rect",{width:b.width+2*i[0],x:-i[0],y:-i[1],height:b.height+2*i[1],className:"ric-edge-textbg",style:o,rx:f,ry:f}),N.jsx("text",{className:"ric-edge-text",y:b.height/2,dy:"0.3em",ref:R,style:r,children:n}),x]}):null}xr.displayName="EdgeText";const pr=c.memo(xr);function Jn(e){return e!=null&&e!==""&&!isNaN(Number(e))}function Ot({id:e,path:t,labelX:n,labelY:r,label:a,labelStyle:o,labelShowBg:i,labelBgStyle:f,labelBgPadding:x,labelBgBorderRadius:l,interactionWidth:y=20,style:b,markerEnd:E,markerStart:R,className:v="",...$}){return N.jsxs(N.Fragment,{children:[N.jsx("path",{id:e,d:t,fill:"none",stroke:"#b1b1b7",strokeWidth:1.5,className:`ric-edge-path ${v}`,style:b,markerEnd:E,markerStart:R,...$}),y?N.jsx("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:y,className:"ric-edge-interaction",style:{pointerEvents:"stroke"}}):null,a&&Jn(n)&&Jn(r)?N.jsx(pr,{x:n,y:r,label:a,labelStyle:o,labelShowBg:i,labelBgStyle:f,labelBgPadding:x,labelBgBorderRadius:l}):null]})}const Wt=20;function Qn(e,t,n){switch(n){case"right":return{x:e+Wt,y:t};case"left":return{x:e-Wt,y:t};case"bottom":return{x:e,y:t+Wt};case"top":return{x:e,y:t-Wt};default:return{x:e+Wt,y:t}}}const An=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:i="bottom",targetPosition:f="top",label:x,labelStyle:l,labelShowBg:y,labelBgStyle:b,labelBgPadding:E,labelBgBorderRadius:R,style:v,markerEnd:$,markerStart:z,interactionWidth:S}){let X,H,_;const B=Qn(n,r,i),L=Qn(a,o,f),j=Math.abs(L.x-B.x),W=Math.max(50,j*.5);let A,p,h,w;switch(i){case"left":A=B.x-W,p=B.y;break;case"top":A=B.x,p=B.y-W;break;case"bottom":A=B.x,p=B.y+W;break;default:A=B.x+W,p=B.y;break}switch(f){case"right":h=L.x+W,w=L.y;break;case"top":h=L.x,w=L.y-W;break;case"bottom":h=L.x,w=L.y+W;break;default:h=L.x-W,w=L.y;break}X=`M ${n},${r} L ${B.x},${B.y} C ${A},${p} ${h},${w} ${L.x},${L.y} L ${a},${o}`;const T=.5,I=.5;return H=I*I*I*B.x+3*I*I*T*A+3*I*T*T*h+T*T*T*L.x,_=I*I*I*B.y+3*I*I*T*p+3*I*T*T*w+T*T*T*L.y,N.jsx(Ot,{id:t,path:X,labelX:H,labelY:_,label:x,labelStyle:l,labelShowBg:y,labelBgStyle:b,labelBgPadding:E,labelBgBorderRadius:R,style:v,markerEnd:$,markerStart:z,interactionWidth:S})});An.displayName="BezierEdge";function Dn({sourceX:e,sourceY:t,targetX:n,targetY:r}){const a=`M ${e},${t}L ${n},${r}`,o=(e+n)/2,i=(t+r)/2;return[a,o,i,0,0]}function Hn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a="right",targetPosition:o="left",curvature:i=.25}){const f=Math.abs(n-e),x=Math.abs(r-t),l=Math.sqrt(f*f+x*x),y=Math.max(l*i,50);let b,E,R,v;switch(a){case"top":b=e,E=t-y;break;case"bottom":b=e,E=t+y;break;case"left":b=e-y,E=t;break;default:b=e+y,E=t;break}switch(o){case"top":R=n,v=r-y;break;case"bottom":R=n,v=r+y;break;case"right":R=n+y,v=r;break;default:R=n-y,v=r;break}const $=`M ${e},${t} C ${b},${E} ${R},${v} ${n},${r}`,z=.5,S=1-z,X=S*S*S*e+3*S*S*z*b+3*S*z*z*R+z*z*z*n,H=S*S*S*t+3*S*S*z*E+3*S*z*z*v+z*z*z*r;return[$,X,H,0,0]}function _n({sourceX:e,sourceY:t,targetX:n,targetY:r}){const a=Math.abs(n-e),o=Math.max(a*.5,50),i=e+o,f=n-o,x=`M ${e},${t} C ${i},${t} ${f},${r} ${n},${r}`,l=.5,y=.5,b=y*y*y*e+3*y*y*l*i+3*y*l*l*f+l*l*l*n,E=y*y*y*t+3*y*y*l*t+3*y*l*l*r+l*l*l*r;return[x,b,E,0,0]}function dn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a="right",targetPosition:o="left",borderRadius:i=5,offset:f=20}){const x=a==="left"||a==="right",l=Math.min(i,Math.abs(n-e)/2,Math.abs(r-t)/2);if(x){if(Math.abs(r-t)<1)return[`M ${e},${t} L ${n},${r}`,(e+n)/2,t,0,0];const R=(e+n)/2,v=r>t?1:-1;return[`M ${e},${t} L ${R-l},${t} Q ${R},${t} ${R},${t+v*l} L ${R},${r-v*l} Q ${R},${r} ${R+(n>R?l:-l)},${r} L ${n},${r}`,R,(t+r)/2,0,0]}const y=(t+r)/2,b=n>e?1:-1;return[`M ${e},${t} L ${e},${y-l} Q ${e},${y} ${e+b*l},${y} L ${n-b*l},${y} Q ${n},${y} ${n},${y+(r>y?l:-l)} L ${n},${r}`,(e+n)/2,y,0,0]}function no({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[,a,o]=Hn({sourceX:e,sourceY:t,targetX:n,targetY:r});return[a,o,0,0]}function ro({sourceX:e,sourceY:t,targetX:n,targetY:r}){return[(e+n)/2,(t+r)/2,0,0]}function oo(e,t,n){const r=n.filter(o=>o.id!==e.id),a={...e,id:e.id,source:t.source,target:t.target,sourceHandle:t.sourceHandle??e.sourceHandle,targetHandle:t.targetHandle??e.targetHandle};return r.push(a),r}const fn=160,hn=60,Ft=20,un=12,yn=20;function Kn(e,t,n){var i,f;const r=e.width||((i=e.measured)==null?void 0:i.width)||fn,a=e.height||((f=e.measured)==null?void 0:f.height)||hn,o=e._absolutePosition||e.position;if(e.handles&&e.handles.length>0){for(const x of e.handles)if(x.type===t&&(!n||x.id===n)){if(x.x!==void 0&&x.y!==void 0)return{x:o.x+x.x,y:o.y+x.y,dir:x.position||(t==="source"?"right":"left")};switch(x.position||(t==="source"?"right":"left")){case"top":return{x:o.x+r/2,y:o.y,dir:"top"};case"bottom":return{x:o.x+r/2,y:o.y+a,dir:"bottom"};case"left":return{x:o.x,y:o.y+a/2,dir:"left"};default:return{x:o.x+r,y:o.y+a/2,dir:"right"}}}}return t==="source"?{x:o.x+r,y:o.y+a/2,dir:"right"}:{x:o.x,y:o.y+a/2,dir:"left"}}function gn(e,t){switch(e.dir){case"right":return{x:e.x+t,y:e.y,dir:e.dir};case"left":return{x:e.x-t,y:e.y,dir:e.dir};case"bottom":return{x:e.x,y:e.y+t,dir:e.dir};case"top":return{x:e.x,y:e.y-t,dir:e.dir};default:return{x:e.x+t,y:e.y,dir:e.dir}}}function so(e,t,n,r,a,o,i,f){const x=Math.min(e,n),l=Math.max(e,n),y=Math.min(t,r),b=Math.max(t,r);if(l<=a||x>=a+i||b<=o||y>=o+f)return!1;const E=.5;if(e>a+E&&e<a+i-E&&t>o+E&&t<o+f-E||n>a+E&&n<a+i-E&&r>o+E&&r<o+f-E)return!0;const R=(e+n)/2,v=(t+r)/2;if(R>a+E&&R<a+i-E&&v>o+E&&v<o+f-E)return!0;const $=[[a,o],[a+i,o],[a+i,o+f],[a,o+f]];for(let z=0;z<4;z++)if(ao(e,t,n,r,$[z][0],$[z][1],$[(z+1)%4][0],$[(z+1)%4][1]))return!0;return!1}function ao(e,t,n,r,a,o,i,f){const x=(i-a)*(t-o)-(f-o)*(e-a),l=(i-a)*(r-o)-(f-o)*(n-a),y=(n-e)*(o-t)-(r-t)*(a-e),b=(n-e)*(f-t)-(r-t)*(i-e);return(x>0&&l<0||x<0&&l>0)&&(y>0&&b<0||y<0&&b>0)}function Bn(e,t,n,r,a){for(let o=0;o<a.length;o++){const i=a[o];if(so(e,t,n,r,i.x,i.y,i.w,i.h))return!1}return!0}function io(e,t,n){for(let r=0;r<n.length;r++){const a=n[r];if(e>a.x&&e<a.x+a.w&&t>a.y&&t<a.y+a.h)return!0}return!1}function Wn(e,t){var r,a;const n=[];for(let o=0;o<e.length;o++){const i=e[o];if(i.hidden||t&&t.has(i.id)||i.type==="group")continue;const f=i._absolutePosition||i.position,x=i.width||((r=i.measured)==null?void 0:r.width)||fn,l=i.height||((a=i.measured)==null?void 0:a.height)||hn;n.push({id:i.id,x:f.x-Ft,y:f.y-Ft,w:x+2*Ft,h:l+2*Ft})}return n}function mr(e,t,n){if(Bn(e.x,e.y,t.x,t.y,n))return null;const r=new Set,a=new Set;r.add(e.x),r.add(t.x),a.add(e.y),a.add(t.y);const o=Ft+5;e.dir==="right"?r.add(e.x+o):e.dir==="left"?r.add(e.x-o):e.dir==="top"?a.add(e.y-o):e.dir==="bottom"&&a.add(e.y+o),t.dir==="right"?r.add(t.x+o):t.dir==="left"?r.add(t.x-o):t.dir==="top"?a.add(t.y-o):t.dir==="bottom"&&a.add(t.y+o);for(let h=0;h<n.length;h++){const w=n[h];r.add(w.x),r.add(w.x+w.w),a.add(w.y),a.add(w.y+w.h)}const i=[...r].sort((h,w)=>h-w),f=[...a].sort((h,w)=>h-w),x=new Map,l=new Map;for(let h=0;h<i.length;h++)x.set(i[h],h);for(let h=0;h<f.length;h++)l.set(f[h],h);const y=i.length,b=f.length,E=(h,w)=>w*y+h,R=x.get(e.x),v=l.get(e.y),$=x.get(t.x),z=l.get(t.y);if(R===void 0||v===void 0||$===void 0||z===void 0)return null;const S=E(R,v),X=E($,z),H=new Float64Array(y*b).fill(1/0),_=new Float64Array(y*b).fill(1/0),B=new Int32Array(y*b).fill(-1),L=new Int8Array(y*b).fill(-1),j=new Uint8Array(y*b);H[S]=0,_[S]=Math.abs(i[$]-e.x)+Math.abs(f[z]-e.y);const W=[S],A=15,p=[[1,0],[-1,0],[0,1],[0,-1]];for(;W.length>0;){let h=0;for(let V=1;V<W.length;V++)_[W[V]]<_[W[h]]&&(h=V);const w=W[h];if(W[h]=W[W.length-1],W.pop(),w===X){const V=[];let F=X;for(;F!==-1&&F!==S;){const te=F/y|0,oe=F%y;V.unshift({x:i[oe],y:f[te]}),F=B[F]}return V.unshift({x:e.x,y:e.y}),co(V,n)}if(j[w])continue;j[w]=1;const T=w/y|0,I=w%y,Y=i[I],J=f[T],ee=L[w];for(let V=0;V<4;V++){const F=I+p[V][0],te=T+p[V][1];if(F<0||F>=y||te<0||te>=b)continue;const oe=E(F,te);if(j[oe])continue;const fe=i[F],ge=f[te];if(io(fe,ge,n)||!Bn(Y,J,fe,ge,n))continue;const Te=Math.abs(fe-Y)+Math.abs(ge-J),ce=ee>=0&&ee!==V?A:0,de=H[w]+Te+ce;de<H[oe]&&(B[oe]=w,L[oe]=V,H[oe]=de,_[oe]=de+Math.abs(i[$]-fe)+Math.abs(f[z]-ge),W.push(oe))}}return null}function co(e,t){if(!e||e.length<=2)return e;const n=[e[0]];for(let r=1;r<e.length-1;r++){const a=n[n.length-1],o=e[r],i=e[r+1],f=Math.abs(a.x-o.x)<.5&&Math.abs(o.x-i.x)<.5,x=Math.abs(a.y-o.y)<.5&&Math.abs(o.y-i.y)<.5;(f||x)&&Bn(a.x,a.y,i.x,i.y,t)||n.push(o)}return n.push(e[e.length-1]),n}function uo(e){const t=new Map,n=new Map;for(const a of e){const o=a._routedPoints;if(!(!o||o.length<2))for(let i=0;i<o.length-1;i++){const f=o[i],x=o[i+1];if(Math.abs(f.y-x.y)<.5){const l=Math.round(f.y*10)/10;t.has(l)||t.set(l,[]),t.get(l).push({edgeId:a.id,segIdx:i,x1:Math.min(f.x,x.x),x2:Math.max(f.x,x.x)})}else if(Math.abs(f.x-x.x)<.5){const l=Math.round(f.x*10)/10;n.has(l)||n.set(l,[]),n.get(l).push({edgeId:a.id,segIdx:i,y1:Math.min(f.y,x.y),y2:Math.max(f.y,x.y)})}}}const r=new Map;for(const a of e)a._routedPoints&&r.set(a.id,a._routedPoints.map(o=>({...o})));for(const[,a]of t){if(a.length<2)continue;const o=er(a,"x1","x2");for(const i of o){if(i.length<2)continue;const f=(i.length-1)*un/2;for(let x=0;x<i.length;x++){const l=i[x],y=-f+x*un,b=r.get(l.edgeId);b&&(b[l.segIdx].y+=y,b[l.segIdx+1].y+=y)}}}for(const[,a]of n){if(a.length<2)continue;const o=er(a,"y1","y2");for(const i of o){if(i.length<2)continue;const f=(i.length-1)*un/2;for(let x=0;x<i.length;x++){const l=i[x],y=-f+x*un,b=r.get(l.edgeId);b&&(b[l.segIdx].x+=y,b[l.segIdx+1].x+=y)}}}return e.map(a=>{const o=r.get(a.id);return o?{...a,_routedPoints:o}:a})}function er(e,t,n){if(e.length<2)return[];const r=[...e].sort((i,f)=>i[t]-f[t]),a=[];let o=[r[0]];for(let i=1;i<r.length;i++){const f=o[o.length-1];r[i][t]<f[n]?o.push(r[i]):(o.length>1&&a.push(o),o=[r[i]])}return o.length>1&&a.push(o),a}function xn(e,t=6,n=!1){if(!e||e.length<2)return null;if(n)return lo(e);const r=t;let a=`M ${e[0].x},${e[0].y}`;for(let o=1;o<e.length-1;o++){const i=e[o-1],f=e[o],x=e[o+1],l=Math.abs(f.x-i.x)+Math.abs(f.y-i.y),y=Math.abs(x.x-f.x)+Math.abs(x.y-f.y),b=Math.min(r,l/2,y/2);if(b>.5){const E=f.x-i.x,R=f.y-i.y,v=x.x-f.x,$=x.y-f.y,z=Math.sqrt(E*E+R*R)||1,S=Math.sqrt(v*v+$*$)||1;a+=` L ${f.x-E/z*b},${f.y-R/z*b}`,a+=` Q ${f.x},${f.y} ${f.x+v/S*b},${f.y+$/S*b}`}else a+=` L ${f.x},${f.y}`}return a+=` L ${e[e.length-1].x},${e[e.length-1].y}`,a}function lo(e){if(e.length===2)return`M ${e[0].x},${e[0].y} L ${e[1].x},${e[1].y}`;if(e.length===3)return`M ${e[0].x},${e[0].y} Q ${e[1].x},${e[1].y} ${e[2].x},${e[2].y}`;const t=.3;let n=`M ${e[0].x},${e[0].y}`;for(let r=0;r<e.length-1;r++){const a=e[r===0?0:r-1],o=e[r],i=e[r+1],f=e[r+2<e.length?r+2:e.length-1],x=o.x+(i.x-a.x)*t,l=o.y+(i.y-a.y)*t,y=i.x-(f.x-o.x)*t,b=i.y-(f.y-o.y)*t;n+=` C ${x},${l} ${y},${b} ${i.x},${i.y}`}return n}function pn(e){if(!e||e.length<2)return{x:0,y:0};let t=0;for(let r=1;r<e.length;r++)t+=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);let n=t/2;for(let r=1;r<e.length;r++){const a=Math.abs(e[r].x-e[r-1].x)+Math.abs(e[r].y-e[r-1].y);if(n<=a){const o=a>0?n/a:0;return{x:e[r-1].x+(e[r].x-e[r-1].x)*o,y:e[r-1].y+(e[r].y-e[r-1].y)*o}}n-=a}return{x:e[0].x,y:e[0].y}}function fo(e,t){if(!e||!t||e.length===0||t.length===0)return t;const n={};for(const o of e)n[o.id]=o;const r=Wn(e,null),a=t.map(o=>{var L,j,W,A;const i=o.type||"default";if(i==="bezier"||i==="simplebezier"||i==="default")return o;const f=n[o.source],x=n[o.target];if(!f||!x||f.hidden||x.hidden)return o;const l=Kn(f,"source",o.sourceHandle),y=Kn(x,"target",o.targetHandle),b=gn(l,yn),E=gn(y,yn),R=5,v=r.filter(p=>p.id!==o.source&&p.id!==o.target),$=f._absolutePosition||f.position,z=f.width||((L=f.measured)==null?void 0:L.width)||fn,S=f.height||((j=f.measured)==null?void 0:j.height)||hn;v.push({id:o.source,x:$.x-R,y:$.y-R,w:z+2*R,h:S+2*R});const X=x._absolutePosition||x.position,H=x.width||((W=x.measured)==null?void 0:W.width)||fn,_=x.height||((A=x.measured)==null?void 0:A.height)||hn;if(v.push({id:o.target,x:X.x-R,y:X.y-R,w:H+2*R,h:_+2*R}),v.length===0)return o;const B=mr(b,E,v);return B&&B.length>=2?(B.unshift({x:l.x,y:l.y}),B.push({x:y.x,y:y.y}),{...o,_routedPoints:B}):o});return uo(a)}function ho(e,t,n,r,a,o,i,f){const x=Wn(i,f?new Set(f):null);if(x.length===0)return null;const l={x:e,y:t,dir:a||"right"},y={x:n,y:r,dir:o||"left"},b=gn(l,yn),E=gn(y,yn),R=mr(b,E,x);return R&&R.length>=2?(R.unshift({x:l.x,y:l.y}),R.push({x:y.x,y:y.y}),R):null}const Fn=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,label:i,labelStyle:f,labelShowBg:x,labelBgStyle:l,labelBgPadding:y,labelBgBorderRadius:b,style:E,markerEnd:R,markerStart:v,interactionWidth:$,routedPoints:z}){let S,X,H;if(z&&z.length>=2){S=xn(z);const _=pn(z);X=_.x,H=_.y}else[S,X,H]=Dn({sourceX:n,sourceY:r,targetX:a,targetY:o});return N.jsx(Ot,{id:t,path:S,labelX:X,labelY:H,label:i,labelStyle:f,labelShowBg:x,labelBgStyle:l,labelBgPadding:y,labelBgBorderRadius:b,style:E,markerEnd:R,markerStart:v,interactionWidth:$})});Fn.displayName="StraightEdge";const Xn=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:i="bottom",targetPosition:f="top",label:x,labelStyle:l,labelShowBg:y,labelBgStyle:b,labelBgPadding:E,labelBgBorderRadius:R,style:v,markerEnd:$,markerStart:z,pathOptions:S,interactionWidth:X,routedPoints:H}){let _,B,L;if(H&&H.length>=2){_=xn(H);const j=pn(H);B=j.x,L=j.y}else[_,B,L]=dn({sourceX:n,sourceY:r,sourcePosition:i,targetX:a,targetY:o,targetPosition:f,borderRadius:S==null?void 0:S.borderRadius,offset:S==null?void 0:S.offset});return N.jsx(Ot,{id:t,path:_,labelX:B,labelY:L,label:x,labelStyle:l,labelShowBg:y,labelBgStyle:b,labelBgPadding:E,labelBgBorderRadius:R,style:v,markerEnd:$,markerStart:z,interactionWidth:X})});Xn.displayName="SmoothStepEdge";const vr=c.memo(function({id:t,...n}){var a;const r=c.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(a=n.pathOptions)==null?void 0:a.offset]);return N.jsx(Xn,{...n,id:t,pathOptions:r})});vr.displayName="StepEdge";const Yn=c.memo(function({id:t,sourceX:n,sourceY:r,targetX:a,targetY:o,sourcePosition:i,targetPosition:f,label:x,labelStyle:l,labelShowBg:y,labelBgStyle:b,labelBgPadding:E,labelBgBorderRadius:R,style:v,markerEnd:$,markerStart:z,interactionWidth:S,routedPoints:X}){let H,_,B;if(X&&X.length>=2){H=xn(X);const L=pn(X);_=L.x,B=L.y}else[H,_,B]=_n({sourceX:n,sourceY:r,targetX:a,targetY:o});return N.jsx(Ot,{id:t,path:H,labelX:_,labelY:B,label:x,labelStyle:l,labelShowBg:y,labelBgStyle:b,labelBgPadding:E,labelBgBorderRadius:R,style:v,markerEnd:$,markerStart:z,interactionWidth:S})});Yn.displayName="SimpleBezierEdge";const yo={input:hr,output:yr,group:gr},go={bezier:An,straight:Fn,simplebezier:Yn},xo=160,po=60;function mo(e){let t=!1;for(let n=0;n<e.length;n++){const r=e[n];if(!r.measured||r.measured.width==null||r.measured.height==null){t=!0;break}}return t?e.map(n=>{var r,a;return((r=n.measured)==null?void 0:r.width)!=null&&((a=n.measured)==null?void 0:a.height)!=null?n:{...n,measured:{width:n.width||xo,height:n.height||po}}}):e}function vo({cards:e,nodes:t=[],edges:n=[],nodeTypes:r,edgeTypes:a,dark:o,gridSize:i,width:f="100%",height:x="420px",className:l="",style:y={},zoomMin:b,zoomMax:E,initialCamera:R,fitView:v,fitViewOptions:$,onNodesChange:z,onEdgesChange:S,onConnect:X,onConnectStart:H,onConnectEnd:_,onNodeClick:B,onNodeDoubleClick:L,onNodeMouseEnter:j,onNodeMouseMove:W,onNodeMouseLeave:A,onNodeContextMenu:p,onNodeDragStart:h,onNodeDrag:w,onNodeDragStop:T,onEdgeClick:I,onEdgeDoubleClick:Y,onEdgeMouseEnter:J,onEdgeMouseMove:ee,onEdgeMouseLeave:V,onEdgeContextMenu:F,onPaneClick:te,onPaneContextMenu:oe,onPaneMouseEnter:fe,onPaneMouseMove:ge,onPaneMouseLeave:Te,onSelectionChange:ce,onInit:de,onMoveStart:Le,onMove:Se,onMoveEnd:we,onDelete:he,onBeforeDelete:le,onError:Me,onDragOver:pe,onDrop:Je,onDragEnter:Nt,onDragLeave:$e,nodesDraggable:Qe,nodesConnectable:Ye,elementsSelectable:mt,multiSelectionKeyCode:gt,selectionOnDrag:vt,selectionMode:bt,connectionMode:Zt,connectionRadius:St,connectOnClick:Gt,isValidConnection:Vt,defaultEdgeOptions:Jt,snapToGrid:Qt,snapGrid:Pt,deleteKeyCode:it,panActivationKeyCode:ct,panOnScroll:wt,panOnScrollMode:mn,panOnScrollSpeed:vn,zoomOnScroll:Ke,zoomOnDoubleClick:Un,zoomOnPinch:bn,preventScrolling:xt,translateExtent:xe,nodeExtent:It,autoPanOnNodeDrag:Ie,autoPanOnConnect:se,autoPanSpeed:ut,edgesReconnectable:K,elevateNodesOnSelect:Pe,elevateEdgesOnSelect:wn,edgeRouting:Mt=!0,onHudUpdate:rt,onNodesProcessed:Mn,showHud:Rn=!0,showHint:De=!0,hintText:He="Drag to pan · Scroll to zoom",children:Rt,...ot}){const[Ue,kt]=c.useState({wx:0,wy:0,zoom:"1.00"}),Tt=c.useRef(null),Kt=c.useRef(null),en=c.useCallback(Z=>{kt(Z),rt==null||rt(Z)},[rt]),lt=c.useMemo(()=>({...yo,...r}),[r]),et=c.useMemo(()=>({...go,...a}),[a]),st=c.useMemo(()=>mo(t),[t]),qe=c.useMemo(()=>{const Z=t.filter(ke=>ke.type&&lt[ke.type]);return Z.sort((ke,Ce)=>{const ue=ke.type==="group"||!ke.parentId&&Z.some(je=>je.parentId===ke.id),_e=Ce.type==="group"||!Ce.parentId&&Z.some(je=>je.parentId===Ce.id);return ue&&!_e?-1:!ue&&_e?1:0})},[t,lt]),Q=c.useMemo(()=>n.filter(Z=>Z.type&&et[Z.type]),[n,et]),Re=c.useMemo(()=>t.map(Z=>Z.type&&lt[Z.type]?{...Z,_customRendered:!0}:Z),[t,lt]),Be=c.useMemo(()=>n.map(Z=>Z.type&&et[Z.type]?{...Z,_customRendered:!0}:Z),[n,et]),{wrapRef:dt,canvasRef:Lt,canvasReady:$t,onPointerDown:Bt,onPointerMove:jt,onPointerUp:At,store:me}=ar({cards:e,nodes:Re,edges:Be,dark:o,gridSize:i,zoomMin:b,zoomMax:E,initialCamera:R,fitView:v,fitViewOptions:$,onHudUpdate:en,onNodesProcessed:Mn,onNodesChange:z,onEdgesChange:S,onConnect:X,onConnectStart:H,onConnectEnd:_,onNodeClick:B,onNodeDoubleClick:L,onNodeMouseEnter:j,onNodeMouseMove:W,onNodeMouseLeave:A,onNodeContextMenu:p,onNodeDragStart:h,onNodeDrag:w,onNodeDragStop:T,onEdgeClick:I,onEdgeDoubleClick:Y,onEdgeMouseEnter:J,onEdgeMouseMove:ee,onEdgeMouseLeave:V,onEdgeContextMenu:F,onPaneClick:te,onPaneContextMenu:oe,onPaneMouseEnter:fe,onPaneMouseMove:ge,onPaneMouseLeave:Te,onSelectionChange:ce,onInit:de,onMoveStart:Le,onMove:Se,onMoveEnd:we,onDelete:he,onBeforeDelete:le,onError:Me,nodesDraggable:Qe,nodesConnectable:Ye,elementsSelectable:mt,multiSelectionKeyCode:gt,selectionOnDrag:vt,selectionMode:bt,connectionMode:Zt,connectionRadius:St,connectOnClick:Gt,isValidConnection:Vt,defaultEdgeOptions:Jt,snapToGrid:Qt,snapGrid:Pt,deleteKeyCode:it,panActivationKeyCode:ct,panOnScroll:wt,panOnScrollMode:mn,panOnScrollSpeed:vn,zoomOnScroll:Ke,zoomOnDoubleClick:Un,zoomOnPinch:bn,preventScrolling:xt,translateExtent:xe,nodeExtent:It,autoPanOnNodeDrag:Ie,autoPanOnConnect:se,autoPanSpeed:ut,edgesReconnectable:K,elevateNodesOnSelect:Pe,edgeRouting:Mt}),ft=c.useContext(Yt),Ct=ft&&typeof ft.getState=="function";c.useEffect(()=>{Ct&&queueMicrotask(()=>{ft.setState({nodes:st,edges:n,nodesRef:me.nodesRef,edgesRef:me.edgesRef,onNodesChangeRef:me.onNodesChangeRef,onEdgesChangeRef:me.onEdgesChangeRef,cameraRef:me.cameraRef,wrapRef:me.wrapRef,workerRef:me.workerRef})})},[Ct,st,n,me,ft]);const Dt=c.useMemo(()=>({...me,edgeLabelContainerRef:Tt,viewportPortalRef:Kt,get nodes(){return st},get edges(){return n},get viewport(){return me.cameraRef.current},get minZoom(){return me.zoomMin||.1},get maxZoom(){return me.zoomMax||5},get domNode(){return me.wrapRef.current},get width(){var Z;return((Z=me.wrapRef.current)==null?void 0:Z.clientWidth)||0},get height(){var Z;return((Z=me.wrapRef.current)==null?void 0:Z.clientHeight)||0}}),[me,st,n]),tt=c.useRef(null),ht=c.useRef(null),Oe=c.useRef(null),at=c.useRef(null);c.useEffect(()=>{let Z;const ke=()=>{const Ce=me.cameraRef.current,ue=`translate(${Ce.x}px, ${Ce.y}px) scale(${Ce.zoom})`,_e=`translate(${Ce.x}, ${Ce.y}) scale(${Ce.zoom})`;tt.current&&(tt.current.style.transform=ue),ht.current&&ht.current.setAttribute("transform",_e),Oe.current&&(Oe.current.style.transform=ue),at.current&&(at.current.style.transform=ue),Z=requestAnimationFrame(ke)};return Z=requestAnimationFrame(ke),()=>cancelAnimationFrame(Z)},[me]);const[Et,ze]=c.useState(null);c.useEffect(()=>{if(!qe.length)return;let Z;const ke=()=>{var on,sn;const Ce=me.cameraRef.current,ue=me.wrapRef.current;if(!ue){Z=requestAnimationFrame(ke);return}const _e=ue.getBoundingClientRect(),je=200,kn=-Ce.x/Ce.zoom-je,Cn=-Ce.y/Ce.zoom-je,En=(_e.width-Ce.x)/Ce.zoom+je,rn=(_e.height-Ce.y)/Ce.zoom+je,pt=new Set;for(const We of qe){const yt=We._absolutePosition||We.position,zn=We.width||((on=We.measured)==null?void 0:on.width)||200,an=We.height||((sn=We.measured)==null?void 0:sn.height)||100;yt.x+zn>=kn&&yt.x<=En&&yt.y+an>=Cn&&yt.y<=rn&&pt.add(We.id)}ze(We=>{if(!We||We.size!==pt.size)return pt;for(const yt of pt)if(!We.has(yt))return pt;return We}),Z=requestAnimationFrame(ke)};return Z=requestAnimationFrame(ke),()=>cancelAnimationFrame(Z)},[qe,me]);const Ze=c.useMemo(()=>Et?qe.filter(Z=>Et.has(Z.id)):qe,[qe,Et]),tn=qe.length>0,nn=Q.length>0;return N.jsx(Yt.Provider,{value:Dt,children:N.jsxs("div",{ref:dt,className:`ric-wrap ${l}`,style:{width:f,height:x,...y},onPointerDown:Bt,onPointerMove:jt,onPointerUp:At,onDragOver:pe,onDrop:Je,onDragEnter:Nt,onDragLeave:$e,tabIndex:0,children:[N.jsx("canvas",{ref:Lt,className:"ric-canvas"}),!$t&&N.jsx("div",{className:"ric-loader",children:N.jsx("div",{className:"ric-spinner"})}),nn&&N.jsx("svg",{className:"ric-edges-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",overflow:"visible"},children:N.jsx("g",{ref:ht,children:Q.map(Z=>N.jsx(Kr,{edge:Z,edgeType:et[Z.type],nodes:t,reconnectable:K},Z.id))})}),tn&&N.jsx("div",{ref:tt,className:"ric-nodes-overlay",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:10},children:Ze.map(Z=>N.jsx(Gr,{node:Z,nodeType:lt[Z.type]},Z.id))}),N.jsx("div",{ref:Z=>{Tt.current=Z,Oe.current=Z},className:"ric-edge-labels",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:5}}),N.jsx("div",{ref:Z=>{Kt.current=Z,at.current=Z},className:"ric-viewport-portal",style:{position:"absolute",top:0,left:0,width:0,height:0,transformOrigin:"0 0",pointerEvents:"none",zIndex:6}}),De&&N.jsx("div",{className:"ric-hint",children:He}),Rn&&N.jsxs("div",{className:"ric-info",children:["world: (",Ue.wx,", ",Ue.wy,")   zoom: ",Ue.zoom,"x",Ue.nodeCount>0&&N.jsxs(N.Fragment,{children:["   nodes: ",Ue.nodeCount]}),Ue.edgeCount>0&&N.jsxs(N.Fragment,{children:["   edges: ",Ue.edgeCount]})]}),N.jsx(dr,{selectionKeyCode:gt||"Shift",selectionMode:bt||"partial"}),Rt]})})}function bo({children:e}){const t=c.useRef(null);return t.current||(t.current=qr()),N.jsx(Yt.Provider,{value:t.current,children:e})}function br(e,t){const n=[],r=new Map,a=[];for(const o of e)if(o.type==="add")a.push(o);else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const i=r.get(o.id);i?i.push(o):r.set(o.id,[o])}for(const o of t){const i=r.get(o.id);if(!i){n.push(o);continue}if(i[0].type==="remove")continue;if(i[0].type==="replace"){n.push({...i[0].item});continue}const f={...o};for(const x of i)wo(x,f);n.push(f)}for(const o of a)o.index!==void 0?n.splice(o.index,0,{...o.item}):n.push({...o.item});return n}function wo(e,t){switch(e.type){case"select":t.selected=e.selected;break;case"position":e.position!==void 0&&(t.position=e.position),e.dragging!==void 0&&(t.dragging=e.dragging);break;case"dimensions":e.dimensions!==void 0&&(t.measured={...e.dimensions},(e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height)),e.handleBounds!==void 0&&(t.handleBounds=e.handleBounds);break}}function wr(e,t){return br(e,t)}function Mr(e,t){return br(e,t)}function Mo(e,t){return!e.source||!e.target?(console.warn("addEdge: source and target are required"),t):t.some(r=>r.source===e.source&&r.target===e.target&&(r.sourceHandle||null)===(e.sourceHandle||null)&&(r.targetHandle||null)===(e.targetHandle||null))?t:[...t,{id:e.id||`e-${e.source}-${e.target}`,...e}]}function Ro(e){const[t,n]=c.useState(e),r=c.useCallback(a=>n(o=>wr(a,o)),[]);return[t,n,r]}function ko(e){const[t,n]=c.useState(e),r=c.useCallback(a=>n(o=>Mr(a,o)),[]);return[t,n,r]}function Rr(){const e=ir(),t=c.useCallback(()=>typeof e.getState=="function"?e.getState():e,[e]),n=c.useCallback(()=>[...t().nodesRef.current],[t]),r=c.useCallback(()=>[...t().edgesRef.current],[t]),a=c.useCallback(p=>t().nodesRef.current.find(h=>h.id===p),[t]),o=c.useCallback(p=>t().edgesRef.current.find(h=>h.id===p),[t]),i=c.useCallback(p=>{var h,w,T,I;if(typeof p=="function"){const Y=p(t().nodesRef.current);(w=(h=t().onNodesChangeRef).current)==null||w.call(h,[...t().nodesRef.current.map(J=>({id:J.id,type:"remove"})),...Y.map(J=>({type:"add",item:J}))])}else(I=(T=t().onNodesChangeRef).current)==null||I.call(T,[...t().nodesRef.current.map(Y=>({id:Y.id,type:"remove"})),...p.map(Y=>({type:"add",item:Y}))])},[t]),f=c.useCallback(p=>{var h,w,T,I;if(typeof p=="function"){const Y=p(t().edgesRef.current);(w=(h=t().onEdgesChangeRef).current)==null||w.call(h,[...t().edgesRef.current.map(J=>({id:J.id,type:"remove"})),...Y.map(J=>({type:"add",item:J}))])}else(I=(T=t().onEdgesChangeRef).current)==null||I.call(T,[...t().edgesRef.current.map(Y=>({id:Y.id,type:"remove"})),...p.map(Y=>({type:"add",item:Y}))])},[t]),x=c.useCallback(p=>{var w,T;const h=Array.isArray(p)?p:[p];(T=(w=t().onNodesChangeRef).current)==null||T.call(w,h.map(I=>({type:"add",item:I})))},[t]),l=c.useCallback(p=>{var w,T;const h=Array.isArray(p)?p:[p];(T=(w=t().onEdgesChangeRef).current)==null||T.call(w,h.map(I=>({type:"add",item:I})))},[t]),y=c.useCallback(({nodes:p=[],edges:h=[]})=>{if(p.length&&t().onNodesChangeRef.current){t().onNodesChangeRef.current(p.map(T=>({id:T.id,type:"remove"})));const w=or(p,t().edgesRef.current);w.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(w.map(T=>({id:T.id,type:"remove"})))}h.length&&t().onEdgesChangeRef.current&&t().onEdgesChangeRef.current(h.map(w=>({id:w.id,type:"remove"})))},[t]),b=c.useCallback(()=>{const p=t().cameraRef.current;return{x:p.x,y:p.y,zoom:p.zoom}},[t]),E=c.useRef(null),R=c.useCallback((p,h)=>{if(E.current&&cancelAnimationFrame(E.current),!h||h<=0){t().cameraRef.current={...p},t().sendCamera();return}const w={...t().cameraRef.current},T=performance.now(),I=Y=>{const J=Y-T,ee=Math.min(J/h,1),V=1-Math.pow(1-ee,3);t().cameraRef.current={x:w.x+(p.x-w.x)*V,y:w.y+(p.y-w.y)*V,zoom:w.zoom+(p.zoom-w.zoom)*V},t().sendCamera(),ee<1&&(E.current=requestAnimationFrame(I))};E.current=requestAnimationFrame(I)},[t]),v=c.useCallback((p,h)=>{const w={x:p.x??t().cameraRef.current.x,y:p.y??t().cameraRef.current.y,zoom:p.zoom??t().cameraRef.current.zoom};R(w,h==null?void 0:h.duration)},[t,R]),$=c.useCallback(()=>t().cameraRef.current.zoom,[t]),z=c.useCallback(p=>{const h=t().cameraRef.current,w=t().wrapRef.current;if(!w)return;const T=w.getBoundingClientRect(),I=T.width/2,Y=T.height/2,J=1.2,ee={x:I-(I-h.x)*J,y:Y-(Y-h.y)*J,zoom:Math.min(t().zoomMax,h.zoom*J)};R(ee,p==null?void 0:p.duration)},[t,R]),S=c.useCallback(p=>{const h=t().cameraRef.current,w=t().wrapRef.current;if(!w)return;const T=w.getBoundingClientRect(),I=T.width/2,Y=T.height/2,J=1/1.2,ee={x:I-(I-h.x)*J,y:Y-(Y-h.y)*J,zoom:Math.max(t().zoomMin,h.zoom*J)};R(ee,p==null?void 0:p.duration)},[t,R]),X=c.useCallback((p,h)=>{const w=t().cameraRef.current,T=t().wrapRef.current;if(!T)return;const I=T.getBoundingClientRect(),Y=I.width/2,J=I.height/2,ee=Math.min(t().zoomMax,Math.max(t().zoomMin,p)),V=ee/w.zoom,F={x:Y-(Y-w.x)*V,y:J-(J-w.y)*V,zoom:ee};R(F,h==null?void 0:h.duration)},[t,R]),H=c.useCallback((p={})=>{const h=t().nodesRef.current;if(!h.length)return;const w=t().wrapRef.current;if(!w)return;const T=w.getBoundingClientRect(),I=p.padding??.1,Y=p.nodes?h.filter(V=>p.nodes.some(F=>F.id===V.id)):h;if(!Y.length)return;const J=ln(Y),ee=zt(J,T.width,T.height,I);p.maxZoom&&(ee.zoom=Math.min(ee.zoom,p.maxZoom)),p.minZoom&&(ee.zoom=Math.max(ee.zoom,p.minZoom)),R(ee,p.duration)},[t,R]),_=c.useCallback((p,h={})=>{const w=t().wrapRef.current;if(!w)return;const T=w.getBoundingClientRect(),I=h.padding??.1,Y=zt(p,T.width,T.height,I);h.maxZoom&&(Y.zoom=Math.min(Y.zoom,h.maxZoom)),h.minZoom&&(Y.zoom=Math.max(Y.zoom,h.minZoom)),R(Y,h.duration)},[t,R]),B=c.useCallback((p,h,w={})=>{const T=t().wrapRef.current;if(!T)return;const I=T.getBoundingClientRect(),Y=w.zoom??t().cameraRef.current.zoom,J={x:I.width/2-p*Y,y:I.height/2-h*Y,zoom:Y};R(J,w.duration)},[t,R]),L=c.useCallback(()=>({nodes:[...t().nodesRef.current],edges:[...t().edgesRef.current],viewport:{...t().cameraRef.current}}),[t]),j=c.useCallback(p=>t().screenToWorld(p.x,p.y),[t]),W=c.useCallback(p=>{const h=t().cameraRef.current,w=t().wrapRef.current;if(!w)return{x:0,y:0};const T=w.getBoundingClientRect();return{x:p.x*h.zoom+h.x+T.left,y:p.y*h.zoom+h.y+T.top}},[t]),A=c.useCallback((p,h)=>{var I,Y;const w=t().nodesRef.current.find(J=>J.id===p);if(!w)return;const T=typeof h=="function"?h(w.data):{...w.data,...h};(Y=(I=t().onNodesChangeRef).current)==null||Y.call(I,[{id:p,type:"replace",item:{...w,data:T}}])},[t]);return{getNodes:n,getEdges:r,getNode:a,getEdge:o,setNodes:i,setEdges:f,addNodes:x,addEdges:l,deleteElements:y,getViewport:b,setViewport:v,getZoom:$,zoomIn:z,zoomOut:S,zoomTo:X,fitView:H,fitBounds:_,setCenter:B,screenToFlowPosition:j,flowToScreenPosition:W,updateNodeData:A,toObject:L}}function Co(){return ve().nodes}function Eo(){return ve().edges}function zo(){return ve().viewport}function No(){return ve().connection}function So(e){const t=ve(),n=Array.isArray(e)?e:[e];return c.useMemo(()=>n.map(r=>{const a=t.nodes.find(o=>o.id===r);return a?{id:a.id,type:a.type,data:a.data}:null}).filter(Boolean),[t.nodes,...n])}function Po(e){const t=ve();return c.useMemo(()=>t.edges.filter(n=>n.source===e||n.target===e),[t.edges,e])}function Io({nodeId:e,type:t,handleId:n}){const r=ve();return c.useMemo(()=>r.edges.filter(a=>t==="source"?a.source===e&&(n?a.sourceHandle===n:!0):a.target===e&&(n?a.targetHandle===n:!0)),[r.edges,e,t,n])}function To({onChange:e,onStart:t,onEnd:n}){const r=ve(),a=c.useRef(e),o=c.useRef(t),i=c.useRef(n);c.useEffect(()=>{a.current=e},[e]),c.useEffect(()=>{o.current=t},[t]),c.useEffect(()=>{i.current=n},[n]),c.useEffect(()=>{const f=x=>{var l;(l=a.current)==null||l.call(a,{x:x.x,y:x.y,zoom:x.zoom})};return r.viewportListeners.add(f),()=>r.viewportListeners.delete(f)},[s])}function Lo({onChange:e}){const t=ve(),n=c.useRef(e);c.useEffect(()=>{n.current=e},[e]),c.useEffect(()=>{const r=a=>{var o;(o=n.current)==null||o.call(n,a)};return t.selectionListeners.add(r),()=>t.selectionListeners.delete(r)},[s])}function $o(e){const[t,n]=c.useState(!1),r=Array.isArray(e)?e:[e];return c.useEffect(()=>{const a=i=>{r.includes(i.key)&&n(!0)},o=i=>{r.includes(i.key)&&n(!1)};return window.addEventListener("keydown",a),window.addEventListener("keyup",o),()=>{window.removeEventListener("keydown",a),window.removeEventListener("keyup",o)}},[r.join(",")]),t}function Bo(){const e=ve();return c.useCallback(t=>{var n;(n=e.workerRef.current)==null||n.postMessage({type:"nodes",data:{nodes:[...s().nodesRef.current]}})},[s])}const jo=e=>{var t;return((t=e.nodes)==null?void 0:t.length)>0};function Ao(e={}){return ve(jo)}function Do(e){const t=ve();return c.useMemo(()=>t.nodes.find(n=>n.id===e)||void 0,[t.nodes,e])}function Ho(e,t){return ve(e,t)}function _o(){return ir()}function Wo({maxHistorySize:e=100}={}){const t=ve(),n=c.useRef([]),r=c.useRef([]),[,a]=c.useState(0),o=c.useRef(null),i=c.useCallback(()=>{const l={nodes:s().nodesRef.current.map(y=>({...y,data:{...y.data}})),edges:s().edgesRef.current.map(y=>({...y}))};o.current&&JSON.stringify(o.current.nodes.map(y=>y.id))===JSON.stringify(l.nodes.map(y=>y.id))&&JSON.stringify(o.current.edges.map(y=>y.id))===JSON.stringify(l.edges.map(y=>y.id))||(n.current.push(l),n.current.length>e&&n.current.shift(),r.current=[],o.current=l,a(y=>y+1))},[t,e]),f=c.useCallback(()=>{var y,b,E,R;const l=n.current.pop();l&&(r.current.push({nodes:s().nodesRef.current.map(v=>({...v,data:{...v.data}})),edges:s().edgesRef.current.map(v=>({...v}))}),(b=(y=s().onNodesChangeRef).current)==null||b.call(y,[...s().nodesRef.current.map(v=>({id:v.id,type:"remove"})),...l.nodes.map(v=>({type:"add",item:v}))]),(R=(E=s().onEdgesChangeRef).current)==null||R.call(E,[...s().edgesRef.current.map(v=>({id:v.id,type:"remove"})),...l.edges.map(v=>({type:"add",item:v}))]),o.current=l,a(v=>v+1))},[s]),x=c.useCallback(()=>{var y,b,E,R;const l=r.current.pop();l&&(n.current.push({nodes:s().nodesRef.current.map(v=>({...v,data:{...v.data}})),edges:s().edgesRef.current.map(v=>({...v}))}),(b=(y=s().onNodesChangeRef).current)==null||b.call(y,[...s().nodesRef.current.map(v=>({id:v.id,type:"remove"})),...l.nodes.map(v=>({type:"add",item:v}))]),(R=(E=s().onEdgesChangeRef).current)==null||R.call(E,[...s().edgesRef.current.map(v=>({id:v.id,type:"remove"})),...l.edges.map(v=>({type:"add",item:v}))]),o.current=l,a(v=>v+1))},[s]);return{undo:f,redo:x,takeSnapshot:i,canUndo:n.current.length>0,canRedo:r.current.length>0}}function Fo(e){const t=c.useRef(e);return c.useEffect(()=>{t.current=e},[e]),c.useCallback(n=>r=>{const a=t.current(r);a!==!1&&a!=null&&n(Array.isArray(a)?a:r)},[])}function Xo(e){const t=c.useRef(e);return c.useEffect(()=>{t.current=e},[e]),c.useCallback(n=>r=>{const a=t.current(r);a!==!1&&a!=null&&n(Array.isArray(a)?a:r)},[])}const In=160,Tn=60;function Yo({width:e=200,height:t=150,nodeColor:n="#3b82f6",nodeStrokeColor:r="#fff",maskColor:a="rgba(0,0,0,0.1)",style:o={},className:i=""}){const f=ve(),x=c.useRef(null),l=c.useRef(null),y=c.useCallback(()=>{const b=x.current;if(!b)return;const E=b.getContext("2d"),R=window.devicePixelRatio||1;b.width=e*R,b.height=t*R,E.scale(R,R),E.clearRect(0,0,e,t);const v=f.nodesRef.current;if(!v.length)return;let $=1/0,z=1/0,S=-1/0,X=-1/0;for(const h of v){const w=h.width||In,T=h.height||Tn;h.position.x<$&&($=h.position.x),h.position.y<z&&(z=h.position.y),h.position.x+w>S&&(S=h.position.x+w),h.position.y+T>X&&(X=h.position.y+T)}const H=40;$-=H,z-=H,S+=H,X+=H;const _=S-$,B=X-z,L=Math.min(e/_,t/B),j=(e-_*L)/2,W=(t-B*L)/2;for(const h of v){if(h.hidden)continue;const w=h.width||In,T=h.height||Tn,I=(h.position.x-$)*L+j,Y=(h.position.y-z)*L+W,J=w*L,ee=T*L;E.fillStyle=h.selected?"#f59e0b":typeof n=="function"?n(h):n,E.fillRect(I,Y,Math.max(J,2),Math.max(ee,2))}const A=f.cameraRef.current,p=f.wrapRef.current;if(p){const h=p.getBoundingClientRect(),w=-A.x/A.zoom,T=-A.y/A.zoom,I=h.width/A.zoom,Y=h.height/A.zoom;E.fillStyle=a,E.fillRect(0,0,e,t);const J=(w-$)*L+j,ee=(T-z)*L+W,V=I*L,F=Y*L;E.clearRect(J,ee,V,F);for(const te of v){if(te.hidden)continue;const oe=te.width||In,fe=te.height||Tn,ge=(te.position.x-$)*L+j,Te=(te.position.y-z)*L+W;E.fillStyle=te.selected?"#f59e0b":typeof n=="function"?n(te):n,E.fillRect(ge,Te,Math.max(oe*L,2),Math.max(fe*L,2))}E.strokeStyle="#3b82f6",E.lineWidth=1.5,E.strokeRect(J,ee,V,F)}},[f,e,t,n,r,a]);return c.useEffect(()=>{let b=!0;function E(){b&&(y(),l.current=requestAnimationFrame(E))}const R=setInterval(()=>{cancelAnimationFrame(l.current),l.current=requestAnimationFrame(E)},66);return y(),()=>{b=!1,clearInterval(R),cancelAnimationFrame(l.current)}},[y]),N.jsx("canvas",{ref:x,className:`ric-minimap ${i}`,style:{position:"absolute",bottom:30,right:10,width:e,height:t,borderRadius:4,border:"1px solid rgba(0,0,0,0.1)",background:"rgba(255,255,255,0.9)",pointerEvents:"none",...o}})}function Uo(){return N.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),N.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function qo(){return N.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:N.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function Oo(){return N.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:N.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}function Zo(){return N.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),N.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function Go(){return N.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2"}),N.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})}function Xt({children:e,className:t="",...n}){return N.jsx("button",{className:`ric-controls-button ${t}`,style:Jo,...n,children:e})}function Vo({showZoom:e=!0,showFitView:t=!0,showInteractive:n=!1,fitViewOptions:r,onZoomIn:a,onZoomOut:o,onFitView:i,onInteractiveChange:f,position:x="bottom-left",orientation:l="vertical",style:y={},className:b="","aria-label":E="Canvas controls",children:R}){const v=ve(),{zoomIn:$,zoomOut:z,fitView:S,getZoom:X}=Rr(),[H,_]=c.useState(!0),B=X()<=v.zoomMin,L=X()>=v.zoomMax,j=c.useCallback(()=>{$(),a==null||a()},[$,a]),W=c.useCallback(()=>{z(),o==null||o()},[z,o]),A=c.useCallback(()=>{S(r||{padding:.1}),i==null||i()},[S,r,i]),p=c.useCallback(()=>{const w=!H;_(w),f==null||f(w)},[H,f]),h={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:30,left:10},"bottom-right":{bottom:30,right:10},"bottom-center":{bottom:30,left:"50%",transform:"translateX(-50%)"}}[x]||{bottom:30,left:10};return N.jsxs("div",{className:`ric-controls ${b}`,style:{position:"absolute",display:"flex",flexDirection:l==="horizontal"?"row":"column",gap:2,zIndex:5,...h,...y},role:"toolbar","aria-label":E,children:[e&&N.jsxs(N.Fragment,{children:[N.jsx(Xt,{onClick:j,disabled:L,title:"Zoom in","aria-label":"Zoom in",className:"ric-controls-zoomin",children:N.jsx(Uo,{})}),N.jsx(Xt,{onClick:W,disabled:B,title:"Zoom out","aria-label":"Zoom out",className:"ric-controls-zoomout",children:N.jsx(qo,{})})]}),t&&N.jsx(Xt,{onClick:A,title:"Fit view","aria-label":"Fit view",className:"ric-controls-fitview",children:N.jsx(Oo,{})}),n&&N.jsx(Xt,{onClick:p,title:H?"Lock interactivity":"Unlock interactivity","aria-label":H?"Lock interactivity":"Unlock interactivity",className:"ric-controls-interactive",children:H?N.jsx(Go,{}):N.jsx(Zo,{})}),R]})}const Jo={width:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid rgba(0,0,0,0.12)",borderRadius:4,background:"#fff",cursor:"pointer",fontSize:16,lineHeight:1,color:"#333",padding:0},Qo=c.memo(Vo);function Ko({variant:e="lines",gap:t=40,size:n=1,color:r,style:a={},className:o=""}){const i=ve();return i.workerRef.current&&i.workerRef.current.postMessage({type:"background",data:{variant:e,gap:t,size:n,color:r}}),null}function es({position:e="top-left",style:t={},className:n="",children:r}){const a={"top-left":{top:10,left:10},"top-right":{top:10,right:10},"top-center":{top:10,left:"50%",transform:"translateX(-50%)"},"bottom-left":{bottom:10,left:10},"bottom-right":{bottom:10,right:10},"bottom-center":{bottom:10,left:"50%",transform:"translateX(-50%)"}}[e]||{top:10,left:10};return N.jsx("div",{className:`ric-panel ${n}`,style:{position:"absolute",zIndex:5,pointerEvents:"all",...a,...t},onPointerDown:o=>o.stopPropagation(),children:r})}function ts({minWidth:e=10,minHeight:t=10,maxWidth:n=1/0,maxHeight:r=1/0,isVisible:a=!0,handleStyle:o={},lineStyle:i={},color:f="#3b82f6",onResizeStart:x,onResize:l,onResizeEnd:y}){const b=c.useContext(qt),E=ve(),R=c.useRef(null),v=c.useCallback((S,X)=>{S.stopPropagation(),S.preventDefault();const H=E.nodesRef.current.find(L=>L.id===b);if(!H)return;R.current={direction:X,startX:S.clientX,startY:S.clientY,width:H.width||160,height:H.height||60},x==null||x(S,{width:R.current.width,height:R.current.height});const _=L=>{var T,I;if(!R.current)return;const j=R.current,W=E.cameraRef.current,A=(L.clientX-j.startX)/W.zoom,p=(L.clientY-j.startY)/W.zoom;let h=j.width,w=j.height;j.direction.includes("e")&&(h=Math.min(n,Math.max(e,j.width+A))),j.direction.includes("w")&&(h=Math.min(n,Math.max(e,j.width-A))),j.direction.includes("s")&&(w=Math.min(r,Math.max(t,j.height+p))),j.direction.includes("n")&&(w=Math.min(r,Math.max(t,j.height-p))),(I=(T=E.onNodesChangeRef).current)==null||I.call(T,[{id:b,type:"dimensions",dimensions:{width:h,height:w},setAttributes:!0}]),l==null||l(L,{width:h,height:w})},B=L=>{R.current=null,y==null||y(L,{}),window.removeEventListener("pointermove",_),window.removeEventListener("pointerup",B)};window.addEventListener("pointermove",_),window.addEventListener("pointerup",B)},[b,E,e,t,n,r,x,l,y]);if(!a)return null;const $=8,z={position:"absolute",width:$,height:$,background:f,border:"1px solid #fff",borderRadius:2,zIndex:20,...o};return N.jsxs(N.Fragment,{children:[N.jsx("div",{style:{...z,bottom:-$/2,right:-$/2,cursor:"nwse-resize"},onPointerDown:S=>v(S,"se")}),N.jsx("div",{style:{...z,bottom:-$/2,left:-$/2,cursor:"nesw-resize"},onPointerDown:S=>v(S,"sw")}),N.jsx("div",{style:{...z,top:-$/2,right:-$/2,cursor:"nesw-resize"},onPointerDown:S=>v(S,"ne")}),N.jsx("div",{style:{...z,top:-$/2,left:-$/2,cursor:"nwse-resize"},onPointerDown:S=>v(S,"nw")}),N.jsx("div",{style:{...z,top:"50%",right:-$/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:S=>v(S,"e")}),N.jsx("div",{style:{...z,top:"50%",left:-$/2,cursor:"ew-resize",transform:"translateY(-50%)"},onPointerDown:S=>v(S,"w")}),N.jsx("div",{style:{...z,left:"50%",top:-$/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:S=>v(S,"n")}),N.jsx("div",{style:{...z,left:"50%",bottom:-$/2,cursor:"ns-resize",transform:"translateX(-50%)"},onPointerDown:S=>v(S,"s")})]})}function ns({isVisible:e,position:t="top",offset:n=10,align:r="center",children:a,style:o={},className:i=""}){const f=c.useContext(qt),l=ve().nodes.find(E=>E.id===f);if(!(e!==void 0?e:l==null?void 0:l.selected))return null;const b={top:{bottom:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginBottom:n},bottom:{top:"100%",left:r==="start"?0:r==="end"?void 0:"50%",right:r==="end"?0:void 0,transform:r==="center"?"translateX(-50%)":void 0,marginTop:n},left:{right:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginRight:n},right:{left:"100%",top:r==="start"?0:r==="end"?void 0:"50%",bottom:r==="end"?0:void 0,transform:r==="center"?"translateY(-50%)":void 0,marginLeft:n}}[t]||{};return N.jsx("div",{className:`ric-node-toolbar ${i}`,style:{position:"absolute",zIndex:1e3,pointerEvents:"all",...b,...o},onPointerDown:E=>E.stopPropagation(),children:a})}function rs({isVisible:e=!1,x:t=0,y:n=0,alignX:r="center",alignY:a="center",children:o,style:i={},className:f=""}){if(!e)return null;const x=r==="center"?"-50%":r==="right"?"-100%":"0",l=a==="center"?"-50%":a==="bottom"?"-100%":"0";return N.jsx("div",{className:`ric-edge-toolbar ${f}`,style:{position:"absolute",left:t,top:n,transform:`translate(${x}, ${l})`,zIndex:1e3,pointerEvents:"all",...i},children:o})}function os({children:e}){var r;const n=(r=ve().edgeLabelContainerRef)==null?void 0:r.current;return n?tr.createPortal(e,n):null}function ss({children:e}){var r;const n=(r=ve().viewportPortalRef)==null?void 0:r.current;return n?tr.createPortal(e,n):null}function kr({fromX:e,fromY:t,toX:n,toY:r,fromPosition:a="right",toPosition:o="left",connectionLineType:i="default",connectionLineStyle:f,connectionLineComponent:x}){if(x)return N.jsx(x,{fromX:e,fromY:t,toX:n,toY:r,fromPosition:a,toPosition:o});let l;switch(i){case"straight":[l]=Dn({sourceX:e,sourceY:t,targetX:n,targetY:r});break;case"step":[l]=dn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o,borderRadius:0});break;case"smoothstep":[l]=dn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o});break;case"simplebezier":[l]=_n({sourceX:e,sourceY:t,targetX:n,targetY:r});break;default:[l]=Hn({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:a,targetPosition:o});break}return N.jsx("path",{d:l,fill:"none",className:"ric-connection-line",stroke:"#b1b1b7",strokeWidth:1.5,style:f})}kr.displayName="ConnectionLine";const as=c.memo(kr),is=Object.freeze({Top:"top",Bottom:"bottom",Left:"left",Right:"right"}),cs=Object.freeze({Arrow:"arrow",ArrowClosed:"arrowclosed"});function us(e){const t=e.width||e.measured&&e.measured.width||0,n=e.height||e.measured&&e.measured.height||0,r=e._absolutePosition||e.position||{x:0,y:0};return{x:r.x,y:r.y,x2:r.x+t,y2:r.y+n}}exports.Background=Ko;exports.BaseEdge=Ot;exports.BezierEdge=An;exports.ConnectionLine=as;exports.ControlButton=Xt;exports.Controls=Qo;exports.DefaultNode=to;exports.EdgeLabelRenderer=os;exports.EdgeText=pr;exports.EdgeToolbar=rs;exports.GroupNode=gr;exports.Handle=Ut;exports.InfiniteCanvas=vo;exports.InfiniteCanvasProvider=bo;exports.InputNode=hr;exports.MarkerType=cs;exports.MiniMap=Yo;exports.NodeResizer=ts;exports.NodeToolbar=ns;exports.OutputNode=yr;exports.Panel=es;exports.Position=is;exports.SelectionBox=dr;exports.SimpleBezierEdge=Yn;exports.SmoothStepEdge=Xn;exports.StepEdge=vr;exports.StraightEdge=Fn;exports.ViewportPortal=ss;exports.addEdge=Mo;exports.applyEdgeChanges=Mr;exports.applyNodeChanges=wr;exports.boxToRect=Br;exports.buildObstacles=Wn;exports.clampPosition=$n;exports.computeRoutedEdges=fo;exports.getBezierEdgeCenter=no;exports.getBezierPath=Hn;exports.getBoundsOfBoxes=jr;exports.getConnectedEdges=or;exports.getEdgeCenter=ro;exports.getIncomers=Ir;exports.getNodeDimensions=jn;exports.getNodesBounds=ln;exports.getNodesInside=Lr;exports.getOutgoers=Tr;exports.getOverlappingArea=Ar;exports.getRoutedLabelPosition=pn;exports.getSimpleBezierPath=_n;exports.getSmoothStepPath=dn;exports.getStraightPath=Dn;exports.getViewportForBounds=zt;exports.isEdge=Pr;exports.isNode=Sr;exports.nodeToBox=us;exports.nodeToRect=Dr;exports.reconnectEdge=oo;exports.rectToBox=$r;exports.routeSinglePath=ho;exports.routedPointsToPath=xn;exports.snapPosition=Ln;exports.useConnection=No;exports.useEdges=Eo;exports.useEdgesState=ko;exports.useHandleConnections=Io;exports.useInfiniteCanvas=ar;exports.useInternalNode=Do;exports.useKeyPress=$o;exports.useNodeConnections=Po;exports.useNodeId=Or;exports.useNodes=Co;exports.useNodesData=So;exports.useNodesInitialized=Ao;exports.useNodesState=Ro;exports.useOnEdgesChangeMiddleware=Xo;exports.useOnNodesChangeMiddleware=Fo;exports.useOnSelectionChange=Lo;exports.useOnViewportChange=To;exports.useReactFlow=Rr;exports.useStore=Ho;exports.useStoreApi=_o;exports.useUndoRedo=Wo;exports.useUpdateNodeInternals=Bo;exports.useViewport=zo;