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