dishui 0.0.59 → 0.0.61

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