@mcurcio/patchbay 0.5.0 → 0.7.0

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 (52) hide show
  1. package/README.md +9 -7
  2. package/dist/composites.js +190 -158
  3. package/dist/composites.js.map +1 -1
  4. package/dist/graph.css +1 -1
  5. package/dist/graph.js +639 -63
  6. package/dist/graph.js.map +1 -1
  7. package/dist/primitives.css +1 -1
  8. package/dist/primitives.js +108 -93
  9. package/dist/primitives.js.map +1 -1
  10. package/dist/testing.js +207 -0
  11. package/dist/testing.js.map +1 -0
  12. package/dist/tokens.css +22 -2
  13. package/dist/types/composites/banner/Banner.d.ts +9 -3
  14. package/dist/types/composites/banner/index.d.ts +2 -2
  15. package/dist/types/composites/command-palette/CommandPalette.d.ts +16 -10
  16. package/dist/types/composites/command-palette/index.d.ts +2 -2
  17. package/dist/types/composites/shortcut-sheet/ShortcutSheet.d.ts +17 -11
  18. package/dist/types/composites/shortcut-sheet/index.d.ts +2 -2
  19. package/dist/types/composites/toaster/Toaster.d.ts +15 -9
  20. package/dist/types/composites/toaster/index.d.ts +2 -2
  21. package/dist/types/graph/add-at/index.d.ts +2 -0
  22. package/dist/types/graph/add-at/useAddAt.d.ts +32 -0
  23. package/dist/types/graph/canvas-tools/CanvasTools.d.ts +40 -0
  24. package/dist/types/graph/canvas-tools/index.d.ts +2 -0
  25. package/dist/types/graph/canvas-tools/motion.d.ts +2 -0
  26. package/dist/types/graph/connect-hints/index.d.ts +4 -0
  27. package/dist/types/graph/connect-hints/mergeFlowProps.d.ts +10 -0
  28. package/dist/types/graph/connect-hints/useConnectHints.d.ts +48 -0
  29. package/dist/types/graph/follow-fit/index.d.ts +2 -0
  30. package/dist/types/graph/follow-fit/useFollowFit.d.ts +21 -0
  31. package/dist/types/graph/ghost-wire/GhostWire.d.ts +16 -0
  32. package/dist/types/graph/ghost-wire/index.d.ts +2 -0
  33. package/dist/types/graph/index.d.ts +8 -0
  34. package/dist/types/graph/meter/Meter.d.ts +9 -3
  35. package/dist/types/graph/meter/index.d.ts +2 -2
  36. package/dist/types/graph/node-box/NodeBox.d.ts +52 -0
  37. package/dist/types/graph/node-box/geometry.d.ts +47 -0
  38. package/dist/types/graph/node-box/index.d.ts +4 -0
  39. package/dist/types/graph/port-row/PortRow.d.ts +31 -0
  40. package/dist/types/graph/port-row/index.d.ts +2 -0
  41. package/dist/types/graph/wire/Wire.d.ts +27 -0
  42. package/dist/types/graph/wire/index.d.ts +2 -0
  43. package/dist/types/primitives/dialog/Dialog.d.ts +8 -2
  44. package/dist/types/primitives/dialog/index.d.ts +2 -2
  45. package/dist/types/primitives/sheet/Sheet.d.ts +8 -2
  46. package/dist/types/primitives/sheet/index.d.ts +2 -2
  47. package/dist/types/primitives/splitter/Splitter.d.ts +8 -2
  48. package/dist/types/primitives/splitter/splitter-math.d.ts +12 -4
  49. package/dist/types/testing/brand-css.d.ts +41 -0
  50. package/dist/types/testing/contrast.d.ts +36 -0
  51. package/dist/types/testing/index.d.ts +2 -0
  52. package/package.json +6 -2
package/dist/graph.js CHANGED
@@ -1,123 +1,699 @@
1
- import "./graph.css";import { jsx as e, jsxs as t } from "react/jsx-runtime";
2
- import { useCallback as n, useImperativeHandle as r, useLayoutEffect as i, useState as a } from "react";
3
- import { useLiveValue as o } from "./hooks.js";
1
+ import "./graph.css";import { Fragment as e, jsx as t, jsxs as n } from "react/jsx-runtime";
2
+ import { createContext as r, memo as i, useCallback as a, useContext as o, useEffect as s, useId as c, useImperativeHandle as l, useLayoutEffect as u, useMemo as d, useRef as f, useState as p } from "react";
3
+ import { Badge as m, IconButton as h, ToolGroup as g, WarnMark as _ } from "./primitives.js";
4
+ import { useLiveValue as v } from "./hooks.js";
5
+ import { BaseEdge as y, EdgeLabelRenderer as b, Handle as x, MiniMap as S, Panel as C, Position as w, getBezierPath as T, useNodeId as E, useReactFlow as D, useStore as O, useStoreApi as k, useUpdateNodeInternals as A } from "@xyflow/react";
6
+ // src/graph/add-at/useAddAt.ts
7
+ var j = (e) => e instanceof Element && e.classList.contains("react-flow__pane");
8
+ function ee(e) {
9
+ if ("changedTouches" in e) {
10
+ let t = e.changedTouches[0];
11
+ return t === void 0 ? null : {
12
+ x: t.clientX,
13
+ y: t.clientY
14
+ };
15
+ }
16
+ return {
17
+ x: e.clientX,
18
+ y: e.clientY
19
+ };
20
+ }
21
+ var M = ({ x: e, y: t }) => typeof document.elementFromPoint == "function" ? document.elementFromPoint(e, t) : null;
22
+ function N(e, t = {}) {
23
+ let n = t.enabled ?? !0, { screenToFlowPosition: r } = D(), i = f({
24
+ onAddAt: e,
25
+ enabled: n,
26
+ screenToFlowPosition: r
27
+ });
28
+ u(() => {
29
+ i.current = {
30
+ onAddAt: e,
31
+ enabled: n,
32
+ screenToFlowPosition: r
33
+ };
34
+ });
35
+ let a = f(null);
36
+ return { flowProps: d(() => ({
37
+ onDoubleClick: (e) => {
38
+ let { onAddAt: t, enabled: n, screenToFlowPosition: r } = i.current;
39
+ n && j(e.target) && t(r({
40
+ x: e.clientX,
41
+ y: e.clientY
42
+ }));
43
+ },
44
+ onConnectStart: (e, { nodeId: t, handleId: n, handleType: r }) => {
45
+ a.current = t === null ? null : {
46
+ nodeId: t,
47
+ handleId: n,
48
+ side: r === "target" ? "input" : "output"
49
+ };
50
+ },
51
+ onConnectEnd: (e, t) => {
52
+ let n = a.current;
53
+ a.current = null;
54
+ let { onAddAt: r, enabled: o, screenToFlowPosition: s } = i.current;
55
+ if (!o || n === null || t.toHandle !== null) return;
56
+ let c = ee(e);
57
+ c !== null && j("changedTouches" in e ? M(c) : e.target) && r(s(c), n);
58
+ },
59
+ zoomOnDoubleClick: !1
60
+ }), []) };
61
+ }
62
+ // src/graph/canvas-tools/motion.ts
63
+ var te = 180;
64
+ function P(e) {
65
+ let t = e == null ? "" : getComputedStyle(e).getPropertyValue("--pb-motion-slow"), n = /^\s*(\d+(?:\.\d+)?)(ms|s)\s*$/.exec(t);
66
+ return n === null ? typeof window.matchMedia == "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches ? 0 : te : Number(n[1]) * (n[2] === "s" ? 1e3 : 1);
67
+ }
68
+ // src/graph/canvas-tools/CanvasTools.tsx
69
+ var F = {
70
+ toolbar: "Canvas",
71
+ zoomIn: "Zoom in",
72
+ zoomOut: "Zoom out",
73
+ fit: "Fit the view",
74
+ tidy: "Tidy the layout",
75
+ minimap: "Minimap"
76
+ }, I = (e) => /* @__PURE__ */ t("svg", {
77
+ viewBox: "0 0 16 16",
78
+ width: "14",
79
+ height: "14",
80
+ "aria-hidden": "true",
81
+ children: /* @__PURE__ */ t("path", {
82
+ d: e,
83
+ fill: "none",
84
+ stroke: "currentColor",
85
+ strokeWidth: "1.5",
86
+ strokeLinecap: "round",
87
+ strokeLinejoin: "round"
88
+ })
89
+ }), L = {
90
+ zoomIn: I("M3 8h10M8 3v10"),
91
+ zoomOut: I("M3 8h10"),
92
+ fit: I("M2 6V2h4M10 2h4v4M14 10v4h-4M6 14H2v-4"),
93
+ tidy: I("M2 2h5v5H2zM9 2h5v5H9zM2 9h5v5H2zM9 9h5v5H9z"),
94
+ minimap: I("M1.5 3h13v10h-13zM8.5 8h4v3h-4z")
95
+ };
96
+ function ne({ position: r = "bottom-left", fitOptions: i, onFit: a, onTidy: o, minimap: s = !1, onMinimap: c, minimapNodeClassName: l, keyShortcuts: u, labels: d, className: f, children: p }) {
97
+ let m = {
98
+ ...F,
99
+ ...d
100
+ }, _ = D(), v = k(), y = () => P(v.getState().domNode), b = (e, n, r) => {
101
+ let i = u?.[e];
102
+ return /* @__PURE__ */ t(h, {
103
+ label: m[e],
104
+ title: i === void 0 || i === "" ? m[e] : `${m[e]} (${i})`,
105
+ "aria-keyshortcuts": i === "" ? void 0 : i,
106
+ "aria-pressed": r,
107
+ onClick: n,
108
+ children: L[e]
109
+ });
110
+ };
111
+ return /* @__PURE__ */ n(e, { children: [/* @__PURE__ */ t(C, {
112
+ position: r,
113
+ className: f === void 0 ? "pb-canvas-tools" : `pb-canvas-tools ${f}`,
114
+ children: /* @__PURE__ */ n(g, {
115
+ label: m.toolbar,
116
+ children: [
117
+ b("zoomIn", () => void _.zoomIn({ duration: y() })),
118
+ b("zoomOut", () => void _.zoomOut({ duration: y() })),
119
+ b("fit", () => {
120
+ a === void 0 ? _.fitView({
121
+ ...i,
122
+ duration: y()
123
+ }) : a();
124
+ }),
125
+ o !== void 0 && b("tidy", o),
126
+ c !== void 0 && b("minimap", () => {
127
+ c(!s);
128
+ }, s),
129
+ p
130
+ ]
131
+ })
132
+ }), s && /* @__PURE__ */ t(S, {
133
+ className: "pb-canvas-minimap",
134
+ ariaLabel: m.minimap,
135
+ nodeClassName: l
136
+ })] });
137
+ }
138
+ // src/graph/connect-hints/mergeFlowProps.ts
139
+ function re(...e) {
140
+ let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
141
+ for (let r of e) if (r !== void 0) {
142
+ for (let [e, i] of Object.entries(r)) if (i !== void 0) {
143
+ if (typeof i == "function") {
144
+ let r = n.get(e) ?? [];
145
+ r.push(i), n.set(e, r), t.delete(e);
146
+ } else t.set(e, i), n.delete(e);
147
+ }
148
+ }
149
+ let r = Object.fromEntries(t);
150
+ for (let [e, t] of n) {
151
+ let [n] = t;
152
+ r[e] = t.length === 1 && n !== void 0 ? n : e === "isValidConnection" ? (...e) => t.every((t) => t(...e) === !0) : (...e) => {
153
+ for (let n of t) n(...e);
154
+ };
155
+ }
156
+ return r;
157
+ }
158
+ // src/graph/connect-hints/useConnectHints.tsx
159
+ var R = r(null);
160
+ function ie({ value: e, children: n }) {
161
+ return /* @__PURE__ */ t(R, {
162
+ value: e,
163
+ children: n
164
+ });
165
+ }
166
+ function ae() {
167
+ return o(R);
168
+ }
169
+ var oe = (e, t) => JSON.stringify([
170
+ e.nodeId,
171
+ e.handleId,
172
+ t.nodeId,
173
+ t.handleId
174
+ ]), se = (e, t) => e.nodeId === t.nodeId && e.handleId === t.handleId;
175
+ function ce(e) {
176
+ let t = f(e);
177
+ u(() => {
178
+ t.current = e;
179
+ });
180
+ let n = f(null), [r, i] = p(null), a = d(() => (e, r) => {
181
+ let i = n.current;
182
+ if (i === null) return t.current(e, r);
183
+ let a = oe(e, r), o = i.get(a);
184
+ if (o !== void 0) return o;
185
+ let s = t.current(e, r);
186
+ return i.set(a, s), s;
187
+ }, []), o = d(() => ({
188
+ onConnectStart: (e, { nodeId: t, handleId: r, handleType: a }) => {
189
+ t !== null && (n.current = /* @__PURE__ */ new Map(), i({
190
+ nodeId: t,
191
+ handleId: r,
192
+ side: a === "target" ? "input" : "output"
193
+ }));
194
+ },
195
+ onConnectEnd: () => {
196
+ n.current = null, i(null);
197
+ },
198
+ isValidConnection: (e) => a({
199
+ nodeId: e.source,
200
+ handleId: e.sourceHandle ?? null
201
+ }, {
202
+ nodeId: e.target,
203
+ handleId: e.targetHandle ?? null
204
+ }) === !0
205
+ }), [a]);
206
+ return {
207
+ value: d(() => r === null ? null : {
208
+ origin: r,
209
+ hintFor: (e, t) => {
210
+ if (t === r.side) return { hint: se(e, r) ? "origin" : null };
211
+ let n = {
212
+ nodeId: r.nodeId,
213
+ handleId: r.handleId
214
+ }, i = t === "input" ? a(n, e) : a(e, n);
215
+ return i === !0 ? { hint: "ok" } : typeof i == "string" ? {
216
+ hint: "no",
217
+ reason: i
218
+ } : { hint: "no" };
219
+ }
220
+ }, [r, a]),
221
+ flowProps: o
222
+ };
223
+ }
224
+ // src/graph/follow-fit/useFollowFit.ts
225
+ var z = (e) => {
226
+ for (let t of e.nodeLookup.values()) if (t.hidden !== !0 && (t.measured.width === void 0 || t.measured.height === void 0)) return !1;
227
+ return !0;
228
+ };
229
+ function le({ key: e, fitOptions: t, onFitted: n }) {
230
+ let r = D(), i = k(), o = O((e) => e.width), c = O((e) => e.height), l = O(z), [m, h] = p(!0), g = f({
231
+ key: e,
232
+ width: o,
233
+ height: c,
234
+ fitOptions: t,
235
+ onFitted: n
236
+ });
237
+ u(() => {
238
+ g.current = {
239
+ key: e,
240
+ width: o,
241
+ height: c,
242
+ fitOptions: t,
243
+ onFitted: n
244
+ };
245
+ });
246
+ let _ = f(null), v = a(async (e) => {
247
+ i.getState().nodeLookup.size > 0 && await r.fitView({
248
+ ...g.current.fitOptions,
249
+ duration: e
250
+ }), requestAnimationFrame(() => {
251
+ g.current.onFitted?.(r.getViewport());
252
+ });
253
+ }, [r, i]);
254
+ return s(() => {
255
+ if (!m || o === 0 || c === 0 || !z(i.getState())) return;
256
+ let t = _.current;
257
+ t !== null && Object.is(t.key, e) && t.width === o && t.height === c || (_.current = {
258
+ key: e,
259
+ width: o,
260
+ height: c
261
+ }, v(0));
262
+ }, [
263
+ m,
264
+ e,
265
+ o,
266
+ c,
267
+ l,
268
+ i,
269
+ v
270
+ ]), {
271
+ following: m,
272
+ fit: a(() => {
273
+ let e = g.current;
274
+ _.current = {
275
+ key: e.key,
276
+ width: e.width,
277
+ height: e.height
278
+ }, h(!0), v(P(i.getState().domNode));
279
+ }, [v, i]),
280
+ flowProps: d(() => ({ onMoveStart: (e) => {
281
+ e !== null && h(!1);
282
+ } }), [])
283
+ };
284
+ }
285
+ // src/graph/ghost-wire/GhostWire.tsx
286
+ function B({ id: r, sourceX: i, sourceY: a, targetX: o, targetY: s, sourcePosition: c, targetPosition: l, data: u }) {
287
+ let [f, p, m] = d(() => T({
288
+ sourceX: i,
289
+ sourceY: a,
290
+ sourcePosition: c,
291
+ targetX: o,
292
+ targetY: s,
293
+ targetPosition: l
294
+ }), [
295
+ i,
296
+ a,
297
+ c,
298
+ o,
299
+ s,
300
+ l
301
+ ]), h = u?.tone === "refused" ? "refused" : "pending", g = u?.label;
302
+ return /* @__PURE__ */ n(e, { children: [/* @__PURE__ */ t("g", {
303
+ className: "pb-ghost-wire",
304
+ "data-tone": h,
305
+ "aria-hidden": "true",
306
+ children: /* @__PURE__ */ t(y, {
307
+ id: r,
308
+ path: f,
309
+ className: "pb-ghost-wire-path",
310
+ interactionWidth: 0
311
+ })
312
+ }), g != null && /* @__PURE__ */ t(b, { children: /* @__PURE__ */ t("div", {
313
+ className: "pb-ghost-wire-label",
314
+ "data-tone": h,
315
+ style: { transform: `translate(-50%, -50%) translate(${p}px, ${m}px)` },
316
+ children: g
317
+ }) })] });
318
+ }
4
319
  // src/graph/meter/Meter.tsx
5
- var s = {
320
+ var V = {
6
321
  floor: -60,
7
322
  zones: [-18, -6],
8
323
  holdMs: 1500,
9
324
  fallDbPerS: 20,
10
325
  clipAt: 1,
11
326
  clipHoldMs: 2e3
12
- }, c = 250;
13
- function l(e) {
327
+ }, H = 250;
328
+ function U(e) {
14
329
  return Number.isFinite(e) && e > 0 ? 20 * Math.log10(e) : e === Infinity ? Infinity : -Infinity;
15
330
  }
16
- function u(e, t) {
331
+ function W(e, t) {
17
332
  return Number.isNaN(e) || t >= 0 ? 0 : Math.min(1, Math.max(0, (e - t) / -t));
18
333
  }
19
- var d = (e) => e === -Infinity ? "−∞" : e.toFixed(1), f = (e, t) => `peak ${d(e)} dB, rms ${d(t)} dB`, p = () => ({
334
+ var G = (e) => e === -Infinity ? "−∞" : e.toFixed(1), K = (e, t) => `peak ${G(e)} dB, rms ${G(t)} dB`, q = { title: K }, J = () => ({
20
335
  peakDb: -Infinity,
21
336
  rmsDb: -Infinity,
22
337
  heldDb: -Infinity,
23
338
  heldAt: -Infinity,
24
339
  clippedAt: -Infinity
25
340
  });
26
- function m(e) {
27
- let t = null, n = e, r = p(), i, a = !1, o = -Infinity, s = !1, c = (e) => {
341
+ function ue(e) {
342
+ let t = null, n = e, r = J(), i, a = !1, o = -Infinity, s = !1, c = (e) => {
28
343
  let t = Math.max(0, e - r.heldAt - n.holdMs), i = t === 0 ? r.heldDb : r.heldDb - Math.max(0, n.fallDbPerS) * t / 1e3;
29
344
  return Math.max(r.peakDb, i);
30
- }, d = (e) => {
345
+ }, l = (e) => {
31
346
  if (t === null) return;
32
347
  let i = e - r.clippedAt < n.clipHoldMs;
33
348
  t.title = n.title(r.peakDb, r.rmsDb, i), o = e, s = !1;
34
- }, f = (e) => {
349
+ }, u = (e) => {
35
350
  if (t === null) return !1;
36
- let i = c(e), l = e - r.clippedAt < n.clipHoldMs;
37
- return t.style.setProperty("--pb-meter-level", String(u(r.rmsDb, n.floor))), t.style.setProperty("--pb-meter-tick", String(u(i, n.floor))), t.dataset.peak = i > n.floor ? "shown" : "hidden", t.dataset.clipped = String(l), a && e - o >= 250 && d(e), i > r.peakDb && i > n.floor || l || a && s;
38
- }, m = () => {
39
- i = void 0, f(performance.now()) && (i = requestAnimationFrame(m));
40
- }, h = () => {
41
- i === void 0 && t !== null && (i = requestAnimationFrame(m));
42
- }, g = () => {
351
+ let i = c(e), u = e - r.clippedAt < n.clipHoldMs;
352
+ return t.style.setProperty("--pb-meter-level", String(W(r.rmsDb, n.floor))), t.style.setProperty("--pb-meter-tick", String(W(i, n.floor))), t.dataset.peak = i > n.floor ? "shown" : "hidden", t.dataset.clipped = String(u), a && e - o >= 250 && l(e), i > r.peakDb && i > n.floor || u || a && s;
353
+ }, d = () => {
354
+ i = void 0, u(performance.now()) && (i = requestAnimationFrame(d));
355
+ }, f = () => {
356
+ i === void 0 && t !== null && (i = requestAnimationFrame(d));
357
+ }, p = () => {
43
358
  i !== void 0 && cancelAnimationFrame(i), i = void 0;
44
359
  };
45
360
  return {
46
361
  attach(e) {
47
- t = e, e === null ? g() : h();
362
+ t = e, e === null ? p() : f();
48
363
  },
49
364
  setScale(e) {
50
365
  let t = e.floor !== n.floor || e.holdMs !== n.holdMs || e.fallDbPerS !== n.fallDbPerS || e.clipHoldMs !== n.clipHoldMs;
51
- n = e, t && h();
366
+ n = e, t && f();
52
367
  },
53
368
  take: ([e, t]) => {
54
- let i = performance.now(), a = l(e), o = c(i);
55
- r.peakDb = a, r.rmsDb = l(t), a >= o && (r.heldDb = a, r.heldAt = i), e >= n.clipAt && (r.clippedAt = i), s = !0, h();
369
+ let i = performance.now(), a = U(e), o = c(i);
370
+ r.peakDb = a, r.rmsDb = U(t), a >= o && (r.heldDb = a, r.heldAt = i), e >= n.clipAt && (r.clippedAt = i), s = !0, f();
56
371
  },
57
372
  reset: () => {
58
- r = p(), g();
373
+ r = J(), p();
59
374
  let e = performance.now();
60
- f(e), a && d(e);
375
+ u(e), a && l(e);
61
376
  },
62
377
  hover(e) {
63
- a = e, e && d(performance.now());
378
+ a = e, e && l(performance.now());
64
379
  }
65
380
  };
66
381
  }
67
- function h({ subscribe: c, read: l, orientation: d = "horizontal", floor: p = s.floor, zones: h = s.zones, holdMs: g = s.holdMs, fallDbPerS: _ = s.fallDbPerS, clipAt: v = s.clipAt, clipHoldMs: y = s.clipHoldMs, label: b = "Level", title: x = f, ref: S, className: C, style: w, onPointerEnter: T, onPointerLeave: E, ...D }) {
68
- let [O] = a(() => m({
69
- floor: p,
70
- holdMs: g,
71
- fallDbPerS: _,
72
- clipAt: v,
73
- clipHoldMs: y,
74
- title: x
382
+ function de({ subscribe: e, read: r, orientation: i = "horizontal", floor: o = V.floor, zones: s = V.zones, holdMs: c = V.holdMs, fallDbPerS: d = V.fallDbPerS, clipAt: f = V.clipAt, clipHoldMs: m = V.clipHoldMs, label: h = "Level", labels: g, ref: _, className: y, style: b, onPointerEnter: x, onPointerLeave: S, ...C }) {
383
+ let { title: w } = {
384
+ ...q,
385
+ ...g
386
+ }, [T] = p(() => ue({
387
+ floor: o,
388
+ holdMs: c,
389
+ fallDbPerS: d,
390
+ clipAt: f,
391
+ clipHoldMs: m,
392
+ title: w
75
393
  }));
76
- i(() => {
77
- O.setScale({
78
- floor: p,
79
- holdMs: g,
80
- fallDbPerS: _,
81
- clipAt: v,
82
- clipHoldMs: y,
83
- title: x
394
+ u(() => {
395
+ T.setScale({
396
+ floor: o,
397
+ holdMs: c,
398
+ fallDbPerS: d,
399
+ clipAt: f,
400
+ clipHoldMs: m,
401
+ title: w
84
402
  });
85
403
  });
86
- let k = n((e) => {
87
- O.attach(e);
88
- }, [O]);
89
- o(c, l, O.take), r(S, () => ({ reset: O.reset }), [O]);
90
- let [A, j] = h, M = C === void 0 ? "pb-meter" : `pb-meter ${C}`, N = {
91
- ...w,
92
- "--pb-meter-mid-at": String(u(A, p)),
93
- "--pb-meter-hot-at": String(u(j, p))
404
+ let E = a((e) => {
405
+ T.attach(e);
406
+ }, [T]);
407
+ v(e, r, T.take), l(_, () => ({ reset: T.reset }), [T]);
408
+ let [D, O] = s, k = y === void 0 ? "pb-meter" : `pb-meter ${y}`, A = {
409
+ ...b,
410
+ "--pb-meter-mid-at": String(W(D, o)),
411
+ "--pb-meter-hot-at": String(W(O, o))
94
412
  };
95
- return /* @__PURE__ */ t("div", {
96
- ...D,
97
- ref: k,
98
- className: M,
413
+ return /* @__PURE__ */ n("div", {
414
+ ...C,
415
+ ref: E,
416
+ className: k,
99
417
  role: "img",
100
- "aria-label": b,
101
- "data-orientation": d,
418
+ "aria-label": h,
419
+ "data-orientation": i,
102
420
  "data-peak": "hidden",
103
421
  "data-clipped": "false",
104
- style: N,
422
+ style: A,
105
423
  onPointerEnter: (e) => {
106
- O.hover(!0), T?.(e);
424
+ T.hover(!0), x?.(e);
107
425
  },
108
426
  onPointerLeave: (e) => {
109
- O.hover(!1), E?.(e);
427
+ T.hover(!1), S?.(e);
110
428
  },
111
- children: [/* @__PURE__ */ t("span", {
429
+ children: [/* @__PURE__ */ n("span", {
112
430
  className: "pb-meter-track",
113
431
  "aria-hidden": "true",
114
- children: [/* @__PURE__ */ e("span", { className: "pb-meter-bar" }), /* @__PURE__ */ e("span", { className: "pb-meter-peak" })]
115
- }), /* @__PURE__ */ e("span", {
432
+ children: [/* @__PURE__ */ t("span", { className: "pb-meter-bar" }), /* @__PURE__ */ t("span", { className: "pb-meter-peak" })]
433
+ }), /* @__PURE__ */ t("span", {
116
434
  className: "pb-meter-lamp",
117
435
  "aria-hidden": "true"
118
436
  })]
119
437
  });
120
438
  }
121
- export { h as Meter, s as defaultMeterScale, f as defaultMeterTitle, u as meterFraction, c as meterTitleEveryMs, l as toDb };
439
+ // src/graph/port-row/PortRow.tsx
440
+ var fe = [
441
+ "ok",
442
+ "no",
443
+ "origin"
444
+ ];
445
+ function Y({ id: e, side: r, label: i, typeLabel: a, hint: o, reason: s, problem: c, trailing: l, connectable: u = !0 }) {
446
+ let d = r !== "output", f = ae(), p = E(), m = o === void 0 && f !== null && p !== null ? f.hintFor({
447
+ nodeId: p,
448
+ handleId: e
449
+ }, d ? "input" : "output") : void 0, h = m === void 0 ? o ?? null : m.hint, g = m === void 0 ? s : m.reason ?? s, v = h !== null && fe.includes(h) ? h : void 0, y = v === "no" && g !== void 0 ? g : void 0;
450
+ return /* @__PURE__ */ n("div", {
451
+ className: "pb-port-row",
452
+ "data-side": d ? "input" : "output",
453
+ "data-hint": v,
454
+ title: y ?? (typeof i == "string" ? i : void 0),
455
+ children: [
456
+ /* @__PURE__ */ t(x, {
457
+ id: e,
458
+ type: d ? "target" : "source",
459
+ position: d ? w.Left : w.Right,
460
+ isConnectable: u,
461
+ className: "pb-port-handle",
462
+ "data-hint": v,
463
+ title: y
464
+ }),
465
+ /* @__PURE__ */ n("span", {
466
+ className: "pb-port-words",
467
+ children: [
468
+ /* @__PURE__ */ t("span", {
469
+ className: "pb-port-label",
470
+ children: i
471
+ }),
472
+ a !== void 0 && /* @__PURE__ */ t("code", {
473
+ className: "pb-port-type",
474
+ children: a
475
+ }),
476
+ c !== void 0 && /* @__PURE__ */ t(_, {
477
+ label: c,
478
+ title: c
479
+ })
480
+ ]
481
+ }),
482
+ l !== void 0 && /* @__PURE__ */ t("span", {
483
+ className: "pb-port-trailing",
484
+ children: l
485
+ })
486
+ ]
487
+ });
488
+ }
489
+ // src/graph/node-box/NodeBox.tsx
490
+ var X = {
491
+ added: "added",
492
+ removed: "removed",
493
+ renamed: "renamed",
494
+ changed: "changed"
495
+ }, pe = [
496
+ "added",
497
+ "removed",
498
+ "renamed",
499
+ "changed"
500
+ ];
501
+ function me({ title: e, subtitle: r, tone: i, disabled: a = !1, failed: o = !1, change: s, labels: l, status: u, line: d, inputs: f = [], outputs: p = [], ports: h = "stacked", footer: g, selected: _ = !1, width: v, className: y, style: b, ...x }) {
502
+ let S = c(), C = h === "side-by-side" ? "side-by-side" : "stacked";
503
+ he(f, p, C);
504
+ let w = {
505
+ ...X,
506
+ ...l
507
+ }, T = s === void 0 ? void 0 : pe.includes(s) ? w[s] : s, E = f.length > 0 || p.length > 0, D = f.map((e) => /* @__PURE__ */ t(Y, {
508
+ ...e,
509
+ side: "input"
510
+ }, e.id)), O = p.map((e) => /* @__PURE__ */ t(Y, {
511
+ ...e,
512
+ side: "output"
513
+ }, e.id));
514
+ return /* @__PURE__ */ n("div", {
515
+ ...x,
516
+ className: y === void 0 ? "pb-node-box" : `pb-node-box ${y}`,
517
+ role: "group",
518
+ "aria-labelledby": S,
519
+ "data-tone": i,
520
+ "data-change": s,
521
+ "data-disabled": a ? "" : void 0,
522
+ "data-failed": o ? "" : void 0,
523
+ "data-selected": _ ? "" : void 0,
524
+ style: v === void 0 ? b : {
525
+ ...b,
526
+ width: `${v}px`
527
+ },
528
+ children: [
529
+ /* @__PURE__ */ n("div", {
530
+ className: "pb-node-header",
531
+ children: [
532
+ /* @__PURE__ */ n("div", {
533
+ className: "pb-node-heading",
534
+ children: [/* @__PURE__ */ t("span", {
535
+ id: S,
536
+ className: "pb-node-title",
537
+ title: typeof e == "string" ? e : void 0,
538
+ children: e
539
+ }), r !== void 0 && /* @__PURE__ */ t("span", {
540
+ className: "pb-node-subtitle",
541
+ children: r
542
+ })]
543
+ }),
544
+ T !== void 0 && /* @__PURE__ */ t(m, {
545
+ tone: s ?? "",
546
+ className: "pb-node-change",
547
+ children: T
548
+ }),
549
+ u !== void 0 && /* @__PURE__ */ t("div", {
550
+ className: "pb-node-status",
551
+ children: u
552
+ })
553
+ ]
554
+ }),
555
+ d !== void 0 && /* @__PURE__ */ t("div", {
556
+ className: "pb-node-line",
557
+ title: typeof d == "string" ? d : void 0,
558
+ children: d
559
+ }),
560
+ E && (C === "side-by-side" ? /* @__PURE__ */ n("div", {
561
+ className: "pb-node-ports",
562
+ "data-ports": "side-by-side",
563
+ children: [/* @__PURE__ */ t("div", {
564
+ className: "pb-node-column",
565
+ "data-side": "input",
566
+ children: D
567
+ }), /* @__PURE__ */ t("div", {
568
+ className: "pb-node-column",
569
+ "data-side": "output",
570
+ children: O
571
+ })]
572
+ }) : /* @__PURE__ */ n("div", {
573
+ className: "pb-node-ports",
574
+ "data-ports": "stacked",
575
+ children: [D, O]
576
+ })),
577
+ g !== void 0 && /* @__PURE__ */ t("div", {
578
+ className: "pb-node-footer",
579
+ children: g
580
+ })
581
+ ]
582
+ });
583
+ }
584
+ function he(e, t, n) {
585
+ let r = E(), i = A(), a = JSON.stringify([
586
+ n,
587
+ e.map((e) => e.id),
588
+ t.map((e) => e.id)
589
+ ]), o = f(a);
590
+ s(() => {
591
+ o.current !== a && (o.current = a, r !== null && i(r));
592
+ }, [
593
+ a,
594
+ r,
595
+ i
596
+ ]);
597
+ }
598
+ // src/graph/node-box/geometry.ts
599
+ var ge = 240, _e = 46, ve = 22, ye = 22, be = 8, xe = 28, Se = 10, Z = 20;
600
+ function Ce(e, t, n) {
601
+ return n === "side-by-side" ? Math.max(e, t) : e + t;
602
+ }
603
+ function we({ inputs: e, outputs: t, ports: n, line: r, footer: i, width: a = 240 }) {
604
+ let o = Ce(Math.max(0, e), Math.max(0, t), n);
605
+ return {
606
+ width: a,
607
+ height: 46 + (r ? 22 : 0) + (o > 0 ? 16 + o * 22 : 0) + (i ? 28 : 0)
608
+ };
609
+ }
610
+ // src/graph/wire/Wire.tsx
611
+ var Q = 8, $ = 4;
612
+ function Te(e) {
613
+ return typeof e != "number" || Number.isNaN(e) ? 0 : Math.min(1, Math.max(0, e));
614
+ }
615
+ function Ee(e, t, n) {
616
+ let r = n === w.Left ? -1 : +(n === w.Right), i = n === w.Top ? -1 : +(n === w.Bottom), a = e + r * Q, o = t + i * Q, s = -i * $, c = r * $;
617
+ return `M ${e} ${t} L ${a + s} ${o + c} L ${a - s} ${o - c} Z`;
618
+ }
619
+ var De = i(function({ id: r, path: i, flow: a, arrow: o, title: s, interactionWidth: c, markerStart: l, markerEnd: u, style: d }) {
620
+ return /* @__PURE__ */ n(e, { children: [
621
+ /* @__PURE__ */ t(y, {
622
+ id: r,
623
+ path: i,
624
+ className: "pb-wire-path",
625
+ interactionWidth: 0,
626
+ markerStart: l,
627
+ markerEnd: u,
628
+ style: d
629
+ }),
630
+ a && /* @__PURE__ */ t("path", {
631
+ d: i,
632
+ fill: "none",
633
+ className: "pb-wire-flow",
634
+ "aria-hidden": "true"
635
+ }),
636
+ o !== void 0 && /* @__PURE__ */ t("path", {
637
+ d: o,
638
+ className: "pb-wire-arrow",
639
+ "aria-hidden": "true"
640
+ }),
641
+ c > 0 && /* @__PURE__ */ t("path", {
642
+ d: i,
643
+ fill: "none",
644
+ strokeOpacity: 0,
645
+ strokeWidth: c,
646
+ className: "react-flow__edge-interaction",
647
+ children: s !== void 0 && /* @__PURE__ */ t("title", { children: s })
648
+ })
649
+ ] });
650
+ });
651
+ function Oe({ id: r, sourceX: i, sourceY: a, targetX: o, targetY: s, sourcePosition: c, targetPosition: l, data: u, selected: f, interactionWidth: p = 20, markerStart: m, markerEnd: h, style: g }) {
652
+ let [_, v, y] = d(() => T({
653
+ sourceX: i,
654
+ sourceY: a,
655
+ sourcePosition: c,
656
+ targetX: o,
657
+ targetY: s,
658
+ targetPosition: l
659
+ }), [
660
+ i,
661
+ a,
662
+ c,
663
+ o,
664
+ s,
665
+ l
666
+ ]), x = u?.arrow === !0, S = d(() => x ? Ee(o, s, l) : void 0, [
667
+ x,
668
+ o,
669
+ s,
670
+ l
671
+ ]), C = u?.emphasis === void 0 ? void 0 : Te(u.emphasis), w = C === void 0 ? void 0 : { "--pb-wire-emphasis": C }, E = u?.label;
672
+ return /* @__PURE__ */ n(e, { children: [/* @__PURE__ */ t("g", {
673
+ className: "pb-wire",
674
+ "data-tone": u?.tone,
675
+ "data-selected": f === !0 ? "" : void 0,
676
+ "data-dashed": u?.dashed === !0 ? "" : void 0,
677
+ "data-emphasis": C === void 0 ? void 0 : "",
678
+ style: w,
679
+ children: /* @__PURE__ */ t(De, {
680
+ id: r,
681
+ path: _,
682
+ flow: u?.flow === !0,
683
+ arrow: S,
684
+ title: u?.title,
685
+ interactionWidth: p,
686
+ markerStart: m,
687
+ markerEnd: h,
688
+ style: g
689
+ })
690
+ }), E != null && /* @__PURE__ */ t(b, { children: /* @__PURE__ */ t("div", {
691
+ className: "pb-wire-label",
692
+ "data-tone": u?.tone,
693
+ style: { transform: `translate(-50%, -50%) translate(${v}px, ${y}px)` },
694
+ children: E
695
+ }) })] });
696
+ }
697
+ export { ne as CanvasTools, ie as ConnectHints, B as GhostWire, Z as HANDLE_HIT, Se as HANDLE_SIZE, de as Meter, xe as NODE_FOOTER, _e as NODE_HEADER, ve as NODE_LINE, be as NODE_PAD, ye as NODE_ROW, ge as NODE_WIDTH, me as NodeBox, Y as PortRow, Oe as Wire, F as defaultCanvasToolsLabels, q as defaultMeterLabels, V as defaultMeterScale, K as defaultMeterTitle, X as defaultNodeBoxLabels, re as mergeFlowProps, W as meterFraction, H as meterTitleEveryMs, we as nodeBoxSize, U as toDb, N as useAddAt, ce as useConnectHints, le as useFollowFit };
122
698
 
123
699
  //# sourceMappingURL=graph.js.map