dishui 0.0.45 → 0.0.46

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