dishui 0.0.57 → 0.0.59

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,643 +1,653 @@
1
- import { useFlowContext as sn } from "./context/FlowContext.js";
2
- import { useFlowUI as cn } from "./context/FlowUIContext.js";
3
- import { usePixiApp as dn } from "./hooks/usePixiApp.js";
4
- import { useViewport as an } from "./hooks/useViewport.js";
5
- import { GridRenderer as ln } from "./canvas/GridRenderer.js";
6
- import { SelectionOverlay as un } from "./canvas/SelectionOverlay.js";
7
- import { shapeDrawers as Be } from "./nodes/shapes.js";
8
- import { findClosestHandleWorld as Gt, getHandlePositions as vt, handleWorldPos as Ut } from "./nodes/NodeHandles.js";
9
- import { distToSegment as Ce, generateId as fn, isPointInNode as Lt, rectsOverlap as hn } from "./nodes/nodeUtils.js";
10
- import { NodeRenderer as yn } from "./nodes/NodeRenderer.js";
11
- import { buildEdgePath as en, linearizeSegments as nn, resolveEdgeEndpoints as Et } from "./edges/edgePaths.js";
12
- import { EdgeRenderer as pn } from "./edges/EdgeRenderer.js";
13
- import { LineRenderer as xn } from "./lines/LineRenderer.js";
14
- import { FreehandTool as gn } from "./lines/FreehandTool.js";
15
- import { GeometricLineTool as wn } from "./lines/GeometricLineTool.js";
16
- import { computeAlignmentSnap as ae } from "./hooks/useAlignmentGuides.js";
17
- import { AlignmentGuidesRenderer as mn } from "./canvas/AlignmentGuides.js";
18
- import { getDocumentSlides as vn, nextAnimIndex as In } from "./nodes/animAnchors.js";
19
- import { useCallback as jt, useEffect as It, useRef as w, useState as Ke } from "react";
20
- import { jsx as Se, jsxs as Ue } from "react/jsx-runtime";
21
- import { Graphics as $t } from "pixi.js";
22
- var bn = {
1
+ import { useFlowContext as ln } from "./context/FlowContext.js";
2
+ import { useFlowUI as un } from "./context/FlowUIContext.js";
3
+ import { usePixiApp as fn } from "./hooks/usePixiApp.js";
4
+ import { useViewport as hn } from "./hooks/useViewport.js";
5
+ import { GridRenderer as yn } from "./canvas/GridRenderer.js";
6
+ import { SelectionOverlay as pn } from "./canvas/SelectionOverlay.js";
7
+ import { shapeDrawers as je } from "./nodes/shapes.js";
8
+ import { findClosestHandleWorld as At, getHandlePositions as It, handleWorldPos as Wt } from "./nodes/NodeHandles.js";
9
+ import { distToSegment as Ne, generateId as xn, isPointInNode as Yt, rectsOverlap as gn } from "./nodes/nodeUtils.js";
10
+ import { NodeRenderer as wn } from "./nodes/NodeRenderer.js";
11
+ import { buildEdgePath as sn, linearizeSegments as cn, resolveEdgeEndpoints as Mt } from "./edges/edgePaths.js";
12
+ import { EdgeRenderer as mn } from "./edges/EdgeRenderer.js";
13
+ import { LineRenderer as vn } from "./lines/LineRenderer.js";
14
+ import { FreehandTool as In } from "./lines/FreehandTool.js";
15
+ import { GeometricLineTool as bn } from "./lines/GeometricLineTool.js";
16
+ import { computeAlignmentSnap as le } from "./hooks/useAlignmentGuides.js";
17
+ import { AlignmentGuidesRenderer as Mn } from "./canvas/AlignmentGuides.js";
18
+ import { getDocumentSlides as Rn, nextAnimIndex as Sn } from "./nodes/animAnchors.js";
19
+ import { useCallback as Jt, useEffect as bt, useRef as I, useState as $e } from "react";
20
+ import { jsx as Ce, jsxs as Je } from "react/jsx-runtime";
21
+ import { Graphics as Qt } from "pixi.js";
22
+ var zn = {
23
23
  nw: "nwse-resize",
24
24
  ne: "nesw-resize",
25
25
  se: "nwse-resize",
26
26
  sw: "nesw-resize"
27
- };
28
- function je(_, z, P) {
29
- const { x: V, y: N } = z.position, G = z.width, T = z.height, C = [
27
+ }, ue = typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia("(pointer: coarse)").matches, Qe = ue ? 2 : 1;
28
+ function $(_, S, H) {
29
+ return Math.min(S * Qe / _, H * Qe);
30
+ }
31
+ function tn(_, S, H) {
32
+ const { x: V, y: E } = S.position, L = S.width, D = S.height, C = [
30
33
  [
31
34
  "nw",
32
35
  V,
33
- N
36
+ E
34
37
  ],
35
38
  [
36
39
  "ne",
37
- V + G,
38
- N
40
+ V + L,
41
+ E
39
42
  ],
40
43
  [
41
44
  "se",
42
- V + G,
43
- N + T
45
+ V + L,
46
+ E + D
44
47
  ],
45
48
  [
46
49
  "sw",
47
50
  V,
48
- N + T
51
+ E + D
49
52
  ]
50
53
  ];
51
- let R = null, q = P;
52
- for (const [U, dt, et] of C) {
53
- const K = Math.hypot(_.x - dt, _.y - et);
54
- K < q && (q = K, R = U);
54
+ let M = null, q = H;
55
+ for (const [j, at, nt] of C) {
56
+ const K = Math.hypot(_.x - at, _.y - nt);
57
+ K < q && (q = K, M = j);
55
58
  }
56
- return R;
59
+ return M;
57
60
  }
58
- function $e(_, z, P, V, N) {
59
- let G = null, T = N;
60
- for (const C of P) {
61
- const R = Et(C, V);
62
- if (!R) continue;
63
- const q = Math.hypot(_ - R.sx, z - R.sy);
64
- q < T && (T = q, G = {
61
+ function en(_, S, H, V, E) {
62
+ let L = null, D = E;
63
+ for (const C of H) {
64
+ const M = Mt(C, V);
65
+ if (!M) continue;
66
+ const q = Math.hypot(_ - M.sx, S - M.sy);
67
+ q < D && (D = q, L = {
65
68
  edgeId: C.id,
66
69
  end: "source",
67
- worldX: R.sx,
68
- worldY: R.sy
70
+ worldX: M.sx,
71
+ worldY: M.sy
69
72
  });
70
- const U = Math.hypot(_ - R.tx, z - R.ty);
71
- U < T && (T = U, G = {
73
+ const j = Math.hypot(_ - M.tx, S - M.ty);
74
+ j < D && (D = j, L = {
72
75
  edgeId: C.id,
73
76
  end: "target",
74
- worldX: R.tx,
75
- worldY: R.ty
77
+ worldX: M.tx,
78
+ worldY: M.ty
76
79
  });
77
80
  }
78
- return G;
81
+ return L;
79
82
  }
80
- function Je(_, z, P, V) {
81
- let N = null, G = V;
82
- for (const T of P) {
83
- const C = T.data.waypoints;
83
+ function nn(_, S, H, V) {
84
+ let E = null, L = V;
85
+ for (const D of H) {
86
+ const C = D.data.waypoints;
84
87
  if (C)
85
- for (let R = 0; R < C.length; R++) {
86
- const q = Math.hypot(_ - C[R].x, z - C[R].y);
87
- q < G && (G = q, N = {
88
- edgeId: T.id,
89
- waypointIndex: R,
90
- wx: C[R].x,
91
- wy: C[R].y
88
+ for (let M = 0; M < C.length; M++) {
89
+ const q = Math.hypot(_ - C[M].x, S - C[M].y);
90
+ q < L && (L = q, E = {
91
+ edgeId: D.id,
92
+ waypointIndex: M,
93
+ wx: C[M].x,
94
+ wy: C[M].y
92
95
  });
93
96
  }
94
97
  }
95
- return N;
98
+ return E;
96
99
  }
97
- function Qe(_, z, P, V, N) {
98
- let G = null, T = N;
99
- for (const C of P) {
100
+ function rn(_, S, H, V, E) {
101
+ let L = null, D = E;
102
+ for (const C of H) {
100
103
  if (C.type !== "simplebezier") continue;
101
- const R = Et(C, V);
102
- if (!R) continue;
103
- const q = C.data.waypoints ?? [], U = [
104
+ const M = Mt(C, V);
105
+ if (!M) continue;
106
+ const q = C.data.waypoints ?? [], j = [
104
107
  {
105
- x: R.sx,
106
- y: R.sy
108
+ x: M.sx,
109
+ y: M.sy
107
110
  },
108
111
  ...q,
109
112
  {
110
- x: R.tx,
111
- y: R.ty
113
+ x: M.tx,
114
+ y: M.ty
112
115
  }
113
- ], dt = C.data.bezierControls, et = U.length - 2;
114
- for (let K = 0; K <= et; K++) {
115
- const nt = U[K], rt = U[K + 1], bt = dt?.[K], Wt = Math.hypot(rt.x - nt.x, rt.y - nt.y), Nt = Math.max(30, Wt * 0.3), Jt = bt?.c1x ?? (K === 0 ? nt.x + R.snx * Nt : nt.x + (rt.x - nt.x) * 0.4), At = bt?.c1y ?? (K === 0 ? nt.y + R.sny * Nt : nt.y), Yt = bt?.c2x ?? (K === et ? rt.x + R.tnx * Nt : rt.x - (rt.x - nt.x) * 0.4), Mt = bt?.c2y ?? (K === et ? rt.y + R.tny * Nt : rt.y), Rt = Math.hypot(_ - Jt, z - At);
116
- Rt < T && (T = Rt, G = {
116
+ ], at = C.data.bezierControls, nt = j.length - 2;
117
+ for (let K = 0; K <= nt; K++) {
118
+ const rt = j[K], ot = j[K + 1], Rt = at?.[K], Xt = Math.hypot(ot.x - rt.x, ot.y - rt.y), Tt = Math.max(30, Xt * 0.3), te = Rt?.c1x ?? (K === 0 ? rt.x + M.snx * Tt : rt.x + (ot.x - rt.x) * 0.4), _t = Rt?.c1y ?? (K === 0 ? rt.y + M.sny * Tt : rt.y), Ft = Rt?.c2x ?? (K === nt ? ot.x + M.tnx * Tt : ot.x - (ot.x - rt.x) * 0.4), St = Rt?.c2y ?? (K === nt ? ot.y + M.tny * Tt : ot.y), zt = Math.hypot(_ - te, S - _t);
119
+ zt < D && (D = zt, L = {
117
120
  edgeId: C.id,
118
121
  segmentIndex: K,
119
122
  controlEnd: "c1",
120
- wx: Jt,
121
- wy: At
123
+ wx: te,
124
+ wy: _t
122
125
  });
123
- const yt = Math.hypot(_ - Yt, z - Mt);
124
- yt < T && (T = yt, G = {
126
+ const pt = Math.hypot(_ - Ft, S - St);
127
+ pt < D && (D = pt, L = {
125
128
  edgeId: C.id,
126
129
  segmentIndex: K,
127
130
  controlEnd: "c2",
128
- wx: Yt,
129
- wy: Mt
131
+ wx: Ft,
132
+ wy: St
130
133
  });
131
134
  }
132
135
  }
133
- return G;
136
+ return L;
134
137
  }
135
- function Mn(_, z, P, V) {
136
- const N = Et(P, V);
137
- if (!N) return 0;
138
- const G = P.data.waypoints ?? [], T = [
138
+ function Cn(_, S, H, V) {
139
+ const E = Mt(H, V);
140
+ if (!E) return 0;
141
+ const L = H.data.waypoints ?? [], D = [
139
142
  {
140
- x: N.sx,
141
- y: N.sy
143
+ x: E.sx,
144
+ y: E.sy
142
145
  },
143
- ...G,
146
+ ...L,
144
147
  {
145
- x: N.tx,
146
- y: N.ty
148
+ x: E.tx,
149
+ y: E.ty
147
150
  }
148
151
  ];
149
- let C = 1 / 0, R = 0;
150
- for (let q = 0; q < T.length - 1; q++) {
151
- const U = Ce(_, z, T[q].x, T[q].y, T[q + 1].x, T[q + 1].y);
152
- U < C && (C = U, R = q);
152
+ let C = 1 / 0, M = 0;
153
+ for (let q = 0; q < D.length - 1; q++) {
154
+ const j = Ne(_, S, D[q].x, D[q].y, D[q + 1].x, D[q + 1].y);
155
+ j < C && (C = j, M = q);
153
156
  }
154
- return R;
157
+ return M;
155
158
  }
156
- function Rn(_, z, P, V, N = 24) {
157
- let { x: G, y: T, w: C, h: R } = { ..._ };
158
- const q = z === "nw" || z === "sw", U = z === "ne" || z === "se", dt = z === "nw" || z === "ne", et = z === "sw" || z === "se";
159
- return q && (G += P, C -= P), U && (C += P), dt && (T += V, R -= V), et && (R += V), C < N && (q && (G = _.x + _.w - N), C = N), R < N && (dt && (T = _.y + _.h - N), R = N), {
160
- x: G,
161
- y: T,
159
+ function En(_, S, H, V, E = 24) {
160
+ let { x: L, y: D, w: C, h: M } = { ..._ };
161
+ const q = S === "nw" || S === "sw", j = S === "ne" || S === "se", at = S === "nw" || S === "ne", nt = S === "sw" || S === "se";
162
+ return q && (L += H, C -= H), j && (C += H), at && (D += V, M -= V), nt && (M += V), C < E && (q && (L = _.x + _.w - E), C = E), M < E && (at && (D = _.y + _.h - E), M = E), {
163
+ x: L,
164
+ y: D,
162
165
  w: C,
163
- h: R
166
+ h: M
164
167
  };
165
168
  }
166
- function ze(_, z, P, V, N) {
167
- const G = Et(P, V);
168
- if (!G) return !1;
169
- const T = nn(en(P.type, G, P.data.waypoints, P.data.bezierControls));
170
- for (let C = 0; C < T.length - 1; C++) if (Ce(_, z, T[C].x, T[C].y, T[C + 1].x, T[C + 1].y) < N) return !0;
169
+ function Ee(_, S, H, V, E) {
170
+ const L = Mt(H, V);
171
+ if (!L) return !1;
172
+ const D = cn(sn(H.type, L, H.data.waypoints, H.data.bezierControls));
173
+ for (let C = 0; C < D.length - 1; C++) if (Ne(_, S, D[C].x, D[C].y, D[C + 1].x, D[C + 1].y) < E) return !0;
171
174
  return !1;
172
175
  }
173
- function tn(_, z, P, V) {
174
- const N = P.points;
175
- for (let G = 0; G < N.length - 1; G++) if (Ce(_, z, N[G].x, N[G].y, N[G + 1].x, N[G + 1].y) < V) return !0;
176
+ function on(_, S, H, V) {
177
+ const E = H.points;
178
+ for (let L = 0; L < E.length - 1; L++) if (Ne(_, S, E[L].x, E[L].y, E[L + 1].x, E[L + 1].y) < V) return !0;
176
179
  return !1;
177
180
  }
178
- function Bn({ onPixiReady: _ }) {
179
- const z = w(null), P = w(null), V = w(13751771), { pixiRef: N, readyRef: G } = dn(z, jt((a) => {
180
- V.current = a.gridDot, P.current && (P.current.dotColor = a.gridDot);
181
- }, [])), { setViewportInternal: T, viewportReqRef: C, viewport: R, autoFocus: q, showGrid: U, showAnchors: dt, gridSize: et, toolMode: K, edgeType: nt, focusOnRect: rt, setFocusOnRect: bt, pendingPlacement: Wt, setPendingPlacement: Nt, setContextMenu: Jt, beginNodeDrag: At, endNodeDrag: Yt, presentation: Mt, editingNodeId: Rt, setEditingNodeId: yt } = cn(), { currentCanvas: le, selection: Ee, setSelection: ft, setDoc: J, currentCanvasId: ue, pushCanvas: rn, doc: Ne } = sn(), St = w(null), Qt = w(null), te = w(null), ee = w(null), fe = w(null), he = w(null), ne = w(null), Xt = w(null), Ft = w(null), re = w(null), Dt = w([]), ye = w(null), pe = w(null), at = w(null), _t = w(null), De = w({
181
+ function $n({ onPixiReady: _ }) {
182
+ const S = I(null), H = I(null), V = I(13751771), { pixiRef: E, readyRef: L } = fn(S, Jt((l) => {
183
+ V.current = l.gridDot, H.current && (H.current.dotColor = l.gridDot);
184
+ }, [])), { setViewportInternal: D, viewportReqRef: C, viewport: M, autoFocus: q, showGrid: j, showAnchors: at, gridSize: nt, toolMode: K, edgeType: rt, focusOnRect: ot, setFocusOnRect: Rt, pendingPlacement: Xt, setPendingPlacement: Tt, setContextMenu: te, beginNodeDrag: _t, endNodeDrag: Ft, presentation: St, editingNodeId: zt, setEditingNodeId: pt } = un(), { currentCanvas: fe, selection: Te, setSelection: ht, setDoc: J, currentCanvasId: he, pushCanvas: dn, doc: De } = ln(), Ct = I(null), ee = I(null), ne = I(null), re = I(null), ye = I(null), pe = I(null), oe = I(null), Ot = I(null), qt = I(null), se = I(null), Dt = I([]), xe = I(null), ge = I(null), lt = I(null), Zt = I(null), ke = I({
182
185
  time: 0,
183
186
  wx: 0,
184
187
  wy: 0
185
- }), Tt = w({
188
+ }), kt = I({
186
189
  time: 0,
187
190
  wx: 0,
188
191
  wy: 0
189
- }), Te = w(0), qt = w(null), ke = w({
192
+ }), He = I(0), Vt = I(null), Pe = I({
190
193
  x: 0,
191
194
  y: 0
192
- }), He = dt || Mt ? le : {
193
- ...le,
194
- nodes: le.nodes.filter((a) => a.type !== "animAnchor")
195
- }, W = w(He);
196
- W.current = He;
197
- const B = w(ue);
198
- B.current = ue;
199
- const Zt = w(Ee);
200
- Zt.current = Ee;
201
- const Pe = w(Ne);
202
- Pe.current = Ne;
203
- const Ot = w(K);
204
- Ot.current = K;
205
- const Vt = w(q);
206
- Vt.current = q;
207
- const Bt = w(rt);
208
- Bt.current = rt;
209
- const Ge = w(nt);
210
- Ge.current = nt;
211
- const Le = w(dt);
212
- Le.current = dt;
213
- const kt = w(Mt);
214
- kt.current = Mt;
215
- const oe = w(Wt);
216
- oe.current = Wt;
217
- const We = w(At);
218
- We.current = At;
219
- const se = w(Yt);
220
- se.current = Yt;
221
- const ot = w(null), Q = w(null), tt = w(null), st = w(null), pt = w(null), ht = w(null), xt = w(null), xe = w(R), ge = w(0), { vmRef: Z, screenToWorld: Ae } = an(N, jt((a) => {
222
- xe.current = a, ge.current || (ge.current = requestAnimationFrame(() => {
223
- ge.current = 0, T(xe.current);
195
+ }), Le = at || St ? fe : {
196
+ ...fe,
197
+ nodes: fe.nodes.filter((l) => l.type !== "animAnchor")
198
+ }, W = I(Le);
199
+ W.current = Le;
200
+ const B = I(he);
201
+ B.current = he;
202
+ const Bt = I(Te);
203
+ Bt.current = Te;
204
+ const Ge = I(De);
205
+ Ge.current = De;
206
+ const Kt = I(K);
207
+ Kt.current = K;
208
+ const Ut = I(q);
209
+ Ut.current = q;
210
+ const jt = I(ot);
211
+ jt.current = ot;
212
+ const Ae = I(rt);
213
+ Ae.current = rt;
214
+ const We = I(at);
215
+ We.current = at;
216
+ const Ht = I(St);
217
+ Ht.current = St;
218
+ const ce = I(Xt);
219
+ ce.current = Xt;
220
+ const Ye = I(_t);
221
+ Ye.current = _t;
222
+ const ie = I(Ft);
223
+ ie.current = Ft;
224
+ const st = I(null), Q = I(null), tt = I(null), ct = I(null), xt = I(null), yt = I(null), gt = I(null), we = I(M), me = I(0), { vmRef: F, screenToWorld: Xe } = hn(E, Jt((l) => {
225
+ we.current = l, me.current || (me.current = requestAnimationFrame(() => {
226
+ me.current = 0, D(we.current);
224
227
  }));
225
- }, [T])), ct = w(Ae);
226
- ct.current = Ae;
227
- const [lt, we] = Ke(null), [me, ve] = Ke(null), Ie = w(lt);
228
- Ie.current = lt;
229
- const ce = w(() => {
228
+ }, [D])), it = I(Xe);
229
+ it.current = Xe;
230
+ const [ut, ve] = $e(null), [Ie, be] = $e(null), Me = I(ut);
231
+ Me.current = ut;
232
+ const de = I(() => {
230
233
  });
231
- ce.current = (a, k, X) => {
232
- yt(a === "node" ? k : null), we({
233
- kind: a,
234
- id: k,
234
+ de.current = (l, P, X) => {
235
+ pt(l === "node" ? P : null), ve({
236
+ kind: l,
237
+ id: P,
235
238
  value: X
236
239
  });
237
240
  };
238
- const Ye = jt((a) => {
239
- const k = Ie.current;
240
- k && (J((X) => {
241
- const L = B.current, O = X.canvases[L];
242
- if (!O) return X;
243
- let F = O;
244
- if (k.kind === "node") F = {
245
- ...O,
246
- nodes: O.nodes.map((A) => A.id === k.id ? {
247
- ...A,
241
+ const _e = Jt((l) => {
242
+ const P = Me.current;
243
+ P && (J((X) => {
244
+ const A = B.current, Z = X.canvases[A];
245
+ if (!Z) return X;
246
+ let O = Z;
247
+ if (P.kind === "node") O = {
248
+ ...Z,
249
+ nodes: Z.nodes.map((Y) => Y.id === P.id ? {
250
+ ...Y,
248
251
  data: {
249
- ...A.data,
250
- label: a
252
+ ...Y.data,
253
+ label: l
251
254
  }
252
- } : A)
255
+ } : Y)
253
256
  };
254
- else if (k.kind === "edge") F = {
255
- ...O,
256
- edges: O.edges.map((A) => A.id === k.id ? {
257
- ...A,
257
+ else if (P.kind === "edge") O = {
258
+ ...Z,
259
+ edges: Z.edges.map((Y) => Y.id === P.id ? {
260
+ ...Y,
258
261
  data: {
259
- ...A.data,
260
- labelText: a
262
+ ...Y.data,
263
+ labelText: l
261
264
  }
262
- } : A)
265
+ } : Y)
263
266
  };
264
267
  else return X;
265
268
  return {
266
269
  ...X,
267
270
  canvases: {
268
271
  ...X.canvases,
269
- [L]: F
272
+ [A]: O
270
273
  }
271
274
  };
272
- }), we(null), yt(null), ve(null));
273
- }, [J, yt]), on = jt(() => {
274
- we(null), yt(null), ve(null);
275
- }, [yt]);
276
- It(() => {
277
- if (!Rt || Ie.current?.id === Rt) return;
278
- const a = W.current.nodes.find((k) => k.id === Rt);
279
- a && ce.current("node", a.id, a.data.label);
280
- }, [Rt]), It(() => {
281
- if (!lt) return;
282
- const a = Z.current;
283
- if (!a) return;
284
- const k = W.current;
275
+ }), ve(null), pt(null), be(null));
276
+ }, [J, pt]), an = Jt(() => {
277
+ ve(null), pt(null), be(null);
278
+ }, [pt]);
279
+ bt(() => {
280
+ if (!zt || Me.current?.id === zt) return;
281
+ const l = W.current.nodes.find((P) => P.id === zt);
282
+ l && de.current("node", l.id, l.data.label);
283
+ }, [zt]), bt(() => {
284
+ if (!ut) return;
285
+ const l = F.current;
286
+ if (!l) return;
287
+ const P = W.current;
285
288
  let X = null;
286
- if (lt.kind === "node") {
287
- const L = k.nodes.find((O) => O.id === lt.id);
288
- L && (X = {
289
- x: L.position.x + L.width / 2,
290
- y: L.position.y + L.height / 2
289
+ if (ut.kind === "node") {
290
+ const A = P.nodes.find((Z) => Z.id === ut.id);
291
+ A && (X = {
292
+ x: A.position.x + A.width / 2,
293
+ y: A.position.y + A.height / 2
291
294
  });
292
- } else if (lt.kind === "edge") {
293
- const L = k.edges.find((F) => F.id === lt.id), O = /* @__PURE__ */ new Map();
294
- for (const F of k.nodes) O.set(F.id, F);
295
- if (L) {
296
- const F = Et(L, O);
297
- if (F) {
298
- const A = nn(en(L.type, F, L.data.waypoints, L.data.bezierControls)), it = A[Math.floor(A.length / 2)] ?? {
299
- x: (F.sx + F.tx) / 2,
300
- y: (F.sy + F.ty) / 2
295
+ } else if (ut.kind === "edge") {
296
+ const A = P.edges.find((O) => O.id === ut.id), Z = /* @__PURE__ */ new Map();
297
+ for (const O of P.nodes) Z.set(O.id, O);
298
+ if (A) {
299
+ const O = Mt(A, Z);
300
+ if (O) {
301
+ const Y = cn(sn(A.type, O, A.data.waypoints, A.data.bezierControls)), dt = Y[Math.floor(Y.length / 2)] ?? {
302
+ x: (O.sx + O.tx) / 2,
303
+ y: (O.sy + O.ty) / 2
301
304
  };
302
305
  X = {
303
- x: it.x,
304
- y: it.y
306
+ x: dt.x,
307
+ y: dt.y
305
308
  };
306
309
  }
307
310
  }
308
311
  }
309
312
  if (X) {
310
- const L = a.worldToScreen(X.x, X.y);
311
- ve({
312
- x: L.x,
313
- y: L.y
313
+ const A = l.worldToScreen(X.x, X.y);
314
+ be({
315
+ x: A.x,
316
+ y: A.y
314
317
  });
315
318
  }
316
- }, [lt, Z]);
317
- const Xe = w(0);
318
- It(() => {
319
- C.current !== Xe.current && (Xe.current = C.current, xe.current = R, Z.current?.setState(R));
319
+ }, [ut, F]);
320
+ const Fe = I(0);
321
+ bt(() => {
322
+ C.current !== Fe.current && (Fe.current = C.current, we.current = M, F.current?.setState(M));
320
323
  }, [
321
- R,
322
- Z,
324
+ M,
325
+ F,
323
326
  C
324
- ]), It(() => {
325
- bt((a, k, X, L, O) => {
326
- const F = Z.current, A = z.current;
327
- if (!F || !A) return;
328
- const it = A.clientWidth || 800, gt = A.clientHeight || 600, wt = Math.max(0, O?.padding ?? 60), Ht = Math.max(1, it - wt * 2), mt = Math.max(1, gt - wt * 2), zt = O?.preserveZoom ? F.state.zoom : Math.min(Ht / Math.max(X, 1), mt / Math.max(L, 1), O?.maxZoom ?? 2), Ct = a + X / 2, ut = k + L / 2, Kt = it / 2 - Ct * zt, Me = gt / 2 - ut * zt;
329
- F.animateTo({
330
- x: Kt,
331
- y: Me,
332
- zoom: zt
333
- }, O?.duration ?? 350);
327
+ ]), bt(() => {
328
+ Rt((l, P, X, A, Z) => {
329
+ const O = F.current, Y = S.current;
330
+ if (!O || !Y) return;
331
+ const dt = Y.clientWidth || 800, wt = Y.clientHeight || 600, mt = Math.max(0, Z?.padding ?? 60), Pt = Math.max(1, dt - mt * 2), vt = Math.max(1, wt - mt * 2), Et = Z?.preserveZoom ? O.state.zoom : Math.min(Pt / Math.max(X, 1), vt / Math.max(A, 1), Z?.maxZoom ?? 2), Nt = l + X / 2, ft = P + A / 2, $t = dt / 2 - Nt * Et, Se = wt / 2 - ft * Et;
332
+ O.animateTo({
333
+ x: $t,
334
+ y: Se,
335
+ zoom: Et
336
+ }, Z?.duration ?? 350);
334
337
  });
335
- }, [bt, Z]);
336
- const Fe = jt((a) => {
337
- J((k) => {
338
- const X = k.canvases[B.current];
338
+ }, [Rt, F]);
339
+ const Oe = Jt((l) => {
340
+ J((P) => {
341
+ const X = P.canvases[B.current];
339
342
  return X ? {
340
- ...k,
343
+ ...P,
341
344
  canvases: {
342
- ...k.canvases,
345
+ ...P.canvases,
343
346
  [B.current]: {
344
347
  ...X,
345
- lines: [...X.lines, a]
348
+ lines: [...X.lines, l]
346
349
  }
347
350
  }
348
- } : k;
351
+ } : P;
349
352
  });
350
- }, [J, ue]), be = w(Fe);
351
- return be.current = Fe, It(() => {
352
- const a = N.current;
353
- if (!a || a.destroyed) return;
354
- let k = !1, X = null, L = null, O = null;
355
- const F = () => {
356
- if (k) return;
357
- if (!G.current) {
358
- setTimeout(F, 30);
353
+ }, [J, he]), Re = I(Oe);
354
+ return Re.current = Oe, bt(() => {
355
+ const l = E.current;
356
+ if (!l || l.destroyed) return;
357
+ let P = !1, X = null, A = null, Z = null;
358
+ const O = () => {
359
+ if (P) return;
360
+ if (!L.current) {
361
+ setTimeout(O, 30);
359
362
  return;
360
363
  }
361
- P.current = new ln(a.app.stage, et, U), P.current.dotColor = V.current, St.current = new un(a.app.stage), Qt.current = new yn(a.world), te.current = new pn(a.world), ee.current = new xn(a.world);
362
- const A = new $t();
363
- A.label = "connect-line", A.visible = !1, a.world.addChild(A), pt.current = A;
364
- const it = new $t();
365
- it.label = "transform-handles", a.app.stage.addChild(it), Xt.current = it;
366
- const gt = new $t();
367
- gt.label = "handle-hover", a.world.addChild(gt), Ft.current = gt;
368
- const wt = new $t();
369
- wt.label = "edge-edit-handles", a.world.addChild(wt), _t.current = wt;
370
- const Ht = new $t();
371
- Ht.label = "ghost-placement", Ht.alpha = 0.5, a.world.addChild(Ht), qt.current = Ht, re.current = new mn(a.world), fe.current = new gn(a.app.stage, a.world, {
372
- onLineComplete: (h) => be.current(h),
373
- screenToWorld: (h, r) => ct.current(h, r)
374
- }), he.current = new wn(a.app.stage, a.world, {
375
- onLineComplete: (h) => be.current(h),
376
- screenToWorld: (h, r) => ct.current(h, r)
377
- }), _?.(a);
378
- const mt = a.app.stage;
379
- mt.on("pointerdown", (h) => {
380
- if (z.current?.focus({ preventScroll: !0 }), Z.current?.multiTouchActive || Z.current?.isPanning || Z.current?.isSpaceHeld || h.button !== 0) return;
381
- const r = Ot.current;
382
- if (r === "pan") {
383
- Z.current?.startPan(h.global.x, h.global.y);
364
+ H.current = new yn(l.app.stage, nt, j), H.current.dotColor = V.current, Ct.current = new pn(l.app.stage), ee.current = new wn(l.world), ne.current = new mn(l.world), re.current = new vn(l.world);
365
+ const Y = new Qt();
366
+ Y.label = "connect-line", Y.visible = !1, l.world.addChild(Y), xt.current = Y;
367
+ const dt = new Qt();
368
+ dt.label = "transform-handles", l.app.stage.addChild(dt), Ot.current = dt;
369
+ const wt = new Qt();
370
+ wt.label = "handle-hover", l.world.addChild(wt), qt.current = wt;
371
+ const mt = new Qt();
372
+ mt.label = "edge-edit-handles", l.world.addChild(mt), Zt.current = mt;
373
+ const Pt = new Qt();
374
+ Pt.label = "ghost-placement", Pt.alpha = 0.5, l.world.addChild(Pt), Vt.current = Pt, se.current = new Mn(l.world), ye.current = new In(l.app.stage, l.world, {
375
+ onLineComplete: (f) => Re.current(f),
376
+ screenToWorld: (f, o) => it.current(f, o)
377
+ }), pe.current = new bn(l.app.stage, l.world, {
378
+ onLineComplete: (f) => Re.current(f),
379
+ screenToWorld: (f, o) => it.current(f, o)
380
+ }), _?.(l);
381
+ const vt = l.app.stage;
382
+ vt.on("pointerdown", (f) => {
383
+ if (S.current?.focus({ preventScroll: !0 }), F.current?.multiTouchActive || F.current?.isPanning || F.current?.isSpaceHeld || f.button !== 0) return;
384
+ const o = Kt.current;
385
+ if (o === "pan") {
386
+ F.current?.startPan(f.global.x, f.global.y);
384
387
  return;
385
388
  }
386
- if (r === "freehand" || r === "line" || r === "polyline" || r === "arrow") return;
387
- const d = ct.current(h.global.x, h.global.y), p = W.current.nodes, D = W.current.edges, E = W.current.lines, m = Zt.current, S = h.metaKey || h.ctrlKey || h.shiftKey, Y = Z.current?.state.zoom ?? 1;
388
- if (oe.current) return;
389
- const o = Date.now(), f = De.current, u = o - f.time < 350 && Math.hypot(d.x - f.wx, d.y - f.wy) < 8 / Y;
390
- if (De.current = {
391
- time: o,
392
- wx: d.x,
393
- wy: d.y
394
- }, m.nodeIds.size === 1 && !S && r === "select") {
395
- const t = p.find((s) => s.id === [...m.nodeIds][0]);
389
+ if (o === "freehand" || o === "line" || o === "polyline" || o === "arrow") return;
390
+ const i = it.current(f.global.x, f.global.y), p = W.current.nodes, N = W.current.edges, k = W.current.lines, z = Bt.current, b = f.metaKey || f.ctrlKey || f.shiftKey, T = F.current?.state.zoom ?? 1;
391
+ if (ce.current) return;
392
+ const c = Date.now(), h = ke.current, u = c - h.time < 350 && Math.hypot(i.x - h.wx, i.y - h.wy) < 8 / T;
393
+ if (ke.current = {
394
+ time: c,
395
+ wx: i.x,
396
+ wy: i.y
397
+ }, z.nodeIds.size === 1 && !b && o === "select") {
398
+ const t = p.find((r) => r.id === [...z.nodeIds][0]);
396
399
  if (t) {
397
- const s = je(d, t, Math.min(10 / Y, 16));
398
- if (s) {
399
- const l = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), n = t.type === "geometryGroup", i = n || t.type === "flowGroup" || t.data.isGroup, I = t.position.x, g = t.position.y, b = t.width, H = t.height;
400
+ const r = tn(i, t, $(T, 10, 16));
401
+ if (r) {
402
+ const d = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), e = t.type === "geometryGroup", s = e || t.type === "flowGroup" || t.data.isGroup, w = t.position.x, m = t.position.y, R = t.width, G = t.height;
400
403
  for (const y of p)
401
- y.id !== t.id && (y.parentId === t.id ? l.set(y.id, {
404
+ y.id !== t.id && (y.parentId === t.id ? d.set(y.id, {
402
405
  x: y.position.x,
403
406
  y: y.position.y,
404
407
  w: y.width,
405
408
  h: y.height
406
- }) : n && y.position.x >= I && y.position.y >= g && y.position.x + y.width <= I + b && y.position.y + y.height <= g + H && l.set(y.id, {
409
+ }) : e && y.position.x >= w && y.position.y >= m && y.position.x + y.width <= w + R && y.position.y + y.height <= m + G && d.set(y.id, {
407
410
  x: y.position.x,
408
411
  y: y.position.y,
409
412
  w: y.width,
410
413
  h: y.height
411
414
  }));
412
- if (i)
413
- for (const y of W.current.lines) y.parentId === t.id ? c.set(y.id, y.points.map((M) => ({ ...M }))) : n && y.points.length > 0 && y.points.every((M) => M.x >= I && M.x <= I + b && M.y >= g && M.y <= g + H) && c.set(y.id, y.points.map((M) => ({ ...M })));
414
- ht.current = {
415
+ if (s)
416
+ for (const y of W.current.lines) y.parentId === t.id ? a.set(y.id, y.points.map((v) => ({ ...v }))) : e && y.points.length > 0 && y.points.every((v) => v.x >= w && v.x <= w + R && v.y >= m && v.y <= m + G) && a.set(y.id, y.points.map((v) => ({ ...v })));
417
+ yt.current = {
415
418
  active: !0,
416
419
  nodeId: t.id,
417
- handle: s,
418
- startWorld: d,
420
+ handle: r,
421
+ startWorld: i,
419
422
  startBounds: {
420
423
  x: t.position.x,
421
424
  y: t.position.y,
422
425
  w: t.width,
423
426
  h: t.height
424
427
  },
425
- childStarts: l,
426
- childLineStarts: c.size > 0 ? c : void 0
428
+ childStarts: d,
429
+ childLineStarts: a.size > 0 ? a : void 0
427
430
  };
428
431
  return;
429
432
  }
430
433
  }
431
434
  }
432
- let e = null;
433
- for (let t = p.length - 1; t >= 0; t--) if (Lt(d.x, d.y, p[t])) {
434
- e = p[t];
435
+ let n = null;
436
+ for (let t = p.length - 1; t >= 0; t--) if (Yt(i.x, i.y, p[t])) {
437
+ n = p[t];
435
438
  break;
436
439
  }
437
- if (e?.parentId) {
438
- const t = p.find((s) => s.id === e.parentId);
439
- t && (e = t);
440
+ if (n?.parentId) {
441
+ const t = p.find((r) => r.id === n.parentId);
442
+ t && (n = t);
440
443
  }
441
- if (e && (r === "select" || r === "connect")) {
442
- const t = Gt(vt(e.width, e.height), e, d.x, d.y, Math.min(14 / Y, 20));
443
- if (t) {
444
+ if ((o === "select" || o === "connect") && (n || ue)) {
445
+ const t = n ? [n] : p, r = $(T, 14, 20);
446
+ let d = null, a = null, e = 1 / 0;
447
+ for (const s of t) {
448
+ const w = At(It(s.width, s.height), s, i.x, i.y, r);
449
+ if (!w) continue;
450
+ const m = Wt(w, s), R = Math.hypot(i.x - m.x, i.y - m.y);
451
+ R < e && (e = R, d = s, a = w);
452
+ }
453
+ if (d && a) {
444
454
  tt.current = {
445
455
  active: !0,
446
- sourceNodeId: e.id,
447
- sourceHandleId: t.id
456
+ sourceNodeId: d.id,
457
+ sourceHandleId: a.id
448
458
  };
449
459
  return;
450
460
  }
451
461
  }
452
- if ((r === "select" || r === "connect") && !S && m.edgeIds.size > 0) {
462
+ if ((o === "select" || o === "connect") && !b && z.edgeIds.size > 0) {
453
463
  const t = /* @__PURE__ */ new Map();
454
- for (const c of p) t.set(c.id, c);
455
- const s = D.filter((c) => m.edgeIds.has(c.id)), l = $e(d.x, d.y, s, t, Math.min(14 / Y, 20));
456
- if (l) {
457
- const c = D.find((n) => n.id === l.edgeId);
458
- if (c) {
459
- const n = l.end === "source" ? "target" : "source";
460
- st.current = {
464
+ for (const a of p) t.set(a.id, a);
465
+ const r = N.filter((a) => z.edgeIds.has(a.id)), d = en(i.x, i.y, r, t, $(T, 14, 20));
466
+ if (d) {
467
+ const a = N.find((e) => e.id === d.edgeId);
468
+ if (a) {
469
+ const e = d.end === "source" ? "target" : "source";
470
+ ct.current = {
461
471
  active: !0,
462
- edgeId: c.id,
463
- movingEnd: l.end,
464
- fixedNodeId: n === "source" ? c.source : c.target,
465
- fixedHandleId: n === "source" ? c.sourceHandle : c.targetHandle
472
+ edgeId: a.id,
473
+ movingEnd: d.end,
474
+ fixedNodeId: e === "source" ? a.source : a.target,
475
+ fixedHandleId: e === "source" ? a.sourceHandle : a.targetHandle
466
476
  };
467
477
  return;
468
478
  }
469
479
  }
470
480
  }
471
- if (r === "select" && m.edgeIds.size > 0 && !e) {
481
+ if (o === "select" && z.edgeIds.size > 0 && !n) {
472
482
  const t = /* @__PURE__ */ new Map();
473
- for (const i of p) t.set(i.id, i);
474
- const s = D.filter((i) => m.edgeIds.has(i.id)), l = Math.min(10 / Y, 14), c = Qe(d.x, d.y, s, t, l);
475
- if (c) {
476
- at.current = {
483
+ for (const s of p) t.set(s.id, s);
484
+ const r = N.filter((s) => z.edgeIds.has(s.id)), d = $(T, 10, 14), a = rn(i.x, i.y, r, t, d);
485
+ if (a) {
486
+ lt.current = {
477
487
  active: !0,
478
- edgeId: c.edgeId,
479
- type: c.controlEnd === "c1" ? "bezierC1" : "bezierC2",
480
- index: c.segmentIndex
488
+ edgeId: a.edgeId,
489
+ type: a.controlEnd === "c1" ? "bezierC1" : "bezierC2",
490
+ index: a.segmentIndex
481
491
  };
482
492
  return;
483
493
  }
484
- const n = Je(d.x, d.y, s, l);
485
- if (n) {
494
+ const e = nn(i.x, i.y, r, d);
495
+ if (e) {
486
496
  if (u) {
487
- J((i) => {
488
- const I = i.canvases[B.current];
489
- return I ? {
490
- ...i,
497
+ J((s) => {
498
+ const w = s.canvases[B.current];
499
+ return w ? {
500
+ ...s,
491
501
  canvases: {
492
- ...i.canvases,
502
+ ...s.canvases,
493
503
  [B.current]: {
494
- ...I,
495
- edges: I.edges.map((g) => {
496
- if (g.id !== n.edgeId) return g;
497
- const b = [...g.data.waypoints ?? []];
498
- b.splice(n.waypointIndex, 1);
499
- const H = {
500
- ...g.data,
501
- waypoints: b.length > 0 ? b : void 0
504
+ ...w,
505
+ edges: w.edges.map((m) => {
506
+ if (m.id !== e.edgeId) return m;
507
+ const R = [...m.data.waypoints ?? []];
508
+ R.splice(e.waypointIndex, 1);
509
+ const G = {
510
+ ...m.data,
511
+ waypoints: R.length > 0 ? R : void 0
502
512
  };
503
- if (g.type === "simplebezier" && g.data.bezierControls) {
504
- const y = [...g.data.bezierControls];
505
- y.splice(n.waypointIndex, 2, null), H.bezierControls = y.some((M) => M !== null) ? y : void 0;
513
+ if (m.type === "simplebezier" && m.data.bezierControls) {
514
+ const y = [...m.data.bezierControls];
515
+ y.splice(e.waypointIndex, 2, null), G.bezierControls = y.some((v) => v !== null) ? y : void 0;
506
516
  }
507
517
  return {
508
- ...g,
509
- data: H
518
+ ...m,
519
+ data: G
510
520
  };
511
521
  })
512
522
  }
513
523
  }
514
- } : i;
524
+ } : s;
515
525
  });
516
526
  return;
517
527
  }
518
- at.current = {
528
+ lt.current = {
519
529
  active: !0,
520
- edgeId: n.edgeId,
530
+ edgeId: e.edgeId,
521
531
  type: "waypoint",
522
- index: n.waypointIndex
532
+ index: e.waypointIndex
523
533
  };
524
534
  return;
525
535
  }
526
536
  if (u) {
527
- for (const i of s) if (ze(d.x, d.y, i, t, Math.min(8 / Y, 12))) {
528
- const I = Mn(d.x, d.y, i, t), g = {
529
- x: d.x,
530
- y: d.y
537
+ for (const s of r) if (Ee(i.x, i.y, s, t, $(T, 8, 12))) {
538
+ const w = Cn(i.x, i.y, s, t), m = {
539
+ x: i.x,
540
+ y: i.y
531
541
  };
532
- J((b) => {
533
- const H = b.canvases[B.current];
534
- return H ? {
535
- ...b,
542
+ J((R) => {
543
+ const G = R.canvases[B.current];
544
+ return G ? {
545
+ ...R,
536
546
  canvases: {
537
- ...b.canvases,
547
+ ...R.canvases,
538
548
  [B.current]: {
539
- ...H,
540
- edges: H.edges.map((y) => {
541
- if (y.id !== i.id) return y;
542
- const M = [...y.data.waypoints ?? []];
543
- M.splice(I, 0, g);
544
- const j = {
549
+ ...G,
550
+ edges: G.edges.map((y) => {
551
+ if (y.id !== s.id) return y;
552
+ const v = [...y.data.waypoints ?? []];
553
+ v.splice(w, 0, m);
554
+ const U = {
545
555
  ...y.data,
546
- waypoints: M
556
+ waypoints: v
547
557
  };
548
558
  if (y.type === "simplebezier" && y.data.bezierControls) {
549
- const $ = [...y.data.bezierControls];
550
- for (; $.length < (y.data.waypoints ?? []).length + 1; ) $.push(null);
551
- $.splice(I, 1, null, null), j.bezierControls = $;
559
+ const et = [...y.data.bezierControls];
560
+ for (; et.length < (y.data.waypoints ?? []).length + 1; ) et.push(null);
561
+ et.splice(w, 1, null, null), U.bezierControls = et;
552
562
  }
553
563
  return {
554
564
  ...y,
555
- data: j
565
+ data: U
556
566
  };
557
567
  })
558
568
  }
559
569
  }
560
- } : b;
561
- }), at.current = {
570
+ } : R;
571
+ }), lt.current = {
562
572
  active: !0,
563
- edgeId: i.id,
573
+ edgeId: s.id,
564
574
  type: "waypoint",
565
- index: I
575
+ index: w
566
576
  };
567
577
  return;
568
578
  }
569
579
  }
570
580
  }
571
- if (e && (r === "select" || r === "connect")) {
572
- !S && !m.nodeIds.has(e.id) ? ft({
573
- nodeIds: /* @__PURE__ */ new Set([e.id]),
581
+ if (n && (o === "select" || o === "connect")) {
582
+ !b && !z.nodeIds.has(n.id) ? ht({
583
+ nodeIds: /* @__PURE__ */ new Set([n.id]),
574
584
  edgeIds: /* @__PURE__ */ new Set(),
575
585
  lineIds: /* @__PURE__ */ new Set()
576
- }) : S && ft((n) => {
577
- const i = new Set(n.nodeIds);
578
- return i.has(e.id) ? i.delete(e.id) : i.add(e.id), {
579
- nodeIds: i,
586
+ }) : b && ht((e) => {
587
+ const s = new Set(e.nodeIds);
588
+ return s.has(n.id) ? s.delete(n.id) : s.add(n.id), {
589
+ nodeIds: s,
580
590
  edgeIds: /* @__PURE__ */ new Set(),
581
591
  lineIds: /* @__PURE__ */ new Set()
582
592
  };
583
- }), Vt.current && Bt.current(e.position.x, e.position.y, e.width, e.height, {
593
+ }), Ut.current && jt.current(n.position.x, n.position.y, n.width, n.height, {
584
594
  padding: 80,
585
595
  preserveZoom: !0,
586
596
  duration: 280
587
597
  });
588
- const t = m.nodeIds.has(e.id) ? new Set(m.nodeIds) : /* @__PURE__ */ new Set([e.id]);
589
- S && !m.nodeIds.has(e.id) && t.add(e.id);
590
- const s = /* @__PURE__ */ new Set();
591
- for (const n of [...t]) {
592
- const i = p.find((M) => M.id === n);
593
- if (!i || i.type !== "flowGroup" && i.type !== "geometryGroup" && !i.data.isGroup) continue;
594
- const I = i.type === "geometryGroup", g = i.position.x, b = i.position.y, H = i.width, y = i.height;
595
- for (const M of p)
596
- if (!(t.has(M.id) || M.id === n)) {
597
- if (M.parentId === n) {
598
- t.add(M.id);
598
+ const t = z.nodeIds.has(n.id) ? new Set(z.nodeIds) : /* @__PURE__ */ new Set([n.id]);
599
+ b && !z.nodeIds.has(n.id) && t.add(n.id);
600
+ const r = /* @__PURE__ */ new Set();
601
+ for (const e of [...t]) {
602
+ const s = p.find((v) => v.id === e);
603
+ if (!s || s.type !== "flowGroup" && s.type !== "geometryGroup" && !s.data.isGroup) continue;
604
+ const w = s.type === "geometryGroup", m = s.position.x, R = s.position.y, G = s.width, y = s.height;
605
+ for (const v of p)
606
+ if (!(t.has(v.id) || v.id === e)) {
607
+ if (v.parentId === e) {
608
+ t.add(v.id);
599
609
  continue;
600
610
  }
601
- I && M.position.x >= g && M.position.y >= b && M.position.x + M.width <= g + H && M.position.y + M.height <= b + y && t.add(M.id);
611
+ w && v.position.x >= m && v.position.y >= R && v.position.x + v.width <= m + G && v.position.y + v.height <= R + y && t.add(v.id);
602
612
  }
603
- for (const M of W.current.lines) M.parentId === n && s.add(M.id);
604
- if (I) for (const M of W.current.lines)
605
- s.has(M.id) || M.points.length > 0 && M.points.every((j) => j.x >= g && j.x <= g + H && j.y >= b && j.y <= b + y) && s.add(M.id);
613
+ for (const v of W.current.lines) v.parentId === e && r.add(v.id);
614
+ if (w) for (const v of W.current.lines)
615
+ r.has(v.id) || v.points.length > 0 && v.points.every((U) => U.x >= m && U.x <= m + G && U.y >= R && U.y <= R + y) && r.add(v.id);
606
616
  }
607
- const l = /* @__PURE__ */ new Map();
608
- for (const n of p) t.has(n.id) && l.set(n.id, { ...n.position });
609
- const c = /* @__PURE__ */ new Map();
610
- if (s.size > 0)
611
- for (const n of W.current.lines) s.has(n.id) && c.set(n.id, n.points.map((i) => ({ ...i })));
612
- ot.current = {
617
+ const d = /* @__PURE__ */ new Map();
618
+ for (const e of p) t.has(e.id) && d.set(e.id, { ...e.position });
619
+ const a = /* @__PURE__ */ new Map();
620
+ if (r.size > 0)
621
+ for (const e of W.current.lines) r.has(e.id) && a.set(e.id, e.points.map((s) => ({ ...s })));
622
+ st.current = {
613
623
  active: !0,
614
624
  nodeIds: t,
615
- lineIds: s.size > 0 ? s : void 0,
616
- startWorld: d,
617
- nodeStarts: l,
618
- linePointStarts: c.size > 0 ? c : void 0
619
- }, We.current();
625
+ lineIds: r.size > 0 ? r : void 0,
626
+ startWorld: i,
627
+ nodeStarts: d,
628
+ linePointStarts: a.size > 0 ? a : void 0
629
+ }, Ye.current();
620
630
  return;
621
631
  }
622
- const v = /* @__PURE__ */ new Map();
623
- for (const t of p) v.set(t.id, t);
624
- const x = Math.min(8 / Y, 12);
625
- for (const t of D) if (ze(d.x, d.y, t, v, x)) {
626
- if (ft(S ? (s) => {
627
- const l = new Set(s.edgeIds);
628
- return l.has(t.id) ? l.delete(t.id) : l.add(t.id), {
629
- ...s,
630
- edgeIds: l
632
+ const g = /* @__PURE__ */ new Map();
633
+ for (const t of p) g.set(t.id, t);
634
+ const x = $(T, 8, 12);
635
+ for (const t of N) if (Ee(i.x, i.y, t, g, x)) {
636
+ if (ht(b ? (r) => {
637
+ const d = new Set(r.edgeIds);
638
+ return d.has(t.id) ? d.delete(t.id) : d.add(t.id), {
639
+ ...r,
640
+ edgeIds: d
631
641
  };
632
642
  } : {
633
643
  nodeIds: /* @__PURE__ */ new Set(),
634
644
  edgeIds: /* @__PURE__ */ new Set([t.id]),
635
645
  lineIds: /* @__PURE__ */ new Set()
636
- }), Vt.current) {
637
- const s = v.get(t.source), l = v.get(t.target);
638
- if (s && l) {
639
- const c = Math.min(s.position.x, l.position.x), n = Math.min(s.position.y, l.position.y), i = Math.max(s.position.x + s.width, l.position.x + l.width), I = Math.max(s.position.y + s.height, l.position.y + l.height);
640
- Bt.current(c, n, i - c, I - n, {
646
+ }), Ut.current) {
647
+ const r = g.get(t.source), d = g.get(t.target);
648
+ if (r && d) {
649
+ const a = Math.min(r.position.x, d.position.x), e = Math.min(r.position.y, d.position.y), s = Math.max(r.position.x + r.width, d.position.x + d.width), w = Math.max(r.position.y + r.height, d.position.y + d.height);
650
+ jt.current(a, e, s - a, w - e, {
641
651
  padding: 80,
642
652
  preserveZoom: !0,
643
653
  duration: 280
@@ -646,465 +656,465 @@ function Bn({ onPixiReady: _ }) {
646
656
  }
647
657
  return;
648
658
  }
649
- for (const t of E) if (tn(d.x, d.y, t, x)) {
650
- const s = m.lineIds.has(t.id);
651
- if (S ? ft((n) => {
652
- const i = new Set(n.lineIds);
653
- return i.has(t.id) ? i.delete(t.id) : i.add(t.id), {
654
- ...n,
655
- lineIds: i
659
+ for (const t of k) if (on(i.x, i.y, t, x)) {
660
+ const r = z.lineIds.has(t.id);
661
+ if (b ? ht((e) => {
662
+ const s = new Set(e.lineIds);
663
+ return s.has(t.id) ? s.delete(t.id) : s.add(t.id), {
664
+ ...e,
665
+ lineIds: s
656
666
  };
657
- }) : s || ft({
667
+ }) : r || ht({
658
668
  nodeIds: /* @__PURE__ */ new Set(),
659
669
  edgeIds: /* @__PURE__ */ new Set(),
660
670
  lineIds: /* @__PURE__ */ new Set([t.id])
661
- }), Vt.current && t.points.length > 0) {
662
- const n = t.points.map((y) => y.x), i = t.points.map((y) => y.y), I = Math.min(...n), g = Math.min(...i), b = Math.max(...n), H = Math.max(...i);
663
- Bt.current(I, g, Math.max(1, b - I), Math.max(1, H - g), {
671
+ }), Ut.current && t.points.length > 0) {
672
+ const e = t.points.map((y) => y.x), s = t.points.map((y) => y.y), w = Math.min(...e), m = Math.min(...s), R = Math.max(...e), G = Math.max(...s);
673
+ jt.current(w, m, Math.max(1, R - w), Math.max(1, G - m), {
664
674
  padding: 80,
665
675
  preserveZoom: !0,
666
676
  duration: 280
667
677
  });
668
678
  }
669
- const l = s ? new Set(m.lineIds) : /* @__PURE__ */ new Set([t.id]), c = /* @__PURE__ */ new Map();
670
- for (const n of E) l.has(n.id) && c.set(n.id, n.points.map((i) => ({ ...i })));
671
- xt.current = {
679
+ const d = r ? new Set(z.lineIds) : /* @__PURE__ */ new Set([t.id]), a = /* @__PURE__ */ new Map();
680
+ for (const e of k) d.has(e.id) && a.set(e.id, e.points.map((s) => ({ ...s })));
681
+ gt.current = {
672
682
  active: !0,
673
- lineIds: l,
674
- startWorld: d,
675
- pointStarts: c
683
+ lineIds: d,
684
+ startWorld: i,
685
+ pointStarts: a
676
686
  };
677
687
  return;
678
688
  }
679
- S || ft({
689
+ b || ht({
680
690
  nodeIds: /* @__PURE__ */ new Set(),
681
691
  edgeIds: /* @__PURE__ */ new Set(),
682
692
  lineIds: /* @__PURE__ */ new Set()
683
- }), r === "select" && (Q.current = {
693
+ }), o === "select" && (Q.current = {
684
694
  active: !0,
685
695
  startScreen: {
686
- x: h.global.x,
687
- y: h.global.y
696
+ x: f.global.x,
697
+ y: f.global.y
688
698
  }
689
699
  });
690
- }), mt.on("globalpointermove", (h) => {
691
- const r = ct.current(h.global.x, h.global.y);
692
- if (ke.current = r, Z.current?.multiTouchActive) return;
693
- const d = Ot.current;
694
- if (d === "freehand" || d === "line" || d === "polyline" || d === "arrow") return;
695
- const p = W.current.nodes, D = W.current.edges, E = Z.current?.state.zoom ?? 1, m = !ot.current?.active && !tt.current?.active && !ht.current?.active && !st.current?.active && !at.current?.active && !xt.current?.active;
696
- let S = null;
697
- for (let o = p.length - 1; o >= 0; o--) if (Lt(r.x, r.y, p[o])) {
698
- const f = p[o];
699
- S = f.parentId ? p.find((u) => u.id === f.parentId)?.id ?? f.id : f.id;
700
+ }), vt.on("globalpointermove", (f) => {
701
+ const o = it.current(f.global.x, f.global.y);
702
+ if (Pe.current = o, F.current?.multiTouchActive) return;
703
+ const i = Kt.current;
704
+ if (i === "freehand" || i === "line" || i === "polyline" || i === "arrow") return;
705
+ const p = W.current.nodes, N = W.current.edges, k = F.current?.state.zoom ?? 1, z = !st.current?.active && !tt.current?.active && !yt.current?.active && !ct.current?.active && !lt.current?.active && !gt.current?.active;
706
+ let b = null;
707
+ for (let c = p.length - 1; c >= 0; c--) if (Yt(o.x, o.y, p[c])) {
708
+ const h = p[c];
709
+ b = h.parentId ? p.find((u) => u.id === h.parentId)?.id ?? h.id : h.id;
700
710
  break;
701
711
  }
702
- if (ne.current = S, m && (d === "select" || d === "connect")) {
703
- const o = /* @__PURE__ */ new Map();
704
- for (const x of p) o.set(x.id, x);
705
- const f = Zt.current, u = f.edgeIds.size > 0 ? D.filter((x) => f.edgeIds.has(x.id)) : [], e = u.length > 0 ? $e(r.x, r.y, u, o, Math.min(12 / E, 18)) : null;
706
- pe.current = e;
707
- let v = null;
708
- if (S) {
709
- const x = p.find((t) => t.id === S);
712
+ if (oe.current = b, z && (i === "select" || i === "connect")) {
713
+ const c = /* @__PURE__ */ new Map();
714
+ for (const x of p) c.set(x.id, x);
715
+ const h = Bt.current, u = h.edgeIds.size > 0 ? N.filter((x) => h.edgeIds.has(x.id)) : [], n = u.length > 0 ? en(o.x, o.y, u, c, $(k, 12, 18)) : null;
716
+ ge.current = n;
717
+ let g = null;
718
+ if (b) {
719
+ const x = p.find((t) => t.id === b);
710
720
  if (x) {
711
- const t = Gt(vt(x.width, x.height), x, r.x, r.y, Math.min(14 / E, 20));
721
+ const t = At(It(x.width, x.height), x, o.x, o.y, $(k, 14, 20));
712
722
  if (t) {
713
- const s = Ut(t, x);
714
- v = {
723
+ const r = Wt(t, x);
724
+ g = {
715
725
  nodeId: x.id,
716
726
  handleId: t.id,
717
- wx: s.x,
718
- wy: s.y
727
+ wx: r.x,
728
+ wy: r.y
719
729
  };
720
730
  }
721
731
  }
722
732
  }
723
- ye.current = v;
733
+ xe.current = g;
724
734
  }
725
- const Y = z.current;
726
- if (Y && m) {
727
- const o = Zt.current;
728
- let f = "";
729
- if (pe.current) f = "crosshair";
730
- else if (ye.current) f = "crosshair";
731
- else if (o.edgeIds.size > 0 && d === "select") {
732
- const u = D.filter((x) => o.edgeIds.has(x.id)), e = /* @__PURE__ */ new Map();
733
- for (const x of p) e.set(x.id, x);
734
- const v = Math.min(10 / E, 14);
735
- (Je(r.x, r.y, u, v) || Qe(r.x, r.y, u, e, v)) && (f = "grab");
735
+ const T = S.current;
736
+ if (T && z) {
737
+ const c = Bt.current;
738
+ let h = "";
739
+ if (ge.current) h = "crosshair";
740
+ else if (xe.current) h = "crosshair";
741
+ else if (c.edgeIds.size > 0 && i === "select") {
742
+ const u = N.filter((x) => c.edgeIds.has(x.id)), n = /* @__PURE__ */ new Map();
743
+ for (const x of p) n.set(x.id, x);
744
+ const g = $(k, 10, 14);
745
+ (nn(o.x, o.y, u, g) || rn(o.x, o.y, u, n, g)) && (h = "grab");
736
746
  }
737
- if (!f && o.nodeIds.size === 1 && d === "select") {
738
- const u = p.find((e) => e.id === [...o.nodeIds][0]);
747
+ if (!h && c.nodeIds.size === 1 && i === "select") {
748
+ const u = p.find((n) => n.id === [...c.nodeIds][0]);
739
749
  if (u) {
740
- const e = je(r, u, Math.min(10 / E, 16));
741
- e && (f = bn[e]);
750
+ const n = tn(o, u, $(k, 10, 16));
751
+ n && (h = zn[n]);
742
752
  }
743
753
  }
744
- if (!f && d === "select") {
745
- const u = W.current.lines, e = Math.min(8 / E, 12);
746
- for (const v of u) if (tn(r.x, r.y, v, e)) {
747
- f = "move";
754
+ if (!h && i === "select") {
755
+ const u = W.current.lines, n = $(k, 8, 12);
756
+ for (const g of u) if (on(o.x, o.y, g, n)) {
757
+ h = "move";
748
758
  break;
749
759
  }
750
760
  }
751
- Y.style.cursor = f;
761
+ T.style.cursor = h;
752
762
  }
753
- if (ht.current?.active) {
754
- const o = ht.current, f = r.x - o.startWorld.x, u = r.y - o.startWorld.y, e = Rn(o.startBounds, o.handle, f, u), v = W.current.nodes, x = ae([{
755
- id: o.nodeId,
763
+ if (yt.current?.active) {
764
+ const c = yt.current, h = o.x - c.startWorld.x, u = o.y - c.startWorld.y, n = En(c.startBounds, c.handle, h, u), g = W.current.nodes, x = le([{
765
+ id: c.nodeId,
756
766
  type: "shapeRect",
757
767
  position: {
758
- x: e.x,
759
- y: e.y
768
+ x: n.x,
769
+ y: n.y
760
770
  },
761
- width: e.w,
762
- height: e.h,
771
+ width: n.w,
772
+ height: n.h,
763
773
  data: {}
764
- }], v);
765
- e.x += x.dx, e.y += x.dy, (o.handle === "ne" || o.handle === "se") && (e.w += x.dx), (o.handle === "se" || o.handle === "sw") && (e.h += x.dy), Dt.current = x.guides;
766
- const t = o.startBounds, s = Math.max(e.w, 24), l = Math.max(e.h, 24), c = t.w > 0 ? s / t.w : 1, n = t.h > 0 ? l / t.h : 1;
767
- J((i) => {
768
- const I = i.canvases[B.current];
769
- return I ? {
770
- ...i,
774
+ }], g);
775
+ n.x += x.dx, n.y += x.dy, (c.handle === "ne" || c.handle === "se") && (n.w += x.dx), (c.handle === "se" || c.handle === "sw") && (n.h += x.dy), Dt.current = x.guides;
776
+ const t = c.startBounds, r = Math.max(n.w, 24), d = Math.max(n.h, 24), a = t.w > 0 ? r / t.w : 1, e = t.h > 0 ? d / t.h : 1;
777
+ J((s) => {
778
+ const w = s.canvases[B.current];
779
+ return w ? {
780
+ ...s,
771
781
  canvases: {
772
- ...i.canvases,
782
+ ...s.canvases,
773
783
  [B.current]: {
774
- ...I,
775
- nodes: I.nodes.map((g) => {
776
- if (g.id === o.nodeId) return {
777
- ...g,
784
+ ...w,
785
+ nodes: w.nodes.map((m) => {
786
+ if (m.id === c.nodeId) return {
787
+ ...m,
778
788
  position: {
779
- x: e.x,
780
- y: e.y
789
+ x: n.x,
790
+ y: n.y
781
791
  },
782
- width: s,
783
- height: l
792
+ width: r,
793
+ height: d
784
794
  };
785
- const b = o.childStarts.get(g.id);
786
- return b ? {
787
- ...g,
795
+ const R = c.childStarts.get(m.id);
796
+ return R ? {
797
+ ...m,
788
798
  position: {
789
- x: e.x + (b.x - t.x) * c,
790
- y: e.y + (b.y - t.y) * n
799
+ x: n.x + (R.x - t.x) * a,
800
+ y: n.y + (R.y - t.y) * e
791
801
  },
792
- width: Math.max(b.w * c, 24),
793
- height: Math.max(b.h * n, 24)
794
- } : g;
802
+ width: Math.max(R.w * a, 24),
803
+ height: Math.max(R.h * e, 24)
804
+ } : m;
795
805
  }),
796
- lines: o.childLineStarts ? I.lines.map((g) => {
797
- const b = o.childLineStarts.get(g.id);
798
- return b ? {
799
- ...g,
800
- points: b.map((H) => ({
801
- x: e.x + (H.x - t.x) * c,
802
- y: e.y + (H.y - t.y) * n
806
+ lines: c.childLineStarts ? w.lines.map((m) => {
807
+ const R = c.childLineStarts.get(m.id);
808
+ return R ? {
809
+ ...m,
810
+ points: R.map((G) => ({
811
+ x: n.x + (G.x - t.x) * a,
812
+ y: n.y + (G.y - t.y) * e
803
813
  }))
804
- } : g;
805
- }) : I.lines
814
+ } : m;
815
+ }) : w.lines
806
816
  }
807
817
  }
808
- } : i;
818
+ } : s;
809
819
  });
810
820
  return;
811
821
  }
812
- if (at.current?.active) {
813
- const o = at.current, f = W.current.nodes, u = /* @__PURE__ */ new Map();
814
- for (const e of f) u.set(e.id, e);
815
- J((e) => {
816
- const v = e.canvases[B.current];
817
- return v ? {
818
- ...e,
822
+ if (lt.current?.active) {
823
+ const c = lt.current, h = W.current.nodes, u = /* @__PURE__ */ new Map();
824
+ for (const n of h) u.set(n.id, n);
825
+ J((n) => {
826
+ const g = n.canvases[B.current];
827
+ return g ? {
828
+ ...n,
819
829
  canvases: {
820
- ...e.canvases,
830
+ ...n.canvases,
821
831
  [B.current]: {
822
- ...v,
823
- edges: v.edges.map((x) => {
824
- if (x.id !== o.edgeId) return x;
825
- if (o.type === "waypoint") {
826
- const Pt = [...x.data.waypoints ?? []];
827
- return o.index < Pt.length && (Pt[o.index] = {
828
- x: r.x,
829
- y: r.y
832
+ ...g,
833
+ edges: g.edges.map((x) => {
834
+ if (x.id !== c.edgeId) return x;
835
+ if (c.type === "waypoint") {
836
+ const Gt = [...x.data.waypoints ?? []];
837
+ return c.index < Gt.length && (Gt[c.index] = {
838
+ x: o.x,
839
+ y: o.y
830
840
  }), {
831
841
  ...x,
832
842
  data: {
833
843
  ...x.data,
834
- waypoints: Pt
844
+ waypoints: Gt
835
845
  }
836
846
  };
837
847
  }
838
- const t = Et(x, u);
848
+ const t = Mt(x, u);
839
849
  if (!t) return x;
840
- const s = x.data.waypoints ?? [], l = [
850
+ const r = x.data.waypoints ?? [], d = [
841
851
  {
842
852
  x: t.sx,
843
853
  y: t.sy
844
854
  },
845
- ...s,
855
+ ...r,
846
856
  {
847
857
  x: t.tx,
848
858
  y: t.ty
849
859
  }
850
- ], c = l.length - 1, n = [...x.data.bezierControls ?? []];
851
- for (; n.length < c; ) n.push(null);
852
- const i = o.index;
853
- if (i >= c) return x;
854
- const I = l[i], g = l[i + 1], b = n[i], H = Math.hypot(g.x - I.x, g.y - I.y), y = Math.max(30, H * 0.3), M = c - 1, j = i === 0 ? I.x + t.snx * y : I.x + (g.x - I.x) * 0.4, $ = i === 0 ? I.y + t.sny * y : I.y, ie = i === M ? g.x + t.tnx * y : g.x - (g.x - I.x) * 0.4, de = i === M ? g.y + t.tny * y : g.y;
855
- return o.type === "bezierC1" ? n[i] = {
856
- c1x: r.x,
857
- c1y: r.y,
858
- c2x: b?.c2x ?? ie,
859
- c2y: b?.c2y ?? de
860
- } : n[i] = {
861
- c1x: b?.c1x ?? j,
862
- c1y: b?.c1y ?? $,
863
- c2x: r.x,
864
- c2y: r.y
860
+ ], a = d.length - 1, e = [...x.data.bezierControls ?? []];
861
+ for (; e.length < a; ) e.push(null);
862
+ const s = c.index;
863
+ if (s >= a) return x;
864
+ const w = d[s], m = d[s + 1], R = e[s], G = Math.hypot(m.x - w.x, m.y - w.y), y = Math.max(30, G * 0.3), v = a - 1, U = s === 0 ? w.x + t.snx * y : w.x + (m.x - w.x) * 0.4, et = s === 0 ? w.y + t.sny * y : w.y, Lt = s === v ? m.x + t.tnx * y : m.x - (m.x - w.x) * 0.4, ae = s === v ? m.y + t.tny * y : m.y;
865
+ return c.type === "bezierC1" ? e[s] = {
866
+ c1x: o.x,
867
+ c1y: o.y,
868
+ c2x: R?.c2x ?? Lt,
869
+ c2y: R?.c2y ?? ae
870
+ } : e[s] = {
871
+ c1x: R?.c1x ?? U,
872
+ c1y: R?.c1y ?? et,
873
+ c2x: o.x,
874
+ c2y: o.y
865
875
  }, {
866
876
  ...x,
867
877
  data: {
868
878
  ...x.data,
869
- bezierControls: n
879
+ bezierControls: e
870
880
  }
871
881
  };
872
882
  })
873
883
  }
874
884
  }
875
- } : e;
885
+ } : n;
876
886
  });
877
887
  return;
878
888
  }
879
- if (xt.current?.active) {
880
- const o = xt.current, f = r.x - o.startWorld.x, u = r.y - o.startWorld.y;
881
- J((e) => {
882
- const v = e.canvases[B.current];
883
- return v ? {
884
- ...e,
889
+ if (gt.current?.active) {
890
+ const c = gt.current, h = o.x - c.startWorld.x, u = o.y - c.startWorld.y;
891
+ J((n) => {
892
+ const g = n.canvases[B.current];
893
+ return g ? {
894
+ ...n,
885
895
  canvases: {
886
- ...e.canvases,
896
+ ...n.canvases,
887
897
  [B.current]: {
888
- ...v,
889
- lines: v.lines.map((x) => {
890
- const t = o.pointStarts.get(x.id);
898
+ ...g,
899
+ lines: g.lines.map((x) => {
900
+ const t = c.pointStarts.get(x.id);
891
901
  return t ? {
892
902
  ...x,
893
- points: t.map((s) => ({
894
- x: s.x + f,
895
- y: s.y + u
903
+ points: t.map((r) => ({
904
+ x: r.x + h,
905
+ y: r.y + u
896
906
  }))
897
907
  } : x;
898
908
  })
899
909
  }
900
910
  }
901
- } : e;
911
+ } : n;
902
912
  });
903
913
  return;
904
914
  }
905
- if (ot.current?.active) {
906
- const o = ot.current, f = r.x - o.startWorld.x, u = r.y - o.startWorld.y, e = W.current.nodes, v = ae(e.filter((s) => o.nodeIds.has(s.id)).map((s) => {
907
- const l = o.nodeStarts.get(s.id);
915
+ if (st.current?.active) {
916
+ const c = st.current, h = o.x - c.startWorld.x, u = o.y - c.startWorld.y, n = W.current.nodes, g = le(n.filter((r) => c.nodeIds.has(r.id)).map((r) => {
917
+ const d = c.nodeStarts.get(r.id);
908
918
  return {
909
- ...s,
919
+ ...r,
910
920
  position: {
911
- x: l.x + f,
912
- y: l.y + u
921
+ x: d.x + h,
922
+ y: d.y + u
913
923
  }
914
924
  };
915
- }), e), x = f + v.dx, t = u + v.dy;
916
- Dt.current = v.guides, J((s) => {
917
- const l = s.canvases[B.current];
918
- return l ? {
919
- ...s,
925
+ }), n), x = h + g.dx, t = u + g.dy;
926
+ Dt.current = g.guides, J((r) => {
927
+ const d = r.canvases[B.current];
928
+ return d ? {
929
+ ...r,
920
930
  canvases: {
921
- ...s.canvases,
931
+ ...r.canvases,
922
932
  [B.current]: {
923
- ...l,
924
- nodes: l.nodes.map((c) => {
925
- const n = o.nodeStarts.get(c.id);
926
- return n ? {
927
- ...c,
933
+ ...d,
934
+ nodes: d.nodes.map((a) => {
935
+ const e = c.nodeStarts.get(a.id);
936
+ return e ? {
937
+ ...a,
928
938
  position: {
929
- x: n.x + x,
930
- y: n.y + t
939
+ x: e.x + x,
940
+ y: e.y + t
931
941
  }
932
- } : c;
942
+ } : a;
933
943
  }),
934
- lines: o.linePointStarts ? l.lines.map((c) => {
935
- const n = o.linePointStarts.get(c.id);
936
- return n ? {
937
- ...c,
938
- points: n.map((i) => ({
939
- x: i.x + x,
940
- y: i.y + t
944
+ lines: c.linePointStarts ? d.lines.map((a) => {
945
+ const e = c.linePointStarts.get(a.id);
946
+ return e ? {
947
+ ...a,
948
+ points: e.map((s) => ({
949
+ x: s.x + x,
950
+ y: s.y + t
941
951
  }))
942
- } : c;
943
- }) : l.lines
952
+ } : a;
953
+ }) : d.lines
944
954
  }
945
955
  }
946
- } : s;
956
+ } : r;
947
957
  });
948
958
  return;
949
959
  }
950
- if (Q.current?.active && St.current) {
951
- const o = Math.min(Q.current.startScreen.x, h.global.x), f = Math.min(Q.current.startScreen.y, h.global.y), u = Math.abs(h.global.x - Q.current.startScreen.x), e = Math.abs(h.global.y - Q.current.startScreen.y);
952
- St.current.showMarquee(o, f, u, e);
960
+ if (Q.current?.active && Ct.current) {
961
+ const c = Math.min(Q.current.startScreen.x, f.global.x), h = Math.min(Q.current.startScreen.y, f.global.y), u = Math.abs(f.global.x - Q.current.startScreen.x), n = Math.abs(f.global.y - Q.current.startScreen.y);
962
+ Ct.current.showMarquee(c, h, u, n);
953
963
  }
954
- if (tt.current?.active && pt.current) {
955
- const o = W.current.nodes.find((f) => f.id === tt.current.sourceNodeId);
956
- if (o) {
957
- const f = vt(o.width, o.height).find((u) => u.id === tt.current.sourceHandleId);
958
- if (f) {
959
- const u = Ut(f, o), e = u.x, v = u.y;
960
- let x = r.x, t = r.y;
961
- const s = ne.current;
962
- if (s && s !== tt.current.sourceNodeId) {
963
- const c = W.current.nodes.find((n) => n.id === s);
964
- if (c) {
965
- const n = Gt(vt(c.width, c.height), c, r.x, r.y, 1 / 0);
966
- if (n) {
967
- const i = Ut(n, c);
968
- x = i.x, t = i.y;
964
+ if (tt.current?.active && xt.current) {
965
+ const c = W.current.nodes.find((h) => h.id === tt.current.sourceNodeId);
966
+ if (c) {
967
+ const h = It(c.width, c.height).find((u) => u.id === tt.current.sourceHandleId);
968
+ if (h) {
969
+ const u = Wt(h, c), n = u.x, g = u.y;
970
+ let x = o.x, t = o.y;
971
+ const r = oe.current;
972
+ if (r && r !== tt.current.sourceNodeId) {
973
+ const a = W.current.nodes.find((e) => e.id === r);
974
+ if (a) {
975
+ const e = At(It(a.width, a.height), a, o.x, o.y, 1 / 0);
976
+ if (e) {
977
+ const s = Wt(e, a);
978
+ x = s.x, t = s.y;
969
979
  }
970
980
  }
971
981
  }
972
- const l = pt.current;
973
- l.clear(), l.moveTo(e, v).lineTo(x, t).stroke({
982
+ const d = xt.current;
983
+ d.clear(), d.moveTo(n, g).lineTo(x, t).stroke({
974
984
  color: 3900150,
975
985
  width: 2,
976
986
  alpha: 0.6
977
- }), l.visible = !0;
987
+ }), d.visible = !0;
978
988
  }
979
989
  }
980
990
  }
981
- if (st.current?.active && pt.current && !pt.current.destroyed) {
982
- const o = st.current, f = W.current.nodes.find((u) => u.id === o.fixedNodeId);
983
- if (f) {
984
- const u = vt(f.width, f.height).find((n) => n.id === o.fixedHandleId), e = u ? Ut(u, f) : {
985
- x: f.position.x + f.width / 2,
986
- y: f.position.y + f.height / 2
987
- }, v = e.x, x = e.y;
988
- let t = r.x, s = r.y;
989
- const l = ne.current;
990
- if (l && l !== o.fixedNodeId) {
991
- const n = W.current.nodes.find((i) => i.id === l);
992
- if (n) {
993
- const i = Gt(vt(n.width, n.height), n, r.x, r.y, 1 / 0);
994
- if (i) {
995
- const I = Ut(i, n);
996
- t = I.x, s = I.y;
991
+ if (ct.current?.active && xt.current && !xt.current.destroyed) {
992
+ const c = ct.current, h = W.current.nodes.find((u) => u.id === c.fixedNodeId);
993
+ if (h) {
994
+ const u = It(h.width, h.height).find((e) => e.id === c.fixedHandleId), n = u ? Wt(u, h) : {
995
+ x: h.position.x + h.width / 2,
996
+ y: h.position.y + h.height / 2
997
+ }, g = n.x, x = n.y;
998
+ let t = o.x, r = o.y;
999
+ const d = oe.current;
1000
+ if (d && d !== c.fixedNodeId) {
1001
+ const e = W.current.nodes.find((s) => s.id === d);
1002
+ if (e) {
1003
+ const s = At(It(e.width, e.height), e, o.x, o.y, 1 / 0);
1004
+ if (s) {
1005
+ const w = Wt(s, e);
1006
+ t = w.x, r = w.y;
997
1007
  }
998
1008
  }
999
1009
  }
1000
- const c = pt.current;
1001
- c.clear(), c.moveTo(v, x).lineTo(t, s).stroke({
1010
+ const a = xt.current;
1011
+ a.clear(), a.moveTo(g, x).lineTo(t, r).stroke({
1002
1012
  color: 16347926,
1003
1013
  width: 2,
1004
1014
  alpha: 0.7
1005
- }), c.visible = !0;
1015
+ }), a.visible = !0;
1006
1016
  }
1007
1017
  }
1008
1018
  });
1009
- const zt = () => {
1019
+ const Et = () => {
1010
1020
  Dt.current = [];
1011
1021
  try {
1012
- re.current?.clear();
1022
+ se.current?.clear();
1013
1023
  } catch {
1014
1024
  }
1015
1025
  try {
1016
- const h = pt.current;
1017
- h && !h.destroyed && (h.clear(), h.visible = !1);
1026
+ const f = xt.current;
1027
+ f && !f.destroyed && (f.clear(), f.visible = !1);
1018
1028
  } catch {
1019
1029
  }
1020
- z.current && (z.current.style.cursor = "");
1030
+ S.current && (S.current.style.cursor = "");
1021
1031
  };
1022
- mt.on("pointerup", (h) => {
1023
- if (zt(), at.current?.active) {
1024
- at.current = null;
1032
+ vt.on("pointerup", (f) => {
1033
+ if (Et(), lt.current?.active) {
1034
+ lt.current = null;
1025
1035
  return;
1026
1036
  }
1027
- if (ht.current?.active) {
1028
- ht.current = null;
1037
+ if (yt.current?.active) {
1038
+ yt.current = null;
1029
1039
  return;
1030
1040
  }
1031
- if (xt.current?.active) {
1032
- xt.current = null;
1041
+ if (gt.current?.active) {
1042
+ gt.current = null;
1033
1043
  return;
1034
1044
  }
1035
- if (ot.current?.active && (ot.current = null, se.current()), Q.current?.active) {
1036
- const r = ct.current(Q.current.startScreen.x, Q.current.startScreen.y), d = ct.current(h.global.x, h.global.y), p = Math.min(r.x, d.x), D = Math.min(r.y, d.y), E = Math.abs(d.x - r.x), m = Math.abs(d.y - r.y);
1037
- if (E > 4 && m > 4) {
1038
- const S = W.current.nodes.filter((o) => hn(p, D, E, m, o.position.x, o.position.y, o.width, o.height)), Y = W.current.lines.filter((o) => o.points.length === 0 ? !1 : o.points.every((f) => f.x >= p && f.x <= p + E && f.y >= D && f.y <= D + m));
1039
- ft({
1040
- nodeIds: new Set(S.map((o) => o.id)),
1045
+ if (st.current?.active && (st.current = null, ie.current()), Q.current?.active) {
1046
+ const o = it.current(Q.current.startScreen.x, Q.current.startScreen.y), i = it.current(f.global.x, f.global.y), p = Math.min(o.x, i.x), N = Math.min(o.y, i.y), k = Math.abs(i.x - o.x), z = Math.abs(i.y - o.y);
1047
+ if (k > 4 && z > 4) {
1048
+ const b = W.current.nodes.filter((c) => gn(p, N, k, z, c.position.x, c.position.y, c.width, c.height)), T = W.current.lines.filter((c) => c.points.length === 0 ? !1 : c.points.every((h) => h.x >= p && h.x <= p + k && h.y >= N && h.y <= N + z));
1049
+ ht({
1050
+ nodeIds: new Set(b.map((c) => c.id)),
1041
1051
  edgeIds: /* @__PURE__ */ new Set(),
1042
- lineIds: new Set(Y.map((o) => o.id))
1052
+ lineIds: new Set(T.map((c) => c.id))
1043
1053
  });
1044
1054
  }
1045
- Q.current = null, St.current?.hideMarquee();
1055
+ Q.current = null, Ct.current?.hideMarquee();
1046
1056
  }
1047
- if (st.current?.active) {
1048
- const r = st.current.edgeId, d = st.current.movingEnd, p = st.current.fixedNodeId;
1049
- st.current = null;
1050
- const D = ct.current(h.global.x, h.global.y), E = W.current.nodes;
1051
- let m = null;
1052
- for (let S = E.length - 1; S >= 0; S--) if (Lt(D.x, D.y, E[S]) && E[S].id !== p) {
1053
- m = E[S];
1057
+ if (ct.current?.active) {
1058
+ const o = ct.current.edgeId, i = ct.current.movingEnd, p = ct.current.fixedNodeId;
1059
+ ct.current = null;
1060
+ const N = it.current(f.global.x, f.global.y), k = W.current.nodes, z = ue ? $(F.current?.state.zoom ?? 1, 12, 24) : 0;
1061
+ let b = null;
1062
+ for (let T = k.length - 1; T >= 0; T--) if (Yt(N.x, N.y, k[T], z) && k[T].id !== p) {
1063
+ b = k[T];
1054
1064
  break;
1055
1065
  }
1056
- if (m) {
1057
- const S = m.id, Y = Gt(vt(m.width, m.height), m, D.x, D.y, 1 / 0)?.id;
1058
- J((o) => {
1059
- const f = o.canvases[B.current];
1060
- return f ? {
1061
- ...o,
1066
+ if (b) {
1067
+ const T = b.id, c = At(It(b.width, b.height), b, N.x, N.y, 1 / 0)?.id;
1068
+ J((h) => {
1069
+ const u = h.canvases[B.current];
1070
+ return u ? {
1071
+ ...h,
1062
1072
  canvases: {
1063
- ...o.canvases,
1073
+ ...h.canvases,
1064
1074
  [B.current]: {
1065
- ...f,
1066
- edges: f.edges.map((u) => u.id !== r ? u : d === "source" ? {
1067
- ...u,
1068
- source: S,
1069
- sourceHandle: Y
1075
+ ...u,
1076
+ edges: u.edges.map((n) => n.id !== o ? n : i === "source" ? {
1077
+ ...n,
1078
+ source: T,
1079
+ sourceHandle: c
1070
1080
  } : {
1071
- ...u,
1072
- target: S,
1073
- targetHandle: Y
1081
+ ...n,
1082
+ target: T,
1083
+ targetHandle: c
1074
1084
  })
1075
1085
  }
1076
1086
  }
1077
- } : o;
1087
+ } : h;
1078
1088
  });
1079
1089
  }
1080
1090
  return;
1081
1091
  }
1082
1092
  if (tt.current?.active) {
1083
- const r = tt.current.sourceNodeId, d = tt.current.sourceHandleId;
1093
+ const o = tt.current.sourceNodeId, i = tt.current.sourceHandleId;
1084
1094
  tt.current = null;
1085
- const p = ct.current(h.global.x, h.global.y), D = W.current.nodes;
1086
- let E = null;
1087
- for (let m = D.length - 1; m >= 0; m--) if (Lt(p.x, p.y, D[m]) && D[m].id !== r) {
1088
- E = D[m];
1095
+ const p = it.current(f.global.x, f.global.y), N = W.current.nodes, k = ue ? $(F.current?.state.zoom ?? 1, 12, 24) : 0;
1096
+ let z = null;
1097
+ for (let b = N.length - 1; b >= 0; b--) if (Yt(p.x, p.y, N[b], k) && N[b].id !== o) {
1098
+ z = N[b];
1089
1099
  break;
1090
1100
  }
1091
- if (E) {
1092
- const m = E.id, S = Gt(vt(E.width, E.height), E, p.x, p.y, 1 / 0)?.id, Y = `edge_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 6)}`, o = Ge.current;
1093
- J((f) => {
1094
- const u = f.canvases[B.current];
1095
- return !u || u.edges.some((e) => e.source === r && e.target === m && e.sourceHandle === d && e.targetHandle === S) ? f : {
1096
- ...f,
1101
+ if (z) {
1102
+ const b = z.id, T = At(It(z.width, z.height), z, p.x, p.y, 1 / 0)?.id, c = `edge_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 6)}`, h = Ae.current;
1103
+ J((u) => {
1104
+ const n = u.canvases[B.current];
1105
+ return !n || n.edges.some((g) => g.source === o && g.target === b && g.sourceHandle === i && g.targetHandle === T) ? u : {
1106
+ ...u,
1097
1107
  canvases: {
1098
- ...f.canvases,
1108
+ ...u.canvases,
1099
1109
  [B.current]: {
1100
- ...u,
1101
- edges: [...u.edges, {
1102
- id: Y,
1103
- source: r,
1104
- target: m,
1105
- sourceHandle: d,
1106
- targetHandle: S,
1107
- type: o,
1110
+ ...n,
1111
+ edges: [...n.edges, {
1112
+ id: c,
1113
+ source: o,
1114
+ target: b,
1115
+ sourceHandle: i,
1116
+ targetHandle: T,
1117
+ type: h,
1108
1118
  data: {
1109
1119
  strokeColor: "theme:base-content",
1110
1120
  strokeWidth: 2,
@@ -1118,95 +1128,95 @@ function Bn({ onPixiReady: _ }) {
1118
1128
  });
1119
1129
  }
1120
1130
  }
1121
- }), mt.on("pointerupoutside", () => {
1122
- zt(), ot.current?.active && se.current(), ot.current = null, ht.current = null, Q.current = null, st.current = null, tt.current = null, at.current = null, xt.current = null, St.current?.hideMarquee();
1131
+ }), vt.on("pointerupoutside", () => {
1132
+ Et(), st.current?.active && ie.current(), st.current = null, yt.current = null, Q.current = null, ct.current = null, tt.current = null, lt.current = null, gt.current = null, Ct.current?.hideMarquee();
1123
1133
  });
1124
- const Ct = z.current;
1125
- let ut = null;
1126
- const Kt = (h) => {
1127
- const r = Ct.getBoundingClientRect(), d = h[0].clientX, p = h[0].clientY, D = h[1].clientX, E = h[1].clientY;
1134
+ const Nt = S.current;
1135
+ let ft = null;
1136
+ const $t = (f) => {
1137
+ const o = Nt.getBoundingClientRect(), i = f[0].clientX, p = f[0].clientY, N = f[1].clientX, k = f[1].clientY;
1128
1138
  return {
1129
- dist: Math.hypot(D - d, E - p),
1130
- midX: (d + D) / 2 - r.left,
1131
- midY: (p + E) / 2 - r.top
1139
+ dist: Math.hypot(N - i, k - p),
1140
+ midX: (i + N) / 2 - o.left,
1141
+ midY: (p + k) / 2 - o.top
1132
1142
  };
1133
- }, Me = () => {
1134
- zt(), ot.current?.active && se.current(), ot.current = null, ht.current = null, Q.current = null, st.current = null, tt.current = null, at.current = null, xt.current = null, St.current?.hideMarquee(), Z.current?.cancelPan();
1135
- }, _e = (h) => {
1136
- if (h.touches.length < 2) return;
1137
- const r = Z.current;
1138
- r && (r.multiTouchActive = !0, Me(), ut = Kt(h.touches), h.preventDefault());
1139
- }, qe = (h) => {
1140
- if (!ut || h.touches.length < 2) return;
1141
- h.preventDefault();
1142
- const r = Z.current;
1143
- if (!r) return;
1144
- const d = Kt(h.touches), p = d.dist / Math.max(1, ut.dist);
1145
- Number.isFinite(p) && p > 0 && r.zoomAt(d.midX, d.midY, p), r.setState({
1146
- x: r.state.x + (d.midX - ut.midX),
1147
- y: r.state.y + (d.midY - ut.midY)
1148
- }), ut = d;
1149
- }, Re = (h) => {
1150
- if (h.touches.length >= 2) {
1151
- ut = Kt(h.touches);
1143
+ }, Se = () => {
1144
+ Et(), st.current?.active && ie.current(), st.current = null, yt.current = null, Q.current = null, ct.current = null, tt.current = null, lt.current = null, gt.current = null, Ct.current?.hideMarquee(), F.current?.cancelPan();
1145
+ }, qe = (f) => {
1146
+ if (f.touches.length < 2) return;
1147
+ const o = F.current;
1148
+ o && (o.multiTouchActive = !0, Se(), ft = $t(f.touches), f.preventDefault());
1149
+ }, Ze = (f) => {
1150
+ if (!ft || f.touches.length < 2) return;
1151
+ f.preventDefault();
1152
+ const o = F.current;
1153
+ if (!o) return;
1154
+ const i = $t(f.touches), p = i.dist / Math.max(1, ft.dist);
1155
+ Number.isFinite(p) && p > 0 && o.zoomAt(i.midX, i.midY, p), o.setState({
1156
+ x: o.state.x + (i.midX - ft.midX),
1157
+ y: o.state.y + (i.midY - ft.midY)
1158
+ }), ft = i;
1159
+ }, ze = (f) => {
1160
+ if (f.touches.length >= 2) {
1161
+ ft = $t(f.touches);
1152
1162
  return;
1153
1163
  }
1154
- if (ut = null, h.touches.length === 0) {
1155
- const r = Z.current;
1156
- r && (r.multiTouchActive = !1), Te.current = performance.now() + 350;
1164
+ if (ft = null, f.touches.length === 0) {
1165
+ const o = F.current;
1166
+ o && (o.multiTouchActive = !1), He.current = performance.now() + 350;
1157
1167
  }
1158
1168
  };
1159
- Ct?.addEventListener("touchstart", _e, { passive: !1 }), Ct?.addEventListener("touchmove", qe, { passive: !1 }), Ct?.addEventListener("touchend", Re), Ct?.addEventListener("touchcancel", Re), X = _e, L = qe, O = Re, mt.on("rightclick", (h) => {
1160
- if (h.preventDefault?.(), Z.current?.didRightPan) return;
1161
- const r = ct.current(h.global.x, h.global.y), d = W.current.nodes;
1169
+ Nt?.addEventListener("touchstart", qe, { passive: !1 }), Nt?.addEventListener("touchmove", Ze, { passive: !1 }), Nt?.addEventListener("touchend", ze), Nt?.addEventListener("touchcancel", ze), X = qe, A = Ze, Z = ze, vt.on("rightclick", (f) => {
1170
+ if (f.preventDefault?.(), F.current?.didRightPan) return;
1171
+ const o = it.current(f.global.x, f.global.y), i = W.current.nodes;
1162
1172
  let p = null;
1163
- for (let S = d.length - 1; S >= 0; S--) if (Lt(r.x, r.y, d[S])) {
1164
- p = d[S].id;
1173
+ for (let b = i.length - 1; b >= 0; b--) if (Yt(o.x, o.y, i[b])) {
1174
+ p = i[b].id;
1165
1175
  break;
1166
1176
  }
1167
- const D = h.nativeEvent, E = D?.clientX ?? h.global.x, m = D?.clientY ?? h.global.y;
1168
- Jt({
1169
- x: E,
1170
- y: m,
1177
+ const N = f.nativeEvent, k = N?.clientX ?? f.global.x, z = N?.clientY ?? f.global.y;
1178
+ te({
1179
+ x: k,
1180
+ y: z,
1171
1181
  nodeId: p
1172
1182
  });
1173
- }), mt.on("pointertap", (h) => {
1174
- if (Z.current?.multiTouchActive || performance.now() < Te.current || h.button !== 0) return;
1175
- const r = Date.now(), d = ct.current(h.global.x, h.global.y), p = oe.current;
1183
+ }), vt.on("pointertap", (f) => {
1184
+ if (F.current?.multiTouchActive || performance.now() < He.current || f.button !== 0) return;
1185
+ const o = Date.now(), i = it.current(f.global.x, f.global.y), p = ce.current;
1176
1186
  if (p) {
1177
- const S = fn("node"), Y = d.x - p.width / 2, o = d.y - p.height / 2, f = ae([{
1187
+ const b = xn("node"), T = i.x - p.width / 2, c = i.y - p.height / 2, h = le([{
1178
1188
  id: "__ghost__",
1179
1189
  type: p.type,
1180
1190
  position: {
1181
- x: Y,
1182
- y: o
1191
+ x: T,
1192
+ y: c
1183
1193
  },
1184
1194
  width: p.width,
1185
1195
  height: p.height,
1186
1196
  data: {}
1187
- }], W.current.nodes), u = Y + f.dx, e = o + f.dy;
1188
- J((v) => {
1189
- const x = v.canvases[B.current];
1190
- if (!x) return v;
1197
+ }], W.current.nodes), u = T + h.dx, n = c + h.dy;
1198
+ J((g) => {
1199
+ const x = g.canvases[B.current];
1200
+ if (!x) return g;
1191
1201
  const t = {};
1192
- p.type === "animAnchor" && (t.animIndex = In(v));
1193
- const s = Math.max(0, ...x.nodes.map((l) => l.zIndex ?? 0), ...x.lines.map((l) => l.zIndex ?? 0));
1202
+ p.type === "animAnchor" && (t.animIndex = Sn(g));
1203
+ const r = Math.max(0, ...x.nodes.map((d) => d.zIndex ?? 0), ...x.lines.map((d) => d.zIndex ?? 0));
1194
1204
  return {
1195
- ...v,
1205
+ ...g,
1196
1206
  canvases: {
1197
- ...v.canvases,
1207
+ ...g.canvases,
1198
1208
  [B.current]: {
1199
1209
  ...x,
1200
1210
  nodes: [...x.nodes, {
1201
- id: S,
1211
+ id: b,
1202
1212
  type: p.type,
1203
1213
  position: {
1204
1214
  x: u,
1205
- y: e
1215
+ y: n
1206
1216
  },
1207
1217
  width: p.width,
1208
1218
  height: p.height,
1209
- zIndex: s + 1,
1219
+ zIndex: r + 1,
1210
1220
  data: {
1211
1221
  ...p.data,
1212
1222
  ...t
@@ -1215,48 +1225,48 @@ function Bn({ onPixiReady: _ }) {
1215
1225
  }
1216
1226
  }
1217
1227
  };
1218
- }), ft({
1219
- nodeIds: /* @__PURE__ */ new Set([S]),
1228
+ }), ht({
1229
+ nodeIds: /* @__PURE__ */ new Set([b]),
1220
1230
  edgeIds: /* @__PURE__ */ new Set(),
1221
1231
  lineIds: /* @__PURE__ */ new Set()
1222
- }), Vt.current && window.setTimeout(() => {
1223
- Bt.current(u, e, p.width, p.height, {
1232
+ }), Ut.current && window.setTimeout(() => {
1233
+ jt.current(u, n, p.width, p.height, {
1224
1234
  padding: 80,
1225
1235
  preserveZoom: !0,
1226
1236
  duration: 280
1227
1237
  });
1228
- }, 0), Tt.current = {
1238
+ }, 0), kt.current = {
1229
1239
  time: 0,
1230
1240
  wx: 0,
1231
1241
  wy: 0
1232
1242
  };
1233
1243
  return;
1234
1244
  }
1235
- const D = Tt.current, E = d.x - D.wx, m = d.y - D.wy;
1236
- if (r - D.time < 400 && Math.abs(E) < 10 && Math.abs(m) < 10) {
1237
- const S = W.current.nodes;
1238
- for (let u = S.length - 1; u >= 0; u--) if (Lt(d.x, d.y, S[u])) {
1239
- const e = S[u], v = e.data.childCanvasId;
1240
- if (v) {
1241
- rn(v), Tt.current = {
1245
+ const N = kt.current, k = i.x - N.wx, z = i.y - N.wy;
1246
+ if (o - N.time < 400 && Math.abs(k) < 10 && Math.abs(z) < 10) {
1247
+ const b = W.current.nodes;
1248
+ for (let u = b.length - 1; u >= 0; u--) if (Yt(i.x, i.y, b[u])) {
1249
+ const n = b[u], g = n.data.childCanvasId;
1250
+ if (g) {
1251
+ dn(g), kt.current = {
1242
1252
  time: 0,
1243
1253
  wx: 0,
1244
1254
  wy: 0
1245
1255
  };
1246
1256
  return;
1247
1257
  }
1248
- ce.current("node", e.id, e.data.label ?? ""), Tt.current = {
1258
+ de.current("node", n.id, n.data.label ?? ""), kt.current = {
1249
1259
  time: 0,
1250
1260
  wx: 0,
1251
1261
  wy: 0
1252
1262
  };
1253
1263
  return;
1254
1264
  }
1255
- const Y = W.current.edges, o = /* @__PURE__ */ new Map();
1256
- for (const u of S) o.set(u.id, u);
1257
- const f = Z.current?.state.zoom ?? 1;
1258
- for (let u = Y.length - 1; u >= 0; u--) if (ze(d.x, d.y, Y[u], o, Math.min(8 / f, 12))) {
1259
- ce.current("edge", Y[u].id, Y[u].data.labelText ?? ""), Tt.current = {
1265
+ const T = W.current.edges, c = /* @__PURE__ */ new Map();
1266
+ for (const u of b) c.set(u.id, u);
1267
+ const h = F.current?.state.zoom ?? 1;
1268
+ for (let u = T.length - 1; u >= 0; u--) if (Ee(i.x, i.y, T[u], c, $(h, 8, 12))) {
1269
+ de.current("edge", T[u].id, T[u].data.labelText ?? ""), kt.current = {
1260
1270
  time: 0,
1261
1271
  wx: 0,
1262
1272
  wy: 0
@@ -1264,39 +1274,39 @@ function Bn({ onPixiReady: _ }) {
1264
1274
  return;
1265
1275
  }
1266
1276
  }
1267
- Tt.current = {
1268
- time: r,
1269
- wx: d.x,
1270
- wy: d.y
1277
+ kt.current = {
1278
+ time: o,
1279
+ wx: i.x,
1280
+ wy: i.y
1271
1281
  };
1272
1282
  });
1273
- let Ze = !1;
1274
- a.app.ticker.add((h) => {
1275
- if (a.destroyed) return;
1276
- const r = h.deltaMS, d = a.app.screen, p = Z.current?.state ?? {
1283
+ let Ve = !1;
1284
+ l.app.ticker.add((f) => {
1285
+ if (l.destroyed) return;
1286
+ const o = f.deltaMS, i = l.app.screen, p = F.current?.state ?? {
1277
1287
  x: 0,
1278
1288
  y: 0,
1279
1289
  zoom: 1
1280
1290
  };
1281
- P.current?.update(p, d.width, d.height);
1282
- const D = Z.current?.isPanning ?? !1;
1283
- D !== Ze && (Ze = D, z.current && (z.current.style.cursor = D ? "grabbing" : ""));
1284
- const E = W.current, m = Zt.current, S = vn(Pe.current), Y = /* @__PURE__ */ new Map();
1285
- S.forEach((t, s) => Y.set(t.node.id, s + 1)), Qt.current?.advanceAnimation(r);
1286
- const o = kt.current ? S[kt.current.current] : void 0;
1287
- Qt.current?.sync(E.nodes, m.nodeIds, ne.current, Y, {
1288
- showAnchors: Le.current,
1289
- presentation: kt.current !== null,
1290
- presentationAnchorId: o?.node.id,
1291
- presentationAnchorVisible: kt.current?.showAnchor ?? !1
1291
+ H.current?.update(p, i.width, i.height);
1292
+ const N = F.current?.isPanning ?? !1;
1293
+ N !== Ve && (Ve = N, S.current && (S.current.style.cursor = N ? "grabbing" : ""));
1294
+ const k = W.current, z = Bt.current, b = Rn(Ge.current), T = /* @__PURE__ */ new Map();
1295
+ b.forEach((t, r) => T.set(t.node.id, r + 1)), ee.current?.advanceAnimation(o);
1296
+ const c = Ht.current ? b[Ht.current.current] : void 0;
1297
+ ee.current?.sync(k.nodes, z.nodeIds, oe.current, T, {
1298
+ showAnchors: We.current,
1299
+ presentation: Ht.current !== null,
1300
+ presentationAnchorId: c?.node.id,
1301
+ presentationAnchorVisible: Ht.current?.showAnchor ?? !1
1292
1302
  });
1293
- const f = /* @__PURE__ */ new Map();
1294
- for (const t of E.nodes) f.set(t.id, t);
1295
- te.current?.advanceAnimation(r), te.current?.sync(E.edges, f, m.edgeIds, null, { presentation: kt.current !== null }), ee.current?.advanceAnimation(r), ee.current?.sync(E.lines, m.lineIds), re.current?.update(Dt.current, d.width, d.height, p);
1296
- const u = Ft.current;
1303
+ const h = /* @__PURE__ */ new Map();
1304
+ for (const t of k.nodes) h.set(t.id, t);
1305
+ ne.current?.advanceAnimation(o), ne.current?.sync(k.edges, h, z.edgeIds, null, { presentation: Ht.current !== null }), re.current?.advanceAnimation(o), re.current?.sync(k.lines, z.lineIds), se.current?.update(Dt.current, i.width, i.height, p);
1306
+ const u = qt.current;
1297
1307
  if (u) {
1298
1308
  u.clear();
1299
- const t = ye.current;
1309
+ const t = xe.current;
1300
1310
  t && (u.circle(t.wx, t.wy, 10).fill({
1301
1311
  color: 3900150,
1302
1312
  alpha: 0.12
@@ -1308,36 +1318,36 @@ function Bn({ onPixiReady: _ }) {
1308
1318
  color: 3900150,
1309
1319
  alpha: 0.9
1310
1320
  }));
1311
- const s = pe.current;
1312
- s && !t && (u.circle(s.worldX, s.worldY, 10).fill({
1321
+ const r = ge.current;
1322
+ r && !t && (u.circle(r.worldX, r.worldY, 10).fill({
1313
1323
  color: 16347926,
1314
1324
  alpha: 0.12
1315
1325
  }).stroke({
1316
1326
  color: 16347926,
1317
1327
  width: 1.5,
1318
1328
  alpha: 0.5
1319
- }), u.circle(s.worldX, s.worldY, 4).fill({
1329
+ }), u.circle(r.worldX, r.worldY, 4).fill({
1320
1330
  color: 16347926,
1321
1331
  alpha: 0.9
1322
1332
  }));
1323
1333
  }
1324
- const e = qt.current;
1325
- if (e) {
1326
- e.clear();
1327
- const t = oe.current;
1334
+ const n = Vt.current;
1335
+ if (n) {
1336
+ n.clear();
1337
+ const t = ce.current;
1328
1338
  if (t) {
1329
- const s = ke.current, l = s.x - t.width / 2, c = s.y - t.height / 2, n = ae([{
1339
+ const r = Pe.current, d = r.x - t.width / 2, a = r.y - t.height / 2, e = le([{
1330
1340
  id: "__ghost__",
1331
1341
  type: t.type,
1332
1342
  position: {
1333
- x: l,
1334
- y: c
1343
+ x: d,
1344
+ y: a
1335
1345
  },
1336
1346
  width: t.width,
1337
1347
  height: t.height,
1338
1348
  data: {}
1339
- }], E.nodes);
1340
- Dt.current = n.guides, e.position.set(l + n.dx, c + n.dy), (Be[t.type] ?? Be.shapeRect)(e, {
1349
+ }], k.nodes);
1350
+ Dt.current = e.guides, n.position.set(d + e.dx, a + e.dy), (je[t.type] ?? je.shapeRect)(n, {
1341
1351
  width: t.width,
1342
1352
  height: t.height,
1343
1353
  fill: "#3b82f6",
@@ -1346,46 +1356,54 @@ function Bn({ onPixiReady: _ }) {
1346
1356
  borderStyle: t.data.borderStyle
1347
1357
  });
1348
1358
  } else
1349
- e.position.set(0, 0), !ot.current?.active && !ht.current?.active && (Dt.current = []);
1359
+ n.position.set(0, 0), !st.current?.active && !yt.current?.active && (Dt.current = []);
1350
1360
  }
1351
- const v = _t.current;
1352
- if (v && (v.clear(), m.edgeIds.size > 0 && Ot.current === "select")) {
1361
+ const g = Zt.current;
1362
+ if (g && (g.clear(), z.edgeIds.size > 0 && Kt.current === "select")) {
1353
1363
  const t = 1 / p.zoom;
1354
- for (const s of E.edges) {
1355
- if (!m.edgeIds.has(s.id)) continue;
1356
- const l = s.data.waypoints;
1357
- if (l) for (const c of l) v.circle(c.x, c.y, 5 * t).fill({ color: 16777215 }).stroke({
1364
+ for (const r of k.edges) {
1365
+ if (!z.edgeIds.has(r.id)) continue;
1366
+ const d = Mt(r, h);
1367
+ d && (g.circle(d.sx, d.sy, 5 * t).fill({ color: 16777215 }).stroke({
1368
+ color: 16347926,
1369
+ width: 1.5 * t
1370
+ }), g.circle(d.tx, d.ty, 5 * t).fill({ color: 16777215 }).stroke({
1371
+ color: 16347926,
1372
+ width: 1.5 * t
1373
+ }));
1374
+ const a = r.data.waypoints;
1375
+ if (a) for (const e of a) g.circle(e.x, e.y, 5 * t).fill({ color: 16777215 }).stroke({
1358
1376
  color: 3900150,
1359
1377
  width: 1.5 * t
1360
1378
  });
1361
- if (s.type === "simplebezier") {
1362
- const c = Et(s, f);
1363
- if (!c) continue;
1364
- const n = l ?? [], i = [
1379
+ if (r.type === "simplebezier") {
1380
+ const e = Mt(r, h);
1381
+ if (!e) continue;
1382
+ const s = a ?? [], w = [
1365
1383
  {
1366
- x: c.sx,
1367
- y: c.sy
1384
+ x: e.sx,
1385
+ y: e.sy
1368
1386
  },
1369
- ...n,
1387
+ ...s,
1370
1388
  {
1371
- x: c.tx,
1372
- y: c.ty
1389
+ x: e.tx,
1390
+ y: e.ty
1373
1391
  }
1374
- ], I = s.data.bezierControls, g = i.length - 2;
1375
- for (let b = 0; b <= g; b++) {
1376
- const H = i[b], y = i[b + 1], M = I?.[b], j = Math.hypot(y.x - H.x, y.y - H.y), $ = Math.max(30, j * 0.3), ie = M?.c1x ?? (b === 0 ? H.x + c.snx * $ : H.x + (y.x - H.x) * 0.4), de = M?.c1y ?? (b === 0 ? H.y + c.sny * $ : H.y), Pt = M?.c2x ?? (b === g ? y.x + c.tnx * $ : y.x - (y.x - H.x) * 0.4), Oe = M?.c2y ?? (b === g ? y.y + c.tny * $ : y.y);
1377
- v.moveTo(H.x, H.y).lineTo(ie, de).stroke({
1392
+ ], m = r.data.bezierControls, R = w.length - 2;
1393
+ for (let G = 0; G <= R; G++) {
1394
+ const y = w[G], v = w[G + 1], U = m?.[G], et = Math.hypot(v.x - y.x, v.y - y.y), Lt = Math.max(30, et * 0.3), ae = U?.c1x ?? (G === 0 ? y.x + e.snx * Lt : y.x + (v.x - y.x) * 0.4), Gt = U?.c1y ?? (G === 0 ? y.y + e.sny * Lt : y.y), Be = U?.c2x ?? (G === R ? v.x + e.tnx * Lt : v.x - (v.x - y.x) * 0.4), Ke = U?.c2y ?? (G === R ? v.y + e.tny * Lt : v.y);
1395
+ g.moveTo(y.x, y.y).lineTo(ae, Gt).stroke({
1378
1396
  color: 10265519,
1379
1397
  width: 1 * t
1380
- }), v.moveTo(y.x, y.y).lineTo(Pt, Oe).stroke({
1398
+ }), g.moveTo(v.x, v.y).lineTo(Be, Ke).stroke({
1381
1399
  color: 10265519,
1382
1400
  width: 1 * t
1383
1401
  });
1384
- const Ve = 4 * t;
1385
- v.circle(ie, de, Ve).fill({ color: 16777215 }).stroke({
1402
+ const Ue = 4 * t;
1403
+ g.circle(ae, Gt, Ue).fill({ color: 16777215 }).stroke({
1386
1404
  color: 3900150,
1387
1405
  width: 1.5 * t
1388
- }), v.circle(Pt, Oe, Ve).fill({ color: 16777215 }).stroke({
1406
+ }), g.circle(Be, Ke, Ue).fill({ color: 16777215 }).stroke({
1389
1407
  color: 3900150,
1390
1408
  width: 1.5 * t
1391
1409
  });
@@ -1393,32 +1411,32 @@ function Bn({ onPixiReady: _ }) {
1393
1411
  }
1394
1412
  }
1395
1413
  }
1396
- const x = Xt.current;
1397
- if (x && (x.clear(), m.nodeIds.size === 1 && Ot.current === "select")) {
1398
- const t = [...m.nodeIds][0], s = E.nodes.find((l) => l.id === t);
1399
- if (s) {
1400
- const l = p.zoom, c = s.position.x * l + p.x, n = s.position.y * l + p.y, i = s.width * l, I = s.height * l;
1401
- x.rect(c, n, i, I).stroke({
1414
+ const x = Ot.current;
1415
+ if (x && (x.clear(), z.nodeIds.size === 1 && Kt.current === "select")) {
1416
+ const t = [...z.nodeIds][0], r = k.nodes.find((d) => d.id === t);
1417
+ if (r) {
1418
+ const d = p.zoom, a = r.position.x * d + p.x, e = r.position.y * d + p.y, s = r.width * d, w = r.height * d;
1419
+ x.rect(a, e, s, w).stroke({
1402
1420
  color: 3900150,
1403
1421
  width: 1.5
1404
1422
  });
1405
- const g = 7, b = g / 2, H = [
1406
- [c, n],
1407
- [c + i, n],
1408
- [c + i, n + I],
1409
- [c, n + I]
1423
+ const m = 7, R = m / 2, G = [
1424
+ [a, e],
1425
+ [a + s, e],
1426
+ [a + s, e + w],
1427
+ [a, e + w]
1410
1428
  ];
1411
- for (const [j, $] of H) x.rect(j - b, $ - b, g, g).fill({ color: 16777215 }).stroke({
1429
+ for (const [U, et] of G) x.rect(U - R, et - R, m, m).fill({ color: 16777215 }).stroke({
1412
1430
  color: 3900150,
1413
1431
  width: 1.5
1414
1432
  });
1415
- const y = 4, M = [
1416
- [c + i / 2, n],
1417
- [c + i, n + I / 2],
1418
- [c + i / 2, n + I],
1419
- [c, n + I / 2]
1433
+ const y = 4, v = [
1434
+ [a + s / 2, e],
1435
+ [a + s, e + w / 2],
1436
+ [a + s / 2, e + w],
1437
+ [a, e + w / 2]
1420
1438
  ];
1421
- for (const [j, $] of M) x.circle(j, $, y).fill({
1439
+ for (const [U, et] of v) x.circle(U, et, y).fill({
1422
1440
  color: 3900150,
1423
1441
  alpha: 0.9
1424
1442
  });
@@ -1426,78 +1444,78 @@ function Bn({ onPixiReady: _ }) {
1426
1444
  }
1427
1445
  });
1428
1446
  };
1429
- return F(), () => {
1430
- if (k = !0, a && !a.destroyed) try {
1431
- a.app.stage.removeAllListeners();
1447
+ return O(), () => {
1448
+ if (P = !0, l && !l.destroyed) try {
1449
+ l.app.stage.removeAllListeners();
1432
1450
  } catch {
1433
1451
  }
1434
- const A = z.current;
1435
- X && A?.removeEventListener("touchstart", X), L && A?.removeEventListener("touchmove", L), O && (A?.removeEventListener("touchend", O), A?.removeEventListener("touchcancel", O)), P.current?.destroy(), St.current?.destroy(), Qt.current?.destroy(), te.current?.destroy(), ee.current?.destroy(), fe.current?.destroy(), he.current?.destroy(), pt.current?.destroy(), Xt.current && (Xt.current.destroy(), Xt.current = null), Ft.current && (Ft.current.destroy(), Ft.current = null), _t.current && (_t.current.destroy(), _t.current = null), qt.current && (qt.current.destroy(), qt.current = null), re.current?.destroy();
1452
+ const Y = S.current;
1453
+ X && Y?.removeEventListener("touchstart", X), A && Y?.removeEventListener("touchmove", A), Z && (Y?.removeEventListener("touchend", Z), Y?.removeEventListener("touchcancel", Z)), H.current?.destroy(), Ct.current?.destroy(), ee.current?.destroy(), ne.current?.destroy(), re.current?.destroy(), ye.current?.destroy(), pe.current?.destroy(), xt.current?.destroy(), Ot.current && (Ot.current.destroy(), Ot.current = null), qt.current && (qt.current.destroy(), qt.current = null), Zt.current && (Zt.current.destroy(), Zt.current = null), Vt.current && (Vt.current.destroy(), Vt.current = null), se.current?.destroy();
1436
1454
  };
1437
- }, [N.current]), It(() => {
1438
- const a = fe.current, k = he.current;
1439
- if (!(!a || !k))
1440
- switch (a.deactivate(), k.deactivate(), K) {
1455
+ }, [E.current]), bt(() => {
1456
+ const l = ye.current, P = pe.current;
1457
+ if (!(!l || !P))
1458
+ switch (l.deactivate(), P.deactivate(), K) {
1441
1459
  case "freehand":
1442
- a.activate();
1460
+ l.activate();
1443
1461
  break;
1444
1462
  case "line":
1445
- k.activate("straight");
1463
+ P.activate("straight");
1446
1464
  break;
1447
1465
  case "polyline":
1448
- k.activate("polyline");
1466
+ P.activate("polyline");
1449
1467
  break;
1450
1468
  case "arrow":
1451
- k.activate("arrow");
1469
+ P.activate("arrow");
1452
1470
  break;
1453
1471
  }
1454
- }, [K]), It(() => {
1455
- P.current && (P.current.visible = U, P.current.gridSize = et);
1456
- }, [U, et]), It(() => {
1457
- const a = z.current;
1458
- if (!a) return;
1459
- const k = 1e-3, X = (L) => {
1460
- L.preventDefault();
1461
- const O = Z.current;
1462
- if (!O) return;
1463
- const F = a.getBoundingClientRect(), A = L.clientX - F.left, it = L.clientY - F.top, gt = L.ctrlKey ? 3 : 1, wt = -L.deltaY * k * gt;
1464
- O.zoomAt(A, it, 1 + wt);
1472
+ }, [K]), bt(() => {
1473
+ H.current && (H.current.visible = j, H.current.gridSize = nt);
1474
+ }, [j, nt]), bt(() => {
1475
+ const l = S.current;
1476
+ if (!l) return;
1477
+ const P = 1e-3, X = (A) => {
1478
+ A.preventDefault();
1479
+ const Z = F.current;
1480
+ if (!Z) return;
1481
+ const O = l.getBoundingClientRect(), Y = A.clientX - O.left, dt = A.clientY - O.top, wt = A.ctrlKey ? 3 : 1, mt = -A.deltaY * P * wt;
1482
+ Z.zoomAt(Y, dt, 1 + mt);
1465
1483
  };
1466
- return a.addEventListener("wheel", X, { passive: !1 }), () => a.removeEventListener("wheel", X);
1467
- }, [Z]), /* @__PURE__ */ Ue("div", {
1484
+ return l.addEventListener("wheel", X, { passive: !1 }), () => l.removeEventListener("wheel", X);
1485
+ }, [F]), /* @__PURE__ */ Je("div", {
1468
1486
  style: {
1469
1487
  position: "relative",
1470
1488
  width: "100%",
1471
1489
  height: "100%"
1472
1490
  },
1473
1491
  children: [
1474
- /* @__PURE__ */ Se("div", {
1475
- ref: z,
1492
+ /* @__PURE__ */ Ce("div", {
1493
+ ref: S,
1476
1494
  className: "flow-canvas-wrapper",
1477
1495
  tabIndex: -1,
1478
- onContextMenu: (a) => a.preventDefault()
1496
+ onContextMenu: (l) => l.preventDefault()
1479
1497
  }),
1480
- lt && me && /* @__PURE__ */ Se("input", {
1498
+ ut && Ie && /* @__PURE__ */ Ce("input", {
1481
1499
  className: "flow-label-editor",
1482
1500
  autoFocus: !0,
1483
- defaultValue: lt.value,
1501
+ defaultValue: ut.value,
1484
1502
  style: {
1485
- left: me.x,
1486
- top: me.y
1503
+ left: Ie.x,
1504
+ top: Ie.y
1487
1505
  },
1488
- onFocus: (a) => a.currentTarget.select(),
1489
- onKeyDown: (a) => {
1490
- a.key === "Enter" ? (a.preventDefault(), Ye(a.target.value)) : a.key === "Escape" && (a.preventDefault(), on()), a.stopPropagation();
1506
+ onFocus: (l) => l.currentTarget.select(),
1507
+ onKeyDown: (l) => {
1508
+ l.key === "Enter" ? (l.preventDefault(), _e(l.target.value)) : l.key === "Escape" && (l.preventDefault(), an()), l.stopPropagation();
1491
1509
  },
1492
- onBlur: (a) => Ye(a.target.value),
1493
- onPointerDown: (a) => a.stopPropagation()
1510
+ onBlur: (l) => _e(l.target.value),
1511
+ onPointerDown: (l) => l.stopPropagation()
1494
1512
  }),
1495
- Wt && !Mt && /* @__PURE__ */ Ue("button", {
1513
+ Xt && !St && /* @__PURE__ */ Je("button", {
1496
1514
  type: "button",
1497
1515
  className: "flow-esc-button",
1498
- onClick: () => Nt(null),
1516
+ onClick: () => Tt(null),
1499
1517
  title: "取消连续放置 (Esc)",
1500
- children: [/* @__PURE__ */ Se("span", {
1518
+ children: [/* @__PURE__ */ Ce("span", {
1501
1519
  "aria-hidden": !0,
1502
1520
  children: "⎋"
1503
1521
  }), " 取消放置 (ESC)"]
@@ -1506,7 +1524,7 @@ function Bn({ onPixiReady: _ }) {
1506
1524
  });
1507
1525
  }
1508
1526
  export {
1509
- Bn as default
1527
+ $n as default
1510
1528
  };
1511
1529
 
1512
1530
  //# sourceMappingURL=FlowCanvas.js.map