dishui 0.0.55 → 0.0.57

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