dishui 0.0.59 → 0.0.60

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